#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 100; n int a[N]; n int main() { n   std::ios::sync_with_stdio(false); n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   vector<int> nrs; n   for (int i = 0; i < n; ++i) nrs.push_back(a[i]); n   for (int i = 1; i < 32; ++i) { n     vector<int> counts(32, 0); n     vector<int> cur; n     for (int j = 0; j < n; ++j) { n       if (not(a[j] & (1 << i))) continue; n       cur.push_back(a[j]); n       for (int k = 0; k < 32; ++k) { n         if (a[j] & (1 << k)) ++counts[k]; n       } n     } n     if (cur.empty()) continue; n     bool ok = true; n     for (int j = 0; j < i; ++j) { n       ok &= counts[j] < counts[i]; n     } n     if (ok) nrs = cur; n   } n   cout << nrs.size() <<   n ; n   for (int i = 0; i < (int)nrs.size(); ++i) { n     if (i > 0) cout <<    ; n     cout << nrs[i]; n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   scanf( %d , &(n)), scanf( %d , &(m)); n   int a[(100000 + 10)][2]; n   for (int i(0), _n(n); i < _n; ++i) { n     scanf( %d , &a[i][1]); n     if (a[i][1] > 0) n       a[i][0] =  + ; n     else n       a[i][0] =  - , a[i][1] = -a[i][1]; n   } n   int yes[(100000 + 10)], no[(100000 + 10)]; n   memset((yes), 0, sizeof(yes)); n   memset((no), 0, sizeof(no)); n   for (int i(0), _n(n); i < _n; ++i) { n     if (a[i][0] ==  + ) n       yes[a[i][1]]++; n     else n       no[a[i][1]]++; n   } n   int sno = 0; n   for (int i(1), _h(n); i <= _h; ++i) sno += no[i]; n   bool may[(100000 + 10)]; n   memset((may), false, sizeof(may)); n   int cnt = 0; n   for (int i(1), _h(n); i <= _h; ++i) n     if (yes[i] + sno - no[i] == m) { n       may[i] = true; n       cnt++; n     } n   for (int i(0), _n(n); i < _n; ++i) { n     if (a[i][0] ==  + ) { n       if (may[a[i][1]] && cnt == 1) n         puts( Truth ); n       else if (may[a[i][1]]) n         puts( Not defined ); n       else n         puts( Lie ); n     } else { n       if (may[a[i][1]] && cnt == 1) n         puts( Lie ); n       else if (may[a[i][1]]) n         puts( Not defined ); n       else n         puts( Truth ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[200010], b[200010], n, m, q; n vector<pair<int, int> > e[200010]; n long long T[800010], d[800010]; n long long f[200010]; n void push(int id) { n   T[id << 1] += d[id]; n   T[id << 1 | 1] += d[id]; n   d[id << 1] += d[id]; n   d[id << 1 | 1] += d[id]; n   d[id] = 0; n   return; n } n void upd(int x, int y, long long dx, int id = 1, int l = 0, int r = n) { n   if (x >= r || l >= y) return; n   if (x <= l && r <= y) { n     T[id] += dx; n     d[id] += dx; n     return; n   } n   push(id); n   upd(x, y, dx, id << 1, l, l + r >> 1); n   upd(x, y, dx, id << 1 | 1, l + r >> 1, r); n   T[id] = min(T[id << 1], T[id << 1 | 1]); n   return; n } n void build() { n   for (int i = 0; i < n; i++) upd(i, i + 1, b[i]); n   for (int i = 0; i < n; i++) { n     for (auto p : e[i]) { n       int to, cost; n       tie(to, cost) = p; n       upd(0, to + 1, cost); n     } n     f[i] = T[1]; n   } n   memset(T, 0, sizeof(T)); n   memset(d, 0, sizeof(d)); n   for (int i = 0; i < n; i++) upd(i, i + 1, a[i] + f[i]); n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> m >> q; n   for (int i = 0; i < n - 1; i++) cin >> a[i] >> b[i + 1]; n   for (int i = 0, u, v, w; i < m; i++) { n     cin >> u >> v >> w; n     e[--u].push_back((make_pair((--v), (w)))); n   } n   build(); n   cout << T[1] << endl; n   while (q--) { n     int x, w; n     cin >> x >> w; n     upd(x - 1, x, w - a[x - 1]); n     a[x - 1] = w; n     cout << T[1] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int N = 2e5 + 7; n int n, m, i, j, a, b; n int check(int x, int y) { n   int dis1 = abs(x - i); n   int dis2 = abs(y - j); n   if (dis1 % a == 0 && dis2 % b == 0) { n     int p = dis1 / a; n     int q = dis2 / b; n     if (p == q) return q; n     if ((p + q) & 1) return inf; n     if (p < q) { n       if (i + a > n && i - a < 1) return inf; n     } else { n       if (j + b > m && j - b < 1) return inf; n     } n     return max(p, q); n   } else n     return inf; n } n int main() { n   scanf( %d , &n); n   scanf( %d , &m); n   scanf( %d , &i); n   scanf( %d , &j); n   scanf( %d , &a); n   scanf( %d , &b); n   int ans = inf; n   ans = min(ans, check(1, 1)); n   ans = min(ans, check(n, 1)); n   ans = min(ans, check(1, m)); n   ans = min(ans, check(n, m)); n   if (ans == inf) n     puts( Poor Inna and pony! ); n   else n     printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( sse4 ) n using namespace std; n const long long INF = 1e18; n const long long MOD = 1e9 + 7; n const long long N = 2e6 + 10; n const long long dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}, n                 dy[8] = {0, 1, 0, -1, -1, 1, -1, 1}; n bool TC = 0; n long long binpow(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b & 1) res = res * 1LL * a; n     a = a * 1LL * a; n     b >>= 1; n   } n   return res; n } n long long s(long long n) { n   long long res = 0; n   while (n) { n     res += n % 10; n     n /= 10; n   } n   return res; n } n void test_case() { n   long long a, b, c; n   cin >> a >> b >> c; n   vector<long long> v; n   for (long long i = 1; i <= 81; i++) { n     long long var = b * ((long long)binpow(i, a)) + c; n     if (s(var) == i && var < 1e9) v.push_back(var); n   } n   cout << (long long)((v).size()) <<   n ; n   for (long long i = 0; i < (long long)((v).size()); i++) { n     cout << v[i] <<    ; n   } n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   if (TC) { n     long long T; n     cin >> T; n     while (T--) test_case(); n   } else n     test_case(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n long long pow_[20]; n long long binpow(long long a, long long n) { n   long long res = 1; n   while (n) { n     if (n % 2 == 1) { n       res = (a * res) % mod; n     } n     a = (a * a) % mod; n     n /= 2; n   } n   return res; n } n long long C(long long n, long long k) { n   long long res = 1; n   n = n % mod; n   for (long long i = n; i >= n - k + 1; i--) { n     res = (res * i) % mod; n   } n   for (long long i = 1; i <= k; i++) { n     res = (res * pow_[i]) % mod; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(); n   cout.tie(); n   for (long long i = 1; i <= 19; i++) { n     pow_[i] = binpow(i, mod - 2); n   } n   long long n, s; n   cin >> n >> s; n   vector<long long> f(n); n   for (long long i = 0; i < n; i++) cin >> f[i]; n   long long res = 0; n   for (long long mask = 0; mask < (1 << n); mask++) { n     long long t = 0; n     for (long long i = 0; i < n; i++) { n       if (mask & (1 << i)) t++; n     } n     long long cur; n     if (t % 2 == 0) n       cur = 1; n     else n       cur = -1; n     long long sum = 0; n     for (long long i = 0; i < n; i++) { n       if (mask & (1 << i)) sum += (f[i] + 1); n     } n     if (s - sum + n - 1 < n - 1) continue; n     cur = (cur * C(s - sum + n - 1, n - 1) + mod) % mod; n     res = (res + cur) % mod; n   } n   cout << res <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n long long int k; n long long int a[100001]; n int main() { n   cin >> n >> k; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   sort(a + 1, a + n + 1); n   for (int i = 1; i <= n / 2; i++) { n     long long int c = (a[i + 1] - a[i] + a[n - i + 1] - a[n - i]) * i; n     if (c <= k) n       k -= c; n     else { n       cout << a[n - i + 1] - a[i] - k / i; n       return 0; n     } n   } n   cout << 0; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INFLL = 1e18; n const int MAXN = 1e6 + 100; n const long long INF = 1e9; n const long long mod1 = 1e9 + 7; n const long long mod2 = 2e9 + 11; n int n; n pair<pair<int, int>, pair<int, int> > a = {{0, 0}, {0, 0}}, n                                       b = {{0, 0}, {0, 0}}; n pair<pair<int, int>, pair<int, int> > solve(int x, int y, int x1, int y1) { n   pair<pair<int, int>, pair<int, int> > ans; n   ans.first = {x, y}; n   ans.second = {x1, y1}; n   int l = x + 1, r = x1; n   while (l <= r) { n     int mid = (l + r) >> 1; n     cout <<  ?   << mid <<     << y <<     << x1 <<     << y1 << endl; n     int ok; n     cin >> ok; n     if (ok == 0) { n       r = mid - 1; n     } else { n       l = mid + 1; n       ans.first.first = mid; n     } n   } n   l = y + 1, r = y1; n   while (l <= r) { n     int mid = (l + r) >> 1; n     cout <<  ?   << x <<     << mid <<     << x1 <<     << y1 << endl; n     int ok; n     cin >> ok; n     if (ok == 0) { n       r = mid - 1; n     } else { n       l = mid + 1; n       ans.first.second = mid; n     } n   } n   l = y, r = y1 - 1; n   while (l <= r) { n     int mid = (l + r) >> 1; n     cout <<  ?   << x <<     << y <<     << x1 <<     << mid << endl; n     int ok; n     cin >> ok; n     if (ok == 0) { n       l = mid + 1; n     } else { n       r = mid - 1; n       ans.second.second = mid; n     } n   } n   l = x, r = x1 - 1; n   while (l <= r) { n     int mid = (l + r) >> 1; n     cout <<  ?   << x <<     << y <<     << mid <<     << y1 << endl; n     int ok; n     cin >> ok; n     if (ok == 0) { n       l = mid + 1; n     } else { n       r = mid - 1; n       ans.second.first = mid; n     } n   } n   return ans; n } n pair<pair<int, int>, pair<int, int> > solve1(int x, int y, int x1, int y1) { n   pair<pair<int, int>, pair<int, int> > ans; n   ans.first = {x, y}; n   ans.second = {x1, y1}; n   int l = x + 1, r = x1; n   while (l <= r) { n     int mid = (l + r) >> 1; n     cout <<  ?   << mid <<     << y <<     << x1 <<     << y1 << endl; n     int ok; n     cin >> ok; n     if (mid <= a.first.first && y <= a.first.second && x1 >= a.second.first && n         y1 >= a.second.second) n       ok--; n     if (ok == 0) { n       r = mid - 1; n     } else { n       l = mid + 1; n       ans.first.first = mid; n     } n   } n   l = y + 1, r = y1; n   while (l <= r) { n     int mid = (l + r) >> 1; n     cout <<  ?   << x <<     << mid <<     << x1 <<     << y1 << endl; n     int ok; n     cin >> ok; n     if (x <= a.first.first && mid <= a.first.second && x1 >= a.second.first && n         y1 >= a.second.second) n       ok--; n     if (ok == 0) { n       r = mid - 1; n     } else { n       l = mid + 1; n       ans.first.second = mid; n     } n   } n   l = y, r = y1 - 1; n   while (l <= r) { n     int mid = (l + r) >> 1; n     cout <<  ?   << x <<     << y <<     << x1 <<     << mid << endl; n     int ok; n     cin >> ok; n     if (x <= a.first.first && y <= a.first.second && x1 >= a.second.first && n         mid >= a.second.second) n       ok--; n     if (ok == 0) { n       l = mid + 1; n     } else { n       r = mid - 1; n       ans.second.second = mid; n     } n   } n   l = x, r = x1 - 1; n   while (l <= r) { n     int mid = (l + r) >> 1; n     cout <<  ?   << x <<     << y <<     << mid <<     << y1 << endl; n     int ok; n     cin >> ok; n     if (x <= a.first.first && y <= a.first.second && mid >= a.second.first && n         y1 >= a.second.second) n       ok--; n     if (ok == 0) { n       l = mid + 1; n     } else { n       r = mid - 1; n       ans.second.first = mid; n     } n   } n   return ans; n } n int main() { n   cin >> n; n   int l = 1, r = n; n   int ans = 1; n   pair<pair<int, int>, pair<int, int> > ha = {{0, 0}, {0, 0}}; n   while (l <= r) { n     int mid = ((l + r) >> 1); n     cout <<  ?   << mid <<     << 1 <<     << n <<     << n << endl; n     int x; n     cin >> x; n     if (x == 2) { n       ans = mid; n       l = mid + 1; n     } else { n       if (x == 0) { n         r = mid - 1; n       } else { n         ha = {{mid, 1}, {n, n}}; n         break; n       } n     } n   } n   if (ha.first.second != 0) { n     a = solve(ha.first.first, ha.first.second, ha.second.first, n               ha.second.second); n     b = solve1(1, 1, n, n); n   } else { n     l = 1, r = n; n     int anss = 1; n     ha = {{0, 0}, {0, 0}}; n     while (l <= r) { n       int mid = ((l + r) >> 1); n       cout <<  ?   << ans <<     << mid <<     << n <<     << n << endl; n       int x; n       cin >> x; n       if (x == 2) { n         anss = mid; n         l = mid + 1; n       } else { n         if (x == 0) { n           r = mid - 1; n         } else { n           ha = {{ans, mid}, {n, n}}; n           break; n         } n       } n     } n     a = solve(ha.first.first, ha.first.second, ha.second.first, n               ha.second.second); n     b = solve1(1, 1, n, n); n   } n   cout <<  !   << a.first.first <<     << a.first.second <<     n        << a.second.first <<     << a.second.second <<     << b.first.first n        <<     << b.first.second <<     << b.second.first <<     n        << b.second.second << endl; n } n


