#include <bits/stdc++.h>   using namespace std;   const int N = 505, mod = 1e9 + 7;   int n, m, e[N][N], f[N][N], g[N][N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = (1); i <= (n); i++)       for (int j = (1); j <= (n); j++) cin >> e[i][j];     for (int i = (1); i <= (n); i++) g[i][i] = f[i][i] = 1;     for (int len = (1); len <= (n); len++)       for (int l = (1); l <= (n - len + 1); l++) {         int r = l + len - 1;         for (int k = (l); k <= (r - 1); k++)           if (e[l][r]) (g[l][r] += (long long)f[l][k] * f[k + 1][r] % mod) %= mod;         for (int k = (l + 1); k <= (r); k++)           (f[l][r] += (long long)g[l][k] * f[k][r] % mod) %= mod;       }     cout << f[1][n] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   const int MAXM = 100010;   const int INF = 1000000000;   int dist[MAXN], dp[MAXN];   pair<int, int> par[MAXN];   bool marked[MAXM];   vector<pair<int, int> > edges[MAXN];   queue<int> q;   vector<pair<int, int> > v;   int x[MAXM], y[MAXM], z[MAXM];   int n, m;   void bfs(int s) {     for (int i = 0; i < n; i++) dist[i] = INF;     dist[s] = 0;     q.push(s);     while (!q.empty()) {       int v = q.front();       q.pop();       for (int i = 0; i < edges[v].size(); i++) {         int u = edges[v][i].first;         if (dist[u] > dist[v] + 1) {           dist[u] = dist[v] + 1;           q.push(u);         }       }     }   }   int main() {     cin >> n >> m;     int working = 0;     for (int i = 0; i < m; i++) {       cin >> x[i] >> y[i] >> z[i];       x[i]--, y[i]--;       working += z[i];       edges[x[i]].push_back(pair<int, int>(y[i], i));       edges[y[i]].push_back(pair<int, int>(x[i], i));     }     bfs(0);     for (int i = 0; i < n; i++) {       v.push_back(pair<int, int>(dist[i], i));       dp[i] = INF;     }     sort(v.begin(), v.end());     dp[0] = 0;     for (int i = 0; i < n; i++) {       int u = v[i].second;       for (int j = 0; j < edges[u].size(); j++) {         int q = edges[u][j].first;         int w = 1 - z[edges[u][j].second];         if (dist[q] == dist[u] + 1 && dp[q] > dp[u] + w) {           par[q] = pair<int, int>(u, edges[u][j].second);           dp[q] = dp[u] + w;         }       }     }     int now = n - 1;     while (now != 0) {       marked[par[now].second] = true;       now = par[now].first;     }     cout << working - dist[n - 1] + dp[n - 1] * 2 << endl;     for (int i = 0; i < m; i++)       if (marked[i] ^ z[i])         cout << x[i] + 1 <<     << y[i] + 1 <<     << 1 - z[i] << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long inf = 0x3f3f3f3f3f3f3f3f;   const long long mod = 998244353;   const int N = 2e5 + 10;   mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());   int n;   int z[100][2];   int qry(int i, int j) {     cout <<  ?   << i <<     << j << endl;     int ans;     cin >> ans;     return ans;   }   int p[N];   int f(int i) {     if (p[i] != -1) return p[i];     if (i != z[0][0])       p[i] = qry(i, z[0][0]);     else       p[i] = qry(i, z[0][1]);     for (int j = 1; j < 11; j++) {       if (i != z[j][0])         p[i] &= qry(i, z[j][0]);       else         p[i] &= qry(i, z[j][1]);     }     return p[i];   }   int main() {     scanf( %d , &n);     memset(p, -1, sizeof(p));     while (1) {       bool ok = 1;       for (int i = 0; i < 11; i++)         if (!z[i][0]) ok = 0;       if (ok) break;       int i = uniform_int_distribution<int>((1), (n))(mt),           j = uniform_int_distribution<int>((1), (n))(mt);       while (i == j)         i = uniform_int_distribution<int>((1), (n))(mt),         uniform_int_distribution<int>((1), (n))(mt);       int tmp = qry(i, j);       for (int u = 0; u < 11; u++)         if (!(tmp >> u & 1)) z[u][0] = i, z[u][1] = j;     }     int idx = 1, val = f(idx);     for (int i = 2; i <= n && val != 0; i++) {       if (qry(i, idx) != val) continue;       idx = i, val = f(i);     }     for (int i = 1; i <= n; i++) {       if (p[i] == -1) p[i] = qry(idx, i);     }     cout <<  ! ;     for (int i = 1; i <= n; i++) cout <<     << p[i];     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, T;   double dp[5001][5001];   int p[5001], t[5001];   double quickpow(double x, int y) {     double res = 1;     while (y) {       if (y & 1) res *= x;       x *= x;       y >>= 1;     }     return res;   }   int main() {     cin >> n >> T;     dp[0][0] = 1;     for (int i = 0; i < n; i++) scanf( %d%d , &p[i], &t[i]);     double ans = 0;     for (int i = 0; i < n; i++) {       double pp = p[i] * 0.01;       double now = 0;       double r = quickpow(1 - pp, t[i] - 1) * pp;       double r2 = quickpow(1 - pp, t[i] - 1);       for (int j = 0; j < T; j++) {         now *= (1 - pp);         now += dp[i][j] * pp;         if (j + 1 >= t[i]) {           now -= dp[i][j + 1 - t[i]] * r;           dp[i + 1][j + 1] = now + dp[i][j + 1 - t[i]] * r2;         } else {           dp[i + 1][j + 1] = now;         }       }       for (int j = 0; j <= T; j++) ans += dp[i + 1][j];     }     printf( %.12f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 2;   int n, l;   long long a[N], f[N];   int main() {     scanf( %d %d , &n, &l);     for (int i = 1; i < n; ++i) scanf( %lld , &a[i]), a[i] += a[i - 1];     long long ans = LLONG_MAX;     for (int i = l; i < n; ++i) ans = min(ans, a[i] - a[i - l]);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, i, j, ans = 0;   long long a, b;   const long long M = (long long)1E9 + 7;   long long power(long long x, long long y) {     long long res = 1;     x %= M;     while (y) {       if (y % 2) res = (res * x) % M;       y = y >> 1;       x = (x * x) % M;     }     return res % M;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     b = power(2LL, (long long)s.length() - 1);     long long x = 1;     for (i = (long long)s.length() - 1; i >= 0; i--) {       if (s[i] ==  1 ) a += x;       x *= 2;       if (x > M) x %= M;       a %= M;     }     cout << (a * b) % M;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005];   map<long long, int> ma;   int main() {     long long b1, q, m, l;     cin >> b1 >> q >> l >> m;     while (m--) {       long long x;       cin >> x;       ma[x] = 1;     }     int ans = 0, i;     for (i = 1; i < 100; i++) {       if (abs(b1) > l) break;       if (!ma[b1]) ans++;       b1 *= q;     }     if (ans < 49)       cout << ans << endl;     else       cout <<  inf  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int nuts, divis, maxsec, capacity, boxees = 0;     cin >> maxsec >> nuts >> divis >> capacity;     while (nuts > 0) {       boxees++;       nuts -= ((min(maxsec, divis + 1)) * capacity);       divis -= ((min(maxsec, divis + 1)) - 1);     }     cout << boxees << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int vis[100010], h[100100];   vector<int> res;   set<int> q, off;   int a[100100];   char s[100010][2];   int main() {     int i, j, z, T, d;     while (cin >> n >> m) {       q.clear();       res.clear();       off.clear();       memset(vis, 0, sizeof(vis));       for (i = 1; i <= m; i++) {         scanf( %s%d , s[i], &a[i]);         if (s[i][0] ==  -  && !vis[a[i]]) q.insert(a[i]);         if (s[i][0] ==  +  && !vis[a[i]]) off.insert(a[i]);         vis[a[i]]++;       }       memset(vis, 0, sizeof(vis));       if (q.size() != 0) {         set<int>::iterator it;         for (it = off.begin(); it != off.end(); it++) vis[*it]++;         off.clear();       }       for (i = 1; i <= m; i++) {         if (s[i][0] ==  +  && q.size() != 0) {           set<int>::iterator it;           for (it = off.begin(); it != off.end(); it++) vis[*it]++;           off.clear();         }         if (s[i][0] ==  - ) {           q.erase(a[i]);           off.insert(a[i]);         } else {           if (off.count(a[i]) != 0) off.erase(a[i]);           q.insert(a[i]);         }         if (q.size() != 0) {           set<int>::iterator it;           for (it = off.begin(); it != off.end(); it++) vis[*it]++;           off.clear();         }       }       for (i = 1; i <= n; i++) {         if (!vis[i]) res.push_back(i);       }       printf( %d n , res.size());       for (i = 0; i < res.size(); i++) {         if (i) printf(   );         printf( %d , res[i]);       }       if (res.size() != 0) puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   long long fac[N], infac[N];   int n, m;   long long poww(long long b, long long p) {     if (p == 0) return 1;     if (p & 1) return (b * poww(b, p - 1)) % m;     return poww((b * b) % m, p / 2);   }   long long npk(int n, int k) { return (fac[n] * infac[n - k]) % m; }   long long nck(int n, int k) {     return (((fac[n] * infac[n - k]) % m) * infac[n - k]) % m;   }   int main() {     cin >> n >> m;     fac[0] = infac[0] = 1;     for (int i = 1; i <= n; i++) {       fac[i] = (i * fac[i - 1]) % m;       infac[i] = poww(fac[i], m - 2);     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       long long a = n - i + 1;       a = (a * fac[i]) % m;       ans = (ans + a * fac[n - i + 1]) % m;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int result;     string input;     cin >> input;     set<string> sinput;     sinput.insert(input);     for (int i = input.size() - 1; i >= 0; --i) {       input = input[input.size() - 1] + input;       input.pop_back();       sinput.insert(input);     }     result = sinput.size();     printf( %d n , result);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   long long n, m, A, cf, cm, maxForce = -1, minSkill, minIdx, i, a[N], b[N];   pair<long long, int> sum[N];   inline long long query(long long money, int limit) {     long long l = sum[1].first, r = A, mid;     if (limit <= 1) {       return A;     }     while (l < r) {       mid = (l + r + 1) / 2;       int x = upper_bound(b + 1, b + limit, mid) - b - 1;       if (mid * x - sum[x].first <= money)         l = mid;       else         r = mid - 1;     }     return r;   }   int main() {     cin >> n >> A >> cf >> cm >> m;     for (i = 1; i <= n; ++i) {       scanf( %d , a + i);       sum[i].first = a[i];       sum[i].second = i;     }     sort(sum + 1, sum + n + 1);     for (i = 1; i <= n; ++i) {       b[i] = sum[i].first;       sum[i].first += sum[i - 1].first;     }     b[n + 1] = A;     for (i = n + 1; i >= 1; --i) {       m -= A - b[i];       if (m < 0) {         break;       }       long long x = query(m, i);       long long force = cf * (n - i + 1) + cm * x;       if (maxForce < force) {         maxForce = force;         minIdx = i;         minSkill = x;       }     }     for (i = n; i >= minIdx; --i) {       a[sum[i].second] = A;     }     cout << maxForce << endl;     for (i = 1; i <= n; ++i) {       printf( %d  , max(a[i], minSkill));     }     return 0;   }


