#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n struct SD { n   int x, y, c; n } p, pp; n int f[50000], bk[110][110]; n int n, m, k, maxx, ans, cur, sum, x, y; n int minn; n int nex[4][2] = {0, 1, 1, 0, 0, -1, -1, 0}; n char mapp[1100][1100]; n queue<struct SD> q; n int bfs(int x, int y) { n   while (q.size()) q.pop(); n   p.x = x, p.y = y, p.c = 0; n   q.push(p); n   ans = 1; n   memset(bk, 0, sizeof(bk)); n   ; n   bk[x][y] = 1; n   while (q.size()) { n     p = q.front(); n     q.pop(); n     if (p.c > 1) return ans < sum; n     for (int i = p.x; i < n; i++) { n       if (mapp[i][p.y] ==  B ) { n         if (bk[i][p.y]) continue; n         pp.x = i, pp.y = p.y, pp.c = p.c + 1; n         bk[pp.x][pp.y] = 1; n         ans++; n         q.push(pp); n       } else n         break; n     } n     for (int i = p.x; i >= 0; i--) { n       if (mapp[i][p.y] ==  B ) { n         if (bk[i][p.y]) continue; n         ans++; n         pp.x = i, pp.y = p.y, pp.c = p.c + 1; n         bk[pp.x][pp.y] = 1; n         q.push(pp); n       } else n         break; n     } n     for (int i = p.y; i < m; i++) { n       if (mapp[p.x][i] ==  B ) { n         if (bk[p.x][i]) continue; n         pp.x = p.x, pp.y = i, pp.c = p.c + 1; n         ans++; n         bk[pp.x][pp.y] = 1; n         q.push(pp); n       } else n         break; n     } n     for (int i = p.y; i >= 0; i--) { n       if (mapp[p.x][i] ==  B ) { n         if (bk[p.x][i]) continue; n         pp.x = p.x, pp.y = i, pp.c = p.c + 1; n         ans++; n         bk[pp.x][pp.y] = 1; n         q.push(pp); n       } else n         break; n     } n   } n   return ans < sum; n } n int main() { n   while (cin >> n >> m) { n     cur = sum = 0; n     for (int i = 0; i < n; i++) scanf( %s , mapp[i]); n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         if (mapp[i][j] ==  B ) { n           sum++; n         } n       } n     } n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         if (mapp[i][j] ==  B ) { n           if (bfs(i, j)) { n             cur = 1; n             break; n           } n         } n       } n       if (cur) break; n     } n     if (cur) n       cout <<  NO  << endl; n     else n       cout <<  YES  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int test; n   cin >> test; n   while (test--) { n     int n; n     cin >> n; n     string s; n     cin >> s; n     for (int i = 0; i < n; i++) { n       if (s[i] !=  ? ) { n         int j = i - 1; n         while (j >= 0 && s[j] ==  ? ) { n           if (s[j + 1] ==  R ) { n             s[j] =  B ; n           } else { n             s[j] =  R ; n           } n           j--; n         } n       } n     } n     reverse((s).begin(), (s).end()); n     for (int i = 0; i < n; i++) { n       if (s[i] !=  ? ) { n         int j = i - 1; n         while (j >= 0 && s[j] ==  ? ) { n           if (s[j + 1] ==  R ) { n             s[j] =  B ; n           } else { n             s[j] =  R ; n           } n           j--; n         } n       } n     } n     reverse((s).begin(), (s).end()); n     if (s[0] ==  ? ) { n       for (int i = 0; i < n; i++) { n         if (i % 2) { n           s[i] =  R ; n         } else { n           s[i] =  B ; n         } n       } n     } n     cout << s <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const ll MOD = 1e9 + 7, N = 1e5 + 10; n void test() { n   ll n, m; n   cin >> n >> m; n   vector<vector<ll>> a(n, vector<ll>(m)); n   ll cnt = 0; n   for (ll i = 0; i < n; ++i) { n     for (ll j = 0; j < m; ++j) { n       char c; n       cin >> c; n       a[i][j] = c -  0 ; n     } n   } n   vector<array<ll, 6>> R; n   if (n & 1) { n     for (ll i = 0; i < m; ++i) { n       if (a[n - 1][i]) { n         if (i != m - 1) { n           R.push_back({n - 1, i, n - 2, i, n - 2, i + 1}); n           a[n - 2][i + 1] ^= 1; n         } else { n           R.push_back({n - 1, i, n - 2, i, n - 2, i - 1}); n           a[n - 2][i - 1] ^= 1; n         } n         a[n - 1][i] ^= 1; n         a[n - 2][i] ^= 1; n       } n     } n     --n; n   } n   if (m & 1) { n     for (ll i = 0; i < n; ++i) { n       if (a[i][m - 1]) { n         if (i != n - 1) { n           R.push_back({i, m - 1, i, m - 2, i + 1, m - 2}); n           a[i + 1][m - 2] ^= 1; n         } else { n           R.push_back({i, m - 1, i, m - 2, i - 1, m - 2}); n           a[i - 1][m - 2] ^= 1; n         } n         a[i][m - 1] ^= 1; n         a[i][m - 2] ^= 1; n       } n     } n     --m; n   } n   auto solve = [&](vector<vector<ll>> a) { n     vector<array<ll, 6>> res; n     ll cnt = 0; n     for (ll i = 0; i < 2; ++i) { n       for (ll j = 0; j < 2; ++j) { n         cnt += a[i][j]; n       } n     } n     if (cnt == 4) { n       res.push_back({0, 0, 1, 0, 1, 1}); n       res.push_back({0, 1, 1, 0, 1, 1}); n       res.push_back({1, 0, 0, 0, 0, 1}); n       res.push_back({1, 1, 0, 0, 0, 1}); n     } else if (cnt == 3) { n       array<ll, 6> r; n       ll c = 0; n       for (ll i = 0; i < 2; ++i) { n         for (ll j = 0; j < 2; ++j) { n           if (a[i][j]) { n             r[c++] = i; n             r[c++] = j; n           } n         } n       } n       res.push_back(r); n     } else if (cnt == 2) { n       vector<array<ll, 2>> is, no; n       for (ll i = 0; i < 2; ++i) { n         for (ll j = 0; j < 2; ++j) { n           if (a[i][j]) { n             is.push_back({i, j}); n           } else { n             no.push_back({i, j}); n           } n         } n       } n       for (auto [x, y] : is) { n         array<ll, 6> r; n         ll c = 0; n         r[c++] = x; n         r[c++] = y; n         for (auto [x, y] : no) { n           r[c++] = x; n           r[c++] = y; n         } n         res.push_back(r); n       } n     } else if (cnt == 1) { n       vector<array<ll, 2>> is, no; n       for (ll i = 0; i < 2; ++i) { n         for (ll j = 0; j < 2; ++j) { n           if (a[i][j]) { n             is.push_back({i, j}); n           } else { n             no.push_back({i, j}); n           } n         } n       } n       for (ll i = 0; i < 3; ++i) { n         array<ll, 6> r; n         ll c = 0; n         r[c++] = is.back()[0]; n         r[c++] = is.back()[1]; n         for (ll j = 0; j < 2; ++j) { n           r[c++] = no[j][0]; n           r[c++] = no[j][1]; n         } n         auto bk = no.back(); n         no.pop_back(); n         no.insert(no.begin(), bk); n         res.push_back(r); n       } n     } n     return res; n   }; n   for (ll i = 0; i < n; i += 2) { n     for (ll j = 0; j < m; j += 2) { n       vector<vector<ll>> K = {{a[i][j], a[i][j + 1]}, n                               {a[i + 1][j], a[i + 1][j + 1]}}; n       auto res = solve(K); n       for (auto r : res) { n         for (ll k = 0; k < 6; ++k) { n           if (k & 1) { n             r[k] += j; n           } else { n             r[k] += i; n           } n         } n         R.push_back(r); n       } n     } n   } n   cout << R.size() <<   n ; n   for (auto i : R) { n     for (ll j = 0; j < 6; ++j) { n       cout << i[j] + 1 <<    ; n     } n     cout <<   n ; n   } n   return; n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   ll tt = 1; n   cin >> tt; n   for (ll i = 0; i < tt; i++) test(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace chrono; n long long mod_add(long long a, long long b, long long m) { n   a = a % m; n   b = b % m; n   return (((a + b) % m) + m) % m; n } n long long mod_mul(long long a, long long b, long long m) { n   a = a % m; n   b = b % m; n   return (((a * b) % m) + m) % m; n } n long long mod_sub(long long a, long long b, long long m) { n   a = a % m; n   b = b % m; n   return (((a - b) % m) + m) % m; n } n long long power(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long modInverse(long long n, long long p) { return power(n, p - 2, p); } n long long nCrMODp(long long n, long long r, long long p) { n   if (n < r) return 0; n   if (r == 0) return 1; n   long long fac[n + 1]; n   fac[0] = 1; n   for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p; n   return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % n          p; n } n void divisors(int n) { n   for (int i = 1; i <= sqrt(n); i++) { n     if (n % i == 0) { n       if (n / i == i) n         cout <<     << i; n       else n         cout <<     << i <<     << n / i; n     } n   } n } n void primeFactors(int n) { n   while (n % 2 == 0) { n     cout << 2 <<    ; n     n = n / 2; n   } n   for (int i = 3; i <= sqrt(n); i = i + 2) { n     while (n % i == 0) { n       cout << i <<    ; n       n = n / i; n     } n   } n   if (n > 2) cout << n <<    ; n } n void solve() { n   int t; n   cin >> t; n   cin.ignore(); n   while (t--) { n     int i, x = 0, y = 0; n     string str; n     cin >> str; n     for (i = 0; i < str.size(); i++) str[i] ==  B  ? x++ : y++; n     y == x ? cout <<  YES n  : cout <<  NO n ; n   } n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   auto start1 = high_resolution_clock::now(); n   solve(); n   auto stop1 = high_resolution_clock::now(); n   auto duration = duration_cast<microseconds>(stop1 - start1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t; n   cin >> t; n   while (t--) { n     long long int n, cnt = 0; n     cin >> n; n     string s[n]; n     long long int h1[10] = {}, h2[10] = {}; n     for (int i = 0; i < n; i++) { n       cin >> s[i]; n       h1[s[i][3] -  0 ]++; n     } n     for (int i = 0; i < n - 1; i++) { n       for (int j = i + 1; j < n; j++) { n         if (s[i].compare(s[j]) == 0) { n           int k; n           cnt++; n           for (k = 0; k < 10; k++) { n             if (h1[k] == 0) { n               break; n             } n           } n           h1[s[i][3] -  0 ]--; n           h1[k]++; n           s[i][3] = k +  0 ; n         } n       } n     } n     cout << cnt << endl; n     for (int i = 0; i < n; i++) { n       cout << s[i] << endl; n     } n   } n   return 0; n } n


