#include <bits/stdc++.h> n using namespace std; n long long power(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) { n       res = (res * x) % p; n     } n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long modInverse(long long a, long long p) { return power(a, p - 2, p); } n long long gcd(long long x, long long y) { n   if (x == 0 || y == 0) { n     return max(y, x); n   } n   return gcd(y % x, x); n } n long long gcdExtended(long long a, long long b, long long &x, long long &y) { n   if (a == 0) { n     x = 0; n     y = 1; n     return b; n   } n   long long x1, y1; n   long long gcd = gcdExtended(b % a, a, x1, y1); n   x = y1 - (b / a) * x1; n   y = x1; n   return gcd; n }; n long long bit[1504]; n void update(long long x) { n   while (x <= 1500) { n     bit[x]++; n     x += (x & (-x)); n   } n } n long long get(long long x) { n   long long ret = 0; n   while (x) { n     ret += bit[x]; n     x -= (x & (-x)); n   } n   return ret; n } n long long dp[1504][1504]; n int main() { n   long long n; n   scanf( %lld , &n); n   vector<long long> a; n   for (long long i = 0; i < n; i++) { n     long long x; n     scanf( %lld , &x); n     a.push_back(x); n   } n   for (long long i = 0; i < n; i++) { n     for (long long j = 1; j <= n; j++) bit[j] = 0; n     long long here = 0; n     for (long long j = i; j < n; j++) { n       update(a[j]); n       here += get(a[j] - 1); n       dp[i][j] = here; n     } n   } n   long long q; n   scanf( %lld , &q); n   long long tot = dp[0][n - 1]; n   tot = (n) * (n - 1); n   tot /= 2; n   tot -= dp[0][n - 1]; n   tot %= 2; n   while (q--) { n     long long x, y; n     scanf( %lld %lld , &(x), &(y)); n     long long len = y - x + 1; n     long long here = (len) * (len - 1); n     here /= 2; n     here %= 2; n     tot = tot + here; n     tot %= 2; n     if (tot) n       cout <<  odd  << endl; n     else n       cout <<  even  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 111111; n int Tit[M]; n int ra[M]; n int k[M]; n int r, j, rslt = 0; n vector<int> vec[M]; n void dfs(int u, int v) { n   ra[u] = ra[v] + 1; n   k[ra[u]] ^= 1; n   int j = vec[u].size(); n   int z; n   while (j--) { n     z = vec[u][j]; n     if (z != v) dfs(z, u); n   } n } n int main() { n   scanf( %d , &r); n   for (j = 2; j <= r; j = j + 1) scanf( %d , Tit + j), vec[Tit[j]].push_back(j); n   dfs(1, 0); n   for (j = 1; j <= r; j = j + 1) rslt += k[j]; n   cout << rslt; n   return 0; n } n


#include <bits/stdc++.h> n typedef long long ll; n #define endl   n  n #define pq priority_queue <pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> n #define graph1 vector<vector<pair<ll,ll>>> n #define graph vector<vector<ll>> n #define pq1 priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll,ll>>>, greater<pair<ll, pair<ll, ll>>>> n #define loop(i,a,b) for (ll i = a; i < b; i++) n using namespace std; n vector <ll>  arr; n bool check3(ll i) n { n     if(max(arr[i],arr[i+2]) >=  arr[i+1] && min(arr[i],arr[i+2]) <=  arr[i+1]  ) n     { n         return true; n     } n     return false; n } n bool check4(ll i) n { n     if(check3(i) ||check3(i + 1)) n     { n         return true; n     } n     if(max(arr[i],arr[i+3]) >=  arr[i + 1] && min(arr[i],arr[i+3]) <=  arr[i+1]  ) n     { n         return true; n     } n     if(max(arr[i],arr[i+3]) >=  arr[i + 2] && min(arr[i],arr[i+3]) <=  arr[i+2]  ) n     { n         return true; n     } n     return false; n } n int main() n { n     ios::sync_with_stdio(0); cin.tie(0); n     ll t; n     cin >> t; n     while(t--) n     { n         ll n; n         cin >> n; n         arr.resize(n); n         loop(i,0,n) n             cin >> arr[i]; n  n         ll ans = n * 2 - 1; n  n         loop(i,0,n-2) n         { n             if(!check3(i)) n             ans++; n         } n         loop(i,0,n-3) n         { n             if(!check4(i)) n             ans++; n         } n         cout << ans << endl; n     } n }


#include <bits/stdc++.h> n using namespace std; n using vi = vector<int>; n using vvi = vector<vi>; n using ll = long long; n using vll = vector<ll>; n using vvll = vector<vll>; n using pii = pair<int, int>; n using pll = pair<ll, ll>; n ll power[40]; n void dfs(int id, vi& v, vi& s) { n   if (id < v.size()) { n     s.push_back(v[id]); n     dfs(id * 2, v, s); n     dfs(id * 2 + 1, v, s); n   } n } n void solve() { n   int h, g, num; n   cin >> h >> g; n   vi v(power[h]); n   vvi mins(power[g], vi()); n   set<int> fin; n   for (int i = 1; i < power[h]; i++) { n     cin >> v[i]; n   } n   for (int i = 0; i < power[g - 1]; i++) { n     dfs(i + power[g - 1], v, mins[i + power[g - 1]]); n     sort(mins[i + power[g - 1]].begin(), mins[i + power[g - 1]].end(), n          greater<int>()); n   } n   for (int i = g; i > 0; i--) { n     for (int j = power[i - 1]; j < power[i]; j++) { n       fin.insert(*mins[j].rbegin()); n     } n     if (i == 1) { n       break; n     } n     for (int j = power[i - 1]; j < power[i]; j += 2) { n       num = max(*mins[j].rbegin(), *mins[j + 1].rbegin()); n       mins[j].pop_back(); n       mins[j + 1].pop_back(); n       mins[j / 2].push_back(v[j / 2]); n       merge(mins[j].begin(), mins[j].end(), mins[j + 1].begin(), n             mins[j + 1].end(), std::back_inserter(mins[j / 2]), greater<int>()); n       while (*mins[j / 2].rbegin() < num) { n         mins[j / 2].pop_back(); n       } n     } n   } n   ll sum = 0; n   vi print; n   print.reserve(power[h] - 1); n   for (int i = 1; i < power[h]; i++) { n     if (fin.find(v[i]) == fin.end()) { n       print.push_back(i); n     } else { n       sum += v[i]; n     } n   } n   reverse(print.begin(), print.end()); n   cout << sum <<   n ; n   for (int i : print) { n     cout << i <<    ; n   } n   cout <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   power[0] = 1; n   for (int i = 1; i < 40; i++) { n     power[i] = 2ll * power[i - 1]; n   } n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n struct Point { n   double x, y; n   Point(double x = 0, double y = 0) : x(x), y(y) {} n }; n double Dot(Point A, Point B) { return A.x * B.x + A.y * B.y; } n double Length(Point A) { return sqrt(Dot(A, A)); } n double Angle(Point A, Point B) { n   return acos(Dot(A, B) / Length(A) / Length(B)); n } n Point Normal(Point A) { n   double L = Length(A); n   return Point(-A.y / L, A.x / L); n } n double Cross(Point A, Point B) { return A.x * B.y - A.y * B.x; } n Point operator+(Point A, Point B) { return Point(A.x + B.x, A.y + B.y); } n Point operator-(Point A, Point B) { return Point(A.x - B.x, A.y - B.y); } n Point operator*(Point A, double p) { return Point(A.x * p, A.y * p); } n Point operator/(Point A, double p) { return Point(A.x / p, A.y / p); } n int dcmp(double x) { n   if (fabs(x) < eps) return 0; n   return x < 0 ? -1 : 1; n } n bool operator<(const Point &a, const Point &b) { n   return a.x < b.x || (a.x == b.x && a.y < b.y); n } n bool operator==(const Point &a, const Point &b) { n   return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0; n } n double GetAngleByLength(double a, double b, double c) { n   double cosA = (b * b + c * c - a * a) / (b * c * 2); n   return acos(cosA); n } n Point Rotate(Point A, double rad) { n   return Point(A.x * cos(rad) - A.y * sin(rad), n                A.x * sin(rad) + A.y * cos(rad)); n } n Point GetLineIntersection(Point P, Point v, Point Q, Point w) { n   Point u = P - Q; n   double t = Cross(w, u) / Cross(v, w); n   return P + v * t; n } n Point R; n Point v; n double solve(Point P, Point vP, Point Q, Point vQ) { n   auto X = GetLineIntersection(P, vP, R, v); n   auto Y = GetLineIntersection(Q, vQ, R, v); n   return Length(P - X) + Length(X - Y) + Length(Q - Y); n } n int main() { n   double a, b, c, x1, y1, x2, y2; n   cin >> a >> b >> c >> x1 >> y1 >> x2 >> y2; n   if (a == 0 || b == 0) { n     double ans = fabs(x1 - x2) + fabs(y1 - y2); n     printf( %.10f n , ans); n     return 0; n   } n   R.x = 0; n   R.y = -c / b; n   v = Point(b, -a); n   double ans = fabs(x1 - x2) + fabs(y1 - y2); n   ans = min(ans, solve(Point(x1, y1), Point(1, 0), Point(x2, y2), Point(1, 0))); n   ans = min(ans, solve(Point(x1, y1), Point(1, 0), Point(x2, y2), Point(0, 1))); n   ans = min(ans, solve(Point(x1, y1), Point(0, 1), Point(x2, y2), Point(1, 0))); n   ans = min(ans, solve(Point(x1, y1), Point(0, 1), Point(x2, y2), Point(0, 1))); n   printf( %.10f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int n, m, a[N], type, l, r; n set<int> q[N]; n inline int myrand() { return rand() ^ (rand() << 16); } n struct item { n   item *l, *r; n   int key, prior, val; n   long long sum; n   item() {} n   item(int _key, int _val) { n     val = sum = _val; n     key = _key; n     prior = myrand(); n     l = r = nullptr; n   } n }; n typedef item *pitem; n pitem t[4 * N]; n inline long long sum(pitem v) { return v ? v->sum : 0; } n inline void upd_cnt(pitem v) { n   if (v) { n     v->sum = sum(v->l) + v->val + sum(v->r); n   } n } n void Merge(pitem &v, pitem l, pitem r) { n   if (!l || !r) { n     v = l ? l : r; n   } else if (l->prior > r->prior) { n     Merge(l->r, l->r, r); n     v = l; n   } else { n     Merge(r->l, l, r->l); n     v = r; n   } n   upd_cnt(v); n } n void Split(pitem v, int key, pitem &l, pitem &r) { n   if (!v) { n     l = r = nullptr; n     return; n   } n   if (key < v->key) { n     Split(v->l, key, l, v->l); n     r = v; n   } else { n     Split(v->r, key, v->r, r); n     l = v; n   } n   upd_cnt(v); n } n void Insert(pitem &v, int key, int val) { n   pitem cur; n   Split(v, key, v, cur); n   Merge(v, v, new item(key, val)); n   Merge(v, v, cur); n } n void Erase(pitem &v, int key) { n   if (!v) { n     cout <<  SOSI ; n     exit(0); n   } n   if (v->key == key) { n     pitem sosi = v; n     Merge(v, v->l, v->r); n     delete sosi; n     return; n   } n   Erase(key < v->key ? v->l : v->r, key); n   upd_cnt(v); n } n void update(int pos, int key, int val, int add) { n   for (int i = pos; i <= n; i |= i + 1) { n     if (add == 1) { n       Insert(t[i], key, val); n     } else { n       Erase(t[i], key); n     } n   } n } n inline long long Get(pitem v, int l, int r) { n   pitem cur1, cur2; n   Split(v, l - 1, v, cur1); n   Split(cur1, r, cur1, cur2); n   long long ans = sum(cur1); n   Merge(v, v, cur1); n   Merge(v, v, cur2); n   return ans; n } n long long get(int pos, int tl, int tr) { n   long long ans = 0; n   for (int i = pos; i >= 1; i &= i + 1, i--) { n     ans += Get(t[i], tl, tr); n   } n   return ans; n } n int main() { n   srand(time(nullptr)); n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     q[i].insert(-1e9); n     t[i] = nullptr; n   } n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     int prv = *(--q[a[i]].insert(i).first); n     update(i, prv, i - prv, +1); n   } n   for (int i = 1; i <= m; i++) { n     cin >> type >> l >> r; n     if (type == 1) { n       auto it = q[a[l]].find(l); n       int prv = *prev(it); n       it = next(it); n       update(l, prv, -1, -1); n       if (it != q[a[l]].end()) { n         int nxt = *it; n         update(nxt, l, -1, -1); n         update(nxt, prv, nxt - prv, +1); n       } n       q[a[l]].erase(l); n       a[l] = r; n       it = q[a[l]].insert(l).first; n       prv = *prev(it); n       it = next(it); n       if (it != q[a[l]].end()) { n         int nxt = *it; n         update(nxt, prv, -1, -1); n         update(nxt, l, nxt - l, +1); n       } n       update(l, prv, l - prv, +1); n     } else { n       cout << get(r, l, r) - get(l - 1, l, r) <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n #define ll long long int n #define fast ios_base::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL); n #define scan(a,n) for(long long int index=0;index<n;index++) cin>>a[index]; n #define print(a,n) for(long long int index=0;index<n;index++) cout<<a[index]<<   ;cout<<endl; n #define mod 1000000007 n #define pb push_back n #define mp make_pair n #define ss second n #define ff first n #define vli vector<long long int> n #define vlli vector<pair<long long int,long long int>> n #define vsi vector<string> n #define all(n) n.begin(),n.end() n #define forn(i,a,b) for(i=a;i<b;i++) n ll mul(ll x,ll y){  return (x*y)%mod;} n ll power(ll x, ll y) {ll res = 1; x %= mod; n  while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;} n ll mod_inv(ll x) {return power(x, mod - 2);} n ll fact(ll n) {ll res = 1; for (ll i = 2; i <= n; i++) res = mul(res , i); return res; }  n ll nCr(ll n, ll r) { return mul(fact(n),mod_inv(mul(fact(r),fact(n - r))));}  n  n   n int main() { n   fast; n   #ifndef ONLINE_JUDGE n   freopen( input.txt , r ,stdin); n   freopen( output.txt , w ,stdout); n   #endif n   ll t=1; n   cin>>t; n   while(t--){ n     ll n,k; n     cin>>n>>k; n     ll a[n],b[n],i; n     for(i=0;i<n;i++){ n       cin>>a[i]>>b[i]; n     } n     ll f=-1,j; n     ll x,y; n     for(i=0;i<n;i++){ n      x=0; n      for(j=0;j<n;j++){ n         y=abs(a[i]-a[j])+abs(b[i]-b[j]); n       if(y<=k) x++; n      } n      if(x==n) f=1; n     } n     cout<<f<<endl; n  n     n  n  n      n   } n return 0;     n  }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int arr[n]; n   long long sum = 0; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   vector<int> odd, even; n   for (int i = 0; i < n; i++) { n     if (arr[i] & 1) n       odd.push_back(arr[i]); n     else n       even.push_back(arr[i]); n   } n   sort(odd.begin(), odd.end()); n   sort(even.begin(), even.end()); n   if (odd.size() > even.size()) { n     for (int i = 0; i < odd.size() - even.size() - 1; i++) sum += odd[i]; n   } else if (odd.size() == even.size()) n     sum = 0; n   else { n     for (int i = 0; i < even.size() - odd.size() - 1; i++) sum += even[i]; n   } n   cout << sum; n } n