#include <bits/stdc++.h>        #define dumb ios_base::sync_with_stdio(false);cin.tie(NULL);           typedef  long long ll;        using namespace std;      #define modulo 1000000007;      bool isprime(long long n)   {       for(long long int i=2;i*i<=n;i++)       {           if(n%i==0)               return 0;       }       return 1;   }   long long gcd(long long int a, long long int b)   {     if (b == 0)       return a;     return gcd(b, a % b);   }      // Function to return LCM of two numbers   long long lcm(int a, int b)   {       return (a / gcd(a, b)) * b;   }         ll ncr(ll n,ll k)   {       ll res = 1;       if (k > n - k)           k = n - k;       for (ll i = 0; i < k; ++i) {           res *= (n - i);           res /= (i + 1);       }       return res;   }      map<int,int> m;      void solve()   {     int n;     cin>>n;        auto it=m.lower_bound(n);     if(it->first==n)     {       cout<<it->second<<endl;       return;     }     else     {       int diff=it->first-n;       if(diff==1)         cout<<it->second+1<<endl;       else         cout<<it->second<<endl;              return;     }      return;    }                     int main()   {     dumb;       int t=1;       cin>>t;       int i=1;       m[0]=0;       int sum=0;       while(1)       {         m[sum+i]=i;         if(sum+i>1000000)           break;         sum+=i;         i++;       }       while(t--)       {         //cout<< in ;          solve();        }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, size_t N>   void PRINT_ARRAY(const T (&a)[N], int n = -1) {     if (!n) n = N;     for (int i = 0; i < n; i++) cout << a[i] <<    ;     cout <<   n ;   }   template <typename T, size_t N, size_t M>   void PRINT_ARRAY(const T (&a)[N][M], int n, int m) {     for (int i = 0; i < n; i++) PRINT_ARRAY(a[i], m);     cout <<   n ;   }   long long arr[3005], cost[3005], lessc, more, ans;   int n;   void solve() {     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i];     for (int i = 0; i < n; i++) cin >> cost[i];     ans = (int)(1e9 + 7);     for (int i = 1; i < n - 1; i++) {       lessc = (int)(1e9 + 7);       more = (int)(1e9 + 7);       for (int j = 0; j < i; j++)         if (arr[i] > arr[j]) lessc = min(lessc, cost[j]);       for (int j = i + 1; j < n; j++)         if (arr[j] > arr[i]) more = min(more, cost[j]);       ans = min(ans, cost[i] + lessc + more);     }     cout << (ans == (int)(1e9 + 7) ? -1 : ans);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     solve();   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   bitset<2020> mat[2020];   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %d%d , &N, &M);       vector<pair<int, int> > E;       int deg[2020] = {};       for (int i = 1; i <= M; i++) {         int x, y;         scanf( %d%d , &x, &y);         deg[x]++;         deg[y]++;         E.push_back(pair<int, int>(x, y));       }       int ok = 1;       for (int i = 1; i <= N; i++)         if (deg[i] & 1) ok = 0;       if (ok) {         puts( 1 );         for (int i = 1; i <= N; i++) printf( 1  );         puts(  );       } else {         for (int i = 1; i <= N; i++) mat[i].reset();         for (int i = 1; i <= N; i++)           if (deg[i] & 1) mat[i][i] = 1;         for (pair<int, int> e : E) {           int x = e.first, y = e.second;           mat[x][y] = !mat[x][y];           mat[y][x] = !mat[y][x];         }         int V[2020] = {};         for (int i = 1; i <= N; i++) V[i] = (deg[i] & 1);         int now = 1;         int base[2020];         for (int i = 1; i <= N; i++) {           int f = -1;           for (int j = now; j <= N; j++)             if (mat[j][i]) {               f = j;               break;             }           if (f == -1) continue;           swap(mat[f], mat[now]);           swap(V[f], V[now]);           for (int j = now + 1; j <= N; j++) {             if (mat[j][i]) {               mat[j] ^= mat[now];               V[j] ^= V[now];             }           }           base[now] = i;           ++now;         }         --now;         int res[2020] = {};         for (int i = now; i; i--) {           int p = base[i];           res[p] = V[i];           if (res[p]) {             for (int j = 1; j < i; j++)               if (mat[j][p]) V[j] ^= 1;           }         }         puts( 2 );         for (int i = 1; i <= N; i++) printf( %d  , res[i] + 1);         puts(  );       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000007;   const long long MOD = 1000000007;   void solve_test() {     int n;     cin >> n;     vector<int> arr(n);     vector<int> ct(101);     for (int i = 0; i < n; i++) {       cin >> arr[i];       ct[arr[i]]++;     }     int max_val = -1;     int max_freq = -1;     for (int i = 1; i <= 100; i++) {       if (ct[i] > max_freq) {         max_freq = ct[i];         max_val = i;       }     }     unordered_map<int, int> um;     int ans = 0;     for (int i = 1; i <= 100; i++) {       if (max_val == i) continue;       um.clear();       int st = 0;       um[0] = -1;       for (int j = 0; j < n; j++) {         if (arr[j] == i) {           st++;         } else if (arr[j] == max_val) {           st--;         }         if (um.find(st) == um.end()) {           um[st] = j;         } else {           ans = max(ans, j - um[st]);         }       }     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int tests;     tests = 1;     while (tests--) {       solve_test();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, T;   char str[15], temp[15];   int main() {     int i, j, k;     scanf( %s%s , str, temp);     i = strlen(str);     sort(str, str + i);     if (str[0] ==  0 ) {       do {         if (str[0] !=  0 ) break;       } while (next_permutation(str, str + i));     }     if (strcmp(str, temp) == 0)       printf( OK n );     else       printf( WRONG_ANSWER n );     scanf(   );   }


#include <bits/stdc++.h>   using namespace std;   void init() {}   const int N = (int)1e6 + 34;   const long long INF = (long long)1e9 + 34;   int n, m;   int a[555][555];   int c[555], r[555];   int main() {     init();     int mxr = -N, mnr = N, mxc = -N, mnc = N;     cin >> n >> m;     int sum = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];         sum += a[i][j];       }     }     if (n == 1) {       for (int j = 0; j < m; j++) {         c[j] = a[0][j];       }       r[0] = 0;     }     if (m == 1) {       for (int i = 0; i < n; i++) {         r[i] = a[i][0];       }       c[0] = 0;     }     if (max(n, m) > 1) {       c[0] = 0;       for (int i = 0; i < n; i++) r[i] = a[i][0];       for (int j = 1; j < m; j++)         for (int i = 0; i < n; i++) {           c[j] = a[i][j] - r[i];         }     }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (a[i][j] != r[i] + c[j]) {           cout <<  -1 n ;           return 0;         }       }     for (int i = 0; i < n; i++) {       mnr = min(mnr, r[i]);       mxr = max(mxr, r[i]);     }     for (int j = 0; j < m; j++) {       mxc = max(mxc, c[j]);       mnc = min(mnc, c[j]);     }     if (mnr + mnc < 0) {       cout <<  -1 n ;       return 0;     }     int dr = 0;     int dc = 0;     if (mnr < 0) {       dc = mnr;       dr = -dc;     } else if (mnc < 0) {       dr = mnc;       dc = -dr;     }     while (n > m && mnr + dr > 0) {       dr--;       dc++;     }     while (n < m && mnc + dc > 0) {       dr++;       dc--;     }     int num = 0;     for (int i = 0; i < n; i++) num += r[i] + dr;     for (int j = 0; j < m; j++) num += c[j] + dc;     cout << num <<   n ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < r[i] + dr; j++) cout <<  row   << i + 1 <<   n ;     }     for (int j = 0; j < m; j++) {       for (int i = 0; i < c[j] + dc; i++) cout <<  col   << j + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, v;     scanf( %d%d%d , &n, &m, &v);     int spec = 1;     if (m < n - 1 || m > (n - 1) * (n - 2) / 2 + 1) {       printf( -1 n );       return 0;     }     if (spec == v) spec++;     printf( %d %d n , v, spec);     m--;     for (int i = 1; i <= n; i++) {       if (i == spec) continue;       for (int j = i + 1; j <= n; j++) {         if (j == spec) continue;         printf( %d %d n , i, j);         m--;         if (m == 0) return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string str[1005];   int tim[1005][1005];   int n, m, t;   int fx[] = {-1, +1, 0, 0};   int fy[] = {0, 0, -1, +1};   vector<pair<int, int> > cur;   bool okay(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); }   void dfs(int x, int y, int curr) {     tim[x][y] = curr;     cur.push_back(make_pair(x, y));     for (int k = 0; k < 4; k++) {       int tx = x + fx[k];       int ty = y + fy[k];       if (okay(tx, ty) == false || tim[tx][ty] != -1 || str[tx][ty] != str[x][y])         continue;       dfs(tx, ty, curr);     }   }   char alt(char x) {     if (x ==  0 )       return  1 ;     else       return  0 ;   }   char query(int x, int y, long long curr) {     if (tim[x][y] == -1) return str[x][y];     long long diff = curr - 1LL * tim[x][y];     if (diff % 2LL == 1LL)       return alt(str[x][y]);     else       return str[x][y];   }   int main() {     scanf( %d %d %d , &n, &m, &t);     for (int i = 0; i < n; i++) {       cin >> str[i];     }     memset(tim, -1, sizeof tim);     vector<pair<int, int> > last;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) last.push_back(make_pair(i, j));     }     for (int curTim = 0; curTim <= n * m; curTim++) {       for (int i = 0; i < last.size(); i++) {         int x = last[i].first, y = last[i].second;         char col = query(x, y, curTim);         for (int k = 0; k < 4; k++) {           int tx = x + fx[k];           int ty = y + fy[k];           if (okay(tx, ty) == false || tim[tx][ty] != -1 || str[tx][ty] != col)             continue;           dfs(tx, ty, curTim);         }       }       last = cur;       cur.clear();       if (last.empty()) break;     }     while (t--) {       int x, y;       long long q;       scanf( %d %d %lld , &x, &y, &q);       x--, y--;       char ans = query(x, y, q);       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int maxn = 100005;   int a[3], d;   void Solve() {     cin >> a[0] >> a[1] >> a[2] >> d;     sort(a, a + 3);     long long res = 0;     if (a[2] < a[1] + d) res += a[1] + d - a[2];     if (a[0] > a[1] - d) res += a[0] - a[1] + d;     cout << res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     if (fopen(                  .inp ,                r )) {       freopen(                         .inp ,            r , stdin);       freopen(                         .out ,            w , stdout);     }     int test_case = 1;     while (test_case--) Solve();     return 0;   }


