#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long int n, k; n   cin >> n >> k; n   long long int a[n], s = 0; n   vector<pair<long long int, long long int> > v; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] <= k) { n       v.push_back({a[i], i + 1}); n       s += a[i]; n     } n   } n   if (s < (k + 1) / 2) { n     cout << -1 << endl; n     return; n   } n   s = 0; n   sort(v.begin(), v.end()); n   vector<long long int> ans; n   for (int i = v.size() - 1; i >= 0; i--) { n     if (s + v[i].first >= (k + 1) / 2 and s + v[i].first <= k) { n       s += v[i].first; n       ans.push_back(v[i].second); n       break; n     } else if (s + v[i].first < (k + 1) / 2) { n       ans.push_back(v[i].second); n       s += v[i].first; n     } n   } n   if (ans.size() == 0) { n     cout << -1 << endl; n   } n   sort(ans.begin(), ans.end()); n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); i++) { n     cout << ans[i] <<    ; n   } n   cout << endl; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n const long long INF = 1e12; n const int MOD = 1e9 + 7; n const unsigned long long BIT_FLAG_0 = (1 << 0); n const unsigned long long BIT_FLAG_1 = (1 << 1); n const unsigned long long BIT_FLAG_2 = (1 << 2); n const unsigned long long BIT_FLAG_3 = (1 << 3); n const unsigned long long BIT_FLAG_4 = (1 << 4); n const unsigned long long BIT_FLAG_5 = (1 << 5); n const unsigned long long BIT_FLAG_6 = (1 << 6); n const unsigned long long BIT_FLAG_7 = (1 << 7); n const long long dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; n const long long Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, n                 Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; n void print() { cout <<   n ; } n template <class Head, class... Tail> n void print(Head &&head, Tail &&...tail) { n   cout << head; n   if (sizeof...(tail) != 0) cout <<    ; n   print(forward<Tail>(tail)...); n } n template <class T> n void print(vector<T> &vec) { n   for (auto &a : vec) { n     cout << a; n     if (&a != &vec.back()) cout <<    ; n   } n   cout <<   n ; n } n template <class T> n void print(set<T> &set) { n   for (auto &a : set) { n     cout << a <<    ; n   } n   cout <<   n ; n } n template <class T> n void print(vector<vector<T>> &df) { n   for (auto &vec : df) { n     print(vec); n   } n } n long long power(long long a, long long n) { n   long long res = 1; n   while (n > 0) { n     if (n & 1) res = res * a; n     a *= a; n     n >>= 1; n   } n   return res; n } n long long comb(long long n, long long k) { n   vector<vector<long long>> v(n + 1, vector<long long>(n + 1, 0)); n   for (long long i = 0; i < (long long)((v).size()); i++) { n     v[i][0] = 1; n     v[i][i] = 1; n   } n   for (long long k = 1; k < (long long)((v).size()); k++) { n     for (long long j = 1; j < k; j++) { n       v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]); n     } n   } n   return v[n][k]; n } n void add(long long &a, long long b) { n   a += b; n   if (a >= MOD) a -= MOD; n } n template <class T> n inline bool chmin(T &a, T b) { n   if (a > b) { n     a = b; n     return true; n   } n   return false; n } n template <class T> n inline bool chmax(T &a, T b) { n   if (a < b) { n     a = b; n     return true; n   } n   return false; n } n __attribute__((constructor)) void faster_io() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n } n long long n, k; n map<long long, long long> got; n pair<bool, multiset<long long>> isOK(long long idx) { n   multiset<long long> ans; n   multiset<long long> trueans; n   long long cnt = 0; n   for (const auto &[key, value] : got) { n     long long types = value / idx; n     cnt += types; n     for (long long ti = 0; ti < (long long)(types); ti++) { n       ans.insert(key); n     } n   } n   if (cnt >= k) { n     long long now = 0; n     for (auto i : ans) { n       trueans.insert(i); n       now++; n       if (now == k) { n         break; n       } n     } n     return make_pair(true, trueans); n   } else { n     return make_pair(false, trueans); n   } n } n multiset<long long> bin_search() { n   multiset<long long> finalans; n   long long ng = n + 1; n   long long ok = 0; n   while (abs(ok - ng) > 1) { n     long long mid = (ok + ng) / 2; n     long long bl = isOK(mid).first; n     auto nums = isOK(mid).second; n     if (bl) { n       ok = mid; n       finalans = nums; n     } else n       ng = mid; n   } n   return finalans; n } n signed main() { n   cin >> n >> k; n   vector<long long> A(n); n   for (long long ni = 0; ni < (long long)(n); ni++) { n     long long v; n     cin >> v; n     A[ni] = v; n     got[v]++; n   } n   auto ret = bin_search(); n   for (auto i : ret) { n     cout << i <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e6 + 5; n int main() { n   ios_base::sync_with_stdio(0); n   long long q; n   cin >> q; n   while (q--) { n     long long n; n     cin >> n; n     long long cnt = 0; n     long long flag = 1; n     while (n != 1) { n       if (n % 2 == 0) { n         n = n / 2; n         cnt++; n       } else if (n % 3 == 0) { n         n = (2 * n) / 3; n         cnt++; n       } else if (n % 5 == 0) { n         n = (4 * n) / 5; n         cnt++; n       } else { n         cout <<  -1  << endl; n         flag = 0; n         break; n       } n     } n     if (flag) cout << cnt << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x; n   while (cin >> x) { n     map<char, int> p1; n     string str, strr; n     ; n     bool l = 0; n     int sum; n     cin >> str; n     for (int i = 0; i < str.size(); i++) { n       p1[str[i]]++; n     } n     for (int i = 0; i < str.size(); i++) { n       if (p1[str[i]] % x != 0) { n         l = 1; n         break; n       } n     } n     if (l == 0) { n       for (char i =  a ; i <=  z ; i++) { n         sum = 0; n         if (p1[i] > 0) { n           sum = p1[i] / x; n         } n         while (sum--) { n           strr += i; n         } n       } n       while (x--) { n         cout << strr; n       } n     } else n       cout << -1; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200200; n const int mod = 1e9 + 7; n int n, a, b; n vector<int> q; n int main() { n   cin >> n >> a >> b; n   q.push_back(a); n   q.push_back(a); n   q.push_back(a); n   q.push_back(a); n   q.push_back(b); n   q.push_back(b); n   sort(q.begin(), q.end()); n   int res = 1e9; n   do { n     int ans = 1, cur = n; n     for (int i = 0; i < q.size(); ++i) n       if (cur - q[i] >= 0) n         cur -= q[i]; n       else n         ans++, cur = n - q[i]; n     res = min(res, ans); n   } while (next_permutation(q.begin(), q.end())); n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using lli = long long int; n lli mod = 1000000007.0; n int main(void) { n   long long t; n   cin >> t; n   lli x; n   lli n; n   while (t--) { n     cin >> n; n     x = 1; n     for (lli i = 2 * n; i >= 3; i--) { n       x *= i; n       x = x % mod; n     } n     cout << x << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, x[210], y[210], ans, dp[210][210]; n long long S[210][210]; n bool in[210][210][210]; n int gogo(int x) { n   if (x % n == 0) return n; n   return x % n; n } n long long cp(int a, int b, int c) { n   return 1LL * (x[a] - x[c]) * (y[b] - y[c]) - n          1LL * (y[a] - y[c]) * (x[b] - x[c]); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d%d , &x[i], &y[i]); n   for (int i = 1; i <= n; i++) n     for (int j = i; j <= n; j++) { n       for (int p = i + 1; p < j; p++) S[i][j] += cp(p, p + 1, i); n     } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j < i; j++) { n       for (int p = gogo(i + 1); p != j; p = gogo(p + 1)) n         S[i][j] += cp(gogo(p), gogo(p + 1), i); n     } n   for (int i = 1; i <= n; i++) n     for (int j = i + 1; j <= n; j++) n       for (int p = j + 1; p <= n; p++) n         if (abs(cp(j, p, i)) + abs(S[i][j]) + abs(S[j][p]) + abs(S[p][i]) == n                 abs(S[1][n]) && n             cp(j, p, i)) { n           in[i][j][p] = true; n         } n   for (int i = 1; i <= n; i++) dp[i][i + 1] = 1; n   for (int i = n; i; i--) n     for (int j = i + 1; j <= n; j++) n       for (int p = i + 1; p < j; p++) n         if (in[i][p][j]) n           dp[i][j] = (dp[i][j] + 1LL * dp[i][p] * dp[p][j]) % 1000000007; n   ans = dp[1][n]; n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int round_up(int i) { n   while (i & (i - 1)) { n     i = ((i - 1) | i) + 1; n   } n   return i; n } n class seg_t { n  public: n   vector<int> seg, ar; n   int n; n   seg_t(vector<int>& a) { n     n = a.size(); n     ar = a; n     int si = round_up(n); n     seg.resize(si * 2); n     build(0, 0, n - 1); n   } n   void build(int i, int l, int r) { n     if (l == r) { n       seg[i] = ar[l]; n       return; n     } n     int mid = (l + r) / 2; n     build(i * 2 + 1, l, mid); n     build(i * 2 + 2, mid + 1, r); n     seg[i] = min(seg[i * 2 + 1], seg[i * 2 + 2]); n   } n   int q(int i, int l, int r, int lind, int rind, int val) { n     if (r < lind || r > rind) { n       return -1; n     } n     if (l == r) { n       if (seg[i] >= val) return -1; n       return l; n     } n     if (lind <= l && r <= rind) { n       if (seg[i] >= val) return -1; n     } n     int mid = (l + r) / 2; n     int t = q(i * 2 + 1, l, mid, lind, rind, val); n     if (t >= 0) return t; n     return q(i * 2 + 2, mid + 1, r, lind, rind, val); n   } n   int qq(int i, int l, int r, int lind, int rind) { n     if (r < lind || r > rind) { n       return 1000000000; n     } n     if (lind <= l && r <= rind) { n       return seg[i]; n     } n     int mid = (l + r) / 2; n     return min(qq(i * 2 + 1, l, mid, lind, rind), n                qq(i * 2 + 2, mid + 1, r, lind, rind)); n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   vector<int> a(2 * n); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     a[i + n] = a[i]; n   } n   seg_t t(a); n   vector<int> b(2 * n); n   for (int i = 0; i < n; i++) { n     int tmp = t.q(0, 0, 2 * n - 1, i, n * 2 - 1, (a[i] + 1) / 2); n     if (tmp == -1) n       b[i] = 1000000000; n     else n       b[i] = tmp; n     b[i + n] = b[i] + n; n   } n   seg_t tt(b); n   for (int i = 0; i < n; i++) { n     int tmp = tt.qq(0, 0, 2 * n - 1, i, n * 2 - 1); n     if (tmp >= 1000000000) n       cout << -1 <<    ; n     else n       cout << tmp - i <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using pii = pair<int, int>; n int const N = 1e5 + 20, MAX = 7000 + 20; n int n, q; n bitset<MAX> bt[N]; n int a[MAX]; n vector<int> dv[MAX]; n bitset<MAX> save[MAX]; n void pre() { n   a[1] = 1; n   for (int i = 1; i < MAX; i++) { n     for (int j = 2 * i; j < MAX; j += i) a[j] ^= a[i], dv[j].push_back(i); n     dv[i].push_back(i); n   } n   for (int i = 1; i < MAX; i++) { n     for (int j = 1; i * j < MAX; j++) { n       if (a[j]) save[i][i * j] = 1; n     } n   } n } n int main() { n   pre(); n   scanf( %d %d  , &n, &q); n   while (q--) { n     int tp, x, y, z, v; n     scanf( %d  , &tp); n     if (tp == 1) { n       scanf( %d %d  , &x, &v); n       x--; n       bt[x].reset(); n       for (int u : dv[v]) bt[x][u] = 1; n     } else if (tp == 2) { n       scanf( %d %d %d  , &x, &y, &z); n       x--, y--, z--; n       bt[x] = (bt[y] ^ bt[z]); n     } else if (tp == 3) { n       scanf( %d %d %d  , &x, &y, &z); n       x--, y--, z--; n       bt[x] = (bt[y] & bt[z]); n     } else if (tp == 4) { n       scanf( %d %d  , &x, &v); n       x--; n       bitset<MAX> tmp = (bt[x] & save[v]); n       putchar( 0  + (tmp.count() & 1)); n     } n   } n   putchar(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int k; n vector<pair<long double, long double> > vp; n const long double PI = 2 * acos(0.0); n bool check(long double r) { n   vector<pair<long double, int> > events; n   for (int i = 0; i < n; ++i) { n     long double ang = atan2(vp[i].second, vp[i].first); n     long double d = n         sqrt(vp[i].first * vp[i].first + vp[i].second * vp[i].second); n     if (d > 2 * r) continue; n     long double alph = (PI - acos(1 - (d * d) / (2 * (r * r)))) / 2; n     long double ang_in = ang - alph; n     long double ang_out = ang + alph; n     if (ang_in < 0) { n       ang_in += 2 * PI; n       ang_out += 2 * PI; n     } n     events.emplace_back(ang_in, 1); n     events.emplace_back(ang_out, -1); n     events.emplace_back(ang_in + 2 * PI, 1); n     events.emplace_back(ang_out + 2 * PI, -1); n   } n   sort(events.begin(), events.end()); n   int ck = 0; n   for (int i = 0; i < (int)events.size(); ++i) { n     ck += events[i].second; n     if (ck >= k) return true; n   } n   return false; n } n int main() { n   cout.setf(ios::fixed); n   cout << setprecision(10); n   cin >> n; n   cin >> k; n   for (int i = 0; i < n; ++i) { n     int first, second; n     cin >> first >> second; n     vp.emplace_back(first, second); n   } n   long double l = 0; n   long double r = 2e5; n   while (r - l > 1e-6) { n     long double mid = (l + r) / 2; n     if (check(mid)) { n       r = mid; n     } else { n       l = mid; n     } n   } n   cout << l << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int a[] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; n const int Q = 1e9 + 7; n int main() { n   string s, t; n   cin >> s >> t; n   vector<int> p(t.length()); n   for (int i = 1; i < t.length(); ++i) { n     int k = p[i - 1]; n     while (k > 0) { n       if (t[k] == t[i]) { n         p[i] = k + 1; n         break; n       } n       k = p[k - 1]; n     } n     if (!p[i] && t[i] == t[0]) p[i] = 1; n   } n   vector<int> x(s.length()); n   if (s[0] == t[0]) x[0] = 1; n   for (int i = 1; i < s.length(); ++i) { n     int k = x[i - 1]; n     if (k == t.length()) k = p[k - 1]; n     while (k > 0) { n       if (s[i] == t[k]) { n         x[i] = k + 1; n         break; n       } n       k = p[k - 1]; n     } n     if (!x[i] && s[i] == t[0]) x[i] = 1; n   } n   vector<int> sum(s.length() + 1), r(s.length() + 1), h(s.length() + 1); n   sum[0] = 0; n   h[0] = 0; n   for (int i = 0; i < s.length(); ++i) { n     if (x[i] == t.length()) { n       r[i + 1] = (h[i - t.length() + 1] + i - t.length() + 2) % Q; n     } else { n       r[i + 1] = r[i]; n     } n     sum[i + 1] = (sum[i] + r[i + 1]) % Q; n     h[i + 1] = (h[i] + sum[i + 1]) % Q; n   } n   cout << sum[s.length()]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long check(long long x) { n   long long i = 0, ans = 0; n   while (x > 0) { n     if ((x & (1)) == 1) { n       ans = max(ans, i); n     } n     x = x >> 1; n     i++; n   } n   return ans; n } n void solve() { n   long long n; n   cin >> n; n   long long a[n + 1]; n   map<long long, long long> mp; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     mp[check(a[i])]++; n   } n   long long ans = 0; n   for (auto x : mp) { n     if (x.second > 1) ans += ((x.second) * (x.second - 1)) / 2; n   } n   cout << ans << endl; n   return; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int cnt = 0; n vector<int> ans; n vector<vector<int> > adj; n void dfs(int u, int col) { n   if (ans[u] != -1) return; n   ans[u] = col; n   for (int i = 0; i < adj[u].size(); ++i) dfs(adj[u][i], col); n } n char conv(int first) { n   if (first == 0) return  b ; n   if (first == 1) return  a ; n   if (first == 2) return  c ; n } n int main() { n   cout.setf(ios::fixed); n   cout.precision(7); n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n, m; n   cin >> n >> m; n   adj = vector<vector<int> >(n); n   vector<int> deg(n, 0); n   for (int asdf = 0; asdf < m; ++asdf) { n     int first, second; n     cin >> first >> second; n     --first; n     --second; n     adj[first].push_back(second); n     adj[second].push_back(first); n     ++deg[first]; n     ++deg[second]; n   } n   ans = vector<int>(n, -1); n   int qt = 0; n   for (int i = 0; i < n; ++i) n     if (deg[i] == n - 1) { n       ans[i] = 0; n       ++qt; n     } n   for (int i = 0; i < n; ++i) n     if (ans[i] == -1) { n       ++cnt; n       dfs(i, cnt); n     } n   bool ok = true; n   if (cnt >= 3) ok = false; n   int n1 = 0, m1 = 0, n2 = 0, m2 = 0; n   for (int i = 0; i < n; ++i) { n     if (ans[i] == 1) { n       ++n1; n       m1 += deg[i] - qt; n     } else if (ans[i] == 2) { n       ++n2; n       m2 += deg[i] - qt; n     } n   } n   if (n1 * (n1 - 1) != m1) ok = false; n   if (n2 * (n2 - 1) != m2) ok = false; n   if (not ok) n     cout <<  No n ; n   else { n     cout <<  Yes n ; n     for (int i = 0; i < n; ++i) cout << conv(ans[i]); n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n typedef std::function<long long(long long)> fun; n class Map { n   int n, w, r; n   std::vector<int> A, B; n   std::function<int(long long)> lower, upper; n   std::vector<long long> who; n   std::vector<int> val; n   void find_array(std::vector<int> &a, const std::vector<long long> &S, fun f, n                   fun g) { n     a.resize(1 << r); n     std::vector<std::list<long long> > set(1 << r); n     std::vector<int> m(1 << (r + 1)); n     std::vector<int> ind; n     for (long long x : S) { n       if (set[f(x)].empty()) ind.push_back(f(x)); n       set[f(x)].push_back(x); n     } n     std::sort(ind.begin(), ind.end(), n               [&](int x, int y) { return set[x].size() > set[y].size(); }); n     for (int i : ind) { n       a[i] = 0; n       for (int j = 0; j < r; ++j) { n         int ex0 = 0, ex1 = 0; n         for (long long y : set[i]) n           ex0 += m[(1 << (j + 1)) + ((y & ((1 << (j + 1)) - 1)) ^ a[i])], n               ex1 += m[(1 << (j + 1)) + n                        ((y & ((1 << (j + 1)) - 1)) ^ (a[i] | (1 << j)))]; n         if (ex1 < ex0) a[i] |= (1 << j); n       } n       for (long long y : set[i]) { n         int v = (g(y) ^ a[i]); n         for (int j = 0; j < r; ++j) n           m[(1 << (r - j)) + v]++, v = v & ((1 << (r - 1 - j)) - 1); n       } n     } n   } n  n  public: n   Map() {} n   Map(const std::vector<long long> &S, int word) { init(S, word); } n   int operator()(long long x) { return lower(x) ^ B[upper(x) ^ A[lower(x)]]; } n   int size() { return (1 << r); } n   bool have(long long x) { return who[(*this)(x)] == x; } n   int &operator[](long long i) { return val[(*this)(i)]; } n   void init(const std::vector<long long> &S, int word) { n     n = (int)S.size(); n     w = word; n     r = std::max(w / 2, (int)std::log2(n) + 3) + 1; n     assert(*std::min_element(S.begin(), S.end()) >= 0); n     assert(*std::max_element(S.begin(), S.end()) < (1ll << word)); n     lower = [&](long long x) { return x & ((1 << r) - 1); }; n     upper = [&](long long x) { return x >> (w - r); }; n     find_array(A, S, lower, upper); n     auto f2 = [&](long long x) { return upper(x) ^ A[lower(x)]; }; n     auto &g2 = lower; n     find_array(B, S, f2, g2); n     who.resize(1 << r, -1); n     for (long long x : S) who[(*this)(x)] = x; n     val.resize(1 << r); n   } n }; n void make_unique(std::vector<long long> &A) { n   std::sort(A.begin(), A.end()); n   A.resize(std::unique(A.begin(), A.end()) - A.begin()); n } n int main() { n   std::ios_base::sync_with_stdio(false); n   std::cin.tie(0); n   int n, k; n   std::cin >> n >> k; n   std::vector<int> A(n); n   long long pref = 0; n   std::vector<long long> values; n   values.push_back(pref); n   for (int i = 0; i < n; ++i) { n     std::cin >> A[i]; n     pref += A[i]; n     values.push_back(pref); n   } n   make_unique(values); n   long long min = *std::min_element(values.begin(), values.end()); n   std::vector<long long> lower, upper; n   for (long long x : values) n     lower.push_back((x - min) & ((1 << 24) - 1)), n         upper.push_back((x - min) >> 24); n   make_unique(lower); n   make_unique(upper); n   Map ml(lower, 24); n   Map mu(upper, 24); n   std::vector<long long> vals; n   auto kto = [&](long long x) { n     if (!ml.have((x - min) & ((1 << 24) - 1)) || !mu.have((x - min) >> 24)) n       return -1ll; n     return ml((x - min) & ((1 << 24) - 1)) + n            1ll * ml.size() * mu((x - min) >> 24); n   }; n   for (long long x : values) vals.push_back(kto(x)); n   make_unique(vals); n   Map map(vals, 40); n   long long ans = 0; n   pref = 0; n   map[kto(pref)]++; n   for (int i = 0; i < n; ++i) { n     pref += A[i]; n     long long pow = 1; n     while (std::abs(pow) < 1000000000ll * 100000ll + 5ll) { n       long long want = (pref - pow); n       if (want >= min && want <= min + (1ll << 48)) { n         if (kto(want) != -1 && map.have(kto(want))) { n           ans += map[kto(want)]; n         } n       } n       pow *= k; n       if (pow == 1) break; n     } n     map[kto(pref)]++; n   } n   std::cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, q, num, tot, tp, cnt, ans, w[200100], head[200100], dfn[200100], n     c[200100], low[200100], sta[200100]; n int dfc, sz[200100], d[200100], f[200100], son[200100], top[200100], n     tree[200100], mn[200100 * 4]; n vector<int> v[200100]; n multiset<int> s[200100]; n struct point { n   int fr, to, nxt; n } a[200100 * 2]; n void add(int x, int y) { n   a[++tot].fr = x; n   a[tot].to = y; n   a[tot].nxt = head[x]; n   head[x] = tot; n } n void tarjan(int x) { n   dfn[x] = low[x] = ++num; n   sta[++tp] = x; n   for (int i = 0; i < v[x].size(); i++) { n     int y = v[x][i]; n     if (!dfn[y]) { n       tarjan(y); n       low[x] = min(low[x], low[y]); n       if (low[y] == dfn[x]) { n         ++cnt; n         int now; n         do { n           now = sta[tp--]; n           add(cnt, now); n           add(now, cnt); n         } while (now != y); n         add(cnt, x); n         add(x, cnt); n       } n     } else n       low[x] = min(low[x], dfn[y]); n   } n } n void dfs1(int x, int fa) { n   f[x] = fa; n   d[x] = d[fa] + 1; n   sz[x] = 1; n   for (int i = head[x]; i; i = a[i].nxt) { n     int y = a[i].to; n     if (y == fa) continue; n     dfs1(y, x); n     sz[x] += sz[y]; n     if (sz[y] > sz[son[x]]) son[x] = y; n   } n } n void dfs2(int x, int lst) { n   top[x] = lst; n   dfn[x] = ++dfc; n   tree[dfc] = x; n   if (son[x]) dfs2(son[x], lst); n   for (int i = head[x]; i; i = a[i].nxt) n     if (!top[a[i].to]) dfs2(a[i].to, a[i].to); n } n void build(int x, int l, int r) { n   if (l == r) return mn[x] = w[tree[l]], void(); n   int mid = (l + r) >> 1; n   build(x << 1, l, mid); n   build(x << 1 | 1, mid + 1, r); n   mn[x] = min(mn[x << 1], mn[x << 1 | 1]); n } n void modify(int x, int l, int r, int p, int y) { n   if (l == r) return mn[x] = y, void(); n   int mid = (l + r) >> 1; n   if (p <= mid) n     modify(x << 1, l, mid, p, y); n   else n     modify(x << 1 | 1, mid + 1, r, p, y); n   mn[x] = min(mn[x << 1], mn[x << 1 | 1]); n } n int query(int x, int l, int r, int L, int R) { n   if (l >= L && r <= R) return mn[x]; n   int mid = (l + r) >> 1, ret = 1e9; n   if (L <= mid) ret = min(ret, query(x << 1, l, mid, L, R)); n   if (R > mid) ret = min(ret, query(x << 1 | 1, mid + 1, r, L, R)); n   return ret; n } n int query(int x, int y, int ret = 1e9) { n   while (top[x] != top[y]) { n     if (d[top[x]] < d[top[y]]) swap(x, y); n     ret = min(ret, query(1, 1, cnt, dfn[top[x]], dfn[x])); n     x = f[top[x]]; n   } n   if (d[x] < d[y]) swap(x, y); n   ret = min(ret, query(1, 1, cnt, dfn[y], dfn[x])); n   if (y > n) ret = min(ret, w[f[y]]); n   return ret; n } n int main() { n   scanf( %d%d%d , &n, &m, &q); n   cnt = n; n   for (int i = 1; i <= n; i++) scanf( %d , &w[i]); n   for (int i = 1, x, y; i <= m; i++) n     scanf( %d%d , &x, &y), v[x].push_back(y), v[y].push_back(x); n   tarjan(1); n   dfs1(1, 0); n   dfs2(1, 1); n   memset(mn, 0x3f, sizeof(mn)); n   for (int i = 1; i <= n; i++) s[f[i]].insert(w[i]); n   for (int i = n + 1; i <= cnt; i++) w[i] = (*s[i].begin()); n   build(1, 1, cnt); n   for (int i = 1; i <= q; i++) { n     char ch[4]; n     int a, b; n     scanf( %s%d%d , ch + 1, &a, &b); n     if (ch[1] ==  C ) { n       if (f[a]) { n         multiset<int>::iterator pos = s[f[a]].find(w[a]); n         s[f[a]].erase(pos); n         s[f[a]].insert(b); n         w[f[a]] = (*s[f[a]].begin()); n         modify(1, 1, cnt, dfn[f[a]], (*s[f[a]].begin())); n       } n       w[a] = b; n       modify(1, 1, cnt, dfn[a], w[a]); n     } else n       printf( %d n , query(a, b)); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int a[111][111]; n char c[111]; n int main() { n   int i, j, k; n   int p, q, r; n   int t, tt, ttt; n   scanf( %d , &n); n   for (i = 1; i <= n; i++) { n     scanf( %s , c); n     for (j = 1; j <= n; j++) { n       if (c[j - 1] ==  E ) n         a[i][j] = 1; n       else n         a[i][j] = 0; n     } n   } n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= n; j++) { n       if (a[i][j] == 0) break; n     } n     if (j == n + 1) break; n   } n   if (i != n + 1) { n     for (j = 1; j <= n; j++) { n       for (i = 1; i <= n; i++) { n         if (a[i][j] == 0) break; n       } n       if (i == n + 1) break; n     } n     if (j != n + 1) { n       printf( -1 ); n     } else { n       for (j = 1; j <= n; j++) { n         for (i = 1; i <= n; i++) { n           if (a[i][j] == 0) { n             printf( %d %d n , i, j); n             break; n           } n         } n       } n     } n   } else { n     for (i = 1; i <= n; i++) { n       for (j = 1; j <= n; j++) { n         if (a[i][j] == 0) { n           printf( %d %d n , i, j); n           break; n         } n       } n     } n   } n   scanf(   ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100001; n vector<int> v, w; n char s[1000001]; n int main() { n   scanf( %s , &s); n   int len = strlen(s); n   for (int i = (0); i < (len); i++) { n     if (s[i] ==  @ ) v.push_back(i); n     if (s[i] ==  . ) w.push_back(i); n   } n   int t = 0, tmp = 0; n   long long ans = 0; n   while (t < v.size() && tmp < w.size()) { n     long long first = 0, mid = 1, last = 0; n     if (t == v.size()) break; n     while (v[t] > w[tmp] && tmp < w.size()) tmp++; n     if (tmp == w.size()) break; n     if (v[t] + 1 == w[tmp]) mid = 0; n     for (int i = v[t] + 1; i < w[tmp]; i++) { n       if ((s[i] >  9  || s[i] <  0 ) && (s[i] >  z  || s[i] <  a )) { n         mid = 0; n         break; n       } n     } n     if (!mid) { n       t++; n       continue; n     } n     if (v[t] > 0) n       for (int i = v[t] - 1; i >= 0; i--) { n         if ((s[i] >=  a  && s[i] <=  z ) || (s[i] >=  0  && s[i] <=  9 ) || n             s[i] ==  _ ) { n           if (s[i] >=  a  && s[i] <=  z ) first++; n         } else n           break; n       } n     if (w[tmp] + 1 < len) n       for (int i = w[tmp] + 1; i < len; i++) { n         if (s[i] >=  a  && s[i] <=  z ) n           last++; n         else n           break; n       } n     ans += first * last; n     t++; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, c; n int ans[1001]; n int zero; n inline void send(int x, int p) { n   if (ans[x] == 0) --zero; n   ans[x] = p; n   printf( %d n , x); n   fflush(stdout); n } n int main() { n   scanf( %d %d %d , &n, &m, &c); n   int mid = (c + 1) / 2; n   zero = n; n   for (int round = 1; zero && round <= m; ++round) { n     int p; n     scanf( %d , &p); n     if (p <= mid) { n       int i; n       for (i = 1; i < n; ++i) n         if (ans[i] == 0 || ans[i] > p) { n           break; n         } n       send(i, p); n     } else { n       int i; n       for (i = n; i > 1; --i) n         if (ans[i] == 0 || ans[i] < p) { n           break; n         } n       send(i, p); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n const int INF = 1000000000; n const int MOD = 1073741824; n const int M = INF; n const double RRR = 180.0 / PI; n vector<vector<int> > g; n vector<bool> used; n void dfs(int v) { n   used[v] = 1; n   for (vector<int>::iterator it = g[v].begin(); it != g[v].end(); ++it) { n     if (!used[*it]) { n       dfs(*it); n     } n   } n } n int main() { n   int x, y; n   cin >> x >> y; n   int d1 = 1, d2 = 0; n   int e = 1; n   int f = 0; n   int a = 0, b = 0; n   int r = 0; n   int ans = 0; n   if (a == x && b == y) { n     cout << 0; n     return 0; n   } n   while (1) { n     a += d1; n     b += d2; n     r++; n     if (a == x && b == y) { n       cout << ans; n       return 0; n     } n     if (r == e) { n       ans++; n       if (f == 0) { n         f = 1; n         d1 = 0; n         d2 = 1; n         r = 0; n       } else { n         if (f == 1) { n           f = 2; n           e++; n           r = 0; n           d1 = -1; n           d2 = 0; n         } else { n           if (f == 2) { n             f = 3; n             r = 0; n             d1 = 0; n             d2 = -1; n           } else { n             f = 0; n             e++; n             r = 0; n             d1 = 1; n             d2 = 0; n           } n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mcd(long long a, long long b) { n   if (b > a) swap(a, b); n   if (b == 0) n     return a; n   else n     return mcd(b, a % b); n } n long long i, j, n, m, q, a, l, r, b; n int main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(0); n   cin >> q; n   while (q--) { n     cin >> n; n     if (n == 1) n       cout << 3; n     else if (n == 2) n       cout << 2; n     else if (n & 1) n       cout << 1; n     else n       cout << 0; n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long modulo = 998244353; n const long long p = modulo; n vector<int> edges[300005]; n int father[300005]; n long long rCount[300005]; n long long oCount[300005]; n long long eCount[300005]; n pair<int, int> gcd(long long a, long long b) { n   if (b == 0ll) return {1ll, 0ll}; n   pair<int, int> q = gcd(b, a % b); n   return {q.second, q.first - q.second * (a / b)}; n } n long long inv(long long a) { n   long long aa = gcd(a, p).first; n   aa %= p; n   if (aa < 0) aa += p; n   return aa; n } n void trace(int index) { n   for (int j = 0; j < edges[index].size(); ++j) { n     int v = edges[index][j]; n     if (v == father[index]) { n       edges[index].erase(edges[index].begin() + j); n       --j; n       continue; n     } n     father[v] = index; n     trace(v); n   } n } n void dfs(int index) { n   if (edges[index].empty()) { n     rCount[index] = 1; n     oCount[index] = 1; n     eCount[index] = 0; n     return; n   } n   long long totalR = 1; n   long long total = 1; n   for (int j = 0; j < edges[index].size(); ++j) { n     int v = edges[index][j]; n     dfs(v); n     totalR *= rCount[v]; n     totalR %= modulo; n     total *= rCount[v] + eCount[v]; n     total %= modulo; n   } n   rCount[index] = totalR; n   oCount[index] = 1; n   eCount[index] = 0; n   for (int j = 0; j < edges[index].size(); ++j) { n     int v = edges[index][j]; n     long long temp = oCount[v] * total; n     temp %= modulo; n     temp *= inv(rCount[v] + eCount[v]); n     temp %= modulo; n     rCount[index] += temp; n     rCount[index] %= modulo; n     oCount[index] *= (rCount[v] + eCount[v]); n     oCount[index] %= modulo; n     eCount[index] += temp; n     eCount[index] %= modulo; n   } n } n int main() { n   int n; n   cin >> n; n   if (n == 1) { n     cout << 1 << endl; n     return 0; n   } n   int u, v; n   for (int i = 0; i < n - 1; ++i) { n     scanf( %i%i , &u, &v); n     --u; n     --v; n     edges[u].push_back(v); n     edges[v].push_back(u); n   } n   for (int i = 0; i < n; ++i) { n     father[i] = -1; n     rCount[i] = 0; n     oCount[i] = 0; n     eCount[i] = 0; n   } n   father[0] = -1; n   trace(0); n   dfs(0); n   long long result = rCount[0]; n   while (result < 0) { n     result += modulo; n   } n   result %= modulo; n   cout << result << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = (int)1e2, maxM = (int)1e2, intMax = INT_MAX, maxValue = 44721; n const long long llmax = LLONG_MAX, INF = (long long)1e9 + 1, mod = 998244353; n long long nod(long long a, long long b) { n   while (a != 0 && b != 0) { n     if (a < b) n       b %= a; n     else n       a %= b; n   } n   return a + b; n } n int nod(int a, int b) { n   while (a != 0 && b != 0) { n     if (a < b) n       b %= a; n     else n       a %= b; n   } n   return a + b; n } n long long nok(long long a, long long b) { return a * b / nod(a, b); } n int nok(int a, int b) { return a * b / nod(a, b); } n long long modPlus(long long a, long long b) { n   a %= mod; n   b %= mod; n   return a + b; n } n long long modPlus(int a, int b) { n   a %= mod; n   b %= mod; n   return (a + b) % mod; n } n long long binPow(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b % 2 == 1) { n       res *= a; n       res %= mod; n     } n     a = a * a; n     a %= mod; n     b >>= 1; n   } n   return res; n } n int n, s, a, b, emaxx = -1; n int main() { n   scanf( %d%d , &n, &s); n   s *= 100; n   for (int i = 0; i < n; i++) { n     scanf( %d%d , &a, &b); n     b += a * 100; n     if (s >= b) emaxx = max((100 - (b % 100)) % 100, emaxx); n   } n   printf( %d n , emaxx); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int a, b, c; n     cin >> a >> b >> c; n     int diff = INT_MAX; n     int a1, b1, c1; n     for (int i = 1; i <= 10000; i++) { n       for (int j = i; j <= 20000; j += i) { n         for (int k = j; k <= 50000; k += j) { n           int dif = abs(a - i) + abs(b - j) + abs(c - k); n           if (dif < diff) { n             diff = dif; n             a1 = i; n             b1 = j; n             c1 = k; n           } n         } n       } n     } n     cout << diff << endl << a1 <<     << b1 <<     << c1 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, q; n int it[35][800005]; n struct point { n   int a[10]; n   point(){}; n   int &operator[](int x) { return a[x]; } n }; n point p[200005]; n int sign(point &p, int bit) { n   int ans = 0; n   for (int i = 0; i < k; i++) { n     if (bit & 1 == 1) { n       ans += p[i]; n     } else { n       ans -= p[i]; n     } n     bit >>= 1; n   } n   return ans; n } n void build(int id, int l, int r) { n   if (l == r - 1) { n     for (int i = 0; i < (1 << k); i++) { n       it[i][id] = sign(p[l], i); n     } n     return; n   } n   int mid = (l + r) / 2; n   build(id * 2, l, mid); n   build(id * 2 + 1, mid, r); n   for (int i = 0; i < (1 << k); i++) { n     it[i][id] = min(it[i][id * 2], it[i][id * 2 + 1]); n   } n } n void update(int id, int l, int r, int pos, point &val) { n   if (l == r - 1) { n     for (int i = 0; i < (1 << k); i++) { n       it[i][id] = sign(val, i); n     } n     return; n   } n   int mid = (l + r) / 2; n   if (pos < mid) { n     update(id * 2, l, mid, pos, val); n   } else { n     update(id * 2 + 1, mid, r, pos, val); n   } n   for (int i = 0; i < (1 << k); i++) { n     it[i][id] = min(it[i][id * 2], it[i][id * 2 + 1]); n   } n } n int chosen[35]; n void get(int id, int l, int r, int a, int b) { n   if (a >= b) return; n   if (l == a && r == b) { n     for (int i = 0; i < (1 << k); i++) { n       chosen[i] = min(chosen[i], it[i][id]); n     } n     return; n   } n   int mid = (l + r) / 2; n   get(id * 2, l, mid, a, min(mid, b)); n   get(id * 2 + 1, mid, r, max(mid, a), b); n } n int main() { n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < k; j++) { n       cin >> p[i][j]; n     } n   } n   build(1, 0, n); n   cin >> q; n   while (q--) { n     int t; n     cin >> t; n     if (t == 1) { n       int x; n       cin >> x; n       x--; n       point cnt; n       for (int i = 0; i < k; i++) { n         cin >> cnt[i]; n       } n       update(1, 0, n, x, cnt); n     } n     if (t == 2) { n       int l, r; n       cin >> l >> r; n       l--; n       for (int i = 0; i < (1 << k); i++) { n         chosen[i] = 1e9; n       } n       get(1, 0, n, l, r); n       int res = 0; n       for (int i = 0; i < (1 << k); i++) { n         res = max(res, abs(chosen[(1 << k) - i - 1] + chosen[i])); n       } n       cout << res << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n int N; n int X[206], Y[206]; n int D[202][202]; n long long area(int i1, int i2, int i3) { n   return 1LL * X[i1] * Y[i2] + 1LL * X[i2] * Y[i3] + 1LL * X[i3] * Y[i1] - n          1LL * Y[i1] * X[i2] - 1LL * Y[i2] * X[i3] - 1LL * Y[i3] * X[i1]; n } n int sign(int i1, int i2, int i3) { n   long long val = area(i1, i2, i3); n   if (val < 0) return -1; n   if (val > 0) return 1; n   return 0; n } n bool inpoly(int x, int y) { n   int pnx = 1e9 + 7, pny = 1e9 + 9; n   X[N + 2] = x; n   Y[N + 2] = y; n   X[N + 3] = pnx; n   Y[N + 3] = pny; n   for (int i = 1; i <= N + 1; ++i) { n     X[i] *= 2; n     Y[i] *= 2; n   } n   int nn = 0; n   for (int i = 1; i <= N; ++i) n     if (sign(N + 2, N + 3, i) * sign(N + 2, N + 3, i + 1) == -1 && n         sign(i, i + 1, N + 2) * sign(i, i + 1, N + 3) == -1) n       ++nn; n   for (int i = 1; i <= N + 1; ++i) { n     X[i] /= 2; n     Y[i] /= 2; n   } n   return (nn % 2); n } n bool isok(int i1, int i2) { n   if (i1 + 1 == i2 || (i2 == N && i1 == 1)) return true; n   for (int i = 1; i <= N; ++i) n     if (i != i1 && i != i2) { n       if (X[i] < min(X[i1], X[i2]) || X[i] > max(X[i1], X[i2])) continue; n       if (Y[i] < min(Y[i1], Y[i2]) || Y[i] > max(Y[i1], Y[i2])) continue; n       if (1LL * (Y[i] - Y[i1]) * (X[i2] - X[i]) == n           1LL * (Y[i2] - Y[i]) * (X[i] - X[i1])) n         return false; n     } n   for (int i = 1; i <= N; ++i) n     if (i != i1 && i + 1 != i1 && (i + 1) % N != i1) n       if (i != i2 && i + 1 != i2 && (i + 1) % N != i2) { n         int p1 = i, p2 = i + 1; n         if (sign(i1, i2, p1) * sign(i1, i2, p2) == -1 && n             sign(p1, p2, i1) * sign(p1, p2, i2) == -1) n           return false; n       } n   int xn = X[i1] + X[i2]; n   int yn = Y[i1] + Y[i2]; n   if (!inpoly(xn, yn)) return false; n   return true; n } n int ways(int i1, int i2) { n   if (D[i1][i2] != -1) return D[i1][i2]; n   if (i1 + 1 == i2) return 1; n   int& now = D[i1][i2]; n   now = 0; n   if (!isok(i1, i2)) return now; n   for (int k = i1 + 1; k <= i2 - 1; ++k) n     now = (now + 1LL * ways(i1, k) * ways(k, i2)) % MOD; n   return now; n } n int main() { n   cin.sync_with_stdio(false); n   cin >> N; n   for (int i = 1; i <= N; ++i) cin >> X[i] >> Y[i]; n   X[N + 1] = X[1]; n   Y[N + 1] = Y[1]; n   memset(D, -1, sizeof(D)); n   cout << ways(1, N) <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 10; n struct Node { n   int a, b, d; n } p[MAXN]; n int n, k; n bool cmp(Node aa, Node bb) { return aa.d < bb.d; } n bool cmp2(Node aa, Node bb) { return aa.d > bb.d; } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %d , &p[i].a); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &p[i].b); n     p[i].d = p[i].a - p[i].b; n   } n   long long ans = 0; n   sort(p + 1, p + 1 + n, cmp); n   if (p[1].d >= 0) { n     for (int i = 1; i <= k; i++) ans += (long long)p[i].a; n     for (int i = k + 1; i <= n; i++) ans += (long long)p[i].b; n   } else if (p[n].d <= 0) { n     sort(p + 1, p + 1 + n, cmp2); n     for (int i = 1; i <= n; i++) { n       ans += (long long)p[i].a; n     } n   } else { n     if (p[k].d <= 0) { n       for (int i = 1; i <= n; i++) { n         if (p[i].d <= 0) n           ans += (long long)p[i].a; n         else n           ans += (long long)p[i].b; n       } n     } else { n       int tmp = 0; n       for (int i = 1; i <= n; i++) { n         if (p[i].d <= 0) { n           ans += (long long)p[i].a; n         } else { n           tmp = i; n           break; n         } n       } n       sort(p + tmp, p + 1 + k, cmp2); n       for (int i = tmp; i <= k; i++) { n         ans += (long long)p[i].a; n       } n       for (int i = k + 1; i <= n; i++) { n         ans += (long long)p[i].b; n       } n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   vector<long long> dp; n   dp.push_back(0); n   dp.push_back(1); n   while (dp.back() <= n - 1) { n     dp.push_back(dp[dp.size() - 1] + dp[dp.size() - 2] + 1); n   } n   cout << dp.size() - 2 << endl; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ,  unroll-loops ) n using namespace std; n const int inf = numeric_limits<int>::max() / 2; n const long double eps = 1e-9; n const long double pi = acos(-1); n inline void solve(), read(); n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   read(); n   solve(); n   return 0; n } n pair<int, int> operator+(pair<int, int> p1, pair<int, int> p2) { n   return {p1.first + p2.first, p1.second + p2.second}; n } n int q; n map<pair<int, int>, int> l, s; n map<int, set<pair<int, int>>> qs; n int n = 0; n int gcd(int a, int b) { n   while (b != 0) { n     a %= b; n     swap(a, b); n   } n   return a; n } n pair<int, int> getp(pair<int, int> p) { n   int g = gcd(p.first, p.second); n   return {p.first / g, p.second / g}; n } n void add(pair<int, int> p) { n   ++n; n   pair<int, int> t = getp(p); n   ++l[t]; n   int d = p.first * p.first + p.second * p.second; n   for (pair<int, int> q : qs[d]) { n     pair<int, int> u = getp(p + q); n     ++s[u]; n   } n   qs[d].insert(p); n } n void del(pair<int, int> p) { n   --n; n   pair<int, int> t = getp(p); n   --l[t]; n   int d = p.first * p.first + p.second * p.second; n   qs[d].erase(p); n   for (pair<int, int> q : qs[d]) { n     pair<int, int> u = getp(p + q); n     --s[u]; n   } n } n int get(pair<int, int> p) { n   pair<int, int> t = getp(p); n   return n - l[t] - 2 * s[t]; n } n inline void solve() { n   for (int i = 0; i < q; i++) { n     int t; n     pair<int, int> p; n     cin >> t >> p.first >> p.second; n     if (t == 1) { n       add(p); n     } else if (t == 2) { n       del(p); n     } else if (t == 3) { n       int ans = get(p); n       cout << ans <<   n ; n     } n   } n } n inline void read() { cin >> q; } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005; n vector<pair<int, int>> adj[N], fish[N]; n int n, m, now, depth[N]; n struct node_t { n   int x, d, v; n   node_t(int x, int d, int v, int t = 0) : x(x - d * t), d(d), v(v) {} n   bool operator<(const node_t &b) const { n     int p = x + now * d, q = b.x + now * b.d; n     return p == q ? d < b.d : p < q; n   } n }; n struct collision_t { n   node_t x, y; n   int when; n   collision_t(node_t x, node_t y) : x(x), y(y) { when = y.x - x.x >> 1; } n   bool operator<(const collision_t &b) const { n     if (when != b.when) { n       return when < b.when; n     } else { n       return make_tuple(x.x, x.v, y.x, y.v) < n              make_tuple(b.x.x, b.x.v, b.y.x, b.y.v); n     } n   } n }; n struct info_t { n   set<collision_t> collisions; n   set<node_t> nodes; n   void insert_collision(node_t x, node_t y) { n     if (x.d > 0 && y.d < 0) { n       collisions.insert(collision_t(x, y)); n     } n   } n   void erase_collision(node_t x, node_t y) { n     if (x.d > 0 && y.d < 0) { n       collisions.erase(collision_t(x, y)); n     } n   } n   void insert(node_t x) { n     if (!x.v) { n       return; n     } n     if (nodes.find(x) != nodes.end()) { n       x.v += nodes.find(x)->v; n       erase(*nodes.find(x)); n     } n     auto it = nodes.insert(x).first, next = it; n     ++next; n     if (it != nodes.begin()) { n       auto prev = it; n       --prev; n       if (next != nodes.end()) { n         erase_collision(*prev, *next); n       } n       insert_collision(*prev, x); n     } n     if (next != nodes.end()) { n       insert_collision(x, *next); n     } n   } n   void erase(node_t x) { n     auto it = nodes.find(x), next = it; n     ++next; n     if (next != nodes.end()) { n       erase_collision(x, *next); n     } n     if (it != nodes.begin()) { n       auto prev = it; n       --prev; n       erase_collision(*prev, x); n       if (next != nodes.end()) { n         insert_collision(*prev, *next); n       } n     } n     nodes.erase(it); n   } n   int reset(int x, int y) { n     node_t l(x + 1, -1, y, now), r(x - 1, 1, y, now); n     return max(0, y - max(nodes.find(l) == nodes.end() ? 0 : nodes.find(l)->v, n                           nodes.find(r) == nodes.end() ? 0 : nodes.find(r)->v)); n   } n   node_t cancel(node_t x, node_t y) { n     if (x.v > y.v) { n       return node_t(x.x, x.d, x.v - y.v); n     } else { n       return node_t(y.x, y.d, y.v - x.v); n     } n   } n   void collide(collision_t x) { n     erase(x.x); n     erase(x.y); n     insert(cancel(x.x, x.y)); n   } n   void maintain(int x) { n     while (!collisions.empty() && collisions.begin()->when <= x) { n       collide(*collisions.begin()); n     } n   } n   void merge(info_t &b) { n     if (nodes.size() < b.nodes.size()) { n       swap(nodes, b.nodes); n       swap(collisions, b.collisions); n     } n     for (auto x : b.nodes) { n       insert(x); n     } n   } n   int query() { n     int answer = 0; n     for (auto x : nodes) { n       if (x.d > 0) { n         answer += x.v; n       } n     } n     return answer; n   } n } info[N]; n void dfs(int x, int parent) { n   for (auto e : adj[x]) { n     int y = e.first, w = e.second; n     if (y != parent) { n       depth[y] = depth[x] + w; n       dfs(y, x); n     } n   } n } n void solve(int x, int parent) { n   for (auto e : adj[x]) { n     int y = e.first, w = e.second; n     if (y != parent) { n       solve(y, x); n       now = -depth[y]; n       info[y].maintain(-(depth[x] + 1)); n       now = -(depth[x] + 1); n       info[x].merge(info[y]); n     } n   } n   now = -(depth[x] + 1); n   for (auto &e : fish[x]) { n     e.second = info[x].reset(e.first, e.second); n   } n   info[x].maintain(-depth[x]); n   now = -depth[x]; n   for (auto e : fish[x]) { n     info[x].insert(node_t(e.first, -1, e.second, now)); n     info[x].insert(node_t(e.first, 1, e.second, now)); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i < n; ++i) { n     int x, y, w; n     scanf( %d %d %d , &x, &y, &w); n     --x; n     --y; n     w <<= 1; n     adj[x].emplace_back(y, w); n     adj[y].emplace_back(x, w); n   } n   scanf( %d , &m); n   for (int i = 1; i <= m; ++i) { n     int day, value, where; n     scanf( %d %d %d , &day, &value, &where); n     day <<= 1; n     --where; n     fish[where].emplace_back(day, value); n   } n   dfs(0, -1); n   solve(0, -1); n   info[0].maintain(INT_MAX); n   printf( %d n , info[0].query()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, j, k; n   double maxm, sum, r; n   cin >> n; n   double A[n]; n   for (i = 0; i < n; i++) cin >> A[i]; n   sort(A, A + n); n   maxm = A[n - 1]; n   for (i = n - 1; i >= 0; i--) { n     sum = 0; n     for (j = n - 1; j >= i; j--) { n       r = A[j]; n       for (k = n - 1; k >= i; k--) { n         if (k != j) r = r * (double(1.0) - A[k]); n       } n       sum += r; n     } n     if (sum > maxm) maxm = sum; n   } n   cout << setprecision(10) << maxm << endl; n } n