#include <bits/stdc++.h> n using namespace std; n using vi = vector<long long int>; n using vvi = vector<vi>; n using vb = vector<bool>; n using vc = vector<char>; n using vs = vector<string>; n using vld = vector<long double>; n using pii = pair<long long int, long long int>; n using psi = pair<string, long long int>; n using pci = pair<char, long long int>; n using vpii = vector<pii>; n long long int mod = 1e9 + 7; n long long int const maxn = 2e5 + 5; n long long int const inf = 1e18; n long long int add(long long int a, long long int b) { n   return ((a % mod) + (b % mod)) % mod; n } n long long int mul(long long int a, long long int b) { n   return ((a % mod) * (b % mod)) % mod; n } n long long int powm(long long int x, long long int n, long long int M) { n   long long int result = 1; n   while (n > 0) { n     if (n % 2 == 1) result = (result * x) % M; n     x = (x * x) % M; n     n = n / 2; n   } n   return result; n } n long long int modinverse(long long int a, long long int m) { n   return powm(a, m - 2, m); n } n bool prime(long long int x) { n   if (x <= 1) return false; n   for (int i = 2; i <= sqrt(x); i++) n     if (x % i == 0) return false; n   return true; n } n long long int divisor(long long int x) { n   long long int cnt = 0; n   for (int i = 1; i <= sqrt(x); i++) { n     if (x % i == 0) { n       if (i != x / i) n         cnt += 2; n       else n         cnt += 1; n     } n   } n   return cnt; n } n vector<long long int> sieve(long long int n) { n   bool prim[n + 1]; n   memset(prim, true, sizeof(prim)); n   for (long long int p = 2; p * p <= n; p++) { n     if (prim[p] == true) { n       for (int i = p * p; i <= n; i += p) prim[i] = false; n     } n   } n   vector<long long int> v; n   for (int i = 2; i <= n; i++) n     if (prim[i]) v.push_back(i); n   return v; n } n vvi adj(maxn); n vb vis(maxn, false); n long long int x, y; n void dfs(long long int u) { n   if (vis[u] == true) return; n   vis[u] = true; n   if (x == -1 and y == -1) { n     x = u; n     y = u; n   } n   x = min(x, u); n   y = max(y, u); n   for (auto v : adj[u]) { n     if (!vis[v]) { n       dfs(v); n     } n   } n } n int main() { n   int t; n   t = 1; n   while (t--) { n     long long int n, m; n     cin >> n >> m; n     vpii ans; n     for (long long int i = 0; i < m; i++) { n       long long int a, b; n       cin >> a >> b; n       adj[a].push_back(b); n       adj[b].push_back(a); n     } n     for (long long int i = 1; i <= n; i++) { n       if (!vis[i]) { n         x = -1; n         y = -1; n         dfs(i); n         ans.push_back({x, y}); n       } n     } n     sort(ans.begin(), ans.end()); n     long long int cnt = 0; n     for (long long int i = 1; i <= (long long int)ans.size() - 1; i++) { n       if (ans[i - 1].second >= ans[i].first) { n         cnt++; n         ans[i].second = max(ans[i - 1].second, ans[i].second); n       } n     } n     cout << cnt <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mx[8] = {-1, 1, -1, 1, -2, 2, -2, 2}; n const int my[8] = {-2, -2, 2, 2, -1, -1, 1, 1}; n const int MAXN = 1100; n const int MAXM = 1100; n int N, M; n const int MAXV = MAXN * MAXM; n int V; n int source[2]; n int target[2]; n int dist[2][MAXV]; n int nxt[2][MAXV]; n int st_dist[2][2]; n bool parity(int v) { return ((v / M) + (v % M)) & 1; } n bool one_move(int a, int b) { n   int dx = abs(a / M - b / M); n   int dy = abs(a % M - b % M); n   return (dx == 1 && dy == 2) || (dx == 2 && dy == 1); n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> N >> M; n   V = N * M; n   { n     int X0, Y0, X1, Y1; n     cin >> X0 >> Y0 >> X1 >> Y1; n     X0--, Y0--, X1--, Y1--; n     source[0] = X0 * M + Y0; n     source[1] = X1 * M + Y1; n   } n   target[0] = (N / 2 - 1) * M + (M / 2 - 1); n   target[1] = (N / 2 + 1 - 1) * M + (M / 2 - 1); n   for (int z = 0; z < 2; z++) { n     for (int i = 0; i < V; i++) dist[z][i] = -1; n     queue<int> q; n     dist[z][target[z]] = 0; n     q.push(target[z]); n     while (!q.empty()) { n       int cur = q.front(); n       q.pop(); n       int x = cur / M, y = cur % M; n       for (int d = 0; d < 8; d++) { n         int nx = x + mx[d], ny = y + my[d]; n         if (0 <= nx && nx < N && 0 <= ny && ny < M) { n           int n = nx * M + ny; n           if (dist[z][n] == -1) { n             dist[z][n] = dist[z][cur] + 1; n             nxt[z][n] = cur; n             q.push(n); n           } n         } n       } n     } n     for (int x = 0; x < 2; x++) { n       st_dist[x][z] = dist[z][source[x]]; n     } n   } n   int adv; n   if (parity(source[0]) != parity(source[1])) { n     adv = 0; n   } else { n     adv = 1; n   } n   int dis_dist = st_dist[!adv][!adv]; n   int adv_turns = (adv == 0) ? dis_dist : dis_dist - 1; n   int me, goal; n   if (st_dist[adv][adv] <= adv_turns) { n     me = adv; n     goal = adv; n   } else if (st_dist[adv][!adv] - 1 <= adv_turns) { n     me = adv; n     goal = !adv; n   } else { n     me = !adv; n     goal = !adv; n   } n   nxt[0][target[0]] = target[0] + 2 * M + 1; n   nxt[1][target[1]] = target[1] - 2 * M + 1; n   cout << (me == 0 ?  WHITE  :  BLACK ) <<   n  << flush; n   int cur[2] = {source[0], source[1]}; n   for (int t = 0; true; t++) { n     if (t % 2 == me) { n       auto print_pos = [&]() { n         cout << (cur[me] / M + 1) <<     << (cur[me] % M + 1) <<   n  << flush; n       }; n       if (one_move(cur[me], cur[!me])) { n         cur[me] = cur[!me]; n         print_pos(); n         exit(0); n       } n       if (cur[me] == target[goal]) goal = me; n       cur[me] = nxt[goal][cur[me]]; n       print_pos(); n       if (cur[me] == target[me]) { n         exit(0); n       } n     } else { n       int x, y; n       cin >> x >> y; n       if (x == -1 && y == -1) { n         exit(0); n       } n       x--, y--; n       cur[!me] = x * M + y; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5000 + 7; n int n, a[maxn], ans[maxn], b[maxn], id; n map<int, int> mp; n int t0 = 0, t1 = 0, t2 = 0; n int cnt[maxn]; n void work(int id) { n   for (int i = 2;; ++i) { n     int t = i * i; n     if (a[id] >= 0 && t > a[id]) return; n     if (a[id] < 0 && t > -1 * a[id]) return; n     if (a[id] % t == 0) { n       while (a[id] % t == 0) { n         a[id] /= t; n       } n     } n   } n } n void init() { n   scanf( %d , &n); n   id = 1; n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n     work(i); n     int t; n     if (t = mp[a[i]]) n       b[i] = t; n     else n       b[i] = mp[a[i]] = id++; n   } n   memset(ans, 0, sizeof ans); n } n int main() { n   init(); n   for (int i = 1; i <= n; ++i) { n     for (int k = 1; k < id; ++k) cnt[k] = 0; n     int sum = 0; n     for (int j = i; j <= n; ++j) { n       if (a[j] && !cnt[b[j]]) { n         sum++; n       } n       cnt[b[j]]++; n       ans[max(1, sum)]++; n     } n   } n   for (int i = 1; i <= n; ++i) { n     printf( %d%c , ans[i], (i == n ?   n  :    )); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a = 0, k = 2000000000; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     if (x % n <= i) n       x = x / n; n     else n       x = x / n + 1; n     if (x < k) { n       a = i; n       k = x; n     } n   } n   cout << (a + 1); n } n