#include<bits/stdc++.h> n #define ls i<<1 n #define rs i<<1|1 n #define fi first n #define se second n #define pb push_back n #define mp make_pair n using namespace std; n typedef long long ll; n typedef vector<int> vct; n typedef pair<int,int> pii; n const int N=2E5+1; n const int inf=1<<30; n ll read() n { n     ll a=0; n     char b=1,c; n     do if((c=getchar())==45)b=-1;while(c<48||c>57); n     do a=(a<<3)+(a<<1)+(c&15);while((c=getchar())>47&&c<58); n     return a*b; n } n void write(ll x,char c) n { n     if(x<0)putchar(45),x=-x; n     char a[20],s=0; n     do a[++s]=x%10|48;while(x/=10); n     do putchar(a[s]);while(--s); n     putchar(c); n } n const int p=1E9+7; n int n,l,r; n int fac[N],inv[N]; n vct a,ans; n int solve(int u,int v) n { n     for(int i=0;i<n;++i) n     { n         int y=u-max(l+a[i]-1,0),z=v-max(n-r+a[i],0); n         if(y<0||z<0)ans[i]=0; n         else ans[i]=(fac[y+z]*1LL*inv[y]%p*inv[z]%p); n     } n     int res=0; n     for(int i=0;i<n;++i)res=(res+(ans[i]-ans[i+1]+p)*1LL*a[i])%p; n     return res; n } n int main() n { n     fac[0]=fac[1]=inv[0]=inv[1]=1; n     for(int i=2;i<N;++i)inv[i]=(p-p/i)*1LL*inv[p%i]%p; n     for(int i=2;i<N;++i) n     { n         fac[i]=fac[i-1]*1LL*i%p; n         inv[i]=inv[i-1]*1LL*inv[i]%p; n     } n     for(int x=read();x--;) n     { n         n=read(),l=read(),r=read(); n         a.resize(n); n         ans.resize(n); n         ans.pb(0); n         iota(a.begin(),a.end(),min(1-l,r-n)); n         int m=n>>1; n         if(n&1)write((solve(m,n-m)+solve(n-m,m))%p,  n ); n         else write(solve(m,m),  n ); n     } n } n


#include <bits/stdc++.h> n using namespace std; n map<string, int> mp; n int main() { n   int i, j, n, m, t; n   string s; n   cin >> t; n   int cnt = 0; n   for (i = 0; i < t; i++) { n     cin >> s; n     int len = s.size(); n     string ans; n     int chk = 1; n     while (chk == 1) { n       ans.clear(); n       chk = 0; n       len = s.size(); n       for (j = 0; j < len - 1; j++) { n         if (s[j] ==  o  && s[j + 1] ==  o ) { n           ans.push_back( u ); n           j++; n           chk = 1; n         } else if (s[j] ==  k  && s[j + 1] ==  h ) { n           ans.push_back( h ); n           j++; n           chk = 1; n         } else if (s[j] ==  u  && s[j + 1] ==  o ) { n           s[j] =  o ; n           s[j + 1] =  u ; n           chk = 1; n           ans.push_back( o ); n         } else n           ans.push_back(s[j]); n       } n       if (j == len - 1) ans.push_back(s[j]); n       s = ans; n     } n     if (mp[ans] == 0) { n       cnt++; n     } n     mp[ans]++; n   } n   cout << cnt << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long int ans = 0; n vector<int> vx[200005]; n bool vu[200005]; n int n, k; n int dfs(int v, int p) { n   int aa = 0, aa2 = 0; n   for (int i = 0; i < vx[v].size(); i++) { n     if (vx[v][i] == p) continue; n     int pr = dfs(vx[v][i], v); n     aa += pr; n     aa2 += min(pr, 2 * k - pr); n   } n   ans += aa2; n   if (vu[v]) aa++; n   return aa; n } n int main() { n   for (int i = 0; i < 200005; i++) vu[i] = 0; n   cin >> n >> k; n   int u, v; n   for (int i = 0; i < k; i++) { n     cin >> u >> v; n     vu[u] = vu[v] = 1; n   } n   for (int i = 1; i < n; i++) { n     cin >> u >> v; n     vx[u].push_back(v); n     vx[v].push_back(u); n   } n   dfs(1, -1); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Point { n   double x, y; n   Point() {} n   Point(double _x, double _y) { n     x = _x; n     y = _y; n   } n   Point operator-(const Point &b) const { return Point(x - b.x, y - b.y); } n   double operator^(const Point &b) const { return x * b.y - y * b.x; } n   double operator*(const Point &b) const { return x * b.x + y * b.y; } n   void transXY(double B) { n     double tx = x, ty = y; n     x = tx * cos(B) - ty * sin(B); n     y = tx * sin(B) + ty * cos(B); n   } n }; n struct Line { n   Point s, e; n   Line() {} n   Line(Point _s, Point _e) { n     s = _s; n     e = _e; n   } n }; n Point PointToLine(Point P, Line L) { n   Point result; n   double t = ((P - L.s) * (L.e - L.s)) / ((L.e - L.s) * (L.e - L.s)); n   result.x = L.s.x + (L.e.x - L.s.x) * t; n   result.y = L.s.y + (L.e.y - L.s.y) * t; n   return result; n } n Point ver[1010]; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; ++i) cin >> ver[i].x >> ver[i].y; n   ver[0] = ver[n]; n   ver[n + 1] = ver[1]; n   double ans = 1e12; n   for (int i = 1; i <= n; ++i) { n     Line l; n     l.s = ver[i - 1]; n     l.e = ver[i + 1]; n     Point p = PointToLine(ver[i], l); n     double len = sqrt((ver[i].x - p.x) * (ver[i].x - p.x) + n                       (ver[i].y - p.y) * (ver[i].y - p.y)); n     ans = min(ans, len / 2); n   } n   printf( %.010lf n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T __sqr(const T x) { n   return x * x; n } n template <class T, class X> n inline T __pow(T a, X y) { n   T z = 1; n   for (int i = 1; i <= y; i++) { n     z *= a; n   } n   return z; n } n template <class T> n inline T gcd(T a, T b) { n   a = abs(a); n   b = abs(b); n   if (!b) return a; n   return __gcd(b, a % b); n } n template <class T> n inline T lcm(T a, T b) { n   a = abs(a); n   b = abs(b); n   return (a / __gcd(a, b)) * b; n } n inline bool ispow2(int x) { return (x != 0 && (x & (x - 1)) == 0); } n template <class T> n void UpdateMin(T &x, T y) { n   if (y < x) { n     x = y; n   } n } n template <class T> n void UpdateMax(T &x, T y) { n   if (x < y) { n     x = y; n   } n } n template <class T, class X, class Y> n inline T bigmod(T n, X m, Y mod) { n   unsigned long long ret = 1, a = n % mod; n   while (m) { n     if (m & 1) ret = (ret * a) % mod; n     m >>= 1; n     a = (a * a) % mod; n   } n   ret %= mod; n   return (T)ret; n } n template <class T, class Y> n inline T modinv(T n, Y mod) { n   return bigmod(n, mod - 2, mod); n } n template <class T, class X> n int getbit(T s, X i) { n   return (s >> i) & 1; n } n template <class T, class X> n T onbit(T s, X i) { n   return s | (T(1) << i); n } n template <class T, class X> n T offbit(T s, X i) { n   return s & (~(T(1) << i)); n } n template <class T> n inline void read(T &n) { n   char c; n   for (c = getchar(); !(c >=  0  && c <=  9 ); c = getchar()) n     ; n   n = c -  0 ; n   for (c = getchar(); c >=  0  && c <=  9 ; c = getchar()) n = n * 10 + c -  0 ; n } n void extended_euclid(long long a, long long b, long long &x, long long &y) { n   if (!b) { n     x = 1, y = 0; n     return; n   } n   long long first, second; n   extended_euclid(b, a % b, first, second); n   x = second; n   y = first - (a / b) * second; n } n pair<long long, pair<long long, long long> > extendedEuclid(long long a, n                                                             long long b) { n   long long x = 1, y = 0; n   long long xLast = 0, yLast = 1; n   long long q, r, m, n; n   while (a != 0) { n     q = b / a; n     r = b % a; n     m = xLast - q * x; n     n = yLast - q * y; n     xLast = x, yLast = y; n     x = m, y = n; n     b = a, a = r; n   } n   return make_pair(b, make_pair(xLast, yLast)); n } n const long long mod[] = {0,          1000000007, 1000000009, n                          1000000021, 1000000033, 1000000097, n                          1000000093, 1000000097, 1000000103}; n const long long base[] = {0,       1000003, 1000033, 1000037, 1000039, n                           1000081, 1000099, 1000117, 1000121}; n char s[(300000 + 20)], ans[(300000 + 20)]; n vector<int> cnt[50]; n int fnd[50]; n int main() { n   int m, n; n   scanf( %d , &m); n   scanf( %s , s); n   n = strlen(s); n   int tot = 0; n   int cov = -1; n   for (int i = 0; i < n; i++) { n     fnd[s[i] -  a ]++; n     cnt[s[i] -  a ].push_back(i); n     if (i == (cov + m)) { n       for (int j = 0; j < 26; j++) { n         if (cnt[j].empty()) continue; n         if (cnt[j].back() <= (i - m)) continue; n         ans[tot++] = s[cnt[j].back()]; n         fnd[s[cnt[j].back()] -  a ]--; n         cov = cnt[j].back(); n         break; n       } n     } n   } n   ans[tot] =   0 ; n   sort(ans, ans + tot); n   int g = tot; n   for (int i = 0; i < (ans[g - 1] -  a ); i++) { n     for (int j = 0; j < fnd[i]; j++) { n       ans[tot++] =  a  + i; n     } n   } n   ans[tot] =   0 ; n   sort(ans, ans + tot); n   puts(ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int a, b; n   node() { a = b = 0; } n } node[10005]; n int main() { n   int n, v; n   cin >> n >> v; n   for (int i = 0; i < n; i++) { n     int a, b; n     cin >> a >> b; n     node[a].a += b; n   } n   int ans = 0; n   for (int i = 1; i <= 3001; i++) { n     int vv = v; n     if (vv < node[i].b) { n       ans += vv; n       node[i + 1].b += node[i].a; n     } else { n       ans += node[i].b; n       vv -= node[i].b; n       if (vv >= node[i].a) { n         ans += node[i].a; n       } else { n         ans += vv; n         node[i + 1].b += node[i].a - vv; n       } n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 100; n const long long inf = (1LL << 30 - 1); n pair<int, int> A[maxn]; n int fa[maxn], X[maxn], Y[maxn], Hx[maxn], Hy[maxn], ans[maxn]; n int FindSet(int x) { return fa[x] == x ? x : fa[x] = FindSet(fa[x]); } n void UnionSet(int u, int v) { n   u = FindSet(u); n   v = FindSet(v); n   if (u != v) fa[u] = v; n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n * m; i++) { n     fa[i] = i; n     scanf( %d , &A[i].first); n     A[i].second = i; n   } n   sort(A, A + n * m); n   int j = -1; n   memset(X, 0, sizeof(X)); n   memset(Y, 0, sizeof(Y)); n   for (int i = 0; i < n * m; i++) { n     if (i != n * m - 1 && A[i].first == A[i + 1].first) continue; n     for (int k = j + 1; k <= i; k++) { n       int p = A[k].second; n       int x = A[k].second / m, y = A[k].second % m; n       Hx[x] = p; n       Hy[y] = p; n     } n     for (int k = j + 1; k <= i; k++) { n       int p = A[k].second; n       int x = A[k].second / m, y = A[k].second % m; n       UnionSet(Hx[x], p); n       UnionSet(Hy[y], p); n     } n     for (int k = j + 1; k <= i; k++) { n       int p = A[k].second; n       int x = A[k].second / m, y = A[k].second % m; n       int pa = FindSet(p); n       ans[pa] = max(ans[pa], max(X[x], Y[y]) + 1); n     } n     for (int k = j + 1; k <= i; k++) { n       int p = A[k].second; n       int x = A[k].second / m, y = A[k].second % m; n       int pa = FindSet(p); n       X[x] = max(X[x], ans[pa]); n       Y[y] = max(Y[y], ans[pa]); n     } n     j = i; n   } n   for (int i = 0; i < n * m; i++) { n     printf( %d , ans[FindSet(i)]); n     if ((i + 1) % m == 0) n       printf(  n ); n     else n       printf(   ); 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> num(n + 1); n   for (int i = 1; i <= n; i++) cin >> num[i]; n   if (num[1] % 2 == 0 || n % 2 == 0 || num[n] % 2 == 0) { n     cout <<  No ; n     return 0; n   } n   cout <<  Yes ; n   return 0; n } n


