#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t = 1; n   cin >> t; n   while (t-- > 0) { n     int n; n     cin >> n; n     string srr[n]; n     for (int i = 0; i < n; i++) { n       cin >> srr[i]; n     } n     vector<pair<int, int>> afirst(n); n     vector<pair<int, int>> bfirst(n); n     vector<pair<int, int>> cfirst(n); n     vector<pair<int, int>> dfirst(n); n     vector<pair<int, int>> efirst(n); n     for (int i = 0; i < n; i++) { n       int countabc[5] = {0}; n       for (int j = 0; j < srr[i].size(); j++) { n         countabc[srr[i][j] -  a ]++; n       } n       afirst[i].first = 2 * countabc[0] - srr[i].size(); n       bfirst[i].first = 2 * countabc[1] - srr[i].size(); n       cfirst[i].first = 2 * countabc[2] - srr[i].size(); n       dfirst[i].first = 2 * countabc[3] - srr[i].size(); n       efirst[i].first = 2 * countabc[4] - srr[i].size(); n       afirst[i].second = i; n       bfirst[i].second = i; n       cfirst[i].second = i; n       dfirst[i].second = i; n       efirst[i].second = i; n     } n     sort(afirst.begin(), afirst.end()); n     sort(bfirst.begin(), bfirst.end()); n     sort(cfirst.begin(), cfirst.end()); n     sort(dfirst.begin(), dfirst.end()); n     sort(efirst.begin(), efirst.end()); n     int maxi = 0; n     int curr = 0; n     int total = 0; n     for (int i = n - 1; i >= 0; i--) { n       curr += afirst[i].first; n       if (curr >= 1) { n         total++; n       } else { n         break; n       } n     } n     maxi = max(maxi, total); n     curr = 0; n     total = 0; n     for (int i = n - 1; i >= 0; i--) { n       curr += bfirst[i].first; n       if (curr >= 1) { n         total++; n       } else { n         break; n       } n     } n     maxi = max(maxi, total); n     curr = 0; n     total = 0; n     for (int i = n - 1; i >= 0; i--) { n       curr += cfirst[i].first; n       if (curr >= 1) { n         total++; n       } else { n         break; n       } n     } n     maxi = max(maxi, total); n     curr = 0; n     total = 0; n     for (int i = n - 1; i >= 0; i--) { n       curr += dfirst[i].first; n       if (curr >= 1) { n         total++; n       } else { n         break; n       } n     } n     maxi = max(maxi, total); n     curr = 0; n     total = 0; n     for (int i = n - 1; i >= 0; i--) { n       curr += efirst[i].first; n       if (curr >= 1) { n         total++; n       } else { n         break; n       } n     } n     maxi = max(maxi, total); n     cout << maxi << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long rd() { n   long long x = 0; n   char o, f = 1; n   while (o = getchar(), o < 48) n     if (o == 45) f = -f; n   do x = (x << 3) + (x << 1) + (o ^ 48); n   while (o = getchar(), o > 47); n   return x * f; n } n const int maxn = 1e2 + 5; n const long long mod = 998244353; n int _; n int n, m, a[maxn][maxn]; n long long ans; n void solve(int x, int y) { n   vector<int> v; n   v.push_back(a[x][y]); n   if (n - x + 1 != x) v.push_back(a[n - x + 1][y]); n   if (m - y + 1 != y) v.push_back(a[x][m - y + 1]); n   if (n - x + 1 != x && m - y + 1 != y) v.push_back(a[n - x + 1][m - y + 1]); n   sort(v.begin(), v.end()); n   int len = v.size(); n   len /= 2; n   for (auto u : v) { n     ans += abs(v[len] - u); n   } n } n int main() { n   for (_ = rd(); _; _--) { n     ans = 0; n     n = rd(); n     m = rd(); n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= m; j++) a[i][j] = rd(); n     for (int i = 1; i <= (n + 1) / 2; i++) { n       for (int j = 1; j <= (m + 1) / 2; j++) solve(i, j); n     } n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T1, typename T2> n inline void chkmin(T1& a, T2 b) { n   if (a > b) a = b; n } n template <typename T1, typename T2> n inline void chkmax(T1& a, T2 b) { n   if (a < b) a = b; n } n using ll = long long; n using ld = long double; n const string FILENAME =  input ; n using ll = long long; n using ld = long double; n struct Point { n   ld x, y; n   Point() {} n   Point(ld _x, ld _y) : x(_x), y(_y) {} n   ld len() { return sqrt(x * x + y * y); } n }; n Point operator+(const Point& a, const Point& b) { n   return Point(a.x + b.x, a.y + b.y); n } n Point operator-(const Point& a, const Point& b) { n   return Point(a.x - b.x, a.y - b.y); n } n ld operator*(const Point& a, const Point& b) { return a.x * b.y - a.y * b.x; } n ld operator^(const Point& a, const Point& b) { return a.x * b.x + a.y * b.y; } n const double Pi = acos(-1); n const int MAXN = 100228; n int n, k; n Point p[MAXN]; n bool ok(double r) { n   vector<pair<double, int> > st; n   int add = 0; n   for (int i = 0; i < n; i++) { n     double f = p[i].len(); n     if (f > 2 * r + 1e-9) { n       continue; n     } n     if (abs(p[i].x) < 1e-9 && abs(p[i].y) < 1e-9) { n       add++; n       continue; n     } n     Point q = p[i]; n     swap(q.x, q.y); n     q.x *= -1; n     double fm = sqrt(q.x * q.x + q.y * q.y); n     q.x /= fm; n     q.y /= fm; n     double h = sqrt(r * r - (f / 2) * (f / 2)); n     q.x *= h; n     q.y *= h; n     Point s = p[i]; n     s.x /= 2; n     s.y /= 2; n     Point e = s + q; n     Point e1 = s - q; n     double l = atan2(e.y, e.x) + 2 * Pi; n     double rr = atan2(e1.y, e1.x) + 2 * Pi; n     while (l < 0) { n       l += 2 * Pi; n     } n     while (rr < 0) { n       rr += 2 * Pi; n     } n     while (l >= 2 * Pi) { n       l -= 2 * Pi; n     } n     while (rr >= 2 * Pi) { n       rr -= 2 * Pi; n     } n     if (l > rr) { n       swap(l, rr); n     } n     if (rr - l <= Pi + 1e-9) { n       st.push_back(make_pair(l, 1)); n       st.push_back(make_pair(rr, -1)); n     } else { n       st.push_back(make_pair(0, 1)); n       st.push_back(make_pair(l, -1)); n       st.push_back(make_pair(rr, 1)); n       st.push_back(make_pair(2 * Pi, -1)); n     } n   } n   sort((st).begin(), (st).end()); n   int cur = 0; n   int tm = 0; n   for (auto x : st) { n     cur += x.second; n     chkmax(tm, cur); n   } n   return tm + add >= k; n } n void solve() { n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     int x, y; n     cin >> x >> y; n     p[i].x = x; n     p[i].y = y; n   } n   double l = 0.0; n   double r = 200228; n   for (int it = 0; it < 36; it++) { n     double mid = (l + r) / 2.0; n     if (ok(mid)) { n       r = mid; n     } else { n       l = mid; n     } n   } n   cout << fixed << l <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1005; n long long sum[N][N]; n int spt[11][N][N], mn[N][N], arr[N][N]; n bool visit[N][N]; n int n, m, a, b, x; n void buildSparse() { n   int LN = log2(n) + 1, LM = log2(m) + 1; n   for (int lg = 1; lg <= LM; lg++) n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= m; j++) n         spt[lg][i][j] = n             min(spt[lg - 1][i][j], spt[lg - 1][i][j + (1 << (lg - 1))]); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       sum[i][j] += sum[i - 1][j]; n       if (j >= b) { n         int lg = log2(b), l = j - b + 1, r = j - (1 << lg) + 1; n         mn[i][j] = min(spt[lg][i][l], spt[lg][i][r]); n       } n     } n   for (int i = 1; i <= n; i++) n     for (int j = b; j <= m; j++) spt[0][i][j] = mn[i][j]; n   for (int lg = 1; lg <= LN; lg++) n     for (int i = 1; i <= n; i++) n       for (int j = b; j <= m; j++) n         spt[lg][i][j] = n             min(spt[lg - 1][i][j], spt[lg - 1][i + (1 << (lg - 1))][j]); n } n long long getRemoved(int i, int j) { n   int lg = log2(a), l = i - a + 1; n   int r = i - (1 << lg) + 1; n   int minn = min(spt[lg][l][j], spt[lg][r][j]); n   long long res = sum[i][j] - sum[i - a][j] - sum[i][j - b] + n                   sum[i - a][j - b] - 1LL * a * b * minn; n   return res; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m >> a >> b; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       cin >> arr[i][j]; n       spt[0][i][j] = arr[i][j]; n       sum[i][j] += sum[i][j - 1] + arr[i][j]; n     } n   } n   buildSparse(); n   vector<pair<long long, pair<int, int>>> v, ans; n   for (int i = a; i <= n; i++) n     for (int j = b; j <= m; j++) v.push_back({getRemoved(i, j), {i, j}}); n   sort(v.begin(), v.end()); n   for (int i = 0; i < v.size(); i++) { n     int x = v[i].second.first - a + 1, y = v[i].second.second - b + 1; n     if (!visit[x][y] && !visit[x + a - 1][y] && !visit[x][y + b - 1] && n         !visit[x + a - 1][y + b - 1]) { n       ans.push_back({v[i].first, {x, y}}); n       for (int j = 0; j < a; j++) n         for (int k = 0; k < b; k++) visit[x + j][y + k] = true; n     } n   } n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); i++) n     cout << ans[i].second.first <<     << ans[i].second.second <<     n          << ans[i].first <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100000 + 10; n struct Edge { n   int from, to, w; n } edges[maxn]; n int val[maxn]; n long long ans; n int size[maxn], fa[maxn]; n bool cmp(Edge a, Edge b) { return a.w > b.w; } n int Getfa(int x) { n   if (fa[x] == x) n     return x; n   else n     return fa[x] = Getfa(fa[x]); n } n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) scanf( %d , &val[i]); n   for (int i = 1; i <= m; ++i) { n     int u, v; n     scanf( %d %d , &u, &v); n     edges[i].from = u, edges[i].to = v; n     edges[i].w = min(val[u], val[v]); n   } n   sort(edges + 1, edges + 1 + m, cmp); n   for (int i = 1; i <= n; ++i) size[i] = 1, fa[i] = i; n   ans = 0; n   for (int i = 1; i <= m; ++i) { n     int u = edges[i].from, v = edges[i].to; n     int fx = Getfa(u), fy = Getfa(v); n     if (fx == fy) continue; n     ans += (long long)size[fx] * size[fy] * edges[i].w; n     fa[fx] = fy; n     size[fy] += size[fx]; n   } n   printf( %.6lf n , (double)2.0 * ans / n / (n - 1)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int N, M; n   char eat; n   cin >> N >> M; n   scanf( %c , &eat); n   char temp[5000]; n   vector<vector<bool>> grid(N, vector<bool>(M)); n   for (int r = 0; r < N; r++) { n     scanf( %s , temp); n     for (int c = 0; c < M; c++) grid[r][c] = (temp[c] ==  1  ? 1 : 0); n   } n   int result = 0; n   vector<vector<int>> memo(N, vector<int>(M)); n   for (int r = 0; r < N; r++) { n     for (int c = M - 1; c >= 0; c--) { n       if (grid[r][c] == 1) memo[r][c] = 1 + (c != M - 1 ? memo[r][c + 1] : 0); n     } n   } n   for (int c = 0; c < M; c++) { n     vector<int> width; n     for (int r = 0; r < N; r++) { n       if (memo[r][c] != 0) width.push_back(memo[r][c]); n     } n     sort(width.rbegin(), width.rend()); n     for (int i = 0; i < width.size(); i++) { n       int area = (i + 1) * width[i]; n       result = max(result, area); n     } n   } n   cout << result << endl; n } n