#include <bits/stdc++.h> n using namespace std; n long long fact[100001], inv[100001], ifact[100001]; n template <typename T, typename T1> n T mod(T x, T1 p) { n   x %= p; n   if (x < 0) x += p; n   return x; n } n template <typename T> n T inverse(T x, T p) { n   x = mod(x, p); n   if (x == 1) return x; n   return mod((1LL * (-p / x) * (inv[p % x] % p)), p); n } n int NcR(int n, int r) { n   int ret = (1LL * ifact[n - r] * ifact[r]) % 1000000007; n   ret = (1LL * ret * fact[n]) % 1000000007; n   return ret; n } n int main(int argc, char **argv) { n   ios::sync_with_stdio(false); n   fact[0] = 1; n   for (int i = 1; i < 100001; i++) { n     fact[i] = 1LL * fact[i - 1] * i % 1000000007; n   } n   ifact[0] = 1; n   for (int i = 1; i < 100001; i++) { n     inv[i] = inverse(i, 1000000007); n     ifact[i] = 1LL * ifact[i - 1] * inv[i] % 1000000007; n   } n   int N; n   cin >> N; n   long long ans = 0; n   for (int i = 1; i < N; i++) { n     ans = (ans + 1LL * NcR(N - 1, i) * NcR(N, i + 1)) % 1000000007; n   } n   ans = (ans * 2 + N) % 1000000007; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x7fffffff; n long long n, m, k, x, s; n const int maxn = 2e5 + 10; n long long a[maxn], b[maxn], c[maxn], d[maxn]; n int main(void) { n   cin.sync_with_stdio(false); n   cin >> n >> m >> k >> x >> s; n   for (int i = (0); i < (m); i++) { n     cin >> a[i]; n   } n   for (int i = (0); i < (m); i++) { n     cin >> b[i]; n   } n   for (int i = (0); i < (k); i++) { n     cin >> c[i]; n   } n   for (int i = (0); i < (k); i++) { n     cin >> d[i]; n   } n   long long ans = n * x; n   for (int i = (0); i < (m); i++) { n     long long cur = 0; n     long long curd = s - b[i]; n     if (curd < 0) continue; n     int idx = upper_bound(d, d + k, curd) - d - 1; n     if (idx < 0) { n       cur = n * a[i]; n       ans = min(ans, cur); n     } else { n       cur = (n - c[idx]) * a[i]; n       ans = min(ans, cur); n     } n   } n   int idx = upper_bound(d, d + k, s) - d - 1; n   if (idx >= 0) { n     long long cur = (n - c[idx]) * x; n     ans = min(ans, cur); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 500; n const int INF = 1e7 + 500; n const int MOD = 1e9 + 7; n const int LOG = 18; n const double EPS = 1e-9; n const double PI = 3.1415926535; n vector<pair<int, int> > P; n long double L = INF, R = -INF, M1, M2; n long double dist(long double x0, long double y0, long double x1, n                  long double y1) { n   return sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)); n } n long double f(long double sx) { n   long double s, h, r = 0; n   for (auto p : P) { n     s = dist(sx, 0, p.first, p.second); n     h = dist(sx, 0, sx, p.second); n     r = max(r, (s * s) / (2 * h)); n   } n   return r; n } n int main() { n   int N, xi, yi; n   bool pl = false, mi = false; n   cin >> N; n   for (int i = 0; i < N; i++) { n     cin >> xi >> yi; n     P.push_back({xi, yi}); n     if (yi > 0) pl = true; n     if (yi < 0) mi = true; n     if (L > xi) L = xi; n     if (R < xi) R = xi; n   } n   if (pl & mi) { n     cout <<  -1  << endl; n     return 0; n   } n   long double rad1, rad2, ans = 1e18; n   for (int i = 0; i < 500; i++) { n     M1 = (2 * L + R) / 3; n     M2 = (L + 2 * R) / 3; n     rad1 = f(M1); n     rad2 = f(M2); n     if (rad1 < rad2) { n       R = M2; n       ans = min(ans, rad1); n     } else { n       L = M1; n       ans = min(ans, rad2); n     } n   } n   cout << setprecision(20) << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n inline void in(int &MAGNUS) { scanf( %d , &MAGNUS); } n inline void out(int MAGNUS) { printf( %d n , MAGNUS); } n inline void in(int &MAGNUS, int &CLAR) { scanf( %d%d , &MAGNUS, &CLAR); } n inline void out(int MAGNUS, int CLAR) { printf( %d %d n , MAGNUS, CLAR); } n inline void inl(long long &LIV) { scanf( %lld , &LIV); } n inline void inl(long long &LIV, long long &MART) { n   scanf( %lld%lld , &LIV, &MART); n } n inline void outl(long long LIV) { printf( %lld n , LIV); } n inline void outl(long long LIV, long long MART) { n   printf( %lld %lld n , LIV, MART); n } n using namespace std; n int main() { n   int N, one, two, twoone = 0; n   in(N); n   in(one, two); n   int ans = 0; n   for (int i = 1; i <= N; i++) { n     int x; n     in(x); n     if (x == 1) { n       if (one > 0) n         one--; n       else { n         if (two > 0) n           two--, twoone++; n         else if (twoone > 0) n           twoone--; n         else n           ans++; n       } n     } else if (x == 2) { n       if (two == 0) n         ans += 2; n       else n         two--; n     } n   } n   out(ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool sBs(const pair<int, int> &a, const pair<int, int> &b) { n   return (a.second < b.second); n } n long long SUMD(long long n); n long long BS(vector<pair<long long, long long> > &PS, long long s, long long e, n              long long ser); n long long MI(long long a, long long m); n long long P[101LL + 1]; n void Sieve(int n = 101LL); n long long Powb(long long b, long long n, long long m); n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   long long q = 1, t; n   cin >> q; n   t = q; n   while (q--) { n     long long i, j, n, m, k, l = 0, r = 0, a = 0, b = 0, c = 0, d = 0, e, g = 1, n                              p, u, v, w, x, y, flag = 1; n     cin >> n >> x; n     long long ans = 0; n     vector<long long> V(n); n     for (i = 0; i < n; i++) cin >> V[i]; n     sort(V.rbegin(), V.rend()); n     for (i = 0; i < n; i++) { n       if (V[i] * (i - l + 1) >= x) { n         ans += 1; n         l = i + 1; n       } n     } n     cout << ans <<   n ; n   } n   return 0; n } n long long Powb(long long b, long long n, long long m) { n   if (n == 0) return 1LL; n   if (n == 1) return b; n   long long temp = Powb(b, n / 2, m); n   if (n % 2 == 0) { n     return (temp * temp) % m; n   } else { n     return (b * ((temp * temp) % m)) % m; n   } n } n long long SUMD(long long n) { n   long long sum = 0; n   while (n > 0) { n     sum += n % 10; n     n = n / 10; n   } n   return sum; n } n long long BS(vector<pair<long long, long long> > &PS, long long s, long long e, n              long long ser) { n   if (s > e) return s; n   long long mid = (s + e) / 2; n   if (PS[mid].first == ser) { n     return mid; n   } else if (PS[mid].first > ser) { n     return BS(PS, s, mid - 1, ser); n   } else n     return BS(PS, mid + 1, e, ser); n } n long long MI(long long a, long long m) { n   long long m0 = m; n   long long y = 0, x = 1; n   if (m == 1) return 0; n   while (a > 1) { n     long long q = a / m; n     long long t = m; n     m = a % m, a = t; n     t = y; n     y = x - q * y; n     x = t; n   } n   if (x < 0) x += m0; n   return x; n } n void Sieve(int n) { n   for (int i = 1; i <= n; i++) P[i] = i; n   for (long long i = 2; i * i <= n; i++) { n     if (P[i] == i) { n       for (long long j = i * i; j <= n; j += i) { n         if (P[j] == j) P[j] = i; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n struct point { n   int x, y, ind; n }; n vector<point> fd[200200]; n vector<point> bd[200200]; n long long out[100100]; n int main() { n   scanf( %d%d%d , &n, &m, &k); n   memset(out, -1, sizeof out); n   for (int i = 0, x, y; i < k; ++i) { n     scanf( %d%d , &x, &y); n     fd[x - y + m].push_back({x, y, i}); n     bd[x + y].push_back({x, y, i}); n   } n   int x = 0, y = 0, dx = 1, dy = 1; n   long long t = 0; n   while (true) { n     if (dx == dy) { n       int l = x - y + m; n       for (int i = 0; i < (int)fd[l].size(); ++i) { n         point &p = fd[l][i]; n         if (out[p.ind] != -1) continue; n         long long dfx = x - p.x; n         out[p.ind] = t + abs(dfx); n       } n     } else { n       int l = x + y; n       for (int i = 0; i < (int)bd[l].size(); ++i) { n         point &p = bd[l][i]; n         if (out[p.ind] != -1) continue; n         long long dfx = x - p.x; n         out[p.ind] = t + abs(dfx); n       } n     } n     int mh, mv; n     if (dx == 1) n       mh = n - x; n     else n       mh = x; n     if (dy == 1) n       mv = m - y; n     else n       mv = y; n     if (mh < mv) { n       if (dx == 1) n         x = n; n       else n         x = 0; n       t += mh; n       y += mh * dy; n       dx *= -1; n     } else if (mh > mv) { n       if (dy == 1) n         y = m; n       else n         y = 0; n       t += mv; n       x += mv * dx; n       dy *= -1; n     } else { n       break; n     } n   } n   for (int i = 0; i < k; ++i) printf( %I64d n , out[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1000000001; n const long long maxg = 4444444444LL; n vector<long long> g; n void recurs(int d, int len, long long z) { n   if (d == len) n     g.push_back(z); n   else { n     recurs(d + 1, len, z * 10 + 4); n     recurs(d + 1, len, z * 10 + 7); n   } n } n long long a[1000]; n long long f[100]; n long long fact(int n) { n   if (n > 50) return inf; n   if (f[n] != 0) return f[n]; n   if (n == 1 || n == 0) return f[n] = 1; n   return f[n] = min(inf, n * min(inf, (fact(n - 1)))); n } n bool good(int a) { n   if (a == 0) return false; n   while (a > 0) { n     if (!(a % 10 == 4 || a % 10 == 7)) return false; n     a /= 10; n   } n   return true; n } n int main() { n   for (int ll = 1; ll <= 9; ll++) { n     recurs(0, ll, 0); n   } n   g.push_back(maxg); n   long long n, k; n   cin >> n >> k; n   if (fact(n) < k) { n     cout << -1 << endl; n     return 0; n   } n   long long p = 1; n   long long m = n - 1; n   while (fact(n - m) + 1 <= k) m--; n   long long s = n - m; n   for (int i = 1; i <= s; i++) a[i] = m + i; n   while (p < k) { n     for (int i = 1;; i++) { n       if (fact(i + 1) + p > k) { n         p += fact(i); n         for (int j = s - i + 1;; j++) { n           if (a[j] > a[s - i]) { n             swap(a[j], a[s - i]); n             break; n           } n         } n         break; n       } n     } n   } n   long long ans = 0; n   for (int i = 0; i < int(g.size()); i++) { n     if (g[i] <= m) ans = i + 1; n   } n   for (int i = 1; i <= s; i++) { n     if (good(i + m) && good(a[i])) ans++; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e3 + 5; n int main() { n   int x1, y1, x2, y2; n   while (~scanf( %d%d%d%d , &x1, &y1, &x2, &y2)) { n     long long x = x2 - x1 + 1; n     long long y = y2 - y1 + 2; n     long long s = x * y / 2 - x / 2; n     printf( %lld n , s); n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long int> facts; n vector<long long int> inv_facts; n long long int c(long long int n, long long int p) { n   if (p < 0 || n < p) return 0; n   return (facts[n] * inv_facts[p]) % 1000000007 * inv_facts[n - p] % 1000000007; n } n long long int pow_mod(long long int x, long long int n) { n   if (n == 0) return 1; n   if (n & 1) return x * pow_mod(x, n - 1) % 1000000007; n   long long int tmp = pow_mod(x, n / 2); n   return tmp * tmp % 1000000007; n } n int main(int argc, char* argv[]) { n   ios_base::sync_with_stdio(false); n   long long int X, Y, N; n   cin >> X >> Y >> N; n   facts.push_back(1); n   inv_facts.push_back(1); n   long long int maxF = X + Y + 1; n   for (long long int n = 1; n <= maxF; ++n) { n     long long int f = facts[n - 1] * n % 1000000007; n     facts.push_back(f); n     inv_facts.push_back(pow_mod(f, 1000000007 - 2)); n   } n   vector<pair<long long int, long long int> > xys; n   for (long long int n = 0; n < N; ++n) { n     long long int x, y; n     cin >> x >> y; n     xys.push_back(make_pair(x - 1, y - 1)); n   } n   xys.push_back(make_pair(X - 1, Y - 1)); n   sort(xys.begin(), xys.end()); n   vector<long long int> dp(N + 1); n   for (long long int n = 0; n <= N; ++n) { n     long long int x = xys[n].first, y = xys[n].second; n     long long int tmp = c(x + y, y); n     for (long long int m = 0; m < N; ++m) { n       long long int xm = xys[m].first, ym = xys[m].second; n       if (xm <= x && ym <= y) n         tmp = (tmp + 1000000007 - n                dp[m] * c(x - xm + y - ym, x - xm) % 1000000007) % n               1000000007; n     } n     dp[n] = tmp; n   } n   cout << dp[N] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000005, md = 998244353; n int n, i, j, k, e, p[N], lmt, len, rt[N], ome[N], rome[N], g[N], h[N], w1[N], n     w2[N], inv[N]; n long long a[N], b[N], w, xxj[65]; n inline void Read(long long &x) { n   char c; n   while ((c = getchar()) <  0  || c >  9 ) n     ; n   x = c -  0 ; n   while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ; n } n void ntt(int a[N], bool t) { n   for (int i = 0; i < len; ++i) n     if (i < rt[i]) swap(a[i], a[rt[i]]); n   for (int l = 2; l <= len; l <<= 1) { n     int m = l >> 1; n     for (int i = 0; i < len; i += l) n       for (int j = 0; j < m; ++j) { n         int w = 1ll * (t ? ome[len / l * j] : rome[len / l * j]) * n                 a[i + j + m] % md; n         a[i + j + m] = (a[i + j] - w + md) % md; n         a[i + j] = (a[i + j] + w) % md; n       } n   } n   if (!t) n     for (int i = 0; i < len; ++i) a[i] = 1ll * a[i] * inv[len] % md; n } n void merge(int l, int r) { n   if (l == r) { n     p[l] = 2; n     return; n   } n   int mid = (l + r) / 2, i; n   merge(l, mid); n   merge(mid + 1, r); n   lmt = 0; n   while ((1 << lmt) <= r - l + 1) ++lmt; n   len = 1 << lmt; n   ome[0] = rome[0] = 1; n   for (i = 1; i < len; ++i) { n     rt[i] = 0; n     for (j = 0; j < lmt; ++j) n       if ((1 << j) & i) rt[i] |= 1 << (lmt - j - 1); n     ome[i] = 1ll * ome[i - 1] * w1[len] % md, n     rome[i] = 1ll * rome[i - 1] * w2[len] % md; n   } n   for (i = 0; i < len; ++i) g[i] = h[i] = 0; n   for (i = l; i <= mid; ++i) g[i - l] = p[i]; n   for (i = mid + 1; i <= r; ++i) h[i - mid - 1] = p[i]; n   ntt(g, true); n   ntt(h, true); n   for (i = 0; i < len; ++i) g[i] = 1ll * g[i] * h[i] % md; n   ntt(g, false); n   for (i = 0; i < len; ++i) { n     g[i + 1] += g[i] / 10; n     g[i] %= 10; n   } n   for (i = l; i <= r; ++i) p[i] = g[i - l]; n } n inline int pw(int a, int b) { n   int rtn = 1; n   while (b) { n     if (b & 1) rtn = 1ll * rtn * a % md; n     a = 1ll * a * a % md; n     b >>= 1; n   } n   return rtn; n } n int main() { n   scanf( %d , &n); n   for (i = 1; i <= n; ++i) { n     Read(a[i]); n     Read(b[i]); n     b[i] ^= a[i]; n     w ^= a[i]; n   } n   e = 0; n   for (i = 1; i <= n; ++i) { n     for (j = 60; j >= 0; --j) n       if ((1ll << j) & b[i]) { n         if (!xxj[j]) { n           xxj[j] = b[i]; n           break; n         } n         b[i] ^= xxj[j]; n       } n     if (b[i] == 0) ++e; n   } n   for (j = 60; j >= 0; --j) n     if ((1ll << j) & w) { n       if (!xxj[j]) { n         printf( 1/1 ); n         return 0; n       } n       w ^= xxj[j]; n     } n   if (n - e == 0) { n     printf( 0/1 ); n     return 0; n   } n   for (i = 1; i <= 2 * (n - e); ++i) { n     w1[i] = pw(3, (md - 1) / i), w2[i] = pw(w1[i], md - 2); n     if (i == 1) n       inv[i] = 1; n     else n       inv[i] = 1ll * inv[md % i] * (md - md / i) % md; n   } n   merge(1, n - e); n   for (i = n - e; p[i] == 0; --i) n     ; n   for (; i >= 2; --i) printf( %d , p[i]); n   printf( %d/ , p[i] - 1); n   for (i = n - e; p[i] == 0; --i) n     ; n   for (; i >= 1; --i) printf( %d , p[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[5005][15], oo = 1e5; n char str[5005]; n int solve(int i, int s) { n   if (str[i] == 0 and s == 2) { n     return 0; n   } else if (str[i] == 0 and s != 2) { n     return oo; n   } else if (~dp[i][s]) { n     return dp[i][s]; n   } else { n     int ans = 0; n     if (s == 0) { n       if (str[i] ==  a ) { n         ans = min(solve(i + 1, s), solve(i + 1, 1)); n       } else { n         ans = min(solve(i + 1, s) + 1, solve(i + 1, 1)); n       } n     } else if (s == 1) { n       if (str[i] ==  b ) { n         ans = min(solve(i + 1, s), solve(i + 1, 2)); n       } else { n         ans = min(solve(i + 1, s) + 1, solve(i + 1, 2)); n       } n     } else if (s == 2) { n       if (str[i] ==  a ) { n         ans = solve(i + 1, s); n       } else { n         ans = solve(i + 1, s) + 1; n       } n     } n     return dp[i][s] = ans; n   } n } n int main() { n   scanf(  %s , str); n   memset(dp, -1, sizeof dp); n   if (str[1] == 0) { n     printf( 1 n ); n   } else { n     printf( %d n , strlen(str) - solve(0, 0)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 5; n int cnt[maxn][26]; n int dif[26]; n int getAns() { n   int cc = 0; n   for (int i = 0; i < 26; ++i) n     if (dif[i]) { n       ++cc; n     } n   return cc; n } n int main() { n   string s; n   cin >> s; n   int len = s.length(); n   for (int i = 1; i <= len; ++i) { n     for (int k = 0; k < 26; ++k) cnt[i][k] = cnt[i - 1][k]; n     ++cnt[i][s[i - 1] -  a ]; n   } n   int q; n   cin >> q; n   while (q--) { n     int l, r; n     cin >> l >> r; n     --l; n     for (int i = 0; i < 26; ++i) dif[i] = cnt[r][i] - cnt[l][i]; n     int tot = getAns(); n     if (tot == 1) { n       if (r - l == 1) n         cout <<  YES  << endl; n       else n         cout <<  NO  << endl; n     } else if (tot == 2) { n       if (s[l] != s[r - 1]) n         cout <<  YES  << endl; n       else n         cout <<  NO  << endl; n     } else { n       cout <<  YES  << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000000007; n inline int add(int a, int b) { n   a += b; n   if (a >= mod) a -= mod; n   return a; n } n inline int mult(int a, int b) { n   long long t = 1ll * a * b; n   if (t >= mod) t %= mod; n   return t; n } n int k, dp[1010][1010]; n int main() { n   scanf( %d , &k); n   dp[1][0] = dp[1][1] = 1; n   for (int p = 1; p < k; p++) { n     for (int i = 0; i <= (p >= 10 ? k : min(k, 1 << p)); i++) { n       for (int j = 0; i + j <= (p >= 10 ? k : min(k, (1 << (p + 1)))); j++) { n         int tmp = mult(dp[p][i], dp[p][j]); n         dp[p + 1][i + j] = add(dp[p + 1][i + j], tmp); n         dp[p + 1][i + j + 1] = add(dp[p + 1][i + j + 1], tmp); n         dp[p + 1][i + j] = add(dp[p + 1][i + j], mult(tmp, mult(i + j, 2))); n         if (i + j) n           dp[p + 1][i + j - 1] = n               add(dp[p + 1][i + j - 1], mult(tmp, mult(i + j, i + j - 1))); n       } n     } n   } n   printf( %d n , dp[k][1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 3e5 + 5; n int a[M], b[M], c, lst[M], sl[M], ans[M]; n struct D { n   int p1, p, s; n }; n queue<D> q; n int read() { n   int s = 0, t = 1; n   char ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) t = -1; n   for (; isdigit(ch); ch = getchar()) s = s * 10 + ch -  0 ; n   return s * t; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) a[i] = read(); n   for (int i = 1; i <= n; i++) b[i] = read(); n   int h = n; n   q.push({n, n, 0}); n   while (!q.empty()) { n     int p1 = q.front().p1, p = q.front().p, s = q.front().s; n     q.pop(); n     if (!p) { n       c = s; n       break; n     } n     for (int i = h - 1; i >= p - a[p]; i--) n       lst[i] = p1, q.push({i, i + b[i], s + 1}), h = i; n   } n   if (!c) return printf( -1 ), 0; n   printf( %d n , c); n   for (int i = 1, x = 0; i <= c; i++, x = lst[x]) ans[i] = x; n   for (int i = c; i; i--) printf( %d  , ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n const int E4 = 1e4 + 2; n const int E5 = 1e5 + 2; n const int E6 = 1e6 + 2; n const int MOD = 1e9 + 7; n const int INF = 1e9 + 8; n const double eps = 1e-12; n const double pi = 3.14159265359; n const long long INFL = 1ll * INF * INF; n void getTime(double sub = 0.0) { n   cout <<  Time :   << fixed << clock() * 1.0 / CLOCKS_PER_SEC - sub <<   n ; n } n double getClock() { return clock() * 1.0 / CLOCKS_PER_SEC; } n long long pw(long long a, long long n, long long K = MOD) { n   return (n ? (pw(((a % K) * (a % K)) % K, n / 2ll, K) * n                ((n & 1ll) ? (a % K) : 1ll)) % n                   K n             : 1ll); n } n int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); } n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n int lcm(int a, int b) { return a * (b / gcd(a, b)); } n long long lcm(long long a, long long b) { return (b / gcd(a, b)) * a; } n int fact(int n) { return n > 0 ? n * fact(n - 1) : 1; } n long long fact(long long n) { return n > 0 ? n * fact(n - 1) : 1; } n int choose(int k, int n) { n   if (k > n) return 0; n   k = (n - k > k ? n - k : k); n   if (k == 0) return 1; n   int R = n; n   for (int i = 2; i <= k; i++) { n     R = R * (n - i + 1) / i; n   } n   return R; n } n long long choose(long long k, long long n) { n   if (k > n) return 0; n   k = (n - k > k ? n - k : k); n   if (k == 0) return 1; n   int R = n; n   for (int i = 2; i <= k; i++) { n     R = R * (n - i + 1) / i; n   } n   return R; n } n int lowbit(int m) { return m & (-m); } n int hibit(int m) { n   for (int i = 30; i >= 0; i--) n     if ((1 << i) & m) return i; n   return 0; n } n long long hibit(long long m) { n   for (int i = 62; i >= 0; i--) n     if ((1ll << i) & m) return i; n   return 0; n } n int getbit(int x, int b) { return (x >> b) & 1; } n long long getbit(long long x, int b) { return (x >> b) & 1; } n int setbit(int x, int b) { return x | (1 << b); } n void _setbit(int &x, int b) { x = setbit(x, b); } n long long setbit(long long x, int b) { return x | (1ll << b); } n void _setbit(long long &x, int b) { x = setbit(x, b); } n int unsetbit(int x, int b) { return x & ((~0) - (1 << b)); } n void _unsetbit(int &x, int b) { x = unsetbit(x, b); } n int bitcnt(int x) { n   x = x - ((x >> 1) & 0x55555555); n   x = (x & 0x33333333) + ((x >> 2) & 0x33333333); n   return ((x + (x >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; n } n long long bitcnt(long long x) { n   int p1 = (x >> 32) & ((1ll << 32) - 1); n   int p2 = x & ((1ll << 32) - 1); n   return bitcnt(p1) + bitcnt(p2); n } n string bin(int x, int len = -1) { n   if (len == -1) { n     len = hibit(x) + 1; n   } n   string res =   ; n   for (int i = len - 1; i >= 0; i--) res.push_back(getbit(x, i) +  0 ); n   return res; n } n string bin(long long x, int len = -1) { n   if (len == -1) { n     len = hibit(x) + 1; n   } n   string res =   ; n   for (int i = len - 1; i >= 0; i--) res.push_back(getbit(x, i) +  0 ); n   return res; n } n int zerocnt(int x) { return hibit(x) - bitcnt(x) + 1; } n int zerocnt(long long x) { return hibit(x) - bitcnt(x) + 1; } n struct IO { n   IO operator>>(int &n) const { n     n = 0; n     bool sign = 0; n     int a = getchar(); n     while (a <  0  || a >  9 ) { n       if (a ==  - ) { n         sign = 1; n         a = getchar(); n         break; n       } n       a = getchar(); n     } n     while (a >=  0  && a <=  9 ) { n       n = (n << 1) + (n << 3) + a -  0 ; n       a = getchar(); n     } n     if (sign) n = ~(n - 1); n     return *this; n   } n   IO operator>>(long long &n) { n     n = 0; n     bool sign = 0; n     char c = getchar(); n     while (c <  0  || c >  9 ) { n       if (c ==  - ) sign = true; n       c = getchar(); n     } n     while (c >=  0  && c <=  9 ) { n       n = n * 10 + c - 48; n       c = getchar(); n     } n     if (sign) n = ~(n - 1); n     return *this; n   } n   IO operator>>(double &x) const { n     scanf( %lf , &x); n     return *this; n   } n   IO operator>>(char &x) const { n     do { n       x = getchar(); n     } while (x ==     || x ==   n ); n     return *this; n   } n   IO operator>>(string &s) const { n     cin >> s; n     return *this; n   } n   IO operator<<(const int x) const { n     printf( %d , x); n     return *this; n   } n   IO operator<<(const double x) const { n     printf( %lf , x); n     return *this; n   } n   IO operator<<(const char x) const { n     putchar(x); n     return *this; n   } n   IO operator<<(const long long x) const { n     cout << x; n     return *this; n   } n   IO operator<<(string x) { n     printf( %s , (x.c_str())); n     return *this; n   } n } in, out; n namespace Input { n template <template <typename, typename...> class Container, typename T> n void cinv(Container<T> &a, int n) { n   for (int i = 0; i < n; i++) { n     T t; n     cin >> t; n     a.push_back(t); n   } n } n template <typename T> n void cinv(T *ptr, int len) { n   for (int i = 0; i < len; i++) { n     in >> *(ptr + i); n   } n } n template <typename T> n void cinv(T A, int n, int m) { n   for (int i = 0; i < n; i++) { n     cinv(A[i], m); n   } n } n }  // namespace Input n namespace Output { n void split(char A) { n   if (A !=  0 ) { n     putchar(A); n   } n } n template <typename T> n void Print(T A, char sp =  0 ) { n   out << A; n   split(sp); n } n template <typename T1, typename T2> n void Print(pair<T1, T2> A, char sp =  0 ) { n   cout <<  (  << A.first <<  ,  << A.second <<  ) ; n   split(sp); n } n template <typename T> n void Print(T A[], int len, char sp =    ) { n   for (int i = 0; i < len; i++) { n     out << A[i]; n     split(sp); n   } n } n template <typename T> n void Print(T *A, int n, int m, char nsp =    , char sp =   n ) { n   for (int i = 0; i < n; i++) { n     Print(A[i], m, nsp); n     split(sp); n   } n } n template <template <typename, typename...> class Container, typename T> n void Print(Container<T> C, char sp =    ) { n   for (auto i : C) { n     Print(i); n     split(sp); n   } n } n template <typename T> n void Print(stack<T> A, char sp =    ) { n   while (A.size()) { n     Print(A.top()); n     split(sp); n     A.pop(); n   } n } n template <template <typename, typename...> class Container, typename T1, n           typename T2> n void Print(Container<T1, T2> C, char sp =    ) { n   for (auto i : C) { n     Print(i); n     split(sp); n   } n } n template <typename T> n void Printl(T A) { n   Print(A,   n ); n } n }  // namespace Output n using namespace Output; n using namespace Input; n int x; n int o; n int n; n int e; n int r; n int z; n int main() { n   string s; n   cin >> x >> s; n   for (auto i : s) { n     if (i ==  o ) { n       o++; n     } n     if (i ==  n ) { n       n++; n     } n     if (i ==  e ) { n       e++; n     } n     if (i ==  r ) { n       r++; n     } n     if (i ==  z ) { n       z++; n     } n   } n   for (int i = 0; i < n; i++) { n     cout << 1 <<    ; n   } n   for (int i = 0; i < z; i++) { n     cout << 0 <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> dp; n int l[305], c[305]; n int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> l[i]; n   for (int i = 0; i < n; i++) cin >> c[i]; n   dp[0] = 0; n   for (int i = 0; i < n; i++) { n     for (auto x : dp) { n       int a = gcd(x.first, l[i]); n       if (dp.count(a)) n         dp[a] = min(dp[a], x.second + c[i]); n       else n         dp[a] = x.second + c[i]; n     } n   } n   if (dp.count(1)) n     cout << dp[1] << endl; n   else n     cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, c, b, ans = 0; n   cin >> n; n   int a[n + 1]; n   for (int i = 1; i <= n - 1; i++) cin >> a[i]; n   cin >> c >> b; n   for (int i = c; i <= b - 1; i++) ans += a[i]; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n using uint = unsigned int; n using ll = long long; n using ull = unsigned long long; n constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } n int bsr(int x) { return 31 - __builtin_clz(x); } n template <class T> n using V = vector<T>; n template <class T> n using VV = V<V<T>>; n template <class T> n T pow(T x, ll n) { n   T r = 1; n   while (n) { n     if (n & 1) r *= x; n     x *= x; n     n >>= 1; n   } n   return r; n } n template <uint MD> n struct ModInt { n   uint v; n   ModInt() : v{0} {} n   ModInt(ll v) : v{normS(v % MD + MD)} {} n   static uint normS(const uint &x) { return (x < MD) ? x : x - MD; }; n   static ModInt make(const uint &x) { n     ModInt m; n     m.v = x; n     return m; n   } n   ModInt operator+(const ModInt &r) const { return make(normS(v + r.v)); } n   ModInt operator-(const ModInt &r) const { return make(normS(v + MD - r.v)); } n   ModInt operator*(const ModInt &r) const { return make((ull)v * r.v % MD); } n   ModInt &operator+=(const ModInt &r) { return *this = *this + r; } n   ModInt &operator-=(const ModInt &r) { return *this = *this - r; } n   ModInt &operator*=(const ModInt &r) { return *this = *this * r; } n   static ModInt inv(const ModInt &x) { return pow(ModInt(x), MD - 2); } n }; n using Mint = ModInt<TEN(9) + 7>; n const int MD = 1001001; n int factor[MD]; n void first() { n   fill(begin(factor), end(factor), -1); n   for (int i = 2; i < MD; i++) { n     if (factor[i] != -1) continue; n     for (int j = i; j < MD; j += i) { n       factor[j] = i; n     } n   } n } n int main() { n   first(); n   V<int> id2v[300]; n   map<V<int>, int> vs; n   int id[MD]; n   for (int i = 1; i < MD; i++) { n     map<int, int> mp; n     int x = i; n     while (factor[x] != -1) { n       mp[factor[x]]++; n       x /= factor[x]; n     } n     V<int> v; n     for (auto p : mp) { n       v.push_back(p.second); n     } n     sort(begin(v), end(v)); n     if (vs.count(v)) { n       id[i] = vs[v]; n     } else { n       int nid = int(vs.size()); n       vs[v] = nid; n       id[i] = nid; n       id2v[nid] = v; n     } n   } n   int C = vs.size(); n   static Mint to1[MD][25], to0[MD][25]; n   to0[0][0] = 1; n   for (int i = 1; i < 30; i++) { n     to1[0][i] = 1; n   } n   for (int i = 1; i < MD; i++) { n     Mint sm0, sm1; n     for (int j = 0; j < 25; j++) { n       sm0 += to0[i - 1][j]; n       sm1 += to1[i - 1][j]; n       to0[i][j] = sm0; n       to1[i][j] = sm1; n     } n   } n   int q; n   scanf( %d , &q); n   for (int i = 0; i < q; i++) { n     int r, n; n     scanf( %d %d , &r, &n); n     V<int> v = id2v[id[n]]; n     Mint co[11]; n     co[0] = 1; n     int nw = 1; n     for (int d : v) { n       for (int i = nw; i >= 0; i--) { n         co[i] = co[i] * to0[r][d]; n         if (i) co[i] += co[i - 1] * to1[r][d]; n       } n       nw++; n     } n     Mint ans = 0; n     for (int i = 0; i < 11; i++) { n       ans += co[i] * Mint(1 << i); n     } n     printf( %d n , ans.v); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cross(const complex<int>& a, const complex<int>& b) { n   return a.real() * b.imag() - a.imag() * b.real(); n } n int hypot2(const complex<int>& a) { n   return a.real() * a.real() + a.imag() * a.imag(); n } n int N; n vector<complex<int> > pt; n vector<complex<int> > hull(const vector<complex<int> >& p) { n   int n = p.size(), k = 0; n   if (n < 3) return p; n   vector<complex<int> > h(2 * n); n   for (int i = 0; i < n; ++i) { n     while (k >= 2 && cross(h[k - 1] - h[k - 2], p[i] - h[k - 2]) <= 0) --k; n     h[k++] = p[i]; n   } n   for (int i = n - 2, e = k + 1; i >= 0; --i) { n     while (k >= e && cross(h[k - 1] - h[k - 2], p[i] - h[k - 2]) <= 0) --k; n     h[k++] = p[i]; n   } n   h.resize(k); n   h.pop_back(); n   return h; n } n bool with_one(const complex<int>& o, int m) { n   vector<complex<int> > p; n   copy_if(pt.begin(), pt.end(), back_inserter(p), n           [&](const complex<int>& a) { return hypot2(a - o) >= m; }); n   auto h = hull(p); n   switch (h.size()) { n     case 0: n     case 1: n       return false; n     case 2: n       return hypot2(h[1] - h[0]) >= m; n   } n   int n = h.size(); n   auto nx = [&](int i) { return i + 1 == n ? 0 : i + 1; }; n   auto cal = [&](int i) { return h[nx(i)] - h[i]; }; n   for (int i = 0, j = 0; i < n; ++i) { n     while (cross(cal(i), cal(j)) >= 0) { n       j = nx(j); n       if (hypot2(h[j] - h[i]) >= m) return true; n     } n   } n   return false; n } n bool ok(int m) { n   for (const complex<int>& p : pt) { n     if (with_one(p, m)) return true; n   } n   return false; n } n int main() { n   cout.precision(20); n   cout << fixed; n   cin >> N; n   for (int i = 0, x, y; i < N; ++i) { n     cin >> x >> y; n     pt.push_back({x, y}); n   } n   sort(pt.begin(), pt.end(), [](const complex<int>& a, const complex<int>& b) { n     return a.real() < b.real() || a.real() == b.real() && a.imag() < b.imag(); n   }); n   int l = 0, h = 1e9; n   while (l + 1 < h) { n     int m = (l + h) / 2; n     if (ok(m)) n       l = m; n     else n       h = m; n   } n   cout << sqrt(l) / 2 <<   n ; n   return 0; n } n


