#include <bits/stdc++.h> n using namespace std; n const int N = 5e5 + 100; n int num[N]; n bool vis[N]; n vector<int> v; n int n, k; n int main() { n   scanf( %d %d , &n, &k); n   int mn = 1e9 + 1000; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &num[i]); n     if (num[i] < mn) { n       mn = num[i]; n       vis[i] = true; n       v.push_back(i); n     } n   } n   v.push_back(n + 1); n   num[n + 1] = 0; n   int cnt = 0; n   int mx = 0; n   for (int i = 1; i < v.size(); i++) { n     mx = max(mx, v[i] - v[i - 1]); n     if (v[i] - v[i - 1] > k) cnt++; n   } n   if (cnt >= 2) { n     puts( NO ); n   } else if (cnt == 0) { n     puts( YES ); n   } else { n     int tmp = -1; n     for (int i = 1; i < v.size(); i++) { n       if (v[i] - v[i - 1] > k) tmp = i; n     } n     bool ans = false; n     if (tmp != v.size() - 1 && v[tmp + 1] - v[tmp - 1] <= 2 * k) ans = true; n     if (tmp == 0 && v[1] <= 2 * k) tmp = true; n     for (int i = v[tmp] + 1; i <= n; i++) { n       if (vis[i]) continue; n       if (num[i] < num[v[tmp - 1]] && num[i] > num[v[tmp]]) ans = true; n     } n     if (ans) n       puts( YES ); n     else n       puts( NO ); n   } n   return 0; n } n