#include <bits/stdc++.h> n void fre() { n   freopen( c://test//input.in ,  r , stdin); n   freopen( c://test//output.out ,  w , stdout); n } n template <class T> n inline void gmax(T &a, T b) { n   if (b > a) a = b; n } n template <class T> n inline void gmin(T &a, T b) { n   if (b < a) a = b; n } n using namespace std; n const int N = 1e5 + 10, M = 0, Z = 1e9 + 7, maxint = 2147483647, n           ms31 = 522133279, ms63 = 1061109567, ms127 = 2139062143; n const double eps = 1e-8, PI = acos(-1.0); n int n, m; n int x, y; n int ind[N], s[N], num, top; n vector<int> a[N], b[N]; n bool e[N]; n void dfs(int x) { n   e[x] = 1; n   num++; n   if (ind[x] == 0) s[++top] = x; n   for (int i = a[x].size() - 1; i >= 0; i--) { n     int y = a[x][i]; n     if (!e[y]) dfs(y); n   } n } n int main() { n   while (~scanf( %d%d , &n, &m)) { n     memset(ind, 0, sizeof(ind)); n     for (int i = 1; i <= n; i++) a[i].clear(), b[i].clear(); n     for (int i = 1; i <= m; i++) { n       scanf( %d%d , &x, &y); n       ind[y]++; n       a[x].push_back(y); n       a[y].push_back(x); n       b[x].push_back(y); n     } n     int ans = 0; n     memset(e, 0, sizeof(e)); n     for (int i = 1; i <= n; i++) n       if (!e[i]) { n         num = top = 0; n         dfs(i); n         int sum = top; n         while (top) { n           int x = s[top--]; n           for (int j = b[x].size() - 1; j >= 0; j--) { n             int y = b[x][j]; n             ind[y]--; n             if (ind[y] == 0) { n               s[++top] = y; n               sum++; n             } n           } n         } n         if (sum == num) n           ans += (num - 1); n         else n           ans += num; n       } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int a, b, c; n     cin >> a >> b >> c; n     if (a > b) swap(a, b); n     int mx = (b - a) * 2; n     if (a > mx || b > mx || c > mx) n       cout <<  -1 n ; n     else { n       if (c > mx / 2) n         cout << c - mx / 2 <<   n ; n       else n         cout << c + mx / 2 <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[50100]; n long long m, ans; n struct node { n   int s, cnt[30]; n   node *ch[2]; n   node(); n } * tp, *nul, *root[50100]; n int getint() { n   char ch; n   while (!isdigit(ch = getchar())) n     ; n   int x = ch -  0 ; n   for (; isdigit(ch = getchar()); x = x * 10 + ch -  0 ) n     ; n   return x; n } n node::node() { ch[0] = tp, tp = this; } n node *newnode(node *x) { n   if (!tp) new node[50000]; n   node *t = tp; n   tp = t->ch[0], *t = *x; n   return t; n } n void insert(node *&x, node *y, int w) { n   node *ret = newnode(y); n   ++(x = ret)->s; n   for (int i = 29; i >= 0; --i) { n     for (int j = 0; j <= i; ++j) x->cnt[j] += (w >> j) & 1; n     int t = (w >> i) & 1; n     x->ch[t] = newnode(y = y->ch[t]), ++(x = x->ch[t])->s; n   } n   x = ret; n } n int main() { n   scanf( %d%I64d , &n, &m); n   nul = new node, tp = 0; n   memset(nul, 0, sizeof(node)); n   root[1] = nul->ch[0] = nul->ch[1] = nul; n   for (int i = 1; i <= n; ++i) insert(root[i + 1], root[i], a[i] = getint()); n   for (int i = 29; i >= 0; --i) { n     long long sum = 0; n     for (int j = 2; j <= n; ++j) sum += root[j]->ch[1 ^ ((a[j] >> i) & 1)]->s; n     if (sum < m) { n       m -= sum, ans += (1LL << i) * sum; n       for (int j = 2; j <= n; ++j) { n         node *x = root[j]->ch[1 ^ ((a[j] >> i) & 1)]; n         for (int k = 0; k <= i - 1; ++k) n           ans += n               (1LL << k) * (((a[j] >> k) & 1) ? x->s - x->cnt[k] : x->cnt[k]); n         root[j] = root[j]->ch[(a[j] >> i) & 1]; n       } n     } else { n       ans += (1LL << i) * m; n       for (int j = 2; j <= n; ++j) root[j] = root[j]->ch[1 ^ ((a[j] >> i) & 1)]; n     } n   } n   printf( %d n , ans % 1000000007); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[200001]; n void op(int i) { n   int res = a[i] ^ a[i + 1] ^ a[i + 2]; n   a[i] = a[i + 1] = a[i + 2] = res; n } n vector<int> push_left(int i) { n   vector<int> v; n   while (i - 2 >= 1 && a[i] == 0 && a[i - 1] == 1 && a[i - 2] == 1) { n     op(i - 2); n     v.push_back(i - 2); n     i -= 2; n   } n   return v; n } n vector<int> push_right(int i, int n) { n   vector<int> v; n   while (i + 2 <= n && a[i] == 0 && a[i + 1] == 1 && a[i + 2] == 1) { n     op(i); n     v.push_back(i); n     i += 2; n   } n   return v; n } n int main() { n   int i, t; n   for (scanf( %d , &t); t--;) { n     int n; n     vector<int> v, ans; n     int cum = 0; n     for (scanf( %d , &n), i = 1; i <= n; ++i) { n       scanf( %d , a + i); n       cum += a[i]; n     } n     if (cum == 0) { n       printf( YES n0 n ); n       continue; n     } else if ((cum & 1) || cum == n) { n       printf( NO n ); n       continue; n     } n     int cur = 1; n     if (a[1]) { n       cum = a[1]; n       cur = 2; n       while (cur <= n && a[cur]) cum += a[cur], ++cur; n       if (cum & 1) { n         --cur; n         bool y = 1; n         while (cur <= n && a[cur]) { n           if (cur + 2 <= n) { n             if (a[cur] + a[cur + 1] + a[cur + 2] == 3) { n               cur += 2; n             } else if (a[cur + 1] + a[cur + 2] == 0) { n               ans.push_back(cur); n               op(cur); n               cur += 2; n             } else if (a[cur + 1] == 0 && a[cur + 2] == 1) { n               ans.push_back(cur); n               op(cur); n               auto push_vec = push_left(cur); n               ans.insert(ans.end(), push_vec.begin(), push_vec.end()); n               cur += 3; n               break; n             } else { n               auto push_vec = push_left(cur + 2); n               ans.insert(ans.end(), push_vec.begin(), push_vec.end()); n               cur += 3; n               break; n             } n           } else { n             y = 0; n             break; n           } n         } n         if (y == 0) { n           printf( NO n ); n           continue; n         } n       } else { n         ans = push_left(cur); n       } n     } n     cur = 1; n     while (cur + 2 <= n) { n       if (a[cur] == 0 && a[cur + 1] + a[cur + 2] == 2) { n         op(cur); n         ans.push_back(cur); n         cur += 2; n       } else if (a[cur]) { n         int st = cur - 1; n         while (1) { n           if (cur + 2 <= n && a[cur + 1] + a[cur + 2] == 2) n             cur += 2; n           else if (cur + 2 <= n && a[cur + 1] + a[cur + 2] == 0) { n             op(cur); n             ans.push_back(cur); n             cur += 2; n           } else if (cur + 2 <= n && a[cur + 1] == 0 && a[cur + 2] == 1) { n             op(cur); n             ans.push_back(cur); n             break; n           } else { n             break; n           } n         } n         auto push_vec = push_right(st, n); n         ans.insert(ans.end(), push_vec.begin(), push_vec.end()); n       } else n         ++cur; n     } n     cum = 0; n     for (i = 1; i <= n; ++i) cum += a[i]; n     if (cum == 0) { n       printf( YES n%d n , ans.size()); n       for (auto x : ans) printf( %d  , x); n       puts(  ); n     } else n       printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void read(T& x) { n   x = 0; n   char s = (char)getchar(); n   bool f = false; n   while (!(s >=  0  && s <=  9 )) { n     if (s ==  - ) f = true; n     s = (char)getchar(); n   } n   while (s >=  0  && s <=  9 ) { n     x = (x << 1) + (x << 3) + s -  0 ; n     s = (char)getchar(); n   } n   if (f) x = (~x) + 1; n } n const long long N = 2e6 + 5, mod = 998244353, MAX = 2e6; n long long power[N], fac[N], inv[N]; n inline long long quickpow(long long a, long long b, long long p = mod) { n   long long res = 1; n   while (b) { n     if (b & 1) res = res * a % p; n     a = a * a % p; n     b >>= 1; n   } n   return res; n } n inline long long C(long long n, long long m) { n   if (n < m) return 0; n   return fac[n] * inv[m] % mod * inv[n - m] % mod; n } n long long n; n long long ans[N]; n void init() { n   long long limit = 2e5; n   long long x = 810; n   ans[1] = 10; n   ans[2] = 180; n   for (register long long i = 3; i <= limit; ++i) { n     ans[i] = ans[i - 1] * 10 + x; n     x *= 10; n     ans[i] %= mod, x %= mod; n   } n } n signed main() { n   init(); n   long long n; n   cin >> n; n   for (register long long i = n; i >= 1; --i) cout << ans[i] <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int kN = 100 + 1; n const int kA = 256; n bool dp[kN][kN][kA]; n bool used[kN][kN][kA]; n vector<pair<int, int> > g[kN]; n bool Dp(int u, int v, int mark) { n   if (!used[u][v][mark]) { n     used[u][v][mark] = true; n     dp[u][v][mark] = false; n     for (const auto& edge : g[u]) { n       if (edge.second < mark) { n         continue; n       } n       dp[u][v][mark] = dp[u][v][mark] || !Dp(v, edge.first, edge.second); n     } n   } n   return dp[u][v][mark]; n } n void Solve() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < m; ++i) { n     int u, v; n     char ch; n     cin >> u >> v >> ch; n     g[u - 1].emplace_back(v - 1, int(ch)); n   } n   for (int u = 0; u < n; ++u) { n     for (int v = 0; v < n; ++v) { n       cout << (Dp(u, v, 0) ?  A  :  B ); n     } n     cout <<   n ; n   } n } n int main() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int tests_count = 1; n   for (int test_index = 0; test_index < tests_count; ++test_index) { n     Solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n int n, S, L; n int a[300005]; n int dp[300005]; n void solve() { n   deque<pair<int, int> > dqmin, dqmax, dqdp; n   int pos = 0; n   for (int i = 1; i <= n; i++) { n     if (i >= L) { n       while (dqdp.size() && dqdp.back().first >= dp[i - L]) dqdp.pop_back(); n       dqdp.push_back(make_pair(dp[i - L], i - L)); n     } n     while (dqmax.size() && dqmax.back().first <= a[i]) dqmax.pop_back(); n     dqmax.push_back(make_pair(a[i], i)); n     while (dqmin.size() && dqmin.back().first >= a[i]) dqmin.pop_back(); n     dqmin.push_back(make_pair(a[i], i)); n     while (dqmax.size() && dqmax.front().first - dqmin.front().first > S) { n       pos++; n       if (dqmax.front().second < pos) dqmax.pop_front(); n       if (dqmin.front().second < pos) dqmin.pop_front(); n     } n     while (dqdp.size() && dqdp.front().second < pos - 1) dqdp.pop_front(); n     if (dqdp.size()) dp[i] = dqdp.front().first + 1; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   cin >> S >> L; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     dp[i] = n + 1; n   } n   solve(); n   if (dp[n] <= n) n     cout << dp[n]; n   else n     cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MaxN = 600005; n template <class t> n inline void rd(t &s) { n   s = 0; n   register char c = getchar(); n   while (!isdigit(c)) c = getchar(); n   while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar(); n   return; n } n long long a[MaxN], b[MaxN], vis[MaxN * 3]; n struct Quetion { n   long long idx, pos, val; n } que[MaxN]; n struct SegTree { n   struct Node { n     long long val, lazy; n   }; n   Node tr[MaxN << 2]; n   inline void clear() { n     memset(tr, 0, sizeof tr); n     return; n   } n   inline void pushup(long long u) { n     tr[u].val = max(tr[(u << 1)].val, tr[(u << 1 | 1)].val); n     return; n   } n   inline void pushdown(long long u, long long l, long long r) { n     if (tr[u].lazy) { n       tr[(u << 1)].lazy += tr[u].lazy; n       tr[(u << 1 | 1)].lazy += tr[u].lazy; n       tr[(u << 1)].val += tr[u].lazy; n       tr[(u << 1 | 1)].val += tr[u].lazy; n       tr[u].lazy = 0; n     } n     return; n   } n   inline void buildtr(long long u, long long l, long long r) { n     if (l == r) { n       tr[u].val = 0; n       return; n     } n     register long long mid = (l + r) >> 1; n     buildtr((u << 1), l, mid); n     buildtr((u << 1 | 1), mid + 1, r); n     pushup((u >> 1)); n     return; n   } n   inline void change(long long u, long long l, long long r, long long ql, n                      long long qr, long long x) { n     if (ql == l && r == qr) { n       tr[u].val += x; n       tr[u].lazy += x; n       return; n     } n     if (l == r) return; n     register long long mid = (l + r) >> 1; n     pushdown(u, l, r); n     if (qr <= mid) n       change((u << 1), l, mid, ql, qr, x); n     else if (mid < ql) n       change((u << 1 | 1), mid + 1, r, ql, qr, x); n     else { n       change((u << 1), l, mid, ql, mid, x); n       change((u << 1 | 1), mid + 1, r, mid + 1, qr, x); n     } n     pushup(u); n     return; n   } n   inline long long query(long long u, long long l, long long r, long long ql, n                          long long qr) { n     if (l == r) return l; n     register long long mid = (l + r) >> 1; n     pushdown(u, l, r); n     if (tr[(u << 1 | 1)].val > 0) n       return query((u << 1 | 1), mid + 1, r, ql, qr); n     else n       return query((u << 1), l, mid, ql, qr); n   } n } segtree; n signed main(void) { n   long long n, m, q; n   register long long cnt = 0; n   rd(n); n   rd(m); n   for (long long i = 1; i <= n; ++i) rd(a[i]), vis[++cnt] = a[i]; n   for (long long i = 1; i <= m; ++i) rd(b[i]), vis[++cnt] = b[i]; n   rd(q); n   for (long long i = 1; i <= q; ++i) { n     rd(que[i].idx); n     rd(que[i].pos); n     rd(que[i].val); n     vis[++cnt] = que[i].val; n   } n   sort(vis + 1, vis + cnt + 1); n   cnt = unique(vis + 1, vis + cnt + 1) - vis - 1; n   for (long long i = 1; i <= n; ++i) n     a[i] = lower_bound(vis + 1, vis + cnt + 1, a[i]) - vis; n   for (long long i = 1; i <= m; ++i) n     b[i] = lower_bound(vis + 1, vis + cnt + 1, b[i]) - vis; n   for (long long i = 1; i <= q; ++i) n     que[i].val = lower_bound(vis + 1, vis + cnt + 1, que[i].val) - vis; n   segtree.buildtr(1, 1, cnt); n   for (long long i = 1; i <= n; ++i) segtree.change(1, 1, cnt, 1, a[i], 1); n   for (long long i = 1; i <= m; ++i) segtree.change(1, 1, cnt, 1, b[i], -1); n   for (long long i = 1; i <= q; ++i) { n     if (que[i].idx == 1) { n       segtree.change(1, 1, cnt, 1, a[que[i].pos], -1); n       a[que[i].pos] = que[i].val; n       segtree.change(1, 1, cnt, 1, a[que[i].pos], 1); n     } else { n       segtree.change(1, 1, cnt, 1, b[que[i].pos], 1); n       b[que[i].pos] = que[i].val; n       segtree.change(1, 1, cnt, 1, b[que[i].pos], -1); n     } n     if (segtree.tr[1].val <= 0) n       puts( -1 ); n     else n       printf( %lld n , vis[segtree.query(1, 1, cnt, 1, cnt)]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void printvec(vector<T>& vec) { n   for (long long int i = 0; i < vec.size(); i++) { n     cout << vec[i] <<    ; n   } n   cout << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   long long int n; n   cin >> n; n   vector<pair<long long int, long long int> > inp; n   for (long long int i = 0; i < n; i++) { n     long long int a, b, c, d; n     cin >> a >> b >> c >> d; n     a = a + b + c + d; n     inp.push_back(make_pair(-a, i)); n   } n   sort(inp.begin(), inp.end()); n   for (long long int i = 0; i < n; i++) { n     if (inp[i].second == 0) { n       cout << i + 1 <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int s = 1000000; n int a[1000001]; n bool belongs[1000001]; n bool used[1000001]; n vector<int> ans; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i <= s; i++) belongs[i] = used[i] = false; n   for (int i = 0; i < n; i++) { n     scanf( %i , &a[i]); n     belongs[a[i]] = true; n   } n   int u = 1; n   for (int i = 0; i < n; i++) n     if (!used[a[i]]) { n       if (belongs[a[i]] && !belongs[s - a[i] + 1] && !used[s - a[i] + 1]) { n         ans.push_back(s - a[i] + 1); n         used[s - a[i] + 1] = true; n         used[a[i]] = true; n       } else if (belongs[a[i]] && belongs[s - a[i] + 1]) { n         while (u <= s && n                (belongs[u] || belongs[s - u + 1] || used[u] || used[s - u + 1])) n           u++; n         used[u] = true; n         used[s - u + 1] = true; n         used[s - a[i] + 1] = true; n         used[a[i]] = true; n         ans.push_back(u); n         ans.push_back(s - u + 1); n         u++; n       } else n         assert(false); n     } n   cout << int(ans.size()) << endl; n   for (int i = 0; i < int(ans.size()); i++) printf( %i  , ans[i]); n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string n; n int sz; n long long mul; n long long ans; n long long powe(long long a, long long b) { n   if (!b) return 1; n   long long tmp = powe(a, b / 2); n   tmp = (tmp * tmp) % 1000000007; n   if (b % 2 == 1) n     return (tmp * a) % 1000000007; n   else n     return tmp; n } n int main() { n   cin >> n; n   sz = ((int)n.size()); n   mul = powe(2, sz - 1); n   long long tp = 1; n   for (int i = sz - 1; i >= 0; i--) { n     if (n[i] ==  1 ) { n       ans = (ans + ((tp * mul) % 1000000007)) % 1000000007; n     } n     tp = (tp * 2) % 1000000007; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n long long MOD = 998244353; n double eps = 1e-12; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n; n   cin >> n; n   string s; n   cin >> s; n   int coins = 0; n   int x, y; n   if (s[0] ==  U ) { n     x = 0; n     y = 1; n   } else { n     x = 1; n     y = 0; n   } n   for (int i = 1; i < n; i++) { n     if (s[i] ==  U ) { n       if (x == y) { n         if (s[i - 1] ==  U ) coins++; n       } n       y++; n     } else { n       if (x == y) { n         if (s[i - 1] ==  R ) coins++; n       } n       x++; n     } n   } n   cout << coins; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 10000; n const int maxm = 20000; n const int maxk = 10; n const int inf = 25; n int tot_edge, sz; n int head[maxn]; n int nxt[maxm]; n int to[maxm]; n int cap[maxm]; n int flow[maxk + 1][maxm]; n int qu[maxn]; n int prv[maxn]; n int when[maxn]; n int pass_flow[maxn]; n int last_time; n int level[maxn], edge_pos[maxn]; n int read() { n   int xx = 0, ff = 1; n   char ch = getchar(); n   while (ch >  9  || ch <  0 ) { n     if (ch ==  - ) ff = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     xx = (xx << 3) + (xx << 1) + ch -  0 ; n     ch = getchar(); n   } n   return xx * ff; n } n void add_edge(int u, int v, int w) { n   nxt[tot_edge] = head[u]; n   head[u] = tot_edge; n   to[tot_edge] = v; n   cap[tot_edge] = w; n   tot_edge++; n } n bool bfs(int s, int t, int *flow) { n   sz = 0; n   qu[sz++] = t; n   int pnt = 0; n   memset(level, -1, sizeof(level)); n   level[t] = 0; n   while (pnt < sz && level[s] == -1) { n     int u = qu[pnt++]; n     for (int e = head[u]; e >= 0; e = nxt[e]) { n       int v = to[e]; n       if (level[v] == -1 && flow[e ^ 1] < cap[e ^ 1]) { n         level[v] = level[u] + 1; n         qu[sz++] = v; n       } n     } n   } n   return level[s] != -1; n } n int dinic(int s, int t, int *flow) { n   int ret = 0; n   while (bfs(s, t, flow)) { n     copy(head, head + maxn, edge_pos); n     function<int(int, int)> find_path = [&](int u, int res) { n       if (u == t) return res; n       for (int &e = edge_pos[u]; e >= 0; e = nxt[e]) { n         int v = to[e]; n         if (flow[e] == cap[e] || level[u] - 1 != level[v]) continue; n         int push = find_path(v, min(res, cap[e] - flow[e])); n         if (push > 0) { n           flow[e] += push; n           flow[e ^ 1] -= push; n           if (flow[e] == cap[e]) e = nxt[e]; n           return push; n         } n       } n       return 0; n     }; n     for (int f; (f = find_path(s, 1e9)) > 0;) ret += f; n   } n   return ret; n } n int augment(int s, int t, int *flow) { n   last_time++; n   sz = 0; n   qu[sz++] = s; n   when[s] = last_time; n   int pnt = 0; n   pass_flow[s] = inf; n   pass_flow[t] = 0; n   while (pnt < sz && when[t] != last_time) { n     int u = qu[pnt++]; n     assert(pass_flow[u] > 0); n     for (int e = head[u]; e >= 0; e = nxt[e]) { n       int v = to[e]; n       if (when[v] != last_time && flow[e] < cap[e]) { n         pass_flow[v] = min(pass_flow[u], cap[e] - flow[e]); n         prv[v] = e; n         when[v] = last_time; n         qu[sz++] = v; n         if (v == t) break; n       } n     } n   } n   int f = pass_flow[t]; n   if (f == 0) return f; n   do { n     int e = prv[t]; n     flow[e] += f; n     flow[e ^ 1] -= f; n     assert(to[e] == t); n     t = to[e ^ 1]; n   } while (t != s); n   return f; n } n int max_flow(int s, int t, int *flow) { n   int res = 0, cur = 0; n   do { n     cur = augment(s, t, flow); n     res += cur; n   } while (cur); n   return res; n } n int n, m, k, q; n int masked[1 << maxk]; n void go(int n, int m, int mask, int pointer) { n   for (int i = 0; (mask >> i & 1) == 0 && i < k; ++i) { n     int n_mask = mask | (1 << i); n     copy(flow[pointer], flow[pointer] + m, flow[pointer + 1]); n     cap[2 * i] = inf; n     masked[n_mask] = masked[mask] + max_flow(0, n - 1, flow[pointer + 1]); n     go(n, m, n_mask, pointer + 1); n     cap[2 * i] = 0; n   } n } n int wei[maxk]; n int suma[1 << maxk]; n int eptr; n struct info { n   int u, v, w; n } edges[maxm]; n vector<int> adj[maxn]; n void relabel(int n, int m) { n   sz = 0; n   qu[sz++] = 0; n   int pnt = 0; n   memset(level, -1, sizeof(level)); n   level[0] = 0; n   level[n - 1] = n - 1; n   while (pnt < sz) { n     int u = qu[pnt++]; n     for (auto v : adj[u]) { n       if (level[v] == -1) { n         level[v] = sz; n         qu[sz++] = v; n       } n     } n   } n   for (int i = 0; i < n; ++i) n     if (level[i] == -1) level[i] = sz++; n   for (int i = 0; i < m; ++i) { n     edges[i].u = level[edges[i].u]; n     edges[i].v = level[edges[i].v]; n   } n } n int main() { n   memset(head, -1, sizeof head); n   n = read(); n   m = read(); n   k = read(); n   q = read(); n   for (int i = 0; i < m; ++i) { n     int u, v, w; n     u = read(); n     v = read(); n     w = read(); n     u--; n     v--; n     edges[i] = {u, v, w}; n     adj[u].push_back(v); n   } n   relabel(n, m); n   for (int i = 0; i < m; ++i) { n     add_edge(edges[i].u, edges[i].v, edges[i].w); n     add_edge(edges[i].v, edges[i].u, 0); n   } n   masked[0] = dinic(0, n - 1, flow[0]); n   go(n, 2 * m, 0, 0); n   int top = (1 << k) - 1; n   for (int i = 0; i < q; ++i) { n     for (int j = 0; j < k; ++j) wei[j] = read(); n     int answer = masked[top]; n     for (int j = 1; j < (1 << k); j++) { n       int x = __builtin_ctz(j); n       suma[j] = suma[j ^ (1 << x)] + wei[x]; n       answer = min(answer, masked[top ^ j] + suma[j]); n     } n     printf( %d n , answer); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string n; n   cin >> n; n   cout <<  25  << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n const int maxn = 1000100; n int cnt_neg = 0, cnt_pos = 0; n int arr[maxn << 1]; n int main() { n   int n; n   scanf( %d , &n); n   for (int e = 1; e <= n; e++) scanf( %d , arr + e), arr[e + n] = arr[e]; n   int hi = 2 * n, lo = n + 1, nowlo = n; n   long long sum = 0; n   set<pair<int, int> > go; n   unordered_set<int> removido; n   for (int cur = hi; cur >= lo; cur--) { n     if (arr[cur] <= nowlo) n       cnt_pos++; n     else n       cnt_neg++, go.insert(make_pair(arr[cur] - nowlo, cur)); n     sum += abs(arr[cur] - nowlo); n     nowlo--; n   } n   long long ans = sum, shift = 0, state = 0; n   for (; lo > 1;) { n     if (arr[hi] <= n) n       cnt_pos--; n     else n       cnt_neg--; n     sum -= abs(arr[hi] - n); n     removido.insert(hi); n     shift++; n     sum += -cnt_neg + cnt_pos; n     sum += abs(arr[lo - 1] - 1); n     if (sum < ans) ans = sum, state = shift; n     if (arr[lo - 1] > 1) n       cnt_neg++, go.insert(make_pair(shift + arr[lo - 1] - 1, lo - 1)); n     else n       cnt_pos++; n     while (!go.empty()) { n       int shi, val; n       tie(shi, val) = *go.begin(); n       int removal = removido.count(val); n       if (!(removal || shi == shift)) break; n       if (!removal) n         cnt_neg--, cnt_pos++; n       else n         removido.erase(go.begin()->second); n       go.erase(go.begin()); n     } n     lo--; n     hi--; n   } n   printf( %lld %lld n , ans, state); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod(long long v, long long k, long long p) { n   long long res = 1; n   for (long long i = 0; i < 4; i++) res *= v, res %= p; n   res -= ((k * v) % p); n   if (res < 0) res += p; n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n, p, k; n   cin >> n >> p >> k; n   long long Array[n]; n   for (long long i = 0; i < n; i++) cin >> Array[i]; n   long long B[n]; n   for (long long i = 0; i < n; i++) B[i] = mod(Array[i], k, p); n   vector<long long> out; n   sort(B, B + n); n   long long cnt = 1; n   for (long long i = 0; i < n - 1; i++) { n     if (B[i + 1] != B[i] and cnt != 1) n       out.push_back(cnt), cnt = 1; n     else if (B[i + 1] == B[i]) n       cnt++; n   } n   if (cnt != 1) out.push_back(cnt); n   long long sum = 0; n   for (long long i = 0; i < out.size(); i++) n     sum += ((out[i] * (out[i] - 1)) / 2); n   cout << sum <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 200000000 + 1; n const int N = 300006, M = 80; n int dp[2][101][10005], a[105], cnt[105]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n; i++) { n     int cnt1 = 0; n     for (int j = 1; j <= n; j++) { n       if (a[i] == a[j]) cnt1++; n     } n     cnt[a[i]] = cnt1; n   } n   sort(a + 1, a + n + 1); n   vector<int> v; n   v.push_back(a[1]); n   for (int i = 2; i <= n; i++) n     if (a[i] != a[i - 1]) v.push_back(a[i]); n   dp[0][0][0] = 1; n   for (int i = 1; i <= v.size(); i++) { n     for (int j = 0; j <= n; j++) { n       for (int k = 0; k <= 100 * n; k++) { n         dp[i % 2][j][k] = dp[1 - i % 2][j][k]; n         for (int l = 1; l <= cnt[v[i - 1]] && l <= j; l++) { n           int z = l * v[i - 1]; n           if (k >= z) n             dp[i % 2][j][k] = dp[i % 2][j][k] + dp[1 - i % 2][j - l][k - z]; n           if (dp[i % 2][j][k] > 10) dp[i % 2][j][k] = 10; n         } n       } n     } n   } n   int ans = 1; n   for (int i = 1; i <= n; i++) { n     for (int j = i; j <= n; j++) { n       if (a[j] != a[i]) break; n       int sum = a[j] * (j - i + 1); n       int z = j - i + 1; n       if (dp[v.size() % 2][z][sum] == 1) ans = max(ans, z); n     } n   } n   if (v.size() == 2) { n     cout << n <<   n ; n     return 0; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n const int MAXN = 1e6 + 5; n int n, m, k; n char str[21]; n int x[MAXN], y[MAXN]; n int s[MAXN], t[MAXN]; n int p[21]; n int f[(1 << 20) + 3], g[(1 << 20) + 3]; n inline void presum() { n   for (int i = 0; i <= k - 1; ++i) { n     for (int S = 0; S <= (1 << k) - 1; ++S) { n       if ((S >> i) & 1) continue; n       f[S] = std::min(f[S ^ (1 << i)], f[S]); n       g[S] = std::max(g[S ^ (1 << i)], g[S]); n     } n   } n } n int main() { n   scanf( %d%d%d , &n, &m, &k); n   scanf( %s , str); n   for (int i = 0; i <= k - 1; ++i) n     if (str[i] ==  1 ) s[0] |= (1 << i); n   scanf( %s , str); n   for (int i = 0; i <= k - 1; ++i) n     if (str[i] ==  1 ) t[0] |= (1 << i); n   for (int i = 1; i <= n; ++i) scanf( %d%d , x + i, y + i); n   for (int i = 1; i <= k; ++i) p[i] = i; n   for (int i = 1; i <= n; ++i) { n     int p1 = -1, p2 = -1; n     for (int j = 1; j <= k; ++j) { n       if (p[j] == x[i]) p1 = j; n       if (p[j] == y[i]) p2 = j; n     } n     std::swap(p[p1], p[p2]); n     for (int j = 0; j <= k - 1; ++j) n       if ((s[0] >> (p[j + 1] - 1)) & 1) s[i] |= 1 << j; n     for (int j = 0; j <= k - 1; ++j) n       if ((t[0] >> (p[j + 1] - 1)) & 1) t[i] |= 1 << j; n   } n   for (int i = 0; i <= (1 << k) - 1; ++i) f[i] = 1e9, g[i] = -1e9; n   for (int i = 0; i <= n; ++i) n     f[s[i]] = std::min(f[s[i]], i), g[t[i]] = std::max(g[t[i]], i); n   presum(); n   int ans = -1e9, ansl = -1, ansr = -1; n   for (int S = 0; S <= (1 << k) - 1; ++S) { n     if (g[S] - f[S] >= m && __builtin_popcount(S) > ans) { n       ans = __builtin_popcount(S); n       ansl = f[S] + 1; n       ansr = g[S]; n     } n   } n   ans = 2 * ans + k - __builtin_popcount(s[0]) - __builtin_popcount(t[0]); n   printf( %d n%d %d n , ans, ansl, ansr); n   return 0; n } n


