#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   long long n, a[maxn], aa[maxn], bb[maxn];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i <= n; i++) {       aa[i] = aa[i - 1] + a[i];     }     long long b[maxn];     for (int i = 1; i <= n; i++) {       b[i] = a[i];     }     sort(b + 1, b + n + 1);     for (int i = 1; i <= n; i++) {       bb[i] = bb[i - 1] + b[i];     }     int T;     cin >> T;     while (T--) {       int type, l, r;       long long sum = 0;       cin >> type >> l >> r;       if (type == 1) {         sum = aa[r] - aa[l - 1];       } else {         sum = bb[r] - bb[l - 1];       }       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using db = double;   using pii = pair<int, int>;   using vi = vector<int>;   mt19937 mrand(time(0));   ll get(ll r) { return ((ll)mrand() * mrand() % r + r) % r; }   ll get(ll l, ll r) { return get(r - l + 1) + l; }   int t, T, n, m, L, R = 1e9, c[100100];   pii seg[100100];   vi G[100100];   bool in(pii seg, int x) { return seg.first <= x && x <= seg.second; }   bool dfs(int x) {     for (int y : G[x])       if (!c[y]) {         c[y] = 3 - c[x];         if (!dfs(y)) return false;       } else if (c[y] == c[x])         return false;     return true;   }   signed main() {     scanf( %d %d %d %d , &t, &T, &n, &m);     for (int i = 1; i <= n; i++)       scanf( %d %d , &seg[i].first, &seg[i].second), L = max(L, seg[i].first),                                                      R = min(R, seg[i].second);     if (L + R > T) R = T - L;     if (L + R <= t) L = t - R;     if (L < 0 || R < 0) return puts( IMPOSSIBLE ), 0;     for (int i = 1; i <= n; i++) {       int l_ = in(seg[i], L), r_ = in(seg[i], R);       if (!l_ && !r_) return puts( IMPOSSIBLE ), 0;       if (l_ && !r_) c[i] = 1;       if (!l_ && r_) c[i] = 2;     }     for (int i = 1, x, y; i <= m; i++)       scanf( %d %d , &x, &y), G[x].push_back(y), G[y].push_back(x);     for (int i = 1; i <= n; i++)       if (c[i] && !dfs(i)) return puts( IMPOSSIBLE ), 0;     for (int i = 1; i <= n; i++)       if (!c[i] && (c[i] = 1) && !dfs(i)) return puts( IMPOSSIBLE ), 0;     string ans;     for (int i = 1; i <= n; i++) ans += c[i] +  0 ;     puts( POSSIBLE ), printf( %d %d n , L, R), cout << ans <<   n ;     fprintf(stderr,  time=%.4f n , (db)clock() / CLOCKS_PER_SEC);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Read(int &n) {     int sign = 1;     n = 0;     char c;     do {       c = getchar();     } while (!isdigit(c) && c !=  - );     if (c ==  - ) {       c = getchar();       sign = -1;     }     do {       n = n * 10 + c - 48;       c = getchar();     } while (isdigit(c));     n *= sign;   }   void Read(long long &n) {     int sign = 1;     n = 0;     char c;     do {       c = getchar();     } while (!isdigit(c) && c !=  - );     if (c ==  - ) {       c = getchar();       sign = -1;     }     do {       n = n * 10ll + c - 48;       c = getchar();     } while (isdigit(c));     n *= sign;   }   void Write(int n) {     if (n == 0) {       putchar( 0 );       return;     } else if (n < 0)       putchar( - ), n = -n;     char C[30];     int d = 0;     while (n) {       C[++d] = (n % 10) + 48;       n /= 10;     }     for (int i = d; i >= 1; --i) putchar(C[i]);   }   void Write(long long n) {     if (n == 0) {       putchar( 0 );       return;     } else if (n < 0)       putchar( - ), n = -n;     char C[30];     int d = 0;     while (n) {       C[++d] = (n % 10ll) + 48;       n /= 10ll;     }     for (int i = d; i >= 1; --i) putchar(C[i]);   }   const int maxn = 1005;   char S[maxn];   int P1 = 0, P2 = 0;   bool DigitOrDot(char c) { return ( 0  <= c && c <=  9 ) || c ==  . ; }   void Solve(int s, int e) {     int val = 0;     int pos = -1;     for (int i = s; i <= e; ++i) {       if (S[i] ==  . ) {         pos = i;         continue;       }       val = val * 10 + (S[i] -  0 );     }     if (e - pos == 2) {       P1 += val / 100;       P2 += val % 100;     } else       P1 += val;   }   int main() {     scanf( %s , S + 1);     int n = strlen(S + 1);     for (int i = 1; i <= n; ++i) {       int s = i, e, j = i;       if (DigitOrDot(S[i]))         while (j <= n && DigitOrDot(S[j])) ++j;       e = j - 1;       if (s <= e) Solve(s, e);       i = j;     }     P1 += P2 / 100;     P2 %= 100;     string ans =   ;     if (P2 != 0)       for (int i = 1; i <= 2; ++i) ans += char((P2 % 10) +  0 ), P2 /= 10;     if (ans !=   ) ans +=  . ;     int d = 0;     if (P1 == 0) ans +=  0 ;     while (P1) {       ans += (char)((P1 % 10) +  0 );       P1 /= 10;       d++;       if (d == 3) d = 0, ans +=  . ;     }     if (ans[ans.size() - 1] ==  . ) ans.erase(ans.size() - 1);     reverse(ans.begin(), ans.end());     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<int> remaining;   set<pair<long long int, long long int> > edge;   int cur = 1;   int cmp[300011];   int bfs(int v) {     int cnt = 0;     queue<int> q;     q.push(v);     vector<int> second;     while (q.size()) {       cnt++;       v = q.front();       q.pop();       cmp[v] = cur;       second.clear();       for (auto x : remaining) {         if (!edge.count({x, v})) {           second.push_back(x);         }       }       for (auto x : second) {         remaining.erase(x);         q.push(x);       }     }     return cnt;   }   int main() {     int n, m, k, u, v;     cin >> n >> m >> k;     for (int j = 0; j < m; j++) {       cin >> u >> v;       edge.insert({u, v});       edge.insert({v, u});     }     for (int i = 2; i <= n; i++) remaining.insert(i);     int cnt = 0;     while (remaining.size()) {       int v = *remaining.begin();       remaining.erase(v);       cnt += bfs(v);       cur++;     }     set<int> q;     int w = 0;     for (int i = 2; i <= n; i++) {       if (!edge.count({1, i})) {         q.insert(cmp[i]);         w++;       }     }     if (q.size() <= k and q.size() > 0 and cnt + 1 == n and         q.size() == cur - 1 and w >= k) {       cout <<  possible ;     } else {       cout <<  impossible ;     }   }


#include <bits/stdc++.h>   constexpr int MAXN = 1e2 + 2;   constexpr int MAXE = 1e4 + 4;   using namespace std;   int n;   vector<double> choc, prefixSum, suffixSum, cpy;   int main() {     std::ios::sync_with_stdio(false);     cin >> n;     choc.resize(n), prefixSum.resize(n), suffixSum.resize(n);     for (int i = 0; i < n; i++) {       cin >> choc[i];       if (i == 0)         prefixSum[0] = choc[0];       else         prefixSum[i] = prefixSum[i - 1] + choc[i];     }     for (int i = n - 1; i >= 0; i--) {       if (i == n - 1)         suffixSum[i] = choc[i];       else         suffixSum[i] = suffixSum[i + 1] + choc[i];     }     cpy = suffixSum;     reverse(cpy.begin(), cpy.end());     double mid = prefixSum[n - 1] / 2;     int midPos = upper_bound(prefixSum.begin(), prefixSum.end(), mid) -                  prefixSum.begin() - 1;     int i = 0, j = n - 1;     for (i = 0; i <= midPos; i++) {       int tAlice = prefixSum[i];       j = upper_bound(cpy.begin(), cpy.end(), tAlice * 1.0) - cpy.begin() - 1;       j = n - 1 - j;       int tBob = suffixSum[j];       if (i + 1 == j) {         if (tAlice - choc[i] > tBob)           i--;         else if (tAlice - choc[i] == tBob)           break;         break;       }       if (i + 2 == j) {         if (tAlice == tBob)           i++;         else if (tAlice < tBob)           i++;         break;       }       if (i >= j) break;     }     cout << i + 1 <<     << n - i - 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   const long double PI = 3.14159265358979323846;   const long long MOD = 998244353;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   void solve() {     int n;     cin >> n;     vector<int> a(n);     map<int, deque<int>> d;     vector<int> b;     for (int i = 0; i < n; i++) {       cin >> a[i];       b.push_back(a[i]);     }     sort(b.begin(), b.end());     b.resize(unique(b.begin(), b.end()) - b.begin());     for (int i = 0; i < n; i++) {       a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();       d[a[i]].push_back(i);     }     map<int, int> dp;     int ans = 0;     for (auto c : d) {       dp[c.first] = d[c.first].size();       if (!d[c.first - 1].empty() && d[c.first - 1].back() < d[c.first].front()) {         dp[c.first] = max(dp[c.first], dp[c.first - 1] + (int)d[c.first].size());       }       int cnt = 0;       for (auto kek : d[c.first - 1]) {         if (kek < d[c.first].front()) {           cnt++;         }       }       dp[c.first] = max(dp[c.first], cnt + (int)d[c.first].size());       ans = max(ans, dp[c.first]);       int ret = 0;       for (auto kek : d[c.first]) {         if (!d[c.first - 1].empty() && kek > d[c.first - 1].back()) {           ret++;         }       }       ans = max(ans, dp[c.first - 1] + ret);       vector<pair<int, int>> arr;       for (auto d : d[c.first - 1]) {         arr.push_back({d, 0});       }       for (auto d : d[c.first]) {         arr.push_back({d, 1});       }       sort(arr.begin(), arr.end());       int dp0 = 0, dp1 = 0;       for (auto c : arr) {         if (c.second == 1) {           dp1++;         } else {           dp0++;           dp1 = max(dp1, dp0);         }       }       ans = max(ans, dp1);     }     cout << n - ans <<   n ;   }   int main() {     srand(time(0));     ios_base::sync_with_stdio(false);     cin.tie(0);     int q;     cin >> q;     while (q--) solve();   }


#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::endl;   const int maxn = 200005;   long long a[maxn], b[maxn];   int n;   int ans, base;   std::map<std::pair<long long, long long>, int> mmp;   long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 1; i <= n; i++) {       if (a[i] == 0) {         if (b[i] == 0) base++;       } else {         long long temp1 = b[i], temp2 = a[i];         if (temp1 < 0)           temp1 = -temp1, temp2 = -temp2;         else if (temp1 == 0)           temp2 = 0;         long long g = gcd(llabs(temp1), llabs(temp2));         if (g) temp1 /= g, temp2 /= g;         mmp[std::make_pair(temp1, temp2)]++;       }     }     for (auto it : mmp) {       ans = std::max(ans, it.second);     }     cout << ans + base << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300005;   template <typename T>   inline void read(T &AKNOI) {     T x = 0, flag = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     AKNOI = flag * x;   }   namespace ModCalculator {   const int MOD = 1e9 + 7;   inline void Inc(int &x, int y) {     x += y;     if (x >= MOD) x -= MOD;   }   inline void Dec(int &x, int y) {     x -= y;     if (x < 0) x += MOD;   }   inline int Add(int x, int y) {     Inc(x, y);     return x;   }   inline int Sub(int x, int y) {     Dec(x, y);     return x;   }   inline int Mul(int x, int y) { return 1LL * x * y % MOD; }   inline int Ksm(int x, int k) {     int ret = 1;     for (; k; k >>= 1) {       if (k & 1) ret = Mul(ret, x);       x = Mul(x, x);     }     return ret;   }   inline int Inv(int x) { return Ksm(x, MOD - 2); }   }  // namespace ModCalculator   using namespace ModCalculator;   int n, fac[MAXN], finv[MAXN], sum[MAXN];   vector<int> a[MAXN];   inline int C(int x, int y) { return Mul(fac[x], Mul(finv[y], finv[x - y])); }   void init() {     read(n);     for (int i = 1; i <= n; ++i) {       int x;       read(x);       for (int j = 2; j * j <= x; ++j) {         if (x % j) continue;         int cnt = 0;         while (x % j == 0) {           ++cnt;           x /= j;         }         a[j].push_back(cnt);       }       if (x > 1) {         a[x].push_back(1);       }     }     fac[0] = 1;     for (int i = 1; i <= n; ++i) {       fac[i] = Mul(fac[i - 1], i);     }     finv[n] = Inv(fac[n]);     for (int i = n; i >= 1; --i) {       finv[i - 1] = Mul(finv[i], i);     }     sum[0] = 1;     for (int i = 1; i < n; ++i) {       sum[i] = Add(sum[i - 1], C(n - 1, i));     }   }   void solve() {     int ans = 0;     for (int i = 2; i < MAXN; ++i) {       if (!a[i].size()) continue;       sort(a[i].begin(), a[i].end());       int r = n - a[i].size();       for (auto x : a[i]) {         ++r;         int coef = (r > 1 ? sum[r - 2] : 0);         Dec(coef, Sub(sum[n - 1], sum[r - 1]));         Inc(ans, Mul(x, coef));       }     }     printf( %d n , ans);   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = 1e3 + 5, OO = 0x3f3f3f3f, MOD = 1000000007, M = 200000 + 5;   const double EPS = 0.000000001;   int n, x, y;   char str[N];   int main() {     scanf( %d %s , &n, str);     for (int i = 0; i < n; ++i) {       x += str[i] ==  R  ? 1 : str[i] ==  L  ? -1 : 0;       y += str[i] ==  U  ? 1 : str[i] ==  D  ? -1 : 0;     }     x = abs(x);     y = abs(y);     printf( %d n , n - x - y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, q, w, t;   int main() {     cin >> a;     cout << (a + 1) / 36 <<     << (a + 1) % 36 / 3;   }