#include <bits/stdc++.h> n using std::cin; n using std::cout; n const int N = 17; n char ch[N]; n int n, r[N], b[N]; n int sr, sb, red[1 << N], blue[1 << N], f[1 << N][123]; n int main() { n   std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> ch[i] >> r[i] >> b[i]; n     sr += r[i]; n     sb += b[i]; n   } n   for (int i = 0; i < (1 << n); ++i) { n     for (int j = 1; j <= n; ++j) { n       if (i & (1 << (j - 1))) { n         if (ch[j] ==  R ) n           ++red[i]; n         else n           ++blue[i]; n       } n     } n   } n   memset(f, -1, sizeof(f)); n   f[0][0] = 0; n   for (int i = 0; i < (1 << n); ++i) { n     for (int j = 0; j <= 121; ++j) { n       if (f[i][j] == -1) continue; n       for (int k = 1; k <= n; ++k) { n         if (i & (1 << (k - 1))) continue; n         int T = i | (1 << (k - 1)); n         f[T][j + std::min(r[k], red[i])] = n             std::max(f[T][j + std::min(r[k], red[i])], n                      f[i][j] + std::min(b[k], blue[i])); n       } n     } n   } n   int res = 1e9; n   for (int i = 0; i <= 121; ++i) { n     if (f[(1 << n) - 1][i] == -1) continue; n     res = std::min(res, std::max(sr - i, sb - f[(1 << n) - 1][i])); n   } n   cout << res + n <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   map<string, int> table; n   table.insert(pair<string, int>( void , 0)); n   while (n--) { n     string cmd; n     cin >> cmd; n     if (cmd ==  typedef ) { n       string from, to, raw; n       cin >> from >> to; n       int depth = 0, i = 0, j = from.size() - 1; n       for (; i < j; ++i) { n         if (from[i] !=  & ) { n           break; n         } n         --depth; n       } n       for (; i < j; --j) { n         if (from[j] !=  * ) { n           break; n         } n         ++depth; n       } n       raw = from.substr(i, j - i + 1); n       map<string, int>::iterator it = table.find(raw); n       if (it == table.end()) { n         table[to] = -1; n       } else if (it->second < 0 || it->second + depth < 0) { n         table[to] = -1; n       } else { n         table[to] = it->second + depth; n       } n     } else if (cmd ==  typeof ) { n       string type, raw; n       cin >> type; n       int depth = 0, i = 0, j = type.size() - 1; n       for (; i < j; ++i) { n         if (type[i] !=  & ) { n           break; n         } n         --depth; n       } n       for (; i < j; --j) { n         if (type[j] !=  * ) { n           break; n         } n         ++depth; n       } n       raw = type.substr(i, j - i + 1); n       map<string, int>::iterator it = table.find(raw); n       if (it == table.end()) { n         cout <<  errtype  << endl; n       } else if (it->second < 0 || it->second + depth < 0) { n         cout <<  errtype  << endl; n       } else { n         cout <<  void  << string(it->second + depth,  * ) << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long MAX = pow(2, 32) - 1; n   int n; n   cin >> n; n   stack<int> fors; n   long long val = 0; n   long long num = 1; n   int i = 0; n   while (i != n) { n     string str; n     cin >> str; n     if (str ==  add ) { n       val += num; n     } else if (str ==  for ) { n       int j; n       cin >> j; n       num *= j; n       fors.push(j); n     } else { n       num /= fors.top(); n       fors.pop(); n     } n     if (val > MAX) { n       cout <<  OVERFLOW!!!  << endl; n       return 0; n     } n     if (num > MAX) { n       int end = 1; n       while (end != 0) { n         string s; n         cin >> s; n         if (s ==  add ) { n           cout <<  OVERFLOW!!!  << endl; n           return 0; n         } else if (s ==  for ) { n           int k; n           cin >> k; n           end++; n         } else { n           end--; n         } n         i++; n       } n       num /= fors.top(); n       fors.pop(); n     } n     i++; n   } n   cout << val << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2005; n const long long mod = 1e9 + 7; n const long long INF = 1e18 + 1; n long long goal, n, m; n long long umbrella[N], rain[N], cache[N][N]; n pair<long long, long long> a[N], b[N]; n long long dp(long long x, long long y) { n   if (x == goal) return 0; n   long long &ans = cache[x][y]; n   if (ans != -1) return ans; n   ans = INF; n   if (umbrella[x]) ans = dp(x, x); n   if (rain[x] and y == goal + 1) return ans; n   if (rain[x]) { n     ans = min(ans, umbrella[y] + min(dp(x + 1, y), dp(x + 1, goal + 1))); n   } else n     ans = min({ans, dp(x + 1, goal + 1), n                umbrella[y] + min(dp(x + 1, y), dp(x + 1, goal + 1))}); n   return ans; n } n void solve() { n   memset(cache, -1, sizeof(cache)); n   cin >> goal >> n >> m; n   for (long long i = 1; i < n + 1; i++) { n     cin >> a[i].first >> a[i].second; n     for (long long j = a[i].first; j < a[i].second; j++) rain[j] = 1; n   } n   for (long long i = 1; i < m + 1; i++) { n     cin >> b[i].first >> b[i].second; n     if (umbrella[b[i].first] == 0) n       umbrella[b[i].first] = b[i].second; n     else n       umbrella[b[i].first] = min(b[i].second, umbrella[b[i].first]); n   } n   sort(a + 1, a + n + 1); n   sort(b + 1, b + m + 1); n   if (a[1].first < b[1].first) { n     cout << -1; n     return; n   } n   cout << dp(0, goal + 1); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100010; n int n, cnt; n vector<int> e[N]; n vector<pair<int, int> > ans; n void init() { n   scanf( %d , &n); n   for (int i = 1, x, y; i < n; ++i) { n     scanf( %d %d , &x, &y); n     e[x].push_back(y); n     e[y].push_back(x); n   } n } n void dfs(int x, int father, int last_idx) { n   int pre = last_idx; n   for (int i = 0; i < e[x].size(); ++i) n     if (e[x][i] != father) { n       printf( 2 %d %d n , x, e[x][i]); n       cnt++; n       if (pre != -1) ans.push_back(make_pair(pre, cnt)); n       pre = cnt; n       dfs(e[x][i], x, cnt); n     } n } n void solve() { n   printf( %d n , n - 1); n   cnt = 0; n   dfs(1, -1, -1); n   for (int i = 0; i < ans.size(); ++i) n     printf( %d %d n , ans[i].first, ans[i].second); n } n int main() { n   init(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, c; n long long x, y, z, n; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n int main() { n   cin >> n; n   a = 1234567; n   b = 123456; n   c = 1234; n   for (int i = 0; i * a <= n; i++) { n     for (int j = 0; i * a + j * b <= n; j++) { n       if ((n - i * a - j * b) % c == 0) { n         cout <<  YES ; n         return 0; n       } n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n const int NUM = 200005; n const int MAXV = 1e6 + 100; n int blen, n, t, l, r, val; n int a[NUM], vcnt[MAXV]; n long long int ans[NUM], answer; n struct query { n   int l, r, ind; n } qs[NUM]; n bool query_cmp(query a, query b) { n   if (a.l / blen != b.l / blen) return a.l < b.l; n   return a.r < b.r; n } n int main() { n   int i; n   std::scanf( %d%d , &n, &t); n   blen = std::ceil(std::sqrt(n)); n   for (i = 0; i < n; ++i) std::scanf( %d , &a[i]); n   for (i = 0; i < t; ++i) { n     std::scanf( %d%d , &l, &r); n     qs[i].l = l - 1; n     qs[i].r = r; n     qs[i].ind = i; n   } n   std::sort(qs, qs + t, query_cmp); n   int ql, qr, cl, cr; n   cl = 0; n   cr = 0; n   answer = 0; n   for (i = 0; i < t; ++i) { n     ql = qs[i].l; n     qr = qs[i].r; n     while (cl > ql) { n       cl--; n       val = a[cl]; n       answer -= (long long int)vcnt[val] * vcnt[val] * val; n       vcnt[val]++; n       answer += (long long int)vcnt[val] * vcnt[val] * val; n     } n     while (cl < ql) { n       val = a[cl]; n       answer -= (long long int)vcnt[val] * vcnt[val] * val; n       vcnt[val]--; n       answer += (long long int)vcnt[val] * vcnt[val] * val; n       cl++; n     } n     while (cr < qr) { n       val = a[cr]; n       answer -= (long long int)vcnt[val] * vcnt[val] * val; n       vcnt[val]++; n       answer += (long long int)vcnt[val] * vcnt[val] * val; n       cr++; n     } n     while (cr > qr) { n       cr--; n       val = a[cr]; n       answer -= (long long int)vcnt[val] * vcnt[val] * val; n       vcnt[val]--; n       answer += (long long int)vcnt[val] * vcnt[val] * val; n     } n     ans[qs[i].ind] = answer; n   } n   for (i = 0; i < t; ++i) printf( %I64d n , ans[i]); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int inf; n const double eps = 1e-8; n const double pi = acos(-1.0); n template <class T, class T2> n int chkmin(T &a, T2 b) { n   return a > b ? a = b, 1 : 0; n } n template <class T, class T2> n int chkmax(T &a, T2 b) { n   return a < b ? a = b, 1 : 0; n } n template <class T> n T sqr(T a) { n   return a * a; n } n template <class T, class T2> n T mmin(T a, T2 b) { n   return a < b ? a : b; n } n template <class T, class T2> n T mmax(T a, T2 b) { n   return a > b ? a : b; n } n template <class T> n T aabs(T a) { n   return a < 0 ? -a : a; n } n template <class T> n int dcmp(T a, T b) { n   return a > b; n } n template <int *a> n int cmp_a(int first, int second) { n   return a[first] < a[second]; n } n struct __INIT__ { n   __INIT__() { n     fill((unsigned char *)(&inf), (unsigned char *)(&inf) + sizeof(inf), 0x3f); n   } n } __INIT___; n namespace io { n const int SIZE = (1 << 21) + 1; n char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, n                                        qu[55]; n int f, qr; n inline void flush() { n   fwrite(obuf, 1, oS - obuf, stdout); n   oS = obuf; n } n inline void putc(char first) { n   *oS++ = first; n   if (oS == oT) flush(); n } n template <typename A> n inline bool read(A &first) { n   for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), n                               (iS == iT ? EOF : *iS++)) n                             : *iS++); n        c <  0  || c >  9 ; n        c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), n                        (iS == iT ? EOF : *iS++)) n                      : *iS++)) n     if (c ==  - ) n       f = -1; n     else if (c == EOF) n       return 0; n   for (first = 0; c <=  9  && c >=  0 ; n        c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), n                        (iS == iT ? EOF : *iS++)) n                      : *iS++)) n     first = first * 10 + (c & 15); n   first *= f; n   return 1; n } n inline bool read(char &first) { n   while ((first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), n                                (iS == iT ? EOF : *iS++)) n                             : *iS++)) ==     || n          first ==   n  || first ==   r ) n     ; n   return first != EOF; n } n inline bool read(char *first) { n   while ((*first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), n                                 (iS == iT ? EOF : *iS++)) n                              : *iS++)) ==   n  || n          *first ==     || *first ==   r ) n     ; n   if (*first == EOF) return 0; n   while (!(*first ==   n  || *first ==     || *first ==   r  || *first == EOF)) n     *(++first) = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), n                               (iS == iT ? EOF : *iS++)) n                            : *iS++); n   *first = 0; n   return 1; n } n template <typename A, typename... B> n inline bool read(A &first, B &...second) { n   return read(first) && read(second...); n } n template <typename A> n inline bool write(A first) { n   if (!first) putc( 0 ); n   if (first < 0) putc( - ), first = -first; n   while (first) qu[++qr] = first % 10 +  0 , first /= 10; n   while (qr) putc(qu[qr--]); n   return 0; n } n inline bool write(char first) { n   putc(first); n   return 0; n } n inline bool write(const char *first) { n   while (*first) { n     putc(*first); n     ++first; n   } n   return 0; n } n inline bool write(char *first) { n   while (*first) { n     putc(*first); n     ++first; n   } n   return 0; n } n template <typename A, typename... B> n inline bool write(A first, B... second) { n   return write(first) || write(second...); n } n struct Flusher_ { n   ~Flusher_() { flush(); } n } io_flusher_; n }  // namespace io n using io ::putc; n using io ::read; n using io ::write; n bitset<1005> l[1005], a, hv; n unsigned w[31], lw[1005]; n int k, c, n; n void Insert() { n   unsigned s = 0; n   for (int i = n; i; --i) n     if (a[i]) { n       if (hv[i]) { n         s ^= lw[i]; n         a ^= l[i]; n       } else { n         s |= 1 << k; n         ++k; n         lw[i] = s; n         l[i] = a; n         hv[i] = 1; n         for (int j = 1; j < i; ++j) n           if (l[i][j]) { n             l[i] ^= l[j]; n             lw[i] ^= lw[j]; n           } n         for (int j = i + 1; j <= n; ++j) n           if (l[j][i]) { n             l[j] ^= l[i]; n             lw[j] ^= lw[i]; n           } n         return; n       } n     } n   w[c] = s; n   ++c; n } n int get() { n   unsigned s = 0; n   for (int i = n; i; --i) n     if (a[i]) { n       if (hv[i]) { n         s ^= lw[i]; n         a ^= l[i]; n       } else n         return -1; n     } n   return s; n } n unsigned v[1 << 15 | 5]; n int dis[1 << 15 | 5]; n int q[1 << 15 | 5]; n void bfs() { n   for (int i = 0; i < (1 << k); ++i) dis[i] = inf; n   int *l = q, *r = q; n   *q = 0; n   dis[0] = 0; n   for (; l <= r; ++l) { n     for (int i = 0; i < c; ++i) n       if (chkmin(dis[*l ^ w[i]], dis[*l] + 1)) { n         *(++r) = *l ^ w[i]; n       } n   } n } n signed main() { n   int s, q; n   read(n, s, q); n   for (int i = 1; i <= s; ++i) { n     int m, first; n     read(m); n     a.reset(); n     for (int j = 1; j <= m; ++j) { n       read(first); n       a[first] = 1; n     } n     Insert(); n   } n   if (k <= 15) { n     bfs(); n     for (; q; --q) { n       int m, first; n       read(m); n       a.reset(); n       for (int j = 1; j <= m; ++j) { n         read(first); n         a[first] = 1; n       } n       int w = get(); n       if (w < 0) n         write( -1 n ); n       else { n         int ans = inf; n         for (int j = 0; j < (1 << k); ++j) n           chkmin(ans, __builtin_popcount(j ^ w) + dis[j]); n         write(ans,   n ); n       } n     } n   } else { n     for (int i = 0; i < c; ++i) { n       v[1 << i] = w[i]; n     } n     for (int i = 1; i < (1 << c); ++i) n       if (i & (i - 1)) v[i] = v[i & (i - 1)] ^ v[i & (-i)]; n     for (; q; --q) { n       int m, first; n       read(m); n       a.reset(); n       for (int j = 1; j <= m; ++j) { n         read(first); n         a[first] = 1; n       } n       int w = get(); n       if (w < 0) n         write( -1 n ); n       else { n         int ans = inf; n         for (int j = 0; j < (1 << c); ++j) n           chkmin(ans, __builtin_popcount(j) + __builtin_popcount(w ^ v[j])); n         write(ans,   n ); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   int k = 0; n   cin >> s; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  a ) { n       k++; n     } n   } n   if (2 * k <= s.length()) { n     cout << 2 * k - 1; n   } else { n     cout << s.length(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n void _fill_int(int* p, int val, int rep) { n   int i; n   for (i = 0; i < rep; i++) p[i] = val; n } n int GETi() { n   int i; n   scanf( %d , &i); n   return i; n } n template <class T> n T sqr(T val) { n   return val * val; n } n int W, H; n int TX[2][100001]; n int TY[2][100001]; n int CT = 0; n void solve() { n   int f, r, i, j, k, l, x, y, cur, tar, dx, dy, sx, sy; n   char st[4]; n   H = GETi(); n   W = GETi(); n   sy = GETi() - 1; n   sx = GETi() - 1; n   scanf( %s , st); n   ; n   dx = (st[1] ==  R ) ? 1 : -1; n   dy = (st[0] ==  U ) ? -1 : 1; n   for (x = 0; x < W; x++) { n     if (((sx + sy) % 2) == (x % 2)) { n       TX[0][x]++; n       CT++; n     } n     if (((sx + sy) % 2) == ((x + H - 1) % 2)) { n       TX[1][x]++; n       CT++; n     } n   } n   for (y = 0; y < H; y++) { n     if (((sx + sy) % 2) == (y % 2)) { n       TY[0][y]++; n       CT++; n     } n     if (((sx + sy) % 2) == ((y + W - 1) % 2)) { n       TY[1][y]++; n       CT++; n     } n   } n   signed long long res = 1; n   for (i = 0; i < 1000000; i++) { n     if (sx == 0 && TY[0][sy]) { n       TY[0][sy] = 0; n       CT--; n     } n     if (sx == W - 1 && TY[1][sy]) { n       TY[1][sy] = 0; n       CT--; n     } n     if (sy == 0 && TX[0][sx]) { n       TX[0][sx] = 0; n       CT--; n     } n     if (sy == H - 1 && TX[1][sx]) { n       TX[1][sx] = 0; n       CT--; n     } n     if (CT == 0) { n       cout << res << endl; n       return; n     } n     if (sx == 0) dx = 1; n     if (sx == W - 1) dx = -1; n     if (sy == 0) dy = 1; n     if (sy == H - 1) dy = -1; n     int ml = 1000000; n     if (dx > 0) ml = min(ml, W - 1 - sx); n     if (dx < 0) ml = min(ml, sx); n     if (dy > 0) ml = min(ml, H - 1 - sy); n     if (dy < 0) ml = min(ml, sy); n     res += ml; n     sx += ml * dx; n     sy += ml * dy; n   } n   printf( -1 n ); n   return; n } n int main(int argc, char** argv) { n   if (argc > 1) freopen(argv[1],  r , stdin); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void optimizeIO() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n } n const int nmax = 150005; n const long long LINF = 1e17; n int ara[110]; n set<int> SET; n int main() { n   optimizeIO(); n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> ara[i]; n     SET.insert(ara[i]); n   } n   int siz = SET.size(); n   if (siz > 3) { n     cout << -1; n     return 0; n   } n   if (siz == 3) { n     vector<int> v; n     for (auto x : SET) v.push_back(x); n     int a = v[2] - v[1]; n     int b = v[1] - v[0]; n     if (a != b) { n       cout << -1; n       return 0; n     } n     if (a == b) { n       cout << a << endl; n       return 0; n     } n   } n   if (siz == 2) { n     vector<int> v; n     for (auto x : SET) v.push_back(x); n     int a = v[1] - v[0]; n     if (a % 2 == 1) { n       cout << a << endl; n       return 0; n     } n     if (a % 2 == 0) { n       cout << a / 2 << endl; n       return 0; n     } n   } n   if (siz == 1) { n     cout << 0 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void getre() { n   int x = 0; n   printf( %d n , 1 / x); n } n void gettle() { n   int res = 1; n   while (1) res <<= 1; n   printf( %d n , res); n } n template <typename T, typename S> n inline bool upmin(T &a, const S &b) { n   return a > b ? a = b, 1 : 0; n } n template <typename T, typename S> n inline bool upmax(T &a, const S &b) { n   return a < b ? a = b, 1 : 0; n } n template <typename N, typename PN> n inline N flo(N a, PN b) { n   return a >= 0 ? a / b : -((-a - 1) / b) - 1; n } n template <typename N, typename PN> n inline N cei(N a, PN b) { n   return a > 0 ? (a - 1) / b + 1 : -(-a / b); n } n template <typename N> n N gcd(N a, N b) { n   return b ? gcd(b, a % b) : a; n } n template <typename N> n inline int sgn(N a) { n   return a > 0 ? 1 : (a < 0 ? -1 : 0); n } n inline void gn(long long &x) { n   int sg = 1; n   char c; n   while (((c = getchar()) <  0  || c >  9 ) && c !=  - ) n     ; n   c ==  -  ? (sg = -1, x = 0) : (x = c -  0 ); n   while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ; n   x *= sg; n } n inline void gn(int &x) { n   long long t; n   gn(t); n   x = t; n } n inline void gn(unsigned long long &x) { n   long long t; n   gn(t); n   x = t; n } n inline void gn(double &x) { n   double t; n   scanf( %lf , &t); n   x = t; n } n inline void gn(long double &x) { n   double t; n   scanf( %lf , &t); n   x = t; n } n inline void gs(char *s) { scanf( %s , s); } n inline void gc(char &c) { n   while ((c = getchar()) > 126 || c < 33) n     ; n } n inline void pc(char c) { putchar(c); } n inline long long sqr(long long a) { return a * a; } n inline double sqrf(double a) { return a * a; } n const int inf = 0x3f3f3f3f; n const double pi = 3.14159265358979323846264338327950288L; n const double eps = 1e-6; n const int TREE_MAXV = 100000 + 5; n struct edge { n   int v, next; n } e[TREE_MAXV * 2]; n int g[TREE_MAXV], etot; n int n; n void ae(int u, int v) { n   e[etot].v = v; n   e[etot].next = g[u]; n   g[u] = etot++; n } n int dfn[TREE_MAXV], rig[TREE_MAXV], pre[TREE_MAXV], h[TREE_MAXV]; n int seq[TREE_MAXV], up[TREE_MAXV], sz[TREE_MAXV]; n void build_hld(int rt) { n   static int qu[TREE_MAXV], son[TREE_MAXV]; n   int p = 0, q = 0; n   qu[q++] = rt; n   pre[rt] = 0; n   h[rt] = 0; n   while (p != q) { n     int u = qu[p++]; n     sz[u] = 1, son[u] = 0; n     for (int i = g[u]; ~i; i = e[i].next) n       if (e[i].v != pre[u]) n         qu[q++] = e[i].v, pre[e[i].v] = u, h[e[i].v] = h[u] + 1; n   } n   sz[0] = 0; n   for (int i = q - 1; i >= 1; i--) { n     sz[pre[qu[i]]] += sz[qu[i]]; n     if (sz[qu[i]] > sz[son[pre[qu[i]]]]) son[pre[qu[i]]] = qu[i]; n   } n   for (int j = 0; j < q; j++) n     if (!son[qu[j]]) { n       int s = qu[j]; n       while (son[pre[s]] == s) s = pre[s]; n       int t = s; n       while (t) up[t] = s, t = son[t]; n     } else { n       int u = qu[j], v = son[u]; n       if (e[g[u]].v != v) { n         for (int i = g[u], j; ~i; j = i, i = e[i].next) n           if (e[i].v == v) { n             e[j].next = e[i].next; n             e[i].next = g[u]; n             g[u] = i; n             break; n           } n       } n     } n   static int stk[TREE_MAXV], cur[TREE_MAXV]; n   int top = 0, ind = 0; n   stk[++top] = rt; n   cur[top] = g[rt]; n   while (top) { n     int u = stk[top]; n     if (cur[top] == g[u]) { n       dfn[u] = ++ind; n       seq[ind] = u; n     } n     if (cur[top] == -1) { n       rig[u] = ind; n       top--; n     } else { n       int v = e[cur[top]].v; n       cur[top] = e[cur[top]].next; n       if (v == pre[u]) continue; n       stk[++top] = v; n       cur[top] = g[v]; n     } n   } n } n void work(int a, int b) { n   int l1, r1; n   while (up[a] != up[b]) { n     if (h[up[a]] < h[up[b]]) swap(a, b); n     l1 = dfn[up[a]], r1 = dfn[a]; n     a = pre[up[a]]; n   } n   if (h[a] > h[b]) swap(a, b); n   l1 = dfn[a] + 1, r1 = dfn[b]; n   if (a != b) { n   } n } n int lca(int a, int b) { n   while (up[a] != up[b]) { n     if (h[up[a]] < h[up[b]]) swap(a, b); n     a = pre[up[a]]; n   } n   if (h[a] > h[b]) swap(a, b); n   return a; n } n void tree_init() { n   static bool ini = 0; n   if (!ini) { n     ini = 1; n     memset(g, -1, sizeof(g)); n   } else { n     for (int i = 0; i <= n; i++) g[i] = -1; n   } n   etot = 0; n } n int rt; n void readedge() { n   for (int i = 1; i <= n; i++) { n     int x, y; n     gn(x); n     gn(y); n     if (x == 0) n       rt = y; n     else n       ae(x, y); n   } n } n int lis[111111]; n int ansquer[3333333]; n int quetot = 0; n struct quer { n   int l, r; n   int x; n   int id; n } que1[3333333], que0[3333333]; n int que1tot = 0, que0tot = 0; n int operator<(const quer &a, const quer &b) { return a.x < b.x; } n void addque(int l, int r, int x, int bo) { n   int id = ++quetot; n   quer tmp = (quer){l, r, x, id}; n   if (bo) n     que1[++que1tot] = tmp; n   else n     que0[++que0tot] = tmp; n } n int poptot = 0; n int popque() { n   int id = ++poptot; n   return ansquer[id]; n } n const int SEG_MAXN = 100000 + 5; n int seg[SEG_MAXN * 4]; n inline void segpu(int x) { seg[x] = max(seg[x << 1], seg[x << 1 | 1]); } n void seginit_in(int l, int r, int x) { n   if (l == r) { n     seg[x] = -inf; n   } else { n     int mid = l + r >> 1; n     seginit_in(l, mid, x << 1); n     seginit_in(mid + 1, r, x << 1 | 1); n     segpu(x); n   } n } n int l1, r1, I; n int sans; n bool ans_bo; n int stag; n void segupd_in(int l, int r, int x) { n   if (l == r) { n     seg[x] = max(seg[x], stag); n   } else { n     int mid = l + r >> 1; n     if (I <= mid) n       segupd_in(l, mid, x << 1); n     else n       segupd_in(mid + 1, r, x << 1 | 1); n     segpu(x); n   } n } n void segque_in(int l, int r, int x) { n   if (l1 <= l && r <= r1) { n     if (!ans_bo) n       ans_bo = 1, sans = seg[x]; n     else n       sans = max(sans, seg[x]); n   } else { n     int mid = l + r >> 1; n     if (l1 <= mid) segque_in(l, mid, x << 1); n     if (r1 > mid) segque_in(mid + 1, r, x << 1 | 1); n   } n } n int segn; n void segupd(int i, int v) { n   stag = v, I = i; n   segupd_in(1, segn, 1); n } n int segque(int l, int r) { n   if (l > r) return -inf; n   ans_bo = 0, l1 = l, r1 = r; n   segque_in(1, segn, 1); n   return sans; n } n void seginit(int n) { n   segn = n; n   seginit_in(1, segn, 1); n } n int ord[111111]; n int cmpsz(int i, int j) { return sz[i] < sz[j]; } n void gaoxunwen() { n   sort(que1 + 1, que1 + que1tot + 1); n   sort(que0 + 1, que0 + que0tot + 1); n   for (int i = (1), _ed = (n + 1); i < _ed; i++) ord[i] = i; n   sort(ord + 1, ord + 1 + n, cmpsz); n   seginit(n); n   int cur = 1; n   for (int i = (1), _ed = (que0tot + 1); i < _ed; i++) { n     int va = que0[i].x; n     while (cur <= n && sz[ord[cur]] <= va) { n       segupd(dfn[ord[cur]], sz[ord[cur]]); n       cur++; n     } n     ansquer[que0[i].id] = segque(que0[i].l, que0[i].r); n   } n   seginit(n); n   cur = n; n   for (int i = (que1tot + 1) - 1, _ed = (1); i >= _ed; i--) { n     int va = que1[i].x; n     while (cur >= 1 && sz[ord[cur]] >= va) { n       segupd(dfn[ord[cur]], -sz[ord[cur]]); n       cur--; n     } n     ansquer[que1[i].id] = -segque(que1[i].l, que1[i].r); n   } n } n struct quj { n   int l, r; n } qq[111]; n int cmpqj(const quj &a, const quj &b) { return a.l < b.l; } n void getque(int nrt, int u, int val, int bo) { n   if (nrt != rt) { n     addque(dfn[nrt], rig[nrt], val, bo); n   } else { n     int qjtot = 0; n     int del = sz[u]; n     qq[++qjtot] = (quj){dfn[u], rig[u]}; n     int v = pre[u]; n     while (v) { n       qq[++qjtot] = (quj){dfn[up[v]], dfn[v]}; n       v = pre[up[v]]; n     } n     sort(qq + 1, qq + 1 + qjtot, cmpqj); n     qq[0].r = 0, qq[qjtot + 1].l = n + 1; n     for (int i = (0), _ed = (qjtot + 1); i < _ed; i++) { n       if (qq[i].r + 1 <= qq[i + 1].l - 1) n         addque(qq[i].r + 1, qq[i + 1].l - 1, val, bo); n     } n     v = pre[u]; n     while (v) { n       addque(dfn[up[v]], dfn[v], val + del, bo); n       v = pre[up[v]]; n     } n   } n } n int gotque(int nrt, int u, int val, int bo) { n   if (nrt != rt) { n     return popque(); n   } else { n     int ret; n     if (bo == 0) n       ret = -inf; n     else n       ret = inf; n     int qjtot = 0; n     int del = sz[u]; n     qq[++qjtot] = (quj){dfn[u], rig[u]}; n     int v = pre[u]; n     while (v) { n       qq[++qjtot] = (quj){dfn[up[v]], dfn[v]}; n       v = pre[up[v]]; n     } n     sort(qq + 1, qq + 1 + qjtot, cmpqj); n     qq[0].r = 0, qq[qjtot + 1].l = n + 1; n     for (int i = (0), _ed = (qjtot + 1); i < _ed; i++) { n       if (qq[i].r + 1 <= qq[i + 1].l - 1) { n         int goo = popque(); n         if (bo == 0) n           upmax(ret, goo); n         else n           upmin(ret, goo); n       } n     } n     v = pre[u]; n     while (v) { n       int goo = popque() - del; n       if (bo == 0) n         upmax(ret, goo); n       else n         upmin(ret, goo); n       v = pre[up[v]]; n     } n     return ret; n   } n } n void prework(int u) { n   int tot = 0; n   for (int i = g[u]; ~i; i = e[i].next) lis[++tot] = sz[e[i].v]; n   if (u != rt) { n     lis[++tot] = n - sz[u]; n   } n   sort(lis + 1, lis + 1 + tot); n   int masz = lis[tot]; n   int nrt = rt; n   for (int i = g[u]; ~i; i = e[i].next) n     if (sz[e[i].v] == masz) { n       nrt = e[i].v; n     } n   if (tot == 0) return; n   if (tot == 1) return; n   if (tot == 2) { n     int a = lis[1], c = lis[2]; n     getque(nrt, u, cei(c - a, 2), 1); n     getque(nrt, u, (c - a) / 2, 0); n     return; n   } else { n     int a = lis[1], b = lis[tot - 1], c = lis[tot]; n     getque(nrt, u, cei(c - a, 2), 1); n     getque(nrt, u, (c - a) / 2, 0); n     getque(nrt, u, c - b, 1); n     return; n   } n } n int work(int u) { n   int tot = 0; n   for (int i = g[u]; ~i; i = e[i].next) lis[++tot] = sz[e[i].v]; n   if (u != rt) { n     lis[++tot] = n - sz[u]; n   } n   sort(lis + 1, lis + 1 + tot); n   int masz = lis[tot]; n   int nrt = rt; n   for (int i = g[u]; ~i; i = e[i].next) n     if (sz[e[i].v] == masz) { n       nrt = e[i].v; n     } n   if (tot == 0) return 0; n   if (tot == 1) return lis[1]; n   if (tot == 2) { n     int a = lis[1], c = lis[2]; n     int d1 = gotque(nrt, u, cei(c - a, 2), 1); n     int d2 = gotque(nrt, u, (c - a) / 2, 0); n     return min(lis[2], min(max(c - d1, a + d1), max(c - d2, a + d2))); n   } else { n     int a = lis[1], b = lis[tot - 1], c = lis[tot]; n     int d1 = gotque(nrt, u, cei(c - a, 2), 1); n     int d2 = gotque(nrt, u, (c - a) / 2, 0); n     int d3 = gotque(nrt, u, c - b, 1); n     int ans = lis[tot]; n     upmin(ans, max(max(a + d1, b), c - d1)); n     upmin(ans, max(max(a + d2, b), c - d2)); n     upmin(ans, max(max(a + d3, b), c - d3)); n     return ans; n   } n } n int main() { n   gn(n); n   tree_init(); n   readedge(); n   build_hld(rt); n   for (int u = (1), _ed = (n + 1); u < _ed; u++) prework(u); n   gaoxunwen(); n   for (int u = (1), _ed = (n + 1); u < _ed; u++) printf( %d n , work(u)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 30; n long long n, a[N], ans, limit = 1e9 + 10; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   reverse(a, a + n); n   for (int i = 0; i < n; i++) { n     ans += min(a[i], limit); n     limit = min(limit - 1, a[i] - 1); n     if (limit <= 0) break; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     x = (x << 3) + (x << 1) + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n int n, m, q, a[200005], b[200005], f[200005], g[200005], h[200005], n     minn[800005], rev[200005]; n vector<int> pos[200005], pos2[200005]; n void build(int o, int l, int r) { n   if (l == r) { n     minn[o] = (g[l] == -1) ? 1E9 : g[l]; n     return; n   } n   int mid = (l + r) >> 1; n   build(o << 1, l, mid); n   build(o << 1 | 1, mid + 1, r); n   minn[o] = min(minn[o << 1], minn[o << 1 | 1]); n } n int query(int o, int l, int r, int nl, int nr) { n   if (nl <= l && r <= nr) return minn[o]; n   int mid = (l + r) >> 1, ans = 1E9; n   if (nl <= mid) ans = min(ans, query(o << 1, l, mid, nl, nr)); n   if (mid < nr) ans = min(ans, query(o << 1 | 1, mid + 1, r, nl, nr)); n   return ans; n } n signed main() { n   n = Read(), m = Read(), q = Read(); n   for (int i = 1; i <= n; i++) a[i] = Read(), rev[a[i]] = i; n   for (int i = 1; i <= m; i++) b[i] = Read(), pos[b[i]].push_back(i); n   memset(f, -1, sizeof(f)); n   memset(g, -1, sizeof(g)); n   memset(h, -1, sizeof(h)); n   for (int i = n; i >= 1; i--) { n     if (i == n) { n       for (int j = 0; j < pos[a[i]].size(); j++) f[pos[a[i]][j]] = pos[a[i]][j]; n       continue; n     } n     for (int j = 0; j < pos[a[i]].size(); j++) { n       vector<int>::iterator it = n           lower_bound(pos[a[i + 1]].begin(), pos[a[i + 1]].end(), pos[a[i]][j]); n       if (it == pos[a[i + 1]].end()) continue; n       f[pos[a[i]][j]] = f[*it]; n     } n   } n   for (int i = 1; i <= n; i++) { n     if (i == 1) { n       for (int j = 0; j < pos[a[i]].size(); j++) h[pos[a[i]][j]] = pos[a[i]][j]; n       continue; n     } n     for (int j = 0; j < pos[a[i]].size(); j++) { n       vector<int>::iterator it = n           lower_bound(pos[a[i - 1]].begin(), pos[a[i - 1]].end(), pos[a[i]][j]); n       if (it == pos[a[i - 1]].begin()) continue; n       --it; n       h[pos[a[i]][j]] = h[*it]; n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < pos[a[i]].size(); j++) n       pos2[a[i]].push_back(h[pos[a[i]][j]]); n   } n   for (int i = 1; i <= m; i++) { n     int ff = rev[b[i]]; n     if (ff == 1) { n       g[i] = f[i]; n       continue; n     } n     if (f[i] == -1) continue; n     vector<int>::iterator it = n         lower_bound(pos2[a[ff - 1]].begin(), pos2[a[ff - 1]].end(), f[i]); n     if (it == pos2[a[ff - 1]].end()) continue; n     int Pos = it - pos2[a[ff - 1]].begin(); n     g[i] = pos[a[ff - 1]][Pos]; n   } n   build(1, 1, m); n   for (int i = 1; i <= q; i++) { n     int l = Read(), r = Read(); n     int mpos = query(1, 1, m, l, r); n     if (mpos <= r) n       putchar( 1 ); n     else n       putchar( 0 ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n ostream& operator<<(ostream& os, vector<T> V) { n   for (auto v : V) os << v <<    ; n   return cout <<   ; n } n template <class T> n ostream& operator<<(ostream& os, set<T> S) { n   for (auto s : S) os << s <<    ; n   return cout <<   ; n } n template <class L, class R> n ostream& operator<<(ostream& os, pair<L, R> P) { n   return os << P.first <<     << P.second; n } n const long long mod = 1e9 + 7; n long long inv(long long i) { n   if (i == 1) return 1; n   return (mod - ((mod / i) * inv(mod % i)) % mod) % mod; n } 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 pwr(long long a, long long b) { n   a %= mod; n   long long res = 1; n   while (b > 0) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n     b >>= 1; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int T = 1; n   cin >> T; n   while (T--) { n     int n, c0, c1, h, x = 0, y = 0; n     cin >> n >> c0 >> c1 >> h; n     string s; n     cin >> s; n     for (int i = 0; i < n; i++) { n       if (s[i] ==  0 ) n         x++; n       else n         y++; n     } n     if (c0 >= c1 + h) { n       cout << x * h + n * c1 <<   n ; n     } else if (c1 >= c0 + h) { n       cout << y * h + n * c0 <<   n ; n     } else { n       cout << x * c0 + y * c1 <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n long long n, m, k, a[11111], kq; n long long min(long long a, long long b) { n   if (a < b) return a; n   return b; n } n int main() { n   scanf( %lld %lld %lld , &n, &m, &k); n   for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); n   if (n % 2 == 0) n     printf( 0 ); n   else { n     kq = a[1]; n     for (int i = 3; i <= n; i += 2) kq = min(kq, a[i]); n     kq = min(kq, (m / ((n + 1) / 2)) * k); n     printf( %lld , kq); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000000 + 7; n const int M = 32; n const long long base = 1e18; n const int mod = 999983; n const int inf = 1e9 + 7; n const double pi = acos(-1); n const int maxn = N * 2; n const double PI = acos(-1); n const double ep = 1e-9; n int n, m, s, e; n int a[N], b[N]; n int last[N]; n map<int, int> st; n vector<int> all[N]; n int dp[2][N]; n int getPos(int x) { n   if (st.count(x)) n     return st[x]; n   else n     return st[x] = st.size(); n } n void solve() { n   cin >> n >> m >> s >> e; n   for (int i = (0); i < (n); i++) scanf( %d , a + i); n   for (int j = (0); j < (m); j++) { n     scanf( %d , b + j); n     all[getPos(b[j])].push_back(j); n   } n   last[0] = -1; n   for (int i = (1); i < (N); i++) last[i] = inf; n   int C = s / e; n   int ans = 0; n   for (int i = (0); i < (n); i++) { n     if (st.count(a[i])) { n       int c = st[a[i]]; n       for (int j = C - 1; j >= 0; j--) { n         typeof(all[c].begin()) it = n             lower_bound(all[c].begin(), all[c].end(), last[j] + 1); n         if (it != all[c].end()) { n           if ((j + 1) * e + (i + 1 + (*it) + 1) <= s) { n             ans = max(ans, j + 1); n           } n           last[j + 1] = min(last[j + 1], *it); n         } n       } n     } n   } n   cout << ans; n } n int main() { n   int T = 1; n   for (int i = (1); i < (T + 1); i++) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int tt; n   cin >> tt; n   unordered_map<string, string> mp; n   unordered_set<string> s; n   for (int i = 0; i < tt; i++) { n     string s1; n     string s2; n     cin >> s1 >> s2; n     if (s.find(s1) == s.end()) { n       mp.insert({s1, s2}); n       s.insert(s2); n     } else { n       for (auto &it : mp) { n         if (s1 == it.second) { n           it.second = s2; n           s.insert(s2); n         } n       } n     } n   } n   cout << mp.size() << endl; n   for (auto it : mp) { n     cout << it.first <<     << it.second << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x[3], y[3]; n bool is_between(int a, int b, int c) { n   return min(a, b) <= c && c <= max(a, b); n } n bool check(int i, int j, int k) { n   return (x[k] == x[i] || x[k] == x[j]) && is_between(y[i], y[j], y[k]) || n          (y[k] == y[i] || y[k] == y[j]) && is_between(x[i], x[j], x[k]); n } n int main() { n   for (int i = 0; i < 3; i++) { n     cin >> x[i] >> y[i]; n   } n   if (x[0] == x[1] && x[1] == x[2] || y[0] == y[1] && y[1] == y[2]) { n     cout << 1 << endl; n   } else if (check(0, 1, 2) || check(0, 2, 1) || check(1, 2, 0)) { n     cout << 2 << endl; n   } else { n     cout << 3 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k; n int main() { n   cin >> n >> k; n   cout << k * (6 * n - 1) << endl; n   for (int i = 1; i <= n; i++) { n     int x = (i - 1) * 6 + 1; n     cout << k * x <<     << k * (x + 1) <<     << k * (x + 2) <<     n          << k * (x + 4) << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline long long getint() { n   long long ssum = 0, ff = 1; n   char ch; n   for (ch = getchar(); !isdigit(ch) && ch !=  - ; ch = getchar()) n     ; n   if (ch ==  - ) ff = -1, ch = getchar(); n   for (; isdigit(ch); ch = getchar()) ssum = ssum * 10 + ch -  0 ; n   return ssum * ff; n } n const long long M = 1e6 + 5, mod = 1e9 + 7; n long long ans, f[M], g[M]; n long long n, t[3]; n signed main() { n   cin >> n; n   for (long long i = 1; i <= n; i++) t[getint()]++; n   f[0] = 1; n   f[1] = 1; n   for (long long i = 2; i <= t[1]; i++) n     (f[i] = f[i - 1] + f[i - 2] * (i - 1)) %= mod; n   g[0] = f[t[1]]; n   for (long long i = 1; i <= t[2]; i++) (g[i] = g[i - 1] * (t[1] + i)) %= mod; n   cout << g[t[2]] << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n inline int read() { n   int n = 0, ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) n     ; n   for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + (ch ^ 48); n   return n; n } n int main() { n   int T = read(); n   while (T--) { n     int ans[3] = {0, 0, 0}; n     int n = read(); n     while (n--) ++ans[read() % 3]; n     int A = ans[0]; n     if (ans[1] < ans[2]) n       A += ans[1] + (ans[2] - ans[1]) / 3; n     else n       A += ans[2] + (ans[1] - ans[2]) / 3; n     printf( %d n , A); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class t> n inline void read(t& res) { n   char ch; n   while (ch = getchar(), !isdigit(ch)) n     ; n   res = ch ^ 48; n   while (ch = getchar(), isdigit(ch)) res = res * 10 + (ch ^ 48); n } n template <class t> n inline void print(t x) { n   if (x > 9) print(x / 10); n   putchar(x % 10 + 48); n } n const int e = 3e5 + 5, z1 = 29, z2 = 31, h1 = 1e9 + 7, h2 = 1e9 + 9; n struct node { n   int s1, s2, len; n   node() {} n   node(int _s1, int _s2, int _len) : s1(_s1), s2(_s2), len(_len) {} n } up[e], down[e]; n vector<int> a[e], b[e], g[e]; n int n, top[e], son[e], m, f[20][e], dep[e], mx[e]; n int p1[e], p2[e], fa[e], dfn[e], id[e << 1], tim, logn[e << 1], c[21][e << 1]; n int q1[e], q2[e], inv1, inv2; n char s[e]; n inline bool operator==(node a, node b) { return a.s1 == b.s1 && a.s2 == b.s2; } n inline node operator+(node a, node b) { n   return node(((long long)a.s1 * p1[b.len] + b.s1) % h1, n               ((long long)a.s2 * p2[b.len] + b.s2) % h2, a.len + b.len); n } n inline int ksm(int x, int y, int mod) { n   int res = 1; n   while (y) { n     if (y & 1) res = (long long)res * x % mod; n     y >>= 1; n     x = (long long)x * x % mod; n   } n   return res; n } n inline void dfs1(int u, int pa) { n   int i; n   fa[u] = pa; n   dep[u] = dep[pa] + 1; n   mx[u] = dep[u]; n   s[u] -=  a  - 1; n   dfn[u] = ++tim; n   id[tim] = u; n   for (i = 0; i < 18; i++) f[i + 1][u] = f[i][f[i][u]]; n   node a = down[pa], b = up[pa]; n   down[u] = node(((long long)z1 * a.s1 + s[u]) % h1, n                  ((long long)z2 * a.s2 + s[u]) % h2, a.len + 1); n   up[u] = node((b.s1 + (long long)p1[b.len] * s[u]) % h1, n                (b.s2 + (long long)p2[b.len] * s[u]) % h2, b.len + 1); n   for (auto v : g[u]) n     if (v != pa) { n       f[0][v] = u; n       dfs1(v, u); n       if (mx[v] > mx[u]) mx[u] = mx[v], son[u] = v; n       id[++tim] = u; n     } n } n inline void dfs2(int u, int pa, int fi) { n   top[u] = fi; n   if (son[u]) dfs2(son[u], u, fi); n   for (auto v : g[u]) n     if (v != pa && v != son[u]) dfs2(v, u, v); n } n inline int cmp(int x, int y) { return dep[x] < dep[y] ? x : y; } n inline void init() { n   int i, j; n   logn[0] = -1; n   for (i = 1; i <= tim; i++) logn[i] = logn[i >> 1] + 1, c[0][i] = id[i]; n   for (j = 1; (1 << j) <= tim; j++) n     for (i = 1; i + (1 << j) - 1 <= tim; i++) n       c[j][i] = cmp(c[j - 1][i], c[j - 1][i + (1 << j - 1)]); n } n inline int lca(int l, int r) { n   l = dfn[l]; n   r = dfn[r]; n   if (l > r) swap(l, r); n   int k = logn[r - l + 1]; n   return cmp(c[k][l], c[k][r - (1 << k) + 1]); n } n inline int anc(int x, int k) { n   if (!k) return x; n   int y = logn[k], to; n   x = f[y][x]; n   k -= (1 << y); n   to = top[x]; n   if (dep[to] <= dep[x] - k) n     return b[to][dep[x] - k - dep[to]]; n   else n     return a[to][dep[to] - dep[x] + k]; n } n inline int sub1(int x, int y) { n   (x -= y) < 0 && (x += h1); n   return x; n } n inline int sub2(int x, int y) { n   (x -= y) < 0 && (x += h2); n   return x; n } n inline node query_up(int x, int y) { n   node a = up[x], b = up[y]; n   return node((long long)sub1(a.s1, b.s1) * q1[b.len] % h1, n               (long long)sub2(a.s2, b.s2) * q2[b.len] % h2, a.len - b.len); n } n inline node query_down(int x, int y) { n   node a = down[y], b = down[x]; n   return node(sub1(a.s1, (long long)b.s1 * p1[a.len - b.len] % h1), n               sub2(a.s2, (long long)b.s2 * p2[a.len - b.len] % h2), n               a.len - b.len); n } n inline node calc(int x, int y, int z, int len) { n   int d1 = dep[x] - dep[z] + 1, d2 = dep[x] + dep[y] - 2 * dep[z] + 1; n   if (len <= d1) { n     int u = anc(x, len - 1); n     return query_up(x, fa[u]); n   } else { n     int u = anc(y, d2 - len); n     return query_up(x, fa[z]) + query_down(z, u); n   } n } n inline int query(int x, int y, int u, int v) { n   int z = lca(x, y), w = lca(u, v), res = 0, l = 1, n       r = min(dep[x] + dep[y] - 2 * dep[z], dep[u] + dep[v] - 2 * dep[w]) + 1; n   while (l <= r) { n     int mid = l + r >> 1; n     if (calc(x, y, z, mid) == calc(u, v, w, mid)) n       res = mid, l = mid + 1; n     else n       r = mid - 1; n   } n   return res; n } n int main() { n   read(n); n   int i, x, y, u, v, j; n   scanf( %s , s + 1); n   for (i = 1; i < n; i++) { n     read(x); n     read(y); n     g[x].emplace_back(y); n     g[y].emplace_back(x); n   } n   inv1 = ksm(z1, h1 - 2, h1); n   inv2 = ksm(z2, h2 - 2, h2); n   p1[0] = p2[0] = q1[0] = q2[0] = 1; n   for (i = 1; i <= n; i++) { n     p1[i] = (long long)p1[i - 1] * z1 % h1; n     p2[i] = (long long)p2[i - 1] * z2 % h2; n     q1[i] = (long long)q1[i - 1] * inv1 % h1; n     q2[i] = (long long)q2[i - 1] * inv2 % h2; n   } n   dfs1(1, 0); n   dfs2(1, 0, 1); n   init(); n   for (i = 1; i <= n; i++) n     if (top[i] == i) { n       int x = i; n       for (j = 0; j <= mx[i] - dep[i]; j++) a[i].emplace_back(x), x = fa[x]; n       x = i; n       while (x) b[i].emplace_back(x), x = son[x]; n     } n   read(m); n   while (m--) { n     read(x); n     read(y); n     read(u); n     read(v); n     print(query(x, y, u, v)); n     putchar(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n #include <algorithm> n using namespace std; n   n #define int long long n #define ll long long n #define rep(i,a,b) for (int i = a; i < b; ++i) n #define mod 1000000007 n #define F first n #define S second n #define printer(v) for(auto f: v) cout<<f<<    n #define pb push_back n #define mp make_pair n #define all(c) c.begin(), c.end() n #define ipair pair<int,int> n #define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++) n   n int bin_power(int x, unsigned int y){   // Modular Exponentiation (Power in Modular Arithmetic) n     int temp; n     if( y == 0) n         return 1; n     temp = bin_power(x, y / 2); n     if (y % 2 == 0) n         return (temp * temp)%mod; n     else n         return (x * temp * temp)%mod; n  n     // ll res = 1;  n     // while(y){ n     //     if(y & 1) res = (res * x)%mod;  n     //     y >>= 1;  n     //     x = (x * x)%mod; n     // } n     // return res; n } n  n int inverse_mod(int a){ n     return bin_power(a, mod-2); n } n  n vector<bool> isPrime_Seive_Of_Erastothenes(long n){ n     vector<bool> prime(n+1,true); n     prime[0] = prime[1] = false; n     for(long i=2;i*i<=n;i++){ n         if(prime[i]){ n             for(long j=i*i;j<=n;j+=i){ n                 prime[j] = false; n             } n         } n     } n     return prime; n } n  n bool is_integer(float k){ n   return std::floor(k) == k; n } n  n int fact(int n); n  n int nCr(int n, int r) { n     if(r > n - r) r = n - r; n     int ans = 1; n     int i; n     for(i = 1; i <= r; i++) { n         ans *= n - r + i; n         ans /= i; n     } n     return ans; n } n  n int fact(int n){ n     int res = 1; n     for (int i = 2; i <= n; i++){ n         res = res * i; n         res = res; n     } n     return res; n } n  n unsigned int gcd(unsigned int u, unsigned int v){       // Basic Euclidean Algorithm for GCD  n     int shift; n     if (u == 0) return v; n     if (v == 0) return u; n     shift = __builtin_ctz(u | v); n     u >>= __builtin_ctz(u); n     do { n         v >>= __builtin_ctz(v); n         if (u > v) { n             unsigned int t = v; n             v = u; n             u = t; n         }   n         v = v - u; n     } while (v != 0); n     return u << shift; n } n  n int gcdExtended(int a, int b, int *x, int *y){      // Extended Euclidean Algorithm n     if (a == 0){ n         *x = 0; n         *y = 1; n         return b; n     } n     int x1, y1; n     int gcd = gcdExtended(b%a, a, &x1, &y1); n     *x = y1 - (b/a) * x1; n     *y = x1; n     return gcd; n } n  n int binarySearch(int l, int r, int k){ n     if(l == r) return l; n     int mid = l + (r - l) / 2; n     cout<< ? <<   <<l+1<<   <<mid+1<<  n ; n     cout.flush(); n     int sum; n     cin>>sum; n     int x = mid - l + 1; n     if (x - sum >= k){ n         return binarySearch(l, mid, k); n     } n     else{ n         k -= (x - sum); n         return binarySearch(mid+1, r, k); n     } n } n  n bool isPrime(int n) n { n     if (n <= 1)  return false; n     if (n <= 3)  return true; n     if (n%2 == 0 || n%3 == 0) return false; n     for (int i=5; i*i<=n; i=i+6) n         if (n%i == 0 || n%(i+2) == 0) n            return false; n     return true; n } n  n int nextPrime(int N) n { n     if (N <= 1) n         return 2; n     int prime = N; n     bool found = false; n     while (!found) { n         prime++; n         if (isPrime(prime)) n             found = true; n     } n     return prime; n } n  n signed main(){ n  ios_base::sync_with_stdio(false); n     cin.tie(NULL); cout.tie(NULL); n  int T; n     cin>>T; n     while(T--){ n         int n; n         cin>>n; n         vector<int> A(n); n         int ans = INT_MAX; n         int index = 0; n         for (int i = 0; i < n; ++i){ n             cin>>A[i]; n             if(A[i] < ans){ n                 ans = A[i]; n                 index = i; n             } n         } n         cout<<n - 1<<endl; n         for(int i = 0; i < index; i++){ n             A[i] = ans + abs(index - i); n             cout<<i + 1<<   <<index + 1<<   <<A[i]<<   <<ans<<endl; n         } n         for(int i = index + 1; i < n; i++){ n             A[i] = ans + abs(index - i); n             cout<<i + 1<<   <<index + 1<<   <<A[i]<<   <<ans<<endl; n         } n     } n     return 0; n }