//頑張って n #include <bits/stdc++.h> n #define ff first n #define ss second n #define ll long long n #define rep(i, n) for (int i = 0; i < n; i++) n using namespace std; n #define all(x) x.begin(), x.end() n void solve() { n    int n; n    cin >> n; n    vector <int> a(n); n    for (auto &i : a) n       cin >> i; n    int mxn = accumulate(all(a), 0); n    vector <bool> dp(mxn + 1); n    dp[0] = true; n    for (int i = 0; i < n; i++) { n       for (int j = mxn - a[i]; j >= 0; j--) { n          if (dp[j] == true) n             dp[a[i] + j] = true; n       } n    } n    if ((mxn % 2 == 0 && !dp[mxn / 2]) || mxn % 2) { n       cout <<  0 n ; n       return; n    } n    while (true) { n       for (int i = 0; i < n; i++) { n          if (a[i] % 2 != 0) { n             cout <<  1 n  << i + 1 <<   n ; n             return; n          } n          a[i] /= 2; n       } n    } n } n int main() { n #ifndef ONLINE_JUDGE n    freopen( inp.in ,  r , stdin);      freopen( outp.in ,  w , stdout); n #endif n    ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL); n    solve(); n    return 0; n }


#include <bits/stdc++.h> n using namespace std; n const long long inf = (long long)1e18; n const int N = 1234567; n long long a[N], b[N]; n int main() { n   int n, k; n   scanf( %d %d , &n, &k); n   n++; n   for (int i = 0; i < n; i++) { n     int foo; n     scanf( %d , &foo); n     a[i] = foo; n   } n   long long z = 0; n   int up = 0; n   for (int i = 0; i < n; i++) { n     z += a[i]; n     b[i] = z; n     if (z % 2 != 0) { n       break; n     } n     up++; n     z /= 2; n   } n   long long value = 0; n   int ans = 0; n   for (int i = n - 1; i >= 0; i--) { n     if (i <= up) { n       long long tmp = value * 2 + b[i]; n       long long z = a[i] - tmp; n       if (-k <= z && z <= k && (i != n - 1 || z != 0)) { n         ans++; n       } n     } n     value = value * 2 + a[i]; n     if (value < -inf || value > inf) { n       break; n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int di[] = {-1, 0, 1, 0}; n const int dj[] = {0, 1, 0, -1}; n const long long MOD = 1e9 + 7; n const long long INF = 1e9; n const double EPS = 1e-11; n class UnionFind { n  private: n   vector<long long> p, rank, setSize; n   int numSets; n  n  public: n   UnionFind(int N) { n     setSize.assign(N, 1); n     numSets = N; n     rank.assign(N, 0); n     p.assign(N, 0); n     for (int i = 0; i < N; i++) p[i] = i; n   } n   int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); } n   bool isSameSet(int i, int j) { return findSet(i) == findSet(j); } n   void unionSet(int i, int j) { n     if (!isSameSet(i, j)) { n       numSets--; n       int x = findSet(i), y = findSet(j); n       if (rank[x] > rank[y]) { n         p[y] = x; n         setSize[x] += setSize[y]; n       } else { n         p[x] = y; n         setSize[y] += setSize[x]; n         if (rank[x] == rank[y]) rank[y]++; n       } n     } n   } n   int numDisjointSets() { return numSets; } n   int sizeOfSet(int i) { return setSize[findSet(i)]; } n }; n int main() { n   ios::sync_with_stdio(false), cin.tie(0); n   int n; n   cin >> n; n   vector<long long> num(n); n   map<int, int> idx, vis; n   for (int i = 0; i < n; ++i) cin >> num[i], idx[num[i]] = i; n   vector<long long> num2 = num; n   sort(num2.begin(), num2.end()); n   UnionFind dsu(n); n   for (int i = 0; i < n; ++i) { n     swap(num[i], num[idx[num2[i]]]); n     dsu.unionSet(i, idx[num2[i]]); n   } n   for (int i = 0; i < n; ++i) num[i] = dsu.findSet(i); n   map<int, vector<long long> > r; n   for (int i = 0; i < n; ++i) r[num[i]].push_back(i + 1); n   cout << r.size() << endl; n   for (map<int, vector<long long> >::iterator i = r.begin(); i != r.end(); n        ++i) { n     cout << i->second.size() <<    ; n     for (int j = 0; j < i->second.size(); ++j) n       cout << i->second[j] <<    n [j == i->second.size() - 1]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n using minheap = priority_queue<T, vector<T>, greater<T>>; n int main() { n   ios_base::sync_with_stdio(false); n   int t; n   cin >> t; n   while (t--) { n     long long w, h; n     cin >> w >> h; n     vector<vector<long long>> a(4); n     for (int i = 0; i < 4; i++) { n       int k, temp; n       cin >> k; n       for (int j = 0; j < k; j++) { n         cin >> temp; n         a[i].push_back(temp); n       } n     } n     long long ans = 0; n     ans = max(ans, (a[0].back() - a[0][0]) * h); n     ans = max(ans, (a[1].back() - a[1][0]) * h); n     ans = max(ans, (a[2].back() - a[2][0]) * w); n     ans = max(ans, (a[3].back() - a[3][0]) * w); n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n char a[5][6] = { aabb ,  abab ,  abba ,  aaaa }; n char s[5][10005]; n bool f[5]; n int find(char s[], int k) { n   int p1 = -1; n   int len = strlen(s); n   int cnt = 0; n   for (int i = len - 1; i >= 0; i--) { n     if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  || s[i] ==  u ) n       cnt++; n     if (cnt == k) return i; n   } n   return -1; n } n bool check(char s[], char t[], int k) { n   int p = find(s, k), q = find(t, k); n   if (p == -1) return false; n   if (q == -1) return false; n   int l1 = strlen(s), l2 = strlen(t); n   if (l1 - p != l2 - q) return false; n   int j = q; n   for (int i = p; i < l1; i++) { n     if (s[i] == t[j]) n       j++; n     else n       return false; n   } n   return true; n } n int main() { n   int n, k; n   while (scanf( %d%d , &n, &k) > 0) { n     memset(f, false, sizeof(f)); n     for (int i = 1; i <= n; i++) { n       for (int j = 0; j < 4; j++) scanf( %s , s[j]); n       if (!check(s[0], s[1], k)) { n         f[0] = true; n         f[3] = true; n       } n       if (!check(s[2], s[3], k)) { n         f[0] = true; n         f[3] = true; n       } n       if (!check(s[0], s[2], k)) { n         f[1] = true; n         f[3] = true; n       } n       if (!check(s[1], s[3], k)) { n         f[1] = true; n         f[3] = true; n       } n       if (!check(s[0], s[3], k)) { n         f[2] = true; n         f[3] = true; n       } n       if (!check(s[2], s[1], k)) { n         f[2] = true; n         f[3] = true; n       } n     } n     bool sol = false; n     if (!f[0] && !f[1] && !f[2]) { n       puts( aaaa ); n       continue; n     } n     for (int i = 2; i >= 0; i--) { n       if (!f[i]) { n         puts(a[i]); n         sol = true; n         break; n       } n     } n     if (!sol) puts( NO ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005; n struct edge { n   int to, index; n   edge(int t = 0, int i = 0) { n     to = t; n     index = i; n   } n }; n vector<edge> g[N]; n int num[N], ans[N], dep[N], fa[18][N], n, m; n void add(int from, int to, int index) { g[from].push_back(edge(to, index)); } n void dfs(int x, int ffa, int d) { n   fa[0][x] = ffa; n   dep[x] = d; n   for (int i = 0; i < g[x].size(); i++) { n     int y = g[x][i].to; n     if (y == ffa) continue; n     dfs(y, x, d + 1); n   } n } n void init() { n   m = 0; n   while (n >= (1 << m)) m++; n   for (int i = 1; i <= m; i++) { n     for (int j = 1; j <= n; j++) { n       if (fa[i - 1][j] < 0) n         fa[i][j] = -1; n       else { n         fa[i][j] = fa[i - 1][fa[i - 1][j]]; n       } n     } n   } n } n int LCA(int x, int y) { n   if (dep[x] < dep[y]) swap(x, y); n   for (int i = m; i >= 0; i--) { n     if ((dep[x] - dep[y]) & (1 << i)) x = fa[i][x]; n   } n   if (x == y) return x; n   for (int i = m; i >= 0; i--) { n     if (fa[i][x] != fa[i][y]) { n       x = fa[i][x]; n       y = fa[i][y]; n     } n   } n   return fa[0][x]; n } n void dfs2(int x, int fa, int z) { n   for (int i = 0; i < g[x].size(); i++) { n     int y = g[x][i].to; n     if (y == fa) continue; n     dfs2(y, x, g[x][i].index); n     num[x] += num[y]; n   } n   ans[z] = num[x]; n } n int main() { n   int x, y, rt; n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     scanf( %d%d , &x, &y); n     add(x, y, i); n     add(y, x, i); n   } n   dfs(1, -1, 0); n   init(); n   int TA; n   scanf( %d , &TA); n   while (TA--) { n     scanf( %d%d , &x, &y); n     rt = LCA(x, y); n     num[x]++; n     num[y]++; n     num[rt] -= 2; n   } n   dfs2(1, -1, 0); n   for (int i = 1; i < n; i++) printf( %d  , ans[i]); n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[2 * 100004], b[2 * 100004], c[2 * 100004], poz, x; n int main() { n   ios::sync_with_stdio(false); n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     c[a[i]] = 1; n   } n   poz = 1; n   for (int i = 1; i <= n; ++i) { n     cin >> b[i]; n     if (c[b[i]] == 0) { n       cout <<  0  ; n       continue; n     } n     for (int j = poz; j <= n; ++j) { n       c[a[j]] = 0; n       if (a[j] == b[i]) { n         cout << j - poz + 1 <<    ; n         poz = j + 1; n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, cou = 0; n   cin >> n; n   string s; n   cin >> s; n   int res = n + 1; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  H ) cou++; n   } n   for (int i = 0; i < n; i++) { n     int cnt = 0; n     for (int j = 0; j < cou; j++) { n       if (s[(i + j) % n] ==  T ) cnt++; n     } n     res = min(res, cnt); n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int x[55], y[55]; n int main(int argc, char** argv) { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &x[i]); n   for (int i = 1; i <= n; i++) scanf( %d , &y[i]); n   int sum = 0; n   for (int i = 1; i <= n; i++) { n     sum += x[i] - y[i]; n   } n   if (sum >= 0) n     cout <<  Yes ; n   else n     cout <<  No ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void read(T &x) { n   T res = 0, f = 1; n   char c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) { n     res = (res << 3) + (res << 1) + c -  0 ; n     c = getchar(); n   } n   x = res * f; n } n const long long N = 200000 + 10; n long long w, a[N], n, mn = 1e13, mx = -1e13, sum; n int main() { n   read(n), read(w); n   for (int i = 1; i <= n; i++) { n     read(a[i]); n     sum += a[i]; n     mn = min(mn, sum); n     mx = max(mx, sum); n   } n   if (abs(mx) > w || abs(mn) > w) { n     printf( 0 ); n     return 0; n   } n   long long l = 0, r = w; n   if (mn < 0) { n     l = 0 - mn; n   } n   if (mx > 0) { n     r = w - mx; n   } n   long long ans = r - l + 1; n   if (ans > 0) n     printf( %lld , r - l + 1); n   else n     printf( 0 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long getint() { n   long long _x = 0, _tmp = 1; n   char _tc = getchar(); n   while ((_tc <  0  || _tc >  9 ) && _tc !=  - ) _tc = getchar(); n   if (_tc ==  - ) _tc = getchar(), _tmp = -1; n   while (_tc >=  0  && _tc <=  9 ) _x *= 10, _x += (_tc -  0 ), _tc = getchar(); n   return _x * _tmp; n } n inline long long add(long long _x, long long _y, n                      long long _mod = 1000000007ll) { n   long long _ = _x + _y; n   if (_ >= _mod) _ -= _mod; n   return _; n } n inline long long sub(long long _x, long long _y, n                      long long _mod = 1000000007ll) { n   long long _ = _x - _y; n   if (_ < 0) _ += _mod; n   return _; n } n inline long long mul(long long _x, long long _y, n                      long long _mod = 1000000007ll) { n   long long _ = _x * _y; n   if (_ >= _mod) _ %= _mod; n   return _; n } n long long mypow(long long _a, long long _x, long long _mod) { n   if (_x == 0) return 1ll; n   long long _tmp = mypow(_a, _x / 2, _mod); n   _tmp = mul(_tmp, _tmp, _mod); n   if (_x & 1) _tmp = mul(_tmp, _a, _mod); n   return _tmp; n } n long long mymul(long long _a, long long _x, long long _mod) { n   if (_x == 0) return 0ll; n   long long _tmp = mymul(_a, _x / 2, _mod); n   _tmp = add(_tmp, _tmp, _mod); n   if (_x & 1) _tmp = add(_tmp, _a, _mod); n   return _tmp; n } n inline bool equal(double _x, double _y) { n   return _x > _y - 1e-9 && _x < _y + 1e-9; n } n int __ = 1, _cs; n void build() {} n long long n, m, a, b; n void init() { n   n = getint(); n   m = getint(); n   a = getint() - 1; n   b = getint() - 1; n } n void solve() { n   long long ai = a / m, aj = a % m; n   long long bi = b / m, bj = b % m; n   if (ai == bi || (a == 0 && b == n - 1) || m == 1) { n     puts( 1 ); n     exit(0); n   } n   if (aj == 0 && (bj == m - 1 || b == n - 1)) { n     puts( 1 ); n     exit(0); n   } n   if (aj == 0 || bj == m - 1 || bi == ai + 1 || bj + 1 == aj || b == n - 1) { n     puts( 2 ); n     exit(0); n   } n   puts( 3 ); n } n int main() { n   build(); n   while (__--) { n     init(); n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class L, class R> n ostream &operator<<(ostream &os, pair<L, R> P) { n   return os <<  (  << P.first <<  ,  << P.second <<  ) ; n } n template <class T> n ostream &operator<<(ostream &os, vector<T> V) { n   os <<  [ ; n   for (auto vv : V) os << vv <<  , ; n   return os <<  ] ; n } n template <class TH> n void _dbg(const char *sdbg, TH h) { n   cerr << sdbg <<  =  << h <<   n ; n } n template <class TH, class... TA> n void _dbg(const char *sdbg, TH h, TA... a) { n   while (*sdbg !=  , ) cerr << *sdbg++; n   cerr <<  =  << h <<  , ; n   _dbg(sdbg + 1, a...); n } n const long long N = 4e5 + 7; n long long n, a[N], pre[N], ansLen, ansIdx; n double ans = -1.0; n double sum(long long l, long long r) { n   return pre[r] - (l > 0 ? pre[l - 1] : 0); n } n double f(long long len, long long idx) { n   double ret = pre[idx] - pre[idx - len - 1]; n   ret += pre[n] - pre[n - len]; n   ret /= len + len + 1; n   ret -= a[idx]; n   if (ret > ans) { n     ans = ret; n     ansIdx = idx; n     ansLen = len; n   } n   return ret; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   cin >> n; n   for (long long i = 1; i <= n; i++) cin >> a[i]; n   sort(a + 1, a + n + 1); n   for (long long i = 1; i <= n; i++) pre[i] = a[i] + pre[i - 1]; n   for (long long i = 1; i <= n; i++) { n     long long cnt = min(i - 1, n - i); n     long long lo = 0, hi = cnt; n     while (hi - lo > 3) { n       long long m1 = lo + (hi - lo) / 3, m2 = hi - (hi - lo) / 3; n       if (f(m1, i) < f(m2, i)) n         lo = m1; n       else n         hi = m2; n     } n     for (long long k = lo; k <= hi; k++) f(k, i); n   } n   cout << 2 * ansLen + 1 <<   n ; n   for (long long i = ansIdx; i >= ansIdx - ansLen; i--) cout << a[i] <<    ; n   for (long long i = n - ansLen + 1; i <= n; i++) cout << a[i] <<    ; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 100; n const int MAXM = 15; n int N, Q, M; n int log2(int v) { n   int r = 1; n   while (v >>= 1) r++; n   return r; n } n int a[MAXN]; n int t[2][MAXN]; n struct ST { n   int v[3 * MAXN][2][MAXM]; n   int l[3 * MAXN], r[3 * MAXN]; n   bool lz[3 * MAXN]; n   int NXT; n   int sz; n   void updv(const int& n) { n     assert(n != -1 and l[n] != -1 and r[n] != -1); n     for (int i = 0; i <= M; i++) n       for (int j = 0; j < 2; j++) v[n][j][i] = v[l[n]][j][v[r[n]][j][i]]; n   } n   void init(int n, int nl, int nr) { n     assert(n != -1 and nl < nr); n     lz[n] = false; n     l[n] = r[n] = -1; n     if (nr - nl == 1) { n       for (int i = 0; i < M; i++) n         for (int j = 0; j < 2; j++) v[n][j][i] = i + 1; n       v[n][a[nl]][M] = M, v[n][!a[nl]][M] = 0; n     } n     if (nr - nl > 1) { n       int m = nl + ((nr - nl) >> 1); n       init(l[n] = NXT++, nl, m); n       init(r[n] = NXT++, m, nr); n       updv(n); n     } n   } n   ST() {} n   ST(const int& s, bool ini) { n     sz = s; n     NXT = 0; n     if (ini) init(NXT++, 0, sz); n   } n   void prop(int n, int nl, int nr) { n     if (!lz[n]) return; n     for (int i = 0; i <= M; i++) swap(v[n][0][i], v[n][1][i]); n     if (nr - nl > 1) { n       lz[l[n]] = !lz[l[n]]; n       lz[r[n]] = !lz[r[n]]; n     } n     lz[n] = false; n   } n   void upd(int n, int nl, int nr, int gl, int gr) { n     if (gl <= nl and gr >= nr) { n       lz[n] = !lz[n]; n       prop(n, nl, nr); n       return; n     } n     if (nr - nl > 1) { n       prop(n, nl, nr); n       int m = nl + ((nr - nl) >> 1); n       if (gl < m) n         upd(l[n], nl, m, gl, gr); n       else n         prop(l[n], nl, m); n       if (gr > m) n         upd(r[n], m, nr, gl, gr); n       else n         prop(r[n], m, nr); n       updv(n); n       return; n     } n     assert(false); n   } n   void upd(int gl, int gr) { upd(0, 0, sz, gl, gr); } n   int qry(int n, int nl, int nr, int gl, int gr, int c = M) { n     prop(n, nl, nr); n     if (gl <= nl and gr >= nr) { n       return v[n][0][c]; n     } n     if (nr - nl > 1) { n       int m = nl + ((nr - nl) >> 1); n       if (gr > m) c = qry(r[n], m, nr, gl, gr, c); n       if (gl < m) c = qry(l[n], nl, m, gl, gr, c); n       return c; n     } n     assert(false); n     return -1; n   } n   int qry(int gl, int gr) { return qry(0, 0, sz, gl, gr); } n } st; n void q1() { n   int l, r, v; n   scanf( %d%d%d , &l, &r, &v); n   if (v & 1) st.upd(--l, r); n } n void q2() { n   int l, r; n   scanf( %d%d , &l, &r); n   printf( %d n , (st.qry(--l, r) == 0 ? 2 : 1)); n } n int main() { n   scanf( %d%d%d , &N, &M, &Q); n   for (int i = 0, v; i < N; i++) { n     scanf( %d , &v); n     a[i] = v & 1; n   } n   st = *(new ST(N, true)); n   for (int i = 0, type; i < Q; i++) { n     scanf( %d , &type); n     if (type == 1) n       q1(); n     else if (type == 2) n       q2(); n   } n   return 0; n } n


