#include <bits/stdc++.h> n using namespace std; n template <class T, size_t... Is> n struct arr_helper; n template <class T, size_t... Is> n using arr = typename arr_helper<T, Is...>::type; n template <class T> n struct arr_helper<T> { n   using type = T; n }; n template <class T, size_t I, size_t... Is> n struct arr_helper<T, I, Is...> { n   using type = array<arr<T, Is...>, I>; n }; n using ll = long long; n using u64 = uint64_t; n using u32 = uint32_t; n using vi = vector<int>; n using vl = vector<ll>; n using vvi = vector<vi>; n using pi = pair<int, int>; n using pl = pair<ll, ll>; n using vpi = vector<pi>; n [[maybe_unused]] const int INF = (int)1e9; n [[maybe_unused]] const ll INFL = (ll)1e18; n ll M = 998244353; n int mod_pow(ll b, ll e) { n   ll res = 1; n   for (; e; b = b * b % M, e /= 2) n     if (e % 2) res = res * b % M; n   return (int)res; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int n, m, k; n   cin >> n >> m >> k; n   vi f(k + 1), fi(k + 1), fn(k + 1); n   f[0] = 1; n   for (int i = (1); i < (k + 1); ++i) f[i] = (ll)f[i - 1] * i % M; n   for (int i = 0; i < (k + 1); ++i) fi[i] = mod_pow(f[i], M - 2); n   fn[0] = 1; n   for (int i = (1); i < (k + 1); ++i) fn[i] = fn[i - 1] * (ll)(n - i + 1) % M; n   auto choose = [&](int n, int k) { n     if (k > n) return 0ll; n     return (ll)f[n] * fi[n - k] % M * (ll)fi[k] % M; n   }; n   auto choose_n = [&](int k) { return fn[k] * (ll)fi[k] % M; }; n   ll sum = 0; n   auto p = mod_pow(m, M - 2); n   auto q = (ll)(m - 1) * p % M; n   vi nmkitok(k + 1); n   for (int i = 0; i < (k + 1); ++i) nmkitok[i] = mod_pow(n - i, k); n   for (int j = 0; j < (k + 1); ++j) { n     ll si = 0; n     for (int ki = 0; ki < (j + 1); ++ki) { n       si += (ll)(ki % 2 ? M - 1 : 1) * choose(j, ki) % M * nmkitok[ki] % M; n       si %= M; n     } n     sum += mod_pow(M - q, j) * (ll)choose_n(j) % M * si % M; n     sum %= M; n   } n   cout << sum <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int t; n   cin >> n >> t; n   if (t == 10 && n == 1) return cout << -1, 0; n   string s; n   if (t == 10) n     s +=  10 , n -= 2; n   else n     s += (char)(t + 48), n--; n   while (n--) s +=  0 ; n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n long long int power(long long int a, long long int b) { n   if (b == 0) return 1; n   if (b == 1) return a; n   long long int c = power(a, b / 2); n   if (b % 2 == 0) return ((c % 1000000007) * (c % 1000000007)) % 1000000007; n   return ((((c % 1000000007) * (c % 1000000007)) % 1000000007) * n           (a % 1000000007)) % n          1000000007; n } n int main() { n   long long int n, i; n   cin >> n; n   long long int a[n]; n   long long int hash[100005] = {0}; n   long long int mini = 99999999999999; n   long long int t = 0; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     hash[a[i]]++; n   } n   for (i = 1; i <= 100; i++) { n     long long int sum = 0; n     for (long long int j = 1; j <= 100; j++) { n       if (j < i) n         sum += (hash[j] * (i - 1 - j)); n       else if (j > i) n         sum += (hash[j] * (j - 1 - i)); n     } n     if (sum < mini) { n       mini = sum; n       t = i; n     } n   } n   cout << t <<     << mini << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s[n + 1]; n   if (n % 2 == 0) n     cout << n * n / 2 << endl; n   else n     cout << ((n * n) + 1) / 2 << endl; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       if (i % 2 != 0 && j % 2 != 0) n         cout <<  C ; n       else if (i % 2 != 0 && j % 2 == 0) n         cout <<  . ; n       else if (i % 2 == 0 && j % 2 != 0) n         cout <<  . ; n       else n         cout <<  C ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, size_t N> n long long SIZE(const T (&t)[N]) { n   return N; n } n template <typename T> n long long SIZE(const T &t) { n   return t.size(); n } n string to_string(const string s, long long x1 = 0, long long x2 = 1e9) { n   return     + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) :   ) +    ; n } n string to_string(const char *s) { return to_string((string)s); } n string to_string(const bool b) { return (b ?  true  :  false ); } n string to_string(const char c) { return string({c}); } n template <size_t N> n string to_string(const bitset<N> &b, long long x1 = 0, long long x2 = 1e9) { n   string t =   ; n   for (long long __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1); n        __iii__ <= __jjj__; ++__iii__) { n     t += b[__iii__] +  0 ; n   } n   return     + t +    ; n } n template <typename A, typename... C> n string to_string(const A(&v), long long x1 = 0, long long x2 = 1e9, n                  C... coords); n long long l_v_l_v_l = 0, t_a_b_s = 0; n template <typename A, typename B> n string to_string(const pair<A, B> &p) { n   l_v_l_v_l++; n   string res =  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; n   l_v_l_v_l--; n   return res; n } n template <typename A, typename... C> n string to_string(const A(&v), long long x1, long long x2, C... coords) { n   long long rnk = rank<A>::value; n   string tab(t_a_b_s,    ); n   string res =   ; n   bool first = true; n   if (l_v_l_v_l == 0) res +=   n ; n   res += tab +  [ ; n   x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); n   auto l = begin(v); n   advance(l, x1); n   auto r = l; n   advance(r, (x2 - x1) + (x2 < SIZE(v))); n   for (auto e = l; e != r; e = next(e)) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     l_v_l_v_l++; n     if (e != l) { n       if (rnk > 1) { n         res +=   n ; n         t_a_b_s = l_v_l_v_l; n       }; n     } else { n       t_a_b_s = 0; n     } n     res += to_string(*e, coords...); n     l_v_l_v_l--; n   } n   res +=  ] ; n   if (l_v_l_v_l == 0) res +=   n ; n   return res; n } n void dbgm() { ; } n template <typename Heads, typename... Tails> n void dbgm(Heads H, Tails... T) { n   cout << to_string(H) <<   |  ; n   dbgm(T...); n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     long long n, ans = 0, sum = 0, mx1 = 0, mx2 = 0; n     cin >> n; n     vector<long long> a(n), od, ev; n     for (long long i = 0; i < n; i++) { n       cin >> a[i]; n       if (i % 2 == 0) ans += a[i]; n     } n     vector<long long> p, q; n     for (long long i = 0; i + 1 < n; i += 2) { n       p.push_back(a[i + 1] - a[i]); n     } n     for (long long i = 1; i + 1 < n; i += 2) { n       q.push_back(a[i] - a[i + 1]); n     } n     if (p.size() > 0) { n       mx1 = p[0]; n       sum = 0; n       for (long long i = 0; i < p.size(); i++) { n         sum += p[i]; n         mx1 = max(mx1, sum); n         sum = max(sum, 0ll); n       } n     } n     if (q.size() > 0) { n       mx2 = q[0]; n       sum = 0; n       for (long long i = 0; i < q.size(); i++) { n         sum += q[i]; n         mx2 = max(mx2, sum); n         sum = max(sum, 0ll); n       } n     } n     ans = max(ans, ans + max(mx1, mx2)); n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = numeric_limits<int>::max(); n const long long LLINF = numeric_limits<long long>::max(); n const unsigned long long ULLINF = numeric_limits<unsigned long long>::max(); n vector<vector<int>> g; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   vector<pair<int, int>> a(n); n   for (int i = 0; i < n; i++) { n     int d, b; n     cin >> d >> b; n     a[i] = {d, b}; n   } n   queue<int> q; n   for (int i = 0; i < n; i++) { n     if (a[i].first == 1) q.push(i); n   } n   vector<pair<int, int>> ans; n   while (!q.empty()) { n     int v = q.front(); n     q.pop(); n     if (a[v].first == 0) continue; n     ans.push_back({v, a[v].second}); n     a[a[v].second].first--; n     a[a[v].second].second ^= v; n     if (a[a[v].second].first == 1) q.push(a[v].second); n   } n   cout << ans.size() <<   n ; n   for (auto k : ans) cout << k.first <<     << k.second <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int lg[1000005], jump[1000005][20], depth[1000005], head[1000005], cnt = 4; n int q, tot, s, t, zj; n struct edge { n   int to, next; n } e[2000005]; n void add(int x, int y) { n   e[++tot].to = y; n   e[tot].next = head[x]; n   head[x] = tot; n } n void dfs(int now, int fa) { n   for (int i = head[now]; i; i = e[i].next) { n     if (e[i].to != fa) { n       dfs(e[i].to, now); n     } n   } n } n int LCA(int x, int y) { n   if (depth[x] < depth[y]) { n     swap(x, y); n   } n   while (depth[x] > depth[y]) { n     x = jump[x][lg[depth[x] - depth[y]] - 1]; n   } n   if (x == y) { n     return x; n   } n   for (int i = lg[depth[x]] - 1; i >= 0; i--) { n     if (jump[x][i] != jump[y][i]) { n       x = jump[x][i]; n       y = jump[y][i]; n     } n   } n   return jump[x][0]; n } n int dis(int a, int b) { n   int lca = LCA(a, b); n   return depth[a] + depth[b] - 2 * depth[lca]; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> q; n   for (int i = 1; i <= q * 2 + 4; i++) { n     lg[i] = lg[i - 1] + (1 << lg[i - 1] == i); n   } n   add(1, 2), add(1, 3), add(1, 4); n   jump[2][0] = jump[3][0] = jump[4][0] = 1; n   depth[1] = 1, depth[2] = depth[3] = depth[4] = 2; n   s = 2, t = 4, zj = 2; n   for (int i = 0; i < q; i++) { n     int v; n     cin >> v; n     cnt++; n     add(v, cnt); n     add(cnt, v); n     depth[cnt] = depth[v] + 1; n     jump[cnt][0] = v; n     for (int j = 1; j <= lg[depth[cnt]]; j++) { n       jump[cnt][j] = jump[jump[cnt][j - 1]][j - 1]; n     } n     if (dis(cnt, s) > dis(s, t)) { n       t = cnt; n       zj = dis(cnt, s); n     } n     if (dis(cnt, t) > dis(s, t)) { n       s = cnt; n       zj = dis(cnt, t); n     } n     cnt++; n     add(v, cnt); n     add(cnt, v); n     depth[cnt] = depth[v] + 1; n     jump[cnt][0] = v; n     for (int j = 1; j <= lg[depth[cnt]]; j++) { n       jump[cnt][j] = jump[jump[cnt][j - 1]][j - 1]; n     } n     if (dis(cnt, s) > dis(s, t)) { n       t = cnt; n       zj = dis(cnt, s); n     } n     if (dis(cnt, t) > dis(s, t)) { n       s = cnt; n       zj = dis(cnt, t); n     } n     cout << zj << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int INF = 10000000000; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int n, m; n   cin >> n >> m; n   long long int chestOdd = 0, chestEven = 0; n   long long int i; n   for (i = 0; i < n; i++) { n     long long int temp; n     cin >> temp; n     if (temp % 2 == 0) { n       chestEven++; n     } else { n       chestOdd++; n     } n   } n   long long int keyOdd = 0, keyEven = 0; n   for (i = 0; i < m; i++) { n     long long int temp; n     cin >> temp; n     if (temp % 2 == 0) { n       keyEven++; n     } else { n       keyOdd++; n     } n   } n   long long int ans = 0; n   ans = min(keyEven, chestOdd); n   ans += min(keyOdd, chestEven); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000010; n const int mod = 998244353; n int n; n long long jc[N], inv[N], ans = 0, an = 0; n long long poww(long long x, long long y) { n   long long ans = 1; n   while (y) { n     if (y & 1) { n       ans = ans * x % mod; n     } n     x = x * x % mod; n     y >>= 1; n   } n   return ans; n } n long long C(long long n, long long m) { n   return jc[n] * inv[m] % mod * inv[n - m] % mod; n } n int main() { n   scanf( %d , &n); n   jc[0] = inv[0] = 1; n   for (int i = 1; i <= n; i++) { n     jc[i] = jc[i - 1] * i % mod; n     inv[i] = poww(jc[i], mod - 2); n   } n   for (int i = 1; i <= n; i++) { n     ans = (ans + n            poww(3, 1ll * n * (n - i) + i) * C(n, i) % mod * ((i & 1) ? 1 : -1) + n            mod) % n           mod; n   } n   ans = ans * 2 % mod; n   for (int i = 0; i < n; i++) { n     long long t = -poww(3, i); n     an = (an + n           C(n, i) * ((i & 1) ? 1 : -1) * (poww(t + 1, n) - poww(t, n) + mod) % n               mod + n           mod) % n          mod; n   } n   ans = (ans + 3 * an) % mod; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int p, q; n   cin >> p >> q; n   string s; n   int **b = new int *[p]; n   for (long long int i = 0; i < p; i++) b[i] = new int[q]; n   for (long long int i = 0; i < p; i++) { n     cin >> s; n     for (long long int j = 0; j < q; j++) { n       b[i][j] = int(s[j]); n     } n   } n   for (long long int j = 0; j < q; j++) { n     int c = b[0][j]; n     for (long long int i = 0; i < p; i++) { n       if (b[i][j] > c) { n         c = b[i][j]; n       } n     } n     for (long long int i = 0; i < p; i++) { n       if (b[i][j] == c) { n         b[i][j] = 0; n       } n     } n   } n   int e = 0; n   for (long long int i = 0; i < p; i++) { n     for (long long int j = 0; j < q; j++) { n       if (b[i][j] == 0) { n         e += 1; n         break; n       } n     } n   } n   cout << e <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct pole { n   int a, b; n   long long odp; n   int nr; n }; n bool porownanie1(pole a, pole b) { n   if (a.b < b.b) return true; n   if (a.b > b.b) return false; n   if (a.nr < b.nr) return true; n   return false; n } n bool porownanie2(pole a, pole b) { n   if (a.nr < b.nr) return true; n   return false; n } n int main() { n   ios_base::sync_with_stdio(0); n   int n; n   cin >> n; n   vector<int> w(n); n   for (int i = 0; i < n; ++i) cin >> w[i]; n   int p; n   cin >> p; n   vector<pole> a(p); n   for (int i = 0; i < p; ++i) { n     cin >> a[i].a >> a[i].b; n     --a[i].a; n     a[i].odp = 0; n     a[i].nr = i; n   } n   sort(a.begin(), a.end(), porownanie1); n   for (int le = 0; le < p;) { n     int pr = le; n     while (pr < p && a[pr].b == a[le].b) ++pr; n     --pr; n     if (a[le].b <= 540) { n       vector<long long> s(n, 0); n       for (int i = n - 1; i >= 0; --i) { n         s[i] = w[i]; n         if (i + a[le].b < n) s[i] += s[i + a[le].b]; n       } n       for (int i = le; i <= pr; ++i) a[i].odp = s[a[i].a]; n     } else { n       for (int i = le; i <= pr; ++i) n         for (int j = a[i].a; j < n; j += a[i].b) a[i].odp += w[j]; n     } n     le = pr + 1; n   } n   sort(a.begin(), a.end(), porownanie2); n   for (int i = 0; i < p; ++i) cout << a[i].odp << endl; n   return 0; n } n