#include <bits/stdc++.h>   using namespace std;   long long n, ans, val[3001000];   priority_queue<int> q;   int main() {     scanf( %lld , &n);     for (int i = 1; i <= n; i++) scanf( %lld , &val[i]);     for (int i = 1; i <= n; i++) {       q.push(-val[i]);       q.push(-val[i]);       ans += val[i] + q.top();       q.pop();     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   int p[N + 10], a[N + 10], pos[N + 10];   struct seg {     int l, r, min;   } t[N * 4 + 10];   int nxt[N + 10][20];   int get(int x, int n) {     int ans = x, cnt = 0;     while (n) {       if (n & 1) ans = nxt[ans][cnt];       if (ans >= 0x7f7f7f7f) break;       n >>= 1;       cnt++;     }     return ans;   }   int n;   void build(int p, int l, int r) {     t[p].l = l;     t[p].r = r;     if (l == r) {       t[p].min = get(l, n - 1);       return;     }     int mid = (l + r) / 2;     build(p * 2, l, mid);     build(p * 2 + 1, mid + 1, r);     t[p].min = min(t[p * 2].min, t[p * 2 + 1].min);   }   int query(int p, int l, int r) {     if (l <= t[p].l && t[p].r <= r) return t[p].min;     int mid = (t[p].l + t[p].r) / 2, ans = 0x7f7f7f7f;     if (l <= mid) ans = min(ans, query(p * 2, l, r));     if (r > mid) ans = min(ans, query(p * 2 + 1, l, r));     return ans;   }   int ans[N + 10];   int main() {     int m, q;     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++) {       scanf( %d , &p[i]);       pos[p[i]] = i;     }     for (int i = 1; i <= m; i++) {       scanf( %d , &a[i]);       a[i] = pos[a[i]];     }     memset(pos, 0x7f, sizeof(pos));     for (int i = m; i; i--) {       nxt[i][0] = pos[a[i] == n ? 1 : a[i] + 1];       pos[a[i]] = i;     }     int logn = (int)(log(n) / log(2)) + 1;     for (int s = 1; s <= logn; s++) {       for (int i = 1; i <= m; i++) {         if (i + (1 << s) - 1 > m) {           nxt[i][s] = 0x7f7f7f7f;           continue;         }         if (nxt[i][s - 1] > m) {           nxt[i][s] = 0x7f7f7f7f;           continue;         }         nxt[i][s] = nxt[nxt[i][s - 1]][s - 1];       }     }     build(1, 1, m);     for (int i = 1; i <= q; i++) {       int l, r;       scanf( %d%d , &l, &r);       int tmp = query(1, l, r);       ans[i] = (tmp <= r);     }     for (int i = 1; i <= q; i++) putchar(48 ^ ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long T, n;     cin >> T;     while (T--) {       cin >> n;       double x = (3.141592653589793238) / (2 * n);       cout << fixed << setprecision(10) << cos(x) / sin(x) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void out(int a) { printf( %d n , a); }   inline void out(int a, int b) { printf( %d %d n , a, b); }   inline void outf(double a) { printf( %3.lf n , a); }   inline void outf(double a, double b) { printf( %3.lf %3.lf n , a, b); }   inline void base() {     ios_base::sync_with_stdio(false);     cin.tie(0);   }   bool cek(long long a, long long b) {     long long tmp = 0;     long long ctr = 1;     while (a) {       if (a % 10 == 7 || a % 10 == 4) {         tmp = tmp + ctr * (a % 10);         ctr *= 10;       }       a /= 10;     }     return tmp == b;   }   int main() {     base();     long long a, b;     cin >> a >> b;     a++;     while (!cek(a, b)) {       a++;     }     cout << a << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a, b, c, s;   const long long mod = 1000000007;   long long res[310000], sum;   int N, ar[310000], srt[310000], dad[310000];   int where[310000], lcp[310000], F[310000], S[310000], T[310000];   pair<int, int> as[310000];   vector<pair<int, int> > q;   int comp(const int &a, const int &b) { return as[a] < as[b]; }   int find(int x) {     if (dad[x] == x) return x;     return dad[x] = find(dad[x]);   }   int main() {     cin >> a >> b >> c;     N = a.size() + b.size() + c.size() + 2;     s =     + a +  #  + b +  0  + c;     for (int i = 1; i <= N; i++) ar[i] = s[i];     for (int z = 0; (1 << z) <= N; z++) {       for (int i = 1; i <= N; i++)         as[i] = pair<int, int>(ar[i],                                ((i + (1 << z)) <= N) ? (ar[i + (1 << z)]) : (-1)),         srt[i] = i;       sort(srt + 1, srt + 1 + N, comp);       pair<int, int> prev = pair<int, int>(-1, -1);       for (int i = 1, cnt = 0; i <= N; i++) {         if (as[srt[i]] != prev) {           prev = as[srt[i]];           ++cnt;         }         ar[srt[i]] = cnt;       }     }     for (int i = 1; i <= N; i++) where[ar[i]] = i;     for (int i = 1, ss = 0; i <= N; i++) {       if (ar[i] == N) continue;       int x = where[ar[i] + 1];       while (s[i + ss] == s[x + ss] && i + ss <= N && x + ss <= N) ss++;       lcp[ar[i]] = ss;       q.push_back(pair<int, int>(ss, ar[i]));       if (ss) ss--;     }     for (int i = 1; i <= N; i++) {       dad[i] = i;       if (where[i] <= a.size())         F[i] = 1;       else if (where[i] <= a.size() + b.size() + 1)         S[i] = 1;       else         T[i] = 1;     }     sort(q.begin(), q.end());     reverse(q.begin(), q.end());     int M = min(a.size(), min(b.size(), c.size()));     for (int i = M, j = 0; i; i--) {       while (j < (int)q.size() && q[j].first >= i) {         int x = q[j].second, y = q[j].second + 1;         long long pl = -1LL * F[find(x)] * S[find(x)] * T[find(x)];         pl -= 1LL * F[find(y)] * S[find(y)] * T[find(y)];         F[find(x)] += F[find(y)];         S[find(x)] += S[find(y)];         T[find(x)] += T[find(y)];         dad[find(y)] = find(x);         pl += 1LL * F[find(x)] * S[find(x)] * T[find(x)];         sum = (sum + pl) % mod;         j++;       }       res[i] = sum;     }     for (int i = 1; i <= M; i++) printf( %d  , res[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 20;   long long sum;   int k, p, n, a[N + 1], i, b[N + 1], left_tree[N + 1], right_tree[N + 1];   vector<long long> leftv, rightv;   void update(int index, int value, int tree[]) {     while (index < N + 1) {       tree[index] += value;       index += (index & -index);     }   }   int read(int index, int tree[]) {     int sum = 0;     while (index > 0) {       sum += tree[index];       index -= (index & -index);     }     return sum;   }   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(b, b + n);     for (i = 0; i < n; i++) {       a[i] = upper_bound(b, b + n, a[i]) - b;     }     for (i = 0; i < n; i++) {       update(a[i], 1, left_tree);       leftv.push_back(read(N, left_tree) - read(a[i], left_tree));     }     for (i = n - 1; i >= 0; i--) {       rightv.push_back(read(a[i], right_tree));       update(a[i], 1, right_tree);     }     reverse(rightv.begin(), rightv.end());     for (i = 0; i < n; i++) {       sum += rightv[i] * leftv[i];     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100001], b[100001];   long long int k, SS;   int compare(const void* a, const void* b) { return (*(int*)a - *(int*)b); }   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];       SS = SS + a[i];     }     if (SS < k) {       cout << -1;       return 0;     }     if (SS == k) {       return 0;     }     qsort(b, n, sizeof(int), compare);     int s = 0;     long long int K = k;     for (int i = 0; i < n; i++)       if (b[i] > s) {         if (K >= (long long int)(n - i) * (b[i] - s)) {           K = K - (long long int)(n - i) * (b[i] - s);           s = b[i];         } else {           break;         }       }     int conlai = n;     for (int i = 0; i < n; i++) {       if (a[i] <= s) {         a[i] = -1;         conlai--;       } else         a[i] = a[i] - s;     }     for (int i = 0; i < n; i++)       if (a[i] != -1) {         a[i] = a[i] - K / conlai;         if (a[i] == 0) a[i] == -1;       }     K = K % conlai;     if (K > 0)       for (int i = 0; i < n; i++) {         if (a[i] >= 1) {           K--;           if (a[i] == 1) a[i] = -1;           if (K == 0) {             for (int j = i + 1; j < n; j++)               if (a[j] != -1) cout << j + 1 <<    ;             for (int j = 0; j <= i; j++)               if (a[j] != -1) cout << j + 1 <<    ;           }         }       }     else       for (int i = 0; i < n; i++)         if (a[i] != -1) cout << i + 1 <<    ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void pv(T a, T b) {     for (T i = a; i != b; ++i) cout << *i <<    ;     cout << endl;   }   int main() {     int N;     scanf( %d , &N);     int cnt[3] = {};     for (int i = 0; i < (int)(N); ++i) {       int a;       scanf( %d , &a);       ++cnt[a - 1];     }     cout << (N - *max_element(cnt, cnt + 3)) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class C>   constexpr int sz(const C &c) {     return int(c.size());   }   using ll = long long;   using ld = long double;   constexpr const char nl =   n , sp =    ;   using T = long double;   constexpr const T EPS = 1e-9;   bool lt(T a, T b) { return a + EPS < b; }   bool le(T a, T b) { return !lt(b, a); }   bool gt(T a, T b) { return lt(b, a); }   bool ge(T a, T b) { return !lt(a, b); }   bool eq(T a, T b) { return !lt(a, b) && !lt(b, a); }   bool ne(T a, T b) { return lt(a, b) || lt(b, a); }   int sgn(T a) { return lt(a, 0) ? -1 : lt(0, a) ? 1 : 0; }   template <class F>   struct Functor {     F f;     Functor(F f) : f(f) {}     template <class U>     bool operator()(const U &a, const U &b) const {       return f(a, b);     }   };   template <class F>   Functor<F> makeFunctor(F f) {     return Functor<F>(f);   }   using pt = complex<T>;   istream &operator>>(istream &stream, pt &p) {     T X, Y;     stream >> X >> Y;     p = pt(X, Y);     return stream;   }   ostream &operator<<(ostream &stream, const pt &p) {     return stream << p.real() <<     << p.imag();   }   bool operator<(const pt &a, const pt &b) {     return eq(a.real(), b.real()) ? lt(a.imag(), b.imag())                                   : lt(a.real(), b.real());   }   bool operator<=(const pt &a, const pt &b) { return !(b < a); }   bool operator>(const pt &a, const pt &b) { return b < a; }   bool operator>=(const pt &a, const pt &b) { return !(a < b); }   bool operator==(const pt &a, const pt &b) { return !(a < b) && !(b < a); }   bool operator!=(const pt &a, const pt &b) { return a < b || b < a; }   struct pt_lt {     bool operator()(const pt &a, const pt &b) const { return a < b; }   };   struct pt_le {     bool operator()(const pt &a, const pt &b) const { return a <= b; }   };   struct pt_gt {     bool operator()(const pt &a, const pt &b) const { return a > b; }   };   struct pt_ge {     bool operator()(const pt &a, const pt &b) const { return a >= b; }   };   struct pt_eq {     bool operator()(const pt &a, const pt &b) const { return a == b; }   };   struct pt_ne {     bool operator()(const pt &a, const pt &b) const { return a != b; }   };   T dot(const pt &a, const pt &b) {     return a.real() * b.real() + a.imag() * b.imag();   }   T cross(const pt &a, const pt &b) {     return a.real() * b.imag() - a.imag() * b.real();   }   T norm(const pt &a) { return dot(a, a); }   T distSq(const pt &a, const pt &b) { return norm(b - a); }   T dist(const pt &a, const pt &b) { return abs(b - a); }   T ang(const pt &a, const pt &b) { return arg(b - a); }   T ang(const pt &a, const pt &b, const pt &c) {     return remainder(ang(b, a) - ang(b, c), 2 * acos(T(-1)));   }   T area2(const pt &a, const pt &b, const pt &c) { return cross(b - a, c - a); }   int ccw(const pt &a, const pt &b, const pt &c) { return sgn(area2(a, b, c)); }   pt rot(const pt &a, const pt &p, const T &theta) {     return (a - p) * pt(polar(T(1), theta)) + p;   }   pt perp(const pt &a) { return pt(-a.imag(), a.real()); }   template <class It>   It sortByAng(It st, It en, const pt &pivot) {     en = partition(st, en, [&](const pt &p) { return p != pivot; });     It mid = partition(st, en, [&](const pt &p) {       return eq(p.imag(), pivot.imag()) ? lt(p.real(), pivot.real())                                         : lt(p.imag(), pivot.imag());     });     auto cmp = [&](const pt &p, const pt &q) { return 0 < ccw(pivot, p, q); };     sort(st, mid, cmp);     sort(mid, en, cmp);     return en;   }   struct Circle {     pt o;     T r;     Circle(T r = 0) : o(0, 0), r(r) {}     Circle(const pt &o, T r) : o(o), r(r) {}     int inCircle(const pt &p) { return sgn(distSq(o, p) - r * r); }   };   int circleCircleIntersection(const Circle &c1, const Circle &c2,                                vector<pt> &res) {     pt d = c2.o - c1.o;     T d2 = norm(d);     if (eq(d2, 0)) return eq(c1.r, c2.r) ? 2 : 0;     T pd = (d2 + c1.r * c1.r - c2.r * c2.r) / 2;     T h2 = c1.r * c1.r - pd * pd / d2;     if (!lt(h2, 0)) {       pt p = c1.o + d * pd / d2, h = perp(d) * sqrt(max(h2 / d2, T(0)));       res.push_back(p - h);       res.push_back(p + h);     }     sort(res.begin(), res.end(), pt_lt());     res.erase(unique(res.begin(), res.end(), pt_eq()), res.end());     return !res.empty();   }   const T PI = acos(T(-1));   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int N;     T D;     cin >> N >> D;     vector<T> R(N);     vector<pt> P(N);     pt O(0, 0);     vector<pair<T, int>> A;     for (int i = 0; i < N; i++) {       cin >> P[i] >> R[i];       T d1 = dist(O, P[i]) - R[i], d2 = dist(O, P[i]) + R[i];       int st = max(int(floor(d1 / D)) - 1, 1), en = max(int(ceil(d2 / D)) + 1, 1);       for (int k = st; k <= en; k++) {         vector<pt> Q;         circleCircleIntersection(Circle(O, k * D), Circle(P[i], R[i]), Q);         if (sz(Q) == 1) Q.push_back(Q[0]);         if (sz(Q) == 2) {           if (ccw(O, Q[0], Q[1]) == -1) swap(Q[0], Q[1]);           T ang0 = arg(Q[0]), ang1 = arg(Q[1]);           if (gt(ang0, ang1)) ang1 += 2 * PI;           for (int j = 0; j <= 2; j++) {             A.emplace_back(ang0, -1);             A.emplace_back(ang1, 1);             ang0 += 2 * PI;             ang1 += 2 * PI;           }         }       }     }     sort(A.begin(), A.end());     int sm = 0, mx = 0;     for (auto &&a : A) {       sm -= a.second;       mx = max(mx, sm);     }     cout << mx << nl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c, k, k1, ans;   int main() {     cin >> a >> b >> c;     if (b > c) swap(b, c);     if (b <= a / 2 && c > a / 2) {       cout <<  Final!  << endl;       return 0;     }     while (c != b) {       b++;       c++;       b /= 2;       c /= 2;       ans++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   using vc = vector<T>;   template <class T>   using vvc = vc<vc<T>>;   template <class T>   void mkuni(vector<T>& v) {     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());   }   long long rand_int(long long l, long long r) {     static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());     return uniform_int_distribution<long long>(l, r)(gen);   }   template <class T>   void print(T x, int suc = 1) {     cout << x;     if (suc == 1)       cout <<   n ;     else       cout <<    ;   }   template <class T>   void print(const vector<T>& v, int suc = 1) {     for (int i = 0; i < v.size(); i++)       print(v[i], i == (int)(v.size()) - 1 ? suc : 2);   }   const int maxn = 1e6 + 7;   int ed[maxn];   int p[maxn];   struct Edge {     int u, v;   } edge[maxn];   struct Q {     int tp, x;   };   int fa[maxn];   int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }   int tot;   vector<int> G[maxn];   void Union(int x, int y) {     x = Find(x), y = Find(y);     if (x == y) return;     tot++;     fa[x] = tot;     fa[y] = tot;     G[tot].push_back(x);     G[tot].push_back(y);   }   int ti[maxn], ot[maxn];   int T;   void dfs(int u, int fa = -1) {     ti[u] = ++T;     for (auto v : G[u])       if (v != fa) dfs(v, u);     ot[u] = T;   }   pair<int, int> mx[maxn << 2];   void modify(int p, int v, int L = 1, int R = tot, int o = 1) {     if (L == R) {       mx[o] = make_pair(v, p);       return;     }     int mid = L + R >> 1;     if (p <= mid)       modify(p, v, L, mid, o << 1);     else       modify(p, v, mid + 1, R, o << 1 | 1);     mx[o] = max(mx[o << 1], mx[o << 1 | 1]);   }   pair<int, int> ask(int l, int r, int L = 1, int R = tot, int o = 1) {     if (l <= L && r >= R) return mx[o];     pair<int, int> ret = {0, 0};     int mid = L + R >> 1;     if (l <= mid) ret = max(ret, ask(l, r, L, mid, o << 1));     if (r > mid) ret = max(ret, ask(l, r, mid + 1, R, o << 1 | 1));     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, m, q;     cin >> n >> m >> q;     for (int i = 1; i <= n + m + q; i++) fa[i] = i;     tot = n;     for (int i = 1; i <= n; i++) cin >> p[i];     for (int i = 1; i <= m; i++) cin >> edge[i].u >> edge[i].v, ed[i] = q;     vc<Q> query(q);     for (int i = 0; i < q; i++) {       int tp, x;       cin >> tp >> x;       if (tp == 2) ed[x] = i;       query[i] = {tp, x};     }     for (int i = 1; i <= m; i++)       if (ed[i] == q) Union(edge[i].u, edge[i].v);     for (int i = q - 1; i >= 0; i--) {       int x = query[i].x;       if (query[i].tp == 2)         Union(edge[x].u, edge[x].v);       else {         query[i].x = Find(query[i].x);         ;       }     }     for (int i = 1; i <= tot; i++)       if (Find(i) == i) dfs(i);     for (int i = 1; i <= n; i++) modify(ti[i], p[i]);     for (int i = 0; i < q; i++) {       if (query[i].tp == 1) {         int x = query[i].x;         auto tar = ask(ti[x], ot[x]);         print(tar.first);         modify(tar.second, 0);       }     }   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<char>> g;   map<long long, bool> dp;   void brute(int n, vector<int> &p) {     int x = find(p.begin(), p.end(), -1) - p.begin();     if (x == int(p.size())) {       vector<vector<char>> dp2(1 << n, vector<char>(n));       vector<int> pos1(n), pos2(n);       for (int i = 0; i < int(p.size()); i++) {         pos1[p[i]] = pos2[p[i]];         pos2[p[i]] = i;       }       for (int i = 0; i < int(n); i++)         if (g[pos1[i]][pos2[i]]) dp2[1 << i][i] = true;       for (int mask = 0; mask < int(1 << n); mask++)         for (int i = 0; i < int(n); i++)           if (dp2[mask][i]) {             for (int j = 0; j < int(n); j++)               if (!((mask >> j) & 1)) {                 dp2[mask | (1 << j)][j] |=                     (g[pos1[i]][pos1[j]] && g[pos2[i]][pos2[j]]);                 dp2[mask | (1 << j)][j] |=                     (g[pos1[i]][pos2[j]] && g[pos2[i]][pos1[j]]);               }           }       for (int i = 0; i < int(n); i++)         if (dp2[(1 << n) - 1][i]) {           long long num = 0;           for (int x : p) num = num * 6 + x;           dp[num] = true;           break;         }       return;     }     for (int y = x + 1; y < int(p.size()); ++y)       if (p[y] == -1) {         p[x] = p[y] = n;         brute(n + 1, p);         p[x] = p[y] = -1;       }   }   bool dfs(vector<int> p) {     vector<int> used(int(p.size()), -1);     int cnt = 0;     for (int i = 0; i < int(p.size()); i++)       if (used[p[i]] == -1) used[p[i]] = cnt++;     long long num = 0;     for (int &x : p) {       x = used[x];       num = num * 6 + x;     }     if (dp.count(num)) return dp[num];     bool res = false;     vector<int> cur(cnt);     for (int i = 0; i < int(p.size()); i++) ++cur[p[i]];     for (int i = 0; i < int(p.size()); i++)       if (cur[p[i]] > 2) {         int x = p[i];         for (int j = i + 1; j < int(p.size()); ++j)           if (p[j] == p[i]) {             p[i] = p[j] = cnt;             if (dfs(p)) {               res = true;               break;             }             p[i] = p[j] = x;           }         break;       }     return dp[num] = res;   }   void brute2(int n, vector<int> &p) {     int x = find(p.begin(), p.end(), -1) - p.begin();     if (x == int(p.size())) {       dfs(p);       return;     }     for (int i = 0; i < int(n + 1); i++) {       for (int y = x + 1; y < int(p.size()); ++y)         if (p[y] == -1) {           p[x] = p[y] = i;           brute2(max(n, i + 1), p);           p[x] = p[y] = -1;         }     }   }   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     g.resize(n, vector<char>(n));     for (int _ = 0; _ < int(m); _++) {       int v, u;       scanf( %d%d , &v, &u);       --v, --u;       g[v][u] = g[u][v] = 1;     }     vector<int> cur(n, -1);     brute(0, cur);     brute2(0, cur);     vector<long long> fact(k + 1);     fact[0] = 1;     for (int i = 1; i <= k; ++i) fact[i] = fact[i - 1] * i;     long long ans = 0;     for (auto it : dp)       if (it.second) {         long long num = it.first;         long long mx = 1;         while (num) {           mx = max(mx, num % 6 + 1);           num /= 6;         }         if (mx <= k) {           ans += fact[k] / fact[k - mx];         }       }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   const long long mod = 1e9 + 7;   int prime[500], judge[500], lcm[500][40], cnt, tol;   int tree[100][maxn << 2], root[maxn], ls[maxn << 6], rs[maxn << 6],       sum[maxn << 6], last[maxn << 1];   int a[maxn], ba = 1 << (int)ceil(log2(1e5 + 1));   inline void sieve() {     int sq = sqrt(maxn << 1);     for (int i = 2; i <= sq; i++) {       if (!judge[i]) prime[judge[i] = ++cnt] = i;       for (int j = 1, v; j <= judge[i] && (v = i * prime[j]) <= sq; j++)         judge[v] = j;     }   }   inline void build(int n, int no) {     int x, v = prime[no];     for (int i = 1; i <= n; i++) {       x = 0;       while (!(a[i] % v)) {         a[i] /= v;         x++;       }       tree[no][ba + i - 1] = x;     }     for (int i = ba - 1; i >= 1; i--)       tree[no][i] = max(tree[no][i << 1], tree[no][i << 1 | 1]);   }   inline int query(int l, int r, int no) {     l = l + ba - 1;     r = r + ba - 1;     int ans = 0;     while (l <= r) {       if (l & 1) ans = max(ans, tree[no][l++]);       if (~r & 1) ans = max(ans, tree[no][r--]);       l >>= 1;       r >>= 1;     }     return ans;   }   inline int powmod(long long a, int b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;       b >>= 1;     }     return ans;   }   inline int buildrt(int l, int r) {     int rt = ++tol;     if (l == r) return rt;     int mid = l + r >> 1;     ls[rt] = buildrt(l, mid);     rs[rt] = buildrt(mid + 1, r);     return rt;   }   inline int updatert(int k, int l, int r, int rt, long long v) {     int now = ++tol;     ls[now] = ls[rt], rs[now] = rs[rt], sum[now] = max(sum[rt], 1) * v % mod;     if (l == r) return now;     int mid = l + r >> 1;     if (k <= mid)       ls[now] = updatert(k, l, mid, ls[now], v);     else       rs[now] = updatert(k, mid + 1, r, rs[now], v);     return now;   }   inline long long queryrt(int rt, int l, int r, int L, int R) {     if (R < l || r < L) return 1;     if (L <= l && r <= R) return max(1, sum[rt]);     int mid = l + r >> 1;     return queryrt(ls[rt], l, mid, L, R) * queryrt(rs[rt], mid + 1, r, L, R) %            mod;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     sieve();     int n, ans = 0, l, r, q;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= cnt; i++) build(n, i);     root[0] = buildrt(1, n);     for (int i = 1; i <= n; i++) {       root[i] = root[i - 1];       if (a[i] == 1) continue;       if (last[a[i]])         root[i] = updatert(last[a[i]], 1, n, root[i], powmod(a[i], mod - 2));       root[i] = updatert(i, 1, n, root[i], a[i]);       last[a[i]] = i;     }     cin >> q;     while (q--) {       cin >> l >> r;       l = (ans + l) % n + 1;       r = (ans + r) % n + 1;       if (l > r) swap(l, r);       ans = 1;       for (int i = 1; i <= cnt; i++)         ans = (long long)ans * powmod(prime[i], query(l, r, i)) % mod;       cout << (ans = ans * queryrt(root[r], 1, n, l, r) % mod) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> p;   vector<int> t;   int main() {     int n, c, a, ans1 = 0, ans2 = 0, t1 = 0, t2 = 0;     cin >> n >> c;     for (int i = 0; i < n * 2; i++) {       cin >> a;       if (i < n) {         p.push_back(a);       } else {         t.push_back(a);       }     }     for (int i = 0; i < p.size(); i++) {       t1 += t[i];       ans1 += max(0, p[i] - c * t1);     }     for (int i = n - 1; i >= 0; i--) {       t2 += t[i];       ans2 += max(0, p[i] - c * t2);     }     if (ans1 > ans2)       cout <<  Limak ;     else if (ans2 > ans1)       cout <<  Radewoosh ;     else       cout <<  Tie ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 3e5 + 5;   int const NN = 20;   int const MAX = 1e9 + 1;   int n, a[N];   struct ITMAX {     pair<int, int> tree[4 * N];     pair<int, int> get_interval(pair<int, int> p, pair<int, int> q) {       return make_pair(min(p.first, q.first), max(p.second, q.second));     }     void build(int node, int l, int r, pair<int, int> val[]) {       if (l == r) {         tree[node] = val[l];         return;       }       int mid = (l + r) / 2;       build(node * 2, l, mid, val);       build(node * 2 + 1, mid + 1, r, val);       tree[node] = get_interval(tree[node * 2], tree[node * 2 + 1]);     }     pair<int, int> get_max(int node, int l, int r, int d, int c) {       if (l > c || r < d) {         return make_pair(MAX, -MAX);       }       if (d <= l && r <= c) {         return tree[node];       }       int mid = (l + r) / 2;       return get_interval(get_max(node * 2, l, mid, d, c),                           get_max(node * 2 + 1, mid + 1, r, d, c));     }   };   ITMAX tree[NN];   pair<int, int> dp[NN][N];   void solve_nxt() {     for (int i = 1; i <= n; i++) {       dp[0][i] = make_pair(max(i - a[i], 1), min(i + a[i], n));     }     tree[0].build(1, 1, n, dp[0]);     for (int j = 1; j < NN; j++) {       for (int i = 1; i <= n; i++) {         dp[j][i] =             tree[j - 1].get_max(1, 1, n, dp[j - 1][i].first, dp[j - 1][i].second);       }       tree[j].build(1, 1, n, dp[j]);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       a[i + n] = a[i];       a[i + n + n] = a[i];     }     if (n == 1) {       cout << 0 << endl;       return 0;     }     n *= 3;     solve_nxt();     int sq = n / 3;     for (int i = sq + 1; i <= sq + sq; i++) {       int l = i;       int r = i;       int ans = 0;       for (int j = NN - 1; j >= 0; j--) {         pair<int, int> interval = tree[j].get_max(1, 1, n, l, r);         int newL = interval.first;         int newR = interval.second;         if (newR - newL + 1 < sq) {           l = newL;           r = newR;           ans += (1 << j);         }       }       cout << ans + 1 <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   int main() {     ios::sync_with_stdio(false);     long long n;     cin >> n;     string s;     cin >> s;     if (s[0] == s[n - 1]) {       char a = s[0];       char b = s[n - 1];       long long x = 0, y = 0;       for (int i = 0; s[i] == a; i++) {         x++;       }       for (int i = n - 1; s[i] == b; i--) {         y++;       }       cout << ((x + 1) * (y + 1)) % mod;     } else {       char a = s[0];       char b = s[n - 1];       long long x = 0, y = 0;       for (int i = 0; s[i] == a; i++) {         x++;       }       for (int i = n - 1; s[i] == b; i--) {         y++;       }       cout << (x + y + 1) % mod;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int pow(long long int a, long long int b) {     long long int ans = 1;     while (b) {       if (b & 1) ans *= a;       a *= a;       b >>= 1;     }     return ans;   }   long long int powmod(long long int a, long long int b) {     long long int ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % 10000000007;       a = (a * a) % 10000000007;       b >>= 1;     }     return ans;   }   bool ispal(string &a) {     for (int i = 0; i < a.size() / 2; i++)       if (a[i] != a[a.size() - i - 1]) return false;     return true;   }   unsigned long long int sum(unsigned long long int n) {     unsigned long long int x = 0;     while (n) {       x += n % 10;       n /= 10;     }     return x;   }   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);     };     unsigned long long int n, m;     cin >> n >> m;     unsigned long long int ans = 0, p = 1;     for (int i = 0; i < m; i++) {       unsigned long long int x;       cin >> x;       ans += (p > x) ? n - p + x : x - p;       p = x;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   struct node {     int x, d;   };   vector<int> adj[100005];   vector<int> good[105];   int vis[100005];   int a[100005];   int d[100005][105];   void bfs(int s) {     queue<node> q;     for (int i = 0; i < good[s].size(); i++) {       int v = good[s][i];       node tmp;       tmp.x = v;       tmp.d = 0;       q.push(tmp);     }     while (!q.empty()) {       node t = q.front();       q.pop();       d[t.x][s] = min(d[t.x][s], t.d);       for (int i = 0; i < adj[t.x].size(); i++) {         int v = adj[t.x][i];         if (vis[v] == 0) {           vis[v] = 1;           node tmp;           tmp.x = v;           tmp.d = t.d + 1;           q.push(tmp);         }       }     }   }   int main() {     int n, m, k, s, u, v;     scanf( %d%d%d%d , &n, &m, &k, &s);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       good[a[i]].push_back(i);     }     for (int i = 0; i < m; i++) {       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     fill(d[0], d[0] + 105 * 100005, inf);     for (int i = 1; i <= k; i++) {       memset(vis, 0, sizeof(vis));       bfs(i);     }     for (int i = 1; i <= n; i++) {       sort(d[i] + 1, d[i] + 1 + k);       long long sum = 0;       for (int j = 1; j <= s; j++) sum += d[i][j];       printf( %lld  , sum);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   int n, a[N], s1[N], s2[N], ans = 0;   void judge(int x, int y, int mid) {     int tmp = 0;     if (x == y)       tmp = s1[mid] + s2[n] - s2[mid];     else       tmp = s1[x - 1] + s2[n] - s2[y] + s2[mid] - s2[x - 1] + s1[y] - s1[mid];     ans = max(ans, tmp);   }   int main() {     scanf( %d , &n);     int i, j, x, y;     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     for (i = 1; i <= n; i++) {       s1[i] = s1[i - 1];       s2[i] = s2[i - 1];       if (a[i] == 1)         s1[i]++;       else         s2[i]++;     }     int mx, val, mid;     for (x = 1; x <= n; x++) {       if (a[x] == 1)         val = -1;       else         val = 1;       mid = x;       mx = val;       judge(x, x, x);       judge(x, x, x - 1);       for (y = x + 1; y <= n; y++) {         if (a[y] == 1)           val--;         else           val++;         if (val > mx) mx = val, mid = y;         judge(x, y, mid);       }     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > q[500005];   int n, m, tot, nms, ans[500005], dep[500005], ms[500005], sz[500005],       t[500005][30], a[500005], hd[500005], to[500005], nxt[500005];   char ch[500005];   int read() {     int x = 0, fl = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fl = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * fl;   }   void add(int x, int y) {     tot++;     to[tot] = y;     nxt[tot] = hd[x];     hd[x] = tot;     return;   }   void dfs(int x, int f) {     sz[x] = 1;     int mx = 0;     for (int i = hd[x]; i; i = nxt[i]) {       int y = to[i];       if (y == f) continue;       dep[y] = dep[x] + 1, dfs(y, x);       sz[x] += sz[y];       if (sz[y] > mx) mx = sz[y], ms[x] = y;     }     return;   }   void calc(int x, int f, int o) {     t[dep[x]][a[x]] += o;     for (int i = hd[x]; i; i = nxt[i]) {       int y = to[i];       if (y == f || y == nms) continue;       calc(y, x, o);     }     return;   }   void dsu(int x, int f, int o) {     for (int i = hd[x]; i; i = nxt[i]) {       int y = to[i];       if (y == f || y == ms[x]) continue;       dsu(y, x, -1);     }     if (ms[x]) dsu(ms[x], x, 1), nms = ms[x];     calc(x, f, 1), nms = 0;     for (int p = 0; p < (int)q[x].size(); p++) {       int d = q[x][p].first, id = q[x][p].second, cnt = 0;       for (int i = 1; i <= 26; i++) cnt += (t[d][i] & 1);       ans[id] = (cnt <= 1);     }     if (o == -1) calc(x, f, -1);     return;   }   int main() {     n = read(), m = read();     for (int i = 2; i <= n; i++) {       int x = read();       add(x, i);     }     scanf( %s , ch + 1);     for (int i = 1; i <= n; i++) a[i] = ch[i] -  a  + 1;     for (int i = 1; i <= m; i++) {       int x = read(), y = read();       q[x].push_back(make_pair(y, i));     }     dep[1] = 1, dfs(1, 0), dsu(1, 0, -1);     for (int i = 1; i <= m; i++) printf( %s n , ans[i] ?  Yes  :  No );     return 0;   }


