#include <bits/stdc++.h> n using namespace std; n const int N = 10, M = 1e6 + 7, K = 200, p = 1e9 + 7; n int n, e[N], s[M], wf[K], q[N][K], f[N][N], ans[N][M]; n bitset<40> op, wq[N][M]; n unordered_map<bitset<40>, int> rt[N]; n inline int read() { n   int num = 0; n   char g = getchar(); n   while (g < 48 || 57 < g) g = getchar(); n   while (47 < g && g < 58) n     num = (num << 1) + (num << 3) + g - 48, g = getchar(); n   return num; n } n inline long long pows(long long u, int v) { n   long long ans = 1; n   while (v > 0) { n     if (v & 1) ans = ans * u % p; n     u = u * u % p, v = v >> 1; n   } n   return ans; n } n inline void find(int u) { n   q[u][0] = 0; n   int os = 0, of = 0; n   for (int i = 0; i < (1 << n); i++) n     if (s[i] == u) q[u][++q[u][0]] = i, wf[i] = ++os; n   for (int i = 1; i <= e[u - 1]; i++) { n     if (!ans[u - 1][i]) continue; n     for (int h = 1; h < (1 << n); h++) { n       long long opq = 1; n       for (int c = 0; c < n; c++) n         if ((1 << c) & h) n           opq = opq * f[u][c + 1] % p; n         else n           opq = opq * (1 - f[u][c + 1] + p) % p; n       bitset<40> c = wq[u - 1][i], hc = op; n       bool tg = 0; n       for (int x = 1; x <= q[u - 1][0]; x++) { n         if (c[x] == 1) { n           for (int t = 0; t < n; t++) n             if (((1 << t) & h) && (!(q[u - 1][x] & (1 << t)))) { n               hc[wf[q[u - 1][x] | (1 << t)]] = 1, tg = 1; n             } n         } n       } n       if (!tg) continue; n       int pos; n       if (rt[u][hc] == 0) rt[u][hc] = ++of, e[u]++, wq[u][e[u]] = hc; n       pos = rt[u][hc]; n       ans[u][pos] = (ans[u][pos] + opq * ans[u - 1][i]) % p; n     } n   } n } n int main() { n   n = read(); n   for (int i = 0; i <= (1 << n); i++) s[i] = __builtin_popcount(i); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) f[i][j] = read() * pows(100, p - 2) % p; n   q[0][0] = 1; n   e[0] = 1, ans[0][1] = 1, wq[0][1][1] = 1; n   for (int i = 1; i <= n; i++) find(i); n   cout << ans[n][1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int r, x, y, x1, y1, t, u; n   double ans = 0; n   cin >> r >> x >> y >> x1 >> y1; n   t = abs(x - x1); n   u = abs(y - y1); n   ans = t * t + u * u; n   ans = sqrt(ans); n   ans = ans / (2 * r); n   ans = ceil(ans); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t seed; n mt19937 rng(seed = chrono::steady_clock::now().time_since_epoch().count()); n inline int32_t rnd(int32_t l = 0, int32_t r = INT_MAX) { n   return uniform_int_distribution<int32_t>(l, r)(rng); n } n template <typename T, typename G> n ostream& operator<<(ostream& out, const pair<T, G>& a) { n   return out <<  (  << a.first <<   ,   << a.second <<  ) ; n } n template <typename T> n ostream& operator<<(ostream& out, const vector<T>& a) { n   out <<  [ ; n   for (const auto& i : a) out << i <<   ,  ; n   return out <<  ] ; n } n template <typename T> n ostream& operator<<(ostream& out, const set<T>& a) { n   out <<  { ; n   for (const auto& i : a) out << i <<   ,  ; n   return out <<  } ; n } n template <typename T, typename G> n ostream& operator<<(ostream& out, const map<T, G>& a) { n   out <<  < ; n   for (const auto& i : a) out << i <<   ,  ; n   return out <<  > ; n } n template <typename T, size_t N> n typename enable_if<!is_same<typename remove_cv<T>::type, char>::value, n                    ostream&>::type n operator<<(ostream& out, T (&a)[N]) { n   out <<  [ ; n   for (size_t i = 0; i < N; ++i) out << a[i] <<   ,  ; n   out <<  ] ; n   return out; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int32_t n, i, first = 0; n   cin >> n; n   vector<int32_t> a(n), b(n), o, e; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     b[i] = a[i] / 2; n     first += b[i]; n     if (a[i] & 1) { n       if (a[i] > 0) { n         o.push_back(i); n       } else { n         e.push_back(i); n       } n     } n   } n   if (first > 0) { n     for (i = 0; i < e.size() && first; i++, first--) b[e[i]]--; n   } else if (first < 0) { n     for (i = 0; i < o.size() && first; i++, first++) b[o[i]]++; n   } n   for (i = 0; i < n; i++) cout << b[i] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 400; n const int MOD = (int)1e9 + 7; n int n, x; n long long fac[N], c[N][N]; n map<int, int> h; n vector<int> d; n int fix(int x) { n   for (int i = 2; i * i <= x; i++) { n     while (x % (i * i) == 0) { n       x /= i * i; n     } n   } n   return x; n } n void add(long long &x, long long y) { n   x += y; n   x %= MOD; n } n int main() { n   memset(c, 0, sizeof c); n   fac[0] = 1; n   for (int i = 1; i < N; i++) { n     fac[i] = fac[i - 1] * i % MOD; n   } n   for (int i = 0; i < N; i++) { n     c[i][0] = 1; n     for (int j = 1; j <= i; j++) { n       c[i][j] = c[i - 1][j - 1] + c[i - 1][j]; n       if (c[i][j] >= MOD) { n         c[i][j] -= MOD; n       } n     } n   } n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &x); n     x = fix(x); n     if (h.count(x) == 0) { n       h[x] = 1; n     } else { n       int y = h[x]; n       h[x] = y + 1; n     } n   } n   for (auto it = h.begin(); it != h.end(); it++) { n     d.push_back(it->second); n   } n   sort(d.begin(), d.end()); n   int now = d[0] + 1; n   vector<long long> dp(now + 1, 0); n   dp[d[0] - 1] = fac[d[0]]; n   for (int i = 1; i < d.size(); i++) { n     vector<long long> ndp(now + d[i] + 1, 0); n     for (int same = 0; same <= now; same++) { n       int dif = now - same; n       if (dp[same] == 0) { n         continue; n       } n       for (int j = 1; j <= d[i] && j <= now; j++) { n         for (int k = 0; k <= same && k <= j; k++) { n           int nsame = same - k + d[i] - j; n           add(ndp[nsame], dp[same] * c[d[i] - 1][j - 1] % MOD * c[same][k] % n                               MOD * c[dif][j - k] % MOD * fac[d[i]]); n         } n       } n     } n     now += d[i]; n     dp.swap(ndp); n   } n   printf( %lld n , dp[0]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300010; n int a[N], f[N][21], la[21]; n int main() { n   int n, q; n   scanf( %d%d , &n, &q); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     for (int j = 0; j <= 18; j++) n       if (!(a[i] & (1 << j))) n         for (int k = 0; k <= 18; k++) n           if (a[i] & (1 << k)) f[i][j] = max(f[i][j], f[la[k]][j]); n     for (int j = 0; j <= 18; j++) n       if (a[i] & (1 << j)) f[i][j] = i, la[j] = i; n   } n   for (int i = 1; i <= q; i++) { n     int l, r; n     scanf( %d%d , &l, &r); n     bool flag = false; n     for (int j = 0; j <= 18; j++) n       if ((a[l] & (1 << j)) && f[r][j] >= l) flag = true; n     if (flag) n       printf( Shi n ); n     else n       printf( Fou n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 5; n const int MOD = 1000000007; n int a[300005]; n int main() { n   int n, p; n   cin >> n >> p; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   while (p--) { n     int l, r, x; n     cin >> l >> r >> x; n     int lar = r - x; n     int num = a[x]; n     int count = 0; n     for (int i = l; i <= r; i++) { n       if (a[i] > num) { n         count++; n       } n     } n     if (count == lar) { n       cout <<  Yes  << endl; n     } else n       cout <<  No  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct edge { n   int a, b, cost; n }; n vector<edge> e; n const int INF = 1e8; n char alphabet[26] = { a ,  b ,  c ,  d ,  e ,  f ,  g ,  h ,  i , n                       j ,  k ,  l ,  m ,  n ,  o ,  p ,  q ,  r , n                       s ,  t ,  u ,  v ,  w ,  x ,  y ,  z }; n bool consistence_check = false; n bool size_check = true; n int aristas = 0; n vector<int> d(27, INF); n void Bellman_Ford(vector<edge> e, int n, int m) { n   d[26] = 0; n   vector<int> p(n); n   int x; n   for (int i = 0; i < n; ++i) { n     x = -1; n     for (int j = 0; j < m; ++j) n       if (d[e[j].a] < INF) { n         if (d[e[j].b] > d[e[j].a] + e[j].cost) { n           d[e[j].b] = max(-INF, d[e[j].a] + e[j].cost); n           p[e[j].b] = e[j].a; n           x = e[j].b; n         } n       } n   } n   if (x == -1) { n     consistence_check = true; n   } n } n void compare_strings(string string1, string string2) { n   int size1 = string1.size(); n   int size2 = string2.size(); n   int minsize = min(size1, size2); n   bool failsafe = true; n   for (int a = 0; a < minsize; a++) { n     if (string1[a] != string2[a]) { n       edge tempedge = {string1[a] -  a , string2[a] -  a , -1}; n       e.emplace_back(tempedge); n       aristas += 1; n       failsafe = false; n       break; n     } n   } n   if (size1 > size2 and failsafe) { n     size_check = false; n   } n } n int main() { n   vector<string> lexico; n   int cantidad; n   cin >> cantidad; n   string temp; n   for (int k = 0; k < cantidad; k++) { n     cin >> temp; n     lexico.emplace_back(temp); n   } n   for (int a = 0; a < cantidad - 1; a++) { n     compare_strings(lexico[a], lexico[a + 1]); n   } n   for (int k = 0; k < 26; k++) { n     edge tempedge = {26, k, 0}; n     e.emplace_back(tempedge); n   } n   aristas += 26; n   if (size_check) { n     Bellman_Ford(e, 27, aristas); n   } n   if (consistence_check) { n     for (int k = 0; k > -26; k--) { n       for (int a = 0; a < 26; a++) { n         if (d[a] == k) { n           cout << alphabet[a]; n         } n       } n     } n   } else { n     cout <<  Impossible ; n   } n   return 0; n } n