#include<cstdio> n #include<iostream> n #include<cmath> n #include<cstring> n #include<vector> n #include<algorithm> n #define fs(i,x,y) for(int i=(x),_=(y);i<=_;++i) n #define fn(i,x,y) for(int i=(x),_=(y);i>=_;--i) n #define tor(i,v,x) for(int i=head[x],v=to[i];i;i=nxt[i],v=to[i]) n #define Li inline n #define R register int n #define ls(x) ch[x][0] n #define rs(x) ch[x][1] n #define mpi(x,y) make_pair(x,y) n #define pi pair<int,int> n //#define int ll  n using namespace std; n typedef long long ll; n template<typename T> n void read(T &x){ n  x=0;char ch=getchar();bool f=0; n  while(ch< 0 ||ch> 9 ){ n   if(ch== - )f=1; n   ch=getchar(); n  } n  while(ch>= 0 &&ch<= 9 )x=(x<<1)+(x<<3)+ch- 0 ,ch=getchar(); n  x=f?-x:x; n } n  n const int N=3005; n const int inf=1e9+7; n int n,m; n int dp[N][N]; n int a[N]; n  n signed main(){ n  int T;read(T);while(T--){ n   read(n);fs(i,1,n)read(a[i]); n   fs(i,2,n){ n    int cnt=0; n    fs(j,2,n)dp[i][j]=inf; n    fn(j,i-1,1){ n     if(j+a[j]<i)continue; n     dp[i][j+a[j]]=min(dp[i][j+a[j]],dp[j][i-1]+cnt);++cnt; n    } n    fs(j,i+1,n)dp[i][j]=min(dp[i][j],dp[i][j-1]); n   } n   printf( %d n ,dp[n][n]); n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int N = 6e4; n long long vis[N]; n long long ans[N]; n vector<long long> adj[N]; n void dfs(long long i, long long pa) { n   if (vis[i] == 1) n     return; n   else { n     vis[i] = 1; n     ans[i] = pa; n     for (vector<long long>::iterator itr = adj[i].begin(); itr != adj[i].end(); n          itr++) { n       if (vis[*itr] != 1) dfs(*itr, i); n     } n   } n } n int main() { n   long long n, r1, r2; n   cin >> n >> r1 >> r2; n   long long arr[n + 1]; n   adj[0].push_back(9999); n   for (long long i = 1; i <= n; i++) { n     long long x; n     if (i == r1) { n       arr[i] = -1; n     } else { n       cin >> x; n       arr[i] = x; n       adj[i].push_back(x); n       adj[x].push_back(i); n     } n   } n   dfs(r2, -1); n   ans[r2] = -1; n   for (long long j = 1; j <= n; j++) { n     if (ans[j] != -1) cout << ans[j] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct Node { n   int a, b, id; n } p[100005]; n bool mark[100005]; n bool cmp1(const Node &p1, const Node &p2) { n   if (p1.b != p2.b) n     return p1.b > p2.b; n   else n     return p1.a < p2.a; n } n bool cmp2(const Node &p1, const Node &p2) { n   if (p1.a != p2.a) n     return p1.a > p2.a; n   else n     return p1.b > p2.b; n } n int main() { n   int n, p1, k; n   cin >> n >> p1 >> k; n   for (int i = 0; i < n; i++) { n     scanf( %d%d , &p[i].a, &p[i].b); n     p[i].id = i + 1; n   } n   sort(p, p + n, cmp1); n   sort(p, p + n - p1 + k, cmp2); n   for (int i = 0; i < k; i++) mark[p[i].id] = true; n   sort(p, p + n - p1 + k, cmp1); n   p1 -= k; n   for (int i = 0; i < n; i++) { n     if (k && mark[p[i].id]) n       --k; n     else if (!k && p1) { n       mark[p[i].id] = true; n       --p1; n     } n   } n   for (int i = 1; i <= n; i++) n     if (mark[i]) printf( %d  , i); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void __print(int x) { cerr << x; } n void __print(long x) { cerr << x; } n void __print(long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char *x) { cerr <<     << x <<    ; } n void __print(const string &x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T &x) { n   int f = 0; n   cerr <<  { ; n   for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n const long long inf = 9223372036854775807; n const long long mod = 1000000007; n const double pi = acos(-1); n long long n = 0; n long long m = 0; n long long k = 0; n long long check(long long value) { n   long long ans = 0; n   for (int i = 1; i < n + 1; i++) { n     ans += min((value) / i, m); n   } n   return ans; n } n bool ifExist(long long val) { n   for (int i = 1; i < n + 1; i++) { n     if (val % i == 0 && val / i >= 1 && val / i <= m) { n       return true; n     } n   } n   return false; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(0); n   cin >> n >> m >> k; n   long long l = 1, r = n * m; n   long long mid = 1; n   while (l < r) { n     mid = (r + l) / 2; n     long long val = check(mid); n     if (val >= k) { n       r = mid; n     } else { n       l = mid + 1; n     } n   } n   cout << l; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int expo(long long int base, long long int exponent, n                    long long int mod) { n   long long int ans = 1; n   while (exponent != 0) { n     if (exponent & 1) ans = (1LL * ans * base) % mod; n     base = (1LL * base * base) % mod; n     exponent >>= 1; n   } n   return ans % mod; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int TESTS = 1; n   while (TESTS--) { n     long long int x, n; n     cin >> x >> n; n     long long int sx = sqrt(x) + 10; n     map<long long int, long long int> ma; n     for (long long int i = 2; i <= sx; i++) { n       while (x % i == 0) { n         x = x / i; n         ma[i]++; n       } n     } n     if (x != 1) ma[x]++; n     vector<long long int> v; n     for (auto i : ma) v.push_back(i.first); n     long long int ans = 1; n     for (auto i : v) { n       long long int p = i; n       long long int e = 0; n       long long int nn = n; n       for (long long int j = 1; true; j++) { n         e += nn / p; n         e = e % (1000000007 - 1); n         nn = nn / p; n         if (nn == 0) break; n       } n       long long int tmp = expo(i, e % (1000000007 - 1), 1000000007); n       ans = (ans * tmp) % 1000000007; n     } n     cout << ans; n   } n   return 0; n } n