#include <bits/stdc++.h> n namespace myland { n using namespace std; n namespace _abbr { n const double EPS(1e-8); n const double PI(acos(-1.0)); n const int INF(0x3f3f3f3f); n const long long INFL(0x3f3f3f3f3f3f3f3fll); n const int MOD(1e9 + 7); n }  // namespace _abbr n using namespace _abbr; n namespace _solve {} n using namespace _solve; n namespace _calculate { n bool odd(long long x) { return x & 1; } n bool even(long long x) { return (x & 1) ^ 1; } n bool posi(long long x) { return x > 0; } n bool nega(long long x) { return x < 0; } n bool zero(long long x) { return x == 0; } n bool prime(long long x) { n   if (x < 2) return 0; n   for (int i = 2; i * i <= x; i++) n     if (x % i == 0) return 0; n   return 1; n } n long long droot(long long x) { return 1 + (x - 1) % 9; } n long long upd(long long a, long long b) { return a % b ? a / b + 1 : a / b; }; n long long random(long long a, long long b) { n   return a + rand() * rand() % (b - a + 1); n }; n long long bitn(long long x) { n   long long c = 0; n   while (x) c++, x >>= 1; n   return c; n } n template <class T> n T sqr(T x) { n   return x * x; n } n long long qpow(long long a, long long n, long long mod = MOD) { n   long long res(1); n   while (n) { n     if (n & 1) (res *= a) %= mod; n     (a *= a) %= mod; n     n >>= 1; n   } n   return res % mod; n } n template <class T> n void tomin(T& a, T b) { n   if (b < a) a = b; n } n template <class T> n void tomax(T& a, T b) { n   if (b > a) a = b; n } n }  // namespace _calculate n using namespace _calculate; n namespace _simple_algo { n long long stol(const string& s) { n   long long x = 0; n   for (char c : s) x = x * 10 + c - 48; n   return x; n } n string ltos(long long x) { n   string s =   ; n   if (x == 0) return  0 ; n   while (x) s = char(x % 10 + 48) + s, x /= 10; n   return s; n } n bool pal(const string& s) { n   int l = s.size(); n   for (int i = 0, j = l - 1; i < j; i++, j--) n     if (s[i] != s[j]) return 0; n   return 1; n } n }  // namespace _simple_algo n using namespace _simple_algo; n namespace _io { n template <class T> n void rd(T& x) { n   cin >> x; n } n long long rd() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n void rd(int& x) { x = rd(); } n void rd(long long& x) { x = rd(); } n template <class A, class B> n void rd(A& a, B& b) { n   rd(a), rd(b); n } n template <class A, class B> n void rd(pair<A, B>& p) { n   cin >> p.first >> p.second; n } n template <class T> n void wt(const T& x) { n   cout << x << endl; n } n template <class T> n void wt(const T& x, char c) { n   cout << x << c; n } n template <class T> n void wt(const T& x, const string& s) { n   cout << x << s; n } n template <class T> n void wt(const T& x, int rnd) { n   cout << fixed << setprecision(rnd) << x << endl; n } n template <class A, class B> n void wt(const pair<A, B>& make_pair) { n   cout << make_pair.first <<     << make_pair.second << endl; n } n template <class T> n void wt(const vector<T>& vec, int l, int r) { n   for (int i = l; i <= r; i++) cout << vec[i] <<    ; n   cout << endl; n } n }  // namespace _io n using namespace _io; n }  // namespace myland n using namespace myland; n const int N(2e5 + 5); n long long h, n; n long long d[N], s[N]; n int main() { n   rd(h, n); n   for (int i = 1; i <= n; i++) rd(d[i]), s[i] = s[i - 1] + d[i]; n   long long t = h; n   for (int i = 1; i <= n; i++) { n     t += d[i]; n     if (t <= 0) wt(i), exit(0); n   } n   if (s[n] >= 0) n     wt(-1), exit(0); n   else { n     long long mn(*min_element((s + 1), (s + n + 1))); n     h += mn; n     long long l(h / (-s[n])); n     h -= mn; n     h += l * s[n]; n     long long ans(l * n); n     while (h > 0) { n       for (int i = 1; i <= n; i++) { n         h += d[i]; n         ans++; n         if (h <= 0) wt(ans), exit(0); n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n string s; n bool check(long long l, long long r) { n   for (long long i = l; i < (r + l) / 2; i++) { n     if (s[i] != s[r - i - 1]) { n       return false; n     } n   } n   return true; n } n long long sulganlox(long long l, long long r) { n   if (r - l == 1) { n     if (s[l] == s[l + 1]) { n       cout <<  Impossible  << endl; n       exit(0); n     } n     return 2; n   } n   if ((r - l) % 2 == 0) { n     if (check(l, (r + l) / 2)) { n       return sulganlox(l, (r + l) / 2); n     } else { n       return 1; n     } n   } else { n     if (check(l, (r + l) / 2)) { n       return sulganlox(l, (r + l) / 2); n     } else { n       return 2; n     } n   } n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> s; n   long long n = s.size(); n   if (n == 1) { n     cout <<  Impossible  << endl; n     return 0; n   } n   cout << sulganlox(0, n) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 19391; n long long a[maxn]; n namespace FAST_IO { n template <typename T> n void read(T &a) { n   a = 0; n   long long f = 1; n   char c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) { n       f = -1; n     } n     c = getchar(); n   } n   while (isdigit(c)) { n     a *= 10; n     a += c -  0 ; n     c = getchar(); n   } n   a = a * f; n } n template <typename T> n void write(T a) { n   if (a < 0) { n     a = -a; n     putchar( - ); n   } n   if (a > 9) { n     write(a / 10); n   } n   putchar(a % 10 +  0 ); n } n template <typename T> n void writeln(T) { n   write(a); n   puts(  ); n } n }  // namespace FAST_IO n long long ans, ans1; n priority_queue<long long> big; n priority_queue<long long, vector<long long>, greater<long long> > small; n signed main() { n   long long n; n   FAST_IO::read(n); n   for (long long i = 1; i <= n; i++) { n     FAST_IO::read(a[i]); n     a[i] -= i; n   } n   for (long long i = 1; i <= n; i++) { n     big.push(a[i]); n     if (a[i] < big.top()) { n       ans += big.top() - a[i]; n       big.pop(); n       big.push(a[i]); n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int nmax = 1e5 + 42; n int n; n long long k; n int arr[nmax]; n void compress() { n   set<int> seen = {}; n   for (int i = 1; i <= n; i++) seen.insert(arr[i]); n   map<int, int> c = {}; n   int val = 0; n   for (auto k : seen) { n     val++; n     c[k] = val; n   } n   for (int i = 1; i <= n; i++) arr[i] = c[arr[i]]; n } n int fenwick[nmax][2]; n int sum(int pos, int index) { n   int ret = 0; n   while (pos) { n     ret = ret + fenwick[pos][index]; n     pos = pos - (pos & (-pos)); n   } n   return ret; n } n int query(int l, int r, int index) { return sum(r, index) - sum(l - 1, index); } n void update(int pos, int add, int index) { n   while (pos <= n) { n     fenwick[pos][index] += add; n     pos = pos + (pos & (-pos)); n   } n } n int main() { n   scanf( %i%lld , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %i , &arr[i]); n   compress(); n   int r = n + 1; n   long long now = 0; n   while (r > 1 && now <= k) { n     r--; n     now = now + query(1, arr[r] - 1, 1); n     if (now > k) { n       now = now - query(1, arr[r] - 1, 1); n       r++; n       break; n     } n     update(arr[r], 1, 1); n   } n   long long ans = 0; n   for (int l = 1; l < n; l++) { n     now = now + query(arr[l] + 1, n, 0) + query(1, arr[l] - 1, 1); n     update(arr[l], 1, 0); n     while (l >= r || (now > k && r <= n)) { n       now = now - query(arr[r] + 1, n, 0) - query(1, arr[r] - 1, 1); n       update(arr[r], -1, 1); n       r++; n     } n     ans = ans + (n - r + 1); n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n std::vector<int> ch[1005]; n bool dfs(const int &u) { n   if (!ch[u].size()) return true; n   int res = 0; n   if (ch[u].size()) { n     for (auto it = ch[u].begin(); it != ch[u].end(); it++) { n       if (!(ch[*it].size())) res++; n     } n   } n   if (res >= 3) n     return true; n   else n     return false; n } n int main() { n   cin >> n; n   for (int i = 2; i <= n; i++) { n     int u; n     cin >> u; n     ch[u].push_back(i); n   } n   for (int i = 1; i <= n; i++) { n     if (!dfs(i)) { n       cout <<  No  << endl; n       return 0; n     } n   } n   cout <<  Yes  << endl; n   return 0; n } n