#include <bits/stdc++.h> n using namespace std; n      n #define pb push_back n #define MP make_pair n #define ll long long n #define lb lower_bound n #define ub upper_bound n #define bs binary_search n  n #define fo(i,a,b) for(int i=a;i<b;i++) n #define rfo(i,b,a) for(int i=b;i>=a;i--) n  n typedef vector<ll> vi; n typedef vector<vi> vvi; n  n  string solve(){ n    ll n; n    cin>>n; n    vi a(n); n    map<int,int> m; n     n    fo(i,0,n){ n        cin>>a[i]; n        m[a[i]] = m[a[i]]  + (i%2); n    } n    sort(a.begin(), a.end()); n    fo(i,0,n){ n        m[a[i]] = m[a[i]]-(i%2); n    } n    map<int,int> :: iterator itr; n    for(itr = m.begin() ; itr!= m.end() ; itr++){ n        if(itr->second != 0) return  NO ; n    } n    return  YES ; n      n } n  n  n int main() n { n  ios_base::sync_with_stdio(false); n     cin.tie(NULL); n     int t; n  cin>>t; n  while(t--) n  { n   cout<<solve()<<endl; n  } n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct t { n   char c; n   int a, b; n   t(char c, int a, int b) : c(c), a(a), b(b) {} n   t() {} n }; n int n; n vector<t> e; n double temp; n double t0 = 1000; n double gen_rand() { n   int x = rand() + 1, y = rand() + 1; n   x %= y; n   return x / (double)y; n } n int get_ans() { n   int r = 0, b = 0; n   int R = 0, B = 0; n   int ans = 0; n   for (int i = 0; i < n; i++) { n     int need = n         max(max(0, max(0, e[i].a - R) - r), max(0, max(0, e[i].b - B) - b)); n     ans += need; n     r -= max(0, max(0, e[i].a - R)); n     b -= max(0, max(0, e[i].b - B)); n     r += need; n     b += need; n     ans++; n     if (e[i].c ==  R ) { n       R++; n     } else { n       B++; n     } n   } n   return ans; n } n int main() { n   srand(time(NULL)); n   cin >> n; n   for (int i = 0; i < n; i++) { n     char c; n     int r, b; n     cin >> c >> r >> b; n     e.push_back({c, r, b}); n   } n   random_shuffle(e.begin(), e.end()); n   temp = t0; n   int ans = INT_MAX; n   for (int qwe = 0; qwe < 70000; ++qwe) { n     int cur = get_ans(); n     ans = min(ans, cur); n     vector<t> was = e; n     for (int i = 0; i < n * temp / t0; i++) { n       swap(e[rand() % n], e[rand() % n]); n     } n     int now = get_ans(); n     ans = min(ans, now); n     if (now < cur) { n       cur = now; n     } else { n       double go = exp(-(now - cur) / temp); n       if (gen_rand() <= go) { n         cur = now; n       } else { n         e = was; n       } n     } n     temp *= 0.999; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T gcd(T a, T b) { n   return (b ? __gcd(a, b) : a); n } n template <typename T> n T lcm(T a, T b) { n   return (a * (b / gcd(a, b))); n } n template <class T> n ostream &operator<<(ostream &os, vector<T> V) { n   os <<  [  ; n   for (auto v : V) os << v <<    ; n   return os <<  ] ; n } n template <class T> n ostream &operator<<(ostream &os, set<T> S) { n   os <<  {  ; n   for (auto s : S) os << s <<    ; n   return os <<  } ; 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 template <class L, class R> n ostream &operator<<(ostream &os, map<L, R> M) { n   os <<  {  ; n   for (auto m : M) os <<  (  << m.first <<  :  << m.second <<  )  ; n   return os <<  } ; n } n const int N = 5e5 + 5; n long long ar[N]; n long long l[N], r[N], ans[N]; n int main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   cin.exceptions(cin.failbit); n   int n; n   cin >> n; n   for (int i = 1; i <= n; ++i) cin >> ar[i]; n   vector<long long> lft(1, 0), rt(1, n + 1); n   for (int i = 1; i <= n; ++i) { n     while (ar[lft.back()] > ar[i]) { n       lft.pop_back(); n     } n     l[i] = l[lft.back()] + ar[i] * (i - lft.back()); n     lft.push_back(i); n   } n   for (int i = n; i; --i) { n     while (ar[rt.back()] > ar[i]) rt.pop_back(); n     r[i] = r[rt.back()] + ar[i] * (rt.back() - i); n     rt.push_back(i); n   } n   for (int i = 1; i <= n; ++i) { n     ans[i] = l[i] + r[i] - ar[i]; n   } n   long long maxa = max_element(ans + 1, ans + n + 1) - ans; n   for (int i = maxa - 1; i; --i) { n     if (ar[i] > ar[i + 1]) ar[i] = ar[i + 1]; n   } n   for (int i = maxa + 1; i <= n; ++i) n     if (ar[i - 1] < ar[i]) ar[i] = ar[i - 1]; n   for (int i = 1; i <= n; ++i) cout << ar[i] <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string getbiner(long long n) { n   string ret =   ; n   while (n) { n     if (n % 2) n       ret +=  1 ; n     else n       ret +=  0 ; n     n /= 2; n   } n   return ret; n } n long long getnum(string s) { n   long long ret = 0; n   long long now = 1; n   cout <<   t  << ( s ) <<   =   << (s) <<   n ; n   for (long long(i) = (0); (i) < (s.length()); (i)++) { n     ret += ((s[i] -  0 ) * now); n     now *= 2; n   } n   return ret; n } n int main() { n   ios::sync_with_stdio(NULL); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n, m; n   cin >> n >> m; n   if (n < m) { n     cout << 0 <<   n ; n     return 0; n   } n   if ((n - m) % 2) { n     cout << 0 <<   n ; n     return 0; n   } n   long long k = (n - m) / 2; n   string a = getbiner(m); n   string b = getbiner(k); n   long long mx = max(a.length(), b.length()); n   long long diffa = mx - a.length(); n   long long diffb = mx - b.length(); n   for (long long(i) = (0); (i) < (diffa); (i)++) a +=  0 ; n   for (long long(i) = (0); (i) < (diffb); (i)++) b +=  0 ; n   reverse(a.begin(), a.end()); n   reverse(b.begin(), b.end()); n   long long counter = 0; n   int flag = 0; n   for (long long(i) = (0); (i) < (a.length()); (i)++) { n     if (a[i] ==  1  && b[i] ==  0 ) { n       counter++; n     } else if (a[i] ==  1  && b[i] ==  1 ) { n       flag = 1; n     } n   } n   if (flag) { n     cout << 0 <<   n ; n     return 0; n   } n   long long ans = pow(2, counter); n   if (n == m) ans -= 2; n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2 * 100 * 1000 + 10; n bool f1[maxn], f2[maxn]; n int n, dis[maxn], dis2[maxn], barg[maxn], mxdis, mxdis2, jj1, j2, h1, h2; n vector<int> e[maxn], e2[maxn]; n vector<pair<int, int> > v1, v2; n void barg2(int v, int p, int t) { n   f2[v] = true; n   dis2[v] = t; n   for (int i = 0; i < e[v].size(); i++) { n     int u = e[v][i]; n     if (u != p && u != h2) barg2(u, v, t + 1); n   } n } n void barg1(int v, int p, int t) { n   f1[v] = true; n   dis[v] = t; n   for (int i = 0; i < e[v].size(); i++) { n     int u = e[v][i]; n     if (u != p && u != h1) barg1(u, v, t + 1); n   } n } n int hazf2(int v, int p) { n   if (v == jj1) return jj1; n   for (int i = 0; i < e2[v].size(); i++) { n     int u = e2[v][i]; n     if (u != p) { n       int x = hazf2(u, v); n       if (x != -1) return u; n     } n   } n   return -1; n } n int hazf1(int v, int p) { n   if (v == j2) return j2; n   for (int i = 0; i < e2[v].size(); i++) { n     int u = e2[v][i]; n     if (u != p) { n       int x = hazf1(u, v); n       if (x != -1) return u; n     } n   } n   return -1; n } n int dfs4(int v, int p) { n   int mx1 = 0, mx2 = 0; n   for (int i = 0; i < e[v].size(); i++) { n     int u = e[v][i]; n     if (u != p) { n       int mx3 = dfs4(u, v); n       if (mx3 > mx2) mx2 = mx3; n       if (mx2 > mx1) swap(mx2, mx1); n     } n   } n   barg[v] = mx2 + mx1; n   return barg[v] + 1; n } n void dfs3(int v, int p, int t) { n   dis2[v] = t; n   for (int i = 0; i < e2[v].size(); i++) { n     int u = e2[v][i]; n     if (u != p) dfs3(u, v, t + 1); n   } n   return; n } n void dfs2(int v, int p, int t) { n   dis[v] = t; n   for (int i = 0; i < e2[v].size(); i++) { n     int u = e2[v][i]; n     if (u != p) dfs2(u, v, t + 1); n   } n   return; n } n bool dfs(int v, int p) { n   bool f = true; n   if (e[v].size() > 2) f = false; n   for (int i = 0; i < e[v].size(); i++) { n     int u = e[v][i]; n     if (u != p) n       if (dfs(u, v) == false) { n         f = false; n         e2[v].push_back(u); n         e2[u].push_back(v); n       } n   } n   return f; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) f1[i] = false, f2[i] = false; n   for (int i = 0; i < n - 1; i++) { n     int v, u; n     cin >> v >> u; n     v--, u--; n     e[v].push_back(u); n     e[u].push_back(v); n   } n   int v; n   for (int i = 0; i < n; i++) n     if (e[i].size() > 2) { n       v = i; n       break; n     } n   dfs(v, -1); n   for (int i = 0; i < n; i++) n     if (e2[i].size() > 0) { n       v = i; n       break; n     } n   dfs2(v, -1, 0); n   dfs4(v, -1); n   mxdis = dis[v]; n   for (int i = 0; i < n; i++) n     if (e2[i].size() > 0 && dis[i] > mxdis) { n       mxdis = dis[i]; n       v = i; n     } n   for (int i = 0; i < n; i++) n     if (e2[i].size() > 0 && dis[i] == mxdis) v1.push_back({barg[i], i}); n   dfs3(v, -1, 0); n   mxdis2 = dis2[v]; n   for (int i = 0; i < n; i++) n     if (e2[i].size() > 0 && dis2[i] > mxdis2) mxdis2 = dis2[i]; n   for (int i = 0; i < n; i++) n     if (e2[i].size() > 0 && dis2[i] == mxdis2) v2.push_back({barg[i], i}); n   sort(&v1[0], &v1[v1.size()]); n   sort(&v2[0], &v2[v2.size()]); n   reverse(&v1[0], &v1[v1.size()]); n   reverse(&v2[0], &v2[v2.size()]); n   if (v1[0].second == v2[0].second) n     if (v2.size() == 1 || v1[1].first > v2[1].first) n       jj1 = v1[1].second, j2 = v2[0].second; n     else n       jj1 = v1[0].second, j2 = v2[1].second; n   else n     jj1 = v1[0].second, j2 = v2[0].second; n   h1 = hazf1(jj1, -1); n   h2 = hazf2(j2, -1); n   barg1(jj1, -1, 0); n   barg2(j2, -1, 0); n   mxdis = -1; n   for (int i = 0; i < n; i++) n     if (f1[i] == true && dis[i] > mxdis) { n       mxdis = dis[i]; n       v = i; n     } n   f1[v] = false; n   cout << v + 1 <<    ; n   mxdis = -1; n   for (int i = 0; i < n; i++) n     if (f2[i] == true && dis2[i] > mxdis) { n       mxdis = dis2[i]; n       v = i; n     } n   f2[v] = false; n   cout << v + 1 <<   n ; n   mxdis = -1; n   for (int i = 0; i < n; i++) n     if (f1[i] == true && e[i].size() == 1 && dis[i] > mxdis) { n       mxdis = dis[i]; n       v = i; n     } n   cout << v + 1 <<    ; n   mxdis = -1; n   for (int i = 0; i < n; i++) n     if (f2[i] == true && e[i].size() == 1 && dis2[i] > mxdis) { n       mxdis = dis2[i]; n       v = i; n     } n   cout << v + 1 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int a[200005]; n string ans =   ; n int main() { n   ios_base::sync_with_stdio(0); n   ; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   int l = 0, r = n - 1; n   int mini = 0; n   while (l <= r) { n     if (l == r) { n       if (a[l] > mini) { n         ans +=  L ; n       } n       break; n     } n     if (a[l] > mini || a[r] > mini) { n       if (a[l] > mini && a[r] > mini) { n         if (a[l] < a[r]) { n           ans +=  L ; n           mini = a[l]; n           l++; n         } else { n           ans +=  R ; n           mini = a[r]; n           r--; n         } n       } else if (a[l] > mini) { n         ans +=  L ; n         mini = a[l]; n         l++; n       } else { n         ans +=  R ; n         mini = a[r]; n         r--; n       } n     } else { n       break; n     } n   } n   cout << ans.size() << endl; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n int n, a[100100], m, x, rs = 1e9; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (int i = 1; i <= m; i++) cin >> x, a[x]++; n   for (int i = 1; i <= n; i++) rs = min(rs, a[i]); n   cout << rs; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> a, b; n int x[50]; n int main() { n   int n, l; n   scanf( %d%d , &n, &l); n   for (int i = 0; i < (int)n; ++i) scanf( %d , x + i); n   for (int i = 1; i < (int)n; ++i) a.push_back(x[i] - x[i - 1]); n   a.push_back(x[0] + l - x[n - 1]); n   for (int i = 0; i < (int)n; ++i) scanf( %d , x + i); n   for (int i = 1; i < (int)n; ++i) b.push_back(x[i] - x[i - 1]); n   b.push_back(x[0] + l - x[n - 1]); n   for (int i = 0; i < (int)n; ++i) n     if (a == b) n       printf( YES n ), exit(0); n     else { n       int t = a[0]; n       for (int j = 1; j < (int)n; ++j) a[j - 1] = a[j]; n       a[n - 1] = t; n     } n   printf( NO n ); n } n