#include <bits/stdc++.h> n #include <vector> n #include <set> n #include <string> n #include <map> n #include <cmath> n #include <algorithm> n typedef long long int ll; n #define f first n #define s second n #define vi vector<int> n #define ld long double n #define pb push_back n #define mp make_pair n #define pii pair<int, int> n #define floop(count,a, n) for(int count{a}; count < n; ++count) n #define tr(c, it) for(auto it{c.begin()}; it != c.end(); ++it) n #define lb lower_bound n #define ub upper_bound n #define bs binary_search n #define newl   n  n  n  n  n using namespace std; n  n const int MOD = 1e9+7; n const ld PI = acos(-1); n const ld EPS = 1e-9; n const ll INF = 1e18; n  n      n int main(){ n  n     ios::sync_with_stdio(0); n     cin.tie(0); cout.tie(0); n         #ifndef ONLINE_JUDGE        n         freopen( input.txt ,  r , stdin);                                      n         freopen( output.txt ,  w , stdout);                        n         #endif     n     int cas;cin>>cas; n         while(cas--){ n             int n; n             cin>>n; n             int a = sqrt(n); n             if(a*a == n) n                 cout<<a<<  n ; n             else n                 cout<<a + 1<<  n ; n  n  n         } n     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC <<  ms n ; n  n     return 0;  n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int l, r; n   cin >> l >> r; n   if (r - l < 2) { n     printf( -1 ); n     return 0; n   } n   if (l & 1) l++; n   if (l + 2 > r) { n     printf( -1 ); n     return 0; n   } n   cout << l <<     << l + 1 <<     << l + 2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 18; n const int MOD = 1000000007; n char c[MAX]; n int r[MAX], b[MAX]; n int dp[1 << 16][125]; n int red[1 << 16], blue[1 << 16]; n void precalc(int n) { n   for (int i = 0; i < (1 << n); i++) { n     for (int j = 0; j < n; j++) { n       if (!(i & (1 << j))) { n         continue; n       } n       if (c[j] ==  R ) { n         red[i]++; n       } else { n         blue[i]++; n       } n     } n   } n } n int main() { n   for (int i = 0; i < 1 << 16; i++) { n     for (int j = 0; j < 125; j++) { n       dp[i][j] = -MOD; n     } n   } n   dp[0][0] = 0; n   long long rt = 0, bt = 0; n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf(  %c %d %d , &c[i], &r[i], &b[i]); n     rt += r[i]; n     bt += b[i]; n   } n   precalc(n); n   long long maxi = 1000000000000000000; n   for (int i = 0; i < (1 << n); i++) { n     for (int j = 0; j < 125; j++) { n       for (int k = 0; k < n; k++) { n         if (i & (1 << k)) { n           continue; n         } n         int res = i | (1 << k); n         int jnew = j + min(red[i], r[k]); n         dp[res][jnew] = max(dp[res][jnew], dp[i][j] + min(blue[i], b[k])); n       } n       maxi = min(maxi, max(rt - j, bt - dp[i][j])); n     } n   } n   printf( %lld n , n + maxi); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T Bitcnt(T a) { n   int sum = 0; n   while (a) { n     if (a & 1) sum++; n     a /= 2; n   } n   return sum; n } n template <class T> n T Max3(T a, T b, T c) { n   return max(a, max(b, c)); n } n template <class T> n T Lcm(T a, T b) { n   T tmp = __gcd(a, b); n   return (a / tmp) * b; n } n template <class T> n T Pow(T a, T b) { n   T ans = 1; n   T base = a; n   while (b) { n     if (b & 1) ans = (ans * base); n     base = (base * base); n     b /= 2; n   } n   return ans; n } n long long Bigmod(long long a, long long b) { n   long long res = 1; n   long long pw = a % 1000000007LL; n   while (b > 0) { n     if (b & 1) res = (res * pw) % 1000000007LL; n     pw = (pw * pw) % 1000000007LL; n     b /= 2; n   } n   return res; n } n int a_x[] = {1, -1, 0, 0}; n int a_y[] = {0, 0, 1, -1}; n long long X, Y; n void extend_euclid(long long a, long long b) { n   if (b == 0) { n     X = a; n     Y = 0; n     return; n   } n   extend_euclid(b, a % b); n   long long x, y; n   x = Y; n   y = X - (a / b) * Y; n   X = x; n   Y = y; n } n long long inverse_modulo(long long a, long long b) { n   extend_euclid(a, b); n   return (X + 1000000007LL) % 1000000007LL; n } n int main() { n   long long x; n   cin >> x; n   if (x == 2) { n     cout << -1; n     return 0; n   } n   if (x % 2 == 0) { n     long long b = (x / 2) * (x / 2) - 1; n     long long c = b + 2; n     cout << b <<     << c; n     return 0; n   } else { n     long long b = (x * x - 1) / 2; n     long long c = (x * x + 1) / 2; n     if (b <= 0 || c <= 0) { n       cout << -1; n       return 0; n     } n     cout << b <<     << c << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int freq[300]; n string s; n const int maxN = 2000; n int primes[maxN]; n int equs[maxN]; n char result[maxN]; n set<pair<int, char> > lets; n int n; n void sieve() { n   for (int i = 2; i < maxN; i++) { n     primes[i] = 1; n   } n   for (long long i = 2; i * i < maxN; i++) { n     if (primes[i] == 1) { n       for (long long j = i * i; j < maxN; j += i) { n         primes[j] = 0; n       } n     } n   } n } n int main(int argc, char const *argv[]) { n   cin >> s; n   sieve(); n   n = s.length(); n   for (int i = 0; i < n; i++) { n     freq[s[i]]++; n   } n   int tot = 0; n   for (int i = 0; i <= n; i++) { n     if (primes[i] == 1 && i * 2 <= n) { n       for (int j = i; j <= n; j += i) { n         if (equs[j] == 0) { n           tot++; n         } n         equs[j] = 1; n       } n     } n   } n   for (int i = 0; i < 300; i++) { n     if (freq[i] != 0) { n       lets.insert(make_pair(-freq[i], i)); n     } n   } n   if (-lets.begin()->first < tot) { n     cout <<  NO  << endl; n     return 0; n   } n   for (int i = 1; i <= n; i++) { n     if (equs[i] == 1) { n       result[i] = lets.begin()->second; n     } n   } n   pair<int, char> tmp = *lets.begin(); n   tmp.first += tot; n   lets.erase(lets.begin()); n   lets.insert(tmp); n   for (int i = 1; i <= n; i++) { n     if (equs[i] == 0) { n       if (lets.begin()->first == 0) { n         lets.erase(lets.begin()); n         i--; n         continue; n       } n       result[i] = lets.begin()->second; n       tmp = *lets.begin(); n       tmp.first++; n       lets.erase(lets.begin()); n       lets.insert(tmp); n     } n   } n   cout <<  YES  << endl; n   for (int i = 1; i <= n; i++) { n     cout << result[i]; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Tp> n inline void rd(Tp &x) { n   x = 0; n   int fh = 1; n   char ch = 1; n   while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar(); n   if (ch ==  - ) fh = -1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   x *= fh; n } n template <typename Tp> n inline void bird(Tp &x) { n   x = 0; n   int fh = 1; n   char ch = 1; n   while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar(); n   if (ch ==  - ) fh = -1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) x = x * 2 + ch -  0 , ch = getchar(); n   x *= fh; n } n template <typename Tp> n inline void smax(Tp &x, Tp y) { n   if (x < y) x = y; n } n const int maxn = 100000 + 7; n const int maxm = 200000 + 7; n const int mod = 1000000007; n int n, m; n int Head[maxn], to[maxm], Next[maxm], w[maxm], tot; n void add(int x, int y, int z) { n   to[++tot] = y, Next[tot] = Head[x], Head[x] = tot, w[tot] = z; n } n inline void Init(void) { n   rd(n); n   rd(m); n   for (int i = 1, x, y, z; i <= m; i++) { n     rd(x); n     rd(y); n     rd(z); n     add(x, y, z); n     add(y, x, z); n   } n } n bool vis[maxn]; n int c[maxn]; n void dfs(int x, int f, int col) { n   if (vis[x]) { n     if (c[x] != col) { n       puts( 0 ); n       exit(0); n     } n     return; n   } n   vis[x] = true; n   c[x] = col; n   for (int i = Head[x]; i; i = Next[i]) { n     int y = to[i]; n     if (y == f) continue; n     if (w[i]) n       dfs(y, x, col); n     else n       dfs(y, x, 3 - col); n   } n } n int fpow(long long x, int p) { n   long long res = 1ll; n   while (p) { n     if (p & 1) res = res * x % mod; n     p >>= 1; n     x = x * x % mod; n   } n   return res; n } n inline void Work(void) { n   long long ans = 1ll; n   for (int i = 1; i <= n; i++) { n     if (vis[i] == false) { n       dfs(i, 0, 1); n       ans = ans * 2 % mod; n     } n   } n   ans = ans * fpow(2, mod - 2) % mod; n   printf( %lld n , ans); n } n signed main(void) { n   Init(); n   Work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a, b, ans[100], i, sum, z = 1; n   scanf( %d%d%d , &n, &a, &b); n   sum = ans[0] = 1; n   for (i = 1; i <= b; i++) { n     ans[i] = sum + 1; n     if (ans[i] > 50000) z = 0; n     sum += ans[i]; n   } n   if (z) { n     if (b != 0) { n       for (; i <= a + b; i++) { n         ans[i] = ans[i - 1] + 1; n         if (ans[i] > 50000) z = 0; n       } n     } else { n       sum = ans[0] = ans[1] = 1; n       for (i = 2; i <= 1 + a + b; i++) { n         ans[i] = ans[i - 1] + 1; n         if (ans[i] > 50000) z = 0; n       } n       if ((n != 1) && (a == n - 1)) z = 0; n     } n   } n   if (z == 0) n     printf( -1 ); n   else { n     for (; i < n; i++) { n       ans[i] = ans[i - 1]; n     } n     for (i = 0; i < n; i++) printf( %d  , ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 20; n inline int read() { n   int ans = 0; n   char last =    , ch = getchar(); n   while (ch< 0  | ch>  9 ) last = ch, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) ans = ans * 10 + ch -  0 , ch = getchar(); n   if (last ==  - ) ans = -ans; n   return ans; n } n int n, k; n vector<int> save[maxn]; n int a[maxn], color[maxn], cnt[maxn], ls[maxn]; n void solve() { n   n = read(), k = read(); n   for (int i = 0; i <= n; i++) save[i].clear(), color[i] = 0; n   for (int i = 0; i <= n - 1; i++) a[i] = read(), save[a[i]].push_back(i); n   int kd = 0; n   for (int i = 0; i <= n; i++) { n     for (int j = 0; j <= min(k, (int)(save[i].size())) - 1; j++) { n       color[save[i][j]] = kd + 1; n       ls[kd + 1] = save[i][j]; n       kd++; n       kd %= k; n     } n   } n   for (int i = 1; i <= kd; i++) color[ls[i]] = 0; n   for (int i = 0; i <= n - 1; i++) cout << color[i] <<    ; n   cout <<   n ; n } n int main() { n   int _t; n   _t = read(); n   while (_t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 201001; n const int MAXK = 51; n const double inf = 1e100; n const double eps = 1e-10; n int K, N; n int tab[MAXN]; n long long sum[MAXN]; n double res[MAXN]; n double odw[MAXN]; n double dp[MAXK][MAXN]; n struct Pt { n   double x, y; n }; n int ccw(const Pt& a, const Pt& b, const Pt& c) { n   double w = 0; n   w += a.x * (b.y - c.y); n   w += b.x * (c.y - a.y); n   w += c.x * (a.y - b.y); n   return w < -eps ? -1 : w > eps; n } n int main() { n   scanf( %d %d , &N, &K); n   for (int i = (1); i <= (N); ++i) { n     scanf( %d , &tab[i]); n     sum[i] = sum[i - 1] + tab[i]; n     odw[i] = odw[i - 1] + 1. / tab[i]; n     res[i] = res[i - 1] + (double)sum[i] / tab[i]; n   } n   for (int i = (1); i <= (N); ++i) dp[1][i] = res[i]; n   for (int k = (2); k <= (K); ++k) { n     vector<Pt> v; n     for (int i = (k - 1); i <= (N); ++i) { n       Pt pt = {-1. * sum[i], dp[k - 1][i] - res[i] + sum[i] * odw[i]}; n       while (v.size() >= 2 && ccw(v[((int)((v).size())) - 2], v.back(), pt) > 0) n         v.pop_back(); n       v.push_back(pt); n     } n     int p = 0; n     for (int i = (k); i <= (N); ++i) { n       while (p + 1 < ((int)((v).size())) && n              v[p].x * odw[i] + v[p].y > v[p + 1].x * odw[i] + v[p + 1].y) n         ++p; n       dp[k][i] = v[p].x * odw[i] + v[p].y + res[i]; n     } n   } n   printf( %.10lf n , dp[K][N]); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 105, INF = 1 << 30, MOD = 1e9 + 7; n int n, k; n vector<int> adj[N]; n long long cnt[N][N]; n long long ans = 0, F[N]; n long long sumOfProducts(vector<int>& arr, int n, int k) { n   long long dp[n + 1][n + 1]; n   memset(dp, 0, sizeof(dp)); n   long long cur_sum = 0; n   for (int i = 1; i <= n; i++) { n     dp[1][i] = arr[i - 1]; n     (cur_sum += arr[i - 1]) %= MOD; n   } n   for (int i = 2; i <= k; ++i) { n     long long temp_sum = 0; n     for (int j = 1; j <= n; j++) { n       (cur_sum -= dp[i - 1][j]) %= MOD; n       dp[i][j] = (arr[j - 1] * cur_sum) % MOD; n       (temp_sum += dp[i][j]) %= MOD; n     } n     cur_sum = temp_sum; n   } n   return (cur_sum + MOD) % MOD; n } n void dfs(int u, int root, int p, int d) { n   ++cnt[root][d]; n   for (int v : adj[u]) { n     if (v == p) continue; n     dfs(v, root, u, d + 1); n   } n } n void solve(int u) { n   memset(cnt, 0, sizeof(cnt)); n   if (adj[u].size() < k) return; n   for (int v : adj[u]) { n     dfs(v, v, u, 0); n   } n   for (int i = 0; i < n; ++i) { n     int CNT = 0; n     for (int v : adj[u]) n       if (cnt[v][i]) ++CNT; n     if (CNT < k) break; n     vector<int> C; n     for (int v : adj[u]) n       if (cnt[v][i]) C.push_back(cnt[v][i]); n     (ans += sumOfProducts(C, CNT, k)) %= MOD; n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   F[0] = 1; n   for (int i = 1; i < N; ++i) F[i] = (F[i - 1] * i) % MOD; n   int t; n   cin >> t; n   while (t--) { n     ans = 0; n     cin >> n >> k; n     for (int i = 0; i < n; ++i) adj[i].clear(); n     for (int i = 0; i < n - 1; ++i) { n       int u, v; n       cin >> u >> v; n       adj[--u].push_back(--v); n       adj[v].push_back(u); n     } n     if (k == 2) n       cout << n * (n - 1) / 2 <<   n ; n     else { n       for (int i = 0; i < n; ++i) solve(i); n       cout << ans % MOD <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXn = 1e5 + 10, MAXx = 4 * MAXn; n struct salar { n   int l, r, max1, leftchild, rightchild, id; n   long long sum; n   salar() { sum = id = l = r = max1 = leftchild = rightchild = 0; } n   void idit(int v) { n     id = v; n     leftchild = 2 * v; n     rightchild = 2 * v + 1; n   } n }; n salar seg[MAXx]; n int ar[MAXn], n, m; n void build(int v, int l, int r) { n   seg[v].l = l, seg[v].r = r; n   seg[v].idit(v); n   if (r - l == 1) { n     seg[v].sum = ar[l]; n     seg[v].max1 = ar[l]; n     return; n   } n   int med = (l + r) / 2; n   build(seg[v].leftchild, l, med); n   build(seg[v].rightchild, med, r); n   seg[v].sum = seg[seg[v].leftchild].sum + seg[seg[v].rightchild].sum; n   seg[v].max1 = max(seg[seg[v].leftchild].max1, seg[seg[v].rightchild].max1); n } n long long get(int v, int l, int r) { n   if (max(l, seg[v].l) >= min(r, seg[v].r)) return 0; n   if (l <= seg[v].l && seg[v].r <= r) { n     return seg[v].sum; n   } n   return get(seg[v].leftchild, l, r) + get(seg[v].rightchild, l, r); n } n void domodule(int v, int l, int r, int x) { n   if (seg[v].max1 < x) return; n   if (max(l, seg[v].l) >= min(r, seg[v].r)) return; n   if (seg[v].r - seg[v].l == 1) { n     ar[seg[v].l] %= x; n     seg[v].sum = ar[seg[v].l]; n     seg[v].max1 = ar[seg[v].l]; n     return; n   } n   domodule(seg[v].leftchild, l, r, x); n   domodule(seg[v].rightchild, l, r, x); n   seg[v].sum = seg[seg[v].leftchild].sum + seg[seg[v].rightchild].sum; n   seg[v].max1 = max(seg[seg[v].leftchild].max1, seg[seg[v].rightchild].max1); n } n void change(int v, int l, int x) { n   if (l < seg[v].l || l >= seg[v].r) return; n   if (seg[v].r - seg[v].l == 1) { n     ar[seg[v].l] = x; n     seg[v].sum = ar[seg[v].l]; n     seg[v].max1 = ar[seg[v].l]; n     return; n   } n   change(seg[v].leftchild, l, x); n   change(seg[v].rightchild, l, x); n   seg[v].sum = seg[seg[v].leftchild].sum + seg[seg[v].rightchild].sum; n   seg[v].max1 = max(seg[seg[v].leftchild].max1, seg[seg[v].rightchild].max1); n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> ar[i]; n   build(1, 0, n); n   for (int i = 0; i < m; i++) { n     int type; n     cin >> type; n     if (type == 1) { n       int l, r; n       cin >> l >> r; n       l--; n       cout << get(1, l, r) << endl; n     } else if (type == 2) { n       int l, r, x; n       cin >> l >> r >> x; n       l--; n       domodule(1, l, r, x); n     } else { n       int l, x; n       cin >> l >> x; n       l--; n       change(1, l, x); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[100005]; n long long b[100005], dpMax[100005], dpMin[100005], ans = (1ll << 63); n void setup() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n - 1; i++) b[i] = abs(a[i] - a[i + 1]); n   n--; n } n void xuly() { n   for (int i = n; i >= 1; i--) { n     dpMax[i] = -min(dpMin[i + 1], 0ll) + b[i]; n     dpMin[i] = -max(dpMax[i + 1], 0ll) + b[i]; n     ans = max(ans, dpMax[i]); n   } n   cout << ans; n } n int main() { n   iostream::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   setup(); n   xuly(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   int n; n   cin >> n; n   int a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i < n; i++) { n     for (int t = 0; t < n - 1; t++) { n       if (a[t] > a[t + 1]) { n         int j = t + 1; n         cout << t + 1 <<     << j + 1 << endl; n         int q = a[t]; n         a[t] = a[j]; n         a[j] = q; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   long long a, b, c, i, j, k, l, m, t, x, y, n, z; n   string s; n   map<long long, long long> mp; n   map<long long, long long>::iterator it; n   cin >> a >> s; n   n = s.size(); n   long long a1[n + 1]; n   a1[0] = 0; n   for (i = 1; i < n + 1; i++) a1[i] = s[i - 1] -  0  + a1[i - 1]; n   for (i = 0; i < n + 1; i++) { n     for (j = i + 1; j < n + 1; j++) { n       mp[a1[j] - a1[i]]++; n     } n   } n   c = 0; n   if (!a) c = (mp[0] * (n * (n + 1) - mp[0])); n   if (!a) { n     cout << c << endl; n     return 0; n   } n   for (i = 0; i < n + 1; i++) { n     for (j = i + 1; j < n + 1; j++) { n       if (a1[j] - a1[i] != 0) n         if (a % (a1[j] - a1[i]) == 0) { n           it = mp.find(a / (a1[j] - a1[i])); n           if (it != mp.end()) c = c + mp[a / (a1[j] - a1[i])]; n         } n     } n   } n   cout << c << 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 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 struct Input { n   int n, k; n   vector<vector<int> > g; n   vector<int> h; n   vector<int> s; n   bool read() { n     if (!(cin >> n)) { n       return 0; n     } n     h.resize(n); n     for (int i = int(0); i < int(n); ++i) { n       cin >> h[i]; n     } n     g.assign(n, vector<int>()); n     for (int i = int(0); i < int(n - 1); ++i) { n       int u, v; n       cin >> u >> v; n       --u, --v; n       g[u].push_back(v); n       g[v].push_back(u); n     } n     cin >> k; n     s.resize(k); n     for (int i = int(0); i < int(k); ++i) { n       cin >> s[i]; n     } n     return 1; n   } n   void init(const Input& input) { *this = input; } n }; n struct Data : Input { n   int ans; n   void write() { cout << ans <<   n ; } n   virtual void solve() {} n   virtual void clear() { *this = Data(); } n }; n struct Solution : Data { n   vector<int> sc_best; n   vector<int> fs_best; n   vector<int> all_vals; n   vector<int> heights; n   vector<int> backw_pos; n   vector<int> forw_pos; n   vector<int> fail_pos; n   vector<int> fail_vers; n   void dfs(int x, int par, int first, int second) { n     if (first == -1 || h[x] <= h[first]) { n       second = first; n       first = x; n     } else if (second == -1 || h[x] <= h[second]) { n       second = x; n     } n     fs_best[x] = first; n     sc_best[x] = second; n     for (auto to : g[x]) { n       if (to != par) { n         dfs(to, x, first, second); n       } n     } n   } n   int mfit() { n     int ans = -1; n     int ln = 0; n     for (int i = int(0); i < int(((int)(all_vals).size())); ++i) { n       int cur = 0; n       vector<int> new_h; n       int rn = ln; n       while (rn < n && fs_best[heights[rn]] == all_vals[i]) ++rn; n       int fail_from = 0, fail_to = fail_pos[i]; n       int lp = forw_pos[i], rp = backw_pos[i]; n       bool ok = true; n       for (int j = int(ln); j < int(rn); ++j) { n         int a = h[all_vals[i]]; n         int b = 2000000000; n         if (sc_best[heights[j]] != -1) { n           b = h[sc_best[heights[j]]]; n         } n         if (fail_from != fail_to) { n           if (b >= fail_vers[fail_from]) { n             umx(cur, fail_vers[fail_from] - a); n             ++fail_from; n           } else { n             ok = false; n           } n         } else if (lp != rp) { n           if (b >= s[lp]) { n             umx(cur, s[lp] - a); n             ++lp; n           } else { n             ok = false; n           } n         } n       } n       if (ok && fail_from == fail_to && lp == rp && (ans == -1 || ans > cur)) { n         ans = cur; n       } n       ln = rn; n     } n     return ans; n   } n   void solve() { n     sort((s).begin(), (s).end()); n     reverse((s).begin(), (s).end()); n     sc_best.assign(n, -1); n     fs_best.assign(n, -1); n     dfs(0, -1, -1, -1); n     heights.resize(n); n     for (int i = int(0); i < int(n); ++i) { n       heights[i] = i; n     } n     sort((heights).begin(), (heights).end(), [&](int a, int b) { n       return (h[fs_best[a]] > h[fs_best[b]] || n               (h[fs_best[a]] == h[fs_best[b]] && fs_best[a] < fs_best[b]) || n               (fs_best[a] == fs_best[b] && n                (sc_best[b] != -1 && n                 (sc_best[a] == -1 || h[sc_best[a]] > h[sc_best[b]])))); n     }); n     all_vals.clear(); n     for (auto x : heights) { n       if (all_vals.empty() || all_vals.back() != fs_best[x]) { n         all_vals.push_back(fs_best[x]); n       } n     } n     int lp = 0, ln = 0; n     int cnt = ((int)(all_vals).size()); n     forw_pos.assign(cnt, 0); n     fail_pos.assign(cnt, 0); n     for (int i = int(0); i < int(cnt - 1); ++i) { n       while (ln < n && fs_best[heights[ln]] == all_vals[i]) { n         int cur_h = h[all_vals[i]]; n         while (lp < k && cur_h < s[lp]) { n           fail_vers.push_back(s[lp]); n           ++lp; n         } n         if (lp < k) { n           ++lp; n         } n         ++ln; n       } n       forw_pos[i + 1] = lp; n       fail_pos[i + 1] = ((int)(fail_vers).size()); n     }; n     backw_pos.assign(cnt, k); n     int rp = k - 1, rn = n - 1; n     for (int i = int(cnt) - 1; i >= int(1); --i) { n       while (rn >= 0 && fs_best[heights[rn]] == all_vals[i]) { n         int cur_h = h[all_vals[i]]; n         if (rp >= 0) { n           if (cur_h >= s[rp]) { n             --rp; n           } n         } n         --rn; n       } n       backw_pos[i - 1] = rp + 1; n     } n     ans = mfit(); 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   ios_base::sync_with_stdio(false); n   sol.read(); n   sol.solve(); n   sol.write(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   long long prod = 1; n   int arr[10]; n   for (int i = 0; i < 10; i++) arr[i] = 1; n   int p = 0; n   while (prod < n) { n     p %= 10; n     prod /= arr[p]; n     ++arr[p]; n     prod *= arr[p]; n     p++; n   } n   string s =  codeforces ; n   for (int i = 0; i < 10; i++) { n     for (int j = 0; j < arr[i]; j++) cout << s[i]; n   } n   return 0; n } n