#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n const int N = 1000000 + 5; n const int K = 26 + 5; n char s[N], t[N]; n int ns[K], nt[K], ans[K]; n int main() { n   scanf( %s %s , s, t); n   for (int i = 0; t[i]; ++i) { n     nt[t[i] -  a ]++; n   } n   int cnt = 0; n   for (int i = 0; s[i]; ++i) { n     if (s[i] !=  ? ) n       ns[s[i] -  a ]++; n     else n       cnt++; n   } n   while (1) { n     int c = 0; n     for (int i = 0; i < 26; ++i) { n       if (nt[i]) c += max(0, nt[i] - ns[i]); n     } n     if (cnt < c) break; n     for (int i = 0; i < 26; ++i) { n       if (nt[i]) { n         ans[i] += max(0, nt[i] - ns[i]); n         ns[i] = max(0, ns[i] - nt[i]); n       } n     } n     cnt -= c; n   } n   int k = 0; n   for (int i = 0; s[i]; ++i) { n     if (s[i] ==  ? ) { n       while (k < 26 && ans[k] <= 0) k++; n       if (k < 26) ans[k]--; n       printf( %c ,  a  + (k < 26 ? k : 0)); n     } else { n       printf( %c , s[i]); n     } n   } n   printf(  n ); n } n


#include <bits/stdc++.h> n const long long INF = 0x3f3f3f3f3f3f3f3fLL; n const int inf = 0x3f3f3f3f; n const int mod = 1e9 + 7; n const double eps = 1e-6; n template <class T> n inline void read(T& x) { n   int sign = 1; n   char c = getchar(); n   x = 0; n   while (c >  9  || c <  0 ) { n     if (c ==  - ) sign = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   x *= sign; n } n using namespace std; n const int maxn = 5e6 + 10; n unsigned long long ji = 1; n long long dp[maxn]; n unsigned long long prehash[maxn], sufhash[maxn]; n char s[maxn]; n inline int val(char x) { n   if (x >=  0  && x <=  9 ) return x -  0 ; n   if (x >=  a  && x <=  z ) return x -  a  + 10; n   if (x >=  A  && x <=  Z ) return x -  Z  + 36; n } n int main() { n   scanf( %s , s + 1); n   int len = 0; n   for (int i = 1; s[i]; ++i) s[i] = val(s[i]); n   for (int i = 1; s[i]; ++i) prehash[i] = prehash[i - 1] * 131 + 1ll * s[i]; n   for (int i = 1; s[i]; ++i) { n     sufhash[i] = sufhash[i - 1] + 1ll * s[i] * ji; n     ji *= 131; n   } n   long long res = 0; n   for (int i = 1; s[i]; ++i) { n     if (prehash[i] == sufhash[i]) { n       dp[i] = dp[i >> 1] + 1; n     } n     res += dp[i]; n   } n   printf( %lld n , res); n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-10; n pair<double, double> za, zb, zc, zd; n pair<double, double> a, b, c, d, e; n pair<double, double> A, B, C, D; n double cha(pair<double, double> a, pair<double, double> b, n            pair<double, double> c) { n   return (b.first - a.first) * (c.second - a.second) - n          (b.second - a.second) * (c.first - a.first); n } n pair<double, double> jiao(pair<double, double> a, pair<double, double> b, n                           pair<double, double> c, pair<double, double> d) { n   double t1 = cha(a, c, b), t2 = cha(a, b, d), t3 = cha(c, a, d), n          t4 = cha(c, d, b); n   return make_pair((c.first * t2 + d.first * t1) / (t1 + t2), n                    (c.second * t2 + d.second * t1) / (t1 + t2)); n } n void work(pair<double, double> a, pair<double, double> b, n           pair<double, double> &c, pair<double, double> &d) { n   c = make_pair((a.first + b.first) / 2, (a.second + b.second) / 2); n   d = make_pair(c.first + b.second - a.second, c.second + a.first - b.first); n } n bool get(pair<double, double> a, pair<double, double> b, n          pair<double, double> c) { n   work(a, b, za, zb), work(b, c, zc, zd); n   d = make_pair(b.first + zd.first - zc.first, n                 b.second + zd.second - zc.second); n   d = jiao(b, d, za, zb); n   e = jiao(za, zb, zc, zd); n   A = make_pair(2 * d.first - e.first, 2 * d.second - e.second); n   B = make_pair(2 * b.first - A.first, 2 * b.second - A.second); n   C = make_pair(2 * c.first - B.first, 2 * c.second - B.second); n   D = make_pair(2 * a.first - A.first, 2 * a.second - A.second); n   return cha(A, B, C) * cha(B, C, D) - eps > 0 && n          cha(B, C, D) * cha(C, D, A) - eps > 0 && n          cha(C, D, A) * cha(D, A, B) - eps > 0; n } n int main() { n   int t; n   for (scanf( %d , &t); t--;) { n     scanf( %lf%lf%lf%lf%lf%lf , &a.first, &a.second, &b.first, &b.second, n           &c.first, &c.second); n     if (fabs(cha(a, b, c)) - eps < 0) { n       printf( NO n ); n       continue; n     } n     if (get(a, b, c) || get(a, c, b) || get(b, a, c)) { n       printf( YES n ); n       printf( %.9f %.9f  , A.first, A.second); n       printf( %.9f %.9f  , B.first, B.second); n       printf( %.9f %.9f  , C.first, C.second); n       printf( %.9f %.9f n , D.first, D.second); n     } else n       printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 200009; n long long N, M; n long long Max[MAXN], A[MAXN]; n long long maxLL(long long num1, long long num2) { n   return (num1 > num2 ? num1 : num2); n } n void Update(int x, long long nh) { n   for (int i = x; i <= N; i += (i & (-i))) Max[i] = maxLL(Max[i], nh); n } n long long Find(int x) { n   long long ret = 0; n   for (int i = x; i >= 1; i -= (i & (-i))) ret = maxLL(ret, Max[i]); n   return ret; n } n int main() { n   cin >> N; n   for (int i = 1; i <= N; i++) Max[i] = 0; n   for (int i = 1; i <= N; i++) { n     cin >> A[i]; n     Update(i, A[i]); n   } n   cin >> M; n   for (int i = 1; i <= M; i++) { n     long long Xx, Yy; n     cin >> Xx >> Yy; n     long long Ans = Find(Xx); n     Update(1, Ans + Yy); n     cout << Ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<long double, int> > v; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     long double x, y; n     cin >> x >> y; n     v.push_back(make_pair(atan2(y, x), i)); n   } n   sort(v.begin(), v.end()); n   v.push_back(v[0]); n   if (v.back().first < 0.0) n     v.back().first = (2 * acos(0.0) + v.back().first + 2 * acos(0.0)); n   long double ans = 1e18; n   int id1, id2; n   for (int i = 1; i < (int)v.size(); i++) { n     long double x = fabs(v[i].first - v[i - 1].first); n     if (x < ans) { n       ans = x; n       id1 = v[i].second; n       id2 = v[i - 1].second; n     } n   } n   cout << id1 <<     << id2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9 + 10; n int main() { n   int n; n   cin >> n; n   int an[n]; n   vector<int> p; n   vector<pair<int, int> > st; n   int i = 0; n   for (int a = 0; a < n * 2; a++) { n     char sy; n     cin >> sy; n     if (sy ==  + ) { n       p.push_back(i++); n       st.push_back({0, 1}); n     } else { n       int x; n       scanf( %d , &x); n       if (st.size() and x > st.back().first) { n         int su = 0; n         while (st.size() and st.back().first < x) { n           su += st.back().second; n           st.pop_back(); n         } n         su--; n         if (su) st.push_back({x, su}); n         an[p.back()] = x; n         p.pop_back(); n       } else { n         cout <<  NO ; n         return 0; n       } n     } n   } n   cout <<  YES n ; n   for (int a = 0; a < n; a++) printf( %d  , an[a]); n } n


#include <bits/stdc++.h> n using namespace std; n int arr[2010], money, mn, mx, ans; n vector<pair<int, int> > tmp; n int main() { n   int n, b; n   cin >> n >> b; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     tmp.push_back(make_pair(arr[i], i)); n   } n   sort(tmp.rbegin(), tmp.rend()); n   for (int i = 0; i < n; i++) { n     mx = tmp[i].first, mn = 1e8; n     for (int j = 0; j < tmp[i].second; j++) { n       mn = min(mn, arr[j]); n     } n     money = b / mn; n     money *= mx; n     money += (b % mn); n     ans = max(ans, money); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n bool comp(string s, string t, vector<int> rows) { n   int i = 0; n   int m = s.size(); n   while (i < m && n          (s[i] == t[i] || (find(rows.begin(), rows.end(), i) != rows.end()))) n     i++; n   if (i == m) return false; n   return s[i] < t[i]; n } n int main() { n   int n, m; n   cin >> n >> m; n   vector<string> table(n); n   for (int i = 0; i < n; i++) cin >> table[i]; n   vector<int> rows; n   for (int j = 0; j < m; j++) { n     for (int i = 1; i < n; i++) { n       int k = i - 1; n       if (comp(table[i], table[k], rows)) { n         for (int l = 0; l < m; l++) { n           if (find(rows.begin(), rows.end(), l) != rows.end()) continue; n           if (table[i][l] < table[k][l]) { n             rows.push_back(l); n             break; n           } n         } n       } n     } n   } n   cout << rows.size() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long p = 1000000007; n int q[200005][3]; n int n, cnt = 1; n vector<int> c[200005]; n int v[200005]; n int l[200005]; n int r[200005]; n int f[200005]; n long long rev[200005]; n void eec_solve(long long& a, const long long x, long long& b, n                const long long y) { n   if (y == 0) { n     a = 1; n     b = 0; n     return; n   } n   long long q = x / y, r = x % y, c = 0, d = 0; n   eec_solve(c, y, d, r); n   a = d; n   b = c - a * q; n } n int solve_lr(int ind, int cur) { n   l[ind] = cur; n   int tmp = 1; n   for (int i = 0; i < c[ind].size(); ++i) tmp += solve_lr(c[ind][i], cur + tmp); n   r[ind] = cur + tmp - 1; n   return tmp; n } n struct seg { n   long long v, c; n }; n seg segt[800005]; n void init(int x, int ll, int rr) { n   segt[x].v = 0; n   segt[x].c = 1; n   if (ll != rr) { n     segt[x].v = 0; n     segt[x].c = 1; n     int k = (ll + rr) / 2; n     init(x * 2, ll, k); n     init(x * 2 + 1, k + 1, rr); n   } n } n void insert(int ind, int v) { n   int x = 1, ll = 1, rr = cnt, k; n   long long cum = v; n   while (ll != rr) { n     k = (ll + rr) / 2; n     if (ind <= k) { n       x = x * 2; n       rr = k; n     } else { n       x = x * 2 + 1; n       ll = k + 1; n     } n   } n   while (x > 0) { n     segt[x].v = (segt[x].v + cum) % p; n     cum = (cum * segt[x].c) % p; n     x = x / 2; n   } n } n void change(int x, int ll, int rr, int i, int j, int cc) { n   if ((ll == i) && (rr == j)) { n     segt[x].c = (((segt[x].c * rev[cc]) % p) * (cc + 1)) % p; n     return; n   } n   int k = (ll + rr) / 2; n   if (i <= k) change(x * 2, ll, k, i, min(k, j), cc); n   if (j > k) change(x * 2 + 1, k + 1, rr, max(i, k + 1), j, cc); n   segt[x].v = n       (segt[x * 2].v * segt[x * 2].c + segt[x * 2 + 1].v * segt[x * 2 + 1].c) % n       p; n } n long long sum(int x, int ll, int rr, int i, int j) { n   if ((ll == i) && (rr == j)) return (segt[x].v * segt[x].c) % p; n   int k = (ll + rr) / 2; n   long long res = 0; n   if (i <= k) res += sum(x * 2, ll, k, i, min(k, j)); n   if (j > k) res += sum(x * 2 + 1, k + 1, rr, max(i, k + 1), j); n   return ((res % p) * segt[x].c) % p; n } n long long getC(int ind) { n   long long res = 1; n   int x = 1, ll = 1, rr = cnt, k; n   while (ll != rr) { n     res = (res * segt[x].c) % p; n     k = (ll + rr) / 2; n     if (ind <= k) { n       x = x * 2; n       rr = k; n     } else { n       x = x * 2 + 1; n       ll = k + 1; n     } n   } n   res = (res * segt[x].c) % p; n   return res; n } n int main() { n   cin >> v[1] >> n; n   for (int i = 0; i < n; ++i) { n     cin >> q[i][0] >> q[i][1]; n     if (q[i][0] == 1) { n       cin >> q[i][2]; n       v[++cnt] = q[i][2]; n       c[q[i][1]].push_back(cnt); n       f[cnt] = q[i][1]; n       q[i][2] = c[q[i][1]].size(); n     } n   } n   for (int i = 1; i <= cnt; ++i) { n     eec_solve(rev[i], i, rev[i + 1], p); n     rev[i] = ((rev[i] % p) + p) % p; n   } n   solve_lr(1, 1); n   init(1, 1, cnt); n   insert(1, v[1]); n   int new_cnt = 1; n   for (int i = 0; i < n; ++i) n     if (q[i][0] == 1) { n       ++new_cnt; n       insert(l[new_cnt], v[new_cnt]); n       change(1, 1, cnt, l[q[i][1]], r[q[i][1]], q[i][2]); n     } else { n       long long res = sum(1, 1, cnt, l[q[i][1]], r[q[i][1]]); n       if (q[i][1] != 1) { n         long long x = getC(l[f[q[i][1]]]); n         long long ta, tb; n         eec_solve(ta, x, tb, p); n         ta = ((ta % p) + p) % p; n         res = (res * ta) % p; n       } n       cout << res << endl; n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int o[101]; n int main() { n   int t; n   cin >> t; n   for (int i = 0; i < t; i++) { n     int e; n     cin >> e; n     if (e % 7 == 0) { n       o[i] = e / 7; n     } else { n       o[i] = e / 7 + 1; n     } n   } n   for (int i = 0; i < t; i++) { n     cout << o[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 5; n int n, m, col[maxn]; n set<int> s; n set<int>::iterator t[maxn]; n int main() { n   while (~scanf( %d %d , &n, &m)) { n     s.clear(); n     for (int i = 1; i <= n; i++) s.insert(i); n     int cnt = 0; n     while (m--) { n       int l, r, c; n       scanf( %d %d %d , &l, &r, &c); n       cnt = 0; n       for (auto it = s.lower_bound(l); *it <= r && it != s.end(); it++) { n         if (*it != c) { n           col[*it] = c; n           t[cnt++] = it; n         } n       } n       for (int i = 0; i < cnt; i++) { n         s.erase(t[i]); n       } n     } n     for (int i = 1; i <= n; i++) { n       printf( %d  , col[i]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   vector<int> mp(32); n   vector<int> A(m); n   for (int i = 0; i < n; i++) { n     int no; n     scanf( %d , &no); n     for (int ii = 0; ii < 31; ii++) n       if (no & (1 << ii)) mp[ii]++; n   } n   for (int i = 0; i < m; i++) scanf( %d , &A[i]); n   sort(A.begin(), A.end()); n   int res = 0; n   for (int i = 0; i < A.size(); i++) { n     for (int ii = A[i]; ii < 31; ii++) n       if (mp[ii] > 0) { n         res++; n         mp[ii]--; n         for (int iii = A[i]; ii != A[i] && iii < ii; iii++) mp[iii]++; n         break; n       } n   } n   printf( %d n , res); n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e2 + 7; n const long long nol = 0; n long long n; n string g, s; n void vkoshp() { n   cin >> n; n   while (n >= 2) { n     g +=  1 ; n     n -= 2; n   } n   if (n == 1) { n     s +=  7 ; n     g.erase(g.begin()); n     s += g; n     g = s; n   } n   cout << g; n } n int main() { n   cout.tie(NULL); n   cin.tie(NULL); n   ios_base::sync_with_stdio(0); n   long long t = 1; n   while (t--) vkoshp(); n } n