#include <bits/stdc++.h> n using namespace std; n complex<double> r() { n   double a, b; n   cin >> a >> b; n   return {a, b}; n } n double cross(complex<double> a, complex<double> b) { n   return (conj(a) * b).imag(); n } n double orient(complex<double> a, complex<double> b, complex<double> c) { n   return cross(b - a, c - a); n } n void up(vector<complex<double> > &st, complex<double> p) { n   while ((long long)(st).size() >= 2 && orient(st.end()[-2], st.back(), p) >= 0) n     st.pop_back(); n   st.push_back(p); n } n struct line { n   complex<double> d; n   double c; n   line(complex<double> a, complex<double> b) : d(b - a), c(cross(d, a)) {} n }; n complex<double> inter(line l1, line l2) { n   return (l1.c * l2.d - l2.c * l1.d) / cross(l1.d, l2.d); n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   long long n; n   complex<double> obj; n   cin >> n; n   obj = r(); n   vector<complex<double> > ps(n); n   double mx = 0, my = 0; n   for (long long i = 0; i < (n); i++) { n     ps[i] = r(); n     mx = max(mx, (ps[i].real())); n     my = max(my, (ps[i].imag())); n   } n   ps.push_back({0.0, my}); n   sort(ps.begin(), ps.end(), [](complex<double> a, complex<double> b) { n     return make_tuple(a.real(), -a.imag()) < make_tuple(b.real(), -b.imag()); n   }); n   vector<complex<double> > hull; n   for (complex<double> p : ps) up(hull, p); n   hull.push_back({mx, 0.0}); n   long long i = upper_bound(hull.begin(), hull.end(), obj, n                             [](complex<double> a, complex<double> b) { n                               return cross(a, b) < 0; n                             }) - n                 hull.begin() - 1; n   complex<double> a = inter(line(0, obj), line(hull[i], hull[i + 1])); n   cout << fixed << setprecision(8) << obj.real() / a.real() <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 110; n const int dx[4] = {0, 0, 1, -1}; n const int dy[4] = {1, -1, 0, 0}; n int n, m, ret; n char G[maxn][maxn]; n bool ok(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; } n void dfs(int x, int y) { n   if (G[x][y] ==  . ) return; n   G[x][y] =  . ; n   for (int i = 0; i < (4); i++) { n     int tx = x + dx[i]; n     int ty = y + dy[i]; n     if (ok(tx, ty) && G[tx][ty] ==  B ) { n       dfs(tx, ty); n     } n   } n } n signed main() { n   while (~scanf( %d , &n) && ~scanf( %d , &m)) { n     memset((G), 0, sizeof(G)); n     ret = 0; n     for (int i = 0; i < (n); i++) scanf( %s , G[i]); n     for (int i = 0; i < (n); i++) { n       for (int j = 0; j < (m); j++) { n         if (G[i][j] ==  B ) { n           dfs(i, j); n           ret++; n         } n       } n     } n     printf( %d n , ret); n   } n   return 0; n } n


#include <bits/stdc++.h> n const int MOD = int(1E9) + 7; n const int MAXN = 100000; n int pw[MAXN + 5], cnt[MAXN + 5]; n void init() { n   pw[0] = 1; n   for (int i = 1; i <= MAXN; i++) pw[i] = 2LL * pw[i - 1] % MOD; n } n int main() { n   init(); n   int n, x; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &x); n     if (x != -1) cnt[x]++; n   } n   int ans = pw[n - 1] - 1; n   for (int i = 1; i <= n; i++) ans = (ans - 1LL * (pw[cnt[i]] - 1) % MOD) % MOD; n   printf( %d n , (ans + MOD) % MOD); n } n


#include <bits/stdc++.h> n using namespace std; n void fre() { n   freopen( c://test//input.in ,  r , stdin); n   freopen( c://test//output.out ,  w , stdout); n } n template <class T1, class T2> n inline void gmax(T1 &a, T2 b) { n   if (b > a) a = b; n } n template <class T1, class T2> n inline void gmin(T1 &a, T2 b) { n   if (b < a) a = b; n } n const int N = 5005, M = 0, Z = 1e9 + 7; n const int inf = 0x3f3f3f3f; n template <class T1, class T2> n inline void gadd(T1 &a, T2 b) { n   a = (a + b) % Z; n } n int casenum, casei; n int n, m; n int f[N][N]; n int d[N][N]; n int v[N]; n int c[N]; n vector<int> a[N]; n int sz[N]; n void dfs(int x) { n   f[x][0] = d[x][0] = sz[x] = 0; n   for (auto y : a[x]) { n     dfs(y); n     for (int i = sz[x]; ~i; --i) { n       for (int j = 1; j <= sz[y]; ++j) { n         gmin(f[x][i + j], f[x][i] + f[y][j]); n         gmin(f[x][i + j], f[x][i] + d[y][j]); n         gmin(d[x][i + j], d[x][i] + d[y][j]); n       } n     } n     sz[x] += sz[y]; n   } n   ++sz[x]; n   for (int i = sz[x]; i; --i) { n     f[x][i] = min(f[x][i - 1] + v[x] - c[x], inf); n     gmin(d[x][i], d[x][i - 1] + v[x]); n   } n } n int main() { n   while (~scanf( %d%d , &n, &m)) { n     memset(f, 63, sizeof(f)); n     memset(d, 63, sizeof(d)); n     for (int i = 1; i <= n; ++i) { n       a[i].clear(); n       scanf( %d%d , &v[i], &c[i]); n       if (i > 1) { n         int fa; n         scanf( %d , &fa); n         a[fa].push_back(i); n       } n     } n     dfs(1); n     int ans = 0; n     for (int i = 1; i <= n; ++i) { n       if (f[1][i] <= m || d[1][i] <= m) { n         gmax(ans, i); n       } n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000003; n const int maxn = 500010; n int n, m; n char str[maxn]; n struct node { n   int lr, ud; n } ma[maxn]; n inline char s(int i, int j) { return str[(i - 1) * m + (j - 1)]; } n int tran(int i, int j) { return (i - 1) * m + (j - 1); } n int solve() { n   int ret = 1; n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       int ind = tran(i, j); n       char cha = s(i, j); n       if (cha >=  1  && cha <=  4 ) { n         if (cha ==  1 ) { n           if (ma[ind].lr != 0 && ma[ind].lr != 1) return -1; n           if (ma[ind].ud != 0 && ma[ind].ud != 1) return -1; n           ma[ind].lr = 1; n           ma[ind].ud = 1; n           for (int k = i - 1; k >= 1; --k) { n             int tp = tran(k, j); n             if (ma[tp].ud == 0) n               ma[tp].ud = ((i - k) % 2 ? 2 : 1); n             else { n               if (ma[tp].ud != ((i - k) % 2 ? 2 : 1)) n                 return -1; n               else n                 break; n             } n           } n           for (int k = i + 1; k <= n; ++k) { n             int tp = tran(k, j); n             if (ma[tp].ud == 0) n               ma[tp].ud = ((k - i) % 2 ? 2 : 1); n             else { n               if (ma[tp].ud != ((k - i) % 2 ? 2 : 1)) n                 return -1; n               else n                 break; n             } n           } n           for (int k = j - 1; k >= 1; --k) { n             int tp = tran(i, k); n             if (ma[tp].lr == 0) n               ma[tp].lr = ((j - k) % 2 ? 2 : 1); n             else { n               if (ma[tp].lr != ((j - k) % 2 ? 2 : 1)) n                 return -1; n               else n                 break; n             } n           } n           for (int k = j + 1; k <= m; ++k) { n             int tp = tran(i, k); n             if (ma[tp].lr == 0) n               ma[tp].lr = ((k - j) % 2 ? 2 : 1); n             else { n               if (ma[tp].lr != ((k - j) % 2 ? 2 : 1)) n                 return -1; n               else n                 break; n             } n           } n         } else if (cha ==  2 ) { n           if (ma[ind].lr != 0 && ma[ind].lr != 1) return -1; n           if (ma[ind].ud != 0 && ma[ind].ud != 2) return -1; n           ma[ind].lr = 1; n           ma[ind].ud = 2; n           for (int k = i - 1; k >= 1; --k) { n             int tp = tran(k, j); n             if (ma[tp].ud == 0) n               ma[tp].ud = ((i - k) % 2 ? 1 : 2); n             else { n               if (ma[tp].ud != ((i - k) % 2 ? 1 : 2)) n                 return -1; n               else n                 break; n             } n           } n           for (int k = i + 1; k <= n; ++k) { n             int tp = tran(k, j); n             if (ma[tp].ud == 0) n               ma[tp].ud = ((k - i) % 2 ? 1 : 2); n             else { n               if (ma[tp].ud != ((k - i) % 2 ? 1 : 2)) n                 return -1; n               else n                 break; n             } n           } n           for (int k = j - 1; k >= 1; --k) { n             int tp = tran(i, k); n             if (ma[tp].lr == 0) n               ma[tp].lr = ((j - k) % 2 ? 2 : 1); n             else { n               if (ma[tp].lr != ((j - k) % 2 ? 2 : 1)) n                 return -1; n               else n                 break; n             } n           } n           for (int k = j + 1; k <= m; ++k) { n             int tp = tran(i, k); n             if (ma[tp].lr == 0) n               ma[tp].lr = ((k - j) % 2 ? 2 : 1); n             else { n               if (ma[tp].lr != ((k - j) % 2 ? 2 : 1)) n                 return -1; n               else n                 break; n             } n           } n         } else if (cha ==  3 ) { n           if (ma[ind].lr != 0 && ma[ind].lr != 2) return -1; n           if (ma[ind].ud != 0 && ma[ind].ud != 2) return -1; n           ma[ind].lr = 2; n           ma[ind].ud = 2; n           for (int k = i - 1; k >= 1; --k) { n             int tp = tran(k, j); n             if (ma[tp].ud == 0) n               ma[tp].ud = ((i - k) % 2 ? 1 : 2); n             else { n               if (ma[tp].ud != ((i - k) % 2 ? 1 : 2)) n                 return -1; n               else n                 break; n             } n           } n           for (int k = i + 1; k <= n; ++k) { n             int tp = tran(k, j); n             if (ma[tp].ud == 0) n               ma[tp].ud = ((k - i) % 2 ? 1 : 2); n             else { n               if (ma[tp].ud != ((k - i) % 2 ? 1 : 2)) n                 return -1; n               else n                 break; n             } n           } n           for (int k = j - 1; k >= 1; --k) { n             int tp = tran(i, k); n             if (ma[tp].lr == 0) n               ma[tp].lr = ((j - k) % 2 ? 1 : 2); n             else { n               if (ma[tp].lr != ((j - k) % 2 ? 1 : 2)) n                 return -1; n               else n                 break; n             } n           } n           for (int k = j + 1; k <= m; ++k) { n             int tp = tran(i, k); n             if (ma[tp].lr == 0) n               ma[tp].lr = ((k - j) % 2 ? 1 : 2); n             else { n               if (ma[tp].lr != ((k - j) % 2 ? 1 : 2)) n                 return -1; n               else n                 break; n             } n           } n         } else { n           if (ma[ind].lr != 0 && ma[ind].lr != 2) return -1; n           if (ma[ind].ud != 0 && ma[ind].ud != 1) return -1; n           ma[ind].lr = 2; n           ma[ind].ud = 1; n           for (int k = i - 1; k >= 1; --k) { n             int tp = tran(k, j); n             if (ma[tp].ud == 0) n               ma[tp].ud = ((i - k) % 2 ? 2 : 1); n             else { n               if (ma[tp].ud != ((i - k) % 2 ? 2 : 1)) n                 return -1; n               else n                 break; n             } n           } n           for (int k = i + 1; k <= n; ++k) { n             int tp = tran(k, j); n             if (ma[tp].ud == 0) n               ma[tp].ud = ((k - i) % 2 ? 2 : 1); n             else { n               if (ma[tp].ud != ((k - i) % 2 ? 2 : 1)) n                 return -1; n               else n                 break; n             } n           } n           for (int k = j - 1; k >= 1; --k) { n             int tp = tran(i, k); n             if (ma[tp].lr == 0) n               ma[tp].lr = ((j - k) % 2 ? 1 : 2); n             else { n               if (ma[tp].lr != ((j - k) % 2 ? 1 : 2)) n                 return -1; n               else n                 break; n             } n           } n           for (int k = j + 1; k <= m; ++k) { n             int tp = tran(i, k); n             if (ma[tp].lr == 0) n               ma[tp].lr = ((k - j) % 2 ? 1 : 2); n             else { n               if (ma[tp].lr != ((k - j) % 2 ? 1 : 2)) n                 return -1; n               else n                 break; n             } n           } n         } n       } n     } n   } n   map<int, bool> row, col; n   map<int, bool>::iterator it; n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       int ind = tran(i, j); n       if (!ma[ind].lr) row[i] = 1; n       if (!ma[ind].ud) col[j] = 1; n     } n   } n   for (int i = 1; i <= row.size(); ++i) ret = ret * 2 % mod; n   for (int i = 1; i <= col.size(); ++i) ret = ret * 2 % mod; n   return ret; n } n int main() { n   while (~scanf( %d%d , &n, &m)) { n     int ans = 0; n     memset(ma, 0, sizeof(ma)); n     for (int i = 1; i <= n; ++i) scanf( %s , str + (i - 1) * m); n     int ret = solve(); n     if (ret == -1) n       puts( 0 ); n     else n       printf( %d n , ret); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   long long k, x; n   cin >> t; n   while (t--) { n     cin >> k >> x; n     cout << x + ((k - 1) * 9) << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, t, i, j, a[300006], q; n int main() { n   scanf( %lld , &t); n   while (t--) { n     long long ans = 0; n     memset(a, 0, sizeof a); n     scanf( %lld%lld , &n, &q); n     for (i = 1; i <= n; i++) { n       scanf( %lld , &a[i]); n     } n     long long flag = 0; n     for (i = 1; i <= n; i++) { n       if (a[i] > a[i - 1] && a[i] > a[i + 1] && flag == 0) { n         ans += a[i]; n         flag = 1; n       } else if (a[i] < a[i - 1] && a[i] < a[i + 1] && flag == 1) { n         ans -= a[i]; n         flag = 0; n       } n     } n     printf( %lld n , ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, k1, k2; n     cin >> n >> k1 >> k2; n     bool ya = 0; n     while (k1--) { n       int a; n       cin >> a; n       if (a == n) { n         ya = 1; n       } n     } n     while (k2--) { n       int a; n       cin >> a; n     } n     if (ya) { n       cout <<  YES  << endl; n     } else { n       cout <<  NO  << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2010; n vector<int> edges[MAXN]; n queue<int> q; n int visited[MAXN]; n int main() { n   int n, m, a, b; n   char x; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> x; n       if (x ==  # ) { n         edges[i].push_back(n + j); n         edges[n + j].push_back(i); n       } n     } n   } n   q.push(n - 1); n   q.push(0); n   while (!q.empty()) { n     a = q.front(); n     q.pop(); n     b = q.front(); n     q.pop(); n     if (a == 0) { n       cout << b; n       return 0; n     } n     for (int i : edges[a]) { n       if (!visited[i]) { n         q.push(i); n         q.push(b + 1); n         visited[i] = true; n       } n     } n   } n   cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 5; n int n, q; n int a[maxn], b[maxn], f[maxn], g[maxn][30]; n int c(int l, int r) { n   int k = (int)log2(r - l + 1); n   return max(g[l][k], g[r - (1 << k) + 1][k]); n } n void solve() { n   cin >> n; n   for (int i = 1; i <= n; ++i) cin >> a[i]; n   cin >> q; n   for (int i = 1; i <= q; ++i) { n     int id, p, first; n     cin >> id; n     if (id == 1) { n       cin >> p >> first; n       a[p] = first; n       b[p] = i; n     } else n       cin >> f[i]; n   } n   for (int i = 1; i <= q; ++i) g[i][0] = f[i]; n   int m = (int)log2(q) + 1; n   for (int j = 1; j <= m; ++j) n     for (int i = 1; i + (1 << (j - 1)) - 1 <= q; ++i) n       g[i][j] = max(g[i][j - 1], g[i + (1 << (j - 1))][j - 1]); n   for (int i = 1; i <= n; ++i) cout << max(a[i], c(max(1, b[i]), q)) <<    ; n } n int main() { solve(); } n


