#include <bits/stdc++.h>   using namespace std;   const int inf = 1012345678;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(false);     int N, Q;     cin >> N >> Q;     vector<vector<int> > g(N);     int limit = 0;     for (int i = 0; i < N; ++i) {       int x, rad = 1;       cin >> x;       for (int j = 2; j * j <= x; ++j) {         int cnt = 0;         while (x % j == 0) x /= j, cnt ^= 1;         if (cnt == 1) g[i].push_back(j), rad *= j;       }       if (x > 1) g[i].push_back(x), rad *= x;       limit = max(limit, rad);     }     vector<vector<pair<int, int> > > qs(N + 1);     for (int i = 0; i < Q; ++i) {       int L, R;       cin >> L >> R;       --L;       qs[R].push_back(make_pair(L, i));     }     vector<vector<int> > curopt(limit + 1, vector<int>(8, -inf));     vector<int> curbound(15, -inf);     vector<int> ans(Q);     for (int i = 0; i < N; ++i) {       for (int j = 0; j < 1 << g[i].size(); ++j) {         int rem = 0, mul = 1;         for (int k = 0; k < g[i].size(); ++k) {           if ((j >> k) & 1)             mul *= g[i][k];           else             ++rem;         }         for (int k = 0; k <= 7; ++k) {           curbound[rem + k] = max(curbound[rem + k], curopt[mul][k]);         }         curopt[mul][rem] = i;       }       for (pair<int, int> j : qs[i + 1]) {         for (int k = 0; k <= 14; ++k) {           if (curbound[k] >= j.first) {             ans[j.second] = k;             break;           }         }       }     }     for (int i = 0; i < Q; ++i) {       cout << ans[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   const int maxn = 1e5 + 3;   int terminal[maxn];   struct spe {     int next, to;   };   spe edge[maxn << 1];   int head[maxn];   int visit[maxn][3];   int cnt = 1, tpoint = -1;   int nxt[maxn][2];   bool dp[maxn][3];   int cir = 0;   bool dfs(int s, int val) {     if (terminal[s] == 1) {       tpoint = s;       return val == 1;     }     if (visit[s][val] == 2) return dp[s][val];     bool temp = false;     visit[s][val] = 1;     for (int i = head[s]; i != -1; i = edge[i].next) {       int t = edge[i].to;       if (visit[t][!val] == 1) {         cir = 1;         continue;       }       if (dfs(t, !val) == true) {         nxt[s][val] = t;         temp = true;       }     }     visit[s][val] = 2;     dp[s][val] = temp;     return temp;   }   int main() {     memset(dp, 0, sizeof dp);     memset(visit, 0, sizeof visit);     memset(head, -1, sizeof head);     memset(edge, 0, sizeof edge);     memset(terminal, 0, sizeof terminal);     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++)       for (int j = 0; j <= 1; j++) nxt[i][j] = i;     int counter = 0;     for (int i = 1; i <= n; i++) {       int k, item;       scanf( %d , &k);       if (k == 0) counter++, terminal[i] = 1;       while (k--) {         scanf( %d , &item);         edge[cnt].to = item;         edge[cnt].next = head[i];         head[i] = cnt++;       }     }     int start;     scanf( %d , &start);     bool ans = dfs(start, 0);     if (ans == true) {       printf( Win n );       int j = 0;       printf( %d , start);       while (nxt[start][j] != start) {         start = nxt[start][j];         j = !j;         printf(  %d , start);       }       printf(  n );     } else if (cir == 1)       printf( Draw n );     else       printf( Lose n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100;   const int maxm = 100;   const int maxlen = maxn + maxm - 1;   struct point {     int ind, p;     bool operator<(const point& b) const { return p < b.p; }   } cell[maxlen];   char state[maxlen];   int n, m;   long long k;   int p;   long long dp[maxlen][maxlen];   long long Cnt() {     memset(dp, 0, sizeof(dp));     if (state[0] ==  ) ) return 0;     dp[0][1] = 1;     for (int i = 1; i <= (n - 1) + (m - 1); ++i) {       for (int j = 0; j <= (n - 1) + (m - 1); ++j) {         if (state[i] == 0) {           if (j > 0) dp[i][j] = dp[i - 1][j - 1];           dp[i][j] += dp[i - 1][j + 1];         } else if (state[i] ==  ( ) {           if (j > 0) dp[i][j] = dp[i - 1][j - 1];         } else           dp[i][j] = dp[i - 1][j + 1];         if (dp[i][j] > k) dp[i][j] = k + 1;       }     }     return dp[(n - 1) + (m - 1)][0];   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m >> k;     for (int i = 0; i <= (n - 1) + (m - 1); ++i)       cell[i].ind = i, cell[i].p = n * m + 1;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         cin >> p;         cell[i + j].p = min(cell[i + j].p, p);       }     sort(cell, cell + n + m - 1);     for (int i = 0; i <= (n - 1) + (m - 1); ++i) {       state[cell[i].ind] =  ( ;       long long num = Cnt();       if (num < k) {         k -= num;         state[cell[i].ind] =  ) ;       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) cout << state[i + j];       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, z, a, b;     cin >> x >> y >> z;     a = max(x, y);     b = min(x, y);     if (b + z < a || z == 0) {       if (x > y)         cout <<  + ;       else if (x < y)         cout <<  - ;       else         cout <<  0 ;     } else if (b + z >= a)       cout <<  ? ;   }


#include <bits/stdc++.h>   const int mod = 1000000007, hmod = 10000019;   int n, a[1000010], p[1000010], f[1000010];   long long sz[1000010];   int g[1000010];   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , a + i), sz[i] = a[i];     for (int i = 2; i <= n; i++) scanf( %d , p + i);     for (int i = n; i > 1; i--) sz[p[i]] += sz[i];     for (int i = 1; i <= n; i++) {       long long j = sz[1] / gcd(sz[1], sz[i]);       if (j <= n) g[j]++;     }     for (int i = n; i; i--)       for (int j = i * 2; j <= n; j += i) g[j] += g[i];     for (int i = n; i >= 1; i--)       if (g[i] >= i) {         f[i] = 1;         for (int j = i * 2; j <= n; j += i) (f[i] += f[j]) %= mod;       }     printf( %d n , f[1]);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &val) {     val = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       val = (val << 3) + (val << 1) + (c ^ 48);       c = getchar();     }     val *= f;   }   template <typename T>   void write_(T val) {     if (!val) return;     write_(val / 10);     putchar(val % 10 + 48);   }   template <typename T>   inline void write(T val) {     if (val == 0)       putchar(48);     else if (val < 0) {       putchar( - );       write_(-val);     } else       write_(val);   }   const int N = 4e5 + 5;   struct segment {     long long l, r;   } s[N];   int n;   long long ans0, ans1, tmp[N << 1], d_[N << 2], d[N << 2];   int main() {     ios::sync_with_stdio(false);     int T;     cin >> T;     while (T--) {       ans0 = 0;       ans1 = INT_MIN;       cin >> n;       for (register int i = 1; i <= n; i++) {         cin >> s[i].l >> s[i].r;         tmp[(i << 1) - 1] = s[i].l;         tmp[i << 1] = s[i].r;       }       sort(tmp + 1, tmp + (n << 1) + 1);       int tot = unique(tmp + 1, tmp + (n << 1) + 1) - tmp - 1;       for (register int i = 1; i <= n; i++) {         s[i].l = lower_bound(tmp + 1, tmp + tot + 1, s[i].l) - tmp;         s[i].r = lower_bound(tmp + 1, tmp + tot + 1, s[i].r) - tmp;         s[i].l <<= 1LL;         s[i].r <<= 1LL;         d[s[i].l]++;         d[s[i].r + 1]--;       }       tot <<= 1LL;       for (register long long i = 1; i <= tot + 5; i++) d[i] += d[i - 1];       for (register long long i = 0; i <= tot + 5; i++) ans0 += d[i] && !d[i + 1];       for (register long long i = 0; i <= tot + 4; i++)         if (d[i] == 1 && d[i + 1] != 1) d_[i]++;       for (register long long i = 1; i <= tot + 5; i++)         if (d[i] == 1 && d[i - 1] != 1) d_[i]++;       for (register long long i = 1; i <= tot + 5; i++) d_[i] += d_[i - 1];       for (register int i = 1; i <= n; i++) {         long long t = d_[s[i].r] - d_[s[i].l - 1];         t /= 2;         t -= (d[s[i].r] == 1) + (d[s[i].l] == 1);         ans1 = max(ans1, t);       }       cout << ans0 + ans1 << endl;       for (register long long i = 0; i <= tot + 10; i++) d[i] = d_[i] = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + (c ^ 48);       c = getchar();     }     return f == 1 ? x : -x;   }   const int N = 3e5 + 4;   long long ans = 0;   int n, a[N], mx[N], mn[N], cnt[N << 1];   inline void solve(int l, int r) {     if (l == r) return ++ans, void();     int mid = l + r >> 1;     mx[mid] = mn[mid] = a[mid];     mx[mid + 1] = mn[mid + 1] = a[mid + 1];     for (int i = mid + 2; i <= r; i++) {       mx[i] = (mx[i - 1] > a[i] ? mx[i - 1] : a[i]);       mn[i] = (mn[i - 1] > a[i] ? a[i] : mn[i - 1]);     }     for (int i = mid - 1; i >= l; i--) {       mx[i] = (mx[i + 1] > a[i] ? mx[i + 1] : a[i]);       mn[i] = (mn[i + 1] > a[i] ? a[i] : mn[i + 1]);     }     int ll = mid, rr = mid;     for (int i = mid + 1, x; i <= r; i++) {       x = i - mx[i] + mn[i];       if (x >= l && x <= mid && mx[x] < mx[i] && mn[x] > mn[i]) ans++;       while (ll >= l && mx[ll] < mx[i]) {         cnt[N + mn[ll] - ll]++;         ll--;       }       while (rr > ll && mn[rr] > mn[i]) {         cnt[N + mn[rr] - rr]--;         rr--;       }       ans += cnt[N + mx[i] - i];     }     while (rr != ll) {       cnt[N + mn[rr] - rr]--;       rr--;     }     ll = rr = mid + 1;     for (int i = mid, x; i >= l; i--) {       x = mx[i] - mn[i] + i;       if (x > mid && x <= r && mx[x] < mx[i] && mn[x] > mn[i]) ans++;       while (rr <= r && mx[rr] < mx[i]) {         cnt[mn[rr] + rr]++;         rr++;       }       while (ll < rr && mn[ll] > mn[i]) {         cnt[mn[ll] + ll]--;         ll++;       }       ans += cnt[mx[i] + i];     }     while (ll != rr) {       cnt[mn[ll] + ll]--;       ll++;     }     solve(l, mid);     solve(mid + 1, r);   }   int main() {     n = read();     for (int i = 1, u, v; i <= n; i++) {       u = read();       v = read();       a[u] = v;     }     solve(1, n);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     long long ans = (6 * (1LL * n * (n + 1)) / 2);     printf( %I64d n , ans + 1);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, num, sum = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> num;       sum += num;     }     num = 0;     for (int i = sum + 1; i < sum + 6; i++) {       if (i % (n + 1) != 1) num++;     }     cout << num;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, m, cnt, xmin, xmax, ymin, ymax, head, tail, g[250 + 2][250 + 2],       f[250 + 2][250 + 2], qx[250 * 250], qy[250 * 250];   bool checkType1() {     if (tail != 4 * (xmax - xmin)) return false;     for (int i = xmin; i <= xmax; ++i) {       if (f[i][ymin] != cnt) return false;       if (f[i][ymax] != cnt) return false;     }     for (int j = ymin; j <= ymax; ++j) {       if (f[xmin][j] != cnt) return false;       if (f[xmax][j] != cnt) return false;     }     return true;   }   bool checkType2() {     if ((xmin + xmax) % 2 || (ymin + ymax) % 2) return false;     int xmid = (xmax + xmin) / 2, ymid = (ymax + ymin) / 2,         rang = (xmax - xmin) / 2;     if (tail != 4 * rang) return false;     for (int x = 0; x <= rang; ++x) {       int y = rang - x;       if (f[xmid - x][ymid - y] != cnt) return false;       if (f[xmid - x][ymid + y] != cnt) return false;       if (f[xmid + x][ymid - y] != cnt) return false;       if (f[xmid + x][ymid + y] != cnt) return false;     }     return true;   }   int main() {     for (scanf( %d , &t); t; --t) {       scanf( %d%d , &n, &m);       memset(g, 0, sizeof(g));       memset(f, 0, sizeof(f));       for (int i = 1; i <= n; ++i) {         char b[250];         scanf( %s , b);         for (int j = 1; j <= m; ++j) g[i][j] = b[j - 1] -  0 ;       }       int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1},           dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1}, ans = cnt = 0;       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= m; ++j)           if (g[i][j] && !f[i][j]) {             f[i][j] = ++cnt;             head = tail = 0;             xmin = xmax = i;             ymin = ymax = j;             qx[tail] = i;             qy[tail] = j;             tail++;             while (head != tail) {               for (int k = 0; k != 8; ++k) {                 int xx = qx[head] + dx[k], yy = qy[head] + dy[k];                 if (g[xx][yy] && !f[xx][yy]) {                   f[xx][yy] = cnt;                   if (xx < xmin) xmin = xx;                   if (xx > xmax) xmax = xx;                   if (yy < ymin) ymin = yy;                   if (yy > ymax) ymax = yy;                   qx[tail] = xx;                   qy[tail] = yy;                   tail++;                 }               }               head++;             }             if (tail <= 1 || xmax - xmin != ymax - ymin) continue;             if (checkType1() || checkType2()) ans++;           }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<pair<long long, long long> > st;   map<long long, long long> tp;   long long ans[100013];   int main() {     long long n, k;     cin >> n >> k;     vector<pair<long long, long long> > v(n);     for (int i = 0; i < n; i++) {       cin >> v[i].first;       v[i].first = -v[i].first;       tp[v[i].first] = i;     }     for (int i = 0; i < n; i++) {       cin >> v[i].second;       v[i].second = -v[i].second;       st.insert({v[i].second, v[i].first});     }     sort(v.begin(), v.end());     for (int i = 0; i < n; i++) {       long long an = -v[i].second, j = 0;       for (auto it = st.begin(); it != st.end() && j < k; it++, j++) {         if (it->second == v[i].first) {           j--;           continue;         } else           an += (-(it->first));       }       st.erase(st.find({v[i].second, v[i].first}));       ans[tp[v[i].first]] = an;     }     for (int i = 0; i < n; i++) {       cout << ans[i] <<    ;     }     return 0;   }


