#include <bits/stdc++.h> n using namespace std; n char s[10001000]; n int n; n vector<int> sep; n void lindon() { n   for (int i = 0; i < n;) { n     sep.push_back(i); n     int p1 = i, p2 = i + 1; n     while (p2 < n && s[p1] <= s[p2]) { n       if (s[p1] == s[p2]) n         ++p1, ++p2; n       else n         p1 = i, ++p2; n     } n     int len = p2 - p1; n     while (i <= p1) i += len; n   } n } n int z[10001000]; n void exkmp() { n   int id, mx = -1; n   for (int i = 1; i <= 2 * n; ++i) { n     int p = 0; n     if (mx > i) p = max(p, min(mx - i, z[i - id])); n     while (p <= 2 * n && s[p] == s[i + p]) ++p; n     z[i] = p; n     if (i + p > mx) id = i, mx = i + p; n   } n   z[0] = 2 * n + 1; n } n string ans; n bool same(string s) { n   string t = s; n   reverse(t.begin(), t.end()); n   return s == t; n } n int T, m; n void rua3() { n   sep.push_back(n); n   m = sep.size() - 2; n   while (T >= 3 && m >= 0) { n     ans += string(s + sep[m], sep[m + 1] - sep[m]); n     --m; n     if (!(m >= 0 && same(string(s + sep[m], sep[m + 1] - sep[m])) && n           same(string(s + sep[m + 1], sep[m + 2] - sep[m + 1])))) n       --T; n   } n } n int rev(int x) { return 2 * n - x; } n string fix(string s) { n   string t = s; n   reverse(t.begin(), t.end()); n   return min(s, t); n } n long long bas1, bas2, mod1, mod2, hasinit; n bool ispri(int x) { n   for (int i = 2; i * i <= x; ++i) n     if (x % i == 0) return 0; n   return 1; n } n int ranpri(int l, int r) { n   for (;;) { n     long long tmp = n         rand() % 10000 * (1e8) + rand() % 10000 * (1e4) + rand() % 10000; n     tmp = tmp % (r - l + 1) + l; n     if (ispri(tmp)) return tmp; n   } n } n struct HASH { n   static const int mxlen = 1e7 + 10; n   int nn, h1[mxlen + 233], h2[mxlen + 233], p1[mxlen + 233], p2[mxlen + 233]; n   void init(char *s, int n) { n     if (!hasinit) { n       srand(time(0)); n       hasinit = 1; n       bas1 = ranpri(1e3, 1e4); n       bas2 = ranpri(1e3, 1e4); n       mod1 = ranpri(5e8, 1e9); n       mod2 = ranpri(5e8, 1e9); n     } n     nn = n; n     h1[0] = h2[0] = 0; n     p1[0] = p2[0] = 1; n     for (int i = 1; i <= n; ++i) { n       h1[i] = (h1[i - 1] * bas1 + s[i - 1]) % mod1; n       h2[i] = (h2[i - 1] * bas2 + s[i - 1]) % mod2; n       p1[i] = p1[i - 1] * bas1 % mod1; n       p2[i] = p2[i - 1] * bas2 % mod2; n     } n   } n   pair<int, int> gay(int l, int r) { n     if (r > nn) return (pair<int, int>){rand(), rand()}; n     int res1 = (h1[r] - (long long)h1[l] * p1[r - l] % mod1 + mod1) % mod1; n     int res2 = (h2[r] - (long long)h2[l] * p2[r - l] % mod2 + mod2) % mod2; n     return (pair<int, int>){res1, res2}; n   } n } hs; n int fuck(int pa, int pb, int lim) { n   int lcp = 0; n   for (int i = 25; i >= 0; --i) n     if (hs.gay(pa, pa + (1 << i)) == hs.gay(pb, pb + (1 << i))) { n       pa += 1 << i; n       pb += 1 << i; n       lcp += 1 << i; n     } n   if (lcp >= lim) return 0; n   return s[pa] < s[pb] ? 1 : -1; n } n vector<pair<int, int> > hashmin(vector<pair<int, int> > a, n                                 vector<pair<int, int> > b) { n   if (!a.size() || !b.size()) return max(a, b); n   if (a[0].second > b[0].second) swap(a, b); n   { n     int t = fuck(a[0].first, b[0].first, a[0].second); n     if (t) return t == 1 ? a : b; n   } n   { n     int t = n         fuck(a[1].first, b[0].first + a[0].second, b[0].second - a[0].second); n     if (t) return t == 1 ? a : b; n   } n   { n     int t = n         fuck(a[1].first + b[0].second - a[0].second, b[1].first, b[1].second); n     if (t) return t == 1 ? a : b; n   } n   return a; n } n string gaolas() { n   int l = sep[m + 1]; n   string res = fix(string(s, l)); n   if (T <= 1 || m <= 0) return res; n   { n     int mn = 0; n     char c1, c2; n     for (int i = 1; i < l - 1; ++i) { n       int lcp1 = z[rev(i)]; n       if (lcp1 < i - mn) { n         c1 = s[i - lcp1]; n         c2 = s[lcp1]; n       } else { n         int lcp2 = z[i - mn]; n         c1 = s[lcp2]; n         c2 = s[i - mn + lcp2]; n       } n       if (c1 > c2) mn = i; n     } n     string t1(s, mn + 1), t2(s + mn + 1, l - mn - 1); n     reverse(t2.begin(), t2.end()); n     string t = t2 + t1; n     res = min(res, t); n   } n   { n     vector<pair<int, int> > best; n     for (int i = m; i >= 0 && i >= m - 25; --i) { n       { n         vector<pair<int, int> > v; n         v.push_back({sep[i], l - sep[i]}); n         v.push_back({0, sep[i]}); n         best = hashmin(best, v); n       } n       { n         vector<pair<int, int> > v; n         v.push_back({sep[i], l - sep[i]}); n         v.push_back({rev(sep[i] - 1), sep[i]}); n         best = hashmin(best, v); n       } n     } n     string tmp = string(s + best[0].first, best[0].second) + n                  string(s + best[1].first, best[1].second); n     res = min(res, tmp); n   } n   return res; n } n int main() { n   scanf( %s%d , s, &T); n   n = strlen(s); n   for (int i = 0; i < n; ++i) s[i + n + 1] = s[i]; n   reverse(s, s + n); n   s[n] =  # ; n   s[n * 2 + 1] =  $ ; n   lindon(); n   exkmp(); n   hs.init(s, 2 * n + 1); n   rua3(); n   ans += gaolas(); n   printf( %s n , ans.c_str()); n } n


#include <bits/stdc++.h> n using namespace std; n int a[1010][1010]; n int mapa[1010][1010]; n int n, m; n int TIME = 0; n bool ok(int val) { n   for (int i = 0; i < n; i++) { n     vector<int> row; n     for (int j = 0; j < m; j++) { n       if (a[i][j] >= val) row.push_back(j); n     } n     for (int first = 0; first < row.size(); first++) n       for (int second = first + 1; second < row.size(); second++) { n         if (mapa[row[first]][row[second]] == TIME) return true; n         mapa[row[first]][row[second]] = TIME; n       } n   } n   return false; n } n int solve(int lo, int hi) { n   if (lo == hi) return lo; n   int mid = (lo + hi + 1) / 2; n   TIME++; n   if (ok(mid)) return solve(mid, hi); n   return solve(lo, mid - 1); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) scanf( %d , &a[i][j]); n   printf( %d , solve(0, 1000100100)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using uint = unsigned; n using ll = long long; n using ull = unsigned long long; n using vi = vector<int>; n using vvi = vector<vi>; n using vl = vector<ll>; n using vvl = vector<vl>; n using vd = vector<double>; n using vvd = vector<vd>; n using vs = vector<string>; n void print_vars(ostream&) {} n template <typename Car, typename... Cdr> n void print_vars(ostream& os, const Car& car, const Cdr&... cdr) { n   print_vars(os << car << (sizeof...(cdr) ?  ,  :   ), cdr...); n } n template <typename T1, typename T2> n ostream& operator<<(ostream& os, const pair<T1, T2>& p) { n   return os <<  (  << p.first <<  ,  << p.second <<  ) ; n } n template <int I, typename Tuple> n void print_tuple(ostream&, const Tuple&) {} n template <int I, typename Car, typename... Cdr, typename Tuple> n void print_tuple(ostream& os, const Tuple& t) { n   os << get<I>(t) << (sizeof...(Cdr) ?  ,  :   ); n   print_tuple<I + 1, Cdr...>(os, t); n } n template <typename... Args> n ostream& operator<<(ostream& os, const tuple<Args...>& t) { n   print_tuple<0, Args...>(os <<  ( , t); n   return os <<  ) ; n } n template <typename Ch, typename Tr, typename C> n basic_ostream<Ch, Tr>& operator<<(basic_ostream<Ch, Tr>& os, const C& c) { n   os <<  [ ; n   for (auto i = begin(c); i != end(c); ++i) n     os << (i == begin(c) ?    :    ) << *i; n   return os <<  ] ; n } n constexpr int INF = 1e9; n constexpr int MOD = 1e9 + 7; n constexpr double EPS = 1e-9; n vector<tuple<ll, ll>> compress(const vector<tuple<ll, ll>>& b, ll n, ll k) { n   vector<tuple<ll, ll>> res; n   ll cur = -1, cnt = 0; n   for (int i = int(0); i < int(b.size()); i++) { n     ll x, c; n     tie(x, c) = b[i]; n     if (x != cur) { n       if (cur != -1) res.emplace_back(cur, cnt); n       cur = x, cnt = c; n     } else { n       (cnt += c) %= k; n       if (cnt == 0) { n         if (res.empty()) n           cur = -1; n         else { n           tie(cur, cnt) = res.back(); n           res.pop_back(); n         } n       } n     } n   } n   if (cnt > 0) res.emplace_back(cur, cnt); n   if (res.size() > 2 * n) { n     int l = n, r = res.size() - n; n     ll cnt = 0; n     for (int i = int(l); i < int(r); i++) cnt += get<1>(res[i]); n     res.erase(begin(res) + l, begin(res) + r); n     res.emplace(begin(res) + l, INF, cnt); n   } n   return res; n } n ll solve(ll n, ll k, ll m, vl a) { n   vector<vector<tuple<ll, ll>>> b(30); n   { n     vector<tuple<ll, ll>> t; n     for (int i = int(0); i < int(n); i++) t.emplace_back(a[i], 1); n     b[0] = compress(t, n, k); n   } n   for (int i = int(1); i < int(b.size()); i++) { n     vector<tuple<ll, ll>> t = b[i - 1]; n     t.insert(end(t), begin(b[i - 1]), end(b[i - 1])); n     b[i] = compress(t, n, k); n   } n   vector<tuple<ll, ll>> c; n   for (int i = int(0); i < int(30); i++) n     if (m >> i & 1) { n       c.insert(end(c), begin(b[i]), end(b[i])); n       c = compress(c, n, k); n     } n   ll res = 0; n   for (auto t : c) res += get<1>(t); n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   constexpr char endl =   n ; n   for (ll n, k, m; cin >> n >> k >> m && n | k | m;) { n     vl a(n); n     for (int i = int(0); i < int(n); i++) cin >> a[i]; n     cout << solve(n, k, m, a) << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long mypow(long long x, int y) { n   long long an = 1; n   while (y) { n     if (y & 1) { n       an *= x; n       an %= 1000000007; n     } n     x *= x; n     x %= 1000000007; n     y >>= 1; n   } n   return an; n } n int d[1000001]; n int f(int k, int w) { n   memset(d, 0, sizeof(d)); n   d[k] = w; n   long long an = mypow(k, w); n   long long tmp = an; n   int now = k; n   for (int i = k - 1; i; i--) { n     d[i] += 2; n     tmp *= mypow(i, 2); n     tmp %= 1000000007; n     while (d[now] == 1) now--; n     d[now]--; n     tmp *= mypow(now, 1000000007 - 2); n     tmp %= 1000000007; n     an += tmp; n     if (an >= 1000000007) an -= 1000000007; n   } n   return an; n } n int main() { n   int i, j, k, w; n   scanf( %d%d , &k, &w); n   int an = f(k, w + 1) - f(k, w); n   if (an < 0) an += 1000000007; n   an += mypow(k, w); n   if (an >= 1000000007) an -= 1000000007; n   printf( %d n , an); n   return 0; n } n