#include <bits/stdc++.h> n using namespace std; n string itos(int a) { n   if (!a) return  0 ; n   string res; n   while (a) { n     res += (char)( 0  + (a % 10)); n     a /= 10; n   } n   reverse((res).begin(), (res).end()); n   return res; n } n int main() { n   int n; n   int a[10], can = 0; n   ; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     can |= 1 << a[i]; n   } n   if (n > 6) { n     cout <<  0  << endl; n     return 0; n   } n   vector<string> v; n   vector<int> mask; n   for (int i = 0; i < 256; i++) { n     string s = itos(i); n     int tmp = 0; n     for (int j = 0; j < s.size(); j++) { n       tmp |= 1 << (int)(s[j] -  0 ); n     } n     if ((tmp & can) == tmp) { n       v.push_back(s); n       mask.push_back(tmp); n     } n   } n   vector<string> ans; n   for (int i = 0; i < (int)(v.size()); i++) n     for (int j = 0; j < (int)(v.size()); j++) { n       int size = min(v[i].size(), v[j].size()); n       bool f = true; n       for (int k = 0; k < size; k++) { n         if (v[i][k] != v[j][v[j].size() - 1 - k]) { n           f = false; n           break; n         } n       } n       if (!f) continue; n       for (int k = 0; k < (int)(v.size()); k++) n         for (int l = 0; l < (int)(v.size()); l++) { n           if ((mask[i] | mask[j] | mask[k] | mask[l]) != can) continue; n           string s = v[i] + v[k] + v[l] + v[j]; n           bool f = true; n           for (int x = 0; 2 * x < s.size(); x++) { n             if (s[x] != s[s.size() - 1 - x]) { n               f = false; n               break; n             } n           } n           if (f) ans.push_back(v[i] +  .  + v[k] +  .  + v[l] +  .  + v[j]); n         } n     } n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl; n } n


#include <bits/stdc++.h> n #pragma GCC target( avx2 ) n #pragma GCC optimization( O3 ) n #pragma GCC optimization( unroll-loops ) n using namespace std; n long long fn(long long x, long long rn[]) { n   if (x == rn[x]) n     return x; n   else n     return rn[x] = fn(rn[x], rn); n } n bool un(long long x, long long y, long long rn[], long long sz[]) { n   x = fn(x, rn); n   y = fn(y, rn); n   if (x == y) return false; n   if (sz[x] < sz[y]) swap(x, y); n   sz[x] += sz[y]; n   rn[y] = x; n   return true; n } n long long gcd(long long a, long long b) { n   if (!b) return a; n   return gcd(b, a % b); n } n long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } n long long MOD = 998244353; n long long mod = 1000000007; n long long power(long long x, long long y, long long p) { n   long long res = 1; n   x %= p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long inv(long long val, long long MODx = MOD) { n   return power(val, MODx - 2, MODx); n } n vector<long long> fac, ifac; n void preFac(long long sz) { n   fac.resize(sz + 1), ifac.resize(sz + 1); n   fac[0] = 1; n   for (int i = 1; i <= sz; i++) { n     fac[i] = (i * fac[i - 1]) % MOD; n   } n   ifac[sz] = inv(fac[sz]); n   for (int i = sz - 1; i >= 0; i--) { n     ifac[i] = ((i + 1) * ifac[i + 1]) % MOD; n   } n } n long long nCr(long long N, long long R) { n   if (R <= N and R >= 0) { n     return ((fac[N] * ifac[R]) % MOD * ifac[N - R]) % MOD; n   } n   return 0; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, k; n   cin >> n >> k; n   map<long long, long long> pos; n   long long p[n + 1], q[n + 1]; n   for (long long i = 1; i <= n; i++) { n     cin >> p[i]; n   } n   for (long long i = 1; i <= n; i++) { n     cin >> q[i]; n     pos[q[i]] = i; n   } n   long long pt = 1; n   long long pt_cons = 1; n   vector<vector<long long>> comp; n   vector<long long> vec; n   while (pt <= n) { n     vec.push_back(p[pt]); n     pt_cons = max(pt_cons, pos[p[pt]]); n     if (pt == pt_cons) { n       comp.push_back(vec); n       vec.clear(); n       pt_cons = 1; n     } n     pt++; n   } n   if (!vec.empty()) { n     comp.push_back(vec); n   } n   if (comp.size() < k) { n     cout <<  NO ; n     return 0; n   } n   string ans(n + 1,  * ); n   char x =  a ; n   for (auto u : comp) { n     for (auto v : u) { n       ans[v] = x; n     } n     x++; n     if (x == ( z  + 1)) { n       x =  z ; n     } n   } n   cout <<  YES n ; n   for (long long i = 1; i <= n; i++) { n     cout << ans[i]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, s; n int c[3]; n void init() { n   int score; n   scanf( %d%d , &n, &s); n   for (int i = 0; i < n; i++) { n     scanf( %d , &score); n     c[score - 3]++; n   } n } n int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } n void extended_gcd(int a, int b, int c, int &x, int &y) { n   if (!b) { n     x = c / a, y = 0; n     return; n   } n   extended_gcd(b, a % b, c, y, x); n   y -= (a / b) * x; n } n void solve() { n   int k[3], ret = 0x7FFFFFFF; n   int d = gcd(c[1], c[2]); n   for (int i = 0; i <= s; i++) { n     int A = c[1], B = c[2], C = s - i * c[0], x, y; n     if (C < 0) break; n     if (C % d != 0) continue; n     extended_gcd(A, B, C, x, y); n     int delta1 = B / d, delta2 = A / d; n     if (y > x && delta2 != 0) { n       int delta = (y - x) / delta2; n       y -= delta2 * delta; n       x += delta1 * delta; n     } n     for (int step = 17; step >= 0; step--) { n       if (y >= x) break; n       if (y + delta2 * (1 << step) <= x - delta1 * (1 << step)) { n         y += delta2 * (1 << step); n         x -= delta1 * (1 << step); n       } n     } n     if (c[1] * x > c[2] * y) { n       for (int step = 17; step >= 0; step--) n         if (x - delta1 * (1 << step) >= i) { n           if (c[1] * (x - delta1 * (1 << step)) >= n               c[2] * (y + delta2 * (1 << step))) { n             x -= delta1 * (1 << step); n             y += delta2 * (1 << step); n           } n         } n     } n     if (y < i && delta2 != 0) { n       int delta = (i - y - 1) / delta2 + 1; n       y += delta2 * delta; n       x -= delta1 * delta; n     } n     for (int j = 0;; j++) { n       if (x >= i && y >= x && n           abs(c[0] * i - c[1] * x) + abs(c[1] * x - c[2] * y) < ret) { n         ret = abs(c[0] * i - c[1] * x) + abs(c[1] * x - c[2] * y); n         k[0] = i, k[1] = x, k[2] = y; n       } n       if (y >= x && c[2] * y > c[1] * x) { n         break; n       } n       y += delta2; n       x -= delta1; n       if (x < i) break; n     } n   } n   if (ret == 0x7FFFFFFF) { n     printf( %d n , -1); n   } else n     printf( %d %d %d n , k[0], k[1], k[2]); n } n int main() { n   init(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n const int M = 1e9 + 7; n long long a[N]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long a, b, x, y, z; n   cin >> a >> b >> x >> y >> z; n   cout << max(0ll, y - (a - 2 * x)) + max(0ll, y - (b - 3 * z)); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   std::cerr << name <<   :   << arg1 << endl; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   std::cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n const long long MOD = 998244353; n const long long INFLL = 0x3f3f3f3f3f3f3f3f; n const int INF = 0x3f3f3f3f; n const long long MAXN = 1e+5 + 7; n const int m = 998244353; n const int nax = 1e6; n long long fatorial[nax + 1]; n long long binary_pow(long long a, long long b) { n   a = a % m; n   long long ans = 1; n   while (b > 0) { n     if (b & 1) { n       ans = (ans * a) % m; n     } n     a = (a * a) % m; n     b = b >> 1; n   } n   return ans; n } n long long modular_inverse(long long a) { return binary_pow(a, m - 2); } n void calcula_fatorial() { n   fatorial[0] = 1; n   for (int i = 1; i <= nax; i++) { n     fatorial[i] = (fatorial[i - 1] * i) % m; n   } n } n long long binomial_coefficient(int n, int k) { n   return fatorial[n] * modular_inverse(fatorial[k]) % m * n          modular_inverse(fatorial[n - k]) % m; n } n void solve() { n   long long n, k; n   cin >> n >> k; n   set<long long> evento; n   map<long long, long long> entrada, saida; n   for (int i = 0; i < n; ++i) { n     long long a, b; n     cin >> a >> b; n     evento.insert(a); n     evento.insert(b); n     entrada[a]++; n     saida[b]++; n   } n   long long ans = 0, sz = 0; n   for (auto e : evento) { n     sz += entrada[e]; n     for (int i = 0; i < saida[e]; ++i) { n       if (sz - 1 < k - 1) { n         sz--; n         continue; n       } n       ans += binomial_coefficient(sz - 1, k - 1); n       ans %= m; n       sz--; n     } n   } n   cout << ans <<   n ; n } n int main() { n   calcula_fatorial(); n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long i, j, n; n   int t = 1; n   while (t--) solve(); n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n  n #define INF 1234567890 n #define ll long long n  n int T; n int N, M, P; n vector<int> g[400401], h[400401]; n bool vis[400401], reach[400401], loop[400401]; n vector<int> st; n int myscc[400401], sz[400401], dp[400401]; n  n void DFS(int n) n { n  vis[n] = true; n  for(int next : g[n]) n  { n   if (vis[next]) continue; n   DFS(next); n  } n  st.push_back(n); n } n void DFS2(int n) n { n  vis[n] = true; n  for(int next : h[n]) n  { n   if (vis[next]) continue; n   DFS2(next); n  } n  myscc[n] = P; n  sz[P]++; n } n void DFS3(int n) n { n  vis[n] = true; n  for(int next : g[n]) n  { n   if (vis[next]) continue; n   DFS3(next); n  } n } n  n bool isScc(int i) n { n  return (sz[myscc[i]] >= 2 || loop[i]); n } n  n int main() n { n  ios::sync_with_stdio(0); cin.tie(0); n  cin.exceptions(ios::badbit | ios::failbit); n  cin >> T; n  while(T--) n  { n   cin >> N >> M; n   // clear n   P = 0; n   for(int i=1; i<=N; i++) n   { n    g[i].clear(); n    h[i].clear(); n   } n   memset(vis, 0, sizeof(bool)*(N+1)); n   memset(reach, 0, sizeof(bool)*(N+1)); n   memset(loop, 0, sizeof(bool)*(N+1)); n   st.clear(); n  n   for(int i=0; i<M; i++) n   { n    int a, b; n    cin >> a >> b; n    if (a == b) { loop[a] = true; continue; } n    g[a].push_back(b); n    h[b].push_back(a); n   } n  n   DFS(1); n   for(int i=1; i<=N; i++) n    if (vis[i]) n     reach[i] = true; n  n   for(int i=1; i<=N; i++) n    if (!vis[i]) n     DFS(i); n  n   memset(vis, 0, sizeof(bool)*(N+1)); n   reverse(st.begin(), st.end()); // DFS 종료 역순 = 위상정렬순 n   for(int n : st) n   { n    if (vis[n]) continue; n    sz[P] = 0; n    DFS2(n); n    P++; n   } n  n   memset(vis, 0, sizeof(bool)*(N+1)); n   for(int i=1; i<=N; i++) n    if (reach[i] && isScc(i) && !vis[i]) n     DFS3(i); // 1 -> scc -> x가 가능한가? n  n   memset(dp, 0, sizeof(int)*(N+1)); // 0,1,2+ n   dp[1] = 1; n   for(int n : st) n   { n    if (dp[n] > 2) dp[n] = 2; n    for(int next : g[n]) n     dp[next] += dp[n]; n   } n  n   for(int i=1; i<=N; i++) n   { n    if (reach[i] == false) cout <<  0  ; n    else if (vis[i]) cout <<  -1  ; n    else if (dp[i] >= 2) cout <<  2  ; n    else cout <<  1  ; n   } n   cout <<   n ; n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int t; n   cin >> t; n   vector<int> a(7); n   while (t--) { n     long long k; n     cin >> k; n     int sum = 0; n     for (int i = 0; i < 7; i++) { n       cin >> a[i]; n       sum += a[i]; n     } n     long long ans = (k / sum) * 7; n     long long rem = k % sum; n     if (rem == 0) { n       ans -= 7; n       rem = sum; n     } n     int min = 7; n     int count = 0, count_sum = 0; n     for (int i = 0; i < 7; i++) { n       count = 0; n       count_sum = 0; n       for (int j = 0; j < 7; j++) { n         count++; n         if (a[(i + j) % 7]) { n           count_sum++; n         } n         if (count_sum == rem) { n           if (count < min) { n             min = count; n             break; n           } n         } n       } n     } n     cout << ans + min << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int go[2], sum; n   node(int x0, int x1, int _sum) { go[0] = x0, go[1] = x1, sum = _sum; } n }; n node root(-1, -1, 0); n vector<node> t = {root}; n int get_sum(int v) { return v == -1 ? 0 : t[v].sum; } n int go(int v, int id) { n   if (t[v].go[id] == -1) { n     t[v].go[id] = t.size(); n     t.push_back(node(-1, -1, 0)); n   } n   return t[v].go[id]; n } n void add(int a) { n   int v = 0; n   for (int bit = 29; bit >= 0; bit--) { n     int x = (a >> bit) & 1; n     v = go(v, x); n     t[v].sum++; n   } n } n int get(int a, int k) { n   int v = 0, ans = 0, bit = 29; n   while (bit >= 0) { n     int x = (a >> bit) & 1, y = (k >> bit) & 1; n     if (x > y) ans += get_sum(t[v].go[0]); n     if ((x ^ 1) > y) ans += get_sum(t[v].go[1]); n     if (t[v].go[x ^ y] == -1) break; n     v = go(v, x ^ y); n     bit--; n   } n   if (bit == -1) ans += t[v].sum; n   return ans; n } n void solve() { n   int n, k; n   cin >> n >> k; n   add(0); n   long long pref = 0, ans = 0; n   for (int i = 1; i <= n; i++) { n     int v; n     cin >> v; n     pref = pref ^ v; n     ans += get(pref, k); n     add(pref); n   } n   cout << ans <<   n ; n } n int main() { n   ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0); n   cout.setf(ios::fixed), cout.precision(20); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1000000009; n long long A[200000]; n long long root(long long a) { n   long long i = a; n   if (A[i] != i) { n     A[i] = root(A[i]); n   } n   return A[a]; n } n void unio(long long a, long long b) { n   long long ra = root(a); n   long long rb = root(b); n   if (ra != rb) { n     A[ra] = rb; n   } n } n signed main() { n   long long n, m; n   cin >> n >> m; n   long long val = 1; n   for (long long i = 1; i <= n; i++) { n     A[i] = i; n   } n   for (long long i = 1; i <= m; i++) { n     long long a, b; n     cin >> a >> b; n     if (root(a) == root(b)) { n       val = (val * 2LL) % mod; n     } else { n       unio(a, b); n     } n     val--; n     val = (val + mod) % mod; n     cout << val << endl; n     val++; n   } n } n