#include <bits/stdc++.h> n using namespace std; n const long long int mod = 1e9 + 7; n const long long int N = 1e5 + 5; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int i, j, tc; n   cin >> tc; n   while (tc--) { n     long long int n, w; n     cin >> n >> w; n     long long int a[n]; n     for (i = 0; i < n; i++) { n       cin >> a[i]; n     } n     vector<long long int> v; n     for (i = 0; i < n; i++) { n       if (a[i] <= w && a[i] >= (w + 1) / 2) { n         v.push_back(i + 1); n         break; n       } n     } n     if (v.size() == 1) { n       cout << 1 <<   n ; n       cout << v[0] <<   n ; n       continue; n     } n     long long int sum = 0; n     for (i = 0; i < n; i++) { n       if (a[i] <= w) { n         sum += a[i]; n         v.push_back(i + 1); n         if (sum >= (w + 1) / 2) break; n       } n     } n     if (sum >= (w + 1) / 2 && sum <= w) { n       cout << v.size() <<   n ; n       for (i = 0; i < v.size(); i++) cout << v[i] <<    ; n       cout <<   n ; n     } else n       cout << -1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n constexpr long long N = 600500; n constexpr long long D = 2000010; n constexpr long double EPS = 1e-8; n ofstream fout; n ifstream fin; n int flag = -1; n long long n, m, k; n vector<vector<int> > v; n vector<int> h; n vector<int> was; n bool comp(int a, int b) { return h[a] > h[b]; } n multiset<int, bool (*)(int, int)> s(comp); n void dfs(int x) { n   int o = 0; n   was[x] = 1; n   for (auto &y : (v[x])) { n     if (!was[y]) { n       dfs(y); n       o = max(o, h[y]); n     } n   } n   h[x] = o + 1; n } n void dfs1(int x) { n   was[x] = 1; n   int u, m = -1; n   for (auto &y : (v[x])) { n     if (!was[y]) { n       if (h[y] > m) { n         m = h[y]; n         u = y; n       } n     } n   } n   if (m == -1) return; n   for (auto &y : (v[x])) { n     if (!was[y]) { n       if (y == u) { n         dfs1(y); n       } else { n         s.insert(y); n       } n     } n   } n } n void solve() { n   long long a, b; n   cin >> n >> k; n   s.clear(); n   v.clear(); n   h.clear(); n   was.clear(); n   v.resize(n); n   h.resize(n); n   was.resize(n); n   for (long long i = 0; i < (n - 1); i++) { n     cin >> a >> b; n     a--; n     b--; n     v[a].push_back(b); n     v[b].push_back(a); n   } n   dfs(0); n   s.insert(0); n   fill(was.begin(), was.end(), 0); n   a = k; n   k = 0; n   while (k < a && !s.empty()) { n     k++; n     int x = *s.begin(); n     s.erase(s.begin()); n     dfs1(x); n   } n   long long mx = -((long long)1e15); n   long long e = count(was.begin(), was.end(), 1); n   if (k < a) { n     for (long long i = (k); i < (a + 1); i++) { n       mx = max(mx, (e - i) * (i)); n     } n   } else { n     mx = ((long long)1e15); n     long long p = count(was.begin(), was.end(), 0); n     for (long long i = (0); i < (p + 1); i++) { n       mx = min(mx, (e - a + (p - i)) * (a - i)); n     } n   } n   cout << mx <<   n ; n } n signed main(signed argc, char *argv[]) { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cout.precision(14); n   cout.fixed; n   srand(time(0)); n   fout.precision(14); n   fout.fixed; n   int tt = 1; n   while (tt--) { n     solve(); n   } n   fout.close(); n   fin.close(); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename First> n void debug_print_in(First first) { n   cerr << first << endl; n   return; n } n template <typename First, typename... Rest> n void debug_print_in(First first, Rest... rest) { n   cerr << first <<    ; n   debug_print_in(rest...); n   return; n } n void IN(void) { return; } n template <typename First, typename... Rest> n void IN(First& first, Rest&... rest) { n   cin >> first; n   IN(rest...); n   return; n } n template <typename First> n void OUT(First first) { n   cout << first << endl; n   return; n } n template <typename First, typename... Rest> n void OUT(First first, Rest... rest) { n   cout << first <<    ; n   OUT(rest...); n   return; n } n template <class t, class u> n t chmax(t& a, u b) { n   if (a < b) a = b; n   return a; n }; n template <class t, class u> n t chmin(t& a, u b) { n   if (a > b) a = b; n   return a; n }; n int popcount(int t) { return __builtin_popcount(t); } n int popcount(long long t) { return __builtin_popcountll(t); } n template <typename T> n void vec_print(vector<T> VEC) { n   for (long long i = (long long)0; i < (long long)VEC.size(); ++i) { n     cerr << VEC[i] <<    ; n   } n   cerr << endl; n }; n template <typename T> n void mat_print(vector<vector<T>> MAT) { n   for (long long i = (long long)0; i < (long long)MAT.size(); ++i) { n     for (long long j = (long long)0; j < (long long)MAT[i].size(); ++j) { n       cerr << MAT[i][j] <<    ; n     } n     cerr << endl; n   } n }; n constexpr int INF = (1 << 30); n constexpr long long INFLL = 1LL << 62; n constexpr long double EPS = 1e-12; n constexpr long long MOD = (long long)((1E+9) + 7); n int main() { n   cin.tie(0); n   ios::sync_with_stdio(false); n   long long n; n   IN(n); n   vector<long long> a(n); n   for (long long i = (long long)0; i < (long long)n; ++i) IN(a[i]); n   vector<long long> d1(n, -1); n   vector<long long> d2(n, -1); n   vector<long long> primes(1, 2); n   for (long long i = 3; i * i <= 2E7; i += 2) { n     bool flag = true; n     for (long long j = 0; primes[j] * primes[j] <= i; ++j) { n       if (i % primes[j] == 0) { n         flag = false; n         break; n       } n     } n     if (flag) { n       primes.push_back(i); n     } n   } n   for (long long i = (long long)0; i < (long long)n; ++i) { n     for (long long j = 0; primes[j] * primes[j] < a[i]; ++j) { n       long long d1_ = primes[j]; n       if (a[i] % d1_ != 0) continue; n       while (a[i] % d1_ == 0) { n         a[i] /= d1_; n       } n       if (a[i] > 1) { n         d1[i] = d1_; n         d2[i] = a[i]; n       } n       break; n     } n   } n   for (long long i = (long long)0; i < (long long)n; ++i) { n     printf( %lld  , d1[i]); n   } n   printf(  n ); n   for (long long i = (long long)0; i < (long long)n; ++i) { n     printf( %lld  , d2[i]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void read(T &x) { n   x = 0; n   char c = getchar(); n   bool flag = false; n   while (!isdigit(c)) { n     if (c ==  - ) flag = true; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = (x << 1) + (x << 3) + (c ^ 48); n     c = getchar(); n   } n   if (flag) x = -x; n } n int n; n int siz[110]; n double fac[110], f[110][110], g[110]; n struct edge { n   int to, nxt; n   edge(int a = 0, int b = 0) { to = a, nxt = b; } n } e[110]; n int head[110], edge_cnt; n void add(int from, int to) { n   e[++edge_cnt] = edge(to, head[from]), head[from] = edge_cnt; n } n double C(int n, int m) { return fac[n] / fac[m] / fac[n - m]; } n void dfs(int x, int fa) { n   f[x][0] = siz[x] = 1; n   for (int i = head[x]; i; i = e[i].nxt) { n     int y = e[i].to; n     if (y == fa) continue; n     dfs(y, x); n     for (int j = 0; j <= siz[y]; ++j) n       for (int k = 1; k <= siz[y]; ++k) n         f[0][j] += k <= j ? f[y][k - 1] / 2 : f[y][j]; n     for (int j = siz[x] - 1; j >= 0; --j) n       for (int k = siz[y]; k >= 0; --k) n         g[j + k] += f[x][j] * f[0][k] * C(j + k, j) * n                     C(siz[x] - 1 - j + siz[y] - k, siz[x] - 1 - j); n     siz[x] += siz[y]; n     for (int i = 0; i < siz[x]; ++i) f[x][i] = g[i]; n     memset(g, 0, sizeof(g)), memset(f[0], 0, sizeof(f[0])); n   } n } n int main() { n   read(n); n   for (int i = 1; i < n; ++i) { n     int x, y; n     read(x), read(y); n     add(x, y), add(y, x); n   } n   fac[0] = 1; n   for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i; n   for (int i = 1; i <= n; ++i) { n     memset(f, 0, sizeof(f)), dfs(i, 0); n     printf( %.10lf n , f[i][n - 1] / fac[n - 1]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int sc[1005]; n   int n, k, p, x, y; n   cin >> n >> k >> p >> x >> y; n   for (int i = 1; i <= k; i++) { n     cin >> sc[i]; n     x -= sc[i]; n   } n   if (x < 0) { n     cout << -1 << endl; n   } else { n     int i; n     int left_cnt = 0; n     int rig_cnt = 0; n     int equ_y_num = 0; n     int half = n / 2; n     sort(sc + 1, sc + k + 1); n     for (i = 1; i <= k; i++) { n       if (sc[i] < y) { n         left_cnt++; n       } else if (sc[i] == y) { n         equ_y_num++; n       } else { n         rig_cnt++; n       } n     } n     if (left_cnt > half) { n       cout << -1 << endl; n       return 0; n     } n     if (rig_cnt + equ_y_num >= (half + 1)) { n       int need = n - k; n       if (need > x) { n         cout << -1 << endl; n         return 0; n       } else { n         int time = n - k; n         while (time--) { n           cout << 1 <<    ; n         } n         cout << endl; n         return 0; n       } n     } n     int need = half + 1 - rig_cnt - equ_y_num; n     need = need * y; n     need += half - left_cnt; n     if (need > x) { n       cout << -1 << endl; n       return 0; n     } else { n       int time = n - k; n       int left_time = half - left_cnt; n       while ((left_time--)) { n         cout << 1 <<    ; n         time--; n       } n       while ((time--)) { n         cout << y <<    ; n       } n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 505; n vector<int> ans; n struct node { n   int val, id; n   bool operator<(const node &o) const { n     if (val == o.val) return id < o.id; n     return val < o.val; n   } n }; n node a[MAXN], b[MAXN]; n void doit(int n) { n   for (int i = 1; i <= n - 2; i++) { n     int id = i; n     for (int j = i; j <= n; j++) n       if (a[j] < a[id]) id = j; n     for (int j = id; j >= i; j--) { n       if (j - 2 >= i) { n         ans.push_back(j - 2); n         swap(a[j], a[j - 1]); n         swap(a[j - 1], a[j - 2]); n         j--; n       } else if (j - 1 >= i) { n         ans.push_back(j - 1); n         ans.push_back(j - 1); n         swap(a[j], a[j - 1]); n         swap(a[j], a[j + 1]); n       } n     } n   } n } n void solve() { n   ans.clear(); n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i].val); n     a[i].id = i; n   } n   memcpy(b, a, sizeof(a)); n   doit(n); n   if (a[n - 1].val > a[n].val) { n     memcpy(a, b, sizeof(a)); n     bool flag = false; n     for (int i = 1; i <= n && !flag; i++) n       for (int j = i + 1; j <= n && !flag; j++) n         if (a[i].val == a[j].val) { n           swap(a[i], a[j]); n           flag = true; n         } n     ans.clear(); n     doit(n); n     if (a[n - 1].val > a[n].val) { n       puts( -1 ); n       return; n     } n   } n   printf( %d n , ans.size()); n   for (auto v : ans) printf( %d  , v); n   puts(  ); n } n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   vector<int> records; n   int max = a[0]; n   records.push_back(0); n   int case1 = -1; n   int case1_records; n   for (int i = 1; i < n; i++) { n     if (max < a[i]) { n       max = a[i]; n       records.push_back(i); n     } else { n       if (case1 == -1) { n         case1 = i; n       } else { n         if (a[case1] > a[i]) { n           case1 = i; n         } n       } n     } n   } n   case1_records = records.size(); n   records.push_back(n); n   int case2 = -1; n   int case2_records = -1; n   int case2_pos = -1; n   for (int i = 0; i < records.size() - 1; i++) { n     int left = records[i]; n     int right = records[i + 1]; n     int count = 0; n     int max = 0; n     if (i > 0) { n       left = records[i - 1]; n       max = a[records[i - 1]]; n     } n     for (int j = left + 1; j < right; j++) { n       if (j != records[i]) n         if (max < a[j]) { n           max = a[j]; n           count++; n         } n     } n     if (case2 < count) { n       case2 = count; n       case2_pos = records[i]; n     } n   } n   case2_records = case1_records - 1 + case2; n   if (case1 == -1) { n     cout << a[case2_pos] << endl; n   } else { n     if (case1_records < case2_records) { n       cout << a[case2_pos] << endl; n     } else if (case1_records == case2_records) { n       cout << min(a[case1], a[case2_pos]) << endl; n     } else { n       cout << a[case1] << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC optimize( O2,no-stack-protector,unroll-loops,fast-math ) n const long long maxn = 1e5 + 10, maxm = 1e6 + 10, lg = 17, mod = 998244353, n                 inf = 1e18; n long long n, len, a, b, par[maxn][lg + 1], h[maxn], zuz[maxn], tguz; n pair<long long, long long> mx[maxn][4]; n vector<long long> g[maxn]; n bool kor[maxn]; n void dfd(long long v = 1, long long p = 0) { n   h[v] = h[p] + 1; n   par[v][0] = p; n   for (int i = 1; i <= lg; i++) par[v][i] = par[par[v][i - 1]][i - 1]; n   fill(mx[v], mx[v] + 4, make_pair(0, v)); n   for (auto u : g[v]) n     if (u != p) { n       dfd(u, v); n       mx[v][0] = mx[u][3]; n       mx[v][0].first++; n       sort(mx[v], mx[v] + 4); n     } n } n void dfu(long long v = 1, long long p = 0) { n   if (mx[v][1].first >= len) zuz[v]++, tguz++; n   for (auto u : g[v]) n     if (u != p) { n       mx[u][0] = (mx[v][3].second == mx[u][3].second ? mx[v][2] : mx[v][3]); n       mx[u][0].first++; n       sort(mx[u], mx[u] + 4); n       dfu(u, v); n       zuz[v] += zuz[u]; n     } n } n long long gup(long long v, long long x) { n   for (int i = 0; i <= lg; i++) n     if (x >> i & 1) v = par[v][i]; n   return v; n } n long long lca(long long v, long long u) { n   if (h[v] < h[u]) swap(v, u); n   v = gup(v, h[v] - h[u]); n   if (v == u) return v; n   for (int i = lg; i >= 0; i--) n     if (par[v][i] != par[u][i]) v = par[v][i], u = par[u][i]; n   return par[v][0]; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   long long T; n   cin >> T; n   while (T--) { n     cin >> n >> a >> b; n     for (int i = 1; i < n; i++) { n       long long v, u; n       cin >> v >> u; n       g[v].push_back(u), g[u].push_back(v); n     } n     dfd(); n     len = h[a] + h[b] - 2 * h[lca(a, b)]; n     dfu(); n     while (1) { n       long long ms; n       for (int i : {3, 2, 1, 0}) { n         long long na = mx[a][i].second; n         if (h[b] + h[na] - 2 * h[lca(b, na)] == len + mx[a][i].first) { n           ms = mx[a][i].first; n           a = na; n           break; n         } n       } n       long long o = lca(a, b); n       if (h[b] - h[o] >= ms) n         b = gup(b, ms); n       else { n         ms -= h[b] - h[o]; n         b = gup(a, h[a] - (h[o] + ms)); n       } n       if (kor[a]) { n         cout <<  NO n ; n         break; n       } n       o = lca(a, b); n       if (o == b) { n         if (zuz[gup(a, h[a] - h[b] - 1)] < tguz) { n           cout <<  YES n ; n           break; n         } n       } else if (zuz[b]) { n         cout <<  YES n ; n         break; n       } n       kor[a] = 1; n       swap(a, b); n     } n     for (int i = 1; i <= n; i++) { n       g[i].clear(), kor[i] = 0, h[i] = 0, zuz[i] = 0; n       memset(par[i], 0, sizeof(par[i])); n     } n     tguz = 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool visit[4]; n long long dfs(vector<long long> &v, vector<char> &chars) { n   long long res = LLONG_MAX; n   if (v.size() == 1) { n     return v.front(); n   } n   for (int i = 0; i < v.size() - 1; i++) { n     for (int j = i + 1; j < v.size(); j++) { n       vector<long long> tmp = v; n       tmp.erase(tmp.begin() + i); n       tmp.erase(tmp.begin() + j - 1); n       long long r = 0; n       if (chars.front() ==  + ) { n         r = v[i] + v[j]; n       } else { n         r = v[i] * v[j]; n       } n       tmp.push_back(r); n       vector<char> ch = chars; n       ch.erase(ch.begin()); n       res = min(res, dfs(tmp, ch)); n     } n   } n   return res; n } n int main() { n   vector<long long> v(4); n   vector<char> chars(3); n   for (int i = 0; i < 4; i++) { n     cin >> v[i]; n   } n   for (int i = 0; i < 3; i++) { n     cin >> chars[i]; n   } n   cout << dfs(v, chars) << endl; n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n const int N = 55; n  n void solve() n { n     int n; n     int ans=0; n     scanf( %d , &n); n     for(int i=1;i<=n;i++) n     { n         int x; n         scanf( %d , &x); n         if(x!=2)    ans++; n     } n     cout<<ans<<endl; n } n int  main() n { n     int t; n     scanf( %d , &t); n     while(t--)  solve(); n     return 0; n }


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