#include <bits/stdc++.h> n long long dx[4] = {0, -1, 0, 1}; n long long dy[4] = {1, 0, -1, 0}; n using namespace std; n class pa3 { n  public: n   long long x, y, z; n   pa3(long long x = 0, long long y = 0, long long z = 0) : x(x), y(y), z(z) {} n   bool operator<(const pa3 &p) const { n     if (x != p.x) return x < p.x; n     if (y != p.y) return y < p.y; n     return z < p.z; n   } n   bool operator>(const pa3 &p) const { n     if (x != p.x) return x > p.x; n     if (y != p.y) return y > p.y; n     return z > p.z; n   } n   bool operator==(const pa3 &p) const { n     return x == p.x && y == p.y && z == p.z; n   } n   bool operator!=(const pa3 &p) const { n     return !(x == p.x && y == p.y && z == p.z); n   } n }; n class pa4 { n  public: n   double x; n   long long y, z, w; n   pa4(double x = 0, long long y = 0, long long z = 0, long long w = 0) n       : x(x), y(y), z(z), w(w) {} n   bool operator<(const pa4 &p) const { n     if (x != p.x) return x < p.x; n     if (y != p.y) return y < p.y; n     if (z != p.z) return z < p.z; n     return w < p.w; n   } n   bool operator>(const pa4 &p) const { n     if (x != p.x) return x > p.x; n     if (y != p.y) return y > p.y; n     if (z != p.z) return z > p.z; n     return w > p.w; n   } n   bool operator==(const pa4 &p) const { n     return x == p.x && y == p.y && z == p.z && w == p.w; n   } n }; n class pa2 { n  public: n   long long x, y; n   pa2(long long x = 0, long long y = 0) : x(x), y(y) {} n   pa2 operator+(pa2 p) { return pa2(x + p.x, y + p.y); } n   pa2 operator-(pa2 p) { return pa2(x - p.x, y - p.y); } n   bool operator<(const pa2 &p) const { return x != p.x ? x < p.x : y < p.y; } n   bool operator>(const pa2 &p) const { return x != p.x ? x > p.x : y > p.y; } n   bool operator==(const pa2 &p) const { n     return abs(x - p.x) == 0 && abs(y - p.y) == 0; n   } n   bool operator!=(const pa2 &p) const { n     return !(abs(x - p.x) == 0 && abs(y - p.y) == 0); n   } n }; n class Point { n  public: n   double x, y; n   Point(double x = 0, double y = 0) : x(x), y(y) {} n   Point operator+(Point p) { return Point(x + p.x, y + p.y); } n   Point operator-(Point p) { return Point(x - p.x, y - p.y); } n   Point operator*(double a) { return Point(x * a, y * a); } n   Point operator/(double a) { return Point(x / a, y / a); } n   double absv() { return sqrt(norm()); } n   double norm() { return x * x + y * y; } n   bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; } n   bool operator==(const Point &p) const { n     return fabs(x - p.x) < (1e-10) && fabs(y - p.y) < (1e-10); n   } n }; n struct Segment { n   Point p1, p2; n }; n double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; } n double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; } n bool parareru(Point a, Point b, Point c, Point d) { n   return abs(cross(a - b, d - c)) < (1e-10); n } n double distance_ls_p(Point a, Point b, Point c) { n   if (dot(b - a, c - a) < (1e-10)) return (c - a).absv(); n   if (dot(a - b, c - b) < (1e-10)) return (c - b).absv(); n   return abs(cross(b - a, c - a)) / (b - a).absv(); n } n bool is_intersected_ls(Segment a, Segment b) { n   if (a.p1 == b.p1 || a.p2 == b.p1 || a.p1 == b.p2 || a.p2 == b.p2) n     return false; n   if (parareru((a.p2), (a.p1), (a.p1), (b.p2)) && n       parareru((a.p2), (a.p1), (a.p1), (b.p1))) { n     if (dot(a.p1 - b.p1, a.p1 - b.p2) < (1e-10)) return true; n     if (dot(a.p2 - b.p1, a.p2 - b.p2) < (1e-10)) return true; n     if (dot(a.p1 - b.p1, a.p2 - b.p1) < (1e-10)) return true; n     if (dot(a.p1 - b.p2, a.p2 - b.p2) < (1e-10)) return true; n     return false; n   } else n     return (cross(a.p2 - a.p1, b.p1 - a.p1) * cross(a.p2 - a.p1, b.p2 - a.p1) < n             (1e-10)) && n            (cross(b.p2 - b.p1, a.p1 - b.p1) * cross(b.p2 - b.p1, a.p2 - b.p1) < n             (1e-10)); n } n double segment_dis(Segment a, Segment b) { n   if (is_intersected_ls(a, b)) return 0; n   double r = distance_ls_p(a.p1, a.p2, b.p1); n   r = min(r, distance_ls_p(a.p1, a.p2, b.p2)); n   r = min(r, distance_ls_p(b.p1, b.p2, a.p2)); n   r = min(r, distance_ls_p(b.p1, b.p2, a.p1)); n   return r; n } n Point intersection_ls(Segment a, Segment b) { n   Point ba = b.p2 - b.p1; n   double d1 = abs(cross(ba, a.p1 - b.p1)); n   double d2 = abs(cross(ba, a.p2 - b.p1)); n   double t = d1 / (d1 + d2); n   return a.p1 + (a.p2 - a.p1) * t; n } n string itos(long long i) { n   ostringstream s; n   s << i; n   return s.str(); n } n long long gcd(long long v, long long b) { n   if (v > b) return gcd(b, v); n   if (v == b) return b; n   if (b % v == 0) return v; n   return gcd(v, b % v); n } n double distans(double x1, double y1, double x2, double y2) { n   double rr = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); n   return sqrt(rr); n } n long long beki(long long wa, long long rr, long long warukazu) { n   if (rr == 0) return 1 % warukazu; n   if (rr == 1) return wa % warukazu; n   if (rr % 2 == 1) return (beki(wa, rr - 1, warukazu) * wa) % warukazu; n   long long zx = beki(wa, rr / 2, warukazu); n   return (zx * zx) % warukazu; n } n double bekid(double w, long long r) { n   if (r == 0) return 1.0; n   if (r == 1) return w; n   if (r % 2) return bekid(w, r - 1) * w; n   double f = bekid(w, r / 2); n   return f * f; n } n long long a[1000020]; n void dfs(long long r) { n   if (r == 0) return; n   if (r == 2) { n     a[1] = 2, a[2] = 1; n     return; n   } n   long long t = -1; n   for (long long j = 0; j < 30; j++) n     if (r & (1 << j)) t = j; n   long long g = (1 << (t + 1)) - 1; n   for (long long i = (1 << t); i <= r; i++) { n     a[i] = g - i; n     a[g - i] = i; n   } n   dfs(g - r - 1); n } n bool ch(long long r) { n   if (r % 2) return false; n   dfs(r); n   return true; n } n vector<long long> ve[30]; n void ch2(long long r) { n   cout <<  YES  << endl; n   if (r == 6) { n     cout <<  3 6 1 5 4 2  << endl; n     return; n   } n   ve[0].push_back(6); n   ve[0].push_back(1); n   ve[0].push_back(5); n   ve[0].push_back(4); n   ve[0].push_back(7); n   ve[0].push_back(2); n   ve[0].push_back(3); n   for (long long i = 8; i <= r; i++) { n     long long t = 0; n     for (long long j = 0; j < 30; j++) n       if (i & (1 << j)) t = j; n     ve[t].push_back(i); n   } n   for (long long i = 0; i < 30; i++) n     if (ve[i].size()) { n       cout << ve[i].back() <<    ; n       for (long long j = 0; j < ve[i].size() - 1; j++) cout << ve[i][j] <<    ; n     } n   cout << endl; n   exit(0); n } n signed main() { n   long long n; n   cin >> n; n   if (ch(n)) { n     cout <<  YES  << endl; n     for (long long i = 1; i <= n; i++) cout << a[i] <<    ; n     cout << endl; n   } else n     cout <<  NO  << endl; n   if (n <= 5 || (n & (-n)) == n) n     cout <<  NO  << endl; n   else n     ch2(n); n   return 0; n   for (long long i = 1; i <= n; i++) ch2(i); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int x, id; n }; n node a[1005]; n bool cmp(node a, node b) { return a.x < b.x; } n int main() { n   int n, k; n   int i; n   scanf( %d%d , &n, &k); n   for (i = 1; i <= n; i++) { n     scanf( %d , &a[i].x); n     a[i].id = i; n   } n   sort(a + 1, a + 1 + n, cmp); n   int sum = 0; n   for (i = 1; i <= n; i++) { n     sum += a[i].x; n     if (sum > k) break; n   } n   printf( %d n , i - 1); n   for (i = i - 1; i > 0; i--) { n     printf( %d  , a[i].id); n   } 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 long long int n, k, ans = 0; n long long int arr[500005]; n void solve() { n   cin >> n >> k; n   map<long long int, long long int> mpp, tot, till; n   for (long long int i = 1; i <= n; i++) { n     cin >> arr[i]; n     tot[arr[i]]++; n   } n   for (long long int i = 1; i <= n; i++) { n     till[arr[i]]++; n     if ((arr[i] % (k)) == 0) { n       long long int a = arr[i] / k, b = arr[i] * k; n       ans = ans + (mpp[a]) * (tot[b] - till[b]); n     } n     mpp[arr[i]]++; n   } n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   { n     solve(); n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a; n   cin >> a; n   if (a[0] >=  a  && a[0] <=  z ) a[0] -= 32; n   cout << a; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e+5; n char str[2 * maxn + 5]; n int main() { n   int cishu; n   cin >> cishu; n   while (cishu--) { n     int n; n     cin >> n; n     for (int a = 0; a < n - 1; a++) cin >> str[a]; n     str[n - 1] =  0 ; n     int tmp = n; n     for (int i = 0; i < n; i++) { n       if (str[i] ==  < ) { n         int amt = 2; n         for (int a = i + 1; a < n; a++) { n           if (str[a] ==  < ) n             amt++; n           else n             break; n         } n         int print = tmp - amt + 1; n         tmp = print - 1; n         for (int b = 0; b < amt; b++) n           printf( %d%c , print++, i + b == n - 1 ?   n  :    ); n         i = i + amt - 1; n       } else n         printf( %d%c , tmp--, i == n - 1 ?   n  :    ); n     } n     tmp = 1; n     for (int i = 0; i < n; i++) { n       if (str[i] ==  > ) { n         int amt = 2; n         for (int a = i + 1; a < n; a++) { n           if (str[a] ==  > ) n             amt++; n           else n             break; n         } n         int print = tmp + amt - 1; n         tmp = print + 1; n         for (int b = 0; b < amt; b++) n           printf( %d%c , print--, i + b == n - 1 ?   n  :    ); n         i = i + amt - 1; n       } else n         printf( %d%c , tmp++, i == n - 1 ?   n  :    ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); n template <typename T> n T ceil(T a, T b) { n   return (a + b - 1) / b; n } n template <typename T> n T binpow(T a, T b) { n   T res = 1; n   while (b > 0) { n     if (b & 1) res = res * a; n     a = a * a; n     b >>= 1; n   } n   return res; n } n void solve() { n   long long n, c = 0; n   string s, t; n   cin >> n; n   cin >> s >> t; n   if (n == 1) { n     if (s == t) { n       cout << 0; n     } else { n       cout << 1; n     } n     return; n   } n   vector<long long> a, b; n   for (long long i = 1; i < n; i++) { n     if (s[i] != t[i] && s[i - 1] != t[i - 1]) { n       pair<char, char> a, b; n       a = {s[i], t[i]}; n       b = {s[i - 1], t[i - 1]}; n       if (a != b) { n         swap(s[i - 1], s[i]); n         c++; n       } n     } n   } n   for (long long i = 0; i < n; i++) { n     c += (s[i] != t[i]); n   } n   cout << c <<   n ; n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long t = 1; n   for (long long i = 1; i < t + 1; i++) { n     solve(); n   } n   cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class Data { n  public: n   int l, r, num; n   Data() {} n   Data(int a, int b, int c) { n     l = a; n     r = b; n     num = c; n   } n   bool operator<(const Data& a) const { return l < a.r; } n }; n vector<Data> a; n int main() { n   int L, b, f, n, q, k; n   cin >> L >> b >> f >> n; n   for (int(qwe) = 0; (qwe) < (n); ++(qwe)) { n     cin >> q >> k; n     if (q == 2) { n       for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i) n         if (i->num == k) { n           a.erase(i); n           break; n         } n     } else { n       bool ok = 0; n       int l = 0; n       int r = L - k; n       if (!a.empty()) r = a[0].l - k - f; n       if (l <= r) { n         a.insert(a.begin(), Data(l, l + k, qwe + 1)); n         cout << l << endl; n         continue; n       } n       for (int i = 0; i < ((int)(a).size()) - 1; ++i) n         if (a[i].r + b <= a[i + 1].l - f - k) { n           cout << a[i].r + b << endl; n           a.insert(a.begin() + i + 1, n                    Data(a[i].r + b, a[i].r + b + k, qwe + 1)); n           ok = 1; n           break; n         } n       if (ok) continue; n       r = L - k; n       l = 0; n       if (!a.empty()) l = a.back().r + b; n       if (l <= r) { n         a.push_back(Data(l, l + k, qwe + 1)); n         cout << l << endl; n       } else n         cout <<  -1 n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   std::string str; n   std::getline(std::cin, str); n   int number = 0; n   for (int j = 0, i = 0; j < str.size(); ++j) { n     int n = 0; n     while (j < str.size() && isdigit(str.at(j))) n = n * 10 + str.at(j++) - 48; n     number = number + n * i++; n     if (j >= str.size()) break; n   } n   std::cout << number << std::endl; n } n