#include<bits/stdc++.h> /*   #include <ext/pb_ds/assoc_container.hpp> // Common file   #include <ext/pb_ds/tree_policy.hpp> // Including */   using namespace std;   //using namespace __gnu_pbds;      //typedefs      typedef long long ll;   typedef vector<int> vi;   typedef vector<ll> vl;   typedef vector<vi> vvi;   typedef vector<vl> vvl;   typedef pair<int,int> pii;   typedef pair<double, double> pdd;   typedef pair<ll, ll> pll;   typedef vector<pii> vii;   typedef vector<pll> vll;   typedef vector<int>::iterator vit;   typedef set<int>::iterator sit;      /*   template<typename T>   using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;   template<typename F, typename S>   using ordered_map = tree<F, S, less<F>, rb_tree_tag, tree_order_statistics_node_update>;   */      //#Defines   #define rep(i,a,b) for(i=a;i<=b;i++)   #define repR(i,a,b) for(i=a;i>=b;i--)   //#define pb push_back   #define pb emplace_back   #define F first   #define S second   #define mp make_pair   #define all(c)  c.begin(),c.end()   #define endl   n    #define pf printf   #define sf scanf   //#define left __left   //#define right __right   //#define tree __tree   #define MOD 1000000007   //#define harmonic(n) 0.57721566490153286l+log(n)      #define RESET(a,b) memset(a,b,sizeof(a))   #define gcd(a,b) __gcd(a,b)   #define lcm(a,b) (a*(b/gcd(a,b)))   #define sqr(a) ((a) * (a))      #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);   #define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);      const double PI = acos(-1);   const double eps = 1e-9;   const int inf = 2000000000;   const ll infLL = 9000000000000000000;         //Bit Operations   inline bool checkBit(ll n, int i) { return n&(1LL<<i); }   inline ll setBit(ll n, int i) { return n|(1LL<<i);; }   inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }      int fx[] = {0, 0, +1, -1};   int fy[] = {+1, -1, 0, 0};   //int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};   //int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};         //Inline functions      inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }   inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }   inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }   inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }   inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }   inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }   inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }   inline ll modInverse(ll a) { return modPow(a, MOD-2); }   inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }   inline bool isInside(pii p,ll n,ll m) { return (p.first>=0&&p.first<n&&p.second>=0&&p.second<m); }   inline bool isInside(pii p,ll n)  { return (p.first>=0&&p.first<n&&p.second>=0&&p.second<n); }   inline bool isSquare(ll x)     { ll s = sqrt(x); return (s*s==x); }   inline bool isFib(ll x)     { return isSquare(5*x*x+4)|| isSquare(5*x*x-4); }   inline bool isPowerOfTwo(ll x)   { return ((1LL<<(ll)log2(x))==x); }         struct func   {    //this is a sample overloading function for sorting stl    bool operator()(pii const &a, pii const &b)     {     if(a.F==b.F)      return (a.S<b.S);     return (a.F<b.F);    }   };      //Prime Number Generator      /*   #define M 100000000   int marked[M/64 + 2];      #define on(x) (marked[x/64] & (1<<((x%64)/2)))   #define mark(x)  marked[x/64] |= (1<<((x%64)/2))      vl prime;      bool isPrime(int num) {     return num > 1 && (num == 2 || ((num & 1) && !on(num)));    }      void sieve(ll n) {    for (ll i = 3; i * i < n; i += 2) {     if (!on(i)) {      for (ll j = i * i; j <= n; j += i + i) {       mark(j);      }     }    }    prime.pb(2);    for(ll i = 3; i <= n; i += 2) {     if(!on(i)) prime.pb(i);     }   }      */      //   //debug   #ifdef tajir   template < typename F, typename S >   ostream& operator << ( ostream& os, const pair< F, S > & p ) {    return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }      template < typename T >   ostream &operator << ( ostream & os, const vector< T > &v ) {    os <<  { ;    for(auto it = v.begin(); it != v.end(); ++it) {     if( it != v.begin() ) os <<  ,  ;      os << *it;    }    return os <<  } ;   }      template < typename T >   ostream &operator << ( ostream & os, const set< T > &v ) {    os <<  [ ;    for(auto it = v.begin(); it != v.end(); ++it) {     if( it != v.begin() ) os <<  ,  ;      os << *it;    }    return os <<  ] ;   }      template < typename T >   ostream &operator << ( ostream & os, const multiset< T > &v ) {    os <<  [ ;    for(auto it = v.begin(); it != v.end(); ++it) {     if( it != v.begin() ) os <<  ,  ;     os << *it;    }    return os <<  ] ;   }      template < typename F, typename S >   ostream &operator << ( ostream & os, const map< F, S > &v ) {    os <<  [ ;    for(auto it = v.begin(); it != v.end(); ++it) {     if( it != v.begin() ) os <<  ,  ;     os << it -> first <<   =   << it -> second ;     }    return os <<  ] ;   }      #define dbg(args...) do {cerr << #args <<   :  ; faltu(args); } while(0)      clock_t tStart = clock();   #define timeStamp dbg( Execution Time:  , (double)(clock() - tStart)/CLOCKS_PER_SEC)      void faltu () {    cerr << endl;   }      template <typename T>   void faltu( T a[], int n ) {    for(int i = 0; i < n; ++i) cerr << a[i] <<    ;    cerr << endl;   }      template <typename T, typename ... hello>   void faltu( T arg, const hello &... rest) {    cerr << arg <<    ;    faltu(rest...);   }   #else   #define dbg(args...)   #endif // tajir      bool valid(string s,int n) {    for(int i = 0; i < (n-1); ++i) {     if(s[i] ==  1  && s[i+1] ==  1 )      return false;    }    return true;   }      int main()   {    #ifdef tajir     freopen( input.txt ,  r , stdin);    #else     // online submission    #endif    optimize();    int n;    string s;    cin >> n >> s;    if(!valid(s,n)) {     cout <<  No  << endl;     return 0;    }    for(int i = 0; i < n; ++i) {     if(s[i] ==  0 ) {      s[i] =  1 ;      if(valid(s,n)) {       cout <<  No  << endl;       return 0;      }      s[i] =  0 ;     }    }    cout <<  Yes  << endl;    return 0;   }                     //?