/** n  * code generated by JHelper n  * More info: https://github.com/AlexeyDmitriev/JHelper n  * @author n  */ n  n #include <iostream> n #include <fstream> n  n #include <iostream> n #include <algorithm> n #include <queue> n #include <vector> n #include <set> n #include <map> n #include <cassert> n #include <functional> n #include <sstream> n #include <cmath> n  n #include <cstring> n #include <cstdio> n #ifndef ATCODER_DSU_HPP n #define ATCODER_DSU_HPP 1 n  n  n  n  n  n namespace atcoder { n  n // Implement (union by size) + (path compression) n // Reference: n // Zvi Galil and Giuseppe F. Italiano, n // Data structures and algorithms for disjoint set union problems n struct dsu { n   public: n     dsu() : _n(0) {} n     explicit dsu(int n) : _n(n), parent_or_size(n, -1) {} n  n     int merge(int a, int b) { n         assert(0 <= a && a < _n); n         assert(0 <= b && b < _n); n         int x = leader(a), y = leader(b); n         if (x == y) return x; n         if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y); n         parent_or_size[x] += parent_or_size[y]; n         parent_or_size[y] = x; n         return x; n     } n  n     bool same(int a, int b) { n         assert(0 <= a && a < _n); n         assert(0 <= b && b < _n); n         return leader(a) == leader(b); n     } n  n     int leader(int a) { n         assert(0 <= a && a < _n); n         if (parent_or_size[a] < 0) return a; n         return parent_or_size[a] = leader(parent_or_size[a]); n     } n  n     int size(int a) { n         assert(0 <= a && a < _n); n         return -parent_or_size[leader(a)]; n     } n  n     std::vector<std::vector<int>> groups() { n         std::vector<int> leader_buf(_n), group_size(_n); n         for (int i = 0; i < _n; i++) { n             leader_buf[i] = leader(i); n             group_size[leader_buf[i]]++; n         } n         std::vector<std::vector<int>> result(_n); n         for (int i = 0; i < _n; i++) { n             result[i].reserve(group_size[i]); n         } n         for (int i = 0; i < _n; i++) { n             result[leader_buf[i]].push_back(i); n         } n         result.erase( n             std::remove_if(result.begin(), result.end(), n                            [&](const std::vector<int>& v) { return v.empty(); }), n             result.end()); n         return result; n     } n  n   private: n     int _n; n     // root node: -1 * component size n     // otherwise: parent n     std::vector<int> parent_or_size; n }; n  n }  // namespace atcoder n  n #endif  // ATCODER_DSU_HPP n  n  n using namespace std; n  n typedef pair<int, int> ii; n typedef long long int64; n typedef vector<int> vi; n  n #define pb push_back n #define mp make_pair n #define all(v) (v).begin(),(v).end() n #define sz(v) ((int)(v).size()) n  n template<class T> T abs(T x) { return x >= 0 ? x : -x; } n template<class T> T sqr(T x) { return x * x; } n  n class TaskC { n public: n     vector<vector<ii>> g; n     vector<vi> up; n     vi d; n     vi tin, tout; n     int T; n  n  void solve(std::istream& in, std::ostream& out) { n      int n, m; n      in >> n >> m; n      vector<pair<int, ii>> edges(m); n      set<ii> es; n      int X = 0; n      for (int i = 0; i < m; ++i) { n             in >> edges[i].second.first >> edges[i].second.second >> edges[i].first; n             X ^= edges[i].first; n             --edges[i].second.first; n             --edges[i].second.second; n             es.insert(ii(edges[i].second.first, edges[i].second.second)); n             es.insert(ii(edges[i].second.second, edges[i].second.first)); n             //g[edges[i].second.first].pb(ii(edges[i].second.second, edges[i].first)); n             //g[edges[i].second.second].pb(ii(edges[i].second.first, edges[i].first)); n         } n      sort(all(edges)); n //     for (int i = 0; i < n; ++i) { n //         sort(all(g[i])); n //     } n      int64 remaining = n; n      remaining *= (n - 1); n      remaining /= 2LL; n      remaining -= m; n      assert(remaining >= 0); n      if (remaining >= n) { n          atcoder::dsu dsu(n); n          set<int> alive; n             for (int i = 0; i < n; ++i) { n                 alive.insert(i); n             } n          for (int i = 0; i < n; ++i) { n              vi cur(all(alive)); n              for (int x : cur) { n                  if (dsu.same(x, i)) continue; n                  if (es.count(ii(x, i))) continue; n                  alive.erase(dsu.leader(x)); n                     alive.erase(dsu.leader(i)); n                  dsu.merge(x, i); n                     alive.insert(dsu.leader(x)); n              } n          } n          int64 res = 0; n          for (auto e : edges) { n              int x = e.second.first; n              int y = e.second.second; n              if (dsu.same(x, y)) continue; n              res += e.first; n              dsu.merge(x, y); n          } n          out << res <<   n ; n          return; n      } n      assert(n <= 1000); n      for (int i = 0; i < n; ++i) { n             for (int j = i + 1; j < n; ++j) { n                 if (!es.count(ii(i, j))) n                     edges.emplace_back(0, ii(i, j)); n             } n         } n      sort(all(edges)); n         int64 base = 0; n         atcoder::dsu dsu(n); n         g = vector<vector<ii>>(n); n         vi in_tree(sz(edges), 0); n         for (int i = 0; i < sz(edges); ++i) { n             auto e = edges[i]; n             int x = e.second.first; n             int y = e.second.second; n             if (dsu.same(x, y)) continue; n             g[x].pb(ii(e.first, y)); n             g[y].pb(ii(e.first, x)); n             base += e.first; n             dsu.merge(x, y); n             in_tree[i] = 1; n         } n         int64 res = base + X; n  n         up = vector<vi>(21, vi(n, -1)); n         tin = vi(n, 0); n         tout = vi(n, 0); n         d = vi(n, 0); n         T = 0; n         dfs(0, -1, 0); n         for (int i = 1; i < sz(up); ++i) { n             for (int j = 0; j < n; ++j) { n                 int x = up[i - 1][j]; n                 if (x != -1) { n                     x = up[i - 1][x]; n                 } n                 up[i][j] = x; n             } n         } n         int64 best = (int64)(1e12); n         for (int I = 0; I < sz(edges); ++I) { n             auto e = edges[I]; n             //if (e.first == 0) continue; n             if (in_tree[I]) continue; n             if (e.first >= best) continue; n             int x = e.second.first; n             int y = e.second.second; n             int r = x; n             for (int i = sz(up) - 1; i >= 0; --i) { n                 int t = up[i][r]; n                 if (t == -1) continue; n                 if (!parent(t, y)) n                     r = t; n             } n             if (!parent(r, y)) n                 r = up[0][r]; n             assert(parent(r, x)); n             assert(parent(r, y)); n             int s = (d[x] - d[r]) + (d[y] - d[r]); n             if (s > 0) { n                 best = min<int64>(best, e.first); n             } n         } n         res = min(res, base + best); n  n         out << res <<   n ; n  } n  n  void dfs(int x, int p, int s) { n      up[0][x] = p; n      ++T; n      tin[x] = T; n      d[x] = s; n      for (ii e : g[x]) if (e.second != p) { n          dfs(e.second, x, s + (e.first == 0 ? 1 : 0)); n      } n      tout[x] = T; n  } n  n  bool parent(int x, int y) { n      return tin[y] >= tin[x] && tin[y] <= tout[x]; n  } n }; n  n  n int main() { n  TaskC solver; n  std::istream& in(std::cin); n  std::ostream& out(std::cout); n  solver.solve(in, out); n  return 0; n } n


