#include <bits/stdc++.h> n using namespace std; n long long exp(long long a, long long n) { n   if (n == 0) return 1; n   long long residue = 1, result = a % 1000000007LL; n   while (n > 1LL) { n     if (n % 2LL == 1LL) residue = residue * result % 1000000007LL; n     result = result * result % 1000000007LL; n     n = n >> 1LL; n   } n   return residue * result % 1000000007LL; n } n void sieve(long long n, vector<bool> &isPrime) { n   for (int i = 0; i <= n; i++) isPrime[i] = true; n   isPrime[0] = isPrime[1] = false; n   for (long long i = 2; i * i <= n; i++) { n     if (!isPrime[i]) continue; n     for (long long j = i * i; j <= n; j += i) { n       isPrime[j] = false; n     } n   } n } n long long nc2(long long n) { return (n * (n - 1LL) / 2LL) % 1000000007LL; } n bool checkPal(string s) { n   string t = s; n   reverse(s.begin(), s.end()); n   if (s == t) n     return true; n   else n     return false; n } n void rev(int i, int k, string &s) { n   int last = (i + k) / 2; n   for (int t = i; t <= last; t++) { n     swap(s[t], s[k - (t - i)]); n   } n } n int len(string &s) { return s.size(); } n vector<int> KMP_preprocessing(string test1) { n   vector<int> preprocess; n   int i = 0, j = 1; n   preprocess.push_back(0); n   int len1 = len(test1); n   while (i < len1 and j < len1) { n     if (test1[i] == test1[j]) { n       preprocess.push_back(i + 1); n       i += 1; n       j += 1; n     } else { n       while (i != 0 and test1[i] != test1[j]) { n         i = preprocess[i - 1]; n       } n       if (test1[i] == test1[j]) { n         preprocess.push_back(i + 1); n         i += 1; n         j += 1; n       } else n         preprocess.push_back(0), j += 1; n     } n   } n   return preprocess; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL), cout.tie(NULL); n   int n, k; n   vector<int> a(200001); n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> a[i]; n   priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, n                  greater<pair<int, pair<int, int>>>> n       minq; n   int last = -1; n   int ans; n   for (int i = 0; i < n; i++) { n     if (a[i] <= -1) { n       if (last != -1) n         minq.push(make_pair(i - last - 1, make_pair(last + 1, i - 1))); n       last = i; n     } n   } n   if (last != -1 && minq.size() + 1 > k) { n     cout << -1 << endl; n     return 0; n   } n   k -= minq.size() + 1; n   while (minq.size() > 0 && n          (minq.top().first == 0 || minq.top().second.first == 0)) { n     minq.pop(); n   } n   ans = 2 * minq.size(); n   while (minq.size() > 0 && minq.top().first <= k) { n     ans -= 2; n     k -= minq.top().first; n     minq.pop(); n   } n   if (last != -1) { n     ans++; n     if (k < n - last - 1) { n       ans++; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC target( avx,tune=native ) n using namespace std; n template <class T> n ostream &operator<<(ostream &os, vector<T> V) { n   os <<  [ ; n   for (auto const &vv : V) os << vv <<  , ; n   os <<  ] ; n   return os; n } n template <class L, class R> n ostream &operator<<(ostream &os, pair<L, R> P) { n   os <<  (  << P.first <<  ,  << P.second <<  ) ; n   return os; n } n template <typename T> n inline void print_128(T num) { n   if (!num) return; n   print_128(num / 10); n   cout.put((num % 10) +  0 ); n } n inline int fstoi(const string &str) { n   auto it = str.begin(); n   bool neg = 0; n   int num = 0; n   if (*it ==  - ) n     neg = 1; n   else n     num = *it -  0 ; n   ++it; n   while (it < str.end()) num = num * 10 + (*it++ -  0 ); n   if (neg) num *= -1; n   return num; n } n inline void getch(char &x) { n   while (x = getchar_unlocked(), x < 33) { n     ; n   } n } n inline void getstr(string &str) { n   str.clear(); n   char cur; n   while (cur = getchar_unlocked(), cur < 33) { n     ; n   } n   while (cur > 32) { n     str += cur; n     cur = getchar_unlocked(); n   } n } n template <typename... Args> n inline void getstr(string &str, Args &...arg) { n   str.clear(); n   char cur; n   while (cur = getchar_unlocked(), cur < 33) { n     ; n   } n   while (cur > 32) { n     str += cur; n     cur = getchar_unlocked(); n   } n   getstr(arg...); n } n template <typename T> n inline bool sc(T &num) { n   bool neg = 0; n   int c; n   num = 0; n   while (c = getchar_unlocked(), c < 33) { n     if (c == EOF) return false; n   } n   if (c ==  - ) { n     neg = 1; n     c = getchar_unlocked(); n   } n   for (; c > 47; c = getchar_unlocked()) num = num * 10 + c - 48; n   if (neg) num *= -1; n   return true; n } n template <typename T, typename... Args> n inline void sc(T &num, Args &...args) { n   bool neg = 0; n   int c; n   num = 0; n   while (c = getchar_unlocked(), c < 33) { n     ; n   } n   if (c ==  - ) { n     neg = 1; n     c = getchar_unlocked(); n   } n   for (; c > 47; c = getchar_unlocked()) num = num * 10 + c - 48; n   if (neg) num *= -1; n   sc(args...); n } n template <typename T> n inline T mod(T i, T n) { n   return (i % n + n) % n; n } n inline void chkmax(int &a, const int &b) { n   if (b > a) a = b; n } n inline void chkmin(int &a, const int &b) { n   if (b < a) a = b; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, l, r, k, t; n   int posa[100001]; n   int posb[100001]; n   memset(posa, 127, sizeof posa); n   memset(posb, 127, sizeof posb); n   sc(n); n   while (n--) { n     sc(t, l, r); n     --r; n     if (t == 1) { n       sc(k); n       if (k > 0) { n         int count = r - l + 1; n         int n = (count + 7) >> 3; n         int i = l; n         switch (count % 8) { n           case 0: n             do { n               chkmin(posa[i], k); n               ++i; n               case 7: n                 chkmin(posa[i], k); n                 ++i; n               case 6: n                 chkmin(posa[i], k); n                 ++i; n               case 5: n                 chkmin(posa[i], k); n                 ++i; n               case 4: n                 chkmin(posa[i], k); n                 ++i; n               case 3: n                 chkmin(posa[i], k); n                 ++i; n               case 2: n                 chkmin(posa[i], k); n                 ++i; n               case 1: n                 chkmin(posa[i], k); n                 ++i; n             } while (--n > 0); n         } n       } else { n         k = -k; n         int count = r - l + 1; n         int n = (count + 7) >> 3; n         int i = l; n         switch (count % 8) { n           case 0: n             do { n               chkmin(posb[i], k); n               ++i; n               case 7: n                 chkmin(posb[i], k); n                 ++i; n               case 6: n                 chkmin(posb[i], k); n                 ++i; n               case 5: n                 chkmin(posb[i], k); n                 ++i; n               case 4: n                 chkmin(posb[i], k); n                 ++i; n               case 3: n                 chkmin(posb[i], k); n                 ++i; n               case 2: n                 chkmin(posb[i], k); n                 ++i; n               case 1: n                 chkmin(posb[i], k); n                 ++i; n             } while (--n > 0); n         } n       } n     } else { n       long long ans = 0; n       int count = r - l + 1; n       int i = l; n       int n = (count + 7) >> 3; n       switch (count % 8) { n         case 0: n           do { n             if (posa[i] < 0x7F7F7F7F && posb[i] < 0x7F7F7F7F) n               ans += posa[i] + posb[i]; n             ++i; n             case 7: n               if (posa[i] < 0x7F7F7F7F && posb[i] < 0x7F7F7F7F) n                 ans += posa[i] + posb[i]; n               ++i; n             case 6: n               if (posa[i] < 0x7F7F7F7F && posb[i] < 0x7F7F7F7F) n                 ans += posa[i] + posb[i]; n               ++i; n             case 5: n               if (posa[i] < 0x7F7F7F7F && posb[i] < 0x7F7F7F7F) n                 ans += posa[i] + posb[i]; n               ++i; n             case 4: n               if (posa[i] < 0x7F7F7F7F && posb[i] < 0x7F7F7F7F) n                 ans += posa[i] + posb[i]; n               ++i; n             case 3: n               if (posa[i] < 0x7F7F7F7F && posb[i] < 0x7F7F7F7F) n                 ans += posa[i] + posb[i]; n               ++i; n             case 2: n               if (posa[i] < 0x7F7F7F7F && posb[i] < 0x7F7F7F7F) n                 ans += posa[i] + posb[i]; n               ++i; n             case 1: n               if (posa[i] < 0x7F7F7F7F && posb[i] < 0x7F7F7F7F) n                 ans += posa[i] + posb[i]; n               ++i; n           } while (--n > 0); n       } n       cout << ans <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ,  unroll-all-loops ) n #pragma GCC target( sse4.2 ) n using namespace std; n ifstream in; n ofstream out; n const long long kk = 1000; n const long long ml = kk * kk; n const long long mod = ml * kk + 7; n const long long inf = ml * ml * ml + 7; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n struct Tree { n   int s = 1; n   int n = 0; n   long long my_null = -mod; n   vector<pair<long long, long long>> t; n   vector<pair<long long, long long>> seg; n   inline long long res(long long v1, long long v2) { return max(v1, v2); } n   void cnt_seg() { n     seg.resize(2 * s); n     seg[1] = {0, s}; n     for (int i = 1; i < s; i++) { n       int tm = seg[i].first + seg[i].second >> 1; n       seg[2 * i] = {seg[i].first, tm}; n       seg[2 * i + 1] = {tm, seg[i].second}; n     } n   } n   void build(long long sz) { n     n = sz; n     while (s < n) s <<= 1; n     t.resize(2 * s, {my_null, 0}); n     cnt_seg(); n   } n   void build(vector<int> v) { n     n = v.size(); n     while (s < n) s <<= 1; n     t.resize(2 * s, {my_null, 0}); n     for (int i = 0; i < n; i++) t[s + i] = {v[i], 0}; n     for (int i = s - 1; i > 0; i--) upd(i); n     cnt_seg(); n   } n   inline void adder(int v, long long val) { n     t[v].first += val; n     t[v].second += val; n   } n   void upd(int v) { n     if (v >= s) return; n     t[v].first = res(t[2 * v].first, t[2 * v + 1].first); n   } n   void push(int v) { n     if (v >= s) return; n     long long psh = t[v].second; n     if (psh == 0) return; n     t[v].second = 0; n     adder(2 * v, psh); n     adder(2 * v + 1, psh); n   } n   long long val(int l, int r, int v, int tl, int tr) { n     if (r <= tl || tr <= l) return my_null; n     push(v); n     if (l <= tl && tr <= r) return t[v].first; n     int tm = tl + tr >> 1; n     long long v1 = val(l, r, 2 * v, tl, tm); n     long long v2 = val(l, r, 2 * v + 1, tm, tr); n     upd(v); n     return res(v1, v2); n   } n   long long val(int l, int r) { return val(l, r + 1, 1, 0, s); } n   long long val(int pl) { return val(pl, pl + 1, 1, 0, s); } n   void add(int l, int r, int v, int tl, int tr, long long val) { n     if (r <= tl || tr <= l) return; n     push(v); n     if (l <= tl && tr <= r) return void(adder(v, val)); n     int tm = tl + tr >> 1; n     add(l, r, 2 * v, tl, tm, val); n     add(l, r, 2 * v + 1, tm, tr, val); n     upd(v); n   } n   void add(int v, long long val) { n     v += s; n     t[v].first += val; n     v >>= 1; n     while (v) upd(v), v >>= 1; n   } n   void add(int l, int r, long long t) { add(l, r + 1, 1, 0, s, t); } n   void show() { n     for (long long i = 1; i < 2 * s; i++) { n       cout <<   t  <<  {  << t[i].first <<       << t[i].second <<  }  ; n       if ((i & (i + 1)) == 0) cout << endl; n     } n   } n }; n int n, m, q; n vector<int> val; n vector<int> ver_by_val; n vector<vector<int>> e; n vector<pair<int, int>> all; n vector<pair<int, int>> qr; n bool viv = false; n vector<int> p; n vector<vector<int>> kids; n int nxt; n vector<int> spliter; n vector<int> value_st; n Tree st; n set<pair<int, int>> seg; n void read() { n   cin >> n >> m >> q; n   val.resize(n); n   ver_by_val.resize(n); n   for (auto &i : val) cin >> i, i--; n   for (int i = 0; i < n; i++) ver_by_val[val[i]] = i; n   e.resize(n); n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     a--, b--; n     e[a].push_back(b); n     e[b].push_back(a); n     all.push_back({a, b}); n   } n   qr.resize(q); n   set<int> left; n   for (int i = 0; i < m; i++) left.insert(i); n   for (auto &p : qr) { n     cin >> p.first >> p.second; n     p.first--; n     p.second--; n     if (p.first) left.erase(p.second); n   } n   for (auto ed : left) qr.push_back({1, ed}); n   q = qr.size(); n } n int pr(int v) { n   if (p[v] == v) return v; n   return p[v] = pr(p[v]); n } n bool unit(int v, int u) { n   v = pr(v); n   u = pr(u); n   if (v == u) return false; n   int s = nxt++; n   kids[s].push_back(v); n   kids[s].push_back(u); n   p[v] = s; n   p[u] = s; n   return true; n } n void prepare() { n   p.resize(2 * n - 1); n   kids.resize(2 * n - 1); n   for (int i = 0; i < p.size(); i++) p[i] = i; n   nxt = n; n   vector<long long> ord; n   for (auto p : qr) n     if (p.first) ord.push_back(p.second); n   reverse(ord.begin(), ord.end()); n   for (auto num : ord) { n     int v = all[num].first; n     int u = all[num].second; n     if (unit(v, u)) n       spliter.push_back(nxt - 1); n     else n       spliter.push_back(-1); n   } n   if (viv) { n     for (int i = 0; i < nxt; i++) { n       cout <<  kids[  << i <<  ] =  ; n       for (auto v : kids[i]) cout << v <<    ; n       cout << endl; n     } n     cout <<  Spliter =  ; n     for (auto i : spliter) cout << i <<    ; n     cout << endl; n   } n } n vector<int> tin, tout; n int t = 0; n void DFS(int v) { n   int my_val = -mod; n   if (v < n) my_val = val[v]; n   value_st[t] = my_val; n   tin[v] = t++; n   for (auto u : kids[v]) n     if (tin[u] == -1) DFS(u); n   value_st[t] = my_val; n   tout[v] = t++; n } n void build() { n   tin.resize(nxt, -1); n   tout.resize(nxt, -1); n   value_st.resize(2 * nxt); n   for (int i = nxt - 1; i >= 0; i--) { n     if (tin[i] == -1) { n       DFS(i); n       seg.insert({tin[i], tout[i]}); n     } n   } n   st.build(value_st); n   if (viv) { n     for (int i = 0; i < nxt; i++) { n       cout <<  seg[  << i <<  ] =   << tin[i] <<     << tout[i] << endl; n     } n   } n } n bool out_seg(int p, pair<int, int> seg) { n   if (p < seg.first || seg.second < p) return true; n   return false; n } n void work() { n   if (viv) st.show(); n   for (auto p : qr) { n     if (p.first) { n       int s = spliter.back(); n       spliter.pop_back(); n       if (s != -1) { n         int v = kids[s][0]; n         int u = kids[s][1]; n         if (viv) { n           cout <<  split vertex   << s <<   on   << v <<   and   << u << endl; n         } n         seg.erase({tin[s], tout[s]}); n         seg.insert({tin[v], tout[v]}); n         seg.insert({tin[u], tout[u]}); n         if (viv) { n           for (auto p : seg) n             cout <<  {  << p.first <<  ,   << p.second <<  },  ; n           cout << endl; n         } n       } n     } else { n       int v = p.second; n       int pl = tin[v]; n       if (viv) cout <<  find for   << v <<   include   << tin[v] << endl; n       auto z = seg.lower_bound({pl, pl}); n       while (out_seg(pl, *z)) z--; n       auto pr = *z; n       int l = pr.first; n       int r = pr.second; n       auto ans = st.val(l, r); n       if (ans >= 0) { n         cout << ans + 1 <<   n ; n         v = ver_by_val[ans]; n         st.add(tin[v], tin[v], -mod); n         st.add(tout[v], tout[v], -mod); n         if (viv) st.show(); n       } else { n         cout <<  0 n ; n       } n     } n   } n } n void solve() { n   read(); n   prepare(); n   build(); n   work(); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, x, y; n   cin >> n >> m >> x >> y; n   vector<vector<int>> chessboard(n, vector<int>(m)); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) chessboard[i][j] = 0; n   cout << x <<     << y << endl; n   chessboard[x - 1][y - 1] = 1; n   if (chessboard[0][y - 1] == 0) cout << 1 <<     << y << endl; n   chessboard[0][y - 1] = 1; n   if (chessboard[0][0] == 0) cout << 1 <<     << 1 << endl; n   chessboard[0][0] = 1; n   int j = 0; n   for (int i = 0; i < n; i++) { n     if (j == m) j--; n     if (j < 0) j++; n     bool plus = (j == 0); n     while (j >= 0 && j < m) { n       if (chessboard[i][j] == 0) { n         cout << i + 1 <<     << j + 1 << endl; n         chessboard[i][j] = 1; n       } n       (plus) ? j++ : j--; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<string> strs; n   int n = 0; n   int j = 0; n   int count = 0; n   cin >> n; n   for (int i = 0; i < n; i++) { n     if (i != 0) { n       string temp =   ; n       cin >> temp; n     } n     string str1 =   ; n     string str2 =   ; n     string str3 =   ; n     string str4 =   ; n     string str5 =   ; n     string str6 =   ; n     cin >> str1 >> str2; n     str3 += str1.at(0); n     str3 += str1.at(1); n     str3 += str2.at(0); n     str3 += str2.at(1); n     str3 += str3; n     str4 += str2.at(0); n     str4 += str1.at(0); n     str4 += str2.at(1); n     str4 += str1.at(1); n     str4 += str4; n     str5 += str2.at(1); n     str5 += str2.at(0); n     str5 += str1.at(1); n     str5 += str1.at(0); n     str5 += str5; n     str6 += str1.at(1); n     str6 += str2.at(1); n     str6 += str1.at(0); n     str6 += str2.at(0); n     str6 += str6; n     if (i == 0) { n       strs.push_back(str3); n       strs.push_back(str4); n       strs.push_back(str5); n       strs.push_back(str6); n       count++; n     } else { n       bool check = false; n       for (int j = 0; j < strs.size(); j++) { n         if (!strs[j].find(str1 + str2)) { n           check = true; n           break; n         } n       } n       if (!check) { n         strs.push_back(str3); n         strs.push_back(str4); n         strs.push_back(str5); n         strs.push_back(str6); n         count++; n       } n     } n   } n   cout << count << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e2 + 5; n int n; n long long hx, hy; n long long ux, uy; n struct line { n   long long x1, y1; n   long long x2, y2; n   line(long long _x1, long long _y1, long long _x2, long long _y2) { n     x1 = _x1; n     y1 = _y1; n     x2 = _x2; n     y2 = _y2; n   } n }; n vector<line> lines; n void get_line(long long a, long long b, long long c) { n   long long x1, y1; n   long long x2, y2; n   if (b == 0) { n     x1 = -c / a; n     x2 = -c / a; n     y1 = -1e7; n     y2 = 1e7; n   } n   if (a == 0) { n     y1 = -c / b; n     y2 = -c / b; n     x1 = -1e7; n     x2 = 1e7; n   } n   if (a != 0 && b != 0) { n     x1 = -1e7; n     x2 = 1e7; n     y1 = (-a * x1 - c) / b; n     y2 = (-a * x2 - c) / b; n   } n   lines.push_back(line(x1, y1, x2, y2)); n } n struct point { n   long long x; n   long long y; n   point() { n     x = 0; n     y = 0; n   } n   point(long long _x, long long _y) { n     x = _x; n     y = _y; n   } n }; n int orientation(point a, point b, point c) { n   long long clockwise = (b.y - a.y) * (c.x - b.x) - (c.y - b.y) * (b.x - a.x); n   if (clockwise > 0) return 1; n   if (clockwise == 0) return 0; n   if (clockwise < 0) return -1; n } n bool do_intersect(line a, line b) { n   point a1, a2; n   point b1, b2; n   a1 = point(a.x1, a.y1); n   a2 = point(a.x2, a.y2); n   b1 = point(b.x1, b.y1); n   b2 = point(b.x2, b.y2); n   if ((orientation(a1, a2, b1) != orientation(a1, a2, b2)) && n       (orientation(b1, b2, a1) != orientation(b1, b2, a2))) n     return true; n   return false; n } n int ans; n int main() { n   int i; n   long long a, b, c; n   cin >> hx >> hy; n   cin >> ux >> uy; n   cin >> n; n   for (i = 1; i <= n; i++) { n     scanf( %I64d%I64d%I64d , &a, &b, &c); n     get_line(a, b, c); n   } n   line road = line(hx, hy, ux, uy); n   for (i = 0; i < lines.size(); i++) { n     if (do_intersect(road, lines[i])) ans++; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL), cout.tie(NULL); n   int n, t, num, x; n   long long int ans; n   cin >> n; n   vector<int> vect; n   vect.push_back(0); n   for (int i = 0; i < n; ++i) { n     cin >> x; n     vect.push_back(x); n   } n   long long int dp[n]; n   dp[1] = vect[1]; n   t = log2(n - 1); n   num = 1 + pow(2, t); n   vect[num] += vect[1]; n   for (int i = 2; i <= n - 1; ++i) { n     dp[i] = dp[i - 1] + vect[i]; n     t = log2(n - i); n     num = i + pow(2, t); n     vect[num] += vect[i]; n   } n   for (int i = 1; i < n; ++i) cout << dp[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n void err() { std::cout << std::endl; } n template <typename T, typename... Args> n void err(T a, Args... args) { n   std::cout << a <<    ; n   err(args...); n } n template <template <typename...> class T, typename t, typename... A> n void err(const T<t> &arg, const A &...args) { n   for (auto &v : arg) std::cout << v <<    ; n   err(args...); n } n using namespace std; n const int N = 1e5 + 5; n void run() { n   string s, t; n   cin >> s >> t; n   int n = s.length(), m = t.length(); n   vector<int> nxt(n, -1); n   for (int i = 0; i < n; i++) n     if (s[i] !=  . ) { n       int t = 0; n       for (int j = i; j < n; j++) { n         if (s[j] !=  . ) n           ++t; n         else n           --t; n         if (t == 0) { n           nxt[i] = j; n           break; n         } n       } n     } n   vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0x3f3f3f3f)); n   dp[0][0] = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j <= m; j++) { n       if (j < m && s[i] == t[j]) { n         dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]); n       } n       dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1); n       if (s[i] !=  .  && nxt[i] != -1) { n         dp[nxt[i] + 1][j] = min(dp[nxt[i] + 1][j], dp[i][j]); n       } n     } n   } n   cout << dp[n][m] <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cout << fixed << setprecision(20); n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, k; n   cin >> n >> k; n   int cnt = 1; n   if (k & 1) n     puts( 1 ); n   else { n     do { n       k /= 2; n       cnt++; n     } while (k % 2 != 1); n     cout << cnt; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, root; n vector<vector<int> > tree, par, sub; n vector<vector<long long> > dp; n void dfs(int u) { n   sub[root][u] = 1; n   for (int v : tree[u]) { n     if (v == par[root][u]) continue; n     par[root][v] = u; n     dfs(v); n     sub[root][u] += sub[root][v]; n   } n } n long long getDP(int u, int v) { n   if (u == v) return 0; n   if (dp[u][v] != -1) return dp[u][v]; n   long long res = n       sub[u][v] * sub[v][u] + max(getDP(par[v][u], v), getDP(u, par[u][v])); n   return dp[u][v] = res; n } n void input() { n   scanf( %d , &n); n   tree.assign(n, vector<int>()); n   for (int i = 0; i < n - 1; ++i) { n     int u, v; n     scanf( %d%d , &u, &v); n     --u, --v; n     tree[u].push_back(v); n     tree[v].push_back(u); n   } n } n void solve() { n   par.assign(n, vector<int>(n, -1)); n   sub.assign(n, vector<int>(n, -1)); n   for (int u = 0; u < n; ++u) { n     root = u; n     dfs(u); n   } n   dp.assign(n, vector<long long>(n, -1LL)); n   long long ans = 0; n   for (int u = 0; u < n; ++u) n     for (int v = 0; v < n; ++v) ans = max(ans, getDP(u, v)); n   cout << ans << endl; n } n int main() { n   input(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n, i, j, k, l, m, b, t, sum, sum1, flag, max1, min1, tmp; n   cin >> n; n   long long a[n + 1]; n   vector<long long> v; n   queue<long long> q; n   for (i = 1; i <= n; i++) { n     cin >> a[i]; n     v.push_back(a[i]); n     q.push(a[i]); n   } n   cin >> m >> k; n   j = m + k; n   sum = 0; n   for (i = 1; i <= n; i++) { n     l = a[i] / j; n     sum1 = a[i] % j; n     sum += l; n     if (sum1 > m) { n       sum++; n     } n   } n   cout << sum * k << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, sum = 0; n   cin >> n; n   map<string, int> mp; n   mp[ Tetrahedron ] = 4; n   mp[ Cube ] = 6; n   mp[ Octahedron ] = 8; n   mp[ Dodecahedron ] = 12; n   mp[ Icosahedron ] = 20; n   while (n--) { n     string s; n     cin >> s; n     sum += mp[s]; n   } n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double A[100], B[100]; n int main() { n   int n, V; n   cin >> n >> V; n   double S = 0.0; n   for (int i = 0; i < n; i++) { n     cin >> A[i]; n     S += A[i]; n   } n   for (int i = 0; i < n; i++) A[i] *= V / S; n   double MIN = 1.0; n   for (int i = 0; i < n; i++) { n     cin >> B[i]; n     MIN = min(MIN, B[i] / A[i]); n   } n   double result = 0.0; n   for (int i = 0; i < n; i++) result += A[i] * MIN; n   cout.precision(10); n   cout << result; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<char, int> m; n map<char, int> m1; n int main() { n   long long int n = 0, d, i = 0, j = 0, l = 0, r = 0, a = 0, b = 0, c1, c2, p, n                 b2, s1 = 0, t = 0, t1 = 0, y = 0, x = 0, s2 = 0, c = 0; n   char ch; n   cin >> a >> b >> c; n   vector<int> adj[100001]; n   int s[3]; n   s[0] = a; n   s[1] = b; n   s[2] = c; n   n = 3; n   sort(s, s + n); n   a = s[2]; n   b = s[1]; n   c = s[0]; n   if (a >= (b + c)) { n     while (a >= b + c) { n       t++; n       c++; n     } n   } n   if (b >= a + c) { n     while (b >= a + c) { n       t++; n       c++; n     } n   } n   if (c >= b + a) { n     while (c >= b + a) { n       t++; n       b++; n     } n   } n   cout << t << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void mnm(T &a, T b) { n   a = min(a, b); n }; n template <typename T> n void mxm(T &a, T b) { n   a = max(a, b); n }; n template <typename T> n int discrete_id(vector<T> &vals, T val, int startId = 1) { n   return startId + n          (int)(lower_bound(vals.begin(), vals.end(), val) - vals.begin()); n } n long long power(long long a, long long n, long long mod) { n   long long ans = 1; n   while (n) { n     if (n & 1) ans = (ans * a) % mod; n     a = (a * a) % mod; n     n /= 2; n   } n   return ans; n } n long long modul(long long x, long long mod) { n   x %= mod; n   if (x < 0) x += mod; n   return x; n } n tuple<long long, long long, long long> eea(long long x, long long y) { n   if (y == 0) return {1LL, 0LL, x}; n   long long a, b, d, q = x / y; n   tie(a, b, d) = eea(y, x % y); n   return {b, a - b * q, d}; n } n long long inv(long long x, long long m) { n   long long a, b, d; n   tie(a, b, d) = eea(x, m); n   assert(d == 1); n   return modul(a, m); n } n char i2c(int c) { return (char)(c +  0 ); } n int get_subtree_sz(int u, int pa, vector<vector<pair<int, int>>> &adj, n                    vector<bool> &deleted, vector<int> &subsz) { n   subsz[u] = 1; n   for (auto e : adj[u]) { n     int v = e.first; n     if (v != pa && !deleted[v]) { n       subsz[u] += get_subtree_sz(v, u, adj, deleted, subsz); n     } n   } n   return subsz[u]; n } n int get_centroid(int u, int pa, int desired, n                  vector<vector<pair<int, int>>> &adj, vector<bool> &deleted, n                  vector<int> &subsz) { n   for (auto e : adj[u]) { n     int v = e.first; n     if (v != pa && !deleted[v] && subsz[v] > desired) { n       return get_centroid(v, u, desired, adj, deleted, subsz); n     } n   } n   return u; n } n int neg(int u, int mod) { return (mod - u) % mod; } n void visit(int u, int pa, vector<vector<pair<int, int>>> &adj, n            vector<bool> &deleted, map<int, int> &need_up, map<int, int> &cnt_up, n            long long &ans, bool add, int _10pd, int _10pmd, int inv10, n            int cur_up, int cur_down, int m, int depth = 1) { n   if (add) { n     ans += cnt_up[(1LL * neg(cur_down, m) * _10pmd) % m]; n     ans += need_up[cur_up]; n   } else { n     ++cnt_up[cur_up]; n     ++need_up[(1LL * neg(cur_down, m) * _10pmd) % m]; n   } n   for (auto e : adj[u]) { n     int v, w; n     tie(v, w) = e; n     if (v != pa && !deleted[v]) { n       w %= m; n       int new_down = (10LL * cur_down + w) % m; n       int new_up = (1LL * w * _10pd + cur_up) % m; n       visit(v, u, adj, deleted, need_up, cnt_up, ans, add, (10LL * _10pd) % m, n             (1LL * inv10 * _10pmd) % m, inv10, new_up, new_down, m, depth + 1); n     } n   } n } n long long centroid_decomp(int u, vector<vector<pair<int, int>>> &adj, n                           vector<bool> &deleted, vector<int> &subsz, n                           map<int, int> &need_up, map<int, int> &cnt_up, int m, n                           int inv10) { n   u = get_centroid(u, 0, get_subtree_sz(u, 0, adj, deleted, subsz) / 2, adj, n                    deleted, subsz); n   deleted[u] = true; n   cnt_up[0] = 1; n   need_up[0] = 1; n   long long ans = 0; n   for (auto e : adj[u]) { n     int v, w; n     tie(v, w) = e; n     if (!deleted[v]) { n       w %= m; n       visit(v, u, adj, deleted, need_up, cnt_up, ans, true, 10 % m, inv10, n             inv10, w, w, m); n       visit(v, u, adj, deleted, need_up, cnt_up, ans, false, 10 % m, inv10, n             inv10, w, w, m); n     } n   } n   cnt_up.clear(); n   need_up.clear(); n   for (auto e : adj[u]) { n     int v = e.first; n     if (!deleted[v]) { n       long long tmp = n           centroid_decomp(v, adj, deleted, subsz, need_up, cnt_up, m, inv10); n       ans += tmp; n     } n   } n   return ans; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   cin >> n >> m; n   vector<vector<pair<int, int>>> adj(n + 1); n   for (int i = (int)(1); i <= (int)(n - 1); ++i) { n     int u, v, w; n     cin >> u >> v >> w; n     adj[u].emplace_back(v, w); n     adj[v].emplace_back(u, w); n   } n   vector<bool> deleted(n + 1, 0); n   vector<int> subsz(n + 1); n   map<int, int> need_up, cnt_up; n   long long a, b, d; n   tie(a, b, d) = eea(10LL, m); n   int inv10 = modul(a, m); n   cout << centroid_decomp(0, adj, deleted, subsz, need_up, cnt_up, m, inv10) n        <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n bool f1(pair<long long, long long> x, pair<long long, long long> y) { n   return x.first > y.first; n } n bool f2(pair<long long, long long> x, pair<long long, long long> y) { n   return x.second > y.second; n } n bool f3(long long x, long long y) { return x > y; } n bool fa(vector<long long> x, vector<long long> y) { return x[0] < y[0]; } n long long fac(long long a) { n   if (a == 1 || a == 0) { n     return 1; n   } else { n     return (a * fac(a - 1)); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   string a; n   cin >> a; n   vector<long long> b; n   if (a.size() == 1) { n     cout << a; n     exit(0); n   } n   a = a +  0 ; n   for (long long i = 0; i < a.size() - 1; i++) { n     if (a[i] == a[i + 1] && a[i] == a[i + 2]) { n       a[i] =  0 ; n     } n   } n   for (long long i = 0; i < a.size(); i++) { n     if (a[i] !=  0 ) b.push_back(a[i]); n   } n   vector<long long> c; n   long long check = 0; n   for (long long i = 0; i < b.size() - 1; i++) { n     if (b[i] == b[i + 1]) { n       c.push_back(i); n       check++; n     } n   } n   if (check > 0) { n     for (long long i = 0; i < c.size() - 1; i++) { n       if (c[i] == c[i + 1] - 2) { n         b[c[i + 1]] = 0; n         i++; n       } n     } n   } n   for (long long i = 0; i < b.size(); i++) { n     if (b[i] != 0) { n       char g = b[i]; n       cout << g; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n long long dx[] = {-1, 0, 1, 0}; n long long dy[] = {0, -1, 0, 1}; n long long msum(long long a, long long b, long long m) { n   return (a % m + b % m) % m; n } n long long msub(long long a, long long b, long long m) { n   return (a % m - b % m) % m; n } n long long mpro(long long a, long long b, long long m) { n   return ((a % m) * (b % m)) % m; n } n void swap(long long &a, long long &b) { n   long long t = a; n   a = b; n   b = t; n } n long long m_m(long long a, long long b, long long m) { n   long long res = 0; n   a = a % m; n   while (b) { n     if (b & 1) { n       res += a; n       res = res % m; n     } n     a = (a * 2) % m; n     b = b / 2; n   } n   return res; n } n long long fxp(long long a, long long b, long long m) { n   if (b == 0) return 1; n   if (b % 2 == 0) return fxp(m_m(a, a, m), b / 2, m); n   return m_m(fxp(a, b - 1, m), a, m); n } n bool sortbysecdesc(const pair<long long, long long> &a, n                    const pair<long long, long long> &b) { n   return a.second > b.second; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, m; n   cin >> n >> m; n   char a[n][m]; n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < m; j++) { n       cin >> a[i][j]; n     } n   } n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < m; j++) { n       if (a[i][j] ==  - ) n         cout << a[i][j]; n       else { n         if ((i + j) % 2 == 0) n           cout <<  B ; n         else n           cout <<  W ; n       } n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int dp[500005][28]; n int ar[500005]; n int p[500005][28]; n int ans[500005]; n string st; n int main() { n   int a, b, c, d, e, x, y, z, k, n; n   cin >> n >> k; n   cin >> st; n   for (a = 0; a < n; a++) ar[a + 1] = st[a] -  A ; n   for (a = 1; a <= n; a++) { n     for (b = 0; b < k; b++) { n       dp[a][b] = 500005; n     } n   } n   for (a = 1; a <= n; a++) { n     for (b = 0; b < k; b++) { n       if (ar[a] == b) n         c = 0; n       else n         c = 1; n       for (d = 0; d < k; d++) { n         if (b == d) continue; n         if (dp[a][b] > dp[a - 1][d] + c) { n           dp[a][b] = min(dp[a][b], dp[a - 1][d] + c); n           p[a][b] = d; n         } n       } n     } n   } n   x = 500005; n   for (a = 0; a < k; a++) n     if (x > dp[n][a]) { n       x = dp[n][a]; n       b = a; n     } n   cout << x << endl; n   a = n; n   while (a >= 1) { n     ans[a] = b; n     b = p[a][b]; n     a--; n   } n   for (a = 1; a <= n; a++) printf( %c , ans[a] +  A ); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> tree[300001]; n int cento[300001]; n int sub[300001]; n int maxCh[300001]; n int n, q; n void dfs(int u, int p = -1) { n   sub[u] = 1; n   maxCh[u] = 0; n   for (int j = 0; j < tree[u].size(); ++j) { n     int v = tree[u][j]; n     if (v == p) continue; n     dfs(v, u); n     sub[u] += sub[v]; n     maxCh[u] = max(maxCh[u], sub[v]); n   } n } n set<pair<pair<int, int>, int> > merge(int u, int p = -1) { n   int sz = tree[u].size(); n   if (sz == 1 && u != 0) { n     cento[u] = u; n     set<pair<pair<int, int>, int> > s; n     s.insert(make_pair(pair<int, int>(sub[u], maxCh[u]), u)); n     return s; n   } n   int bigCh = -1; n   int maxsz = -1; n   for (int j = 0; j < tree[u].size(); ++j) { n     int v = tree[u][j]; n     if (v == p) continue; n     if (maxsz < sub[v]) { n       maxsz = sub[v]; n       bigCh = v; n     } n   } n   set<pair<pair<int, int>, int> > s = merge(bigCh, u); n   for (int j = 0; j < tree[u].size(); ++j) { n     int v = tree[u][j]; n     if (v == p || v == bigCh) continue; n     set<pair<pair<int, int>, int> > tmp = merge(v, u); n     for (set<pair<pair<int, int>, int> >::iterator it = tmp.begin(); n          it != tmp.end(); ++it) { n       s.insert(*it); n     } n   } n   s.insert(make_pair(pair<int, int>(sub[u], maxCh[u]), u)); n   int x = sub[u] >> 1; n   ; n   if (sub[u] & 1) ++x; n   set<pair<pair<int, int>, int> >::iterator it = n       s.lower_bound(make_pair(pair<int, int>(x, 0), 0)); n   cento[u] = it->second; n   return s; n } n int main() { n   scanf( %d %d , &n, &q); n   int v = 0; n   for (int i = 1; i < n; ++i) { n     scanf( %d , &v); n     --v; n     tree[i].push_back(v); n     tree[v].push_back(i); n   } n   memset(cento, -1, sizeof(cento)); n   dfs(0, -1); n   for (int i = 0; i < n; ++i) { n     --sub[i]; n   } n   merge(0, -1); n   while (q--) { n     int u; n     scanf( %d , &u); n     --u; n     printf( %d n , cento[u] + 1); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 400005; n int tr[N << 2], lz[N << 2]; n set<int> st[N]; n inline void push(int v, int l, int r) { n   tr[v] += lz[v]; n   if (l != r) { n     lz[2 * v] += lz[v]; n     lz[2 * v + 1] += lz[v]; n   } n   lz[v] = 0; n } n void build(int v, int l, int r, int n) { n   lz[v] = 0; n   if (l == r) { n     tr[v] = l - 1; n     return; n   } n   int m = (l + r) / 2; n   build(2 * v, l, m, n); n   build(2 * v + 1, m + 1, r, n); n   tr[v] = max(tr[2 * v], tr[2 * v + 1]); n } n void update(int v, int s, int e, int l, int r, int x) { n   push(v, s, e); n   if (l <= s && e <= r) { n     tr[v] += x; n     if (s != e) { n       lz[2 * v] += x; n       lz[2 * v + 1] += x; n     } n     return; n   } n   if (r < s || e < l || l > r) return; n   int m = (s + e) / 2; n   update(2 * v, s, m, l, r, x); n   update(2 * v + 1, m + 1, e, l, r, x); n   tr[v] = max(tr[2 * v], tr[2 * v + 1]); n } n int query(int v, int s, int e, int l, int r) { n   push(v, s, e); n   if (l <= s && e <= r) return tr[v]; n   int m = (s + e) / 2; n   if (r <= m) return query(2 * v, s, m, l, r); n   if (m < l) return query(2 * v + 1, m + 1, e, l, r); n   return max(query(2 * v, s, m, l, r), query(2 * v + 1, m + 1, e, l, r)); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cout << setprecision(32); n   int n, k, m; n   cin >> n >> k >> m; n   int n2 = n << 1; n   build(1, 1, n2, n2); n   int x, y; n   map<int, int> mp; n   while (m--) { n     cin >> x >> y; n     y += abs(k - x); n     if (st[y].find(x) != st[y].end()) { n       update(1, 1, n2, 1, y, -1); n       st[y].erase(x); n       mp[y]--; n       if (!mp[y]) mp.erase(y); n     } else { n       update(1, 1, n2, 1, y, 1); n       st[y].insert(x); n       mp[y]++; n     } n     if (mp.empty()) { n       cout << 0 <<   n ; n       continue; n     } n     int mx = mp.rbegin()->first; n     cout << max(0, query(1, 1, n2, 1, mx) - n) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 5; n const int mod = 998244353; n long long qpow(long long a, long long b) { n   long long ans = 1; n   a %= mod; n   assert(b >= 0); n   for (; b; b >>= 1) { n     if (b & 1) ans = ans * a % mod; n     a = a * a % mod; n   } n   return ans; n } n long long gcd(long long a, long long b) { return b > 0 ? gcd(b, a % b) : a; } n int a[maxn]; n int w[maxn]; n int one, zero, num, sum; n long long dp[60][60][60][60]; n long long ans[60]; n int main() { n   int n, m, T; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) cin >> a[i], num += a[i]; n   for (int i = 1; i <= n; i++) n     cin >> w[i], sum = (sum + w[i]) % mod, one = (one + a[i] * w[i]) % mod; n   zero = (sum - one + mod) % mod; n   for (int i = 1; i <= n; i++) { n     if (a[i] == 0) { n       dp[1][i][0][1] = 1ll * qpow(sum, mod - 2) * w[i] % mod; n       dp[1][i][0][0] = 1ll * qpow(sum, mod - 2) * (zero - w[i]) % mod; n       dp[1][i][1][0] = 1ll * qpow(sum, mod - 2) * (one) % mod; n     } else { n       dp[1][i][1][1] = 1ll * qpow(sum, mod - 2) * w[i] % mod; n       dp[1][i][1][0] = 1ll * qpow(sum, mod - 2) * (one - w[i]) % mod; n       dp[1][i][0][0] = 1ll * qpow(sum, mod - 2) * (zero) % mod; n     } n   } n   for (int i = 1; i <= m; i++) { n     for (int j = 1; j <= n; j++) { n       for (int t = 0; t <= i; t++) { n         for (int k = 0; k <= i; k++) { n           int state = ((sum + t - (i - t)) % mod + mod) % mod; n           int o0 = zero - (i - t); n           int o1 = one + t; n           if (a[j] == 0) { n             dp[i + 1][j][t][k] += 1ll * dp[i][j][t][k] * qpow(state, mod - 2) % n                                   mod * (o0 - (w[j] - k)) % mod; n             dp[i + 1][j][t][k] %= mod; n             dp[i + 1][j][t][k + 1] += 1ll * dp[i][j][t][k] * n                                       qpow(state, mod - 2) % mod * n                                       ((w[j] - k)) % mod; n             dp[i + 1][j][t][k + 1] %= mod; n             dp[i + 1][j][t + 1][k] += n                 1ll * dp[i][j][t][k] * qpow(state, mod - 2) % mod * (o1) % mod; n             dp[i + 1][j][t + 1][k] %= mod; n           } else { n             dp[i + 1][j][t + 1][k] += 1ll * dp[i][j][t][k] * n                                       qpow(state, mod - 2) % mod * n                                       (o1 - (w[j] + k)) % mod; n             dp[i + 1][j][t + 1][k] %= mod; n             dp[i + 1][j][t + 1][k + 1] += 1ll * dp[i][j][t][k] * n                                           qpow(state, mod - 2) % mod * n                                           ((w[j] + k)) % mod; n             dp[i + 1][j][t + 1][k + 1] %= mod; n             dp[i + 1][j][t][k] += n                 1ll * dp[i][j][t][k] * qpow(state, mod - 2) % mod * (o0) % mod; n             dp[i + 1][j][t][k] %= mod; n           } n         } n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j <= m; j++) { n       for (int k = 0; k <= m; k++) { n         int temp = a[i] ? 1 : -1; n         ans[i] = (ans[i] + (w[i] + k * temp) * dp[m][i][j][k]) % mod; n       } n     } n     cout << (ans[i] + mod) % mod << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long n; n long long b[200005]; n long long cnt[65]; n vector<long long> vec, vec2; n int main(void) { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> b[i]; n   for (int i = 1; i <= n; i++) { n     long long x = 0; n     for (long long t = b[i]; t % 2 == 0; t /= 2) x++; n     cnt[x]++; n   } n   long long mn = -1e9, mn_i; n   for (int i = 0; i < 65; i++) { n     if (mn < cnt[i]) { n       mn = cnt[i]; n       mn_i = i; n     } n   } n   for (int i = 1; i <= n; i++) { n     if (!(b[i] % (1LL << mn_i) == 0 && b[i] % (1LL << (mn_i + 1)))) n       vec.push_back(b[i]); n   } n   cout << (int)vec.size() << endl; n   for (int i = 0; i < vec.size(); i++) cout << vec[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e9; n const long long N = 1e5 + 1; n const long long mod = 1e9 + 7; n const long double eps = 1E-7; n vector<int> a[N]; n int n, k, x, ans; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> k; n   for (int i = 1; i <= k; i++) cin >> x, a[x].push_back(i); n   for (int i = 1; i <= n; i++) { n     if (a[i].size() == 0) n       ans += 1 + (i != 1) + (i != n); n     else { n       x = a[i][0]; n       if (i != 1) n         if (upper_bound(a[i - 1].begin(), a[i - 1].end(), x) == a[i - 1].end()) n           ans++; n       if (i != n) n         if (upper_bound(a[i + 1].begin(), a[i + 1].end(), x) == a[i + 1].end()) n           ans++; n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void fast_io() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n } n signed main() { n   fast_io(); n   long long x, y, z, t1, t2, t3; n   cin >> x >> y >> z >> t1 >> t2 >> t3; n   long long time1 = abs(y - x) * t1; n   long long time2 = abs(x - z) * t2 + abs(y - x) * t2 + 3 * t3; n   if (time2 <= time1) { n     cout <<  YES ; n   } else { n     cout <<  NO ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> a[1000001]; n int b[1000001], ans[1000001]; n int main() { n   int n, h; n   cin >> n >> h; n   for (int i = 0; i < n; i++) { n     int c; n     cin >> c; n     a[i] = make_pair(c, i + 1); n   } n   sort(a, a + n); n   for (int i = 0; i < n; i++) b[i] = a[i].first; n   int diff = b[n - 1] + b[n - 2] - b[0] - b[1]; n   int km = 0; n   for (int k = 1; k < n; k++) { n     int other; n     int small = int(1e9); n     if (k >= 2) { n       other = b[1] + b[2]; n       if (other < small) small = other; n     } n     other = b[0] + b[1] + h; n     if (other < small) small = other; n     if (k < n - 1) { n       other = b[0] + b[k + 1]; n       if (other < small) small = other; n     } n     int big = b[n - 1] + h; n     if (k == n - 1) n       big += b[0]; n     else n       big += b[k]; n     other = b[n - 1] + b[n - 2]; n     if (other > big) big = other; n     if (big - small < diff) { n       diff = big - small; n       km = k; n     } n   } n   cout << diff << endl; n   for (int i = 1; i <= n; i++) ans[i] = 1; n   for (int i = 1; i <= km; i++) ans[a[i].second] = 2; n   for (int i = 1; i <= n; i++) cout << ans[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int power(int x, int y, int p) { n   int res = 1; n   x = x % p; n   if (x == 0) return 0; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n int main() { n   { n     ios_base::sync_with_stdio(0); n     cin.tie(NULL); n     cout.tie(NULL); n   }; n   long long k, x = 1; n   string s =  codeforces ; n   int arr[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; n   cin >> k; n   while (x < k) { n     for (int i = 0; i < 10; i++) { n       long long m = 1; n       for (int j = 0; j < 10; j++) n         if (j != i) m *= arr[j]; n       x += m; n       arr[i]++; n       if (x >= k) { n         break; n       }; n     } n   } n   for (int i = 0; i < 10; i++) n     for (int j = 0; j < arr[i]; j++) cout << s[i]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string second; n   int ans = 0, a = 1; n   cin >> second; n   int k = second.length() - 1; n   for (int i = 1; i < second.size(); i++) { n     ans += (1 << i); n   } n   for (int i = 0; i < second.length(); i++) { n     if (i == k) { n       if (second[i] ==  4 ) n         ans += 1; n       else n         ans += 2; n       continue; n     } n     if (second[i] ==  4 ) continue; n     ans += (1 << (k - i)); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n const double PI = acos(-1.0); n using namespace std; n const int MAXN = 500117; n int n, a[MAXN], ans; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; scanf( %d , &a[i++])) n     ; n   int j = 0, cur = 0; n   for (int i = 1; i < n - 1; i++) { n     if (a[i] != a[i - 1] && a[i] != a[i + 1]) { n       if (cur == 0) j = i; n       cur++; n     } else if (cur > 0) { n       ans = max(ans, (cur + 1) / 2); n       for (int k = j, t = i - 1; k <= t; n            a[k] = a[k - 1], a[t] = a[t + 1], k++, t--) n         ; n       cur = 0; n     } n   } n   if (cur > 0) { n     ans = max(ans, (cur + 1) / 2); n     for (int k = j, t = n - 2; k <= t; n          a[k] = a[k - 1], a[t] = a[t + 1], k++, t--) n       ; n   } n   printf( %d n , ans); n   for (int i = 0; i < n; printf( %d  , a[i++])) n     ; n   putchar(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int sum = 0; n   bool ne = 0; n   for (int i = 0; i < 5; i++) { n     int x; n     cin >> x; n     sum += x; n   } n   if (sum % 5 != 0 or sum == 0) { n     cout <<  -1 ; n   } else n     cout << sum / 5; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100010; n int n, q; n char s[N]; n int t[26][4 * N]; n int c[26][4 * N]; n int d[26]; n void pushDown(int id, int p, int l, int r, int m) { n   if (c[id][p] == 0) { n     t[id][p << 1] = 0; n     t[id][p << 1 | 1] = 0; n     c[id][p << 1] = 0; n     c[id][p << 1 | 1] = 0; n     c[id][p] = -1; n   } else if (c[id][p] == 1) { n     t[id][p << 1] = m - l + 1; n     t[id][p << 1 | 1] = r - m; n     c[id][p << 1] = 1; n     c[id][p << 1 | 1] = 1; n     c[id][p] = -1; n   } n } n void update(int id, int p, int l, int r, int u, int v, int add) { n   if (v < l || r < u) return; n   if (u <= l && r <= v) { n     t[id][p] = (r - l + 1) * add; n     c[id][p] = add; n     return; n   } n   int m = (l + r) >> 1; n   pushDown(id, p, l, r, m); n   update(id, p << 1, l, m, u, v, add); n   update(id, p << 1 | 1, m + 1, r, u, v, add); n   t[id][p] = t[id][p << 1] + t[id][p << 1 | 1]; n } n int getSum(int id, int p, int l, int r, int u, int v) { n   if (v < l || r < u) return 0; n   if (u <= l && r <= v) return t[id][p]; n   int m = (l + r) >> 1; n   pushDown(id, p, l, r, m); n   int t1 = getSum(id, p << 1, l, m, u, v); n   int t2 = getSum(id, p << 1 | 1, m + 1, r, u, v); n   return t1 + t2; n } n int main() { n   scanf( %d %d n , &n, &q); n   scanf( %s n , s); n   memset(t, 0, sizeof t); n   memset(c, 0xff, sizeof c); n   for (int i = 0; i < n; ++i) update(s[i] -  a , 1, 1, n, i + 1, i + 1, 1); n   while (q--) { n     int u, v, type; n     scanf( %d %d %d n , &u, &v, &type); n     for (int i = 0; i < 26; ++i) d[i] = getSum(i, 1, 1, n, u, v); n     for (int i = 0; i < 26; ++i) update(i, 1, 1, n, u, v, 0); n     if (type == 1) { n       int p = u; n       for (int i = 0; i < 26; ++i) n         if (d[i]) { n           update(i, 1, 1, n, p, p + d[i] - 1, 1); n           p += d[i]; n         } n     } else { n       int p = u; n       for (int i = 25; i >= 0; --i) n         if (d[i]) { n           update(i, 1, 1, n, p, p + d[i] - 1, 1); n           p += d[i]; n         } n     } n   } n   for (int i = 1; i <= n; ++i) { n     for (int j = 0; j < 26; ++j) { n       int p = getSum(j, 1, 1, n, i, i); n       if (p) { n         printf( %c ,  a  + j); n         break; n       } n     } n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,mmx,tune=native ) n #pragma comment(linker,  /STACK:256000000 ) n using namespace std; n mt19937 rd( n     (unsigned int)chrono::steady_clock::now().time_since_epoch().count()); n const int INF = 1000 * 1000 * 1000 + 322; n const long long LLINF = n     2LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL + 57; n constexpr unsigned int MOD = 1000 * 1000 * 1000 + 7; n constexpr unsigned int FFT_MOD = 998244353; n const int P1E6 = 1336337; n const int P1E3 = 1009; n const long long P1E14 = 100000000000031; n const long long P1E17 = 100000000000000003; n const long double PI = acosl(-1.); n const long double EPS = 1e-9; n template <typename T, typename U> n inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) { n   _out << _p.x <<     << _p.y; n   return _out; n } n template <typename T, typename U> n inline istream &operator>>(istream &_in, pair<T, U> &_p) { n   _in >> _p.x >> _p.y; n   return _in; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const vector<T> &_v) { n   if (_v.empty()) return _out; n   _out << _v.front(); n   for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) _out <<     << *_it; n   return _out; n } n template <typename T> n inline istream &operator>>(istream &_in, vector<T> &_v) { n   for (auto &_i : _v) _in >> _i; n   return _in; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const set<T> &_s) { n   if (_s.empty()) return _out; n   _out << *_s.begin(); n   for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out <<     << *_it; n   return _out; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const multiset<T> &_s) { n   if (_s.empty()) return _out; n   _out << *_s.begin(); n   for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out <<     << *_it; n   return _out; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) { n   if (_s.empty()) return _out; n   _out << *_s.begin(); n   for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out <<     << *_it; n   return _out; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) { n   if (_s.empty()) return _out; n   _out << *_s.begin(); n   for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out <<     << *_it; n   return _out; n } n template <typename T, typename U> n inline ostream &operator<<(ostream &_out, const map<T, U> &_m) { n   if (_m.empty()) return _out; n   _out <<  (  << _m.begin()->x <<  :   << _m.begin()->y <<  ) ; n   for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) n     _out <<  , (  << _it->x <<  :   << _it->y <<  ) ; n   return _out; n } n template <typename T, typename U> n inline ostream &operator<<(ostream &_out, const unordered_map<T, U> &_m) { n   if (_m.empty()) return _out; n   _out <<  (  << _m.begin()->x <<  :   << _m.begin()->y <<  ) ; n   for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) n     _out <<  , (  << _it->x <<  :   << _it->y <<  ) ; n   return _out; n } n const char *infile =   ; n const char *outfile =   ; n inline long long gcd(long long a, long long b) { n   while (b) { n     a %= b; n     swap(a, b); n   } n   return a; n } n inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n inline int pwm(long long xx, long long pow, int MD) { n   if (pow < 0) { n     pow = pow % (MD - 1) + MD - 1; n   } n   long long mlt = 1; n   while (pow) { n     if (pow & 1) { n       mlt *= xx; n       mlt %= MD; n     } n     xx *= xx; n     pow >>= 1; n     xx %= MD; n   } n   return (int)mlt; n } n inline long long gcdex(long long a, long long b, long long &x, long long &y) { n   if (b == 0) { n     x = 1; n     y = 0; n     return a; n   } n   long long xx, yy; n   long long gc = gcdex(b, a % b, yy, xx); n   x = xx; n   y = yy - (a / b) * xx; n   return gc; n } n inline int inv(long long r, int _mod) { return pwm(r % _mod, _mod - 2, _mod); } n const int N = 500 * 1000 + 57; n int mpd[N]; n int ans[N]; n inline void solve() { n   iota(mpd, mpd + N, 0); n   for (int i = 2; i * i < N; ++i) { n     if (mpd[i] == i) { n       for (int j = i * i; j < N; j += i) { n         mpd[j] = min(mpd[j], i); n       } n     } n   } n   int n; n   cin >> n; n   vector<int> ans; n   for (int i = 1; i <= n; ++i) { n     ans.push_back(i / mpd[i]); n   } n   sort((ans).begin(), (ans).end()); n   ans.erase(ans.begin()); n   cout << ans <<   n ; n } n int main() { n   if (*infile !=   0 ) (void)freopen(infile,  r , stdin); n   if (*outfile !=   0 ) (void)freopen(outfile,  w , stdout); n   cout.tie(nullptr); n   cin.tie(nullptr); n   ios_base::sync_with_stdio(false); n   cout << setprecision(20); n   cout << fixed; n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n int n, a[200010]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n * 2; i++) scanf( %d , a + i); n   std::sort(a, a + n * 2); n   long long ans = (a[n - 1] - a[0]) * 1ll * (a[n * 2 - 1] - a[n]), tmp; n   for (int i = 0; i < n; i++) n     if ((tmp = (a[n * 2 - 1] - a[0]) * 1ll * (a[i + n] - a[i + 1])) < ans) n       ans = tmp; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, p, c, t, sum = 0, res = 0, m, x = 0, y = 0; n vector<int> v, z; n int main() { n   cin >> n >> c; n   for (int i = 0; i < n; ++i) { n     cin >> p; n     v.push_back(p); n   } n   for (int i = 0; i < n; ++i) { n     cin >> t; n     z.push_back(t); n   } n   m = n - 1; n   for (int i = 0; i < n; i++) { n     x += z[i]; n     p = v[i] - (c * x); n     if (p > 0) sum += p; n     y += z[m]; n     t = v[m] - (c * y); n     if (t > 0) res += t; n     m--; n   } n   if (sum > res) n     cout <<  Limak  << endl; n   else if (res > sum) n     cout <<  Radewoosh  << endl; n   else n     cout <<  Tie  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 10000000000000000; n const int maxN = 1000 + 10; n const int maxM = 20000 + 10; n long long d1; n int er[maxM]; n vector<int> paths1; n struct Edge { n   int from, to; n   long long dist; n }; n struct HeapNode { n   long long d; n   int u; n   bool operator<(const HeapNode& rhs) const { return d > rhs.d; } n }; n vector<Edge> edges; n vector<int> G[maxN]; n bool done[maxN]; n long long d[maxN]; n int p[maxM]; n struct Dijkstra { n   int n, m; n   void init(int n) { n     this->n = n; n     for (int i = 0; i < n; i++) G[i].clear(); n     edges.clear(); n   } n   void AddEdge(int from, int to, long long dist) { n     edges.push_back((Edge){from, to, dist}); n     m = edges.size(); n     G[from].push_back(m - 1); n   } n   void dijkstra(int s) { n     priority_queue<HeapNode> Q; n     for (int i = 0; i < n; i++) d[i] = INF; n     d[s] = 0; n     memset(done, 0, sizeof(done)); n     Q.push((HeapNode){0, s}); n     while (!Q.empty()) { n       HeapNode x = Q.top(); n       Q.pop(); n       int u = x.u; n       if (done[u]) continue; n       done[u] = true; n       for (int i = 0; i < G[u].size(); i++) { n         Edge& e = edges[G[u][i]]; n         if (d[e.to] > d[u] + e.dist) { n           d[e.to] = d[u] + e.dist; n           p[e.to] = G[u][i]; n           Q.push((HeapNode){d[e.to], e.to}); n         } n       } n     } n   } n   void GetShortestPaths(int s, int u) { n     dijkstra(s); n     if (d[u] >= INF) { n       d1 = d[u]; n       return; n     } n     for (int i = u; i <= u; i++) { n       d1 = d[i]; n       paths1.clear(); n       int t = i; n       paths1.push_back(t); n       while (t != s) { n         paths1.push_back(edges[p[t]].from); n         t = edges[p[t]].from; n       } n       reverse(paths1.begin(), paths1.end()); n     } n   } n }; n Dijkstra solver; n Edge ei[10000 + 10]; n int main() { n   int n, m, s, t; n   long long L; n   while (~scanf( %d%d%lld%d%d , &n, &m, &L, &s, &t)) { n     memset(er, 0, sizeof(er)); n     int er_cnt = 0; n     for (long long i = 0; i < m; i++) { n       scanf( %d%d%lld , &ei[i].from, &ei[i].to, &ei[i].dist); n       if (ei[i].dist == 0) { n         er[i] = ++er_cnt; n       } n     } n     solver.init(n); n     for (int i = 0; i < m; i++) { n       if (er[i]) ei[i].dist = L; n       solver.AddEdge(ei[i].from, ei[i].to, ei[i].dist); n       solver.AddEdge(ei[i].to, ei[i].from, ei[i].dist); n     } n     solver.GetShortestPaths(s, t); n     if (d1 < L) n       printf( NO n ); n     else if (d1 == L) { n       printf( YES n ); n       for (long long i = 0; i < m; i++) n         printf( %d %d %lld n , ei[i].from, ei[i].to, ei[i].dist); n     } else { n       solver.init(n); n       for (int i = 0; i < m; i++) { n         if (er[i]) ei[i].dist = 1; n         solver.AddEdge(ei[i].from, ei[i].to, ei[i].dist); n         solver.AddEdge(ei[i].to, ei[i].from, ei[i].dist); n       } n       solver.GetShortestPaths(s, t); n       if (d1 > L) n         printf( NO n ); n       else if (d1 == L) { n         printf( YES n ); n         for (int i = 0; i < m; i++) n           printf( %d %d %lld n , ei[i].from, ei[i].to, ei[i].dist); n       } else { n         int x = 1, y = er_cnt, ans; n         while (x <= y) { n           int mid = (x + y) / 2; n           solver.init(n); n           for (int i = 0; i < m; i++) { n             if (1 <= er[i] && er[i] <= mid) n               ei[i].dist = 1; n             else if (er[i] > mid) n               ei[i].dist = L; n             solver.AddEdge(ei[i].from, ei[i].to, ei[i].dist); n             solver.AddEdge(ei[i].to, ei[i].from, ei[i].dist); n           } n           solver.GetShortestPaths(s, t); n           if (d1 <= L) { n             ans = mid; n             y = mid - 1; n           } else n             x = mid + 1; n         } n         solver.init(n); n         for (int i = 0; i < m; i++) { n           if (1 <= er[i] && er[i] <= ans) n             ei[i].dist = 1; n           else if (er[i] > ans) n             ei[i].dist = L; n           solver.AddEdge(ei[i].from, ei[i].to, ei[i].dist); n           solver.AddEdge(ei[i].to, ei[i].from, ei[i].dist); n         } n         solver.GetShortestPaths(s, t); n         long long add = L - d1; n         long long pre, cnt = 0, now; n         printf( YES n ); n         for (int i = 0; i < m; i++) { n           if (er[i] != ans) n             printf( %d %d %lld n , ei[i].from, ei[i].to, ei[i].dist); n           else n             printf( %d %d %lld n , ei[i].from, ei[i].to, ei[i].dist + add); n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<pair<int, int> > *e; n int *parent; n set<int> *v; n int fp(int a) { n   if (parent[a] != a) parent[a] = fp(parent[a]); n   return parent[a]; n } n void dsu(int a, int b) { n   a = fp(a); n   b = fp(b); n   if (a != b) { n     if (v[a].size() < v[b].size()) swap(a, b); n     for (set<int>::iterator i = v[b].begin(); i != v[b].end(); i++) n       v[a].insert(*i); n     v[b].clear(); n     parent[b] = a; n   } n } n void add(int a, int b, int c) { n   v[fp(a)].insert(b); n   v[fp(b)].insert(a); n   set<pair<int, int> >::iterator t = e[b].lower_bound(make_pair(c, -1)); n   if ((t == e[b].end()) || (t->first != c)) { n     e[b].insert(make_pair(c, a)); n   } else { n     dsu(a, t->second); n   } n   t = e[a].lower_bound(make_pair(c, -1)); n   if ((t == e[a].end()) || (t->first != c)) { n     e[a].insert(make_pair(c, b)); n   } else { n     dsu(b, t->second); n   } n } n int main() { n   int n, m, c, q; n   int i; n   char ch; n   scanf( %d %d %d %d , &n, &m, &c, &q); n   parent = new int[100010]; n   v = new set<int>[100010]; n   e = new set<pair<int, int> >[100010]; n   for (i = 0; i < n; i++) { n     parent[i] = i; n   } n   int a, b, cl; n   while (m--) { n     scanf( %d %d %d , &a, &b, &cl); n     add(a, b, cl); n   } n   while (q--) { n     scanf(  %c , &ch); n     if (ch ==  ? ) { n       scanf( %d %d , &a, &b); n       if (fp(a) == fp(b) || (v[fp(a)].find(b) != v[fp(a)].end())) n         printf( Yes n ); n       else n         printf( No n ); n     } else { n       scanf( %d %d %d , &a, &b, &cl); n       add(a, b, cl); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   map<pair<long long int, long long int>, long long int> m; n   long long int ans = 0; n   long long int n, count = 0; n   cin >> n; n   string s; n   for (int i = 1; i <= n; i++) { n     int l = 0, r = 0; n     cin >> s; n     for (int j = 0; j < s.length(); j++) n       if (s[j] ==  ( ) n         l++; n       else if (s[j] ==  )  && l > 0) n         l--; n       else n         r++; n     if (l > 0 && r > 0) n       continue; n     else if (l == 0 && r == 0) { n       ans++; n       continue; n     } else if (l > 0) n       m[make_pair(0, l)]++; n     else n       m[make_pair(1, r)]++; n   } n   ans = ans * ans; n   count = 0; n   for (map<pair<long long int, long long int>, long long int>::iterator it = n            m.begin(); n        it != m.end(); it++) n     count = count + n             m[it->first] * m[make_pair(!(it->first.first), it->first.second)]; n   cout << ans + count / 2; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int seq[100]; n int ans; n vector<string> in; n void solve(int k, int l) { n   if (k <= l) { n     vector<int> buf(in.size()); n     for (int i = 0; i < (int)in.size(); ++i) { n       buf[i] = 0; n     } n     for (int i = 0; i < (int)in.size(); ++i) { n       for (int j = 0; j < k; ++j) { n         buf[i] += in[i][seq[j]] * pow(10, j); n       } n     } n     sort(buf.begin(), buf.end()); n     ans = min(ans, *(buf.rbegin()) - *(buf.begin())); n     return; n   } n   for (int i = 0; i < k; ++i) { n     if (seq[i] < 0) { n       seq[i] = l; n       solve(k, l + 1); n       seq[i] = -1; n     } n   } n } n int main(void) { n   int n, k; n   while (cin >> n >> k) { n     ans = (100000000); n     for (int i = 0; i < 100; ++i) { n       seq[i] = -1; n     } n     in.clear(); n     in.resize(n); n     for (int i = 0; i < n; ++i) { n       cin >> in[i]; n     } n     solve(k, 0); n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int M = 1000000007; n long long n, m; n void solve() {} n void test() { n   long long n; n   cin >> n; n   vector<int> a(n); n   int count[101] = { n       0, n   }; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     count[a[i]]++; n   } n   bool flag = 1; n   int ans = 0; n   for (long long i = 0; i < 101; i++) { n     if (count[i] == 0 && flag) { n       cout << 2 * i << endl; n       return; n     } n     if (count[i] == 1 && flag) { n       ans += i; n       flag = 0; n     } n     if (count[i] == 0 && !flag) { n       ans += i; n       cout << ans << endl; n       return; n     } n   } n } n int main() { n   long long t; n   cin >> t; n   while (t--) test(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n const long long inf = 1e9 + 5; n int n, m, a[maxn], b[maxn], nxt[maxn], prv[maxn]; n long long gt, ct[maxn]; n pair<int, int> sa[maxn]; n set<pair<long long, int> > cross; n long long up(long long x) { return x + (n - x % n) % n; } n long long down(long long x) { return x - x % n; } n long long pos(int idx, long long p, long long v, long long t) { n   long long ret = p + t / n * v; n   if (idx < t % n) { n     ret += v; n   } n   return ret; n } n long long time(int x) { n   long long px = a[x], vx = b[x]; n   int y = nxt[x]; n   long long py = a[y], vy = b[y]; n   long long dx = pos(x, px, vx, gt); n   long long dy = pos(y, py, vy, gt); n   if (dy <= dx) { n     py += (dx - dy) + (m - (dx - dy) % m) % m; n   } n   if (vx <= vy) { n     if (x < gt % n) { n       if (pos(y, py, vy, up(gt) + x + 1) <= pos(x, px, vx, up(gt) + x + 1)) { n         return up(gt) + x + 1; n       } n     } else { n       if (pos(y, py, vy, down(gt) + x + 1) <= n           pos(x, px, vx, down(gt) + x + 1)) { n         return down(gt) + x + 1; n       } n     } n     return n * inf; n   } n   long long lo, hi = n * inf / (vx - vy) + 10; n   if (x < gt % n) { n     lo = up(gt) + x + 1; n   } else { n     lo = down(gt) + x + 1; n   } n   while (lo < hi) { n     long long mid = (lo + hi) / 2; n     long long cur; n     if (x < mid % n) { n       cur = down(mid) + x + 1; n     } else { n       cur = down(mid) - n + x + 1; n     } n     if (pos(y, py, vy, cur) <= pos(x, px, vx, cur)) { n       hi = mid; n     } else { n       lo = mid + 1; n     } n   } n   return lo; n } n void erase(int x) { n   cross.erase({ct[x], x}); n   nxt[prv[x]] = nxt[x]; n   prv[nxt[x]] = prv[x]; n } n int dist(int x, int y) { return (y - x + m) % m; } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> a[i] >> b[i]; n     --a[i]; n     sa[i] = {a[i], i}; n   } n   sort(sa, sa + n); n   for (int i = 0; i < n; i++) { n     nxt[sa[i].second] = sa[(i + 1) % n].second; n     prv[sa[(i + 1) % n].second] = sa[i].second; n   } n   for (int i = 0; i < n; i++) { n     ct[i] = time(i); n     cross.insert({ct[i], i}); n   } n   while (cross.size() > 1 && cross.begin()->first < n * inf) { n     long long t = cross.begin()->first; n     int x = cross.begin()->second; n     int px = pos(x, a[x], b[x], t - 1) % m; n     int cnt = 0; n     while (1) { n       int y = nxt[x]; n       if (x == y) { n         break; n       } else { n         int py = pos(y, a[y], b[y], t - 1) % m; n         if (dist(px, py) <= b[x]) { n           erase(y); n           ++cnt; n         } else { n           break; n         } n       } n     } n     px = (px + b[x]) % m; n     b[x] = max(b[x] - cnt, 0); n     a[x] = (px - pos(x, 0, b[x], t)) % m; n     if (a[x] < 0) { n       a[x] += m; n     } n     int w = prv[x]; n     if (w == x) { n       break; n     } n     cross.erase({ct[w], w}); n     cross.erase({ct[x], x}); n     ct[w] = time(w); n     ct[x] = time(x); n     cross.insert({ct[w], w}); n     cross.insert({ct[x], x}); n     gt = t; n   } n   cout << cross.size() <<   n ; n   for (auto &f : cross) { n     cout << f.second + 1 <<    ; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long power(long long a, long long b) { n   long long ans = 1; n   while (b > 0) { n     if (b & 1) { n       ans = (ans * a); n     } n     a = (a * a); n     b >>= 1; n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long a, b, i, l = 0, u; n   cin >> a >> b; n   if (a > b) { n     cout <<  -1 ; n     return 0; n   } n   if (a == 0 && b == 0) { n     cout <<  0 ; n     return 0; n   } n   if (a == 0 && b % 2 == 0) { n     cout <<  2 n  << b / 2 <<     << b / 2; n     return 0; n   } n   if (a == b) { n     cout << 1 <<   n  << a; n     return 0; n   } n   if (a % 2 != 0 && b % 2 != 0) { n     long long d = b - a; n     if (d == 0) { n       cout <<  1 n  << 1; n       return 0; n     } n     if ((a & (d / 2)) == 0) { n       cout <<  2  n            <<   n ; n       cout << a + d / 2 <<    ; n       cout << d / 2; n       return 0; n     } n     cout <<  3  n          <<   n ; n     cout << a <<    ; n     cout << d / 2 <<     << d / 2; n     return 0; n   } n   if (a % 2 == 0 && b % 2 == 0) { n     long long d = a; n     vector<int> v; n     while (d > 0) { n       v.push_back(d & 1); n       d = d >> 1; n     } n     while (v.size() <= 60) { n       v.push_back(0); n     } n     for (i = 60; i >= 0; i--) { n       if (v[i] == 0) { n         u = power(2, i); n         if (a + l + 2 * u == b) break; n         if (a + l + 2 * u < b) { n           l = l + 2 * u; n         } n       } n     } n     if (((a + l / 2 + u) ^ (l / 2 + u)) != a) { n       long long d = b - a; n       cout <<  3  n            <<   n ; n       cout << a <<    ; n       cout << d / 2 <<     << d / 2; n       return 0; n     } n     cout <<  2 n ; n     cout << a + l / 2 + u <<     << l / 2 + u <<   n ; n     return 0; n   } n   cout <<  -1 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n int n, k, l[N], r[N], f[2][N], q[N]; n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= k; ++i) scanf( %d%d , &l[i], &r[i]); n   f[0][0] = 0; n   for (int i = 1; i <= (n << 1); ++i) f[0][i] = 0x3f3f3f3f; n   for (int i = 1; i <= k; ++i) { n     int cur = i & 1, last = !cur; n     memset(f[cur], 0x3f, sizeof(int) * (n + 1)); n     int L = 1, R = 0, now = 0; n     for (int j = min(n, r[i]); j >= 0; --j) { n       f[cur][j] = f[last][j]; n       int ql = l[i] - j, qr = min(r[i] - j, n); n       while (now <= qr) { n         while (L <= R && f[last][q[R]] > f[last][now]) --R; n         q[++R] = now; n         ++now; n       } n       while (L <= R && q[L] < ql) ++L; n       f[cur][j] = min(f[cur][j], f[last][q[L]] + 1); n     } n     L = 1, R = 0; n     now = 0; n     for (int j = 0; j <= n && j <= r[i]; ++j) { n       int ql = j + l[i] - r[i], qr = j; n       while (now <= qr) { n         while (L <= R && f[last][q[R]] > f[last][now]) --R; n         q[++R] = now; n         ++now; n       } n       while (L <= R && q[L] < ql) ++L; n       f[cur][j] = min(f[cur][j], f[last][q[L]] + 2); n     } n   } n   if (f[k & 1][n] == 0x3f3f3f3f) { n     puts( Hungry ); n     return 0; n   } n   puts( Full ); n   printf( %d n , f[k & 1][n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   int n, x[100005]; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> x[i]; n   sort(x + 1, x + 1 + n); n   for (int i = 2; i <= n; i++) n     if (x[i - 1] * 2 > x[i] && x[i - 1] != x[i]) return cout <<  YES , 0; n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline bool ylmin(T &a, T b) { n   return a < b ? 0 : (a = b, 1); n } n template <class T> n inline bool ylmax(T &a, T b) { n   return a > b ? 0 : (a = b, 1); n } n template <class T> n inline T abs(T x) { n   return x < 0 ? -x : x; n } n inline char read() { n   static const int IO_LEN = 1024 * 1024; n   static char buf[IO_LEN], *ioh, *iot; n   if (ioh == iot) { n     iot = (ioh = buf) + fread(buf, 1, IO_LEN, stdin); n     if (ioh == iot) return -1; n   } n   return *ioh++; n } n template <class T> n inline void read(T &x) { n   static int iosig; n   static char ioc; n   for (iosig = 0, ioc = read(); !isdigit(ioc); ioc = read()) n     if (ioc ==  - ) iosig = 1; n   for (x = 0; isdigit(ioc); ioc = read()) x = (x << 1) + (x << 3) + (ioc ^  0 ); n   if (iosig) x = -x; n } n const int MAXN = 2e5 + 10; n long long T, n, a[MAXN], b[MAXN], id[MAXN]; n inline bool cmp(int x, int y) { return a[x] < a[y]; } n int main() { n   for (read(T); T; T--) { n     read(n); n     for (int i = (1); i <= (n); i++) read(a[i]), id[i] = i; n     for (int i = (1); i <= (n); i++) read(b[i]); n     sort(id + 1, id + n + 1, cmp); n     long long sum = 0, ans = 1e9; n     for (int i = (1); i <= (n); i++) sum += b[i]; n     for (int i = (0); i <= (n); i++) { n       sum -= b[id[i]]; n       ylmin(ans, max(a[id[i]], sum)); n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int temp, i, j, k, T; n long long pow_r(long long d, long long n) { n   long long x = 1ll; n   while (n > 0) { n     if (n & 1) x = (x * d); n     d = (d * d); n     n >>= 1; n   } n   return x; n } n int n, da[6], db[6]; n pair<int, pair<int, int> > a[8]; n int dist(int p, int q) { n   return (a[p].second.first - a[q].second.first) * n              (a[p].second.first - a[q].second.first) + n          (a[p].second.second - a[q].second.second) * n              (a[p].second.second - a[q].second.second); n } n void check() { n   da[0] = dist(0, 1); n   da[1] = dist(1, 2); n   da[2] = dist(2, 3); n   da[3] = dist(3, 0); n   da[4] = dist(0, 2); n   da[5] = dist(1, 3); n   db[0] = dist(4, 5); n   db[1] = dist(5, 6); n   db[2] = dist(6, 7); n   db[3] = dist(7, 4); n   db[4] = dist(4, 6); n   db[5] = dist(5, 7); n   if (da[0] == da[1] && da[1] == da[2] && da[2] == da[3] && da[4] == da[5] && n       db[0] == db[2] && db[1] == db[3] && db[4] == db[5]) { n     puts( YES ); n     cout << a[0].first <<     << a[1].first <<     << a[2].first <<     n          << a[3].first << endl; n     cout << a[4].first <<     << a[5].first <<     << a[6].first <<     n          << a[7].first << endl; n     exit(0); n   } n } n int main() { n   n = 8; n   i = 0; n   while (n--) { n     scanf( %d , &a[i].second.first); n     scanf( %d , &a[i].second.second); n     a[i].first = i + 1; n     ++i; n   } n   n = 8; n   sort(a, a + 8); n   do { n     check(); n   } while (next_permutation(a, a + 8)); n   puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int p = 1e9 + 7; n inline int read() { n   int neg = 1, num = 0; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) neg = -1; n   for (; isdigit(c); c = getchar()) num = (num << 1) + (num << 3) + c -  0 ; n   return neg * num; n } n int n, cnt[200010]; n inline int Pow(int x, int y) { n   int res = 1; n   for (; y; y >>= 1, x = 1ll * x * x % p) n     if (y & 1) res = 1ll * res * x % p; n   return res; n } n int main() { n   n = read(); n   for (int i = 1; i <= n; i++) { n     int a = read(); n     if (a != -1) cnt[a]++; n   } n   int sum = 0; n   for (int i = 1; i <= n; i++) sum = (sum + Pow(2, cnt[i]) - 1) % p; n   sum = Pow(2, n - 1) - 1 - sum; n   sum = (sum % p + p) % p; n   cout << sum; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 150; n const double eps = 1e-8; n struct point { n   double x, y; n   point() {} n   point(double _x, double _y) : x(_x), y(_y) {} n   friend bool operator<(const point &a, const point &b) { n     if (fabs(a.x - b.x) < eps) { n       return a.y < b.y; n     } n     return a.x < b.x; n   } n }; n vector<point> vec; n map<point, int> vis; n point square1; n point CircumCenter(point a, point b, point c) { n   point cp; n   double a1 = b.x - a.x, b1 = b.y - a.y, c1 = (a1 * a1 + b1 * b1) / 2; n   double a2 = c.x - a.x, b2 = c.y - a.y, c2 = (a2 * a2 + b2 * b2) / 2; n   double d = a1 * b2 - a2 * b1; n   cp.x = a.x + (c1 * b2 - c2 * b1) / d; n   cp.y = a.y + (a1 * c2 - a2 * c1) / d; n   return cp; n } n double getDistance(point a, point b) { n   return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); n } n double dianji(point veca, point vecb) { n   return veca.x * vecb.x + veca.y * vecb.y; n } n bool isLenEqual(point a, point b, point c) { n   if (fabs(getDistance(a, b) - getDistance(a, c)) < eps) return true; n   return false; n } n int fdTriangle(point a, point b, point c) { n   point vecOne = point(a.x - b.x, a.y - b.y); n   point vecTwo = point(b.x - c.x, b.y - c.y); n   point vecThree = point(c.x - a.x, c.y - a.y); n   double dj1 = dianji(vecOne, vecTwo); n   double dj2 = dianji(vecTwo, vecThree); n   double dj3 = dianji(vecThree, vecOne); n   if (fabs(dj1) < eps || fabs(dj2) < eps || fabs(dj3) < eps) { n     if (fabs(dj1) < eps && isLenEqual(a, b, c)) { n       square1 = a; n       return 2; n     } else if (fabs(dj2) < eps && isLenEqual(c, a, b)) { n       square1 = c; n       return 2; n     } else if (fabs(dj3) < eps && isLenEqual(b, a, c)) { n       square1 = b; n       return 2; n     } n     return 0; n   } n   if (dj1 < 0 && dj2 < 0 && dj3 < 0) return 1; n   return 0; n } n void compute() { n   double mx = -1.0; n   point all_ans; n   int all_flag = 0; n   for (int i = 0; i < vec.size(); i++) { n     for (int j = 0; j < vec.size(); j++) { n       for (int k = 0; k < vec.size(); k++) { n         if (i == j || j == k || i == k) continue; n         int flag = 0; n         point pos_ans; n         point a = vec[i], b = vec[j], c = vec[k]; n         if (!(fabs((b.y - a.y) * (c.x - b.x) - (b.x - a.x) * (c.y - b.y)) < n               eps)) { n           int type = fdTriangle(a, b, c); n           if (type == 1) { n             flag = 1; n             pos_ans = CircumCenter(a, b, c); n           } else if (type == 2) { n             point cc = CircumCenter(a, b, c); n             double X = 2 * cc.x - square1.x; n             double Y = 2 * cc.y - square1.y; n             if (vis[point(X, Y)] == 1) { n               flag = 1; n               pos_ans = cc; n             } n           } n         } n         if (flag == 1) { n           double r = getDistance(pos_ans, a); n           for (int z = 0; z < vec.size(); z++) { n             point each = vec[z]; n             if (getDistance(pos_ans, each) + eps < r) { n               flag = 0; n               break; n             } n           } n           if (flag == 1 && mx < r) { n             mx = r; n             all_flag = 1; n             all_ans = pos_ans; n           } n         } n       } n     } n   } n   if (all_flag == 1) { n     printf( %.6f n , mx); n   } else { n     printf( -1 n ); n   } n } n int main() { n   int n; n   while (cin >> n) { n     vis.clear(); n     vec.clear(); n     for (int i = 0; i < n; i++) { n       double x, y; n       cin >> x >> y; n       point p = point(x, y); n       vec.push_back(p); n       vis[p] = 1; n     } n     compute(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool prime(int x) { n   int cnt = 0; n   for (int i = 1; i <= x; i++) n     if (x % i == 0) cnt++; n   return (cnt <= 2); n } n void fl() { fflush(stdout); } n int kul[] = {4, 9, 25, 49}; n char odg[5]; n int main() { n   int prosti = 1; n   for (int i = 0; i < 4; i++) { n     printf( %d n , kul[i]); n     fl(); n     scanf( %s , odg); n     if (odg[0] ==  y ) prosti = 0; n   } n   if (prosti) { n     int cnt = 0; n     for (int i = 2; i <= 50; i++) { n       if (prime(i)) { n         printf( %d n , i); n         fl(); n         scanf( %s , odg); n         if (odg[0] ==  y ) cnt++; n       } n     } n     if (cnt >= 2) prosti = 0; n   } n   if (prosti == 1) { n     printf( prime n ); n     fl(); n   } else { n     printf( composite n ); n     fl(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename T1> n ostream &operator<<(ostream &out, pair<T, T1> obj) { n   out <<  (  << obj.first <<  ,  << obj.second <<  ) ; n   return out; n } n template <typename T, typename T1> n ostream &operator<<(ostream &out, map<T, T1> cont) { n   typename map<T, T1>::const_iterator itr = cont.begin(); n   typename map<T, T1>::const_iterator ends = cont.end(); n   for (; itr != ends; ++itr) out << *itr <<    ; n   out << endl; n   return out; n } n template <typename T> n ostream &operator<<(ostream &out, set<T> cont) { n   typename set<T>::const_iterator itr = cont.begin(); n   typename set<T>::const_iterator ends = cont.end(); n   for (; itr != ends; ++itr) out << *itr <<    ; n   out << endl; n   return out; n } n template <typename T> n ostream &operator<<(ostream &out, multiset<T> cont) { n   typename multiset<T>::const_iterator itr = cont.begin(); n   typename multiset<T>::const_iterator ends = cont.end(); n   for (; itr != ends; ++itr) out << *itr <<    ; n   out << endl; n   return out; n } n template <typename T, n           template <typename ELEM, typename ALLOC = allocator<ELEM>> class CONT> n ostream &operator<<(ostream &out, CONT<T> cont) { n   typename CONT<T>::const_iterator itr = cont.begin(); n   typename CONT<T>::const_iterator ends = cont.end(); n   for (; itr != ends; ++itr) out << *itr <<    ; n   out << endl; n   return out; n } n template <typename T, unsigned int N, typename CTy, typename CTr> n typename enable_if<!is_same<T, char>::value, basic_ostream<CTy, CTr> &>::type n operator<<(basic_ostream<CTy, CTr> &out, const T (&arr)[N]) { n   for (auto i = 0; i < N; ++i) out << arr[i] <<    ; n   out << endl; n   return out; n } n template <typename T> n T gcd(T a, T b) { n   T min_v = min(a, b); n   T max_v = max(a, b); n   while (min_v) { n     T temp = max_v % min_v; n     max_v = min_v; n     min_v = temp; n   } n   return max_v; n } n template <typename T> n T lcm(T a, T b) { n   return (a * b) / gcd(a, b); n } n template <typename T> n T fast_exp_pow(T base, T exp, T mod) { n   long long res = 1; n   while (exp) { n     if (exp & 1) { n       res *= base; n       res %= mod; n     } n     exp >>= 1; n     base *= base; n     base %= mod; n   } n   return res % mod; n } n int N, M, K, L, R; n long long C, answer = 99999999999999LL; n long long dp_solve[310][310]; n long long min_cost[310][310]; n int main() { n   scanf( %d%d%d , &N, &M, &K); n   for (auto i = 0; i < 310; ++i) n     for (auto j = 0; j < 310; ++j) n       dp_solve[i][j] = min_cost[i][j] = 99999999999999LL; n   for (auto i = 0; i < M; ++i) { n     scanf( %d%d%lld , &L, &R, &C); n     min_cost[L][R] = min(min_cost[L][R], C); n   } n   for (auto r = 1; r <= N; ++r) n     for (auto l = 1; l <= r; ++l) n       min_cost[l][r] = min(min_cost[l][r], min_cost[l - 1][r]); n   for (int l = N; l >= 1; --l) n     for (int r = N; r >= l; --r) n       min_cost[l][r] = min(min_cost[l][r], min_cost[l][r + 1]); n   for (auto i = 0; i <= N; ++i) { n     dp_solve[i][0] = 0; n     for (auto j = 0; j <= i; ++j) { n       if (dp_solve[i][j] == 99999999999999LL) continue; n       dp_solve[i + 1][j] = min(dp_solve[i + 1][j], dp_solve[i][j]); n       for (auto k = i + 1; k <= N; ++k) n         dp_solve[k][j + (k - i)] = n             min(dp_solve[k][j + (k - i)], dp_solve[i][j] + min_cost[i + 1][k]); n     } n   } n   answer = dp_solve[N][K]; n   if (answer >= 99999999999999LL) answer = -1; n   printf( %lld n , answer); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = 3.1415926535; n double squared(double n) { return n * n; } n typedef struct { n   int cx; n   int cy; n   int r; n   int R; n } circle_t; n bool isBlack(double x, double y, circle_t c) { n   double val = squared(x - (double)c.cx) + squared(y - (double)c.cy); n   if (val > squared(c.R)) { n     return false; n   } else if (val >= squared(c.r)) { n     return true; n   } else { n     return false; n   } n } n int returnOkNum(circle_t c, circle_t c2) { n   int blackOutNum = 0; n   int blackInNum = 0; n   int ret = 0; n   const int DIVIDE = 100000; n   for (int i = 0; i < DIVIDE; ++i) { n     double xOut = (double)c.R * cos(2.0 * PI * i / DIVIDE) + c.cx; n     double yOut = (double)c.R * sin(2.0 * PI * i / DIVIDE) + c.cy; n     double xIn = (double)c.r * cos(2.0 * PI * i / DIVIDE) + c.cx; n     double yIn = (double)c.r * sin(2.0 * PI * i / DIVIDE) + c.cy; n     if (isBlack(xOut, yOut, c2)) { n       ++blackOutNum; n     } n     if (isBlack(xIn, yIn, c2)) { n       ++blackInNum; n     } n   } n   if (blackOutNum <= 3) { n     ++ret; n   } n   if (blackInNum <= 3) { n     ++ret; n   } n   return ret; n } n int main(void) { n   vector<circle_t> cs(2); n   for (int i = 0; i < 2; ++i) { n     cin >> cs[i].cx >> cs[i].cy >> cs[i].r >> cs[i].R; n   } n   int ret = returnOkNum(cs[0], cs[1]); n   ret += returnOkNum(cs[1], cs[0]); n   cout << ret << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x; n   scanf( %d%d , &n, &x); n   int i, j, ans = 0; n   int a1[100002], a2[100002]; n   for (i = 1; i <= n; i++) { n     scanf( %d%d , &a1[i], &a2[i]); n     ans = ans + (a2[i] - a1[i] + 1) + (a1[i] - a2[i - 1] - 1) % x; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n const int M = 1e3 + 10; n const long long mod = 1e9 + 7; n const long long inf = 1e18 + 10; n int a[N], st[N], ft[N], ind[N], lzy[4 * N], t, n, m; n vector<int> adj[N]; n bitset<M> seg[4 * N], P, res, one; n void dfs(int v, int p) { n   st[v] = t; n   ind[t++] = v - 1; n   for (int u : adj[v]) n     if (u != p) dfs(u, v); n   ft[v] = t; n } n void build(int l = 0, int r = n, int id = 1) { n   if (r - l == 1) { n     seg[id][a[ind[l]]] = 1; n     return; n   } n   int mid = (l + r) / 2; n   build(l, mid, 2 * id); n   build(mid, r, 2 * id + 1); n   seg[id] = seg[2 * id] | seg[2 * id + 1]; n } n void shift(int id) { n   int x = lzy[id]; n   seg[2 * id] = (seg[2 * id] << x) & one | (seg[2 * id] >> (m - x)); n   seg[2 * id + 1] = (seg[2 * id + 1] << x) & one | (seg[2 * id + 1] >> (m - x)); n   lzy[2 * id] = (lzy[2 * id] + x) % m; n   lzy[2 * id + 1] = (lzy[2 * id + 1] + x) % m; n   lzy[id] = 0; n } n void upd(int l, int r, int x, int s = 0, int e = n, int id = 1) { n   if (e <= l || r <= s) return; n   if (l <= s && e <= r) { n     seg[id] = (seg[id] << x) & one | (seg[id] >> (m - x)); n     lzy[id] = (lzy[id] + x) % m; n     return; n   } n   shift(id); n   int mid = (s + e) / 2; n   upd(l, r, x, s, mid, 2 * id); n   upd(l, r, x, mid, e, 2 * id + 1); n   seg[id] = seg[2 * id] | seg[2 * id + 1]; n } n void get(int l, int r, int s = 0, int e = n, int id = 1) { n   if (e <= l || r <= s) return; n   if (l <= s && e <= r) { n     res |= seg[id]; n     return; n   } n   shift(id); n   int mid = (s + e) / 2; n   get(l, r, s, mid, 2 * id); n   get(l, r, mid, e, 2 * id + 1); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> a[i], a[i] %= m; n   for (int i = 1; i < n; i++) { n     int u, v; n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   dfs(1, 0); n   build(); n   for (int i = 2; i < m; i++) P[i] = 1; n   for (int i = 2; i < m; i++) n     if (P[i]) n       for (int j = i * i; j < m; j += i) P[j] = 0; n   for (int i = 0; i < m; i++) one[i] = 1; n   int q; n   cin >> q; n   while (q--) { n     int typ; n     cin >> typ; n     if (typ == 1) { n       int v, x; n       cin >> v >> x; n       x %= m; n       upd(st[v], ft[v], x); n     } else { n       int v; n       cin >> v; n       res &= 0; n       get(st[v], ft[v]); n       cout << (res & P).count() <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using lint = long long int; n using P = pair<int, int>; n using PL = pair<lint, lint>; n constexpr int MOD = 1000000007; n constexpr lint B1 = 1532834020; n constexpr lint M1 = 2147482409; n constexpr lint B2 = 1388622299; n constexpr lint M2 = 2147478017; n constexpr int INF = 2147483647; n void yes(bool expr) { cout << (expr ?  Yes  :  No ) <<   n ; } n template <class T> n void chmax(T &a, const T &b) { n   if (a < b) a = b; n } n template <class T> n void chmin(T &a, const T &b) { n   if (b < a) a = b; n } n vector<int> csort(vector<int> &c, vector<int> &tmp) { n   vector<int> ret; n   int ptr = c.size(); n   for (int i = (tmp.size()) - 1, i_begin_ = (0); i >= i_begin_; i--) { n     ptr -= tmp[i]; n     for (int j = (0), j_end_ = (tmp[i]); j < j_end_; j++) n       ret.push_back(c[ptr + j]); n   } n   return ret; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   vector<int> c(n); n   for (int i = (0), i_end_ = (n); i < i_end_; i++) cin >> c[i]; n   for (int i = (0), i_end_ = (n); i < i_end_; i++) c[i]--; n   int opes = 0; n   vector<vector<int>> ans; n   while (true) { n     bool comp = true; n     for (int i = (0), i_end_ = (n); i < i_end_; i++) n       if (c[i] != i) { n         comp = false; n         break; n       } n     if (comp) break; n     vector<int> tmp; n     for (int i = (0), i_end_ = (opes); i < i_end_; i++) tmp.push_back(1); n     if ((n - opes) % 2 == 0) { n       for (int i = (0), i_end_ = (n); i < i_end_; i++) n         if (c[i] == opes) { n           tmp.push_back(i + 1 - opes); n           if (n - 1 - i > 0) tmp.push_back(n - 1 - i); n           break; n         } n     } else { n       for (int i = (0), i_end_ = (n); i < i_end_; i++) n         if (c[i] == opes) { n           tmp.push_back(n - opes - i); n           if (i > 0) tmp.push_back(i); n           break; n         } n       reverse((tmp).begin(), (tmp).end()); n     } n     if (tmp.size() > 1) { n       ans.push_back(tmp); n       c = csort(c, tmp); n     } n     opes++; n   } n   cout << ans.size() << endl; n   for (int i = (0), i_end_ = (ans.size()); i < i_end_; i++) { n     cout << ans[i].size() <<    ; n     for (int j = (0), j_end_ = (ans[i].size()); j < j_end_; j++) n       cout << ans[i][j] << (j != ans[i].size() - 1 ?     :   ); n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long x = 0, f = 1; n   char c = getchar(); n   while ((c <  0  || c >  9 ) && (c !=  - )) c = getchar(); n   if (c ==  - ) f = -1, c = getchar(); n   while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar(); n   return x * f; n } n const int N = 1e6 + 10; n int n, a[N][2], dp[N][2][2], ans[N]; n pair<int, int> pre[N][2][2]; n inline void solve() { n   n = read(); n   for (int i = (1); i <= (n); i++) a[i][0] = read(), a[i][1] = -a[i][0]; n   if (n == 1) return puts( YES n1 n ), void(0); n   for (int i = (1); i <= (n); i++) n     for (int j = (0); j <= (1); j++) n       for (int k = (0); k <= (1); k++) n         dp[i][j][k] = n + 1, pre[i][j][k] = make_pair(-1, -1); n   for (int j = (0); j <= (1); j++) dp[1][j][0] = -n - 1; n   for (int i = (1); i < (n); i++) n     for (int j = (0); j <= (1); j++) n       for (int k = (0); k <= (1); k++) n         if (dp[i][j][k] < n + 1) { n           for (int l = (0); l <= (1); l++) { n             int x = 0, y = 0; n             if (k == 0) n               x = a[i][j], y = dp[i][j][k]; n             else n               y = a[i][j], x = dp[i][j][k]; n             int z = a[i + 1][l]; n             if (z < y) continue; n             if (z > x) { n               if (y < dp[i + 1][l][0]) n                 dp[i + 1][l][0] = y, pre[i + 1][l][0] = make_pair(j, k); n             } else { n               if (x < dp[i + 1][l][1]) n                 dp[i + 1][l][1] = x, pre[i + 1][l][1] = make_pair(j, k); n             } n           } n         } n   int x = -1, y = -1; n   for (int j = (0); j <= (1); j++) n     for (int k = (0); k <= (1); k++) n       if (pre[n][j][k].first != -1) x = j, y = k; n   if (x == -1) return puts( NO ), void(0); n   for (int i = (n); i >= (1); i--) { n     ans[i] = a[i][x]; n     auto tmp = pre[i][x][y]; n     x = tmp.first, y = tmp.second; n   } n   puts( YES ); n   for (int i = (1); i <= (n); i++) printf( %d  , ans[i]); n   puts(  ); n } n int main() { n   int T = read(); n   while (T--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n map<long long, long long> m1; n long long query(long long a, long long b) { n   long long ans = 0; n   while (a != b) { n     if (a > b) { n       ans += m1[a]; n       a = a / 2; n     } else { n       ans += m1[b]; n       b = b / 2; n     } n   } n   return ans; n } n void update(long long a, long long b, long long m) { n   while (a != b) { n     if (a > b) { n       m1[a] += m; n       a = a / 2; n     } else { n       m1[b] += m; n       b = b / 2; n     } n   } n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long q; n   cin >> q; n   while (q--) { n     long long ch; n     cin >> ch; n     if (ch == 2) { n       long long a, b; n       cin >> a >> b; n       cout << query(a, b) << endl; n     } else { n       long long a, b, m; n       cin >> a >> b >> m; n       update(a, b, m); n     } n   } n   return 0; n } n


