#include<bits/stdc++.h>   using namespace std;      #ifdef LOCAL   #include  debug.h    #endif      #ifdef LOCAL   #define debug(...) cerr <<  [  << #__VA_ARGS__ <<  ]: , debug_out(__VA_ARGS__)   #else   #define debug(...) 42   #endif      #define endl   n    typedef long long ll;   typedef long double ld;   typedef vector<int> vi;   typedef std::vector<vector<int> > vvi;   typedef pair<int, int> pi;   typedef pair<ll, ll> pll;   typedef vector<ll> vll;   typedef vector<pi> vpi;   typedef vector<pll> vpll;   typedef vector<vll> vvll;   typedef vector<vi> vvi;   typedef vector<double> vd;   typedef vector<vector<double>> vvd;   typedef vector<ld> vld;   typedef vector<vld> vvld;   typedef vector<bool> vb;   typedef vector<vb> vvb;   typedef vector<char> vch;   typedef vector<vch> vvch;      #define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)   #define repi(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)   #define pb push_back   #define fi first   #define se second   #define all(a) a.begin(), a.end()   #define sz(a) (int)(a.size())      template<typename T> void umin(T &a, T b) { a = min(a, b); }   template<typename T> void umax(T &a, T b) { a = max(a, b); }      ll nxt() {    ll x; cin >> x; return x;   }      void setIO(string s) {    #ifndef LOCAL    ios_base::sync_with_stdio(0); cin.tie(0);     freopen((s+ .in ).c_str(), r ,stdin);    freopen((s+ .out ).c_str(), w ,stdout);    #endif   }      void yes() {    cout <<  yes n ;   }      void no() {    cout <<  no n ;   }      void flush() {    debug( ################# );   }      const ll mod = 1e9 + 7;   const ll INF = 1e9;      void solve() {     int m, k; cin >> m >> k;     vi cnt(k + 1);        rep(i, 1, k + 1) {       cnt[i] = nxt();     }        int mx = *max_element(all(cnt));     int mxid = -1;     rep(i, 1, k + 1) if (cnt[i] == mx) mxid = i;        int lo = 1, hi = 200005;     while (lo < hi) {       int mid = (lo + hi) / 2;       ll one = 1LL * mid * mid - 1LL * (mid / 2) * (mid / 2);       ll two = 1LL * mid * ((mid + 1) / 2);       if (one >= m && two >= mx) {         hi = mid;       } else {         lo = mid + 1;       }     }        int n = lo;     vvi a(n + 1, vi(n + 1));        vpi filling_order;     rep(i, 1, k + 1) filling_order.pb({cnt[i], i});     sort(all(filling_order)); reverse(all(filling_order));        vi order;     for (auto it : filling_order) {       rep(i, 0, it.fi) order.pb(it.se);     }        assert(sz(order) == m);     int ptr = 0;     int done = 0;     for (int row = 2; row <= n; row += 2) {       for (int col = 1; col <= n; col += 2) {         if (done >= mx) break;         a[row][col] = order[ptr++];         done++;       }     }        if (done < mx) {       for (int row = 1; row <= n; row += 2) {         for (int col = 1; col <= n; col += 2) {           if (done >= mx) break;           a[row][col] = order[ptr++];           done++;         }       }     } else {       for (int row = 2; row <= n; row += 2) for (int col = 1; col <= n; col += 2) {         if (ptr >= m) break;         if (a[row][col] == 0) a[row][col] = order[ptr++];       }     }     //all reds are filled        //fill all non-filled     for (int row = 1; row <= n; row++) {       int add = 2;       if (row % 2 == 1) {         add = 1;       }       for (int col = 1; col <= n; col += add) {         if (a[row][col] == 0 && ptr < m) {           a[row][col] = order[ptr++];         }       }     }        cout << n << endl;     for (int row = 1; row <= n; row++) {       for (int col = 1; col <= n; col++) {         cout << a[row][col] <<    ;       }       cout << endl;     }        flush();     for (int row = 1; row <= n; row++) for (int col = 1; col <= n; col++) {       debug(row, col);       if (row + 1 <= n && col + 1 <= n && a[row][col] != 0 && a[row + 1][col + 1] != 0) assert(a[row][col] != a[row + 1][col + 1]);       if (row + 1 <= n && col - 1 >= 1 && a[row][col] != 0 && a[row + 1][col - 1] != 0) assert(a[row][col] != a[row + 1][col - 1]);          if (row + 1 <= n && col + 1 <= n) assert(a[row][col] == 0 or a[row][col + 1] == 0 or a[row + 1][col] == 0 or a[row + 1][col + 1] == 0);     }   }           int32_t main(){    // setIO( trapped );    ios_base::sync_with_stdio(false);    cin.tie(NULL);       cout << fixed << setprecision(10);       int T = 1;    cin >> T;       for (int tc = 1; tc <= T; tc++) {     // cout <<  Case #  << tc <<  :  ;     solve();    }   }


#include <bits/stdc++.h>   #define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);   #define hell 1000000007   #define pb push_back   #define endl   n    #define rep(i, s, n)    for(ll i = s; i < (n); ++i)   #define F first   #define S second    #define ll long long   #define sz(a) a.size()   #define pii std::pair<int, int>    #define pll std::pair<ll, ll>     #define vi vector<int>     #define vl vector<ll>   #define vvi vector<vi >    #define vii vector<pii >   #define vll vector<pll >   #define INF INT_MAX   #define inf 9e18   #define N int(2e5+5)   #define all(v) v.begin(),v.end()   #define mod 998244353       using namespace std;   ll add(ll a,ll b)   {    return (a%hell+b%hell)%hell;   }   ll mul(ll a,ll b)   {    return ((a%hell)*(b%hell))%hell;   }   ll n;   ll fast_pow(ll a,ll b)   {    ll ans=1;    while(b)    {     if(b&1)ans=ans*a;     a=a*a;     b>>=1;    }    return ans;   }   void solve()   {    ll x,s=0,p;vi v;    while(n>0)    {     // x=log2(n+2)*1ll-2;     for(x=0;(1ll<<(x+2))-2<=n;x++);     x-=1;     p=(1ll<<(x+2))-2;     n-=p;     v.pb(x);s+=1+x;    }    cout<<s<<endl;    for(auto i:v){cout<<1<<   ;rep(j,0,i)cout<<0<<   ;}   }   int main()   {    FAST    ll test=1;    cin>>test;    while(test--)     {     cin>>n;     if(n&1){cout<<-1<<endl;continue;}     solve();     cout<<endl;    }    return 0;   }


#include <bits/stdc++.h>   using std::abs;   using std::array;   using std::cerr;   using std::cin;   using std::cout;   using std::generate;   using std::make_pair;   using std::map;   using std::max;   using std::max_element;   using std::min;   using std::min_element;   using std::pair;   using std::reverse;   using std::set;   using std::sort;   using std::string;   using std::unique;   using std::vector;   template <typename T>   T input() {     T res;     cin >> res;     {};     return res;   }   template <typename IT>   void input_seq(IT b, IT e) {     std::generate(b, e,                   input<typename std::remove_reference<decltype(*b)>::type>);   }   bool bad(char a) {     return a !=  a  and a !=  e  and a !=  i  and a !=  o  and a !=  u ;   }   bool bad(string a) {     return a.size() >= 3 and bad(a[a.size() - 1]) and bad(a[a.size() - 2]) and            bad(a[a.size() - 3]) and            not(a[a.size() - 1] == a[a.size() - 2] and                a[a.size() - 2] == a[a.size() - 3]);   }   int main() {     std::iostream::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     string s = input<string>();     string b =   ;     for (char ch : s) {       b += ch;       if (bad(b)) {         b.pop_back();         cout << b <<    ;         b.clear();         b += ch;       }     }     if (b !=   ) cout << b;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, k;   long long int i;   long long int sum = 0;   long long int cheng = 1;   long long int ans[200010];   struct xxx {     long long int num;     long long int id;     bool operator<(const struct xxx &node) const { return num > node.num; }   } xxx[200010];   int main() {     scanf( %lld%lld , &n, &k);     for (i = 0; i < n; i++) {       xxx[i].id = i;       scanf( %lld , &xxx[i].num);     }     sort(xxx, xxx + n);     for (i = 0; i < k; i++) sum = sum + xxx[i].num;     for (i = 0; i < k; i++) ans[i] = xxx[i].id;     sort(ans, ans + k);     for (i = 0; i < k - 1; i++) cheng = cheng * (ans[i + 1] - ans[i]) % 998244353;     printf( %lld %lld , sum, cheng);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   int a[105], n, K, sn;   struct Mat {     int a[105][105];     Mat() { memset(a, 0, sizeof(a)); }     Mat operator*(const Mat &b) const {       Mat c = Mat();       for (int i = 0; i <= sn; i++)         for (int j = 0; j <= sn; j++)           for (int k = 0; k <= sn; k++)             c.a[i][j] = (c.a[i][j] + (long long)a[i][k] * b.a[k][j]) % mod;       return c;     }   } ret, mp;   int q_pow(int x, int n) {     int ret = 1;     for (; n; n >>= 1, x = (long long)x * x % mod)       if (n & 1) ret = (long long)ret * x % mod;     return ret;   }   void q_pow(int K) {     for (; K; K >>= 1, mp = mp * mp)       if (K & 1) ret = ret * mp;   }   int main() {     scanf( %d%d , &n, &K);     int now = 0;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), sn += a[i] == 1;     for (int i = n - sn + 1; i <= n; i++) now += a[i] == 1;     ret.a[0][now] = 1;     for (int i = 0; i <= sn; i++) {       mp.a[i][i - 1] = i * (n - sn * 2 + i);       mp.a[i][i + 1] = (sn - i) * (sn - i);       mp.a[i][i] =           (n * (n - 1) >> 1) - i * (n - sn * 2 + i) - (sn - i) * (sn - i);     }     q_pow(K);     printf( %I64d n , ((long long)ret.a[0][sn] *                            q_pow(q_pow(n * (n - 1) >> 1, mod - 2), K) % mod +                        mod) %                           mod);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s, sum = 0, big;     cin >> n >> s;     int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];       sum += arr[i];     }     sort(arr, arr + n);     big = arr[n - 1];     if (sum - big <= s)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   long long f[N];   const int mod = 1000000007;   int main() {     string s;     cin >> s;     s +=  , ;     long long ans = 1;     int l = s.size();     f[0] = 1, f[1] = 1, f[2] = 2;     for (int i = 3; i <= l; i++) f[i] = (f[i - 1] + f[i - 2]) % mod;     long long now = 0, nn = -1;     int c = 1;     for (int i = 0; i < l; i++) {       if (s[i] ==  m  || s[i] ==  w ) {         c = 0;         break;       }       if (s[i] ==  u ) {         if (nn == 1)           now++;         else {           ans = ans * f[now] % mod;           now = 1, nn = 1;         }       } else if (s[i] ==  n ) {         if (nn == 2)           now++;         else {           ans = ans * f[now] % mod;           now = 1, nn = 2;         }       } else {         ans = ans * f[now] % mod;         now = 0, nn = -1;       }     }     if (c == 0)       cout <<  0 n ;     else       cout << ans % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, s[50005], ans[50005];   pair<int, int> t[50005];   int main() {     scanf( %d , &n);     for (int i = (1); i <= (n); i++) scanf( %d , &s[i]);     s[n + 1] = s[1];     for (int i = (1); i <= (n); i++) t[i] = make_pair(s[i] + s[i + 1], i);     sort(t + 1, t + n + 1);     for (int i = (1); i <= (n); i++) ans[t[i].second] = i;     for (int i = (1); i <= (n); i++)       printf( %d%c , ans[i] - 1, i == n ?   n  :    );     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   void die(string S) {     puts(S.c_str());     exit(0);   }   char occ[10][10];   bool T[4][3][3] = {{{1, 1, 1}, {0, 1, 0}, {0, 1, 0}},                      {{0, 1, 0}, {0, 1, 0}, {1, 1, 1}},                      {{1, 0, 0}, {1, 1, 1}, {1, 0, 0}},                      {{0, 0, 1}, {1, 1, 1}, {0, 0, 1}}};   int n, m;   int ans;   int occur, occuc;   char res[10][10];   void Solve(int step) {     if (step > ans) {       ans = step;       memcpy(res, occ, sizeof(occ));     }     for (int type = 0; type < 4; type++) {       bool fl = true;       for (int i = occur; i < n - 2 && fl; i++)         for (int j = (i == occur ? occuc : 0); j < m - 2 && fl; j++) {           bool f = true;           for (int k = 0; k < 3; k++)             for (int l = 0; l < 3; l++)               if (occ[i + k][j + l] !=  .  && T[type][k][l]) {                 f = false;                 break;               }           if (f) {             for (int k = 0; k < 3; k++)               for (int l = 0; l < 3; l++)                 if (T[type][k][l]) occ[i + k][j + l] = ( A  + step);             int tmp = 0;             if (j == m - 3) {               tmp = occuc;               occuc = 0;               occur++;             } else               occuc += 2 + (type == 3);             Solve(step + 1);             for (int k = 0; k < 3; k++)               for (int l = 0; l < 3; l++)                 if (T[type][k][l]) occ[i + k][j + l] =  . ;             if (j == m - 3) {               occur--;               occuc = tmp;             } else               occuc -= 2 + (type == 3);             fl = false;           }         }     }   }   int main() {     cin >> n >> m;     if (n == 9 && m == 9) {       puts( 13 );       puts( AAABBBCCC );       puts( .AD.BE.C. );       puts( .AD.BE.C. );       puts( FDDDEEE.H );       puts( FFFGGGHHH );       puts( FIIIGJJJH );       puts( .KILG.JM. );       puts( .KILLLJM. );       puts( KKKL..MMM );       return 0;     }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) occ[i][j] = res[i][j] =  . ;     Solve(0);     cout << ans << endl;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cout << res[i][j];       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   long long v[500000];   long long f[100005], p[100005];   bool chk(int n) {     while (n) {       int t = n % 10;       if (t == 4 || t == 7) {         n /= 10;       } else         return false;     }     return true;   }   void egcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;     } else {       egcd(b, a % b, x, y);       long long k = a / b;       k = x - k * y;       x = y;       y = k;     }   }   long long r(long long d) {     long long x, y;     egcd(d, 1000000007, x, y);     x %= 1000000007;     if (x < 0) x += 1000000007;     return x;   }   long long C(int a, int b) {     if (a == 0 || b == 0) return 1;     long long tmp = p[a] * r(p[b]);     tmp = ((tmp % 1000000007) * r(p[a - b])) % 1000000007;     return tmp;   }   int main() {     int n, k;     while (scanf( %d%d , &n, &k) != -1) {       int i, j;       int m = 0;       mp.clear();       for (i = 0; i < n; i++) {         int x;         scanf( %d , &x);         if (chk(x))           mp[x]++;         else           m++;       }       map<int, int>::iterator it;       int cnt = 0;       for (it = mp.begin(); it != mp.end(); it++) {         v[cnt++] = it->second;       }       memset(f, 0, sizeof(f));       f[0] = 1;       for (i = 0; i < cnt; i++) {         for (j = k; j - 1 >= 0; j--) {           f[j] = (f[j] + f[j - 1] * v[i]) % 1000000007;         }       }       long long ans = 0;       p[0] = 1;       for (i = 1; i <= n; i++) p[i] = (p[i - 1] * i) % 1000000007;       for (i = 0; i <= k && i <= m; i++) {         ans = (ans + f[k - i] * C(m, i)) % 1000000007;       }       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve();   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       solve();     }     return 0;   }   void solve() {     string s, t;     cin >> s >> t;     long long a[10];     memset(a, 0, sizeof(a));     if (s.length() == 1 && s[0] ==  0 ) {       if (t == s) {         cout <<  OK ;         return;       } else {         cout <<  WRONG_ANSWER ;         return;       }     }     for (long long i = 0; i < s.length(); i++) {       a[s[i] -  0 ]++;     }     string ans;     if (a[0] == 0) {       ans = s;       sort(ans.begin(), ans.end());       if (ans == t) {         cout <<  OK ;         return;       } else {         cout <<  WRONG_ANSWER ;         return;       }     } else {       long long index;       for (long long i = 1; i < 10; i++) {         if (a[i] != 0) {           index = i;           break;         }       }       a[index]--;       for (long long i = 0; i < 10; i++) {         if (a[i] != 0) {           while (a[i]--) {             char temp =  0  + i;             ans += string(1, temp);           }         }       }       sort(ans.begin(), ans.end());       char t2 =  0  + index;       string rtans = string(1, t2);       rtans += ans;       if (rtans == t) {         cout <<  OK ;         return;       } else {         cout <<  WRONG_ANSWER ;         return;       }     }     return;   }