#include <bits/stdc++.h> n const int maxn = 200005, K = 37, mod = 1e9 + 7; n int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; } n int dec(int a, int b) { return a - b < 0 ? a - b + mod : a - b; } n int mul(int a, int b) { return 1ll * a * b % mod; } n int ksm(int a, int b = mod - 2) { n   int ret = 1; n   for (; b; b >>= 1, a = mul(a, a)) n     if (b & 1) ret = mul(ret, a); n   return ret; n } n int n, a[maxn]; n std::tuple<int, int, int> p[maxn]; n int f[maxn], c[maxn], mx, ans; n void ins(int x, int v) { n   for (; x <= mx; x += x & -x) c[x] = std::max(c[x], v); n } n int ask(int x) { n   int res = 0xcfcfcfcf; n   for (; x; x -= x & -x) res = std::max(res, c[x]); n   return res; n } n int main() { n   memset(c, 0xcf, sizeof(c)); n   memset(f, 0xcf, sizeof(f)); n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) n     scanf( %d , a + i), p[i] = std::make_tuple(i - a[i], a[i], i), n                         mx = std::max(mx, a[i]); n   mx++; n   std::sort(p + 1, p + 1 + n); n   ins(1, 0); n   for (int i = 1; i <= n; i++) { n     if (std::get<2>(p[i]) >= std::get<1>(p[i])) n       f[i] = ask(std::get<1>(p[i])) + 1; n     ins(std::get<1>(p[i]) + 1, f[i]); n     ans = std::max(ans, f[i]); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = (1 << 30) - 1; n const long long lINF = (1LL << 62) - 1; n const double dINF = 1e40; n const int MAXT = 1 << 22, MAXN = 1001000; n struct seg_tree { n   int sum[MAXT], len; n   void build(int n) { n     for (len = 1; len < n; len <<= 1) n       ; n   } n   template <int val> n   void update(int pos) { n     for (int x = pos + len; x > 0; x >>= 1) sum[x] += val; n   } n   int find(int k) { n     int x; n     for (x = 1; x < len;) { n       x <<= 1; n       if (sum[x] < k) { n         k -= sum[x]; n         x ^= 1; n       } n     } n     return x - len; n   } n } ds; n int pos[MAXT], val[MAXN]; n bool app[MAXN]; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   ds.build(n + m); n   for (int i = 0; i < n; i++) { n     pos[m + i] = i; n     ds.update<1>(m + i); n   } n   memset(val, -1, sizeof(val)); n   bool flag = true; n   for (int i = m - 1; i >= 0; i--) { n     int k, mark; n     scanf( %d%d , &mark, &k); n     int p = ds.find(k), op = pos[p]; n     ds.update<-1>(p); n     pos[i] = op; n     ds.update<1>(i); n     if (val[op] == -1) n       val[op] = mark; n     else if (val[op] != mark) { n       flag = false; n       break; n     } n   } n   memset(app, false, sizeof(app)); n   for (int i = 0; i < n; i++) n     if (val[i] != -1) { n       if (app[val[i]]) { n         flag = false; n         break; n       } n       app[val[i]] = true; n     } n   if (flag) { n     for (int i = 0, v = 1; i < n; i++) { n       if (val[i] == -1) { n         for (; app[v]; ++v) n           ; n         app[v] = true; n         val[i] = v; n       } n       if (i == n - 1) n         printf( %d n , val[i]); n       else n         printf( %d  , val[i]); n     } n   } else n     puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = (long long)-1e18; n const int N = 200 * 1000 + 100; n vector<int> g[N]; n vector<int> w[N]; n vector<pair<long long, long long> > cur; n long long add[N]; n long long ans[N]; n int a[N]; n long long dfs2(int v) { n   ans[v] = add[v]; n   for (int i = 0; i < g[v].size(); i++) ans[v] += dfs2(g[v][i]); n   return ans[v]; n } n void dfs(int v, int par, long long h) { n   if (v != par) { n     long long dist = h - a[v]; n     vector<pair<long long, long long> >::iterator it = lower_bound( n         cur.begin(), cur.end(), pair<long long, long long>(dist, INF)); n     add[par]++; n     if (it != cur.begin()) { n       it--; n       add[it->second]--; n     } n   } n   cur.push_back(pair<long long, long long>(h, v)); n   for (int i = 0; i < g[v].size(); i++) dfs(g[v][i], v, h + w[v][i]); n   cur.pop_back(); n } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (int i = 1; i < n; i++) { n     int p, l; n     cin >> p >> l; n     p--; n     g[p].push_back(i); n     w[p].push_back(l); n   } n   dfs(0, 0, 0); n   dfs2(0); n   for (long long i = 0; i < n; i++) cout << ans[i] <<    ; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n std::mt19937 rnd( n     (int)std::chrono::steady_clock::now().time_since_epoch().count()); n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n const int NDIG = 6; n const int MAXQ = 100000; n const int MAXSUM = 999999; n int nvals; n int gain[NDIG]; n int nq; n int q[MAXQ]; n long long qans[MAXQ]; n long long dp[NDIG + 1][MAXSUM + 1]; n long long tmp[MAXSUM + 1]; n pair<long long, int> qq[MAXSUM + 1]; n int qhead, qtail; n void solve() { n   for (int ndig = (0); ndig <= (NDIG); ++ndig) n     for (int sum = (0); sum <= (MAXSUM); ++sum) n       dp[ndig][sum] = ndig == 0 && sum == 0 ? 0 : LLONG_MIN; n   for (int ndig = (1); ndig <= (NDIG); ++ndig) { n     int curgain = gain[NDIG - ndig]; n     long long vargain = (long long)10 * curgain; n     for (int sum = (0); sum <= (MAXSUM); ++sum) n       tmp[sum] = dp[ndig - 1][sum] == LLONG_MIN n                      ? LLONG_MIN n                      : dp[ndig - 1][sum] - (sum / 3) * vargain; n     for (int mod = (0); mod < (30); ++mod) n       if (mod <= 9 * nvals) { n         long long fixedgain = (long long)(mod / 3) * curgain; n         qhead = qtail = 0; n         for (int sum = mod; sum <= MAXSUM; sum += 10) { n           int fst = (sum - mod) / 10; n           int qmx = min((sum - mod) / 30, (9 * nvals - mod) / 30); n           long long now = tmp[fst]; n           while (qtail < qhead && now >= qq[qhead - 1].first) --qhead; n           qq[qhead++] = make_pair(now, fst); n           while (qtail < qhead && qq[qtail].second < fst - (qmx - 10)) ++qtail; n           long long best = qtail < qhead ? qq[qtail].first : LLONG_MIN; n           if (best != LLONG_MIN) { n             dp[ndig][sum] = n                 max(dp[ndig][sum], best + fixedgain + (fst / 3) * vargain); n           } n           for (int q = (max(0, qmx - 10)); q <= (qmx); ++q) { n             long long opt = dp[ndig - 1][fst - 3 * q]; n             if (opt == LLONG_MIN) continue; n             int nthree = mod / 3 + 10 * q; n             opt += fixedgain + q * vargain; n             if (nthree >= 3 * (nvals - 1) && mod % 3 != 0) n               opt -= (long long)(nthree - 3 * (nvals - 1)) * curgain; n             dp[ndig][sum] = max(dp[ndig][sum], opt); n           } n         } n       } n   } n   for (int i = (0); i < (nq); ++i) qans[i] = dp[NDIG][q[i]]; n } n void run() { n   scanf( %d , &nvals); n   for (int i = (0); i < (NDIG); ++i) scanf( %d , &gain[i]); n   scanf( %d , &nq); n   for (int i = (0); i < (nq); ++i) scanf( %d , &q[i]); n   solve(); n   for (int i = (0); i < (nq); ++i) printf( %lld n , qans[i]); n } n long long qansstupid[MAXQ]; n void solvestupid() { n   auto calc = [&](int x) { n     long long ret = 0; n     for (int i = 0; x > 0; ++i, x /= 10) n       if (x % 10 % 3 == 0) ret += (long long)(x % 10 / 3) * gain[i]; n     return ret; n   }; n   for (int i = (0); i < (nq); ++i) { n     int sum = q[i]; n     qansstupid[i] = LLONG_MIN; n     if (nvals == 4) { n       for (int a = (0); a <= (sum); ++a) n         for (int b = (0); b <= (sum - a); ++b) n           for (int c = (0); c <= (sum - a - b); ++c) { n             int d = sum - a - b - c; n             long long cur = calc(a) + calc(b) + calc(c) + calc(d); n             qansstupid[i] = max(qansstupid[i], cur); n           } n     } else if (nvals == 3) { n       for (int a = (0); a <= (sum); ++a) n         for (int b = (0); b <= (sum - a); ++b) { n           int c = sum - a - b; n           long long cur = calc(a) + calc(b) + calc(c); n           qansstupid[i] = max(qansstupid[i], cur); n         } n     } else if (nvals == 2) { n       for (int a = (0); a <= (sum); ++a) { n         int b = sum - a; n         long long cur = calc(a) + calc(b); n         qansstupid[i] = max(qansstupid[i], cur); n       } n     } else if (nvals == 1) { n       int a = sum; n       long long cur = calc(a); n       qansstupid[i] = max(qansstupid[i], cur); n     } else { n       assert(false); n     } n   } n } n void stress() { n   for (int rep = (0); rep < (1000); ++rep) { n     nvals = rnd() % 4 + 1; n     int sum = rnd() % (nvals == 4 ? 100 : 10000) + 1; n     for (int i = (0); i < (NDIG); ++i) gain[i] = rnd() % 1000 + 1; n     nq = 1, q[0] = sum; n     solve(); n     solvestupid(); n     bool ok = true; n     for (int i = (0); i < (nq); ++i) n       if (qans[i] != qansstupid[i]) ok = false; n     if (ok) { n       printf( . ); n       continue; n     } n     printf( err have=%lld want=%lld n , qans[0], qansstupid[0]); n     printf( %d n , nvals); n     for (int i = (0); i < (NDIG); ++i) { n       if (i != 0) printf(   ); n       printf( %d , gain[i]); n     } n     puts(  ); n     printf( %d n , nq); n     for (int i = (0); i < (nq); ++i) printf( %d n , q[i]); n   } n } n int main() { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool isprime(int a) { n   for (int i = 2; i * i <= a; i++) { n     if (a % i == 0) return false; n   } n   return true; n } n bool v[10010]; n int gcd(int a, int b) { n   if (a % b == 0) return b; n   return gcd(b, a % b); n } n int main() { n   int T; n   cin >> T; n   for (int i = 2; i < 10010; i++) { n     v[i] = isprime(i); n   } n   while (T--) { n     int a; n     int b; n     cin >> a >> b; n     if (a == 1 || b == 1) { n       cout <<  Finite  << endl; n       continue; n     } n     if (gcd(a, b) == 1) { n       cout <<  Finite  << endl; n       continue; n     } else { n       cout <<  Infinite  << endl; n       continue; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n const long long mod = 1000000007; n const long long Inf = 2 * 1e9; n using namespace std; n long long toint(string s) { n   long long anss = 0; n   for (int(i) = 0; (i) < s.length(); (i)++) anss = anss * 10 + (s[i] -  0 ); n   return anss; n } n long long gcd(long long a, long long b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n vector<bool> used(200001, false); n vector<int> g(200001); n void dfs(int v) { n   used[v] = true; n   if (!used[g[v]]) dfs(g[v]); n } n int main() { n   int n; n   cin >> n; n   vector<int> t(n + 1), ch(n + 1); n   for (int(i) = 1; (i) < n + 1; (i)++) { n     scanf( %d , &t[i]); n     if (i > 1) t[i] -= t[1]; n   } n   t[1] = 0; n   ch[0] = 0; n   for (int(i) = 1; (i) < n + 1; (i)++) { n     int ans = 20; n     ch[i] = ch[i - 1]; n     int pos = n         lower_bound((t).begin(), (t).end(), max(0, t[i] - 89)) - t.begin(); n     int sum = ch[i] - ch[max(0, pos - 1)]; n     ans = min({ans, 50 - sum}); n     pos = lower_bound((t).begin(), (t).end(), max(0, t[i] - 1439)) - t.begin(); n     sum = ch[i] - ch[max(0, pos - 1)]; n     ans = min({ans, 120 - sum}); n     ch[i] += ans; n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void input() {} n int main() { n   input(); n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   if (n % 2 == 0) n     cout << -1 <<   n ; n   else { n     for (int i = 0; i < n; i++) cout << i <<    ; n     cout <<   n ; n     for (int i = 0; i < n; i++) cout << i <<    ; n     cout <<   n ; n     for (int i = 0; i < n; i++) cout << (2 * i) % n <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int i, j, k, n, m, l; n const int N = 1e5 + 8; n int vis[N]; n vector<int> adj[N]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n; n   for (i = 1; i < n; i++) { n     int u, v; n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   queue<int> q; n   q.push(1); n   memset(vis, 0, sizeof(vis)); n   vis[1] = 1; n   l = 0; n   long long ev = 0, od = 0; n   while (1) { n     int c = q.size(); n     if (!c) break; n     while (c) { n       int s = q.front(); n       q.pop(); n       c--; n       if (l & 1) n         ev++; n       else n         od++; n       for (auto u : adj[s]) { n         if (!vis[u]) { n           vis[u] = 1; n           q.push(u); n         } n       } n     } n     l++; n   } n   cout << (ev * od - (n - 1)) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double r[1000]; n double p = atan(1.) * 4.; n int main() { n   double rez = 0; n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> r[i]; n   sort(r, r + n); n   bool t = true; n   for (int i = n - 1; i >= 0; i--) { n     if (t) n       rez += r[i] * r[i] * p; n     else n       rez -= r[i] * r[i] * p; n     t = !t; n   } n   printf( %.6f , rez); n   cin >> n; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   getline(cin, s); n   int i = s.size() - 1; n   while (s[i] ==  ? ) { n     i--; n   } n   while (s[i] == 32) { n     i--; n   } n   if (s[i] ==  y  || s[i] ==  u  || s[i] ==  o  || s[i] ==  i  || s[i] ==  e  || n       s[i] ==  a ) { n     cout <<  YES ; n     return 0; n   } n   if (s[i] ==  Y  || s[i] ==  U  || s[i] ==  O  || s[i] ==  I  || s[i] ==  E  || n       s[i] ==  A ) { n     cout <<  YES ; n     return 0; n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n const double eps = 1e-6; n const int INF = 0x3f3f3f3f; n const int MAXN = 1e5 + 10; n int cnt, head[MAXN], tot; n int n, tim, a[MAXN], root[MAXN]; n struct Poi { n   int w, dfn, dep, col; n } poi[MAXN]; n bool cmp(int a, int b) { return poi[a].dep < poi[b].dep; } n struct Edge { n   int v, nex; n } edge[MAXN * 2]; n struct Node { n   int l, r, m; n } node[MAXN * 20]; n void add(int u, int v) { n   edge[cnt] = {v, head[u]}; n   head[u] = cnt++; n } n void dfs(int u, int fa) { n   poi[u].dep = poi[fa].dep + 1; n   poi[u].dfn = ++tim; n   for (int i = head[u]; ~i; i = edge[i].nex) { n     int v = edge[i].v; n     if (v == fa) continue; n     dfs(v, u); n   } n   poi[u].col = tim; n } n void up(int rt) { node[rt].m = min(node[node[rt].l].m, node[node[rt].r].m); } n void update(int &rt, int l, int r, int k, int x) { n   node[++tot] = node[rt]; n   rt = tot; n   if (l == r) { n     node[rt].m = x; n     return; n   } n   int mid = ((l + r) >> 1); n   if (k <= mid) n     update(node[rt].l, l, mid, k, x); n   else n     update(node[rt].r, mid + 1, r, k, x); n   up(rt); n } n int bin(int x) { n   int l = 1, r = n; n   while (l <= r) { n     int mid = ((l + r) >> 1); n     if (poi[a[mid]].dep <= x) n       l = mid + 1; n     else n       r = mid - 1; n   } n   return r; n } n int query(int rt, int l, int r, int L, int R) { n   if (l == L && r == R) return node[rt].m; n   int mid = ((l + r) >> 1); n   if (R <= mid) n     return query(node[rt].l, l, mid, L, R); n   else if (L > mid) n     return query(node[rt].r, mid + 1, r, L, R); n   else { n     int a = query(node[rt].l, l, mid, L, mid); n     int b = query(node[rt].r, mid + 1, r, mid + 1, R); n     return min(a, b); n   } n } n inline int read() { n   int k = 0; n   char f = 1; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -1; n   for (; isdigit(c); c = getchar()) k = k * 10 + c -  0 ; n   return k * f; n } n int main() { n   int s; n   memset(head, -1, sizeof head); n   cin >> n >> s; n   for (int i = 1; i <= n; i++) poi[i].w = read(), a[i] = i; n   for (int i = 1; i < n; i++) { n     int u, v; n     u = read(), v = read(); n     add(u, v); n     add(v, u); n   } n   dfs(s, 0); n   sort(a + 1, a + 1 + n, cmp); n   node[0].m = INF; n   for (int i = 1; i <= n; i++) { n     root[i] = root[i - 1]; n     int idx = a[i]; n     int p = poi[idx].dfn; n     int w = poi[idx].w; n     update(root[i], 1, n, p, w); n   } n   int m; n   cin >> m; n   int ans = 0; n   while (m--) { n     int x, k; n     x = read(), k = read(); n     x = (x + ans) % n + 1; n     k = (k + ans) % n; n     int dep = poi[x].dep + k; n     int l = poi[x].dfn, r = poi[x].col; n     int p = bin(dep); n     ans = query(root[p], 1, n, l, r); n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   for (int row = -n; row <= n; row++) { n     int top = n - abs(row); n     for (int i = 0; i < abs(row); i++) { n       cout <<     ; n     } n     for (int i = 0; i < top; ++i) { n       cout << i <<    ; n     } n     for (int i = top; i > 0; --i) { n       cout << i <<    ; n     } n     cout << 0 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int n, d = 0; n   n = s.size(); n   for (int i = 0; i < n; i++) { n     if (s[i] ==  o ) d++; n   } n   if (d == 0) { n     cout <<  YES ; n     return 0; n   } n   if ((n - d) % d == 0) { n     cout <<  YES ; n     return 0; n   } n   cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 10002; n const int maxm = 15000002; n int f[maxm], p[maxn]; n bool v[maxn]; n int a[maxn]; n int n, m, s; n int main() { n   int i, j; n   for (i = 2; i < 12; i++) { n     if (!v[i]) p[s++] = i; n     for (j = 0; j < s && i * p[j] < 12; j++) { n       v[i * p[j]] = 1; n       if (i % p[j] == 0) break; n     } n   } n   for (i = 2; i < maxm; i++) n     if (!f[i]) n       for (j = i; j < maxm; j += i) f[j] = i; n   scanf( %d , &n); n   m = 1; n   for (j = 0; j < s; ++j) { n     m *= p[j]; n     if (m > n) break; n   } n   --j; n   m = 0; n   for (i = 2; i <= 2 * n * n && i < maxm; ++i) n     if (f[i] <= p[j]) { n       a[m++] = i; n     } n   sort(a, a + m); n   reverse(a, a + m); n   for (i = 0; i < n; ++i) printf( %d  , a[i]); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n int minx, miny, minz, maxx, maxy, maxz, n, m, Q, x, y, z, mx1, mn1, mx2, mn2, n     mx3, mn3, D, cnt; n using namespace std; n struct node { n   int l, r, maxx, maxy, maxz, minx, miny, minz, d[3]; n } t[2000005]; n inline bool cmp(node aa, node bb) { n   if (aa.d[D] == bb.d[D]) { n     if (aa.d[(D + 1) % 3] == bb.d[(D + 1) % 3]) n       return aa.d[(D + 2) % 3] < bb.d[(D + 2) % 3]; n     return aa.d[(D + 1) % 3] < bb.d[(D + 1) % 3]; n   } n   return aa.d[D] < bb.d[D]; n } n inline void update(int x, int y) { n   t[x].maxx = max(t[x].maxx, t[y].maxx); n   t[x].minx = min(t[x].minx, t[y].minx); n   t[x].maxy = max(t[x].maxy, t[y].maxy); n   t[x].miny = min(t[x].miny, t[y].miny); n   t[x].maxz = max(t[x].maxz, t[y].maxz); n   t[x].minz = min(t[x].minz, t[y].minz); n } n int build(int l, int r, int d) { n   int mid = (l + r) >> 1; n   D = d; n   nth_element(t + l, t + mid, t + r + 1, cmp); n   t[mid].minx = t[mid].maxx = t[mid].d[0]; n   t[mid].miny = t[mid].maxy = t[mid].d[1]; n   t[mid].minz = t[mid].maxz = t[mid].d[2]; n   if (l < mid) t[mid].l = build(l, mid - 1, (d + 1) % 3), update(mid, t[mid].l); n   ; n   if (r > mid) t[mid].r = build(mid + 1, r, (d + 1) % 3), update(mid, t[mid].r); n   ; n   return mid; n } n bool inc(int l1, int r1, int l2, int r2) { n   if (l1 > r2 || l2 > r1) n     return 0; n   else n     return 1; n } n bool in(int d) { n   if (!inc(t[d].minx, t[d].maxx, mn1, mx1)) return 0; n   if (!inc(t[d].miny, t[d].maxy, mn2, mx2)) return 0; n   if (!inc(t[d].minz, t[d].maxz, mn3, mx3)) return 0; n   return 0 ^ 1; n } n bool check(int l1, int r1, int l2, int r2) { return l2 <= l1 && r2 >= r1; } n bool check(int d) { n   if (!check(t[d].minx, t[d].maxx, mn1, mx1)) return 0; n   if (!check(t[d].miny, t[d].maxy, mn2, mx2)) return 0; n   if (!check(t[d].minz, t[d].maxz, mn3, mx3)) return 0; n   return 1; n } n int query(int k) { n   if (!k) return 0; n   if (!in(k)) return 0; n   if (check(k)) return 0 ^ 1; n   if (t[k].d[0] >= mn1 && t[k].d[0] <= mx1 && t[k].d[1] >= mn2 && n       t[k].d[1] <= mx2 && t[k].d[2] >= mn3 && t[k].d[2] <= mx3) n     return 0 ^ 1; n   if (query(t[k].l)) return 1; n   if (query(t[k].r)) return 1; n   return 0; n } n inline int read() { n   char ch = getchar(); n   int f = 1, w = 0; n   for (; ch <  0  || ch >  9 ; ch = getchar()) n     if (ch ==  - ) f = -1; n   for (; ch >=  0  && ch <=  9 ; ch = getchar()) w = w * 10 + ch -  0 ; n   return w * f; n } n int main() { n   minx = read(); n   miny = read(); n   minz = read(); n   n = read(); n   m = read(); n   Q = read(); n   maxx = maxy = maxz = 1; n   for (int i = 1; i <= n; i++) { n     x = read(); n     y = read(); n     z = read(); n     minx = min(minx, x); n     maxx = max(maxx, x); n     miny = min(miny, y); n     maxy = max(maxy, y); n     minz = min(minz, z); n     maxz = max(maxz, z); n   } n   for (int i = 1; i <= m; i++) { n     x = read(); n     y = read(); n     z = read(); n     if (x >= minx && x <= maxx && y >= miny && y <= maxy && z <= maxz && n         z >= minz) n       return puts( INCORRECT ), 0; n     t[++cnt].d[0] = x; n     t[cnt].d[1] = y; n     t[cnt].d[2] = z; n   } n   puts( CORRECT ); n   int rt = build(1, cnt, 1); n   while (Q--) { n     x = read(); n     y = read(); n     z = read(); n     if (minx <= x && x <= maxx && miny <= y && y <= maxy && minz <= z && n         z <= maxz) { n       puts( OPEN ); n       continue; n     } n     mx1 = max(x, maxx); n     mn1 = min(x, minx); n     mx2 = max(y, maxy); n     mn2 = min(y, miny); n     mx3 = max(z, maxz); n     mn3 = min(z, minz); n     if (query(rt)) n       puts( CLOSED ); n     else n       puts( UNKNOWN ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool debug = false; n int n, m, k; n int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; n long long ln, lk, lm; n int gg(int x, int y) { n   int z = y; n   while (x % y != 0) { n     z = x % y; n     x = y; n     y = z; n   } n   return z; n } n map<int, vector<int>> X[2]; n map<pair<pair<int, int>, pair<int, int>>, vector<int>> mp[2]; n int cx[20005], cy[20005], cr[20005], ans; n int dis(int i, int j) { n   return (cx[i] - cx[j]) * (cx[i] - cx[j]) + (cy[i] - cy[j]) * (cy[i] - cy[j]); n } n pair<int, int> gett(int x, int y) { n   if (y == 0) return {0, 1}; n   int tmp = gg(abs(x), abs(y)); n   pair<int, int> tt = {abs(y / tmp), abs(x / tmp)}; n   if ((y < 0 && x > 0) || (y > 0 && x < 0)) tt.second *= -1; n   return tt; n } n void cal(int i, int j) { n   if (cy[i] == cy[j]) { n     int x = cx[i] + cx[j]; n     if (x % 2 != 0) return; n     x /= 2; n     auto p = X[0][x]; n     int sz = p.size(); n     if (sz == 0) return; n     int tar = cy[i]; n     int c = p.end() - upper_bound(p.begin(), p.end(), tar); n     p = X[1][x]; n     c += sz - (p.end() - lower_bound(p.begin(), p.end(), tar)); n     ans += sz - c; n     return; n   } n   int x = cx[i] - cx[j], y = cy[i] - cy[j]; n   int zx = (cx[i] + cx[j]), zy = (cy[i] + cy[j]); n   pair<int, int> kk = gett(y * -1, x); n   pair<int, int> bb = gett(kk.second * 2, kk.second * zy - kk.first * zx); n   if (mp[0].find({kk, bb}) == mp[0].end()) return; n   auto p = mp[0][{kk, bb}]; n   int sz = p.size(); n   int tar = zx / 2; n   int c = p.end() - upper_bound(p.begin(), p.end(), tar); n   p = mp[1][{kk, bb}]; n   c += sz - (p.end() - lower_bound(p.begin(), p.end(), tar)); n   ans += sz - c; n } n int main() { n   scanf( %d%d , &n, &m); n   int a, b, c, d; n   for (int(i) = 0; (i) < (int)(n); (i)++) { n     scanf( %d%d%d%d , &a, &b, &c, &d); n     if (a == c) { n       X[0][a].push_back({min(b, d)}); n       X[1][a].push_back({max(b, d)}); n     } else { n       int x = a - c, y = b - d; n       pair<int, int> tt = gett(x, y); n       y = d * a - c * b; n       pair<int, int> bb = gett(x, y); n       mp[0][{tt, bb}].push_back(min(a, c)); n       mp[1][{tt, bb}].push_back(max(a, c)); n     } n   } n   for (int(i) = 0; (i) < (int)(2); (i)++) { n     for (auto &p : X[i]) sort(p.second.begin(), p.second.end()); n     for (auto &p : mp[i]) sort(p.second.begin(), p.second.end()); n   } n   for (int(i) = 0; (i) < (int)(m); (i)++) n     scanf( %d%d%d , cx + i, cy + i, cr + i); n   for (int(i) = 0; (i) < (int)(m); (i)++) n     for (int j = i + 1; j < m; j++) n       if (cr[i] == cr[j]) { n         int D = cr[i] + cr[j]; n         D *= D; n         if (dis(i, j) > D) { n           cal(i, j); n         } n       } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MN = 200010; n int a[MN], b[MN], p[MN], q[MN]; n char ans[MN]; n int main() { n   int t, m, k; n   for (scanf( %d , &t); t--;) { n     scanf( %d%d , &m, &k); n     int pos = 0, pos1; n     for (int i = 1; i <= k; i++) { n       scanf( %d , &a[i]); n     } n     bool flag = false; n     for (int i = 1; i < m; i++) { n       scanf( %d%d , &p[i], &q[i]); n       if (q[i] == 1 && !flag) { n         flag = true; n         for (int j = 1; j <= k; j++) { n           b[j] = a[j]; n         } n         pos1 = pos; n       } n       if (p[i] != 0) { n         a[p[i]]--; n       } else { n         pos++; n       } n     } n     int minA = MN; n     if (flag) { n       for (int i = 1; i <= k; i++) { n         if (a[i] == b[i]) { n           minA = min(minA, a[i]); n         } n       } n       pos -= minA; n     } n     for (int i = 1; i <= k; i++) { n       if (flag && a[i] == b[i] && a[i] <= pos1) { n         printf( Y ); n       } else { n         printf( %c , (a[i] > pos ?  N  :  Y )); n       } n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char a[10][10]; n   char b[10][10]; n   vector<char> v, l; n   long long int i, count = 0, j; n   for (i = 0; i < 2; i++) { n     for (j = 0; j < 2; j++) { n       cin >> a[i][j]; n     } n   } n   v.push_back(a[0][0]); n   v.push_back(a[0][1]); n   v.push_back(a[1][1]); n   v.push_back(a[1][0]); n   for (i = 0; i < 2; i++) { n     for (j = 0; j < 2; j++) { n       cin >> b[i][j]; n     } n   } n   l.push_back(b[0][0]); n   l.push_back(b[0][1]); n   l.push_back(b[1][1]); n   l.push_back(b[1][0]); n   int flag = 0; n   v.erase(remove(v.begin(), v.end(),  X ), v.end()); n   l.erase(remove(l.begin(), l.end(),  X ), l.end()); n   for (i = 0; i < 3; i++) { n     if (equal(v.begin(), v.end(), l.begin())) { n       flag = 1; n       break; n     } else { n       vector<char>::iterator k = v.begin() + 2; n       char la = *k; n       v.insert(v.begin(), *k); n       v.erase(v.begin() + 3); n     } n   } n   if (flag) n     cout <<  YES n ; n   else n     cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   vector<int> a(n); n   int sum = 0, maxi = -1; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     sum += a[i]; n     maxi = max(a[i], maxi); n   } n   if (maxi > (sum / 2)) n     cout <<  T  n          <<   n ; n   else { n     if (sum % 2 == 0) n       cout <<  HL  n            <<   n ; n     else n       cout <<  T  n            <<   n ; n   } n } n int main() { n   int t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int k, d, i, n, x; n   scanf( %d%d , &k, &d); n   n = k; n   x = d; n   if ((k > 1) && (d == 0)) { n     printf( No solution ); n   } else { n     for (i = 1; ((i < n) && (x > 0)); i++) { n       printf( 1 ); n       x--; n     } n     while (i < n) { n       printf( 0 ); n       i++; n     } n     if (x == 0) { n       printf( 0 ); n     } else { n       printf( %d , (d - i + 1)); n     } n   } n } n