#include <bits/stdc++.h>   const int SIZE = 5e5 + 5;   using namespace std;   vector<pair<int, int> > v;   set<pair<int, int> > H;   bool used[SIZE];   int b[SIZE];   int main() {     int(n);     scanf( %d , &n);     for (int i = 0; i < (n); ++i) {       int(x);       scanf( %d , &x);       v.push_back(make_pair(x, i));       H.insert(make_pair(i, x));     }     long long an = 0;     sort((v).begin(), (v).end());     for (int i = 0; i < (((int)(v).size())); ++i) {       if (v[i].second == 0 || v[i].second == n - 1) continue;       set<pair<int, int> >::iterator it =           H.lower_bound(make_pair(v[i].second, 0));       set<pair<int, int> >::iterator it2 = it;       int now = it->second;       it2--;       int tmp = it2->second;       it2++;       it2++;       tmp = min(it2->second, tmp);       if (now <= tmp) {         used[i] = 1;         an += tmp;         H.erase(it);       }     }     int bn = 0;     for (set<pair<int, int> >::iterator it = H.begin(); it != H.end(); it++) {       b[bn++] = it->second;     }     if (bn > 2) {       sort(b, b + bn);       for (int i = 0; i + 2 < bn; i++) an += b[i];     }     cout << an << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long lint;   typedef pair<int, int> pi;   const int MAXN = 250005;      const int mod = 998244353; //1e9 + 7;//998244353;      template<typename T>   T gcd(const T &a, const T &b) {       return b == T(0) ? a : gcd(b, a % b);   }      struct mint {       int val;       mint() { val = 0; }       mint(const lint& v) {           val = (-mod <= v && v < mod) ? v : v % mod;           if (val < 0) val += mod;       }          friend ostream& operator<<(ostream& os, const mint& a) { return os << a.val; }       friend bool operator==(const mint& a, const mint& b) { return a.val == b.val; }       friend bool operator!=(const mint& a, const mint& b) { return !(a == b); }       friend bool operator<(const mint& a, const mint& b) { return a.val < b.val; }          mint operator-() const { return mint(-val); }       mint& operator+=(const mint& m) { if ((val += m.val) >= mod) val -= mod; return *this; }       mint& operator-=(const mint& m) { if ((val -= m.val) < 0) val += mod; return *this; }       mint& operator*=(const mint& m) { val = (lint)val*m.val%mod; return *this; }       friend mint ipow(mint a, lint p) {           mint ans = 1; for (; p; p /= 2, a *= a) if (p&1) ans *= a;           return ans;       }       friend mint inv(const mint& a) { assert(a.val); return ipow(a, mod - 2); }       mint& operator/=(const mint& m) { return (*this) *= inv(m); }          friend mint operator+(mint a, const mint& b) { return a += b; }       friend mint operator-(mint a, const mint& b) { return a -= b; }       friend mint operator*(mint a, const mint& b) { return a *= b; }       friend mint operator/(mint a, const mint& b) { return a /= b; }       operator int64_t() const {return val; }   };   char str[MAXN];      int main(){    int t;    scanf( %d ,&t);    while(t--){     int n;     scanf( %d ,&n);     scanf( %s , str);     int empt = n;     int ret = 0;     for(int i = 0; i < n; i++){      if(str[i] ==  0 ) continue;      int e = i;      while(e < n && str[e] ==  1 ) e++;      empt -= e - i;    //  if((e - i) % 2) empt--;      ret += (e - i) / 2;      i = e;     }     mint dap = 1, divi = 1;     for(int i = 0; i < empt + ret; i++) dap *= mint(i + 1);     for(int i = 0; i < empt; i++) divi *= mint(i + 1);     for(int i = 0; i < ret; i++) divi *= mint(i + 1);     cout << dap / divi << endl;    }   }