#include <bits/stdc++.h>   using namespace std;   int n, x, a, ans, r[2001], t[2001][2001];   bool f[2001][2001];   int main() {     scanf( %d , &n);     for (int _ = 1; _ <= n; _++)       while (scanf( %d: , &x)) {         r[_]++;         for (int i = 1; i < x; i++) scanf( %d, , &a), t[_][a] = x;         scanf( %d , &a), t[_][a] = x;         if (getchar() !=  - ) break;       }     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         if (t[i][j] + t[j][i] == n) f[i][j] = f[j][i] = true, ans++;     if (ans != (n - 1)) return printf( -1 n ), 0;     for (int i = 1; i <= n; i++) {       a = 0;       for (int j = 1; j <= n; j++)         if (f[i][j]) a++;       if (a != r[i]) return printf( -1 n ), 0;     }     printf( %d n , ans);     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         if (f[i][j]) printf( %d %d n , i, j);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 5e5 + 10, mod = 1e9 + 7;   int n, q, cnt;   int nxt[maxN + 1], res[maxN + 1], ans[maxN + 1];   int pw[maxN + 1], id[maxN + 1], tp[maxN + 1];   int L[maxN + 1], R[maxN + 1], S[maxN + 1];   int stk[maxN + 1], top;   int sum[maxN + 1], mn[maxN + 1][21], lg[maxN + 1];   char s[maxN + 1];   vector<int> pm[maxN + 1], pa[maxN + 1];   vector<int> son[maxN + 1], pre[maxN + 1], p0[maxN + 1];   inline int read() {     int num = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) num = (num << 3) + (num << 1) + (ch ^ 48), ch = getchar();     return num * f;   }   inline void update(int &x, int y) { x = x + y >= mod ? x + y - mod : x + y; }   inline int mpow(int a, int x) {     int ans = 1;     while (x) {       if (x & 1) ans = 1ll * ans * a % mod;       a = 1ll * a * a % mod;       x >>= 1;     }     return ans;   }   inline int get_mn(int l, int r) {     int k = lg[r - l + 1];     return min(mn[l][k], mn[r - (1 << k) + 1][k]);   }   inline bool check(int l, int r) {     if (sum[r] != sum[l - 1]) return false;     if (s[l] ==  *  || s[l] ==  + ) return false;     if (s[r] ==  *  || s[r] ==  + ) return false;     return get_mn(l, r) >= sum[r];   }   inline int get_Mul(int l, int r) {     int id = sum[r];     int x = lower_bound(pm[id].begin(), pm[id].end(), l) - pm[id].begin();     if (x == pm[id].size() || pm[id][x] > r) return -1;     return pm[id][x];   }   inline int get_Add(int l, int r) {     int id = sum[r];     int x = lower_bound(pa[id].begin(), pa[id].end(), l) - pa[id].begin();     if (x == pa[id].size() || pa[id][x] > r) return -1;     return pa[id][x];   }   inline int build(int l, int r) {     int node = ++cnt;     L[node] = l, R[node] = r;     while (s[l] ==  (  && nxt[l] == r) id[l++] = node, r--;     int mid = get_Add(l, r);     if (mid != -1) {       tp[node] = 0;       int x = l;       while (mid != -1) {         id[mid] = node;         son[node].push_back(build(x, mid - 1));         x = mid + 1;         mid = get_Add(x, r);       }       son[node].push_back(build(x, r));       int sum = 0;       for (int i = 0; i < son[node].size(); i++) {         update(sum, res[son[node][i]]);         pre[node].push_back(sum);       }       return res[node] = sum, node;     }     mid = get_Mul(l, r);     if (mid != -1) {       tp[node] = 1;       int x = l;       while (mid != -1) {         id[mid] = node;         son[node].push_back(build(x, mid - 1));         x = mid + 1;         mid = get_Mul(x, r);       }       son[node].push_back(build(x, r));       int sum = 1, tot = 0;       for (int i = 0; i < son[node].size(); i++) {         if (!res[son[node][i]])           tot++;         else           sum = 1ll * sum * res[son[node][i]] % mod;         pre[node].push_back(sum);         p0[node].push_back(tot);       }       return res[node] = tot ? 0 : sum, node;     }     tp[node] = 2;     for (int i = l; i <= r; i++)       res[node] = (10ll * res[node] % mod + s[i] -  0 ) % mod;     return node;   }   inline int get(int l, int r) {     int ans = S[r];     update(ans, mod - 1ll * S[l - 1] * pw[r - l + 1] % mod);     return ans;   }   inline int findl(int node, int x) {     int l = 0, r = son[node].size() - 1, ans = -1;     while (l <= r) {       int mid = (l + r) >> 1;       if (L[son[node][mid]] < x)         ans = mid, l = mid + 1;       else         r = mid - 1;     }     return ans;   }   inline int findr(int node, int x) {     int l = 0, r = son[node].size() - 1, ans = son[node].size();     while (l <= r) {       int mid = (l + r) >> 1;       if (R[son[node][mid]] > x)         ans = mid, r = mid - 1;       else         l = mid + 1;     }     return ans;   }   inline int query3(int node, int l, int r) {     l = max(l, L[node]), r = min(r, R[node]);     if (l > r) return 0;     return get(l, r);   }   inline int query2(int node, int l, int r) {     if (tp[node] == 2) return query3(node, l, r);     l = max(l, L[node]), r = min(r, R[node]);     if (l > r) return 0;     int x = findl(node, l), y = findr(node, r);     int ans = (y ? pre[node][y - 1] : 1), tot = (y ? p0[node][y - 1] : 0);     if (x != -1)       ans = 1ll * ans * mpow(pre[node][x], mod - 2) % mod, tot -= p0[node][x];     if (x != -1 && R[son[node][x]] >= l)       ans = 1ll * ans * query3(son[node][x], l, r) % mod;     if (y != son[node].size() && L[son[node][y]] <= r)       ans = 1ll * ans * query3(son[node][y], l, r) % mod;     return tot ? 0 : ans;   }   inline int query1(int node, int l, int r) {     int x = findl(node, l), y = findr(node, r);     int ans = (y ? pre[node][y - 1] : 0);     if (x != -1) update(ans, mod - pre[node][x]);     if (x != -1 && R[son[node][x]] >= l) update(ans, query2(son[node][x], l, r));     if (y != son[node].size() && L[son[node][y]] <= r)       update(ans, query2(son[node][y], l, r));     return ans;   }   inline int solve(int l, int r) {     if (s[l] ==  (  && nxt[l] == r) return res[id[l]];     int mid = get_Add(l, r);     if (mid != -1) return query1(id[mid], l, r);     mid = get_Mul(l, r);     if (mid != -1) return query2(id[mid], l, r);     return get(l, r);   }   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = 1; i <= n; i++) {       sum[i] = sum[i - 1];       if (s[i] ==  ( ) sum[i]++, stk[++top] = i;       if (s[i] ==  ) ) sum[i]--, nxt[stk[top--]] = i;     }     for (int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;     for (int i = 1; i <= n; i++) mn[i][0] = sum[i];     for (int j = 1; (1 << j) <= n; j++)       for (int i = 1; i + (1 << j) - 1 <= n; i++)         mn[i][j] = min(mn[i][j - 1], mn[i + (1 << j - 1)][j - 1]);     for (int i = 1; i <= n; i++) {       if (s[i] ==  + ) pa[sum[i]].push_back(i);       if (s[i] ==  * ) pm[sum[i]].push_back(i);     }     pw[0] = 1;     for (int i = 1; i <= n; i++) pw[i] = 10ll * pw[i - 1] % mod;     for (int i = 1; i <= n; i++) {       S[i] = 10ll * S[i - 1] % mod;       if (isdigit(s[i])) update(S[i], s[i] -  0 );     }     build(1, n);     q = read();     while (q--) {       int l = read(), r = read();       if (!check(l, r)) {         puts( -1 );         continue;       }       printf( %d n , solve(l, r));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     string s;     cin >> s;     int count = 0;     while (s.size() != 1) {       int sum = 0;       for (int i = 0; i < s.size(); i++) sum += s[i] - 48;       string res =   ;       while (sum) {         int digit = sum % 10;         sum /= 10;         res += (char)(digit + 48);       }       s = res;       count++;     }     cout << count;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3,  Ofast ,  inline )   #pragma GCC target( avx,avx2 )   using namespace std;   template <class t>   inline t read(t &x) {     char c = getchar();     bool f = 0;     x = 0;     while (!isdigit(c)) f |= c ==  - , c = getchar();     while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     if (f) x = -x;     return x;   }   template <class t, class... A>   inline void read(t &x, A &...a) {     read(x);     read(a...);   }   template <class t>   inline void write(t x) {     if (x < 0)       putchar( - ), write(-x);     else {       if (x > 9) write(x / 10);       putchar( 0  + x % 10);     }   }   long long A, B, C, S, ansA, ansB, ansC, ansS, pw[505][505], V, n, v[10005];   void dfs2(long long x, long long b, long long a) {     if (1.0 * b * b > V / a) return;     if (x > n) {       B = max(B, b);       return;     }     for (long long i = v[x]; ~i; i--) dfs2(x + 1, b * pw[x][i], a);   }   void dfs1(long long x, long long a) {     if (1.0 * a * a * a > V) return;     if (x > n) {       long long bc = V / a, lim = 4 * a * sqrt(bc) + 2 * bc;       if (lim >= ansS) return;       B = 0;       A = a;       dfs2(1, 1, A);       C = V / A / B;       S = (A * B + B * C + A * C) << 1;       if (S < ansS) {         ansS = S;         ansA = A;         ansB = B;         ansC = C;       }       return;     }     for (long long i = v[x]; ~i; i--) {       v[x] -= i;       dfs1(x + 1, a * pw[x][i]);       v[x] += i;     }   }   void doit() {     read(n);     V = 1;     for (long long i = 1, x, y; i <= n; i++) {       read(x, y);       v[i] = y;       pw[i][0] = 1;       for (long long j = 1; j <= y; j++) pw[i][j] = pw[i][j - 1] * x;       V *= pw[i][y];     }     ansS = 1ll << 62;     dfs1(1, 1);     write(ansS);     putchar(   );     write(ansA);     putchar(   );     write(ansB);     putchar(   );     write(ansC);     puts(  );   }   signed main() {     long long t;     read(t);     while (t--) doit();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       string n;       int s;       cin >> n >> s;       reverse(n.begin(), n.end());       char temp[] =  0 ;       n.insert(n.size(), temp);       int sum = 0;       for (int i = 0; i < n.size(); i++) sum += n[i] - 48;       char ans[25];       for (int i = 0; i < 25; i++) ans[i] = 0;       ans[0] =  0 ;       int i = 0;       while (sum > s) {         int dig = (n[i] - 48);         int car = 0;         sum -= dig;         n[i] =  0 ;         if (dig > 0) {           ans[i] = 10 - dig + 48;           car = 1;         } else           ans[i] =  0 ;         for (int j = i + 1; car; j++) {           int t = (n[j] - 48 + car);           if (t == 10)             sum -= n[j] - 48;           else             sum++;           n[j] = (t % 10) + 48;           car = t / 10;         }         i++;       }       int size = 0;       while (ans[++size])         ;       reverse(ans, ans + size);       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long sqr(long long x) { return x * x; }   int mysqrt(long long x) {     int l = 0, r = 1e9 + 1;     while (r - l > 1) {       int m = (l + r) / 2;       if (m * (long long)m <= x)         l = m;       else         r = m;     }     return l;   }   mt19937 rnd(1227);   mt19937_64 rndll(12365);   long long AR = 19, BR = 13, CR = 23, XR = 228, YR = 322, MODR = 1e9 + 993;   long long myrand() {     long long ZR = (XR * AR + YR * BR + CR) % MODR;     XR = YR;     YR = ZR;     return ZR;   }   const int Mod = 1e9 + 9;   int bpow(int x, int y) {     if (y == 0) return 1;     if (y == 1) return x;     int ret = bpow(x, y >> 1);     ret = (ret * (long long)ret) % Mod;     if (y & 1) ret = (ret * (long long)x) % Mod;     return ret;   }   int bdiv(int x, int y) { return (x * (long long)bpow(y, Mod - 2)) % Mod; }   void setmin(int &x, int y) { x = min(x, y); }   void setmax(int &x, int y) { x = max(x, y); }   void setmin(long long &x, long long y) { x = min(x, y); }   void setmax(long long &x, long long y) { x = max(x, y); }   int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }   const long long llinf = 2e18 + 100;   const double eps = 1e-9;   const int maxn = 2e5 + 100, maxw = 1e7 + 100, inf = 2e9 + 100, sq = 300,             mod = 1e9 + 9, LG = 17;   int n;   vector<int> e[maxn];   int a[maxn];   vector<int> ans;   bool vis[maxn];   void go(int v, int par) {     ans.push_back(v);     vis[v] = 1;     for (int i : e[v])       if (i != par && !vis[i]) go(i, v);   }   void dfs(int v, int par) {     for (int i : e[v])       if (i != par) {         dfs(i, v);         if (vis[i]) a[v] ^= 1;       }     if (a[v] == 0) go(v, par);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       int v = i, u;       cin >> u;       u--;       if (u >= 0) {         e[v].push_back(u);         e[u].push_back(v);         a[v] ^= 1;         a[u] ^= 1;       }     }     dfs(0, -1);     if (ans.size() < n)       cout <<  NO ;     else {       cout <<  YES n ;       for (int i : ans) cout << i + 1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = int(1e5 + 5);   int n, A, cf, cm;   int a[MAXN], tmp1[MAXN], tmp2[MAXN];   long long s[MAXN], m;   int _max = 0, _min = int(1e9);   bool cmp(int x, int y) { return a[x] < a[y]; }   int main() {     cin >> n >> A >> cf >> cm >> m;     for (int i = 0; i < n; i++) tmp1[i] = i, cin >> a[i];     if (!cm && !cf) {       puts( 0 );       for (int i = 0; i < n; i++) cout << a[i] <<    ;       return 0;     }     sort(tmp1, tmp1 + n, cmp);     sort(a, a + n);     for (int i = 0; i < n; i++) {       s[i] = a[i];       i ? s[i] += s[i - 1] : 0;     }     long long ret, ans = 0;     a[n] = A;     for (int i = n; i >= 0; i--) {       ret = m - (1ll * A * (n - i) - (s[n - 1] - (i ? s[i - 1] : 0)));       if (ret < 0) break;       if (!cm) {         ans = 1ll * (n - i) * cf;         _max = n - i;         _min = 0;         continue;       }       long long l = a[0], r = A, mid;       while (l < r) {         mid = r - ((r - l) >> 1);         int k = upper_bound(a, a + n, mid) - a;         k = min(k, i);         if (ret >= 1ll * k * mid - (k ? s[k - 1] : 0))           l = mid;         else           r = mid - 1;       }       long long force = 1ll * (n - i) * cf + 1ll * l * cm;       if (force > ans) {         ans = force;         _max = n - i;         _min = l;       }     }     cout << ans << endl;     for (int i = 0; i < n - _max; i++) tmp2[tmp1[i]] = max(_min, a[i]);     for (int i = n - _max; i < n; i++) tmp2[tmp1[i]] = A;     for (int i = 0; i < n; i++) cout << tmp2[i] <<    ;     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   double v1, v2, l;   int main() {     scanf( %d%lf%lf%lf%d , &n, &l, &v1, &v2, &k);     int T = n / k;     if (n % k) T++;     printf( %.7lf n , (2 * T - 2 + (v1 + v2) / v1 - v2 / v1 + v1 / v2) * l /                           ((2 * T - 2) * v1 + v1 + v2));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool ans[310000];   struct Query {     int x1, y1, x2, y2, id;   } querys[310000];   bool operator<(Query a, Query b) { return a.x2 < b.x2; }   struct Point {     int x, y;   } points[310000];   bool operator<(Point a, Point b) { return a.x < b.x; }   int minv[310000 << 2];   void pushup(int o) { minv[o] = min(minv[((o) << 1)], minv[((o) << 1 | 1)]); }   void update(int o, int L, int R, int x, int val) {     if (L == R) {       minv[o] = val;       return;     }     int M = (L + R) >> 1;     if (x <= M)       update(((o) << 1), L, M, x, val);     else       update(((o) << 1 | 1), M + 1, R, x, val);     pushup(o);   }   int query(int o, int L, int R, int ql, int qr) {     if (ql <= L && R <= qr) return minv[o];     int M = (L + R) >> 1;     int ans = 0x3f3f3f3f;     if (ql <= M) ans = min(ans, query(((o) << 1), L, M, ql, qr));     if (qr > M) ans = min(ans, query(((o) << 1 | 1), M + 1, R, ql, qr));     return ans;   }   int main() {     int n, m, t, q;     scanf( %d%d%d%d , &n, &m, &t, &q);     for (int i = 1; i <= t; i++) scanf( %d%d , &points[i].x, &points[i].y);     for (int i = 1; i <= q; i++)       scanf( %d%d%d%d , &querys[i].x1, &querys[i].y1, &querys[i].x2,             &querys[i].y2),           querys[i].id = i;     sort(points + 1, points + t + 1);     sort(querys + 1, querys + q + 1);     for (int i = 1, j = 1; i <= q; i++) {       while (j <= t && points[j].x <= querys[i].x2) {         update(1, 1, m, points[j].y, points[j].x);         j++;       }       ans[querys[i].id] |=           query(1, 1, m, querys[i].y1, querys[i].y2) >= querys[i].x1;     }     swap(n, m);     for (int i = 1; i <= t; i++) swap(points[i].x, points[i].y);     for (int i = 1; i <= q; i++) {       swap(querys[i].x1, querys[i].y1);       swap(querys[i].x2, querys[i].y2);     }     sort(points + 1, points + t + 1);     sort(querys + 1, querys + q + 1);     memset(minv, 0, sizeof(minv));     for (int i = 1, j = 1; i <= q; i++) {       while (j <= t && points[j].x <= querys[i].x2) {         update(1, 1, m, points[j].y, points[j].x);         j++;       }       ans[querys[i].id] |=           query(1, 1, m, querys[i].y1, querys[i].y2) >= querys[i].x1;     }     for (int i = 1; i <= q; i++) {       if (ans[i])         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int x = n / 2, y = (n / 2) + 1, prime1 = 0, prime2 = 0;     if (n % 2 == 0) {       x = (n / 2);       y = n / 2;     }     for (int i = 1; i <= n; i++) {       for (int j = 2; j < x; j++) {         if (x % j == 0) {           prime1++;           break;         } else if (j == x - 1) {           prime1 = 0;           break;         }       }       for (int j = 2; j < y; j++) {         if (y % j == 0) {           prime2++;           break;         } else if (j == y - 1) {           prime1 = 0;           prime2 = 0;         }       }       if (prime1 >= 1 && prime2 >= 1)         break;       else {         x--;         y++;       }     }     cout << x <<     << y;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5, inf = 1e9 + 7;   long long n, k, f[30];   string s, t, r;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long i, j, a, b, ans = 0;     cin >> s >> t;     r = s;     sort(r.begin(), r.end(), greater<long long>());     if (r <= t) return cout << -1, 0;     n = s.size();     for (i = 0; i < n; i++) f[s[i] -  a ]++;     k = t.size();     for (i = 0; i < min(k, n); i++) {       if (f[t[i] -  a ]) {         s[i] = t[i], f[t[i] -  a ]--;       } else {         for (j = t[i] -  a ; j < 26; j++)           if (f[j]) {             s[i] = char(j +  a );             f[j]--;             i++;             for (j = 0; j < 26; j++) {               while (f[j]--) s[i] = char(j +  a ), i++;             }             cout << s;             return 0;           }         for (j = 25; j >= 0; j--) {           while (f[j]--) s[i] = char(j +  a ), i++;         }         next_permutation(s.begin(), s.end());         cout << s;         return 0;       }     }     if (i == n) next_permutation(s.begin(), s.end());     for (j = 0; j < 26; j++) {       while (f[j]--) s[i] = char(j +  a ), i++;     }     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, k;     cin >> n;     int a[n], b[n];     for (i = 1; i <= n; i++) {       cin >> a[i];     }     for (i = 1; i <= n; i++) {       k = a[i];       b[k] = i;     }     for (i = 1; i <= n; i++) {       cout << b[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const double Pi = acos(-1.0);   const int INF = 1 << 29;   const int MAXN = 505;   int n;   int M[MAXN][MAXN];   int R[MAXN];   long long A[MAXN];   int main(int argc, char** argv) {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         scanf( %d , &M[i][j]);       }     }     for (int i = 0; i < n; i++) {       scanf( %d , &R[n - i - 1]);       R[n - i - 1]--;     }     for (int k = 0; k < n; k++) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           M[R[i]][R[j]] = min(M[R[i]][R[j]], M[R[i]][R[k]] + M[R[k]][R[j]]);         }       }       for (int i = 0; i <= k; i++) {         for (int j = 0; j <= k; j++) {           A[n - k - 1] += M[R[i]][R[j]];         }       }     }     for (int i = 0; i < n; i++) {       printf( %I64d  , A[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   const long long INF = 2000000000LL;   long long res[MAXN], xx[MAXN << 1], cnt[MAXN << 1], la[MAXN << 1];   struct Event {     long long l, r, y, v;     Event() {}     Event(long long _l, long long _r, long long _y, long long _v)         : l(_l), r(_r), y(_y), v(_v) {}     bool operator<(const Event &t) const { return y < t.y; }   } e[MAXN << 1];   int main() {     int n, k;     scanf( %d%d , &n, &k);     int tot = 0;     xx[tot++] = -INF;     for (int i = 0; i < n; i++) {       long long x, y;       scanf( %I64d%I64d , &x, &y);       xx[tot++] = x;       xx[tot++] = x + k;       e[i << 1] = Event(x, x + k, y, 1);       e[i << 1 | 1] = Event(x, x + k, y + k, -1);     }     sort(xx, xx + tot);     tot = unique(xx, xx + tot) - xx;     sort(e, e + 2 * n);     for (int i = 0; i < tot; i++) la[i] = -INF;     for (int i = 0; i < 2 * n; i++) {       int l = upper_bound(xx, xx + tot, e[i].l) - xx;       int r = lower_bound(xx, xx + tot, e[i].r) - xx;       for (int j = l; j <= r; j++) {         res[cnt[j]] += (xx[j] - xx[j - 1]) * (e[i].y - la[j]);         cnt[j] += e[i].v;         la[j] = e[i].y;       }     }     for (int i = 1; i <= n; i++) printf( %I64d  , res[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   long long l, val[205], cst[205];   char s[205];   long long ch[205][26], fail[205], cnt = 1;   void Insert(char *s, long long w) {     long long len = strlen(s), r = 0;     for (long long i = 0; i < len; i++) {       long long val = s[i] -  a ;       if (!ch[r][val]) ch[r][val] = cnt++;       r = ch[r][val];     }     val[r] += w;   }   long long Q[205], L, R;   void build(long long r) {     Q[L = 0] = r, R = 1;     long long p, c;     for (; L < R;) {       r = Q[L++];       for (long long i = 0; i < 26; i++)         if (c = ch[r][i]) {           Q[R++] = c;           for (p = fail[r]; p != 0 && ch[p][i] == 0; p = fail[p])             ;           long long tmp = ch[p][i];           if (tmp && tmp != c)             fail[c] = tmp;           else             fail[c] = 0;           val[c] += val[fail[c]];         } else {           for (p = fail[r]; p != 0 && ch[p][i] == 0; p = fail[p])             ;           long long tmp = ch[p][i];           if (tmp)             ch[r][i] = tmp;           else             ch[r][i] = 0;         }     }   }   long long dp[205][205], dp2[205][205], dp3[205][205], A[205][205], B[205][205];   void solve(long long a[205][205], long long b[205][205],              long long c[205][205]) {     memcpy(A, a, sizeof A), memcpy(B, b, sizeof B);     for (long long k = 0; k < cnt; k++)       for (long long i = 0; i < cnt; i++)         for (long long j = 0; j < cnt; j++)           if (A[i][k] != -0x3f3f3f3f3f3f3f3fll &&               B[k][j] != -0x3f3f3f3f3f3f3f3fll)             c[i][j] = max(c[i][j], A[i][k] + B[k][j]);   }   int main() {     scanf( %lld%lld , &n, &l);     for (long long i = 1; i <= n; i++) scanf( %lld , &cst[i]);     fail[0] = -1;     for (long long i = 1; i <= n; i++) {       scanf( %s , s);       Insert(s, cst[i]);     }     build(0);     for (long long i = 0; i < cnt; i++)       for (long long j = 0; j < cnt; j++)         dp[i][j] = dp2[i][j] = -0x3f3f3f3f3f3f3f3fll;     for (long long i = 0; i < cnt; i++) dp[i][i] = dp2[i][i] = 0;     for (long long i = 0; i < cnt; i++)       for (long long j = 0; j < 26; j++) dp[i][ch[i][j]] = val[ch[i][j]];     for (; l; l >>= 1, solve(dp, dp, dp))       if (l & 1) solve(dp, dp2, dp2);     printf( %lld n , *max_element(dp2[0], dp2[0] + cnt + 1));   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 2e5, mod = 1e9 + 7;   vector<char> s;   long long X;   void paste(long long p, long long l, long long cnt) {     if (s.size() > X + 3 || l == 0) return;     for (long long i = 0; i < cnt; ++i)       for (long long j = 0; j < l; ++j)         if (s.size() > X + 3)           return;         else           s.push_back(s[p + j]);   }   long long md(long long a) {     if (a < 0)       return (a + mod * 2) % mod;     else       return a % mod;   }   void solve() {     long long x;     cin >> x;     X = x;     string str;     cin >> str;     s = vector<char>(str.begin(), str.end());     long long p = 0;     long long cl = s.size();     while (p < x) {       ++p;       long long num = s[p - 1] -  0 ;       paste(p, s.size() - p, num - 1);       cl = (cl + (num - 1) * md(cl - p)) % mod;     }     cout << cl << endl;     return;   }   signed main() {     ios::sync_with_stdio(false);     long long t;     cin >> t;     for (long long i = 0; i < t; ++i) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using seg = pair<int, int>;   using ll = long long;   seg intersect(seg a, seg b) {     seg ret = {max(a.first, b.first), min(a.second, b.second)};     if (ret.first > ret.second) return {-1, -1};     return ret;   }   inline int len(const seg& a) { return a.second - a.first; }   const int inf = 1234567890;   struct node {     int l, r;     seg x;     node() {}     node(int _l, int _r) : l(_l), r(_r), x(0, inf) {}     node(int _l, int _r, const seg& _x) : node(_l, _r) { x = _x; }     node(node a, node b) : node(a.l, b.r) { x = intersect(a.x, b.x); }     void update(const seg& v) { x = v; }   };   struct segment_tree {     int n;     vector<node> arr;     segment_tree(const vector<seg>& a) : n(a.size()), arr(4 * n) {       mk(a, 0, 0, n - 1);     }     node mk(const vector<seg>& a, int i, int l, int r) {       int m = (l + r) / 2;       return arr[i] = l > r    ? node(l, r)                       : l == r ? node(l, r, a[l])                                : node(mk(a, 2 * i + 1, l, m),                                       mk(a, 2 * i + 2, m + 1, r));     }     node update(int at, seg v, int i = 0) {       int hl = arr[i].l, hr = arr[i].r;       if (at < hl || hr < at) return arr[i];       if (hl == at && at == hr) {         arr[i].update(v);         return arr[i];       }       return arr[i] = node(update(at, v, 2 * i + 1), update(at, v, 2 * i + 2));     }     node query(int l, int r, int i = 0) {       int hl = arr[i].l, hr = arr[i].r;       if (r < hl || hr < l) return node(hl, hr);       if (l <= hl && hr <= r) return arr[i];       return node(query(l, r, 2 * i + 1), query(l, r, 2 * i + 2));     }   };   int main() {     ios::sync_with_stdio(false), cin.tie(nullptr);     int n;     cin >> n;     vector<seg> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i].first >> a[i].second;     }     segment_tree st(a);     int mx = 0;     for (int i = 0; i < n; ++i) {       st.update(i, seg(0, inf));       mx = max(mx, len(st.query(0, n - 1).x));       st.update(i, a[i]);     }     cout << mx <<   n ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   struct segment_tree {     int val[200005 << 2];     inline void update(int l, int r, int k, int x, int w) {       if (l == r) {         val[k] = w;         return;       }       int mid = l + r >> 1;       if (x <= mid)         update(l, mid, k << 1, x, w);       else         update(mid + 1, r, k << 1 | 1, x, w);       val[k] = max(val[k << 1], val[k << 1 | 1]);     }     inline int query(int l, int r, int k, int L, int R) {       if (L <= l && r <= R) return val[k];       int mid = l + r >> 1, ans = 0;       if (L <= mid) ans = max(ans, query(l, mid, k << 1, L, R));       if (mid < R) ans = max(ans, query(mid + 1, r, k << 1 | 1, L, R));       return ans;     }   } sgt;   int p[200005], pos[200005], a[200005], lg2[200005];   int lastp[200005], pre[200005][20];   char str[200005];   int main() {     int n, m, q;     scanf( %d%d%d , &n, &m, &q);     lg2[1] = 0;     for (int i = 2; i <= m; i++) lg2[i] = lg2[i >> 1] + 1;     for (int i = 1; i <= n; i++) {       scanf( %d , &p[i]);       pos[p[i]] = i;     }     p[n + 1] = p[1], p[0] = p[n];     for (int i = 1; i <= m; i++) {       scanf( %d , &a[i]);       pre[i][0] = lastp[p[pos[a[i]] - 1]];       for (int k = 1; k <= lg2[i]; k++) pre[i][k] = pre[pre[i][k - 1]][k - 1];       lastp[a[i]] = i;     }     for (int i = 1; i <= m; i++) {       int x = i, k = n - 1;       while (k) {         x = pre[x][lg2[k]];         k -= 1 << lg2[k];       }       if (x) sgt.update(1, m, 1, i, x);     }     for (int i = 1; i <= q; i++) {       int l, r;       scanf( %d%d , &l, &r);       int t = sgt.query(1, m, 1, l, r);       if (t >= l)         str[i] =  1 ;       else         str[i] =  0 ;     }     str[q + 1] =   0 ;     puts(str + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double PI = acos(-1.0);   const int N = 1e5 + 5;   int n;   map<string, set<string> > m;   map<string, set<string> > m2;   set<string> host;   vector<set<string> > res;   int main(void) {     ios_base::sync_with_stdio(false);     cin >> n;     while (n--) {       string s;       cin >> s;       host.insert(s);       string s1 =   , s2 =   ;       int count = 0;       for (int i = 0; i < (int)s.size(); i++) {         if (s[i] ==  / ) count++;         if (count < 3) {           s1 += s[i];         } else {           s2 += s[i];         }       }       s1 +=    ;       s2 +=    ;       m[s1].insert(s2);     }     for (map<string, set<string> >::iterator it = m.begin(); it != m.end();          it++) {       string str =   ;       for (set<string>::iterator itt = (it->second).begin();            itt != (it->second).end(); itt++) {         str += (*itt);       }       m2[str].insert(it->first);     }     for (map<string, set<string> >::iterator it = m2.begin(); it != m2.end();          it++) {       if ((it->second).size() > 1) {         res.push_back(it->second);       }     }     cout << res.size() << endl;     for (int i = 0; i < (int)res.size(); i++) {       for (set<string>::iterator it = res[i].begin(); it != res[i].end(); it++) {         cout << (*it) <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   struct Block {     vector<array<int, 3>> events;     int pop_before;     vector<int> stack_after;     void add_event(array<int, 3> v) {       events.insert(upper_bound(events.begin(), events.end(), v), v);       sort(events.begin(), events.end());       pop_before = 0;       stack_after.clear();       for (auto [p, t, x] : events) {         if (t)           stack_after.push_back(x);         else {           if (stack_after.size())             stack_after.pop_back();           else             ++pop_before;         }       }     }   };   int main() {     cin.tie(0)->sync_with_stdio(0);     int q;     cin >> q;     int R = (int)sqrt(q);     int B = (q + R - 1) / R;     vector<Block> blocks(B);     for (int qq = 0; qq < q; ++qq) {       int p, t, x = 0;       cin >> p >> t;       --p;       if (t == 1) cin >> x;       blocks[p / R].add_event({p, t, x});       vector<array<int, 2>> remaining;       for (int i = 0; i < B; ++i) {         int to_pop = blocks[i].pop_before;         while (to_pop && remaining.size()) {           int pop_here = min(remaining.back()[0], to_pop);           to_pop -= pop_here;           remaining.back()[0] -= pop_here;           if (remaining.back()[0] == 0) remaining.pop_back();         }         if (blocks[i].stack_after.size())           remaining.push_back({(int)blocks[i].stack_after.size(), i});       }       if (remaining.size()) {         cout << blocks[remaining.back()[1]].stack_after[remaining.back()[0] - 1]              <<   n ;       } else         cout <<  -1 n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int64_t n, i;     cin >> n;     string s;     cin >> s;     string ans =   ;     ans = ans + s[0];     bool st = true;     if ((n - 1) & 1) {       st = false;     }     for (i = 1; i < n; i++) {       if (st) {         ans = s[i] + ans;         st = false;       } else {         ans = ans + s[i];         st = true;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   int main() {     int req_amount;     std::cin >> req_amount;     while (req_amount--) {       std::string s;       std::cin >> s;       int counter = 0;       for (const auto c : s) {         counter -= ((c ==  B ) ? -1 : 1);       }       std::cout << ((counter == 0) ?  YES  :  NO ) << std::endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T > 0) {       T--;       string a, b;       int d;       cin >> a >> b;       for (int i = 0; i < b.length(); i++)         if (b[b.size() - i - 1] ==  1 ) {           d = i;           break;         }       for (int i = d; i <= a.size() - 1; i++) {         if (a[a.size() - i - 1] ==  1 ) {           cout << i - d << endl;           d = 100005;           break;         }       }       if (d != 100005) {         cout << a.size() - b.size() << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 1005;   int n, s;   struct Parcel {     int l, r, w, s, v, id;   } a[N];   vector<Parcel> p[N];   ll dp[N][N];   ll dfs(int pos, int r) {     if (dp[pos][r] != -1) return dp[pos][r];     ll &ret = dp[pos][r];     ret = 0;     vector<ll> f(a[pos].r + 1);     for (int i = a[pos].l; i <= a[pos].r; i++) {       if (i) f[i] = f[i - 1];       for (auto &j : p[i])         if (j.l >= a[pos].l && j.w <= r && j.id != pos)           f[i] = max(f[i], f[j.l] + j.v + dfs(j.id, min(j.s, r - j.w)));     }     return ret = f[a[pos].r];   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> s;     for (int i = 1; i <= n; i++)       cin >> a[i].l >> a[i].r >> a[i].w >> a[i].s >> a[i].v,           a[i].id = i, p[a[i].r].push_back(a[i]);     a[0].l = 0;     a[0].r = 2 * n;     memset(dp, -1, sizeof(dp));     cout << dfs(0, s) << endl;     return 0;   }