#include <bits/stdc++.h> n using namespace std; n char c; n int s = 0, k = 0, n = 0, x, f = 0; n ; n int main() { n   while (cin.get(c)) { n     if (c ==   n ) break; n     switch (s) { n       case 0: { n         if (c >=  a  && c <=  z  || c >=  A  && c <=  Z  || c ==  _  || n             c >=  0  && c <=  9 ) { n           s = 1; n           k++; n         } else { n           cout <<  NO ; n           return 0; n         } n         break; n       } n       case 1: { n         if ((c >=  a  && c <=  z  || c >=  A  && c <=  Z  || c ==  _  || n              c >=  0  && c <=  9 ) && n             k < 16) n           k++; n         else if (c ==  @ ) { n           s = 2; n           k = 0; n           f = 1; n         } else { n           cout <<  NO ; n           return 0; n         } n         break; n       } n       case 2: { n         if ((c >=  a  && c <=  z  || c >=  A  && c <=  Z  || c ==  _  || n              c >=  0  && c <=  9 ) && n             k < 16 && n < 32) { n           k++; n           n++; n           f = 0; n         } else if (c ==  .  && f == 0) { n           k = 0; n           n++; n           f = 1; n         } else if (c ==  /  && f == 0) { n           k = 0; n           f = 1; n           s = 3; n         } else { n           cout <<  NO ; n           return 0; n         } n         break; n       } n       case 3: { n         if (c >=  a  && c <=  z  || c >=  A  && c <=  Z  || c ==  _  || n             c >=  0  && c <=  9 ) { n           k++; n           f = 0; n         } else if (c ==  /  && f == 0) { n           k = 0; n           f = 1; n         } else { n           cout <<  NO ; n           return 0; n         } n         break; n       } n     } n   } n   if (f == 1) n     cout <<  NO ; n   else n     cout <<  YES ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     double a, b, c, d, k; n     cin >> a >> b >> c >> d >> k; n     double pen = a / c; n     double pencil = b / d; n     pen = ceil(pen); n     pencil = ceil(pencil); n     if ((pen + pencil) <= k) { n       double diff = k - pen - pencil; n       cout << pen + diff <<     << pencil <<   n ; n     } else n       cout << -1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000023; n long long int power(long long int a, long long int b) { n   long long int ans = 1; n   while (b) { n     if (b & 1) ans = (ans * a); n     b /= 2; n     a = (a * a); n   } n   return ans; n } n bool sortbysec(const pair<long long int, long long int> &a, n                const pair<long long int, long long int> &b) { n   if (a.first > b.first) n     return 1; n   else if (a.first == b.first) n     return (a.second < b.second); n   else n     return 0; n } n long long int hash1[N]; n long long int p_pow[N]; n string str; n long long int n; n void cal_pow() { n   long long int p = 31; n   for (long long int i = 0; i < N; i++) { n     if (i != 0) n       p_pow[i] = (p_pow[i - 1] * p) % 1000000007; n     else n       p_pow[i] = 1; n   } n } n void calc() { n   hash1[0] = str[0] -  a  + 1; n   for (long long int i = 1; i <= str.size() - 1; i++) { n     hash1[i] = (hash1[i - 1] + (p_pow[i] * (str[i] -  a  + 1)) % 1000000007) % n                1000000007; n   } n } n long long int check(long long int val, long long int len) { n   for (long long int i = 1; i < n - len; i++) { n     long long int temp = n         (p_pow[n - 1 - i] * (hash1[i + len - 1] - hash1[i - 1] + 1000000007) % n          1000000007) % n         1000000007; n     if (temp == val) return 1; n   } n   return 0; n } n void solve() { n   cin >> str; n   cal_pow(); n   calc(); n   vector<pair<long long int, long long int>> v; n   n = str.size(); n   for (long long int i = 0; i < n - 1; i++) { n     long long int f = (p_pow[n - 1] * hash1[i]) % 1000000007; n     long long int s = n         (p_pow[i] * (hash1[n - 1] - hash1[n - i - 2] + 1000000007) % n          1000000007) % n         1000000007; n     if (f == s) v.push_back({i + 1, f}); n   } n   if (!v.size()) { n     cout <<  Just a legend  << endl; n     return; n   } n   sort((v).begin(), (v).end()); n   v.push_back({n + 3, 1}); n   long long int l = 0, r = v.size() - 1; n   if (!check(v[0].second, v[0].first)) { n     cout <<  Just a legend  << endl; n     return; n   } n   while ((l + 1) < r) { n     long long int mid = (l + r) / 2; n     if (check(v[mid].second, v[mid].first)) n       l = mid; n     else n       r = mid; n   } n   long long int idx = 0, len = v[l].first; n   while (len--) { n     cout << str[idx]; n     idx++; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int Test; n   Test = 1; n   long long int t = 0; n   while (t++ < Test) { n     solve(); n   } n   cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC n        <<  ms n ; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using pll = pair<ll, ll>; n bool cmpx(const pll& a, const pll& b) { return a.first < b.first; } n bool cmpy(const pll& a, const pll& b) { return a.second < b.second; } n ll sq(const ll& first) { return first * first; } n ll dis(const pll& a, const pll& b) { n   return sq(a.first - b.first) + sq(a.second - b.second); n } n vector<pll> px, py; n ll closest_pair(int l, int r) { n   if (r - l <= 1) return 1e18; n   int m = (l + r) / 2; n   ll d = min(closest_pair(l, m), closest_pair(m, r)); n   inplace_merge(py.begin() + l, py.begin() + m, py.begin() + r, cmpy); n   vector<pll> strip; n   for (int i = l; i < r; i++) n     if (sq(py[i].first - px[m].first) < d) strip.push_back(py[i]); n   for (int i = 0; i < strip.size(); i++) n     for (int j = i + 1; n          j < strip.size() && sq(strip[j].second - strip[i].second) < d; j++) n       d = min(d, dis(strip[i], strip[j])); n   return d; n } n void solve() { n   int n; n   cin >> n; n   ll cur = 0, first; n   for (int i = 0; i < n; i++) { n     cin >> first; n     cur += first; n     px.emplace_back(i, cur); n   } n   sort(px.begin(), px.end(), cmpx); n   py = px; n   cout << closest_pair(0, n) <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   int owo = 1; n   while (owo--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const long long int INF = 1000000007; n const int N = 1000000 + 7; n long long int trans[N]; n long long int ca[N]; n long long int maxb[N]; n int main() { n   std::ios::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   long long int d; n   cin >> n >> d; n   for (int i = 0; i < n; i++) cin >> trans[i]; n   ca[0] = trans[0]; n   for (int i = 1; i < n; i++) ca[i] = ca[i - 1] + trans[i]; n   maxb[n] = LLONG_MIN / 2; n   for (int i = n - 1; i >= 0; i--) maxb[i] = max(ca[i], maxb[i + 1]); n   long long int currentAdd = 0; n   int ans = 0; n   for (int i = 0; i < n; i++) { n     ca[i] += currentAdd; n     if (ca[i] > d) { n       cout << -1 << endl; n       return 0; n     } n     if (trans[i] == 0) { n       if (ca[i] < 0) { n         long long int all = d - (maxb[i + 1] + currentAdd); n         if (ca[i] + all > d) { n           all = d - ca[i]; n         } n         ca[i] += all; n         currentAdd += all; n         if (ca[i] < 0) { n           cout << -1 << endl; n           return 0; n         } n         ans++; n       } n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int mod = 1000000007; n int dp[4][200005]; n int main() { n   long long a, b; n   scanf( %I64d %I64d , &a, &b); n   long long t = sqrt(2 * (a + b)); n   while ((t * t + t > 2 * (a + b)) || ((t * t + 3 * t + 2) <= 2 * (a + b))) { n     --t; n   } n   long long sum = t * (t + 1) / 2; n   dp[0][0] = 1; n   dp[1][0] = 1; n   dp[1][1] = 1; n   int cur = 0; n   for (int i = 1; i <= t; ++i) { n     long long temp = i * (i + 1) / 2; n     for (int j = 0; j <= temp && j <= a; ++j) { n       cur = i % 3; n       if (j == 0) { n         dp[cur][j] = 1; n         continue; n       } n       int k = cur - 1; n       if (k < 0) k = k + 3; n       dp[cur][j] = dp[k][j]; n       if (j >= i) dp[cur][j] += dp[k][j - i]; n       if (dp[cur][j] >= mod) dp[cur][j] %= mod; n     } n   } n   long long result = 0; n   long long temp = sum - b; n   if (temp < 0) temp = 0; n   t = t % 3; n   for (int i = (int)temp; i <= a; ++i) { n     result += dp[t][i]; n     result %= mod; n   } n   printf( %I64d n , result); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n template <class T1, class T2> n struct cmpf { n   bool rev; n   inline bool operator()(const pair<T1, T2>& a, const pair<T1, T2>& b) const { n     return (a.first < b.first) ^ rev; n   } n   cmpf(bool b = false) { rev = b; } n }; n template <class T1, class T2> n struct cmps { n   bool rev; n   inline bool operator()(const pair<T1, T2>& a, const pair<T1, T2>& b) const { n     return (a.second < b.second) ^ rev; n   } n   cmps(bool b = false) { rev = b; } n }; n long long binpow(long long x, long long p, const long long& mod) { n   assert(mod > 0); n   long long ret = 1; n   for (; p > 0; p >>= 1, x = x * x % mod) n     if (p & 1) ret = ret * x % mod; n   return ret; n } n template <class T> n bool chmn(T& a, const T& b) { n   return (greater<T>()(a, b) ? (a = b, true) : false); n } n template <class T> n bool chmx(T& a, const T& b) { n   return (less<T>()(a, b) ? (a = b, true) : false); n } n void setIO(const string& filename =   ) { n   if (filename.size() > 0) { n     freopen((filename +  .in ).c_str(),  r , stdin); n     freopen((filename +  .out ).c_str(),  w , stdout); n   } n   cin.tie(0)->sync_with_stdio(0); n } n int chr[8] = {-1, 0, 1, 0, -1, -1, 1, 1}; n int chc[8] = {0, 1, 0, -1, -1, 1, -1, 1}; n const long long MOD = 1e9 + 7; n const int INIT = 1001001001; n const int MN = 201001; n const long long INF = 2e18 + 1; n long long N, M, K, Q; n pair<long long, long long> A[MN]; n long long safe[MN]; n long long treasure[MN][2]; n long long dp[MN][2]; n void solve(int testcase) { n   cin >> N >> M >> K >> Q; n   for (int i = 0; i < N; ++i) { n     treasure[i][0] = INIT; n     treasure[i][1] = 0; n     dp[i][0] = dp[i][1] = INF; n   } n   vector<long long> rows; n   rows.push_back(0); n   for (int i = 0; i < K; ++i) { n     cin >> A[i].first >> A[i].second; n     --A[i].first; n     --A[i].second; n     rows.push_back(A[i].first); n   } n   for (int i = 0; i < Q; ++i) { n     cin >> safe[i]; n     --safe[i]; n   } n   sort(safe, safe + Q); n   sort(begin(rows), end(rows)); n   rows.resize(unique(begin(rows), end(rows)) - rows.begin()); n   const int R = ((int)(rows.size())); n   long long up_cost = 0; n   for (int i = 0; i < K; ++i) { n     chmx(up_cost, A[i].first); n     A[i].first = lower_bound(begin(rows), end(rows), A[i].first) - rows.begin(); n     chmn(treasure[A[i].first][0], A[i].second); n     chmx(treasure[A[i].first][1], A[i].second); n   } n   if (treasure[0][0] == INIT) treasure[0][0] = 0; n   dp[0][0] = treasure[0][1] + (treasure[0][1] - treasure[0][0]); n   dp[0][1] = treasure[0][1]; n   for (int r = 1; r < R; ++r) { n     long long reach_left = INF, reach_right = INF; n     for (int i = 0; i < 4; ++i) { n       int idx; n       if (i >= 2) { n         idx = (upper_bound(safe, safe + Q, treasure[r - 1][i & 1]) - safe) - 1; n       } else { n         idx = lower_bound(safe, safe + Q, treasure[r - 1][i & 1]) - safe; n       } n       if (0 <= idx && idx < Q) { n         const long long dist = n             dp[r - 1][i & 1] + abs(safe[idx] - treasure[r - 1][i & 1]); n         chmn(reach_left, dist + abs(treasure[r][0] - safe[idx])); n         chmn(reach_right, dist + abs(treasure[r][1] - safe[idx])); n       } n     } n     const long long between = treasure[r][1] - treasure[r][0]; n     dp[r][0] = reach_right + between; n     dp[r][1] = reach_left + between; n   } n   (treasure, R, 2); n   (dp, R, 2); n   cout << up_cost + min(dp[R - 1][0], dp[R - 1][1]) << endl; n } n int main() { n   setIO(); n   long long T = 1; n   for (int t = 1; t <= T; ++t) { n     solve(t); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char buf[100005]; n int cnt[10]; n int cnt2[10]; n int main() { n   scanf( %s , buf); n   int N = strlen(buf); n   for (int i = 0; i < (N); ++i) cnt[buf[i] -  0 ]++; n   for (int i = 0; i < (10); ++i) cnt2[i] = cnt[i]; n   int best = 0, bestres = cnt[0]; n   for (int d = 1; d <= 9; ++d) { n     if (!cnt[d] || !cnt2[10 - d]) continue; n     cnt[d]--; n     cnt2[10 - d]--; n     int temp = 1; n     for (int i = 0; i < (10); ++i) temp += min(cnt[i], cnt2[9 - i]); n     temp += max(0, min(cnt[0] - cnt2[9], cnt2[0] - cnt[9])); n     cnt[d]++; n     cnt2[10 - d]++; n     if (temp > bestres) { n       bestres = temp; n       best = d; n     } n   } n   if (best == 0) { n     for (int i = 0; i < (2); ++i) { n       for (int j = 9; j >= 0; j--) n         for (int k = 0; k < (cnt[j]); ++k) printf( %d , j); n       printf(  n ); n     } n   } else { n     cnt[best]--; n     cnt2[10 - best]--; n     int ilezer = max(0, min(cnt[0] - cnt2[9], cnt2[0] - cnt[9])); n     for (int j = 0; j < (10); ++j) { n       int ile = cnt[j] - min(cnt[j], cnt2[9 - j]); n       if (j == 0) ile -= ilezer; n       for (int k = 0; k < (ile); ++k) printf( %d , j); n     } n     for (int j = 0; j < (10); ++j) { n       for (int k = 0; k < (min(cnt[j], cnt2[9 - j])); ++k) printf( %d , j); n     } n     printf( %d , best); n     for (int k = 0; k < (ilezer); ++k) printf( 0 ); n     printf(  n ); n     for (int j = 0; j < (10); ++j) { n       int ile = cnt2[j] - min(cnt2[j], cnt[9 - j]); n       if (j == 0) ile -= ilezer; n       for (int k = 0; k < (ile); ++k) printf( %d , j); n     } n     for (int j = 9; j >= 0; j--) { n       for (int k = 0; k < (min(cnt2[j], cnt[9 - j])); ++k) printf( %d , j); n     } n     printf( %d , 10 - best); n     for (int k = 0; k < (ilezer); ++k) printf( 0 ); n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s[1005], ss[1005]; n   cin >> s[0] >> ss[0]; n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> s[i] >> ss[i]; n   for (int i = 0; i <= n; i++) { n     if (i == 0) { n       cout << s[0] <<     << ss[0] << endl; n       continue; n     } else if (s[i] == s[i - 1]) { n       s[i] = ss[i]; n       ss[i] = ss[i - 1]; n       cout << s[i] <<     << ss[i] << endl; n     } else if (s[i] == ss[i - 1]) { n       s[i] = s[i - 1]; n       cout << s[i] <<     << ss[i] << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n int a[100]; n int ans; n int main() { n   cin >> n >> m >> k; n   for (int i = 0; i < k; i++) { n     cin >> a[i]; n     a[i]--; n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       int x; n       cin >> x; n       x--; n       int pos = 0; n       while (a[pos] != x) { n         pos++; n       } n       ans += pos + 1; n       for (int i = pos; i > 0; i--) { n         a[i] = a[i - 1]; n       } n       a[0] = x; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   long long n, k; n   cin >> n >> k; n   long long ans = 0; n   for (int i = (int)0; i < (int)n; ++i) { n     long long l, r; n     cin >> l >> r; n     ans += r - l + 1; n   } n   int ted = 0; n   while (ans % k) { n     ted++; n     ans++; n   } n   cout << ted << endl; n } n