#include <bits/stdc++.h>   using namespace std;   int a[100001];   int main() {     int n, x = 0;     cin >> n;     for (int i = 2; i <= n; i++) {       if (a[i] == 0) {         x++;         a[i] = x;         for (int j = i; j <= n; j += i) a[j] = x;       }     }     for (int i = 2; i <= n; i++) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     int n;     double edge;     while (t) {       cin >> n;       n = n * 2;       edge = sin(3.1415926535897932384626 / n / 2);       edge = 0.5 / edge;       cout << setprecision(12);       cout << edge << endl;       --t;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 7;   struct node {     int x1, y1, x2, y2;     node() {}     node(int _x1, int _y1, int _x2, int _y2)         : x1(_x1), y1(_y1), x2(_x2), y2(_y2) {}   } q[N];   int n, m, r[N], r1[N], c[N], c1[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &r[i]);     for (int i = 1; i <= n; i++) scanf( %d , &c[i]);     for (int i = 1; i <= n; i++) {       if (r[i] == i && c[i] == i) continue;       int x, y;       for (int j = i; j <= n; j++)         if (r[j] == i) r[j] = r[i], x = j;       for (int j = i; j <= n; j++)         if (c[j] == i) c[j] = c[i], y = j;       q[++m] = node(x, i, i, y);     }     printf( %d n , m);     for (int i = 1; i <= m; i++)       printf( %d %d %d %d n , q[i].x1, q[i].y1, q[i].x2, q[i].y2);   }


#include <bits/stdc++.h>   using namespace std;   int n, k, a[10010];   long long ans;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     for (int i = 1; i <= k; i++) ans += a[i];     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   bool sortinrev(const pair<int, int>& a, const pair<int, int>& b) {     if (a.first == b.first) return b.second > a.second;     return a.first > b.first;   }   void run(vector<int> v) {     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;     cout << endl;   }   int modInverse(long long int a, long long int m) {     long long int m0 = m;     long long int y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long int q = a / m;       long long int t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   void numberOfNodes(int n, vector<long long int> adj[],                      vector<long long int>& count1, int s, int e) {     vector<long long int>::iterator u;     count1[s] = 1;     for (u = adj[s].begin(); u != adj[s].end(); u++) {       if (*u == e) continue;       numberOfNodes(n, adj, count1, *u, s);       count1[s] += count1[*u];     }   }   void solve() {     int n, k, unhappy = 0;     cin >> n >> k;     vector<pair<int, int>> edges;     vector<int> adj[n + 1];     unordered_map<int, int> mp[n + 1];     vector<bool> vis(n + 1, 0);     for (int i = 0; i < k; i++) {       int x, y;       cin >> x >> y;       if (mp[x].find(y) == mp[x].end()) {         mp[x][y]++;         mp[y][x]++;         edges.push_back({x, y});         adj[x].push_back(y);         adj[y].push_back(x);       }     }     unhappy += (k - edges.size());     k -= unhappy;     queue<int> q;     int ans = 0;     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         q.push(i);         vector<int> vec;         vis[i] = 1;         vec.push_back(i);         while (!q.empty()) {           int p = q.front();           q.pop();           for (int j = 0; j < adj[p].size(); j++) {             if (!vis[adj[p][j]]) {               vec.push_back(adj[p][j]);               vis[adj[p][j]] = 1;               q.push(adj[p][j]);             }           }         }         ans += (vec.size() - 1);       }     }     cout << unhappy + k - ans << endl;   }   int main() {     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double esp = 0.0000000001;   const double PI = acos(-1.0);   const int mod = 1e9 + 7;   const int MY = 1400 + 5;   const int MX = 1010 + 5;   int num, n, k;   vector<int> G[MX];   int d[MX * MX], g[MX][MX], vis[MX];   struct node {     int x, y;   } P[MX];   bool dfs(int cnt, int m) {     if (cnt > n) return true;     if (vis[cnt]) return dfs(cnt + 1, m);     for (int i = 0; i < (int)G[cnt].size(); ++i) {       m += !vis[G[cnt][i]];       vis[G[cnt][i]]++;     }     if (m <= k && dfs(cnt + 1, m)) return true;     int temp = m;     for (int i = 0; i < (int)G[cnt].size(); ++i) {       vis[G[cnt][i]]--;       m -= !vis[G[cnt][i]];     }     if (G[cnt].size() != 1) {       vis[cnt]++;       if (m + 1 <= k && m + 1 < temp && dfs(cnt + 1, m + 1)) return true;       vis[cnt]--;     }     return false;   }   bool judge(int dist) {     memset(vis, false, sizeof(vis));     for (int i = 1; i <= n; ++i) G[i].clear();     for (int i = 1; i < n; ++i)       for (int j = i + 1; j <= n; ++j)         if (g[i][j] > dist) {           G[i].push_back(j);           G[j].push_back(i);         }     return dfs(1, 0);   }   int binary_search(int le, int rt) {     int mid;     while (le < rt) {       mid = (le + rt) >> 1;       if (judge(d[mid]))         rt = mid;       else         le = mid + 1;     }     return le;   }   int main() {     while (~scanf( %d%d , &n, &k)) {       num = 0;       d[0] = 0;       for (int i = 1; i <= n; ++i) scanf( %d%d , &P[i].x, &P[i].y);       for (int i = 1; i < n; ++i)         for (int j = i + 1; j <= n; ++j)           d[++num] = g[i][j] = (P[i].x - P[j].x) * (P[i].x - P[j].x) +                                (P[i].y - P[j].y) * (P[i].y - P[j].y);       sort(d, d + num + 1);       num = unique(d, d + num + 1) - d - 1;       int mx = binary_search(0, num);       judge(d[mx]);       bool first = false;       for (int i = n; i >= 1; --i)         if (vis[i]) {           if (first) putchar(   );           printf( %d , i);           k--;           first = true;         }       for (int i = n; i >= 1 && k > 0; --i)         if (!vis[i]) {           if (first) putchar(   );           printf( %d , i);           k--;           first = true;         }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int MAXN = 2e5 + 51;   long long int n, r;   long long int prefix[MAXN], f[MAXN];   inline long long int read() {     register long long int num = 0, neg = 1;     register char ch = getchar();     while (!isdigit(ch) && ch !=  - ) {       ch = getchar();     }     if (ch ==  - ) {       neg = -1;       ch = getchar();     }     while (isdigit(ch)) {       num = (num << 3) + (num << 1) + (ch -  0 );       ch = getchar();     }     return num * neg;   }   int main() {     n = read();     for (register int i = 1; i <= n; i++) {       prefix[i] = prefix[i - 1] + read();     }     r = prefix[n];     for (register int i = n - 1; i >= 1; i--) {       f[i] = r, r = max(r, prefix[i] - f[i]);     }     printf( %lld n , f[1]);   }


