#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 6;   vector<int> num, low, S, vis;   int cntr, numCC;   int par[N];   vector<int> adj[N];   void tarjanSCC(int v) {     low[v] = num[v] = ++cntr;     vis[v] = 1;     S.push_back(v);     for (auto u : adj[v]) {       if (num[u] == -1) tarjanSCC(u);       if (vis[u]) low[v] = min(low[v], low[u]);     }     if (low[v] == num[v]) {       while (1) {         int u = S.back();         S.pop_back();         vis[u] = 0;         par[u] = numCC;         if (u == v) break;       }       numCC++;     }   }   int u[N], v[N], w[N];   vector<pair<int, long long>> edge[N];   long long gain[N], del[N];   long long sum(long long n) { return n * (n + 1) / 2; }   long long get(int c) {     long long l = 0, r = c;     while (l < r) {       long long mid = (l + r + 1) >> 1;       if (sum(mid) <= c) {         l = mid;       } else {         r = mid - 1;       }     }     return 1LL * c * (l + 1) - del[l];   }   long long dp[N];   long long dfs(int now) {     if (dp[now] != -1) return dp[now];     long long best = 0;     for (auto it : edge[now]) {       best = max(best, dfs(it.first) + it.second);     }     return dp[now] = best + gain[now];   }   int main() {     for (int i = 1; i < N; i++) del[i] = del[i - 1] + sum(i);     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d %d %d , u + i, v + i, w + i);       adj[u[i]].push_back(v[i]);     }     int s;     scanf( %d , &s);     num.assign(n + 1, -1);     low.assign(n + 1, 0);     vis.assign(n + 1, 0);     cntr = numCC = 0;     for (int i = 1; i <= n; i++)       if (num[i] == -1) tarjanSCC(i);     for (int i = 0; i < m; i++) {       int a = par[u[i]];       int b = par[v[i]];       if (a == b) {         gain[a] += get(w[i]);       } else {         edge[a].emplace_back(b, w[i]);       }     }     memset(dp, -1, sizeof(dp));     cout << dfs(par[s]) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   template <typename T, typename U>   std::istream& operator>>(std::istream& i, pair<T, U>& p) {     i >> p.first >> p.second;     return i;   }   template <typename T>   std::istream& operator>>(std::istream& i, vector<T>& t) {     for (auto& v : t) {       i >> v;     }     return i;   }   template <typename T, typename U>   std::ostream& operator<<(std::ostream& o, const pair<T, U>& p) {     o << p.first <<     << p.second;     return o;   }   template <typename T>   std::ostream& operator<<(std::ostream& o, const vector<T>& t) {     if (t.empty()) o <<   n ;     for (size_t i = 0; i < t.size(); ++i) {       o << t[i] <<    n [i == t.size() - 1];     }     return o;   }   template <typename T>   using minheap = priority_queue<T, vector<T>, greater<T>>;   template <typename T>   using maxheap = priority_queue<T, vector<T>, less<T>>;   template <typename T>   bool in(T a, T b, T c) {     return a <= b && b < c;   }   unsigned int logceil(int x) {     return (unsigned int)(8 * sizeof(int) - __builtin_clz(x));   }   namespace std {   template <typename T, typename U>   struct hash<pair<T, U>> {     hash<T> t;     hash<U> u;     size_t operator()(const pair<T, U>& p) const {       return t(p.x) ^ (u(p.y) << 7);     }   };   }  // namespace std   template <typename T>   T gcd(T a, T b) {     if (a < b) swap(a, b);     return b ? gcd(b, a % b) : a;   }   template <typename T>   class vector2 : public vector<vector<T>> {    public:     vector2() {}     vector2(size_t a, size_t b, T t = T())         : vector<vector<T>>(a, vector<T>(b, t)) {}   };   template <typename T>   class vector3 : public vector<vector2<T>> {    public:     vector3() {}     vector3(size_t a, size_t b, size_t c, T t = T())         : vector<vector2<T>>(a, vector2<T>(b, c, t)) {}   };   template <typename T>   class vector4 : public vector<vector3<T>> {    public:     vector4() {}     vector4(size_t a, size_t b, size_t c, size_t d, T t = T())         : vector<vector3<T>>(a, vector3<T>(b, c, d, t)) {}   };   template <typename T>   class vector5 : public vector<vector4<T>> {    public:     vector5() {}     vector5(size_t a, size_t b, size_t c, size_t d, size_t e, T t = T())         : vector<vector4<T>>(a, vector4<T>(b, c, d, e, t)) {}   };   void fastIO() { ios::sync_with_stdio(false); }   template <typename T, typename... Args>   T max(T t, Args... args) {     return max(max<T>(args...), t);   }   template <typename T, typename... Args>   T min(T t, Args... args) {     return min(min<T>(args...), t);   }   using PLL = pair<long long, unsigned long long>;   class FFooFighters {    public:     void solve(std::istream& in, std::ostream& out) {       fastIO();       int n;       in >> n;       vector<PLL> a(n);       in >> a;       unsigned long long mb = 1;       unsigned long long res = 0;       long long ds = 0;       for (auto p : a) {         ds += p.first;       }       for (int i = 0; i < 64; ++i) {         long long cs = 0;         for (auto p : a) {           if (p.second >= mb && p.second < 2 * mb) {             ds += p.first;             long long nmask = p.second & res;             if (__builtin_popcountll(nmask) % 2 == 1)               cs -= p.first;             else               cs += p.first;           }         }         if (cs != 0 && signbit(ds) == signbit(cs)) {           res |= mb;         }         mb <<= 1;       }       out << res << endl;     }   };   int main() {     FFooFighters solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     solver.solve(in, out);     return 0;   }


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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