#include <bits/stdc++.h>   const int N = 50;   std::vector<int> *graph[N][N], *igraph[N][N];   std::vector<int> expand(std::vector<int> *graph[N][N], std::vector<int> queue,                           int max) {     for (int t = 0; t + 1 < (int)queue.size() && (int)queue.size() <= max; ++t) {       int u = queue[t];       int v = queue[t + 1];       if (graph[u][v] == NULL) {         return std::vector<int>();       } else {         for (int w : *graph[u][v]) {           queue.push_back(w);         }       }     }     return queue;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     memset(graph, 0, sizeof(graph));     for (int i = 0; i < m; ++i) {       int x, y, k;       scanf( %d%d%d , &x, &y, &k);       x--;       y--;       std::vector<int> seq;       while (k--) {         int v;         scanf( %d , &v);         seq.push_back(--v);       }       graph[x][y] = new std::vector<int>(seq);       std::reverse(seq.begin(), seq.end());       igraph[y][x] = new std::vector<int>(seq);     }     bool found = false;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         if (graph[i][j] != NULL) {           std::vector<int> seq = *graph[i][j];           for (int k = 1; k < (int)seq.size(); ++k) {             if (seq[k - 1] == i && seq[k] == j) {               std::vector<int> fw = expand(                   graph, std::vector<int>(seq.begin() + k, seq.end()), 2 * n);               std::vector<int> iseq(seq.begin(), seq.begin() + k);               std::reverse(iseq.begin(), iseq.end());               std::vector<int> bw = expand(igraph, iseq, 2 * n);               if (!fw.empty() && !bw.empty()) {                 std::reverse(bw.begin(), bw.end());                 for (int t : fw) {                   bw.push_back(t);                 }                 if ((int)bw.size() <= 2 * n && !found) {                   found = true;                   printf( %d n , (int)bw.size());                   for (int i = 0; i < (int)bw.size(); ++i) {                     printf( %d%c , bw[i] + 1,    n [i == (int)bw.size() - 1]);                   }                 }               }             }           }         }       }     }     if (!found) {       puts( 0 );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = 3.1415926535897;   int m, n, dp[5005][5005], ans;   char yy[5005], sy[5005];   signed main() {     std::ios::sync_with_stdio(0);     std::cin.tie(0);     cin >> m >> n >> yy >> sy;     for (int i = 0; i < m; ++i)       for (int j = 0; j < n; ++j) {         if (yy[i] == sy[j])           dp[i + 1][j + 1] = dp[i][j] + 2;         else           dp[i + 1][j + 1] = max(max(dp[i + 1][j], dp[i][j + 1]) - 1, 0);         ans = max(ans, dp[i + 1][j + 1]);       }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   int main() {     int x, y, z, a, b, c;     scanf( %d %d %d , &x, &y, &z);     scanf( %d %d %d , &a, &b, &c);     if (x == a || y == b || z == c)       printf( YES n );     else       printf( NO n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       unordered_set<char> st;       for (int i = 0; i < s.length(); i++) {         if (s[i] != s[i + 1]) {           st.insert(s[i]);         } else {           i++;         }       }       vector<char> v;       for (auto i : st) {         v.push_back(i);       }       sort(v.begin(), v.end());       for (auto i = v.begin(); i != v.end(); i++) {         cout << *i;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 61;   const int K = 22222;   const int M = K + K + 5;   int n, m;   int a[N], b[N];   long long m1[M], m2[M];   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < m; i++) scanf( %d , &b[i]);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         m1[a[i] + b[j] + K] |= 1LL << i;         m2[a[i] + b[j] + K] |= 1LL << j;       }     }     int ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         for (int p = 0; p < n; p++) {           for (int q = 0; q < m; q++) {             int x = a[i] + b[j] + K;             int y = a[p] + b[q] + K;             int res1 = __builtin_popcountll(m1[x]) + __builtin_popcountll(m1[y]) -                        __builtin_popcountll(m1[x] & m1[y]);             int res2 = __builtin_popcountll(m2[x]) + __builtin_popcountll(m2[y]) -                        __builtin_popcountll(m2[x] & m2[y]);             ans = max(ans, res1 + res2);           }         }       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   int n, ans[100001][4], cnt = 0;   pair<int, int> t[4];   priority_queue<pair<int, int> > q;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       ++mp[x];     }     for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) {       q.push({it->second, it->first});     }     while (q.size() >= 3) {       ++cnt;       for (int i = 1; i <= 3; i++) {         t[i] = q.top();         q.pop();         ans[cnt][i] = t[i].second;       }       for (int i = 1; i <= 3; i++) {         t[i].first--;         if (t[i].first) {           q.push(t[i]);         }       }     }     cout << cnt <<   n ;     for (int i = 1; i <= cnt; i++) {       sort(ans[i] + 1, ans[i] + 4);       cout << ans[i][3] <<     << ans[i][2] <<     << ans[i][1] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   void qmax(int &x, int y) {     if (x < y) x = y;   }   void qmin(int &x, int y) {     if (x > y) x = y;   }   inline long long read() {     char s;     long long k = 0, base = 1;     while ((s = getchar()) !=  -  && s != EOF && !(isdigit(s)))       ;     if (s == EOF) exit(0);     if (s ==  - ) base = -1, s = getchar();     while (isdigit(s)) {       k = k * 10 + (s ^  0 );       s = getchar();     }     return k * base;   }   inline void write(int x) {     static char cnt, num[15];     cnt = 0;     if (!x) {       printf( 0 );       return;     }     for (; x; x /= 10) num[++cnt] = x % 10;     for (; cnt; putchar(num[cnt--] + 48))       ;   }   const int maxn = 1e5 + 100;   int a[maxn];   int n, l, r, l1, r1, la, ra;   int q(int x) {     printf( ? %d n , x);     fflush(stdout);     int y;     scanf( %d , &y);     return y;   }   void ret(int x) {     printf( ! %d n , x);     fflush(stdout);     exit(0);   }   int main() {     n = read();     if ((n / 2) % 2 == 1) {       ret(-1);       return 0;     }     memset(a, 0x3f3f3f3f, sizeof(a));     l = 1, r = n / 2;     la = q(l);     ra = q(n / 2 + l);     if (la == ra) {       ret(l);       return 0;     }     int mdl, mdr, mda, mdb;     while (l <= r) {       mdl = (l + r) / 2;       mdr = mdl + n / 2;       mda = q(mdl);       mdb = q(mdr);       if (mda == mdb) {         ret(mdl);         return 0;       }       if ((la < ra) ^ (mda < mdb))         r = mdl - 1;       else         l = mdl + 1;     }     ret(-1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, sx, sy, ex, ey, a, b;   vector<pair<int, long long>> node[100001];   vector<pair<long long, int>> X, Y;   vector<long long> dist;   vector<bool> done;   int mulMod(long long, long long);   int addMod(int, int);   void readArray(int *, int);   void printArray(int *, int);   void addEdgesFromStart() {     for (int i = 0; i < m; i++) {       long long w = min(abs(sx - X[i].first), abs(sy - Y[i].first));       node[0].push_back({X[i].second, w});     }   }   void addEdgesToEnd() {     for (int i = 0; i < m; i++) {       long long w = abs(ex - X[i].first) + abs(ey - Y[i].first);       node[X[i].second].push_back({m + 1, w});     }     long long w = abs(ex - sx) + abs(ey - sy);     node[0].push_back({m + 1, w});   }   void addEdges(vector<pair<long long, int>> &coord) {     for (int i = 1; i < coord.size(); i++) {       int id1 = coord[i - 1].second, id2 = coord[i].second;       long long w = coord[i].first - coord[i - 1].first;       node[id1].push_back({id2, w});       node[id2].push_back({id1, w});     }   }   struct comp {     bool operator()(const pair<long long, int> &x,                     const pair<long long, int> &y) {       return (x.first > y.first);     }   };   int main() {     cin >> n >> m;     cin >> sx >> sy >> ex >> ey;     for (int i = 1; i <= m; i++) {       cin >> a >> b;       X.push_back({a, i});       Y.push_back({b, i});     }     addEdgesFromStart();     addEdgesToEnd();     sort(X.begin(), X.end());     sort(Y.begin(), Y.end());     addEdges(X);     addEdges(Y);     priority_queue<pair<long long, int>, vector<pair<long long, int>>, comp> pq;     dist.resize(m + 2, LONG_MAX);     done.resize(m + 2, false);     dist[0] = 0;     pq.push({dist[0], 0});     while (!pq.empty()) {       pair<long long, int> curr = pq.top();       pq.pop();       if (curr.second == m + 1) {         dist[m + 1] = curr.first;         break;       }       if (done[curr.second]) continue;       int id = curr.second;       long long w = curr.first;       done[id] = true;       dist[id] = w;       for (auto edge : node[id])         if (dist[edge.first] > w + edge.second)           pq.push({w + edge.second, edge.first});     }     cout << dist[m + 1] << endl;     return 0;   }   int mulMod(long long a, long long b) {     a *= b;     a %= 1000000007;     return (int)a;   }   int addMod(int a, int b) {     long long c = a + b;     if (c >= 1000000007) {       c -= 1000000007;     }     return (int)c;   }   void readArray(int *nums, int n) {     for (int i = 0; i < n; i++) cin >> nums[i];   }   void printArray(int *nums, int n) {     for (int i = 0; i < n; i++) cout << nums[i] <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6;   long long int x[maxn];   long long int sum, ans;   map<long long int, long long int> table[27];   string s;   int main() {     for (int i = 1; i <= 26; i++) cin >> x[i];     cin >> s;     for (int i = 0; i < s.size(); i++) {       ans += table[s[i] -  a  + 1][sum];       sum += x[s[i] -  a  + 1];       table[s[i] -  a  + 1][sum]++;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   signed main() {     long long n;     cin >> n;     vector<long long> a(n);     vector<long long> ruio(n + 1, 0);     vector<long long> ruit(n + 1, 0);     long long ro = 0;     long long rt = 0;     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 1) {         ro++;       } else {         rt++;       }       ruio[i + 1] = ro;       ruit[i + 1] = rt;     }     long long ans = rt;     for (long long i = 0; i < n; i++) {       long long ltmp = 0;       for (long long j = 0; j < i; j++) {         ltmp = max(ltmp, ruio[j] + (ruit[i + 1] - ruit[j]));       }       long long rtmp = 0;       for (long long j = i; j < n; j++) {         rtmp = max(rtmp, (ruio[j + 1] - ruio[i]) + (ruit[n] - ruit[j]));       }       ans = max(ans, ltmp + rtmp);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double r, x1, y1, x2, y2;     cin >> r >> x1 >> y1 >> x2 >> y2;     double distance = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));     if (distance == 0) {       cout << 0;       return 0;     }     if (distance <= 2 * r) {       cout << 1;       return 0;     }     double midDistance = distance - (2 * r);     double x = midDistance / (2 * r);     int y = x;     int z = ceil(x);     if ((z - y) == 0) {       cout << y + 1;       return 0;     } else {       cout << y + 2;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int T, n, m, a[N], b[N], cnt, res[N << 1], v[N << 1], t, c[N << 1], pr[N],       sf[N], p[N];   long long ans;   void add(int x, int y) {     for (int i = x; i; i -= i & (-i)) c[i] += y;   }   int query(int x) {     int ans = 0;     for (int i = x; i <= t; i += i & (-i)) ans += c[i];     return ans;   }   void solve(int l, int r, int nl, int nr) {     if (l > r || nl > nr) return;     int mid = (l + r) / 2, ans = 1e9;     pr[nl - 1] = sf[nr + 1] = 0;     for (int i = nl; i <= nr; i++) pr[i] = pr[i - 1] + (a[i] > b[mid]);     for (int i = nr; i >= nl; i--) sf[i] = sf[i + 1] + (a[i] < b[mid]);     for (int i = nl; i <= nr; i++)       if (ans > pr[i - 1] + sf[i]) ans = pr[i - 1] + sf[i], p[mid] = i;     solve(l, mid - 1, nl, p[mid]), solve(mid + 1, r, p[mid], nr);   }   signed main() {     scanf( %d , &T);     while (T--) {       scanf( %d%d , &n, &m), cnt = ans = 0;       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       for (int i = 1; i <= m; i++) scanf( %d , &b[i]);       sort(b + 1, b + 1 + m), solve(1, m + 1, 1, n + 1);       for (int i = 1, j = 1; i <= n + 1; i++) {         while (j <= m && p[j] <= i) res[++cnt] = b[j], j++;         if (i <= n) res[++cnt] = a[i];       }       for (int i = 1; i <= cnt; i++) v[i] = res[i];       sort(v + 1, v + 1 + cnt), t = unique(v + 1, v + 1 + cnt) - v - 1,                                 fill(c + 1, c + 1 + t, 0);       for (int i = 1; i <= cnt; i++) {         res[i] = lower_bound(v + 1, v + 1 + t, res[i]) - v;         ans += query(res[i] + 1), add(res[i], 1);       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   long long fact[200005];   long long factinv[200005];   long long lgput(long long a, long long exp) {     long long rz = 1;     while (exp) {       if (exp & 1LL) {         --exp;         rz = (rz * 1LL * a) % mod;       } else {         exp >>= 1LL;         a = (a * 1LL * a) % mod;       }     }     return rz;   }   long long comb(long long a, long long b) {     return ((fact[a] * factinv[b]) % mod * factinv[a - b]) % mod;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long k, mxc = 0, n, m, a, b, i, j = 0, t;     cin >> n >> k;     fact[0] = fact[1] = 1;     for (i = 2; i <= n; ++i) fact[i] = (fact[i - 1] * i) % mod;     for (i = 1; i <= n; ++i) factinv[i] = lgput(fact[i], mod - 2);     factinv[0] = factinv[1];     if (k >= n) {       cout << 0;       return 0;     }     long long rz = 0;     k = n - k;     for (i = 0; i <= k; ++i) {       if (i & 1) {         rz = (rz + mod - comb(k, i) * lgput(k - i, n)) % mod;       } else {         rz = (rz + comb(k, i) * lgput(k - i, n)) % mod;       }     }     rz = (rz * comb(n, n - k)) % mod;     if (k != n)       cout << (rz * 2LL) % mod;     else       cout << rz;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2 * 1000 * 100 + 10;   int to[N], nxt[N], idx[N], tot;   int rnk[N], sz[N];   bool visited[N];   int minsz, center;   void add_edge(int u, int v) {     ++tot;     to[tot] = v;     nxt[tot] = idx[u];     idx[u] = tot;   }   int compute_size(int node, int parent) {     int s = 1;     for (int i = idx[node]; i != 0; i = nxt[i]) {       if (!visited[to[i]] && parent != to[i]) {         s += compute_size(to[i], node);       }     }     return sz[node] = s;   }   void compute_center(int node, int parent, int totsz) {     int upsz = totsz - sz[node];     int dnsz = -1;     for (int i = idx[node]; i != 0; i = nxt[i]) {       if (!visited[to[i]] && parent != to[i]) {         compute_center(to[i], node, totsz);         dnsz = max(dnsz, sz[to[i]]);       }     }     if (max(upsz, dnsz) < minsz) {       minsz = max(upsz, dnsz);       center = node;     }   }   void dfs(int node, int depth) {     int totsz = compute_size(node, 0);     minsz = INT_MAX;     compute_center(node, 0, totsz);     int c = center;     rnk[c] = depth;     visited[c] = true;     for (int i = idx[c]; i != 0; i = nxt[i]) {       if (!visited[to[i]]) {         dfs(to[i], depth + 1);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     tot = 0;     memset(nxt, 0, sizeof(nxt));     memset(idx, 0, sizeof(idx));     memset(visited, false, sizeof(visited));     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       add_edge(u, v);       add_edge(v, u);     }     dfs(1, 0);     for (int i = 1; i <= n; i++) {       cout << static_cast<char>(rnk[i] +  A ) <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct data {     int a, b, c, d;     data() {}     data(int a, int b, int c, int d) : a(a), b(b), c(c), d(d) {}   };   const int MAX = 100500;   data info[MAX];   int main() {     std::ios_base::sync_with_stdio(false);     int n, k;     cin >> n >> k;     info[0] = data(1, 2, 3, 5);     int mx;     for (int i = 1; i < n; i++) {       info[i] = data(info[i - 1].a + 6, info[i - 1].b + 6, info[i - 1].c + 6,                      info[i - 1].d + 6);     }     mx = info[n - 1].d * k;     cout << mx <<   n ;     for (int i = 0; i < n; i++) {       cout << info[i].a * k <<     << info[i].b * k <<     << info[i].c * k <<                << info[i].d * k <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[500005];   long long add[500005];   int main() {     int i, j, n, x, y, z, m;     long long sum;     scanf( %d , &n);     sum = 0;     a[0] = 0;     m = 1;     for (i = 0; i < n; i++) {       scanf( %d , &x);       if (x == 1) {         scanf( %d%d , &y, &z);         sum += y * z;         add[y - 1] += z;         printf( %lf n , sum * 1.0 / m);       }       if (x == 2) {         scanf( %d , &y);         a[m++] = y;         add[m - 1] = 0;         sum += y;         printf( %lf n , sum * 1.0 / m);       }       if (x == 3) {         sum -= a[m - 1];         sum -= add[m - 1];         a[m - 1] = 0;         add[m - 2] += add[m - 1];         add[m - 1] = 0;         m--;         printf( %lf n , sum * 1.0 / m);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int N = 1100;   int n;   vector<int> g[N];   int ed[N][3];   int ans[10 * N][3];   int ansSz;   void addAns(int v, int u, int x) {     ans[ansSz][0] = v + 1;     ans[ansSz][1] = u + 1;     ans[ansSz][2] = x;     ansSz++;   }   int getLeaf(int v, int par, int u) {     if (v == u) return -1;     if ((int)g[v].size() == 1) return v;     int res = -2;     for (int w : g[v]) {       if (w == par) continue;       int z = getLeaf(w, v, u);       if (z == -1) return -1;       res = z;     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int v, u, w;       scanf( %d%d%d , &v, &u, &w);       v--;       u--;       ed[i][0] = v;       ed[i][1] = u;       ed[i][2] = w;       g[v].push_back(u);       g[u].push_back(v);     }     for (int v = 0; v < n; v++) {       if ((int)g[v].size() == 2) {         printf( NO n );         return 0;       }     }     for (int i = 1; i < n; i++) {       int v = ed[i][0], u = ed[i][1], x = ed[i][2] / 2;       vector<int> vv, uu;       if ((int)g[v].size() == 1) {         vv.push_back(v);       } else {         for (int w : g[v]) {           int z = getLeaf(w, v, u);           if (z != -1) vv.push_back(z);           if ((int)vv.size() == 2) break;         }       }       if ((int)g[u].size() == 1) {         uu.push_back(u);       } else {         for (int w : g[u]) {           int z = getLeaf(w, u, v);           if (z != -1) uu.push_back(z);           if ((int)uu.size() == 2) break;         }       }       if ((int)uu.size() == 1) swap(vv, uu);       if ((int)uu.size() == 1) {         addAns(vv[0], uu[0], 2 * x);       } else if ((int)vv.size() == 1) {         addAns(vv[0], uu[0], x);         addAns(vv[0], uu[1], x);         addAns(uu[0], uu[1], -x);       } else {         addAns(vv[0], uu[0], x);         addAns(vv[1], uu[1], x);         addAns(vv[0], vv[1], -x);         addAns(uu[0], uu[1], -x);       }     }     printf( YES n );     printf( %d n , ansSz);     for (int i = 0; i < ansSz; i++)       printf( %d %d %d n , ans[i][0], ans[i][1], ans[i][2]);     return 0;   }