#include <bits/stdc++.h> n typedef long long ll; n typedef long double ld; n using namespace std; n vector<ll> prime_factors(ll num) { n   vector<ll> ans; n   while (num % 2) { n     ans.push_back(2); n     num /= 2; n   } n   for (int i = 3; i * i <= num; i += 2) { n     while (num % i == 0) { n       ans.push_back(i); n       num /= i; n     } n   } n   if (num > 2) ans.push_back(num); n   return ans; n } n void tests() { n   int n; n   cin >> n; n   map<int, vector<int>> data; n   vector<pair<int, int>> ans; n   ans.reserve(n); n   for (int i = 1; i < n + 1; i++) { n     int x; n     cin >> x; n     data[x].push_back(i); n   } n   for (auto &i : data) { n     int len = i.second.size(); n     if (len == 1) n       ans.push_back(make_pair(i.first, 0)); n     else if (len == 2) n       ans.push_back(make_pair(i.first, i.second[1] - i.second[0])); n     else { n       int cd = i.second[1] - i.second[0]; n       for (int pos = 2; pos < len; ++pos) { n         if (i.second[pos] - i.second[pos - 1] != cd) goto end; n       } n       ans.push_back(make_pair(i.first, cd)); n     } n   end:; n   } n   cout << ans.size() << char(10); n   for (auto &i : ans) cout << i.first << char(32) << i.second << char(10); n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t = 1; n   while (t--) { n     tests(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100010]; n int b[100010]; n int cha[100010]; n vector<int> lis; n int inc[100010]; n int decr[100010]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     int x, y; n     cin >> x >> y; n     cha[x]++; n     cha[y + 1]--; n   } n   for (int i = 1; i <= m; i++) { n     a[i] = a[i - 1] + cha[i]; n   } n   lis.push_back(-100); n   lis.push_back(a[1]); n   inc[1] = 1; n   for (int i = 2; i <= m; i++) { n     int temp = upper_bound(lis.begin(), lis.end(), a[i]) - lis.begin(); n     if (temp == lis.size()) lis.push_back(a[i]); n     inc[i] = temp; n     lis[temp] = a[i]; n   } n   for (int i = m; i >= 1; i--) b[m + 1 - i] = a[i]; n   for (int i = m; i >= 1; i--) a[i] = b[i]; n   lis.clear(); n   lis.push_back(-100); n   lis.push_back(a[1]); n   decr[1] = 1; n   for (int i = 2; i <= m; i++) { n     int temp = upper_bound(lis.begin(), lis.end(), a[i]) - lis.begin(); n     if (temp == lis.size()) lis.push_back(a[i]); n     decr[i] = temp; n     lis[temp] = a[i]; n   } n   for (int i = 1; i <= m; i++) inc[i] += decr[m + 1 - i]; n   cout << *max_element(inc + 1, inc + m + 1) - 1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   pair<char, bool> ar[100][100]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> ar[i][j].first; n       ar[i][j].second = false; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       for (int k = 0; k < m; k++) { n         if (k == j) continue; n         if (ar[i][j].first == ar[i][k].first) { n           ar[i][j].second = true; n           ar[i][k].second = true; n         } n       } n       for (int k = 0; k < n; k++) { n         if (k == i) continue; n         if (ar[i][j].first == ar[k][j].first) { n           ar[i][j].second = true; n           ar[k][j].second = true; n         } n       } n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (ar[i][j].second == false) cout << ar[i][j].first; n     } n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 100007; n const int maxM = 300007; n const long long INF = (1LL << 60); n const long long M = 1000000007; n long long C[maxN]; n vector<int> G[maxN]; n vector<int> H[maxN]; n int V[maxN]; n stack<int> S; n vector<int> SSS[maxN]; n void DFSG(int x) { n   V[x] = 1; n   for (int g : G[x]) n     if (V[g] == 0) DFSG(g); n   S.push(x); n } n void DFSH(int x, int y) { n   V[x] = 2; n   SSS[y].push_back(x); n   for (int h : H[x]) n     if (V[h] == 1) DFSH(h, y); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, m, a, b, k; n   long long ans = 0, cmb = 1, tans, tcmb; n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> C[i]; n   } n   cin >> m; n   for (int i = 1; i <= m; ++i) { n     cin >> a >> b; n     G[a].push_back(b); n     H[b].push_back(a); n   } n   for (int i = 1; i <= n; ++i) { n     if (V[i] == 0) DFSG(i); n   } n   k = 0; n   while (!S.empty()) { n     a = S.top(); n     S.pop(); n     if (V[a] == 1) { n       ++k; n       DFSH(a, k); n     } n   } n   for (int i = 1; i <= k; ++i) { n     tans = INF; n     tcmb = 1; n     for (int s : SSS[i]) { n       if (C[s] < tans) { n         tans = C[s]; n         tcmb = 1; n       } else if (C[s] == tans) { n         ++tcmb; n       } n     } n     ans += tans; n     cmb *= tcmb; n     cmb %= M; n   } n   cout << ans <<     << cmb <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int a[N], b[N]; n int main() { n   int n, ans = 0, x; n   cin >> n >> x; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n; i++) cin >> b[i]; n   sort(a + 1, a + 1 + n); n   sort(b + 1, b + 1 + n); n   for (int i = 1, j = n; i <= n && j >= 1; i++) { n     if (a[i] + b[j] >= x) ans++, j--; n   } n   cout <<  1   << ans; n } n


#include <bits/stdc++.h> n using namespace std; n void check(vector<vector<long long> >& a, vector<vector<long long> >& b) { n   long long n = a.size(), m = a[0].size(); n   for (long long i = 0; i < n; i++) n     for (long long j = 0; j < m; j++) n       if (a[i][j] > b[i][j]) swap(a[i][j], b[i][j]); n } n bool correct(vector<vector<long long> > a) { n   long long n = a.size(), m = a[0].size(); n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < m; j++) { n       if ((i + 1 < n && a[i][j] >= a[i + 1][j]) || n           (j + 1 < m && a[i][j] >= a[i][j + 1]) || n           (i - 1 >= 0 && a[i][j] <= a[i - 1][j]) || n           (j - 1 >= 0 && a[i][j] <= a[i][j - 1])) n         return false; n     } n   } n   return true; n } n int32_t main() { n   long long n, m; n   cin >> n >> m; n   vector<vector<long long> > a(n, vector<long long>(m, 0)), n       b(n, vector<long long>(m, 0)); n   for (long long i = 0; i < n; i++) n     for (long long j = 0; j < m; j++) cin >> a[i][j]; n   for (long long i = 0; i < n; i++) n     for (long long j = 0; j < m; j++) cin >> b[i][j]; n   check(a, b); n   if (correct(a) && correct(b)) n     cout <<  Possible n ; n   else n     cout <<  Impossible n ; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n long long n, m, a, b, c, k, temp, x, y; n const int MAXN = 100000 + 11; n inline long long max(long long a, long long b) { return ((a > b) ? a : b); } n inline long long min(long long a, long long b) { return ((a > b) ? b : a); } n inline long long gcd(long long a, long long b) { n   if (b == 0) return a; n   a %= b; n   return gcd(b, a); n } n inline vector<long long> read(int n) { n   vector<long long> v(n); n   for (int i = 0; i < v.size(); i++) cin >> v[i]; n   return v; n } n vector<int> tree[200000]; n void bfst() { n   for (int i = n - 1; i > 0; --i) n     merge(tree[i << 1].begin(), tree[i << 1].end(), tree[i << 1 | 1].begin(), n           tree[i << 1 | 1].end(), back_inserter(tree[i])); n } n long long qfstgreater(int l, int r, int val) { n   long long res = 0; n   for (l += n, r += n; l < r; l >>= 1, r >>= 1) { n     if (l & 1) n       res += tree[l].end() - upper_bound(tree[l].begin(), tree[l].end(), val), n           l++; n     if (r & 1) n       res += tree[r - 1].end() - n              upper_bound(tree[r - 1].begin(), tree[r - 1].end(), val), n           r--; n   } n   return res; n } n long long qfstlesser(int l, int r, int val) { n   long long res = 0; n   for (l += n, r += n; l < r; l >>= 1, r >>= 1) { n     if (l & 1) n       res += lower_bound(tree[l].begin(), tree[l].end(), val) - tree[l].begin(), n           l++; n     if (r & 1) n       res += lower_bound(tree[r - 1].begin(), tree[r - 1].end(), val) - n              tree[r - 1].begin(), n           r--; n   } n   return res; n } n void solveforthiscase(const int& test) { n   cin >> n >> k; n   vector<long long> v = read(n); n   for (int i = 0; i < n; i++) tree[i + n].push_back(v[i]); n   bfst(); n   long long inv = 0, ans = 0, r = n - 1; n   for (; r > 0; r--) { n     long long ti = 0; n     if (v[r] < v[0]) ti++; n     ti += qfstlesser(r + 1, n, v[r]); n     if (inv + ti > k) break; n     inv += ti; n   } n   r++; n   if (r == 1) { n     cout << (n * (n - 1)) / 2; n     return; n   } n   ans += (n - r); n   for (int l = 1; l < n; l++) { n     inv += qfstgreater(0, l, v[l]) + qfstlesser(r, n, v[l]); n     while (r < n && inv > k) { n       inv -= qfstlesser(r + 1, n, v[r]); n       inv -= qfstgreater(0, l + 1, v[r++]); n     } n     if (r == n) break; n     ans += n - r; n   } n   cout << ans; n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   clock_t start, end; n   start = clock(); n   int test = 1; n   for (int i = 1; i <= test; i++) solveforthiscase(i); n   end = clock(); n   long double t_t = (long double)(end - start) / (long double)(CLOCKS_PER_SEC); n   if (false) cerr << (long double)t_t * 1000 <<   ms  ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int h, l, i; n   cin >> h >> l; n   long double x; n   x = (long double)(l * l - h * h) / (long double)(2 * h); n   std::cout << std::setprecision(9) << x <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0, f = 1; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -1; n   for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ; n   return x * f; n } n const int MAXN = 200010; n inline void solve() { n   int x = read(); n   for (int i = 2; i <= 30; i++) n     if (x % ((1 << i) - 1) == 0) { n       printf( %d n , x / ((1 << i) - 1)); n       return; n     } n } n int main() { n   for (int Cas = read(); Cas; Cas--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n vector<int> sz[1001]; n vector<int> s[1001]; n vector<int> l; n bool v[1001]; n int dist[1001][1001]; n vector<pair<int, pair<int, int> > > t; n void bfs(int a, int f) { n   for (int i = 0; i < sz[a].size(); i++) { n     int x = sz[a][i]; n     if (dist[x][f] == 0) { n       dist[x][f] = dist[a][f] + 1; n       bfs(x, f); n     } n   } n } n void solve(int a, int b, int y) { n   if (y == 0) { n     return; n   } n   if (sz[a].size() == 1) { n     swap(a, b); n   } n   if (sz[a].size() == 1) { n     t.push_back({a, {b, y}}); n     return; n   } n   int esz, msz, besz = 0, bmsz = 0; n   for (int i = 0; i < sz[a].size(); i++) { n     int x = sz[a][i]; n     if (x != b) { n       esz = x; n       swap(esz, msz); n     } n   } n   int c, d, e, f; n   if (sz[b].size() == 1) { n     e = b; n     f = b; n   } else { n     for (int i = 0; i < sz[b].size(); i++) { n       int x = sz[b][i]; n       if (x != a) { n         besz = x; n         swap(besz, bmsz); n       } n     } n   } n   for (int i = 0; i < l.size(); i++) { n     int x = l[i]; n     if (dist[a][x] < dist[b][x]) { n       if (dist[esz][x] < dist[msz][x]) { n         c = x; n       } else { n         d = x; n       } n     } else { n       if (besz != 0) { n         if (dist[besz][x] < dist[bmsz][x]) { n           e = x; n         } else { n           f = x; n         } n       } else { n         e = x; n         swap(e, f); n       } n     } n   } n   y /= 2; n   t.push_back({c, {e, y}}); n   t.push_back({d, {f, y}}); n   t.push_back({c, {d, -y}}); n   if (e != f) { n     t.push_back({e, {f, -y}}); n   } n } n int main() { n   cin >> n; n   for (int i = 1; i < n; i++) { n     int a, b, c; n     cin >> a >> b >> c; n     sz[a].push_back(b); n     sz[b].push_back(a); n     s[a].push_back(c); n     s[b].push_back(c); n   } n   for (int i = 1; i <= n; i++) { n     if (sz[i].size() == 2) { n       cout <<  NO ; n       return 0; n     } n     if (sz[i].size() == 1) { n       l.push_back(i); n     } n   } n   for (int i = 1; i <= n; i++) { n     dist[i][i] = 1; n     bfs(i, i); n   } n   cout <<  YES  n        <<   n ; n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < sz[i].size(); j++) { n       int x = sz[i][j]; n       int y = s[i][j]; n       if (i < x) { n         solve(i, x, y); n       } n     } n   } n   cout << t.size() <<   n ; n   for (int i = 0; i < t.size(); i++) { n     cout << t[i].first <<     << t[i].second.first <<     << t[i].second.second n          <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[44], b[44], PP[44], PPP[44], PHI[44]; n long long dp[1 << 22], DP[1 << 22]; n pair<int, int> P[44]; n void is_ok() { n   dp[0] = 0; n   DP[0] = 0; n   int st = 0; n   for (int i = 0; i < n; ++i) { n     int dr = st + (1 << i); n     while (st < dr) { n       ++st; n       dp[st] = dp[st - (1 << i)] + a[i + 1]; n       DP[st] = DP[st - (1 << i)] + b[i + 1]; n       if (dp[st] == DP[st] && st != (1 << n) - 1) return; n     } n   } n   for (int i = 1; i <= n; ++i) cout << b[i] <<    ; n   exit(0); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     P[i] = make_pair(a[i], i); n   } n   sort(P + 1, P + n + 1); n   P[n + 1] = P[1]; n   for (int i = 2; i <= n + 1; ++i) PHI[P[i].second] = PP[P[i].second] = i - 1; n   for (int t = 1; t <= n; ++t) { n     for (int i = 1; i <= n; ++i) b[i] = P[PP[i]].first; n     is_ok(); n     for (int i = 1; i <= n; ++i) PPP[i] = PP[PHI[i]]; n     for (int i = 1; i <= n; ++i) PP[i] = PPP[i]; n   } n   cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int n, q; n string s; n int dp[251][251][251]; n int nxt[26][112345]; n int len[3]; n int chs[3][250]; n template <class T, class U> n inline void smax(T &a, U b) { n   a = a > b ? a : b; n } n template <class T, class U> n inline void smin(T &a, U b) { n   a = a < b ? a : b; n } n int main() { n   std::ios::sync_with_stdio(false), std::cin.tie(0); n   cin >> n >> q; n   cin >> s; n   for (int i = 0; i < 26; i++) { n     nxt[i][n] = nxt[i][n + 1] = n; n     for (int j = n - 1; j >= 0; j--) n       if (s[j] ==  a  + i) n         nxt[i][j] = j; n       else n         nxt[i][j] = nxt[i][j + 1]; n   } n   dp[0][0][0] = -1; n   for (int t = 0; t < q; t++) { n     char c; n     int group; n     cin >> c >> group; n     group -= 1; n     if (c ==  + ) { n       char ch; n       cin >> ch; n       chs[group][len[group]] = ch -  a ; n       len[group]++; n       int i[3]; n       for (i[0] = group == 0 ? len[0] : 0; i[0] <= len[0]; i[0]++) n         for (i[1] = group == 1 ? len[1] : 0; i[1] <= len[1]; i[1]++) n           for (i[2] = group == 2 ? len[2] : 0; i[2] <= len[2]; i[2]++) { n             if (!i[0] && !i[1] && !i[2]) continue; n             dp[i[0]][i[1]][i[2]] = n; n             for (int k = 0; k < 3; k++) { n               if (i[k] > 0) { n                 smin(dp[i[0]][i[1]][i[2]], n                      nxt[chs[k][i[k] - 1]] n                         [dp[i[0] - (0 == k)][i[1] - (1 == k)][i[2] - (2 == k)] + n                          1]); n               } n             } n           } n     } else { n       len[group]--; n     } n     cout << ((dp[len[0]][len[1]][len[2]] < n) ?  Yes  :  No ) <<   n ; n   } n   cout << flush; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mxn = 1e6 + 3; n struct node { n   int v, i, j, id; n } a[mxn]; n int n, m, r[mxn], c[mxn], f[mxn], v[mxn], o[mxn]; n int cmp(node a, node b) { return a.v < b.v; } n int fffa(int x) { return f[x] == x ? x : f[x] = fffa(f[x]); } n int main() { n   scanf( %d%d , &n, &m); n   for (int(i) = (int)(1); (i) <= (int)(n); ++(i)) n     for (int(j) = (int)(1); (j) <= (int)(m); ++(j)) { n       int id = (i - 1) * m + j; n       scanf( %d , &o[id]); n       a[id].v = o[id]; n       a[id].i = i; n       a[id].j = j; n       a[id].id = f[id] = id; n     } n   sort(a + 1, a + 1 + n * m, cmp); n   for (int(i) = (int)(1); (i) <= (int)(n * m); ++(i)) { n     int fi = fffa(r[a[i].i]); n     int fj = fffa(c[a[i].j]); n     v[a[i].id] = max(v[fi] + (a[i].v > o[fi]), v[fj] + (a[i].v > o[fj])); n     int p = fffa(a[i].id); n     if (a[i].v == o[fi]) f[fi] = p; n     if (a[i].v == o[fj]) f[fj] = p; n     r[a[i].i] = c[a[i].j] = p; n   } n   for (int(i) = (int)(1); (i) <= (int)(n); ++(i)) n     for (int(j) = (int)(1); (j) <= (int)(m); ++(j)) n       printf( %d%c , v[fffa((i - 1) * m + j)],    n [j == m]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2000000; n const long long int MOD = 1000000009; n const long long int P = 31; n int N; n long long int t[4 * MAXN] = {0}; n long long int tp[4 * MAXN] = {0}; n void make_push(int v, int l, int r, long long int tmp) { n   t[v] += (r - l + 1) * tmp; n   tp[v] += tmp; n } n void push(int v, int l, int r) { n   if (l != r) { n     make_push(2 * v + 1, l, (l + r) / 2, tp[v]); n     make_push(2 * v + 2, (l + r) / 2 + 1, r, tp[v]); n   } n   tp[v] = 0; n } n void update(int ql, int qr, long long int qv, int v = 0, int l = 0, n             int r = N - 1) { n   if (qr < l || r < ql) return; n   push(v, l, r); n   if (ql <= l && r <= qr) { n     make_push(v, l, r, qv); n   } else { n     update(ql, qr, qv, 2 * v + 1, l, (l + r) / 2); n     update(ql, qr, qv, 2 * v + 2, (l + r) / 2 + 1, r); n     t[v] = t[2 * v + 1] + t[2 * v + 2]; n   } n } n long long int get_ans(int qp, int v = 0, int l = 0, int r = N - 1) { n   if (qp < l || r < qp) return 0; n   push(v, l, r); n   if (qp <= l && r <= qp) n     return t[v]; n   else n     return get_ans(qp, 2 * v + 1, l, (l + r) / 2) + n            get_ans(qp, 2 * v + 2, (l + r) / 2 + 1, r); n } n int A[MAXN], T[MAXN], X[MAXN]; n int id[MAXN]; n long long int ans[MAXN]; n vector<int> ts; n bool cmp(int idl, int idr) { n   if (X[idl] != X[idr]) return X[idl] < X[idr]; n   return idl < idr; n } n int main() { n   scanf( %d , &N); n   for (int i = 0; i < N; i++) { n     scanf( %d %d %d , &A[i], &T[i], &X[i]); n     id[i] = i; n   } n   sort(id, id + N, cmp); n   ts.reserve(N); n   int lb, rb = 0; n   int offs = 0, sz; n   int tid; n   while (rb < N) { n     lb = rb; n     while (rb < N && X[id[rb]] == X[id[lb]]) rb++; n     sz = rb - lb; n     for (int i = lb; i < rb; i++) { n       ts.push_back(T[id[i]]); n     } n     sort(ts.begin(), ts.end()); n     for (int i = lb; i <= rb; i++) { n       tid = lower_bound(ts.begin(), ts.end(), T[id[i]]) - ts.begin(); n       if (A[id[i]] == 1) { n         update(offs + tid, offs + sz - 1, 1); n       } else if (A[id[i]] == 2) { n         update(offs + tid, offs + sz - 1, -1); n       } else { n         ans[id[i]] = get_ans(offs + tid); n       } n     } n     offs += sz; n     ts.clear(); n   } n   for (int i = 0; i < N; i++) { n     if (A[i] == 3) printf( %I64d n , ans[i]); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const ll MOD = 1e9 + 7, N = 1e5 + 10; n void test() { n   string s; n   cin >> s; n   vector<ll> cnt(26); n   for (auto c : s) { n     cnt[c -  a ]++; n   } n   ll m; n   cin >> m; n   vector<ll> b(m); n   for (ll i = 0; i < m; i++) { n     cin >> b[i]; n   } n   ll n = s.length(); n   vector<ll> done(m); n   string res(m,  . ); n   ll up = 25; n   for (ll i = 0; i < m; i++) { n     ll mx = 1e9; n     for (ll j = 0; j < m; j++) { n       if (done[j]) continue; n       mx = min(mx, b[j]); n     } n     if (mx == 1e9) break; n     vector<ll> pos; n     for (ll j = 0; j < m; j++) { n       if (done[j]) continue; n       if (mx == b[j]) { n         pos.push_back(j); n       } n     } n     ll v; n     for (ll j = up; j >= 0; --j) { n       if (cnt[j] >= pos.size()) { n         v = j; n         break; n       } n     } n     up = v - 1; n     for (auto &e : pos) { n       res[e] = char(v +  a ); n     } n     for (auto &e : pos) { n       for (ll j = 0; j < m; j++) { n         if (!done[j]) { n           b[j] -= abs(j - e); n         } n       } n     } n     for (auto &e : pos) done[e] = 1; n   } n   cout << res <<   n ; n   return; n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   ll tt = 1; n   cin >> tt; n   for (ll i = 0; i < tt; i++) test(); n   return 0; n } n