#include <bits/stdc++.h>   using namespace std;   string s;   long long k, n;   int index_1[(int)(1e6 + 5)], num = 0;   void solve() {     cin >> k >> s;     n = s.size();     if (k == 0) {       long long last = 0, ans = 0;       for (int i = 0; i < n; i++) {         if (s[i] ==  0 )           last++;         else {           ans += last * (last + 1) / 2;           last = 0;         }       }       ans += last * (last + 1) / 2;       cout << ans;       return;     }     for (int i = 0; i < n; i++) {       if (s[i] ==  1 ) index_1[num++] = i;     }     long long ans = 0;     for (int i = k - 1; i < num; i++) {       long long t1 = n - 1 - index_1[i] + 1;       if (i < num - 1) t1 = index_1[i + 1] - index_1[i];       long long t2 = index_1[i - (k - 1)] - 0 + 1;       if (i - (k - 1) > 0) t2 = index_1[i - (k - 1)] - index_1[i - (k - 1) - 1];       ans += t1 * t2;     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int in() {     int n;     scanf( %d , &n);     return n;   }   long long Lin() {     long long n;     scanf( %lld , &n);     return n;   }   double Din() {     double n;     scanf( %lf , &n);     return n;   }   const long long inf = (long long)1e17;   const long long mod = (long long)1e9 + 7;   const int N = 1e5 + 5;   vector<int> g[N];   bool vis[N];   int par[18][N], dep[N], sz[N];   void lca_build(int u, int d = 0) {     vis[u] = true, dep[u] = d, sz[u] = 1;     for (int i = 1; i <= 17; i++) {       par[i][u] = par[i - 1][par[i - 1][u]];     }     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (!vis[v]) {         par[0][v] = u;         lca_build(v, dep[u] + 1);         sz[u] += sz[v];       }     }   }   int lca_query(int u, int v) {     if (dep[u] < dep[v]) swap(u, v);     for (int i = 17; i >= 0 && u != v; i--) {       if (dep[par[i][u]] >= dep[v]) u = par[i][u];     }     if (u == v) return u;     for (int i = 17; i >= 0; i--) {       if (par[i][u] != par[i][v]) u = par[i][u], v = par[i][v];     }     return par[0][u];   }   int lifting(int u, int p) {     for (int i = 17; i >= 0; i--) {       if ((1 << i) <= p) u = par[i][u], p -= (1 << i);     }     return u;   }   int dis(int u, int v, int l) { return dep[u] + dep[v] - 2 * dep[l]; }   int solve() {     int n = in();     for (int i = 1; i < n; i++) {       int u = in(), v = in();       g[u].push_back(v);       g[v].push_back(u);     }     par[0][1] = 1;     lca_build(1);     int q = in();     while (q--) {       int u = in(), v = in();       int l = lca_query(u, v);       int d = dis(u, v, l);       int ans = 0;       if (u == v) {         ans = n;       } else if (d & 1) {         ans = 0;       } else if (dep[u] == dep[v]) {         int x = lifting(u, d / 2 - 1);         int y = lifting(v, d / 2 - 1);         ans = n - sz[x] - sz[y];       } else if (dep[u] > dep[v]) {         int x = lifting(u, d / 2);         int y = lifting(u, d / 2 - 1);         ans = sz[x] - sz[y];       } else {         int x = lifting(v, d / 2);         int y = lifting(v, d / 2 - 1);         ans = sz[x] - sz[y];       }       printf( %d n , ans);     }     return 0;   }   int main() {     int test = 1, tc = 0;     while (test--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[200005];   long long cum[200005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long tc;     cin >> tc;     while (tc--) {       long long n, p, k;       cin >> n >> p >> k;       for (int i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       long long ans = 0;       long long cnt = 0;       long long temp = p;       for (int i = k - 1; i < n; i += k) {         if (a[i] <= temp) {           temp -= a[i];           cnt += k;         } else           break;       }       long long sum = 0;       for (int i = 0; i < n; i++) {         sum += a[i];         cum[i] = sum;       }       ans = max(ans, cnt);       int in = 0;       while (in < k && (temp - a[in]) >= 0) {         cnt = 0;         temp = p;         temp -= cum[in];         if (temp < 0) break;         for (int i = in + k; i < n; i += k) {           if (a[i] <= temp) {             temp -= a[i];             cnt += k;           } else             break;         }         ans = max(ans, cnt + in + 1);         in++;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using lint = long long;   const lint linf = 1e18 + 7;   const lint inf = 1e9 + 7;   const int MOD = 1000000007;   void press(vector<long long>& x) {     map<int, int> memo;     int n = x.size();     for (int i = 0; i < n; ++i) {       memo[x[i]] += 1;     }     int cur = 1;     for (auto& val : memo) {       val.second = cur;       ++cur;     }     for (int i = 0; i < n; ++i) {       x[i] = memo[x[i]];     }   }   void solve() {     int n;     cin >> n;     vector<lint> a(n, 0);     for (int i = 0; i < n; ++i) cin >> a[i];     auto b = a;     press(b);     vector<vector<int>> dp(n + 5, vector<int>(3, 0));     vector<int> cnt(n + 5, 0);     for (int i = 0; i < n; ++i) cnt[b[i]] += 1;     int res = n - 1;     for (int i = 0; i < n; ++i) {       if (dp[b[i]][0] == 0) {         dp[b[i]][0] = max(dp[b[i] - 1][1], dp[b[i] - 1][2]) + 1;       }       if (dp[b[i]][1] + 1 < cnt[b[i]])         ++dp[b[i]][1];       else {         dp[b[i]][2] = dp[b[i]][0] + dp[b[i]][1];         res = min(res, n - dp[b[i]][2]);         dp[b[i]][1] += 1;       }       int hoge = dp[b[i]][1] + cnt[b[i] + 1] - dp[b[i] + 1][1];       res = min(res, n - hoge);       hoge = cnt[b[i]] - dp[b[i]][1] + dp[b[i] - 1][2] + 1;       res = min(res, n - hoge);     }     cout << res <<   n ;   }   signed main() {     cin.tie(0);     ios::sync_with_stdio(false);     int t;     cin >> t;     for (int i = 0; i < t; ++i) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int mod = 10007;   const long long INF = 1e18 + 1234;   int setbit(int n, int pos) { return n = n | (1 << pos); }   int resetbit(int n, int pos) { return n = n & ~(1 << pos); }   bool checkbit(int n, int pos) { return (bool)(n & (1 << pos)); }   template <typename T>   T mul(T x, T y) {     x %= mod;     y %= mod;     return (x * y) % mod;   }   template <typename T>   T add(T x, T y) {     x %= mod;     y %= mod;     return (x + y) % mod;   }   template <typename T>   T modPow(T x, T k, T mod) {     if (k == 0) return 1;     if (k & 1) {       return ((x % mod) * modPow(x, k - 1, mod) % mod) % mod;     } else {       T ret = modPow(x, k / 2, mod);       ret %= mod;       return (ret * ret) % mod;     }   }   template <typename T>   T ext_gcd(T num1, T num2, T& X, T& Y) {     T r2, r1, q2, q1, x2, x1, y2, y1, x, y, r;     x2 = 1;     y2 = 0;     x1 = 0;     y1 = 1;     for (r2 = num1, r1 = num2; r1 != 0;          y2 = y1, y1 = y, x2 = x1, x1 = x, r2 = r1, r1 = r) {       q1 = r2 / r1;       x = x2 - q1 * x1;       y = y2 - q1 * y1;       r = r2 % r1;     }     X = x2;     Y = y2;     return r2;   }   template <typename T>   void print(const T& v) {     cerr << v <<    ;   }   template <typename T1, typename... T2>   void print(const T1& first, const T2&... rest) {     print(first);     print(rest...);   }   template <class T>   string to_str(T t) {     stringstream second;     second << t;     return second.str();   }   template <typename T>   T modInv(T x, T m) {     return modPow(x, m - 2, m);   }   template <typename T>   void dbg_a(T a[], int n = 10) {     cerr <<  [  ;     for (int i = 0; i < n; i++) cerr << a[i] <<    ;     cerr <<   ]           <<   n ;   }   template <typename F, typename S>   ostream& operator<<(ostream& os, const pair<F, S>& p) {     return os <<  [   << p.first <<  ,   << p.second <<   ] ;   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     os <<  [  ;     for (int i = 0; i < v.size(); i++) os << v[i] <<    ;     return os <<   ] n ;   }   const int M = (int)1e6 + 123;   const int maxn = (int)1e6;   bool check(int x, int c, int m) {     int k = min(m, c);     c -= x;     m -= x;     if (c + m >= x)       return 1;     else       return 0;   }   void solve() {     int x = 2048, y, z, k, ans = 0, c, m;     cin >> c >> m >> x;     k = min(c, min(m, x));     ans = k;     c -= k;     m -= k;     x -= k;     if (c == 0 or m == 0) {       cout << ans <<   n ;       return;     }     int s = 0, e = min(c, m), mid;     int ret = 0;     while (s <= e) {       mid = s + (e - s) / 2;       if (check(mid, c, m)) {         ret = mid;         s = mid + 1;       } else {         e = mid - 1;       }     }     cout << ans + ret <<   n ;   }   int main() {     ios ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1, c = 0;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2020;   int prv[N], nxt[N], n;   long long h, x[N];   int px[N], nx[N], pxa[N], nxa[N];   bool mark[N][N][4];   double p, dp[N][N][4];   void prep() {     for (int i = n - 1; i >= 0; i--) {       if (i + 1 == n || x[i + 1] - x[i] >= h) {         nxa[i] = h;         nxt[i] = i;       } else {         nxt[i] = nxt[i + 1];         nxa[i] = min(h, x[i + 1] - x[i]);       }       if (i + 1 == n)         nx[i] = h;       else if (x[i + 1] - x[i] >= 2 * h)         nx[i] = h;       else         nx[i] = max(0LL, x[i + 1] - x[i] - h);     }     for (int i = 0; i < n; i++) {       if (i == 0 || x[i] - x[i - 1] >= h) {         pxa[i] = h;         prv[i] = i;       } else {         pxa[i] = min(h, x[i] - x[i - 1]);         prv[i] = prv[i - 1];       }       if (i == 0)         px[i] = h;       else if (x[i] - x[i - 1] >= 2 * h)         px[i] = h;       else         px[i] = max(0LL, x[i] - x[i - 1] - h);     }   }   double f(int l, int r, int mask) {     if (l > r) return 0;     if (l == r) {       int h1 = pxa[l], h2 = nxa[l];       if (mask & 1) h1 = px[l];       if (mask & 2) h2 = nx[l];       return p * h2 + (1.0 - p) * h1;     }     double &ret = dp[l][r][mask];     if (mark[l][r][mask]) return ret;     int nxtr = min(r, nxt[l]);     int h1 = nxa[nxtr];     if (mask & 2 && nxtr == r) h1 = nx[nxtr];     ret += p * ((x[nxtr] - x[l] + h1) + f(nxtr + 1, r, mask | 1));     h1 = pxa[l];     if (mask & 1) h1 = px[l];     ret += (1.0 - p) * (h1 + f(l + 1, r, mask & 2));     ret /= 2.0;     int prvl = max(l, prv[r]);     h1 = pxa[prvl];     if (mask & 1 && prvl == l) h1 = px[prvl];     double ret2 = (1.0 - p) * ((x[r] - x[prvl] + h1) + f(l, prvl - 1, mask | 2));     int hh = nxa[r];     if (mask & 2) hh = nx[r];     ret2 += p * (hh + f(l, r - 1, mask & 1));     ret2 *= 0.5;     ret += ret2;     mark[l][r][mask] = true;     return ret;   }   int main(void) {     ios::sync_with_stdio(false);     cin >> n >> h >> p;     p = 1.0 - p;     for (int i = 0; i < n; i++) cin >> x[i];     sort(x, x + n);     prep();     printf( %.11lf n , f(0, n - 1, 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 3 * 100000 + 1;     vector<int> v(n);     v[0] = 0;     for (int i = 1; i < n; i++) {       v[i] = i ^ v[i - 1];     }     int a, b, t, ans;     cin >> t;     while (t--) {       cin >> a >> b;       if (v[a - 1] == b) {         ans = a;       } else if ((v[a - 1] ^ b) == a)         ans = a + 2;       else         ans = a + 1;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b, i, p = 2e9;   int main() {     for (cin >> n; i < n; i++) {       cin >> a >> b;       if (max(a, b) <= p)         p = max(a, b);       else if (a <= p)         p = a;       else if (b <= p)         p = b;       else         return cout <<  NO , 0;     }     cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   inline int re_ad() {     int x = 0, f = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + (ch ^ 48), ch = getchar();     return x * f;   }   int a, b, m;   int rd[2010], ans;   int col[2010][2010];   struct node {     int u, v;   } e[100010];   int main() {     register int i, j, x, y;     register int co[2], now;     a = re_ad();     b = re_ad();     m = re_ad();     for (i = 1; i <= m; ++i) {       e[i].u = x = re_ad();       e[i].v = y = re_ad() + a;       ++rd[x];       ++rd[y];     }     for (i = 1; i <= a + b; ++i) ans = max(ans, rd[i]);     for (i = 1; i <= m; ++i) {       for (j = 1; j <= ans; ++j)         if (!col[e[i].u][j]) {           co[0] = j;           break;         }       for (j = 1; j <= ans; ++j)         if (!col[e[i].v][j]) {           co[1] = j;           break;         }       col[e[i].u][co[0]] = e[i].v;       col[e[i].v][co[1]] = e[i].u;       if (co[0] == co[1]) continue;       now = 1;       x = e[i].v;       while (x) {         swap(col[x][co[1]], col[x][co[0]]);         x = col[x][co[now]];         now ^= 1;       }     }     printf( %d n , ans);     for (i = 1; i <= m; ++i) {       for (j = 1; j <= ans; ++j) {         if (col[e[i].u][j] == e[i].v) {           printf( %d  , j);           break;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long x[1000006] = {}, y[1000006] = {}, a[1000006] = {}, b[1000006] = {},             x2[1000006][3], y2[1000006][3];   long long dfs(int i, long long xx, long long yy, long long px[4][2]) {     int k = i % 4;     for (int jj = 0; jj < k - 1; jj++) {       if (xx == px[jj][0] && yy == px[jj][1]) return -1;     }     px[k][0] = xx;     px[k][1] = yy;     if (i % 4 < 3) {       long long c1 = dfs(i + 1, x[i + 1], y[i + 1], px);       long long c2 = -1;       for (int jj = 0; jj < 3; jj++) {         long long c3 = dfs(i + 1, x2[i + 1][jj], y2[i + 1][jj], px);         if (c3 >= 0 && c2 == -1)           c2 = c3 + jj + 1;         else if (c3 >= 0 && c2 >= 0)           c2 = min(c2, c3 + jj + 1);       }       if (c1 < 0 && c2 < 0)         return -1;       else if (c1 >= 0 && c2 >= 0)         return min(c1, c2);       else if (c1 >= 0)         return c1;       else         return c2;     }     vector<long long> vm;     map<long long, long long> jk;     for (int ii = 0; ii < 4; ii++) {       for (int jj = ii + 1; jj < 4; jj++) {         long long rr = (px[ii][0] - px[jj][0]) * (px[ii][0] - px[jj][0]) +                        (px[ii][1] - px[jj][1]) * (px[ii][1] - px[jj][1]);         if (jk.find(rr) == jk.end()) {           jk[rr] = 1;           vm.push_back(rr);         } else           jk[rr]++;       }     }     if (vm.size() > 2) return -1;     sort(vm.begin(), vm.end());     if (jk[vm[0]] == 4 && jk[vm[1]] == 2 && 2 * vm[0] == vm[1])       return 0;     else       return -1;   }   long long check(int st) {     int i = st;     long long px[4][2] = {};     long long c1 = dfs(st, x[st], y[st], px);     long long c2 = -1;     for (int jj = 0; jj < 3; jj++) {       long long c3 = dfs(st, x2[i][jj], y2[i][jj], px);       if (c3 >= 0 && c2 == -1)         c2 = c3 + jj + 1;       else if (c3 >= 0 && c2 >= 0)         c2 = min(c2, c3 + jj + 1);     }     if (c1 < 0 && c2 < 0)       return -1;     else if (c1 >= 0 && c2 >= 0)       return min(c1, c2);     else if (c1 >= 0)       return c1;     else       return c2;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     for (int i = 0; i < 4 * n; i++) {       cin >> x[i] >> y[i] >> a[i] >> b[i];       int fx = x[i] - a[i];       int fy = y[i] - b[i];       for (int j = 2; j >= 0; j--) {         x2[i][j] = fy;         y2[i][j] = (-1) * fx;         fx = x2[i][j];         fy = y2[i][j];       }       for (int j = 0; j < 3; j++) {         x2[i][j] += a[i];         y2[i][j] += b[i];       }     }     for (int i = 0; i < 4 * n; i += 4) {       long long ct = 0;       ct = check(i);       if (ct >= 0)         cout << ct << endl;       else         cout <<  -1 n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int count = 0, sum = 0;     int n;     cin >> n;     int arr[101];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int i = 0; i < n; i++) {       sum += arr[i];     }     for (int i = 0; i < n; i++) {       if ((sum - arr[i]) % 2 == 0) count++;     }     cout << count;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   const int maxN = 80;   long long f[maxN];   int d[maxN];   const int maxD = 1000;   const int K = 13;   int dp[maxD][maxD];   bool filled = false;   pair<int, int> get(int order, long long x) {     if (order == K && filled) {       return make_pair(dp[x][1], dp[x][f[K]]);     }     if (order == 0) {       return make_pair(0, 0);     }     if (order == 1) {       return make_pair(x != 1, x != 2);     }     if (x > f[order - 1]) {       int add = 0;       while (order > 1 && x > f[order - 1]) {         x -= f[order - 1];         order -= 2;         ++add;       }       pair<int, int> current = get(order, x);       return make_pair(current.first + add, current.second);     }     pair<int, int> current = get(order - 1, x);     int toOne = min(current.first, current.second + 2);     int toN = min(current.first, current.second) + 1 + d[order - 2];     return make_pair(toOne, toN);   }   int calc(int order, long long x, long long y) {     if (order == K && filled) {       return dp[x][y];     }     if (x == y) {       return 0;     }     if (x > y) {       swap(x, y);     }     if (order == 1) {       return x != y;     }     if (order == 0) {       return 0;     }     if (f[order - 1] >= y) {       pair<int, int> a = get(order - 1, x);       pair<int, int> b = get(order - 1, y);       int score = min(a.first + b.second, a.second + b.first) + 2;       return min(score, calc(order - 1, x, y));     }     if (x > f[order - 1]) {       while (order > 1 && x > f[order - 1]) {         x -= f[order - 1];         y -= f[order - 1];         order -= 2;       }       return calc(order, x, y);     }     pair<int, int> a = get(order - 2, y - f[order - 1]);     pair<int, int> b = get(order - 1, x);     return min(b.first, b.second) + 1 + a.first;   }   void gen() {     int t = 100000;     int n = 1000;     cout << t <<     << n << endl;     for (int i = 0; i < t; ++i) {       long long x = 1LL * rand() * rand() * rand() + 1LL;       long long y = 1LL * rand() * rand() * rand() + 1LL;       cout << x <<     << y << endl;     }   }   int main() {     f[0] = 1;     f[1] = 2;     for (int i = 2; i < maxN; ++i) {       f[i] = f[i - 1] + f[i - 2];     }     d[0] = 0;     d[1] = 1;     for (int i = 2; i < maxN; ++i) {       d[i] = d[i - 2] + 1;     }     for (int i = 1; i <= f[K]; ++i) {       for (int j = i; j <= f[K]; ++j) {         dp[i][j] = dp[j][i] = calc(K, i, j);       }     }     cerr << clock() << endl;     filled = true;     int t, n;     scanf( %d%d , &t, &n);     if (n >= maxN) {       n = maxN - 1;     }     for (int i = 1; i <= t; ++i) {       long long u, v;       scanf( %I64d%I64d , &u, &v);       if (u > v) {         swap(u, v);       }       int m = n;       while (m > 20 && f[m - 5] >= v) {         --m;       }       printf( %d n , calc(m, u, v));     }     cerr << clock() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, m, r = 0, t;     cin >> n;     for (i = 0; i < n; i++) {       cin >> m;       while ((m) && (r)) {         if (m > r)           m %= r;         else           r %= m;       }       r += m;     }     cout << r * n << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 8;   const int M = 100010;   const int INF = 1 << 30;   int n, q;   map<int, int> sum, val;   void init() {     sum.clear();     val.clear();   }   void add(int p, int v) {     if (val.find(p) == val.end()) val[p] = 0;     val[p] += v;     while (p) {       if (sum.find(p) == sum.end()) sum[p] = 0;       sum[p] += v;       p /= 2;     }   }   double dfs(int h, int u, double Max) {     if (h == n) {       if (val.find(u) == val.end())         return 0.0;       else         return max(Max, (double)val[u]);     }     int l = u * 2, r = u * 2 + 1;     double L = (sum[u] - sum[r]);     double R = (sum[u] - sum[l]);     double ans1 = max(Max, R);     double ans2 = max(Max, L);     if ((double)sum[l] > Max) ans1 = max(ans1, dfs(h + 1, l, ans1));     if ((double)sum[r] > Max) ans2 = max(ans2, dfs(h + 1, r, ans2));     return (ans1 + ans2) * 0.5;   }   void solve() {     char qry[3];     while (q--) {       scanf( %s , &qry);       if (qry[0] ==  a ) {         int p, v;         scanf( %d %d , &p, &v);         add(p, v);       } else {         double res = dfs(0, 1, 0.0);         printf( %.10lf n , res);       }     }   }   int main() {     while (cin >> n >> q) {       init();       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int M = 220000;   vector<int> e1[M], e2[M];   int p[M], dis[M];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       e1[u].push_back(v);       e2[v].push_back(u);     }     int k;     cin >> k;     for (int i = 0; i < k; i++) cin >> p[i];     queue<int> q;     q.push(p[k - 1]);     dis[p[k - 1]] = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int v : e2[u]) {         if (dis[v] == 0) {           dis[v] = dis[u] + 1;           q.push(v);         }       }     }     int mi = 0, mx = 0;     for (int i = 0; i < k - 1; i++) {       if (dis[p[i]] != dis[p[i + 1]] + 1) ++mi;       for (int v : e1[p[i]]) {         if (v != p[i + 1] && dis[p[i]] == dis[v] + 1) {           ++mx;           break;         }       }     }     cout << mi <<     << mx << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int nums[n];     for (int i = 0; i < n; i++) {       cin >> nums[i];     }     if ((nums[0] % 2 == 0)) {       cout <<  No ;       return 0;     }     if ((nums[n - 1] % 2 == 0)) {       cout <<  No ;       return 0;     }     if ((n % 2) == 0) {       cout <<  No ;       return 0;     }     cout <<  Yes ;     return 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int treeNo[111111];   vector<vector<int> > BIT;   vector<pair<int, int> > E[111111];   int in[111111];   int base[111111];   int P[111111], depth[111111];   void update(int x, int val, int id) {     for (; x < BIT[id].size(); x += (x & -x)) BIT[id][x] += val;   }   int read(int x, int id) {     int sum = 0;     for (; x; x -= (x & -x)) sum += BIT[id][x];     return sum;   }   void dfs(int first, int par, int d, int id) {     P[first] = par;     depth[first] = d;     BIT[id].push_back(0);     treeNo[first] = id;     for (int i = 0; i < E[first].size(); i++) {       int u = E[first][i].first;       if (u == par) continue;       dfs(u, first, d + 1, id);       base[E[first][i].second] = u;     }   }   int main() {     int N;     cin >> N;     int u, first;     for (int i = 1; i < N; i++) {       cin >> u >> first;       E[u].push_back({first, i});       E[first].push_back({u, i});       in[u]++;       in[first]++;     }     int root = 0;     for (int i = 1; i <= N; i++)       if (in[i] > 2) root = i;     if (root == 0)       for (int i = 1; i <= N; i++)         if (in[i] == 1) root = i;     BIT.resize(E[root].size());     for (int i = 0; i < E[root].size(); i++) {       BIT[i].push_back(0);       dfs(E[root][i].first, root, 1, i);       base[E[root][i].second] = E[root][i].first;     }     int Q, t;     cin >> Q;     while (Q--) {       scanf( %d %d , &t, &first);       if (t == 3) {         scanf( %d , &u);         if (u == root or first == root) {           if (u == root) swap(u, first);           int sum = read(depth[u], treeNo[u]);           if (sum == 0)             printf( %d n , depth[u]);           else             printf( -1 n );         } else if (treeNo[u] == treeNo[first]) {           if (depth[u] == depth[first])             printf( 0 n );           else {             if (depth[first] < depth[u]) swap(u, first);             int sum =                 read(depth[first], treeNo[first]) - read(depth[u], treeNo[first]);             if (sum == 0)               printf( %d n , depth[first] - depth[u]);             else               printf( -1 n );           }         } else {           int sum = read(depth[u], treeNo[u]) + read(depth[first], treeNo[first]);           if (sum == 0)             printf( %d n , depth[first] + depth[u]);           else             printf( -1 n );         }       } else if (t == 2) {         int b = base[first];         update(depth[b], 1, treeNo[b]);       } else if (t == 1) {         int b = base[first];         update(depth[b], -1, treeNo[b]);       }     }   }