#include <bits/stdc++.h> n using namespace std; n void solve(void) { n   string a, b, c; n   cin >> a >> b >> c; n   int n = a.length(); n   for (int i = 0; i < n; i++) { n     if (c[i] != a[i] && c[i] != b[i]) { n       cout <<  NO n ; n       return; n     } n   } n   cout <<  YES n ; n } n int main(void) { n   ios_base ::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string mapp[105]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> mapp[i]; n   int sx = 0x3f3f3f3f, sy = 0x3f3f3f3f, ex = 0, ey = 0, cnt = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (mapp[i][j] ==  B ) { n         sx = min(sx, i); n         sy = min(sy, j); n         ex = max(ex, i); n         ey = max(ey, j); n         cnt++; n       } n     } n   } n   if (cnt == 0) { n     cout << 1; n     return 0; n   } n   int len = max(ex - sx + 1, ey - sy + 1); n   if (len > n || len > m) { n     cout << -1; n     return 0; n   } n   cout << len * len - cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int v, s, vs, sv; n void printAns() { n   cout <<  vier:   << v <<   sieben:   << s <<   vs:   << vs <<   sv:   << sv n        << endl; n } n int main() { n   cin >> v >> s >> vs >> sv; n   string ans =   ; n   bool flag = true; n   if (v < vs || s < vs || v < sv || v < sv) n     flag = false; n   else { n     for (int i = 0; i < vs; i++) ans +=  47 ; n     v -= vs; n     s -= vs; n     sv -= (vs - 1); n     if (sv > 2 || sv < 0) n       flag = false; n     else { n       if (sv == 1 || sv == 2) { n         if (v && sv) { n           ans +=  4 ; n           v--; n           sv--; n         } n         if (s && sv) { n           ans =  7  + ans; n           s--; n           sv--; n         } n       } n       if (s < 0 || v < 0 || sv != 0) n         flag = false; n       else { n         if (ans.empty()) { n           if (s && v) n             flag = false; n           else if (v) n             ans.insert(0, v,  4 ); n           else if (s) n             ans.insert(0, s,  7 ); n         } else { n           for (int i = 0; i < (int)ans.length(); i++) { n             if (!v && !s) n               break; n             else if (ans[i] ==  4  && v) { n               ans.insert(i, v,  4 ); n               v = 0; n             } n           } n           for (int i = ans.length() - 1; i >= 0; i--) { n             if (!v && !s) n               break; n             else if (ans[i] ==  7  && s) { n               ans.insert(i, s,  7 ); n               s = 0; n             } n           } n         } n       } n     } n   } n   if (flag) n     cout << ans << endl; n   else n     cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long GCD(long long a, long long b) { n   while (b != 0) { n     int t = a; n     a = b; n     b = t % b; n   } n   return a; n } n inline long long LCM(long long a, long long b) { n   if (a == 0 || b == 0) return GCD(a, b); n   return a * b / GCD(a, b); n } n inline long long CEIL(long long n, long long d) { return n / d + n % d != 0; } n inline long long ROUND(long long n, long long d) { n   return n / d + (long long)((n % d) * 2 >= d); n } n inline long long POW(long long a, long long n) { n   if (n < 0) return 0; n   long long ret = 1; n   while (n) { n     if (n % 2) ret *= a; n     a = a * a; n     n /= 2; n   } n   return ret; n } n const int MAXN = 101, INF = 100000; n struct node { n   node *l, *r, *p; n   int bdp[MAXN], mdp[MAXN]; n   node(node *p = 0) : l(0), r(0), p(p) { n     fill(bdp, bdp + MAXN, -INF); n     fill(mdp, mdp + MAXN, INF); n   } n   node *child() { n     if (!l) n       return l = new node(this); n     else n       return r = new node(this); n   } n } * root, *cur; n int p, m, n, op; n string str; n void input() { cin >> str >> p >> m; } n void dfs(node *u) { n   if (!u->l) { n     return; n   } n   node *l = u->l, *r = u->r; n   dfs(l), dfs(r); n   for (int(i) = (0); (i) < (int)(n + 1); ++(i)) { n     for (int(j) = (0); (j) < (int)(i + 1); ++(j)) { n       int k = i - j - (op == 1 ? 1 : 0); n       if (k >= 0) u->bdp[i] = max(u->bdp[i], l->bdp[j] + r->bdp[k]); n       if (k >= 0) u->mdp[i] = min(u->mdp[i], l->mdp[j] + r->mdp[k]); n       k = i - j - (op == -1 ? 1 : 0); n       if (k >= 0) u->bdp[i] = max(u->bdp[i], l->bdp[j] - r->mdp[k]); n       if (k >= 0) u->mdp[i] = min(u->mdp[i], l->mdp[j] - r->bdp[k]); n     } n   } n } n int solve() { n   if (p > m) n     n = m, op = -1; n   else n     n = p, op = 1; n   root = cur = new node(); n   for (int(i) = (0); (i) < (int)(str.size()); ++(i)) { n     switch (str[i]) { n       case  ( : n       case  ? : n         cur = cur->child(); n         break; n       case  ) : n         cur = cur->p; n         break; n       default: n         cur->bdp[0] = cur->mdp[0] = str[i] -  0 ; n         cur = cur->p; n     } n   } n   assert(cur == 0); n   dfs(root); n   cout << root->bdp[n] <<   n ; n   return 0; n } n void execute() { input(), solve(); } n int main(void) { n   cin.tie(0); n   ios_base::sync_with_stdio(false); n   execute(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 205; n int mat[maxn][maxn], tmp[maxn][maxn]; n int r[maxn], c[maxn]; n int n, m; n void invRow(int row) { n   for (int j = 1; j <= m; ++j) { n     tmp[row][j] ^= 1; n   } n } n void invCol(int col) { n   for (int i = 1; i <= n; ++i) { n     tmp[i][col] ^= 1; n   } n } n bool solve(int x, int y) { n   memset(tmp, 0, sizeof(tmp)); n   memset(r, 0, sizeof(r)); n   memset(c, 0, sizeof(c)); n   for (int i = x; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       if (i == x && j < y) n         tmp[i][j] = 0; n       else n         tmp[i][j] = 1; n     } n   } n   for (int i = 1; i <= n; ++i) r[i] = mat[i][1] ^ tmp[i][1] ^ c[1]; n   for (int j = 1; j <= m; ++j) c[j] = mat[1][j] ^ tmp[1][j] ^ r[1]; n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       if ((r[i] ^ c[j]) != (mat[i][j] ^ tmp[i][j])) return false; n     } n   } n   return true; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       scanf( %d , &mat[i][j]); n     } n   } n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       if (solve(i, j)) { n         puts( YES ); n         for (int i = 1; i <= n; ++i) printf( %d , r[i]); n         putchar(  n ); n         for (int j = 1; j <= m; ++j) printf( %d , c[j]); n         putchar(  n ); n         return 0; n       } n     } n   } n   puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a, b; n   cin >> a >> b; n   long long n, m, i, j, k = 200000; n   n = a.size(); n   m = b.size(); n   for (i = 1; i <= k; i++) { n     if (n - i >= 0 && m - i >= 0) { n       if (a[n - i] != b[m - i]) break; n     } else n       break; n   } n   cout << (n - i) + 1 + (m - i) + 1; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 500004; n long long p, pos1, pos2, q, x, l, ans = 0, r, y, z, k, n, m, t, d, c = 0, n                                   sum = 0; n long long int mn = 0x3f3f3f3f, len, cnt = 1, mx = -1000; n std::vector<int> v[MAX]; n string s[10004], s1, s2; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> s[i]; n     m += s[i].size(); n   } n   cin >> s1; n   int len = 2 * m / n; n   for (int i = 0; i < n; i++) s[i] += s1; n   sort(s, s + n); n   int a[n]; n   memset(a, (0), sizeof(a)); n   for (int i = 0; i < n / 2; i++) { n     for (int j = 0; j < n; j++) { n       if (!a[j]) { n         cout << s[j]; n         x = s[j].size(); n         ++a[j]; n         break; n       } n     } n     for (int j = 0; j < n; j++) { n       if (!a[j] and s[j].size() == len - x + 2) { n         cout << s[j].substr(0, s[j].size() - 1); n         ++a[j]; n         break; n       } n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long a, b, c, n, res; n int main() { n   cin >> a >> b >> c >> n; n   long s[n + 1]; n   for (long i = 1; i <= n; ++i) { n     cin >> s[i]; n     if (s[i] > b && s[i] < c) res++; n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int powermod(long long int B, long long int P, long long int M) { n   long long int r = 1; n   if (B >= M) B %= M; n   while (P > 0) { n     if ((P & 1) == 1) { n       r *= B; n       if (r >= M) r %= M; n     } n     P >>= 1; n     B *= B; n     if (B >= M) B %= M; n   } n   return r; n } n long long int modinv(long long int B, long long int M) { n   return powermod(B, M - 2, M); n } n int main() { n   long long int MOD = 1000000007LL; n   long long int A, B, N, x, res = 1; n   cin >> A >> B >> N >> x; n   if (A == 1) { n     res = x + B * (N % MOD); n   } else { n     long long int An = powermod(A, N, MOD); n     res = An * x; n     long long int tmp = B * (An - 1) % MOD; n     tmp = tmp * modinv(A - 1, MOD) % MOD; n     res += tmp; n   } n   res %= MOD; n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename X, typename Y> n static inline void xmin(X &x, Y y) { n   if (y < x) x = y; n } n template <typename X, typename Y> n static inline void xmax(X &x, Y y) { n   if (x < y) x = y; n } n long long pw(long long x, long long y, long long md) { n   if (!y) return 1; n   if (y & 1) return (x * pw(x, y - 1, md)) % md; n   long long tmp = pw(x, y / 2, md); n   return (tmp * tmp) % md; n } n int n, a[200001], sm[200001], seg[524288]; n void ins(int x, int v, int s = 1, int e = n, int i = 1) { n   seg[i] += v; n   int md = (s + e) / 2; n   if (s == e) return; n   if (x > md) n     ins(x, v, md + 1, e, 2 * i + 1); n   else n     ins(x, v, s, md, 2 * i); n } n int que(int x, int s = 1, int e = n, int i = 1) { n   if (s > x) return 0; n   if (e <= x) return seg[i]; n   int md = (s + e) / 2; n   return que(x, s, md, 2 * i) + que(x, md + 1, e, 2 * i + 1); n } n int elt(int x, int s = 1, int e = n, int i = 1) { n   if (s == e) return s; n   int md = (s + e) / 2; n   return seg[2 * i] >= x ? elt(x, s, md, 2 * i) n                          : elt(x - seg[2 * i], md + 1, e, 2 * i + 1); n } n void solve() { n   cin >> n; n   for (int i = 1; i <= n; ++i) cin >> a[i], ins(a[i] + 1, 1); n   for (int i = 1; i <= n; ++i) ins(a[i] + 1, -1), sm[i] = que(a[i] + 1); n   for (int i = 1; i <= n; ++i) cin >> a[i], ins(a[i] + 1, 1); n   for (int i = 1; i <= n; ++i) ins(a[i] + 1, -1), sm[i] += que(a[i] + 1); n   for (int i = n; i >= 1; --i) n     if (sm[i] > n - i) sm[i] -= n - i + 1, ++sm[i - 1]; n   for (int i = 1; i <= n; ++i) ins(i, 1); n   for (int i = 1; i <= n; ++i) { n     sm[i] = elt(sm[i] + 1); n     ins(sm[i], -1); n   } n   for (int i = 1; i <= n; ++i) cout << sm[i] - 1 <<    ; n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int TESTS = 1; n   while (TESTS--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool hell(vector<int>& v1, vector<int>& v2) { return v1.size() < v2.size(); } n int main() { n   int n; n   cin >> n; n   vector<vector<int> > f(100); n   int a[2 * n + 1]; n   for (int i = 1; i <= 2 * n; i++) { n     cin >> a[i]; n     f[a[i]].push_back(i); n   } n   int b[2 * n + 1]; n   int u = 1; n   sort(f.begin() + 10, f.end(), hell); n   for (int i = 10; i < 100; i++) { n     for (int j = 0; j < f[i].size(); j++) { n       b[f[i][j]] = u; n       if (u == 1) n         u = 2; n       else n         u = 1; n     } n   } n   int u1 = 0, u2 = 0; n   for (int i = 10; i < 100; i++) { n     if (f[i].size() == 0) { n       continue; n     } n     if (f[i].size() >= 2) { n       u1++; n       u2++; n     } else { n       if (b[f[i][0]] == 1) { n         u1++; n       } else n         u2++; n     } n   } n   cout << (u1 * u2) << endl; n   for (int i = 1; i <= 2 * n; i++) { n     cout << b[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, v; n int main() { n   cin >> n >> v; n   int ans = 0; n   int p = 1; n   int cur = 0; n   for (int i = n - 1; i >= 0; i--, p++) { n     if (cur >= i) continue; n     ans += p * (min(i, v - cur)); n     cur = cur + min(i, v - cur) - 1; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 810, maxn = 200010; n long long n, m, k, top, cnt, num; n struct wy { n   long long x, y, z; n } t[maxn]; n inline long long cmp(wy a, wy b) { return a.z < b.z; } n long long b[MAXN], c[MAXN], a[MAXN][MAXN], w[maxn]; n inline void discrete() { n   sort(b + 1, b + 1 + top); n   for (long long i = 1; i <= top; ++i) n     if (b[i] != b[i - 1]) c[++cnt] = b[i]; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> m >> k; n   for (long long i = 1; i <= m; ++i) { n     long long x, y, z; n     cin >> x >> y >> z; n     t[i] = (wy){x, y, z}; n   } n   sort(t + 1, t + 1 + m, cmp); n   for (long long i = 1; i <= ((m) > (k) ? (k) : (m)); ++i) { n     b[++top] = t[i].x; n     b[++top] = t[i].y; n   } n   discrete(); n   for (long long i = 1; i <= cnt; ++i) n     for (long long j = 1; j <= cnt; ++j) a[i][j] = 20000000000000000ll; n   for (long long i = 1; i <= ((m) > (k) ? (k) : (m)); ++i) { n     long long x = lower_bound(c + 1, c + 1 + cnt, t[i].x) - c; n     long long y = lower_bound(c + 1, c + 1 + cnt, t[i].y) - c; n     a[y][x] = a[x][y] = t[i].z; n   } n   for (long long p = 1; p <= cnt; ++p) { n     for (long long i = 1; i <= cnt; ++i) n       for (long long j = 1; j <= cnt; ++j) { n         a[i][j] = n             ((a[i][j]) > (a[i][p] + a[p][j]) ? (a[i][p] + a[p][j]) : (a[i][j])); n       } n   } n   for (long long i = 1; i <= cnt; ++i) n     for (long long j = i + 1; j <= cnt; ++j) c[++num] = a[i][j]; n   sort(c + 1, c + 1 + num); n   printf( %lld , c[k]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string n; n   int k = 0; n   cin >> n; n   if (n[0] <=  Z ) { n     for (int i = 0; i < n.size(); i++) { n       if (n[i] <=  Z ) k++; n     } n     if (k == n.size()) { n       transform(n.begin(), n.end(), n.begin(), (int (*)(int))tolower); n       cout << n; n     } else n       cout << n; n   } else { n     for (int i = 0; i < n.size(); i++) { n       if (n[i] <=  Z ) k++; n     } n     if (k == n.size() - 1) { n       transform(n.begin(), n.end(), n.begin(), (int (*)(int))tolower); n       n.at(0) = toupper(n.at(0)); n       cout << n; n     } else n       cout << n; n   } n } n