// Problem: C. Minimum Ties n // Contest: Codeforces - Educational Codeforces Round 104 (Rated for Div. 2) n // URL: https://codeforces.com/contest/1487/problem/C n // Memory Limit: 256 MB n // Time Limit: 1000 ms n //  n // Powered by CP Editor (https://cpeditor.org) n  n //Weakness disgust me n #include bits/stdc++.h                    n #define fill(a)  memset(a, 0, sizeof (a)) n #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); n #define rep(i,n) for(int i=0;i<n;i++) n typedef long long ll; n #define int ll n const ll MOD = 1e9 + 7; n using namespace std; n void solve() n {   n  ll n; n  cin>>n; n  ll res[n][n]; n  memset(res,0,sizeof(res)); n   n  for(int i=1;i<=((n-1)/2);i++) n  { n   for(int j=0;j<n;j++) n   { n    res[(j+i)%n][j]=-1; n    res[j][(j+i)%n]=1; n   } n  } n   n  for(int i=0;i<n;i++) n  { n   for(int j=i+1;j<n;j++) n   { n    cout<<res[i][j]<<   ; n   } n    n  } n   n   n } n signed main() n {     n  fast; n     int t=1; n     cin>>t; n     while( t-- ) n     {   n         solve(); n         cout<<  n ; n     } n     n }


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const double err = 1e-12; n const double PI = 3.141592653589793; n const int N = 2e5 + 5; n int n; n vector<int> V; n bool chk(int val) { n   auto it = upper_bound((V).begin(), (V).end(), val); n   for (; it != V.end(); it++) { n     int aj = *it, ai = *it + val; n     while (ai <= V.back()) { n       auto tmp = lower_bound((V).begin(), (V).end(), ai); n       if (tmp != V.end() && (*tmp) % aj >= val) return true; n       ai += aj; n     } n   } n   return false; n } n void solve() { n   cin >> n; n   V = vector<int>(n); n   for (int i = 0; i < n; i++) cin >> V[i]; n   sort((V).begin(), (V).end()); n   V.erase(unique((V).begin(), (V).end()), V.end()); n   int l = 1, r = 1e6, ans = 0; n   while (l <= r) { n     int m = (l + r) / 2; n     if (chk(m)) { n       ans = m; n       l = m + 1; n     } else n       r = m - 1; n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int main() { n   scanf( %d%d , &n, &m); n   long long dp[m + 2]; n   int now = 0; n   int c, sum = 0; n   for (int i = 0; i < m; i++) { n     scanf( %d , &c); n     sum += c; n     dp[i] = sum; n   } n   dp[0] = -2147483647; n   long long ans = -2147483647; n   long long mm[m + 2]; n   for (int i = m - 1; i >= 0; i--) { n     if (i == m - 1) n       mm[i] = dp[i]; n     else n       mm[i] = max(dp[i], mm[i + 1]); n   } n   for (int i = 1; i < n; i++) { n     sum = 0; n     now = 1 - now; n     for (int j = 0; j < m; j++) { n       scanf( %d , &c); n       sum += c; n       dp[j] = sum; n     } n     for (int j = 0; j < m; j++) { n       if (i % 2 == 1) { n         if (j < m - 1) { n           dp[j] += mm[j + 1]; n         } else if (j == m - 1) { n           dp[j] = -2147483647; n         } n       } else { n         if (j == 0) n           dp[j] = -2147483647; n         else { n           dp[j] += mm[j - 1]; n         } n       } n       if (i == n - 1) { n         ans = max(ans, dp[j]); n       } n     } n     if (i % 2 == 0) { n       for (int j = m - 1; j >= 0; j--) { n         if (j == m - 1) n           mm[j] = dp[j]; n         else n           mm[j] = max(dp[j], mm[j + 1]); n       } n     } else { n       for (int j = 0; j < m; j++) { n         if (j == 0) n           mm[j] = dp[j]; n         else n           mm[j] = max(dp[j], mm[j - 1]); n       } n     } n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   vector<int> v(n); n   for (auto &first : v) cin >> first; n   int z = 0; n   for (auto first : v) n     if (first == 0) z++; n   if (z <= 1) { n     cout <<  0 n ; n     return; n   } n   vector<pair<int, int> > cnt(n, make_pair(0, 0)); n   int u = 0; n   for (int i = 0; i < n; ++i) { n     if (v[i] == 0) n       u++; n     else { n       cnt[v[i] - 1].first = max(cnt[v[i] - 1].first, min(u, z / 2)); n     } n     if (u > z - z / 2) { n       break; n     } n   } n   u = 0; n   for (int i = 0; i < n; ++i) { n     if (v[n - i - 1] == 0) n       u++; n     else { n       cnt[v[n - i - 1] - 1].second = n           max(cnt[v[n - i - 1] - 1].second, min(u, z / 2)); n     } n     if (u > z - z / 2) { n       break; n     } n   } n   sort(cnt.begin(), cnt.end(), greater<pair<int, int> >()); n   int ans = 0; n   multiset<int> rb; n   int ptr = 0; n   for (int i = z / 2; i > 0; i--) { n     while (ptr < cnt.size() && cnt[ptr].first == i) { n       rb.insert(cnt[ptr].second); n       ptr++; n     } n     if (rb.size()) { n       rb.erase(rb.begin()); n       ans++; n     } n   } n   while (ptr < cnt.size()) { n     rb.insert(cnt[ptr].second); n     ptr++; n   } n   for (int i = 1; i <= z / 2; ++i) { n     while (rb.size()) { n       auto it = rb.begin(); n       auto val = (*it); n       if (val < i) n         rb.erase(it); n       else n         break; n     } n     if (rb.size()) { n       rb.erase(rb.begin()); n       ans++; n     } n   } n   cout << min(ans, z / 2) <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   for (int i = 0; i < t; ++i) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n; n   cin >> n; n   long long int x; n   x = n % 4; n   if (n == 0) n     cout <<  1 ; n   else if (x == 0) n     cout <<  6 ; n   else if (x == 1) n     cout <<  8 ; n   else if (x == 2) n     cout <<  4 ; n   else if (x == 3) n     cout <<  2 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> grav[2050]; n int n; n int m, k; n int mark[2050]; n bool bad[2050]; n int sz[2050]; n void dfs(int v, int color) { n   mark[v] = color; n   for (int i = 0; i < (int)grav[v].size(); i++) { n     int u = grav[v][i]; n     if (mark[u] == 0) dfs(u, color); n   } n } n int main() { n   int u, v; n   cin >> n; n   cin >> m; n   for (int i = 0; i < (int)(m); i++) { n     cin >> u >> v; n     --u; n     --v; n     grav[u].push_back(v); n     grav[v].push_back(u); n   } n   int color = 1; n   for (int i = 0; i < (int)(n); i++) { n     if (mark[i] == 0) dfs(i, color++); n     sz[mark[i]]++; n   } n   cin >> k; n   for (int i = 0; i < (int)(k); i++) { n     cin >> u >> v; n     --u; n     --v; n     if (mark[u] == mark[v]) bad[mark[u]] = true; n   } n   int mx = 0; n   for (int c = 1; c < color; ++c) { n     if (!bad[c] && (mx == 0 || sz[c] > sz[mx])) mx = c; n   } n   cout << sz[mx] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve(); n int arr[200005]; n int count1[200005]; n int count2[200005]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   long long sum1 = 0; n   long long sum2 = 0; n   int cnt1 = 0; n   int cnt2 = 0; n   int j = 0; n   for (int i = n - 1; i >= 0; i--) { n     if (arr[i] == 0) { n       cnt1++; n     } n     count1[i] = cnt1; n   } n   for (int i = 0; i < n; i++) { n     if (arr[i] == 1) { n       cnt2++; n     } n     count2[i] = cnt2; n   } n   for (int i = 0; i < n; i++) { n     if (arr[i] == 1) sum2 += count1[i]; n   } n   for (int i = 0; i < n; i++) { n     if (arr[i] == 0) sum1 += count2[i]; n   } n   if (sum1 >= sum2) n     cout << sum2 << endl; n   else n     cout << sum1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2000 * 2000 + 1; n int n, m, mark[N], mx, rep; n string s; n vector<int> adj[N]; n bool circle(int v) { n   mark[v] = 1; n   for (int i = 0; i < adj[v].size(); i++) { n     int u = adj[v][i]; n     if (mark[u] == 1 || (!mark[u] && circle(u))) return true; n   } n   mark[v] = 2; n   return false; n } n int dfs(int v) { n   int res = 1; n   for (int i = 0; i < adj[v].size(); i++) { n     int u = adj[v][i], t = dfs(u); n     res = max(res, t + 1); n     if (t > mx) n       mx = t, rep = false; n     else if (t == mx) n       rep = true; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     string t; n     cin >> t; n     s += t; n   } n   n *= m; n   for (int i = 0; i < n; i++) n     if (s[i] ==  ^ ) n       adj[i - m].push_back(i); n     else if (s[i] ==  < ) n       adj[i - 1].push_back(i); n     else if (s[i] ==  > ) n       adj[i + 1].push_back(i); n     else if (s[i] ==  v ) n       adj[i + m].push_back(i); n   for (int i = 0; i < n; i++) n     if (circle(i)) { n       cout << -1 <<   n ; n       return 0; n     } n   fill(mark, mark + n, 0); n   for (int i = 0; i < n; i++) n     if (s[i] ==  # ) dfs(i); n   cout << max(0, 2 * mx - !rep) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 300005; n int a[maxn]; n int n, m, ma, mi; n int sum[2000005], ans[2000005]; n bool ok(int mid) { n   int ans = 0, i; n   for (i = mid; i <= ma; i += mid) { n     ans += sum[i + m] - sum[i - 1]; n   } n   if (ans == n) return true; n   return false; n } n int main() { n   int i, j; n   scanf( %d %d , &n, &m); n   ma = 1, mi = 1000006; n   for (i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     mi = min(mi, a[i]); n     ma = max(ma, a[i]); n     sum[a[i]]++; n   } n   if (m >= mi) { n     printf( %d n , mi); n     return 0; n   } n   for (i = 1; i <= ma + m; i++) { n     sum[i] += sum[i - 1]; n   } n   for (i = mi; i > m; i--) { n     if (ok(i)) break; n   } n   printf( %d n , i); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> arr(4 * n, 0); n     for (int i = 0; i < 4 * n; i++) { n       cin >> arr[i]; n     } n     sort(arr.begin(), arr.end()); n     int f = 1, i = 0, j = 4 * n - 1, area = arr[i] * arr[j]; n     while (i < j) { n       if ((arr[i + 1] != arr[i]) || (arr[j - 1] != arr[j]) || n           (arr[i] * arr[j] != area)) { n         f = 0; n         break; n       } n       i += 2; n       j -= 2; n     } n     if (f) { n       cout <<  YES n ; n     } else { n       cout <<  NO n ; n     } n   } n } n


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


#pragma GCC optimize( O3 ) n #pragma GCC optimize( unroll-loops ) n #include<iostream> n #include<string> n #include<cstdio> n #include<vector> n #include<cmath> n #include<algorithm> n #include<functional> n #include<iomanip> n #include<queue> n #include<ciso646> n #include<random> n #include<map> n #include<set> n #include<bitset> n #include<stack> n #include<unordered_map> n #include<unordered_set> n #include<utility> n #include<cassert> n #include<complex> n #include<numeric> n #include<array> n using namespace std; n  n //#define int long long n typedef long long ll; n  n typedef unsigned long long ul; n typedef unsigned int ui; n constexpr ll mod = 10007; n const ll INF = mod * mod; n typedef pair<int, int>P; n #define stop char nyaa;cin>>nyaa; n #define rep(i,n) for(int i=0;i<n;i++) n #define per(i,n) for(int i=n-1;i>=0;i--) n #define Rep(i,sta,n) for(int i=sta;i<n;i++) n #define rep1(i,n) for(int i=1;i<=n;i++) n #define per1(i,n) for(int i=n;i>=1;i--) n #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) n #define all(v) (v).begin(),(v).end() n typedef pair<ll, ll> LP; n typedef long double ld; n typedef pair<ld, ld> LDP; n const ld eps = 1e-12; n const ld pi = acosl(-1.0); n  n ll mod_pow(ll x, ll n, ll m = mod) { n  if (n < 0) { n   ll res = mod_pow(x, -n, m); n   return mod_pow(res, m - 2, m); n  } n  if (abs(x) >= m)x %= m; n  if (x < 0)x += m; n  ll res = 1; n  while (n) { n   if (n & 1)res = res * x % m; n   x = x * x % m; n >>= 1; n  } n  return res; n } n struct modint { n  ll n; n  modint() :n(0) { ; } n  modint(ll m) :n(m) { n   if (n >= mod)n %= mod; n   else if (n < 0)n = (n % mod + mod) % mod; n  } n  operator int() { return n; } n }; n bool operator==(modint a, modint b) { return a.n == b.n; } n modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; } n modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; } n modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; } n modint operator+(modint a, modint b) { return a += b; } n modint operator-(modint a, modint b) { return a -= b; } n modint operator*(modint a, modint b) { return a *= b; } n modint operator^(modint a, ll n) { n  if (n == 0)return modint(1); n  modint res = (a * a) ^ (n / 2); n  if (n % 2)res = res * a; n  return res; n } n  n ll inv(ll a, ll p) { n  return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); n } n modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); } n modint operator/=(modint& a, modint b) { a = a / b; return a; } n const int max_n = 1 << 1; n modint fact[max_n], factinv[max_n]; n void init_f() { n  fact[0] = modint(1); n  for (int i = 0; i < max_n - 1; i++) { n   fact[i + 1] = fact[i] * modint(i + 1); n  } n  factinv[max_n - 1] = modint(1) / fact[max_n - 1]; n  for (int i = max_n - 2; i >= 0; i--) { n   factinv[i] = factinv[i + 1] * modint(i + 1); n  } n } n modint comb(int a, int b) { n  if (a < 0 || b < 0 || a < b)return 0; n  return fact[a] * factinv[b] * factinv[a - b]; n } n modint combP(int a, int b) { n  if (a < 0 || b < 0 || a < b)return 0; n  return fact[a] * factinv[a - b]; n } n  n void solve() { n  int n, m, x; cin >> n >> m >> x; n  vector<int> h(n); rep(i, n)cin >> h[i]; n  vector<int> sum(m); n  priority_queue<P, vector<P>, greater<P>> q; n  rep(i, m)q.push({ 0,i }); n  vector<int> ans(n); n  rep(i, n) { n   P p = q.top(); q.pop(); n   int id = p.second; n   ans[i] = id; n   sum[id] += h[i]; n   q.push({ sum[id],id }); n  } n  cout <<  YES n ; n  rep(i, n) { n   if (i > 0)cout <<    ; n   cout << ans[i] + 1; n  } n  cout <<   n ; n } n  n  n signed main() { n  ios::sync_with_stdio(false); n  cin.tie(0); n  //cout << fixed << setprecision(10); n  //init_f(); n  //init(); n  //expr(); n  int t; cin >> t; rep(i, t) n   solve(); n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, dd, q; n   cin >> n >> dd >> q; n   int arr[200001]; n   for (int i = 0; i < 200001; i++) { n     arr[i] = 0; n   } n   for (int h = 0; h < n; h++) { n     int t1, t2; n     cin >> t1 >> t2; n     arr[t1]++; n     arr[t2 + 1]--; n   } n   int count = 0; n   for (int k = 0; k < 200001; k++) { n     count += arr[k]; n     arr[k] = count; n   } n   count = 0; n   int ans[200001]; n   for (int k = 0; k <= 200000; k++) { n     if (arr[k] >= dd) { n       count++; n     } n     ans[k] = count; n   } n   for (int kk = 0; kk < q; kk++) { n     int r1, r2; n     cin >> r1 >> r2; n     cout << ans[r2] - ans[r1 - 1] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n     int t; n     cin >> t; n     while(t--){ n         int n; n         cin >> n; n         vector<int> arr(n,0); n         for(int i = 0; i < n; i++){ n             cin >> arr[i]; n         } n         vector<int> str; n         str.push_back(arr[0]); n         cout << str[0] << endl; n         for(int i = 1; i < n; i++){ n             vector<int> temp; n             if(arr[i] == 1){ n                 for(int i = 0; i < str.size(); i++){ n                     temp.push_back(str[i]); n                 } n                 // temp = str; n                 temp.push_back(1); n             } n             else{ n                 for(int j = str.size() - 1; j >= 0; j--){ n                     if(str[j] == arr[i] - 1){ n                         for(int k = 0; k < j; k++){ n                             temp.push_back(str[k]); n                         } n                         temp.push_back(arr[i]); n                         break; n                     } n                 } n             } n             str = {}; n             for(int i = 0; i < temp.size(); i++){ n                 str.push_back(temp[i]); n             } n             for(int i = 0; i < str.size(); i++){ n                 cout << str[i]; n                 if(i != str.size() - 1) n                     cout <<  . ; n             } n             cout << endl; n         } n     } n } n


#include <bits/stdc++.h> n using namespace std; n int a; n char c[100009]; n unsigned int dp[200009] = {1}; n int main() { n   scanf( %d%s , &a, c); n   for (int i = a; i >= 1; i--) { n     c[i] = c[i - 1]; n   } n   if (a & 1) { n     cout << 0; n   } else { n     int e = a >> 1; n     int q = 0; n     for (int i = 1; i <= a; i++) { n       if (c[i] ==  ? ) { n         for (int j = (i >> 1); j >= i - e && j > 0; j--) { n           dp[j] += dp[j - 1]; n         } n       } else { n         q++; n       } n     } n     unsigned int ans = dp[e]; n     for (int i = 1; i <= e - q; i++) { n       ans *= 25; n     } n     cout << ans; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   while (scanf( %d , &n) == 1) { n     int ara[n + 4], diftab[n + 4]; n     ara[0] = 0; n     for (int i = 1; i <= n; i++) { n       scanf( %d , &ara[i]); n       diftab[i - 1] = ara[i] - ara[i - 1]; n     } n     int ansara[n + 1], index = 0; n     for (int i = 1; i <= n; i++) { n       bool paisi = true; n       for (int j = 0; j < n; j++) { n         if (diftab[j] != diftab[j % i]) { n           paisi = false; n           break; n         } n       } n       if (paisi) ansara[index++] = i; n     } n     printf( %d n , index); n     for (int i = 0; index > i; i++) printf( %d  , ansara[i]); n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> uf; n map<int, vector<int> > contents; n map<int, int> val; n void make(int a) { n   if (uf.find(a) == uf.end()) { n     uf[a] = a; n     contents[a].push_back(a); n     val[a] = 0; n   } n } n int main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   int q; n   cin >> q; n   int last = 0; n   for (int i = 0; i < q; i++) { n     int t; n     cin >> t; n     if (t == 1) { n       int l, r, x; n       cin >> l >> r >> x; n       l ^= last; n       r ^= last; n       x ^= last; n       if (l > r) swap(l, r); n       r++; n       make(l); n       make(r); n       if (uf[l] == uf[r]) continue; n       int v = val[l] ^ val[r] ^ x; n       l = uf[l]; n       r = uf[r]; n       if (contents[l].size() > contents[r].size()) { n         swap(l, r); n       } n       for (int a : contents[l]) { n         uf[a] = r; n         val[a] ^= v; n         contents[r].push_back(a); n       } n       contents.erase(l); n     } else { n       int l, r; n       cin >> l >> r; n       l ^= last; n       r ^= last; n       if (l > r) swap(l, r); n       r++; n       make(l); n       make(r); n       if (uf[l] != uf[r]) { n         cout << -1 <<   n ; n         last = 1; n       } else { n         cout << (val[l] ^ val[r]) <<   n ; n         last = val[l] ^ val[r]; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> g[200005]; n int par[19][200005]; n int depth[200005]; n int dp[200005]; n char s[200005]; n void dfs(int u, int p, int d, int val) { n   par[0][u] = p; n   depth[u] = d; n   dp[u] = val ^ (1 << (s[u] -  a )); n   for (int i = 0; i < g[u].size(); i++) { n     int v = g[u][i]; n     if (v == p) continue; n     dfs(v, u, d + 1, dp[u]); n   } n } n int LCA(int a, int b) { n   if (depth[a] < depth[b]) swap(a, b); n   int diff = depth[a] - depth[b]; n   for (int i = 18; i >= 0; i--) { n     if ((diff >> i) & 1) a = par[i][a]; n   } n   if (a == b) return a; n   for (int i = 18; i >= 0; i--) { n     if (par[i][a] != par[i][b]) a = par[i][a], b = par[i][b]; n   } n   return par[0][a]; n } n int dist(int a, int b) { return dp[a] ^ dp[b] ^ (1 << (s[LCA(a, b)] -  a )); } n int nn = 0; n int sub[200005]; n bool vis[200005]; n vector<pair<int, int> > edge[200005]; n long long cnt[2000005]; n long long ans[200005], add[200005]; n void dfs1(int u, int p) { n   sub[u] = 1; n   nn++; n   for (int i = 0; i < g[u].size(); i++) { n     int v = g[u][i]; n     if (v == p || vis[v]) continue; n     dfs1(v, u); n     sub[u] += sub[v]; n   } n } n int dfs2(int u, int p) { n   for (int i = 0; i < g[u].size(); i++) { n     int v = g[u][i]; n     if (v == p || vis[v]) continue; n     if (sub[v] > nn / 2) return dfs2(v, u); n   } n   return u; n } n void dfs3(int u, int p, int r, int idx) { n   int bits = dist(u, r); n   edge[idx].push_back(pair<int, int>(bits, u)); n   cnt[bits]++; n   for (int i = 0; i < g[u].size(); i++) { n     int v = g[u][i]; n     if (v == p || vis[v]) continue; n     dfs3(v, u, r, idx); n   } n } n void dfs4(int u, int p) { n   for (int i = 0; i < g[u].size(); i++) { n     int v = g[u][i]; n     if (v == p || vis[v]) continue; n     dfs4(v, u); n     add[u] += add[v]; n     add[v] = 0; n   } n   ans[u] += add[u]; n } n void decompose(int u, int p) { n   nn = 0; n   dfs1(u, u); n   int centroid = dfs2(u, u); n   vis[centroid] = 1; n   for (int i = 0; i < g[centroid].size(); i++) { n     int v = g[centroid][i]; n     if (v == p || vis[v]) continue; n     edge[i].clear(); n     dfs3(v, centroid, centroid, i); n   } n   for (int i = 0; i < g[centroid].size(); i++) { n     int v = g[centroid][i]; n     if (v == p || vis[v]) continue; n     for (int j = 0; j < edge[i].size(); j++) cnt[edge[i][j].first]--; n     for (int j = 0; j < edge[i].size(); j++) { n       int bits = edge[i][j].first; n       int cur = edge[i][j].second; n       int tot = __builtin_popcount(bits); n       if (tot <= 1) add[centroid]++, add[cur]++; n       add[cur] += cnt[bits ^ (1 << (s[centroid] -  a ))]; n       for (int j = 0; j < 20; j++) { n         add[cur] += cnt[bits ^ (1 << j) ^ (1 << (s[centroid] -  a ))]; n       } n     } n     for (int j = 0; j < edge[i].size(); j++) cnt[edge[i][j].first]++; n   } n   for (int i = 0; i < g[centroid].size(); i++) { n     int v = g[centroid][i]; n     if (v == p || vis[v]) continue; n     for (int j = 0; j < edge[i].size(); j++) cnt[edge[i][j].first] = 0; n   } n   for (int i = 0; i < g[centroid].size(); i++) { n     int v = g[centroid][i]; n     if (v == p || vis[v]) continue; n     dfs4(v, centroid); n     add[centroid] += add[v]; n     add[v] = 0; n   } n   ans[centroid] += add[centroid] / 2; n   add[centroid] = 0; n   for (int i = 0; i < g[centroid].size(); i++) { n     int v = g[centroid][i]; n     if (v == p || vis[v]) continue; n     decompose(v, centroid); n   } n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n - 1; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     g[a].push_back(b); n     g[b].push_back(a); n   } n   scanf( %s , s + 1); n   dfs(1, 0, 0, 0); n   for (int j = 1; j <= 18; j++) { n     for (int i = 1; i <= n; i++) { n       if (par[j - 1][i] != 0) par[j][i] = par[j - 1][par[j - 1][i]]; n     } n   } n   decompose(1, 0); n   for (int i = 1; i <= n; i++) printf( %lld  , ans[i] + 1); n } n


#include <bits/stdc++.h> n using namespace std; n bool *Seive(long long n, bool *p) { n   memset(p, 1, sizeof(p)); n   long long i, j; n   for (i = 2; i <= n; i++) { n     if (p[i] == 1) n       for (j = i * i; j <= n; j += i) { n         p[j] = 0; n       } n   } n   p[1] = 0; n   return p; n } n long long gcd(long long a, long long b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n long long modexp(long long x, long long y) { n   if (y == 0) n     return 1; n   else if (y % 2 == 0) { n     return modexp((x * x) % (long long)998244353, y / 2); n   } else { n     return (x * modexp((x * x) % (long long)998244353, (y - 1) / 2)) % n            (long long)998244353; n   } n } n long long fact(long long n) { n   long long f = 1; n   for (long long i = 2; i <= n; i++) { n     f = (i % (long long)998244353 * f % (long long)998244353) % n         (long long)998244353; n   } n   return f; n } n long long nCr(long long n, long long r) { n   return (fact(n) * modexp((fact(n - r) * fact(r)) % (long long)998244353, n                            (long long)998244353 - 2)) % n          (long long)998244353; n } n void showlist(list<int64_t> g) { n   list<int64_t>::iterator it; n   for (it = g.begin(); it != g.end(); ++it) cout << *it <<    ; n   cout <<   n ; n } n void swap(int64_t &a, int64_t &b) { n   int64_t t; n   t = a; n   a = b; n   b = t; n } n void build(int64_t l, int64_t r, int64_t i) { n   if (l == r) { n   } else { n     int64_t mid = (l + r) / 2; n     build(l, mid, 2 * i); n     build(mid + 1, r, 2 * i + 1); n   } n } n void update(int64_t p, int64_t l, int64_t r, int64_t i) { n   if (l == r) { n   } else { n     int64_t mid = (l + r) / 2; n     if (p <= mid) { n       update(p, l, mid, 2 * i); n     } else { n       update(p, mid + 1, r, 2 * i + 1); n     } n   } n } n void query(int64_t y, int64_t z, int64_t l, int64_t r, int64_t i) { n   if (y <= l && z >= r) { n   } else { n     int64_t mid = (l + r) / 2; n     if (z <= mid) { n       query(y, z, l, mid, 2 * i); n     } else if (y > mid) { n       query(y, z, mid + 1, r, 2 * i + 1); n     } else { n       query(y, z, l, mid, 2 * i); n       query(y, z, mid + 1, r, 2 * i + 1); n     } n   } n } n void make_set(int64_t v) {} n int64_t find_set(int64_t v) {} n void union_sets(int64_t a, int64_t b) {} n int64_t dfs(int64_t r, int64_t *d, int64_t &e, int64_t l, n             vector<vector<int64_t>> &adj, int64_t *v, int64_t a[][2]) { n   a[r][1] = e + d[r]; n   e = a[r][1]; n   l = e; n   int64_t j = 0; n   for (int64_t i = 0; i < adj[r].size(); i++) { n     if (v[adj[r][i]] == 0) { n       v[adj[r][i]] = 1; n       a[adj[r][i]][0] = l - (j + 1); n       dfs(adj[r][i], d, e, l, adj, v, a); n       j++; n     } n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int64_t n, k, i, j, w; n   cin >> n >> k; n   string s; n   set<string> g; n   for (i = 0; i < n; i++) { n     cin >> s; n     g.insert(s); n   } n   vector<string> v; n   for (auto it = g.begin(); it != g.end(); it++) { n     v.push_back(*it); n   } n   int64_t sum = 0; n   for (i = 0; i < n - 2; i++) { n     string q; n     q = v[i]; n     set<string> t; n     for (j = i + 1; j < n; j++) { n       t.insert(v[j]); n     } n     for (j = i + 1; j < n; j++) { n       string z; n       z = v[j]; n       string d; n       for (w = 0; w < k; w++) { n         if (q[w] == z[w]) { n           d += q[w]; n         } else { n           char a; n           if (q[w] ==  S  && z[w] ==  T  || z[w] ==  S  && q[w] ==  T ) { n             a =  E ; n           } else if (q[w] ==  E  && z[w] ==  T  || z[w] ==  E  && q[w] ==  T ) { n             a =  S ; n           } else if (q[w] ==  E  && z[w] ==  S  || z[w] ==  E  && q[w] ==  S ) { n             a =  T ; n           } n           d += a; n         } n       } n       if (t.find(d) != t.end()) { n         sum++; n         t.erase(d); n         t.erase(z); n       } else { n         t.erase(z); n       } n     } n   } n   cout << sum <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int main() { n   int t; n   cin >> t; n   while (t--) { n     string s; n     cin >> s; n     vector<int> counts; n     int current_count = 0; n     for (char c : s) { n       if (c ==  1 ) { n         current_count += 1; n       } else if (current_count != 0) { n         counts.emplace_back(current_count); n         current_count = 0; n       } n     } n     if (current_count != 0) { n       counts.emplace_back(current_count); n     } n     sort(counts.begin(), counts.end()); n     int n = counts.size(); n     int score = 0; n     for (int i = 1 - (n % 2); i < n; i += 2) { n       score += counts[i]; n     } n     cout << score <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool chmax(T &a, const T &b) { n   if (a < b) { n     a = b; n     return 1; n   } n   return 0; n } n template <class T> n bool chmin(T &a, const T &b) { n   if (a > b) { n     a = b; n     return 1; n   } n   return 0; n } n template <class T> n ostream &operator<<(ostream &os, const vector<T> &t) { n   os <<  [ ; n   for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) { n     if (it != t.begin()) os <<  , ; n     os << *it; n   } n   os <<  ] ; n   return os; n } n template <class T> n ostream &operator<<(ostream &os, const set<T> &t) { n   os <<  { ; n   for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) { n     if (it != t.begin()) os <<  , ; n     os << *it; n   } n   os <<  } ; n   return os; n } n template <class S, class T> n ostream &operator<<(ostream &os, const pair<S, T> &t) { n   return os <<  (  << t.first <<  ,  << t.second <<  ) ; n } n const int INF = 1 << 28; n const double EPS = 1e-8; n const int MOD = 1000000007; n long long int t, a, b; n long double x[2][60]; n long long int dfs(int co, long long int re1, long long int re2) { n   if (co == 1) { n     if (t == a || (re1 - re2) % (t - a)) return 0; n     long long int i = (re1 - re2) / (t - a); n     return !(re1 - i * t < 0 || re2 - i * a < 0 || i < 0); n   } n   long long int ans = 0; n   while (re1 >= 0 && re2 >= 0) { n     ans += dfs(co - 1, re1, re2); n     re1 -= x[0][co]; n     re2 -= x[1][co]; n   } n   return ans; n } n int main() { n   cin >> t >> a >> b; n   if (t == 1 && a == 1 && b == 1) { n     puts( inf ); n     return 0; n   } n   if (t == a && a == b) { n     puts( 2 ); n     return 0; n   } n   if (t == a) { n     puts( 0 ); n     return 0; n   } n   for (long long int i = 0; i < (long long int)(60); i++) { n     x[0][i] = powl(t, i); n     x[1][i] = powl(a, i); n   } n   cout << dfs(59, a, b) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005; n int n; n long long a[N], b[N]; n int f[N][2]; n long long WIN(long long x, long long y) { n   assert(x <= y); n   if (y & 1) return !(x & 1); n   if (x * 2 > y) return x & 1; n   if (x * 4 > y) return 1; n   return WIN(x, y / 4); n } n long long LOSE(long long x, long long y) { n   assert(x <= y); n   if (x * 2 > y) return 1; n   return WIN(x, y / 2); n } n int main() { n   scanf( %d , &n); n   for (int i = (int)(1); i <= (int)(n); i++) scanf( %lld%lld , &a[i], &b[i]); n   f[n][0] = WIN(a[n], b[n]); n   f[n][1] = LOSE(a[n], b[n]); n   for (int i = (int)(n - 1); i >= (int)(1); i--) { n     if (f[i + 1][0] == 0 && WIN(a[i], b[i])) f[i][0] = 1; n     if (f[i + 1][0] == 1 && LOSE(a[i], b[i])) f[i][0] = 1; n     if (f[i + 1][1] == 0 && WIN(a[i], b[i])) f[i][1] = 1; n     if (f[i + 1][1] == 1 && LOSE(a[i], b[i])) f[i][1] = 1; n   } n   cout << f[1][0] <<     << f[1][1] << endl; n } n


#include <bits/stdc++.h> n int main() { n   char str[120]; n   gets(str); n   int len = strlen(str) - 1; n   int i; n   int count = 0; n   int reversed = 0; n   for (i = 0; i < len; i++) { n     if (str[i] ==  V  && str[i + 1] ==  K ) { n       str[i] =  c ; n       str[i + 1] =  c ; n       ++count; n     } n   } n   for (i = 0; i < len; i++) { n     if ((str[i] ==  V  && str[i + 1] ==  V ) || n         (str[i] ==  K  && str[i + 1] ==  K )) n       reversed = 1; n   } n   printf( %d , count + reversed); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxCol = 200010; n const int maxID = 400010; n const int INF = 400010; n typedef struct RangeInfo { n   int dist[2][2]; n   int L; n   int R; n   RangeInfo() { L = R = -1; } n   RangeInfo(int idx, const vector<vector<bool> >& isEmpty) { n     L = R = idx; n     dist[0][0] = isEmpty[0][idx] ? 0 : INF; n     dist[1][1] = isEmpty[1][idx] ? 0 : INF; n     dist[0][1] = dist[1][0] = (isEmpty[0][idx] && isEmpty[1][idx]) ? 1 : INF; n   } n   bool operator==(RangeInfo other) { return L == other.L && R == other.R; } n } RangeInfo; n class SegmentTree { n  private: n   vector<RangeInfo> segTree; n   vector<vector<bool> > isEmpty; n   int N; n   RangeInfo nullRange; n   int getLeft(int idx) { return idx << 1; } n   int getRight(int idx) { return (idx << 1) + 1; } n   RangeInfo merge(const RangeInfo& left, const RangeInfo& right) { n     RangeInfo result; n     result.L = left.L; n     result.R = right.R; n     for (int startRow = 0; startRow < 2; startRow++) { n       for (int endRow = 0; endRow < 2; endRow++) { n         result.dist[startRow][endRow] = INF; n         for (int midRow = 0; midRow < 2; midRow++) { n           result.dist[startRow][endRow] = n               min(result.dist[startRow][endRow], n                   left.dist[startRow][midRow] + 1 + right.dist[midRow][endRow]); n         } n       } n     } n     return result; n   } n   void build(int idx, int L, int R) { n     if (L == R) { n       RangeInfo singleRange(L, isEmpty); n       segTree[idx] = singleRange; n     } else { n       build(getLeft(idx), L, (L + R) / 2); n       build(getRight(idx), (L + R) / 2 + 1, R); n       RangeInfo left = segTree[getLeft(idx)], right = segTree[getRight(idx)]; n       segTree[idx] = merge(left, right); n     } n   } n   RangeInfo rmq(const int& idx, const int& targetL, const int& targetR) { n     int curL = segTree[idx].L; n     int curR = segTree[idx].R; n     if (targetR < curL || curR < targetL) return nullRange; n     if (targetL <= curL && curR <= targetR) return segTree[idx]; n     RangeInfo left = rmq(getLeft(idx), targetL, targetR); n     RangeInfo right = rmq(getRight(idx), targetL, targetR); n     if (left == nullRange) return right; n     if (right == nullRange) return left; n     RangeInfo result = merge(left, right); n     return result; n   } n  n  public: n   SegmentTree(const vector<vector<bool> >& _isEmpty) { n     isEmpty = _isEmpty; n     N = isEmpty[0].size(); n     segTree.resize(8 * N); n     build(1, 0, N - 1); n   } n   RangeInfo rmq(const int& targetL, const int& targetR) { n     return rmq(1, targetL, targetR); n   } n }; n typedef struct Coord { n   int row, col; n   Coord(int& id, const int& N) { n     id--; n     row = id / N; n     col = id % N; n   } n } Coord; n int main() { n   int N, M; n   cin >> N >> M; n   vector<vector<bool> > isEmpty(2, vector<bool>(N, false)); n   char cur; n   for (int r = 0; r < 2; r++) { n     for (int c = 0; c < N; c++) { n       cin >> cur; n       isEmpty[r][c] = cur ==  . ; n     } n   } n   SegmentTree segTree(isEmpty); n   int sourceId, targetId; n   for (int i = 0; i < M; i++) { n     cin >> sourceId >> targetId; n     Coord left(sourceId, N); n     Coord right(targetId, N); n     if (left.col > right.col) { n       swap(left, right); n     } n     RangeInfo result = segTree.rmq(left.col, right.col); n     int shortestCost = result.dist[left.row][right.row]; n     cout << (shortestCost == INF ? -1 : shortestCost) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 7; n const int M = 22; n const long long mod = 1e9 + 7; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   long long s = 0; n   while (s * 10 + 9 <= n + n - 1) { n     s = s * 10 + 9; n   } n   if (s == n + n - 1) { n     cout << 1; n   } else { n     long long len = 1; n     while (len * 1ll * 10 <= 1ll * n + n - 1ll) { n       len *= 10; n     } n     long long i = s; n     long long ans = 0; n     for (; i <= n + n - 1; i += len) { n       if (i <= n + 1) { n         ans += (i - 1) / 2; n       } else { n         long long x = i - n; n         x = n - x + 1; n         ans += x / 2; n       } n     } n     cout << ans; n   } n } n


#include<bits/stdc++.h> n #define rep(i,a,b)    for(int i=a;i<b;i++) n #define ret(x) return cout<<x,0; n #define rety return cout<< YES ,0; n #define retn return cout<< NO ,0; n typedef long long ll; n typedef double db; n typedef long double ld; n #define stt string n #define ve vector<ll> n #define se set<ll> n #define ar array n ll mod=1e9+7,mod2=998244353; n using namespace std; n ll fac[10000000]; n ll gcd(ll x, ll y) n { n    if(y==0) n        return x; n    return gcd(y,x%y); n } n ll fexp(ll a,ll b,ll m){ll ans = 1;while(b){if(b&1)ans=ans*a%m; b/=2;a=a*a%m;}return ans;} n ll inverse(ll a, ll p){return fexp(a, p-2,p);} n ll ncr(ll n, ll r,ll p) n { n    if (r==0) return 1; n    return (fac[n]*inverse(fac[n-r],p)%p*inverse(fac[r],p)%p)%p; n } n // ____Z-Algorithm_____ n vector<ll> za(string s) n { n   ll n = s.size(); n    vector<ll> z(n); n    ll x = 0, y = 0,p=0; n           for(ll i= 1; i < n; i++) n          { n           z[i] = max(p,min(z[i-x],y-i+1)); n         while(i+z[i] < n && s[z[i]] == s[i+z[i]]) n              { n               x = i; y = i+z[i]; z[i]++; n              } n          } n return z; n } n void subset(ll a[],ll k) n { n    for (int i = 1; i < pow(2, k); i++) n    { n        for (int j = 0; j < k; j++) n        { n            if (i & 1 << j) n            { n                 cout<<a[j]<<   ; n            } n        } n        cout<<endl; n    } n } n vector<ll> pr(string s) n { n    ll n = s.length(); n    vector<ll> pi(n); n    for (int i = 1; i < n; i++) n    { n        int j = pi[i-1]; n        while (j > 0 && s[i] != s[j]) n            j = pi[j-1]; n        if (s[i] == s[j]) n            j++; n        pi[i] = j; n    } n    return pi; n } n //---------------------------------------------------------------------/ n int main() n { n   ios::sync_with_stdio(0); n   cin.tie(0); n   ll t; n   cin>>t; n   while(t--) n   { n     int n; n cin >> n; n vector<int> a(n); n for(int i = 0; i < n; i++) { n     cin >> a[i]; n } n cout << 3*n << endl; n  for(int i = 1; i <= n; i+=2) n  { n     cout << 1 <<     << i <<     << i+1 << endl; n     cout << 2 <<     << i <<     << i+1 << endl; n     cout << 2 <<     << i <<     << i+1 << endl; n     cout << 1 <<     << i <<     << i+1 << endl; n     cout << 2 <<     << i <<     << i+1 << endl; n     cout << 2 <<     << i <<     << i+1 << endl; n  } n  } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool umin(T& a, T b) { n   if (a > b) { n     a = b; n     return 1; n   } n   return 0; n } n template <class T> n bool umax(T& a, T b) { n   if (a < b) { n     a = b; n     return 1; n   } n   return 0; n } n long long F[2][2][1009][1009]; n void upd(int x, int y, long long v) { n   for (int i = x; i < 1009; i += i & (-i)) n     for (int j = y; j < 1009; j += j & (-j)) n       F[x & 1][y & 1][i][j] = F[x & 1][y & 1][i][j] xor v; n } n long long tap(int x, int y) { n   long long res = 0; n   for (int i = x; i; i -= i & (-i)) n     for (int j = y; j; j -= j & (-j)) res = res xor F[x & 1][y & 1][i][j]; n   return res; n } n int main() { n   int n, q; n   scanf( %d%d , &n, &q); n   while (q--) { n     int type, x, x1, y1, y; n     long long v; n     scanf( %d%d%d%d%d , &type, &x, &y, &x1, &y1); n     if (type == 2) { n       scanf( %lld , &v); n       upd(x, y, v); n       upd(x1 + 1, y, v); n       upd(x, y1 + 1, v); n       upd(x1 + 1, y1 + 1, v); n     } else n       printf( %lld n , tap(x1, y1) xor tap(x1, y - 1) xor tap(x - 1, y1) xor n                            tap(x - 1, y - 1)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 10; n int pref[N]; n vector<int> v; n int fsoma(int l, int r) { n   l--; n   int ans = pref[r]; n   if (l >= 0) ans -= pref[l]; n   return ans; n } n long long n, k, l; n void rbest(pair<int, int> &a, pair<int, int> b) { n   if (b.first > a.first or (a.first == b.first and b.second < a.second)) a = b; n } n pair<int, int> comb(pair<int, int> a, pair<int, int> b) { n   return {a.first + b.first, a.second + b.second}; n } n vector<pair<int, int>> dp(n); n pair<int, int> rec(int i) { n   if (i >= 0) return dp[i]; n   return {0, 0}; n } n pair<int, int> f(int c) { n   dp = vector<pair<int, int>>(n); n   for (int i = 0; i < n; i++) { n     rbest(dp[i], rec(i - 1)); n     rbest(dp[i], comb(rec(i - l), {fsoma(i - (l - 1), i) - c, 1})); n   } n   return dp[n - 1]; n } n long long solve(vector<int> &_v) { n   v = _v; n   for (int i = 0; i < (int)(v.size()); i++) { n     pref[i] = v[i]; n     if (i) pref[i] += pref[i - 1]; n   } n   int lo = 0, hi = l + 1; n   while (lo < hi) { n     int mid = (lo + hi) / 2; n     if (f(mid).second <= k) n       hi = mid; n     else n       lo = mid + 1; n   } n   auto par = f(lo); n   return pref[(int)(v.size()) - 1] - (par.first + lo * k); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> k >> l; n   string s; n   cin >> s; n   vector<int> v1((int)(s.size())), v2((int)(s.size())); n   for (int i = 0; i < (int)(s.size()); i++) { n     if (s[i] >=  A  and s[i] <=  Z ) { n       v1[i] = 1; n     } else { n       v2[i] = 1; n     } n   } n   cout << min(solve(v1), solve(v2)) <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n void fast() { n   std::ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   cerr.tie(NULL); n } n int main() { n   fast(); n   unsigned long long over = pow(2, 32); n   string s; n   int i; n   unsigned long long num = 0; n   stack<unsigned long long> loop; n   loop.push(1); n   int n; n   cin >> n; n   while (n--) { n     cin >> s; n     if (s ==  add ) { n       num += loop.top(); n       if (num >= over) { n         cout <<  OVERFLOW!!! ; n         return 0; n       } n     } else if (s ==  for ) { n       cin >> i; n       loop.push(min(over, loop.top() * i)); n     } else { n       loop.pop(); n     } n   } n   cout << num; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m; n char A[1020304], B[1020304]; n int data[1020304][27], vis[1020304]; n int main() { n   cin >> n >> m; n   scanf( %s%s , A + 1, B + 1); n   int la = strlen(A + 1), lb = strlen(B + 1); n   memset(vis, 0, sizeof(vis)); n   int len = 0; n   int Tot = 0; n   for (int i = 1; i <= lb; ++i) n     if (!vis[i]) { n       ++Tot; n       vis[i] = Tot; n       memset(data[Tot], 0, sizeof(data[Tot])); n       ++data[Tot][B[i] -  a ]; n       len = 1; n       for (int z = (i - 1 + la) % lb + 1; !vis[z]; z = (z - 1 + la) % lb + 1) { n         vis[z] = Tot; n         ++data[Tot][B[z] -  a ]; n         ++len; n       } n     } n   long long ans = 0; n   for (int i = 1; i <= la; ++i) { n     for (int j = 0; j <= 25; ++j) n       if ( a  + j != A[i]) { n         long long pos = (i - 1 + lb) % lb + 1; n         ans += (long long)data[vis[pos]][j] * n / len; n       } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, k; n long long calc(long long nk, long long mk) { n   return (n / (nk + 1)) * (m / (mk + 1)); n } n int main() { n   cin >> n >> m >> k; n   if (k > n + m - 2) { n     cout << -1; n     return 0; n   } n   long long nk = min(k, n - 1); n   long long mk = min(k, m - 1); n   long long a = calc(nk, k - nk); n   long long b = calc(k - mk, mk); n   cout << max(a, b); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char* argv[]) { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   int minr = 1e9 + 2; n   int maxl = 0; n   for (int i = 0; i < n; i++) { n     int l, r; n     cin >> l >> r; n     if (l > maxl) { n       maxl = l; n     } n     if (r < minr) { n       minr = r; n     } n   } n   int m; n   cin >> m; n   int minr2 = 1e9 + 2; n   int maxl2 = 0; n   for (int i = 0; i < m; i++) { n     int l, r; n     cin >> l >> r; n     if (l > maxl2) { n       maxl2 = l; n     } n     if (r < minr2) { n       minr2 = r; n     } n   } n   int diff1 = maxl - minr2; n   int diff2 = maxl2 - minr; n   int sol = max(max(diff1, diff2), 0); n   cout << sol <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> report(n); n   int posCount = 0; n   int negCount = 0; n   for (int i = 0; i < n; i++) { n     cin >> report[i]; n     if (report[i] >= 0) { n       posCount++; n     } else { n       negCount++; n     } n   } n   if (posCount == n) { n     cout << 1 << endl; n     cout << n << endl; n     return 0; n   } n   if (negCount <= 2) { n     cout << 1 << endl; n     cout << n << endl; n     return 0; n   } n   int neg = 0; n   int folders = 0; n   int partitions = 0; n   vector<int> item; n   for (int i = 0; i < report.size(); i++) { n     folders++; n     if (report[i] < 0) { n       neg++; n       if (neg == 3) { n         item.push_back(--folders); n         i--; n         partitions++; n         folders = 0; n         neg = 0; n       } n     } n   } n   if (folders != 0) { n     item.push_back(folders); n   } n   cout << ++partitions << endl; n   for (auto x : item) { n     cout << x <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int b[105]; n int vis[105]; n int main() { n   int n; n   scanf( %d , &n); n   int a[105]; n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     b[a[i]]++; n   } n   int ans1 = 0; n   int ans2 = 0; n   int jo = 1; n   int mm = 0; n   for (int i = 0; i < n; i++) { n     int x = a[i]; n     if (b[x] > 0) { n       if (b[x] <= 2) { n         if (jo == 1) { n           vis[i] = 1; n           jo = -1; n           ans1++; n           if (b[x] == 2) { n             for (int j = i + 1; j <= n; j++) { n               if (a[i] == x) { n                 vis[i] = -1; n                 jo = 1; n                 ans2++; n                 break; n               } n             } n           } n         } else { n           vis[i] = -1; n           jo = 1; n           ans2++; n           if (b[x] == 2) { n             for (int j = i + 1; j <= n; j++) { n               if (a[i] == x) { n                 vis[i] = 1; n                 jo = -1; n                 ans1++; n                 break; n               } n             } n           } n         } n         b[x] = 0; n       } else { n         mm++; n       } n     } n   } n   if (ans1 == ans2) { n     cout <<  YES  << endl; n     for (int i = 0; i < n; i++) { n       if (vis[i] == 1) { n         cout <<  B ; n       } else { n         cout <<  A ; n       } n     } n   } else { n     if (mm == 0) { n       cout <<  NO  << endl; n     } else { n       if (ans1 > ans2) { n         for (int i = 0; i < n; i++) { n           if (b[a[i]] > 2) { n             vis[i] = -1; n             break; n           } n         } n         cout <<  YES  << endl; n         for (int i = 0; i < n; i++) { n           if (vis[i] == 1 || vis[i] == 0) { n             cout <<  B ; n           } else { n             cout <<  A ; n           } n         } n       } else { n         for (int i = 0; i < n; i++) { n           if (b[a[i]] > 2) { n             vis[i] = 1; n             break; n           } n         } n         cout <<  YES  << endl; n         for (int i = 0; i < n; i++) { n           if (vis[i] == 1) { n             cout <<  B ; n           } else { n             cout <<  A ; n           } n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s1; n   string s2; n   while (cin >> s1 >> s2) { n     int n = s1.length(), m = s2.length(); n     int dp[n + 1][m + 1]; n     for (int i = 0; i < n + 1; i++) dp[i][0] = i; n     for (int i = 0; i < m + 1; i++) dp[0][i] = i; n     for (int i = 1; i < n + 1; i++) { n       for (int j = 1; j < m + 1; j++) { n         if (s1[i - 1] == s2[j - 1]) n           dp[i][j] = dp[i - 1][j - 1]; n         else n           dp[i][j] = min(min(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]) + 1; n       } n     } n     cout << dp[n][m] << endl; n     int i = n, j = m; n     while (i >= 0 && j >= 0) { n       if (dp[i][j - 1] == dp[i][j] - 1) { n         cout <<  INSERT   + to_string(i + 1) +     + s2[j - 1] << endl; n         j--; n       } else if (dp[i - 1][j] == dp[i][j] - 1) { n         cout <<  DELETE   + to_string(i) << endl; n         i--; n       } else if (dp[i - 1][j - 1] == dp[i][j] - 1 && s1[i - 1] != s2[j - 1]) { n         cout <<  REPLACE   + to_string(i) +     + s2[j - 1] << endl; n         i--, j--; n       } else n         i--, j--; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Trie { n   struct Node { n     char c; n     vector<pair<int, int> > n; n     Node* ch[26]; n     Node(char ch) { n       this->c = ch; n       for (int i = 0; i < 26; i++) this->ch[i] = NULL; n     } n   }; n   Node* root; n   vector<pair<int, int> > res; n   int sum; n   Trie() { n     root = new Node(   ); n     sum = 0; n   } n   void create(string s, int t, int ind) { n     Node* now = root; n     for (int i = 0; i < s.size(); i++) { n       if (now->ch[s[i] -  a ] == NULL) n         now = now->ch[s[i] -  a ] = new Node(s[i]); n       else n         now = now->ch[s[i] -  a ]; n     } n     (now->n).push_back(make_pair(ind, t)); n   } n   pair<vector<int>, vector<int> > dfs(Node* now, int depth) { n     vector<int> O, P; n     for (int i = 0; i < 26; i++) n       if (now->ch[i] != NULL) { n         pair<vector<int>, vector<int> > t = dfs(now->ch[i], depth + 1); n         O.insert(O.end(), t.first.begin(), t.first.end()); n         P.insert(P.end(), t.second.begin(), t.second.end()); n       } n     vector<pair<int, int> > t = now->n; n     for (int i = 0; i < t.size(); i++) n       if (t[i].second == 1) n         O.push_back(t[i].first); n       else if (t[i].second == 2) n         P.push_back(t[i].first); n     while (O.size() && P.size()) { n       sum += depth; n       res.push_back(make_pair(O[0], P[0])); n       O.erase(O.begin()); n       P.erase(P.begin()); n     } n     return make_pair(O, P); n   } n   void doit() { n     dfs(root, 0); n     printf( %d n , sum); n     for (int i = 0; i < res.size(); i++) n       printf( %d %d n , res[i].first, res[i].second); n   } n }; n int main() { n   Trie trie; n   string s; n   int n; n   scanf( %d n , &n); n   for (int i = 1; i <= 2; i++) n     for (int j = 1; j <= n; j++) { n       cin >> s; n       trie.create(s, i, j); n     } n   trie.doit(); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1E5 + 5; n int t[N], n, a[N], f[N], b[N], k, x, mid; n vector<int> G[N]; n long long ans; n bool O = 0; n int work() { n   memset(f, 0, sizeof(f)); n   for (int i = k; i <= n - k + 1; i++) f[b[i]]++; n   int o = 0; n   for (int i = 1; i <= n; i++) n     if (f[i] & 1) { n       if (o) return n - k + 1; n       o = i; n     } n   if (((n & 1) ^ (o > 0))) return n - k + 1; n   memset(f, 0, sizeof(f)); n   for (int i = 1; i <= n; i++) G[i].clear(); n   for (int i = k; i <= n - k + 1; i++) { n     x = b[i]; n     t[x]++; n     G[x].push_back(i); n   } n   int mini = k; n   if (o && o != b[mid]) mini = mid; n   O = 1; n   for (int i = n - k + 1; i >= mini; i--) n     if (i > mid) { n       f[x = b[i]]++; n       if (f[x] > t[x] || G[x][f[x] - 1] >= i) return i - 1; n       if (b[i] != b[n - i + 1]) mini = max(mini, G[x][f[x] - 1]); n     } else if (b[i] != b[n - i + 1]) n       return i - 1; n   return mini - 1; n } n int main() { n   cin >> n; n   mid = n / 2 + (n & 1); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (k = 1; k <= mid && a[k] == a[n - k + 1]; k++) n     ; n   if (k > mid) { n     cout << (long long)n * (n + 1) / 2; n     return 0; n   } n   for (int i = k; i <= n - k + 1; i++) b[i] = a[i]; n   ans = n - k + 1 - work(); n   for (int i = k; i <= n - k + 1; i++) b[n - i + 1] = a[i]; n   ans += n - k + 1 - work(); n   ans = ans * k; n   if (ans) ans += (long long)(k - 1) * (k - 1); n   if (O) ans--; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 0x3f3f3f3f; n const int N = 2e5 + 10; n const long long mod = 1e9 + 7; n const bool debug = false; n int F[N], Finv[N], inv[N]; n void init() { n   inv[1] = 1, F[0] = Finv[0] = 1; n   for (int i = 2; i < N; i++) n     inv[i] = (mod - mod / i) * 1ll * inv[mod % i] % mod; n   for (int i = 1; i < N; i++) { n     F[i] = F[i - 1] * 1ll * i % mod; n     Finv[i] = Finv[i - 1] * 1ll * inv[i] % mod; n   } n } n int comb(int n, int m) { n   if (m < 0 || m > n) return 0; n   return F[n] * 1ll * Finv[n - m] % mod * Finv[m] % mod; n } n int main() { n   init(); n   int n; n   long long T; n   scanf( %d%lld , &n, &T); n   long long pre = 1, r = 0, ans = 0, gg = 1; n   for (int i = 1, x; i <= n; ++i) { n     scanf( %d , &x); n     T -= x; n     if (T < 0) break; n     pre = (pre * 2 - comb(i - 1, r) + mod) % mod; n     while (r < min(i * 1ll, T)) { n       pre += comb(i, ++r); n     } n     while (r > min(i * 1ll, T)) { n       pre -= comb(i, r--); n     } n     pre %= mod; n     if (pre < 0) pre += mod; n     gg = gg * (mod + 1) / 2 % mod; n     ans = (ans + pre * gg) % mod; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n long long a[1010]; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   long long k; n   cin >> k; n   cin >> k; n   cin >> k; n   long long x = (long long)a[2] * a[1] / k; n   long double dx = x; n   long long ans = (long long)(sqrt(x) + 0.005); n   cout << ans <<    ; n   for (int i = 1; i < n; i++) { n     cout << a[i] / ans <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long _pow(long long a, long long b) { n   long long x = 1; n   for (long long j = 0; j < b; j++) { n     x *= a; n   } n   return x; n } n bool test(int a, int n, int m) { n   if (a <= 0) n     return true; n   else if (m == 0 && n == 0) n     return false; n   else { n     if (n > 0 && (a > (a / 2) + 10)) return test(a / 2 + 10, n - 1, m); n     if (m > 0) return test(a - 10, n, m - 1); n     if (n > 0) return false; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int t; n   cin >> t; n   for (int h = 0; h < t; h++) { n     int a, n, m; n     cin >> a >> n >> m; n     cout << (test(a, n, m) ?  YES  :  NO ) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, d; n   cin >> a >> b >> c >> d; n   int m = max((3 * a) / 10, a - (a * c) / 250); n   int v = max((3 * b) / 10, b - (b * d) / 250); n   if (m > v) n     cout <<  Misha  << endl; n   else if (v > m) n     cout <<  Vasya  << endl; n   else n     cout <<  Tie  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long md = 1e9 + 7; n const long long arr = 2e5; n long long a[arr], aa[arr]; n long long n, d, b; n bool check(long long u) { n   for (long long i = 1; i <= n; i++) a[i] = aa[i]; n   long long pluss = 0; n   long long uu = u; n   long long start = 1; n   long long mid = n / 2 + n % 2; n   while (1) { n     if (a[start] >= b) n       pluss += a[start] - b; n     else if (uu) n       uu--, pluss += a[start]; n     else n       break; n     start++; n     if (start > mid) break; n   } n   long long last = start; n   pluss += a[start]; n   for (long long i = start; i <= mid; i++) { n     while (last + 1 <= min(i + i * d, n)) { n       last++; n       pluss += a[last]; n       a[last] = 0; n     } n     if (pluss < b) return (0); n     pluss -= b; n   } n   for (long long i = 1; i <= n; i++) a[i] = aa[i]; n   reverse(a + 1, a + 1 + n); n   pluss = 0; n   uu = u; n   start = 1; n   mid = n / 2; n   while (1) { n     if (a[start] >= b) n       pluss += a[start] - b; n     else if (uu) n       uu--, pluss += a[start]; n     else n       break; n     start++; n     if (start > mid) break; n   } n   last = start; n   pluss += a[start]; n   for (long long i = start; i <= mid; i++) { n     while (last + 1 <= min(i + i * d, n)) { n       last++; n       pluss += a[last]; n       a[last] = 0; n     } n     if (pluss < b) return (0); n     pluss -= b; n   } n   return (1); n } n signed main() { n   cin >> n >> d >> b; n   for (long long i = 1; i <= n; i++) cin >> aa[i]; n   long long l = 0; n   long long r = n; n   while (r - l > 1) { n     long long d = (l + r) / 2; n     if (check(d)) n       r = d; n     else n       l = d; n   } n   if (check(l)) n     cout << l; n   else n     cout << r; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int main() { n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   cin >> n >> m; n   int finalPos[4 * n]; n   memset(finalPos, -1, sizeof(finalPos)); n   for (int i = (2 * n) + 1, j = 0; i <= m; i++, j += 2) { n     finalPos[j] = i; n   } n   for (int i = 1, j = 1; i <= (2 * n) && i <= m; i++, j += 2) finalPos[j] = i; n   for (int i = 0; i < (4 * n); i++) { n     if (finalPos[i] != -1) cout << finalPos[i] <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double pi = 3.1415926535897932384626433832795l; n template <typename T> n inline auto sqr(T x) -> decltype(x * x) { n   return x * x; n } n template <typename T> n inline T abs(T x) { n   return x > T() ? x : -x; n } n template <typename T1, typename T2> n inline bool umx(T1& a, T2 b) { n   if (a < b) { n     a = b; n     return 1; n   } n   return 0; n } n template <typename T1, typename T2> n inline bool umn(T1& a, T2 b) { n   if (b < a) { n     a = b; n     return 1; n   } n   return 0; n } n const int N = 100100; n struct Input { n   int n; n   vector<pair<int, int> > a[N]; n   int len[N]; n   int num[N], w[N]; n   int q; n   bool read() { n     if (scanf( %d , &n) != 1) return 0; n     for (int i = 0; i < int(n - 1); ++i) { n       int u, v; n       scanf( %d %d %d , &u, &v, &len[i]); n       u--, v--; n       a[u].push_back(make_pair(v, i)); n       a[v].push_back(make_pair(u, i)); n     } n     cin >> q; n     for (int i = 0; i < int(q); ++i) { n       scanf( %d %d , &num[i], &w[i]); n       num[i]--; n     } n     return 1; n   } n   void init(const Input& input) { *this = input; } n }; n struct Data : Input { n   long double ans[N]; n   void write() { n     for (int i = 0; i < int(q); ++i) { n       printf( %0.15lf n , (double)ans[i]); n     } n   } n   virtual void solve() {} n   virtual void clear() { *this = Data(); } n }; n struct Solution : Data { n   int sz[N]; n   int kol[N]; n   bool use[N]; n   int dfs(int v, int idx = -1) { n     use[v] = 1; n     sz[v] = 1; n     for (int i = 0; i < int(a[v].size()); ++i) { n       int to = a[v][i].first; n       if (use[to]) continue; n       sz[v] += dfs(to, a[v][i].second); n     } n     if (idx >= 0) kol[idx] = sz[v]; n     return sz[v]; n   } n   inline long double c(int a, int b) { n     if (a < b) return 0; n     if (b == 0) return 1; n     if (b == 1) return a; n     if (b == 2) { n       return (long double)a * (a - 1) / 2.0; n     } n     return (long double)a * (a - 1) * (a - 2) / 6.0; n   } n   inline long double get(int i) { n     return 2.0 * (long double)kol[i] * c((n - kol[i]), 2) + n            2.0 * (long double)(n - kol[i]) * c(kol[i], 2); n   } n   void solve() { n     dfs(0); n     long double res = 0; n     for (int i = 0; i < int(n - 1); ++i) { n       res += get(i) * len[i]; n     } n     for (int i = 0; i < int(q); ++i) { n       res -= get(num[i]) * len[num[i]]; n       len[num[i]] = w[i]; n       res += get(num[i]) * len[num[i]]; n       ans[i] = res / c(n, 3); n     } n   } n   void clear() { *this = Solution(); } n }; n Solution sol; n int main() { n   cout.setf(ios::showpoint | ios::fixed); n   cout.precision(20); n   sol.read(); n   sol.solve(); n   sol.write(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T re() { n   T N = 0; n   char c = getchar(); n   bool neg = 0; n   for (; c <  0  || c >  9 ; c = getchar()) neg |= c ==  - ; n   for (; c >=  0  && c <=  9 ; c = getchar()) N = (N << 3) + (N << 1) + c -  0 ; n   return neg ? -N : N; n } n const int MX = 200; n const int MXPOW5 = 8000; n int n, k; n long long a[MX + 5]; n int two[MX + 5], five[MX + 5]; n int dp[2][MX + 5][MXPOW5 + 5]; n int main() { n   n = re<int>(); n   k = re<int>(); n   for (int i = 1; i <= n; i++) a[i] = re<long long>(); n   for (int i = 1; i <= n; i++) { n     for (long long t = a[i]; t % 2 == 0; t /= 2) two[i]++; n     for (long long t = a[i]; t % 5 == 0; t /= 5) five[i]++; n   } n   int prv = 0, now = 1; n   for (int i = 0; i <= k; i++) n     for (int j = 0; j <= MXPOW5; j++) dp[prv][i][j] = -0x3f3f3f3f; n   dp[prv][0][0] = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j <= k; j++) n       for (int l = 0; l <= MXPOW5; l++) dp[now][j][l] = dp[prv][j][l]; n     for (int j = 0; j < k; j++) n       for (int l = 0; l + five[i] <= MXPOW5; l++) n         dp[now][j + 1][l + five[i]] = n             max(dp[now][j + 1][l + five[i]], dp[prv][j][l] + two[i]); n     swap(now, prv); n   } n   int ans = 0; n   for (int i = 0; i <= MXPOW5; i++) ans = max(ans, min(i, dp[prv][k][i])); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   int a = 97, z = 97 + 25, t = n; n   string s =   ; n   for (int i = 0; i < n; i++) { n     if (t >= k) { n       for (int j = 0; j < k; j++) { n         s += a + j; n       } n       i += k; n       i--; n       t -= k; n     } else { n       s += a; n       a++; n     } n   } n   cout << s << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int N; n   cin >> N; n   int grandN; n   vector<int> result; n   for (int i = 0; i < N; i++) { n     vector<int> grandmas; n     int temp; n     int res = 1; n     cin >> grandN; n     for (int j = 0; j < grandN; j++) { n       cin >> temp; n       grandmas.push_back(temp); n     } n     sort(grandmas.begin(), grandmas.end()); n     for (int j = 0; j < grandN; j++) { n       if (grandmas.at(j) <= j + 1) { n         res = j + 2; n       } n     } n     result.push_back(res); n   } n   for (auto i : result) { n     cout << i << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000010; n int n, m, cnt, head[maxn], vis[maxn], mark[maxn], ans[maxn], tot; n struct edge { n   int to, next; n } e[maxn]; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = (x << 1) + (x << 3) + (ch ^ 48); n     ch = getchar(); n   } n   return x * f; n } n void add(int from, int to) { n   e[++cnt] = (edge){to, head[from]}; n   head[from] = cnt; n } n void dfs(int now, int father, int edge) { n   vis[now] = 1; n   vector<int> bian; n   for (int i = head[now]; i; i = e[i].next) { n     int to = e[i].to; n     if (!vis[to]) dfs(to, now, i); n   } n   for (int i = head[now]; i; i = e[i].next) { n     int to = e[i].to; n     if (to != father && !mark[i]) { n       bian.push_back(i); n       mark[i] = 1; n       if (i & 1) n         mark[i + 1] = 1; n       else n         mark[i - 1] = 1; n     } n   } n   int size = bian.size(); n   for (int i = 0; i < size; i++) { n     if (i & 1) ans[++tot] = now; n     ans[++tot] = e[bian[i]].to; n   } n   if (size & 1) { n     if (father) n       ans[++tot] = now, ans[++tot] = father, mark[edge] = 1; n     else n       tot--; n   } n } n int main() { n   n = read(), m = read(); n   for (int i = 1; i <= m; i++) { n     int u = read(), v = read(); n     add(u, v), add(v, u); n   } n   for (int i = 1; i <= n; i++) n     if (!vis[i]) dfs(i, 0, 0); n   printf( %d n , tot / 3); n   for (int i = 1; i <= tot; i++) { n     printf( %d  , ans[i]); n     if (i % 3 == 0) puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<string, string> vars; n struct proc { n   string name, arg[10]; n   int argn; n   proc(string v, bool V) { n     string til =   ; n     int k = 0; n     for (int i = 0; i < v.length(); i++) { n       if (v[i] ==  ( ) { n         name = til; n         til =   ; n         continue; n       } else if (v[i] ==  ,  || v[i] ==  ) ) { n         if (V) n           arg[k++] = vars[til]; n         else n           arg[k++] = til; n         til =   ; n         continue; n       } else n         til += v[i]; n     } n     argn = k; n   } n   bool operator==(proc k) { n     if (name == k.name) { n       if (argn == k.argn) { n         for (int i = 0; i < argn; i++) { n           if (arg[i] ==  T  || arg[i] == k.arg[i]) continue; n           return false; n         } n         return true; n       } n     } n     return false; n   } n }; n vector<proc> p; n string DeleteSpaces(string k) { n   string ans =   ; n   for (int i = 0; i < k.length(); i++) n     if (k[i] !=    ) ans += k[i]; n   return ans; n } n int main() { n   int n, m, k; n   cin >> n; n   for (int i = 0; i < n; i++) { n     string v; n     cin >> v; n     getline(cin, v); n     proc Pro(DeleteSpaces(v), false); n     p.push_back(Pro); n   } n   cin >> k; n   for (int i = 0; i < k; i++) { n     string type, name; n     cin >> type >> name; n     vars[name] = type; n   } n   cin >> m; n   cin.ignore(); n   for (int i = 0; i < m; i++) { n     string v; n     getline(cin, v); n     proc Pro(DeleteSpaces(v), true); n     int ans = 0; n     for (int j = 0; j < p.size(); j++) { n       if (p[j] == Pro) ans++; n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[105]; n double t[105]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   int cnt; n   for (int d = -1000; d <= 1000; d++) { n     if (d != 0) { n       for (int i = 0; i < n; i++) { n         t[i] = a[i] * 1.0 / d; n       } n       cnt = 0; n       for (int i = 0; i < n; i++) { n         if (t[i] > 0) { n           cnt++; n         } n       } n       if (cnt >= (n + 1) / 2) { n         cout << d << endl; n         return 0; n       } n     } n   } n   cout << 0 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1000000007; n bool is_prime(long long n) { n   if (n == 1 || n == 0) return false; n   if (n == 2 || n == 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (long long i = 1; (6 * i + 1) <= n; i++) { n     if (6 * i + 1 == n) return true; n     if (6 * i - 1 == n) return true; n   } n   return false; n } n unordered_set<long long> prime_till_n(long long n) { n   vector<long long> arr(n + 1); n   arr[0] = 0; n   arr[1] = 0; n   for (long long i = 2; i <= n; i++) arr[i] = (long long)1; n   for (long long i = 2; i <= (n - 1) / 2; i++) { n     if (arr[i] == 1) { n       long long j = i; n       while (i + j <= n) { n         if (arr[i + j] == 1) { n           arr[i + j] = 0; n         } n         j += i; n       } n     } n   } n   unordered_set<long long> ans; n   for (long long i = 0; i <= n; i++) { n     if (arr[i] == 1) ans.insert(i); n   } n   return ans; n } n bool is_palindrome(string s) { n   string r = s; n   reverse(r.begin(), r.end()); n   if (s.compare(r) == 0) return true; n   return false; n } n bool issubstr(string s1, string s2) { n   int M = s1.length(); n   int N = s2.length(); n   for (int i = 0; i <= N - M; i++) { n     int j; n     for (j = 0; j < M; j++) n       if (s2[i + j] != s1[j]) break; n     if (j == M) return true; n   } n   return false; n } n long long xortilln(long long n) { n   if (n % 4 == 0ll) return n; n   if (n % 4 == 1ll) return 1ll; n   if (n % 4 == 2ll) return n + 1ll; n   return 0ll; n } n void solve() { n   string s; n   long long n; n   cin >> n; n   vector<long long> v(n); n   for (long long i = 0; i < n; i++) cin >> v[i]; n   cin >> s; n   vector<long long> up, down; n   for (long long i = 0; i < n; i++) { n     if (s[i] ==  1 ) n       up.push_back(v[i]); n     else n       down.push_back(v[i]); n   } n   sort(up.begin(), up.end()); n   sort(down.begin(), down.end()); n   unordered_map<long long, long long> up2, down2; n   for (int i = 0; i < down.size(); i++) down2[down[i]] = i + 1; n   for (int i = 0; i < up.size(); i++) up2[up[i]] = down.size() + i + 1; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  1 ) n       cout << up2[v[i]] <<    ; n     else n       cout << down2[v[i]] <<    ; n   } n   cout <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   long long i = 1, t = 1; n   cin >> t; n   while (t--) { n     solve(); n     i++; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int h1, m1, h2, m2, result1, result2; n   char c =  : ; n   while (cin >> h1 >> c >> m1 >> h2 >> c >> m2) { n     if (m1 < m2) { n       h1 -= 1; n       m1 += 60; n     } n     result2 = m1 - m2; n     result1 = h1 - h2; n     if (result1 < 0) result1 += 24; n     if (result1 == 24) result1 = 0; n     cout << setw(2) << setfill( 0 ) << abs(result1) << c << setw(2) n          << setfill( 0 ) << abs(result2) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n; n   cin >> n; n   n = n / 2520; n   cout << n; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000 + 5; n map<string, int> mat; n int fonction(string a, string b, string c) { n   int x = (mat[b] - mat[a] + 12) % 12; n   int y = (mat[c] - mat[b] + 12) % 12; n   int z = (mat[c] - mat[a] + 12) % 12; n   if (x == 4 && y == 3 && z == 7) return 1; n   if (x == 3 && y == 4) return 0; n   return -1; n } n int main() { n   mat[ C ] = 1; n   mat[ C# ] = 2; n   mat[ D ] = 3; n   mat[ D# ] = 4; n   mat[ E ] = 5; n   mat[ F ] = 6; n   mat[ F# ] = 7; n   mat[ G ] = 8; n   mat[ G# ] = 9; n   mat[ A ] = 10; n   mat[ B ] = 11; n   mat[ H ] = 12; n   string a, b, c; n   cin >> a; n   cin >> b; n   cin >> c; n   if (fonction(a, b, c) == 1 || fonction(a, c, b) == 1 || n       fonction(b, a, c) == 1 || fonction(b, c, a) == 1 || n       fonction(c, a, b) == 1 || fonction(c, b, a) == 1) n     cout <<  major ; n   else if (fonction(a, b, c) == 0 || fonction(a, c, b) == 0 || n            fonction(b, a, c) == 0 || fonction(b, c, a) == 0 || n            fonction(c, a, b) == 0 || fonction(c, b, a) == 0) n     cout <<  minor ; n   else n     cout <<  strange ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void scanv(vector<T>& v, int n) { n   v.resize(n); n   for (int i = 0; i < n; i++) cin >> v[i]; n } n template <typename T> n void scanvv(vector<vector<T> >& v, int n, int m) { n   v.resize(n); n   for (int i = 0; i < n; i++) scanv(v[i], m); n } n vector<int> p, s; n int main() { n   ios_base::sync_with_stdio(false); n   int cs, n, i, j; n   cin >> cs; n   while (cs--) { n     cin >> n; n     scanv(p, n); n     s.clear(); n     s.emplace_back(p[0]); n     for (i = 1; i < n; i++) { n       if (p[i] < p[i - 1]) { n         j = i + 1; n         while (j < n && p[j] < p[j - 1]) j++; n         s.emplace_back(p[j - 1]); n         i = j - 1; n       } else { n         j = i + 1; n         while (j < n && p[j] > p[j - 1]) j++; n         s.emplace_back(p[j - 1]); n         i = j - 1; n       } n     } n     cout << s.size() <<   n ; n     for (i = 0; i < s.size(); i++) { n       if (i) cout <<    ; n       cout << s[i]; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, s[7]; n long long lin[100005][1 << 7], cov[1 << 7]; n char ch[100005], ans[100005]; n vector<long long> e[100005]; n bool hall(long long x) { n   for (long long ss = 0; ss <= (1 << 6) - 1; ss++) { n     long long sum = 0; n     for (long long i = 1; i <= 6; i++) n       if (ss >> i - 1 & 1) sum += s[i]; n     if (lin[x][ss] < sum) return 0; n   } n   return 1; n } n signed main() { n   scanf( %s , ch + 1); n   n = strlen(ch + 1); n   for (long long i = 1; i <= n; i++) s[ch[i] -  a  + 1]++; n   cin >> m; n   for (long long i = 1, p; i <= m; i++) { n     string pat; n     cin >> p >> pat; n     for (long long j = 0; j < pat.length(); j++) n       e[p].push_back(pat[j] -  a  + 1), cov[p] |= 1 << pat[j] -  a ; n   } n   for (long long i = 1; i <= n; i++) n     if (e[i].size() == 0) { n       cov[i] = (1 << 6) - 1; n       for (long long j = 1; j <= 6; j++) e[i].push_back(j); n     } n   for (long long i = n; i >= 1; i--) { n     for (long long s = 0; s <= (1 << 6) - 1; s++) n       if (s & cov[i]) n         lin[i][s] = lin[i + 1][s] + 1; n       else n         lin[i][s] = lin[i + 1][s]; n   } n   for (long long i = 1; i <= n; i++) { n     sort(e[i].begin(), e[i].end()); n     for (long long j = 0; j < e[i].size(); j++) { n       s[e[i][j]]--; n       if (hall(i + 1)) { n         ans[i] = (char)(e[i][j] +  a  - 1); n         break; n       } n       s[e[i][j]]++; n     } n   } n   if (strlen(ans + 1) < n) return puts( Impossible ), 0; n   for (long long i = 1; i <= n; i++) cout << ans[i]; n   return puts(  ), 0; n } n


/** n  * Author: Daniel n  * Created Time: 2021-03-13 13:41:37 n **/ n  n // time-limit: 2000 n #include <bits/stdc++.h> n  n using namespace std; n  n #define F first  n #define S second n #define ER erase n #define IS insert n #define PI acos(-1) n #define PB pop_back n #define EB emplace_back n #define lowbit(x) (x & -x) n #define SZ(x) ((int)x.size()) n #define MP(x, y) make_pair(x, y) n #define ALL(x) x.begin(), x.end() n #define RALL(x) x.rbegin(), x.rend() n #define SOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<fixed<<setprecision(10) n  n typedef long long LL; n typedef vector<LL> VL; n typedef vector<int> VI; n typedef pair<LL, LL> PLL; n typedef pair<int, int> PII; n typedef unsigned long long ULL; n typedef pair<double, double> PDD; n typedef vector<pair<int, int> > VPII; n  n template <typename A> using VE = vector<A>; n template <typename A> using USET = unordered_set<A>; n template <typename A> using HEAP = priority_queue<A>; n template <typename A, typename B> using PA = pair<A, B>; n template <typename A, typename B> using UMAP = unordered_map<A, B>; n template <typename A> using RHEAP = priority_queue<A, vector<A>, greater<A> >; n  n template <typename A, typename B> n string to_string(pair<A, B> p); n  n template <typename A, typename B, typename C> n string to_string(tuple<A, B, C> p); n  n template <typename A, typename B, typename C, typename D> n string to_string(tuple<A, B, C, D> p); n  n string to_string(const string& s) { return     + s +    ; } n  n string to_string(const char* s) { return to_string((string)s); }  n  n string to_string(const char c) { return to_string((string)   + c); }  n  n string to_string(bool b) { return (b ?  true  :  false ); } n  n string to_string(vector<bool> v)  n { n     bool first = true; n     string res =  { ; n     for (int i = 0; i < static_cast<int>(v.size()); i++)  n     { n         if (!first) res +=  ,  ; n         first = false; n         res += to_string(v[i]); n     } n     res +=  } ; n     return res; n } n  n template <size_t N> n string to_string(bitset<N> v) n { n     string res =   ; n     for (size_t i = 0; i < N; i++) res += static_cast<char>( 0  + v[i]); n     return res; n } n  n template <typename A> n string to_string(A v) n { n     bool first = true; n     string res =  { ; n     for (const auto &x : v) n     { n         if (!first) res +=  ,  ; n         first = false; n         res += to_string(x); n     } n     res +=  } ; n     return res; n } n  n template <typename A, typename B> n string to_string(pair<A, B> p) { return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; } n  n template <typename A, typename B, typename C> n string to_string(tuple<A, B, C> p) { return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + to_string(get<2>(p)) +  ) ; } n  n template <typename A, typename B, typename C, typename D> n string to_string(tuple<A, B, C, D> p) { return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ; } n  n void debug_out() { cout <<   n ; } n  n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { cout <<     << to_string(H); debug_out(T...); } n  n #ifdef LOCAL n #define debug(...) cout <<  [  << #__VA_ARGS__ <<  ]: , debug_out(__VA_ARGS__) n #else n #define debug(...) 42 n #endif n  n /////////////////////////////////////////////////////////////////////////// n //////////////////// DO NOT TOUCH BEFORE THIS LINE //////////////////////// n /////////////////////////////////////////////////////////////////////////// n  n // check the limitation!!! n const int N = 5010, M = 1010; n  n int n; n int a[N][N]; n int res[N]; n int p[N]; n struct Node n { n     int u, v, val; n     bool operator<(const Node &t) const n     { n         if (val != t.val) return val < t.val; n         else return u < t.u; n     } n }; n  n int find(int x) n { n     if (x != p[x]) p[x] = find(p[x]); n     return p[x]; n } n  n // read the question carefully!!! n int main() n { n     SOS; n  n     cin >> n; n     for (int i = 1; i <= n; i ++ ) n         for (int j = 1; j <= n; j ++ ) n             cin >> a[i][j]; n     VE<Node> b; n     for (int i = 1; i <= n; i ++ ) n         for (int j = i; j <= n; j ++ ) n             b.EB((Node){i, j, a[i][j]}); n     sort(ALL(b)); n     VPII edge; n     int m = n; n     for (int i = 1; i <= n; i ++ )  n     { n         p[i] = i; n         res[i] = a[i][i]; n     } n     for (auto [u, v, val] : b) n     { n         int pa = find(u), pb = find(v); n         if (pa == pb) continue; n         else if (val == res[pb]) n         { n             p[pa] = pb; n             edge.EB(pa, pb); n         } n         else if (val == res[pa]) n         { n             p[pb] = pa; n             edge.EB(pb, pa); n         } n         else n         { n             p[pa] = p[pb] = ++ m; n             p[m] = m; n             res[m] = val; n             edge.EB(pa, m); n             edge.EB(pb, m); n         } n     } n     cout << m <<   n ; n     for (int i = 1; i <= m; i ++ ) n     { n         cout << res[i]; n         cout <<    n [i == m]; n     } n     cout << find(1) <<   n ; n     for (auto [x, y] : edge) cout << x <<     << y <<   n ; n     return 0; n } n  n // GOOD LUCK!!! n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int ans = INT_MAX; n     for (int i = 0; i * i <= n; i++) { n       ans = min(ans, i + (n + i) / (i + 1)); n     } n     cout << ans - 1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int MAX_N = (int)5e5 + 4, MAX_M = (int)1e7 + 4; n const double eps = 1e-6; n const int mod = (int)1e9 + 7; n using namespace std; n int n; n int a[MAX_N]; n bool pr[MAX_M]; n int lp[MAX_M], mu[MAX_M]; n inline void sieve() { n   for (int i = 2; i < MAX_M; i++) { n     if (pr[i]) continue; n     lp[i] = i; n     if (1ll * i * i < MAX_M) n       for (int j = i * i; j < MAX_M; j += i) n         if (!pr[j]) pr[j] = 1, lp[j] = i; n   } n   mu[1] = 1; n   for (int i = 2; i < MAX_M; i++) { n     if (i == lp[i]) n       mu[i] = -1; n     else if (!mu[i / lp[i]] || lp[i] == lp[i / lp[i]]) n       mu[i] = 0; n     else n       mu[i] = (-1) * mu[i / lp[i]]; n   } n } n vector<int> add; n vector<pair<int, int> > first; n void rec(int v, int id, int now, vector<int> &add) { n   if (v == int((first).size())) { n     add.push_back(now); n     return; n   } n   rec(v + 1, id, now, add); n   for (int i = 1; i <= first[v].second; i++) { n     now *= first[v].first; n     rec(v + 1, id, now, add); n   } n } n inline void fact(int id, int x) { n   first.clear(); n   while (x > 1) { n     if (first.empty() || first.back().first != lp[x]) n       first.push_back(make_pair(lp[x], 1)); n     else n       first.back().second++; n     x /= lp[x]; n   } n   add.clear(); n   rec(0, id, 1, add); n } n int cnt[MAX_M], all; n unordered_set<int> q; n int ans; n int two[MAX_N]; n inline int calc(int id) { n   fact(id, a[id]); n   int nw = all; n   for (auto i : add) { n     nw = (nw - mu[i] * two[cnt[i] - 1]) % mod; n     if (nw < 0) nw += mod; n   } n   nw = two[n - 1] - 1 - nw; n   if (nw < 0) nw += mod; n   for (auto i : add) { n     if (i == 1) continue; n     nw = (nw + mu[i] * (two[cnt[i] - 1] - 1)) % mod; n     if (nw < 0) nw += mod; n   } n   return nw; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   sieve(); n   for (int i = 1; i <= n; i++) { n     fact(i, a[i]); n     for (auto j : add) cnt[j]++, q.insert(j); n   } n   two[0] = 1; n   for (int i = 1; i <= n; i++) two[i] = 2ll * two[i - 1] % mod; n   for (auto i : q) { n     all = (all + mu[i] * (two[cnt[i]] - 1)) % mod; n     if (all < 0) all += mod; n   } n   for (int i = 1; i <= n; i++) ans = (ans + calc(i)) % mod; n   printf( %d n , ans); n   return 0; n } n