#include <bits/stdc++.h>   struct circle {     double r, x, y;     circle(void) : r(0), x(0), y(0) {}     bool contains(const circle& o) const {       double dx, dy;       dx = o.x - x;       dy = o.y - y;       return (dx * dx + dy * dy <= r * r) && o.r < r;     }   };   circle fences[1024];   circle control[1024];   int depth[1024];   int parent[11][1024];   int control_parent[1024];   int V, n;   int find_parent(const circle& c, const int& ignore) {     int best_j, best, j;     best_j = V;     best = -INT_MAX;     for (j = 0; j < V; ++j) {       if (j != ignore && fences[j].contains(c)) {         if (depth[j] > best) {           best = depth[j];           best_j = j;         }       }     }     return best_j;   }   void build_tree(void) {     int i, j;     for (i = 0; i < V; ++i) {       depth[i] = 1;       for (j = 0; j < V; ++j) {         if (i != j && fences[j].contains(fences[i])) {           ++depth[i];         }       }     }     for (i = 0; i < V; ++i) {       parent[0][i] = find_parent(fences[i], i);     }     for (i = 1; i <= n; ++i) {       control_parent[i] = find_parent(control[i], -1);     }   }   void build_lca(void) {     int lg2, i;     parent[0][V] = V;     for (lg2 = 1; lg2 < 11; ++lg2) {       for (i = 0; i < V; ++i) {         parent[lg2][i] = parent[lg2 - 1][parent[lg2 - 1][i]];       }     }   }   int get_lca(int a, int b) {     int step, lg2;     if (depth[a] < depth[b]) {       std::swap(a, b);     }     for (lg2 = 10, step = 1024; lg2 >= 0; --lg2, step >>= 1) {       if (depth[a] - step >= depth[b]) {         a = parent[lg2][a];       }     }     if (a == b) {       return a;     }     for (lg2 = 10, step = 1024; lg2 >= 0; --lg2, step >>= 1) {       if (parent[lg2][a] != parent[lg2][b]) {         a = parent[lg2][a];         b = parent[lg2][b];       }     }     return parent[0][a];   }   int main(void) {     int i, q;     int control_1, control_2, control_3;     std::cin.tie(0);     std::ios_base::sync_with_stdio(0);     std::cin >> n >> V >> q;     for (i = 1; i <= n; ++i) {       std::cin >> control[i].x >> control[i].y;     }     for (i = 0; i < V; ++i) {       std::cin >> fences[i].r >> fences[i].x >> fences[i].y;     }     build_tree();     build_lca();     for (i = 0; i < q; ++i) {       std::cin >> control_1 >> control_2;       control_1 = control_parent[control_1];       control_2 = control_parent[control_2];       control_3 = get_lca(control_1, control_2);       std::cout << (depth[control_1] + depth[control_2] - 2 * depth[control_3])                 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int logb(int base, int x) { return (log(x) / log(base)); }   int occurs(vector<long long> v, int n) {     auto it = lower_bound(((v)).begin(), ((v)).end(), (n));     auto it1 = upper_bound(((v)).begin(), ((v)).end(), (n));     int x = it1 - it;     return x;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long powm(int a, int b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * 1LL * a) % mod;       b >>= 1;       a = (a * 1LL * a) % mod;     }     return res;   }   long long nCr(long long n, long long k) {     int fact[n];     long long res = (fact[n] * powm(fact[k], mod - 2)) % mod;     return (res * powm(fact[n - k], mod - 2)) % mod;   }   const int N = 1e5 + 5, inf = 1e9;   vector<int> g[N];   int n, m, d;   int mxin[N], mxout[N], marked[N];   void dfs_down(int v, int p) {     mxin[v] = -inf;     if (marked[v]) mxin[v] = 0;     for (auto u : g[v]) {       if (u == p) continue;       dfs_down(u, v);       mxin[v] = max(mxin[v], mxin[u] + 1);     }   }   void dfs_up(int v, int p) {     int max1 = -1 * inf, max2 = -1 * inf;     for (auto u : g[v]) {       if (u == p) continue;       if (mxin[u] >= max1)         max2 = max1, max1 = mxin[u];       else if (mxin[u] > max2)         max2 = mxin[u];     }     for (auto u : g[v]) {       if (u == p) continue;       int used = (mxin[u] == max1) ? max2 : max1;       mxout[u] = max(1 + mxout[v], 2 + used);       if (mxout[u] < 0 && marked[u]) mxout[u] = 0;       dfs_up(u, v);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> d;     int x, y;     for (int(i) = 0; (i) < (m); ++(i)) {       cin >> x;       marked[x] = 1;     }     for (int(i) = 0; (i) < (n - 1); ++(i)) {       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     dfs_down(1, 0);     mxout[1] = (marked[1] ? 0 : -inf);     dfs_up(1, 0);     int ans = 0;     for (int i = 1; i <= n; i++) ans += (mxin[i] <= d && mxout[i] <= d);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, V, A[64], B[64];   bool canCook(double x) {     double tot = 0.0;     for (int i = 0; i < n; i++)       if (A[i] * x > B[i])         return 0;       else         tot += A[i] * x;     return tot <= V;   }   double totalAmount(double x) {     double tot = 0.0;     for (int i = 0; i < n; i++) tot += A[i] * x;     return tot;   }   int main() {     scanf( %d%d , &n, &V);     for (int i = 0; i < n; i++) scanf( %d , &A[i]);     for (int i = 0; i < n; i++) scanf( %d , &B[i]);     double lo = 0.0, hi = double(2 * V), mid;     while (abs(hi - lo) >= 1e-6) {       mid = (hi + lo) / 2;       if (canCook(mid))         lo = mid;       else         hi = mid;     }     printf( %.6f n , totalAmount(lo));   }


#include <bits/stdc++.h>   using namespace std;   map<long long, int> mp;   long long n, k, i, v[500005], val[500005], x, sum[500005], fr[500005],       frec[500005], fr3[500005], nr, sum2[500005], bucket, val1, m, st, dr, s,       stcur, drcur, sol[500005], fr2[500005], val2, b[500005];   struct wow {     long long st, dr, poz;   } a[500005];   long long cautbin(long long x) {     long long st = 0, dr = n, mij, sol = 0;     while (st <= dr) {       mij = (st + dr) / 2;       if (sum2[mij] <= x) {         if (sum2[mij] == x) {           sol = mij;         }         st = mij + 1;       } else {         dr = mij - 1;       }     }     return sol;   }   bool compare(wow a, wow b) {     if (a.st / bucket != b.st / bucket) {       return a.st < b.st;     }     return a.dr < b.dr;   }   int main() {     cin >> n >> k;     for (i = 1; i <= n; i++) {       cin >> x;       if (x == 1) {         val[i] = 1;       } else {         val[i] = -1;       }     }     for (i = 1; i <= n; i++) {       cin >> x;       v[i] = x * val[i];     }     for (i = 1; i <= n; i++) {       sum[i] = sum[i - 1] + v[i];     }     for (i = 0; i <= n; i++) {       mp[sum[i] - k] = mp[sum[i]] = mp[sum[i] + k] = 0;     }     nr = 0;     for (auto &a : mp) {       a.second = ++nr;     }     for (i = 0; i <= n; i++) {       fr[i] = mp[sum[i] - k];       fr2[i] = mp[sum[i]];       fr3[i] = mp[sum[i] + k];     }     cin >> m;     for (i = 1; i <= m; i++) {       cin >> a[i].st >> a[i].dr;       a[i].st--;       a[i].poz = i;     }     bucket = 300;     sort(a + 1, a + m + 1, compare);     st = 0;     dr = -1;     s = 0;     for (i = 1; i <= m; i++) {       stcur = a[i].st;       drcur = a[i].dr;       while (st > stcur) {         st--;         s = s + frec[fr3[st]];         frec[fr2[st]]++;       }       while (dr < drcur) {         dr++;         s = s + frec[fr[dr]];         frec[fr2[dr]]++;       }       while (st < stcur) {         frec[fr2[st]]--;         s = s - frec[fr3[st]];         st++;       }       while (dr > drcur) {         frec[fr2[dr]]--;         s = s - frec[fr[dr]];         dr--;       }       sol[a[i].poz] = s;     }     for (i = 1; i <= m; i++) {       cout << sol[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[200005], sum, cnt, ans;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       sum += a[i];     }     for (int i = 1; i <= n; i += 2) cnt += a[i];     ans = cnt;     for (int i = 1; i < n; i++) {       cnt = sum - cnt + a[i];       ans = max(ans, cnt);     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long m;   long long p(long long x) {     long long kmx = 0;     while ((kmx * kmx * kmx) <= x) kmx++;     kmx--;     long long ret = 0;     for (long long i = 2; i <= kmx; i++) ret += x / (i * i * i);     return ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> m;     long long ans = 0;     long long lo = 1, hi = 1e16;     while (lo <= hi) {       long long mi = (lo + hi) / 2;       if (p(mi) >= m) {         ans = mi;         hi = mi - 1;       } else         lo = mi + 1;     }     if (p(ans) != m) ans = -1;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxx = 200010;   unsigned long long t, n;   unsigned long long ans = 0, total = 0, sum = 0;   unsigned long long a[maxx], b[maxx], bj[maxx];   int main() {     scanf( %lld , &t);     while (t--) {       scanf( %lld , &n);       ans = 0, total = 0, sum = 1;       while (n >= sum) {         unsigned long long opt = sum;         total++;         sum *= 2;         ans += total + (n - opt) / sum * total;       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   const long long inf = 1e18 + 9;   int n, m, k, q;   vector<pair<int, int> > g[maxn];   pair<long long, pair<int, int> > edges[maxn];   pair<int, int> query[maxn];   struct data {     int id;     long long val;     bool operator<(const data& other) const { return val > other.val; }   };   long long d[maxn];   int lab[maxn];   int low[maxn], high[maxn];   vector<int> vec[maxn];   void read_input() {     cin >> n >> m >> k >> q;     for (int i = 1; i <= m; ++i) {       int u, v, w;       cin >> u >> v >> w;       edges[i] = make_pair(w, pair<int, int>(u, v));       g[u].push_back(pair<int, int>(v, w));       g[v].push_back(pair<int, int>(u, w));     }     for (int i = 1; i <= q; ++i) {       int u, v;       cin >> u >> v;       query[i] = pair<int, int>(u, v);     }   }   void dijkstra() {     priority_queue<data> pq;     fill(d + 1, d + n + 1, inf);     for (int i = 1; i <= k; ++i) {       d[i] = 0;       pq.push({i, 0});     }     while (!pq.empty()) {       data tp = pq.top();       pq.pop();       if (tp.val != d[tp.id]) continue;       int u = tp.id;       for (auto& to : g[u]) {         int v = to.first, w = to.second;         if (d[v] > d[u] + w) {           d[v] = d[u] + w;           pq.push({v, d[v]});         }       }     }   }   int find_set(int u) { return lab[u] < 0 ? u : lab[u] = find_set(lab[u]); }   void union_sets(int u, int v) {     if (lab[u] < lab[v]) swap(u, v);     lab[v] += lab[u];     lab[u] = v;   }   void solve() {     dijkstra();     for (int i = 1; i <= m; ++i) {       int u = edges[i].second.first, v = edges[i].second.second;       edges[i].first += d[u] + d[v];     }     sort(edges + 1, edges + m + 1);     for (int i = 1; i <= q; ++i) {       low[i] = 1;       high[i] = m;     }     while (true) {       bool stop = true;       for (int i = 1; i <= q; ++i)         if (low[i] <= high[i]) {           stop = false;           int mid = (low[i] + high[i]) / 2;           vec[mid].push_back(i);         }       if (stop) break;       fill(lab + 1, lab + n + 1, -1);       for (int i = 1; i <= m; ++i) {         int u = edges[i].second.first, v = edges[i].second.second;         u = find_set(u);         v = find_set(v);         if (u != v) union_sets(u, v);         while ((int)vec[i].size()) {           int id = vec[i].back();           vec[i].pop_back();           if (find_set(query[id].first) == find_set(query[id].second))             high[id] = i - 1;           else             low[id] = i + 1;         }       }     }     for (int i = 1; i <= q; ++i) cout << edges[low[i]].first <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     read_input();     solve();   }