#include <bits/stdc++.h> n int main() { n   int tp, x, ans; n   while (~scanf( %d , &x)) { n     x = x < 0 ? -x : x, ans = ceil((-1 + sqrt(1 + 8.0 * x)) / 2), n     tp = ans * (ans + 1) / 2 - x; n     while (tp & 1) ans++, tp += ans; n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   { n     int t; n     cin >> t; n     long long int a[t]; n     for (int i = 0; i < t; i++) { n       cin >> a[i]; n       if (a[i] % 2 == 0 && a[i] != 0) n         cout << a[i] - 1 <<    ; n       else n         cout << a[i] <<    ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int T, a[260]; n int main() { n   scanf( %d , &T); n   while (T--) { n     int s = 0; n     int ct = 0; n     for (int i = 0; i < 250; i++) { n       scanf( %d , &a[i]); n       s += a[i]; n     } n     double ave = s / 250.0; n     for (int i = 0; i < 250; i++) { n       if (fabs(a[i] - ave) <= ave / 2) ct++; n     } n     if (ct > 250 * 0.75) n       printf( poisson n ); n     else n       printf( uniform n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } n int main() { n   int a, b; n   while (scanf( %d%d , &a, &b) != EOF) { n     int g = gcd(a, b); n     int x = -1, y = -1; n     for (int dx = 1; dx <= 1000; ++dx) n       for (int dy = 1; dy <= 1000; ++dy) n         if (dx * dx + dy * dy == g * g) x = dx, y = dy; n     if (x == -1 && y == -1) n       printf( NO n ); n     else { n       printf( YES n0 0 n ); n       if (a / g * y == b / g * x) swap(a, b); n       printf( %d %d n , a / g * x, a / g * y); n       printf( %d %d n , -b / g * y, b / g * x); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char str[200005]; n int arr[200005]; n int cum[200005]; n int main() { n   scanf( %s , &str); n   int n = strlen(str); n   int q, idx; n   scanf( %d , &q); n   while (q--) { n     scanf( %d , &idx); n     int l = idx, r = n - idx + 1; n     arr[l]++; n     arr[r + 1]--; n   } n   for (int i = 1; i <= n; i++) { n     cum[i] = cum[i - 1] + arr[i]; n   } n   for (int i = 0; i < n; i++) { n     if (cum[i + 1] % 2 == 0) { n       printf( %c , str[i]); n     } else { n       printf( %c , str[n - i - 1]); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long int n, m; n   cin >> n; n   cin >> m; n   char str[2002][2002]; n   long int A[10002][2]; n   long int cnt = 0; n   long int i, j; n   for (i = 0; i < n; i++) { n     cin >> str[i]; n     for (j = 0; j < m; j++) { n       if (str[i][j] ==  w ) { n         A[cnt][0] = i; n         A[cnt][1] = j; n         cnt++; n       } n     } n   } n   long int i_min = n, i_max = 0, j_min = m, j_max = 0; n   for (i = 0; i < cnt; i++) { n     if (A[i][0] < i_min) i_min = A[i][0]; n     if (A[i][0] > i_max) i_max = A[i][0]; n     if (A[i][1] < j_min) j_min = A[i][1]; n     if (A[i][1] > j_max) j_max = A[i][1]; n   } n   long int dim; n   long int Idy = -1; n   long int Idx = -1; n   if (i_max - i_min > j_max - j_min) { n     dim = i_max - i_min + 1; n     for (i = 0; i < cnt; i++) { n       if (A[i][0] != i_max && A[i][0] != i_min) { n         Idy = A[i][1]; n         break; n       } n     } n     if (Idy == -1) { n       if (m - j_min > dim) n         j_max = j_min + dim - 1; n       else { n         j_max = m - 1; n         j_min = j_max - dim + 1; n       } n     } else { n       if (j_max == j_min) { n         if (j_min + dim - 1 < m) n           j_max = j_min + dim - 1; n         else n           j_min = j_max - dim + 1; n       } else { n         if (Idy == j_min) n           j_max = j_min + dim - 1; n         else n           j_min = j_max - dim + 1; n       } n     } n   } else if (i_max - i_min < j_max - j_min) { n     dim = j_max - j_min + 1; n     for (i = 0; i < cnt; i++) { n       if (A[i][1] != j_max && A[i][1] != j_min) { n         Idx = A[i][0]; n         break; n       } n     } n     if (Idx == -1) { n       if (n - i_min > dim) n         i_max = i_min + dim - 1; n       else { n         i_max = n - 1; n         i_min = i_max - dim + 1; n       } n     } else { n       if (i_max == i_min) { n         if (i_min + dim - 1 < n) n           i_max = i_min + dim - 1; n         else n           i_min = i_max - dim + 1; n       } else { n         if (Idx == i_min) n           i_max = i_min + dim - 1; n         else n           i_min = i_max - dim + 1; n       } n     } n   } n   if (!((i_max < n) && (i_min >= 0) && (j_max < m) && (j_min >= 0))) { n     cout <<  -1  n          <<   n ; n     return 0; n   } n   long int cnt2 = 0; n   for (j = j_min; j <= j_max; j++) { n     if (str[i_min][j] ==  w ) n       cnt2++; n     else n       str[i_min][j] =  + ; n     if (i_max == i_min) continue; n     if (str[i_max][j] ==  w ) n       cnt2++; n     else n       str[i_max][j] =  + ; n   } n   for (i = i_min + 1; i < i_max; i++) { n     if (str[i][j_min] ==  w ) n       cnt2++; n     else n       str[i][j_min] =  + ; n     if (j_max == j_min) continue; n     if (str[i][j_max] ==  w ) n       cnt2++; n     else n       str[i][j_max] =  + ; n   } n   if (cnt == -1) { n     for (i = 0; i < 2000; i++) cout <<  w ; n     cout << endl; n     for (i = 1; i < 2000 - 1; i++) { n       cout <<  w ; n       for (j = 1; j < 1999; j++) cout <<  . ; n       cout <<  w ; n       cout << endl; n     } n     for (i = 0; i < 2000; i++) cout <<  w ; n     cout << endl; n     return 0; n   } n   if (cnt != cnt2) { n     cout <<  -1 n ; n     return 0; n   } n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) cout << str[i][j]; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1); n int n, ans = 0; n int b[1000001]; n int num; n void dfs(int u, int d) { n   if (u == n) { n     num = min(num, ans); n     return; n   } n   if (abs(b[u] - b[u - 1] - d) > 1) return; n   int d1 = b[u] - b[u - 1]; n   if (d1 < d) { n     b[u]++; n     ans++; n     dfs(u + 1, d); n     b[u]--; n     ans--; n   } else if (d1 > d) { n     b[u]--; n     ans++; n     dfs(u + 1, d); n     b[u]++; n     ans--; n   } else if (d1 == d) n     dfs(u + 1, d); n   return; n } n int main() { n   scanf( %d , &n); n   for (long long(i) = (0); (i) < (n); (i)++) scanf( %d , b + i); n   num = 2e7; n   dfs(1, b[1] - b[0]); n   dfs(1, b[1] - b[0] + 1); n   dfs(1, b[1] - b[0] - 1); n   b[0]++; n   ans = 1; n   dfs(1, b[1] - b[0]); n   dfs(1, b[1] - b[0] + 1); n   dfs(1, b[1] - b[0] - 1); n   b[0] -= 2; n   ans = 1; n   dfs(1, b[1] - b[0]); n   dfs(1, b[1] - b[0] + 1); n   dfs(1, b[1] - b[0] - 1); n   if (num < 2e7) n     printf( %d n , num); n   else n     puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void DBG() { cerr << endl; } n template <class Head, class... Tail> n void DBG(Head H, Tail... T) { n   cerr <<     << H; n   DBG(T...); n } n using ll = long long; n using ld = long double; n template <class T> n using vec = vector<T>; n template <class... Args> n inline void read(Args&... args) { n   ((cin >> args), ...); n } n template <class... Args> n inline void show(Args... args) { n   ((cout << args <<    ), ...); n } n template <class T1, class T2> n inline bool ckmin(T1& a, T2 b) { n   return a > b ? a = b, 1 : 0; n } n template <class T1, class T2> n inline bool ckmax(T1& a, T2 b) { n   return a < b ? a = b, 1 : 0; n } n template <class T> n inline void operator>>(istream& in, vector<T>& v) { n   for (auto i = 0; i < int(v.size()); i++) in >> v[i]; n } n template <class T> n inline void operator<<(ostream& out, const vector<T>& v) { n   for (auto i = 0; i < int(v.size()); i++) n     out << v[i] <<    n [i + 1 == int(v.size())]; n } n const int MOD = 7340033; n ll dp[31][4][1001]; n void solve() { n   int n, k; n   read(n, k); n   function<ll(int, int, int)> F = [&](int part, int idx, int rem) { n     if (part == 0 || idx == 4) return rem == 0 ? 1ll : 0ll; n     if (idx == 0 && rem == 0) return 1ll; n     if (~dp[part][idx][rem]) return dp[part][idx][rem]; n     ll cnt = 0; n     int new_rem = idx == 0 ? rem - 1 : rem; n     for (auto i = 0; i < new_rem + 1; i++) { n       cnt += F(part, idx + 1, i) * F(part - 1, 0, new_rem - i); n       cnt %= MOD; n     } n     return dp[part][idx][rem] = cnt; n   }; n   int part = 0; n   while (n > 1 && n % 2) n /= 2, part++; n   cout << F(part, 0, k) <<   n ; n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout << fixed << setprecision(12); n   cerr << fixed << setprecision(12); n   memset(dp, -1, sizeof(dp)); n   int _ = 1; n   cin >> _; n   for (auto i = 1; i < _ + 1; i++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = LONG_MAX; n const long long arr = 1000000; n bool comp(pair<string, long long> a, pair<string, long long> b) { n   return a.second > b.second; n } n int main(void) { n   long long n; n   cin >> n; n   vector<pair<long long, long long> > v; n   for (int i = 0; i < n + 1; i++) { n     long long x, y; n     cin >> x >> y; n     v.push_back({x, y}); n   } n   long long ans = 0; n   for (int i = 1; i < n; i++) { n     long long x1 = v[i - 1].first, y1 = v[i - 1].second; n     long long x2 = v[i].first, y2 = v[i].second; n     long long x3 = v[i + 1].first, y3 = v[i + 1].second; n     if (x1 == x2 && y2 > y1) { n       if (x3 < x1 && y3 > y1) ans++; n     } n     if (y1 == y2 && x2 > x1) { n       if (x3 > x1 && y3 > y1) ans++; n     } n     if (x1 == x2 && y2 < y1) { n       if (x3 > x1 && y3 < y1) ans++; n     } n     if (y1 == y2 && x2 < x1) { n       if (x3 < x1 && y3 < y1) ans++; n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long Mod = 7 + 1e9; n const long long INF32 = 5 + 2e9; n const long long INF64 = 1 + 1e18; n const long long MAX = 5 + 3e5; n int N, M, ans = 4; n int main() { n   cin >> N >> M; n   for (int i = 1; i <= N; i++) n     for (int j = 1; j <= M; j++) { n       bool b; n       cin >> b; n       if (b && (i == 1 || j == 1 || i == N || j == M)) { n         ans = 2; n         break; n       } n     } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T1, typename T2> n inline void chkmin(T1 &x, T2 y) { n   if (x > y) x = y; n } n template <typename T1, typename T2> n inline void chkmax(T1 &x, T2 y) { n   if (x < y) x = y; n } n template <typename T, typename U> n inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) { n   _out << _p.first <<     << _p.second; n   return _out; n } n template <typename T, typename U> n inline istream &operator>>(istream &_in, pair<T, U> &_p) { n   _in >> _p.first >> _p.second; n   return _in; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const vector<T> &_v) { n   if (_v.empty()) { n     return _out; n   } n   _out << _v.front(); n   for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { n     _out <<     << *_it; n   } n   return _out; n } n template <typename T> n inline istream &operator>>(istream &_in, vector<T> &_v) { n   for (auto &_i : _v) { n     _in >> _i; n   } n   return _in; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const set<T> &_s) { n   if (_s.empty()) { n     return _out; n   } n   _out << *_s.begin(); n   for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { n     _out <<     << *_it; n   } n   return _out; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const multiset<T> &_s) { n   if (_s.empty()) { n     return _out; n   } n   _out << *_s.begin(); n   for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { n     _out <<     << *_it; n   } n   return _out; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) { n   if (_s.empty()) { n     return _out; n   } n   _out << *_s.begin(); n   for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { n     _out <<     << *_it; n   } n   return _out; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) { n   if (_s.empty()) { n     return _out; n   } n   _out << *_s.begin(); n   for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { n     _out <<     << *_it; n   } n   return _out; n } n template <typename T, typename U> n inline ostream &operator<<(ostream &_out, const map<T, U> &_m) { n   if (_m.empty()) { n     return _out; n   } n   _out <<  (  << _m.begin()->first <<  :   << _m.begin()->second <<  ) ; n   for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { n     _out <<  , (  << _it->first <<  :   << _it->second <<  ) ; n   } n   return _out; n } n template <typename T, typename U> n inline ostream &operator<<(ostream &_out, const unordered_map<T, U> &_m) { n   if (_m.empty()) { n     return _out; n   } n   _out <<  (  << _m.begin()->first <<  :   << _m.begin()->second <<  ) ; n   for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { n     _out <<  , (  << _it->first <<  :   << _it->second <<  ) ; n   } n   return _out; n } n const string FILENAME =  input ; n const int MAXN = 100228; n long long gettr(long long A, long long B, long long C) { n   if (C < 0) { n     return 0; n   } n   if (A > B) { n     swap(A, B); n   } n   long long p = C / B; n   long long k = B / A; n   long long d = (C - p * B) / A; n   return gettr(B - k * A, A, C - A * (k * p + d + 1)) + (p + 1) * (d + 1) + n          k * p * (p + 1) / 2; n } n long long get(long long A, long long cnta, long long B, long long cntb, n               long long C) { n   if (C >= A * cnta + B * cntb) { n     return cnta * cntb; n   } n   if (C < 0) { n     return 0; n   } n   return gettr(A, B, C) - gettr(A, B, C - A * cnta) - n          gettr(A, B, C - B * cntb) + gettr(A, B, C - A * cnta - B * cntb); n } n int gcd(int a, int b) { n   if (a == 0) { n     return b; n   } n   return gcd(b % a, a); n } n int n; n int a[MAXN]; n int d[MAXN * 4]; n long long cnt[MAXN]; n int spusk(int v, int vl, int vr, int l, int x) { n   if (d[v] % x == 0) { n     return -1; n   } n   if (vr < l) { n     return -1; n   } n   if (vl == vr) { n     return vl; n   } n   int t = spusk(v * 2, vl, (vl + vr) / 2, l, x); n   if (t != -1) { n     return t; n   } n   return spusk(v * 2 + 1, (vl + vr) / 2 + 1, vr, l, x); n } n long long pref[MAXN]; n long long prefs[MAXN]; n long long check(long long mid) { n   long long ans = 0; n   for (int i = 1; i < n; i++) { n     if (cnt[i] > 0) { n       long long s = min(cnt[i], mid / i); n       ans += s * (cnt[i] + 1) - s * (s + 1) / 2; n     } n   } n   int uk = 1; n   for (int i = 1; i < n; i++) { n     if (cnt[i] == 0) { n       continue; n     } n     if (i < uk) { n       ans += cnt[i] * (pref[uk - 1] - pref[i]); n     } n     while (uk < n && prefs[uk] - prefs[i] <= mid) { n       if (i < uk && cnt[uk] > 0) { n         ans += get(i, cnt[i], uk, cnt[uk], n                    mid - (prefs[uk - 1] - prefs[i]) - i - uk); n       } n       uk++; n     } n     if (uk == n) { n       continue; n     } n     ans += n         get(i, cnt[i], uk, cnt[uk], mid - (prefs[uk - 1] - prefs[i]) - i - uk); n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   int ss = 1; n   while (ss < n) { n     ss <<= 1; n   } n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     d[ss + i] = a[i]; n   } n   for (int i = ss - 1; i >= 1; i--) { n     d[i] = gcd(d[i * 2], d[i * 2 + 1]); n   } n   for (int i = 0; i < n; i++) { n     int cur = i; n     int need = 0; n     while (cur < n) { n       need = gcd(need, a[cur]); n       int pos = spusk(1, 1, ss, cur + 1, need) - 1; n       if (pos == -2) { n         pos = n; n       } n       cnt[need] += pos - cur; n       cur = pos; n     } n   } n   long long m = 1LL * n * (n + 1) / 2; n   m = m * (m + 1) / 2; n   m = (m + 1) / 2; n   n = 100001; n   for (int i = 1; i < n; i++) { n     pref[i] = pref[i - 1] + cnt[i]; n     prefs[i] = prefs[i - 1] + cnt[i] * i; n   } n   long long l = 1, r = prefs[n - 1]; n   while (l != r) { n     long long mid = (l + r) / 2; n     if (check(mid) >= m) { n       r = mid; n     } else { n       l = mid + 1; n     } n   } n   cout << r <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = (int)1e9 + 7; n long long int pow(long long int base, long long int exp, int m) { n   if (exp == 0) n     return 1; n   else if (exp == 1) n     return base; n   long long int root = pow(base, exp >> 1, m); n   if ((exp & 1) == 0) n     return (root * root) % m; n   else n     return (((root * root) % m) * base) % m; n } n long long int fact[(int)1e6]; n long long int ncr(int n, int r) { n   return (((fact[n] * pow(fact[n - r], mod - 2, mod)) % mod) * n           pow(fact[r], mod - 2, mod)) % n          mod; n } n void solve(long long int *a, int n) { n   if (n == 2) { n     cout << (a[0] + a[1]) % mod; n     return; n   } n   int last = 1, i, j; n   for (i = n; i > 2; i--) { n     if (i % 2 == 0) { n       last *= -1; n     } n   } n   j = n / 2; n   long long int p1 = 0, p2 = 0; n   for (i = 0; i < n; i += 2) { n     long long int v = ncr(j - 1, i / 2); n     v = v * a[i]; n     v %= mod; n     p1 = (p1 + v) % mod; n   } n   for (i = 1; i < n; i += 2) { n     long long int v = ncr(j - 1, i / 2); n     v = (v * a[i]) % mod; n     p2 = (p2 + v) % mod; n   } n   p2 *= last; n   p1 += p2; n   p1 %= mod; n   if (p1 < 0) p1 += mod; n   cout << p1; n } n int main() { n   int t, n, m, i, j, k, l, p; n   cin >> n; n   fact[0] = 1; n   for (i = 1; i < (int)3e5; i++) { n     fact[i] = fact[i - 1] * i; n     fact[i] %= mod; n   } n   long long int a[n]; n   for (int i = 0; i < n; ++i) { n     scanf( %lld , a + i); n   } n   if (n == 1) { n     cout << a[0]; n     return 0; n   } n   if (n % 2 == 0) n     solve(a, n); n   else { n     long long int tmp[n - 1]; n     p = 1; n     for (i = 0; i < n - 1; i++) { n       tmp[i] = a[i] + (p * a[i + 1]); n       tmp[i] %= mod; n       if (tmp[i] < 0) tmp[i] += mod; n       p *= -1; n     } n     solve(tmp, n - 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> v(n); n     for (int i = 0; i < n; i++) cin >> v[i]; n     int mn = INT_MAX; n     int cnt = 0; n     for (int i = n - 1; i >= 0; i--) { n       if (v[i] > mn) cnt++; n       mn = min(mn, v[i]); n     } n     cout << cnt <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n std::istream& operator>>(std::istream& i, pair<T, U>& p) { n   i >> p.first >> p.second; n   return i; n } n template <typename T> n std::istream& operator>>(std::istream& i, vector<T>& t) { n   for (auto& v : t) { n     i >> v; n   } n   return i; n } n template <typename T, typename U> n std::ostream& operator<<(std::ostream& o, const pair<T, U>& p) { n   o << p.first <<     << p.second; n   return o; n } n template <typename T> n std::ostream& operator<<(std::ostream& o, const vector<T>& t) { n   if (t.empty()) o <<   n ; n   for (size_t i = 0; i < t.size(); ++i) { n     o << t[i] <<    n [i == t.size() - 1]; n   } n   return o; n } n template <typename T> n using minheap = priority_queue<T, vector<T>, greater<T>>; n template <typename T> n using maxheap = priority_queue<T, vector<T>, less<T>>; n unsigned int logceil(long long first) { n   return first ? 8 * sizeof(long long) - __builtin_clzll(first) : 0; n } n namespace std { n template <typename T, typename U> n struct hash<pair<T, U>> { n   hash<T> t; n   hash<U> u; n   size_t operator()(const pair<T, U>& p) const { n     return t(p.first) ^ (u(p.second) << 7); n   } n }; n }  // namespace std n template <typename T, typename F> n T bsh(T l, T h, const F& f) { n   T r = -1, m; n   while (l <= h) { n     m = (l + h) / 2; n     if (f(m)) { n       l = m + 1; n       r = m; n     } else { n       h = m - 1; n     } n   } n   return r; n } n template <typename F> n double bshd(double l, double h, const F& f, double p = 1e-9) { n   unsigned int r = 3 + (unsigned int)log2((h - l) / p); n   while (r--) { n     double m = (l + h) / 2; n     if (f(m)) { n       l = m; n     } else { n       h = m; n     } n   } n   return (l + h) / 2; n } n template <typename T, typename F> n T bsl(T l, T h, const F& f) { n   T r = -1, m; n   while (l <= h) { n     m = (l + h) / 2; n     if (f(m)) { n       h = m - 1; n       r = m; n     } else { n       l = m + 1; n     } n   } n   return r; n } n template <typename F> n double bsld(double l, double h, const F& f, double p = 1e-9) { n   unsigned int r = 3 + (unsigned int)log2((h - l) / p); n   while (r--) { n     double m = (l + h) / 2; n     if (f(m)) { n       h = m; n     } else { n       l = m; n     } n   } n   return (l + h) / 2; n } n template <typename T> n T gcd(T a, T b) { n   if (a < b) swap(a, b); n   return b ? gcd(b, a % b) : a; n } n template <typename T> n class vector2 : public vector<vector<T>> { n  public: n   vector2() {} n   vector2(size_t a, size_t b, T t = T()) n       : vector<vector<T>>(a, vector<T>(b, t)) {} n }; n template <typename T> n class vector3 : public vector<vector2<T>> { n  public: n   vector3() {} n   vector3(size_t a, size_t b, size_t c, T t = T()) n       : vector<vector2<T>>(a, vector2<T>(b, c, t)) {} n }; n template <typename T> n class vector4 : public vector<vector3<T>> { n  public: n   vector4() {} n   vector4(size_t a, size_t b, size_t c, size_t d, T t = T()) n       : vector<vector3<T>>(a, vector3<T>(b, c, d, t)) {} n }; n template <typename T> n class vector5 : public vector<vector4<T>> { n  public: n   vector5() {} n   vector5(size_t a, size_t b, size_t c, size_t d, size_t e, T t = T()) n       : vector<vector4<T>>(a, vector4<T>(b, c, d, e, t)) {} n }; n class DAlmostAll { n  public: n   int N; n   vector<vector<int>> E; n   vector<int> S; n   vector<pair<std::pair<int, int>, int>> Ans; n   int size(int u, int p) { n     S[u] = 1; n     for (int v : E[u]) n       if (v != p) S[u] += size(v, u); n     return S[u]; n   } n   void fill(int u, int p, int& cnt, int par, long long mul) { n     int mine = cnt; n     long long val = (cnt - par) * mul; n     val = min(1000000LL, val); n     Ans.push_back({{u + 1, p + 1}, val}); n     cnt++; n     for (int v : E[u]) n       if (v != p) { n         fill(v, u, cnt, mine, mul); n       } n   } n   int centroid(int u, int p) { n     int m = N - S[u]; n     for (int v : E[u]) n       if (v != p) m = max(m, S[v]); n     if (2 * m <= N) return u; n     for (int v : E[u]) n       if (v != p && 2 * S[v] > N) return centroid(v, u); n     return -1; n   } n   void solve(istream& cin, ostream& cout) { n     cin >> N; n     E.resize(N); n     for (int i = 0; i < N - 1; ++i) { n       int u, v; n       cin >> u >> v; n       --u; n       --v; n       E[u].push_back(v); n       E[v].push_back(u); n     } n     S.assign(N, 0); n     size(0, -1); n     int ctr = centroid(0, -1); n     long long mul = 1; n     int M = E[ctr].size(); n     size(ctr, -1); n     vector2<bool> B(M + 1, N + 1, false); n     B[0][0] = true; n     for (int i = 0; i < M; ++i) { n       for (int j = 0; j <= N; ++j) { n         if (B[i][j]) { n           B[i + 1][j] = true; n           B[i + 1][j + S[E[ctr][i]]] = true; n         } n       } n     } n     for (int i = 0; i <= N; ++i) { n       if (B[M][i] && (i + 1) * (N - i - 1) + i >= 2 * N * N / 9) { n         vector<bool> Left(M, false); n         int first = i; n         for (int j = M - 1; j >= 0; --j) { n           if (!B[j][first]) { n             Left[j] = true; n             first -= S[E[ctr][j]]; n           } n         } n         int c1 = 1, c2 = 1; n         for (int j = 0; j < M; ++j) { n           if (Left[j]) { n             fill(E[ctr][j], ctr, c1, 0, 1); n           } else { n             fill(E[ctr][j], ctr, c2, 0, i + 1); n           } n         } n         for (auto a : Ans) { n           cout << a <<   n ; n         } n         break; n       } n     } n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   DAlmostAll solver; n   std::istream& in(std::cin); n   std::ostream& out(std::cout); n   solver.solve(in, out); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n int n, m; n int a[maxn]; n int b[maxn]; n int ans[maxn]; n int main() { n   cin >> n >> m; n   int num = 0; n   for (int i = 0; i < m; i++) { n     scanf( %d , a + i); n     if (b[a[i]] == 0) num++; n     b[a[i]]++; n     if (num == n) { n       ans[i] = 1; n       num = 0; n       for (int j = 1; j <= n; j++) { n         b[j]--; n         if (b[j] > 0) num++; n       } n     } else { n       ans[i] = 0; n     } n   } n   for (int i = 0; i < m; i++) { n     printf( %d , ans[i]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 myrand(time(0)); n bool isprime(long long n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (long long i = 5; i * i <= n; i += 6) { n     if (n % i == 0 || n % (i + 2) == 0) return false; n   } n   return true; n } n long long modexp(long long a, long long b, long long m) { n   long long r = 1; n   a = a % m; n   while (b > 0) { n     if (b & 1) r = (r * a) % m; n     b = b >> 1; n     a = (a * a) % m; n   } n   return r % m; n } n long long builtin_popcount(long long x) { n   long long cnt = 0; n   for (long long i = 60; i >= 0; i--) { n     if ((1LL << i) & x) cnt++; n   } n   return cnt; n } n long long addmod(long long a, long long b) { n   a %= 1000000007; n   b %= 1000000007; n   return (a + b) % 1000000007; n } n long long mulmod(long long a, long long b) { n   a %= 1000000007; n   b %= 1000000007; n   return (a * b) % 1000000007; n } n long long submod(long long a, long long b) { n   a %= 1000000007; n   b %= 1000000007; n   a -= b; n   if (a < 0) a += 1000000007; n   return a % 1000000007; n } n struct CustomCompare { n   bool operator()(pair<long long, long long> a, pair<long long, long long> b) { n     return a.first < b.first; n   } n }; n long long n, m, d; n vector<vector<long long> > g; n vector<long long> arr; n void dfs(long long src, vector<long long> &dp, long long par = -1) { n   dp[src] = (par != -1 ? dp[par] + 1LL : 0LL); n   for (auto x : g[src]) { n     if (x != par) dfs(x, dp, src); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m >> d; n   g = vector<vector<long long> >(n); n   arr = vector<long long>(m); n   vector<long long> vis(n, 0); n   for (int i = 0; i < m; i++) cin >> arr[i], arr[i]--, vis[arr[i]] = 1; n   for (int i = 1; i < n; i++) { n     long long u, v; n     cin >> u >> v; n     --u, --v; n     g[u].push_back(v), g[v].push_back(u); n   } n   vector<long long> dp(n, 0); n   dfs(0, dp); n   long long a = -1, mx = -1000000007; n   for (int i = 0; i < n; i++) { n     if (mx < dp[i] && vis[i]) { n       mx = dp[i]; n       a = i; n     } n     dp[i] = 0; n   } n   dfs(a, dp); n   long long b = -1; n   mx = -1000000007; n   for (int i = 0; i < n; i++) { n     if (mx < dp[i] && vis[i]) { n       mx = dp[i]; n       b = i; n     } n   } n   vector<long long> dp2(n); n   dfs(b, dp2); n   long long ans = 0; n   for (int i = 0; i < n; i++) n     if (dp[i] <= d && dp2[i] <= d) ans++; n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using pii = pair<int, int>; n template <typename... T> n void rd(T&... args) { n   ((cin >> args), ...); n } n template <typename... T> n void wr(T... args) { n   ((cout << args <<    ), ...); n   cout << endl; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int tt; n   cin >> tt; n   while (tt--) { n     int n; n     cin >> n; n     vector<int> a(n), l(n); n     for (auto& i : a) cin >> i; n     for (auto& i : l) cin >> i; n     vector<int> tmp; n     for (int i = 0; i < n; i++) { n       if (!l[i]) { n         tmp.push_back(a[i]); n       } n     } n     sort(tmp.begin(), tmp.end()); n     for (int i = 0; i < n; i++) { n       if (l[i]) n         cout << a[i] <<    ; n       else { n         cout << tmp.back() <<    ; n         tmp.pop_back(); n       } n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string x; n   cin >> x; n   int sum = 0, s; n   s = x.size(); n   for (int i = 0; i < x.size(); i++) { n     if (x[i] == x[s - i - 1] && n         (x[i] ==  A  || x[i] ==  H  || x[i] ==  I  || x[i] ==  M  || n          x[i] ==  O  || x[i] ==  T  || x[i] ==  U  || x[i] ==  V  || n          x[i] ==  W  || x[i] ==  X  || x[i] ==  Y )) n       sum++; n   } n   if (sum == s) { n     cout <<  YES ; n     return 0; n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   vector<long long> v; n   long long last; n   int q, a, b, lo, hi, one, two; n   long double aa, bb; n   cin >> q; n   cout << fixed; n   cout << setprecision(6); n   while (q--) { n     cin >> a; n     if (a == 1) { n       cin >> b; n       if (v.size() == 0) { n         v.push_back(b); n       } else { n         v.push_back(b); n         v.back() += v[v.size() - 2]; n       } n     } else { n       lo = 0; n       hi = v.size() - 2; n       if (hi < 0) { n         cout << (long double)0 <<   n ; n         continue; n       } n       last = v.back() - v[v.size() - 2]; n       while (lo < hi) { n         one = ((hi - lo) / 3) + lo; n         two = hi - ((hi - lo) / 3); n         aa = (long double)(v[one] + last) / (long double)(one + 2); n         bb = (long double)(v[two] + last) / (long double)(two + 2); n         if (aa < bb) { n           hi = two - 1; n         } else { n           lo = one + 1; n         } n       } n       aa = (long double)(v[lo] + last) / (long double)(lo + 2); n       aa = (long double)last - aa; n       cout << aa <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int n; n int main() { n   cin >> n; n   long long int cnt = 0, c; n   for (long long int i = 2; i <= sqrt(n); i++) { n     if (n % i == 0) cnt++; n   } n   if (cnt == 0) { n     cout << n; n     goto skip; n   } n   for (long long int i = 2; i <= sqrt(n); i++) n     if (n % i == 0) { n       c = i; n       break; n     } n   while (n % c == 0) { n     n /= c; n   } n   if (n == 1) { n     cout << c; n   } else { n     cout << 1; n   } n skip:; n   return 0; n } n


