#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 100; n struct node { n   int flag, a, b; n   long long sum; n } t[maxn * 8]; n int a[maxn], cnt[maxn * 2], js[maxn * 2]; n void pushdown(int x, int l, int r) { n   if (t[x].flag) { n     int num = t[x].flag; n     t[2 * x].sum += num * l; n     t[2 * x + 1].sum += num * r; n     t[2 * x].flag += num; n     t[2 * x + 1].flag += num; n     t[x].flag = 0; n   } n } n int ask(int x, int l, int r, int pos) { n   int mid; n   if (l == r) { n     return t[x].sum; n   } n   mid = (l + r) / 2; n   pushdown(x, mid - l + 1, r - mid); n   if (pos <= mid) n     return ask(2 * x, l, mid, pos); n   else n     return ask(2 * x + 1, mid + 1, r, pos); n } n void add(int x, int l, int r, int ql, int qr, int val) { n   int mid; n   if (ql == l && qr == r) { n     t[x].flag += val; n     t[x].sum += (qr - ql + 1); n     return; n   } n   mid = (l + r) / 2; n   pushdown(x, mid - l + 1, r - mid); n   if (qr <= mid) { n     add(2 * x, l, mid, ql, qr, val); n   } else { n     if (ql > mid) n       add(2 * x + 1, mid + 1, r, ql, qr, val); n     else { n       add(2 * x, l, mid, ql, mid, val); n       add(2 * x + 1, mid + 1, r, mid + 1, qr, val); n     } n   } n   t[x].sum = t[2 * x].sum + t[2 * x + 1].sum; n } n void build(int x, int l, int r) { n   int mid; n   t[x].flag = 0; n   t[x].sum = 0; n   if (l == r) { n     return; n   } n   mid = (l + r) / 2; n   build(2 * x, l, mid); n   build(2 * x + 1, mid + 1, r); n } n int top; n node s[maxn]; n int cmp(node a, node b) { return a.sum < b.sum; } n int main() { n   node e; n   int T, n, flag, ans, k, up; n   scanf( %d , &T); n   while (T--) { n     scanf( %d%d , &n, &k); n     for (int i = 1; i <= 2 * k; i++) { n       cnt[i] = 0; n       js[i] = 0; n     } n     build(1, 1, k * 2); n     for (int i = 1; i <= n; i++) { n       scanf( %d , &a[i]); n     } n     if (n == 2) { n       printf( 0 n ); n       continue; n     } n     top = 0; n     if (n % 2) n       up = n / 2 + 1; n     else n       up = n / 2; n     for (int i = 1; i <= up; i++) { n       e.a = a[i]; n       e.b = a[n - i + 1]; n       if (e.a > e.b) swap(e.a, e.b); n       e.sum = e.a + e.b; n       s[++top] = e; n       js[e.sum]++; n     } n     sort(s + 1, s + top + 1, cmp); n     int last = 0; n     ans = n; n     for (int i = 1; i <= top; i++) { n       e = s[i]; n       if (e.sum == last) { n         add(1, 1, 2 * k, e.a + 1, e.b + k, 1); n         continue; n       } n       cnt[e.sum] += n / 2 - js[e.sum] + i - 1 - ask(1, 1, 2 * k, e.sum); n       add(1, 1, 2 * k, e.a + 1, e.b + k, 1); n       last = e.sum; n     } n     for (int i = 1; i <= top / 2; i++) { n       swap(s[i], s[top - i + 1]); n     } n     build(1, 1, k * 2); n     last = 0; n     ans = n; n     for (int i = 1; i <= top; i++) { n       e = s[i]; n       if (e.sum == last) { n         add(1, 1, 2 * k, e.a + 1, e.b + k, 1); n         continue; n       } n       cnt[e.sum] += i - 1 - ask(1, 1, 2 * k, e.sum); n       ans = min(ans, cnt[e.sum]); n       add(1, 1, 2 * k, e.a + 1, e.b + k, 1); n       last = e.sum; n     } n     for (int i = 1; i <= 2 * k; i++) { n       if (js[i]) continue; n       ans = min(ans, n - ask(1, 1, 2 * k, i)); n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, a[100001], b[100001]; n vector<long long> v[100001]; n signed main() { n   cin >> n; n   long long i; n   for (i = 1; i < n + 1; i++) { n     cin >> a[i]; n     v[a[i]].push_back(i); n   } n   bool ok = 1; n   long long clr = 1; n   for (i = 0; i < 100001; i++) { n     if (!v[i].empty()) { n       long long k = v[i].size(); n       long long j; n       if (k % (n - i) != 0) { n         ok = 0; n         break; n       } n       long long t = k / (n - i); n       long long temp = 1; n       j = 0; n       while (temp <= t) { n         while (j < temp * (n - i)) { n           b[v[i][j]] = clr; n           j++; n         } n         clr++; n         temp++; n       } n     } n   } n   if (ok) { n     cout <<  Possible n ; n     for (i = 1; i < n + 1; i++) cout << b[i] <<    ; n   } else n     cout <<  Impossible ; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool uin(T &a, T b) { n   return a > b ? (a = b, true) : false; n } n template <class T> n bool uax(T &a, T b) { n   return a < b ? (a = b, true) : false; n } n const long long maxn = 1000001, mod = 1e9 + 7; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   int ar[n]; n   map<int, int> mapp; n   for (long long i = 0; i < (long long)(n); ++i) { n     cin >> ar[i]; n     mapp[ar[i]] = i; n   } n   set<int> s; n   s.insert(-1); n   s.insert(n); n   int ans = 0; n   for (int i = n; i >= 1; i--) { n     int idx = mapp[i]; n     auto it = s.lower_bound(idx); n     auto iit = s.upper_bound(idx); n     if (it != s.begin()) it--; n     int a = *it + 1; n     int b = *iit - 1; n     if (idx - a < b - idx) { n       for (long long j = (long long)(a); j <= (long long)(idx - 1); ++j) { n         int acha = mapp[i - ar[j]]; n         if (acha > idx && acha <= b) { n           ans++; n         } n       } n     } else { n       for (long long j = (long long)(idx + 1); j <= (long long)(b); ++j) { n         int acha = mapp[i - ar[j]]; n         if (acha < idx && acha >= a) { n           ans++; n         } n       } n     } n     s.insert(mapp[i]); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Trie { n   Trie *nx[2]; n   int cnt; n   Trie() { n     nx[0] = nx[1] = nullptr; n     cnt = 0; n   } n }; n Trie *root; n void ins(long long x) { n   Trie *now = root; n   for (int bit = 45; bit >= 0; --bit) { n     int p = (x >> bit) & 1LL; n     if (now->nx[p] == nullptr) now->nx[p] = new Trie(); n     now = now->nx[p]; n     now->cnt++; n   } n } n long long query(long long x) { n   Trie *now = root; n   long long ret = 0LL; n   for (int bit = 45; bit >= 0; --bit) { n     int p = (x >> bit) & 1LL; n     p ^= 1; n     if (now->nx[p] != nullptr && now->nx[p]->cnt > 0) { n       ret += 1LL << bit; n       now = now->nx[p]; n     } else { n       now = now->nx[p ^ 1]; n     } n     if (now == nullptr || now->cnt == 0) break; n   } n   return ret; n } n const int MXSZ = 1e5; n int n; n long long a[MXSZ + 5]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   root = new Trie(); n   cin >> n; n   long long curr = 0LL; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     curr ^= a[i]; n     ins(curr); n   } n   long long mx = 0LL; n   mx = max(mx, query(0)); n   curr = 0LL; n   for (int i = n; i >= 1; --i) { n     curr ^= a[i]; n     mx = max(mx, query(curr)); n   } n   cout << mx <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int b[5000]; n int f[5000]; n int main() { n   scanf(  %d , &n); n   for (int i = 0; i < (int)(n); i++) scanf(  %d , b + i); n   for (int i = 0; i < (int)(n); i++) b[i]--; n   for (int i = 0; i < n; i++) { n     int c[5000] = {}; n     pair<int, int> best = make_pair(0, 0); n     for (int j = i; j < n; j++) { n       c[b[j]]++; n       best = max(best, make_pair(c[b[j]], -b[j])); n       f[-best.second]++; n     } n   } n   for (int i = 0; i < (int)(n); i++) printf( %d  , f[i]); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using LL = long long; n const int maxn = 3000010; n int n, b; n int pre[maxn], vis[maxn]; n vector<int> prime; n struct init { n   init() { n     memset(pre, 0, sizeof pre); n     prime.clear(); n     for (int i = 2; i < maxn; i++) { n       if (pre[i] == 0) { n         pre[i] = i; n         prime.emplace_back(i); n       } n       for (int j = 0; j < prime.size() && i * prime[j] < maxn; j++) { n         if (prime[j] > pre[i]) break; n         pre[i * prime[j]] = prime[j]; n       } n     } n   } n } init_; n bool ok(int x) { n   if (x == 1) return 0; n   return pre[x] == 0; n } n signed main() { n   while (cin >> n) { n     memset(vis, 0, sizeof vis); n     for (int i = 1; i <= 2 * n; i++) { n       scanf( %d , &b); n       vis[b]++; n     } n     for (int i = maxn - 1; i > 1; i--) { n       if (pre[i] == i) continue; n       while (vis[i] > 0) { n         printf( %d  , i); n         vis[i]--; n         vis[i / pre[i]]--; n       } n     } n     for (int i = 2; i < maxn; i++) { n       while (vis[i] > 0) { n         printf( %d  , i); n         vis[i]--; n         vis[prime[i - 1]]--; n       } n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0), cin.tie(0); n   string s; n   cin >> s; n   sort(s.begin(), s.end()); n   reverse(s.begin(), s.end()); n   cout << s[0]; n   for (long long int(i) = (1); (i) < (s.length()); (i)++) { n     if (s[i] == s[i - 1]) n       cout << s[i]; n     else n       break; n   } n   cout <<   n ; n } n


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