#include<bits/stdc++.h> n  n using namespace std;  n typedef long long ll; n  n const int N = 400 + 5; n int n = 0, m = 0; n int dp[N][N] = {}; n int c[N][N] = {}, smc[N] = {}; n int ans = 0; n  n int main(){ n  cin >> n >> m; n  dp[0][0] = 1; n  for(int i = 0 ; i <= n + 1 ; i ++) for(int j = 0 ; j <= i ; j ++){ n   if(j == 0) c[j][i] = 1; n   else c[j][i] = (c[j - 1][i - 1] + c[j][i - 1]) % m; n    n  } n  for(int i = 0 ; i <= n + 1 ; i ++){ n   if(i == 0) smc[i] = 1; n   else smc[i] = (smc[i - 1] * 2) % m; n  } n  for(int i = 1 ; i <= n + 1; i ++) n   for(int j = ceil(i / 2.0) ; j < i ; j ++){ n    for(int k = i - j - 1 ; k < i - 1 ; k ++) dp[i][j] = (dp[i][j] + (((1ll * dp[k][j - i + k + 1] * c[i - k - 1][j]) % m) * smc[i - k - 2]) % m) % m; n    if(i == n + 1) ans = (ans + dp[i][j]) % m; n      } n  cout << ans; n  return 0; n } n  n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100003; n int l[maxn], r[maxn], L, R, K, n, cnt[maxn][30], sum[30], A[30], B[30]; n char c[maxn], s[maxn]; n int List[30][maxn], a[maxn], len[maxn], tot = 0; n inline int get() { n   int f = 0, v = 0; n   char ch; n   while (!isdigit(ch = getchar())) n     if (ch ==  - ) break; n   if (ch ==  - ) n     f = 1; n   else n     v = ch - 48; n   while (isdigit(ch = getchar())) v = v * 10 + ch - 48; n   if (f == 1) n     return -v; n   else n     return v; n } n int check(int st, int ed) { n   bool f = 0, g = 0; n   for (int i = 0; i < 26; i++) { n     int tp = cnt[ed][i] - cnt[st - 1][i]; n     if (tp > B[i]) g = 1; n     if (tp < A[i]) f = 1; n   } n   if (f && g) return 2; n   if (f) return -1; n   if (g) return 1; n   return 0; n } n void add(int st, int ed, int v) { n   for (int i = st; i <= ed; i++) { n     if (L <= a[i] && a[i] <= R) tot--; n     a[i] += v; n     if (L <= a[i] && a[i] <= R) tot++; n   } n } n int main() { n   scanf( %s , s + 1); n   n = strlen(s + 1); n   K = get(); n   L = get(), R = get(); n   for (int i = 1; i <= K; i++) scanf(  %c , &c[i]), l[i] = get(), r[i] = get(); n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < 26; j++) cnt[i][j] = cnt[i - 1][j]; n     cnt[i][s[i] -  a ]++; n   } n   if (L == K && R == K) { n     long long ans = 0; n     for (int i = 0; i < 26; i++) A[i] = 0, B[i] = n + 1; n     for (int i = 1; i <= K; i++) { n       A[c[i] -  a ] = max(A[c[i] -  a ], l[i]); n       B[c[i] -  a ] = min(B[c[i] -  a ], r[i]); n       if (A[c[i] -  a ] > B[c[i] -  a ]) return puts( 0 ), 0; n     } n     for (int i = 1; i <= n; i++) { n       bool flag = 1; n       L = i, R = n; n       int Left, Right; n       while (L <= R) { n         int mid = (L + R) / 2, t = check(i, mid); n         if (t == 2) { n           flag = 0; n           break; n         } n         if (t == 1) n           R = mid - 1; n         else n           L = mid + 1; n       } n       Right = R; n       L = i, R = n; n       while (L <= R) { n         int mid = (L + R) / 2, t = check(i, mid); n         if (t == 2) { n           flag = 0; n           break; n         } n         if (t == -1) n           L = mid + 1; n         else n           R = mid - 1; n       } n       Left = L; n       if (flag && Right >= Left) ans += Right - Left + 1; n     } n     cout << ans << endl; n     return 0; n   } n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     if (L == 0) tot++; n     int tp = s[i] -  a ; n     List[tp][++len[tp]] = i; n     for (int j = 1; j <= K; j++) { n       if (l[j] == 0) add(i, i, 1); n       if (c[j] != s[i]) continue; n       if (len[tp] >= l[j] && l[j] != 0) n         add(List[tp][len[tp] - l[j]] + 1, List[tp][len[tp] - l[j] + 1], 1); n       if (len[tp] > r[j]) n         add(List[tp][len[tp] - r[j] - 1] + 1, List[tp][len[tp] - r[j]], -1); n     } n     ans += tot; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int m; n struct Edge { n   int x; n   int y; n   int t; n   Edge(int x, int y, int t) : x(x), y(y), t(t) {} n   void print() { cout << x <<     << y <<     << t << endl; } n }; n vector<Edge> edges; n vector<int> edge_idx[200005]; n int in_digree[200005]; n queue<int> Q; n int order[200005]; n int main() { n   int i, j, k; n   int x, y, z; n   int t; n   cin >> t; n   while (0 < t--) { n     edges.clear(); n     while (!Q.empty()) Q.pop(); n     for (i = 0; i < n; i++) edge_idx[i].clear(); n     memset(in_digree, 0, sizeof(in_digree)); n     cin >> n >> m; n     for (i = 0; i < m; i++) { n       cin >> z >> x >> y; n       x--; n       y--; n       Edge e(x, y, z); n       if (e.x != x || e.y != y || e.t != z) return -1; n       edge_idx[x].push_back(edges.size()); n       edge_idx[y].push_back(edges.size()); n       edges.push_back(e); n       if (z) { n         in_digree[y] += 1; n       } n     } n     for (i = 0; i < n; i++) { n       if (in_digree[i] == 0) { n         Q.push(i); n       } n     } n     int cnt = 0; n     k = 0; n     while (!Q.empty()) { n       x = Q.front(); n       Q.pop(); n       order[x] = k++; n       cnt++; n       for (i = 0; i < edge_idx[x].size(); i++) { n         Edge e = edges[edge_idx[x][i]]; n         z = -1; n         if (e.t == 1 && e.x == x) { n           y = e.y; n           if (--in_digree[y] == 0) Q.push(y); n         } n       } n     } n     if (cnt != n) { n       cout <<  NO n ; n     } else { n       cout <<  YES n ; n       for (i = 0; i < edges.size(); i++) { n         Edge e = edges[i]; n         if (order[e.x] < order[e.y]) { n           cout << e.x + 1 <<     << e.y + 1 << endl; n         } else { n           cout << e.y + 1 <<     << e.x + 1 << endl; n         } n       } n     } n   } n   return 0; n } n