#include <bits/stdc++.h> n using namespace std; n vector<string> val; n bool check1[110]; n bool check2[110]; n char a[5] = { R ,  G ,  B ,  Y ,  W }; n bool used1[5]; n bool used2[5]; n char val1[5]; n int val2[5]; n int ans = 1000 * 1000; n void go2(int pos, int cnt, int cnt2) { n   if (pos == cnt) { n     for (int i = 0; i < val.size(); i++) { n       check1[i] = false; n       check2[i] = false; n     } n     for (int i = 0; i < cnt2; i++) { n       for (int j = 0; j < val.size(); j++) { n         if (val[j][0] == val1[i]) { n           check1[j] = true; n         } n       } n     } n     for (int i = 0; i < cnt; i++) { n       for (int j = 0; j < val.size(); j++) { n         if ((val[j][1] -  0 ) == val2[i]) check2[j] = true; n       } n     } n     for (int i = 0; i < val.size(); i++) { n       if (check1[i] == true && check2[i]) continue; n       if (check1[i] && !check2[i]) { n         for (int j = i + 1; j < val.size(); j++) { n           if (check1[j] && !check2[j]) n             if (val[i][1] != val[j][1] && val[i][0] == val[j][0]) return; n         } n       } n       if (!check1[i] && check2[i]) { n         for (int j = i + 1; j < val.size(); j++) { n           if (!check1[j] && check2[j]) { n             if (val[i][0] != val[j][0] && val[i][1] == val[j][1]) return; n           } n         } n       } n       if (!check1[i] && !check2[i]) { n         for (int j = i + 1; j < val.size(); j++) { n           if (!check1[j] && !check2[j]) n             if (val[i] != val[j]) return; n         } n       } n     } n     if (ans > cnt + cnt2) ans = cnt + cnt2; n   } else { n     for (int i = 0; i < 5; i++) { n       if (!used2[i]) { n         used2[i] = true; n         val2[pos] = i + 1; n         go2(pos + 1, cnt, cnt2); n         used2[i] = false; n       } n     } n   } n } n void go1(int pos, int cnt) { n   if (pos == cnt) { n     go2(0, 0, cnt); n     go2(0, 1, cnt); n     go2(0, 2, cnt); n     go2(0, 3, cnt); n     go2(0, 4, cnt); n     go2(0, 5, cnt); n   } else { n     for (int i = 0; i < 5; i++) { n       if (!used1[i]) { n         used1[i] = true; n         val1[pos] = a[i]; n         go1(pos + 1, cnt); n         used1[i] = false; n       } n     } n   } n } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     string s; n     cin >> s; n     val.push_back(s); n   } n   go1(0, 0); n   go1(0, 1); n   go1(0, 2); n   go1(0, 3); n   go1(0, 4); n   go1(0, 5); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long m; n long long f(long long a) { n   long long res = 0; n   for (long long k = 2;; k++) { n     long long k3 = k * k * k; n     if (k3 > a) break; n     if (res > m - a / k3) return -1; n     res += a / k3; n   } n   return res; n } n int main() { n   cin >> m; n   long long l = 1, r = 9000000000000000000LL; n   while (l < r) { n     long long mid = (l + r) >> 1; n     long long rr = f(mid); n     if (rr >= m || rr == -1) n       r = mid; n     else n       l = mid + 1; n   } n   while (f(l - 1) == m) l--; n   cout << (f(l) == m ? l : -1) << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 505; n const long long MOD = 998244353; n int n, sizb, sizc; n long long a[MAXN], b[MAXN], c[MAXN]; n bool fac[MAXN]; n std::map<long long, int> mp; n inline long long gcd(long long x, long long y) { n   if (!x || !y) return x + y; n   while (y) { n     std::swap(x, y); n     y %= x; n   } n   return x; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %I64d , &a[i]); n     if (a[i] == 1) n--, i--; n   } n   for (int i = 1; i <= n; i++) { n     long long sq = sqrt(a[i]) + 0.5; n     if (sq * sq == a[i]) { n       fac[i] = 1; n       long long sqsq = sqrt(sq) + 0.5; n       if (sqsq * sqsq == sq) { n         if (mp.find(sqsq) != mp.end()) n           mp[sqsq] = mp[sqsq] + 4; n         else n           mp[sqsq] = 4; n         continue; n       } n       if (mp.find(sq) != mp.end()) n         mp[sq] = mp[sq] + 2; n       else n         mp[sq] = 2; n       continue; n     } n     long long cb = cbrt(a[i]) + 0.5; n     if (cb * cb * cb == a[i]) { n       fac[i] = 1; n       if (mp.find(cb) != mp.end()) n         mp[cb] = mp[cb] + 3; n       else n         mp[cb] = 3; n       continue; n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = i + 1; j <= n; j++) { n       if (a[i] == a[j]) continue; n       long long d = gcd(a[i], a[j]); n       if (d == 1) continue; n       if (!fac[i]) { n         if (mp.find(d) != mp.end()) n           mp[d] = mp[d] + 1; n         else n           mp[d] = 1; n         long long e = a[i] / d; n         if (mp.find(e) != mp.end()) n           mp[e] = mp[e] + 1; n         else n           mp[e] = 1; n         fac[i] = 1; n       } n       if (!fac[j]) { n         if (mp.find(d) != mp.end()) n           mp[d] = mp[d] + 1; n         else n           mp[d] = 1; n         long long e = a[j] / d; n         if (mp.find(e) != mp.end()) n           mp[e] = mp[e] + 1; n         else n           mp[e] = 1; n         fac[j] = 1; n       } n     } n     if (!fac[i]) c[++sizc] = a[i]; n   } n   std::sort(c + 1, c + sizc + 1); n   long long ans = 1; n   for (auto it : mp) ans = ans * (it.second + 1) % MOD; n   int temp = 0; n   for (int i = 1; i <= sizc; i++) { n     if (i == 1 || c[i] == c[i - 1]) n       temp++; n     else { n       ans = ans * (temp + 1) % MOD * (temp + 1) % MOD; n       temp = 1; n     } n   } n   ans = ans * (temp + 1) % MOD * (temp + 1) % MOD; n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, n, fl = 0, fl2; n   cin >> t; n   while (t--) { n     fl = 0, fl2 = 0; n     cin >> n; n     vector<int> v; n     int p = n; n     for (int i = 2; i * i <= n; i++) { n       if (p % i == 0 && fl <= 1) { n         v.push_back(i); n         p /= i; n         fl++; n       } n     } n     if (v.size() == 2 && v[0] != v[1] && v[0] != p && v[1] != p) { n       cout <<  YES  << endl; n       cout << v[0] <<     << v[1] <<     << p << endl; n     } else n       cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 1e5 + 10; n unordered_set<int> adj[MX]; n vector<int> ans; n bool vis[MX]; n set<pair<int, int>> ord; n void dfs(int u) { n   vis[u] = true; n   ans.push_back(u); n   for (int v : adj[u]) { n     if (!vis[v]) dfs(v); n   } n } n bool can(int k, int t, int n) { n   k -= t; n   for (int i = 1; i <= n; i++) vis[i] = false; n   while (!ord.empty()) { n     auto it = ord.begin(); n     if ((*it).first >= k) break; n     int u = (*it).second; n     ord.erase(it); n     for (int v : adj[u]) { n       ord.erase({adj[v].size(), v}); n       adj[v].erase(u); n       if (adj[v].size() != 0) ord.insert({adj[v].size(), v}); n     } n     adj[u].clear(); n   } n   if (t == 0) { n     for (int i = 1; i <= n; i++) { n       if (!vis[i]) { n         ans.clear(); n         dfs(i); n         if (ans.size() > k) { n           cout << 1 <<     << ans.size() <<   n ; n           for (int xx : ans) cout << xx <<    ; n           cout <<   n ; n           return true; n         } n       } n     } n     return false; n   } n   while (!ord.empty()) { n     auto it = ord.begin(); n     if ((*it).first > k) break; n     int u = (*it).second; n     if ((*it).first == k) { n       vector<int> vv; n       vv.push_back(u); n       for (int v : adj[u]) vv.push_back(v); n       bool ok = true; n       for (int i = 0; i <= k; i++) { n         for (int j = i + 1; j <= k; j++) { n           if (adj[vv[i]].find(vv[j]) == adj[vv[i]].end()) { n             ok = false; n             break; n           } n         } n         if (!ok) break; n       } n       if (ok) { n         cout << 2 <<   n ; n         for (int xx : vv) cout << xx <<    ; n         cout <<   n ; n         return true; n       } n     } n     ord.erase(it); n     for (int v : adj[u]) { n       ord.erase({adj[v].size(), v}); n       adj[v].erase(u); n       if (adj[v].size() != 0) ord.insert({adj[v].size(), v}); n     } n     adj[u].clear(); n   } n   return false; n } n void solve() { n   int n, m, k; n   cin >> n >> m >> k; n   ord.clear(); n   ans.clear(); n   for (int i = 1; i <= n; i++) { n     adj[i].clear(); n     vis[i] = false; n   } n   int x, y; n   for (int i = 0; i < m; i++) { n     cin >> x >> y; n     adj[x].insert(y); n     adj[y].insert(x); n   } n   for (int i = 1; i <= n; i++) ord.insert({adj[i].size(), i}); n   if (can(k, 1, n)) return; n   if (can(k, 0, n)) return; n   cout << -1 <<   n ; n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cout.precision(10); n   cout << fixed; n   int t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string str; n string sbyt( 127 ), ssho( 32767 ), sint( 2147483647 ), n     slon( 9223372036854775807 ); n int main() { n   while (cin >> str) { n     if (str.size() > 19) { n       cout <<  BigInteger n ; n       continue; n     } n     if (str.size() < sbyt.size()) n       cout <<  byte n ; n     else if (str.size() == sbyt.size() && str <= sbyt) n       cout <<  byte n ; n     else if (str.size() < ssho.size()) n       cout <<  short n ; n     else if (str.size() == ssho.size() && str <= ssho) n       cout <<  short n ; n     else if (str.size() < sint.size()) n       cout <<  int n ; n     else if (str.size() == sint.size() && str <= sint) n       cout <<  int n ; n     else if (str.size() < slon.size()) n       cout <<  long n ; n     else if (str.size() == slon.size() && str <= slon) n       cout <<  long n ; n     else n       cout <<  BigInteger n ; n   } n } n