#include <bits/stdc++.h> n using namespace std; n bool KT(long long k, long long n) { n   long long take = 0, cur = n; n   while (cur > 0) { n     long long temp = min(k, cur); n     take += temp; n     cur -= temp; n     cur -= cur / 10; n   } n   if (take * 2 >= n) return true; n   return false; n } n int main() { n   long long n; n   cin >> n; n   long long left = 1, right = n, res = 0; n   while (left <= right) { n     long long mid = (left + right) / 2; n     if (KT(mid, n)) { n       res = mid; n       right = mid - 1; n     } else { n       left = mid + 1; n     } n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct in { n   int x, y; n } a[300000]; n int get(int prex, int prey, int x, int y, int k) { n   int num, ans = 100000000; n   if (prex <= k) { n     num = (prex + x + k - 1) / k - 1; n     if (y == num) n       ans = prex + x - num * k; n     else if (y > num && y <= (long long)x * k) n       ans = 1; n   } n   if (prey <= k) { n     num = (x + k - 1) / k - 1; n     if (y == num) n       ans = min(ans, x - num * k); n     else if (y > num && y - k + prey <= (long long)(x - 1) * k) n       ans = 1; n   } n   return ans; n } n int main() { n   int N, K, pre0 = 0, pre1 = 0, next0, next1; n   scanf( %d%d , &N, &K); n   for (int i = 1; i <= N; i++) scanf( %d , &a[i].x); n   for (int i = 1; i <= N; i++) scanf( %d , &a[i].y); n   for (int i = 1; i <= N; i++) { n     next0 = get(pre0, pre1, a[i].x, a[i].y, K); n     next1 = get(pre1, pre0, a[i].y, a[i].x, K); n     pre0 = next0; n     pre1 = next1; n   } n   if (pre0 <= K || pre1 <= K) n     puts( YES ); n   else n     puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n float a1(float x, float y, float z) { n   if (x >= 1.0) n     return z * log(y) + log(log(x)); n   else if (x < 1.0 && y < 1.0 && z < 1.0) n     return z * log(y) + log(log(1 / x)); n   else n     return 0.0 / 0.0; n } n float a2(float x, float y, float z) { n   if (x >= 1.0) n     return log(z) + log(y) + log(log(x)); n   else if (x < 1.0 && y < 1.0 && z < 1.0) n     return log(z) + log(y) + log(log(1 / x)); n   else n     return 0.0 / 0.0; n } n int main() { n   float x, y, z; n   scanf( %f %f %f , &x, &y, &z); n   float a[12]; n   char pat[12][10] = { x^y^z 0 ,  x^z^y 0 ,  (x^y)^z 0 ,  (x^z)^y 0 , n                        y^x^z 0 ,  y^z^x 0 ,  (y^x)^z 0 ,  (y^z)^x 0 , n                        z^x^y 0 ,  z^y^x 0 ,  (z^x)^y 0 ,  (z^y)^x 0 }; n   a[0] = a1(x, y, z); n   a[1] = a1(x, z, y); n   a[2] = a2(x, y, z); n   a[3] = a2(x, z, y); n   a[4] = a1(y, x, z); n   a[5] = a1(y, z, x); n   a[6] = a2(y, x, z); n   a[7] = a2(y, z, x); n   a[8] = a1(z, x, y); n   a[9] = a1(z, y, x); n   a[10] = a2(z, x, y); n   a[11] = a2(z, y, x); n   float ans; n   int pos, i; n   if (x >= 1.0) { n     ans = a[0]; n     pos = 0; n   } else if (y >= 1.0) { n     ans = a[4]; n     pos = 4; n   } else { n     ans = a[8]; n     pos = 8; n   } n   if (x < 1 && y < 1 && z < 1) { n     for (i = 11; i >= 0; --i) { n       if (a[i] <= ans) { n         ans = a[i]; n         pos = i; n       } n     } n   } else { n     for (i = 11; i >= 0; --i) { n       if (a[i] >= ans) { n         ans = a[i]; n         pos = i; n       } n     } n   } n   printf( %s , pat[pos]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> vi; n void primefact(int n) { n   while (n % 2 == 0) { n     vi.push_back(2); n     n /= 2; n   } n   int i = 3; n   while (i <= n) { n     while (n % i == 0) { n       vi.push_back(i); n       n /= i; n     } n     i += 2; n   } n   if (n > 2) vi.push_back(n); n } n int main() { n   int n, k, last = 1, i; n   cin >> n >> k; n   primefact(n); n   if (k > vi.size()) n     cout <<  -1  << endl; n   else { n     for (i = 0; i < k - 1; i++) cout << vi[i] <<    ; n     for (i = k - 1; i < vi.size(); i++) last *= vi[i]; n     cout << last; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200005; n const long long INF = 1e9; n const long long MOD = 1000000007; n int prevs[20]; n int main() { n   ios ::sync_with_stdio(0); n   cin.tie(0); n   int n, q; n   cin >> n >> q; n   int arr[n]; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   int ar[n][20]; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < 20; j++) ar[i][j] = n + 3; n   for (int i = n - 1; i >= 0; i--) { n     int x = 1; n     for (int j = 0; j < 20; j++) { n       if ((x << j) & arr[i]) { n         ar[i][j] = i; n         if (prevs[j] != 0) n           for (int k = 0; k < 20; k++) n             ar[i][k] = min(ar[i][k], ar[prevs[j]][k]); n         prevs[j] = i; n       } n     } n   } n   while (q--) { n     int x, y; n     cin >> x >> y; n     x--, y--; n     if (!arr[x] || !arr[y]) { n       cout <<  Fou  << endl; n       continue; n     } n     int p = 1; n     int l = 0; n     for (int j = 0; j < 20; j++) n       if (p << j & arr[y]) n         if (ar[x][j] <= y) { n           l = 1; n           continue; n         } n     if (l == 1) n       cout <<  Shi  << endl; n     else n       cout <<  Fou  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n; n char s[1000005]; n int main() { n   int i, j, l, r, p = 0; n   scanf( %s , s); n   n = strlen(s); n   for (j = 0; j < n && s[j] !=  . ; j++) n     ; n   if (j == n) { n     s[n] =  . ; n     n++; n   } n   for (i = 0; i < n && s[i] ==  0 ; i++) n     ; n   if (i == j) { n     for (; i < n - 1 && s[i + 1] ==  0 ; i++) swap(s[i], s[i + 1]), p--; n     if (i == n - 1) { n       printf( 0 n ); n       return 0; n     } n     swap(s[i], s[i + 1]), p--; n     for (r = n - 1; s[r] ==  0 ; r--) n       ; n     if (s[r] ==  . ) r--; n     for (; i <= r; i++) printf( %c , s[i]); n     if (p != 0) printf( E%d n , p); n   } else { n     for (; j > i + 1; j--) swap(s[j], s[j - 1]), p++; n     for (r = n - 1; s[r] ==  0 ; r--) n       ; n     if (s[r] ==  . ) r--; n     for (; i <= r; i++) printf( %c , s[i]); n     if (p != 0) printf( E%d n , p); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxn = 1000 + 10; n const int INF = 0x7f7f7f7f; n const double eps = 1e-10; n const double pi = acos(-1.0); n inline int realcmp(double a, double b) { n   return (a > b + eps) ? 1 : ((a + eps < b) ? -1 : 0); n } n int main() { n   double hh, mm; n   ios::sync_with_stdio(0); n   scanf( %lf:%lf , &hh, &mm); n   hh += mm / 60; n   while (realcmp(hh, 12) >= 0) hh -= 12; n   printf( %.9lf  , 30.0 * hh); n   printf( %.9lf n , 6.0 * mm); n   return 0; n } n