#include <bits/stdc++.h> n template <typename T> n T gcd(T a, T b) { n   if (!b) return a; n   return gcd(b, a % b); n } n template <typename T> n T lcm(T a, T b) { n   return a * b / gcd(a, b); n } n template <typename T> n void chmin(T& a, T b) { n   a = (a > b) ? b : a; n } n template <typename T> n void chmax(T& a, T b) { n   a = (a < b) ? b : a; n } n int in() { n   int x; n   scanf( %d , &x); n   return x; n } n using namespace std; n const int MAXN = 502; n int N, M; n int P[MAXN][MAXN]; n vector<int> G[MAXN], GA[MAXN]; n vector<int> comp; n bool vis[MAXN]; n int color[MAXN]; n void dfs(int x) { n   vis[x] = true; n   for (int i = 0; i < (int)GA[x].size(); i++) { n     int u = G[x][i]; n     if (!vis[u]) { n       dfs(u); n     } n   } n } n bool dfs_color(int node, int c) { n   if (color[node] != 0) { n     if (color[node] == c) { n       return true; n     } else { n       return false; n     } n   } n   color[node] = c; n   for (int i = 0; i < (int)GA[node].size(); i++) { n     if (!dfs_color(GA[node][i], -c)) { n       return false; n     } n   } n   return true; n } n int main(void) { n   cin >> N >> M; n   string S(N,  b ); n   for (int i = 0; i < M; i++) { n     int A, B; n     cin >> A >> B; n     A -= 1; n     B -= 1; n     P[A][B] = 1; n     P[B][A] = 1; n     G[A].push_back(B); n     G[B].push_back(A); n   } n   bool valid = true; n   for (int i = 0; i < N; i++) { n     for (int j = i; j < N; j++) { n       if (i != j && !P[i][j]) { n         GA[i].push_back(j); n         GA[j].push_back(i); n       } n     } n   } n   for (int i = 0; i < N; i++) { n     if (!vis[i] && GA[i].size() > 0) { n       comp.push_back(i); n     } n   } n   for (int i = 0; i < (int)comp.size(); i++) { n     if (color[comp[i]] == 0 && !dfs_color(comp[i], 1)) { n       valid = false; n     } n   } n   for (int i = 0; i < N; i++) { n     if (color[i] == -1) { n       S[i] =  a ; n     } n     if (color[i] == 1) { n       S[i] =  c ; n     } n   } n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < N; j++) { n       if (i != j) { n         if (P[i][j] && abs(S[i] - S[j]) > 1) { n           valid = false; n         } n         if (!P[i][j] && abs(S[i] - S[j]) <= 1) { n           valid = false; n         } n       } n     } n   } n   if (valid) { n     cout <<  Yes n  << S <<   n ; n   } else { n     cout <<  No n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int add(int x, int y) { return ((x + y) % 998244353 + 998244353) % 998244353; } n int mul(int x, int y) { return (long long)x * y % 998244353; } n int mypow(int x, int c) { n   int ret = 1; n   while (c > 0) { n     if (c & 1) { n       ret = mul(ret, x); n     } n     c /= 2; n     x = mul(x, x); n   } n   return ret; n } n int seg[200002 * 4], ad[200002 * 4], mm[200002 * 4]; n void init(int pos, int l, int r) { n   mm[pos] = 1; n   if (l == r) { n     return; n   } n   int mid = (l + r) / 2; n   init(pos * 2, l, mid); n   init(pos * 2 + 1, mid + 1, r); n } n void push(int pos, int l, int r) { n   seg[pos] = mul(seg[pos], mm[pos]); n   seg[pos] = add(seg[pos], mul(r - l + 1, ad[pos])); n   if (l != r) { n     mm[pos * 2] = mul(mm[pos], mm[pos * 2]); n     mm[pos * 2 + 1] = mul(mm[pos], mm[pos * 2 + 1]); n     ad[pos * 2] = add(mul(ad[pos * 2], mm[pos]), ad[pos]); n     ad[pos * 2 + 1] = add(mul(ad[pos * 2 + 1], mm[pos]), ad[pos]); n   } n   mm[pos] = 1; n   ad[pos] = 0; n } n void update(int pos, int l, int r, int ql, int qr, int m, int a) { n   push(pos, l, r); n   if (r < ql || qr < l) { n     return; n   } n   if (ql <= l && r <= qr) { n     mm[pos] = mul(mm[pos], m); n     ad[pos] = add(mul(m, ad[pos]), a); n     push(pos, l, r); n     return; n   } n   int mid = (l + r) / 2; n   update(pos * 2, l, mid, ql, qr, m, a); n   update(pos * 2 + 1, mid + 1, r, ql, qr, m, a); n   seg[pos] = add(seg[pos * 2], seg[pos * 2 + 1]); n } n int query(int pos, int l, int r, int ql, int qr) { n   push(pos, l, r); n   if (r < ql || qr < l) { n     return 0; n   } n   if (ql <= l && r <= qr) { n     return seg[pos]; n   } n   int mid = (l + r) / 2; n   return add(query(pos * 2, l, mid, ql, qr), n              query(pos * 2 + 1, mid + 1, r, ql, qr)); n } n set<pair<int, int> > s[200002]; n void solve() { n   int n, q; n   scanf( %d %d  , &n, &q); n   init(1, 1, n); n   for (int i = n; i; --i) { n     s[i].insert({n + 2, 0}); n   } n   while (q--) { n     int type, l, r; n     scanf( %d %d %d  , &type, &l, &r); n     if (type == 1) { n       int x; n       scanf( %d  , &x); n       int ml = l, mr = r; n       int cur = l; n       set<pair<int, int> >::iterator it = s[x].lower_bound({l + 1, 0}); n       if (it != s[x].begin()) { n         it = prev(it); n         pair<int, int> t = *it; n         if (t.second + 1 >= l) { n           ml = min(ml, t.first); n           mr = max(mr, t.second); n           s[x].erase(it); n           update(1, 1, n, l, min(r, t.second), 2, 0); n           cur = t.second + 1; n         } n       } n       while (true) { n         set<pair<int, int> >::iterator it = s[x].lower_bound({cur, 0}); n         pair<int, int> tmp = *it; n         if (tmp.first <= r + 1) { n           if (cur < tmp.first) { n             update(1, 1, n, cur, min(r, tmp.first - 1), 1, 1); n           } n           if (tmp.first <= r) { n             update(1, 1, n, tmp.first, min(tmp.second, r), 2, 0); n           } n           cur = tmp.second + 1; n           mr = max(mr, tmp.second); n           s[x].erase(it); n         } else { n           if (cur <= r) { n             update(1, 1, n, cur, r, 1, 1); n           } n           break; n         } n       } n       s[x].insert({ml, mr}); n     } else { n       printf( %d n , query(1, 1, n, l, r)); n     } n   } n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long a, b; n   cin >> a >> b; n   if (b / 2 >= a) n     cout << (b % (b / 2 + 1)); n   else n     cout << b % a; n   cout <<   n ; n   return; n } n signed main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   srand(time(NULL)); n   long long t = 1; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 15; n const int M = 20; n bool used[N]; n vector<int> adj[N]; n int a[N], b[N], w[N]; n int out[N]; n int dsu[N]; n int f(int x) { return dsu[x] == x ? x : dsu[x] = f(dsu[x]); } n bool merge(int id) { n   int u = f(a[id]), v = f(b[id]); n   if (u != v) { n     dsu[u] = v; n     return true; n   } n   return false; n } n int anc[N][M], wa[N][M]; n int depth[N]; n void construct(int node, int par) { n   for (int i = 1; i < M; ++i) { n     anc[node][i] = anc[anc[node][i - 1]][i - 1]; n     wa[node][i] = max(wa[node][i - 1], wa[anc[node][i - 1]][i - 1]); n   } n   for (int eid : adj[node]) { n     int ch = a[eid] ^ b[eid] ^ node; n     if (ch != par) { n       depth[ch] = depth[node] + 1; n       anc[ch][0] = node; n       wa[ch][0] = w[eid]; n       construct(ch, node); n     } n   } n } n pair<int, int> getAnc(int x, int y) { n   if (depth[x] < depth[y]) swap(x, y); n   int diff = depth[x] - depth[y], ret = 0; n   for (int i = 0; i < M; ++i) { n     if (diff & (1 << i)) { n       ret = max(ret, wa[x][i]); n       x = anc[x][i]; n     } n   } n   if (x != y) { n     for (int i = M - 1; i >= 0; --i) { n       if (anc[x][i] != anc[y][i]) { n         ret = max(ret, max(wa[x][i], wa[y][i])); n         x = anc[x][i]; n         y = anc[y][i]; n       } n     } n     ret = max(ret, max(wa[x][0], wa[y][0])); n     x = anc[x][0]; n   } n   return {ret, x}; n } n multiset<int> g[N]; n vector<int> ed[N]; n void dfs(int node, int par) { n   for (int eid : adj[node]) { n     int ch = a[eid] ^ b[eid] ^ node; n     if (ch != par) { n       dfs(ch, node); n       out[eid] = g[ch].size() == 0 ? -1 : (*g[ch].begin()) - 1; n       if (g[node].size() < g[ch].size()) { n         swap(g[node], g[ch]); n       } n       for (int x : g[ch]) g[node].insert(x); n     } n   } n   for (int val : ed[node]) { n     assert(g[node].find(val) != g[node].end()); n     g[node].erase(g[node].find(val)); n     assert(g[node].find(val) != g[node].end()); n     g[node].erase(g[node].find(val)); n   } n } n void solve2() { n   int n, m; n   scanf( %d %d , &n, &m); n   vector<pair<int, int> > edges; n   for (int i = 0; i < m; ++i) { n     scanf( %d %d %d  , &a[i], &b[i], &w[i]); n     edges.push_back({w[i], i}); n   } n   for (int i = n; i; --i) dsu[i] = i; n   sort(edges.begin(), edges.end()); n   for (int i = 0; i < m; ++i) { n     int id = edges[i].second; n     if (merge(id)) { n       used[id] = true; n       adj[a[id]].push_back(id); n       adj[b[id]].push_back(id); n     } n   } n   construct(1, 0); n   for (int i = 0; i < m; ++i) { n     if (!used[i]) { n       pair<int, int> tmp = getAnc(a[i], b[i]); n       out[i] = tmp.first - 1; n       g[a[i]].insert(w[i]); n       g[b[i]].insert(w[i]); n       ed[tmp.second].push_back(w[i]); n     } n   } n   dfs(1, 0); n   for (int i = 0; i < m; ++i) { n     printf( %d n , out[i]); n   } n } n void solve() { solve2(); } n int main() { n   solve(); n   return 0; n } n


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