#include <bits/stdc++.h> n int main() { n   int n, o, i, k, m; n   scanf( %d%d , &n, &o); n   scanf( %d%d , &k, &m); n   int a[n], b[o]; n   for (i = 0; i < n; i++) scanf( %d , &a[i]); n   for (i = 0; i < o; i++) scanf( %d , &b[i]); n   if (a[k - 1] < b[o - m]) n     printf( YES ); n   else n     printf( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 5e5 + 9; n vector<long long> adj[N], vec[N]; n long long h[N], up[N], ans[N]; n pair<long long, long long> edge[N]; n vector<pair<long long, long long> > a[N]; n void DFS1(long long u, long long par) { n   h[u] = 1; n   for (long long v : adj[u]) n     if (v != par) { n       DFS1(v, u); n       h[u] = max(h[u], h[v] + 1); n       vec[u].push_back(h[v]); n     } n } n void DFS2(long long u, long long par) { n   multiset<long long> s; n   for (long long v : adj[u]) n     if (v != par) s.insert(-h[v]); n   for (long long v : adj[u]) n     if (v != par) { n       s.erase(s.find(-h[v])); n       up[v] = up[u] + 1; n       if (!s.empty()) up[v] = max(up[v], -(*s.begin()) + 1); n       vec[v].push_back(up[v]); n       s.insert(-h[v]); n     } n   for (long long v : adj[u]) n     if (v != par) DFS2(v, u); n } n void DFS3(long long u, long long par) { n   for (long long v : adj[u]) n     if (v != par) { n       vector<pair<long long, long long> > b; n       long long iu = 0, iv = 0; n       while (iu < a[u].size() && iv < a[v].size()) { n         if (a[u][iu].first < a[v][iv].first) n           b.push_back(a[u][iu++]); n         else if (a[u][iu].first > a[v][iv].first) n           b.push_back(a[v][iv++]); n         else if (a[u][iu].first == a[v][iv].first) n           b.push_back({a[v][iv].first, a[v][iv++].second + a[u][iu++].second}); n       } n       while (iv < a[v].size()) b.push_back(a[v][iv++]); n       while (iu < a[u].size()) b.push_back(a[u][iu++]); n       for (long long i = 0; i < b.size(); i++) { n         if (b[i].first == up[v]) b[i].second--; n         if (b[i].first == h[v]) b[i].second--; n       } n       long long num = 0; n       while (b.size()) { n         ans[b.back().first * 2] = n             max(ans[b.back().first * 2], (num += b.back().second)); n         b.pop_back(); n       } n       DFS3(v, u); n     } n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   long long n; n   cin >> n; n   for (long long i = 1; i < n; i++) { n     long long u, v; n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   fill(ans, ans + N, 1); n   DFS1(1, 0); n   DFS2(1, 0); n   for (long long i = 1; i <= n; i++) { n     sort(vec[i].begin(), vec[i].end()); n     for (long long j = 0; j < vec[i].size() - 1; j++) n       if (vec[i][j] != vec[i][j + 1]) n         ans[vec[i][j] * 2 + 1] = n             max(ans[vec[i][j] * 2 + 1], (long long)vec[i].size() - j); n     for (long long j = 0; j < vec[i].size(); j++) n       ans[vec[i][j] * 2 - 1] = n           max(ans[vec[i][j] * 2 - 1], (long long)vec[i].size() - j), n                           ans[vec[i][j] * 2] = max( n                               ans[vec[i][j] * 2], (long long)vec[i].size() - j); n     for (long long j = 0, k = 0; max(j, k) < vec[i].size(); j = k) { n       while (k < vec[i].size() && vec[i][j] == vec[i][k]) k++; n       a[i].push_back({vec[i][j], k - j}); n     } n   } n   DFS3(1, 0); n   for (long long i = n; i > 0; i--) ans[i] = max(ans[i], ans[i + 2]); n   for (long long i = 1; i <= n; i++) n     ans[1] = max(ans[1], (long long)adj[i].size() + 1); n   for (long long i = 1; i <= n; i++) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool dp[10005][3]; n int main() { n   int n, i; n   string s; n   set<string> ans; n   cin >> s; n   n = s.length(); n   for (i = n - 1; i >= 5; i--) { n     if (i + 2 <= n) { n       if (i + 2 == n || dp[i + 2][1] || n           (dp[i + 2][0] && s.substr(i + 2, 2) != s.substr(i, 2))) { n         dp[i][0] = true; n         ans.insert(s.substr(i, 2)); n       } n     } n     if (i + 3 <= n) { n       if (i + 3 == n || dp[i + 3][0] || n           (dp[i + 3][1] && s.substr(i + 3, 3) != s.substr(i, 3))) { n         dp[i][1] = true; n         ans.insert(s.substr(i, 3)); n       } n     } n   } n   cout << ans.size() << endl; n   while (!ans.empty()) { n     cout << *ans.begin() << endl; n     ans.erase(ans.begin()); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 345; n int ai[maxn]; n int bi[maxn]; n bool used[maxn]; n int m, r, t; n void init() { n   for (int i = 1; i <= m; i++) { n     scanf( %d , &ai[i]); n     ai[i]++; n   } n } n vector<int> V; n void play() { n   memset(bi, 0, sizeof(bi)); n   memset(used, 0, sizeof(used)); n   V.clear(); n   if (t < r) { n     printf( -1 n ); n     return; n   } n   long long sum = 0; n   for (int i = 1; i <= m; i++) { n     int st = 0; n     while (bi[ai[i]] < r) { n       for (int j = ai[i] - st; j <= ai[i] - st + t - 1; j++) { n         if (j <= 0 || j > 320) continue; n         bi[j]++; n       } n       sum++; n       st++; n     } n   } n   printf( %I64d n , sum); n } n int main() { n   while (scanf( %d%d%d , &m, &t, &r) != EOF) { n     init(); n     play(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7, N = 1e5 + 5; n int main() { n   std::ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n; n   cin >> n; n   long long a[n + 5], ans = 0, maxx = 0, sum = 0; n   vector<long long> e, o; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] & 1) n       e.push_back(a[i]); n     else n       o.push_back(a[i]); n     maxx = max(a[i], maxx); n     sum += a[i]; n   } n   sort(e.begin(), e.end()), sort(o.begin(), o.end()); n   long long es = (long long)e.size(), os = (long long)o.size(); n   if (abs(es - os) <= 1) { n     cout << 0; n     return 0; n   } n   if (es == 0 || os == 0) { n     cout << sum - maxx; n     return 0; n   } n   if (es > os) { n     for (int i = 0; i < (es - os - 1); i++) { n       ans += e[i]; n     } n   } else { n     for (int i = 0; i < (os - es - 1); i++) { n       ans += o[i]; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, k, x, y; n   scanf( %d%d%d , &n, &m, &k); n   bool f = false; n   while (k--) { n     scanf( %d%d , &x, &y); n     int mn = (1 << 20); n     for (int i = 1; i <= n; ++i) n       for (int j = 1; j <= m; ++j) n         if (i == 1 || j == 1 || i == n || j == m) n           mn = min(mn, abs(i - x) + abs(j - y)); n     if (mn <= 4) f = true; n   } n   if (f) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n } n