#include<bits/stdc++.h> n #define rb(a,b,c) for(int a=b;a<=c;++a) n #define rl(a,b,c) for(int a=b;a>=c;--a) n #define LL long long n #define IT iterator n #define PB push_back n #define II(a,b) make_pair(a,b) n #define FIR first n #define SEC second n #define FREO freopen( check.out , w ,stdout) n #define rep(a,b) for(int a=0;a<b;++a) n #define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) n #define random(a) rng()%a n #define ALL(a) a.begin(),a.end() n #define POB pop_back n #define ff fflush(stdout) n #define fastio ios::sync_with_stdio(false) n #define check_min(a,b) a=min(a,b) n #define check_max(a,b) a=max(a,b) n using namespace std; n //inline int read(){ n //    int x=0; n //    char ch=getchar(); n //    while(ch< 0 ||ch> 9 ){ n //        ch=getchar(); n //    } n //    while(ch>= 0 &&ch<= 9 ){ n //        x=(x<<1)+(x<<3)+(ch^48); n //        ch=getchar(); n //    } n //    return x; n //} n const int INF=0x3f3f3f3f; n typedef pair<int,int> mp; n /*} n */ n const int MAXN=505; n int t,n,a[MAXN<<1][MAXN]; n bool era[MAXN<<1],cho[MAXN<<1]; n int cnt[MAXN][MAXN]; n int fa[MAXN<<1]; n int root(int x){ n  return fa[x]=(x==fa[x]? x:root(fa[x])); n } n vector<int> g[MAXN<<1]; n bool col[MAXN<<1]; n bool vis[MAXN<<1]; n void dfs(int now){ n  vis[now]=1; n  for(auto it:g[now]){ n   if(!vis[it]){ n    col[it]=col[now]^1; n    dfs(it); n   } n  } n } n void solve(){ n  scanf( %d ,&n); n  rb(i,1,n*2) rb(j,1,n) scanf( %d ,&a[i][j]); n  memset(era,0,sizeof(era)); n  memset(vis,0,sizeof(vis)); n  memset(cho,0,sizeof(cho)); n  memset(cnt,0,sizeof(cnt)); n  memset(col,0,sizeof(col)); n  rb(i,1,n*2) rb(j,1,n) cnt[j][a[i][j]]++; n  rb(T,1,n){ n   mp Tmp=II(-1,-1); n   rb(j,1,n){ n    rb(k,1,n) if(cnt[j][k]==1){ n     Tmp=II(j,k); n     break; n    } n    if(Tmp.FIR!=-1) break; n   } n   if(Tmp.FIR==-1) break; n   int x; n   rb(j,1,2*n){ n    if(!era[j]&&a[j][Tmp.FIR]==Tmp.SEC){ n     x=j; n     break; n    } n   } n   cho[x]=1; n   rb(j,1,2*n) if(!era[j]&&j!=x){ n    rb(k,1,n) if(j!=x&&a[j][k]==a[x][k]) era[j]=1; n    if(era[j]){ n     rb(k,1,n) cnt[k][a[j][k]]--; n    } n   } n   rb(k,1,n) cnt[k][a[x][k]]--; n  } n  rb(i,1,n*2) g[i].clear(),fa[i]=i; n  rb(i,1,n*2) era[i]|=cho[i]; n  rb(i,1,n*2) if(!era[i]) rb(j,i+1,n*2) if(!era[j]) { n   bool E=0; n   rb(k,1,n) if(a[i][k]==a[j][k]){ n    E=1; n    break; n   } n   if(E){ n    g[i].PB(j); n    g[j].PB(i); n    fa[root(i)]=root(j); n   } n  } n  rb(i,1,n*2) if(!era[i]&&!vis[i]) dfs(i); n  int ans=1; n  vector<int> res; n  rb(i,1,n*2){ n   if(!era[i]&&col[i]==0){ n    res.PB(i); n   } n  } n  rb(i,1,n*2) if(!era[i]&&root(i)==i) ans=(ans+ans)%998244353; n  rb(i,1,2*n) if(cho[i]) res.PB(i); n  printf( %d n ,ans); n  for(auto it:res){ n   printf( %d  ,it); n  } n  puts(  ); n } n int main(){ n  scanf( %d ,&t); n  while(t--) solve(); n  return 0; n }


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