#include <bits/stdc++.h> n namespace tree { n const int N = 501000, MOD = 998244353; n inline void inc(int a, int &b) { b = (a + b) % MOD; } n int begin[N], next[N * 2], to[N * 2]; n int f[N][2], siz[N][2]; n int n, e; n void add(int x, int y, bool k = 1) { n   to[++e] = y; n   next[e] = begin[x]; n   begin[x] = e; n   if (k) add(y, x, 0); n } n void dfs(int p = 1, int h = 0) { n   f[p][0] = 0, f[p][1] = 0; n   siz[p][0] = 1, siz[p][1] = 0; n   for (int i = begin[p], q; i; i = next[i]) n     if ((q = to[i]) != h) { n       dfs(q, p); n       int F[2] = {0}, S[2] = {0}; n       for (int cut = 0; cut <= 1; cut++) n         for (int x = 0; x <= 1; x++) n           for (int y = 0; y <= 1; y++) { n             if (!cut && !x && !y) { n               inc((long long)f[p][x] * siz[q][y] % MOD, F[1]); n               inc((long long)f[q][y] * siz[p][x] % MOD, F[1]); n               inc((long long)siz[p][x] * siz[q][y] % MOD, F[1]); n               inc((long long)siz[p][x] * siz[q][y] % MOD, S[1]); n             } else { n               inc((long long)f[p][x] * siz[q][y] % MOD, F[x]); n               inc((long long)f[q][y] * siz[p][x] % MOD, F[x]); n               inc((long long)siz[p][x] * siz[q][y] % MOD, S[x]); n             } n           } n       f[p][0] = F[0], siz[p][0] = S[0]; n       f[p][1] = F[1], siz[p][1] = S[1]; n     } n } n void solve() { n   scanf( %d , &n); n   for (int i = 1, u, v; i < n; i++) scanf( %d%d , &u, &v), add(u, v); n   dfs(); n   int ans = (f[1][0] + f[1][1]) * 2ll % MOD; n   ans = (ans + MOD) % MOD; n   printf( %d n , ans); n } n }  // namespace tree n int main() { n   tree::solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5; n int n, fa[maxn + 2], cont[maxn + 2]; n int mx1[maxn + 2], mx2[maxn + 2], diameter[maxn + 2]; n bool vist[maxn + 2]; n vector<int> G[maxn + 2]; n vector<long long> dist[maxn + 2]; n map<pair<int, int>, double> Map; n void dfs1(int x, int pre, int col) { n   vist[x] = 1, fa[x] = col; n   int aa[3]; n   for (auto nx : G[x]) { n     if (nx == pre) continue; n     dfs1(nx, x, col); n     aa[0] = mx1[nx] + 1, aa[1] = mx1[x], aa[2] = mx2[x]; n     sort(aa, aa + 3); n     mx1[x] = aa[2], mx2[x] = aa[1]; n   } n } n void dfs2(int x, int pre, vector<long long> &ds, int di) { n   ds.push_back(max(di, mx1[x])); n   for (auto nx : G[x]) { n     if (nx == pre) continue; n     if (mx1[nx] + 1 == mx1[x]) n       dfs2(nx, x, ds, max(di, mx2[x]) + 1); n     else n       dfs2(nx, x, ds, max(di, mx1[x]) + 1); n   } n } n int BinSearch(vector<long long> &arr, long long key) { n   int l = 1, r = arr.size() - 1, res = 0; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (arr[mid] - arr[mid - 1] < key) n       res = mid, l = mid + 1; n     else n       r = mid - 1; n   } n   return res; n } n int main() { n   int m, T, u, v; n   scanf( %d%d%d , &n, &m, &T); n   for (int i = 1; i <= n; ++i) fa[i] = i; n   for (int i = 1; i <= m; ++i) { n     scanf( %d%d , &u, &v); n     G[u].push_back(v); n     G[v].push_back(u); n   } n   for (int i = 1; i <= n; ++i) n     if (!vist[i]) { n       dfs1(i, 0, i); n       dfs2(i, 0, dist[i], 0); n       dist[i].push_back(0); n       sort(dist[i].begin(), dist[i].end()); n       diameter[i] = dist[i][dist[i].size() - 1]; n       for (int k = 1; k < dist[i].size(); ++k) dist[i][k] += dist[i][k - 1]; n     } n   while (T--) { n     scanf( %d%d , &u, &v); n     u = fa[u], v = fa[v]; n     if (u == v) { n       printf( %d n , -1); n       continue; n     } n     if (Map.count(make_pair(u, v))) { n       printf( %f n , Map[make_pair(u, v)]); n       continue; n     } n     if (dist[u].size() > dist[v].size()) swap(u, v); n     long long mxd = max(diameter[u], diameter[v]), sum = 0; n     for (int i = 1; i < dist[u].size(); ++i) { n       int index = BinSearch(dist[v], mxd - (dist[u][i] - dist[u][i - 1]) - 1); n       sum += (dist[v][dist[v].size() - 1] - dist[v][index]); n       sum += (dist[u][i] - dist[u][i - 1] + 1) * (dist[v].size() - 1 - index); n       sum += mxd * index; n     } n     double ans = double(sum) / (dist[u].size() - 1) / (dist[v].size() - 1); n     Map[make_pair(u, v)] = Map[make_pair(v, u)] = ans; n     printf( %.10f n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base ::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, i, j, k, x, cnt = 0, y; n   vector<int> a; n   vector<int> b; n   vector<int> c; n   vector<int> d; n   vector<int> e; n   vector<int> f; n   vector<int> v; n   map<int, int> p; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> x; n     if (x == 4) n       a.push_back(i); n     else if (x == 8) n       b.push_back(i); n     else if (x == 15) n       c.push_back(i); n     else if (x == 16) n       d.push_back(i); n     else if (x == 23) n       e.push_back(i); n     else n       f.push_back(i); n   } n   v.push_back(a.size()); n   v.push_back(b.size()); n   v.push_back(c.size()); n   v.push_back(d.size()); n   v.push_back(e.size()); n   v.push_back(f.size()); n   sort(v.begin(), v.end()); n   k = v[0]; n   i = 0; n   while (k--) { n     j = upper_bound(b.begin(), b.end(), a[i]) - b.begin(); n     if (j >= b.size() || b.size() == 0) break; n     y = j; n     j = upper_bound(c.begin(), c.end(), b[j]) - c.begin(); n     b.erase(b.begin(), b.begin() + y + 1); n     if (j >= c.size() || c.size() == 0) break; n     y = j; n     j = upper_bound(d.begin(), d.end(), c[j]) - d.begin(); n     c.erase(c.begin(), c.begin() + y + 1); n     if (j >= d.size() || d.size() == 0) break; n     y = j; n     j = upper_bound(e.begin(), e.end(), d[j]) - e.begin(); n     d.erase(d.begin(), d.begin() + y + 1); n     if (j >= e.size() || e.size() == 0) break; n     y = j; n     j = upper_bound(f.begin(), f.end(), e[j]) - f.begin(); n     e.erase(e.begin(), e.begin() + y + 1); n     if (j >= f.size() || f.size() == 0) break; n     f.erase(f.begin(), f.begin() + j + 1); n     i++; n     cnt++; n   } n   cout << n - cnt * 6; n } n


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