#include <iostream> n #include <bits/stdc++.h> n using namespace std; n typedef long long int l; n #define fastIO              ios::sync_with_stdio(false), cin.tie(0) n #define pf                  push_front n #define pb                  push_back n #define popb                pop_back() n #define popf                pop_front() n #define loop(i,n)           for(int i=0;i<n;i++) n #define loope(i,n)           for(int i=0;i<=n;i++) n #define loop1(i,n)           for(int i=1;i<n;i++) n #define loops(i,x,n)        for(int i=x;i<n;i++) n #define loopr(i,n)          for(int i=n-1;i>=0;i--) n #define loop1e(i,n)          for(int i=1;i<=n;i++) n #define F first n #define S second n #define LB lower_bound n #define UB upper_bound n #define vc vector n #define vll vector<long long> n #define pll pair<long long,long long> n #define eb emplace_back n #define pb push_back n #define mp make_pair n #define INT_BITS 32 n #define  st                  l t; cin>>t; n #define  sn                  l n; cin>>n; n #define all(x) x.begin(),x.end() n //#define  unordered_map<l,l>  u; n #define MOD1 1000000007 n int main() n { n     st; n     while(t--) n     { n  n         l n; n         cin>>n; n         l a[n]; n         l k = n; n for(int i=0;i<n;i++){ n             a[i]=k; n             k--; n         } n         if(n&1){ n             int p=n/2; n             swap(a[p],a[p+1]); n         } n         for(int i=0;i<n;i++){ n             cout<<a[i]<<   ; n         } n         cout<<endl; n        // cout<<endl; n  n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ans[210000], k; n vector<pair<int, int>> item, b; n struct R { n   int l, r, cc; n   long long value; n   R(int L, int R, int CC = 0, long long VALUE = 0) { n     l = L, r = R, cc = CC, value = VALUE; n   } n }; n vector<R> range; n void update() { n   long long value; n   int l, r, c; n   for (int i = 0; i < range.size(); i++) { n     l = range[i].l, r = range[i].r; n     c = range[i].cc, value = range[i].value; n     for (int j = l; j <= r; j++) b[j].first -= value, ans[b[j].second] += c; n   } n   sort(b.begin(), b.end()); n   range.clear(); n   range.push_back(R(0, k - 1)); n } n int main() { n   int n, c, q, l, r; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d %d , &c, &q); n     item.push_back(make_pair(-q, c)); n   } n   sort(item.begin(), item.end()); n   scanf( %d , &k); n   for (int i = 0; i < k; i++) scanf( %d , &c), b.push_back(make_pair(c, i)); n   sort(b.begin(), b.end()); n   int value = 0; n   update(); n   for (int i = 0; i < n; i++) { n     c = item[i].second; n     q = range.size(); n     for (int j = 0; j < q; j++) { n       l = range[j].l, r = range[j].r; n       value = range[j].value; n       if (b[l].first >= value + c) n         range[j].value += c, ++range[j].cc; n       else if (b[r].first >= c + value) { n         int index = lower_bound(b.begin() + l, b.begin() + r + 1, n                                 make_pair(c + value, 0)) - n                     b.begin(); n         range.push_back(R(index, r, range[j].cc + 1, value + c)); n         range[j].r = index - 1; n       } n     } n     if (range.size() > 500) update(); n   } n   update(); n   for (int i = 0; i < k; i++) printf( %d  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t, i, j, k, l, m, n, p, q, r, s = 0, a, b, c, d, ans = 0, x, y; n   cin >> n >> k; n   string s1; n   cin >> s1; n   for (i = 0; i < n; i++) { n     if (s1[i] ==  G ) { n       p = i; n     } else if (s1[i] ==  T ) { n       q = i; n     } n   } n   if (abs(p - q) % k != 0) { n     cout <<  NO n ; n     return 0; n   } n   a = min(p, q); n   b = max(p, q); n   for (i = a; i <= b; i += k) { n     if (s1[i] ==  # ) { n       cout <<  NO n ; n       return 0; n     } n   } n   cout <<  YES n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   int x, y, a, b; n   double dis = 0; n   cin >> x >> y; n   a = x; n   b = y; n   n--; n   while (n--) { n     cin >> x >> y; n     dis += (double)sqrt(pow(y - b, 2) + pow(x - a, 2)); n     a = x; n     b = y; n   } n   dis = (dis / 50) * k; n   printf( %.6f , dis); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, sum = 0; n   cin >> n >> m; n   sum = n + (n - 1) / (m - 1); n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const int MAXN = 200010; n const long long MOD = 998244353; n int main() { n   int n; n   scanf( %d , &n); n   if (n == 1) n     printf( 1 2 n ); n   else n     printf( %d 2 n , (n - 1) * 2); n   printf( 1 2 n ); n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1}; n const int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; n const int N = 3e5 + 2; n int v[N], n, q; n void read() { n   cin >> n >> q; n   for (int i = 1; i <= n; i++) cin >> v[i]; n   v[0] = 0; n   v[n + 1] = 0; n } n int maxima_con[N], minima_con[N]; n long long maxima_sum = 0, minima_sum = 0; n bool is_maxima(int indx) { return v[indx] > max(v[indx - 1], v[indx + 1]); } n bool is_minima(int indx) { return v[indx] < min(v[indx - 1], v[indx + 1]); } n void see(int indx) { n   int &i = indx; n   maxima_sum -= maxima_con[i]; n   minima_sum -= minima_con[i]; n   maxima_con[i] = 0; n   minima_con[i] = 0; n   if (is_maxima(i)) { n     maxima_con[i] = v[i]; n     maxima_sum += maxima_con[i]; n   } n   if (is_minima(i)) { n     minima_con[i] = v[i]; n     minima_sum += minima_con[i]; n   } n } n void solve(int test_case) { n   read(); n   for (int i = 1; i <= n; i++) { n     see(i); n   } n   cout << maxima_sum - minima_sum; n   cout <<   n ; n   ; n   for (int i = 0; i < q; i++) { n     int l, r; n     cin >> l >> r; n     swap(v[l], v[r]); n     for (int del = -1; del <= 1; del++) { n       int indx = l + del; n       if (indx > 0 && indx <= n) see(indx); n       indx = r + del; n       if (indx > 0 && indx <= n) see(indx); n     } n     cout << maxima_sum - minima_sum; n     cout <<   n ; n     ; n   } n } n void clear_data() { n   for (int i = 1; i <= n; i++) maxima_con[i] = 0, minima_con[i] = 0; n   maxima_sum = 0; n   minima_sum = 0; n } n int main() { n   ios_base ::sync_with_stdio(false); n   cin.tie(0); n   int t = 1; n   cin >> t; n   for (int i = 1; i <= t; i++) { n     solve(i); n     clear_data(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e6 + 10; n const long long mod = 1e9 + 7; n long long read() { n   long long x = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) x = (x << 1) + (x << 3) + c -  0 , c = getchar(); n   return x * f; n } n double ans; n struct BIT { n   long long tr[N]; n   long long Bmax; n   long long lb(long long x) { return (-x) & x; } n   void init(long long n) { n     Bmax = n; n     for (long long i = 0; i <= n; i++) tr[i] = 0; n   } n   long long query(long long x) { n     if (x <= 0) return 0; n     long long res = 0; n     while (x) { n       res += tr[x]; n       x -= lb(x); n     } n     return res; n   } n   void update(long long x, long long w) { n     if (x <= 0) return; n     while (x <= Bmax) { n       tr[x] += w; n       x += lb(x); n     } n   } n } t1, t2; n int a[N]; n int main() { n   long long n = read(); n   for (int i = 1; i <= n; i++) a[i] = read(); n   for (long long i = 1; i <= n; i++) { n     ans += (double)1.00 * i * (i - 1) / 4.00 * (n - i + 1); n   } n   t1.init(n); n   t2.init(n); n   for (long long i = 1; i <= n; i++) { n     long long o1 = t1.query(n) - t1.query(a[i]); n     long long o2 = t2.query(n) - t2.query(a[i]); n     t1.update(a[i], 1); n     t2.update(a[i], i); n     ans += (double)(1.00 * n * (n + 1) * o1 * 0.5 - 1.00 * (n - i + 1) * o2); n   } n   printf( %.10lf , ans / (1.00 * n * (n + 1) / 2)); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000005; n const int inf = 1e9 + 7; n long long fac[N], M, inv[N]; n inline long long po(long long x, long long y, long long z) { n   long long res = 1; n   while (y) { n     if (y & 1) res = res * x % z; n     x = x * x % z; n     y >>= 1; n   } n   return res; n } n long long ans[N], M2; n inline long long C(int x, int y) { n   return fac[x] * inv[y] % M2 * inv[x - y] % M2; n } n int main() { n   int n, m, a; n   scanf( %d%d%d%lld , &n, &m, &a, &M); n   long long res = 1; n   for (int i = (1); i <= (2000000); i++) { n     res = res * (long long)a % M; n     if (res == 1) { n       M2 = i; n       break; n     } n   } n   fac[0] = fac[1] = inv[0] = inv[1] = 1; n   for (int i = (2); i <= (M2); i++) { n     fac[i] = fac[i - 1] * (long long)i % M2; n     inv[i] = po(fac[i], M2 - 2, M2); n   } n   ans[0] = 1; n   for (int i = (1); i <= (N - 1); i++) { n     ans[i] = ans[i - 1]; n     ans[i] += C(m, i); n   } n   for (int i = (n - 1); i >= (0); i--) printf( %lld  , po(a, ans[i], M)); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int II() { n   int n; n   scanf( %d , &n); n   return n; n } n int table[100][100]; n char message[100][200]; n string names[100]; n void recprint(int m, int s) { n   if (m < 0) return; n   recprint(m - 1, table[m][s]); n   cout << names[s]; n   printf( :%s n , message[m]); n } n int main() { n   int T = II(); n   while (T--) { n     set<std::string> usernames; n     int N = II(); n     for (int x = 0; x < N; x++) { n       string s; n       cin >> s; n       usernames.insert(s); n     } n     for (auto it = usernames.begin(); it != usernames.end(); it++) n       names[distance(usernames.begin(), it)] = *it; n     int M = II(); n     int sa = N, sb = N; n     for (int m = 0; m < M; m++) { n       for (int x = 0; x < N; x++) table[m][x] = N; n       string user; n       user.clear(); n       char c = getchar(); n       while (c < 32) c = getchar(); n       while (c !=  : ) { n         user += c; n         c = getchar(); n       } n       int it = distance(usernames.begin(), usernames.find(user)); n       if (it < N) n         for (int x = 0; x < N; x++) n           if (x != it) table[m][x] = -1; n       user.clear(); n       char *msg = message[m]; n       c = getchar(); n       while (true) { n         bool ended = false; n         if (c ==  !  || c ==  ?  || c ==  .  || c ==  ,  || c ==     || n             c == 10) { n           int it = distance(usernames.begin(), usernames.find(user)); n           if (it < N) table[m][it] = -1; n           ended = true; n         } n         if (c == 10) break; n         *msg = c; n         msg++; n         user += c; n         if (ended) user.clear(); n         c = getchar(); n       } n       *msg = 0; n       for (int x = 0; x < N; x++) n         if (table[m][x] != -1) table[m][x] = (x == sa ? sb : sa); n       sa = sb = -1; n       for (int x = 0; x < N; x++) n         if (table[m][x] != -1) sa = x; n       for (int x = 0; x < N; x++) n         if (table[m][x] != -1) n           if (x != sa) sb = x; n     } n     if (sa == -1) n       printf( Impossible n ); n     else n       recprint(M - 1, sa); n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> ans; n struct item { n   int key, prior; n   item *left, *right; n   item() {} n   item(int key, int prior) : key(key), prior(prior), left(NULL), right(NULL) {} n }; n typedef item* pitem; n void split(pitem temp, int key, pitem& left, pitem& right) { n   if (!temp) n     left = right = NULL; n   else if (key < temp->key) n     split(temp->left, key, left, temp->left), right = temp; n   else n     split(temp->right, key, temp->right, right), left = temp; n } n void insert(pitem& temp, pitem it) { n   if (!temp) n     temp = it; n   else if (it->prior > temp->prior) n     split(temp, it->key, it->left, it->right), temp = it; n   else n     insert(it->key < temp->key ? temp->left : temp->right, it); n } n void merge(pitem& temp, pitem left, pitem right) { n   if (!left || !right) n     temp = left ? left : right; n   else if (left->prior > right->prior) n     merge(left->right, left->right, right), temp = left; n   else n     merge(right->left, left, right->left), temp = right; n } n void erase(pitem& temp, int key) { n   if (temp->key == key) n     merge(temp, temp->left, temp->right); n   else n     erase(key < temp->key ? temp->left : temp->right, key); n } n pitem unite(pitem left, pitem right) { n   if (!left || !right) return left ? left : right; n   if (left->prior < right->prior) swap(left, right); n   pitem lt, rt; n   split(right, left->key, lt, rt); n   left->left = unite(left->left, lt); n   left->right = unite(left->right, rt); n   return left; n } n int getMin(pitem temp) { n   while (temp->left) temp = temp->left; n   return temp->key; n } n pitem eraseMin(pitem temp) { n   int minn = getMin(temp); n   erase(temp, minn); n   return temp; n } n void dfs(pitem temp) { n   ans.push_back(temp->key); n   if (temp->left) dfs(temp->left); n   if (temp->right) dfs(temp->right); n } n long long mass[200000]; n vector<int> mass1[200000]; n unordered_map<int, bool> prefs; n int n; n bool f(long long m, bool fin) { n   if (fin) { n     for (int i = 0; i < n; i++) { n       int now = 0; n       int last = -1; n       for (int u = mass1[i].size() - 1; u > -1; u--) { n         now *= 2; n         now += mass1[i][u]; n         if (prefs[now] == 0 && now <= m) last = now; n       } n       cout << last <<    ; n       prefs[last] = 1; n     } n     return 0; n   } else n     for (int i = 0; i < n; i++) { n       int now = 0; n       int last = -1; n       for (int u = mass1[i].size() - 1; u > -1; u--) { n         now *= 2; n         now += mass1[i][u]; n         if (now > m) break; n         if (prefs[now] == 0) last = now; n       } n       if (last == -1) n         return 0; n       else n         prefs[last] = 1; n     } n   return 1; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> mass[i]; n   sort(mass, mass + n); n   reverse(mass, mass + n); n   for (int i = 0; i < n; i++) { n     long long a = mass[i]; n     while (a) { n       mass1[i].push_back(a % 2); n       a /= 2; n     } n   } n   long long l = 1, r = 1e9; n   for (int b = 0; b < 30; b++) { n     prefs.clear(); n     long long mid = (l + r) / 2; n     if (f(mid, 0)) n       r = mid; n     else n       l = mid; n   } n   prefs.clear(); n   f(r, 1); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( -O2 ) n using namespace std; n void err(istream_iterator<string> it) { cerr << endl; } n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cerr << *it <<   =   << a <<   t ; n   err(++it, args...); n } n template <typename T1, typename T2> n ostream& operator<<(ostream& c, pair<T1, T2>& v) { n   c <<  (  << v.first <<  ,  << v.second <<  ) ; n   return c; n } n template <template <class...> class TT, class... T> n ostream& operator<<(ostream& out, TT<T...>& c) { n   out <<  {  ; n   for (auto& x : c) out << x <<    ; n   out <<  } ; n   return out; n } n const int LIM = 1e5 + 5, MOD = 998244353; n int t, n, m, k, x, y, w; n inline long long powm(long long x, long long pw, long long Mod = MOD) { n   x %= Mod; n   long long res = 1; n   while (pw) { n     if (pw & 1LL) res = ((res * x)) % Mod; n     pw >>= 1; n     x = ((x * x)) % Mod; n   } n   return res; n } n inline long long inv(long long x, long long Mod = MOD) { n   return powm(x, Mod - 2, Mod); n } n template <int mod> n struct FWHT { n   vector<int> fwht(vector<int> P, bool inverse, bool nomod = 0) { n     int sz = P.size(); n     for (int len = 1; 2 * len <= sz; len <<= 1) { n       for (int i = 0; i < sz; i += 2 * len) { n         for (int j = 0; j < len; ++j) { n           int u = P[i + j]; n           int v = P[i + len + j]; n           if (nomod) { n             P[i + j] = (u + v); n             P[i + len + j] = (u - v); n           } else { n             P[i + j] = (u + v) % mod; n             P[i + len + j] = (u - v + mod) % mod; n           } n         } n       } n     } n     if (inverse) { n       long long iv = inv(sz, mod); n       for (int i = 0; i < sz; ++i) P[i] = P[i] * iv % mod; n     } n     return P; n   } n   vector<int> mult(vector<int> A, vector<int> B) { n     A = fwht(A, 0); n     B = fwht(B, 0); n     for (int i = 0; i < A.size(); ++i) A[i] = A[i] * 1LL * B[i] % mod; n     return fwht(A, 1); n   } n   vector<int> pow(vector<int> A, long long k) { n     A = fwht(A, 0); n     for (int i = 0; i < A.size(); ++i) A[i] = powm(A[i], k); n     return fwht(A, 1); n   } n }; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> k; n   int sz = (1 << k); n   vector<int> A(sz, 0), B(sz, 0), C(sz, 0), D(sz, 0); n   long long o1, o2, o3; n   cin >> o1 >> o2 >> o3; n   int totxor = 0; n   for (int i = 0; i < n; ++i) { n     cin >> x >> y >> w; n     totxor ^= x; n     y ^= x, w ^= x; n     A[y]++; n     B[w]++; n     C[y ^ w]++; n   } n   FWHT<MOD> f; n   A = f.fwht(A, 0, 1), B = f.fwht(B, 0, 1), C = f.fwht(C, 0, 1); n   for (int i = 0; i < sz; ++i) { n     int x1 = (n + A[i]) / 2, x2 = (n + B[i]) / 2, x3 = (n + C[i]) / 2; n     int a1 = (x1 + x2 + x3 - n) / 2, b1 = x2 - a1, c1 = x1 - a1, d1 = x3 - a1; n     D[i] = ((powm(o1 + o2 + o3, a1) * powm(o1 - o2 + o3 + MOD, b1) % MOD) * n             powm(o1 + o2 - o3 + MOD, c1) % MOD) * n            powm(o1 - o2 - o3 + MOD + MOD, d1) % MOD; n   } n   D = f.fwht(D, 1); n   for (int i = 0; i < sz; ++i) cout << D[i ^ totxor] <<    ; n   cout <<   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   int *a = new int[m]; n   if (m % 2 == 0) { n     for (int i = 0; i < m; i++) { n       if (i % 2 == 0) a[i] = m / 2 - i / 2; n       if (i % 2 == 1) a[i] = m / 2 + 1 + (i - 1) / 2; n     } n   } else { n     for (int i = 0; i < m; i++) { n       if (i % 2 == 1) a[i] = (m - 1) / 2 - (i - 1) / 2; n       if (i % 2 == 0) a[i] = (m + 1) / 2 + i / 2; n     } n   } n   for (int i = 0; i < n; i++) cout << a[i % m] << endl; n   return 0; n } n