#include <bits/stdc++.h>   long long exp(long long x, long long p) {     long long ret = 1;     while (p > 0) {       if (p & 1) {         ret = (ret * x) % 1000000007;       }       p >>= 1;       x = (x * x) % 1000000007;     }     return ret;   }   signed main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     std::cout.tie(0);     long long t;     std::cin >> t;     std::vector<long long> powers(2000000, 0);     while (t--) {       long long n, p;       std::cin >> n >> p;       long long arr[n];       for (long long i = 0; i < n; i++) {         std::cin >> arr[i];       }       std::sort(arr, arr + n);       if (p == 1) {         if (n % 2)           std::cout << 1 << std::endl;         else           std::cout << 0 << std::endl;         continue;       }       long long ans = 0;       std::set<long long> pows;       long long r = n - 1;       long long cur = -1;       while (r >= 0) {         cur = arr[r];         r--;         while (r >= 0) {           powers[arr[r]]++;           pows.insert(arr[r]);           long long next = arr[r];           while (powers[next] == p) {             powers[next] = 0;             pows.erase(next);             powers[next + 1]++;             pows.insert(next + 1);             next++;           }           if (powers[cur]) {             powers[cur] = 0;             cur = -1;             pows.erase(cur);             r--;             break;           }           r--;         }       }       while (!pows.empty()) {         long long u = *pows.begin();         pows.erase(pows.begin());         ans = (ans + (exp(p, u) * powers[u]) % 1000000007) % 1000000007;         powers[u] = 0;       }       if (cur != -1) {         ans = (exp(p, cur) + 1000000007 - ans) % 1000000007;       }       std::cout << ans << std::endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 99999999;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     if (n == 1) {       cout << 1;       return 0;     }     vector<int> a(n);     ;     for (int i = 0; i < (n); ++i) cin >> a[i];     ;     vector<int> c;     for (int j = 1; j < n; ++j) {       if (a[j] > a[j - 1])         c.push_back(1);       else if (a[j] < a[j - 1])         c.push_back(-1);       else         c.push_back(0);     }     vector<pair<int, int>> d;     int p = 1;     for (int k = 1; k < c.size(); ++k) {       if (c[k] == c[k - 1])         p++;       else {         d.push_back({p, c[k - 1]});         p = 1;       }     }     d.push_back({p, c[c.size() - 1]});     vector<int> answ;     if (d[0].second == 0)       answ.push_back(3);     else if (d[0].second == -1)       answ.push_back(5);     else       answ.push_back(1);     int last = 0;     for (int i = 0; i < d.size(); ++i) {       int cnt = d[i].first;       int type = d[i].second;       if (type == 0) {         bool f = answ[last] == 3;         for (int j = 0; j < cnt - 1; ++j) {           if (f)             answ.push_back(4);           else             answ.push_back(3);           f = !f;           last++;         }         if (i + 1 < d.size() && d[i + 1].second == -1) {           if (answ[last] == 5)             answ.push_back(4);           else             answ.push_back(5);           last++;         } else if (i + 1 < d.size() && d[i + 1].second == 1) {           if (answ[last] == 1)             answ.push_back(2);           else             answ.push_back(1);           last++;         } else {           if (answ[last] == 4)             answ.push_back(3);           else             answ.push_back(4);           last++;         }       } else {         for (int j = 0; j < cnt - 1; ++j) {           answ.push_back(answ[last] + type);           last++;         }         if (answ[last] > 5 || answ[last] < 1) {           cout << -1;           return 0;         }         if (i + 1 < d.size() && d[i + 1].second == -1) {           if (answ[last] == 5) {             cout << -1;             return 0;           }           answ.push_back(5);           last++;         } else if (i + 1 < d.size() && d[i + 1].second == 1) {           if (answ[last] == 1) {             cout << -1;             return 0;           }           answ.push_back(1);           last++;         } else {           answ.push_back(answ[last] + type);           last++;           if (answ[last] > 5 || answ[last] < 1) {             cout << -1;             return 0;           }         }       }     }     for (int l = 0; l < n; ++l) {       cout << answ[l] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int LIM = 3e5 + 7;   int T[LIM][10], n, m, ans1, ans2;   bool spr(int x) {     vector<int> V[1 << m];     for (int i = 0; i < (n); ++i) {       int l = 0;       for (int j = 0; j < (m); ++j) {         if (T[i][j] >= x) l += 1 << j;       }       V[l].push_back(i);     }     for (int i = 0; i < (1 << m); ++i) {       if (!V[i].size()) continue;       for (int j = 0; j < (1 << m); ++j) {         if (!V[j].size()) continue;         if ((i | j) == (1 << m) - 1) {           ans1 = V[i][0];           ans2 = V[j][0];           return true;         }       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < (n); ++i)       for (int j = 0; j < (m); ++j) cin >> T[i][j];     int p = 0, k = 1000000000;     while (p < k) {       int sr = (p + k) / 2;       if (spr(sr))         p = sr + 1;       else         k = sr - 1;     }     spr(p);     cout << ans1 + 1 <<     << ans2 + 1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int minimumStones(string s, int n) {     int i = 0, counts = 0;     while (s[i] ==  - ) {       counts++;       i++;     }     for (int i = 0; i < n; i++) {       if (s[i] ==  - )         counts--;       else         counts++;       if (counts == 0) {         int j = i + 1;         while (s[j] ==  - ) {           counts++;           j++;         }       }     }     return counts;   }   int main() {     int n;     cin >> n;     string s;     cin >> s;     cout << minimumStones(s, n);   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-3;   const int SZ = 4000050, INF = 0x7FFFFFFF;   const double PI = acos(-1);   struct nd {     double a, b, c, d, e;     nd(double _a = 0, double _b = 0, double _c = 0, double _d = 0, double _e = 0)         : a(_a), b(_b), c(_c), d(_d), e(_e) {}     nd operator-(nd &rbs) {       return nd(a - rbs.a, b - rbs.b, c - rbs.c, d - rbs.d, e - rbs.e);     }   };   double len(nd &x) {     double res = sqrt(x.a * x.a + x.b * x.b + x.c * x.c + x.d * x.d + x.e * x.e);     return res;   }   double Dot(nd &x, nd &y) {     return (x.a * y.a + x.b * y.b + x.c * y.c + x.d * y.d + x.e * y.e) / len(x) /            len(y);   }   bool test(nd &x, nd &y) {     double ang = acos(Dot(x, y));     return ang < (PI / 2) && fabs(ang - (PI / 2)) > EPS;   }   int main() {     int pnum;     cin >> pnum;     vector<nd> vct;     if (pnum > 11) {       cout << 0 << endl;       return 0;     }     for (int i = 0; i < pnum; ++i) {       nd tmp;       cin >> tmp.a >> tmp.b >> tmp.c >> tmp.d >> tmp.e;       vct.push_back(tmp);     }     vector<int> res;     for (int i = 0; i < pnum; ++i) {       bool ok = 1;       for (int j = 0; j < pnum; ++j) {         if (j == i) continue;         for (int k = 0; k < pnum; ++k) {           if (k == j) continue;           nd ac = vct[j] - vct[i];           nd bc = vct[k] - vct[i];           if (test(ac, bc)) ok = 0;         }       }       if (ok) {         res.push_back(i + 1);       }     }     cout << res.size() << endl;     for (int i = 0; i < res.size(); ++i) {       cout << res[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5, K = 300;   int n, mx, ct, ans, a[N], buc[N], lst[N * 2], tp[N], cnt;   inline void Add(int x, int k) {     cnt -= (tp[x] == ct), tp[x] += k, cnt += (tp[x] == ct);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , a + i), ++buc[a[i]];     mx = max_element(buc + 1, buc + n + 1) - buc;     for (ct = 1; ct <= K; ++ct) {       memset(tp, 0, sizeof(tp)), cnt = 0;       for (int l = 1, r = 1; r <= n; ++r) {         Add(a[r], 1);         while (tp[a[r]] > ct) Add(a[l++], -1);         if (cnt > 1) ans = max(ans, r - l + 1);       }     }     for (int i = 1, s; i <= n; ++i)       if (i != mx && buc[i] > K) {         memset(lst, -1, sizeof(lst)), lst[s = n] = 0;         for (int j = 1; j <= n; ++j) {           s += a[j] == mx ? 1 : (a[j] == i ? -1 : 0);           if (~lst[s])             ans = max(ans, j - lst[s]);           else             lst[s] = j;         }       }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long getnum() {     char c = getchar();     long long num, sign = 1;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) sign = -1;     for (num = 0; c >=  0  && c <=  9 ;) {       c -=  0 ;       num = num * 10 + c;       c = getchar();     }     return num * sign;   }   int main() {     int n = getnum(), m = getnum();     int ans = 0;     while (1) {       if ((ans * n) % 10 == 0 && ans > 0) {         cout << ans;         return 0;       }       if ((ans * n - m) % 10 == 0) {         cout << ans;         return 0;       }       ans++;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a;     b = a;     reverse(b.begin(), b.end());     printf( %s%s n , a.c_str(), b.c_str());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long tree[400005];   int n;   long long r[100005], h[100005], v[100005];   pair<long long, int> p[100005];   int mp[100005];   void update(int nd, int bb, int ee, int ii, long long vv) {     if (bb == ee && bb == ii) {       tree[nd] = vv;       return;     }     if (bb > ii || ee < ii) return;     int ll = nd << 1, rr = ll | 1, mm = (bb + ee) >> 1;     update(ll, bb, mm, ii, vv);     update(rr, mm + 1, ee, ii, vv);     tree[nd] = max(tree[ll], tree[rr]);     return;   }   long long query(int nd, int bb, int ee, int ii, int jj) {     if (jj < ii) return 0;     if (bb >= ii && ee <= jj) return tree[nd];     if (bb > jj || ee < ii) return 0;     int ll = nd << 1, rr = ll | 1, mm = (bb + ee) >> 1;     return max(query(ll, bb, mm, ii, jj), query(rr, mm + 1, ee, ii, jj));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> r[i] >> h[i];       p[i] = {r[i] * r[i] * h[i], i};     }     sort(p, p + n);     for (int i = 0, ii = 0; i < n; i++) {       if (i > 0 && p[i].first == p[i - 1].first) ii--;       mp[p[i].second] = ii;       ii++;     }     for (int i = 0; i < n; i++) {       update(1, 0, n - 1, mp[i],              r[i] * r[i] * h[i] + query(1, 0, n - 1, 0, mp[i] - 1));     }     cout << fixed << setprecision(9) << double(tree[1]) * acos(-1.0) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[200020];   long long va[200020];   long long b[200020];   long long c[200020];   char ans[200020];   char ansstring[200020];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       va[a[i]] = i;     }     for (int i = 1; i <= n; i++) {       cin >> b[i];       c[i] = va[b[i]];     }     char ch =  a ;     for (int i = 1; i <= n; i++) {       long long reach = c[i];       if (ch >  z ) {         ch--;       }       for (int j = i; j <= reach; j++) {         reach = max(reach, c[j]);         ans[j] = ch;       }       i = reach;       ch++;     }     if (ch -  a  < k) {       cout <<  NO ;       return 0;     }     for (int i = 1; i <= n; i++) {       ansstring[b[i]] = ans[i];     }     cout <<  YES n ;     for (int i = 1; i <= n; i++) {       cout << ansstring[i];     }   }