/*  Karmanye vadhikaraste Ma Phaleshu Kadachana | Ma Karmaphalaheturbhurma Te Sangostvakarmani ||*/ n //----------------------------------------------------------------------------------------------------------------// n  n /* this is begining have to survive more and go through long journey*/  n //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// n #include<bits/stdc++.h> n using namespace std; n #define pb push_back n #define vi vector<int> n #define vii vector<vi> n #define vll vector<long long> n #define mx(v) *max_element(v.begin(),v.end()) n #define mn(v) *min_element(v.begin(),v.end()) n #define st(v) sort(v.begin(),v.end()) n #define bg .begin() n #define ed .end() n #define fi first n #define sc second n #define fr(i,l,u) for(i=l;i<u;i++) n #define rfr(i,l,u) for(i=l;i>u;i--) n #define ll long long int n #define lld long long double n #define uld unsigned long long int n #define pii pair<int,int> n #define flash ios_base::sync_with_stdio(0);cin.tie(NULL); n #define mod 1000000007 n   n  void solve() n { n     ll n,i,x,sum=0,rem=0; n     cin>>n; n     vi v; n     fr(i,0,n) n     { n         cin>>x; n         sum+=x; n     } n     rem=sum%n; n     cout<<(n-rem)*rem<<endl; n      n      n }       n int main() n { n      int t; n    cin>>t; n    while(t--) solve(); n  n }


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n int n, k; n char s[N]; n int chk(char s[]) { n   for (int i = 1; i <= n; i += k) { n     for (int j = 1; j <= k; j++) { n       if (i + j - 1 > n || i + j - 1 + k > n) break; n       if (s[i + j - 1] != s[i + j - 1 + k]) { n         if (s[i + j - 1] > s[i + j - 1 + k]) n           return -1; n         else n           return 1; n       } n     } n   } n   return 0; n } n int main() { n   cin >> n >> k; n   scanf( %s , s + 1); n   int flag = chk(s); n   if (flag == 0) { n     printf( %d n , n); n     printf( %s n , s + 1); n     return 0; n   } else if (flag == -1) { n     for (int i = 1; i <= n; i += k) { n       for (int j = 1; j <= k; j++) { n         if (i + j - 1 > n || i + j - 1 + k > n) break; n         s[i + j - 1 + k] = s[i + j - 1]; n       } n     } n     printf( %d n , n); n     printf( %s n , s + 1); n     return 0; n   } else { n     bool ff = 0; n     if (s[k] ==  9 ) n       s[k] =  0 , ff = 1; n     else n       s[k]++; n     if (ff) { n       for (int i = k - 1; i >= 1; i--) { n         if (s[i] ==  9 ) { n           s[i] =  0 ; n           continue; n         } n         s[i]++; n         break; n       } n     } n     for (int i = 1; i <= n; i += k) { n       for (int j = 1; j <= k; j++) { n         if (i + j - 1 > n || i + j - 1 + k > n) break; n         s[i + j - 1 + k] = s[i + j - 1]; n       } n     } n     printf( %d n , n); n     printf( %s n , s + 1); n     return 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ans = 0, ar[100001], n, ll, ars[100001]; n string s; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &ars[i]); n     ar[i] = ar[i - 1] + ars[i]; n   } n   cin >> s; n   for (int i = n - 1; i >= 0; i--) { n     if (s[i] ==  1 ) { n       ans = max(ans, ar[i] + ll); n     } n     if (s[i] ==  1 ) ll += (ars[i + 1]); n   } n   ans = max(ans, ll); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n vector<pair<int, int> > a; n long long sum, ans; n int e, deg; n int get_e(int num, int deg) { n   if (num == 1) return 0; n   if (num == 2) return 1; n   int res = num * (num - 1) / 2; n   if (deg & 1) { n     int bad = num - 2; n     res += bad / 2; n   } n   return res; n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= m; i++) { n     int q, w; n     scanf( %d %d , &q, &w); n     a.push_back(make_pair(w, q)); n   } n   sort(a.rbegin(), a.rend()); n   for (int i = 1; i <= min(3000, m); i++) { n     sum += a[i - 1].first; n     deg = i - 1; n     e = get_e(i, deg); n     if (e + 1 <= n) ans = max(ans, sum); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rnd(1919810); n int T, n, K, zr; n inline char qry(int la, int ra, int lb, int rb) { n   cout <<  ?   << ra - la + 1 <<     << rb - lb + 1 << endl; n   for (int i = la; i <= ra; i++) cout << i << (i == ra ?   n  :    ); n   for (int i = lb; i <= rb; i++) cout << i << (i == rb ?   n  :    ); n   fflush(stdout); n   char c[15]; n   return scanf( %s , c), *c; n } n inline char blck1() { n   for (int i = 2; i <= n; i++) n     if (qry(1, 1, i, i) ==  S ) return 1; n   return 0; n } n inline char rdck1() { n   for (int i = 1, x = rnd() % (n - 1) + 2; i <= 30; n        i++, x = rnd() % (n - 1) + 2) n     if (qry(1, 1, x, x) ==  S ) return 1; n   return 0; n } n inline void work(int l, int r) { n   int md = (l + r) >> 1; n   if (l == r) return printf( ! %d n , l), void(); n   if (qry(1, md - l + 1, l, md) ==  E ) n     return work(md + 1, r); n   else n     return work(l, md); n } n inline void solve() { n   cin >> n >> K; n   if ((n <= 30 && blck1()) || (n > 30 && rdck1())) return puts( ! 1 ), void(); n   for (int i = 1; i <= n; i <<= 1) n     if (qry(1, min(i, n - i), i + 1, min(i << 1, n)) !=  E ) n       return work(i + 1, min(i << 1, n)); n } n int main() { n   for (cin >> T; T--;) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename float_t> n struct _complex_ { n   float_t x, y; n   _complex_<float_t>(float_t _x = 0, float_t _y = 0) : x(_x), y(_y) {} n   float_t real() const { return x; } n   void real(float_t _x) { x = _x; } n   float_t imag() const { return y; } n   void imag(float_t _y) { y = _y; } n   _complex_<float_t> &operator+=(const _complex_<float_t> &other) { n     x += other.x; n     y += other.y; n     return *this; n   } n   _complex_<float_t> &operator-=(const _complex_<float_t> &other) { n     x -= other.x; n     y -= other.y; n     return *this; n   } n   _complex_<float_t> operator+(const _complex_<float_t> &other) const { n     return _complex_<float_t>(*this) += other; n   } n   _complex_<float_t> operator-(const _complex_<float_t> &other) const { n     return _complex_<float_t>(*this) -= other; n   } n   _complex_<float_t> operator*(const _complex_<float_t> &other) const { n     return {x * other.x - y * other.y, x * other.y + other.x * y}; n   } n   _complex_<float_t> operator*(float_t mult) const { n     return {x * mult, y * mult}; n   } n }; n template <typename float_t> n _complex_<float_t> conj(const _complex_<float_t> &c) { n   return {c.x, -c.y}; n } n template <typename float_t> n _complex_<float_t> polar(float_t magnitude, float_t angle) { n   return {magnitude * cos(angle), magnitude * sin(angle)}; n } n template <typename float_t> n ostream &operator<<(ostream &stream, const _complex_<float_t> &c) { n   return stream <<  (  << c.x <<  ,   << c.y <<  ) ; n } n const int mod = 1e9 + 7; n const long long inf = 9223372036854775807; n struct query { n   int y, pos, type; n   query(int a, int b, int c) { y = a, pos = b, type = c; } n }; n bool query_sort(const query &a, const query &b) { n   if ((a.y ^ b.y)) { n     return (a.y < b.y); n   } n   return (a.pos ^ b.pos) ? (a.pos < b.pos) : (a.type < b.type); n } n int n, k; n int x_coor[300 * 100001], y_coor[300 * 100001], sorted_x[100001]; n long long ans[100001]; n map<int, int> pos; n signed main() { n   cin >> n >> k; n   for (int i = 0; i < n; ++i) { n     cin >> x_coor[i] >> y_coor[i]; n     sorted_x[i] = x_coor[i]; n   } n   sort(sorted_x, sorted_x + n); n   int oniichan = 0; n   sorted_x[n] = mod; n   for (int i = 0; i < n; ++i) { n     if (sorted_x[i] ^ sorted_x[i + 1]) { n       pos[sorted_x[i]] = oniichan + 1; n       oniichan += min(sorted_x[i] + k, sorted_x[i + 1]) - sorted_x[i]; n     } n   } n   vector<query> q; n   for (int i = 0; i < n; ++i) { n     q.push_back(query(y_coor[i], pos[x_coor[i]], 1)); n     q.push_back(query(y_coor[i] + k, pos[x_coor[i]], -1)); n   } n   sort((q).begin(), (q).end(), query_sort); n   memset(x_coor, 0, sizeof(x_coor)); n   memset(y_coor, 0, sizeof(y_coor)); n   for (query &i : q) { n     for (int j = i.pos; j < i.pos + k; ++j) { n       ans[y_coor[j]] += i.y - x_coor[j]; n       y_coor[j] += i.type; n       x_coor[j] = i.y; n     } n   } n   for (int i = 1; i < n + 1; ++i) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:268435456 ) n using namespace std; n const int maxn = 4050; n const int maxsec = 86400; n vector<pair<int, int> > input; n int dp[maxn][maxn]; n int main() { n   int k, n; n   scanf( %d , &n); n   ; n   scanf( %d , &k); n   ; n   int i, j; n   int x, y; n   for (i = 0; i < n; ++i) { n     scanf( %d , &x); n     ; n     scanf( %d , &y); n     ; n     input.push_back(make_pair(x - 1, y)); n   } n   if (k >= n) { n     printf( %d n , maxsec); n     ; n     return 0; n   } n   sort(input.begin(), input.end()); n   int m = input.size(); n   dp[0][0] = input[0].first + input[0].second; n   for (j = 1; j <= k; ++j) dp[0][j] = 0; n   for (i = 1; i < m; ++i) { n     dp[i][0] = max(input[i].first, dp[i - 1][0]) + input[i].second; n     for (j = 1; j <= k; ++j) { n       dp[i][j] = min(dp[i - 1][j - 1], n                      max(dp[i - 1][j], input[i].first) + input[i].second); n     } n   } n   int ans = input[k].first; n   int wakeup; n   for (i = 0; i < m; ++i) n     for (j = 0; j <= k; ++j) { n       if (i + k - j + 1 < m) n         wakeup = input[i + k - j + 1].first; n       else n         wakeup = maxsec; n       ans = max(ans, wakeup - dp[i][j]); n     } n   printf( %d n , ans); n   ; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   std::ios_base::sync_with_stdio(0); n   int n, m, k, a, ans = 0; n   std::cin >> n >> m >> k; n   for (int i = 0; i < n; i++) { n     std::cin >> a; n     if (a == 1) { n       m--; n       if (m == -1) { n         m++; n         ans++; n       } n     } n     if (a == 2) { n       if (k > 0) n         k--; n       else { n         m--; n         if (m == -1) { n           m++; n           ans++; n         } n       } n     } n   } n   std::cout << ans++; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int row[5001] = {0}; n int rowt[5001] = {0}; n int col[5001] = {0}; n int colt[5001] = {0}; n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   int q, t, a; n   for (int i = 1; i < k + 1; i++) { n     cin >> q >> t >> a; n     t--; n     if (q == 1) { n       row[t] = a; n       rowt[t] = i; n     } n     if (q == 2) { n       col[t] = a; n       colt[t] = i; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (colt[j] > rowt[i]) n         cout << col[j] <<    ; n       else n         cout << row[i] <<    ; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int Array[n]; n   for (int i = (int)0; i < (int)n; ++i) cin >> Array[i]; n   stable_sort(Array, Array + n); n   int Sum = accumulate(Array, Array + n, 0, plus<int>()); n   int Middle = Sum / n; n   vector<int> a(n, Middle); n   int NewSum = Middle * n; n   int Diff = n - (Sum - NewSum); n   int Ans = 0; n   for (int i = 0; i < n; ++i) { n     if (i >= Diff) { n       Ans += abs(Array[i] - (a[i] + 1)); n     } else { n       Ans += abs(Array[i] - a[i]); n     } n   } n   cout << Ans / 2; n   return 0; n } n


#include <bits/stdc++.h> n const double pi = 3.1415926535897; n using namespace std; n int main() { n   string s; n   cin >> s; n   int counter = 0; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  a ) counter++; n   } n   if (s.length() / 2 < counter) n     cout << s.length(); n   else n     cout << (counter - 1) * 2 + 1; n } n


/*#pragma GCC optimize( O3 ) n #pragma GCC target( avx,avx2,fma ) n #pragma GCC optimize( unroll-loops )*/ n #include<bits/stdc++.h> n using namespace std; n  n #define  CIN            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) n #define  ll             long long int n #define  pb             push_back n #define  ull            unsigned long long int n #define  pii            pair < ll, ll> n #define  pll            pair < ll, pii> n #define  ff             first n #define  ss             second n #define  mx4            1000005 n #define  MOD            1000000007 n #define  mod2           1000000009 n #define  min3(a,b,c)    min(a,min(b,c)) n #define  min4(a,b,c,d)  min(d,min(a,min(b,c))) n #define  max3(a,b,c)    max(a,max(b,c)) n #define  max4(a,b,c,d)  max(d,max(a,max(b,c))) n #define  ms(a,b)        memset(a,b,sizeof(a)) n #define  mpp            make_pair n #define  gcd(a, b)      __gcd(a,b) n #define  lcm(a, b)      ((a)*(b)/gcd(a,b)) n #define  input          freopen( input.txt , rt , stdin) n #define  output         freopen( output.txt , wt , stdout) n #define  PI             2*acos(0.0) n #define  zero(a)        memset(a,0,sizeof a) n #define  all(a)         a.begin(),a.end() n #define  rall(a)        a.rbegin(),a.rend() n #define  rev(a)         reverse(all(a)) n #define  upper(s)       transform(s.begin(),s.end(),s.begin(), ::toupper) n #define  lower(s)       transform(s.begin(),s.end(),s.begin(), ::tolower) n #define  Unique(X)      (X).erase(unique(all(X)),(X).end()) n #define  MX             200005 n #define  nl               n  n #define  yes            cout<< YES <<endl n #define  no             cout<< NO <<endl n #define  fix(x)         cout<<fixed<<setprecision(x) n #define  coutv(v)       for(auto it:v)cout<<it<<space;cout<<nl; n #define  cinv(v)        for(auto &it:v)cin>>it; n #define  Case(x)        cout<< Case  <<x<< :   n #define  strtoint(a)    atoi(a.c_str()) n #define  dbg(x)         cerr<<#x<<  is  <<x<<  n ; n #define  fix(x)         cout<<fixed<<setprecision(x) n #define  leastonepos(x) __builtin_ffs(x) n #define  leadingoff(x)  __builtin_clz(x) n #define  trailingoff(x) __builtin_ctz(x) n #define  numofone(x)    __builtin_popcount(x) n #define  error(args...) { string _s = #args; replace(_s.begin(), _s.end(),  , ,    ); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); } n  n ///Compute_phi_co_prime n /*void computeTotient(int n){ll phi[n+5];for (int i=1; i<=n; i++)phi[i] = i;for (int p=2; p<=n; p++) n {if (phi[p] == p){phi[p] = p-1;for (int i = 2*p; i<=n; i += p){phi[i] = (phi[i]/p) * (p-1);}}}}*/ n ///seieve n /*vector<bool>mark(100000004);vector<int>prm;void sieve(int x){mark[0]=mark[1]=1; n for(int i =4; i<=x; i=i+2)mark[i]=1;for(int i=3; i*i<=x; i+=2)if(!mark[i]) n for(int j=i*i; j<=x; j+=2*i)mark[j]=1;prm.push_back(2);for(int i=3; i<=x; i+=2) n if(mark[i]==0)prm.push_back(i);}*/ n ///PrimeFactorization n /*vector<int>pf;void primeFact(ll n){for(int i=0; i<prm.size()&&prm[i]*prm[i]<=n; i++) n {if(n%prm[i]==0){while(n%prm[i]==0){n=n/prm[i] ;pf.push_back(prm[i]);}}}if(n>1)pf.push_back(n);}*/ n ///power n /*ll pow( ll base , ll val ){ll res = 1 ;for(int i = 1 ; i <= val ; i++ ){res *= base ;}return res ;}*/ n ///Fibonacci n /*ll fib[ 100005 ] ;fib[ 1 ] = 1 ;fib[ 2 ] = 2 ; n for( int i = 3 ; i <= 100000 ; i ++ ){ fib[ i ] = ( fib[ i - 1 ] + fib[ i - 2 ] ) % MOD ;}*/ n //min_dis(character) n /*ll min_dis(char ch1,char ch2){ll x = abs(ch1-ch2);return min(x,26-x);}*/ n ///leap_year n /*inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }*/ n ///BinToDec n /*ll BinToDec(bitset<64>bs) n {ll sum = 0 ,lim=bs.size();for( int i = 0 ; i <= lim ; i ++ )sum += bs2[ i ] * pow( 2, i ) ;return sum ;}*/ n ///Multiplication_With_Mod n /*long long fun(long long a, long long b){long long res = 0;a %= MOD;while (b) n {if (b & 1)res = (res + a) % MOD;a = (2 * a) % MOD;b >>= 1;}return res;}*/ n ///power of two n /*ll Pow[65];void power_of_two(){Pow[0]=1; n for(int i = 1 ; i <= 60 ; i++) Pow[i]=Pow[i-1]*2ll;}*/ n /* ll com[200005][102]; n void combination() n { n     com[1][1]=com[0][0]=1; n     com[1][0]=1; n     for(ll i=2; i<=200004; i++) n     { n         com[i][0]=1; n         for(ll j=1; j<=min(i,100LL); j++) n         { n             com[i][j]=com[i-1][j]+com[i-1][j-1]; n             com[i][j]%=MOD; n         } n     } n } n */ n ///---------------Order set------------------- n ///*os.find_by_order(index) os.order_of_key(value) n /*#include <ext/pb_ds/assoc_container.hpp> n #include <ext/pb_ds/tree_policy.hpp> n using namespace __gnu_pbds; n template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; n orderset<ll>os ;*/ n /*ll Os_Bound(ll x , ll UpOrLow) n {if(UpOrLow==2) x++;ll pos = os.order_of_key(x);if (pos == os.size()) return -1;else return *(os.find_by_order(pos));}*/ n  n ///priority_queue<int,vector<int>,greater<int> >pq; n ///string s5 =  abcdefghijklmnopqrstuvwxyz ; n ///string s6 =  ABCDEFGHIJKLMNOPQRSTUVWXYZ ; n ///int days [14] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; n ///string month[14]= { January ,  February ,  March ,  April ,  May ,  June ,  July ,  August ,  September ,  October ,  November ,  December }; n ///--------------Graph Moves-------------------------------------- n ///const int fx[] = {+1,-1,+0,+0}; n ///const int fy[] = {+0,+0,+1,-1}; n ///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King s move n ///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king s Move n ///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight s move n ///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight s move n ///--------------------------------------------------------------- n void err(istream_iterator<string> it) n { n     cerr<<endl; n } n template<typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) n { n     cerr << *it <<   =   << a <<   |  ; n     err(++it, args...); n } n /*int Set(int N,int pos){return N=N | (1<<pos);} n bool check(int N,int pos){return (bool)(N & (1<<pos));} n int reset(int N,int pos){return N= N & ~(1<<pos);}*/ n /* n /*ll bigmod(ll a , ll b , ll m) n { n     if(b==0) return 1; n     if(b&1) return (a%m * bigmod(a,b-1,m))%m; n     ll x = bigmod(a,b/2,m); n     return (x*x)%m; n } n ll inverse(ll a , ll b , ll m) n { n     return ((a%m)*bigmod(b,m-2,m)%m); n }*/ n /* n set<ll>st; n set<ll>::reverse_itertor it ; n for( it = rbegin() ; it!=st.rend() ; it++) n st.erase(next(it).base()); n set<ll>::iterator it ; n for( it = begin() ; it!=st.end() ; it++) n st.erase(it); n */ n /* n struct data{ n     ll wt,iq,indx; n     bool operator <(const data &other) const{ n         if (wt==other.wt) return iq>other.iq; n         return wt<other.wt; n     } n }ara[1005]; n */ n  n vector<ll>v1,v2,v3,v4; n ///vector<pii>v5; n string s1, s2, s3; n ///map<ll,ll>mp; n ///map<ll,ll>::iterator it; n ///ll ara[100005]; n ///multiset<ll>ms; n ///multiset<ll>::iterator it; n ///set<ll>st; n ///set<ll>::iterator it; n ///R () ; n  n int main() n { n     CIN; n     ll  a,b,c,d,e,f,i,j,k,m,n,cnt1=0,cnt2=0,sum1=0,sum2=0,chk1=0,chk2=0,T=1; n     cin>> T ; n     for( i = 1 ; i<= 32 ; i++) n     { n         v1.pb(pow(2,i)); n         //cout<<v1.back()<<endl; n     } n     while(T--) n     { n         cin >> a ; n         ll ck=0; n         if(a%2) n         { n             no; n             continue; n         } n  n         ll x = a/2; n         ll y = sqrt(x); n         if(y*y==x) n         { n             yes; n             continue; n         } n  n         ll low = 1 , high = 100000, ans = 0; n  n         while(low<=high) n         { n             ll mid = (low+high)/2ll; n             if(mid*mid*4<=a) n             { n                 ans=mid; n                 low=mid+1; n             } n             else{ n                 high=mid-1; n             } n         } n         if(ans*ans*4==a) n         { n             yes; n         } n         else{ n             no; n         } n  n  n     } n     return 0 ; n } n ///printf & cout ekshatey use korbo nah n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n array<int, N> a; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> a[i]; n   long long ans = 0; n   long long power = 1; n   while (abs(power) < 1e15) { n     map<long long, int> m; n     m[0] = 1; n     long long sum = 0ll; n     for (int i = 0; i < n; i++) { n       sum += a[i]; n       ans += m[sum - power]; n       m[sum]++; n     } n     power *= k; n     if (power == 1) break; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve(int n, int k) { n   int i; n   for (i = 1; i <= 2 * k; ++i) n     if (i & 1) n       printf( %d %d  , 2 * i - 1, 2 * i); n     else n       printf( %d %d  , 2 * i, 2 * i - 1); n   for (i = 4 * k + 1; i <= 2 * n; ++i) printf( %d  , i); n   putchar(  n ); n } n int main() { n   int n, k; n   scanf( %d %d , &n, &k); n   solve(n, k); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 8; n const int dxs[] = {2, 1, -1, -2, -2, -1, 1, 2}; n const int dys[] = {-1, -2, -2, -1, 1, 2, 2, 1}; n char s0[8], s1[8]; n bool flds[N][N]; n inline void readpos(char s[], int &x, int &y) { n   x = s[0] -  a ; n   y = s[1] -  1 ; n } n inline void setknight(int x, int y) { n   for (int di = 0; di < 8; di++) { n     int vx = x + dxs[di], vy = y + dys[di]; n     if (vx >= 0 && vx < N && vy >= 0 && vy < N) flds[vy][vx] = true; n   } n } n int main() { n   scanf( %s%s , s0, s1); n   int rx, ry, kx, ky; n   readpos(s0, rx, ry); n   readpos(s1, kx, ky); n   flds[ry][rx] = flds[ky][kx] = true; n   for (int x = 0; x < N; x++) flds[ry][x] = true; n   for (int y = 0; y < N; y++) flds[y][rx] = true; n   setknight(kx, ky); n   setknight(rx, ry); n   int cnt = 0; n   for (int y = 0; y < N; y++) n     for (int x = 0; x < N; x++) n       if (!flds[y][x]) cnt++; n   printf( %d n , cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x, y; n   cin >> n >> x >> y; n   if ((x == n / 2 || x == n / 2 + 1) && (y == n / 2 || y == n / 2 + 1)) n     cout <<  NO  << endl; n   else n     cout <<  YES  << endl; n } n


#include <bits/stdc++.h> n const int MAXINT = 2147483640; n const long long MAXLL = 9223372036854775800LL; n const long long MAXN = 1000000; n const double pi = 3.1415926535897932384626433832795; n using namespace std; n double s, v1, v2; n long long n, kol; n long long check(double xx) { n   long long sum = 0; n   double anstime = 0, vk, s1, s2, tin, s3; n   while (1) { n     s3 = s - v1 * anstime; n     vk = (s3 - (xx - anstime) * v1) / (v2 - v1); n     anstime += vk; n     sum += kol; n     if (sum >= n) break; n     s2 = vk * v2 + (anstime - vk) * v1; n     s1 = anstime * v1; n     tin = (s2 - s1) / (v1 + v2); n     anstime += tin; n     if (anstime > xx) return 0; n   } n   if (xx - anstime >= 0) n     return 1; n   else n     return 0; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   srand(time(0)); n   double time, kolend, s1, t1, s2, l, r, c; n   cin >> n >> s >> v1 >> v2 >> kol; n   l = 0; n   r = s / v1 + 1; n   while (r - l > 1e-6) { n     c = (l + r) / 2; n     if (check(c)) n       r = c; n     else n       l = c; n   } n   cout << fixed << setprecision(7) << l << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, ans; n   scanf( %lld , &n); n   if (n % 2 == 0) { n     ans = n / 2; n   } n   if (n % 2 == 1) { n     ans = (n - 1) / 2 - n; n   } n   printf( %lld n , ans); n   return 0; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, d, a[1000]; n int main() { n   cin >> n >> d; n   for (int i = 0; i < n; i++) { n     int s; n     cin >> s; n     a[s]++; n   } n   int maxn = 0; n   for (int i = 1; i <= 100; i++) { n     int l = 0; n     for (int j = i; j <= i + d; j++) { n       l += a[j]; n     } n     if (l > maxn) { n       maxn = l; n     } n   } n   cout << n - maxn << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int s1[105], s2[105]; n int a[105], b[105]; n int tt[305]; n int main() { n   int n, T; n   scanf( %d%d , &n, &T); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     b[i] = a[i]; n   } n   sort(b + 1, b + 1 + n); n   for (int i = 1; i <= n; i++) tt[b[i]] = i; n   memset(s1, 0, sizeof s1); n   memset(s2, 0, sizeof s2); n   int boardl = min(T / 2, 100); n   int boardr = min(T - boardl, 100); n   for (int i = 1; i <= boardl; i++) n     for (int j = 1; j <= n; j++) { n       int nowm = 0; n       for (int k = 1; k <= tt[a[j]]; k++) nowm = max(nowm, s1[k]); n       s1[tt[a[j]]] = nowm + 1; n     } n   for (int i = 1; i <= boardr; i++) n     for (int j = n; j; j--) { n       int nowm = 0; n       for (int k = n; k >= tt[a[j]]; k--) nowm = max(nowm, s2[k]); n       s2[tt[a[j]]] = nowm + 1; n     } n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     int ans1 = 0, ans2 = 0; n     if (tt[b[i]] != tt[b[i - 1]]) { n       for (int j = 1; j <= tt[b[i]]; j++) ans1 = max(ans1, s1[j]); n       for (int j = tt[b[i]]; j <= n; j++) ans2 = max(ans2, s2[j]); n       ans = max( n           ans, ans1 + ans2 + (T - boardl - boardr) * (tt[b[i]] - tt[b[i - 1]])); n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 8; n int a[N], b[N]; n int n, m; n long long x, k, y; n bool chk(int l, int r, long long &res) { n   if (l > r) return true; n   bool canDel = false; n   int mx = *max_element(a + l, a + r + 1); n   int len = r - l + 1; n   if (l - 1 >= 0 && a[l - 1] > mx) canDel = true; n   if (r + 1 < n && a[r + 1] > mx) canDel = true; n   if (len < k && !canDel) return false; n   int need = len % k; n   res += need * y; n   len -= need; n   if (y * k >= x) { n     res += len / k * x; n   } else if (canDel) { n     res += len * y; n   } else { n     res += (len - k) * y + x; n   } n   return true; n } n int main() { n   cin >> n >> m >> x >> k >> y; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < m; i++) cin >> b[i]; n   long long res = 0; n   int lst = -1, posa = 0, posb = 0; n   while (posb < m) { n     while (posa < n && a[posa] != b[posb]) posa++; n     if (posa == n) { n       cout <<  -1 ; n       return 0; n     } n     if (!chk(lst + 1, posa - 1, res)) { n       cout <<  -1 ; n       return 0; n     } n     lst = posa; n     posb++; n   } n   if (!chk(lst + 1, n - 1, res)) { n     cout <<  -1 ; n     return 0; n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n int x, k; n int NumsBetween(int a, int b) { return (b / x - (a - 1) / x); } n int main() { n   int n; n   std::cin >> n >> x >> k; n   std::vector<int> array(n, 0); n   for (int i = 0; i < n; ++i) { n     std::cin >> array[i]; n   } n   std::sort(array.begin(), array.end()); n   long long answ = 0; n   int pointer = 0; n   int start = 0; n   int finish = 0; n   while (pointer < n) { n     for (; start < n; start += 1) { n       if (NumsBetween(array[pointer], array[start]) >= k) break; n     } n     for (; finish < n; finish += 1) { n       if (NumsBetween(array[pointer], array[finish]) > k) break; n     } n     answ += finish - start; n     pointer += 1; n     if (start != n && pointer != n && array[pointer] > array[start]) n       start = pointer; n     if (finish != n && start != n && array[start] > array[finish]) n       finish = start; n   } n   std::cout << answ << std::endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T sqr(const T &x) { n   return x * x; n } n inline long long sqr(int x) { return sqr<long long>(x); } n template <class T> n T binpow(const T &a, long long n) { n   return n == 0 ? 1 : sqr(binpow(a, n / 2)) * (n % 2 ? a : 1); n } n long long binpow(long long a, long long n, long long modulo) { n   return n == 0 ? 1 n                 : sqr(binpow(a, n / 2, modulo)) % modulo * (n % 2 ? a : 1) % n                       modulo; n } n long long gcd(long long a, long long b, long long &x, long long &y) { n   if (a == 0) { n     x = 0; n     y = 1; n     return b; n   } n   long long x1, y1; n   long long d = gcd(b % a, a, x1, y1); n   x = y1 - (b / a) * x1; n   y = x1; n   return d; n } n inline long long phi(long long n) { n   long long result = n; n   for (long long i = 2; i * i <= n; ++i) n     if (n % i == 0) { n       while (n % i == 0) n /= i; n       result -= result / i; n     } n   if (n > 1) result -= result / n; n   return result; n } n inline vector<long long> inverseAll(long long m) { n   vector<long long> r(m); n   r[1] = 1; n   for (int i = 2; i < m; ++i) r[i] = (m - (m / i) * r[m % i] % m) % m; n   return r; n } n inline long long gcd(long long a, long long b) { return gcd(a, b, a, b); } n inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n inline long long llrand() { n   const long long lsbToFill = (sizeof(long long) << 3) - 1; n   const long long bitsFilledInIteration = __builtin_popcountll(RAND_MAX); n   long long number = 0; n   for (long long lsbFilled = 0; lsbFilled <= lsbToFill; n        lsbFilled += bitsFilledInIteration) { n     number ^= (((long long)rand()) << lsbFilled); n   } n   return number & numeric_limits<long long>::max(); n } n inline long long llrand(long long begin, long long end) { n   return begin + llrand() % (end - begin); n } n struct Dinic { n   struct Edge { n     int u, v; n     long long cap, flow; n     Edge() {} n     Edge(int u, int v, long long cap) : u(u), v(v), cap(cap), flow(0) {} n   }; n   int N; n   vector<Edge> E; n   vector<vector<int>> g; n   vector<int> d, pt; n   Dinic(int N) : N(N), E(0), g(N), d(N), pt(N) {} n   void AddEdge(int u, int v, long long cap) { n     if (u != v) { n       E.emplace_back(Edge(u, v, cap)); n       g[u].emplace_back(E.size() - 1); n       E.emplace_back(Edge(v, u, 0)); n       g[v].emplace_back(E.size() - 1); n     } n   } n   bool BFS(int S, int T) { n     queue<int> q({S}); n     fill(d.begin(), d.end(), N + 1); n     d[S] = 0; n     while (!q.empty()) { n       int u = q.front(); n       q.pop(); n       if (u == T) break; n       for (int k : g[u]) { n         Edge &e = E[k]; n         if (e.flow < e.cap && d[e.v] > d[e.u] + 1) { n           d[e.v] = d[e.u] + 1; n           q.emplace(e.v); n         } n       } n     } n     return d[T] != N + 1; n   } n   long long DFS(int u, int T, long long flow = -1) { n     if (u == T || flow == 0) return flow; n     for (int &i = pt[u]; i < g[u].size(); ++i) { n       Edge &e = E[g[u][i]]; n       Edge &oe = E[g[u][i] ^ 1]; n       if (d[e.v] == d[e.u] + 1) { n         long long amt = e.cap - e.flow; n         if (flow != -1 && amt > flow) amt = flow; n         if (long long pushed = DFS(e.v, T, amt)) { n           e.flow += pushed; n           oe.flow -= pushed; n           return pushed; n         } n       } n     } n     return 0; n   } n   long long MaxFlow(int S, int T) { n     long long total = 0; n     while (BFS(S, T)) { n       fill(pt.begin(), pt.end(), 0); n       while (long long flow = DFS(S, T)) total += flow; n     } n     return total; n   } n }; n vector<long long> Dijkstra(const vector<list<pair<int, long long>>> &g, int s) { n   vector<long long> d(int((g).size()), numeric_limits<long long>::max() / 2LL); n   priority_queue<pair<long long, int>> q; n   d[s] = 0; n   q.emplace(-0, s); n   while (!q.empty()) { n     while (q.top().first > d[q.top().second]) { n       q.pop(); n     } n     int v = q.top().second; n     q.pop(); n     for (const auto &cw : g[v]) { n       if (d[v] + cw.second < d[cw.first]) { n         d[cw.first] = d[v] + cw.second; n         q.emplace(-d[cw.first], cw.first); n       } n     } n   } n   return d; n } n struct BinarySearchIterator n     : public std::iterator<std::forward_iterator_tag, bool> { n   long long value; n   typename iterator_traits<BinarySearchIterator>::difference_type operator-( n       const BinarySearchIterator &it) const { n     return value - it.value; n   } n   BinarySearchIterator &operator++() { n     ++value; n     return *this; n   } n   bool operator!=(const BinarySearchIterator &it) const { n     return value != it.value; n   } n   bool operator*() const { return true; } n }; n template <int ALPHA> n class AhoCorasick { n  public: n   static const int ILLEGAL_INDEX; n   static const int ROOT; n   struct Node { n     bool leaf; n     int parent; n     int parentCharacter; n     int link; n     int next[ALPHA]; n     int go[ALPHA]; n     int outputFunction; n     Node(int parent = ILLEGAL_INDEX, int parentCharacter = ALPHA) n         : leaf(false), n           parent(parent), n           parentCharacter(parentCharacter), n           link(ILLEGAL_INDEX), n           outputFunction(ILLEGAL_INDEX) { n       fill_n(next, ALPHA, ILLEGAL_INDEX); n       fill_n(go, ALPHA, ILLEGAL_INDEX); n     } n   }; n   vector<Node> tree = vector<Node>(1); n   AhoCorasick() {} n   AhoCorasick(int maxStatesNumber) { tree.reserve(maxStatesNumber); } n   template <class Iterator> n   void add(int length, const Iterator begin) { n     int vertex = ROOT; n     for (int i = 0; i < length; ++i) { n       if (ILLEGAL_INDEX == tree[vertex].next[begin[i]]) { n         tree[vertex].next[begin[i]] = int((tree).size()); n         tree.push_back(Node(vertex, begin[i])); n       } n       vertex = tree[vertex].next[begin[i]]; n     } n     tree[vertex].leaf = true; n   } n   int getLink(int vertex) { n     assert(0 <= vertex && vertex < tree.size()); n     if (ILLEGAL_INDEX == tree[vertex].link) { n       if (ROOT == vertex || ROOT == tree[vertex].parent) { n         tree[vertex].link = ROOT; n       } else { n         tree[vertex].link = n             go(getLink(tree[vertex].parent), tree[vertex].parentCharacter); n       } n     } n     return tree[vertex].link; n   } n   int go(int vertex, int character) { n     assert(0 <= character && character < ALPHA); n     assert(0 <= vertex && vertex < tree.size()); n     if (ILLEGAL_INDEX == tree[vertex].go[character]) { n       if (ILLEGAL_INDEX == tree[vertex].next[character]) { n         tree[vertex].go[character] = n             ROOT == vertex ? ROOT : go(getLink(vertex), character); n       } else { n         tree[vertex].go[character] = tree[vertex].next[character]; n       } n     } n     return tree[vertex].go[character]; n   } n   int getOutputFunction(int vertex) { n     assert(0 <= vertex && vertex < tree.size()); n     if (ILLEGAL_INDEX == tree[vertex].outputFunction) { n       if (tree[vertex].leaf || ROOT == vertex) { n         tree[vertex].outputFunction = vertex; n       } else { n         tree[vertex].outputFunction = getOutputFunction(getLink(vertex)); n       } n     } n     return tree[vertex].outputFunction; n   } n }; n template <int ALPHA> n const int AhoCorasick<ALPHA>::ILLEGAL_INDEX = -1; n template <int ALPHA> n const int AhoCorasick<ALPHA>::ROOT = 0; n int main(int argc, const char *argv[]) { n   ios::sync_with_stdio(false); n   cin.tie(0); n   srand((unsigned int)time(NULL)); n   int n; n   while (cin >> n) { n     vector<long long> a(n); n     for (int i = (0); i < (n); ++i) { n       cin >> a[i]; n     } n     map<long long, long long> valueToPrevious; n     set<long long> values; n     map<long long, int> valueToPosition; n     for (int i = (0); i < (n); ++i) { n       auto it = values.lower_bound(a[i]); n       if (it == values.begin()) { n         valueToPrevious[a[i]] = -1; n       } else { n         --it; n         valueToPrevious[a[i]] = *it; n         values.erase(it); n       } n       values.insert(a[i]); n       valueToPosition[a[i]] = i; n     } n     vector<list<long long>> lists; n     set<long long> used; n     for (int i = n - 1; i >= 0; --i) { n       list<long long> currentList; n       if (!used.count(a[i])) { n         for (long long current = a[i]; - 1 != current; n              current = valueToPrevious[current]) { n           currentList.push_front(current); n           used.insert(current); n         } n         lists.push_back(currentList); n       } n     } n     sort((lists).begin(), (lists).end(), n          [&](const list<long long> &a, const list<long long> &b) { n            return valueToPosition[a.front()] < valueToPosition[b.front()]; n          }); n     for (const auto &currentList : lists) { n       for (const long long element : currentList) { n         cout << element <<    ; n       } n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 100000; n vector<int> divisors[MX + 10]; n int n, last[MX + 10], pos, X; n int main() { n   for (int j = 1; j <= MX; j++) n     for (int i = j; i <= MX; i += j) divisors[i].push_back(j); n   cin >> n; n   for (int j = 1; j <= n; j++) { n     cin >> X >> pos; n     pos = j - pos; n     int sz = divisors[X].size(), ret = 0, div; n     for (int i = 0; i < sz; i++) { n       div = divisors[X][i]; n       if (last[div] < pos) ret++; n       last[div] = j; n     } n     cout << ret << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-8; n const long long SZ = 1010, SSZ = 100010, APB = 26, one = 93, n                 INF = 0x3f3f3f3f3f3f3f3f, mod = 1000000007; n long long n, m, bg, fn, cnt; n long long to[SSZ], wt[SSZ], head[SZ]; n long long nex[SSZ], mk[SSZ]; n long long dfn[SZ], low[SZ], tot; n bool vst[SZ]; n void add(long long u, long long v, long long w) { n   ++cnt; n   nex[cnt] = head[u]; n   head[u] = cnt; n   to[cnt] = v, wt[cnt] = w; n } n bool dfs(long long x) { n   vst[x] = 1; n   if (x == fn) return 1; n   for (long long i = head[x]; i != -1; i = nex[i]) { n     long long t = to[i]; n     if (!vst[t]) { n       mk[i] = 1; n       if (dfs(t)) return 1; n       mk[i] = 0; n     } n   } n   return 0; n } n stack<long long> stk; n void tar(long long x, long long p, long long &res2, long long &eg2) { n   dfn[x] = low[x] = ++tot; n   vst[x] = 1; n   for (long long i = head[x]; i != -1; i = nex[i]) { n     if (i != (p ^ 1) && mk[i] != 2 && mk[i ^ 1] != 2) { n       long long t = to[i], w = wt[i]; n       if (!dfn[t]) { n         tar(t, i, res2, eg2); n         low[x] = min(low[x], low[t]); n       } else n         low[x] = min(low[x], low[t]); n       if (dfn[x] < low[t] && dfn[fn] >= dfn[t]) { n         if (w < res2) { n           res2 = w, eg2 = i; n         } n       } n     } n   } n } n void init() { n   cin >> n >> m >> bg >> fn; n   cnt = -1; n   memset(head, -1, sizeof(head)); n   for (long long i = 1; i <= m; ++i) { n     long long a, b, c; n     cin >> a >> b >> c; n     add(a, b, c); n     add(b, a, c); n   } n   dfs(bg); n   if (vst[fn] == 0) { n     cout << 0 << endl << 0; n     return; n   } n   long long res = INF, vt1 = -1, vt2; n   for (long long i = 0; i <= cnt; ++i) { n     if (mk[i]) { n       mk[i] = 2; n       memset(vst, 0, sizeof(vst)); n       tot = 0; n       memset(dfn, 0, sizeof(dfn)); n       memset(low, 0, sizeof(low)); n       long long res1 = wt[i], res2 = INF, eg1 = i, eg2; n       tar(bg, -1, res2, eg2); n       if (!vst[fn]) res2 = 0, eg2 = -5; n       if (res1 + res2 < res) { n         res = res1 + res2; n         vt1 = eg1 / 2 + 1, vt2 = eg2 / 2 + 1; n       } n       mk[i] = 1; n     } n   } n   if (vt1 == -1) { n     cout << -1 << endl; n     return; n   } n   cout << res << endl; n   cout << (vt2 == -1 ? 1 : 2) << endl; n   cout << vt1 <<    ; n   if (vt2 != -1) cout << vt2 << endl; n } n void work() {} n int main() { n   std::ios::sync_with_stdio(0); n   long long casenum; n   { n     init(); n     work(); n   } n   return 0; n } n


#include <bits/stdc++.h> n struct node { n   int h, typ; n   bool operator<(node b) const { n     if (typ == b.typ) return h > b.h; n     return typ < b.typ; n   } n } a[10010]; n int n, x, y, sum, L, R, ans, dp[10010]; n int main() { n   scanf( %d%d%d , &n, &x, &y); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i].h), sum += a[i].h; n   for (int i = 1; i <= n; i++) scanf( %d , &a[i].typ); n   L = sum - y, R = sum - x; n   std::sort(a + 1, a + n + 1); n   memset(dp, 128, sizeof(dp)); n   dp[0] = 0; n   for (int i = 1; i <= n; i++) n     for (int j = sum; j >= a[i].h; j--) { n       int res = dp[j - a[i].h]; n       if (L <= j && R >= j) res += a[i].typ; n       dp[j] = std::max(dp[j], res); n     } n   for (int i = 0; i <= sum; i++) ans = std::max(ans, dp[i]); n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   long long data[n + 1]; n   long long mx = LLONG_MIN; n   for (int i = 1; i <= n; i++) { n     cin >> data[i]; n     mx = max(mx, data[i]); n   } n   vector<int> graph[n + 1]; n   for (int i = 0; i < n - 1; i++) { n     int s, t; n     cin >> s >> t; n     graph[s].push_back(t); n     graph[t].push_back(s); n   } n   int mxi = 0; n   long long mxcnt = 0; n   for (int i = 1; i <= n; i++) { n     if (data[i] == mx) { n       mxi = i; n       mxcnt++; n     } n   } n   long long res = mx; n   if (mxcnt == 1) { n     int level[n + 1]; n     fill_n(level, n + 1, -1); n     deque<int> queue; n     queue.push_back(mxi); n     level[mxi] = 0; n     while (!queue.empty()) { n       int cur = queue.front(); n       res = max(res, data[cur] + level[cur]); n       queue.pop_front(); n       for (int next : graph[cur]) { n         if (level[next] < 0) { n           level[next] = min(2, level[cur] + 1); n           queue.push_back(next); n         } n       } n     } n   } else { n     bool level1 = false; n     for (int i = 1; !level1 && i <= n; i++) { n       long long cnt = data[i] == mx ? 1 : 0; n       for (int next : graph[i]) { n         if (data[next] == mx) cnt++; n       } n       level1 |= cnt == mxcnt; n     } n     res = level1 ? mx + 1 : mx + 2; n   } n   cout << res <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long tree[3 * 100005]; n bool lazy[3 * 100005]; n void update(long long node, long long b, long long e, long long i, long long j, n             long long v) { n   if (i > e || j < b) { n     return; n   } n   if (b >= i && e <= j) { n     lazy[node] = true; n     { tree[node] = tree[node] | v; } n     return; n   } n   if (lazy[node]) { n     tree[node * 2] |= tree[node]; n     tree[node * 2 + 1] |= tree[node]; n     lazy[node * 2] = 1; n     lazy[node * 2 + 1] = 1; n     lazy[node] = 0; n   } n   update(node * 2, b, (b + e) / 2, i, j, v); n   update(node * 2 + 1, (b + e) / 2 + 1, e, i, j, v); n   tree[node] = tree[node * 2] & tree[node * 2 + 1]; n } n long long query(long long node, long long b, long long e, long long i, n                 long long j) { n   if (i > e || j < b) { n     return (1LL << 33) - 1; n   } n   if (b >= i && e <= j) { n     return tree[node]; n   } n   if (lazy[node]) { n     tree[node * 2] |= tree[node]; n     tree[node * 2 + 1] |= tree[node]; n     lazy[node * 2] = 1; n     lazy[node * 2 + 1] = 1; n     lazy[node] = 0; n   } n   return query(node * 2, b, (b + e) / 2, i, j) & n          query(node * 2 + 1, (b + e) / 2 + 1, e, i, j); n } n int main() { n   long long n, m; n   cin >> n >> m; n   pair<long long, long long> p[m + 1]; n   long long a[m + 1]; n   memset(tree, 0, sizeof tree); n   memset(lazy, 0, sizeof lazy); n   for (long long i = 1; i <= m; i++) { n     long long x, y, z; n     cin >> x >> y >> z; n     update(1, 1, n, x, y, z); n     p[i].first = x; n     p[i].second = y; n     a[i] = z; n   } n   int f = 1; n   for (long long i = 1; i <= m; i++) { n     long long x = query(1, 1, n, p[i].first, p[i].second); n     if (x != a[i]) { n       f = 0; n     } n   } n   if (f == 1) { n     cout <<  YES n ; n     for (long long i = 1; i <= n; i++) { n       cout << query(1, 1, n, i, i) <<    ; n     } n     cout << endl; n   } else { n     cout <<  NO n ; n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n const long long mod = 1e9 + 7; n long long sod(long long n) { n   long long sum = 0; n   while (n > 0) { n     sum += n % 10; n     n /= 10; n   } n   return sum; n } n long long dig(long long n) { n   long long cnt = 0; n   while (n > 0) { n     n /= 10; n     cnt++; n   } n   return cnt; n } n long long divs(long long n) { n   long long cnt = 0; n   for (long long x = 1; x * x <= n; x++) { n     if (n % x == 0) { n       cnt++; n       if (n / x != x) cnt++; n     } n   } n   return cnt; n } n long long isprime(long long n) { n   if (n < 2) return false; n   for (long long x = 2; x * x <= n; x++) n     if (n % x == 0) return false; n   return true; n } n long long power(long long x, unsigned long long y, long long p = mod) { n   long long res = 1; n   x = x % p; 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 const long long inf = 1e18; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     string s; n     cin >> s; n     long long ans = 0; n     long long found = 0; n     for (long long x = 0; x < n; x++) { n       long long pos = x + 1; n       long long bck = n - x; n       long long cnt = 0; n       if (s[x] ==  1 ) { n         cnt = 2 * pos; n         ans = max(ans, cnt); n         long long cnt2 = 2 * bck; n         ans = max(ans, cnt2); n       } n     } n     if (ans == 0) ans = n; n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int nodes_size; n long long int edge_size; n class edge { n  public: n   long long int node; n   long long int cost; n   edge(long long int i, long long int j) { n     node = i; n     cost = j; n   } n }; n class graph { n  public: n   long long int node; n   vector<edge> edges; n   long long int parent; n   long long int cost; n   vector<long long int> children; n } nodes[1005]; n long long int visited[1005]; n class point { n  public: n   long long int x; n   long long int y; n   point() {} n   point(long long int i, long long int j) { n     x = i; n     y = j; n   } n }; n void fill_array(long long int ar[], long long int value, long long int size) { n   for (long long int i = 0; i < size; i++) ar[i] = value; n } n void print_ll_vector(vector<long long int> v) { n   for (long long int i = 0; i < v.size(); i++) cout << v[i] <<    ; n   cout << endl; n } n void input_graph(bool is_undirected, bool is_cost) { n   cin >> nodes_size; n   edge_size = nodes_size - 1; n   for (long long int i = 0; i < edge_size; i++) { n     long long int a, b, c; n     cin >> a >> b; n     if (is_cost) { n       cin >> c; n       nodes[a].edges.push_back(edge(b, c)); n       if (is_undirected) nodes[b].edges.push_back(edge(a, c)); n     } else { n       nodes[a].edges.push_back(edge(b, 1)); n       if (is_undirected) nodes[b].edges.push_back(edge(a, 1)); n     } n   } n } n vector<pair<long long int, long long int> > destroyed_edges; n long long int ctr = 0, c; n vector<long long int> ans; n void dfs(long long int node, long long int parent) { n   visited[node] = 1; n   for (long long int i = 0; i < nodes[node].edges.size(); i++) { n     if (nodes[node].edges[i].node != parent) { n       if (visited[nodes[node].edges[i].node]) { n         if (node > nodes[node].edges[i].node) { n           if (c > 0 || ctr == 1) { n             destroyed_edges.push_back( n                 make_pair(node, nodes[node].edges[i].node)); n             c++; n           } else { n             c++; n             ans.push_back(node); n             ans.push_back(nodes[node].edges[i].node); n           } n         } n       } else n         dfs(nodes[node].edges[i].node, node); n     } n   } n } n vector<long long int> new_edges; n int main() { n   input_graph(true, false); n   fill_array(visited, 0, nodes_size + 1); n   for (long long int i = 1; i <= nodes_size; i++) { n     if (!visited[i]) { n       c = 0; n       ctr++; n       dfs(i, -1); n       if (c == 0 && i != 1) new_edges.push_back(i); n     } n   } n   cout << (ans.size() / 2) + new_edges.size() << endl; n   for (long long int i = 0; i < ans.size();) { n     cout << ans[i] <<     << ans[i + 1] <<     << ans[i] <<     << 1 << endl; n     i = i + 2; n   } n   for (long long int i = 0; i < new_edges.size(); i++) n     cout << destroyed_edges[i].first <<     << destroyed_edges[i].second <<     n          << destroyed_edges[i].first <<     << new_edges[i] << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int n; n pair<long long, long long> h2md_logl[100000][19]; n pair<long long, long long> h2md_logr[100000][19]; n long long dist_log[100000][19]; n long long h[100000]; n int max_2h_minus_d(int from, int to, int dir, long long& dist, n                    long long& alldist) { n   long long curd = 0; n   long long dmark = 0; n   long long curtree = from; n   int curind = from; n   int l = 0; n   if (dir == 1) { n     l = to - from; n     if (l < 0) l += n; n   } else if (dir == 0) { n     l = from - to; n     if (l < 0) l += n; n   } n   l++; n   int l2 = 1; n   int deg = 0; n   while (l > 0) { n     if (l % 2 == 1) { n       pair<long long, long long> pret; n       if (dir == 0) n         pret = h2md_logl[curtree][deg]; n       else n         pret = h2md_logr[curtree][deg]; n       long long dist_bw_marks = 0; n       int newtree = curtree; n       if (dir == 1) { n         newtree += l2; n         if (newtree >= n) newtree -= n; n       } else { n         newtree -= l2; n         if (newtree < 0) newtree += n; n       } n       if (dir == 1) n         dist_bw_marks = dist_log[curtree][deg]; n       else { n         dist_bw_marks = dist_log[newtree][deg]; n       } n       int pret_ind = pret.first; n       if (pret.second - 2 * h[curind] - dmark > 0) { n         dmark = dist_bw_marks + pret.second - 2 * h[pret_ind]; n         curind = pret_ind; n       } else { n         dmark += dist_bw_marks; n       } n       curtree = newtree; n       curd += dist_bw_marks; n     } n     l /= 2; n     l2 *= 2; n     deg += 1; n   } n   dist = curd - dmark; n   if (dir == 0) n     alldist = curd - dist_log[curtree][0]; n   else { n     curtree--; n     if (curtree < 0) curtree += n; n     alldist = curd - dist_log[curtree][0]; n   } n   return curind; n } n int main() { n   int m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> dist_log[i][0]; n   } n   for (int i = 0; i < n; i++) { n     cin >> h[i]; n     h2md_logl[i][0] = make_pair(i, 2 * h[i]); n     h2md_logr[i][0] = make_pair(i, 2 * h[i]); n   } n   int n2 = 2; n   int deg = 1; n   while (n2 < 2 * n) { n     int half = n2 / 2; n     for (int i = 0; i < n; i++) { n       int mid = i + half; n       int midl = i - half; n       if (midl < 0) midl += n; n       if (mid >= n) mid -= n; n       long long disttohalf = dist_log[i][deg - 1]; n       long long disttohalfl = dist_log[midl][deg - 1]; n       dist_log[i][deg] = disttohalf + dist_log[mid][deg - 1]; n       if (h2md_logr[i][deg - 1].second > n           h2md_logr[mid][deg - 1].second - disttohalf) { n         h2md_logr[i][deg] = h2md_logr[i][deg - 1]; n       } else { n         h2md_logr[i][deg] = n             make_pair(h2md_logr[mid][deg - 1].first, n                       h2md_logr[mid][deg - 1].second - disttohalf); n       } n       if (h2md_logl[i][deg - 1].second > n           h2md_logl[midl][deg - 1].second - disttohalfl) { n         h2md_logl[i][deg] = h2md_logl[i][deg - 1]; n       } else { n         h2md_logl[i][deg] = n             make_pair(h2md_logl[midl][deg - 1].first, n                       h2md_logl[midl][deg - 1].second - disttohalfl); n       } n     } n     deg++; n     n2 *= 2; n   } n   long long distl, distr, alldist; n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     int f, t; n     f = b; n     if (f >= n) f -= n; n     t = a - 2; n     if (t < 0) t += n; n     int indf = max_2h_minus_d(f, t, 1, distl, alldist); n     int indt = max_2h_minus_d(t, f, 0, distr, alldist); n     if (indf != indt) { n       cout << alldist + 2 * (h[indf] + h[indt]) - distl - distr; n     } else if (indf == f) { n       int newindt = indt + 1; n       if (newindt == n) newindt = 0; n       long long ndr, nar; n       int indtt = max_2h_minus_d(t, newindt, 0, ndr, nar); n       cout << alldist + 2 * (h[indf] + h[indtt]) - distl - ndr; n     } else if (indt == t) { n       int newindf = indf - 1; n       if (newindf < 0) newindf = n - 1; n       long long ndl, nal; n       int indff = max_2h_minus_d(f, newindf, 1, ndl, nal); n       cout << alldist + 2 * (h[indff] + h[indt]) - ndl - distr; n     } else { n       int newindf = indf - 1; n       int newindt = indt + 1; n       if (newindf < 0) newindf = n - 1; n       if (newindt == n) newindt = 0; n       long long ndl, ndr; n       long long nal, nar; n       int indff = max_2h_minus_d(f, newindf, 1, ndl, nal); n       int indtt = max_2h_minus_d(t, newindt, 0, ndr, nar); n       cout << max(alldist + 2 * (h[indff] + h[indt]) - ndl - distr, n                   alldist + 2 * (h[indf] + h[indtt]) - distl - ndr); n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e18; n int main(void) { n   ios_base::sync_with_stdio(false); n   int N; n   cin >> N; n   long long minx = inf, maxx = -inf, miny = inf, maxy = -inf; n   vector<pair<long long, long long>> A(N); n   for (int i = 0; i < N; ++i) { n     cin >> A[i].first >> A[i].second; n     minx = min(minx, A[i].first); n     miny = min(miny, A[i].second); n     maxx = max(maxx, A[i].first); n     maxy = max(maxy, A[i].second); n   } n   long long ans4 = 2 * (maxx - minx) + 2 * (maxy - miny); n   long long ans3 = 0; n   for (int s = 0; s < (1 << 6); ++s) { n     vector<int> cntx(3, 0), cnty(3, 0); n     for (int i = 0; i < 3; ++i) { n       if (s & (1 << i)) { n         cntx[i]++; n         cntx[(i + 1) % 3]--; n       } else { n         cntx[i]--; n         cntx[(i + 1) % 3]++; n       } n       if (s & (1 << (3 + i))) { n         cnty[i]++; n         cnty[(i + 1) % 3]--; n       } else { n         cnty[i]--; n         cnty[(i + 1) % 3]++; n       } n     } n     long long perim = 0; n     for (int i = 0; i < 3; ++i) { n       long long best = -1e18; n       for (auto& p : A) { n         best = max(best, p.first * cntx[i] + p.second * cnty[i]); n       } n       perim += best; n     } n     ans3 = max(ans3, perim); n   } n   cout << ans3; n   for (int i = 4; i <= N; ++i) { n     cout <<     << ans4; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int INF = LONG_LONG_MAX; n const long long int NINF = LONG_LONG_MIN; n const long long int mmod = 998244353; n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long int t; n   cin >> t; n   while (t-- > 0) { n     long long int c, m, x; n     cin >> c >> m >> x; n     long long int a = min(c, m); n     cout << min(a, (c + m + x) / 3) << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 5; n long long mod = 1000000007; n vector<long long> gr[200001]; n vector<long long> grev[200001]; n long long a[200005]; n void solve() { n   long long n, d, a, b; n   cin >> n >> d >> a >> b; n   vector<pair<long long, long long> > ans; n   for (long long i = int(0); i < int(n); i++) { n     long long x, y; n     cin >> x >> y; n     long long val = x * a + y * b; n     ans.push_back({val, i + 1}); n   } n   sort(ans.begin(), ans.end()); n   long long val = 0; n   vector<long long> ind; n   long long i = 0; n   for (i = 0; i < n; i++) { n     val += ans[i].first; n     if (val <= d) n       ind.push_back(ans[i].second); n     else n       break; n   } n   cout << i <<   n ; n   for (long long i = int(0); i < int(ind.size()); i++) { n     cout << ind[i] <<    ; n   } n   cout <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t; n   t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = int(2e5) + 9; n int main() { n   int t; n   cin >> t; n   while (t--) { n     string s; n     cin >> s; n     int n = s.size(); n     int m1 = 0, m2 = 0; n     bool on = false; n     int n1 = 0, n0 = 0, N1 = 0, N0 = 0; n     for (int i = 0; i < n; i++) { n       n0 += (s[i] ==  0 ); n       n1 += (s[i] ==  1 ); n     } n     int ans = n; n     for (int i = 0; i < n; i++) { n       N0 += (s[i] ==  0 ); n       N1 += (s[i] ==  1 ); n       n0 -= (s[i] ==  0 ); n       n1 -= (s[i] ==  1 ); n       ans = min(ans, N0 + n1); n       ans = min(ans, N1 + n0); n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e4 + 50; n const int INF = 1e8 + 100; n int val[MAXN], vec[MAXN]; n int dp[MAXN][100]; n int n, t; n bool check(int x) { return x == ((1 << 3) - 1); } n int solve(int id, int suco) { n   if (check(suco)) return 0; n   if (id >= n) return (INF); n   if (dp[id][suco] != -1) return dp[id][suco]; n   int ans = INF; n   ans = min(solve(id + 1, (suco | vec[id])) + val[id], solve(id + 1, suco)); n   return dp[id][suco] = ans; n } n int32_t main() { n   cin >> n; n   string s; n   for (int i = 0; i < n; i++) { n     int aux = 0; n     cin >> t >> s; n     for (auto c : s) aux |= (1 << (int(c -  A ))); n     vec[i] = aux; n     val[i] = t; n   } n   memset(dp, -1, sizeof dp); n   int ans = solve(0, 0); n   cout << (ans == INF ? -1 : ans) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s1 = n      What are you doing at the end of the world? Are you busy? Will you save   n      us? ; n string s2 =  What are you doing while sending   ; n string s3 =   ? Are you busy? Will you send   ; n string s4 =   ? ; n long long M[100005]; n char f(long long n, long long k) { n   if (n == 0) return s1[k]; n   if (k < s2.size()) return s2[k]; n   k = k - s2.size(); n   if (k < M[n - 1]) return f(n - 1, k); n   k = k - M[n - 1]; n   if (k < s3.size()) return s3[k]; n   k = k - s3.size(); n   if (k < M[n - 1]) return f(n - 1, k); n   k = k - M[n - 1]; n   if (k < s4.size()) return s4[k]; n   k = k - s4.size(); n   return  . ; n } n int main() { n   ios_base::sync_with_stdio(0); n   long long q; n   cin >> q; n   M[0] = s1.size(); n   for (long long i = 1; i <= 53; i++) { n     if (M[i - 1]) n       M[i] = s2.size() + M[i - 1] + s3.size() + M[i - 1] + s4.size(); n   } n   for (long long i = 54; i <= 100001; i++) M[i] = M[53]; n   for (long long i = 0; i < q; i++) { n     long long n, k; n     cin >> n >> k; n     long long n2 = n; n     if (n2 > 53) n2 = 53; n     if (k > M[n2]) n       cout <<  . ; n     else n       cout << f(n, k - 1); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int d[1503][1503][26], e[1503][26], z[1503][26]; n int main() { n   ios::sync_with_stdio(false); n   int n, q, m; n   char c; n   string s; n   cin >> n >> s >> q; n   for (int i = 0; i < 26; i++) n     for (int j = 1; j <= n; j++) e[j][i] = e[j - 1][i] + (s[j - 1] ==  a  + i); n   for (int i = 1; i <= n; i++) n     for (int j = i; j <= n; j++) n       for (int k = 0; k < 26; k++) d[i][j][k] = e[j][k] - e[i - 1][k]; n   for (int i = 1; i <= n; i++) n     for (int j = 0; j < 26; j++) { n       int l = 1; n       for (int k = 1; k <= n; k++) { n         while (d[l][k][j] + i < k - l + 1) l++; n         z[i][j] = max(z[i][j], k - l + 1); n       } n     } n   while (q--) cin >> m >> c, cout << z[m][c -  a ] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } n int n, arr[109]; n vector<int> odd, even; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < (int)(n); i++) { n     scanf( %d , &arr[i]); n     if (arr[i] % 2 == 0) n       even.push_back(i); n     else n       odd.push_back(i); n   } n   if (even.size() == n - 1) n     printf( %d n , odd[0] + 1); n   else n     printf( %d n , even[0] + 1); n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int data; n   long int sum; n   struct node *left, *right; n   struct node* next; n }; n struct node* newNode(int data) { n   struct node* Node = new (struct node); n   Node->data = data; n   Node->left = Node->right = Node->next = NULL; n   return (Node); n } n long long ans[110][110][2]; n void solveTestCase() { n   int n1, n2, k1, k2; n   scanf( %d , &n1); n   ; n   scanf( %d , &n2); n   ; n   scanf( %d , &k1); n   ; n   scanf( %d , &k2); n   ; n   k1 = min(k1, n1); n   k2 = min(k2, n2); n   ans[0][0][0] = 1; n   ans[0][0][1] = 1; n   for (int i = 0; i < n1 + 1; i++) { n     for (int j = 0; j < n2 + 1; j++) { n       if (i == 0 && j == 0) { n         continue; n       } n       for (int k = 1; k < k1 + 1; k++) { n         if (i - k < 0) { n           break; n         } n         ans[i][j][0] = (ans[i][j][0] + ans[i - k][j][1]) % 100000000; n       } n       for (int k = 1; k < k2 + 1; k++) { n         if (j - k < 0) { n           break; n         } n         ans[i][j][1] = (ans[i][j][1] + ans[i][j - k][0]) % 100000000; n       } n     } n   } n   long long ans_final = (ans[n1][n2][0] + ans[n1][n2][1]) % 100000000; n   printf( %I64d n , ans_final); n   ; n } n int main() { n   solveTestCase(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n long long a[100001]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]); n   scanf( %d , &m); n   int Left = 1; n   for (; m--;) { n     int x, y; n     scanf( %d%d , &x, &y); n     while (Left < x) { n       a[Left + 1] = max(a[Left + 1], a[Left]); n       ++Left; n     } n     printf( %I64d n , a[Left]); n     a[Left] += y; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n inline long long read() { n   long long x = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   return x * f; n } n long long n; n long long f[35][35][2]; n inline long long power(long long x, long long y) { n   if (y < 0) return 1; n   long long ans = 1; n   for (; y; y >>= 1) { n     if (y & 1) ans = ans * x % mod; n     x = x * x % mod; n   } n   return ans; n } n signed main() { n   n = read(); n   f[31][0][1] = 1; n   for (long long i = 30; i >= 0; i--) { n     if (!((n >> i) & 1)) { n       for (long long j = 0; j <= 30 - i; j++) { n         f[i][j + 1][0] = (f[i][j + 1][0] + f[i + 1][j][0]) % mod; n         f[i][j][0] = (f[i][j][0] + f[i + 1][j][0] * power(2, j) % mod) % mod; n         f[i][j][1] = n             (f[i][j][1] + f[i + 1][j][1] * power(2, j - 1) % mod) % mod; n       } n     } else { n       for (long long j = 0; j <= 30 - i; j++) { n         f[i][j + 1][0] = (f[i][j + 1][0] + f[i + 1][j][0]) % mod; n         f[i][j][0] = (f[i][j][0] + f[i + 1][j][0] * power(2, j) % mod) % mod; n         f[i][j + 1][1] = (f[i][j + 1][1] + f[i + 1][j][1]) % mod; n         f[i][j][0] = n             (f[i][j][0] + f[i + 1][j][1] * power(2, j - 1) % mod) % mod; n         if (j) n           f[i][j][1] = n               (f[i][j][1] + f[i + 1][j][1] * power(2, j - 1) % mod) % mod; n       } n     } n   } n   long long ans = 1; n   for (long long i = 1; i <= 30; i++) n     ans = (ans + f[0][i][0] + f[0][i][1]) % mod; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200005; n int n, m, lim, p = 1, a[N], nex[N * 2], spot[N * 2], head[N], fa[N], f[N], g[N]; n int maxcolor[N][2], c[N]; n bool color[N], v[N]; n void add(int x, int y) { n   nex[++p] = head[x], head[x] = p, spot[p] = y; n   nex[++p] = head[y], head[y] = p, spot[p] = x; n } n void dfs1(int x) { n   int tp, y, cnt = 0, m1 = 0, m2 = 0; n   v[x] = 1; n   for (tp = head[x]; y = spot[tp], tp; tp = nex[tp]) n     if (a[y] >= lim && y != fa[x]) { n       fa[y] = x; n       dfs1(y); n       if (!c[y]) n         cnt += f[y]; n       else { n         c[x]++; n         if (f[y] > m2) m2 = f[y]; n         if (m1 < m2) swap(m1, m2); n       } n     } n   maxcolor[x][0] = m1; n   maxcolor[x][1] = m2; n   f[x] = cnt + m1 + 1; n   c[x] += color[x]; n } n void dfs2(int x, int &ret) { n   if (fa[x]) { n     if (c[fa[x]] - (c[x] != 0) > 0) { n       if (c[x]) { n         if (f[x] < maxcolor[fa[x]][0]) { n           g[x] = f[x] - maxcolor[x][0] + max(maxcolor[x][0], g[fa[x]]); n           if (g[fa[x]] > maxcolor[x][1]) maxcolor[x][1] = g[fa[x]]; n           if (maxcolor[x][0] < maxcolor[x][1]) n             swap(maxcolor[x][0], maxcolor[x][1]); n         } else { n           g[x] = f[x] - maxcolor[x][0] + n                  max(maxcolor[x][0], n                      g[fa[x]] - maxcolor[fa[x]][0] + maxcolor[fa[x]][1]); n           if (g[fa[x]] - maxcolor[fa[x]][0] + maxcolor[fa[x]][1] > n               maxcolor[x][1]) n             maxcolor[x][1] = g[fa[x]] - maxcolor[fa[x]][0] + maxcolor[fa[x]][1]; n           if (maxcolor[x][0] < maxcolor[x][1]) n             swap(maxcolor[x][0], maxcolor[x][1]); n         } n       } else n         g[x] = f[x] - maxcolor[x][0] + max(maxcolor[x][0], g[fa[x]] - f[x]); n     } else { n       if (c[x]) { n         if (f[x] < maxcolor[fa[x]][0]) n           g[x] = f[x] + g[fa[x]]; n         else n           g[x] = f[x] + g[fa[x]] - maxcolor[fa[x]][0] + maxcolor[fa[x]][1]; n       } else n         g[x] = g[fa[x]]; n     } n     c[x] += ((c[fa[x]] - (c[x] != 0)) != 0); n   } else n     g[x] = f[x]; n   ret = max(ret, g[x]); n   for (int tp = head[x]; tp; tp = nex[tp]) n     if (a[spot[tp]] >= lim && spot[tp] != fa[x]) dfs2(spot[tp], ret); n } n int solve() { n   memset(v, 0, sizeof(v)); n   memset(fa, 0, sizeof(fa)); n   memset(c, 0, sizeof(c)); n   int maxn = 0; n   for (int i = 1; i <= n; i++) n     if (a[i] >= lim && v[i] == 0) { n       dfs1(i), dfs2(i, maxn); n     } n   return maxn >= m; n } n int main() { n   int i, x, y, l, r, tp; n   cin >> n >> m; n   for (i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (i = 1; i < n; i++) { n     scanf( %d%d , &x, &y); n     add(x, y); n   } n   for (l = 1, r = 1000000; l < r;) { n     lim = l + r + 1 >> 1; n     memset(color, 0, sizeof(color)); n     for (i = 1; i <= n; i++) n       if (a[i] < lim) n         for (tp = head[i]; tp; tp = nex[tp]) color[spot[tp]] = 1; n     if (solve()) n       l = lim; n     else n       r = lim - 1; n   } n   cout << l; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, b[101][101]; n bool isHorrizontal() { n   int i, j; n   for (i = 0; i < n / 3; i++) { n     for (j = 0; j < m; j++) { n       if (b[i][j] != 1) return false; n     } n   } n   for (i = n / 3; i < (n - n / 3) / 2 + (n / 3); i++) { n     for (j = 0; j < m; j++) { n       if (b[i][j] != 2) return false; n     } n   } n   for (i = (n - n / 3) / 2 + (n / 3); i < n; i++) { n     for (j = 0; j < m; j++) { n       if (b[i][j] != 3) return false; n     } n   } n   return true; n } n bool isVertical() { n   int i, j; n   for (i = 0; i < n; i++) { n     for (j = 0; j < m / 3; j++) { n       if (b[i][j] != 1) return false; n     } n   } n   for (i = 0; i < n; i++) { n     for (j = m / 3; j < (m - m / 3) / 2 + (m / 3); j++) { n       if (b[i][j] != 2) return false; n     } n   } n   for (i = 0; i < n; i++) { n     for (j = (m - m / 3) / 2 + (m / 3); j < m; j++) { n       if (b[i][j] != 3) return false; n     } n   } n   return true; n } n int main() { n   int i, j, c = 0, tmp = 0; n   scanf( %d %d , &n, &m); n   char a; n   map<char, int> mp; n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       scanf(  %c , &a); n       if (!mp.count(a)) { n         tmp++; n         mp[a] = tmp; n       } n       b[i][j] = mp[a]; n       if (b[i][j] == 3) c = 1; n     } n   } n   if (c == 1) { n     if (n % 3 == 0 || m % 3 == 0) { n       if (n % 3 == 0 && isHorrizontal()) n         puts( YES ); n       else if (m % 3 == 0 && isVertical()) n         puts( YES ); n       else n         puts( NO ); n     } else n       puts( NO ); n   } else n     puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using pii = pair<int, int>; n int main() { n   ios_base::sync_with_stdio(false); n   int t; n   cin >> t; n   while (t--) { n     ll a, b, c; n     cin >> a >> b >> c; n     ll x, y; n     if (a == c and b == 1) { n       cout <<  -1 -1  <<   n ; n       continue; n     } n     if (c <= a) n       x = -1; n     else n       x = 1; n     if (a * b <= c) n       y = -1; n     else n       y = b; n     cout << x <<     << y <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int grid[101][101]; n int canDoRowOperation(int r, int c) { n   int m = 1000; n   for (int j = 0; j < c; j++) m = min(m, grid[r][j]); n   return m; n } n int canDoClmOperation(int r, int c) { n   int m = 1000; n   for (int i = 0; i < r; i++) m = min(m, grid[i][c]); n   return m; n } n int main() { n   int r, c; n   scanf( %d %d , &r, &c); n   for (int i = 0; i < r; i++) { n     for (int j = 0; j < c; j++) { n       scanf( %d , &grid[i][j]); n     } n   } n   vector<string> r_c; n   vector<int> vec_num; n   if (r <= c) { n     for (int i = 0; i < r; i++) { n       int m = canDoRowOperation(i, c); n       if (m) { n         for (int j = 0; j < c; j++) grid[i][j] -= m; n       } n       for (int k = 0; k < m; k++) { n         r_c.push_back( row ); n         vec_num.push_back(i + 1); n       } n     } n     for (int j = 0; j < c; j++) { n       int m = canDoClmOperation(r, j); n       if (m) { n         for (int i = 0; i < r; i++) grid[i][j] -= m; n       } n       for (int k = 0; k < m; k++) { n         r_c.push_back( col ); n         vec_num.push_back(j + 1); n       } n     } n   } else { n     for (int j = 0; j < c; j++) { n       int m = canDoClmOperation(r, j); n       if (m) { n         for (int i = 0; i < r; i++) grid[i][j] -= m; n       } n       for (int k = 0; k < m; k++) { n         r_c.push_back( col ); n         vec_num.push_back(j + 1); n       } n     } n     for (int i = 0; i < r; i++) { n       int m = canDoRowOperation(i, c); n       if (m) { n         for (int j = 0; j < c; j++) grid[i][j] -= m; n       } n       for (int k = 0; k < m; k++) { n         r_c.push_back( row ); n         vec_num.push_back(i + 1); n       } n     } n   } n   bool isPossible = true; n   for (int i = 0; i < r; i++) n     for (int j = 0; j < c; j++) n       if (grid[i][j]) isPossible = false; n   if (isPossible == false) { n     cout << -1 << endl; n   } else { n     int sz = r_c.size(); n     cout << sz << endl; n     for (int i = 0; i < sz; i++) cout << r_c[i] <<     << vec_num[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 100010; n inline long long read() { n   long long p = 0; n   long long f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     p = p * 10 + ch -  0 ; n     ch = getchar(); n   } n   return p * f; n } n long long a[N]; n long long R[N << 1], L[N << 1]; n int main() { n   long long n = read(); n   long long m = read(); n   if (n == 1) { n     printf( 0 n ); n     return 0; n   } n   for (long long i = 1; i <= m; i++) a[i] = read(); n   long long ans = 0; n   long long l = 1; n   long long r = n; n   for (long long i = 1; i <= n; i++) R[i] = i; n   for (long long i = 1; i <= m; i++) { n     long long x = a[i]; n     l++; n     r++; n     R[r] = R[r - 1]; n     R[l + x - 1] = R[l + x - 2]; n   } n   l++; n   r++; n   R[r] = R[r - 1]; n   for (long long i = l; i <= r; i++) ans += R[i] + 1; n   l = m + 2; n   r = n + m + 1; n   for (long long i = 1; i <= n; i++) L[i + m + 1] = i; n   for (long long i = 1; i <= m; i++) { n     long long x = a[i]; n     l--; n     r--; n     L[l] = L[l + 1]; n     L[l + x - 1] = L[l + x]; n   } n   l--; n   r--; n   L[l] = L[l + 1]; n   for (long long i = l; i <= r; i++) ans -= L[i]; n   return printf( %lld n , ans), 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, s; n   scanf( %d%d , &n, &s); n   int a, max, sum = 0; n   scanf( %d , &a); n   max = a; n   sum += a; n   for (int i = 1; i < n; i++) { n     scanf( %d , &a); n     if (a > max) max = a; n     sum += a; n   } n   sum -= max; n   if (sum <= s) n     printf( YES ); n   else n     printf( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int pos[100005]; n pair<int, long long> ai[4 * 100005]; n void update_ai(int node, int l, int r, int pos, pair<int, long long> val) { n   if (l == r) { n     ai[node] = val; n     return; n   } n   int mid = (l + r) >> 1; n   if (pos <= mid) n     update_ai(2 * node, l, mid, pos, val); n   else n     update_ai(2 * node + 1, mid + 1, r, pos, val); n   ai[node].first = ai[2 * node].first + ai[2 * node + 1].first; n   ai[node].second = ai[2 * node].second + ai[2 * node + 1].second; n } n void query_ai(int node, int l, int r, int lq, int rq, n               pair<int, long long> &ans) { n   if (lq <= l && r <= rq) { n     ans.first += ai[node].first; n     ans.second += ai[node].second; n     return; n   } n   int mid = (l + r) >> 1; n   if (lq <= mid) query_ai(2 * node, l, mid, lq, rq, ans); n   if (mid + 1 <= rq) query_ai(2 * node + 1, mid + 1, r, lq, rq, ans); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     int x; n     scanf( %d , &x); n     pos[x] = i; n   } n   double sol = 0; n   for (int i = 1; i <= n; ++i) { n     pair<int, long long> x = make_pair(0, 0); n     query_ai(1, 1, n, 1, pos[i], x); n     sol += ((double)(n - pos[i] + 1)) / n * (((double)x.second) / (n + 1)); n     x = make_pair(0, 0); n     query_ai(1, 1, n, pos[i], n, x); n     sol += x.first - n            ((double)pos[i]) / n * (x.first - ((double)x.second) / (n + 1)); n     update_ai(1, 1, n, pos[i], make_pair(1, pos[i])); n   } n   printf( %.20f n , sol); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long nx2(long long n) { n   long long p = 1; n   if (n && !(n & (n - 1))) return n; n   while (p < n) p <<= 1; n   return p; n } n namespace Debug { n void dout() { cerr <<   n ; } n template <typename Head, typename... Tail> n void dout(Head H, Tail... T) { n   cerr <<     << H; n   dout(T...); n } n template <typename T> n void douta(const T *a, int n) { n   cerr <<   n[ ; n   for (int i = 0; i < n; i++) { n     cerr <<     << a[i]; n   } n   cerr <<   ] n ; n } n template <typename T> n void doutaa(T **b, int r, int c) { n   for (int i = 0; i < r; i++) { n     cerr <<  [ ; n     for (int j = 0; j < c; j++) { n       cerr <<     << b[i][j]; n     } n     cerr <<   ] n ; n   } n } n template <typename T> n void dout(const vector<T> v) { n   cerr <<   n[ ; n   for (T i : v) { n     cerr <<     << i; n   } n   cerr <<   ] n ; n } n template <typename T> n void dout(const vector<vector<T>> v) { n   cerr <<   n ; n   for (vector<T> u : v) { n     cerr <<  [ ; n     for (T i : u) { n       cerr <<     << i; n     } n     cerr <<   ] n ; n   } n } n template <typename F, typename S> n void dout(const vector<pair<F, S>> u) { n   cerr <<   n ; n   for (pair<F, S> v : u) { n     cerr <<  [   << v.first <<     << v.second <<   ] n ; n   } n } n }  // namespace Debug n using namespace Debug; n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, m, k; n   cin >> n >> m >> k; n   vector<vector<vector<long long>>> adj(n); n   vector<long long> si(k); n   for (long long i = 0; i < m + k; i++) { n     if (i < m) { n       long long u, v, x; n       cin >> u >> v >> x, --u, --v; n       adj[u].push_back({v, x, i}); n       adj[v].push_back({u, x, i}); n     } else { n       long long s, y; n       cin >> s >> y, --s; n       si[i - m] = s; n       adj[0].push_back({s, y, i}); n       adj[s].push_back({0, y, i}); n     } n   } n   vector<long long> vis(n), vis1(n), dist(n, INT_MAX); n   priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, n                  greater<pair<long long, long long>>> n       pq; n   dist[0] = 0; n   pq.push({dist[0], 0}); n   vis[0] = 0; n   while (!pq.empty()) { n     long long u = pq.top().second; n     pq.pop(); n     if (vis1[u]) { n       continue; n     } n     vis1[u] = 1; n     for (auto vwi : adj[u]) { n       long long v = vwi[0], w = vwi[1], i = vwi[2]; n       if (v == 0) { n         continue; n       } n       if (dist[v] > dist[u] + w) { n         vis[v] = i; n         dist[v] = dist[u] + w; n         pq.push({dist[v], v}); n       } else if (dist[v] == dist[u] + w && vis[v] >= m && i < m) { n         vis[v] = i; n         pq.push({dist[v], v}); n       } n     } n   } n   long long res = 0; n   for (long long i = 0; i < k; i++) { n     res += (vis[si[i]] != i + m); n   } n   cout << res <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long x, y, u = 0, v = 0; n vector<pair<long long, long long> > visited; n void move(char c) { n   if (c ==  U ) n     v++; n   else if (c ==  D ) n     v--; n   else if (c ==  L ) n     u--; n   else n     u++; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> x >> y; n   if (x == 0 && y == 0) { n     cout <<  Yes ; n     return 0; n   } n   string s; n   cin >> s; n   for (long long i = 0; i < (long long)s.size(); ++i) { n     move(s[i]); n     if (u == x && v == y) { n       cout <<  Yes ; n       return 0; n     } n     visited.push_back(make_pair(u, v)); n   } n   if (u == 0 && v == 0) { n     cout <<  No ; n     return 0; n   } n   long long h_shift = u, v_shift = v; n   for (long long i = 0; i < (long long)s.size(); ++i) { n     move(s[i]); n     if (u == x && v == y) { n       cout <<  Yes ; n       return 0; n     } n     long long u_ref = x - visited[i].first; n     long long v_ref = y - visited[i].second; n     long long p = (h_shift ? u_ref % h_shift : u_ref); n     long long q = (v_shift ? v_ref % v_shift : v_ref); n     if (((u_ref < 0 && h_shift > 0) || (u_ref > 0 && h_shift < 0)) || n         ((v_ref < 0 && v_shift > 0) || (v_ref > 0 && v_shift < 0))) n       continue; n     if (p == 0 && q == 0 && (u_ref * v_shift == v_ref * h_shift)) { n       cout <<  Yes ; n       return 0; n     } n   } n   cout <<  No ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)5e5 + 123, inf = 1e9, mod = 1e9 + 7, M = 511; n const long long INF = (long long)1e18; n int n, m, k, x, y, d, t, e; n long long A[M][M], a[2][M][M]; n vector<pair<int, int> > ex[M][M], ey[M][M]; n int main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(NULL); n   cin >> n >> m >> k; n   for (int i = 1; i <= k; ++i) { n     cin >> x >> y >> d >> t >> e; n     if (x + y >= t && ((x + y) - t) % 4 == 0) { n       A[x][y] += e; n       if (x + d + y >= t && ((x + d + y) - t) % 4 == 2) { n         ex[x + d][y].push_back(make_pair(d, e)); n       } n       if (x + y + d >= t && ((x + y + d) - t) % 4 == 3) { n         ey[x][y + d].push_back(make_pair(d, e)); n       } n     } n     if (x + d + y - d >= t && ((x + d + y - d) - t) % 4 == 1) { n       A[x + d][y - d] += e; n       if (x + d + y >= t && ((x + d + y) - t) % 4 == 2) { n         ey[x + d][y].push_back(make_pair(d, e)); n       } n     } n     if (x + d + y >= t && ((x + d + y) - t) % 4 == 2) { n       A[x + d][y] += e; n     } n     if (x + y + d >= t && ((x + y + d) - t) % 4 == 3) { n       A[x][y + d] += e; n     } n   } n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) a[0][i][j] = a[1][i][j] = INF; n   a[0][0][0] = a[1][0][0] = 0; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) { n       sort(ex[i][j].begin(), ex[i][j].end()); n       sort(ey[i][j].begin(), ey[i][j].end()); n     } n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) { n       long long cost = a[0][i][j]; n       for (int k = 1; k + i < n; ++k) { n         cost += A[i + k][j]; n         for (int w = 0; w < (int)ex[i + k][j].size(); ++w) { n           if (i + k - ex[i + k][j][w].first >= i) n             cost -= ex[i + k][j][w].second; n           else n             break; n         } n         a[1][i + k][j] = min(a[1][i + k][j], cost); n       } n       cost = a[1][i][j]; n       for (int k = 1; k + j < m; ++k) { n         cost += A[i][j + k]; n         for (int w = 0; w < (int)ey[i][j + k].size(); ++w) { n           if (j + k - ey[i][j + k][w].first >= j) n             cost -= ey[i][j + k][w].second; n           else n             break; n         } n         a[0][i][j + k] = min(a[0][i][j + k], cost); n       } n     } n   cout << min(a[0][n - 1][m - 1], a[1][n - 1][m - 1]); n   return 0; n } n