#include <bits/stdc++.h>   using namespace std;   const long long int INF = 2e18;   const long long int N = 2e5 + 5;   bool isPrime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long int i = 5; i * i <= n; i = i + 6) {       if (n % i == 0 || n % (i + 2) == 0) return false;     }     return true;   }   long long int factorial(long long int n) {     long long int ans = 1;     for (long long int i = 1; i <= n; i++) ans = (ans * i) % 1000000007;     return ans;   }   long long int exp(long long int x, long long int n) {     long long int res = 1;     while (n > 0) {       if (n % 2 == 1) res = (res * x) % 1000000007;       x = (x * x) % 1000000007;       n = n / 2;     }     return res;   }   void null() {     long long int n;     cin >> n;     char a[n][n];     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < n; j++) {         cin >> a[i][j];       }     }     long long int ans = 0;     if (a[0][1] == a[1][0]) {       if (a[n - 1][n - 2] == a[n - 2][n - 1]) {         if (a[n - 1][n - 2] == a[0][1]) {           cout << 2 <<   n ;           cout << 1 <<     << 2 <<   n ;           cout << 2 <<     << 1 <<   n ;           return;         } else {           cout << 0 <<   n ;           return;         }       }       if (a[n - 1][n - 2] != a[n - 2][n - 1]) {         if (a[n - 1][n - 2] == a[0][1]) {           cout << 1 <<   n ;           cout << n <<     << n - 1 <<   n ;           return;         } else if (a[n - 2][n - 1] == a[0][1]) {           cout << 1 <<   n ;           cout << n - 1 <<     << n <<   n ;           return;         }       }     } else {       if (a[n - 1][n - 2] == a[n - 2][n - 1]) {         if (a[0][1] == a[n - 1][n - 2]) {           cout << 1 <<   n ;           cout << 1 <<     << 2 <<   n ;           return;         } else {           cout << 1 <<   n ;           cout << 2 <<     << 1 <<   n ;           return;         }       } else {         cout << 2 <<   n ;         if (a[0][1] == a[n - 1][n - 2]) {           cout << 1 <<     << 2 <<   n ;           cout << n - 1 <<     << n <<   n ;           return;         } else if (a[0][1] == a[n - 2][n - 1]) {           cout << 1 <<     << 2 <<   n ;           cout << n <<     << n - 1 <<   n ;           return;         }       }     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t = 1;     clock_t start, end;     start = clock();     cin >> t;     while (t--) {       null();     }     end = clock();     double time_taken = double(end - start) / double(CLOCKS_PER_SEC);   }