#include <bits/stdc++.h>   using namespace std;   bool in_range(long long l, long long v, long long r) {     return (l <= v && v <= r);   }   int main() {     long long x;     cin >> x;     x = ((-x) % 360 + 360) % 360;     int ans = 0;     if (x >= 225 && x < 315)       ans = 1;     else if (x >= 135 && x < 225)       ans = 2;     else if (x > 45 && x < 135)       ans = 3;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class Solution {    public:     void solve(std::istream& in, std::ostream& out) {       long long n, k, b, c, a, d;       in >> n >> k >> b >> c;       b = min(b, 5 * c);       vector<pair<long long, long long>> x(n);       for (int i = 0; i < n; i++) {         in >> a;         x[i] = make_pair(a, 0);       }       for (int i = 0; i < n; i++) {         for (int j = 1; j < 5; j++) {           x.push_back(make_pair(x[i].first + j, -j));         }       }       n = x.size();       vector<vector<pair<long long, long long>>> y(5), z(5);       for (int i = 0; i < n; i++) {         a = x[i].first % 5;         if (a < 0) {           a = a + 5;         }         y[a].push_back(x[i]);       }       for (int i = 0; i < 5; i++) {         sort(begin(y[i]), end(y[i]));         int t = y[i].size();         long long h = y[i].back().first;         z[i] = vector<pair<long long, long long>>(t);         for (int j = 0; j < t; j++) {           z[i][j] =               make_pair(-((h - y[i][j].first) / 5 * b - y[i][j].second * c), j);         }         sort(begin(z[i]), end(z[i]));       }       long long m = 100000000000000000;       for (int i = 0; i < 5; i++) {         int t = y[i].size();         priority_queue<pair<int, int>> q;         long long p = 0;         int l = t - 1, r = t - 1;         long long h;         while (l >= 0) {           if (r < 0) break;           d = y[i][r].first;           if (q.size()) {             a = q.top().first;             p -= (h - a) / 5 * b * q.size();             h = a;           }           while (q.size() && d < q.top().first) {             p += q.top().second * c;             q.pop();             if (q.size()) {               a = q.top().first;               p -= (h - a) / 5 * b * q.size();               h = a;             } else               p = 0;           }           if (q.size()) {             a = q.top().first;             p += (d - a) / 5 * b * q.size();           }           while (l >= 0 && q.size() < k) {             a = z[i][l].second;             if (y[i][a].first > d) {               l--;               continue;             }             p -= y[i][a].second * c;             p += (d - y[i][a].first) / 5 * b;             q.push(y[i][a]);             l--;           }           if (q.size() == k) m = min(m, p);           h = d;           r--;           while (r >= 0 && y[i][r].first == y[i][r + 1].first) r--;         }       }       out << m;     }   };   void solve(std::istream& in, std::ostream& out) {     out << std::setprecision(12);     Solution solution;     solution.solve(in, out);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     istream& in = cin;     ostream& out = cout;     solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[100000], s = 0, nz = 0;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (int i = 0; i < n; i++) {       if (a[i] == a[i + 1] && a[i] != 0) s++;       if (a[i] == 0) nz++;     }     cout << n - s - nz << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string now, st;   vector<int> num[26];   int main(void) {     int n, k;     cin >> n >> k;     cin >> st;     for (int i = 0; i < (k); i++) {       num[st[i] -  a ].push_back(i);     }     for (int Case = 0; Case < (n); Case++) {       cin >> now;       long long res = 0;       int len = now.size();       for (int i = 0; i < (len); i++) {         if (i >= k || st[i] != now[i]) {           int alpha = now[i] -  a ;           if (num[alpha].empty()) {             res += len;             continue;           }           int left = 0, right = num[alpha].size() - 1, mid;           while (left < right) {             mid = (left + right + 1) >> 1;             if (num[alpha][mid] <= i)               left = mid;             else               right = mid - 1;           }           int tmp = abs(i - num[alpha][left]);           if (left + 1 < num[alpha].size())             tmp = min(tmp, abs(i - num[alpha][left + 1]));           res += tmp;         }       }       cout << res << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mn = 500005;   int n, fp, ln;   pair<double, double> inp[mn];   bool f(double mid) {     double ma = -(int)1e9;     for (int i = fp; i < ln + 1; i++) {       double pos = inp[i].first + mid * inp[i].second;       if (inp[i].second < 0) {         if (pos <= ma) return 1;       } else         ma = max(ma, pos);     }     return 0;   }   int main() {     n = ({       int t;       scanf( %d , &t);       t;     });     for (int i = 0; i < n; i++)       inp[i].first = ({         int t;         scanf( %d , &t);         t;       }),       inp[i].second = ({         int t;         scanf( %d , &t);         t;       });     fp = ln = -1;     for (int i = n - 1; i >= 0; i--)       if (inp[i].second > 0) fp = i;     for (int i = 0; i < n; i++)       if (inp[i].second < 0) ln = i;     if (fp == -1 || ln == -1 || fp > ln) {       printf( -1 n );       return 0;     }     double lo = 0, hi = double(1e9) + 5, mid = (lo + hi) / 2;     for (int times = 0; times < 100; times++) {       if (f(mid))         hi = mid;       else         lo = mid;       mid = (lo + hi) / 2;     }     printf( %.15lf n , mid);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using ld = long double;   const int mod = 1e9 + 7;   const ll inf = 2e9;   const ll INF = 2e18;   const ld EPS = 1e-7;   const int N = 1e5 + 55;   ll sx[N], sy[N];   void solve() {     int n, m;     cin >> n >> m;     vector<vector<int>> a(n, vector<int>(m));     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> a[i][j];         sx[i] += a[i][j];         sy[j] += a[i][j];       }     }     ll mx = 0;     vector<ll> v;     for (int i = 0; i < n; ++i) {       v.clear();       for (int j = 0; j < m; ++j) {         v.push_back(sy[j] - a[i][j]);         sort(v.rbegin(), v.rend());         while (v.size() > 3) {           v.pop_back();         }       }       ll cur = sx[i];       for (ll a : v) {         cur += a;       }       mx = max(mx, cur);     }     for (int j = 0; j < m; ++j) {       v.clear();       for (int i = 0; i < n; ++i) {         v.push_back(sx[i] - a[i][j]);         sort(v.rbegin(), v.rend());         while (v.size() > 3) {           v.pop_back();         }       }       ll cur = sy[j];       for (ll a : v) {         cur += a;       }       mx = max(mx, cur);     }     if (n > m) {       for (int i = 0; i < m; ++i) {         for (int k = i + 1; k < m; ++k) {           v.clear();           for (int j = 0; j < n; ++j) {             v.push_back(sx[j] - a[j][i] - a[j][k]);             sort(v.rbegin(), v.rend());             while (v.size() > 2) {               v.pop_back();             }           }           ll cur = sy[i] + sy[k];           for (ll a : v) {             cur += a;           }           mx = max(mx, cur);         }       }     } else {       for (int i = 0; i < n; ++i) {         for (int k = i + 1; k < n; ++k) {           v.clear();           for (int j = 0; j < m; ++j) {             v.push_back(sy[j] - a[i][j] - a[k][j]);             sort(v.rbegin(), v.rend());             while (v.size() > 2) {               v.pop_back();             }           }           ll cur = sx[i] + sx[k];           for (ll a : v) {             cur += a;           }           mx = max(mx, cur);         }       }     }     sort(sx, sx + n);     sort(sy, sy + m);     for (ll i = n - 1, sum = 0; i >= max(0, n - 4); --i) {       sum += sx[i];       mx = max(mx, sum);     }     for (ll i = m - 1, sum = 0; i >= max(0, m - 4); --i) {       sum += sy[i];       mx = max(mx, sum);     }     cout << mx;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     int tt = 1;     while (tt--) {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6, M = 1e9 + 7;   int gcd(int a, int b) {     if (!b) return a;     return gcd(b, a % b);   }   int n, x[N], y[N];   map<pair<long double, long double>, int> mp;   int t(int i, int j) {     long double dX = x[i] - x[j];     long double dY = y[i] - y[j];     long double g = gcd(dX, dY);     dX /= g, dY /= g;     vector<int> r;     for (int k = 0; k < n; k++) {       if (k == i || k == j) continue;       long double tmpx = x[i] - x[k];       long double tmpy = y[i] - y[k];       long double g = gcd(tmpx, tmpy);       tmpx /= g, tmpy /= g;       if (tmpx == dX && tmpy == dY)         continue;       else         r.push_back(k);     }     if (r.size() < 2) return true;     long double x2 = x[r[0]] - x[r[1]];     long double y2 = y[r[0]] - y[r[1]];     g = gcd(x2, y2);     if (g) x2 /= g, y2 /= g;     for (int i = 1; i < r.size(); i++) {       long double tmpx = x[r[0]] - x[r[i]];       long double tmpy = y[r[0]] - y[r[i]];       long double g = gcd(tmpx, tmpy);       if (g) tmpx /= g, tmpy /= g;       if (x2 != tmpx || y2 != tmpy) return false;     }     return true;   }   int main() {     scanf( %d , &n);     int cnt = 0;     for (int i = 0; i < n; i++) scanf( %d%d , &x[i], &y[i]);     for (int i = 1; i < n; i++) {       long double dX = x[i] - x[0];       long double dY = y[i] - y[0];       long double g = gcd(dX, dY);       dX /= g, dY /= g;       if (!mp[{dX, dY}]) mp[{dX, dY}] = i, cnt++;       if (cnt == 2) break;     }     if (cnt < 2) {       return puts( YES ), 0;     } else {       vector<int> v;       for (auto it = mp.begin(); it != mp.end(); it++) {         v.push_back(it->second);         if (t(0, it->second)) return puts( YES );       }       if (t(v[0], v[1])) return puts( YES );     }     puts( NO );   }