#include  bits/stdc++.h  n using namespace std; n #define pb          push_back n #define ll          long long n #define mp          make_pair n #define pii         pair<int,int> n #define vi          vector<int> n #define vii         vector<pii> n #define mi          map<int,int> n #define mii         map<pii,int> n #define all(a)      (a).begin(),(a).end() n #define x           first n #define y           second n #define sz(x)       (int)x.size() n #define endl          n  n #define MOD         1000000007 n #define hell        1000000007 n #define debug(x) cout <<  >  << #x <<  :  << x << endl; n #define rep(i,a,b)  for(int i=a;i<b;i++) n #define rev(i,a,b)  for(int i=a;i>=b;i--) n #define ll          long long n #define bg(i)       i.begin() n #define fset(it,s)   for(auto it = s.begin(); it != s.end(); it++) n   n   n #define track(x)                cerr<<#x<< :  <<x<<endl n #define track2(x, y)             cerr<<#x<< :  <<x<<  |  <<#y<< :  <<y<<endl n #define track3(x, y, z)          cerr<<#x<< :  <<x<<  |  <<#y<< :  <<y<<  |  <<#z<< :  <<z<<endl n #define track4(a, b, c, d)       cerr<<#a<< :  <<a<<  |  <<#b<< :  <<b<<  |  <<#c<< :  <<c<<  |  <<#d<< :  <<d<<endl n   n #define ed(i)       i.end() n #define mem(a)      memset(a, 0, sizeof(a)) n ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;} n ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;} n ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;} n ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);} n void self_max(int &a, int &b) {a = max(a, b); } n void self_min(int &a, int &b) {a = min(a, b); } n  n const ll sizes  = 1e7+1; n const ll mod  = 1000000007; n  n ll n, m , k , o , p; n // ll a[sizes]; n  n void solve(){ n     cin >> n >> m >> k; n     ll sum1 = 0 , sum2 = 0 , sum3 = 0 , sum = 0; n     vector<ll>a , b , c, d; n     for(int i = 0 ;  i < n ; i++){ n         cin >> o; n         a.pb(o); n         sum += o; n       n         sum1+=o; n     } n     for(int i = 0 ; i < m ; i++){ n         cin >> o; n         b.pb(o); n         sum2 += o; n         sum += o; n     } n     for(int i = 0 ; i < k ; i++){ n         cin >> o; n         c.pb(o); n         sum3 += o; n         sum += o; n     } n  n     sort(all(a));sort(all(b));sort(all(c)); n     d.push_back(a[0]); n     d.pb(b[0]); n     d.pb(c[0]); n     sort(all(d)); n     ll mn = min(min(sum1 , sum2) , sum3); n     mn = min(mn , d[0] + d[1]); n  n     cout << sum - (2 * mn) << endl;; n } n  n int main() { n     ios::sync_with_stdio(false); n     cout<<fixed<<setprecision(2); n     cin.tie(0); n     cout.tie(0); n     // fun(); n     int t = 1; n     // cin >> t;   n     int p = t;   n     while(t--){ n         solve(); n     }    n } n  n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int maxn = 115 + 5; n char s[maxn][maxn]; n int main() { n   int n, m; n   while (~scanf( %d%d , &n, &m)) { n     int mini = inf, maxi = 0, minj = inf, maxj = 0; n     getchar(); n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= m; j++) { n         scanf( %c , &s[i][j]); n         if (s[i][j] ==  B ) { n           mini = min(mini, i); n           minj = min(minj, j); n           maxi = max(maxi, i); n           maxj = max(maxj, j); n         } n       } n       getchar(); n     } n     printf( %d %d n , (mini + maxi) / 2, (minj + maxj) / 2); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, two, one; n   cin >> n >> m; n   if (m < n - 1 || m > 2 * n + 2) n     cout <<  -1 ; n   else { n     if (m < n) { n       cout <<  0 ; n       n--; n     } n     while (m > 0 || n > 0) { n       two = max(m - n - 1, 0); n       one = min(2 * n + 2, m); n       if (two) { n         cout <<  11 ; n         m -= 2; n         two--; n       } else if (one) { n         cout <<  1 ; n         m--; n         one--; n       } n       if (n) cout <<  0 ; n       n--; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using LL = long long; n constexpr int maxn = 100000 + 1; n LL h[maxn], p[maxn], up[maxn], sz[maxn]; n int par[maxn]; n vector<int> G[maxn], order; n void DFS(int u) { n   sz[u] = p[u]; n   for (int v : G[u]) n     if (v != par[u]) { n       par[v] = u; n       DFS(v); n       sz[u] += sz[v]; n     } n   h[u] = sz[u] - h[u]; n   order.push_back(u); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int t; n   for (cin >> t; t; t -= 1) { n     int n, m; n     cin >> n >> m; n     for (int i = 1; i <= n; i += 1) cin >> p[i]; n     for (int i = 1; i <= n; i += 1) cin >> h[i]; n     for (int i = 1; i <= n; i += 1) G[i].clear(); n     for (int i = 1; i <= n; i += 1) up[i] = 0; n     for (int i = 1, x, y; i < n; i += 1) { n       cin >> x >> y; n       G[x].push_back(y); n       G[y].push_back(x); n     } n     order.clear(); n     DFS(1); n     int ans = 1; n     for (int u : order) n       if (h[u] < 0 or (h[u] & 1)) n         ans = 0; n       else if (h[u] / 2 > up[u] + p[u]) n         ans = 0; n       else n         up[par[u]] += h[u] / 2; n     cout << (ans ?  YES n  :  NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n; n bool check(int x, long long y) { n   if (n * 2 / x < x + y) return true; n   if (n * 2 / x > x + y) return false; n   return n * 2 <= x * (x + y); n } n long long calc(long long y) { n   int l = 1, r = 2e9, mid; n   while (l < r) { n     mid = (l >> 1) + (r >> 1) + (l & r & 1); n     if (check(mid, y - 3)) n       r = mid; n     else n       l = mid + 1; n   } n   if ((r + y - 3) * r != 2 * n || 0 == (r & 1)) return -1; n   return r * y / 2; n } n int main() { n   bool ok = false; n   cin >> n; n   for (int i = 1; i <= 62; ++i) { n     long long res = calc(1LL << i); n     if (~res) { n       ok = true; n       printf( %I64d n , res); n     } n   } n   if (!ok) puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5e5 + 10; n pair<int, int> p[maxn], q[maxn]; n int t[maxn]; n int tot; n int n, k; n int dp[maxn][2]; n void solve() { n   memset(dp, 0x3f3f3f3f, sizeof(dp)); n   int e = 0; n   for (int i = 1; i <= tot; i++) { n     dp[i][e] = min(dp[i - 1][e], q[i].second - q[i].first); n   } n   e ^= 1; n   for (int ki = 2; ki <= k; ki++, e ^= 1) { n     dp[1][e] = 0x3f3f3f3f; n     for (int i = 2; i <= tot; i++) { n       bool last = q[i - 1].second == q[i].first; n       dp[i][e] = n           min(dp[i - 1 - last][e ^ 1] + q[i].second - q[i].first, dp[i - 1][e]); n     } n   } n   cout << dp[tot][e ^ 1] << endl; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> k >> n; n   for (int i = 0; i < n; i++) cin >> t[i]; n   sort(t, t + n); n   for (int i = 1; i < n; i++) { n     p[i] = make_pair(t[i - 1], t[i]); n   } n   sort(p + 1, p + n, [](const pair<int, int> &x, const pair<int, int> &y) { n     return (x.second - x.first) < (y.second - y.first); n   }); n   tot = min(3 * k, n - 1); n   for (int i = 1; i <= tot; i++) { n     q[i] = p[i]; n   } n   sort(q + 1, q + tot + 1, n        [](const pair<int, int> &x, const pair<int, int> &y) { n          return x.first < y.first; n        }); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100; n const int V = 100 * 50; n bool edge[V][V], nf[V]; n int ans, cnt_v, n; n int from[V], start_v[N], value[V]; n void ri() { n   int a, i, j, m, x1, x2; n   memset(from, 0xff, sizeof(from)); n   memset(edge, false, sizeof(edge)); n   cin >> n >> m; n   for (i = 0; i < n; i++) { n     start_v[i] = cnt_v; n     cin >> a; n     j = 2; n     while (a > 1) { n       for (; j * j <= a && a % j != 0; j++) n         ; n       if (a % j != 0) j = a; n       value[cnt_v++] = j; n       a /= j; n     } n   } n   start_v[n] = cnt_v; n   while (m--) { n     cin >> x1 >> x2; n     x1--; n     x2--; n     for (i = start_v[x1]; i < start_v[x1 + 1]; i++) n       for (j = start_v[x2]; j < start_v[x2 + 1]; j++) { n         edge[i][j] = value[i] == value[j]; n         edge[j][i] = value[i] == value[j]; n       } n   } n } n bool ok(int v1) { n   int temp, v2; n   nf[v1] = false; n   for (v2 = 0; v2 < cnt_v; v2++) n     if (edge[v1][v2] && nf[v2]) { n       nf[v2] = false; n       temp = from[v2]; n       from[v2] = v1; n       if (temp == -1 || ok(temp)) return true; n       from[v2] = temp; n     } n   return false; n } n void solve() { n   int i, j; n   for (i = 0; i < n; i++) { n     if (i & 1) continue; n     for (j = start_v[i]; j < start_v[i + 1]; j++) { n       memset(nf, true, sizeof(nf)); n       if (ok(j)) ans++; n     } n   } n } n void print() { cout << ans << endl; } n int main() { n   ri(); n   solve(); n   print(); n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 4e5 + 10; n const double eps = 1e-8; n const long long inf = 1e18 + 7; n using namespace std; n struct edge { n   int t, v; n   edge *next; n } e[MAXN << 1], *h[MAXN], *o = e; n void add(int x, int y, int w) { n   o->t = y; n   o->v = w; n   o->next = h[x]; n   h[x] = o++; n } n long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   return x * f; n } n int n, a[MAXN]; n long long dp[MAXN]; n int main() { n   n = read(); n   for (int i = 1; i <= n; i++) a[i] = read(); n   if (n == 1) n     return 0 * printf( %d n , a[1]); n   else if (n == 3) { n     int minn = 1e9 + 7; n     long long sum = 0; n     for (int i = 1; i <= n; i++) minn = min(minn, a[i]), sum += a[i]; n     return 0 * printf( %lld n , sum - minn); n   } n   for (int i = n + 1; i <= 2 * n; i++) a[i] = a[i - n]; n   for (int i = 2 * n; i >= 1; i--) dp[i] = a[i] + dp[i + 2]; n   long long maxx = 0; n   for (int i = 1; i <= n; i++) { n     maxx = max(maxx, a[i] + a[i + 1] + dp[i + 3] - dp[i + n]); n   } n   printf( %lld n , maxx); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k = 0, dem = 0, s; n char c[1000001]; n int e[100001]; n deque<int> pq; n int main() { n   cin >> n; n   ; n   for (int i = 1; i <= n; ++i) { n     cin >> c[i]; n     if (c[i] ==  8 ) { n       pq.push_back(i); n       dem++; n     } n   } n   s = n - 11; n   s /= 2; n   for (int i = 1; i <= n; i++) { n     if (s == 0 || dem == 0) break; n     if (c[i] ==  8 ) { n       pq.pop_front(); n       dem--; n       s--; n     } n   } n   if (dem == 0 || pq.front() > n - 10) n     cout <<  NO ; n   else n     cout <<  YES ; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> p, rk; n int getp(int v) { n   if (v == p[v]) return v; n   return p[v] = getp(p[v]); n } n long long res; n long long get(int cnt) { return cnt * 1ll * (cnt - 1) / 2; } n void merge(int u, int v) { n   u = getp(u); n   v = getp(v); n   if (rk[u] < rk[v]) swap(u, v); n   res -= get(rk[u]); n   res -= get(rk[v]); n   rk[u] += rk[v]; n   res += get(rk[u]); n   p[v] = u; n } n int main() { n   int n, m; n   cin >> n >> m; n   res = 0; n   p = rk = vector<int>(n, 1); n   iota(p.begin(), p.end(), 0); n   vector<pair<int, pair<int, int>>> e(n - 1); n   for (int i = 0; i < n - 1; ++i) { n     cin >> e[i].second.first >> e[i].second.second >> e[i].first; n     --e[i].second.first; n     --e[i].second.second; n   } n   vector<pair<int, int>> q(m); n   vector<long long> ans(m); n   for (int i = 0; i < m; ++i) { n     cin >> q[i].first; n     q[i].second = i; n   } n   sort(e.begin(), e.end()); n   sort(q.begin(), q.end()); n   int pos = 0; n   for (int i = 0; i < m; ++i) { n     while (pos < n - 1 && e[pos].first <= q[i].first) { n       int u = e[pos].second.first; n       int v = e[pos].second.second; n       merge(u, v); n       ++pos; n     } n     ans[q[i].second] = res; n   } n   for (int i = 0; i < m; ++i) { n     cout << ans[i] <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   string s; n   cin >> s; n   s[0] = toupper(s[0]); n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n long long i, a[200005], n, x = 0; n int main() { n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     a[i] += x; n     x = max(x, a[i]); n   } n   for (i = 0; i < n; i++) cout << a[i] <<    ; n   cout << endl; n } n