#include <bits/stdc++.h>   using namespace std;   void optimise() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   void solve() {     string s;     cin >> s;     string s2;     cin >> s2;     sort(s.begin(), s.end());     for (long long int i = 0; i < s.size(); i++) {       for (long long int j = i + 1; j < s.size(); j++) {         string k = s;         swap(k[i], k[j]);         if (stoll(k) >= stoll(s) && stoll(k) <= stoll(s2)) s = k;       }     }     cout << s;   }   signed main() {     optimise();     long long int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T modinv(T a, T n) {     T i = n, v = 0, d = 1;     while (a > 0) {       T t = i / a, x = a;       a = i % x;       i = x;       x = d;       d = v - t * x;       v = x;     }     return (v + n) % n;   }   long long modpow(long long n, long long k, long long mod) {     if (k == 0) return 1LL;     long long ans = 1;     while (k > 0) {       if (k & 1) ans = (ans * n) % mod;       k >>= 1;       n = (n * n) % mod;     }     return ans % mod;   }   template <class T>   struct Fraction {     T a, b;     Fraction(T a = 0, T b = 1);     string toString();   };   template <class T>   Fraction<T>::Fraction(T a, T b) {     T d = GCD(a, b);     a /= d;     b /= d;     if (b < 0) a = -a, b = -b;     this->a = a;     this->b = b;   }   template <class T>   string Fraction<T>::toString() {     ostringstream sout;     sout << a <<  /  << b;     return sout.str();   }   template <class T>   Fraction<T> operator+(Fraction<T> p, Fraction<T> q) {     return Fraction<T>(p.a * q.b + q.a * p.b, p.b * q.b);   }   template <class T>   Fraction<T> operator-(Fraction<T> p, Fraction<T> q) {     return Fraction<T>(p.a * q.b - q.a * p.b, p.b * q.b);   }   template <class T>   Fraction<T> operator*(Fraction<T> p, Fraction<T> q) {     return Fraction<T>(p.a * q.a, p.b * q.b);   }   template <class T>   Fraction<T> operator/(Fraction<T> p, Fraction<T> q) {     return Fraction<T>(p.a * q.b, p.b * q.a);   }   template <class T>   string str(T Number) {     string Result;     ostringstream convert;     convert << Number;     Result = convert.str();     return Result;   }   int StringToNumber(const string &Text) {     istringstream ss(Text);     int result;     return ss >> result ? result : 0;   }   template <class T>   inline vector<pair<T, int> > FACTORISE(T n) {     vector<pair<T, int> > R;     for (T i = 2; n > 1;) {       if (n % i == 0) {         int C = 0;         for (; n % i == 0; C++, n /= i)           ;         R.push_back(make_pair(i, C));       }       i++;       if (i > n / i) i = n;     }     if (n > 1) R.push_back(make_pair(n, 1));     return R;   }   template <class T>   inline T TOTIENT(T n) {     vector<pair<T, int> > R = FACTORISE(n);     T r = n;     for (int i = 0; i < R.size(); i++) r = r / R[i].first * (R[i].first - 1);     return r;   }   template <class T>   inline T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   double rnd(float d) { return floor(d + 0.49); }   int main() {     string s;     cin >> s;     int k = ({       int x;       scanf( %d , &x);       x;     });     long long ans = 0;     long long n = ((int)(s).size());     long long t = (modpow(2, n, 1000000007) - 1 + 1000000007);     long long inv = modpow(t + 1000000007, 1000000007 - 2, 1000000007);     for (long long i = 0; i < n; i++) {       if ((s[i] - 48) % 5 == 0) {         ans = (ans + modpow(2, i, 1000000007)) % 1000000007;       }     }     cout << (ans * (modpow(2, (k)*n, 1000000007) - 1 + 1000000007) % 1000000007 *              inv) %                 1000000007          <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[50], p[50], b[50];   bool cmp(int x, int y) {     if (a[x] < a[y]) return 1;     return 0;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       p[i] = i;     }     sort(p, p + n, cmp);     for (int i = 0; i < n - 1; i++) {       b[p[i + 1]] = a[p[i]];     }     b[p[0]] = a[p[n - 1]];     for (int i = 0; i < n; i++) {       printf( %d  , b[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 100;   int f[maxn];   int a[maxn];   char s[maxn];   int main() {     int d;     scanf( %d , &d);     scanf( %s , s);     int len = strlen(s);     a[1] = s[0] -  0 ;     for (int i = 1; i < len; i++) {       a[i + 1] = a[i] + (s[i] -  0 );     }     for (int i = 1; i <= len; i++) {       for (int j = 0; j < i; j++) {         f[a[i] - a[j]]++;       }     }     long long ans = 0;     for (int i = 1; i < maxn; i++) {       if (d % i) continue;       if ((d / i) >= maxn) continue;       ans += (long long)f[i] * f[d / i];     }     if (d == 0) {       ans = 0;       for (int i = 0; i < maxn; i++) ans += (long long)f[0] * f[i];       ans *= 2;       ans -= (long long)f[0] * f[0];     }     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int kN = 2e5 + 10;   int N, M;   struct Ele {     long long len;     char c;     void read() {       len = 0;       char s[30];       scanf( %s , s);       for (int i = 0; s[i]; i++) {         if (s[i] ==  - ) {           c = s[i + 1];           break;         } else {           len *= 10;           len += s[i] -  0 ;         }       }     }     bool operator==(const Ele &e) const { return len == e.len && c == e.c; }     bool operator!=(const Ele &e) const { return !((*this) == e); }   };   Ele A[kN], B[kN], T[kN];   int tn;   void merge(Ele a[], int &n) {     int p = 0;     for (int i = 1; i <= n; i++) {       if (p && a[p].c == a[i].c) {         a[p].len += a[i].len;       } else {         p++;         a[p] = a[i];       }     }     n = p;   }   bool check(int i, int j) {     return i >= 1 && i <= N && A[i].len >= B[j].len && A[i].c == B[j].c;   }   int lst[kN];   int main() {     scanf( %d %d , &N, &M);     for (int i = 1; i <= N; i++) A[i].read();     for (int i = 1; i <= M; i++) B[i].read();     merge(A, N);     merge(B, M);     for (int i = 2; i < M; i++) T[++tn] = B[i];     long long ans = 0;     if (M == 1) {       for (int i = 1; i <= N; i++) {         if (A[i].c == B[1].c && A[i].len >= B[1].len) {           ans += A[i].len - B[1].len + 1;         }       }     } else {       lst[1] = 0;       for (int i = 2; i <= tn; i++) {         int p = lst[i - 1];         while (p && T[p + 1] != T[i]) p = lst[p];         if (T[p + 1] == T[i]) p++;         lst[i] = p;       }       int j = 0;       for (int i = 1; i <= N; i++) {         while (j < tn && j && T[j + 1] != A[i]) j = lst[j];         if (tn && T[j + 1] == A[i]) j++;         if (j == tn) {           if (check(i + 1, M) && check(i - tn, 1)) {             ans++;           }           j = lst[j];         }       }     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   vector<int> g[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, s;     cin >> n >> s;     for (int i = 0; i < n - 1; ++i) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     int leaves = 0;     for (int i = 1; i <= n; ++i) {       if (g[i].size() == 1) leaves++;     }     long double ans = (long double)(2 * s) / (long double)leaves;     cout << fixed << setprecision(8) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fast() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       gcd(b, a % b);   }   long long lcd(long long a, long long b) { return (a * b) / gcd(a, b); }   int main() {     int t;     cin >> t;     while (t--) {       int n, a[100] = {0};       vector<int> v;       cin >> n;       for (int i = 0; i < 2 * n; i++) {         int temp;         cin >> temp;         if (a[temp] == 0) v.push_back(temp);         a[temp] = 1;       }       for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[1010], b[1010], cnt, x[1010], y[1010], z[1010], w[1010];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= n; ++i) scanf( %d , &b[i]);     for (int i = 1; i <= n; ++i) {       if (a[i] == i && b[i] == i) continue;       ++cnt;       for (int j = i; j <= n; ++j)         if (a[j] == i) x[cnt] = j, y[cnt] = i, swap(a[j], a[i]);       for (int j = i; j <= n; ++j)         if (b[j] == i) z[cnt] = i, w[cnt] = j, swap(b[j], b[i]);     }     printf( %d n , cnt);     for (int i = 1; i <= cnt; ++i)       printf( %d %d %d %d n , x[i], y[i], z[i], w[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double a, b, c, d;     cin >> a >> b >> c >> d;     cout << (long long)ceil((ceil(b / c) * a) / d) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   map<int, int> mpi;   map<string, int> mps;   map<int, vector<int> > path;   map<int, int> visited;   set<int> st;   vector<int> v;   map<int, int>::iterator iti;   map<string, int>::iterator its;   set<int>::iterator sit;   vector<int>::iterator itv;   void fresh() {     mpi.clear();     mps.clear();     st.clear();     v.clear();     path.clear();     visited.clear();   }   int main() {     fast();     int n, a, b, c, d, x1, x2, y1, y2;     int tst;     cin >> tst;     while (tst--) {       cin >> n >> a >> b >> c >> d;       bool flag = false;       for (int i = c - d; i <= c + d; i++) {         if ((i / n) >= (a - b) && (i / n) <= (a + b)) {           int x = ceil((float)i / (float)n);           if (x >= (a - b) && x <= (a + b)) {             flag = true;             break;           }         }       }       if (flag) {         cout <<  YES  << endl;         ;       } else         cout <<  NO  << endl;       ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long ans = 1;     for (long long int i = 2; i * i <= n; i++) {       long long int temp = 0;       while (n % i == 0) {         temp++;         n /= i;       }       ans *= (temp + 1);     }     if (n > 1) ans *= 2;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   bool isGeometrical(int *a, int n) {     if (a[0] == 0) {       for (int i = 0; i < n; i++)         if (a[i] != 0) return false;       return true;     }     for (int i = 0; i < n - 1; i++)       if (a[i + 1] * a[0] != a[i] * a[1]) return false;     return true;   }   int main() {     int n;     scanf( %d , &n);     int a[100000], num0 = 0, pos0 = -1;     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       if (a[i] == 0) {         num0++;         if (pos0 == -1) pos0 = i;       }     }     if (n <= 2) {       printf( %d n , isGeometrical(a, n) ? 0 : 1);       return 0;     }     if (n == 3) {       int ans = 2;       if (isGeometrical(a, n))         ans = 0;       else {         int b[2];         b[0] = a[0], b[1] = a[1];         if (isGeometrical(b, 2)) ans = 1;         b[0] = a[0], b[1] = a[2];         if (isGeometrical(b, 2)) ans = 1;         b[0] = a[1], b[1] = a[2];         if (isGeometrical(b, 2)) ans = 1;       }       printf( %d n , ans);       return 0;     }     if (num0 >= 2) {       int cnt = 0;       for (int i = 1; i < n; i++)         if (a[i] != 0) cnt++;       printf( %d n , min(cnt, 2));       return 0;     }     if (num0 == 1) {       for (int i = pos0; i < n - 1; i++) a[i] = a[i + 1];       printf( %d n , isGeometrical(a, n - 1) ? 1 : 2);       return 0;     }     if (isGeometrical(a, n)) {       puts( 0 );       return 0;     }     if (isGeometrical(a + 1, n - 1)) {       puts( 1 );       return 0;     }     swap(a[0], a[1]);     if (isGeometrical(a + 1, n - 1)) {       puts( 1 );       return 0;     }     swap(a[0], a[1]);     int cnt = 0;     for (int i = 0; i < n - 1; i++) {       if (a[i + 1] * a[0] != a[i] * a[1]) {         cnt++;         a[i + 1] = a[i];       }       if (cnt == 2) break;     }     printf( %d n , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10, mod = 1e9 + 7, L = 20;   vector<int> G[N], g[N];   int h[N], x[5 * N], y[5 * N], par[N][L];   map<int, bool> mp[N];   void dfs(int v, int p) {     par[v][0] = p;     for (int i = 1; i < L; i++) par[v][i] = par[par[v][i - 1]][i - 1];     for (int u : g[v])       if (u != p && h[u] == -1) h[u] = h[v] + 1;     for (int u : g[v])       if (h[u] == h[v] + 1) dfs(u, v);   }   int pr(int v, int x) {     for (int i = 0; i < L; i++)       if ((1 << i) & x) v = par[v][i];     return v;   }   int lca(int u, int v) {     if (h[u] > h[v]) swap(u, v);     v = pr(v, h[v] - h[u]);     if (u == v) return v;     for (int i = L - 1; i >= 0; i--)       if (par[v][i] != par[u][i]) u = par[u][i], v = par[v][i];     return par[v][0];   }   int solve(int u, int v) {     int p = lca(u, v);     int ret = h[u] + h[v] - 2 * h[p];     if (p == u || p == v) return ret;     int x = pr(u, h[u] - h[p] - 1), y = pr(v, h[v] - h[p] - 1);     if (x > y) swap(x, y);     if (mp[x][y]) ret--;     return ret;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     memset(h, -1, sizeof(h));     int n, m, q;     cin >> n >> m >> q;     h[0] = 0;     for (int i = 0; i < m; i++) {       cin >> x[i] >> y[i];       x[i]--;       y[i]--;       if (x[i] > y[i]) swap(x[i], y[i]);       g[x[i]].push_back(y[i]);       g[y[i]].push_back(x[i]);       mp[x[i]][y[i]] = true;     }     dfs(0, 0);     for (int i = 0; i < q; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       cout << solve(x, y) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long blk = 300;   struct data {     long long l, r, i;     data() { l = r = i = 0; }     data(long long v1, long long v2, long long v3) {       l = v1;       r = v2;       i = v3;     }     bool operator<(const data &x) const {       if (l / blk != x.l / blk)         return (l / blk < x.l / blk);       else         return (r < x.r);     }   };   long long num[100005], num2[100005];   data query[100005];   long long freq[1048600], freq2[1048600];   long long output[100005];   int main() {     long long a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t;     scanf( %lld %lld %lld , &a, &b, &c);     num[0] = 0;     for (i = 1; i <= a; i++) {       scanf( %lld , &num[i]);       num2[i] = num[i];       num[i] ^= num[i - 1];     }     for (i = a - 1; i >= 1; i--) num2[i] ^= num2[i + 1];     for (i = 1; i <= b; i++) {       scanf( %lld %lld , &d, &e);       query[i] = data(d, e, i);     }     sort(query + 1, query + b + 1);     memset(freq, 0, sizeof(freq));     l = 1;     r = 0;     long long ans = 0;     num[a + 1] = 0;     freq[0]++;     freq2[num2[1]]++;     for (i = 1; i <= b; i++) {       freq2[num2[r + 1]]--;       while (r < query[i].r) {         r++;         ans += freq[c ^ num[r]];         freq[num[r]]++;         freq2[num2[r]]++;       }       while (r > query[i].r) {         freq[num[r]]--;         freq2[num2[r]]--;         ans -= freq[c ^ num[r]];         r--;       }       freq2[num2[r + 1]]++;       freq[num[l - 1]]--;       while (l < query[i].l) {         freq2[num2[l]]--;         freq[num[l]]--;         ans -= freq2[c ^ num2[l]];         l++;       }       while (l > query[i].l) {         l--;         ans += freq2[c ^ num2[l]];         freq2[num2[l]]++;         freq[num[l]]++;       }       freq[num[l - 1]]++;       output[query[i].i] = ans;     }     for (i = 1; i <= b; i++) {       printf( %lld n , output[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int tam = 100010;   const int MOD = 1000000007;   const int MOD1 = 998244353;   const double EPS = 1e-9;   const double PI = acos(-1);   int ar[3000000];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) ar[i] = i + 1;     for (int i = 2; i < n + 1; i++) {       for (int j = (n + i - 2) - (n % i == 0 ? i : n % i); j > i - 3; j -= i) {         ar[min(n + i - 2, j + i)] = ar[j];       }     }     for (int i = n - 1; i < 2 * n - 1; i++) {       if (i > n - 1) cout <<    ;       cout << ar[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     int n;     cin >> n >> str;     bool flag = true;     int fs = 0, ss = 0;     for (int i = 0; i < n; i++) {       if (str[i] !=  4  && str[i] !=  7 ) {         flag = false;       }     }     for (int i = 0; i < n / 2; i++) {       fs += str[i] -  0 ;     }     for (int i = n / 2; i < n; i++) {       ss += str[i] -  0 ;     }     if (fs != ss) flag = false;     if (flag)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   inline int gi() {     register int x = 0, f = 0;     register char ch = getchar();     while (!isdigit(ch)) f ^= ch ==  - , ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return f ? -x : x;   }   std::set<std::pair<int, int> > st[100010];   std::bitset<200010> bit, I, B, C;   inline bool nmd(int n, int g) {     for (int i = 1; i < n; ++i)       for (auto j : st[i]) {         int a = j.first, b = j.second;         a = (a + g - 1) % n + 1, b = (b + g - 1) % n + 1;         if (st[i].find({a, b}) == st[i].end() &&             st[i].find({b, a}) == st[i].end())           return 0;       }     puts( Yes );     exit(0);   }   int main() {     long long n = gi(), m = gi(), a, b, c;     for (int i = 1; i <= m; ++i) {       a = gi(), b = gi();       if (a > b) std::swap(a, b);       c = std::min(b - a, a + n - b);       if (b - a != c) std::swap(a, b);       if (c * 2 == n)         st[c].insert({b, a}), st[c].insert({a, b});       else         st[c].insert({a, b});     }     for (int i = 1; i * i <= n; ++i)       if (n % i == 0) {         nmd(n, i);         if (i * i != n && i != 1) nmd(n, n / i);       }     puts( No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e5 + 5;   const int M = 1e6;   const long long INF = (long long)(1e18);   const int inf = 1e9;   const long long MOD = 1000000007LL;   long long n, m;   long long a[MAX_N];   long long ans[MAX_N];   long long suff[MAX_N];   void solve() {}   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     long long s = 0LL;     for (long long i = 1; i <= m; i++) {       cin >> a[i];       s += a[i];     }     bool ok = true;     for (long long i = 1; i <= m; i++) {       if (i - 1 + a[i] > n) {         ok = false;         break;       }     }     if (s < n || !ok) {       cout << -1;       return 0;     }     for (long long i = m; i >= 1; i--) {       suff[i] = suff[i + 1] + a[i];       ans[i] = max(i, n - suff[i] + 1);     }     for (long long i = 1; i <= m; i++) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   struct E {     int to;     vector<long long> w;   };   const long long INF = 1e18;   const int N = 3e5 + 5, L = 20;   vector<E> g[N];   long long t[N], d[2][2][N][L];   int anc[N][L], tin[N], tout[N];   int timer = 0, n;   void deep(int node) {     for (E e : g[node]) {       if (e.to != anc[node][0]) {         anc[e.to][0] = node;         deep(e.to);         t[node] = min(t[node], t[e.to] + e.w[0] + e.w[1]);       }     }   }   void walk(int node, long long u) {     u = min(u, t[node]);     t[node] = u;     for (E e : g[node]) {       if (e.to != anc[node][0]) walk(e.to, u + e.w[0] + e.w[1]);     }   }   void dfs(int node) {     tin[node] = timer++;     for (int i = 1; i < L; i++) {       anc[node][i] = anc[anc[node][i - 1]][i - 1];       for (int x = 0; x < 2; x++) {         for (int y = 0; y < 2; y++) {           for (int z = 0; z < 2; z++) {             d[x][z][node][i] =                 min(d[x][z][node][i],                     d[x][y][node][i - 1] + d[y][z][anc[node][i - 1]][i - 1]);           }         }       }     }     for (E e : g[node]) {       if (e.to != anc[node][0]) {         anc[e.to][0] = node;         for (int i = 0; i < 2; i++) {           d[i][i][e.to][0] = min(e.w[i], e.w[1 - i] + t[node] + t[e.to]);           d[i][1 - i][e.to][0] = min(e.w[1 - i] + t[e.to], t[node] + e.w[i]);         }         dfs(e.to);       }     }     tout[node] = timer;   }   bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }   long long calc(int x, int a, int y, int b) {     long long dp[2];     dp[x] = 0;     dp[1 - x] = t[a];     if (a == b) return dp[y];     for (int i = L - 1; i >= 0; i--) {       if (!upper(anc[a][i], b)) {         long long ndp[2] = {INF, INF};         for (int j = 0; j < 2; j++) {           for (int k = 0; k < 2; k++) {             ndp[k] = min(ndp[k], dp[j] + d[j][k][a][i]);           }         }         for (int j = 0; j < 2; j++) dp[j] = ndp[j];         a = anc[a][i];       }     }     return min(dp[0] + d[0][y][a][0], dp[1] + d[1][y][a][0]);   }   int getLca(int a, int b) {     if (upper(a, b)) return a;     for (int i = L - 1; i >= 0; i--) {       if (!upper(anc[a][i], b)) a = anc[a][i];     }     return anc[a][0];   }   long long getAns(int a, int b) {     int x = a % 2, y = b % 2;     a /= 2;     b /= 2;     int l = getLca(a, b);     long long ans = min(calc(x, a, 0, l) + calc(y, b, 0, l),                         calc(x, a, 1, l) + calc(y, b, 1, l));     return ans;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> t[i];     }     for (int i = 0; i < n - 1; i++) {       int x, y;       long long w1, w2;       cin >> x >> y >> w1 >> w2;       x--, y--;       g[x].push_back({y, {w1, w2}});       g[y].push_back({x, {w1, w2}});     }     for (int i = 0; i < 2; i++) {       for (int j = 0; j < 2; j++) {         for (int k = 0; k < n; k++) {           for (int h = 0; h < L; h++) {             d[i][j][k][h] = INF;           }         }       }     }     deep(0);     walk(0, INF);     dfs(0);     int q;     cin >> q;     while (q--) {       int a, b;       cin >> a >> b;       a--, b--;       cout << getAns(a, b) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     long long ans = 0;     for (int i = 0; i < k && n >= 2; i++) {       ans += n - 1 + n - 2;       n -= 2;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   char src[2002], tar[2002];   int ans[2002 * 4], n;   int get(int l, int r, char ch) {     for (int i = l; i <= r; i++)       if (src[i] == ch) return i;     return -1;   }   void reverse(int l, int r) {     for (int i = l; i < r - i + l; i++) swap(src[i], src[r - i + l]);   }   void doswap(int la, int lb) {     reverse(la + lb + 1, n);     reverse(1, n);     reverse(2, n);   }   void work() {     int step = 0;     for (int i = n; i >= 1; i--) {       int p = get(n - i + 1, n, tar[i]);       if (p == -1) {         puts( -1 );         return;       } else {         ans[++step] = n;         ans[++step] = p - 1;         ans[++step] = 1;         doswap(n - i, p - n + i - 1);       }     }     printf( %d n , step);     for (int i = 1; i <= step; i++) printf( %d  , ans[i]);     putchar(  n );   }   int main() {     scanf( %d , &n);     scanf( %s , src + 1);     scanf( %s , tar + 1);     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   int main() {     ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int t;     cin >> t;     for (int hh = 1; hh <= t; hh++) {       int a, b, c, r, aa, bb;       cin >> aa >> bb >> c >> r;       int r1, r2;       r1 = c - r;       r2 = c + r;       a = min(aa, bb);       b = max(aa, bb);       if (a >= r2) {         cout << b - a << endl;         continue;       }       if (b <= r1) {         cout << b - a << endl;         continue;       }       if (a >= r1 && b <= r2) {         cout << 0 << endl;         continue;       }       if (a < r1 && b > r2) {         cout << r1 - a + b - r2 << endl;         continue;       }       if (a < r1 && b <= r2) {         cout << r1 - a << endl;         continue;       }       if (a >= r1 && b > r2) {         cout << b - r2 << endl;         continue;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxn = 300001;   int n;   long long a[mxn], dp[mxn];   map<int, int> first[mxn];   void answer() {     cin >> n;     long long ret = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       first[i].clear();       if (first[i - 1].count(a[i])) {         int x = first[i - 1][a[i]];         ret += (dp[i] = (x ? dp[x - 1] : 0) + 1);         swap(first[i], first[x - 1]);         first[i][a[x - 1]] = x - 1;       } else {         dp[i] = 0;       }       first[i][a[i]] = i;     }     cout << ret <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     for (int i = 0; i < t; i++) answer();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> a(n);     int prev = -1;     bool invalid = false;     for (int i = 0; i < n; i++) {       cin >> a[i];       invalid = (prev > a[i]) || (a[i] > i + 1);       prev = a[i];     }     if (invalid) {       cout << -1 << endl;       return;     }     int mex = a.back();     vector<int> ans(n);     bool first = true;     for (int i = 0, cnt = 0; i < n; i++) {       if (first && i == mex) {         first = false;         cnt++;       }       ans[i] = cnt++;     }     for (int i = n - 1; ~i; i--) {       if (ans[a[i]] == a[i]) {         swap(ans[a[i]], ans[i + 1]);       }     }     for (int i = 0; i < n; i++) {       cout << ans[i] <<    n [i + 1 == n];     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (1 << 20) + 50;   const int MAXLOG = 21;   long long int a[MAXN];   long long int data[MAXLOG][MAXN];   long long int answer[2][MAXN];   long long int n;   void build(int s = 0, int e = (1 << n), int h = 0) {     if (e - s < 2) {       data[h][s] = a[s];       return;     }     int mid = (s + e) / 2;     build(s, mid, h + 1);     build(mid, e, h + 1);     merge(data[h + 1] + s, data[h + 1] + mid, data[h + 1] + mid, data[h + 1] + e,           data[h] + s);     for (int i = s; i < mid; i++) {       long long int now = lower_bound(data[h + 1] + mid, data[h + 1] + e, a[i]) -                           (data[h + 1] + mid);       answer[0][h] += now;     }     for (int i = mid; i < e; i++) {       long long int now = lower_bound(data[h + 1] + s, data[h + 1] + mid, a[i]) -                           (data[h + 1] + s);       answer[1][h] += now;     }   }   int main() {     scanf( %I64d , &n);     for (int i = 0; i < (1 << n); i++) {       scanf( %I64d , a + i);     }     build();     long long int q;     scanf( %I64d , &q);     while (q--) {       long long int ans = 0;       long long int cur;       scanf( %I64d , &cur);       for (int i = n - cur; i < n; ++i) {         swap(answer[0][i], answer[1][i]);       }       for (int i = 0; i < n; i++) {         ans += answer[0][i];       }       printf( %I64d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n, a[N], cnt[N], sum[N];   vector<int> pos[N];   set<int> S;   int main() {     scanf( %d , &n);     for (int i = (1); i <= (n); ++i)       scanf( %d , &a[i]), ++cnt[a[i]], pos[a[i]].push_back(i);     int tt = 0, mx = 0;     for (int i = (1); i <= (n); ++i) {       if (cnt[i] > cnt[mx]) {         mx = i;         tt = 0;       }       if (cnt[i] == cnt[mx]) {         ++tt;       }     }     if (tt > 1) {       printf( %d n , n);       return 0;     }     for (int i = (1); i <= (n + 1); ++i)       sum[i] = sum[i - 1] + (a[i] == mx), a[i] == mx && (S.insert(i), 0);     int ans = 0;     for (int i = (1); i <= (n); ++i)       if (i != mx && ((int)(pos[i]).size())) {         vector<int> v;         for (auto x : pos[i]) {           {             auto it = S.lower_bound(x);             if (it != S.begin()) {               v.push_back(*prev(it));               S.erase(prev(it));             }             if (it != S.end()) {               v.push_back(*it);               S.erase(*it);             }           }           {             auto it = S.lower_bound(x);             if (it != S.begin()) {               v.push_back(*prev(it));               S.erase(prev(it));             }             if (it != S.end()) {               v.push_back(*it);               S.erase(*it);             }           }         }         vector<int> t(v);         for (auto x : pos[i]) v.push_back(x);         {           auto it = S.lower_bound(*min_element(v.begin(), v.end()));           if (it != S.begin()) {             --it;             v.push_back(*it);           }           v.push_back(0);           it = S.upper_bound(*max_element(v.begin(), v.end()));           if (it != S.end()) {             v.push_back(*it);           }           v.push_back(n + 1);         }         sort(v.begin(), v.end());         map<int, int> fi;         fi[sum[v[0]]] = v[0];         int s = 0;         for (int j = (1); j <= (((int)(v).size()) - 1); ++j) {           if (fi.count(sum[v[j] - 1] + s)) {             ans = max(ans, v[j] - 1 - fi[sum[v[j] - 1] + s]);           }           if (a[v[j]] == i) --s;           if (!fi.count(sum[v[j]] + s)) fi[sum[v[j]] + s] = v[j];         }         for (auto x : t) S.insert(x);       }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O3 )   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( fast-math )   #pragma GCC target( sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native )   mt19937 rng(time(NULL));   const int inf = 1e9 + 100;   const long long linf = 2e18;   const long long maxn = 2e5 + 100;   const int mod = 1e9 + 7;   vector<int> g[maxn];   int c[maxn];   bool f = 1;   void dfs(int v, int cl) {     c[v] = cl;     for (int i : g[v]) {       if (c[i] == 0)         dfs(i, cl == 1 ? 2 : 1);       else if (c[i] == cl)         f = 0;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<pair<int, int> > ans(m);     for (int i = 0; i < m; ++i) {       cin >> ans[i].first >> ans[i].second;       g[ans[i].first - 1].push_back(ans[i].second - 1);       g[ans[i].second - 1].push_back(ans[i].first - 1);     }     for (int i = 0; i < n; ++i)       if (!c[i]) dfs(i, 1);     if (f) {       cout <<  YES n ;       for (auto i : ans) {         if (c[i.first - 1] == 2)           cout << 1;         else           cout << 0;       }     } else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void wldd() {     long long n, a, b;     cin >> n >> a >> b;     b = b % n;     long long sum = 0;     if (b < 0) {       sum = n + a + b;     } else {       sum = a + b;     }     if (sum % n == 0)       cout << n <<   n ;     else       cout << abs(sum % n) <<   n ;   }   int32_t main() {     wldd();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sgn(double x) { return (x > 1e-8) - (x < -1e-8); }   int count_bit(int x) { return x == 0 ? 0 : count_bit(x >> 1) + (x & 1); }   template <class T>   inline void to_min(T &a, const T b) {     if (b < a) a = b;   }   template <class T>   inline void to_max(T &a, const T b) {     if (b > a) a = b;   }   const int maxn = 200000 + 10;   int n, a[3], w[maxn];   bool used[maxn];   int rearray(int n) {     int newn = 0;     for (int i = 0; i < (n); ++i) {       if (!used[i]) {         w[newn++] = w[i];       }     }     return newn;   }   int solve() {     int r = a[2] + a[1] + a[0];     if (r < w[n - 1]) {       return -1;     }     int ret = 0;     int l = a[2] + a[1];     while (n >= 0 && w[n - 1] > l) {       ++ret;       --n;     }     r = l;     l = a[2] + a[0];     memset(used, 0, sizeof(used));     int max_idx = upper_bound(w, w + n, a[0]) - w - 1;     while (n >= 0 && w[n - 1] > l) {       ++ret;       --n;       if (max_idx >= 0) {         used[max_idx--] = true;       }     }     n = rearray(n);     r = l;     l = max(a[2], a[1] + a[0]);     memset(used, 0, sizeof(used));     max_idx = upper_bound(w, w + n, a[1]) - w - 1;     while (n >= 0 && w[n - 1] > l) {       ++ret;       --n;       if (max_idx >= 0) {         used[max_idx--] = true;       }     }     n = rearray(n);     if (a[1] + a[0] > a[2]) {       r = a[1] + a[0];       l = a[2];       memset(used, 0, sizeof(used));       max_idx = upper_bound(w, w + n, a[2]) - w - 1;       while (n >= 0 && w[n - 1] > l) {         ++ret;         --n;         if (max_idx >= 0) {           used[max_idx--] = true;         }       }       n = rearray(n);     }     memset(used, 0, sizeof(used));     int idx_3 = n - 1;     int idx_2 = upper_bound(w, w + n, a[1]) - w;     int idx_1 = upper_bound(w, w + n, a[1]) - w - 1;     int idx_0 = 0;     while (true) {       while (idx_3 >= 0 && used[idx_3]) --idx_3;       if (idx_3 < 0) break;       used[idx_3--] = true;       ++ret;       if (idx_1 >= idx_0) {         while (idx_1 >= idx_0 && used[idx_1]) --idx_1;         if (idx_1 >= idx_0) {           used[idx_1--] = true;         }         while (idx_0 <= idx_1 && w[idx_0] <= a[0] && used[idx_0]) ++idx_0;         if (idx_0 <= idx_1 && w[idx_0] <= a[0]) {           used[idx_0++] = true;         }       } else {         if (!used[idx_2] && w[idx_2] <= a[0] + a[1]) {           used[idx_2++] = true;         }       }     }     return ret;   }   int main() {     ios::sync_with_stdio(false);     cout << fixed << setprecision(8);     cin >> n;     for (int i = 0; i < (3); ++i) {       cin >> a[i];     }     sort(a, a + 3);     for (int i = 0; i < (n); ++i) {       cin >> w[i];     }     sort(w, w + n);     cout << solve() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T gcd(T a, T b) {     if (!b) return a;     while (b ^= a ^= b ^= a %= b)       ;     return a;   }   template <class T>   T max(const T& t1, const T& t2, const T& t3) {     return max(max(t1, t2), t3);   }   template <class T>   T max(const T& t1, const T& t2, const T& t3, const T& t4) {     return max(max(t1, t2), max(t3, t4));   }   long long fpow(long long x, long long y, long long mod = 0x7fffffffffffffffll) {     long long ret = 1;     while (y) {       if (y & 1) ret *= x, ret %= mod;       x *= x;       x %= mod;       y >>= 1;     }     return ret;   }   void ex_gcd(long long a, long long b, long long& x, long long& y) {     if (b == 0) {       x = a;       y = 0;       return;     }     ex_gcd(b, a % b, y, x);     y = y - a / b * x;   }   long long modrev(long long x, long long mod) {     long long x1, x2;     ex_gcd(x, mod, x1, x2);     return x1;   }   unsigned long long T_rand() { return (unsigned long long)(rand()); }   unsigned long long Rand() {     return (T_rand() << 48) | (T_rand() << 32) | (T_rand() << 16) | T_rand();   }   template <class T>   bool PRE_INPUT_INTENGER(T& ret) {     ;     ret = 0;     char c = getchar();     if (c == -1) return 0;     bool f = 0;     while ((c <  0  || c >  9 ) && (c != -1) && (c !=  - )) c = getchar();     if (c ==  - ) {       f = 1;       c = getchar();     }     while (c >=  0  && c <=  9 ) ret *= 10, ret += c -  0 , c = getchar();     if (f) ret = -ret;     if (c == -1) return 0;     return 1;   }   bool input(int& ret) { return PRE_INPUT_INTENGER(ret); }   bool input(long long& ret) { return PRE_INPUT_INTENGER(ret); }   bool input(unsigned long long& ret) { return PRE_INPUT_INTENGER(ret); }   bool input(unsigned int& ret) { return PRE_INPUT_INTENGER(ret); }   template <class T>   bool PRE_INPUT_DOUBLE(T& ret) {     ;     ret = 0;     char c = getchar();     if (c == -1) return 0;     bool f = 0;     while ((c <  0  || c >  9 ) && (c != -1) && (c !=  . ) && (c !=  - ))       c = getchar();     bool isright = 0;     if (c ==  - ) {       f = 1;       c = getchar();     }     T t = 1;     while ((c >=  0  && c <=  9 ) || (c ==  . )) {       if (c ==  . )         isright = 1;       else {         ret *= 10, ret += c -  0 ;         if (isright) t *= 10;       }       c = getchar();     }     ret /= t;     if (f) ret = -ret;     if (c == -1) return 0;     return 1;   }   bool input(double& ret) { return PRE_INPUT_DOUBLE(ret); }   bool input(float& ret) { return PRE_INPUT_DOUBLE(ret); }   bool IS_SPECIAL_CHAR(const char& ret) {     return (ret ==     || ret ==   n  || ret ==   t  || ret ==   r  ||             ret ==   v );   }   bool input(char& ret) {     ;     ret = getchar();     if (ret == -1) return 0;     while (IS_SPECIAL_CHAR(ret)) ret = getchar();     return ~ret;   }   bool input(char* ret) {     ;     char c;     if (!input(c)) return 0;     *ret++ = c;     while (!IS_SPECIAL_CHAR(*(ret - 1))) *ret++ = getchar();     *(ret - 1) = 0;     return 1;   }   template <class T1, class T2>   bool input(T1& t1, T2& t2) {     return input(t1) && input(t2);   }   template <class T1, class T2, class T3>   bool input(T1& t1, T2& t2, T3& t3) {     return input(t1) && input(t2) && input(t3);   }   template <class T1, class T2, class T3, class T4>   bool input(T1& t1, T2& t2, T3& t3, T4& t4) {     return input(t1) && input(t2) && input(t3) && input(t4);   }   template <class T1, class T2, class T3, class T4, class T5>   bool input(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5) {     return input(t1) && input(t2) && input(t3) && input(t4) && input(t5);   }   template <class T>   void input(T* a, int n) {     for (int i = 0; i <= n - 1; i++) input(a[i]);   }   template <class T>   void PRE_OUTPUT_INTENGER(const T& t) {     ;     if (!t) {       putchar( 0 );       return;     }     T key = t;     int tt[25];     if (key < 0) {       putchar( - );       key = -key;     }     int cnt = 0;     while (key) tt[cnt++] = key % 10, key /= 10;     while (cnt) putchar(tt[--cnt] +  0 );     ;   }   void output(const int& t) { PRE_OUTPUT_INTENGER(t); }   void output(const long long& t) { PRE_OUTPUT_INTENGER(t); }   void output(const unsigned long long& t) { PRE_OUTPUT_INTENGER(t); }   void output(const unsigned int& t) { PRE_OUTPUT_INTENGER(t); }   template <class T>   void PRE_OUTPUT_DOUBLE(const T& key) {     ;     printf( %.*f , 6, key);     ;   }   void output(const double& t) { PRE_OUTPUT_DOUBLE(t); }   void output(const float& t) { PRE_OUTPUT_DOUBLE(t); }   void output(const char* ch) {     ;     int cnt = 0;     while (ch[cnt]) putchar(ch[cnt++]);     ;   }   void output(const char& c) {     ;     putchar(c);     ;   }   void output(const string& s) { output(s.c_str()); }   template <class T1, class T2>   void output(const T1& t1, const T2& t2) {     output(t1);     output(t2);   }   template <class T1, class T2, class T3>   void output(const T1& t1, const T2& t2, const T3& t3) {     output(t1);     output(t2);     output(t3);   }   template <class T1, class T2, class T3, class T4>   void output(const T1& t1, const T2& t2, const T3& t3, const T4& t4) {     output(t1);     output(t2);     output(t3);     output(t4);   }   template <class T1, class T2, class T3, class T4, class T5>   void output(const T1& t1, const T2& t2, const T3& t3, const T4& t4,               const T5& t5) {     output(t1);     output(t2);     output(t3);     output(t4);     output(t5);   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void output(const T1& t1, const T2& t2, const T3& t3, const T4& t4,               const T5& t5, const T6& t6) {     output(t1);     output(t2);     output(t3);     output(t4);     output(t5);     output(t6);   }   template <class T1, class T2, class T3, class T4, class T5, class T6, class T7>   void output(const T1& t1, const T2& t2, const T3& t3, const T4& t4,               const T5& t5, const T6& t6, const T7& t7) {     output(t1);     output(t2);     output(t3);     output(t4);     output(t5);     output(t6);     output(t7);   }   template <class T>   void printal(T* a, int n) {     for (int i = 0; i < n - 1; i++) output(a[i],    );     output(a[n - 1],   n );   }   template <class T>   void printel(T* a, int n) {     for (int i = 0; i < n; i++) output(a[i],   n );   }   template <class T>   void inputal(T* a, int n) {     for (int i = 0; i <= n - 1; i++) input(a[i]);   }   const int maxn = 1e5 + 10;   struct Node {     string s;     int cnt;     char last;     bool operator<(const Node& t) const {       if (cnt < t.cnt) return true;       if (last < t.last) return true;       return false;     }     bool operator==(const Node& t) const {       return cnt == t.cnt && last == t.last;     }   };   Node node[maxn];   const char* vowel =  aeiou ;   bool is_vowel(char c) {     switch (c) {       case  a :       case  e :       case  i :       case  o :       case  u :         return true;       default:         return false;     }   }   map<int, map<char, vector<int>>> mp;   int ans[4 * maxn];   int main() {     int n;     input(n);     for (int i = 0; i <= n - 1; i++) {       cin >> node[i].s;       node[i].cnt = 0;       for (const char& c : node[i].s) {         if (is_vowel(c)) {           ++node[i].cnt;           node[i].last = c;         }       }       if (mp.count(node[i].cnt) == 0) {         mp[node[i].cnt] = map<char, vector<int>>();       }       if (mp[node[i].cnt].count(node[i].last) == 0) {         mp[node[i].cnt][node[i].last] = vector<int>();       }       mp[node[i].cnt][node[i].last].push_back(i);     }     vector<pair<int, int>> has_same;     map<int, vector<int>> single;     for (const pair<int, map<char, vector<int>>>& t : mp) {       for (const pair<char, vector<int>>& t2 : t.second) {         for (int i = 0; i < t2.second.size(); i += 2) {           if (i == t2.second.size() - 1) {             if (single.count(t.first) == 0) {               single[t.first] = vector<int>();             }             single[t.first].push_back(t2.second[i]);           } else {             has_same.push_back(make_pair(t2.second[i], t2.second[i + 1]));           }         }       }     }     int cnt = 0;     int last_double_idx = 0;     for (const pair<int, vector<int>>& t : single) {       int last_single_idx = 0;       if (last_double_idx == has_same.size()) break;       while (t.second.size() - last_single_idx > 1) {         if (last_double_idx == has_same.size()) break;         pair<int, int>& cur = has_same[last_double_idx++];         ans[cnt++] = t.second[last_single_idx++];         ans[cnt++] = cur.first;         ans[cnt++] = t.second[last_single_idx++];         ans[cnt++] = cur.second;       }     }     while (last_double_idx + 1 < has_same.size()) {       ans[cnt++] = has_same[last_double_idx].first;       ans[cnt++] = has_same[last_double_idx + 1].first;       ans[cnt++] = has_same[last_double_idx].second;       ans[cnt++] = has_same[last_double_idx + 1].second;       last_double_idx += 2;     }     output(cnt / 4);     putchar(  n );     for (int i = 0; i < cnt; i += 2) {       output(node[ans[i]].s,    , node[ans[i + 1]].s);       putchar(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int a, b, ans = 0;       cin >> a >> b;       ans = min(a, b);       ans = min(ans, (a + b) / 3);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long x;     int c;     friend bool operator<(node x, node y) { return x.x < y.x; }   } a[400001];   long long leftdata[400001], rightdata[400001];   int n;   long long ans;   long long max1, max2, l1, r1, ttt;   void work1() {     long long tans;     l1 = 0;     for (int i = 1; i <= n; ++i)       if (a[i].c == 0) {         tans = ans;         if (l1 != 0) ans += a[i].x - l1;         l1 = a[i].x;       }     l1 = 0;     for (int i = 1; i <= n; ++i)       if (a[i].c == 1) {         tans = ans;         if (l1 != 0) ans += a[i].x - l1;         l1 = a[i].x;       }     cout << ans << endl;   }   void work2() {     long long tans;     long long f1 = 0, f2 = 0;     int sum = 0;     for (int i = 1; i <= n; ++i) {       if (a[i].c == 2) {         max2 = max(a[i].x - r1, max2);         max1 = max(a[i].x - l1, max1);         sum++;         if (sum == 1) {           tans = ans;           if (f1 != 0) ans = ans + a[i].x - f1;           if (f2 != 0) ans = ans + a[i].x - f2;         } else {           long long t1 = a[i].x + a[i].x - ttt - ttt;           long long t2 =               (a[i].x + a[i].x - ttt - ttt) - max1 + (a[i].x - ttt) - max2;           long long yzc = min(t1, t2);           ans = ans + yzc;         }         l1 = r1 = ttt = a[i].x;         max1 = 0;         max2 = 0;       } else if (a[i].c == 0) {         if (f1 == 0) f1 = a[i].x;         if (max1 < a[i].x - l1) max1 = a[i].x - l1;         l1 = a[i].x;       } else {         if (f2 == 0) f2 = a[i].x;         if (max2 < a[i].x - r1) max2 = a[i].x - r1;         r1 = a[i].x;       }     }     f1 = 0;     f2 = 0;     for (int i = n; i >= 1; --i) {       if (a[i].c == 2) {         tans = ans;         if (f1 != 0) ans = ans + f1 - a[i].x;         if (f2 != 0) ans = ans + f2 - a[i].x;         break;       } else if (a[i].c == 0) {         if (f1 == 0) f1 = a[i].x;       } else {         tans = ans;         if (f2 == 0) f2 = a[i].x;       }     }     cout << ans << endl;   }   int main() {     scanf( %d , &n);     char tmp[123];     int sumx = 0;     for (int i = 1; i <= n; ++i) {       long long x;       scanf( %lld , &x);       scanf( %s , tmp);       a[i].x = x;       if (tmp[0] ==  R )         a[i].c = 0;       else if (tmp[0] ==  B )         a[i].c = 1;       else         a[i].c = 2, sumx++;     }     sort(a + 1, a + n + 1);     ans = max1 = max2 = l1 = r1 = ttt = 0;     if (sumx == 0)       work1();     else       work2();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, d, h;   vector<pair<int, int> > ans;   int main() {     ios::sync_with_stdio(0);     cin >> n >> d >> h;     if (2 * h < d || (d == 1 && n > 2)) {       cout << -1 <<   n ;       return 0;     }     for (int i = 2; i <= h + 1; i++) ans.push_back(make_pair(i - 1, i));     int idx = 1;     bool done = false;     for (int i = h + 2; i <= d + 1; i++) {       ans.push_back(make_pair(idx, i));       done = true;       idx = i;     }     if (done)       idx = 1;     else       idx = 2;     for (int i = d + 2; i <= n; i++) ans.push_back(make_pair(idx, i));     for (int i = 0; i < ans.size(); i++)       cout << ans[i].first <<     << ans[i].second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k, n, m, t, l;     cin >> t;     while (t--) {       string s, p, q =  abacaba , r;       cin >> n >> s;       int cnt = 0, cntt = 0;       p = s;       r = s;       for (i = 0; i < n; i++) {         int c = 0;         for (j = i, k = 0; j < i + 7 && j < n; j++) {           if (q[k] == s[j]) {             k++;             c++;           } else {             k = 0;             break;           }         }         if (c == 7) cnt++;         if (s[i] ==  ? ) cntt++;       }       if (cnt > 1)         cout <<  No  << endl;       else if (cntt == 0 && cnt == 0)         cout <<  No  << endl;       else {         int ans = 0;         if (cnt == 0) {           for (i = 0; i + 6 < n; i++) {             bool f = 1;             s = p;             for (j = 0; j < i; j++) {               if (s[j] ==  ? ) s[j] =  x ;             }             for (j = 0; j < 7; j++) {               if (s[j + i] != q[j] && s[j + i] !=  ? ) {                 f = 0;                 break;               } else if (s[j + i] ==  ? )                 s[j + i] = q[j];             }             if (f == 0) continue;             int con = 0;             if (f == 1) {               for (l = 0; l + 6 < n; l++) {                 int ok = 1;                 for (j = 0; j < 7; j++) {                   if (s[j + l] != q[j]) {                     ok = 0;                     break;                   }                 }                 con += ok;               }               if (con == 1) {                 cout <<  Yes  << endl;                 for (i = 0; i < n; i++)                   if (s[i] ==  ? ) s[i] =  x ;                 cout << s << endl;                 ans = 1;                 break;               } else                 continue;             }           }           if (ans == 0) cout <<  No  << endl;         } else if (cnt == 1) {           for (i = 0; i < n; i++) {             if (s[i] ==  ? ) s[i] =  x ;           }           cout <<  Yes  << endl;           cout << s << endl;         } else           cout <<  No  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long d, n, m;     cin >> d >> n >> m;     vector<pair<long long, long long>> V(m);     for (auto &x : V) cin >> x.first >> x.second;     sort(V.begin(), V.end());     bool poss = true;     for (int i = 0; i < V.size() - 1; i++)       poss = poss && V[i].first + n >= V[i + 1].first;     poss = poss && V[0].first <= n;     poss = poss && d - V.back().first <= n;     if (!poss) {       printf( -1 n );       return 0;     }     sort(V.begin(), V.end(),          [](pair<long long, long long> a, pair<long long, long long> b) {            return a.second < b.second;          });     set<int> pos;     pos.insert(0);     pos.insert(d);     long long ans = 0;     for (auto &x : V) {       auto aft = pos.lower_bound(x.first);       auto bef = prev(aft);       long long reach = max(0ll, n - (x.first - *bef));       long long leave = min(n, *aft - x.first);       ans += x.second * max(0ll, leave - reach);       pos.insert(x.first);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 3e5, N = 2e6 + 90, SQ = 300, base = 1999, mod = 1e9 + 7,                   INF = 1e9 + 1, lg = 30;   const long double eps = 1e-4;   long long n, a[maxn], b[maxn], c[maxn], d[maxn], cnt[maxn], s1, s2, tot;   inline bool check() {     for (long long i = 0; i < n; ++i) {       for (long long j = 0; j < lg; ++j) {         if (a[i] & (1ll << j)) {           cnt[j]++;         }       }     }     for (long long i = 0; i < n; ++i) {       long long res1 = 0, res2 = 0;       for (long long j = 0; j < lg; ++j) {         if (a[i] & (1ll << j)) {           res1 += (cnt[j] * (1ll << j));           res2 += (n - cnt[j]) * (1ll << j);         }         res2 += (cnt[j] * (1ll << j));       }       if (res1 != b[i] || res2 != c[i]) {         return 0;       }     }     return 1;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long i = 0; i < n; ++i) {       cin >> b[i];       s1 += b[i];     }     for (long long i = 0; i < n; ++i) {       cin >> c[i];       s2 += c[i];     }     if ((s1 + s2) % (2 * n) != 0) {       cout << -1 <<   n ;       return 0;     }     tot = (s1 + s2) / (2 * n);     for (long long i = 0; i < n; ++i) {       d[i] = b[i] + c[i];     }     for (long long i = 0; i < n; ++i) {       a[i] = (d[i] - tot) / n;     }     if (check()) {       for (long long i = 0; i < n; ++i) {         cout << a[i] <<    ;       }       cout <<   n ;     } else {       cout << -1 <<   n ;     }   }


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


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


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     int sum = 0;     vector<int> a(n);     map<int, int> c;     c[0] = 1;     bool fl = 0;     long long ans = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > m) sum++;       if (a[i] < m) sum--;       if (a[i] == m) fl = 1;       if (fl)         ans += c[sum] + c[sum - 1];       else         c[sum]++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 3;   bool in[113];   bool odw[113];   bool prze[113];   vector<int> v[113];   string tab[MAXN];   vector<char> ans;   bool por = false;   void DFS(int x) {     prze[x] = true;     odw[x] = true;     for (auto it : v[x]) {       if (prze[it])         por = true;       else if (!odw[it])         DFS(it);     }     ans.push_back(char(x +  a ));     prze[x] = false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, k, p;     bool check;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> p;       for (int j = 0; j < k; j++) {         cin >> tab[p * k + j];         for (auto &it : tab[p * k + j]) in[it -  a ] = true;       }     }     for (int i = 1; i < n * k; i++) {       check = false;       for (unsigned int j = 0; j < min(tab[i].size(), tab[i - 1].size()); j++) {         if (tab[i][j] != tab[i - 1][j]) {           check = true;           v[tab[i - 1][j] -  a ].push_back(tab[i][j] -  a );           break;         }       }       if (!check && tab[i - 1].size() > tab[i].size()) por = true;     }     for (int i = 0; i < 26; i++) {       if (!odw[i] && in[i]) DFS(i);     }     if (por)       cout <<  IMPOSSIBLE ;     else {       for (int i = (int)(ans.size()) - 1; i >= 0; i--) cout << ans[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 200005;   int n, m;   long long ans[Maxn];   struct Segment {     long long l, r;     int pos;   } A[Maxn], land[Maxn];   bool cmp(const Segment &a, const Segment &b) {     return a.l < b.l || a.l == b.l && a.r < b.r;   }   struct node {     int pos;     long long val;     node() {}     node(int _pos, long long _val) {       pos = _pos;       val = _val;     }   } p[Maxn];   bool operator<(node a, node b) { return a.val > b.val; }   bool cmp2(const node &a, const node &b) { return a.val < b.val; }   priority_queue<node> H;   int Get() {     char ch;     int v = 0;     bool f = false;     while (!isdigit(ch = getchar()))       if (ch ==  - ) f = true;     v = ch - 48;     while (isdigit(ch = getchar())) v = v * 10 + ch - 48;     if (f)       return -v;     else       return v;   }   int main() {     n = Get(), m = Get();     for (int i = 1; i <= n; i++) scanf( %I64d%I64d , &land[i].l, &land[i].r);     for (int i = 1; i <= m; i++) scanf( %I64d , &p[i].val), p[i].pos = i;     for (int i = 1; i <= n - 1; i++)       A[i].l = land[i + 1].l - land[i].r, A[i].r = land[i + 1].r - land[i].l,       A[i].pos = i;     n--;     sort(A + 1, A + 1 + n, cmp);     sort(p + 1, p + 1 + m, cmp2);     if (m < n) {       puts( No );       return 0;     }     long long mx = 0;     for (int i = 1, j = 1; i <= m; i++) {       while (A[j].l <= p[i].val && j <= n) H.push(node(A[j].pos, A[j].r)), j++;       while (!H.empty() && H.top().val < p[i].val) H.pop();       if (!H.empty()) {         node tmp = H.top();         ans[tmp.pos] = p[i].pos;         H.pop();       }     }     bool flag = true;     for (int i = 1; i <= n; i++)       if (ans[i] == 0) flag = false;     if (flag) {       puts( Yes );       for (int i = 1; i <= n - 1; i++) printf( %d  , ans[i]);       printf( %d n , ans[n]);     } else       puts( No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x, k, n, q, cnt;   long long num[10];   int bel[1 << 10];   struct Square {     long long num[75][75];     Square() {       for (int i = 1; i <= 70; i++) {         for (int j = 1; j <= 70; j++) num[i][j] = 1e18;         num[i][i] = 0;       }     }     Square operator*(const Square &a) const {       Square tmp;       for (int i = 1; i <= cnt; i++) tmp.num[i][i] = 1e18;       for (int i = 1; i <= cnt; i++)         for (int j = 1; j <= cnt; j++)           for (int k = 1; k <= cnt; k++)             tmp.num[i][j] = tmp.num[i][j] < (num[i][k] + a.num[k][j])                                 ? tmp.num[i][j]                                 : (num[i][k] + a.num[k][j]);       return tmp;     }     Square operator^(const int &x) {       if (!x) return Square();       Square tmp, tmp1;       int times = x;       for (int i = 1; i <= cnt; i++)         for (int j = 1; j <= cnt; j++) tmp1.num[i][j] = num[i][j];       while (times) {         if (times & 1) tmp = tmp * tmp1;         times >>= 1;         tmp1 = tmp1 * tmp1;       }       return tmp;     }   } one;   struct Stone {     int place;     long long val;   } stone[30];   bool calc(int tmp) {     int many = 0;     for (int i = 1; i <= 8; i++)       if (tmp & (1 << (i - 1))) many++;     return many == x;   }   bool cmp(Stone a, Stone b) { return a.place < b.place; }   int main() {     scanf( %d%d%d%d , &x, &k, &n, &q);     for (int i = 0; i <= (1 << k) - 1; i++)       if (calc(i)) bel[i] = ++cnt;     for (int i = 1; i <= k; i++) scanf( %lld , &num[i]);     for (int i = 1; i <= q; i++) scanf( %d%lld , &stone[i].place, &stone[i].val);     sort(stone + 1, stone + q + 1, cmp);     for (int i = 1; i <= cnt; i++) one.num[i][i] = 1e18;     for (int i = 1; i <= (1 << k) - 1; i++) {       if (i & 1) {         if (!bel[i]) continue;         for (int j = 1; j <= k; j++)           if (!((1 << j) & i)) one.num[bel[i]][bel[((1 << j) | i) >> 1]] = num[j];       } else if (bel[i])         one.num[bel[i]][bel[i >> 1]] = 0;     }     int now = 1;     long long sum = 0;     Square ans;     for (int i = 1; i <= q; i++) {       if (stone[i].place > n - x) {         sum += stone[i].val;         continue;       }       ans = ans * (one ^ (stone[i].place - now)), now = stone[i].place;       for (int j = 1; j <= (1 << k) - 1; j += 2)         if (bel[j])           for (int k = 1; k <= cnt; k++) ans.num[k][bel[j]] += stone[i].val;     }     ans = ans * (one ^ (n - x + 1 - now));     printf( %lld , ans.num[1][1] + sum);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 110;   int a[N * N], n, T, dp[N * N], rec[305];   int cal(int x) {     int m = n * x, len = 0;     for (int i = 1; i <= m; i++) {       if (a[i] >= dp[len])         dp[++len] = a[i];       else {         int pos = upper_bound(dp + 1, dp + len + 1, a[i]) - dp;         dp[pos] = a[i];       }     }     return len;   }   int main() {     scanf( %d%d , &n, &T);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i < n; i++) {       for (int j = 1; j <= n; j++) {         a[i * n + j] = a[j];       }     }     if (T <= n)       printf( %d n , cal(T));     else {       memset(rec, 0, sizeof(rec));       for (int i = 1; i <= n; i++) ++rec[a[i]];       int tmp = 0;       for (int i = 1; i <= n; i++) tmp = max(tmp, rec[a[i]]);       int ans = tmp * (T - n) + cal(n);       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int r = 0;     int rr = 0;     int prev = 10000;     while (n--) {       int a, b;       cin >> a >> b;       if (a != b)         r = 1;       else {         if (a > prev) rr = 1;       }       prev = a;     }     if (r == 1)       cout <<  rated  << endl;     else {       if (rr == 0)         cout <<  maybe  << endl;       else         cout <<  unrated  << endl;     }     return 0;   }


#include <bits/stdc++.h>      using namespace std;   typedef long long ll;   #define endl   n    #define x1 fgdfgdg   const ll DIM = 2E5+7;   ll A[DIM];   ll GCD(ll a,ll b){       if (a==0 || b==0)return a+b;       return GCD(b%a,a);   }   int main() {       ios_base::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);       ll n,m;       cin>>n>>m;       for(ll i = 1;i<=n;++i){           cin>>A[i];       }       sort(A+1,A+1+n);       ll gcd = A[2]-A[1];       for(ll i = 2;i<=n;++i){           if (i==2)gcd = A[i]-A[i-1];           else gcd = GCD(A[i]-A[i-1],gcd);       }       for(ll i = 1;i<=m;++i){           ll x;           cin>>x;           if (n!=1)           cout<<GCD(A[1]+x,gcd)<<   ;           else cout<<A[1]+x<<   ;       }       cout<<endl;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int k, d;   string a, b =  CODEFORCES ;   int main() {     cin >> a;     if (a == b) {       cout <<  YES n ;       return 0;     }     for (int i = 0; i < a.size(); i++) {       for (int j = i; j < a.size(); j++) {         string h;         for (int l = 0; l < i; l++) h += a[l];         for (int l = j + 1; l < a.size(); l++) h += a[l];         if (h == b) k = 1;       }     }     if (k == 1)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   struct node {     int x, flag;   } a[2 * N];   bool cmp(const node a, const node b) {     if (a.x == b.x)       return a.flag > b.flag;     else       return a.x < b.x;   }   vector<pair<int, int> > ans;   int main(void) {     int n, k, l, r;     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d%d , &l, &r);       a[2 * i].x = l;       a[2 * i].flag = 1;       a[2 * i + 1].x = r;       a[2 * i + 1].flag = -1;     }     n *= 2;     sort(a, a + n, cmp);     for (int i = 1; i < n; i++) a[i].flag += a[i - 1].flag;     for (int i = 0; i < n; i++) {       int cnt = 0;       if (a[i].flag >= k) {         l = a[i].x;         while (i < n && a[i].flag >= k) i++;         r = a[i].x;         ans.push_back(make_pair(l, r));       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++)       cout << ans[i].first <<     << ans[i].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long prime[2000006];   int main() {     long long i, j;     prime[1] = 1;     for (i = 2; i < 2000006; i++) {       for (j = 2 * i; j < 2000006; j += i) prime[j] = 1;     }     long long n;     cin >> n;     long long a[n], co = 0;     for (i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 1) co++;     }     if (co > 1) {       for (i = 0; i < n; i++) {         if (prime[a[i] + 1] == 0 && a[i] > 1) {           cout << co + 1 << endl << a[i] <<    ;           for (j = 0; j < co; j++) cout << 1 <<    ;           return 0;         }       }       cout << co << endl;       for (i = 0; i < co; i++) cout << 1 <<    ;       return 0;     }     for (i = 0; i < n; i++) {       for (j = i + 1; j < n; j++) {         if (prime[a[i] + a[j]] == 0) {           cout << 2 << endl;           cout << a[i] <<     << a[j];           return 0;         }       }     }     cout << 1 << endl << a[0];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-6;   const double PI = acos(-1);   const int INF = 1e9;   void FAST() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   }   signed main() {     FAST();     int n;     cin >> n;     vector<long long> a(n + n);     for (int i = 0; i < n + n; i++) {       cin >> a[i];     }     sort(a.begin(), a.end());     long long ans = (a[n - 1] - a[0]) * (a[n + n - 1] - a[n]);     for (int i = 1; i < n; i++) {       ans = min(ans, (a[n - 1 + i] - a[i]) * (a[n + n - 1] - a[0]));     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j, first, end, count = 0;     cin >> n >> m;     vector<int> a(m + 1, 0);     for (i = 0; i < n; i++) {       cin >> first >> end;       for (j = first; j <= end; j++) a[j] = 1;     }     for (i = 1; i < m + 1; i++) {       if (a[i] == 0) count++;     }     cout << count << endl;     for (i = 1; i < m + 1; i++) {       if (a[i] == 0) cout << i <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void swap(int& a, int& b) {     int tmp;     tmp = a;     a = b;     b = tmp;   }   void QuickSort(int l, int h, int a[], int b[]) {     int i = l, j = h;     int pivot = a[l + rand() % (h - l + 1)];     while (i <= j) {       while (a[i] < pivot) i++;       while (a[j] > pivot) j--;       if (i <= j) {         swap(a[i], a[j]);         swap(b[i], b[j]);         i++;         j--;       }     }     if (l < j) QuickSort(l, j, a, b);     if (i < h) QuickSort(i, h, a, b);   }   int main() {     int n, r, avg;     long long s = 0;     cin >> n >> r >> avg;     int b[n + 1], a[n + 1];     for (int i = 1; i <= n; i++) {       cin >> a[i] >> b[i];       s += (long long)a[i];     }     long long d = (long long)n * avg - s;     if (d <= 0) {       cout << 0;       return 0;     }     QuickSort(1, n, b, a);     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (d >= r - a[i]) {         ans += (long long)(r - a[i]) * b[i];         d -= r - a[i];         if (!d) break;       } else {         ans += (long long)d * b[i];         break;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     set<int> s;     long long int n, m, k, a;     cin >> n >> m;     while (n--) {       cin >> k;       while (k--) {         cin >> a;         s.insert(a);       }     }     if (s.size() == m) {       cout <<  YES             <<   n ;     } else {       cout <<  NO             <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, q;   pair<int, bool> a[400100];   int dsu[200100];   pair<int, int> query[200100];   long long ans[200100];   int last[200100];   long long prsum[400100];   int f(int x) {     if (dsu[x] < 0) return x;     int r = f(dsu[x]);     dsu[x] = r;     return r;   }   void join(int x, int y) {     int r1 = f(x);     int r2 = f(y);     if (r1 != r2) {       if (dsu[r1] > dsu[r2]) swap(r1, r2);       last[r1] = max(last[r1], last[r2]);       dsu[r1] += dsu[r2];       dsu[r2] = r1;     }   }   priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>,                  greater<pair<int, pair<int, int>>>>       pq;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long sum = 0;     cin >> n >> m >> q;     for (int i = 1; i <= n; i++) {       cin >> a[i].first;       sum += a[i].first;       a[i].second = 1;     }     for (int i = 1; i <= m; i++) {       cin >> a[i + n].first;       a[i + n].second = 0;     }     sort(a + 1, a + 1 + n + m);     for (int i = 0; i <= n + 10; i++) {       dsu[i] = -1;     }     int cur = 1;     for (int i = 1; i <= n + m; i++) {       if (a[i].second == 1) {         if (i < n + m) pq.push({a[i + 1].first - a[i].first, {i, cur}});         last[cur] = i;         cur++;       }     }     for (int i = 0; i < q; i++) {       cin >> query[i].first;       query[i].second = i;     }     sort(query, query + q);     for (int i = 1; i <= n + m; i++) {       prsum[i] = prsum[i - 1] + a[i].first;     }     for (int i = 0; i < q; i++) {       int v = query[i].first;       while (!pq.empty() && v >= pq.top().first) {         pair<int, int> tmp = pq.top().second;         pq.pop();         if (a[tmp.first + 1].second == 1) {           int r1 = f(tmp.second);           int r2 = f(tmp.second + 1);           sum += prsum[last[r2] + dsu[r2]] - prsum[last[r2] + dsu[r2] + dsu[r1]];           sum -= prsum[last[r1]] - prsum[last[r1] + dsu[r1]];           join(tmp.second, tmp.second + 1);         } else if (tmp.first + 1 == n + m) {           sum += a[tmp.first + 1].first -                  a[tmp.first + dsu[f(tmp.second)] + 1].first;           last[f(tmp.second)]++;         } else {           pq.push({a[tmp.first + 2].first - a[tmp.first + 1].first,                    {tmp.first + 1, tmp.second}});           sum += a[tmp.first + 1].first -                  a[tmp.first + dsu[f(tmp.second)] + 1].first;           last[f(tmp.second)]++;         }       }       ans[query[i].second] = sum;     }     for (int i = 0; i < q; i++) {       cout << ans[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   const int maxi = 2000000000;   const int maxq = 1000000000;   const double eps = 1e-10;   const double pi = 3.1415926535897932;   const double inf = 1e+18;   const int mo = 1000000007;   using namespace std;   long long l, r;   int main() {     cin >> l >> r;     if (l == r) {       puts( 0 );       return 0;     }     for (int i = 62; i >= 0; i--) {       if ((1ll << (i)) > l && (1ll << (i)) <= r) {         cout << (1ll << (i + 1)) - 1 << endl;         return 0;       }       if ((1ll << (i)) <= l) {         l -= (1ll << (i));         r -= (1ll << (i));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double PI = 3.1415926535897932384626433;   double DP[(1 << 20)];   vector<double> fx, fy, lg;   double calc(double px, double py, double t, double al) {     double d = sqrt((px - t) * (px - t) + py * py);     double sina = sin(al * (PI / 180.0));     double sinb = fabs(py) / d;     double bt = asin(sinb) * (180.0 / PI);     if (px < t) bt = 180 - bt;     if (al + bt >= 180) return t + 300000.0;     double gm = 180 - bt - al;     double sinc = sin(gm * (PI / 180.0));     return t + (sina * (d / sinc));   }   int main() {     int i, mask, n, l, r, cr;     cin >> n >> l >> r;     int xx, yy, al;     double cl = l;     bool hasp = false;     for (i = 0; i < n; ++i) {       cin >> xx >> yy >> al;       if (yy == 0) {         if (hasp || xx >= r || xx <= l) {           cout << r - l <<   n ;           return 0;         }         hasp = true;         cl = xx;       } else {         fx.push_back(xx);         fy.push_back(yy);         lg.push_back(al);       }     }     n = fx.size();     DP[0] = cl;     for (mask = 1; mask < (1 << n); ++mask) {       DP[mask] = cl;       for (i = 0; i < n; ++i) {         if (mask & (1 << i)) {           cr = mask - (1 << i);           DP[mask] = max(DP[mask], calc(fx[i], fy[i], DP[cr], lg[i]));         }       }     }     printf( %.8lf n , min((double)r, DP[(1 << n) - 1]) - l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n + 1];     vector<int> v;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] == 1) {         v.push_back(1);       } else {         v[v.size() - 1] = max(arr[i], v[v.size() - 1]);       }     }     cout << v.size() << endl;     for (int i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i;   int main() {     string s;     cin >> s;     int k;     i = 0;     while (s[i] ==  0 ) {       i++;     }     int f = 0, v = 0;     bool b = false;     while (i != s.size()) {       if (s[i] ==  4 )         f++;       else if (s[i] ==  7 )         v++;       i++;     }     if (b)       cout << -1;     else {       if (f != 0 && f == v)         cout << 4;       else if (f > v)         cout << 4;       else if (v > f)         cout << 7;       else         cout << -1;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   struct node {     int sz;     vector<int> m, M;     node() {       sz = 1;       for (int i = 0; i < k; ++i) {         int tmp;         scanf( %d , &tmp);         m.push_back(tmp);         M.push_back(tmp);       }     }     bool operator<(const node &nd) const {       for (int i = 0; i < k; ++i) {         if (M[i] > nd.m[i]) return false;       }       return true;     }     void merge(const node &nd) {       for (int i = 0; i < k; ++i) {         m[i] = min(m[i], nd.m[i]);         M[i] = max(M[i], nd.M[i]);       }       sz += nd.sz;     }   };   set<node> st;   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; ++i) {       node nd = node();       auto lb = st.lower_bound(nd), ub = st.upper_bound(nd);       while (lb != ub) {         nd.merge(*lb);         lb = st.erase(lb);       }       st.insert(nd);       printf( %d n , (st.rbegin())->sz);     }     return 0;   }