#include <bits/stdc++.h>   using namespace std;   long long n, a, b;   int main() {     cin >> n;     a = (n + 2) * (n + 1) / 2 * n / 3;     b = (n + 4) * (n + 3) / 2 * (n + 2) / 3 * (n + 1) / 4 * n / 5;     cout << a * b;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   const int MOD = 1e9 + 7;   vector<pair<long long int, long long int> > vp;   map<long long int, long long int> mp, mpp;   vector<long long int> v, v1, v2;   long long int dp[N], visit[N];   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<     ;     __f(comma + 1, args...);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int n, m, val, k, d, mi = 1e9, mx(0);     long long int sum(0), ct(0), p(0), q(0);     cin >> n >> m;     if (n <= 2 * m)       cout << 0 <<    ;     else       cout << n - 2 * m <<    ;     long long int low = 0, high = n;     while (low <= high) {       long long int mid = (low + high) >> 1;       if (((mid * (mid - 1) / 2)) >= m) {         high = mid - 1;       } else {         low = mid + 1;       }     }     cout << n - (high + 1);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &(n));     static long long a[int(5e3 + 5)];     set<int> s;     for (int i = 1, __R = n; i <= __R; i++) {       scanf( %lld , &(a[i]));       s.insert(a[i]);     }     static long long b[int(5e3 + 5)], k = 0;     for (long long x : s) b[++k] = x;     static long long dp[2][int(5e3 + 5)];     int lst = 0, cur = 1;     dp[lst][1] = abs(a[1] - b[1]);     for (int j = 2, __R = k; j <= __R; j++)       dp[lst][j] = min(dp[lst][j - 1], abs(a[1] - b[j]));     for (int i = 2, __R = n; i <= __R; i++) {       dp[cur][1] = dp[lst][1] + abs(a[i] - b[1]);       for (int j = 2, __R = k; j <= __R; j++)         dp[cur][j] = min(dp[cur][j - 1], dp[lst][j] + abs(a[i] - b[j]));       swap(lst, cur);     }     cout << dp[lst][k] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int count1[100005], count2[100005], count3[100005];   bool can_be_palin(int *a, int size) {     int i, no_of_odd = 0;     for (i = 0; i < size; i++) no_of_odd += a[i] % 2;     return (no_of_odd <= 1);   }   bool is_palin(int *a, int l, int r) {     for (int i = l; i <= (l + r) / 2; i++)       if (a[i] != a[r + l - i]) return false;     return true;   }   bool func(int *a, int n, int end, int l, int r) {     int i;     fill(count1, count1 + n + 1, 0);     fill(count2, count2 + n + 1, 0);     if (end - l + 1 >= r - end) {       for (i = l; i <= end; i++) count1[a[i]]++;       for (i = r; i > end; i--) count2[a[i]]++;       for (i = 1; i <= n; i++) {         if (count2[i] > count1[i]) return false;         count1[i] -= count2[i];       }       return can_be_palin(count1, n + 1);     } else {       for (i = l; i <= end; i++) count1[a[i]]++;       for (i = r; i >= r - end + l; i--) count2[a[i]]++;       for (i = 1; i <= n; i++) {         if (count2[i] > count1[i]) return false;         count1[i] -= count2[i];       }       return can_be_palin(count1, n + 1) && is_palin(a, end + 1, r - end + l - 1);     }   }   bool func2(int *a, int n, int end, int l, int r) {     int i;     fill(count1, count1 + n + 1, 0);     fill(count2, count2 + n + 1, 0);     if (r - end + 1 >= end - l) {       for (i = r; i >= end; i--) count1[a[i]]++;       for (i = l; i < end; i++) count2[a[i]]++;       for (i = 1; i <= n; i++) {         if (count2[i] > count1[i]) return false;         count1[i] -= count2[i];       }       return can_be_palin(count1, n + 1);     } else {       for (i = r; i >= end; i--) count1[a[i]]++;       for (i = l; i <= l + r - end; i++) count2[a[i]]++;       for (i = 1; i <= n; i++) {         if (count2[i] > count1[i]) return false;         count1[i] -= count2[i];       }       return can_be_palin(count1, n + 1) && is_palin(a, r - end + l + 1, end - 1);     }   }   int main() {     int n, i;     scanf( %d , &n);     long long ans = 0;     int a[n];     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i < n / 2 && a[i] == a[n - 1 - i]; i++)       ;     if (i == n / 2) {       printf( %I64d , (long long)n * (n + 1) / 2);       return 0;     }     int l = i, r = n - 1 - i, left_prev = l, right_prev = r, end = (l + r) / 2;     int prev_pos = -1;     while (left_prev < end - 1 && end < right_prev - 1) {       bool flag = true;       flag = func(a, n, end, l, r);       int mid1 = (end + left_prev) / 2;       int mid2 = (end + right_prev) / 2;       if (flag == false) {         left_prev = end;         end = mid2;       } else {         right_prev = end;         prev_pos = end;         end = mid1;       }     }     for (int k = left_prev; k < r && k < right_prev; k++)       if (func(a, n, k, l, r) == true)         prev_pos = (prev_pos == -1) ? k : min(prev_pos, k);     if (prev_pos != -1) ans += (long long)(l + 1) * (r - prev_pos);     right_prev = r, left_prev = l, end = (l + r) / 2;     prev_pos = -1;     while (end < right_prev - 1 && left_prev < end - 1) {       bool flag = true;       flag = func2(a, n, end, l, r);       int mid1 = (end + right_prev) / 2;       int mid2 = (end + left_prev) / 2;       if (flag == false) {         right_prev = end;         end = mid2;       } else {         left_prev = end;         prev_pos = end;         end = mid1;       }     }     for (int k = right_prev; k > l && k > left_prev; k--)       if (func2(a, n, k, l, r) == true)         prev_pos = (prev_pos == -1) ? k : max(prev_pos, k);     if (prev_pos != -1) ans += (long long)(n - r) * (prev_pos - l);     fill(count1, count1 + n + 1, 0);     for (i = l; i <= r; i++) count1[a[i]]++;     if (can_be_palin(count1, n + 1) == true) ans += (long long)(l + 1) * (n - r);     printf( %I64d , ans);   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimization( unroll-loops )   std::pair<int, int> DR[] = {{-1, 0}, {0, 1},   {1, 0}, {0, -1},                               {-1, 1}, {-1, -1}, {1, 1}, {1, -1}};   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     ~debug() { cerr << endl; }     template <class c>     typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {       cerr << boolalpha << i;       return *this;     }     template <class c>     typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {       return *this << range(begin(i), end(i));     }     template <class c, class b>     debug& operator<<(pair<b, c> d) {       return *this <<  (  << d.first <<  ,   << d.second <<  ) ;     }     template <class c>     debug& operator<<(rge<c> d) {       *this <<  [ ;       for (auto it = d.b; it != d.e; ++it) *this <<  ,   + 2 * (it == d.b) << *it;       return *this <<  ] ;     }   };   long long gcd(long long a, long long b) {     if (b) return gcd(b, a % b);     return a;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long n, m, a, b, g[3005 * 3005], val[3005][3005], mn[3005][3005], x, y, z,       ans;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cerr.tie(0);     cout.tie(0);     cin >> n >> m >> a >> b;     cin >> g[0] >> x >> y >> z;     for (long long i = 1; i < n * m; i++) {       g[i] = (g[i - 1] * x + y) % z;     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         val[i][j] = g[i * m + j];       }     }     for (long long j = 0; j < m; j++) {       deque<long long> dq;       for (long long i = 0; i < a; i++) {         while ((long long)((dq).size()) && val[dq.back()][j] >= val[i][j])           dq.pop_back();         dq.push_back(i);       }       mn[0][j] = val[dq.front()][j];       for (long long i = 1; i <= n - a; i++) {         if (dq.front() == i - 1) dq.pop_front();         while ((long long)((dq).size()) && val[dq.back()][j] >= val[i + a - 1][j])           dq.pop_back();         dq.push_back(i + a - 1);         mn[i][j] = val[dq.front()][j];       }     }     for (long long i = 0; i <= n - a; i++) {       deque<long long> dq;       for (long long j = 0; j < b; j++) {         while ((long long)((dq).size()) && mn[i][dq.back()] >= mn[i][j])           dq.pop_back();         dq.push_back(j);       }       ans += mn[i][dq.front()];       for (long long j = 1; j <= m - b; j++) {         if (dq.front() == j - 1) dq.pop_front();         while ((long long)((dq).size()) && mn[i][dq.back()] >= mn[i][j + b - 1])           dq.pop_back();         dq.push_back(j + b - 1);         ans += mn[i][dq.front()];       }     }     return cout << ans, 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   inline int rand(int x, int y) {     ++y;     return (rng() % (y - x)) + x;   }   string to_string(char c) {     string second(1, c);     return second;   }   string to_string(bool b) { return (b ?  true  :  false ); }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   void degug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void degug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     degug_out(T...);   }   inline int gcd(int a, int b) {     if (a > b) swap(a, b);     if (a == 0) return b;     return gcd(b % a, a);   }   int n;   int read() {     bool neg = false;     int res = 0;     char c = getchar();     while (true) {       if (c ==  - ) break;       if ( 0  <= c && c <=  9 ) break;       c = getchar();     }     if (c ==  - )       neg = true;     else       res = c -  0 ;     while (true) {       c = getchar();       if (c <  0  || c >  9 ) break;       res = (res << 1) + (res << 3) + (c -  0 );     }     if (neg) return -res;     return res;   }   const int sz = 670;   int store[sz + 2][sz + 2];   int A[(500006)];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     n = read();     for (int i = (0); i <= (int)(n - 1); ++i) {       int op, x, y;       op = read(), x = read(), y = read();       if (op == 1) {         for (int i = (1); i <= (int)(sz); ++i) {           store[i][x % i] += y;         }         A[x] += y;       } else {         if (x > sz) {           int ans = 0;           for (int i = y; i <= 500000; i += x) ans += A[i];           cout << ans <<   n ;         } else {           cout << store[x][y] <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   int a[MAXN], b[MAXN], c[MAXN];   int tb[MAXN];   int d, n;   long long x;   long long getNextX() {     x = (x * 37 + 10007) % 1000000007;     return x;   }   void initAB() {     for (int i = 0; i < n; i = i + 1) {       a[i] = i + 1;     }     for (int i = 0; i < n; i = i + 1) {       swap(a[i], a[getNextX() % (i + 1)]);     }     for (int i = 0; i < n; i = i + 1) {       if (i < d)         b[i] = 1;       else         b[i] = 0;     }     for (int i = 0; i < n; i = i + 1) {       swap(b[i], b[getNextX() % (i + 1)]);     }   }   struct node {     int p, num;     bool operator<(const node &t) const { return num > t.num; }   };   node nd[MAXN];   int main() {     while (cin >> n >> d >> x) {       initAB();       int cnt = 10000000;       for (int i = 0; i < n; i++) {         nd[i].num = a[i];         nd[i].p = i;       }       sort(nd, nd + n);       int l = 0;       for (int i = 0; i < n; i++) {         if (b[i] == 1) {           tb[l++] = i;         }       }       memset(c, -1, sizeof(c));       for (int i = 0; i < n; i++) {         int p = nd[i].p;         for (int j = 0; j < l && cnt > 0; j++) {           if (p + tb[j] < n && c[p + tb[j]] == -1) {             c[p + tb[j]] = a[p];           }           cnt--;         }       }       for (int i = 0; i < n; i++) {         if (c[i] == -1) {           c[i] = 0;           for (int j = 0; j < l && i - tb[j] >= 0; j++) {             c[i] = max(c[i], a[i - tb[j]] * b[tb[j]]);           }         }         printf( %d n , c[i]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       string s;       cin >> s;       long long int i = 0;       string ans = s;       string w;       string temp;       long long int k = 1;       while (i != n) {         if ((n - i) % 2 == 0) {           w = s.substr(i, n - i) + s.substr(0, i);         } else {           temp = s.substr(0, i);           reverse(temp.begin(), temp.end());           w = s.substr(i, n - i) + temp;         }         if (w.compare(ans) < 0) {           ans = w;           k = i + 1;         }         i += 1;       }       cout << ans << endl;       cout << k << endl;     }     return 0;   }


#include <bits/stdc++.h>   const double PI = acos(-1.0);   const double EPS = 1e-9;   using namespace std;   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 <<  { ;     typename vector<T>::const_iterator it;     for (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 <<  [ ;     typename set<T>::const_iterator it;     for (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 <<  [ ;     typename map<F, S>::const_iterator it;     for (it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << it->first <<   =   << it->second;     }     return os <<  ] ;   }   template <class T>   void deb_array(T *arr, int length) {     for (int i = 0; i < length; i++) {       cout << arr[i] <<    ;     }     cout <<   n ;   }   const int maxn = 500;   const double INF = 1e18 + 1;   double p[maxn][maxn], dp[maxn][maxn], prob[maxn][maxn];   int n, m;   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     m = 1 << n;     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= m; j++) {         cin >> p[i][j];         p[i][j] /= 100;       }     }     for (int i = 0; i <= m; i++) {       for (int j = 0; j <= m; j++) {         prob[i][j] = 1.0;       }     }     for (int i = 1; i <= n; i++) {       int k = (1 << i);       int bonus = k >> 1;       for (int j = 0; j <= m; j += k) {         int b = j;         int e = j + k;         int m = (b + e) / 2;         for (int c = j + 1; c <= m; c++) {           prob[i][c] = 0;           for (int d = m + 1; d <= e; d++) {             prob[i][c] = prob[i][c] + prob[i - 1][c] * prob[i - 1][d] * p[c][d];           }         }         for (int c = m + 1; c <= e; c++) {           prob[i][c] = 0;           for (int d = j + 1; d <= m; d++) {             prob[i][c] = prob[i][c] + prob[i - 1][c] * prob[i - 1][d] * p[c][d];           }         }         for (int c = m + 1; c <= e; c++) {           if (prob[i][c] == 0 || (dp[i - 1][c] == 0 && i != 1)) {             continue;           }           for (int d = j + 1; d <= m; d++) {             dp[i][c] =                 max(dp[i][c], dp[i - 1][c] + dp[i - 1][d] + prob[i][c] * bonus);           }         }         for (int c = j + 1; c <= m; c++) {           if (prob[i][c] == 0 || (dp[i - 1][c] == 0 && i != 1)) {             continue;           }           for (int d = m + 1; d <= e; d++) {             dp[i][c] =                 max(dp[i][c], dp[i - 1][c] + dp[i - 1][d] + prob[i][c] * bonus);           }         }       }     }     cout << fixed << setprecision(12) << *max_element(dp[n], dp[n] + m + 1)          <<   n ;     return 0;   }