#include <bits/stdc++.h> n using namespace std; n void read_file(bool outToFile = true) {} n int main() { n   read_file(); n   string a, b; n   char str[1000000 + 1]; n   while (scanf( %s , str) != EOF) { n     a = str; n     scanf( %s , str); n     b = str; n     int n = a.length(), m = b.length(); n     if (n != m) { n       printf( NO n ); n       continue; n     } n     if (n == 1) { n       string ans = a == b ?  YES  :  NO ; n       printf( %s n , ans.c_str()); n       continue; n     } n     bool aHasOne, bHasOne; n     aHasOne = bHasOne = 0; n     for (int i = 0; i < n; i++) { n       if (a[i] ==  1 ) aHasOne = 1; n       if (b[i] ==  1 ) bHasOne = 1; n     } n     string ans = aHasOne == bHasOne ?  YES  :  NO ; n     printf( %s n , ans.c_str()); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, comp = 0, a[100005], b[100005], v[100005]; n bool vis[100005]; n set<int> s[100005]; n void dfs(int u) { n   if (vis[u]) return; n   vis[u] = true; n   s[comp].insert(u); n   dfs(v[u]); n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     b[i] = a[i]; n   } n   sort(b, b + n); n   for (int i = 0; i < n; i++) { n     int l = 0, r = n - 1; n     while (l <= r) { n       int mid = (l + r) / 2; n       if (b[mid] == a[i]) { n         v[i] = mid; n         break; n       } else if (b[mid] < a[i]) { n         l = mid + 1; n       } else { n         r = mid - 1; n       } n     } n   } n   for (int i = 0; i < n; i++) { n     if (!vis[i]) { n       dfs(i); n       comp++; n     } n   } n   cout << comp << endl; n   for (int i = 0; i < comp; i++) { n     cout << s[i].size(); n     for (set<int>::iterator it = s[i].begin(); it != s[i].end(); it++) { n       cout <<     << (*it + 1); n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long used[100001], last, a[100001]; n vector<long long> v[1000001], verr[100001]; n void build(long long tv, long long tl, long long tr) { n   if (tl == tr) n     v[tv].push_back(used[tl]); n   else { n     long long tm = (tl + tr) / 2; n     build(tv * 2, tl, tm); n     build(tv * 2 + 1, tm + 1, tr); n     long long x = 0, y = 0; n     while (x < v[tv * 2].size() && y < v[tv * 2 + 1].size()) { n       if (v[tv * 2][x] < v[tv * 2 + 1][y]) { n         v[tv].push_back(v[tv * 2][x]); n         x++; n       } else { n         v[tv].push_back(v[tv * 2 + 1][y]); n         y++; n       } n     } n     while (x < v[tv * 2].size()) { n       v[tv].push_back(v[tv * 2][x]); n       x++; n     } n     while (y < v[tv * 2 + 1].size()) { n       v[tv].push_back(v[tv * 2 + 1][y]); n       y++; n     } n   } n } n long long ans(long long tv, long long tl, long long tr, long long l, n               long long r, long long z) { n   if (r < tl || tr < l) return 0; n   if (l <= tl && tr <= r) { n     long long x, y; n     x = 0; n     y = v[tv].size() - 1; n     while (x + 1 < y) { n       long long mm = (x + y) / 2; n       if (v[tv][mm] < z) n         x = mm; n       else n         y = mm; n     } n     if (v[tv][y] < z) return y + 1; n     if (v[tv][x] < z) return x + 1; n     return 0; n   } n   long long tm = (tl + tr) / 2; n   return ans(tv * 2, tl, tm, l, r, z) + ans(tv * 2 + 1, tm + 1, tr, l, r, z); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n, k, i, j, l, r, x, y, q; n   cin >> n >> k; n   for (i = 1; i <= n; i++) { n     cin >> a[i]; n     verr[a[i]].push_back(i); n   } n   for (i = 1; i <= 100000; i++) { n     for (j = 0; j < verr[i].size(); j++) { n       if (j + 1 - k > 0) { n         used[verr[i][j]] = verr[i][j - k]; n       } n     } n   } n   build(1, 1, n); n   cin >> q; n   for (i = 1; i <= q; i++) { n     cin >> x >> y; n     l = (x + last) % n + 1; n     r = (y + last) % n + 1; n     if (l > r) swap(l, r); n     last = ans(1, 1, n, l, r, l); n     cout << last <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[100005]; n int main() { n   int n, k, x, sum; n   scanf( %d %d , &n, &k); n   for (int i = 0; i < (n); i++) scanf( %d , &a[i]); n   int ng = 0, ps = 0, nm = -(1 << 28), pm = (1 << 28); n   for (int i = 0; i < (n); i++) { n     if (a[i] < 0) n       ng++; n     else n       ps++; n     if (a[i] < 0 && a[i] > nm) n       nm = a[i]; n     else if (a[i] >= 0 && a[i] < pm) n       pm = a[i]; n   } n   if (ng >= k) { n     sum = 0; n     for (int i = 0; i < (n); i++) { n       if (i < k) n         sum += ((a[i]) < 0 ? -(a[i]) : (a[i])); n       else n         sum += a[i]; n     } n   } else { n     sum = 0; n     for (int i = 0; i < (n); i++) { n       sum += ((a[i]) < 0 ? -(a[i]) : (a[i])); n     } n     if ((k - ng) & 1) { n       if (!ng) n         sum = sum - 2 * a[0]; n       else n         sum = ((sum + 2 * nm > sum - 2 * pm) ? (sum + 2 * nm) : (sum - 2 * pm)); n     } n   } n   printf( %d n , sum); 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(NULL); n   int n; n   string s; n   cin >> n >> s; n   int steps0 = 0; n   int steps1 = 0; n   for (int i = 0; i < n; ++i) { n     steps0 += ((s[i] -  0 ) != (i % 2)); n     steps1 += ((s[i] -  0 ) == (i % 2)); n   } n   cout << min(steps0, steps1) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 105; n long long max(long long a, long long b) { n   if (a > b) n     return a; n   else n     return b; n } n long long min(long long a, long long b) { n   if (a < b) n     return a; n   else n     return b; n } n void vecdisp(vector<long long> v) { n   for (long long i = 0; i < v.size(); i++) cout << v[i] <<    ; n } n void arrdisp(long long a[], long long n) { n   for (long long i = 0; i < n; i++) cout << a[i] <<    ; n } n void sarrdisp(string s[], long long n) { n   for (long long i = 0; i < n; i++) cout << s[i] <<   n ; n } n void twodarrdisp(long long *a, long long r, long long c) { n   for (long long i = 0; i < r; i++) { n     for (long long j = 0; j < c; j++) cout << (*((a + i * c) + j)) <<    ; n     cout <<   n ; n   } n } n void setdisp(set<long long> s) { n   for (auto it = s.begin(); it != s.end(); ++it) cout <<     << *it; n } n long long nod(long long a) { n   long long c = 0; n   set<long long> s; n   while (a > 0) { n     ++c; n     s.insert(a % 10); n     a /= 10; n   } n   if (s.size() == c) n     return 1; n   else n     return 0; n } n long long sod(long long a) { n   long long c = 0; n   while (a > 0) { n     c += a % 10; n     a /= 10; n   } n   return c; n } n bool isComposite(long long n) { n   if (n <= 1) return false; n   if (n <= 3) return false; n   if (n % 2 == 0 || n % 3 == 0) return true; n   for (long long i = 5; i * i <= n; i += 6) { n     if (n % i == 0 || n % (i + 2) == 0) return true; n   } n   return false; n } n long long countDivisors(long long n) { n   long long cnt = 0; n   for (long long i = 1; i <= sqrt(n); i++) { n     if (n % i == 0) { n       if (n / i == i) n         cnt++; n       else n         cnt += 2; n     } n   } n   return cnt; n } n long long isPalindrome(string s) { n   long long l = s.size(); n   long long flag = 0; n   for (long long i = 0; i < l; i++) { n     if (s[i] != s[l - i - 1]) { n       flag = 1; n       break; n     } n   } n   if (flag) n     return 0; n   else n     return 1; n } n void solve() { n   long long stops[N] = {0}; n   long long n, r, x; n   cin >> n; n   for (long long i = 0; i < n; i++) { n     cin >> r; n     for (long long i = 0; i < r; i++) { n       cin >> x; n       ++stops[x]; n     } n   } n   for (long long i = 1; i <= 100; i++) { n     if (stops[i] == n) cout << i <<    ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   long long t = 1; n   if (!t) cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 1; n vector<pair<long long, long long> > g[N]; n set<pair<long long, long long> > q; n long long dist[N]; n int main() { n   cin.tie(0); n   cout.tie(0); n   long long n, m, u, v, w; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     cin >> u >> v >> w; n     u--; n     v--; n     w = w * 2; n     g[u].push_back({v, w}); n     g[v].push_back({u, w}); n   } n   for (int i = 0; i < n; i++) { n     cin >> dist[i]; n     q.insert({dist[i], i}); n   } n   while (!q.empty()) { n     auto now = *q.begin(); n     auto u = now.second; n     q.erase(q.begin()); n     for (auto v : g[u]) { n       if (dist[v.first] > dist[u] + v.second) { n         q.erase({dist[v.first], v.first}); n         dist[v.first] = dist[u] + v.second; n         q.insert({dist[v.first], v.first}); n       } n     } n   } n   for (int i = 0; i < n; i++) cout << dist[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios::sync_with_stdio(false); n   string s, res =   ; n   cin >> s; n   int len = s.length(); n   if (len <= 3) { n     cout << s[0] << endl; n     return 0; n   } n   int l = 0, r = len - 1; n   while (l + 1 < r - 1) { n     if (s[l] == s[r] || s[l] == s[r - 1]) n       res += s[l]; n     else if (s[l + 1] == s[r] || s[l + 1] == s[r - 1]) n       res += s[l + 1]; n     l += 2, r -= 2; n   } n   string ch =   ; n   if (l <= r) ch += s[l]; n   string re_res = res; n   reverse(re_res.begin(), re_res.end()); n   cout << res << ch << re_res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, col[100010], out[100010], sum[3], cn, id[100010]; n vector<int> g[100010]; n void dfs(int x) { n   for (int i = 0, v; i < g[x].size(); i++) { n     v = g[x][i]; n     if (col[v]) continue; n     col[v] = 3 ^ col[x]; n     dfs(v); n   } n } n void get() { n   for (int i = 1, st = 3; i <= n; i++) n     if (col[i] == 1 && !id[i]) { n       if (st == 3) cn++, st = 0; n       st++, id[i] = cn; n     } n   for (int i = 1, st = 3; i <= n; i++) n     if (col[i] == 2 && !id[i]) { n       if (st == 3) cn++, st = 0; n       st++, id[i] = cn; n     } n   puts( YES ); n   for (int i = 1; i <= n; i++) printf( %d  , id[i]); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0, u, v; i < m; i++) { n     scanf( %d%d , &u, &v); n     g[u].push_back(v); n     g[v].push_back(u); n   } n   for (int i = 1; i <= n; i++) n     if (!col[i]) col[i] = 1, dfs(i); n   for (int i = 1; i <= n; i++) n     for (int j = 0; j < g[i].size(); j++) n       if (col[i] ^ col[g[i][j]]) out[i]++; n   for (int i = 1; i <= n; i++) sum[col[i]]++; n   if (!(sum[1] % 3) && !(sum[2] % 3)) return get(), 0; n   if (sum[1] % 3 > sum[2] % 3) { n     swap(sum[1], sum[2]); n     for (int i = 1; i <= n; i++) col[i] = 3 ^ col[i]; n   } n   for (int i = 1; i <= n; i++) n     if (col[i] == 1 && sum[2] - out[i] >= 2) { n       id[i] = cn = 1; n       for (int p = 0; p < g[i].size(); p++) col[g[i][p]] = 0; n       for (int p = 1, st = 2; st && p <= n; p++) n         if (col[p] == 2) st--, id[p] = 1; n       for (int p = 0; p < g[i].size(); p++) col[g[i][p]] = 2; n       return get(), 0; n     } n   if (sum[1] > 1) { n     int xp = 0, yp = 0; n     for (int i = 1; i <= n; i++) n       if (col[i] == 2 && sum[1] - out[i] >= 2) { n         if (!xp) n           xp = i; n         else n           yp = i; n       } n     if (yp) { n       id[xp] = cn = 1; n       for (int p = 0; p < g[xp].size(); p++) col[g[xp][p]] = 0; n       for (int p = 1, st = 2; st && p <= n; p++) n         if (col[p] == 1) st--, id[p] = 1; n       for (int p = 0; p < g[xp].size(); p++) col[g[xp][p]] = 1; n       id[yp] = cn = 2; n       for (int p = 0; p < g[yp].size(); p++) col[g[yp][p]] = 0; n       for (int p = 1, st = 2; st && p <= n; p++) n         if (col[p] == 1) st--, id[p] = 2; n       for (int p = 0; p < g[yp].size(); p++) col[g[yp][p]] = 1; n       return get(), 0; n     } n   } n   return printf( NO ), 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   vector<bool> possible(1010); n   possible[0] = true; n   for (int i = 0; i < 1000; ++i) { n     if (!possible[i]) n       continue; n     else { n       possible[i + 3] = true; n       possible[i + 5] = true; n       possible[i + 7] = true; n     } n   } n   int t; n   cin >> t; n   for (int tt = 0; tt < t; ++tt) { n     int n; n     cin >> n; n     if (!possible[n]) { n       cout <<  -1 n ; n       continue; n     } else { n       vector<int64_t> ans(3); n       while (n != 0) { n         if (possible[n - 3]) { n           n -= 3; n           ans[0]++; n         } else if (possible[n - 5]) { n           n -= 5; n           ans[1]++; n         } else { n           n -= 7; n           ans[2]++; n         } n       } n       cout << ans[0] <<     << ans[1] <<     << ans[2] <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n long long v[4000 + 1], c[4000 + 1], d[4000 + 1], done[4000 + 1], sol[4000 + 1], n     stiva[4000 + 1]; n int main() { n   int n, i, j, vf; n   long long sum, sc; n   fscanf(stdin,  %d , &n); n   for (i = 1; i <= n; i++) { n     fscanf(stdin,  %I64d%I64d%I64d , &v[i], &d[i], &c[i]); n   } n   i = 1; n   while (i <= n) { n     if (done[i] == 0) { n       sol[++sol[0]] = i; n       sum = 0; n       j = i + 1; n       vf = 0; n       while ((v[i] > 0) && (j <= n)) { n         if (done[j] == 0) { n           c[j] -= v[i]; n           if (c[j] < 0) { n             done[j] = 1; n             stiva[++vf] = j; n           } n           v[i]--; n         } n         j++; n       } n       while (vf > 0) { n         sum = d[stiva[vf]]; n         vf--; n         for (j = stiva[vf + 1] + 1; j <= n; j++) { n           if (done[j] == 0) { n             c[j] -= sum; n             if (c[j] < 0) { n               done[j] = 1; n               stiva[++vf] = j; n             } n           } n         } n       } n     } n     i++; n   } n   fprintf(stdout,  %I64d n , sol[0]); n   for (i = 1; i <= sol[0]; i++) { n     fprintf(stdout,  %I64d  , sol[i]); n   } n   fclose(stdin); n   fclose(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 55; n int a[maxn][maxn], b[maxn][maxn]; n int vis[maxn][maxn]; n vector<pair<int, int> > ans; n int main(int argc, char const *argv[]) { n   ios::sync_with_stdio(false); n   int n, m; 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 , &a[i][j]); n     } n   } n   for (int i = 1; i < n; i++) { n     for (int j = 1; j < m; j++) { n       if (a[i + 1][j + 1] == 1 && a[i][j] == 1 && a[i + 1][j] == 1 && n           a[i][j + 1] == 1) { n         ans.push_back(make_pair(i, j)); n       } n     } n   } n   for (int i = 0; i < ans.size(); i++) { n     int x = ans[i].first; n     int y = ans[i].second; n     b[x][y] = 1; n     b[x + 1][y + 1] = 1; n     b[x + 1][y] = 1; n     b[x][y + 1] = 1; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (b[i][j] != a[i][j]) { n         printf( -1 n ); n         return 0; n       } n     } n   } n   printf( %d n , ans.size()); n   for (int i = 0; i < ans.size(); i++) { n     printf( %d %d n , ans[i].first, ans[i].second); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   vector<pair<int, bool> > list(n); n   for (int i = 0; i < n; i++) cin >> list[i].first; n   int tmp; n   for (int i = 0; i < m; i++) { n     cin >> tmp; n     list[tmp - 1].second = 1; n   } n   vector<int> v1(n - m), v2(m); n   int c1 = 0, c2 = 0; n   for (int i = 0; i < n; i++) { n     if (list[i].second == 1) n       v2[c1++] = list[i].first; n     else n       v1[c2++] = list[i].first; n   } n   sort(v1.begin(), v1.end()); n   sort(v2.begin(), v2.end()); n   c1 = c2 = 0; n   long long cnt = 0; n   for (int i = 0; i < v1.size(); i++) cnt += v1[i]; n   if (cnt < v2.back()) { n     cnt += v2.back(); n     v2.back() = -1; n   } n   for (int i = 0; i < v2.size(); i++) { n     if (v2[i] != -1) cnt *= 2; n   } n   cout << cnt; n   return 0; n } n