#include  bits/stdc++.h  n #define FI first.first n #define SE first.second n #define TH second n #define fi first n #define se second n #define th second n  n using namespace std; n  n string to_string(const string& str) { n   return str; n } n  n template<typename T> n string to_string(const set<T>& mys) { n   if(mys.empty()) return  {} ; n   string ret =  { ; n   for(auto el: mys) ret += to_string(el) +  ,  ; n   ret.pop_back(), ret.pop_back(); // Remove last space and comma n   ret +=  } ; n   return ret; n } n  n template<typename T> n string to_string(const pair<T, T>& pr) { n   return  (  + to_string(pr.fi) +  ,  + to_string(pr.se) +  ) ; n } n  n template<typename T> n string to_string(const vector<T>& vc, int w) { n   if(vc.empty()) return   ; n   if(w + 1 == vc.size()) return to_string(vc[w]); n   return to_string(vc[w]) +  ,  + to_string(vc, w + 1); n } n  n template<typename T> n string to_string(const vector<T>& vc) { n   return  {  + to_string(vc, 0) +  } ; n } n  n void debug_out() { cerr << endl; } n   n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { n   cerr <<     << to_string(H); n   debug_out(T...); n } n   n #ifdef DEBUG n #define debug(...) cerr <<  [  << #__VA_ARGS__ <<  ]: , debug_out(__VA_ARGS__) n #else n #define debug(...) 42 n #endif n  n class DebugStream {}LOG; n template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; } n #ifdef DEBUG n #define LOG clog n #endif n  n typedef long long ll; n typedef pair<ll, ll> ii; n typedef long double ld; n mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); n  n const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 43; n  n int n, k, dp[maxN][bs], tmp[bs]; n vector<int> adj[maxN]; n  n void apply(int* toad, int* used) { n   for(int i = 0; i < k; i++) n     toad[(i + 1) % k] ^= used[i]; n } n  n void botUp(int nd, int an) { n   for(auto sn: adj[nd]) { n     if(sn == an) continue; n     botUp(sn, nd); n     apply(dp[nd], dp[sn]); n   } n } n  n void topDown(int nd, int an) { n   for(auto sn: adj[nd]) { n     if(sn == an) continue; n     memcpy(tmp, dp[sn], sizeof tmp); n     apply(dp[nd], tmp); n     apply(dp[sn], dp[nd]); n     apply(dp[nd], tmp); n     topDown(sn, nd); n   } n } n  n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   #ifdef DEBUG n   freopen( input.txt ,  r , stdin); n   #endif n  n   cin >> n >> k; n   k *= 2; n   for(int i = 1, u, v; i < n; i++) { n     cin >> u >> v; n     u--, v--; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   for(int i = 0; i < n; i++) cin >> dp[i][0]; n   botUp(0, -1); n   topDown(0, -1); n   for(int i = 0; i < n; i++) { n     int rsp = 0; n     for(int j = k / 2; j < k; j++) rsp ^= dp[i][j]; n     cout << (rsp? 1: 0) <<    ;  n   } n   cout <<   n ; n } n  n