#include <bits/stdc++.h>   const int INF = 200000000;   using namespace std;   int timer, lg, n;   vector<vector<int> > g;   vector<vector<int> > dp(200005);   int time_in[200005], time_out[200005], parent[200005], a[200005];   void DFS(int, int);   bool issubtree(int, int);   int lca(int, int);   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     g.resize(n + 1);     lg = log2(n + 1);     for (int k = 0; k <= n; k++) dp[k].resize(lg + 1);     for (int k = 2; k <= n; k++) {       int x;       cin >> x;       a[k] = x;       g[x].push_back(k);       g[k].push_back(x);     }     int u = 1;     int v = 2;     int dist = 1;     DFS(1, 0);     cout << 1 <<    ;     for (int k = 3; k <= n; k++) {       int lca1 = lca(u, k);       int lca2 = lca(v, k);       if (lca1 > lca2) {         if (lca1 >= dist) {           v = k;           dist = lca1;         }       } else {         if (lca2 >= dist) {           u = k;           dist = lca2;         }       }       cout << dist <<    ;     }     return 0;   }   void DFS(int v, int p) {     parent[v] = p;     dp[v][0] = p;     for (int k = 1; k <= lg; k++) dp[v][k] = dp[dp[v][k - 1]][k - 1];     time_in[v] = timer++;     for (int k = 0; k < g[v].size(); k++) {       int to = g[v][k];       if (to == p) continue;       DFS(to, v);     }     time_out[v] = timer++;   }   bool issubtree(int a, int b) {     if (time_in[a] <= time_in[b] && time_out[b] <= time_out[a]) return 1;     return 0;   }   int lca(int a, int b) {     if (issubtree(a, b)) {       int cnt = 0;       for (int k = lg; k >= 0; k--) {         if (dp[b][k] == 0) continue;         if (issubtree(dp[b][k], a)) continue;         b = dp[b][k];         cnt += pow(2, k);       }       return cnt + 1;     }     if (issubtree(b, a)) {       int cnt = 0;       for (int k = lg; k >= 0; k--) {         if (dp[a][k] == 0) continue;         if (issubtree(dp[a][k], b)) continue;         a = dp[a][k];         cnt += pow(2, k);       }       return cnt + 1;     }     int cnt = 0;     int sav = a;     for (int k = lg; k >= 0; k--) {       if (dp[a][k] == 0) continue;       if (issubtree(dp[a][k], b)) continue;       a = dp[a][k];       cnt += pow(2, k);     }     a = sav;     for (int k = lg; k >= 0; k--) {       if (dp[b][k] == 0) continue;       if (issubtree(dp[b][k], a)) continue;       b = dp[b][k];       cnt += pow(2, k);     }     return cnt + 2;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     string b;     cin >> a >> b;     while (a++) {       int i = a;       string comp =   ;       while (i > 0) {         int c = i % 10;         if (c == 4 || c == 7) {           comp = to_string(c) + comp;         }         i /= 10;       }       if (comp == b) {         cout << a;         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int h1, h2;   int a, b;   int ans = 0;   int main() {     scanf( %d%d , &h1, &h2);     scanf( %d%d , &a, &b);     h1 += a * 8;     if (h1 >= h2)       printf( 0 n );     else if (h1 < h2 && b >= a)       printf( -1 n );     else if (h1 < h2 && b < a) {       int num1 = (h2 - h1) % ((a - b) * 12);       if (num1 == 0)         printf( %d n , (h2 - h1) / ((a - b) * 12));       else         printf( %d n , (h2 - h1) / ((a - b) * 12) + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   class BIT {    public:     vector<int> bit;     int size_ = 0;     void init(int sz) {       size_ = sz + 2;       bit.resize(size_ + 2, 0);     }     void add(int pos, int x) {       pos++;       while (pos <= size_) {         bit[pos] += x;         pos += (pos & -pos);       }     }     int sum(int pos) {       int s = 0;       pos++;       while (pos >= 1) {         s += bit[pos];         pos -= (pos & -pos);       }       return s;     }     int searchs(int pos) {       int cl = 0, cr = size_ + 1, cm, minx = (1 << 30);       for (int i = 0; i < 22; i++) {         cm = ((cl + cr) >> 1);         int v = sum(cm);         if (v >= pos) {           minx = min(minx, cm);           cr = cm;         } else {           cl = cm;         }       }       return minx;     }   };   int N, A[1 << 18];   int Q, K[1 << 18], P[1 << 18], ans[1 << 18];   vector<pair<int, int>> rem;   vector<int> G[1 << 18];   BIT Z;   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) scanf( %d , &A[i]);     scanf( %d , &Q);     for (int i = 1; i <= Q; i++) scanf( %d%d , &K[i], &P[i]);     for (int i = 1; i <= N; i++) rem.push_back(make_pair(-A[i], i));     for (int i = 1; i <= Q; i++) G[K[i]].push_back(i);     sort(rem.begin(), rem.end());     Z.init(N + 2);     for (int i = 1; i <= N; i++) {       Z.add(rem[i - 1].second, 1);       for (int j = 0; j < G[i].size(); j++) {         int idx = G[i][j];         int val = Z.searchs(P[idx]);         ans[idx] = A[val];       }     }     for (int i = 1; i <= Q; i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   inline long long rd() {     long long x = 0, w = 1;     char ch = 0;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return x * w;   }   int to[N << 2], nt[N << 2], hd[N << 1], dg[N << 1], tot = 1;   void add(int x, int y) {     ++tot, to[tot] = y, nt[tot] = hd[x], hd[x] = tot, ++dg[x];     ++tot, to[tot] = x, nt[tot] = hd[y], hd[y] = tot, ++dg[y];   }   bool cs[N << 2], ban[N << 2], v[N << 1];   int n, m, a[N][2], b[N << 1];   void dfs(int x) {     v[x] = 1;     for (int &i = hd[x]; i; i = nt[i]) {       if (ban[i]) continue;       int y = to[i];       ban[i] = ban[i ^ 1] = 1, cs[i] = 1;       dfs(y);     }   }   int main() {     n = rd();     for (int i = 1; i <= n; ++i)       a[i][0] = b[i * 2 - 1] = rd(), a[i][1] = b[i * 2] = rd() + 1;     sort(b + 1, b + n + n + 1), m = unique(b + 1, b + n + n + 1) - b - 1;     for (int i = 1; i <= n; ++i) {       a[i][0] = lower_bound(b + 1, b + m + 1, a[i][0]) - b;       a[i][1] = lower_bound(b + 1, b + m + 1, a[i][1]) - b;       add(a[i][0], a[i][1]);     }     for (int i = 1, la = 0; i <= m; ++i)       if (dg[i] & 1) {         if (!la)           la = i;         else           add(la, i), la = 0;       }     for (int i = 1; i <= m; ++i)       if (!v[i]) dfs(i);     for (int i = 1; i <= n; ++i) printf( %d  , cs[i << 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000 * 100 + 10, mod = 1000000007;   long long a[maxn];   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int t;     t = 1;     while (t--) {       long long n;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> a[i];       }       cout <<  9??>>??0  << endl;       for (int i = 0; i < 9; i++) cout << i <<  ??<>  << i + 1 << endl;       cout <<  ??<>1  << endl;       for (int i = 0; i <= 9; i++) cout <<  ?  << i <<  >>  << i <<  ?  << endl;       for (int i = 0; i < 9; i++) cout << i <<  ?<>  << i + 1 << endl;       cout <<  9?>>??0  << endl;       cout <<  >>?  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 3;   const int INF = 1e9;   const int MOD = 1e9 + 7;   int main() {     long long n;     long long ans = 1;     cin >> n;     long long p = 2;     while (n > 1 && p * p <= n) {       if (n % p)         p++;       else {         n /= p;         if (ans % p) ans *= p;       }     }     if (ans % n) ans *= n;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> r1, r2, cr;   int main() {     int n, prev = 0;     cin >> n;     r1.push_back(0);     r2.push_back(0);     for (int i = 0; i < n - 1; i++) {       int w;       cin >> w;       w += prev;       prev = w;       r1.push_back(w);     }     prev = 0;     for (int i = 0; i < n - 1; i++) {       int w;       cin >> w;       w += prev;       prev = w;       r2.push_back(w);     }     for (int i = 0; i < n; i++) {       int w;       cin >> w;       cr.push_back(w);     }     int minl = cr[0] + r2[n - 1], pos = 0;     for (int i = 0; i < n; i++) {       int cal = cr[i] + r1[i] + (r2[n - 1] - r2[i]);       if (cal < minl) {         pos = i;         minl = cal;       }     }     int minl2 = 100000;     for (int i = 0; i < n; i++) {       if (i == pos) {         continue;       }       int cal = cr[i] + r1[i] + (r2[n - 1] - r2[i]);       if (cal < minl2) {         minl2 = cal;       }     }     cout << minl + minl2;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-11;   const int INFINITE = 0x3f3f3f3f;   template <class T>   inline void checkmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   inline void checkmax(T &a, T b) {     if (b > a) a = b;   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class T>   inline T lowbit(T n) {     return (n ^ (n - 1)) & n;   }   template <class T>   inline int countbit(T n) {     return (n == 0) ? 0 : (1 + countbit(n & (n - 1)));   }   typedef vector<int> VI;   typedef vector<VI> VII;   typedef vector<string> VS;   const long long MAXP = 1000000LL;   long long add(string a, string b, string c) {     if (a.size() == 0 || b.size() == 0 || c.size() == 0) return -1LL * INFINITE;     if ((a.size() > 1 && a[0] ==  0 ) || (b.size() > 1 && b[0] ==  0 ) ||         (c.size() > 1 && c[0] ==  0 ))       return -1LL * INFINITE;     if (a.size() > 7 || b.size() > 7 || c.size() > 7) return -1LL * INFINITE;     long long aa = 0;     for (int i = (int)(0); i < (int)(a.size()); i++) aa = aa * 10 + (a[i] -  0 );     if (aa > MAXP) return -1LL * INFINITE;     long long bb = 0;     for (int i = (int)(0); i < (int)(b.size()); i++) bb = bb * 10 + (b[i] -  0 );     if (bb > MAXP) return -1LL * INFINITE;     long long cc = 0;     for (int i = (int)(0); i < (int)(c.size()); i++)       cc = cc * 10LL + (c[i] -  0 );     if (cc > MAXP) return -1LL * INFINITE;     return (aa + bb + cc);   }   int main() {     ios::sync_with_stdio(false);     string s;     cin >> s;     int l = (int)s.size();     long long maxm = -1LL * INFINITE;     for (int i = (int)(0); i < (int)(l - 2); i++)       for (int j = (int)(i + 1); j < (int)(l - 1); j++) {         string a = s.substr(0, i + 1);         string b = s.substr(i + 1, j - i);         string c = s.substr(j + 1);         checkmax(maxm, add(a, b, c));       }     if (maxm == -1LL * INFINITE)       cout <<  -1 n ;     else       cout << maxm << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Kid {     int v, d;     long long p;     int id;   };   void Transform(vector<Kid>& q) {     int idx = -1;     for (int i = 0; i < q.size(); ++i) {       if (q[i].p < 0) {         idx = i;         break;       }     }     if (idx == -1) return;     for (int i = idx + 1; i < q.size(); ++i) {       q[i].p -= q[idx].d;     }     q.erase(q.begin() + idx);     Transform(q);   }   int main() {     int n;     cin >> n;     vector<Kid> q(n);     int kid = 0;     for (Kid& k : q) {       cin >> k.v >> k.d >> k.p;       k.id = kid++;     }     vector<int> ans;     while (!q.empty()) {       Kid k = q[0];       q.erase(q.begin());       assert(k.p >= 0);       ans.push_back(k.id);       for (int i = 0; i < min((int)q.size(), k.v); ++i) {         q[i].p -= (k.v - i);       }       Transform(q);     }     cout << ans.size() << endl;     for (int id : ans) {       cout << id + 1 <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 100000 + 10;   struct NODE {     long long int index;     long long int a;     bool operator<(const NODE& x) const { return a < x.a; }   } node[M];   struct SUR {     long long int index;     long long int a;     bool operator<(const SUR& x) const { return index < x.index; }   } sur[M];   int main() {     long long int n, k;     cin >> n >> k;     long long int bk = k;     long long int sum = 0;     for (int i = 0; i < n; i++) {       cin >> node[i].a;       node[i].index = i + 1;       sum += node[i].a;     }     sort(node, node + n);     if (sum < bk) {       cout <<  -1  << endl;     } else {       if (sum > bk) {         long long int p1 = 0;         vector<long long int> psum;         vector<long long int> id;         long long int pmin = 0;         while (p1 < n) {           long long int p2 = p1;           while (p2 < n && node[p2].a == node[p1].a) {             p2++;           }           p2--;           long long int value = (node[p1].a - pmin) * (n - 1 - p1 + 1);           psum.push_back(value);           id.push_back(p1);           pmin = node[p1].a;           p2++;           p1 = p2;         }         long long int tsum = 0;         int index = -1;         for (int i = 0; i < psum.size(); i++) {           if (tsum + psum[i] <= k) {             tsum += psum[i];           } else {             index = i;             break;           }         }         long long int res = k - tsum;         res = res % (n - id[index]);         int istart = 0;         for (int i = id[index]; i < n; i++) {           sur[istart].a = node[i].a;           sur[istart++].index = node[i].index;         }         sort(sur, sur + istart);         long long int lastmin = (id[index] - 1 >= 0 ? node[id[index] - 1].a : 0);         long long int div = (k - tsum) / (n - id[index]);         for (int i = 0; i < istart; i++) {           if (i < res) {             sur[i].a = sur[i].a - 1 - lastmin - div;           } else {             sur[i].a = sur[i].a - lastmin - div;           }         }         vector<int> ans;         for (int i = 0; i < istart; i++) {           if (sur[(i + res) % istart].a > 0) {             ans.push_back(sur[(i + res) % istart].index);           }         }         for (int i = 0; i < ans.size(); i++) {           cout << ans[i];           if (i < ans.size() - 1) {             cout <<    ;           } else {             cout << endl;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   struct Fib {     long long a, b;     Fib operator+(const Fib& o) const {       return {(a + o.a) % MOD, (b + o.b) % MOD};     }   };   struct FibOp {     long long a, b, c, d;     FibOp operator()(const FibOp& o) const {       FibOp res = {a * o.a + b * o.c, a * o.b + b * o.d, c * o.a + d * o.c,                    c * o.b + d * o.d};       res.a %= MOD;       ;       res.b %= MOD;       ;       res.c %= MOD;       ;       res.d %= MOD;       ;       return res;     }     Fib operator()(const Fib& f) const {       Fib res = {a * f.a + b * f.b, c * f.a + d * f.b};       res.a %= MOD;       ;       res.b %= MOD;       ;       return res;     }   };   const long long K = 32;   FibOp pwr[K];   FibOp negpwr[K];   Fib zero = {0, 1};   void setup() {     pwr[0] = {1, 1, 1, 0};     negpwr[0] = {0, 1, 1, MOD - 1};     for (int i = 1; i < K; ++i) {       pwr[i] = pwr[i - 1](pwr[i - 1]);       negpwr[i] = negpwr[i - 1](negpwr[i - 1]);     }   }   Fib FibMult(Fib f, long long cnt, FibOp p[K]) {     for (int r = K - 1; r >= 0; --r) {       if (cnt & (1LL << r)) {         f = p[r](f);       }     }     return f;   }   Fib FibMult(Fib f, long long cnt) {     return (cnt >= 0 ? FibMult(f, cnt, pwr) : FibMult(f, -cnt, negpwr));   }   struct Node {     long long lo[2] = {0, 0};     long long hi[2] = {0, 0};     long long add[2] = {0, 0};     long long sz = 1;     Fib f;     void apply(long long a[2]) {       for (int i = 0; i < 2; ++i) {         add[i] += a[i];         lo[i] += a[i];         hi[i] += a[i];       }       f = FibMult(f, a[0] + a[1]);     }   };   struct Segtree {     vector<Node> t;     int n, h;     Segtree(int sz) {       h = 32 - __builtin_clz(sz);       n = 1 << h;       t = vector<Node>(n << 1);       for (int i = n - 1; i > 0; --i) {         t[i].sz = t[i * 2].sz + t[i * 2 + 1].sz;       }     }     void push(int x) {       if (!t[x].add[0] && !t[x].add[1]) {         return;       }       assert(x < n);       t[x << 1].apply(t[x].add);       t[x << 1 | 1].apply(t[x].add);       t[x].add[0] = 0;       t[x].add[1] = 0;     }     void pull(int x) {       for (int i = 0; i < 2; ++i) {         t[x].lo[i] = min(t[x * 2].lo[i], t[x * 2 + 1].lo[i]);         t[x].hi[i] = max(t[x * 2].hi[i], t[x * 2 + 1].hi[i]);       }       t[x].f = t[x << 1].f + t[x << 1 | 1].f;       t[x].apply(t[x].add);     }     void set_init(int x, int k, int va) {       x += n;       t[x].lo[k] = t[x].hi[k] = va;       t[x].f = FibMult(zero, t[x].lo[0] + t[x].lo[1]);       for (x /= 2; x; x /= 2) {         pull(x);       }     }     long long query(int l, int r, int x, int lv, int rv) {       if (r <= lv || rv <= l) {         return 0;       }       if (l <= lv && rv <= r) {         return t[x].f.a;       }       push(x);       int mv = (lv + rv) / 2;       long long ans = 0;       ans += query(l, r, x * 2, lv, mv);       ans += query(l, r, x * 2 + 1, mv, rv);       return ans % MOD;     }     long long query(int l, int r) { return query(l, r, 1, 0, n); }     void add(int l, int r, int k, long long va, int x, int lv, int rv) {       if (r <= lv || rv <= l) {         return;       }       if (l <= lv && rv <= r) {         long long a[2] = {0, 0};         a[k] = va;         t[x].apply(a);         return;       }       push(x);       int mv = (lv + rv) / 2;       add(l, r, k, va, x * 2, lv, mv);       add(l, r, k, va, x * 2 + 1, mv, rv);       pull(x);     }     void add(int l, int r, int k, long long va) { add(l, r, k, va, 1, 0, n); }     void minupdate(int l, int r, int k, long long va, int x, int lv, int rv) {       if (r <= lv || rv <= l) {         return;       }       if (t[x].hi[k] <= va) {         return;       }       if (l <= lv && rv <= r && t[x].lo[k] == t[x].hi[k]) {         long long a[2] = {0, 0};         a[k] = va - t[x].lo[k];         t[x].apply(a);         return;       }       push(x);       int mv = (lv + rv) / 2;       minupdate(l, r, k, va, x * 2, lv, mv);       minupdate(l, r, k, va, x * 2 + 1, mv, rv);       pull(x);     }     void minupdate(int l, int r, int k, long long va) {       return minupdate(l, r, k, va, 1, 0, n);     }     void maxupdate(int l, int r, int k, long long va, int x, int lv, int rv) {       if (r <= lv || rv <= l) {         return;       }       if (t[x].lo[k] >= va) {         return;       }       if (l <= lv && rv <= r && t[x].lo[k] == t[x].hi[k]) {         long long a[2] = {0, 0};         a[k] = va - t[x].lo[k];         t[x].apply(a);         return;       }       push(x);       int mv = (lv + rv) / 2;       maxupdate(l, r, k, va, x * 2, lv, mv);       maxupdate(l, r, k, va, x * 2 + 1, mv, rv);       pull(x);     }     void maxupdate(int l, int r, int k, long long va) {       return maxupdate(l, r, k, va, 1, 0, n);     }   };   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     setup();     int n, q;     cin >> n >> q;     Segtree st(n + 10);     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       st.set_init(i, 0, x);     }     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       st.set_init(i, 1, x);     }     for (int _i = 0; _i < q; ++_i) {       int type;       cin >> type;       if (type == 1) {         int k, l, r, x;         cin >> k >> l >> r >> x;         --k;         st.minupdate(l, r + 1, k, x);       } else if (type == 2) {         int k, l, r, x;         cin >> k >> l >> r >> x;         --k;         st.maxupdate(l, r + 1, k, x);       } else if (type == 3) {         int k, l, r, x;         cin >> k >> l >> r >> x;         --k;         st.add(l, r + 1, k, x);       } else if (type == 4) {         int l, r;         cin >> l >> r;         cout << st.query(l, r + 1) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double p[100010];   double E[100010];   int main() {     int n;     cin >> n;     p[0] = 0;     E[0] = 0;     double ans = 0;     for (int i = 1; i <= n; ++i) {       cin >> p[i];       E[i] = (1.0 - p[i - 1]) * p[i] + 2 * p[i] * p[i - 1] + p[i] * E[i - 1];       ans += E[i];     }     cout << setprecision(10) << ans << endl;   }