#include <bits/stdc++.h> n const int N = (int)2e5 + 5; n const int MOD = (int)1e9 + 7; n const bool MULTI_TEST = true; n const double PI = acos(-1.0); n using namespace std; n void solve() { n   int n; n   cin >> n; n   int a[n]; n   int max = 0, index = -1; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] > max) { n       max = a[i]; n     } n   } n   if (*min_element(a, a + n) == max) n     cout <<  -1 n ; n   else { n     for (int i = 0; i < n - 1; i++) { n       if (a[i] == max && a[i] > a[i + 1]) index = i + 1; n     } n     if (index != -1) { n       cout << index <<   n ; n       return; n     } else { n       for (int i = 1; i < n; i++) { n         if (a[i] == max && a[i] > a[i - 1]) index = i + 1; n       } n     } n     cout << index << endl; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   int t = 1; n   if (MULTI_TEST) cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[100500], c[300], dp[100500][305], z, cnt, tmp, e, s, l, r, n, m, x, n     y, k, j, p, k1, k2, i, cur, rez; n vector<long long> f[100500]; n long long Abs(long long x) { n   if (x < 0) return -x; n   return x; n } n int main() { n   cin >> n >> m >> s >> e; n   for (i = 0; i < n; i++) cin >> a[i]; n   for (j = 0; j < m; j++) { n     cin >> x; n     f[x].push_back(j); n   } n   for (i = 0; i <= n; i++) n     for (j = 0; j <= s / e; j++) dp[i][j] = m + 1; n   dp[0][0] = -1; n   for (i = 0; i < n; i++) { n     for (j = 0; j <= s / e; j++) n       if (dp[i][j] != m + 1) { n         long long tmp = upper_bound(f[a[i]].begin(), f[a[i]].end(), dp[i][j]) - n                         f[a[i]].begin(); n         if (tmp != f[a[i]].size()) n           dp[i + 1][j + 1] = min(dp[i + 1][j + 1], f[a[i]][tmp]); n         dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); n       } n   } n   rez = 0; n   for (i = 0; i <= n; i++) { n     for (j = 0; j <= s / e; j++) { n       if (i + dp[i][j] + 1 + j * e <= s && dp[i][j] != m + 1) rez = max(rez, j); n     } n   } n   cout << rez << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct data { n   float x, a; n } h[1005]; n bool cmp(data a, data b) { return a.x < b.x; }; n int main() { n   int n, ans = 2; n   float t, d; n   cin >> n >> t; n   for (int i = 1; i <= n; i++) cin >> h[i].x >> h[i].a; n   sort(h + 1, h + n + 1, cmp); n   for (int i = 1; i < n; i++) { n     d = h[i + 1].x - h[i].x - h[i].a / 2 - h[i + 1].a / 2; n     if (d > t) ans += 2; n     if (abs(d - t) < 1e-6) ans++; n   } n   cout << ans << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n template <typename T> n using minpq = priority_queue<T, vector<T>, greater<T>>; n const int N = 5e5 + 5; n int n; n long long a[N], x; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   for (int i = (0); i < ((n + 1) / 2); i++) cin >> a[i]; n   cin >> x; n   long long sum = 0, mn = n / 2 + 1, mx = n; n   vector<pair<long long, long long>> ve; n   for (int i = (n + 1) / 2 - 1; i >= 0; i--) { n     sum += a[i]; n     if (x > 0) { n       if (sum <= 0) { n         mn = max(mn, n                  min((long long)n - i + 1, (-sum + x) / x + (n + 1) / 2 - i)); n       } n     } else if (x < 0) { n       if (sum > 0) { n         long long val = (sum - x - 1) / -x - 1 + (n + 1) / 2 - i; n         if (n - i + 1 > val) { n           ve.emplace_back(val + 1, n - i); n         } n       } else { n         mn = max(mn, (long long)n - i + 1); n       } n     } else if (sum <= 0) { n       mn = max(mn, (long long)n - i + 1); n     } n   } n   reverse((ve).begin(), (ve).end()); n   for (auto &p : ve) { n     if (p.first <= mx && mx <= p.second) { n       mx = p.first - 1; n     } n   } n   if (mn <= mx) { n     cout << mx <<   n ; n   } else { n     cout <<  -1 n ; n   } n } n