#include<bits/stdc++.h> n using namespace std; n typedef long long int ll; n #define MAX 2000000000 n vector<ll> feaseable; n void setfun(){ n     for(ll i = 3; i<MAX; i+=2){ n         ll sq = i * i; n         if(sq>MAX){ n             break; n         } n         ll c = (sq + 1)/2; n         feaseable.push_back(c); n     } n } n  n int main(){ n     int t; n     cin>>t; n     setfun(); n     while(t--){ n         int n; n         cin>>n; n         auto x = upper_bound(feaseable.begin(),feaseable.end(),n); n         int ans = x - feaseable.begin(); n         cout<<ans<<endl; n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   long n, k, a; n   cin >> n >> k >> a; n   long n_moves; n   cin >> n_moves; n   set<pair<long, long> > s; n   s.insert(make_pair(n, 1)); n   long max_ships = (n + 1) / (a + 1); n   for (int i = 1; i <= n_moves; i++) { n     long x; n     cin >> x; n     set<pair<long, long> >::iterator it = s.lower_bound(make_pair(x, -1)); n     long l = it->second; n     long r = it->first; n     max_ships -= (r - l + 2) / (a + 1); n     if ((x - 1) >= l) { n       max_ships += ((x - 1) - l + 2) / (a + 1); n     } n     if ((x + 1) <= r) { n       max_ships += (r - (x + 1) + 2) / (a + 1); n     } n     if (max_ships < k) { n       cout << i; n       return 0; n     } n     s.erase(it); n     if ((x - 1) >= l) s.insert(make_pair(x - 1, l)); n     if ((x + 1) <= r) s.insert(make_pair(r, x + 1)); n   } n   cout <<  -1 ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n #pragma GCC optimization( unroll-loops ) n using namespace std; n int parent[150000]; n int size[150000]; n long long int edges[150000]; n struct dsu { n   void init(int n) { n     for (int i = 0; i < n; ++i) { n       parent[i] = i; n       size[i] = 1; n       edges[i] = 0; n     } n   } n   int p(int x) { n     if (parent[x] == x) return x; n     return parent[x] = p(parent[x]); n   } n   void unite(int x, int y) { n     int supx = p(x); n     int supy = p(y); n     if (supx != supy) { n       if (size[supx] > size[supy]) { n         parent[supy] = supx; n         size[supx] += size[supy]; n         edges[supx] += edges[supy] + 1; n       } else { n         parent[supx] = supy; n         size[supy] += size[supx]; n         edges[supy] += edges[supx] + 1; n       } n     } else { n       edges[supx]++; n     } n   } n }; n int n, m, x, y; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   cin >> n >> m; n   dsu d; n   d.init(n); n   for (int i = 0; i < m; ++i) { n     cin >> x >> y; n     x--; n     y--; n     d.unite(x, y); n   } n   for (int i = 0; i < n; ++i) { n     if (parent[i] == i) { n       long long int ed = edges[i]; n       long long int vertices = size[i]; n       if (ed != (vertices * (vertices - 1)) / 2) { n         cout <<  NO ; n         return 0; n       } n     } n   } n   cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 100000007; n const int M = 100005; n const double pi = acos(-1); n struct pt { n   long long x, y, EWGDFGdfgfsdhfdshfdhf; n   bool operator<(const pt &a) const { return (x < a.x); } n   bool operator>(const pt &a) const { return (x > a.x); } n }; n long long CAlASFSAF[100050], n, m, k; n set<pt> u[200050]; n set<pt> d[200050]; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n; n   cin >> m; n   cin >> k; n   for (int i = 1; i <= k; i++) { n     pt p; n     cin >> p.x; n     cin >> p.y; n     p.EWGDFGdfgfsdhfdshfdhf = i; n     u[p.y - p.x + 100000].insert(p); n     d[p.y + p.x].insert(p); n   } n   pt now, lst; n   now.x = 0; n   now.y = 0; n   now.EWGDFGdfgfsdhfdshfdhf = 0; n   long long xPXPXPPXXPXP = 1, nowdy = 1; n   for (int i = 1; i <= k; i++) CAlASFSAF[i] = -1; n   CAlASFSAF[0] = 0; n   long long NTNTNFN = 0, PLOPLO = 0; n   set<pt>::iterator ite; n   while (true) { n     lst = now; n     if (nowdy == 1) { n       if (xPXPXPPXXPXP == 1) { n         while (!u[now.y - now.x + 100000].empty()) { n           lst = now; n           NTNTNFN = PLOPLO; n           now = *(u[now.y - now.x + 100000].begin()); n           PLOPLO = NTNTNFN + abs(now.x - lst.x); n           if (CAlASFSAF[now.EWGDFGdfgfsdhfdshfdhf] == -1) n             CAlASFSAF[now.EWGDFGdfgfsdhfdshfdhf] = PLOPLO; n           u[now.y - now.x + 100000].erase(u[now.y - now.x + 100000].begin()); n         } n       } else { n         while (!d[now.y + now.x].empty()) { n           lst = now; n           NTNTNFN = PLOPLO; n           ite = d[now.y + now.x].end(); n           ite--; n           now = *ite; n           PLOPLO = NTNTNFN + abs(now.x - lst.x); n           if (CAlASFSAF[now.EWGDFGdfgfsdhfdshfdhf] == -1) n             CAlASFSAF[now.EWGDFGdfgfsdhfdshfdhf] = PLOPLO; n           d[now.y + now.x].erase(ite); n         } n       } n     } else { n       if (xPXPXPPXXPXP == 1) { n         while (!d[now.y + now.x].empty()) { n           lst = now; n           NTNTNFN = PLOPLO; n           now = *(d[now.y + now.x].begin()); n           PLOPLO = NTNTNFN + abs(now.x - lst.x); n           if (CAlASFSAF[now.EWGDFGdfgfsdhfdshfdhf] == -1) n             CAlASFSAF[now.EWGDFGdfgfsdhfdshfdhf] = PLOPLO; n           d[now.y + now.x].erase(d[now.y + now.x].begin()); n         } n       } else { n         while (!u[now.y - now.x + 100000].empty()) { n           lst = now; n           NTNTNFN = PLOPLO; n           ite = u[now.y - now.x + 100000].end(); n           ite--; n           now = *ite; n           PLOPLO = NTNTNFN + abs(now.x - lst.x); n           if (CAlASFSAF[now.EWGDFGdfgfsdhfdshfdhf] == -1) n             CAlASFSAF[now.EWGDFGdfgfsdhfdshfdhf] = PLOPLO; n           u[now.y - now.x + 100000].erase(ite); n         } n       } n     } n     pt tr = now; n     tr.x += (xPXPXPPXXPXP * min(abs(now.x - (xPXPXPPXXPXP == 1 ? n : 0)), n                                 abs(now.y - (nowdy == 1 ? m : 0)))); n     tr.y += (nowdy * min(abs(now.x - (xPXPXPPXXPXP == 1 ? n : 0)), n                          abs(now.y - (nowdy == 1 ? m : 0)))); n     tr.EWGDFGdfgfsdhfdshfdhf = 0; n     PLOPLO = PLOPLO + abs(tr.x - now.x); n     if (((tr.x == 0) || (tr.x == n)) && ((tr.y == 0) || (tr.y == m))) break; n     if (((xPXPXPPXXPXP == 1) && (tr.x == n)) || n         ((xPXPXPPXXPXP == -1) && (tr.x == 0))) n       xPXPXPPXXPXP *= (-1); n     if (((nowdy == 1) && (tr.y == m)) || ((nowdy == -1) && (tr.y == 0))) n       nowdy *= (-1); n     now = tr; n   } n   for (int i = 1; i <= k; i++) { n     cout << CAlASFSAF[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100 + 10; n char s[maxn][maxn]; n int main() { n   int a, b; n   for (int i = 0; i < 11; i++) gets(s[i]); n   scanf( %d%d , &a, &b); n   int r = (a - 1) % 3, c = (b - 1) % 3; n   int flag = 0; n   for (int i = r * 3 + r; i < (r + 1) * 3 + r; i++) { n     for (int j = c * 3 + c; j < (c + 1) * 3 + c; j++) { n       if (s[i][j] ==  . ) { n         flag = 1; n         break; n       } n     } n   } n   if (flag) { n     for (int i = r * 3 + r; i < (r + 1) * 3 + r; i++) { n       for (int j = c * 4; j < c * 4 + 3; j++) { n         if (s[i][j] ==  . ) s[i][j] =  ! ; n       } n     } n     for (int i = 0; i < 11; i++) printf( %s n , s[i]); n   } else { n     for (int i = 0; i < 11; i++) { n       for (int j = 0; j < 11; j++) n         if (s[i][j] ==  . ) s[i][j] =  ! ; n     } n     for (int i = 0; i < 11; i++) printf( %s n , s[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char arr[100][100]; n   int m, n, k = 0; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   if (m == 1 || n == 1) { n     cout << 0; n     return 0; n   } n   for (int i = 0; i < n - 1; i++) { n     for (int j = 0; j < m - 1; j++) { n       if ( f  != arr[i][j] &&  f  != arr[i + 1][j] &&  f  != arr[i][j + 1] && n            f  != arr[i + 1][j + 1]) n         continue; n       if ( a  != arr[i][j] &&  a  != arr[i + 1][j] &&  a  != arr[i][j + 1] && n            a  != arr[i + 1][j + 1]) n         continue; n       if ( c  != arr[i][j] &&  c  != arr[i + 1][j] &&  c  != arr[i][j + 1] && n            c  != arr[i + 1][j + 1]) n         continue; n       if ( e  != arr[i][j] &&  e  != arr[i + 1][j] &&  e  != arr[i][j + 1] && n            e  != arr[i + 1][j + 1]) n         continue; n       k++; n     } n   } n   cout << k; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int m, n, count = 0, count1 = 0, x = 0; n   cin >> m >> n; n   int a[m][n], b[m][n]; n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < n; j++) { n       cin >> b[i][j]; n       a[i][j] = 1; n     } n   } n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < n; j++) { n       if (b[i][j] == 0) { n         for (int k = 0; k < n; k++) { n           if (a[i][k] == 1) { n             a[i][k] = 0; n             count++; n             if (count == n * m) break; n           } n         } n         for (int k = 0; k < m; k++) { n           if (a[k][j] == 1) { n             a[k][j] = 0; n             count++; n             if (count == n * m) break; n           } n         } n       } n       if (count == n * m) break; n     } n     if (count == n * m) break; n   } n   if (count == n * m) { n     for (int i = 0; i < m; i++) { n       for (int j = 0; j < n; j++) { n         if (b[i][j] == 1) { n           cout <<  NO ; n           count = 0; n           break; n         } n       } n       if (count == 0) break; n     } n     if (count != 0) { n       cout <<  YES  << endl; n       for (int i = 0; i < m; i++) { n         for (int j = 0; j < n; j++) cout << a[i][j] <<    ; n         cout << endl; n       } n     } n   } else { n     for (int i = 0; i < m; i++) { n       for (int j = 0; j < n; j++) { n         x = 0; n         if (b[i][j] == 1) { n           for (int k = 0; k < m; k++) x = x || a[k][j]; n           for (int k = 0; k < n; k++) x = x || a[i][k]; n           if (x != 1) { n             cout <<  NO ; n             count1++; n             break; n           } n         } n       } n       if (count1 > 0) break; n     } n     if (count1 == 0) { n       cout <<  YES  << endl; n       for (int i = 0; i < m; i++) { n         for (int j = 0; j < n; j++) { n           cout << a[i][j] <<    ; n         } n         cout << endl; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int getLength(long long int x) { n   long long int c = 0; n   while (x > 0) { n     c++; n     x /= 10; n   } n   return c; n } n int main() { n   long long int n, k, i, j; n   cin >> n >> k; n   long long int a[n], lengths[n]; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     lengths[i] = getLength(a[i]); n   } n   vector<vector<long long int>> v(11); n   long long int l, m; n   for (i = 0; i < n; i++) { n     l = lengths[i]; n     m = a[i] % k; n     v[l].push_back(m); n   } n   for (i = 0; i <= 10; i++) { n     sort(v[i].begin(), v[i].end()); n   } n   long long int ans = 0, avail, req; n   for (i = 0; i < n; i++) { n     for (j = 1; j <= 10; j++) { n       avail = (a[i] % k * ((long long int)(pow(10, j)) % k)) % k; n       req = (k - avail) % k; n       auto l = lower_bound(v[j].begin(), v[j].end(), req); n       auto r = upper_bound(v[j].begin(), v[j].end(), req); n       ans += (r - l); n       if (lengths[i] == j && (avail + a[i] % k) % k == 0) --ans; n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long int eet(long long int a, long long int b, long long int *x, n                   long long int *y) { n   if (a == 0) { n     *x = 0; n     *y = 1; n     return b; n   } n   long long int x1, y1; n   long long int gcd = eet(b % a, a, &x1, &y1); n   *x = y1 - (b / a) * x1; n   *y = x1; n   return gcd; n } n int main() { n   long long int n, m, i, j, k, cnt = 0, sum = 0, mn = INT_MAX, ind, n                                rem = 1000000007, ok = 0, size, lcm, n                                mx = INT_MIN, diff, num, x, y, z, ee; n   int flag = 0, t = 1; n   string s, str, s1, s2, s3; n   char ch; n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   while (t--) { n     long long int a, b, c; n     cin >> a >> b >> c; n     c = -c; n     long long int GCD = eet(a, b, &x, &y); n     if (c % GCD != 0) { n       cout << -1; n       return 0; n     } n     long long int mul = c / GCD; n     cout << x * mul <<     << y * mul; n     cout << endl; n   } n } n