#include <bits/stdc++.h>   constexpr int MAXN = 1e5 + 5;   using namespace std;   int tot, n, cnt;   unordered_map<int, int> Map;   vector<int> vec;   vector<pair<string, int>> opt;   string s;   inline void discretization() {     sort(vec.begin(), vec.end());     cnt = unique(vec.begin(), vec.end()) - vec.begin();     for (int i = 0; i < cnt; i++) Map[vec[i]] = i;   }   struct Node {     Node *lson, *rson;     int cnt, l, r;     long long sum[5];   } Tree[MAXN << 1];   inline Node *newNode(Node *&root) { return root = &Tree[++tot]; }   inline void update(Node *root) {     root->cnt = root->lson->cnt + root->rson->cnt;     for (int i = 0; i < 5; i++)       root->sum[i] = root->lson->sum[i] +                      root->rson->sum[((i - root->lson->cnt) % 5 + 5) % 5];   }   inline void build(int L, int R, Node *root) {     root->l = L, root->r = R;     if (L == R) return;     int mid = (L + R) >> 1;     build(L, mid, newNode(root->lson)), build(mid + 1, R, newNode(root->rson));   }   inline void modify(int pos, int val, Node *root) {     if (root->l == pos && root->r == pos) {       root->cnt += val, root->sum[1] += val * vec[pos];       return;     }     int mid = (root->l + root->r) >> 1;     if (pos <= mid) modify(pos, val, root->lson);     if (pos > mid) modify(pos, val, root->rson);     update(root);   }   int main() {     std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1, x; i <= n; i++) {       cin >> s;       if (s ==  add )         cin >> x, opt.push_back({s, x}), vec.push_back(x);       else if (s ==  del )         cin >> x, opt.push_back({s, x});       else         opt.push_back({s, 0});     }     discretization(), build(0, cnt, Tree);     for (auto i : opt) {       if (i.first ==  add )         modify(Map[i.second], 1, Tree);       else if (i.first ==  del )         modify(Map[i.second], -1, Tree);       else         cout << Tree->sum[3] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   void add(int &a, int b) {     a += b;     if (a >= mod) a -= mod;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<int> dp(20002), pre(20002, 0);     int zero = 10000;     int ans = 0;     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       ++pre[zero];       for (int j = 0; j <= zero << 1; ++j) {         if (j >= x) add(dp[j], pre[j - x]);         if (j + x <= zero * 2) add(dp[j], pre[j + x]);       }       add(ans, dp[zero]);       if (i == n) continue;       pre = dp;       memset(&dp[0], 0, sizeof dp[0] * dp.size());     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   map<int, int> m;   string s;   long long ans;   bool flag;   void solve() {     cin >> n;     cin >> k;     vector<int> a(n);     int maxi = 0;     for (auto i = 0; i < n; i++) cin >> a[i];     ;     for (auto i = 0; i < n; i++) {       maxi = max(maxi, a[i]);       m[a[i]]++;       if (m[a[i]] >= k) {         cout << 0;         return;       }     }     long long ans = INT_MAX;     for (auto x = 1; x < 200000; x++) {       queue<int> q;       q.push(x);       long long an = 0;       int mul = 0;       int K = 0;       while (!q.empty() && K < k) {         int N = q.size();         while (N-- && K < k) {           int y = q.front();           q.pop();           int count = m[y];           if ((y * 2 - 1) < maxi) {             q.push(y * 2);             q.push(y * 2 + 1);           }           if (count > (k - K)) count = (k - K);           an += count * mul;           K += count;         }         mul++;       }       if (K == k) ans = min(an, ans);     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   const int S = 400004;   int last, tr[S][26], fail[S], len[S], tot = 0, eg = 1, h[S], nx[S << 1],                                         v[S << 1], e[S];   char c[S];   void insert(int &last, char c) {     c -=  a ;     int p = last, now = ++tot;     len[now] = len[last] + 1;     while (p != -1 && !tr[p][c]) {       tr[p][c] = now;       p = fail[p];     }     if (p == -1)       fail[now] = 0;     else {       int q = tr[p][c];       if (len[p] + 1 == len[q])         fail[now] = q;       else {         int w = ++tot;         len[w] = len[p] + 1;         fail[w] = fail[q];         for (int i = 0; i < 26; ++i) tr[w][i] = tr[q][i];         fail[q] = fail[now] = w;         while (p != -1 && tr[p][c] == q) {           tr[p][c] = w;           p = fail[p];         }       }     }     last = now;   }   inline void egadd(int uu, int vv) {     nx[++eg] = h[uu];     h[uu] = eg;     v[eg] = vv;   }   long long res = 0;   void dfs(int x) {     for (int i = h[x]; i; i = nx[i]) {       dfs(v[i]);       e[x] += e[v[i]];     }     res += (len[x] - len[fail[x]]) * 1ll * e[x] * e[x];   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       tot = last = 0;       fail[0] = -1;       res = 0;       scanf( %s , c + 1);       for (int i = 1; c[i]; ++i) insert(last, c[i]);       int p = 0;       for (int i = 1; c[i]; ++i) {         p = tr[p][c[i] -  a ];         e[p] = 1;       }       for (int i = 1; i <= tot; ++i) egadd(fail[i], i);       dfs(0);       printf( %lld n , res);       for (int i = 0; i <= tot; ++i) {         fail[i] = len[i] = 0;         h[i] = 0;         e[i] = 0;         for (int j = 0; j < 26; ++j) tr[i][j] = 0;       }       eg = 1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 + 3;   void read(int &x) {     char ch;     bool flag = 0;     for (ch = getchar(); !isdigit(ch) && ((flag |= (ch ==  - )) || 1);          ch = getchar())       ;     for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar())       ;     x *= 1 - 2 * flag;   }   string fuck[maxn];   int edge[105][105];   map<string, int> cou;   int a[105], b[105];   int out = -1;   vector<string> output;   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       string tmp;       cin >> tmp;       fuck[i] = tmp;       cou[tmp] = i;     }     for (int i = 0; i < m; i++) {       string c, d;       cin >> c >> d;       edge[cou[c]][cou[d]] = 1;       edge[cou[d]][cou[c]] = 1;     }     int aa[50];     for (int i = 0; i < (1 << n); i++) {       memset(aa, 0, sizeof(aa));       int top = 0;       for (int j = 0; j < n; j++) {         if (i & (1 << j)) {           aa[j] = 1;           top++;         }       }       bool f = 1;       for (int j = 0; j < n; j++) {         for (int k = j + 1; k < n; k++) {           if (aa[j] && aa[k] && edge[j][k]) {             f = 0;             break;           }         }       }       if (!f) continue;       if (top > out) {         out = top;         output.clear();         for (int j = 0; j < n; j++) {           if (aa[j]) output.push_back(fuck[j]);         }       }     }     cout << output.size() << endl;     sort(output.begin(), output.begin() + out);     for (int i = 0; i < output.size(); i++) cout << output[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 10000000;   int main() {     int n;     string s;     scanf( %d , &n);     cin >> s;     for (int i = 0; i < s.size(); i++) {       for (int j = 1; j < 25; j++) {         if (i + j * 4 < 100) {           if (s[i] ==  *  && s[i + j] ==  *  && s[i + j * 2] ==  *  &&               s[i + j * 3] ==  *  && s[i + j * 4] ==  * ) {             printf( yes );             return 0;           }         }       }     }     printf( no );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void print_array(T* arr, int num) {     for (int(i) = (0); (i) < (num); (i)++) cout << arr[i] <<    ;     cout <<   n ;   }   template <typename T>   void print_vector(vector<T> vec) {     for (int(i) = (0); (i) < (vec.size()); (i)++) cout << vec[i] <<    ;     cout <<   n ;   }   void setIO() {}   int n, x, p0[5010], b0[5010], arr[5010], b[5010], p[5010];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     setIO();     cin >> n;     for (int(i) = (0); (i) < (n); (i)++) {       cout <<  ?   << 0 <<     << i <<   n ;       cout.flush();       cin >> p0[i];     }     for (int(i) = (0); (i) < (n); (i)++) {       cout <<  ?   << i <<     << 0 <<   n ;       cout.flush();       cin >> b0[i];     }     int ans = 0;     bitset<5010> chk;     for (int(i) = (0); (i) < (n); (i)++) {       chk.reset();       int found = 1;       for (int(j) = (0); (j) < (n); (j)++) {         p[j] = b0[j] ^ i;         if (p[j] >= n || chk[p[j]]) {           found = 0;           break;         }         chk[p[j]] = 1;       }       if (!found) continue;       for (int(j) = (0); (j) < (n); (j)++) b[p[j]] = j;       for (int(j) = (0); (j) < (n); (j)++) {         if (p0[j] != (p[0] ^ b[j]) || b0[j] != (p[j] ^ b[0])) {           found = 0;           break;         }       }       if (found) {         ans++;         if (ans == 1)           for (int(j) = (0); (j) < (n); (j)++) arr[j] = p[j];       }     }     cout <<  !  <<   n  << ans <<   n ;     for (int(i) = (0); (i) < (n); (i)++) cout << arr[i] <<    ;     cout.flush();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     double L, v1, v2;     cin >> n >> L >> v1 >> v2 >> k;     double p = 2 * (n / k - (n % k == 0)) + 1;     printf( %.10f , double(L * (p * v2 + v1)) / double(v2 * (p * v1 + v2)));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tt;     cin >> tt;     while (tt--) {       int k;       cin >> k;       string s, a, b;       cin >> s >> a >> b;       int n = (int)(s).size();       vector<int> x;       vector<int> p(k, -1);       bool goodx = true;       for (int i = 0; i < n; ++i) {         int c = s[i] -  a ;         if (p[c] != -1) {           if (p[c] < a[i] -  a ) {             goodx = false;             break;           } else if (p[c] == a[i] -  a ) {             continue;           } else {             goodx = true;             break;           }         }         p[c] = a[i] -  a ;         x.push_back(i);       }       bool found = false;       for (int u = 0; u <= (int)(x).size(); ++u) {         if (u == (int)(x).size() && !goodx) {           continue;         }         p.assign(k, -1);         vector<bool> occ(k, false);         bool ok = true;         for (int i = 0; i < u; ++i) {           if (occ[a[x[i]] -  a ]) {             ok = false;             break;           }           occ[a[x[i]] -  a ] = true;           p[s[x[i]] -  a ] = a[x[i]] -  a ;         }         if (u < (int)(x).size()) {           int pos = a[x[u]] -  a  + 1;           while (pos < k && occ[pos]) {             ++pos;           }           if (pos == k) {             ok = false;           } else {             p[s[x[u]] -  a ] = pos;             occ[pos] = true;           }         }         if (!ok) {           continue;         }         int pos = 0;         for (int i = 0; i < n; ++i) {           if (p[s[i] -  a ] != -1) {             continue;           }           while (occ[pos]) {             ++pos;           }           p[s[i] -  a ] = pos;           occ[pos] = true;         }         string res =   ;         for (int i = 0; i < n; ++i) {           res += char(p[s[i] -  a ] +  a );         }         if (res > b) {           continue;         }         found = true;         cout <<  YES n ;         for (int i = 0; i < k; ++i) {           if (p[i] != -1) {             continue;           }           while (occ[pos]) {             ++pos;           }           p[i] = pos;           occ[pos] = true;         }         for (int i = 0; i < k; ++i) {           cout << char(p[i] +  a );         }         cout <<   n ;         break;       }       if (!found) {         cout <<  NO n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     long long x, y;     int id;   };   long long judge(Point p0, Point p1, Point p2) {     return (p1.x - p0.x) * (p2.y - p1.y) - (p2.x - p1.x) * (p1.y - p0.y);   }   long long cmp(Point a, Point b) {     if (a.x == b.x) return a.y < b.y;     return a.x < b.x;   }   Point s[100005];   int main() {     int n;     while (~scanf( %d , &n)) {       for (int i = 1; i <= n; i++)         scanf( %lld%lld , &s[i].x, &s[i].y), s[i].id = i;       sort(s + 1, s + 1 + n, cmp);       int flag, ans;       int a = 0, b = 0, c = 0;       for (int i = 3; i <= n; i++) {         flag = 0, ans = 0;         if (judge(s[1], s[2], s[i]) == 0) ans++;         if (ans == 0) {           a = s[1].id, b = s[2].id, c = s[i].id;           flag = 1;           break;         }       }       printf( %d %d %d n , a, b, c);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int clique_size(vector<int> *graph, vector<int> &govs, int *visited,                   int starting) {     visited[starting] = 1;     int size = 1;     for (int i = 0; i < graph[starting].size(); i++) {       if (!visited[graph[starting][i]]) {         size += clique_size(graph, govs, visited, graph[starting][i]);       }     }     return size;   }   int main(int argc, char *argv[]) {     vector<int> graph[1001];     vector<int> govs;     int visited[1001] = {0};     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < k; i++) {       int c;       cin >> c;       govs.push_back(c);     }     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       graph[u].push_back(v);       graph[v].push_back(u);     }     int connected_points = 0;     int max_state_size = 0;     int answer = 0;     for (int i = 0; i < k; i++) {       int count = clique_size(graph, govs, visited, govs[i]);       connected_points += count;       max_state_size = (count > max_state_size) ? count : max_state_size;       answer += count * (count - 1) / 2;     }     int remaining = n - connected_points;     answer -= max_state_size * (max_state_size - 1) / 2;     max_state_size += remaining;     answer += max_state_size * (max_state_size - 1) / 2;     cout << answer - m <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long s = 0;     bool f = 0;     char ch =    ;     while (!isdigit(ch)) {       f |= (ch ==  - );       ch = getchar();     }     while (isdigit(ch)) {       s = (s << 3) + (s << 1) + (ch ^ 48);       ch = getchar();     }     return (f) ? (-s) : (s);   }   inline void write(long long x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x < 10) {       putchar(x +  0 );       return;     }     write(x / 10);     putchar((x % 10) +  0 );     return;   }   const int N = 100005;   int n, Num, a[N];   struct Zidianshu {     int Trie[N * 25][25], cnt;     int End[N * 25];     inline void Init() { cnt = 0; }     inline void Insert(int Num) {       int i, Root = 0;       for (i = 0; i <= 23; i++) {         int oo = (Num & (1 << i)) >> i;         if (!Trie[Root][oo]) Trie[Root][oo] = ++cnt;         Root = Trie[Root][oo];       }       End[Root]++;     }     inline int Query(int Num, int Want) {       int i, Root = 0;       for (i = 0; i <= 23; i++) {         int oo = ((Want & (1 << i)) >> i) ^ ((Num & (1 << i)) >> i);         if (!Trie[Root][oo]) return 0;         Root = Trie[Root][oo];       }       return End[Root];     }   } Trie;   int main() {     Trie.Init();     int i;     long long ans = 0;     n = read();     Num = read();     for (i = 1; i <= n; i++) {       a[i] = read();       ans += 1ll * Trie.Query(a[i], Num);       Trie.Insert(a[i]);     }     write(ans), putchar(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e9;   long long sum(long long l, long long r) { return (l + r) * (r - l + 1) / 2; }   int main() {     long long n, H;     cin >> n >> H;     long long l = H, r = 2e9, ans = -1;     while (l <= r) {       long long mid = (l + r) >> 1;       if (n >= sum(H, mid) + sum(1, mid) - mid)         ans = mid, l = mid + 1;       else         r = mid - 1;     }     if (ans != -1) {       cout << 2 * ans - H +                   ((n - sum(H, ans) - sum(1, ans) + ans) + ans - 1) / ans            << endl;     } else {       l = 1, r = min(H, N);       while (l <= r) {         long long mid = (l + r) >> 1;         if (n >= sum(1, mid))           ans = mid, l = mid + 1;         else           r = mid - 1;       }       cout << ans + (n - sum(1, ans) + ans - 1) / ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d n , &n);     string str;     getline(cin, str);     int ans = 0;     int subans = 0;     for (int i = 0; i < n; i++) {       if (str[i] !=    ) {         int ascii = (int)str[i];         if (ascii >= 65 && ascii <= 90) {           subans++;         }         ans = max(ans, subans);       } else {         subans = 0;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long s, x;   string S, X;   long long dp[64][2];   long long d__p(int i, int st) {     if (i == S.size() && st)       return 0;     else if (i == S.size())       return 1;     long long &res = dp[i][st];     if (res != -1) return res;     res = 0;     int x = S[i] -  0 ;     int y = X[i] -  0 ;     for (int a = 0; a <= 1; a++) {       for (int b = 0; b <= 1; b++) {         int remember = (a + b + st) > 1;         int Sum = a + b + st;         Sum %= 2;         int Xor = a ^ b;         if (Sum != x || Xor != y) continue;         res += d__p(i + 1, remember);       }     }     return res;   }   int main() {     cin >> s >> x;     for (int i = 63; i >= 0; i--) {       if (s & (1LL << i))         S +=  1 ;       else         S +=  0 ;       if (x & (1LL << i))         X +=  1 ;       else         X +=  0 ;     }     reverse(S.begin(), S.end());     reverse(X.begin(), X.end());     memset(dp, -1, sizeof dp);     cout << d__p(0, 0) - 2 * (s == x);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class DREAD {     friend int fread();     static const int buff_max = 20000000 + 10;     char buf[buff_max], *pt;       public:     void clear() {       for (; isspace(*pt); ++pt)         ;     }     void Init() {       buf[fread(buf, 1, buff_max, stdin)] = EOF;       pt = buf;     }     bool eoln() { return *pt ==   n ; }     inline bool eof() { return *pt == EOF; }     int Int() {       bool pos = 1;       int res = 0;       for (; !isdigit(*pt) && *pt !=  -  && !eof(); ++pt)         ;       if (*pt ==  - ) pos = 0, ++pt;       for (; isdigit(*pt); ++pt) res = res * 10 + (*pt -  0 );       return pos ? res : -res;     }   } READ;   const int N_MAX = 5000 + 10;   int N, M, seq[N_MAX], bad[N_MAX];   namespace Nwork {   int gcd[N_MAX];   int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }   int p[N_MAX], e[N_MAX], cnt;   int exist(int p) { return *lower_bound(bad + 1, bad + M + 1, p) == p ? -1 : 1; }   int calc(int x) {     cnt = 0;     for (int i = 2, k = int(sqrt(x)); i <= k; ++i) {       if (x == 1) break;       if (x % i == 0) {         p[++cnt] = i;         for (e[cnt] = 0; x % i == 0; x /= i) ++e[cnt];       }     }     if (x != 1) p[++cnt] = x, e[cnt] = 1;     int ret = 0;     for (int i = 1; i <= cnt; ++i) ret += exist(p[i]) * e[i];     return ret;   }   void main() {     gcd[1] = seq[1];     for (int i = 2; i <= N; ++i) gcd[i] = GCD(gcd[i - 1], seq[i]);     sort(bad + 1, bad + M + 1);     for (int r = N; r >= 1; --r)       if (calc(gcd[r]) < 0)         for (int i = 1; i <= r; ++i) {           seq[i] /= gcd[r];           gcd[i] /= gcd[r];         }     int ret = 0;     for (int i = 1; i <= N; ++i) ret += calc(seq[i]);     printf( %d n , ret);   }   }  // namespace Nwork   namespace Ninit {   void init() {     N = READ.Int(), M = READ.Int();     for (int i = 1; i <= N; ++i) seq[i] = READ.Int();     for (int i = 1; i <= M; ++i) bad[i] = READ.Int();   }   }  // namespace Ninit   int main() {     READ.Init();     Ninit::init();     Nwork::main();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   enum { MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009 };   template <typename T>   ostream &operator<<(ostream &cout, vector<T> &a) {     for (size_t i = 0; i < a.size(); ++i) cout << a[i] <<    ;     return cout;   }   template <typename T>   ostream &operator<<(ostream &cout, vector<vector<T> > &a) {     for (size_t i = 0; i < a.size(); ++i) cout << a[i] << endl;     return cout;   }   int p[256];   inline bool eq(int a, int b) { return p[a] == p[b]; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     for (int i = 0; i < sizeof(p) / sizeof(*p); ++i) {       p[i] = i;     }     p[ 1 ] = p[ i ] = p[ l ];     p[ 0 ] = p[ o ];     for (int i =  A ; i <=  Z ; ++i) {       p[i] = p[i -  A  +  a ];     }     string s;     cin >> s;     int n;     cin >> n;     string a;     for (int i = 0; i < n; ++i) {       cin >> a;       if (a.size() != s.size()) {         continue;       }       bool bad = 1;       for (int j = 0; j < a.size(); ++j) {         if (!eq(a[j], s[j])) {           bad = 0;           break;         }       }       if (bad) {         cout <<  No  <<   n ;         return 0;       }     }     cout <<  Yes  <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const double err = 1e-12;   const double PI = 3.141592653589793;   const int N = 1e5 + 5;   int n;   vector<int> res;   void solve() {     cin >> n;     if (n & 1) {       cout << 1 <<    ;       n--;       for (int i = 2; i <= n; i += 2) cout << i + 1 <<     << i <<    ;       cout << endl;     } else {       cout << n <<    ;       n--;       for (int i = 2; i <= (n - 1); i += 2) cout << i + 1 <<     << i <<    ;       cout << 1 << endl;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 55;   long long f[maxn][maxn][maxn][maxn];   long long pw[maxn];   int c[maxn];   void init() {     f[0][0][0][0] = 1;     pw[0] = 1;     for (int i = 1; i < maxn; i++) pw[i] = (pw[i - 1] * 2ll) % mod;   }   long long cal(int x, bool xx) { return x ? pw[x - 1] : xx; }   void cal_ans(int ew, int ow, int eb, int ob, int now, long long& ret) {     if (now != 0 && ew)       (ret += f[ew - 1][ow][eb][ob] * pw[ew + ow - 1 + eb] % mod * cal(ob, 0) %               mod) %= mod;     if (now != 0 && ow)       (ret += f[ew][ow - 1][eb][ob] * pw[ew + ow - 1 + eb] % mod * cal(ob, 1) %               mod) %= mod;     if (now != 1 && eb)       (ret += f[ew][ow][eb - 1][ob] * pw[eb + ob - 1 + ew] % mod * cal(ow, 0) %               mod) %= mod;     if (now != 1 && ob)       (ret += f[ew][ow][eb][ob - 1] * pw[eb + ob - 1 + ew] % mod * cal(ow, 1) %               mod) %= mod;   }   int main(int argc, const char** argv) {     init();     int n, p;     cin >> n >> p;     for (int i = 1; i <= n; i++) scanf( %d , c + i);     long long ans = 0;     for (int i = 1; i <= n; i++)       for (int ew = 0; ew <= i; ew++)         for (int ow = 0; ow + ew <= i; ow++)           for (int eb = 0; ow + ew + eb <= i; eb++) {             int ob = i - ow - ew - eb;             cal_ans(ew, ow, eb, ob, c[i], f[ew][ow][eb][ob]);             if (i == n && ((ow + ob) & 1) == p) (ans += f[ew][ow][eb][ob]) %= mod;           }     cout << ans << endl;     return 0;   }