#include <bits/stdc++.h> n const int inf = (1ll << 30) - 1; n const int maxn = (int)1e5 + 10; n using namespace std; n int dp[150][(1 << 16) + 100]; n int c[111]; n int r[111]; n int b[111]; n char temp[111]; n int cntR[(1 << 16) + 10]; n int cntB[(1 << 16) + 10]; n int n; n void solve() { n   memset(dp, -1, sizeof dp); n   queue<pair<pair<int, int>, int> > pq; n   scanf( %d , &n); n   int xx = 0; n   for (int i = 0; i < n; i++) { n     scanf( %s%d%d , temp, &r[i], &b[i]); n     c[i] = temp[0] ==  R  ? 1 : 0; n     xx += c[i]; n   } n   if (xx * 2 > n) { n     for (int i = 0; i < n; i++) { n       c[i] ^= 1; n       swap(r[i], b[i]); n     } n   } n   for (int i = 0; i < (1 << n); i++) { n     for (int j = 0; j < n; j++) { n       if (i & (1 << j)) { n         if (c[j]) n           cntR[i]++; n         else n           cntB[i]++; n       } n     } n   } n   dp[0][0] = 0; n   pq.push(make_pair(make_pair(0, 0), 0)); n   while (pq.size() > 0) { n     int x = pq.front().first.first; n     int y = pq.front().first.second; n     int mask = pq.front().second; n     pq.pop(); n     if (dp[x][mask] < y) continue; n     for (int i = 0; i < n; i++) { n       if (mask & (1 << i)) continue; n       int nmask = mask | (1 << i); n       int X = x, Y = y; n       if (r[i] >= cntR[mask]) { n         X += cntR[mask]; n       } else n         X += r[i]; n       if (b[i] >= cntB[mask]) { n         Y += cntB[mask]; n       } else n         Y += b[i]; n       if (dp[X][nmask] == -1 || dp[X][nmask] < Y) { n         dp[X][nmask] = Y; n         pq.push(make_pair(make_pair(X, Y), nmask)); n       } n     } n   } n   int sumA = 0, sumB = 0; n   for (int i = 0; i < n; i++) { n     sumA += r[i]; n     sumB += b[i]; n   } n   int ans = inf; n   for (int i = 0; i < 144; i++) { n     if (dp[i][(1 << n) - 1] == -1) continue; n     ans = min(ans, max(sumA - i, sumB - dp[i][(1 << n) - 1])); n   } n   printf( %d n , ans + n); n } n int main() { n   int t = 1; n   for (int i = 1; i <= t; i++) { n     solve(); 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   long long a, b, c, count = 0; n   scanf( %lld %lld , &a, &b); n   while (a--) { n     scanf( %lld , &c); n     if (c <= b) n       count++; n     else n       count += 2; n   } n   printf( %lld , count); n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 300100, MOD = 1e9 + 7; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n int main() { n   ios::sync_with_stdio(0); n   cout.tie(0); n   cin.tie(0); n   int n; n   cin >> n; n   vector<int> arr(n); n   int odd = 0, even = 0; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     if (arr[i] % 2 == 0) n       even++; n     else n       odd++; n   } n   if (odd > 0 && even > 0) sort(arr.begin(), arr.end()); n   for (auto& a : arr) { n     cout << a <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, k, l, ans = 0, sign = 1, count = 0; n   string s; n   getline(cin, s); n   l = s.size(); n   vector<int> v; n   for (i = 0; i < l; i++) { n     if (s[i] ==  ? ) { n       v.push_back(sign); n       sign == 1 ? count++ : count--; n     } else if (s[i] ==  + ) n       sign = 1; n     else if (s[i] ==  - ) n       sign = -1; n     else if (s[i] !=     && s[i] !=  = ) { n       ans = 10 * ans + s[i] -  0 ; n     } n   } n   int remain = ans - count; n   vector<int> v1(v.size(), 1); n   for (i = 0; i < v.size(); i++) { n     if (v[i] == 1 && remain > 0) { n       int old = v1[i]; n       v1[i] = min(ans, v1[i] + remain); n       remain -= (v1[i] - old); n     } else if (v[i] == -1 && remain < 0) { n       int old = v1[i]; n       v1[i] = min(ans, v1[i] - remain); n       remain += (v1[i] - old); n     } n   } n   if (remain != 0) { n     printf( Impossible n ); n     return 0; n   } n   printf( Possible n ); n   for (i = 0; i < v.size(); i++) { n     if (i == 0) { n       printf( %d  , v1[i]); n     } else { n       printf( %c %d  , v[i] == 1 ?  +  :  - , v1[i]); n     } n   } n   printf( = %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, ans(0); n int main() { n   cin >> n >> m; n   while ((n + m) >= 3 && n > 0 && m > 0) { n     if (n >= m) { n       ans++; n       n -= 2; n       m--; n     } else { n       ans++; n       m -= 2; n       n--; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n void debug_out() { clog <<   n ; } n template <typename H, typename... T> n void debug_out(H head, T... tail) { n   clog <<     << head; n   debug_out(tail...); n } n template <typename T> n ostream &operator<<(ostream &os, const vector<T> &vec) { n   for (auto &i : vec) os << i <<    ; n   return os; n } n template <typename T> n ostream &operator<<(ostream &os, const vector<vector<T>> &vec) { n   if (!vec.empty()) os << vec[0]; n   for (size_t i = 1; i < vec.size(); ++i) os <<   n  << vec[i]; n   return os; n } n template <typename T, typename U> n ostream &operator<<(ostream &os, const pair<T, U> &p) { n   os << p.first <<     << p.second; n   return os; n } n template <typename T> n ostream &operator<<(ostream &os, const set<T> &s) { n   for (auto &i : s) os << i <<    ; n   return os; n } n struct SegmentTree { n   int n; n   vector<int> mi; n   vector<int64_t> sum; n   vector<int> push_value; n   SegmentTree(int _n) : n(_n) { n     mi.resize(4 * n); n     sum.resize(4 * n); n     push_value.resize(4 * n); n   } n   void push(int v, int tl, int tr) { n     if (push_value[v]) { n       push_value[v * 2] = push_value[v * 2 + 1] = push_value[v]; n       int mid = tl + tr >> 1; n       mi[v * 2] = mi[v * 2 + 1] = push_value[v]; n       sum[v * 2] = 1LL * (mid - tl + 1) * push_value[v]; n       sum[v * 2 + 1] = 1LL * (tr - mid) * push_value[v]; n       push_value[v] = 0; n     } n   } n   void update(int l, int r, int val) { update(1, 0, n - 1, l, r, val); } n   void update(int v, int tl, int tr, int l, int r, int val) { n     if (l > r) return; n     if (tl == l && tr == r) { n       push_value[v] = val; n       sum[v] = 1LL * (r - l + 1) * val; n       mi[v] = val; n     } else { n       push(v, tl, tr); n       int mid = tl + tr >> 1; n       update(v * 2, tl, mid, l, min(mid, r), val); n       update(v * 2 + 1, mid + 1, tr, max(mid + 1, l), r, val); n       mi[v] = min(mi[v * 2], mi[v * 2 + 1]); n       sum[v] = sum[v * 2] + sum[v * 2 + 1]; n     } n   } n   int ask(int l, int r, int y) { return ask(1, 0, n - 1, l, r, y); } n   int ask(int v, int tl, int tr, int l, int r, int y) { n     if (mi[v] >= y || l > r) return -1; n     if (tl == tr) return tl; n     push(v, tl, tr); n     int mid = tl + tr >> 1; n     int ans = ask(v * 2, tl, mid, l, min(mid, r), y); n     if (ans == -1) ans = ask(v * 2 + 1, mid + 1, tr, max(mid + 1, l), r, y); n     return ans; n   } n   int query(int l, int r, int &y) { return query(1, 0, n - 1, l, r, y); } n   int query(int v, int tl, int tr, int l, int r, int &y) { n     if (mi[v] > y || l > r) return 0; n     if (tl == tr) return y -= sum[v], 1; n     if (tl == l && tr == r && y >= sum[v]) return y -= sum[v], (r - l + 1); n     push(v, tl, tr); n     int mid = tl + tr >> 1; n     int ans = query(v * 2, tl, mid, l, min(mid, r), y); n     ans += query(v * 2 + 1, mid + 1, tr, max(mid + 1, l), r, y); n     return ans; n   } n   int get_element(int pos) { return get_element(1, 0, n - 1, pos); } n   int get_element(int v, int tl, int tr, int pos) { n     if (tl == tr) return sum[v]; n     push(v, tl, tr); n     int mid = tl + tr >> 1; n     if (pos <= mid) return get_element(v * 2, tl, mid, pos); n     return get_element(v * 2 + 1, mid + 1, tr, pos); n   } n   void print_tree() { n     cout <<  { ; n     if (n) cout << get_element(1, 0, n - 1, 0); n     for (int i = 1; i < n; ++i) cout <<  ,   << get_element(1, 0, n - 1, i); n     cout <<  } n ; n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, q; n   cin >> n >> q; n   SegmentTree st(n); n   for (int i = 0; i < n; ++i) { n     int val; n     cin >> val; n     st.update(i, i, val); n   } n   while (q--) { n     int type, x, y; n     cin >> type >> x >> y; n     --x; n     if (type == 1) { n       int pos = st.ask(0, x, y); n       if (pos != -1) st.update(pos, x, y); n     } else { n       int ans = st.query(x, n - 1, y); n       cout << ans <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int tc; n   std::cin >> tc; n   while (tc--) { n     int64_t a, b, c; n     std::cin >> a >> b >> c; n     std::cout << a + b + c - 1 << std::endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, A, ni, ai; n string si; n vector<int> hero; n vector<string> moves; n vector<int> player; n bool used[22][(int)(1 << 20)]; n int dp[22][(int)(1 << 20)]; n int BAD = 99999999; n int memo(int a, int b) { n   if (used[a][b]) return dp[a][b]; n   if (a == A) return 0; n   int res = -BAD; n   for (int i = 0; i < A; ++i) { n     if ((b & (1 << i)) > 0) continue; n     int add = hero[i]; n     if (moves[a] ==  p ) { n       if (player[a] % 2 == 0) { n         add *= -1; n         if (res == -BAD) n           res = add + memo(a + 1, b + (1 << i)); n         else n           res = min(res, add + memo(a + 1, b + (1 << i))); n       } else { n         if (res == -BAD) n           res = add + memo(a + 1, b + (1 << i)); n         else n           res = max(res, add + memo(a + 1, b + (1 << i))); n       } n     } else { n       if (player[a] % 2 == 0) { n         if (res == -BAD) n           res = memo(a + 1, b + (1 << i)); n         else n           res = min(res, memo(a + 1, b + (1 << i))); n       } else { n         if (res == -BAD) n           res = memo(a + 1, b + (1 << i)); n         else n           res = max(res, memo(a + 1, b + (1 << i))); n       } n     } n   } n   used[a][b] = true; n   dp[a][b] = res; n   return dp[a][b]; n } n void solve() { cout << memo(0, 0) << endl; } n int main() { n   cin >> N; n   for (int i = 0; i < N; ++i) { n     cin >> ni; n     hero.push_back(ni); n   } n   sort(hero.begin(), hero.end()); n   reverse(hero.begin(), hero.end()); n   cin >> A; n   for (int i = 0; i < A; ++i) { n     cin >> si; n     cin >> ai; n     moves.push_back(si); n     player.push_back(ai); n   } n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n string s; n int isPalin(int start, int end) { n   if (start == end) return 1; n   int i = (start + end - 1) / 2; n   while (start <= i) { n     if (s[start++] != s[end--]) return 0; n   } n   return 1; n } n int main() { n   cin >> s; n   int start = 0, end = s.length() - 1, flag = 1; n   if (isPalin(start, end)) { n     flag = ((end - start + 1) % 2 == 1) ? 2 : flag; n     end = (start + end - 1) / 2; n   } n   while (start < end) { n     if (isPalin(start, end)) { n       flag = ((end - start + 1) % 2 == 1) ? 2 : flag; n       end = (start + end - 1) / 2; n     } else { n       cout << flag << endl; n       return 0; n     } n   } n   end = ((int)s.length() - 2) / 2; n   while (start < end) { n     if (isPalin(start, end)) n       end--; n     else { n       cout << flag << endl; n       return 0; n     } n   } n   cout <<  Impossible n ; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9; n const int N = 2e6 + 1; n const long long mod = 998244353; n long long fact[N]; n long long power(long long x, long long n) { n   long long res = 1; n   x %= mod; n   while (n) { n     if (n & 1) res = (res * x) % mod; n     x = (x * x) % mod; n     n >>= 1; n   } n   return res; n } n long long modInv(long long n) { return power(n, mod - 2); } n long long ncr(long long n, long long r) { n   if (n < 0 || r < 0 || r > n) return 0; n   long long num = fact[n]; n   long long denom = (fact[n - r] * fact[r]) % mod; n   return (num * modInv(denom)) % mod; n } n void pre() { n   fact[0] = 1; n   for (int i = 1; i < N; i++) { n     fact[i] = (fact[i - 1] * i) % mod; n   } n } n void solve() { n   long long n, k; n   cin >> n >> k; n   long long y = n - k; n   if (y < 0) { n     cout << 0 <<   n ; n     return; n   } n   long long ans = ncr(n, y); n   long long sum = 0; n   for (int i = 0; i <= y; i++) { n     long long temp = (ncr(y, y - i) * power(y - i, n)) % mod; n     if (i % 2) { n       sum = (sum + mod - temp) % mod; n     } else { n       sum = (sum + temp) % mod; n     } n   } n   ans = (ans * sum) % mod; n   if (y != n) { n     ans = (ans * 2) % mod; n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   std::cout << std::fixed << std::setprecision(20); n   ; n   int t = 1; n   pre(); n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char** argv) { n   int n; n   cin >> n; n   long long int sum = 0; n   for (int i = 1; i < n; i++) { n     sum += ((n - i) * i); n   } n   cout << sum + n; n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 5000 + 10; n char s[MAXN]; n int f[MAXN][MAXN]; n bool isP[MAXN][MAXN]; n int main() { n   scanf( %s , s + 1); n   int len = strlen(s + 1); n   for (int i = 1; i <= len + 1; i++) { n     f[i][i + 1] = 1; n     isP[i][i + 1] = isP[i][i] = true; n   } n   for (int l = 2; l <= len; l++) { n     for (int i = 1; i + l <= len + 1; i++) { n       int j = i + l; n       isP[i][j] = (isP[i + 1][j - 1] && s[i] == s[j - 1]); n     } n   } n   for (int l = 2; l <= len; l++) { n     for (int i = 1; i + l <= len + 1; i++) { n       int j = i + l; n       f[i][j] = f[i][j - 1] + f[i + 1][j] - f[i + 1][j - 1] + isP[i][j]; n     } n   } n   int q; n   scanf( %d , &q); n   while (q--) { n     int l, r; n     scanf( %d%d , &l, &r); n     printf( %d n , f[l][r + 1]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n stack<int> ST, SI; n vector<int> P; n char OR[10000], TEMP[10000]; n int L, S, C; n int main() { n   while (scanf( %s , TEMP) == 1) strcat(OR, TEMP); n   L = strlen(OR); n   for (S = 0; S < L;) { n     if (OR[S + 2] ==  a ) n       ST.push(0), SI.push(C), C = 0, S += 7; n     else if (OR[S + 2] ==  r ) n       ST.push(1), S += 4; n     else if (OR[S + 2] ==  d ) n       ST.push(2), C++, S += 4; n     else if (OR[S + 3] ==  a ) n       P.push_back(C), C = SI.top(), SI.pop(), S += 8; n     else if (OR[S + 3] ==  r ) n       ST.pop(), S += 5; n     else if (OR[S + 3] ==  d ) n       ST.pop(), S += 5; n   } n   sort(P.begin(), P.end()); n   int i; n   for (i = 0; i < P.size(); i++) printf( %d  , P[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int a, b; n   cin >> a >> b; n   while (1) { n     if (a >= (2 * b)) { n       a = a % (2 * b); n     } else if (b >= (2 * a)) n       b = b % (2 * a); n     else n       break; n     if ((a == 0 || b == 0)) break; n   } n   cout << a <<     << b << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1100; n int N, K, L; n string S; n int nc[26]; n vector<char> res[MAXN]; n int main() { n   ios_base::sync_with_stdio(0); n   for (int i = 0; i < 26; i++) nc[i] = 0; n   cin >> N >> L >> K >> S; n   for (int i = 0; i < S.length(); i++) nc[S[i] -  a ]++; n   int nlo = 0, tlen = 0; n   for (int i = 0; i < 26; i++) { n     if (tlen == L) break; n     int ncnt = (K - nlo); n     int nb = nc[i] / ncnt; n     nb = min(nb, L - tlen); n     for (int j = nlo; j < K; j++) { n       for (int k = 0; k < nb; k++) { n         res[j].push_back((char) a  + i); n         nc[i]--; n       } n     } n     tlen += nb; n     if (tlen == L) break; n     int nleft = nc[i] % ncnt; n     for (int j = 0; j < nleft; j++) { n       res[nlo++].push_back((char) a  + i); n       nc[i]--; n     } n   } n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < 26; j++) { n       while (nc[j] > 0 && res[i].size() < L) { n         res[i].push_back((char) a  + j); n         nc[j]--; n       } n     } n   } n   for (int i = 0; i < N; i++) { n     for (char c : res[i]) cout << c; n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 mrand(43); n const double PI = acos((double)-1); n const double eps = 1e-5; n const long long inf0 = 1023 * 1024 * 1024; n const long long inf = inf0 * inf0; n const long long mod = 1e9 + 7; n void solve(); n void scan(); n signed main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(false); n   cout << fixed; n   cout.precision(15); n   solve(); n   return 0; n } n const int N = 1e5; n void solve() { n   int m; n   cin >> m; n   vector<int> a; n   vector<pair<pair<long long, long long>, pair<long long, long long>>> kek; n   long long n = 0; n   while (m--) { n     int tp; n     cin >> tp; n     if (tp == 1) { n       int x; n       cin >> x; n       if (a.size() < N) n         a.push_back(x); n       else n         kek.push_back({{n, n}, {-1, x}}); n       n++; n     } else { n       long long l, c; n       cin >> l >> c; n       while (c && a.size() < N) { n         for (int i = 0; i < l; i++) { n           a.push_back(a[i]); n         } n         n += l; n         c--; n       } n       if (c) kek.push_back({{n, n + l * c - 1}, {0, l - 1}}); n       n += l * c; n     } n   } n   int q; n   cin >> q; n   while (q--) { n     long long x; n     cin >> x; n     x--; n     if (x < a.size()) n       cout << a[x] <<    ; n     else { n       int h = upper_bound((kek).begin(), (kek).end(), n                           make_pair(make_pair(x, (long long)4e18), n                                     make_pair(1ll, 1ll))) - n               kek.begin() - 1; n       x -= kek[h].first.first; n       cout << a[x % (kek[h].second.second + 1)] <<    ; n     } n   } n   return; n } n