#include <bits/stdc++.h> n struct point { n   long x; n   long y; n   long z; n }; n const long maxn = 5001; n const double inf = 2000000000; n const double eps = 1.0e-8; n point a[maxn]; n double nnew, min; n long n, q, choice1, choice2; n double d[maxn]; n double sqr(double x) { return (x * x); } n double dist(point a, point b) { n   return (pow(sqr(a.x - b.x) + sqr(a.y - b.y) + sqr(a.z - b.z), 0.5)); n } n int main() { n   scanf( %ld , &n); n   for (q = 1; q <= n; q++) scanf( %ld%ld%ld , &a[q].x, &a[q].y, &a[q].z); n   min = inf; n   for (long h = 2; h <= n; h++) d[h] = dist(a[1], a[h]); n   for (choice1 = 2; choice1 <= n; choice1++) n     for (choice2 = choice1 + 1; choice2 <= n; choice2++) { n       nnew = (d[choice1] + d[choice2] + dist(a[choice1], a[choice2])) / 2; n       if (min - nnew > eps) min = nnew; n     } n   printf( %0.8lf , min); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x, i, y, ans = 0, q; n   scanf( %d%d , &n, &x); n   y = int(sqrt(x)); n   if (n < y) y = n; n   for (i = 1; i <= y; i++) { n     if (x % i == 0) { n       q = x / i; n       if (q <= n) { n         if (i == q) n           ans++; n         else n           ans += 2; n       } n     } n   } n   if (x == 1) n     printf( %d n , 1); n   else n     printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mx = 1e9; n struct Data { n   int p1, p2, p3, p4; n   Data(int a = mx, int b = mx, int c = mx, int d = mx) { n     p1 = a, p2 = b, p3 = c, p4 = d; n   } n }; n inline Data UN(Data a, Data b) { n   Data c; n   c.p1 = min(a.p1 + b.p1, a.p2 + b.p3), c.p2 = min(a.p1 + b.p2, a.p2 + b.p4); n   c.p3 = min(a.p3 + b.p1, a.p4 + b.p3), c.p4 = min(a.p3 + b.p2, a.p4 + b.p4); n   c.p1 = min(c.p1, mx), c.p2 = min(c.p2, mx), c.p3 = min(c.p3, mx), n   c.p4 = min(c.p4, mx); n   return c; n } n struct node { n   int l, r; n   Data s; n } T[200010 << 2]; n char G[3][200010]; n void build(int rt, int l, int r) { n   T[rt].l = l, T[rt].r = r; n   int mid = (l + r) >> 1; n   if (l == r) { n     if (G[1][l] ==  . ) T[rt].s.p1 = 1; n     if (G[2][l] ==  . ) T[rt].s.p4 = 1; n     if (G[1][l] ==  .  && G[2][l] ==  . ) T[rt].s.p2 = T[rt].s.p3 = 2; n     return; n   } n   build(rt << 1, l, mid), build(rt << 1 | 1, mid + 1, r); n   T[rt].s = UN(T[rt << 1].s, T[rt << 1 | 1].s); n } n Data query(int rt, int start, int end) { n   int l = T[rt].l, r = T[rt].r, mid = (l + r) >> 1; n   if (start <= l && r <= end) return T[rt].s; n   if (end <= mid) return query(rt << 1, start, end); n   if (start > mid) return query(rt << 1 | 1, start, end); n   return UN(query(rt << 1, start, end), query(rt << 1 | 1, start, end)); n } n int main() { n   int n, q; n   scanf( %d%d , &n, &q); n   scanf( %s%s , G[1] + 1, G[2] + 1); n   build(1, 1, n); n   while (q--) { n     int a, b; n     scanf( %d%d , &a, &b); n     int l = a > n ? a - n : a, r = b > n ? b - n : b, res; n     if (l > r) swap(l, r), swap(a, b); n     Data tmp = query(1, l, r); n     if (a <= n && b <= n) res = tmp.p1; n     if (a <= n && b > n) res = tmp.p2; n     if (a > n && b <= n) res = tmp.p3; n     if (a > n && b > n) res = tmp.p4; n     if (res < 1e8) n       printf( %d n , res - 1); n     else n       printf( -1 n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t, x, y, a, b; n   scanf( %lld , &t); n   while (t--) { n     scanf( %lld %lld %lld %lld , &x, &y, &a, &b); n     bool yes = false; n     int i = 0; n     int tens = 1000000; n     while (x <= y) { n       if (x == y) { n         yes = true; n         break; n       } n       while (x + a * tens > y - b * tens && tens > 1) tens /= 10; n       x += tens * a; n       y -= tens * b; n       i += tens; n     } n     printf( %d n , yes ? i : -1); n   } n   return 0; n } n