#include <bits/stdc++.h> n using namespace std; n int luck_number[105], tot; n int dp[10005][7]; n bool is_luck(int x) { n   while (x) { n     int y = x % 10; n     x = x / 10; n     if (y > 0 && y < 4) return false; n     if (y > 4 && y < 7) return false; n     if (y > 7) return false; n   } n   return true; n } n void init() { n   tot = 0; n   for (int i = 0; i <= 10000; i++) { n     if (is_luck(i)) luck_number[tot++] = i; n   } n } n void pre10000() { n   for (int i = 0; i <= 10000; i++) n     for (int j = 0; j <= 6; j++) dp[i][j] = -1; n   for (int i = 0; i <= 6; i++) { n     dp[0][i] = 0; n   } n   for (int i = 1; i <= 6; i++) { n     for (int j = 0; j < tot; j++) { n       int x = luck_number[j]; n       for (int k = x; k <= 10000; k++) { n         if (dp[k - x][i - 1] != -1) { n           dp[k][i] = x; n         } n       } n     } n   } n } n int main() { n   init(); n   pre10000(); n   int cas; n   scanf( %d , &cas); n   while (cas--) { n     long long N; n     cin >> N; n     if (N < 10000LL) { n       int n = (int)(N); n       if (dp[n][6] != -1) { n         for (int i = 6; i > 0; i--) { n           printf( %d  , dp[n][i]); n           n -= dp[n][i]; n         } n         puts(  ); n       } else n         printf( -1 n ); n     } else { n       int n1 = (int)(N % 4000LL); n       if (dp[n1][6] == -1) n1 += 4000, N -= 4000; n       long long res[7]; n       for (int i = 6; i > 0; i--) { n         res[i] = (long long)(dp[n1][i]); n         n1 -= dp[n1][i]; n       } n       long long n2 = N - n1; n       long long p = n2 / 4000LL, base = 1000LL; n       while (p) { n         int d = (int)(p % 10LL); n         if (d <= 6) { n           for (int i = 1; i <= d; i++) { n             res[i] += base * 4; n           } n         } else { n           for (int i = 1; i <= d - 7; i++) { n             res[i] += base * 4; n           } n           for (int i = 6; i >= 3; i--) { n             res[i] += base * 7; n           } n         } n         base *= 10LL; n         p /= 10LL; n       } n       for (int i = 1; i <= 6; i++) cout << res[i] <<    ; n       puts(  ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n const long long md = 998244353; n const int Inf = 1e9; n const long long Inf64 = 1e18; n const long long MaxN = 2e5 + 10; n const long long MaxM = 11; n const long double eps = 1e-15; n const long long dx[4] = {0, 1, 0, -1}; n const long long dy[4] = {1, 0, -1, 0}; n const long long ddx[4] = {1, 1, -1, -1}; n const long long ddy[4] = {1, -1, 1, -1}; n const long double Pi = acos(-1); n using namespace std; n long long gcd(long long a, long long b) { n   while (a) { n     b %= a; n     swap(a, b); n   } n   return b; n } n long long gcdex(long long a, long long mod = md) { n   long long g = mod, r = a, x = 0, y = 1; n   while (r != 0) { n     long long q = g / r; n     g %= r; n     swap(g, r); n     x -= q * y; n     swap(x, y); n   } n   return x < 0 ? x + mod : x; n } n long long binpow(long long a, long long n) { n   long long res = 1; n   while (n) { n     if (n & 1) { n       res *= a; n       res %= md; n     } n     a *= a; n     a %= md; n     n >>= 1; n   } n   return res % md; n } n bitset<MaxN> A; n bitset<MaxN> B; n long long dst(pair<long long, long long> a, pair<long long, long long> b) { n   return abs(a.first - b.first) + abs(a.second - b.second); n } n long long Mt[MaxN]; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cerr.tie(0); n   cout << fixed, cout.precision(10); n   long long N; n   cin >> N; n   map<long long, vector<pair<long long, long long> > > Mp; n   for (int i = 0; i < N; i++) { n     long long a, b; n     cin >> a >> b; n     Mp[max(a, b)].push_back({a, b}); n   } n   Mp[0].push_back({0, -0}); n   for (auto& a : Mp) { n     sort(a.second.begin(), a.second.end(), n          [=](pair<long long, long long> a, pair<long long, long long> b) { n            return a.first < b.first || n                   (a.first == b.first && a.second > b.second); n          }); n   } n   vector<vector<long long> > dp(Mp.size() + 1, vector<long long>(2, Inf64)); n   dp[0][1] = dp[0][0] = 0; n   long long lvl = 0; n   long long v = 0; n   for (auto& it : Mp) { n     lvl++; n     pair<long long, long long> l = it.second[0]; n     pair<long long, long long> r = it.second.back(); n     pair<long long, long long> lstl = Mp[v][0]; n     pair<long long, long long> lstr = Mp[v].back(); n     dp[lvl][0] = min(dp[lvl][0], dp[lvl - 1][0] + dst(lstl, r) + dst(l, r)); n     dp[lvl][0] = min(dp[lvl][0], dp[lvl - 1][1] + dst(lstr, r) + dst(l, r)); n     dp[lvl][1] = min(dp[lvl][1], dp[lvl - 1][0] + dst(lstl, l) + dst(l, r)); n     dp[lvl][1] = min(dp[lvl][1], dp[lvl - 1][1] + dst(lstr, l) + dst(l, r)); n     v = it.first; n   } n   cout << min(dp[lvl][0], dp[lvl][1]) <<   n ; n   cerr <<   n  n        <<  Time execute:   << clock() / (double)CLOCKS_PER_SEC <<   sec  n        <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int> > adj(2001); n int match[2001 + 1], dis[2001 + 1]; n bool visited[2001 + 1], minimumVertexCover[2001], maximumIndependentSet[2001]; n const int inf = 1E9; n void ResetVisited() { n   for (int i = 0; i <= 2001; ++i) { n     visited[i] = 0; n   } n } n bool BFS(vector<int> &U) { n   queue<int> Q; n   for (auto u : U) { n     if (match[u] == 2001) { n       dis[u] = 0; n       Q.push(u); n     } else { n       dis[u] = inf; n     } n   } n   dis[2001] = inf; n   while (!Q.empty()) { n     int u = Q.front(); n     Q.pop(); n     visited[u] = 1; n     if (dis[u] < dis[2001]) { n       for (auto v : adj[u]) { n         if (dis[match[v]] == inf) { n           visited[v] = 1; n           dis[match[v]] = 1 + dis[u]; n           Q.push(match[v]); n         } n       } n     } n   } n   return (dis[2001] != inf); n } n bool DFS(int u) { n   if (u == 2001) { n     return true; n   } n   for (auto v : adj[u]) { n     if (dis[match[v]] == 1 + dis[u]) { n       if (DFS(match[v])) { n         match[v] = u; n         match[u] = v; n         return true; n       } n     } n   } n   dis[u] = inf; n   return false; n } n int HopcroftKarpMaximumMatching(vector<int> &U, vector<int> &V) { n   for (auto u : U) { n     match[u] = 2001; n   } n   for (auto v : V) { n     match[v] = 2001; n   } n   int matching = 0; n   for (ResetVisited(); BFS(U); ResetVisited()) { n     for (auto u : U) { n       if (match[u] == 2001) { n         matching += DFS(u); n       } n     } n   } n   return matching; n } n void FillMinimumVertexCover(vector<int> &U, vector<int> &V) { n   for (auto u : U) { n     minimumVertexCover[u] = (match[u] != 2001 && visited[u] == 0); n   } n   for (auto v : V) { n     minimumVertexCover[v] = (match[v] != 2001 && visited[v] == 1); n   } n } n void FillMaximumIndependentSet(vector<int> &U, vector<int> &V) { n   for (auto u : U) { n     maximumIndependentSet[u] = (match[u] == 2001 || visited[u] == 1); n   } n   for (auto v : V) { n     maximumIndependentSet[v] = (match[v] == 2001 || visited[v] == 0); n   } n } n vector<tuple<int, int, int> > segments; n vector<int> AddSegments(vector<pair<int, int> > v) { n   vector<int> V; n   sort(v.begin(), v.end()); n   for (int i = 0; i < v.size() - 1; ++i) { n     if (v[i + 1].first == v[i].first) { n       V.push_back(segments.size()); n       segments.push_back(make_tuple(v[i].first, v[i].second, v[i + 1].second)); n     } n   } n   return V; n } n bool DoSegmentsIntersect(int i, int j) { n   int x, y1, y2, y, x1, x2; n   tie(x, y1, y2) = segments[i]; n   tie(y, x1, x2) = segments[j]; n   return (x1 < x && x < x2 && y1 < y && y < y2); n } n vector<tuple<int, int, int, int> > MakeAnswerSegments( n     vector<int> &V, vector<pair<int, int> > &P, bool isHorizontal) { n   vector<tuple<int, int, int> > v; n   for (auto i : V) { n     if (maximumIndependentSet[i]) { n       v.push_back(segments[i]); n     } n   } n   for (auto p : P) { n     v.push_back(make_tuple(p.first, p.second, p.second)); n   } n   sort(v.begin(), v.end()); n   vector<tuple<int, int, int, int> > ans; n   for (int i = 0, j; i < v.size(); i = j) { n     int x, y1, y2; n     tie(x, y1, y2) = v[i]; n     for (j = i + 1; j < v.size(); ++j) { n       int nx, ny1, ny2; n       tie(nx, ny1, ny2) = v[j]; n       if (nx == x && ny1 == y2) { n         y2 = ny2; n       } else { n         break; n       } n     } n     if (isHorizontal) { n       ans.push_back(make_tuple(y1, x, y2, x)); n     } else { n       ans.push_back(make_tuple(x, y1, x, y2)); n     } n   } n   return ans; n } n void PrintAnswerSegments(vector<tuple<int, int, int, int> > &ans) { n   printf( %lu n , ans.size()); n   for (auto t : ans) { n     int x1, y1, x2, y2; n     tie(x1, y1, x2, y2) = t; n     printf( %d %d %d %d n , x1, y1, x2, y2); n   } n } n int main() { n   int n; n   vector<pair<int, int> > xyPoints, yxPoints; n   cin >> n; n   while (n--) { n     int x, y; n     cin >> x >> y; n     xyPoints.push_back(make_pair(x, y)); n     yxPoints.push_back(make_pair(y, x)); n   } n   vector<int> U = AddSegments(xyPoints); n   vector<int> V = AddSegments(yxPoints); n   for (auto u : U) { n     for (auto v : V) { n       if (DoSegmentsIntersect(u, v)) { n         adj[u].push_back(v); n       } n     } n   } n   HopcroftKarpMaximumMatching(U, V); n   FillMaximumIndependentSet(U, V); n   vector<tuple<int, int, int, int> > horizontalSegments = n       MakeAnswerSegments(V, yxPoints, 1); n   vector<tuple<int, int, int, int> > verticalSegments = n       MakeAnswerSegments(U, xyPoints, 0); n   PrintAnswerSegments(horizontalSegments); n   PrintAnswerSegments(verticalSegments); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long linf = 1e18 + 9; n const int inf = 1e9 + 9; n const int N = 2e5 + 9; n int n, q, l[N], r[N], a[N], wh[N]; n long long bit[N], ans[N]; n vector<int> h[N]; n vector<pair<int, int> > Q[N]; n void update(int t) { n   t++; n   while (t <= n + 1) { n     bit[t]++; n     t += (t & -t); n   } n } n long long query(int t) { n   long long sum = 0; n   t++; n   while (t > 0) { n     sum += bit[t]; n     t -= (t & -t); n   } n   return sum; n } n int main() { n   scanf( %d %d , &n, &q); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     wh[a[i]] = i; n   } n   for (int i = 1; i <= q; i++) { n     scanf( %d %d , &l[i], &r[i]); n     Q[r[i]].push_back(make_pair(l[i], i)); n   } n   for (int i = 1; i <= n; i++) { n     for (int j = i; j <= n; j += i) { n       h[j].push_back(i); n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < h[a[i]].size(); j++) { n       if (wh[h[a[i]][j]] <= i) { n         update(wh[h[a[i]][j]]); n       } n     } n     for (int j = a[i] * 2; j <= n; j += a[i]) { n       if (wh[j] < i) { n         update(wh[j]); n       } n     } n     for (int j = 0; j < Q[i].size(); j++) { n       ans[Q[i][j].second] += query(i) - query(Q[i][j].first - 1); n     } n   } n   for (int i = 1; i <= q; i++) { n     printf( %lld n , ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   cin.tie(nullptr)->sync_with_stdio(false); n   long long t; n   cin >> t; n   while (t--) { n     long long n, a, b, da, db; n     cin >> n >> a >> b >> da >> db; n     vector<vector<long long>> adj(n + 1); n     for (long long i = 0; i < n - 1; i++) { n       long long x, y; n       cin >> x >> y; n       adj[x].push_back(y); n       adj[y].push_back(x); n     } n     if (true) { n       vector<bool> vis(n + 1); n       vector<long long> dis(n + 1); n       queue<long long> q; n       q.push(a); n       vis[a] = true; n       while (!q.empty()) { n         long long cur = q.front(); n         q.pop(); n         for (long long nxt : adj[cur]) { n           if (!vis[nxt]) { n             vis[nxt] = true; n             dis[nxt] = dis[cur] + 1; n             q.push(nxt); n           } n         } n       } n       if (dis[b] <= da) { n         cout <<  Alice n ; n         continue; n       } n     } n     if (true) { n       long long start = 0; n       if (true) { n         vector<bool> vis(n + 1); n         vector<long long> dis(n + 1); n         queue<long long> q; n         q.push(a); n         vis[a] = true; n         while (!q.empty()) { n           long long cur = q.front(); n           q.pop(); n           for (long long nxt : adj[cur]) { n             if (!vis[nxt]) { n               vis[nxt] = true; n               dis[nxt] = dis[cur] + 1; n               q.push(nxt); n             } n           } n         } n         long long mx = 0; n         for (long long i = 1; i <= n; i++) { n           if (dis[i] > mx) { n             mx = dis[i]; n             start = i; n           } n         } n       } n       if (true) { n         vector<bool> vis(n + 1); n         vector<long long> dis(n + 1); n         queue<long long> q; n         q.push(start); n         vis[start] = true; n         while (!q.empty()) { n           long long cur = q.front(); n           q.pop(); n           for (long long nxt : adj[cur]) { n             if (!vis[nxt]) { n               vis[nxt] = true; n               dis[nxt] = dis[cur] + 1; n               q.push(nxt); n             } n           } n         } n         long long dia = 0; n         for (long long i = 1; i <= n; i++) { n           dia = max(dia, dis[i]); n         } n         if (da * 2 >= dia) { n           cout <<  Alice n ; n           continue; n         } n       } n     } n     if (da * 2 < db) { n       cout <<  Bob n ; n     } else { n       cout <<  Alice n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long p, d; n   while (scanf( %I64d%I64d , &p, &d) != EOF) { n     long long ans = ++p; n     for (long long i = 10;; i *= 10) { n       if (p % i > d) break; n       ans = p - p % i; n     } n     printf( %I64d n , ans - 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   if (s.find( 0 ) != string::npos) { n     s.erase(s.find( 0 ), 1); n   } else { n     s.erase(s.size() - 1, 1); n   } n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   int d = 0, tot = 0, c; n   bool flag = false; n   for (int i = 0; i < n; i++) { n     cin >> c; n     tot = tot + c; n     if (tot >= 8 && flag == false) { n       k = k - 8; n       tot = tot - 8; n       d++; n       if (k <= 0) flag = true; n     } else if (tot < 8 && flag == false) { n       k = k - tot; n       tot = 0; n       d++; n       if (k <= 0) flag = true; n     } n   } n   if (flag == true) { n     cout << d << endl; n   } else { n     cout << -1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, sum = 0, minodd = 101, i; n   scanf( %d , &n); n   for (; n > 0; --n) { n     scanf( %d , &i); n     if (minodd > i && i % 2) { n       minodd = i; n     } n     sum += i; n   } n   if (minodd == 101) n     printf( 0 ); n   else if (sum % 2) n     printf( %d , sum); n   else n     printf( %d , sum - minodd); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, t, m; n   cin >> t; n   while (t--) { n     cin >> n; n     int i; n     int a[n], b[n]; n     for (i = 0; i < n; i++) { n       cin >> a[i]; n     } n     int f = 0; n     for (i = 0; i < n; i++) { n       cin >> b[i]; n     } n     int p = 0, v = 0; n     for (i = 0; i < n; i++) { n       if (a[i] < b[i]) { n         p = i; n         v = b[i] - a[i]; n         break; n       } n       if (a[i] > b[i]) { n         f = 1; n         cout <<  NO  << endl; n         break; n       } n     } n     if (f == 1) { n       continue; n     } n     for (i = p; i < n; i++) { n       if (a[i] < b[i]) { n         if ((b[i] - a[i]) != v) { n           f = 1; n           cout <<  NO  << endl; n           break; n         } n       } else if (a[i] > b[i]) { n         f = 1; n         cout <<  NO  << endl; n         break; n       } else { n         p = i; n         break; n       } n     } n     if (f == 1) continue; n     if (f == 0 && i == n) { n       cout <<  YES  << endl; n       continue; n     } n     for (i = p; i < n; i++) { n       if (a[i] != b[i]) { n         f = 1; n         cout <<  NO  << endl; n         break; n       } n     } n     if (f == 0) cout <<  YES  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2000; n int cubeta[MAXN + 2]; n int color; n int arr[MAXN + 2]; n void mapea(int n) { n   set<int> nums; n   for (int i = 1; i <= n; i++) nums.insert(arr[i]); n   map<int, int> val; n   int cnt = 1; n   set<int>::iterator it = nums.begin(); n   while (it != nums.end()) { n     val[*it] = cnt; n     cnt++; n     it++; n   } n   for (int i = 1; i <= n; i++) arr[i] = val[arr[i]]; n } n int busca(int l, int n) { n   int r = n; n   while (r > l && cubeta[arr[r]] != color) { n     cubeta[arr[r]] = color; n     r--; n   } n   return r + 1; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> arr[i]; n   mapea(n); n   int resp = n; n   for (int l = 0; l <= n; l++) { n     color++; n     bool continuar = true; n     for (int i = 1; i <= l; i++) { n       if (cubeta[arr[i]] == color) continuar = false; n       cubeta[arr[i]] = color; n     } n     if (!continuar) break; n     int r = busca(l, n); n     resp = min(resp, r - l - 1); n   } n   cout << resp <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int res = -1; n   for (int i = 1; i < s.size(); i++) { n     for (int j = 1; i + j < s.size(); j++) { n       int p1; n       string P1 = s.substr(0, i); n       if (P1.size() > 1 && P1[0] ==  0 ) n         p1 = -1; n       else if (P1.size() >= 7 && P1 !=  1000000 ) n         p1 = -1; n       else n         istringstream(P1) >> p1; n       int p2; n       string P2 = s.substr(i, j); n       if (P2.size() > 1 && P2[0] ==  0 ) n         p2 = -1; n       else if (P2.size() >= 7 && P2 !=  1000000 ) n         p2 = -1; n       else n         istringstream(P2) >> p2; n       int p3; n       string P3 = s.substr(i + j, s.size()); n       if (P3.size() > 1 && P3[0] ==  0 ) n         p3 = -1; n       else if (P3.size() >= 7 && P3 !=  1000000 ) n         p3 = -1; n       else n         istringstream(P3) >> p3; n       if (p1 == -1 || p2 == -1 || p3 == -1) continue; n       res = max(res, p1 + p2 + p3); n     } n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using LL = long long; n using PII = pair<int, int>; n int main() { n   auto get_factors = [](int n) { n     vector<int> ret; n     for (int i = 1; i * i <= n; i++) { n       if (n % i == 0) { n         ret.push_back(i); n         if (i * i != n) ret.push_back(n / i); n       } n     } n     sort(ret.begin(), ret.end()); n     return ret; n   }; n   vector<vector<int>> factors(1e5 + 1); n   for (int i = (1); i <= (1e5); ++i) factors[i] = get_factors(i); n   ios::sync_with_stdio(false); n   int tc; n   cin >> tc; n   while (tc--) { n     int x[3], cnt[8] = {0}; n     cin >> x[0] >> x[1] >> x[2]; n     vector<int> v; n     for (int i = 0; i < 3; i++) { n       for (auto val : factors[x[i]]) v.push_back(val); n     } n     sort(v.begin(), v.end()); n     v.erase(unique(v.begin(), v.end()), v.end()); n     for (auto val : v) { n       int mask = 0; n       for (int i = 0; i < 3; i++) { n         if (x[i] % val == 0) mask |= 1 << i; n       } n       cnt[mask]++; n     } n     int ans = 0; n     for (int a = 1; a < 8; a++) { n       for (int b = a; b < 8; b++) { n         int t1 = a | b; n         if (t1 == (t1 & -t1)) continue; n         for (int c = b; c < 8; c++) { n           int t2 = a | c, t3 = b | c; n           if (t2 == (t2 & -t2)) continue; n           if (t3 == (t3 & -t3)) continue; n           if ((a | b | c) != 7) continue; n           if (a != b && a != c && b != c) { n             ans += cnt[a] * cnt[b] * cnt[c]; n           } else if (a == b && b == c) { n             int n = cnt[a] + 2; n             ans += n * (n - 1) * (n - 2) / 6; n           } else if (a == b) { n             ans += cnt[a] * (cnt[a] + 1) / 2 * cnt[c]; n           } else if (a == c) { n             ans += cnt[a] * (cnt[a] + 1) / 2 * cnt[b]; n           } else if (b == c) { n             ans += cnt[b] * (cnt[b] + 1) / 2 * cnt[a]; n           } n         } n       } n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, i, name[100], cnt; n   string str; n   char ch; n   cin >> n >> k; n   cnt = 0; n   for (i = 1; i <= k - 1; i++) { n     name[i] = ++cnt; n   } n   for (i = k; i <= n; i++) { n     cin >> str; n     if (str[0] ==  N ) { n       name[i] = name[i - k + 1]; n     } else { n       name[i] = ++cnt; n     } n   } n   for (i = 1; i <= n; i++) { n     if (name[i] <= 26) { n       ch = ( A  - 1) + name[i]; n       str = ch; n     } else { n       ch = ( a ) + name[i] - 26; n       str =  A ; n       str = str + ch; n     } n     cout << str <<    ; n   } n } n