#include<bits/stdc++.h> n using namespace std; n   n #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); n #define int long long n #define rep(i,a,b)    for(int i=a;i<b;i++) n #define repn(i,a,b)   for(int i=a;i>=b;i--) n #define ff first n #define ss second n #define lb lower_bound n #define ub upper_bound n #define pii pair<int,int> n #define vi vector<int> n #define vs vector<string> n #define vii vector<pii> n #define vvi vector<vector<int>> n #define vvii vector<vector<pii>> n #define pb push_back n #define ppb pop_back n #define pf push_front n #define ppf pop_front n #define sz(x) (int)x.size() n #define all(v) (v).begin(), (v).end()    n #define ret(x) return cout<<x,0; n #define rety return cout<< YES ,0; n #define retn return cout<< NO ,0; n #define fl fflush(stdout)    n #define hell 1000000007 n #define hell2 998244353  n #define pi 3.14159265358979323846 n  n int solve(){ n     int n,m; n     cin >> n >> m; n     string s,a; n     cin >> s; n     a = s; n     for(int i = 0; i < min(m,n); i++){ n         int x{}; n         for(int j = 0; j < n; j++){ n             if(j == 0){ n                 if(s[1] ==  1  && s[0] ==  0 ) n                     a[0] =  1 ; n                 x++;     n             } n             else if(j == n-1){ n                 if(s[n-1] ==  0  && s[n-2] ==  1 ) n                     a[n-1] =  1 ; n                 x++; n             } n             else{ n                 if((s[j-1] ==  1  && s[j+1] ==  0  && s[j] ==  0 ) || (s[j-1] ==  0  && s[j+1] ==  1  && s[j] ==  0 )) n                     a[j] =  1 ; n                 x++;     n             } n         } n         s = a; n         if(x == 0) n             break; n     } n     cout << s << endl; n      n     return 0; n } n      n signed main(){ n     IOS; n     int tp=1; n  cin>>tp; n     while(tp--){ n         solve(); n     } n      n     return 0; n } n  n  n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   int ans = 0; n   int inp; n   for (int i = 0; i < n; i++) { n     cin >> inp; n     int temp = (inp + k - 1) / k; n     ans += temp; n   } n   cout << (ans + 1) / 2 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n map<char, int> m; n char letters[30]; n int numbers[30]; n int mystring[30]; n int ceiling(int top, int bottom) { return (top + bottom - 1) / bottom; } n int main() { n   string s; n   int n; n   cin >> s >> n; n   for (int i = 0; i < (int)s.length(); i++) m[s[i]]++; n   int numChar = 0; n   for (map<char, int>::iterator it = m.begin(); it != m.end(); ++it) { n     letters[numChar] = it->first; n     numbers[numChar] = it->second; n     numChar++; n   } n   if (numChar > n) { n     cout << -1 << endl; n     return 0; n   } n   for (int i = 0; i < numChar; i++) mystring[i] = 1; n   for (int i = numChar; i < n; i++) { n     int needMost = -1, needMostIndex = -1; n     for (int j = 0; j < numChar; j++) { n       if (ceiling(numbers[j], mystring[j]) > needMost) { n         needMost = ceiling(numbers[j], mystring[j]); n         needMostIndex = j; n       } n     } n     mystring[needMostIndex]++; n   } n   int needMost = -1; n   for (int j = 0; j < numChar; j++) { n     if (ceiling(numbers[j], mystring[j]) > needMost) { n       needMost = ceiling(numbers[j], mystring[j]); n     } n   } n   cout << needMost << endl; n   for (int i = 0; i < numChar; i++) n     for (int j = 0; j < mystring[i]; j++) cout << letters[i]; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long Size = 501; n const long long mod = 1e9 + 7; n long long a[Size], num[Size]; n bool vis[Size]; n long long f[Size], d[Size]; n long long dp[Size][Size]; n inline long long min(long long a, long long b) { return a < b ? a : b; } n inline long long max(long long a, long long b) { return a > b ? a : b; } n long long fastpow(long long b, long long p, long long k) { n   long long ans = 1; n   while (p) { n     if (p & 1) ans = ans * b % k; n     b = b * b % k; n     p >>= 1; n   } n   return ans; n } n void init() { n   f[0] = 1; n   for (long long i = 1; i <= 300; i++) f[i] = f[i - 1] * i % mod; n   d[300] = fastpow(f[300], mod - 2, mod); n   for (long long i = 299; i >= 0; i--) d[i] = d[i + 1] * (i + 1) % mod; n } n long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = 10 * x + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n long long C(long long a, long long b) { n   if (a < 0 || b < 0 || a < b) return 0; n   if (!b || a == b) return 1; n   return (f[a] * d[b] % mod) * d[a - b] % mod; n } n int main() { n   init(); n   C(2, 1); n   long long n = read(), size = 0; n   for (long long i = 1; i <= n; i++) a[i] = read(); n   for (long long i = 1; i <= n; i++) { n     if (!vis[i]) { n       size++; n       for (long long j = i; j <= n; j++) { n         if (sqrt(a[i] * a[j]) == (long long)sqrt(a[i] * a[j])) { n           vis[j] = true; n           num[size]++; n         } n       } n     } n   } n   long long sum = num[1] - 1; n   dp[1][sum] = 1; n   for (long long i = 2; i <= size; sum += num[i++]) { n     for (long long j = 0; j <= sum; j++) { n       if (!dp[i - 1][j]) continue; n       for (long long k = 0; k <= num[i]; k++) { n         long long tmp = min(j, k + 1), temp; n         for (long long l = 0; l <= tmp; l++) { n           temp = dp[i - 1][j] * C(num[i] - 1, k) % mod * C(j, l) % mod * n                  C(sum + 2 - j, k - l + 1) % mod; n           dp[i][j + num[i] - 1 - k - l] += temp; n           dp[i][j + num[i] - 1 - k - l] %= mod; n         } n       } n     } n   } n   long long ans = dp[size][0]; n   for (long long i = 1; i <= size; i++) ans = ans * f[num[i]] % mod; n   printf( %I64d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 500010; n const int MAXM = 500010; n const int INF = 1e9 + 7; n const double pi = acos(0.0) * 2.0; n const double eps = 1e-12; n inline int read(int &x) { n   scanf( %d , &x); n   return x; n } n inline long long read(long long &x) { n   scanf( %I64d , &x); n   return x; n } n inline char read(char c) { n   c = getchar(); n   return c; n } n inline char *read(char *&x) { n   scanf( %s , x); n   return x; n } n inline char *readln(char *&x) { n   gets(x); n   return x; n } n inline string read(string &x) { n   cin >> x; n   return x; n } n inline string readln(string &x) { n   getline(cin, x); n   return x; n } n inline float read(float &x) { n   scanf( %f , &x); n   return x; n } n inline double read(double &x) { n   scanf( %lf , &x); n   return x; n } n inline void ToString(char *x, string &y) { y = x; } n template <typename T> n inline void read(vector<T> &a, int n) { n   a.clear(); n   T x; n   for (int i = 0; i < n; i++) a.push_back(read(x)); n } n template <typename T> n inline void read(T a[], int n) { n   for (int i = 0; i < n; i++) read(a[i]); n } n inline int write(int x) { n   printf( %d , x); n   return x; n } n inline int writeln(int x) { n   printf( %d n , x); n   return x; n } n inline long long write(long long x) { n   printf( %I64d , x); n   return x; n } n inline long long writeln(long long x) { n   printf( %I64d n , x); n   return x; n } n inline char write(char c) { n   putchar(c); n   return c; n } n inline char writeln(char c) { n   putchar(c); n   putchar(  n ); n   return c; n } n inline char *write(char *x) { n   printf( %s , x); n   return x; n } n inline char *writeln(char *x) { n   puts(x); n   return x; n } n inline string write(string x) { n   cout << x; n   return x; n } n inline string writeln(string x) { n   cout << x <<   n ; n   return x; n } n inline float write(float x) { n   printf( %f , x); n   return x; n } n inline float writeln(float x) { n   printf( %f n , x); n   return x; n } n inline double write(double x) { n   printf( %lf , x); n   return x; n } n inline double writeln(double x) { n   printf( %lf n , x); n   return x; n } n template <typename T> n inline void write(vector<T> &a, int n) { n   for (int i = 0; i < n - 1; i++) { n     write(a[i]); n     putchar(   ); n   } n   writeln(a[n - 1]); n } n template <typename T> n inline void writeln(vector<T> &a, int n) { n   for (int i = 0; i < n; i++) writeln(a[i]); n } n template <typename T> n inline void write(T a[], int n) { n   for (int i = 0; i < n - 1; i++) { n     write(a[i]); n     putchar(   ); n   } n   writeln(a[n - 1]); n } n template <typename T> n inline void writeln(T a[], int n) { n   for (int i = 0; i < n; i++) writeln(a[i]); n } n template <class T> n inline T abs1(T a) { n   return a < 0 ? -a : a; n } n template <class T> n inline T max1(T a, T b) { n   return a > b ? a : b; n } n template <class T> n inline T max1(T a, T b, T c) { n   return max1(max1(a, b), c); n } n template <class T> n inline T max1(T a, T b, T c, T d) { n   return max1(max1(a, b, c), d); n } n template <class T> n inline T max1(T a, T b, T c, T d, T e) { n   return max1(max1(a, b, c, d), e); n } n template <class T> n inline T min1(T a, T b) { n   return a < b ? a : b; n } n template <class T> n inline T min1(T a, T b, T c) { n   return min1(min1(a, b), c); n } n template <class T> n inline T min1(T a, T b, T c, T d) { n   return min1(min1(a, b, c), d); n } n template <class T> n inline T min1(T a, T b, T c, T d, T e) { n   return min1(min1(a, b, c, d), e); n } n inline int jud(double a, double b) { n   if (abs(a) < eps && abs(b) < eps) n     return 0; n   else if (abs1(a - b) / abs1(a) < eps) n     return 0; n   if (a < b) return -1; n   return 1; n } n template <typename t> n inline int jud(t a, t b) { n   if (a < b) return -1; n   if (a == b) return 0; n   return 1; n } n int N, M, T = INF, Cases = 0; n double l, r; n double ans[MAXN]; n string s; n int main() { n   std::ios::sync_with_stdio(false); n   cin >> s; n   N = s.length(); n   double sum = 0; n   for (int i = 1; i <= N; i++) sum += 1 / double(i); n   ans[0] = ans[N - 1] = sum; n   l = 1; n   r = N; n   for (int i = 1; i < (N + 1) / 2; i++) { n     sum -= 1.0 / l + 1.0 / r; n     ans[i] = ans[N - i - 1] = ans[i - 1] + sum; n     l += 1; n     r -= 1; n   } n   double res = 0; n   for (int i = 0; i < N; i++) { n     if (s[i] ==  A  || s[i] ==  E  || s[i] ==  O  || s[i] ==  I  || n         s[i] ==  U  || s[i] ==  Y ) n       res += ans[i]; n   } n   cout.setf(ios::fixed); n   cout << setprecision(9) << res << endl; n   return 0; n } n