#include <bits/stdc++.h> n using namespace std; n int al = 1 << 29; n char ans[1000100]; n char a[1000100]; n int n, m; n void computer(int x, int y) { n   int l = 0; n   while (x != y) { n     if (x > y) { n       a[l++] =  T ; n       x -= y; n     } else { n       a[l++] =  B ; n       y -= x; n     } n   } n   if (x > 1) return; n   a[l++] =  T ; n   if (l != n) return; n   reverse(a, a + l); n   int cur = 0; n   int i; n   for (i = 1; i < n; i++) { n     if (a[i - 1] == a[i]) cur++; n   } n   if (cur < al) { n     al = cur; n     for (i = 0; i < n; i++) ans[i] = a[i]; n   } n } n int main() { n   int i; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= m; i++) { n     computer(i, m); n     computer(m, i); n   } n   if (al >= 1000100) n     cout <<  IMPOSSIBLE  << endl; n   else { n     cout << al << endl; n     for (i = 0; i < n; i++) cout << ans[i]; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, s; n int a[110][2]; n int main() { n   scanf( %d %d , &n, &s); n   for (int i = 0; i < n; i++) { n     scanf( %d %d , &a[i][0], &a[i][1]); n   } n   int cnt = 0; n   int maxcnt = 0; n   int temp = 0; n   for (int i = 0; i < n; i++) { n     if ((a[i][0] == s && a[i][1] != 0) || a[i][0] > s) n       temp++; n     else n       cnt = 100 - a[i][1]; n     if (cnt > maxcnt && cnt < 100) { n       maxcnt = cnt; n     } n     cnt = 0; n   } n   if (temp == n) n     printf( -1 n ); n   else n     printf( %d n , maxcnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long inf = 0x3f3f3f3f3f3f3f3f; n const long long mod = 998244353; n const int N = 3e5 + 10; n int n; n int a[N]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= n; i++) n     if (a[i] <= a[i - 1] && a[i] <= a[i + 1]) { n       puts( NO ); n       return 0; n     } n   puts( YES ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 10; n int n, m; n int a[maxn], par[maxn], t[maxn]; n vector<int> g[maxn]; n int get_par(int v) { return (par[v] == -1) ? v : par[v] = get_par(par[v]); } n void merge(int u, int v) { n   u = get_par(u); n   v = get_par(v); n   if (v == u) return; n   par[u] = v; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   cin >> n >> m; n   memset(par, -1, sizeof par); n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 0; i < m; i++) { n     int u, v; n     cin >> u >> v; n     merge(u, v); n   } n   for (int i = 1; i <= n; i++) g[get_par(i)].push_back(a[i]); n   for (int i = 1; i <= n; i++) sort(g[i].begin(), g[i].end()); n   for (int i = 1; i <= n; i++) { n     cout << g[get_par(i)].back() <<    ; n     g[get_par(i)].pop_back(); n   } n   cout <<   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 x, y, n = 0; n     cin >> x >> y; n     for (int i = 2; i <= x; i++) { n       if (x % i == 0) { n         n = i; n         break; n       } n     } n     cout << x + n + (y - 1) * 2 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int sum = 0; n   cin >> n; n   int **p; n   p = new int *[n]; n   for (int i = 0; i < n; i++) { n     p[i] = new int[n]; n     for (int j = 0; j < n; j++) { n       cin >> p[i][j]; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (i == j || i + j == n - 1 || i == (n - 1) / 2 || j == (n - 1) / 2) { n         sum += p[i][j]; n       } n     } n   } n   cout << sum; n   return 0; n } n


#include <bits/stdc++.h> n int DEBUG = 1; n using namespace std; n const int N = 100 * 1000 + 5; n const long long INF = 1e17; n long long gcd(long long a, long long b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n long long n, k; n long long a, b; n long long x; n long long MIN = +INF; n long long MAX = -INF; n long long dist(long long v, long long u) { n   if (v > u) swap(v, u); n   return min(u - v, x - (u - v)); n } n void check(long long s2) { n   long long d = dist(a, s2); n   long long L = d; n   long long cur = x / gcd(L, x); n   MAX = max(MAX, cur); n   MIN = min(MIN, cur); n } n int main() { n   cin >> n >> k; n   cin >> a >> b; n   x = n * k; n   for (long long e = 0; e < x; e += k) { n     check((e - b + x) % x); n     check((e + b) % x); n   } n   cout << MIN <<     << MAX << endl; n   return 0; n } n