#include <bits/stdc++.h>   constexpr int N = 1.5e5, M = 1 << 18;   int n, q;   int parent[N], dep[N];   char ch[N];   int down[N], h[N], deg[N];   int mx[N][26], edge[N][26], sum[N];   int e[N][2];   int bad;   void add(int u, int c, int v) {     u = down[u];     edge[u][c] += v;     for (u = parent[u]; u != -1; u = parent[u]) {       bad -= sum[u] > h[u];       sum[u] -= mx[u][c];       mx[u][c] = 0;       for (int i = 0; i < deg[u]; ++i)         mx[u][c] = std::max(mx[u][c], mx[e[u][i]][c] + edge[e[u][i]][c]);       sum[u] += mx[u][c];       bad += sum[u] > h[u];     }   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     std::cin >> n >> q;     parent[0] = -1;     for (int i = 1; i < n; ++i) {       std::cin >> parent[i] >> ch[i];       --parent[i];       e[parent[i]][deg[parent[i]]++] = i;     }     for (int i = n - 1; i > 0; --i) h[parent[i]] = h[i] + 1;     for (int i = 1; i < n; ++i) {       if (h[parent[i]] != h[i] + 1) {         while (q--) std::cout <<  Fou n ;         return 0;       }       if (parent[i] != 0 && deg[parent[i]] == 1) parent[i] = parent[parent[i]];     }     for (int i = n - 1; i > 0; --i) down[i] = deg[i] == 1 ? down[e[i][0]] : i;     for (int i = 0; i < n; ++i) deg[i] = 0;     for (int i = 1; i < n; ++i)       if (down[i] == i) e[parent[i]][deg[parent[i]]++] = i;     for (int i = 1; i < n; ++i)       if (ch[i] !=  ? ) add(i, ch[i] -  a , 1);     while (q--) {       int v;       char c;       std::cin >> v >> c;       --v;       if (ch[v] !=  ? ) add(v, ch[v] -  a , -1);       if (c !=  ? ) add(v, c -  a , 1);       ch[v] = c;       if (bad == 0) {         int ans = 0;         for (int i = 0; i < 26; ++i) ans += (i + 1) * (h[0] - sum[0] + mx[0][i]);         std::cout <<  Shi   << ans <<   n ;       } else {         std::cout <<  Fou n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     int x[5001], y[5001], z[5001];     scanf( %d , &n);     double mx = -10;     for (int i = 0; i < n; i++) {       scanf( %d , x + i);       mx = max(mx, x[i] * 1.0);     }     scanf( %d , &m);     for (int i = 0; i < m; i++) scanf( %d , y + i);     scanf( %d , &k);     for (int i = 0; i < k; i++) scanf( %d , z + i);     double A, B;     scanf( %lf %lf , &A, &B);     double mn = 2e9 * 1.0;     for (int j = 0; j < m; j++) {       for (int l = 0; l < k; l++) {         mn = min((A * z[l] * 1.0) / (B * y[j] * 1.0), mn);       }     }     printf( %.10f n , mx * 1.0 / sqrt(1.0 + mn));   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int k, n, m, x, ans;   int a[N];   string second, r;   map<string, int> vis1, vis2;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       char e[50];       scanf( %s , e);       r = second = e;       while (second.find( kh ) != -1) {         x = second.find( kh );         second.erase(second.begin() + x);       }       r = second;       while (second.find( oo ) != -1) {         x = second.find( oo );         second[x] =  u ;         second.erase(second.begin() + x + 1);       }       while (r.find( u ) != -1) {         x = r.find( u );         r[x] =  o ;         r.insert(r.begin() + x,  o );       }       vis1[second] = 1;       vis2[r] = 1;     }     printf( %d n , min(vis1.size(), vis2.size()));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize  trapv    void solve() {     int64_t n, x, y;     cin >> n >> x >> y;     vector<pair<int64_t, int64_t> > a;     for (uint64_t i = 0; i < n; i++) {       int u, v;       cin >> u >> v;       a.push_back(make_pair(u, v));     }     sort(a.begin(), a.end());     multiset<int64_t, greater<int64_t> > curr;     int64_t res = 0;     for (uint64_t i = 0; i < a.size(); i++) {       auto it = curr.upper_bound(a[i].first);       if (it != curr.end()) {         if (((a[i].second - *it) * y) < (x + y * (a[i].second - a[i].first))) {           res += (a[i].second - *it) * y;           res %= 1000000007;           curr.erase(it);         } else {           res += x + y * (a[i].second - a[i].first);           res %= 1000000007;         }         curr.insert(a[i].second);       } else {         res += x + y * (a[i].second - a[i].first);         res %= 1000000007;         curr.insert(a[i].second);       }     }     cout << res << endl;     return;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     int a = abs(x1 - x2);     int b = abs(y1 - y2);     int u = min(a, b);     cout << u + abs(a - b);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n][n];     for (int i = 0; i < n; i++) {       string s;       cin >> s;       for (int j = 0; j < n; j++) {         arr[j][i] = s[j];       }     }     int cnt = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         int c = 0;         if (i != 0) {           if (arr[j][i - 1] ==  o ) {             c++;           }         }         if (i != n - 1) {           if (arr[j][i + 1] ==  o ) {             c++;           }         }         if (j != 0) {           if (arr[j - 1][i] ==  o ) {             c++;           }         }         if (j != n - 1) {           if (arr[j + 1][i] ==  o ) {             c++;           }         }         if (c % 2 == 0) {           cnt++;         }       }     }     if (cnt == n * n) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   long long t,n;long long lowbit(long long x){return x&-x;}   int main(){cin>>t;while(t--){cin>>n;if(!(n-lowbit(n)))puts( NO );else puts( YES );}}