#include <iostream> n  n int main(void) { n  int count; n  std::cin >> count; n  for (int i = 0; i < count; ++i) { n   int number; n   std::cin >> number; n   int64_t sum = 0; n   for (int j = 0; j < number; ++j) { n    int part; n    std::cin >> part; n    sum += part; n   } n   std::cout << (sum % number) * (number - sum % number) <<   n ; n  } n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ii = pair<int, int>; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   vector<int> v(n); n   for (auto &i : v) cin >> i; n   int q; n   cin >> q; n   vector<int> idx(n, 0); n   vector<int> ops(q, 0); n   for (int i = 0; i < q; ++i) { n     int op; n     cin >> op; n     if (op == 1) { n       int p, x; n       cin >> p >> x; n       v[p - 1] = x; n       idx[p - 1] = i; n     } else { n       int x; n       cin >> x; n       ops[i] = x; n     } n   } n   for (int i = q - 2; i >= 0; --i) ops[i] = max(ops[i], ops[i + 1]); n   for (int i = 0; i < n; ++i) { n     v[i] = max(ops[idx[i]], v[i]); n   } n   for (int i = 0; i < n; ++i) cout << v[i] <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #define ll long long n #define ld long double n #define lchild 2*node n #define rchild 2*node+1 n #define mid (l+r)/2 n #define mod 1000000007 n #define mx 200007 n #define pii pair<int,int> n #define pci pair<int,int> n #define ff first n #define ss second n #define piii pair<int,pii> n using namespace std; n  n int t1[mx][21], lg2[mx], t2[mx][21]; n int arr[mx]; n  n void f( int n ) n { n     int i, j, k, m, l, r, q; n     lg2[1] = 0; n     for (i = 2; i <= n; i++) lg2[i] = lg2[i / 2] + 1; n     for (i = 1; i <= n; i++) t1[i][0] = arr[i], t2[i][0] = arr[i]; n     for (j = 1; j <= 20; j++) for (i = 1; i + (1 << (j - 1)) <= n; i++) t1[i][j] = min(t1[i][j - 1], t1[i + (1 << (j - 1))][j - 1]); n     for (j = 1; j <= 20; j++) for (i = 1; i + (1 << (j - 1)) <= n; i++) t2[i][j] = max(t2[i][j - 1], t2[i + (1 << (j - 1))][j - 1]);         n } n  n int squery1( int l, int r ) n { n     // int ans = min(ans, t[l][i]), l += (1 << i); n     int k = lg2[r - l + 1]; n     int ans = min(t1[l][k], t1[r - (1 << k) + 1][k]); n  n     return ans; n } n  n int squery2( int l, int r ) n { n     // int ans = min(ans, t[l][i]), l += (1 << i); n     int k = lg2[r - l + 1]; n     int ans = max(t2[l][k], t2[r - (1 << k) + 1][k]); n  n     return ans; n } n  n  n  n int main() n { n     ios_base::sync_with_stdio(0); n     cin.tie(0); n  n     int tc; n     cin >> tc; n  n     while (tc--) n     { n         int n; n         cin >> n; n  n         for ( int i = 1; i <= n; i++ ) n             cin >> arr[i]; n  n         f(n); n  n         int pre[n + 5], suff[n + 5]; n         pre[1] = arr[1]; n         suff[n] = arr[n]; n  n         for ( int i = 2; i <= n; i++ ) n             pre[i] = max( pre[i - 1], arr[i] ); n         for ( int i = n - 1; i >= 1; i-- ) n             suff[i] = max( suff[i + 1], arr[i] ); n  n         bool f= 0; n         int out, lf, rt; n  n         for ( int i = 2; i < n; i++ ) n         { n             int x = arr[i]; n  n             int baam = i, daan = i; n  n             int l = 1, r = i; n  n             if ( i > 1 ) n             { n                 int ans = i; n                 while (l <= r) n                 { n                     int q = squery1( mid, i ); n  n                     if (q != x) n                         l = mid + 1; n                     else n                         ans = mid, r = mid - 1; n                 } n  n                 baam = ans; n             } n  n             l = i, r = n; n  n             if ( i < n ) n             { n                 int ans = i; n                 while (l <= r) n                 { n                     int q = squery1( i, mid ); n  n                     // cout<<x<<   <<l<<   <<r<<   <<q<<endl; n  n                     if (q != x) n                         r = mid - 1; n                     else n                         ans = mid, l = mid + 1; n                 } n  n                 daan = ans; n             } n  n             baam= max( baam, 2 ); n             daan= min( daan, n-1 ); n  n             if( baam<i and arr[baam]==arr[i] ) n                 baam++; n             if( daan>i and arr[daan]==arr[i] ) n                 daan--; n  n             if( pre[baam-1]==suff[daan+1] and pre[baam-1]==arr[i] ) n             { n                 f= 1; n                 out= daan-baam+1; n                 lf= baam-1; n                 rt= n-daan; n                 break; n             } n  n             // cout<<i<<   <<baam<<   <<daan<<   <<pre[baam-1]<<    <<suff[daan+1]<<endl; n         } n  n         if(f) n             cout<< YES n <<lf<<   <<out<<   <<rt<<  n ; n         else n             cout<< NO n ; n  n     } n }


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200005; n int a[maxn]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n * 2; i++) scanf( %d , &a[i]); n   sort(a, a + n * 2); n   long long area = 1ll * (a[n - 1] - a[0]) * (a[n * 2 - 1] - a[n]); n   for (int i = 1; i < n; i++) { n     area = min(area, 1ll * (a[i + n - 1] - a[i]) * (a[n * 2 - 1] - a[0])); n   } n   printf( %I64d , area); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c; n   cin >> a >> b; n   if (a >= b) { n     c = (a - b) / 2; n     cout << b <<     << c; n   } else { n     c = (b - a) / 2; n     cout << a <<     << c; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, d; n   scanf( %d %d , &n, &d); n   int data[n + 10]; n   for (int i = 0; i < n; i++) scanf( %d , &data[i]); n   long long ans = 0; n   for (int i = 0; i < n - 1; i++) { n     int h = upper_bound(data, data + n, data[i] + d) - data; n     h--; n     int l = i; n     int n = (h - l) + 1; n     if (n < 3) continue; n     n -= 2; n     ans += ((long long)(n) * (long long)(n + 1)) / 2; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 123; n int n, t, label[N], times = 0; n vector<int> e[N]; n vector<pair<int, int> > res; n void newLabel(int u) { n   res.push_back(make_pair(u, times)); n   label[u] = times; n } n void dfs(int u, int backLabel = -1, int p = 0) { n   newLabel(u); n   int numchild = (int)e[u].size() - (u > 1); n   for (int v : e[u]) { n     if (v == p) continue; n     if (label[u] >= t) { n       times = backLabel - numchild; n       newLabel(u); n     } n     times = label[u] + 1; n     dfs(v, label[u], u); n     if (label[v] > label[u]) { n       times = label[u]; n       newLabel(v); n     } n     ++times; n     newLabel(u); n     --numchild; n   } n   if (u > 1 && label[u] > backLabel) { n     times = backLabel; n     newLabel(u); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(); n   cout.tie(); n   cin >> n; n   for (int i = 1; i < n; ++i) { n     int u, v; n     cin >> u >> v; n     e[u].push_back(v); n     e[v].push_back(u); n   } n   t = -1; n   for (int i = 1; i <= n; ++i) t = max(t, (int)e[i].size()); n   dfs(1); n   cout << res.size() <<   n ; n   for (pair<int, int> x : res) { n     cout << x.first <<     << x.second <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct point { n   double df, de; n   void init(double _df, double _de) { n     df = _df; n     de = _de; n   } n } V[100]; n int nf, ne, ns, rf, re, rs, df, de; n int n, top, place[13]; n double ans = 0, dp[21][21], lf, le, ls; n bool cmp(const point &a, const point &b) { return a.df > b.df; } n double cross(double l1, double r1, double l2, double r2) { n   if (l2 >= r1 || l1 >= r2) return 0; n   return min(r1, r2) - max(l1, l2); n } n void init_V() { n   top = 0; n   for (int i = 0; i < n; i++) n     if (place[i] < 2) { n       double t1 = lf * df, t2 = le * de; n       for (int j = 0; j < n; j++) n         if (place[j]) { n           t1 += df * place[j] * n                 cross(j - ls / 2, j + ls / 2, i - lf / 2, i + lf / 2); n           t2 += de * place[j] * n                 cross(j - ls / 2, j + ls / 2, i - le / 2, i + le / 2); n         } n       for (int j = 1; j + place[i] <= 2; j++) V[top++].init(t1, t2); n     } n   sort(V, V + top, cmp); n } n void init_dp() { n   memset(dp, 0, sizeof(dp)); n   for (int i = 0; i <= nf; i++) n     for (int j = 0; j <= ne; j++) { n       if (i) dp[i][j] = max(dp[i][j], dp[i - 1][j] + V[i + j - 1].df); n       if (j) dp[i][j] = max(dp[i][j], dp[i][j - 1] + V[i + j - 1].de); n     } n   ans = max(ans, dp[nf][ne]); n } n void dfs(int p, int left) { n   if ((n - p) * 2 < left) return; n   if (p == n) { n     init_V(); n     init_dp(); n     return; n   } n   for (int i = 0; i <= 2 && left >= i; i++) { n     place[p] = i; n     dfs(p + 1, left - i); n   } n } n int main() { n   cin >> nf >> ne >> ns >> rf >> re >> rs >> df >> de; n   n = (nf + ne + ns + 1) / 2; n   lf = 2 * sqrt(rf * rf - 1.0); n   le = 2 * sqrt(re * re - 1.0); n   ls = 2 * sqrt(rs * rs - 1.0); n   dfs(0, ns); n   printf( %.10lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n struct rge { n   T b, e; n }; n template <class T> n rge<T> range(T i, T j) { n   return rge<T>{i, j}; n } n struct debug { n   template <class T> n   debug& operator<<(const T&) { n     return *this; n   } n }; n using ll = long long; n template <typename T> n void min_self(T& a, T b) { n   a = min(a, b); n } n template <typename T> n void max_self(T& a, T b) { n   a = max(a, b); n } n const int mxN = 2500 * 1000 + 5; n int xs[mxN], N = 0; n const ll inf = 1e18; n class SegTree { n  public: n   struct Node { n     ll mn = inf; n     void merge(Node x, Node y) { mn = min(x.mn, y.mn); } n   }; n   SegTree(int _n) : n(_n) { n     tree.resize(4 * n); n     lazy.resize(4 * n); n   } n   void build(int i, int L, int R) { n     if (L == R) { n       tree[i].mn = 0; n     } else { n       int m = L + (R - L) / 2; n       build(2 * i, L, m); n       build(2 * i + 1, m + 1, R); n       tree[i].merge(tree[2 * i], tree[2 * i + 1]); n     } n   } n   void push(int i) { n     ll& v = lazy[i]; n     tree[2 * i].mn += v; n     lazy[2 * i] += v; n     tree[2 * i + 1].mn += v; n     lazy[2 * i + 1] += v; n     v = 0; n   } n   Node get(int i, int L, int R, int tl, int tr) { n     if (tl > tr) return Node(); n     if (L == tl && tr == R) { n       return tree[i]; n     } else { n       push(i); n       int m = L + (R - L) / 2; n       Node ans; n       ans.merge(get(2 * i, L, m, tl, min(tr, m)), n                 get(2 * i + 1, m + 1, R, max(m + 1, tl), tr)); n       return ans; n     } n   } n   ll get(int tl, int tr) { n     Node ans = get(1, 1, n, tl, tr); n     return ans.mn; n   } n   void upd(int i, int L, int R, int tl, int tr, int val) { n     if (tl > tr) return; n     if (L == tl && tr == R) { n       tree[i].mn += val; n       lazy[i] += val; n     } else { n       push(i); n       int m = L + (R - L) / 2; n       upd(2 * i, L, m, tl, min(tr, m), val); n       upd(2 * i + 1, m + 1, R, max(m + 1, tl), tr, val); n       tree[i].merge(tree[2 * i], tree[2 * i + 1]); n     } n   } n   void upd(int tl, int tr, int val) { upd(1, 1, n, tl, tr, val); } n  n  private: n   int n; n   vector<Node> tree; n   vector<ll> lazy; n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   vector<pair<int, int>> tv; n   for (int i = 0; i < n; i++) { n     int a, b; n     cin >> a >> b; n     for (int x : {a - 1, a, a + 1, b - 1, b, b + 1}) { n       xs[N++] = x; n     } n     tv.emplace_back(a, b); n   } n   sort(xs, xs + N); n   N = unique(xs, xs + N) - xs; n   SegTree st(N); n   st.build(1, 1, N); n   for (auto pp : tv) { n     int L = pp.first, R = pp.second; n     L = lower_bound(xs, xs + N, L) - xs; n     R = lower_bound(xs, xs + N, R) - xs; n     st.upd(L + 1, R + 1, 1); n   } n   int who = 1; n   for (auto pp : tv) { n     int L = pp.first, R = pp.second; n     L = lower_bound(xs, xs + N, L) - xs; n     R = lower_bound(xs, xs + N, R) - xs; n     if (st.get(L + 1, R + 1) > 1) { n       cout << who <<   n ; n       exit(0); n     } n     who++; n   } n   cout <<  -1 n ; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long a, b; n   cin >> a >> b; n   if (b - a > 5) { n     cout << 0 <<   n ; n   } else { n     long long val = 1; n     for (long long j = a + 1; j <= b; j++) { n       val *= (j % 10); n       val %= 10; n     } n     cout << val <<   n ; n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n struct Point { n   int x; n   int y; n }; n struct Rect { n   int left; n   int top; n   int right; n   int bottom; n }; n bool FindBoundary(const vector<Point> &pts, Rect *getRect) { n   if (pts.empty()) { n     return false; n   } n   auto it = pts.begin(); n   getRect->left = it->x; n   getRect->right = it->x; n   getRect->top = it->y; n   getRect->bottom = it->y; n   for (auto it = pts.begin(); it != pts.end(); ++it) { n     if (getRect->left > it->x) { n       getRect->left = it->x; n     } n     if (getRect->right < it->x) { n       getRect->right = it->x; n     } n     if (getRect->top < it->y) { n       getRect->top = it->y; n     } n     if (getRect->bottom > it->y) { n       getRect->bottom = it->y; n     } n   } n   return true; n } n bool IsSquare(const Rect *rect) { n   return rect->right - rect->left == rect->top - rect->bottom; n } n bool CheckPoints(const vector<Point> &pts, const Rect *rect, int n) { n   int left = 0, top = 0, right = 0, bottom = 0; n   bool notAny = true; n   for (auto it = pts.begin(); it != pts.end(); ++it) { n     notAny = true; n     if (it->x == rect->left) { n       notAny = false; n       ++left; n     } n     if (it->x == rect->right) { n       notAny = false; n       ++right; n     } n     if (it->y == rect->top) { n       notAny = false; n       ++top; n     } n     if (it->y == rect->bottom) { n       notAny = false; n       ++bottom; n     } n     if (notAny) { n       return false; n     } n   } n   if (left < n || right < n || top < n || bottom < n) { n     return false; n   } n   return true; n } n int main(int argc, char *argv[]) { n   int n = 0; n   cin >> n; n   int amount = 4 * n + 1; n   vector<Point> points; n   for (int i = 0; i < amount; ++i) { n     Point pt; n     cin >> pt.x >> pt.y; n     points.push_back(pt); n   } n   bool found = false; n   for (int i = 0; i < amount; ++i) { n     vector<Point> sqPoints; n     for (int j = 0; j < amount; ++j) { n       if (j != i) { n         sqPoints.push_back(points[j]); n       } n     } n     Rect rect; n     if (!FindBoundary(sqPoints, &rect)) { n       continue; n     } n     if (!IsSquare(&rect)) { n       continue; n     } n     if (!CheckPoints(sqPoints, &rect, n)) { n       continue; n     } n     printf( %d %d , points[i].x, points[i].y); n     break; n   } n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n typedef long long ll; n //#define rep(i,a,b) for(int i=a;i<b;i++); n void solve(){ n  ll n; n  cin>>n; n  string s; n  cin>>s; n  vector<ll>v; n  for(int i=0;i<n;i++){ n   if (s[i]== * ){ n    v.push_back(i); n   } n  } n  if (v.size()<=1 or v.size()==n){ n   cout<<0<<endl; n  } n  else{ n  ll mid=v.size()/2; n  ll ans=0; n  for(int i=0;i<v.size();i++){ n   ans+=abs(v[i]-v[mid]); n  } n   n  n  if (v.size()%2==0){ n   ll t1=v.size()/2; n   ll t2=v.size()/2-1; n  n   ll d1=t1*(t1+1)/2; n   ll d2=t2*(t2+1)/2; n   ans-=(d1+d2); n  } n  n  else{ n   ll t1=v.size()/2; n   ll d1=t1*(t1+1)/2; n   ans-=(2*d1); n  } n  n  cout<<ans<<endl; n } n } n int main(){ n  int t=1; n  cin>>t; n  while(t--) n  solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = 3.141592653589793; n const long long I_MAX = 1LL << 60; n long long mod = 1000000007; n const long long maxN = 2E5; n vector<long long> inv(maxN + 5, 1); n vector<long long> fac(maxN + 5, 1); n void ADD(long long &x, long long y) { n   x += y; n   if (x >= mod) x -= mod; n   if (x < 0) x += mod; n } n void MUL(long long &x, long long y) { n   x *= y; n   x = (x % mod + mod) % mod; n } n long long mypow(long long b, long long e) { n   long long ans = 1; n   while (e) { n     if (e & 1) MUL(ans, b); n     MUL(b, b); n     e >>= 1; n   } n   return ans; n } n long long modinv(long long n) { return mypow(n, mod - 2); } n void calcInv(long long n) { n   for (int i = 2; i <= n; ++i) { n     inv[i] = (mod - mod / i) * inv[mod % i] % mod; n   } n } n void calcFac(long long n) { n   for (int i = 2; i <= n; ++i) { n     fac[i] = fac[i - 1] * i % mod; n   } n } n long long cm(long long a, long long b) { n   long long ans = 1; n   if (a < b) return 0; n   MUL(ans, inv[fac[a - b]]); n   MUL(ans, inv[fac[b]]); n   MUL(ans, fac[a]); n   return ans; n } n long long Lucas(long long n, long long m) { n   if (m == 0) return 1; n   return cm(n % mod, m % mod) * Lucas(n / mod, m / mod) % mod; n } n long long doLucas(long long n, long long m) { n   calcInv(mod); n   calcFac(mod); n   return Lucas(n, m); n } n const long long maxn = 1E5; n void precal() { return; } n void solve() { n   long long n; n   scanf( %I64d , &n); n   int pln[n + 5][n + 5]; n   memset(pln, -1, sizeof(pln)); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) { n       if ((i & 1) and (j & 1)) n         pln[i][j] = 0; n       else if ((i & 1)) n         pln[i][j] = 2; n       else if ((j & 1)) n         pln[i][j] = 4; n       else n         pln[i][j] = 6; n     } n   pln[1][1] = 1; n   pln[n][n] = 0; n   int rep; n   for (int i = 1; i <= n; i += 2) { n     for (int j = 1; j <= n - 2 - 2 * (i == n); j += 2) { n       printf( ? %d %d %d %d n , i, j, i, j + 2); n       fflush(stdout); n       scanf( %d , &rep); n       if (rep == 1) { n         pln[i][j + 2] = pln[i][j]; n       } else { n         pln[i][j + 2] = pln[i][j] ^ 1; n       } n     } n     if (i + 2 <= n) { n       printf( ? %d %d %d %d n , i, 1, i + 2, 1); n       fflush(stdout); n       scanf( %d , &rep); n       if (rep == 1) { n         pln[i + 2][1] = pln[i][1]; n       } else { n         pln[i + 2][1] = pln[i][1] ^ 1; n       } n     } n   } n   for (int i = 2; i <= n; i += 2) { n     for (int j = 1; j <= n - 2; j += 2) { n       printf( ? %d %d %d %d n , i, j, i, j + 2); n       fflush(stdout); n       scanf( %d , &rep); n       if (rep == 1) { n         pln[i][j + 2] = pln[i][j]; n       } else { n         pln[i][j + 2] = pln[i][j] ^ 1; n       } n     } n     if (i + 2 <= n) { n       printf( ? %d %d %d %d n , i, 1, i + 2, 1); n       fflush(stdout); n       scanf( %d , &rep); n       if (rep == 1) { n         pln[i + 2][1] = pln[i][1]; n       } else { n         pln[i + 2][1] = pln[i][1] ^ 1; n       } n     } n   } n   for (int i = 1; i <= n; i += 2) { n     for (int j = 2; j <= n - 2; j += 2) { n       printf( ? %d %d %d %d n , i, j, i, j + 2); n       fflush(stdout); n       scanf( %d , &rep); n       if (rep == 1) { n         pln[i][j + 2] = pln[i][j]; n       } else { n         pln[i][j + 2] = pln[i][j] ^ 1; n       } n     } n     if (i + 2 <= n) { n       printf( ? %d %d %d %d n , i, 2, i + 2, 2); n       fflush(stdout); n       scanf( %d , &rep); n       if (rep == 1) { n         pln[i + 2][2] = pln[i][2]; n       } else { n         pln[i + 2][2] = pln[i][2] ^ 1; n       } n     } n   } n   for (int i = 2; i <= n; i += 2) { n     for (int j = 2; j <= n - 2; j += 2) { n       printf( ? %d %d %d %d n , i, j, i, j + 2); n       fflush(stdout); n       scanf( %d , &rep); n       if (rep == 1) { n         pln[i][j + 2] = pln[i][j]; n       } else { n         pln[i][j + 2] = pln[i][j] ^ 1; n       } n     } n     if (i + 2 <= n) { n       printf( ? %d %d %d %d n , i, 2, i + 2, 2); n       fflush(stdout); n       scanf( %d , &rep); n       if (rep == 1) { n         pln[i + 2][2] = pln[i][2]; n       } else { n         pln[i + 2][2] = pln[i][2] ^ 1; n       } n     } n   } n   printf( ? %d %d %d %d n , 1, 1, 2, 2); n   fflush(stdout); n   scanf( %d , &rep); n   if (rep == 1) { n     for (int i = 2; i <= n; i += 2) n       for (int j = 2; j <= n; j += 2) { n         pln[i][j] ^= 7; n       } n   } else { n     for (int i = 2; i <= n; i += 2) n       for (int j = 2; j <= n; j += 2) { n         pln[i][j] ^= 6; n       } n   } n   printf( ? %d %d %d %d n , 1, 2, 2, 3); n   fflush(stdout); n   scanf( %d , &rep); n   if (rep == 1) { n     int x = pln[2][3] ^ 2; n     for (int i = 2; i <= n; i += 2) n       for (int j = 1; j <= n; j += 2) { n         pln[i][j] ^= x; n       } n   } else { n     int x = pln[2][3] ^ 3; n     for (int i = 2; i <= n; i += 2) n       for (int j = 1; j <= n; j += 2) { n         pln[i][j] ^= x; n       } n   } n   int px = n, py = n; n   for (int i = 2; i <= n; ++i) { n     for (int j = 3; j <= n; ++j) { n       if (pln[i - 1][j - 2] == pln[i][j - 1] and pln[i][j - 2] == pln[i][j]) { n         px = i; n         py = j; n       } n       if (pln[i - 1][j - 2] != pln[i][j - 1] and pln[i][j - 2] != pln[i][j]) { n         px = i; n         py = j; n       } n       if (pln[i - 1][j - 2] == pln[i][j - 1] and n           pln[i - 1][j - 1] == pln[i][j]) { n         px = i; n         py = j; n       } n       if (pln[i - 1][j - 2] != pln[i][j - 1] and n           pln[i - 1][j - 1] != pln[i][j]) { n         px = i; n         py = j; n       } n       if (pln[i - 1][j - 2] == pln[i - 1][j] and pln[i][j - 2] == pln[i][j]) { n         px = i; n         py = j; n       } n       if (pln[i - 1][j - 2] != pln[i - 1][j] and pln[i][j - 2] != pln[i][j]) { n         px = i; n         py = j; n       } n     } n   } n   printf( ? %d %d %d %d n , px - 1, py - 2, px, py); n   fflush(stdout); n   scanf( %d , &rep); n   if (px % 2 != py % 2) { n     if (rep == 1) { n       int x = pln[px][py] ^ pln[px - 1][py - 2]; n       for (int i = 2; i <= n; i += 2) n         for (int j = 1; j <= n; j += 2) { n           pln[i][j] ^= x; n         } n       for (int i = 1; i <= n; i += 2) n         for (int j = 2; j <= n; j += 2) { n           pln[i][j] ^= x; n         } n     } else { n       int x = pln[px][py] ^ pln[px - 1][py - 2] ^ 1; n       for (int i = 2; i <= n; i += 2) n         for (int j = 1; j <= n; j += 2) { n           pln[i][j] ^= x; n         } n       for (int i = 1; i <= n; i += 2) n         for (int j = 2; j <= n; j += 2) { n           pln[i][j] ^= x; n         } n     } n   } else { n     if (rep == 1) { n       int x = pln[px][py] ^ pln[px - 1][py - 2]; n       for (int i = 2; i <= n; i += 2) n         for (int j = 1; j <= n; j += 2) { n           pln[i][j] ^= x; n         } n       for (int i = 1; i <= n; i += 2) n         for (int j = 2; j <= n; j += 2) { n           pln[i][j] ^= x; n         } n     } else { n       int x = pln[px][py] ^ pln[px - 1][py - 2] ^ 1; n       for (int i = 2; i <= n; i += 2) n         for (int j = 1; j <= n; j += 2) { n           pln[i][j] ^= x; n         } n       for (int i = 1; i <= n; i += 2) n         for (int j = 2; j <= n; j += 2) { n           pln[i][j] ^= x; n         } n     } n   } n   printf( ! n ); n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= n; ++j) { n       printf( %d , pln[i][j]); n     } n     printf(  n ); n   } n   fflush(stdout); n } n int main() { n   precal(); n   int t = 1; n   for (int i = 1; i <= t; ++i) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int W, H, n; n   scanf( %d%d%d , &W, &H, &n); n   multiset<int> w, h; n   w.insert(-W); n   h.insert(-H); n   set<int> wa, ha; n   wa.insert(0); n   wa.insert(W); n   ha.insert(0); n   ha.insert(H); n   for (int i = 0; i < n; i++) { n     char t; n     int x; n     scanf(  n%c%d , &t, &x); n     if (t ==  H ) { n       auto r = ha.lower_bound(x); n       auto l = r; n       l--; n       h.erase(h.find((*l) - (*r))); n       ha.insert(x); n       h.insert((*l) - x); n       h.insert(x - (*r)); n     } else if (t ==  V ) { n       auto r = wa.lower_bound(x); n       auto l = r; n       l--; n       w.erase(w.find((*l) - (*r))); n       wa.insert(x); n       w.insert((*l) - x); n       w.insert(x - (*r)); n     } n     printf( %lld n , 1ll * (*h.begin()) * (*w.begin())); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAX = 1000009; n long long mod = 998244353; n long long n, kek[MAX]; n vector<long long> child[MAX]; n long long bin(long long num, long long power) { n   if (power == 0) n     return 1; n   else { n     long long an = (num) % mod; n     if (power % 2 == 0) { n       an = bin(num, power / 2); n       long long an1 = an; n       an *= an1; n       an %= mod; n       return an; n     } else { n       an *= bin(num, power - 1); n       an %= mod; n       return an; n     } n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long q; n   cin >> q; n   while (q--) { n     long long n, k; n     cin >> n >> k; n     if (n % k <= k / 2) { n       cout << n <<   n ; n     } else n       cout << n - ((n % k) - k / 2) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool chk(int n, int first) { return n & (1 << first); } n void set(int& n, int first) { n = n | (1 << first); } n void reset(int& n, int first) { n = n & ~(1 << first); } n const int mx = 600010; n bool f[mx]; n int a[mx][3], _size; n char s[mx]; n int new_node() { n   ++_size; n   for (int i = 0; i < 3; i++) a[_size][i] = 0; n   f[_size] = false; n   return _size; n } n void Insert(char str[]) { n   int cur = 0, i = -1; n   while (str[++i] !=   0 ) { n     int& next = a[cur][str[i] -  a ]; n     if (next == 0) next = new_node(); n     cur = next; n   } n   f[cur] = true; n } n bool Search(int i, int cur, bool flag) { n   if (s[i] ==   0 ) return f[cur] && flag; n   if (flag) { n     int next = a[cur][s[i] -  a ]; n     if (next == 0) return false; n     return Search(i + 1, next, 1); n   } else { n     int next = a[cur][s[i] -  a ]; n     if (next > 0 && Search(i + 1, next, 0)) return true; n     for (int j = 0; j < 3; j++) { n       next = a[cur][j]; n       if (next == 0) continue; n       if (s[i] == j +  a ) continue; n       if (Search(i + 1, next, 1)) return true; n     } n     return false; n   } n } n int main() { n   int i, j, k, n, m; n   while (scanf( %d%d , &n, &m) == 2) { n     _size = -1; n     new_node(); n     for (i = 0; i < n; i++) { n       scanf( %s , s); n       Insert(s); n     } n     for (i = 0; i < m; i++) { n       scanf( %s , s); n       if (Search(0, 0, 0)) n         printf( YES n ); n       else n         printf( NO n ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n class Solution { n  public: n   long long minCost(int n, vector<int>& blocks, vector<int>& prices) { n     int m = prices.size(); n     vector<int> pre(n, 0); n     iota(pre.begin(), pre.end(), 0); n     if (!blocks.empty() && blocks[0] == 0) { n       return -1; n     } n     for (int i = 0, j = 0; i < n && j < blocks.size(); ++i) { n       if (i == blocks[j]) { n         pre[i] = pre[i - 1]; n         ++j; n       } n     } n     int minL = 0; n     for (int i = 0; i < blocks.size(); ++i) { n       int cnt = 1; n       while (i + 1 < blocks.size() && blocks[i + 1] == blocks[i] + 1) { n         ++i; n         ++cnt; n       } n       minL = max(minL, cnt); n     } n     long long res = LLONG_MAX; n     int minPrice = INT_MAX; n     for (int l = m; l > minL; --l) { n       if (minPrice < prices[l - 1]) { n         continue; n       } n       minPrice = prices[l - 1]; n       int cnt = 0; n       int p = 0; n       while (p < n) { n         p += l; n         ++cnt; n         if (p < n && pre[p] != p) { n           p = pre[p]; n         } n       } n       res = min(res, 1LL * cnt * prices[l - 1]); n     } n     return res == LLONG_MAX ? -1 : res; n   } n }; n int main(int argc, char** argv) { n   int n, m, k; n   scanf( %d%d%d , &n, &m, &k); n   vector<int> blocks; n   blocks.reserve(m); n   for (int i = 0, b = 0; i < m; ++i) { n     scanf( %d , &b); n     blocks.push_back(b); n   } n   vector<int> prices; n   prices.reserve(k); n   for (int i = 0, p = 0; i < k; ++i) { n     scanf( %d , &p); n     prices.push_back(p); n   } n   Solution sol; n   printf( %s n , to_string(sol.minCost(n, blocks, prices)).c_str()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1000005]; n int main() { n   string s; n   int p = 1, q = 1, ans = 0, ansCount = 1; n   a[0] = -1; n   cin >> s; n   for (int i = 0, sz = s.length(); i < sz; i++) { n     if (s[i] ==  ( ) { n       a[p] = i; n       p++; n     } else { n       p--; n       if (p == 0) { n         a[0] = i; n         p = 1, q = 1; n       } else { n         int dis = i - a[p - 1]; n         if (dis > ans) { n           ans = dis, ansCount = 1; n         } else if (dis == ans) n           ansCount++; n       } n     } n   } n   cout << ans <<     << ansCount; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, k; n vector<long long> arr; n void solve() { n   cin >> n >> m >> k; n   arr.resize(n); n   for (long long i = 0; i < n; i++) cin >> arr[i]; n   vector<long long> b; n   long long l = arr[n - 1] - arr[0]; n   ; n   for (int i = 1; i < n; i++) { n     b.push_back(arr[i] - arr[i - 1]); n   } n   sort(b.begin(), b.end()); n   long long i = b.size() - 1; n   int ctr = k - 1; n   for (; ctr > 0; i--, ctr--) { n     l -= b[i]; n     l += 1; n   } n   l++; n   cout << l << endl; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int tc; n   cin >> tc; n   for (int t = 1; t <= tc; t++) { n     int b, p, f, rsl = 0; n     int h, c; n     cin >> b >> p >> f; n     cin >> h >> c; n     b /= 2; n     if (h >= c) { n       int mbp = min(b, p); n       rsl += mbp * h; n       b -= mbp; n       rsl += min(b, f) * c; n     } else { n       int mbp = min(b, f); n       rsl += mbp * c; n       b -= mbp; n       rsl += min(b, p) * h; n     } n     cout << rsl << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int maxn = 3e5 + 5; n const long long inf = 1e18; n int ind[maxn], now, n; n using namespace std; n set<pair<int, int>> e[maxn]; n vector<long long> answers; n bool vis[maxn]; n long long dp[maxn][2]; n struct node { n   int u, val; n   inline bool operator<(const node &b) const { return val > b.val; } n }; n priority_queue<node> pq; n set<int> S; n bool cur[maxn]; n multiset<long long> q[maxn]; n long long val[maxn]; n inline void dfs(int u, int fa) { n   vis[u] = 1; n   vector<long long> vec; n   long long sum = 0; n   for (auto x : e[u]) { n     int v = x.first, w = x.second; n     if (v == fa || cur[v]) continue; n     dfs(v, u); n     sum += dp[v][1]; n     vec.push_back(dp[v][0] - dp[v][1] + w); n   } n   int cnt = 0; n   int now = ::now - (ind[u] - (int)(q[u].size()) - (int)(e[u].size())); n   auto it = q[u].end(); n   while (1) { n     if (it == q[u].begin()) break; n     it--; n     int x = *it; n     if (cnt >= (int)(e[u].size()) || cnt >= now) break; n     cnt++; n     vec.push_back(x); n   } n   sort(vec.begin(), vec.end(), greater<long long>()); n   for (int i = 0; i <= now - 2; ++i) n     if (vec[i] >= 0) dp[u][0] += vec[i]; n   dp[u][1] = dp[u][0]; n   if (now > 0 && vec[now - 1] >= 0) dp[u][1] += vec[now - 1]; n   dp[u][0] += sum, dp[u][1] += sum; n } n std::vector<long long> minimum_closure_costs(int N, std::vector<int> U, n                                              std::vector<int> V, n                                              std::vector<int> W) { n   answers.resize(N); n   n = N; n   long long nowval = 0; n   for (int i = 0; i <= N - 2; ++i) { n     U[i]++, V[i]++; n     e[U[i]].insert({V[i], W[i]}); n     e[V[i]].insert({U[i], W[i]}); n     ind[U[i]]++, ind[V[i]]++; n     nowval += W[i]; n   } n   for (int i = 1; i <= n; ++i) pq.push({i, ind[i]}); n   for (int i = 1; i <= n; ++i) S.insert(i); n   int maxind = 0; n   for (int i = 1; i <= n; ++i) maxind = max(maxind, ind[i]); n   for (int i = 0; i <= n - 1; ++i) { n     now = i; n     if (now > maxind) break; n     for (int j : S) { n       dp[j][0] = dp[j][1] = 0, vis[j] = 0; n       while ((int)(q[j].size()) > ind[j] - now && (int)(q[j].size())) { n         val[j] -= *--q[j].end(); n         nowval -= *--q[j].end(); n         q[j].erase(--q[j].end()); n       } n     } n     vector<node> tmp; n     while (!pq.empty()) { n       auto x = pq.top(); n       if (x.val <= now) { n         tmp.push_back(x); n         cur[x.u] = 1; n         for (auto it = e[x.u].begin(); it != e[x.u].end();) { n           auto xx = *it; n           it++; n           if (!cur[xx.first]) { n             e[x.u].erase(e[x.u].lower_bound({xx.first, 0})); n             e[xx.first].erase(e[xx.first].lower_bound({x.u, 0})); n             q[xx.first].insert(xx.second); n             val[xx.first] += xx.second; n           } n         } n       } else n         break; n       pq.pop(); n     } n     for (int j : S) { n       dp[j][0] = dp[j][1] = 0, vis[j] = 0; n       while ((int)(q[j].size()) > ind[j] - now && (int)(q[j].size())) { n         val[j] -= *--q[j].end(); n         nowval -= *--q[j].end(); n         q[j].erase(--q[j].end()); n       } n     } n     for (auto x : tmp) S.erase(x.u); n     now = i; n     for (int x : S) n       if (!vis[x]) dfs(x, 0), answers[i] += max(dp[x][0], dp[x][1]); n     answers[i] = nowval - answers[i]; n   } n   return answers; n } n int main() { n   int N; n   assert(1 == scanf( %d , &N)); n   std::vector<int> U(N - 1), V(N - 1), W(N - 1); n   for (int i = 0; i < N - 1; ++i) { n     assert(3 == scanf( %d %d %d , &U[i], &V[i], &W[i])); n     U[i]--, V[i]--; n   } n   std::vector<long long> closure_costs = minimum_closure_costs(N, U, V, W); n   for (int i = 0; i < static_cast<int>(closure_costs.size()); ++i) { n     if (i > 0) { n       printf(   ); n     } n     printf( %lld , closure_costs[i]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-5; n const int inf = (1 << 31) - 1; n const int hinf = 1000000000; n const int mod = 1000000007; n const int N = 3030; n int dp[3030][3030]; n int n; n int head[3030]; n int weizhi; n struct node { n   int u, v, w, next; n } point[3030 << 1]; n void add(int u, int v, int w) { n   point[weizhi].u = u; n   point[weizhi].v = v; n   point[weizhi].w = w; n   point[weizhi].next = head[u]; n   head[u] = weizhi++; n } n void dfs(int now, int par, int dp[N]) { n   dp[now] = 0; n   for (int k = head[now]; k != -1; k = point[k].next) { n     int i = point[k].v; n     if (i == par) continue; n     dfs(i, now, dp); n     dp[now] += dp[i] + point[k].w; n   } n } n void DFS(int now, int p, int a, int& ret) { n   ret = min(ret, dp[now][now] - dp[now][a]); n   for (int k = head[now]; k != -1; k = point[k].next) { n     int i = point[k].v; n     if (i == p) continue; n     DFS(i, now, a, ret); n   } n } n int main() { n   scanf( %d , &n); n   int a, b; n   memset((head), -1, sizeof(head)); n   weizhi = 0; n   for (int i = 1; i < n; i++) { n     scanf( %d%d , &a, &b); n     add(a, b, 0); n     add(b, a, 1); n   } n   memset(dp, 0, sizeof(dp)); n   if (n == 1) { n     cout << 0 << endl; n     return 0; n   } n   for (int i = 1; i <= n; i++) { n     dfs(i, -1, dp[i]); n   } n   int ans = inf; n   for (int u = 1; u <= n; u++) { n     for (int k = head[u]; k != -1; k = point[k].next) { n       int i = point[k].v; n       int w = point[k].w; n       if (w) continue; n       int ret1 = inf; n       int ret2 = inf; n       DFS(i, u, u, ret1); n       DFS(u, i, i, ret2); n       ans = min(ans, ret1 + ret2 - 1); n     } n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std::chrono; n template <typename A> n ostream &operator<<(ostream &cout, vector<A> const &v); n template <typename A, typename B> n ostream &operator<<(ostream &cout, pair<A, B> const &p) { n   return cout <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <typename A> n ostream &operator<<(ostream &cout, vector<A> const &v) { n   cout <<  [ ; n   for (int i = 0; i < v.size(); i++) { n     if (i) cout <<  ,  ; n     cout << v[i]; n   } n   return cout <<  ] ; n } n template <typename A, typename B> n istream &operator>>(istream &cin, pair<A, B> &p) { n   cin >> p.first; n   return cin >> p.second; n } n mt19937 rng(steady_clock::now().time_since_epoch().count()); n void usaco(string filename) { n   freopen((filename +  .in ).c_str(),  r , stdin); n   freopen((filename +  .out ).c_str(),  w , stdout); n } n const long double pi = 3.14159265358979323846; n const long long mod = 1000000007; n long long n, m, k, q, Q, T, l, r, x, y, z; n long long c[1000005]; n string second, t; n long long ans = 0; n int pt, a, b; n int query(int a, int b) { n   cout <<  ?   << a <<     << b << endl; n   cin >> x; n   return x; n } n void getZero() { n   if (pt < 0) { n     cout <<  !   << a <<     << b << endl; n     exit(0); n   } n   b ^= (1 << pt); n   x = query(a, b); n   if (x == 1) n     a ^= (1 << pt); n   else n     b ^= (1 << pt); n   --pt; n   getZero(); n } n int main() { n   { n     ios_base::sync_with_stdio(false); n     cin.tie(NULL); n     cout.tie(NULL); n   }; n   pt = 29; n   a = b = 0; n   int cache = -2; n   while (pt >= 0) { n     int x, y; n     if (cache == -2) { n       x = query(a, b); n     } else n       x = cache; n     if (x == 0) getZero(); n     a ^= (1 << pt); n     b ^= (1 << pt); n     y = query(a, b); n     if (x == y) n       cache = x; n     else n       cache = -2; n     if (x == y) { n       a ^= (1 << pt); n       z = query(a, b); n       if (z == 1) n         a ^= (1 << pt); n       else n         b ^= (1 << pt); n     } else { n       if (x > y) n         b ^= (1 << pt); n       else n         a ^= (1 << pt); n     } n     --pt; n   } n   cout <<  !   << a <<     << b << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long f[20][55][2600], c[20]; n long long l[5005], tot = 0; n void Turn(long long k) { n   memset(c, 0, sizeof(c)); n   while (k) c[++c[0]] = k % 10, k /= 10; n   return; n } n int gcd(int x, int y) { return x % y ? gcd(y, x % y) : y; } n long long Search(int x, int lcm, int num, bool flag) { n   if (!x && num % lcm == 0) n     return 1; n   else if (!x) n     return 0; n   if (!flag && ~f[x][l[lcm]][num]) return f[x][l[lcm]][num]; n   int k = flag ? c[x] : 9; n   long long s = 0; n   for (int i = 0; i <= k; i++) { n     s += Search(x - 1, i ? lcm * i / gcd(lcm, i) : lcm, (num * 10 + i) % 2520, n                 flag && i == k); n   } n   if (!flag) f[x][l[lcm]][num] = s; n   return s; n } n long long Calc(long long k) { n   Turn(k); n   return Search(c[0], 1, 0, 1); n } n int main() { n   for (int i = 1; i <= 2520; i++) n     if (2520 % i == 0) l[i] = ++tot; n   memset(f, -1, sizeof(f)); n   long long x, y; n   int T; n   cin >> T; n   while (T--) { n     cin >> x >> y; n     cout << Calc(y) - Calc(x - 1) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e5 + 100, INF = 1e9; n struct edge { n   long long to, cost, id; n }; n vector<edge> g[N]; n long long d[N], cost[N], path[N], used[N]; n pair<long long, long long> from[N]; n long long n, m; n void bfs() { n   fill(d, d + n, INF); n   d[0] = 0; n   queue<long long> q; n   q.push(0); n   while ((long long)q.size()) { n     long long v = q.front(); n     q.pop(); n     if (used[v]) continue; n     used[v] = 1; n     for (auto i : g[v]) { n       long long u = i.to; n       long long c = cost[v] + i.cost; n       if (d[v] + 1 < d[u] || (d[v] + 1 == d[u] && c < cost[u])) { n         d[u] = d[v] + 1; n         from[u] = {v, i.id}; n         cost[u] = c; n         q.push(u); n       } n     } n   } n   long long v = n - 1; n   while (v != 0) { n     long long id = from[v].second; n     path[id] = 1; n     v = from[v].first; n   } n } n signed main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n >> m; n   vector<pair<pair<long long, long long>, long long>> ed(m); n   for (long long i = 0; i < m; i++) { n     long long a, b, c; n     cin >> a >> b >> c; n     a--; n     b--; n     ed[i] = {{a, b}, c}; n     c ^= 1; n     g[a].push_back({b, c, i}); n     g[b].push_back({a, c, i}); n   } n   bfs(); n   long long ans = 0; n   for (long long i = 0; i < m; i++) { n     if (path[i] && ed[i].second == 0 || (!path[i] && ed[i].second == 1)) ans++; n   } n   cout << ans <<   n ; n   for (long long i = 0; i < m; i++) { n     if (path[i] && ed[i].second == 0 || (!path[i] && ed[i].second == 1)) n       cout << ed[i].first.first + 1 <<     << ed[i].first.second + 1 <<     n            << (ed[i].second ^ 1) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000010; n const int mod = 1e9 + 7; n int t[N], dp[2][3][3]; n int main() { n   int n, K; n   scanf( %d%d , &n, &K); n   for (int i = 1; i <= n; i++) { n     int x; n     scanf( %d , &x); n     t[x]++; n   } n   int cur = 1, pre = 0; n   for (int i = 1; i <= K; i++) { n     memset(dp[cur], 0, sizeof(dp[cur])); n     for (int j = 0; j < 3; j++) n       for (int k = 0; k < 3; k++) n         for (int l = 0; l < 3; l++) n           if (j + k + l <= t[i]) n             dp[cur][k][l] = n                 max(dp[cur][k][l], dp[pre][j][k] + l + (t[i] - j - k - l) / 3); n     swap(cur, pre); n   } n   printf( %d n , dp[pre][0][0]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int MOD = 1e9 + 7; n long long int INF = 1e18; n long long int sub(long long int a, long long int b, long long int p = MOD) { n   return ((a % p) - (b % p) + p) % p; n } n long long int mult(long long int a, long long int b, long long int p = MOD) { n   return ((a % p) * (b % p)) % p; n } n long long int add(long long int a, long long int b, long long int p = MOD) { n   return (a % p + b % p) % p; n } n long long int fpow(long long int n, long long int k, long long int p = MOD) { n   long long int r = 1; n   while (k > 0) { n     if (k & 1) r = r * n % p; n     n = n * n % p; n     k = k >> 1; n   } n   return r; n } n long long int inv(long long int a, long long int p = MOD) { n   return fpow(a, p - 2, p); n } n long long int power(long long int a, long long int b) { n   long long int ans = 1; n   long long int i; n   for (i = 1; i < b + 1; i++) { n     ans *= a; n   } n   return ans; n } n long long int fdiv(long long int a, long long int b, long long int p = MOD) { n   long long int yinv = inv(b); n   long long int ans = (a * yinv) % p; n   return ans; n } n unsigned long long int I1018 = 1000000000000000000; n const unsigned long long int I10e5 = 100000; n const long long int I10e6 = 1e6; n template <typename T> n istream &operator>>(istream &in, vector<T> &a) { n   for (auto &item : a) { n     in >> item; n   } n   return in; n } n template <typename T, typename U> n ostream &operator<<(ostream &out, pair<T, U> &a) { n   cout << a.first <<     << a.second; n   return out; n } n template <typename T, typename U> n istream &operator>>(istream &out, pair<T, U> &a) { n   cin >> a.first >> a.second; n   return out; n } n template <typename T, typename U> n ostream &operator<<(ostream &out, map<T, U> &a) { n   for (auto &item : a) { n     out << item << endl; n   } n   return out; n } n template <typename T> n ostream &operator<<(ostream &out, vector<T> &a) { n   for (auto &item : a) { n     out << item <<    ; n   } n   return out; n } n template <typename T> n ostream &operator<<(ostream &out, vector<vector<T>> &a) { n   for (auto &item : a) { n     out << item <<   n ; n   } n   return out; n } n std::vector<bool> is_prime; n std::vector<long long int> primes; n void sieve(long long int n) { n   is_prime.resize(n + 2, true); n   primes.clear(); n   long long int p; n   for (p = 2; p * p <= n; p++) { n     if (is_prime[p]) { n       long long int i; n       for (i = p * p; i <= n; i += p) { n         is_prime[i] = false; n       } n     } n   } n   is_prime[0] = is_prime[1] = false; n   long long int i; n   for (i = 2; i <= n; i++) { n     if (is_prime[i]) { n       primes.emplace_back(i); n     } n   } n } n map<long long int, long long int> prime_factors(long long int n) { n   map<long long int, long long int> s; n   long long int i; n   long long int tc = 0; n   while (n % 2 == 0) { n     tc++; n     n /= 2; n   } n   if (tc > 0) { n     s[2] = tc; n   } n   for (i = 3; i <= sqrt(n); i += 2) { n     tc = 0; n     while (n % i == 0) { n       tc++; n       n /= i; n     } n     if (tc > 0) { n       s[i] = tc; n     } n   } n   if (n > 2) { n     s[n] += 1; n   } n   return s; n } n std::vector<long long int> fact_vec; n void fact_fun(long long int n) { n   fact_vec.resize(n + 10); n   long long int i; n   fact_vec[0] = 1; n   for (i = 1; i <= n + 2; i++) { n     fact_vec[i] = (fact_vec[i - 1] * i) % MOD; n   } n } n long long int npr(long long int n, long long int r) { n   long long int ans = fact_vec[n]; n   ans /= fact_vec[n - r]; n   return ans; n } n long long int ncr(long long int n, long long int r) { n   long long int ans = fact_vec[n]; n   ans = fdiv(ans, fact_vec[n - r]); n   ans = fdiv(ans, fact_vec[r]); n   return ans; n } n long long int nc2(long long int n) { return (n * (n - 1)) / 2; } n int main() { n   long long int i, j; n   ios::sync_with_stdio(false); n   cin.tie(0); n   string s; n   cin >> s; n   long long int n = s.length(); n   std::vector<long long int> cnt(n + 10, 0); n   for (i = 0; i < n; i++) { n     cnt[i + 1] = cnt[i] + ((s[i] >=  A  && s[i] <=  Z ) ? 1 : 0); n   } n   long long int ans = INF; n   for (i = 0; i < n + 1; i++) { n     long long int left = i - cnt[i]; n     long long int right = cnt[n] - cnt[i]; n     ans = min(ans, left + right); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000005; n const long long MOD = 1000000007; n long long k, w, ans; n long long fac[MAXN]; n long long inv[MAXN]; n long long power(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b & 1) (res *= a) %= MOD; n     (a *= a) %= MOD; n     b >>= 1; n   } n   return res; n } n void init() { n   fac[0] = 1; n   for (int i = 1; i <= k; i++) fac[i] = fac[i - 1] * i % MOD; n   inv[k] = power(fac[k], MOD - 2); n   for (int i = k; i >= 1; i--) inv[i - 1] = inv[i] * i % MOD; n } n int main() { n   cin >> k >> w; n   init(); n   for (int i = 1; i <= k; i++) { n     if (i <= w - 1) n       (ans += i * fac[k] % MOD * fac[k] % MOD * power(k, w - i - 1) % MOD * n               inv[k - i] % MOD * inv[k - i]) %= MOD; n     else n       (ans += w * fac[k] % MOD * fac[k - i + w - 1] % MOD * inv[k - i] % MOD * n               inv[k - i] % MOD) %= MOD; n     if (i < k) { n       if (i + 1 <= w - 1) n         (ans += i * fac[k] % MOD * fac[k] % MOD * power(k, w - i - 2) % MOD * n                 inv[k - i] % MOD * inv[k - i - 1]) %= MOD; n       else n         (ans += (w - 1) * fac[k] % MOD * fac[k - i + w - 2] % MOD * inv[k - i] % n                 MOD * inv[k - i - 1]) %= MOD; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1000000007; n const double sn = 1e-9; n const long double PI = 3.141592653589793238L; n int n, c, d; n int mc[100005]; n int md[100005]; n vector<pair<int, int>> ac; n vector<pair<int, int>> ad; n bool cmp(pair<int, int> p1, pair<int, int> p2) { return p1.first > p2.first; } n int check(int l, int r, vector<pair<int, int>> &arr, int v) { n   while (l != r) { n     int mid = (l + r) / 2; n     if (arr[mid].first <= v) n       r = mid; n     else n       l = mid + 1; n   } n   return l; n } n int main() { n   scanf( %d%d%d , &n, &c, &d); n   for (int i = 0; i < n; i++) { n     int b, p; n     char t[5]; n     scanf( %d%d%s , &b, &p, t); n     if (t[0] ==  C ) { n       ac.push_back(make_pair(p, b)); n     } else { n       ad.push_back(make_pair(p, b)); n     } n   } n   sort(ac.begin(), ac.end(), cmp); n   sort(ad.begin(), ad.end(), cmp); n   int sz1 = ac.size(), sz2 = ad.size(); n   if (sz1 != 0) { n     mc[sz1 - 1] = ac[sz1 - 1].second; n     for (int i = sz1 - 2; i >= 0; i--) mc[i] = max(ac[i].second, mc[i + 1]); n   } n   if (sz2 != 0) { n     md[sz2 - 1] = ad[sz2 - 1].second; n     for (int i = sz2 - 2; i >= 0; i--) md[i] = max(ad[i].second, md[i + 1]); n   } n   int abc = check(0, sz1, ac, c), abd = check(0, sz2, ad, d); n   int mh = INT_MIN; n   if (abc != sz1 && abd != sz2) { n     mh = max(mh, mc[abc] + md[abd]); n   } n   for (int i = 0; i < sz1; i++) { n     if (ac[i].first > c) continue; n     int v = check(i + 1, sz1, ac, c - ac[i].first); n     if (v != sz1) { n       mh = max(mh, mc[v] + ac[i].second); n     } n   } n   for (int i = 0; i < sz2; i++) { n     if (ad[i].first > d) continue; n     int v = check(i + 1, sz2, ad, d - ad[i].first); n     if (v != sz2) { n       mh = max(mh, md[v] + ad[i].second); n     } n   } n   printf( %d n , max(mh, 0)); n   return 0; n } n


#include <bits/stdc++.h> n  n using namespace std; n  n #define FOR(n) for(int i = 0; i < int(n); ++i) n #define RFOR(n) for(int i = n; ~i; --i) n  n int gcd(int a, int b) { n     if(b == 0) n         return a; n     return gcd(b, a % b); n } n  n void solve() { n     int n; n     cin >> n; n     map<pair<int, int>, int> mp; n     long long ans = 0; n     FOR(n) { n         int x, y, u, v; n         cin >> x >> y >> u >> v; n         x -= u; n         y -= v; n         int g = gcd(abs(x), abs(y)); n         x /= g; n         y /= g; n         mp[{x, y}]++; n         ans += mp[{-x, -y}]; n     } n     cout << ans <<   n ; n } n  n int main(int argc, char* argv[]) { n     ios::sync_with_stdio(false); n     cin.tie(nullptr); n      n     int testCase = 1; n     cin >> testCase; n     for(int t = 0; t < testCase; ++t)  n        solve(); n  n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n vector<vector<int> > edges(2e5 + 5); n bool vis[200005]; n int lev[200005]; n int n, m, a, b, mx; n void bfs(int node) { n   int level = 0; n   deque<pair<int, int> > dq; n   dq.push_back({level, node}); n   vis[node] = 1; n   while (!dq.empty()) { n     node = dq.front().second, level = dq.front().first; n     lev[node] = level; n     dq.pop_front(); n     for (auto i : edges[node]) n       if (!vis[i]) dq.push_back({level + 1, i}), vis[node] = 1; n   } n   memset(vis, 0, sizeof vis), a = 0; n } n void dfs(int node) { n   if (a >= lev[node]) return; n   vis[node] = 1; n   mx = max(mx, lev[node]); n   for (auto i : edges[node]) n     if (!vis[i]) a++, dfs(i), a--; n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n >> m; n   for (int i = 1; i < n; i++) n     cin >> a >> b, edges[a].push_back(b), edges[b].push_back(a); n   bfs(1); n   dfs(m); n   cout << mx * 2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int d, n, m; n int cntl[100011], cntr[100011], cntt[100011], cntb[100011]; n struct Sofa { n   int x1, y1, x2, y2; n } sofa[100011]; n int main() { n   scanf( %d , &d); n   scanf( %d %d , &n, &m); n   for (int i = 0; i < d; i++) { n     int x1, y1, x2, y2; n     scanf( %d %d %d %d , &x1, &y1, &x2, &y2); n     cntl[min(x1, x2)]++; n     cntr[max(x1, x2)]++; n     cntt[min(y1, y2)]++; n     cntb[max(y1, y2)]++; n     sofa[i].x1 = x1; n     sofa[i].y1 = y1; n     sofa[i].x2 = x2; n     sofa[i].y2 = y2; n   } n   for (int i = 1; i <= n; i++) cntl[i] += cntl[i - 1]; n   for (int i = n; i >= 0; i--) cntr[i] += cntr[i + 1]; n   for (int i = 1; i <= m; i++) cntt[i] += cntt[i - 1]; n   for (int i = m; i >= 0; i--) cntb[i] += cntb[i + 1]; n   int tl, tr, tt, tb; n   scanf( %d %d %d %d , &tl, &tr, &tt, &tb); n   for (int i = 0; i < d; i++) { n     int tmpl = cntl[max(sofa[i].x1, sofa[i].x2) - 1], n         tmpr = cntr[min(sofa[i].x1, sofa[i].x2) + 1], n         tmpt = cntt[max(sofa[i].y1, sofa[i].y2) - 1], n         tmpb = cntb[min(sofa[i].y1, sofa[i].y2) + 1]; n     if (max(sofa[i].x1, sofa[i].x2) != min(sofa[i].x1, sofa[i].x2)) { n       tmpl--; n       tmpr--; n     } n     if (max(sofa[i].y1, sofa[i].y2) != min(sofa[i].y1, sofa[i].y2)) { n       tmpt--; n       tmpb--; n     } n     if (tmpl == tl && tmpr == tr && tmpt == tt && tmpb == tb) { n       cout << i + 1; n       return 0; n     } n   } n   cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   long long int n; n   long long int x; n   long long int y; n   long long int number; n   scanf( %I64d %I64d %I64d , &n, &x, &y); n   number = y - (n - 1); n   while (true) { n     if (number <= 0) { n       printf( -1 n ); n       break; n     } n     if (number * number + n - 1 >= x) { n       printf( %I64d n , number); n       for (int i = 0; i < n - 1; i++) { n         printf( 1 n ); n       } n       break; n     } n     number--; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n constexpr long long ROWS = 2; n constexpr long long NMAX = 1e5; n long long h[ROWS][NMAX]; n long long dp[ROWS][NMAX]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long COLS; n   cin >> COLS; n   for (long long i = 0; i < ROWS; ++i) n     for (long long j = 0; j < COLS; ++j) cin >> h[i][j]; n   for (long long j = COLS - 1; j >= 0; --j) n     for (long long i = ROWS - 1; i >= 0; --i) { n       if (j == COLS - 1) n         dp[i][j] = h[i][j]; n       else if (j == COLS - 2) n         dp[i][j] = h[i][j] + h[i == 0 ? 1 : 0][j + 1]; n       else n         dp[i][j] = n             h[i][j] + max(dp[i == 0 ? 1 : 0][j + 1], dp[i == 0 ? 1 : 0][j + 2]); n     } n   cout << max(dp[0][0], dp[1][0]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ans = 0; n long long mod = 1e9 + 7; n int cnt[100005], Tcnt[100005], arr[100005]; n vector<int> pri; n void era() { n   pri.push_back(2); n   for (int i = 3; i <= 100000; i += 2) { n     if (!arr[i]) n       for (long long j = (long long)i * i; j <= 100000; j += i) { n         arr[j] = 1; n       } n   } n   for (int i = 3; i <= 100000; i += 2) { n     if (arr[i] == 0) pri.push_back(i); n   } n } n int GGG(int p) { n   int ret = 0; n   for (int i = 0; i < pri.size(); i++) { n     if (pri[i] > p) break; n     int cnt = 0; n     while (p % pri[i] == 0) { n       p /= pri[i]; n       ++cnt; n     } n     if (cnt >= 2) return -1; n     if (cnt != 0) ret++; n   } n   return ret; n } n long long po(int k) { n   if (k == 0) return 1; n   if (k == 1) return 2; n   long long ret = po(k / 2); n   ret = ret * ret % mod; n   if (k & 1) ret = ret * 2 % mod; n   return ret; n } n int main() { n   era(); n   int n; n   scanf( %d , &n); n   for (int t, i = 1; i <= n; i++) { n     scanf( %d , &t); n     cnt[t]++; n   } n   for (int i = 2; i <= 100000; i++) { n     for (int j = i; j <= 100000; j += i) { n       Tcnt[i] += cnt[j]; n     } n   } n   ans += po(n) - 1; n   for (int i = 2; i <= 100000; i++) { n     if (Tcnt[i] == 0) continue; n     int Gcnt = GGG(i); n     if (Gcnt == -1) continue; n     if (Gcnt % 2 == 0) { n       ans += po(Tcnt[i]) - 1; n       ans %= mod; n     } else { n       ans -= po(Tcnt[i]) - 1; n       while (ans < 0) ans += mod; n     } n   } n   printf( %I64d , ans); n } n


#include <bits/stdc++.h> n const long long MaxN = 205; n const long long lim = 1e18 + 5; n template <class t> n inline void read(t &s) { n   s = 0; n   register long long f = 1; n   register char c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar(); n   s *= f; n   return; n } n template <class t, class... A> n inline void read(t &x, A &...a) { n   read(x); n   read(a...); n } n template <class t> n inline void write(t x) { n   if (x < 0) putchar( - ), x = -x; n   long long buf[21], top = 0; n   while (x) buf[++top] = x % 10, x /= 10; n   if (!top) buf[++top] = 0; n   while (top) putchar(buf[top--] ^  0 ); n   return; n } n inline void setIn(std::string s) { n   freopen(s.c_str(),  r , stdin); n   return; n } n inline void setOut(std::string s) { n   freopen(s.c_str(),  w , stdout); n   return; n } n inline void setIO(std::string s =   ) { n   setIn(s +  .in ); n   setOut(s +  .out ); n   return; n } n template <class t> n inline bool checkmin(t &x, t y) { n   if (x > y) { n     x = y; n     return 1; n   } n   return 0; n } n template <class t> n inline bool checkmax(t &x, t y) { n   if (x < y) { n     x = y; n     return 1; n   } n   return 0; n } n inline long long lowbit(long long x) { return x & (-x); } n long long a[MaxN][MaxN], p[MaxN], t[MaxN], n, m, K, q; n long long b[MaxN], f[MaxN][MaxN]; n inline void add(long long &x, long long y) { (x += y) >= lim && (x = lim); } n inline long long calc() { n   std::memset(f, 0, sizeof f); n   f[0][0] = 1; n   for (long long i = 1; i <= q; ++i) { n     if (b[i] >= 0) n       for (long long j = 1; j <= q; ++j) add(f[i][j], f[i - 1][j - 1]); n     if (b[i] <= 0) n       for (long long j = 0; j < q; ++j) add(f[i][j], f[i - 1][j + 1]); n   } n   return f[q][0]; n } n signed main(void) { n   read(n, m, K); n   for (long long i = 1; i <= n; ++i) n     for (long long j = 1; j <= m; ++j) read(a[i][j]); n   { n     std::vector<std::pair<long long, long long> > dr; n     for (long long i = 1; i <= n; ++i) n       for (long long j = 1; j <= m; ++j) n         dr.push_back(std::make_pair(a[i][j], i + j - 1)); n     std::sort((dr).begin(), (dr).end()); n     register long long cnt = 0; n     for (auto i : dr) n       if (!p[i.second]) p[i.second] = ++cnt; n     for (long long i = 1; i <= cnt; ++i) t[p[i]] = i; n     for (long long i = 1; i <= cnt; ++i) p[i] = t[i]; n   } n   q = n + m - 1; n   register long long sum = 0; n   for (long long i = 1; i <= q; ++i) { n     b[p[i]] = 1; n     register long long t = calc(); n     if (sum + t >= K) continue; n     b[p[i]] = -1; n     sum += t; n   } n   for (long long i = 1; i <= n; ++i, std::puts(  )) n     for (long long j = 1; j <= m; ++j) n       std::putchar(b[i + j - 1] > 0 ?  (  :  ) ); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:16777216 ) n using namespace std; n const double eps = 1e-9; n const double pi = acos(-1.0); n const int mod = (int)1e9 + 7; n const int maxn = (int)1e5 + 10; n int pp[4 * maxn]; n int a[maxn], c[6][6], pw[maxn][6], pref[maxn][6]; n struct node { n   int cnt; n   int sum[6]; n   node() { n     cnt = 0; n     memset(sum, 0, sizeof(sum)); n   } n   node(int cntt) { n     cnt = cntt; n     memset(sum, 0, sizeof(sum)); n   } n } t[4 * maxn]; n void push(int idx, int l, int m, int r) { n   if (pp[idx] != -1) { n     pp[2 * idx] = pp[idx]; n     pp[2 * idx + 1] = pp[idx]; n     for (int i = 0; i <= 5; i++) { n       t[2 * idx].sum[i] = (long long)pref[m - l + 1][i] * pp[idx] % mod; n       t[2 * idx + 1].sum[i] = (long long)pref[r - m][i] * pp[idx] % mod; n     } n     pp[idx] = -1; n   } n } n void make(int idx) { n   t[idx].cnt = t[2 * idx].cnt + t[2 * idx + 1].cnt; n   for (int i = 0; i <= 5; i++) { n     t[idx].sum[i] = t[2 * idx].sum[i]; n     for (int j = i; j >= 0; j--) { n       t[idx].sum[i] += n           (long long)((long long)t[2 * idx + 1].sum[i - j] * c[i][j] % mod) * n           pw[t[2 * idx].cnt][j] % mod; n       t[idx].sum[i] %= mod; n     } n   } n } n void build(int l, int r, int idx) { n   if (l == r) { n     t[idx].cnt = 1; n     for (int i = 0; i <= 5; i++) { n       t[idx].sum[i] = a[l]; n     } n   } else { n     int m = (l + r) >> 1; n     build(l, m, 2 * idx); n     build(m + 1, r, 2 * idx + 1); n     make(idx); n   } n } n void put(int l, int r, int a, int b, int val, int idx) { n   if (b < l || r < a) return; n   if (a <= l && r <= b) { n     pp[idx] = val; n     for (int i = 0; i <= 5; i++) { n       t[idx].sum[i] = (long long)pref[r - l + 1][i] * val % mod; n     } n   } else { n     int m = (l + r) >> 1; n     push(idx, l, m, r); n     put(l, m, a, b, val, 2 * idx); n     put(m + 1, r, a, b, val, 2 * idx + 1); n     make(idx); n   } n } n node make(node lf, node rg) { n   if (lf.cnt == 0) return rg; n   if (rg.cnt == 0) return lf; n   node res = lf; n   res.cnt += rg.cnt; n   for (int i = 0; i <= 5; i++) { n     for (int j = i; j >= 0; j--) { n       res.sum[i] += (long long)((long long)rg.sum[i - j] * c[i][j] % mod) * n                     pw[lf.cnt][j] % mod; n       res.sum[i] %= mod; n     } n   } n   return res; n } n node get(int l, int r, int a, int b, int idx) { n   if (b < l || r < a) return node(0); n   if (a <= l && r <= b) return t[idx]; n   int m = (l + r) >> 1; n   push(idx, l, m, r); n   node lf = get(l, m, a, b, 2 * idx); n   node rg = get(m + 1, r, a, b, 2 * idx + 1); n   return make(lf, rg); n } n int main() { n   memset(pp, -1, sizeof(pp)); n   for (int i = 1; i < maxn; i++) { n     pw[i][0] = 1; n     for (int j = 1; j <= 5; j++) { n       pw[i][j] = (long long)pw[i][j - 1] * i % mod; n     } n     for (int j = 0; j <= 5; j++) { n       pref[i][j] = pref[i - 1][j] + pw[i][j]; n       pref[i][j] %= mod; n     } n   } n   for (int i = 0; i <= 5; i++) { n     c[i][0] = 1; n   } n   for (int i = 1; i <= 5; i++) { n     for (int j = 1; j <= i; j++) { n       c[i][j] = c[i - 1][j] + c[i - 1][j - 1]; n     } n   } n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   build(0, n - 1, 1); n   int l, r, x; n   char s[11]; n   for (int i = 0; i < m; i++) { n     scanf( %s%d%d%d , s, &l, &r, &x); n     --l; n     --r; n     if (s[0] ==  = ) { n       put(0, n - 1, l, r, x, 1); n     } else { n       printf( %d n , get(0, n - 1, l, r, 1).sum[x]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 6e5 + 20; n int main() { n   int n, filas, columnas; n   cin >> n; n   while (n--) { n     cin >> filas >> columnas; n     int arr[300][300] = {0}; n     bool ya = false; n     for (int i = 0; i < filas; i++) { n       for (int j = 0; j < columnas; j++) { n         cin >> arr[i][j]; n         if (arr[i][j] > 4) n           ya = true; n         else if ((i == 0 && j == 0) || (i == 0 && j == columnas - 1) || n                  (i == filas - 1 && j == 0) || n                  (i == filas - 1 && j == columnas - 1)) { n           if (arr[i][j] > 2) ya = true; n         } else if (i == 0 || i == filas - 1 || j == 0 || j == columnas - 1) { n           if (arr[i][j] > 3) ya = true; n         } n       } n     } n     if (ya) n       cout <<  NO  << endl; n     else { n       cout <<  YES  << endl; n       for (int i = 0; i < filas; i++) { n         for (int j = 0; j < columnas; j++) { n           if ((i == 0 && j == 0) || (i == 0 && j == columnas - 1) || n               (i == filas - 1 && j == 0) || n               (i == filas - 1 && j == columnas - 1)) n             cout << 2 <<    ; n           else if (i == 0 || i == filas - 1 || j == 0 || j == columnas - 1) n             cout << 3 <<    ; n           else n             cout << 4 <<    ; n         } n         cout << endl; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n char str[100010]; n int f[100010][26 + 2], pre[100010][26], suf[100010][26], g[100010], n; n int ans[26 + 2]; n int dfs(int l, int r, int c, int fl) { n   if (l > r) return 0; n   if (ans[c] != -1) return ans[c]; n   int u = 0; n   for (int i = 0; i < 26; i++) { n     int L = suf[l][i], R = pre[r][i]; n     if (R < l) continue; n     int s = g[L] ^ g[R]; n     if (!fl) n       s ^= f[L - 1][c] ^ dfs(R + 1, r, i, 0); n     else n       s ^= dfs(l, L - 1, i, 1) ^ f[r][i]; n     u |= 1 << s; n   } n   return ans[c] = __builtin_ctz(~u); n } n int main() { n   scanf( %s , str + 1); n   n = strlen(str + 1); n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < 26; j++) pre[i][j] = pre[i - 1][j]; n     pre[i][str[i] -  a ] = i; n   } n   for (int i = 0; i < 26; i++) suf[n + 1][i] = n + 1; n   for (int i = n; i >= 1; i--) { n     for (int j = 0; j < 26; j++) suf[i][j] = suf[i + 1][j]; n     suf[i][str[i] -  a ] = i; n   } n   for (int i = 1; i <= n; i++) { n     int c = str[i] -  a ; n     g[i] = f[i - 1][c] ^ g[pre[i - 1][c]]; n     memset(ans, -1, sizeof(ans)); n     for (int j = 0; j < 26; j++) f[i][j] = dfs(pre[i][j] + 1, i, j, 0); n   } n   int m; n   scanf( %d , &m); n   while (m-- > 0) { n     int l, r; n     scanf( %d%d , &l, &r); n     memset(ans, -1, sizeof(ans)); n     if (dfs(l, r, 26, 1)) n       puts( Alice ); n     else n       puts( Bob ); n   } n } n


#include <bits/stdc++.h> n namespace ZDY { n #pragma GCC optimize(3) n template <class T> n __inline__ __attribute__((always_inline)) T ABS(T x) { n   return x > 0 ? x : -x; n } n template <class T> n __inline__ __attribute__((always_inline)) T MAX(T x, T y) { n   return x > y ? x : y; n } n template <class T> n __inline__ __attribute__((always_inline)) T MIN(T x, T y) { n   return x < y ? x : y; n } n template <class T> n __inline__ __attribute__((always_inline)) T GCD(T x, T y) { n   return y ? GCD(y, x % y) : x; n } n template <class T> n __inline__ __attribute__((always_inline)) void SWAP(T &x, T &y) { n   T t = x; n   x = y; n   y = t; n } n }  // namespace ZDY n using namespace ZDY; n using namespace std; n namespace IO { n const int str = 1 << 20; n static char in_buf[str], *in_s, *in_t; n bool __ = 0; n __inline__ __attribute__((always_inline)) char gc() { n   return (in_s == in_t) && n              (in_t = (in_s = in_buf) + fread(in_buf, 1, str, stdin)), n          in_s == in_t ? EOF : *in_s++; n } n __inline__ __attribute__((always_inline)) void in(string &ch) { n   ch.clear(); n   if (__) return; n   char c; n   while ((c = gc()) != EOF && isspace(c)) n     ; n   if (c == EOF) { n     __ = 1; n     return; n   } n   ch += c; n   while ((c = gc()) != EOF && !isspace(c)) ch += c; n   if (c == EOF) __ = 1; n } n __inline__ __attribute__((always_inline)) void in(char &ch) { n   if (__) return; n   char c; n   while ((c = gc()) != EOF && isspace(c)) n     ; n   if (c == EOF) n     __ = 1; n   else n     ch = c; n } n __inline__ __attribute__((always_inline)) void in(char *ch) { n   *ch =   0 ; n   if (__) return; n   char c; n   while ((c = gc()) != EOF && isspace(c)) n     ; n   if (c == EOF) { n     __ = 1; n     return; n   } n   *ch = c; n   ch++; n   while ((c = gc()) != EOF && !isspace(c)) *ch = c, ch++; n   if (c == EOF) __ = 1; n   *ch =   0 ; n } n template <typename T> n __inline__ __attribute__((always_inline)) void in(T &x) { n   if (__) return; n   char c = gc(); n   bool f = 0; n   while (c != EOF && (c <  0  || c >  9 )) f ^= (c ==  - ), c = gc(); n   if (c == EOF) { n     __ = 1; n     return; n   } n   x = 0; n   while (c != EOF &&  0  <= c && c <=  9 ) x = x * 10 + c - 48, c = gc(); n   if (c == EOF) __ = 1; n   if (f) x = -x; n } n template <typename T, typename... arr> n __inline__ __attribute__((always_inline)) void in(T &x, arr &...y) { n   in(x), in(y...); n } n const char ln =   n ; n static char out_buf[str], *out_s = out_buf, *out_t = out_buf + str; n __inline__ __attribute__((always_inline)) void flush() { n   fwrite(out_buf, 1, out_s - out_buf, stdout); n   out_s = out_buf; n } n __inline__ __attribute__((always_inline)) void pt(char c) { n   (out_s == out_t) ? (fwrite(out_s = out_buf, 1, str, stdout), *out_s++ = c) n                    : (*out_s++ = c); n } n __inline__ __attribute__((always_inline)) void out(const char *s) { n   while (*s) pt(*s++); n } n __inline__ __attribute__((always_inline)) void out(char *s) { n   while (*s) pt(*s++); n } n __inline__ __attribute__((always_inline)) void out(char c) { pt(c); } n __inline__ __attribute__((always_inline)) void out(string s) { n   for (int i = 0; s[i]; i++) pt(s[i]); n } n template <typename T> n __inline__ __attribute__((always_inline)) void out(T x) { n   if (!x) { n     pt( 0 ); n     return; n   } n   if (x < 0) pt( - ), x = -x; n   char a[50], t = 0; n   while (x) a[t++] = x % 10, x /= 10; n   while (t--) pt(a[t] +  0 ); n } n template <typename T, typename... arr> n __inline__ __attribute__((always_inline)) void out(T x, arr &...y) { n   out(x), out(y...); n } n }  // namespace IO n using namespace IO; n int n, head[1000011], cnt = 0, a[1000011]; n struct edge { n   int to, nxt; n } e[1000011 * 2]; n __inline__ __attribute__((always_inline)) void add(int x, int y) { n   e[++cnt].to = y; n   e[cnt].nxt = head[x]; n   head[x] = cnt; n } n void dfs(int x, int d) { n   a[x] = d; n   for (int i(head[x]), to; to = e[i].to, i; i = e[i].nxt) n     if (!a[to]) dfs(to, MIN(d, to)); n } n int main() { n   int q, opt, x, y, la = 0, tt = 2122219134; n   in(n, q); n   for (int i(1); i <= n - 1; ++i) in(x, y), add(x, y), add(y, x); n   in(y, x); n   x = x % n + 1; n   dfs(x, x); n   while (--q) { n     in(opt, x); n     x = (la + x) % n + 1; n     if (opt == 1) n       tt = MIN(tt, a[x]); n     else n       out(la = MIN(tt, a[x]), ln); n   } n   flush(); n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n char dis[2000010]; n int a[2000010]; n int main() { n   int t; n   scanf( %d , &t); n   for (int i = 0; i < 200010; i += 3) { n     dis[i] =  R , dis[i + 1] =  G , dis[i + 2] =  B ; n   } n   while (t--) { n     int n, k; n     scanf( %d %d , &n, &k); n     string s; n     cin >> s; n     int minn = INF; n     int x = 0; n     while (x < 3) { n       for (int i = 0; i < n; i++) { n         if (s[i] != dis[i + x]) n           a[i] = 1; n         else n           a[i] = 0; n         if (i != 0) a[i] = a[i - 1] + a[i]; n       } n       x++; n       minn = min(minn, a[k - 1]); n       for (int i = k; i < n; i++) { n         minn = min(minn, a[i] - a[i - k]); n       } n     } n     printf( %d n , minn); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, b, c, d, e, f, g, h, i, j, k, l, n, v, t; n   cin >> n >> k; n   long long m[k]; n   for (i = 0; i < k; i++) cin >> m[i]; n   if (n % 2 == 0) { n     a = m[k - 1]; n     if (a & 1) n       cout <<  odd n ; n     else n       cout <<  even n ; n   } else { n     a = 0; n     for (i = 0; i < k; i++) { n       if (m[i] & 1) a++; n     } n     if (a & 1) n       cout <<  odd n ; n     else n       cout <<  even n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long n; n   cin >> n; n   int s = 0, a; n   a = n / 100; n   n = n % 100; n   s += a; n   if (n != 0) { n     a = n / 20; n     n %= 20; n     s += a; n     if (n != 0) { n       a = n / 10; n       n %= 10; n       s += a; n       if (n != 0) { n         a = n / 5; n         n %= 5; n         s += a; n         if (n != 0) s += n; n       } n     } n   } n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e5 + 9; n int pre[MAX], suf[MAX], a[MAX]; n long long ans = 0, cnt = 0; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) n     cin >> a[i], pre[i] = (i > 0 ? pre[i - 1] + a[i] : a[i]); n   int sum = pre[n - 1] / 3; n   if (pre[n - 1] % 3 != 0) return cout << 0, 0; n   for (int i = n - 1; i >= 0; i--) suf[i] = suf[i + 1] + a[i]; n   if (pre[0] == sum) cnt++; n   for (int i = 2; i < n; i++) { n     if (suf[i] == sum) ans += cnt; n     if (pre[i - 1] == sum) cnt++; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const long long INF = 1e18; n const double EPS = 1e-6; n const int MAX_N = 500 + 5; n int n; n int arr[MAX_N]; n int memo[MAX_N][MAX_N]; n int memo2[MAX_N][MAX_N]; n int dp(int l, int r) { n   if (l == r) return memo[l][r] = arr[l]; n   if (memo[l][r] != -1) return memo[l][r]; n   for (int i = l; i < r; ++i) { n     if (dp(l, i) == dp(i + 1, r) && dp(l, i) > 0) n       return memo[l][r] = dp(l, i) + 1; n   } n   return memo[l][r] = -10; n } n int solve(int l, int r) { n   if (memo[l][r] != -10) return 1; n   if (memo2[l][r] != -1) return memo2[l][r]; n   int mini = n; n   for (int i = l; i < r; ++i) { n     mini = min(mini, solve(l, i) + solve(i + 1, r)); n   } n   return memo2[l][r] = mini; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   memset(memo, -1, sizeof memo); n   memset(memo2, -1, sizeof memo2); n   for (int i = 0; i < n; ++i) { n     cin >> arr[i]; n   } n   dp(0, n - 1); n   cout << solve(0, n - 1) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void gn(T &first) { n   char c, sg = 0; n   while (c = getchar(), (c >  9  || c <  0 ) && c !=  - ) n     ; n   for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ; n        c = getchar()) n     first = (first << 1) + (first << 3) + c -  0 ; n   if (sg) first = -first; n } n template <class T1, class T2> n inline void gn(T1 &x1, T2 &x2) { n   gn(x1), gn(x2); n } n pair<int, int> edge[500010]; n int w[500010]; n int n, m, Q; n int id[500010]; n int col[1010]; n int root[1010]; n int rev[500010]; n inline int find_root(int u) { n   if (root[u] == u) return u; n   int first = find_root(root[u]); n   col[u] ^= col[root[u]]; n   return root[u] = first; n } n int main() { n   gn(n, m); n   gn(Q); n   for (int i = 1; i <= m; i++) { n     gn(edge[i].first, edge[i].second); n     gn(w[i]); n   } n   for (int i = 1; i <= m; i++) id[i] = i; n   sort(id + 1, id + m + 1, [&](int u, int v) { return w[u] > w[v]; }); n   while (Q--) { n     int L, R; n     gn(L, R); n     for (int i = 1; i <= n; i++) { n       col[i] = 0; n       root[i] = i; n     } n     int ans = -1; n     for (int i = 1; i <= m; i++) { n       if (id[i] > R || id[i] < L) continue; n       int u = edge[id[i]].first, v = edge[id[i]].second; n       if (find_root(u) == find_root(v)) { n         if (col[u] == col[v]) { n           ans = w[id[i]]; n           break; n         } n         continue; n       } n       col[root[u]] = col[u] ^ col[v] ^ 1; n       root[root[u]] = root[v]; n     } n     printf( %d n , ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1ll << 32; n int n, m, s, e; n string ans =   ; n bool ch(int l, int r, int idx, bool b) { n   bool re = 1; n   if (l <= idx && idx <= r) re = 0; n   if (b) { n     if (l <= idx + 1 && idx + 1 <= r) re = 0; n   } else if (l <= idx - 1 && idx - 1 <= r) n     re = 0; n   return re; n } n int main() { n   scanf( %d %d %d %d , &n, &m, &s, &e); n   map<int, pair<int, int>> mp; n   for (int i = 0; i < m; i++) { n     int a; n     scanf( %d , &a); n     scanf( %d %d , &mp[a].first, &mp[a].second); n   } n   int j = 1; n   if (s < e) { n     for (int i = s; i < e; i++) { n       if (mp[j].first) { n         if (ch(mp[j].first, mp[j].second, i, 1)) n           ans +=  R ; n         else { n           ans +=  X ; n           i--; n         } n         j++; n       } else { n         while (!mp[j].first && i < e) { n           ans +=  R ; n           i++; n           j++; n         } n         i--; n       } n     } n   } else { n     for (int i = s; i > e; i--) { n       if (mp[j].first) { n         if (ch(mp[j].first, mp[j].second, i, 0)) n           ans +=  L ; n         else { n           ans +=  X ; n           i++; n         } n         j++; n       } else { n         while (!mp[j].first && i > e) { n           ans +=  L ; n           i--; n           j++; n         } n         i++; n       } n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int a[n]; n     vector<int> vec; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n     }; n     int l[n]; n     map<int, int> mpp; n     for (int i = 0; i < n; i++) { n       cin >> l[i]; n       if (l[i] == 0) { n         mpp[i] = 0; n         vec.push_back(a[i]); n       } else { n         mpp[i] = 1; n       } n     } n     int j = 0; n     sort(vec.rbegin(), vec.rend()); n     for (int i = 0; i < n; i++) { n       if (mpp[i] == 0) { n         cout << vec[j] <<    ; n         j++; n       } else { n         cout << a[i] <<    ; n       } n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } n const int INF = (((1 << 30) - 1) << 1) + 1; n const int nINF = 1 << 31; n pair<long long, long long> egcd(long long a, long long b, n                                 pair<long long, long long> x = {1, 0}, n                                 pair<long long, long long> y = {0, 1}) { n   return (b == 0) n              ? x n              : egcd(b, a % b, y, n                     {x.first - a / b * y.first, x.second - a / b * y.second}); n } n long long modInv(long long a, long long n) { n   return ((egcd(a, n).first % n) + n) % n; n } n const long long M = 998244353; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long mult(long long a, long long b) { return (a * b) % M; } n long long add(long long a, long long b) { return (a + b) % M; } n struct frac { n   long long n, d; n   void simp() { n     long long g = gcd(n, d); n     n /= g; n     d /= g; n   } n   frac(long long in_n, long long in_d) { n     n = in_n, d = in_d; n     simp(); n   } n   frac operator+(frac& oth) { n     frac ret(n * oth.d + d * oth.n, d * oth.d); n     ret.simp(); n     return ret; n   } n }; n const int N = 2e5 + 10; n int n, p[N], m = 0, l[N], have[N]; n long long bit[N]; n long long getSum(int i) { n   long long sum = 0; n   ++i; n   while (i > 0) { n     sum += bit[i]; n     i -= i & (-i); n   } n   return sum; n } n void updateBIT(int i, long long val) { n   ++i; n   while (i <= n + 5) { n     bit[i] += val; n     i += i & (-i); n   } n } n signed main() { n   ios::sync_with_stdio(false); n   cin >> n; n   for (int i = 0; i < (n); i++) { n     cin >> p[i]; n     if (p[i] != -1) n       have[p[i]] = 1; n     else n       ++m; n   } n   for (int i = (1); i <= (n); i++) { n     l[i] = l[i - 1]; n     if (!have[i]) ++l[i]; n   } n   long long k = 0; n   frac einv(0, 1); n   frac lm(0, 1); n   long long lmi = 0; n   long long inv = 0; n   long long ans = 0; n   for (int i = 0; i < (n); i++) { n     int x = p[i]; n     if (x != -1) { n       int above = getSum(n) - getSum(x); n       inv += above; n       ans = add(ans, above); n       updateBIT(x, 1); n       if (m) { n         frac ex((m - l[x]) * k, m); n         frac cex(l[x], m); n         einv = einv + ex; n         lm = lm + cex; n         lmi = add(lmi, mult(cex.n, modInv(cex.d, M))); n         ans = add(ans, mult(ex.n, modInv(ex.d, M))); n       } n     } else { n       einv = einv + lm; n       ans = add(ans, lmi); n       frac ex(k, 2); n       einv = einv + ex; n       ans = add(ans, mult(ex.n, modInv(ex.d, M))); n       ++k; n     } n   } n   frac kinv(inv, 1); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 7; n int a[maxn]; n int n, s; n int main() { n   scanf( %d%d , &n, &s); n   if (s >= 2 * n) { n     s -= 2 * n; n     puts( YES ); n     printf( %d , 2 + s); n     for (int i = 1; i < n; ++i) printf(  %d , 2); n     puts(  ); n     puts( 1 ); n   } else n     puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, s = 0; n   cin >> n; n   vector<int> a(n); n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n     s += a[i]; n   } n   sort(begin(a), end(a)); n   if (s % 2 == 0 && 2 * a[n - 1] <= s) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T gcd(T x, T y) { n   if (x < y) swap(x, y); n   while (y > 0) { n     T f = x % y; n     x = y; n     y = f; n   } n   return x; n } n struct Node { n   Node *l, *r; n   long long a, b; n   Node() : l(NULL), r(NULL), a(0), b(0) {} n }; n Node* makeTree(int fr, int to) { n   Node* node = new Node(); n   if (fr == to) return node; n   int m = (fr + to) / 2; n   node->l = makeTree(fr, m); n   node->r = makeTree(m + 1, to); n   return node; n } n Node* update(Node* _node, int fr, int to, int x1, int x2, long long a, n              long long b) { n   if (x2 < fr || x1 > to) return _node; n   Node* node = new Node(); n   *node = *_node; n   if (x1 <= fr && to <= x2) { n     node->a += a; n     node->b += b; n     return node; n   } n   int m = (fr + to) / 2; n   node->l = update(node->l, fr, m, x1, x2, a, b); n   node->r = update(node->r, m + 1, to, x1, x2, a, b); n   return node; n } n long long query(Node* node, int fr, int to, long long x) { n   long long res = node->a * x + node->b; n   if (fr == to) return res; n   int m = (fr + to) / 2; n   if (x <= m) n     return res + query(node->l, fr, m, x); n   else n     return res + query(node->r, m + 1, to, x); n } n Node* froot[75007]; n const int maxx = 200002; n int main(int argc, char* argv[]) { n   int n; n   std::cin.sync_with_stdio(false); n   std::cin.tie(nullptr); n   cin >> n; n   { n     froot[0] = makeTree(0, maxx); n     for (int i = 1; i <= n; i++) { n       int x1, x2, y1, a, b, y2; n       cin >> x1 >> x2 >> y1 >> a >> b >> y2; n       froot[i] = update(froot[i - 1], 0, maxx, 0, x1, 0, y1); n       froot[i] = update(froot[i], 0, maxx, x1 + 1, x2, a, b); n       froot[i] = update(froot[i], 0, maxx, x2 + 1, maxx, 0, y2); n     } n     int m; n     cin >> m; n     long long last = 0; n     while (m--) { n       int l, r, x; n       cin >> l >> r >> x; n       last = (last + x) % 1000000000ll; n       last = n           query(froot[r], 0, maxx, last) - query(froot[l - 1], 0, maxx, last); n       cout << last << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long GCD(long long x, long long y) { n   while (y != 0) { n     long long t = x % y; n     x = y; n     y = t; n   } n   return x; n } n long long n, a, b; n long long cs; n bool calc() { n   scanf( %lld %lld , &a, &b); n   long long g = GCD(a, b); n   long long p = a / g; n   long long q = b / g; n   long long pq = p * q; n   bool ret = (g % pq == 0); n   if (ret) { n     long long r = g / pq; n     long long i = 1; n     while (i * i * i < r) { n       i++; n     } n     if (i * i * i == r) return true; n   } n   return false; n } n int main() { n   scanf( %lld , &n); n   while (cs < n) { n     cs++; n     bool ans = calc(); n     if (ans) n       printf( Yes n ); n     else n       printf( No n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n int main(void) { n   int n; n   cin >> n >> s; n   int l = 0, r = 0; n   for (auto &c : s) n     if (c ==  L ) n       ++l; n     else n       ++r; n   cout << r + l + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, res = 1; n int main() { n   cin >> a >> b; n   if (b - (a + 1) > 20) { n     cout << 0; n     return 0; n   } n   for (long long i = a + 1; i <= b; i++) res = (res * (i % 10)) % 10; n   cout << res; n } n


#include <bits/stdc++.h> n using namespace std; n void Solve() { n   long long int n, q; n   cin >> n >> q; n   long long int a[n + 1], cnt[n + 1]; n   for (auto i = 1; i < n + 1; i++) cin >> a[i], cnt[i] = 0; n   while (q--) { n     long long int l, r; n     cin >> l >> r; n     cnt[l]++; n     if (r != n) cnt[r + 1]--; n   } n   for (auto i = 2; i < n + 1; i++) cnt[i] += cnt[i - 1]; n   sort(cnt + 1, cnt + n + 1); n   sort(a + 1, a + n + 1); n   long long int ans = 0; n   for (auto i = 1; i < n + 1; i++) ans += cnt[i] * a[i]; n   cout << ans <<   n ; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int T = 1; n   while (T--) Solve(); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n long long rand_seed() { n   long long a = rng(); n   return a; n } n int t; n int n; n string s; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> t; n   for (; t; --t) { n     cin >> n; n     cin >> s; n     bool ok = 0; n     for (int i = 0; i + 10 < n; ++i) n       if (s[i] ==  8 ) ok = 1; n     if (ok) n       cout <<  YES n ; n     else n       cout <<  NO n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100], b[45], c[100]; n int main() { n   int x; n   cin >> x; n   int p = 0, ans = 0, q = 0, f = 0; n   while (x) { n     c[p++] = x % 2; n     if (x % 2 == 0) f = 1; n     x = x / 2; n   } n   int pp = 0; n   for (int h = p - 1; h >= 0; h--) { n     a[pp++] = c[h]; n   } n   if (f) { n     while (ans + 1) { n       int flag = 0, flag1 = 0, flag2 = 0; n       for (int i = 0; i < p; i++) { n         if (flag) { n           if (a[i] == 1) n             a[i] = 0; n           else if (a[i] == 0) n             a[i] = 1; n         } else if (a[i] == 0) { n           ans++; n           a[i] = 1; n           flag = 1; n           b[q++] = p - i; n         } n       } n       for (int i = 0; i < p; i++) { n         if (a[i] == 0) { n           break; n         } n         if (i == p - 1) { n           flag1 = 1; n         } n       } n       if (flag1) { n         break; n       } n       ans++; n       for (int j = p - 1; j >= 0; j--) { n         a[j]++; n         if (a[j] == 2) n           a[j] = 0; n         else if (a[j] = 1) n           break; n       } n       for (int i = 0; i < p; i++) { n         if (a[i] == 0) { n           break; n         } n         if (i == p - 1) { n           flag2 = 1; n         } n       } n       if (flag2) { n         break; n       } n     } n     cout << ans << endl; n     for (int k = 0; k < q; k++) { n       if (k == 0) n         cout << b[k]; n       else n         cout <<     << b[k]; n     } n     cout << endl; n   } else { n     cout << 0 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long f[300005][2], g[300005]; n vector<int> vec[300005]; n long long powi(long long a, long long b) { n   long long p; n   if (!b) return 1; n   p = powi(a, b / 2); n   p = (p * p) % 998244353; n   if (b % 2) p = (p * a) % 998244353; n   return p; n } n long long mmi(long long x) { return powi(x, 998244353 - 2); } n void dfs(int s, int par = 0) { n   for (int v : vec[s]) { n     if (v != par) dfs(v, s); n   } n   f[s][0] = 1; n   for (int v : vec[s]) { n     if (v == par) continue; n     f[s][0] *= f[v][0]; n     f[s][0] %= 998244353; n   } n   long long temp = 1; n   for (int v : vec[s]) { n     if (v == par) continue; n     temp *= f[v][1] + f[v][0]; n     temp %= 998244353; n   } n   for (int v : vec[s]) { n     if (v == par) continue; n     long long temp2 = temp; n     temp2 = (temp2 * mmi(f[v][1] + f[v][0])) % 998244353; n     temp2 = (temp2 * g[v]) % 998244353; n     f[s][1] += temp2; n     f[s][1] %= 998244353; n   } n   f[s][0] += f[s][1]; n   f[s][0] %= 998244353; n   g[s] = 1; n   for (int v : vec[s]) { n     if (v == par) continue; n     g[s] *= f[v][0] + f[v][1]; n     g[s] %= 998244353; n   } n   return; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     int u, v; n     scanf( %d %d , &u, &v); n     vec[u].push_back(v); n     vec[v].push_back(u); n   } n   dfs(1); n   long long ans = f[1][0]; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math ) n const int maxn = 1e6 + 50; n int seg[4 * maxn], ans[maxn], last_pos[maxn], next_pos[maxn]; n int n, m; n vector<int> v, get_val, partial_xor; n vector<pair<pair<int, int>, int> > ques; n void update(int val, int l, int r = n) { n   for (l += n, r += n; l < r; l >>= 1, r >>= 1) { n     if (l & 1) seg[l++] ^= val; n     if (r & 1) seg[--r] ^= val; n   } n } n int get_xor(int idx) { n   int res = 0; n   for (idx += n; idx; idx >>= 1) res ^= seg[idx]; n   return res; n } n void sweep(int pos) { n   int val = get_val[v[pos]]; n   int nxt = next_pos[pos]; n   update(val, pos, nxt); n } n void input() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     int b; n     cin >> b; n     if (i == 0) n       partial_xor.push_back(b); n     else n       partial_xor.push_back(partial_xor[i - 1] ^ b); n     get_val.push_back(b); n     v.push_back(b); n     last_pos[i] = n; n   } n   cin >> m; n   for (int i = 0; i < m; i++) { n     int l, r; n     cin >> l >> r; n     l--, r--; n     ques.push_back({{l, r}, i}); n   } n } n void map_it() { n   sort(get_val.begin(), get_val.end()); n   vector<int>::iterator ip; n   ip = std::unique(get_val.begin(), get_val.end()); n   get_val.resize(std::distance(get_val.begin(), ip)); n   for (int i = v.size() - 1; i > -1; i--) { n     v[i] = lower_bound(get_val.begin(), get_val.end(), v[i]) - get_val.begin(); n     next_pos[i] = last_pos[v[i]]; n     last_pos[v[i]] = i; n   } n   for (int i = 0; i < get_val.size(); i++) update(get_val[i], last_pos[i]); n } n void answer_ques(int i) { n   pair<int, int> p = ques[i].first; n   ans[ques[i].second] = get_xor(p.second) ^ partial_xor[p.first] ^ n                         partial_xor[p.second] ^ get_val[v[p.first]]; n } n void calc() { n   int go_pos = 0; n   int i = 0; n   sort(ques.begin(), ques.end()); n   while (go_pos < ques.size()) { n     while (go_pos < ques.size() and i == ques[go_pos].first.first) n       answer_ques(go_pos++); n     if (go_pos == ques.size()) break; n     while (i < ques[go_pos].first.first) sweep(i++); n   } n } n void ansing() { n   for (int i = 0; i < m; i++) cout << ans[i] <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   input(); n   map_it(); n   calc(); n   ansing(); n } n


#include <bits/stdc++.h> n using namespace std; n long long pow(long long b, long long e, long long m) { n   long long t = 1; n   for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0; n   return t; n } n template <class T> n inline bool chkmin(T &a, T b) { n   return a > b ? a = b, true : false; n } n template <class T> n inline bool chkmax(T &a, T b) { n   return a < b ? a = b, true : false; n } n template <class T> n inline T sqr(T x) { n   return x * x; n } n template <typename T> n T gcd(T x, T y) { n   for (T t; x; t = x, x = y % x, y = t) n     ; n   return y; n } n template <class edge> n struct Graph { n   vector<vector<edge> > adj; n   Graph(int n) { n     adj.clear(); n     adj.resize(n + 5); n   } n   Graph() { adj.clear(); } n   void resize(int n) { adj.resize(n + 5); } n   void add(int s, edge e) { adj[s].push_back(e); } n   void del(int s, edge e) { adj[s].erase(find(iter(adj[s]), e)); } n   vector<edge> &operator[](int t) { return adj[t]; } n }; n int main() { n   ios_base::sync_with_stdio(false); n   int n, m; n   cin >> n >> m; n   if (m == 3) { n     if (n == 3) { n       cout <<  0 0  << endl <<  1 1  << endl <<  1 0  << endl; n     } else if (n == 4) { n       cout <<  0 0  << endl n            <<  0 1  << endl n            <<  -1 -1  << endl n            <<  1 -1  << endl; n     } else { n       cout << -1 << endl; n     } n     return 0; n   } n   const int X = 1e7; n   for (int i = 1; i <= m; ++i) { n     cout << i <<     << +(X + i * i) << endl; n   } n   for (int i = 1; i <= n - m; ++i) { n     cout << i <<     << -(X + i * i) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( avx,avx2,fma ) n #pragma GCC optimization( unroll-loops ) n using namespace std; n template <typename T> n bool mycomp(T x, T y) { n   return (x == y); n } n bool paircomp(const pair<long long int, long long int> &x, n               const pair<long long int, long long int> &y) { n   return x.second < y.second; n } n long long int f[6][6]; n void solve() { n   long long int m; n   cin >> m; n   for (long long int i = 0; i < m; i++) { n     long long int x, y; n     cin >> x >> y; n     f[x][y] = 1; n     f[y][x] = 1; n   } n   for (long long int i = 1; i <= 5; i++) { n     for (long long int j = i + 1; j <= 5; j++) { n       for (long long int k = j + 1; k <= 5; k++) { n         if (f[i][j] && f[i][k] && f[j][k]) { n           cout <<  WIN ; n           return; n         } n         if (!f[i][j] && !f[i][k] && !f[j][k]) { n           cout <<  WIN n ; n           return; n         } n       } n     } n   } n   cout <<  FAIL ; n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int t = 1; n   while (t--) { n     solve(); n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n using vc = vector<T>; n using pii = pair<long long, long long>; n void xmax(long long& a, long long b) { a = max(a, b); } n void xmin(long long& a, long long b) { a = min(a, b); } n void print(vc<long long>& a, string second) { n   cerr << second <<   :  ; n   for (long long i = 0; i < a.size(); i++) { n     cerr << a[i] <<    ; n   } n   cerr << endl; n } n long long dist(pii a, pii b) { n   return (a.first - b.first) * (a.first - b.first) + n          (a.second - b.second) * (a.second - b.second); n } n long long find_min(vc<pii> p) { n   if (p.size() == 1) return 1e18; n   if (p.size() == 2) { n     return dist(p[0], p[1]); n   } n   long long n = p.size(); n   long long mid = (p[0].first + p[n - 1].first) / 2; n   vc<pii> ri; n   vc<pii> le; n   for (long long i = 0; i < n; i++) { n     if (p[i].first <= mid) n       le.push_back(p[i]); n     else n       ri.push_back(p[i]); n   } n   long long mini = 1e18; n   xmin(mini, find_min(le)); n   xmin(mini, find_min(ri)); n   vc<pii> cut; n   long double delta = sqrt(mini) + 1; n   for (long long i = 0; i < le.size(); i++) { n     if (abs(mid - le[i].first) <= delta) n       cut.push_back({le[i].second, le[i].first}); n   } n   for (long long i = 0; i < ri.size(); i++) { n     if (abs(mid - ri[i].first) <= delta) n       cut.push_back({ri[i].second, ri[i].first}); n   } n   sort(cut.begin(), cut.end()); n   for (long long i = 0; i < cut.size(); i++) { n     for (long long j = 1; j < 20 && i + j < cut.size(); j++) { n       xmin(mini, dist(cut[i], cut[i + j])); n     } n   } n   return mini; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long n; n   cin >> n; n   vc<long long> a(n); n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n   } n   vc<long long> p(n); n   for (long long i = 1; i < n; i++) { n     p[i] = p[i - 1] + a[i]; n   } n   vc<pair<long long, long long> > st(n); n   for (long long i = 0; i < n; i++) { n     st[i] = {i, p[i]}; n   } n   long long res = find_min(st); n   cout << res <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n inline void sfr(int *a) { n   char c = 0; n   while (c < 33) c = fgetc(stdin); n   *a = 0; n   while (c > 33) { n     *a = *a * 10 + c -  0 ; n     c = fgetc(stdin); n   } n } n inline void sfp(int a) { n   char c[1000]; n   sprintf(c,  %d , a); n   puts(c); n } n int main() { n   int n; n   cin >> n; n   ; n   int m; n   cin >> m; n   ; n   int A[n][m]; n   getchar(); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       char c =   n ; n       while (c ==   n ) c = getchar(); n       A[i][j] = (c ==  1 ); n     } n   } n   int B[n]; n   int mx = 0; n   for (int i = n - 1; i >= 0; i--) B[i] = 0; n   for (int i = m - 1; i >= 0; i--) { n     vector<int> D; n     for (int j = 0; j < n; j++) { n       if (A[j][i]) { n         B[j] = B[j] + 1; n         D.push_back(B[j]); n       } else { n         B[j] = 0; n         D.push_back(0); n       } n     } n     sort(D.begin(), D.end()); n     for (int j = 0; j < n; j++) mx = max(mx, D[j] * (n - j)); n   } n   cout << mx << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, dir[200005]; n long long cnt, le; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &dir[i]); n     if (dir[i] == 0) le++; n   } n   for (int i = 0; i < n; i++) { n     if (dir[i] == 1) n       cnt += le; n     else n       le--; n   } n   printf( %I64d , cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int maxn = 2e5 + 6; n const long long int inf = 2e18 + 1; n long long int a[maxn]; n int main() { n   long long int n, k; n   cin >> n >> k; n   long long int next[n]; n   for (long long int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   next[n - 1] = n; n   for (long long int i = n - 2; i >= 0; i--) { n     if (a[i + 1] != 1) { n       next[i] = i + 1; n     } else { n       next[i] = next[i + 1]; n     } n   } n   long long int ans = 0; n   for (long long int i = 0; i < n; i++) { n     if (k == 1) { n       ans++; n     } n     long long int r = i; n     long long int mul = a[i]; n     long long int sum = a[i]; n     while (next[r] != n && a[next[r]] <= inf / mul) { n       mul = mul * a[next[r]]; n       sum = sum + next[r] - r - 1 + a[next[r]]; n       r = next[r]; n       long long int check = -1; n       if (mul % k == 0) { n         check = mul / k; n       } n       long long int store = next[r] - r - 1; n       if (check >= sum && check <= sum + store) { n         ans = ans + 1; n       } n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long T, W, B, H, P; n long long fpb(long long A, long long B) { n   if (A == 0) { n     return B; n   } n   return fpb(B % A, A); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> T >> W >> B; n   H = W / fpb(W, B); n   if (T / B < H) { n     P = min(W, B) - 1 - max((long long)0, min(W, B) - 1 - T); n   } else { n     H *= B; n     P = (T / H + 1) * min(W, B) - 1 - max((long long)0, min(W, B) - 1 - T % H); n   } n   H = fpb(P, T); n   cout << P / H <<  /  << T / H <<   n ; n } n