#include <bits/stdc++.h>   using namespace std;   bool isPrime(int n) {     if (n <= 1) return false;     for (int i = 2; i < n; i++)       if (n % i == 0) return false;     return true;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int n;     cin >> n;     vector<int> v;     if (n == 1) {       cout <<  0 ;       return 0;     }     int temp;     for (long long int i = (2); i <= (n); i++) {       temp = i;       if (isPrime(i)) {         while (temp <= n) {           v.push_back(temp);           temp *= i;         }       }     }     cout << v.size() << endl;     for (auto i = v.begin(); i != v.end(); i++) cout << *i <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 120;   int a[N][N], n, k;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> k;     if (k > n * n) {       cout <<  -1 n ;     } else {       for (int i = 0; i < n && k > 0; i++) {         a[i][i] = 1, k--;         for (int j = i + 1; j < n && k > 1; j++) {           a[i][j] = 1, a[j][i] = 1, k -= 2;         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           cout << a[i][j] << (j + 1 == n ?   n  :    );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const int MAXN = 200010;   const double EPS = 1e-7;   inline int read() {     char c = getchar();     int x = 0, f = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + (c -  0 );       c = getchar();     }     return x * f;   }   char s[55], t[55];   int cnt[30], vis[55];   vector<int> pos[30];   vector<int> ans;   int main() {     int n = read();     scanf( %s , s + 1);     scanf( %s , t + 1);     for (int i = 1; i <= n; i++) cnt[s[i] -  a ]++;     for (int i = 1; i <= n; i++) pos[t[i] -  a ].push_back(i);     int flag = 1;     for (int i = 0; i < 26; i++)       if (cnt[i] != (int)((pos[i]).size())) flag = 0;     if (flag) {       for (int i = 1; i <= n; i++) {         for (int j = i; j <= n; j++) {           if (s[j] == t[i]) {             for (int k = j - 1; k >= i; k--) {               swap(s[k], s[k + 1]);               ans.push_back(k);             }             break;           }         }       }       cout << (int)((ans).size()) << endl;       for (int i = 0; i < (int)((ans).size()); i++) cout << ans[i] <<    ;     } else       puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gen(int order) {     long long sum = 0;     while (order != 0) {       sum = (sum * 10) + 9;       order--;     }     return sum;   }   int main() {     long long l, r;     cin >> l >> r;     long long p = l, k = r;     int order = 0, sorder = 0;     while (k != 0) {       k = k / 10;       order++;     }     while (p != 0) {       p = p / 10;       sorder++;     }     if (sorder == order) {       long long max = gen(order);       if ((max - 1) / 2 <= r && l <= (max - 1) / 2) {         long long ans = ((max + 1) / 2) * ((max - 1) / 2);         cout << ans;       } else {         long long max = gen(order);         if (r < (max - 1) / 2) {           long long ans = r * (max - r);           cout << ans;         } else {           long long ans = l * (max - l);           cout << ans;         }       }     } else {       long long max = gen(order);       long long smax = gen(order - 1);       if (r >= (max - 1) / 2) {         long long ans = ((max + 1) / 2) * ((max - 1) / 2);         cout << ans;       } else {         if (l <= (smax + 1) / 2) {           if ((smax + 1) * (smax - 1) / 4 > r * (max - r)) {             cout << (smax + 1) * (smax - 1) / 4;           } else {             cout << r * (max - r);           }         } else {           if (l * (smax - l) > r * (max - r)) {             cout << l * (smax - l);           } else {             cout << r * (max - r);           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T a, T b) {     return a ? gcd(b % a, a) : b;   }   template <typename T>   T lcm(T a, T b) {     return (a / gcd(a, b)) * b;   }   string int_to_str_easy(long long n) {     return n ?    : int_to_str_easy(n / 10) + (char)( 0  + n % 10);   }   template <typename T>   T sum(vector<T> v) {     T ans = 0;     for (T i : v) ans += i;     return ans;   }   bool is_down(char x) { return ( a  <= x && x <=  z ); }   bool is_upper(char x) { return ( A  <= x && x <=  Z ); }   bool is_digit(char x) { return ( 0  <= x && x <=  9 ); }   string follow(string s) {     for (int i = 0; i < s.length(); i++)       if (is_upper(s[i])) s[i] +=  a  -  A ;     return s;   }   const long double pi = 3.141592653589793238462643383279;   const long double log23 = 1.58496250072115618145373894394781;   const long double eps = 1e-8;   const long double zero = 0;   const long long INF = 1e18;   const int COUT = 30;   const int prost = 239;   const long long prost64 = 239;   const int two = 2;   const long long MOD = 1000000007;   const int BIG = 1e9;   const int alf = 26;   const int MAX_M = 2001;   const int MAX_N = 2 * 1e5 + 1;   const int km = (1 << 18) - 1;   const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};   const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};   const int dx[4] = {-1, 0, 1, 0};   const int dy[4] = {0, 1, 0, -1};   const int bit_max = 32;   void solve() { return; }   int n;   string s;   int main() {     cin.sync_with_stdio(0);     cin >> n >> s;     string e =   ;     int ans = 0;     for (int i = 0; i < n; i++) {       if (i % 2 == 0)         e +=  r ;       else         e +=  b ;     }     int now = 0;     string w = s;     int no1 = 0;     int no2 = 0;     for (int i = 0; i < n; i++) {       if (w[i] != e[i] && (i + 1) % 2 == 0)         no1++;       else if (w[i] != e[i])         no2++;     }     now = min(no1, no2) + abs(no1 - no2);     ans = now;     now = 0;     e =   ;     for (int i = 0; i < n; i++) {       if (i % 2 == 0)         e +=  b ;       else         e +=  r ;     }     w = s;     no1 = 0;     no2 = 0;     for (int i = 0; i < n; i++) {       if (w[i] != e[i] && (i + 1) % 2 == 0)         no1++;       else if (w[i] != e[i])         no2++;     }     now = min(no1, no2) + abs(no1 - no2);     ans = min(ans, now);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   const int MAXN = 1e6 + 10;   const long long MOD = 1e9 + 7;   const long long MOD2 = 998244353;   const long long INF = 8e18;   const int LOG = 22;   long long pw(long long a, long long b, long long mod) {     return (!b ? 1                : (b & 1 ? (a * pw(a * a % mod, b / 2, mod)) % mod                         : pw(a * a % mod, b / 2, mod)));   }   long long dp[2][MAXN];   int x[MAXN];   vector<int> G[MAXN];   void DFS(int v, int par) {     dp[0][v] = 1;     dp[1][v] = 0;     for (auto u : G[v]) {       if (u == par) {         continue;       }       DFS(u, v);       dp[1][v] = (dp[1][v] * dp[0][u]) % MOD;       dp[1][v] = (dp[1][v] + dp[1][u] * dp[0][v]) % MOD;       dp[0][v] = (dp[0][v] * dp[0][u]) % MOD;     }     if (x[v]) {       dp[1][v] = dp[0][v];     } else {       dp[0][v] = (dp[0][v] + dp[1][v]) % MOD;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int a;       cin >> a;       G[a].push_back(i);       G[i].push_back(a);     }     for (int i = 0; i < n; i++) {       cin >> x[i];     }     DFS(0, -1);     cout << dp[1][0] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   const int MAXN = 1e5 + 10;   const long long mod = (1ll << 32);   const long long inf = 1e16;   const int N = 1e7 + 1;   struct Query {     int l, r, id;   };   Query q[MAXN];   long long a[MAXN], p[MAXN], cntl[N], cntr[N], res[MAXN], K = 1000, k, n, Q;   long long ans = 0;   bool cmp(Query a, Query b) {     if (a.l / K != b.l / K) return a.l < b.l;     return a.r < b.r;   }   void addL(int id) {     cntr[p[id]]++;     cntl[p[id - 1]]++;     ans += cntr[k ^ p[id - 1]];   }   void addR(int id) {     cntr[p[id]]++;     cntl[p[id - 1]]++;     ans += cntl[k ^ p[id]];   }   void delL(int id) {     ans -= cntr[k ^ p[id - 1]];     cntr[p[id]]--;     cntl[p[id - 1]]--;   }   void delR(int id) {     ans -= cntl[k ^ p[id]];     cntr[p[id]]--;     cntl[p[id - 1]]--;   }   void solve() {     cin >> n >> Q >> k;     for (int i = 1; i < n + 1; ++i) {       cin >> a[i];       p[i] = p[i - 1] ^ a[i];     }     for (int i = 0; i < Q; ++i) {       int l, r;       cin >> l >> r;       q[i] = {l, r, i};     }     sort(q, q + Q, cmp);     int L = 1, R = 0;     for (int i = 0; i < Q; ++i) {       int l = q[i].l, r = q[i].r, id = q[i].id;       while (L > l) addL(--L);       while (R < r) addR(++R);       while (L < l) delL(L++);       while (R > r) delR(R--);       res[id] = ans;     }     for (int i = 0; i < Q; ++i) cout << res[i] <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     solve();   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     cin.tie(0);     ios_base::sync_with_stdio(false);     int a, ta, b, tb;     string t;     cin >> a >> ta >> b >> tb >> t;     int p =         600 * (t[0] -  0 ) + 60 * (t[1] -  0 ) + 10 * (t[3] -  0 ) + t[4] -  0 ;     int q = p + ta;     int ans = 0, i;     for (i = 300; i < 1440; i += b) {       if (p * (ta + tb) < ta * tb + p * tb + i * ta &&           ta * tb + p * tb + i * ta < q * (ta + tb))         ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   long long ara[205];   long long dp[205][205][205];   int n, k, x;   long long rec(int pos, int last, int left) {     if (last > k) return -1e17;     if (pos == n + 1) {       if (!left) return 0;       return (-1e17);     }     if (left < 0) return -1e17;     long long& ret = dp[pos][last][left];     if (~ret) return ret;     ret = -1e17;     if (rec(pos + 1, 1, left - 1) >= 0)       ret = max(ret, rec(pos + 1, 1, left - 1) + ara[pos]);     if (rec(pos + 1, last + 1, left) >= 0)       ret = max(ret, rec(pos + 1, last + 1, left));     return ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     scanf( %d %d %d , &n, &k, &x);     for (int i = 1; i <= n; i++) scanf( %lld , &ara[i]);     memset(dp, -1, sizeof dp);     printf( %lld n , (rec(1, 1, x) <= 0 ? -1 : rec(1, 1, x)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long num[300010];   long long sum[300010];   int n;   bool cmp(int a, int b) { return a > b; }   int main() {     while (~scanf( %d , &n)) {       for (int i = 0; i < n; i++) cin >> num[i];       sort(num, num + n, cmp);       sum[0] = num[0];       for (int i = 1; i < n; i++) {         sum[i] = sum[i - 1] + num[i];       }       long long ans = sum[n - 1];       for (int i = n - 2; i >= 0; i--) ans += sum[i] + num[n - 1 - i];       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double n, m, k, a, b, c;   string s;   vector<double> v;   int main() {     scanf( %lf %lf %lf , &a, &b, &c);     if (a == 0 && b == 0 && c == 0) {       printf( -1 n );       return 0;     }     if (a == 0 && b == 0 && c != 0) {       printf( 0 n );       return 0;     }     if (b * b - 4 * a * c < 0) {       printf( 0 n );       return 0;     }     if (a == 0) {       printf( 1 n );       double cev = -c / b;       printf( %lf , cev);       return 0;     }     if (b * b - 4 * a * c == 0) {       printf( 1 n );       double cev = -b / (2 * a);       printf( %lf , cev);       return 0;     }     printf( 2 n );     double cev = (-b - sqrt(b * b - 4 * a * c)) / (2 * a);     double cevap = (-b + sqrt(b * b - 4 * a * c)) / (2 * a);     v.push_back(cev);     v.push_back(cevap);     sort(v.begin(), v.end());     printf( %lf n , v[0]);     printf( %lf n , v[1]);     return 0;   }