#include <bits/stdc++.h>   using namespace std;   const signed long long Infinity = 1000000100;   const long double Epsilon = 1e-9;   template <typename T, typename U>   ostream& operator<<(ostream& os, const pair<T, U>& p) {     return os <<  (  << p.first <<  ,  << p.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& V) {     os <<  [ ;     for (int(i) = (0); (i) < (int(V.size())); (i)++)       os << V[i] << ((i == int(V.size()) - 1) ?    :  , );     return os <<  ] ;   }   template <typename T>   ostream& operator<<(ostream& os, const set<T>& S) {     os <<  ( ;     for (__typeof(S.begin()) i = S.begin(); i != S.end(); ++i)       os << *i << (*i == *S.rbegin() ?    :  , );     return os <<  ) ;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, const map<T, U>& M) {     os <<  { ;     for (__typeof(M.begin()) i = M.begin(); i != M.end(); ++i)       os << *i << (*i.first == M.rbegin()->first ?    :  , );     return os <<  } ;   }   int Rep[555][555];   int REP[555 * 555];   int Siz[555 * 555];   int Find(int a) {     if (REP[a] != a) REP[a] = Find(REP[a]);     return REP[a];   }   void Union(int a, int b) {     a = Find(a);     b = Find(b);     if (a == b) return;     REP[a] = b;     Siz[b] += Siz[a];   }   char T[555][555];   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   void U(int a, int b) {     if (T[a][b] ==  X ) return;     for (int(i) = (0); (i) <= (3); (i)++) {       if (T[a + dx[i]][b + dy[i]] ==  X ) continue;       Union(Rep[a][b], Rep[a + dx[i]][b + dy[i]]);       Rep[a + dx[i]][b + dy[i]] = Rep[a][b] = Find(Rep[a][b]);     }   }   int state[555 * 555];   int sum;   int ans;   void add(int a) {     if (state[a] == 0) sum += Siz[a];     state[a]++;   }   void rem(int a) {     state[a]--;     if (state[a] == 0) sum -= Siz[a];   }   int n;   void a(int a, int b) {     if (T[a][b] ==  X  and a != 0 and b != 0 and a != n + 1 and b != n + 1) sum++;   }   void r(int a, int b) {     if (T[a][b] ==  X  and a != 0 and b != 0 and a != n + 1 and b != n + 1) sum--;   }   int main() {     int k;     scanf( %d%d , &n, &k);     for (int(i) = (1); (i) <= (n); (i)++)       for (int(j) = (1); (j) <= (n); (j)++) {         scanf(  %c , &T[i][j]);         Rep[i][j] = i + (j - 1) * n;         REP[i + (j - 1) * n] = i + (j - 1) * n;         Siz[i + (j - 1) * n] = T[i][j] !=  X ;       }     for (int(i) = (0); (i) <= (n + 1); (i)++)       T[i][0] = T[0][i] = T[i][n + 1] = T[n + 1][i] =  X ;     for (int(i) = (1); (i) <= (n); (i)++)       for (int(j) = (1); (j) <= (n); (j)++) U(i, j);     for (int(i) = (0); (i) <= (n); (i)++) {       if (i + k + 1 > n + 1) break;       for (int(j) = (0); (j) <= (555 * 555 - 1); (j)++) state[j] = 0;       sum = 0;       for (int(j) = (0); (j) <= (n + 1); (j)++) {         for (int(l) = (1); (l) <= (k); (l)++) add(Find(Rep[i + l][j]));         if (j > 0) add(Find(Rep[i][j - 1]));         if (j > 0) add(Find(Rep[i + k + 1][j - 1]));         if (j > 0)           for (int(l) = (1); (l) <= (k); (l)++) a(i + l, j - 1);         if (j - k - 2 >= 0)           for (int(l) = (1); (l) <= (k); (l)++) rem(Find(Rep[i + l][j - k - 2]));         if (j - k - 1 >= 0) rem(Find(Rep[i][j - k - 1]));         if (j - k - 1 >= 0) rem(Find(Rep[i + k + 1][j - k - 1]));         if (j - k - 1 >= 0)           for (int(l) = (1); (l) <= (k); (l)++) r(i + l, j - k - 1);         ans = max(ans, sum);       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   inline char gc() {     static const int L = 23333;     static char sxd[L], *sss = sxd, *ttt = sxd;     if (sss == ttt) {       ttt = (sss = sxd) + fread(sxd, 1, L, stdin);       if (sss == ttt) {         return EOF;       }     }     return *sss++;   }   template <class T>   inline bool read(T& x) {     x = 0;     char c = gc();     bool flg = false;     for (; !isdigit(c); c = gc()) {       if (c ==  - ) {         flg = true;       } else if (c == EOF) {         return false;       }     }     for (; isdigit(c); c = gc()) {       x = (x * 10) + (c ^ 48);     }     if (flg) {       x = -x;     }     return true;   }   template <class T>   inline void write(T x) {     if (x < 0) {       x = -x;       putchar( - );     }     if (x > 9) {       write(x / 10);       x %= 10;     }     putchar(x | 48);   }   template <class T>   inline void writeln(T x) {     write(x);     puts(  );   }   template <class T>   inline void writesp(T x) {     write(x);     putchar(   );   }   using namespace std;   const int maxn = 100005;   int gcd(int a, int b) {     while (b) {       int t = a % b;       a = b;       b = t;     }     return a;   }   int n;   struct Edge {     int to, nxt;   } e[maxn << 1];   int first[maxn];   int du[maxn];   int dubk[maxn];   int cnt;   void add_edge(int u, int v) {     du[u]++, du[v]++;     e[++cnt].nxt = first[u];     first[u] = cnt;     e[cnt].to = v;     e[++cnt].nxt = first[v];     first[v] = cnt;     e[cnt].to = u;   }   int final_ans[maxn];   void init() {     cnt = 0;     for (int i = 1; i <= n; ++i) {       first[i] = du[i] = final_ans[i] = 0;     }   }   bool np[maxn];   int factor[maxn];   int prime[maxn];   void oula(const int n = 100000) {     np[1] = true;     int cnt = 0;     for (int i = 2; i <= n; ++i) {       if (!np[i]) {         prime[++cnt] = i;         factor[i] = i;       }       for (int j = 1; j <= cnt && (long long)i * prime[j] <= n; ++j) {         np[i * prime[j]] = true;         factor[i * prime[j]] = prime[j];         if (!(i % prime[j])) {           break;         }       }     }   }   bool vis[maxn];   int nn[maxn];   int bfs(int xx) {     for (int i = 1; i <= n; ++i) {       vis[i] = false;       nn[i] = du[i] = dubk[i];     }     queue<int> q;     while (!q.empty()) {       q.pop();     }     for (int i = 1; i <= n; ++i) {       if (du[i] <= 1) {         q.push(i);         vis[i] = true;       }     }     int ans = n - 1;     while (!q.empty()) {       int now = q.front();       q.pop();       bool flg = false;       if (du[now]) {         int tmpans = gcd(ans, nn[now]);         if (tmpans % xx) {           nn[now]--;           ans = gcd(ans, nn[now]);         } else {           ans = tmpans;           flg = true;         }       } else {         ans = gcd(ans, nn[now]);       }       if (ans % xx) {         return 1;       }       for (int i = first[now]; i; i = e[i].nxt) {         int to = e[i].to;         if (!vis[to]) {           du[to]--;           if (flg) {             nn[to]--;           }           if (du[to] <= 1) {             q.push(to);             vis[to] = true;           }         }       }     }     return ans;   }   const int mod = 998244353;   int ksm(int a, int b) {     int ans = 1;     for (; b; b >>= 1, a = (long long)a * a % mod) {       if (b & 1) {         ans = (long long)ans * a % mod;       }     }     return ans;   }   void solve() {     read(n);     init();     for (int i = 1; i < n; ++i) {       int u, v;       read(u), read(v);       add_edge(u, v);     }     for (int i = 1; i <= n; ++i) {       dubk[i] = du[i];     }     int tt = n - 1;     int tmpans = 0;     while (tt > 1) {       int pme = factor[tt];       while (!(tt % pme)) {         tt /= pme;       }       int nowans = bfs(pme);       if (nowans > 1 && !final_ans[nowans]) {         final_ans[nowans] = 1;         tmpans++;       }     }     final_ans[1] = ksm(2, n - 1) - tmpans;     if (final_ans[1] < 0) {       final_ans[1] += mod;     }     for (int i = 1; i <= n; ++i) {       writesp(final_ans[i]);     }     puts(  );   }   int main() {     oula();     int T;     read(T);     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   const long long M = 1e9 + 7;   const double pi = 3.14159265358979323846;   using namespace std;   long long ans = 1;   vector<long long> adj[2005];   long long vis[200005] = {0};   void dfs(long long x) {     vis[x] = 1;     for (long long i = 0; i < adj[x].size(); i++) {       if (vis[adj[x][i]] == 0) dfs(adj[x][i]);     }   }   bool prime(long long n) {     if (n <= 2)       return false;     else {       for (long long i = 2; i <= sqrt(n); i++) {         if (n % i == 0) {           return false;         }       }       return true;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) {       long long n;       cin >> n;       for (long long i = 0; i < n; i++) {         if (i % 2 == 0) {           for (long long j = 0; j < n; j++) {             if (j % 2 == 0)               cout <<  W ;             else               cout <<  B ;           }           cout <<   n ;         } else {           for (long long j = 0; j < n; j++) {             if (j % 2 == 0)               cout <<  B ;             else               cout <<  W ;           }           cout <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, cnt0 = 3;   int g, r, b;   bool markb = true, markg = true, markr = true;   char id[ Z ][ Z ];   vector<char> st, m;   int tt[500];   int main() {     scanf( %d n , &n);     for (int i = 1; i <= n; ++i) {       char ch;       scanf( %c , &ch);       if (ch ==  B ) {         ++b;         cnt0 -= markb;         markb = false;       }       if (ch ==  G ) {         ++g;         cnt0 -= markg;         markg = false;       }       if (ch ==  R ) {         ++r;         cnt0 -= markr;         markr = false;       }     }     if (b >= 1 && g >= 1 && r >= 1) {       printf( BGR );       return 0;     }     if (cnt0 == 2) {       if (b) {         printf( B );         return 0;       }       if (g) {         printf( G );         return 0;       }       if (r) {         printf( R );         return 0;       }     }     if (g == 0) {       if (r >= 2 && b >= 2) {         printf( BGR );         return 0;       }     }     if (r == 0) {       if (g >= 2 && b >= 2) {         printf( BGR );         return 0;       }     }     if (b == 0) {       if (g >= 2 && r >= 2) {         printf( BGR );         return 0;       }     }     markb = markg = markr = false;     id[ G ][ G ] =  G ;     id[ R ][ R ] =  R ;     id[ B ][ B ] =  B ;     id[ G ][ R ] = id[ R ][ G ] =  B ;     id[ B ][ R ] = id[ R ][ B ] =  G ;     id[ G ][ B ] = id[ B ][ G ] =  R ;     if (b >= 1) m.push_back( B );     if (b >= 2) m.push_back( B );     if (g >= 1) m.push_back( G );     if (g >= 2) m.push_back( G );     if (r >= 1) m.push_back( R );     if (r >= 2) m.push_back( R );     for (int i = 1; i <= m.size(); ++i) tt[i] = i;     do {       st.clear();       for (int i = 1; i <= m.size(); ++i) st.push_back(m[tt[i] - 1]);       for (int i = 0; i < st.size() - 1;) {         st.push_back(id[st[i]][st[i + 1]]);         i += 2;       }       if (st.back() ==  B ) markb = true;       if (st.back() ==  G ) markg = true;       if (st.back() ==  R ) markr = true;     } while (next_permutation(tt + 1, tt + m.size() + 1));     if (markb) printf( B );     if (markg) printf( G );     if (markr) printf( R );     return 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     long int x, y;     cin >> n >> m >> x >> y;     long int* a = new long int[n];     long int* b = new long int[m];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     int count = -1, indi = 0, indj = 0;     long int** res = new long int*[min(m, n)];     while ((indi < n) && (indj < m))       if (b[indj] < a[indi] - x)         ++indj;       else if (b[indj] > a[indi] + y)         ++indi;       else {         res[(++count)] = new long int[2];         res[count][0] = indi + 1;         res[count][1] = indj + 1;         ++indi;         ++indj;       }     cout << count + 1 << endl;     for (int i = 0; i < count + 1; i++)       cout << res[i][0] <<     << res[i][1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int r, b;     cin >> r >> b;     cout << max(r, b) - 1 <<     << min(r, b) <<   n ;     return 0;   }