#include <bits/stdc++.h> n using namespace std; n int N, K; n int a[2210], b[2210]; n int cnt[2210]; n long long func(void) { n   int i, j = N; n   int aans = -1, bans = -1, bid = -1; n   long long best = (1ll << 60); n   for (i = N - 1; i >= 0; i--) { n     while (j > i || (j > 0 && cnt[j - 1] > 0)) { n       j--; n       if (b[j] > 0 && (bid == -1 || b[j] < b[bid])) bid = j; n     } n     if (a[i] > 0 && bid != -1 && a[i] + b[bid] < best) { n       best = a[i] + b[bid]; n       aans = i; n       bans = bid; n     } n   } n   if (aans < bans) { n     for (i = aans; i < bans; i++) cnt[i]++; n   } else { n     for (i = aans - 1; i >= bans; i--) cnt[i]--; n   } n   a[aans] = b[bans] = 0; n   return best; n } n int main(void) { n   int i; n   cin >> N >> K; n   for ((i) = 0; (i) < (int)(N); (i)++) cin >> a[i]; n   for ((i) = 0; (i) < (int)(N); (i)++) cin >> b[i]; n   long long ans = 0; n   for ((i) = 0; (i) < (int)(K); (i)++) ans += func(); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e5 + 2; n const int mod = 998244353; n void inc(int& x, const int& y) { (x += y) >= mod ? x -= mod : 0; } n void dec(int& x, const int& y) { x < y ? x += mod - y : x -= y; } n void cmax(int& x, const int& y) { x = x > y ? x : y; } n int n, k, m; n int l[N], r[N], x[N], pos[N], a[N], f[N]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n >> k >> m; n   for (int i = 1; i <= m; i++) cin >> l[i] >> r[i] >> x[i]; n   int ans = 1; n   for (int p = 0; p <= k - 1; p++) { n     for (int i = 1; i <= n + 1; i++) pos[i] = a[i] = 0; n     for (int i = 1; i <= m; i++) n       if (x[i] >> p & 1) n         ++a[l[i]], --a[r[i] + 1]; n       else n         cmax(pos[r[i] + 1], l[i]); n     for (int i = 2; i <= n + 1; i++) a[i] += a[i - 1], cmax(pos[i], pos[i - 1]); n     f[0] = 1; n     int sum = 1, l = 0; n     for (int i = 1; i <= n + 1; i++) { n       while (l < pos[i]) dec(sum, f[l]), f[l++] = 0; n       f[i] = a[i] ? 0 : sum, inc(sum, f[i]); n     } n     ans = 1ll * ans * f[n + 1] % mod; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void Solution() { n   int n, k; n   cin >> n >> k; n   int a[n]; n   vector<int> v; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (5 - a[i] >= k) { n       v.push_back(a[i]); n     } n   } n   cout << v.size() / 3 << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   Solution(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, x, y; n long long r; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long binsearch(long long i, long long j, long long w, long long m) { n   if (i == j) { n     if (i * w <= a && i * m <= b) return i; n     return -1; n   } n   if (i == j - 1) { n     if (j * w <= a && j * m <= b) return j; n     if (i * w <= a && i * m <= b) return i; n     return -1; n   } n   long long mid = (i + j) / 2; n   if (mid * w <= a && mid * m <= b) return binsearch(mid, j, w, m); n   return binsearch(i, mid - 1, w, m); n } n int main() { n   cin >> a >> b >> x >> y; n   r = x / y; n   long long h = gcd(x, y); n   long long k = binsearch(0, 2000000000, x / h, y / h); n   if (k == -1) { n     cout << 0 <<     << 0; n     return 0; n   } n   cout << k * (x / h) <<     << k * (y / h); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct point { n   int x, y; n }; n int n, k, l[1000002], r[1000002]; n point a[1000002]; n bool cmp(point a, point b) { return a.x < b.x; } n void nhap() { n   cin >> n >> k; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i].x; n     l[i] = 0; n     r[i] = 0; n   } n   for (int i = 1; i <= n; ++i) cin >> a[i].y; n   sort(a + 1, a + n + 1, cmp); n } n void sol1() { n   int cur = 1, st = 1; n   l[1] = 1; n   for (int i = 2; i <= n; ++i) { n     if (a[i].x - a[st].x <= k) n       cur++; n     else { n       while (a[i].x - a[st].x > k) { n         ++st; n       } n       cur = i - st + 1; n     } n     l[i] = max(l[i - 1], cur); n   } n } n void sol2() { n   int cur = 1, st = n; n   r[n] = 1; n   for (int i = n - 1; i >= 1; --i) { n     if (a[st].x - a[i].x <= k) n       cur++; n     else { n       while (a[st].x - a[i].x > k) --st; n       cur = st - i + 1; n     } n     r[i] = max(r[i + 1], cur); n   } n } n void xuly() { n   int kq = 0; n   for (int i = 1; i < n; ++i) kq = max(kq, l[i] + r[i + 1]); n   if (kq == 0) ++kq; n   cout << kq <<   n ; n } n int main(int argc, const char* argv[]) { n   int t; n   cin >> t; n   for (int i = 1; i <= t; ++i) { n     nhap(); n     sol1(); n     sol2(); n     xuly(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void fre() { n   freopen( c://test//input.in ,  r , stdin); n   freopen( c://test//output.out ,  w , stdout); n } n template <class T1, class T2> n inline void gmax(T1 &a, T2 b) { n   if (b > a) a = b; n } n template <class T1, class T2> n inline void gmin(T1 &a, T2 b) { n   if (b < a) a = b; n } n const int N = 1010, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f; n int n; n int a[N], b[N]; n int main() { n   while (~scanf( %d , &n)) { n     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n     sort(a + 1, a + n + 1); n     int p = 1; n     for (int i = 1; i <= n; i += 2) { n       b[i] = a[p++]; n     } n     for (int i = 2; i <= n; i += 2) { n       b[i] = a[p++]; n     } n     bool flag = 1; n     for (int i = 1; i <= n; i += 2) { n       if (i < n) { n         if (b[i] > b[i + 1]) flag = 0; n       } n       if (i > 1) { n         if (b[i] > b[i - 1]) flag = 0; n       } n     } n     if (!flag) n       puts( Impossible ); n     else { n       for (int i = 1; i <= n; ++i) printf( %d  , b[i]); n       puts(  ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5; n int n, k, a[N]; n long long seg[4 * N + 4], dp[N + 1][12]; n void update(int p, int l, int r, int indx, long long val) { n   if (l == r) { n     seg[p] = val; n     return; n   } n   int mid = l + (r - l) / 2; n   if (indx <= mid) n     update(p * 2, l, mid, indx, val); n   else n     update(p * 2 + 1, mid + 1, r, indx, val); n   seg[p] = seg[p * 2] + seg[p * 2 + 1]; n } n long long get(int p, int l, int r, int a, int b) { n   if (l >= a && r <= b) { n     return seg[p]; n   } n   if (l > b || r < a) { n     return 0; n   } n   int mid = l + (r - l) / 2; n   return get(p * 2, l, mid, a, b) + get(p * 2 + 1, mid + 1, r, a, b); n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; ++i) scanf( %d , a + i); n   for (int i = 0; i <= N; ++i) dp[i][1] = 1; n   for (int j = 2; j <= k + 1; ++j) { n     memset(seg, 0, sizeof seg); n     for (int i = 0; i < n; ++i) { n       dp[i][j] = get(1, 0, n - 1, 1, a[i] - 1); n       update(1, 0, n - 1, a[i], dp[i][j - 1]); n     } n   } n   long long ans = 0; n   for (int i = 0; i < n; ++i) { n     ans += dp[i][k + 1]; n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n const long long INF = 0x3f3f3f3f3f3f3f3f; n const long long llinf = (1LL << 61); n const int inf = (1 << 30); n const int nmax = 1e3 + 50; n const int mod = 1e9 + 7; n using namespace std; n int n, m, i, j, a[nmax][nmax], aa[nmax][nmax], b[nmax][nmax], bb[nmax][nmax], n     ca[nmax][nmax], cb[nmax][nmax], mn; n char c[nmax][nmax]; n vector<pair<pair<int, int>, int> > ans; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cerr.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (i = 1; i <= n; i++) n     for (j = 1; j <= m; j++) cin >> c[i][j]; n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= m; j++) n       if (c[i][j] ==  * ) a[i][j] = a[i][j - 1] + 1; n     for (j = m; j >= 1; j--) n       if (c[i][j] ==  * ) aa[i][j] = aa[i][j + 1] + 1; n   } n   for (i = 1; i <= m; i++) { n     for (j = 1; j <= n; j++) n       if (c[j][i] ==  * ) b[j][i] = b[j - 1][i] + 1; n     for (j = n; j >= 1; j--) n       if (c[j][i] ==  * ) bb[j][i] = bb[j + 1][i] + 1; n   } n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= m; j++) { n       if (c[i][j] ==  * ) { n         mn = min(min(a[i][j], aa[i][j]), min(b[i][j], bb[i][j])); n         if (mn > 1) { n           ca[i][j - mn + 1]++; n           ca[i][j + mn]--; n           cb[i - mn + 1][j]++; n           cb[i + mn][j]--; n           ans.push_back({{i, j}, mn - 1}); n         } n       } n     } n   } n   for (i = 1; i <= n; i++) n     for (j = 1; j <= m; j++) ca[i][j] += ca[i][j - 1]; n   for (i = 1; i <= m; i++) n     for (j = 1; j <= n; j++) cb[j][i] += cb[j - 1][i]; n   for (i = 1; i <= n; i++) n     for (j = 1; j <= m; j++) n       if (c[i][j] ==  *  && !ca[i][j] && !cb[i][j]) n         return cout << -1 << endl, 0; n   cout << ans.size() << endl; n   for (i = 0; i < ans.size(); i++) n     cout << ans[i].first.first <<     << ans[i].first.second <<     n          << ans[i].second << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class trio { n  public: n   long long first, second, third; n }; n long long gcdExtended(long long a, long long b, long long *x, long long *y) { n   if (a == 0) { n     *x = 0, *y = 1; n     return b; n   } n   long long x1, y1; n   long long gcd = gcdExtended(b % a, a, &x1, &y1); n   *x = y1 - (b / a) * x1; n   *y = x1; n   return gcd; n } n long long modInverse(long long a, long long m) { n   long long x, y; n   long long g = gcdExtended(a, m, &x, &y); n   long long res = (x % m + m) % m; n   return res; n } n long long power(long long x, long long y) { n   long long ans = 1, second = x; n   while (y) { n     if (y & 1) { n       ans *= second; n       ans %= 1000000007; n     } n     second *= second; n     second %= 1000000007; n     y >>= 1; n   } n   return ans; n } n const long long N = 51; n long long dp1[N]; n long long dp3[N]; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   __int128 val = 1; n   dp1[0] = 1; n   dp1[1] = 1; n   dp1[2] = 1; n   for (long long i = 3; i < N; ++i) { n     val *= (i - 2); n     val = min(val, (__int128)1000000000000000001); n     dp1[i] = val; n   } n   dp3[0] = 1; n   dp3[1] = 1; n   for (long long i = 2; i < N; ++i) { n     val = 0; n     for (long long j = 1; j < i + 1; ++j) { n       val += (__int128)dp3[i - j] * dp1[j]; n       val = min(val, (__int128)1000000000000000001); n     } n     dp3[i] = val; n   } n   long long third; n   cin >> third; n   while (third--) { n     long long n, k; n     cin >> n >> k; n     long long arr[N] = {0}; n     if (dp3[n] < k) { n       cout << -1 <<   n ; n       continue; n     } n     for (long long i = 1; i <= n;) { n       long long len, left, st; n       __int128 count; n       for (long long j = i; j <= n; ++j) { n         len = j - i + 1; n         left = n - i - len + 1; n         st = j; n         count = (__int128)dp1[len] * dp3[left]; n         count = min(count, (__int128)1000000000000000001); n         if (count < k) { n           k -= (count); n         } else { n           break; n         } n       } n       arr[i] = st; n       set<long long> available; n       for (long long j = i; j < i + len; ++j) { n         available.insert(j); n       } n       available.erase(st); n       for (long long j = i + 1; j < i + len; ++j) { n         if (j == i + len - 1) { n           arr[j] = *(available.begin()); n           break; n         } n         for (auto it : available) { n           long long cur = it; n           while (cur != j && cur) { n             cur = arr[cur]; n           } n           if (cur == j) continue; n           count = (__int128)dp1[len - (j - i)] * dp3[left]; n           count = min(count, (__int128)1000000000000000001); n           if (count < k) { n             k -= (count); n           } else { n             arr[j] = it; n             break; n           } n         } n         available.erase(arr[j]); n       } n       i += len; n     } n     for (long long i = 1; i < n + 1; ++i) { n       cout << arr[i] <<    ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void checkmin(T &a, T b) { n   if (b < a) a = b; n } n template <class T> n inline void checkmax(T &a, T b) { n   if (b > a) a = b; n } n int cond = (long long)1; n void _main() { n   int n, w, m; n   scanf( %d%d%d , &n, &w, &m); n   int guests = m; n   int usedbottles = 0; n   int botid = 1; n   int fuel = m; n   int used = 0; n   bool ok = 1; n   vector<vector<pair<int, int> > > sol; n   for (int i = (0); i < (m); ++i) { n     int needfuel = n; n     vector<pair<int, int> > result; n     while (needfuel > 0) { n       if (fuel > 0) { n         int use = min(fuel, needfuel); n         result.push_back(pair<int, int>(botid, use)); n         fuel -= use; n         needfuel -= use; n         ++used; n         if (used > 2) ok = 0; n         if (fuel == 0) { n           botid++; n           fuel = m; n           used = 0; n         } n       } else n         assert(0); n     } n     sol.push_back(result); n   } n   if (!ok) cout <<  NO  << endl; n   cout.precision(6); n   if (ok) { n     cout <<  YES  << endl; n     for (int i = (0); i < (m); ++i) { n       for (int j = (0); j < ((int)(sol[i]).size()); ++j) { n         if (j) cout <<    ; n         long double myfuel = (long double)sol[i][j].second * w / m; n         cout << fixed << sol[i][j].first <<     << myfuel; n       } n       cout << endl; n     } n   } n } n int main(int argc, char **argv) { n   string p =  ../gcj/source/  + string(  ) + argv[0][strlen(argv[0]) - 1]; n   for (int i = (0); i < (argc); ++i) n     if (strcmp(argv[i],  1n ) == 0) { n       freopen( 1.in ,  r , stdin); n     } n   for (int i = (0); i < (argc); ++i) n     if (strcmp(argv[i],  2n ) == 0) { n       freopen( 2.in ,  r , stdin); n     } n   for (int i = (0); i < (argc); ++i) n     if (strcmp(argv[i],  3n ) == 0) { n       freopen( 3.in ,  r , stdin); n     } n   for (int i = (0); i < (argc); ++i) n     if (strcmp(argv[i],  4n ) == 0) { n       freopen( 4.in ,  r , stdin); n     } n   for (int i = (0); i < (argc); ++i) n     if (strcmp(argv[i],  5n ) == 0) { n       freopen( 5.in ,  r , stdin); n     } n   for (int i = (0); i < (argc); ++i) n     if (strcmp(argv[i],  s0 ) == 0) { n       freopen((p +  -small-0.in ).c_str(),  r , stdin); n       freopen((p +  -small-0.out ).c_str(),  w , stdout); n     } n   for (int i = (0); i < (argc); ++i) n     if (strcmp(argv[i],  s1 ) == 0) { n       freopen((p +  -small-1.in ).c_str(),  r , stdin); n       freopen((p +  -small-1.out ).c_str(),  w , stdout); n     } n   for (int i = (0); i < (argc); ++i) n     if (strcmp(argv[i],  s2 ) == 0) { n       freopen((p +  -small-2.in ).c_str(),  r , stdin); n       freopen((p +  -small-2.out ).c_str(),  w , stdout); n     } n   for (int i = (0); i < (argc); ++i) n     if (strcmp(argv[i],  l0 ) == 0) { n       freopen((p +  -large-0.in ).c_str(),  r , stdin); n       freopen((p +  -large-0.out ).c_str(),  w , stdout); n     } n   for (int i = (0); i < (argc); ++i) n     if (strcmp(argv[i],  q ) == 0) cond = 1 << 30; n   _main(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, x; n int a[255]; n long long dp[255][255][255]; n int main() { n   cin >> n >> k >> x; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i <= n; i++) n     for (int j = 0; j <= k; j++) { n       for (int p = 0; p <= x; p++) { n         dp[i][j][p] = -LLONG_MAX; n       } n     } n   dp[0][1][0] = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 1; j <= k; j++) n       for (int choose = 0; choose <= x; choose++) { n         if (dp[i][j][choose] == -LLONG_MAX) continue; n         if (j != k) { n           dp[i + 1][j + 1][choose] = n               max(dp[i + 1][j + 1][choose], dp[i][j][choose]); n         } n         dp[i + 1][1][choose + 1] = n             max(dp[i + 1][1][choose + 1], dp[i][j][choose] + a[i]); n       } n   } n   long long res = -LLONG_MAX; n   for (int i = 0; i <= k; i++) res = max(res, dp[n][i][x]); n   if (res == -LLONG_MAX) res = -1; n   cout << res; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 11, mod = 998244353; n int ans, n, k, blo, bel[N], f[N], g[N], a[N], L[N], R[N], las[N], bef[N], n     lim[N], sum[411][N], Sum[411]; n inline void inc(int &x, int y) { n   x += y; n   if (x >= mod) x -= mod; n } n inline void deal(int l, int r, int x) { n   int o = bel[l]; n   for (register int i = l; i <= r; ++i) { n     if (f[i] <= lim[o]) inc(Sum[o], mod - g[i - 1]); n     inc(sum[o][f[i]], mod - g[i - 1]); n     f[i] += x; n     inc(sum[o][f[i]], g[i - 1]); n     if (f[i] <= lim[o]) inc(Sum[o], g[i - 1]); n   } n } n inline void modify(int l, int r, int x) { n   int o; n   if (bel[l] == bel[r]) { n     deal(l, r, x); n     return; n   } n   o = bel[l]; n   deal(l, R[o], x); n   o = bel[r]; n   deal(L[o], r, x); n   for (register int i = bel[l] + 1; i <= bel[r] - 1; ++i) { n     if (x == 1) inc(Sum[i], mod - sum[i][lim[i]]); n     lim[i] -= x; n     if (x == -1) inc(Sum[i], sum[i][lim[i]]); n   } n } n int main() { n   scanf( %d%d , &n, &k); n   blo = sqrt(n); n   for (register int i = 1; i <= n; ++i) { n     scanf( %d , a + i), bel[i] = (i - 1) / blo + 1; n     las[i] = bef[a[i]]; n     bef[a[i]] = i; n   } n   for (register int i = 1; i <= n; ++i) { n     if (!L[bel[i]]) L[bel[i]] = i; n     R[bel[i]] = i; n   } n   for (register int i = 1; i <= bel[n]; ++i) lim[i] = k; n   g[0] = 1; n   for (register int i = 1; i <= n; ++i) { n     inc(sum[bel[i]][0], g[i - 1]), inc(Sum[bel[i]], g[i - 1]); n     modify(las[i] + 1, i, 1); n     if (las[i]) modify(las[las[i]] + 1, las[i], -1); n     ans = 0; n     for (register int j = 1; j <= bel[i]; ++j) inc(ans, Sum[j]); n     g[i] = ans; n   } n   printf( %d n , g[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using pii = pair<int, int>; n const int N = 1000 + 20; n int n, m, q, part[N][N]; n string s[N]; n inline int get(int x) { return (__builtin_popcount(x) & 1 ? -1 : +1); } n inline int get(int x, int y) { return get(x) * get(y); } n inline pii calc(int x) { n   int a = x / 2, b = x / 2; n   if (x & 1) { n     if (get(x - 1) == 1) n       a++; n     else n       b++; n   } n   return pii(a, b); n } n inline pii calc(int x, int y) { n   pii p1 = calc(x), p2 = calc(y); n   return pii(p1.first * p2.first + p1.second * p2.second, n              p1.first * p2.second + p1.second * p2.first); n } n inline int f(int x, int y) { n   int res = 0; n   int X = x / n, Y = y / m; n   x %= n, y %= m; n   pii p = calc(X, Y); n   res += part[n][m] * p.first + (n * m - part[n][m]) * p.second; n   p = calc(X); n   if (get(Y) == -1) swap(p.first, p.second); n   res += part[n][y] * p.first + (n * y - part[n][y]) * p.second; n   p = calc(Y); n   if (get(X) == -1) swap(p.first, p.second); n   res += part[x][m] * p.first + (x * m - part[x][m]) * p.second; n   if (get(X, Y) == 1) n     res += part[x][y]; n   else n     res += (x * y - part[x][y]); n   return res; n } n int32_t main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n >> m >> q; n   for (int i = 0; i < n; i++) { n     cin >> s[i]; n     for (int j = 0; j < m; j++) { n       part[i + 1][j + 1] = n           (s[i][j] ==  1 ) + part[i][j + 1] + part[i + 1][j] - part[i][j]; n     } n   } n   while (q--) { n     int x1, hlkhjl, x2, y2; n     cin >> x1 >> hlkhjl >> x2 >> y2; n     x1--, hlkhjl--; n     cout << f(x2, y2) - f(x1, y2) - f(x2, hlkhjl) + f(x1, hlkhjl) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   long long a, b, m; n   long long vx, vy, vz; n   cin >> a >> b >> m >> vx >> vy >> vz; n   double time = -((double)(m) / (double)(vy)); n   double xc = (double)(a) / 2.0 + time * vx; n   if (xc >= 0) { n     long long p = xc / a; n     if (p % 2 == 1) { n       xc = (p + 1) * a - xc; n     } else { n       xc -= p * a; n     } n   } else { n     long long p = xc / a; n     if (p % 2 == 0) { n       xc -= p * a; n       xc = -xc; n     } else { n       xc -= p * a; n       xc = -xc; n       xc = a - xc; n     } n   } n   double zc = time * vz; n   if (zc >= 0) { n     long long p = zc / b; n     if (p % 2 == 1) { n       zc = (p + 1) * b - zc; n     } else { n       zc -= p * b; n     } n   } else { n     long long p = zc / b; n     if (p % 2 == 0) { n       zc -= p * b; n       zc = -zc; n     } else { n       zc -= p * b; n       zc = -zc; n       zc = b - zc; n     } n   } n   printf( %0.12llf %0.12llf , xc, zc); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 7; n long long a[MAXN]; n int n, k, x; n void print() { n   for (int i = 1; i <= n; ++i) cout << a[i] <<    ; n   exit(0); n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n >> k >> x; n   vector<int> zeros; n   int n_pos = 0, n_neg = 0, n_zer = 0; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     if (a[i] > 0) ++n_pos; n     if (a[i] < 0) ++n_neg; n     if (a[i] == 0) ++n_zer, zeros.push_back(i); n   } n   if (n_zer) { n     if (n_zer > k) print(); n     if ((n_zer & 1) == (n_neg & 1)) n       a[zeros.back()] += 1LL * x, zeros.pop_back(), ++n_pos, --k; n     for (auto v : zeros) a[v] -= 1LL * x, ++n_neg, --k; n   } n   set<pair<long long, int> > s; n   for (int i = 1; i <= n; ++i) s.insert({abs(a[i]), i}); n   if ((n_neg & 1) == 0) { n     int id = s.begin()->second; n     bool save = (a[id] > 0); n     s.erase(s.begin()); n     while (k && (a[id] == 0 || ((a[id] > 0) == save))) { n       if (save) n         a[id] -= 1LL * x; n       else n         a[id] += 1LL * x; n       --k; n     } n     if (k == 0) print(); n     s.insert({abs(a[id]), id}); n   } n   while (k--) { n     int id = s.begin()->second; n     s.erase(s.begin()); n     if (a[id] > 0) n       a[id] += 1LL * x; n     else n       a[id] -= 1LL * x; n     s.insert({abs(a[id]), id}); n   } n   print(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 2e6 + 10; n int n, k, count1; n int a[MAX]; n int res = 1e19 + 10; n int binary_search1(int x, int l, int r) { n   int res = 0; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (a[mid] <= x) { n       res = mid; n       l = mid + 1; n     } else n       r = mid - 1; n   } n   return res; n } n int binary_search2(int x, int l, int r) { n   int res = 0; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (a[mid] < x) { n       l = mid + 1; n     } else { n       res = mid; n       r = mid - 1; n     } n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   scanf( %d %d n , &n, &k); n   count1 = 0; n   for (int i = 1; i <= n; i++) { n     char s; n     scanf( %c , &s); n     if (s ==  0 ) { n       a[++count1] = i; n     } n   } n   sort(a + 1, a + 1 + count1); n   k += 1; n   for (int i = 1; i <= count1 - k + 1; i++) { n     int l = i; n     int r = k + i - 1; n     int pos1 = binary_search1((a[l] + a[r]) >> 1, l, r); n     int pos2 = binary_search2((a[l] + a[r]) >> 1, l, r); n     if (pos1 != 0) { n       res = min(res, max(a[pos1] - a[l], a[r] - a[pos1])); n     } n     if (pos2 != 0) { n       res = min(res, max(a[pos2] - a[l], a[r] - a[pos2])); n     } n   } n   printf( %d , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x7fffffff; n const int Size = 1000 * 1000 + 1; n char buffer[Size]; n int solution(int nTest) { n   int n, m, K; n   scanf( %d%d%d , &n, &m, &K); n   vector<string> name; n   vector<vector<int> > a, b, c; n   for (int i = 0; i < n; i++) { n     scanf( %s , buffer); n     name.push_back(buffer); n     int ta, tb, tc; n     vector<int> va, vb, vc; n     for (int j = 0; j < m; j++) { n       scanf( %d%d%d , &ta, &tb, &tc); n       va.push_back(ta); n       vb.push_back(tb); n       vc.push_back(tc); n     } n     a.push_back(va); n     b.push_back(vb); n     c.push_back(vc); n   } n   int res = 0; n   for (int i = 0; i < n; i++) { n     for (int k = 0; k < n; k++) { n       int t = K; n       vector<pair<int, int> > v; n       for (int j = 0; j < m; j++) { n         v.push_back(make_pair(b[k][j] - a[i][j], j)); n       } n       sort(v.begin(), v.end()); n       reverse(v.begin(), v.end()); n       int sum = 0; n       for (int j = 0; j < m; j++) { n         if (v[j].first >= 0) { n           int ct = c[i][v[j].second]; n           if (t >= ct) { n             sum += ct * v[j].first; n             t -= ct; n           } else { n             sum += t * v[j].first; n             t = 0; n           } n         } n       } n       res = max(res, sum); n     } n   } n   printf( %d n , res); n   return 0; n } n int main() { n   if (0) { n     freopen( input.txt ,  r , stdin); n     freopen( output.txt ,  w , stdout); n   } n   int i = 0, n = 99999; n   while (i < n && solution(i)) { n     i++; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int N = 1e5, V = 5; n const unsigned long long MOD = 1ull << 58, INV5 = 14757395258967641293ull; n struct Com { n   unsigned long long a[V]; n   inline void clear() { a[0] = a[1] = a[2] = a[3] = a[4] = 0; } n   inline Com() { clear(); } n   inline unsigned long long &operator[](int x) { return a[x]; } n   inline const unsigned long long &operator[](const int &x) const { n     return a[x]; n   } n   inline Com operator+(const Com &b) const { n     Com c; n     for (int i = 0; i < V; i++) c[i] = a[i] + b[i]; n     return c; n   } n   inline Com operator-(const Com &b) const { n     Com c; n     for (int i = 0; i < V; i++) c[i] = a[i] - b[i]; n     return c; n   } n   inline Com operator*(const unsigned long long &b) const { n     Com c; n     for (int i = 0; i < V; i++) c[i] = a[i] * b; n     return c; n   } n   inline Com operator*(const Com &b) const { n     static unsigned long long d[V << 1]; n     for (int i = 0; i < V; i++) n       for (int j = 0; j < V; j++) d[i + j] += a[i] * b[j]; n     Com c; n     for (int i = 0; i < V; i++) c[i] = d[i] + d[i + V], d[i] = d[i + V] = 0; n     return c; n   } n   inline Com &operator+=(const Com &b) { return *this = *this + b; } n   inline Com &operator*=(const unsigned long long &b) { n     return *this = *this * b; n   } n   inline Com &operator*=(const Com &b) { return *this = *this * b; } n   inline void out() { n     printf( (%llu,%llu,%llu,%llu,%llu) n , a[0], a[1], a[2], a[3], a[4]); n   } n   inline unsigned long long val() { return (a[0] - a[4]) >> 5; } n   inline bool operator!=(const Com &b) const { n     for (int i = 0; i < V; i++) n       if (a[i] != b[i]) return 1; n     return 0; n   } n } w[2][V << 1], a[N]; n inline Com qpow(Com a, int b) { n   Com c; n   c[0] = 1; n   for (; b; b >>= 1, a *= a) n     if (b & 1) c *= a; n   return c; n } n inline void pre() { n   w[0][0][0] = w[1][0][0] = 1; n   w[0][1][3] = w[1][1][2] = -1; n   for (int i = 2; i < V << 1; i++) { n     w[0][i] = w[0][i - 1] * w[0][1], w[1][i] = w[1][i - 1] * w[1][1]; n   } n } n const int pw[V] = {1, 10, 100, 1000, 10000}; n inline void fft(int opt) { n   for (int i = 0; i < V; i++) n     for (int j = 0; j < N; j++) n       if (!((j / pw[i]) % 10)) { n         static Com f[V << 1]; n         for (int a = 0; a < V << 1; a++) n           for (int b = 0; b < V << 1; b++) { n             f[a] += ::a[j + b * pw[i]] * n                     (opt ? w[0][(10 - a * b % 10) % 10] : w[0][a * b % 10]); n           } n         for (int a = 0; a < V << 1; a++) { n           ::a[j + a * pw[i]] = f[a]; n           f[a].clear(); n         } n       } n   if (opt) { n     unsigned long long INV = INV5 * INV5 * INV5 * INV5 * INV5; n     for (int i = 0; i < N; i++) a[i] *= INV; n   } n } n int n; n int main() { n   pre(); n   scanf( %d , &n); n   for (int i = 1, x; i <= n; i++) { n     scanf( %d , &x); n     a[x][0]++; n   } n   fft(0); n   for (int i = 0; i < N; i++) a[i] = qpow(a[i], n); n   fft(1); n   for (int i = 0; i < n; i++) printf( %llu n , a[i].val() % MOD); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(2) n using namespace std; n const int maxn = 2e5; n const int INF = 0x7fffffff; n const int mod = 1e9 + 7; n const double eps = 1e-7; n const double Pi = acos(-1.0); n inline int read_int() { n   char c; n   int ret = 0, sgn = 1; n   do { n     c = getchar(); n   } while ((c <  0  || c >  9 ) && c !=  - ); n   if (c ==  - ) n     sgn = -1; n   else n     ret = c -  0 ; n   while ((c = getchar()) >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 ); n   return sgn * ret; n } n inline long long read_ll() { n   char c; n   long long ret = 0, sgn = 1; n   do { n     c = getchar(); n   } while ((c <  0  || c >  9 ) && c !=  - ); n   if (c ==  - ) n     sgn = -1; n   else n     ret = c -  0 ; n   while ((c = getchar()) >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 ); n   return sgn * ret; n } n int n, arr[maxn + 5], res[maxn + 5]; n vector<int> dc, ic; n int main() { n   n = read_int(); n   for (int i = 1; i <= n; ++i) arr[i] = read_int(); n   for (int i = 1; i <= n; ++i) { n     if (dc.empty() && ic.empty()) { n       if (i < n && arr[i] <= arr[i + 1]) n         ic.push_back(i); n       else n         dc.push_back(i); n     } else if (dc.empty()) { n       int id = ic.back(); n       if (arr[i] <= arr[id]) n         dc.push_back(i); n       else { n         if (i + 1 <= n && arr[i] <= arr[i + 1]) n           ic.push_back(i); n         else n           dc.push_back(i); n       } n     } else if (ic.empty()) { n       int id = dc.back(); n       if (arr[i] >= arr[id]) n         ic.push_back(i); n       else { n         if (i + 1 <= n && arr[i] <= arr[i + 1]) n           ic.push_back(i); n         else n           dc.push_back(i); n       } n     } else { n       int id1 = ic.back(), id2 = dc.back(); n       if (arr[i] <= arr[id1] && arr[i] >= arr[id2]) { n         cout <<  NO  << endl; n         return 0; n       } else if (arr[i] > arr[id1] && arr[i] < arr[id2]) { n         if (i + 1 <= n && arr[i] <= arr[i + 1]) n           ic.push_back(i); n         else n           dc.push_back(i); n       } else if (arr[i] > arr[id1]) n         ic.push_back(i); n       else n         dc.push_back(i); n     } n   } n   for (int i = 0; i < dc.size(); ++i) res[dc[i]] = 1; n   cout <<  YES  << endl; n   for (int i = 1; i <= n; ++i) printf( %d%c , res[i],    n [i == n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 505, maxmax = 1000000; n int n, javab[maxn][maxn]; n vector<int> v; n int dp(int l, int r) { n   int x = maxmax; n   if (l == r) { n     javab[l][r] = 1; n     return 1; n   } n   if (l == r - 1) { n     if (v[r] == v[l]) { n       javab[l][r] = 1; n       return 1; n     } else { n       javab[l][r] = 2; n       return 2; n     } n   } n   if (javab[l][r - 1] != 0) n     x = min(x, javab[l][r - 1] + 1); n   else { n     x = min(x, dp(l, r - 1) + 1); n   } n   for (int i = r - 1; i >= l; i--) { n     if (v[r] == v[i]) { n       if (i == l) { n         if (javab[l + 1][r - 1] != 0) { n           x = min(x, javab[l + 1][r - 1]); n         } else n           x = min(x, dp(l + 1, r - 1)); n         break; n       } n       if (javab[l][i - 1] != 0) { n         if (javab[i][r] != 0) { n           x = min(x, javab[l][i - 1] + javab[i][r]); n         } else { n           x = min(x, javab[l][i - 1] + dp(i, r)); n         } n       } else { n         if (javab[i][r] != 0) { n           x = min(x, dp(l, i - 1) + javab[i][r]); n         } else { n           x = min(x, dp(l, i - 1) + dp(i, r)); n         } n       } n     } n   } n   javab[l][r] = x; n   return x; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     v.push_back(x); n   } n   int javab = dp(0, v.size() - 1); n   cout << javab; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( no-stack-protector ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC optimize( fast-math ) n #pragma GCC target( sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native ) n using namespace std; n template <typename T> n void uin(T &a, T b) { n   if (b < a) { n     a = b; n   } n } n template <typename T> n void uax(T &a, T b) { n   if (b > a) { n     a = b; n   } n } n const long long N = 100 * 1000 + 228; n vector<long long> g[N]; n long long deg[N]; n long long h[N], p[N]; n void dfs(long long v, long long par = -1) { n   h[v] = (par == -1 ? 0 : h[par] + 1); n   p[v] = par; n   for (long long to : g[v]) { n     if (to != par) dfs(to, v); n   } n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long n; n   cin >> n; n   for (long long i = 0; i < n - 1; ++i) { n     long long u, v; n     cin >> u >> v; n     ++deg[u]; n     ++deg[v]; n     g[u].emplace_back(v); n     g[v].emplace_back(u); n   } n   long long root = 1; n   for (long long i = 1; i <= n; ++i) { n     if (deg[i] > 1) { n       root = i; n       break; n     } n   } n   dfs(root); n   bool even = 0, odd = 0; n   for (long long i = 1; i <= n; ++i) { n     if (deg[i] == 1) { n       if (h[i] & 1) n         odd = 1; n       else n         even = 1; n     } n   } n   long long min_colors = 0; n   if (even && odd) { n     min_colors = 3; n   } else { n     min_colors = 1; n   } n   vector<long long> pars; n   long long leafs = 0; n   for (long long i = 1; i <= n; ++i) { n     if (deg[i] == 1) { n       pars.emplace_back(p[i]); n       ++leafs; n     } n   } n   sort(pars.begin(), pars.end()); n   pars.erase(unique(pars.begin(), pars.end()), pars.end()); n   long long max_colors = (long long)pars.size(); n   max_colors += (n - 1 - leafs); n   cout << min_colors <<     << max_colors <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n const int MAXLEN = 15; n long long dp[MAXLEN + 1][2]; n long long dpleq[MAXLEN + 1][2]; n inline int conv(char c) { n   if (isdigit(c)) return c -  0 ; n   if (islower(c)) return c -  a  + 10; n   assert(false); n } n long long calc(char* s) { n   int slen = strlen(s); n   long long ret = 0; n   for (int mx = (0); mx < (16); ++mx) { n     int pos = mx / 4, off = mx % 4; n     if (pos >= slen) continue; n     memset(dp, 0, sizeof(dp)); n     memset(dpleq, 0, sizeof(dpleq)); n     dp[0][0] = dpleq[0][0] = 1; n     for (int i = (0); i < (slen); ++i) n       for (int j = (0); j < (2); ++j) n         for (int k = (0); k <= (mx); ++k) { n           if (i == pos && (k & (1 << off)) == 0) continue; n           int nj = j == 1 || k == mx ? 1 : 0; n           dp[i + 1][nj] += dp[i][j]; n           if (k < conv(s[i])) n             dpleq[i + 1][nj] += dp[i][j]; n           else if (k == conv(s[i])) n             dpleq[i + 1][nj] += dpleq[i][j]; n         } n     long long cur = dpleq[slen][1]; n     ret += cur; n   } n   return ret; n } n void dec(char* s) { n   for (int i = 0;; ++i) n     if (s[i] ==  0 ) n       s[i] =  f ; n     else { n       assert(s[i] !=   0 ); n       if (s[i] ==  a ) n         s[i] =  9 ; n       else n         --s[i]; n       break; n     } n   int slen = strlen(s); n   while (slen >= 2 && s[slen - 1] ==  0 ) --slen; n   s[slen] =   0 ; n } n int nq; n char sl[MAXLEN + 1], sr[MAXLEN + 1]; n long long solve() { n   reverse(sl, sl + strlen(sl)); n   reverse(sr, sr + strlen(sr)); n   long long ret = calc(sr); n   if (strcmp(sl,  0 ) != 0) { n     dec(sl); n     ret -= calc(sl); n   } n   return ret; n } n void run() { n   scanf( %d , &nq); n   for (int qi = (0); qi < (nq); ++qi) { n     scanf( %s%s , sl, sr); n     printf( %lld n , solve()); n   } n } n int main() { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n; n   scanf( %d , &n); n   int ans = 0; n   int score = -1; n   for (int i = 0; i < n; i++) { n     int sub, subsc = 0; n     scanf( %d , &sub); n     subsc += sub; n     scanf( %d , &sub); n     subsc += sub; n     scanf( %d , &sub); n     subsc += sub; n     scanf( %d , &sub); n     subsc += sub; n     if (subsc > score) { n       ans++; n     } n     if (!i) score = subsc; n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 450, inf = 1e8; n int n1, n2, m, r, b, node, s, t, S, T, a[N], id[N]; n char col1[N], col2[N]; n int head[N], ce = 1, inq[N], dis[N], maxflow, mincost, need; n struct edge { n   int to, nxt, cap, flow, w; n } e[5000]; n void lnk(int a, int b, int c, int w) { n   e[++ce] = (edge){b, head[a], c, 0, w}, head[a] = ce; n   e[++ce] = (edge){a, head[b], 0, 0, -w}, head[b] = ce; n } n bool bfs() { n   for (int i = 1; i <= node; ++i) dis[i] = inf, inq[i] = 0; n   dis[s] = 0, inq[s] = 1; n   queue<int> q; n   q.push(s); n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (int i = head[u]; i; i = e[i].nxt) { n       int v = e[i].to; n       if (e[i].cap > e[i].flow && dis[v] > dis[u] + e[i].w) { n         dis[v] = dis[u] + e[i].w; n         if (!inq[v]) q.push(v), inq[v] = 1; n       } n     } n     inq[u] = 0; n   } n   return dis[t] < inf; n } n int dfs(int u, int lim) { n   if (u == t) return mincost += dis[t] * lim, lim; n   int tag = 0; n   inq[u] = 1; n   for (int i = head[u]; i; i = e[i].nxt) n     if (e[i].cap > e[i].flow && dis[e[i].to] == dis[u] + e[i].w && n         !inq[e[i].to]) { n       int d = dfs(e[i].to, min(lim - tag, e[i].cap - e[i].flow)); n       tag += d, e[i].flow += d, e[i ^ 1].flow -= d; n       if (tag == lim) { n         inq[u] = 0; n         return tag; n       } n     } n   return tag; n } n int main() { n   scanf( %d%d%d%d%d , &n1, &n2, &m, &r, &b); n   scanf( %s , col1 + 1); n   scanf( %s , col2 + 1); n   node = n1 + n2, S = ++node, T = ++node, s = ++node, t = ++node; n   for (int i = 1; i <= n1; ++i) n     if (col1[i] ==  R ) n       ++a[i], --a[S], lnk(S, i, inf, 0); n     else if (col1[i] ==  B ) n       --a[i], ++a[T], lnk(i, T, inf, 0); n     else n       lnk(S, i, inf, 0), lnk(i, T, inf, 0); n   for (int i = 1; i <= n2; ++i) n     if (col2[i] ==  R ) n       --a[i + n1], ++a[T], lnk(i + n1, T, inf, 0); n     else if (col2[i] ==  B ) n       ++a[i + n1], --a[S], lnk(S, i + n1, inf, 0); n     else n       lnk(S, i + n1, inf, 0), lnk(i + n1, T, inf, 0); n   for (int i = 1; i <= T; ++i) n     if (a[i] > 0) n       lnk(s, i, a[i], 0), need += a[i]; n     else if (a[i] < 0) n       lnk(i, t, -a[i], 0); n   lnk(T, S, inf, 0); n   for (int i = 1, u, v; i <= m; ++i) n     scanf( %d%d , &u, &v), id[i] = ce + 1, lnk(u, v + n1, 1, r), n                            lnk(v + n1, u, 1, b); n   while (bfs()) maxflow += dfs(s, inf); n   if (maxflow < need) { n     puts( -1 ); n     return 0; n   } n   printf( %d n , mincost); n   for (int i = 1; i <= m; ++i) n     if (e[id[i]].flow) n       putchar( R ); n     else if (e[id[i] + 2].flow) n       putchar( B ); n     else n       putchar( U ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int search_factor(int n) { n   if (n % 2 == 0) { n     return n / 2; n   } else { n     for (int i = (n - 1) / 2; i >= 1; i -= 1) { n       if (n % i == 0) return i; n     } n   } n } n int main() { n   int n; n   cin >> n; n   long long int sum = n; n   while (n != 1) { n     int res = search_factor(n); n     sum += res; n     n = res; n   } n   cout << sum; n   return 0; n } n