#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int two = 0, one = 0;     int x[n + 1000];     for (int i = 0; i < n; ++i) cin >> x[i];     for (int i = 0; i < n; ++i) {       if (x[i] == 2)         ++two;       else         ++one;     }     if (two == 0) {       for (int i = 0; i < one; ++i) cout <<  1  ;     } else if (one == 0) {       for (int i = 0; i < two; ++i) cout <<  2  ;     } else {       --two;       cout <<  2  ;       --one;       cout <<  1  ;       for (int i = 0; i < two; ++i) cout <<  2  ;       for (int i = 0; i < one; ++i) cout <<  1  ;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T sqr(T x) {     return x * x;   }   const int maxn = 3 * (int)1e5 + 5;   int n;   int a[maxn];   int p[maxn];   int main() {     srand(time(NULL));     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       p[a[i]] = i;     }     int q;     cin >> q;     while (q--) {       int tst, x, y;       cin >> tst >> x >> y;       if (tst == 2) {         swap(a[x], a[y]);         p[a[x]] = x;         p[a[y]] = y;       } else {         int ans = 1;         int last = -1;         for (int i = x; i <= y; ++i) {           if (p[i] < last) ++ans;           last = p[i];         }         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string colors =  ROYGBIV ;     string remainder =  GBIVGB ;     string answer =   ;     for (int i = 0; i < n / 7; ++i) {       answer += colors;     }     for (int i = 0; i < n % 7; ++i) {       answer += remainder[i];     }     cout << answer;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, N = 1e5 + 5;   int n, m, sta[N], tp, tot, siz[N], low[N], dfn[N], be[N], bl, dep[N], f[N][22],       w[N];   vector<int> e[N], vec[N];   int read() {     int x = 0, f = 1;     char s;     while ((s = getchar()) >  9  || s <  0 )       if (s ==  - ) f = -1;     while (s >=  0  && s <=  9 )       x = (x << 1) + (x << 3) + (s ^ 48), s = getchar();     return x * f;   }   void addEdge(int u, int v) {     e[u].push_back(v);     e[v].push_back(u);   }   void tarjan(int u, int fa) {     sta[++tp] = u;     dfn[u] = low[u] = ++tot;     for (int i = 0; i < e[u].size(); ++i) {       int v = e[u][i];       if (v == fa) continue;       if (!dfn[v])         tarjan(v, u), low[u] = min(low[u], low[v]);       else         low[u] = min(low[u], dfn[v]);     }     if (low[u] == dfn[u]) {       int v = 0;       ++bl;       do {         v = sta[tp--];         be[v] = bl;         ++siz[bl];       } while (v ^ u);     }   }   int LCA(int u, int v) {     if (dep[u] < dep[v]) swap(u, v);     for (int i = 20; i >= 0; --i)       if (dep[f[u][i]] >= dep[v]) u = f[u][i];     if (u == v) return u;     for (int i = 20; i >= 0; --i)       if (f[u][i] ^ f[v][i]) u = f[u][i], v = f[v][i];     return f[u][0];   }   void dfs(int u, int fa) {     dep[u] = dep[fa] + 1;     f[u][0] = fa;     w[u] = w[fa] + (siz[u] > 1);     for (int i = 1; i <= 20; ++i) f[u][i] = f[f[u][i - 1]][i - 1];     for (int i = 0; i < vec[u].size(); ++i)       if (vec[u][i] ^ fa) dfs(vec[u][i], u);   }   int qkpow(int x, int y) {     int r = 1;     while (y) {       if (y & 1) r = 1ll * r * x % mod;       x = 1ll * x * x % mod;       y >>= 1;     }     return r;   }   int main() {     n = read(), m = read();     for (int i = 1; i <= m; ++i) addEdge(read(), read());     tarjan(1, 0);     for (int i = 1; i <= n; ++i)       for (int j = 0; j < e[i].size(); ++j)         if (be[i] ^ be[e[i][j]]) vec[be[i]].push_back(be[e[i][j]]);     dfs(1, 0);     int u, v;     for (int t = read(); t; --t) {       u = be[read()], v = be[read()];       int lca = LCA(u, v);       printf( %d n , qkpow(2, w[u] + w[v] - w[lca] * 2 + (siz[lca] > 1)));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int pct(int x) { return __builtin_popcount(x); }   int pct(long long x) { return __builtin_popcountll(x); }   int bt(int x) { return 31 - __builtin_clz(x); }   int bt(long long x) { return 63 - __builtin_clzll(x); }   int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }   long long cdiv(long long a, long long b) {     return a / b + !(a < 0 || a % b == 0);   }   int nxt_C(int x) {     int c = x & -x, r = x + c;     return (((r ^ x) >> 2) / c) | r;   }   long long nxt_C(long long x) {     long long c = x & -x, r = x + c;     return (((r ^ x) >> 2) / c) | r;   }   vector<int> get_bits(int mask) {     vector<int> bb;     while (mask) {       int b = bt(mask);       bb.push_back(b);       mask ^= (1 << b);     }     reverse(bb.begin(), bb.end());     return bb;   }   int get_mask(vector<int> v) {     int mask = 0;     for (int x : v) {       mask ^= (1 << x);     }     return mask;   }   template <typename T>   void uniq(vector<T> &v) {     sort(v.begin(), v.end());     v.resize(unique(v.begin(), v.end()) - v.begin());   }   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   long long rand(long long l, long long r) {     uniform_int_distribution<long long> uid(l, r);     return uid(rng);   }   void sc() {}   template <typename Head, typename... Tail>   void sc(Head &H, Tail &...T) {     cin >> H;     sc(T...);   }   const int mod = 1e9 + 7;   int pwr(int a, long long b) {     int ans = 1;     while (b) {       if (b & 1) ans = (ans * 1LL * a) % mod;       a = (a * 1LL * a) % mod;       b >>= 1;     }     return ans;   }   const int N = 1005;   vector<int> s[N];   int in[N];   int query(vector<int> v) {     cout <<  ?   << (int)v.size() <<    ;     for (int x : v) {       cout << x <<    ;     }     cout << endl;     int y;     sc(y);     return y;   }   int go(int l, int r, int maxi) {     if (l == r) return l;     int m = (l + r) >> 1;     vector<int> v;     for (int i = l; i <= m; i++) {       v.push_back(i);     }     int q = query(v);     if (q == maxi) {       return go(l, m, maxi);     } else {       return go(m + 1, r, maxi);     }   }   void solve() {     memset(in, 0, sizeof in);     int n, k;     sc(n, k);     for (int i = 1; i <= k; i++) {       s[i].clear();       int c;       sc(c);       for (int j = 1; j <= c; j++) {         int x;         sc(x);         s[i].push_back(x);         in[x] = i;       }     }     vector<int> v;     for (int i = 1; i <= n; i++) {       v.push_back(i);     }     int maxi = query(v);     int idx = go(1, n, maxi);     int kk = in[idx];     v.clear();     for (int i = 1; i <= n; i++) {       if (in[i] != kk) v.push_back(i);     }     int z = query(v);     cout <<  !  ;     for (int i = 1; i <= k; i++) {       if (i == kk) {         cout << z <<    ;       } else {         cout << maxi <<    ;       }     }     cout << endl;     string s;     sc(s);     if (s ==  Incorrect ) {       exit(0);     }   }   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     for (int tt = 1; tt <= t; tt++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct number {     long long sum, a, b;     bool operator<(const number& in) const { return sum < in.sum; }     bool operator>(const number& in) const { return sum > in.sum; }   };   vector<number> v;   const long long MN = 2000 + 1;   long long a[MN], b[MN];   long long n, m, suma, sumb;   int main() {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];       suma += a[i];     }     cin >> m;     for (long long j = 0; j < m; j++) {       cin >> b[j];       sumb += b[j];     }     for (long long i = 0; i < m; i++)       for (long long j = i + 1; j < m; j++) {         number temp;         temp.a = i;         temp.b = j;         temp.sum = 2 * (b[i] + b[j]);         v.push_back(temp);       }     sort(v.begin(), v.end());     long long best = abs(suma - sumb), in1 = -1, in2, in3 = -1;     for (long long i = 0; i < n; i++)       for (long long j = 0; j < m; j++)         if (best > abs(suma - sumb - a[i] - a[i] + b[j] + b[j])) {           best = abs(suma - sumb - a[i] - a[i] + b[j] + b[j]);           in1 = i;           in2 = j;         }     if (m > 1 && n > 1) {       for (long long i = 0; i < n; i++)         for (long long j = i + 1; j < n; j++) {           long long want = suma - sumb - a[i] - a[j] - a[i] - a[j];           want *= -1;           vector<number>::iterator low, up;           number temp;           temp.sum = want;           low = std::lower_bound(v.begin(), v.end(), temp);           up = upper_bound(v.begin(), v.end(), temp);           if (low >= v.begin() && low < v.end())             if (best > abs(want - v[low - v.begin()].sum)) {               best = abs(want - v[low - v.begin()].sum);               in1 = i;               in2 = j;               in3 = low - v.begin();             }           while (up >= v.end()) up--;           if (best > abs(want - v[up - v.begin()].sum)) {             best = abs(want - v[up - v.begin()].sum);             in1 = i;             in2 = j;             in3 = up - v.begin();           }         }     }     if (in1 == -1) {       cout << best << endl << 0 << endl;       return 0;     }     if (in3 == -1) {       cout << best << endl << 1 << endl << in1 + 1 <<     << in2 + 1 << endl;       return 0;     }     cout << best << endl;     cout << 2 << endl;     cout << in1 + 1 <<     << v[in3].a + 1 << endl;     cout << in2 + 1 <<     << v[in3].b + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const int xx[4] = {1, -1, 0, 0};   const int yy[4] = {0, 0, 1, -1};   int inline nextin() {     int t;     if (scanf( %d , &t) != 1) exit(0);     return t;   }   int inline in() {     int x = 0, c;     for (; (unsigned)((c = getchar()) -  0 ) >= 10;) {       if (c ==  - ) return -in();       if (!~c) throw ~0;     }     do {       x = (x << 3) + (x << 1) + (c -  0 );     } while ((unsigned)((c = getchar()) -  0 ) < 10);     return x;   }   int n, k;   string s[10005];   map<int, int> m;   int rhyme(int pos) {     string a = s[pos].substr(m[pos], ((int)(s[pos]).size()) - m[pos]);     string b =         s[pos + 1].substr(m[pos + 1], ((int)(s[pos + 1]).size()) - m[pos + 1]);     string c =         s[pos + 2].substr(m[pos + 2], ((int)(s[pos + 2]).size()) - m[pos + 2]);     string d =         s[pos + 3].substr(m[pos + 3], ((int)(s[pos + 3]).size()) - m[pos + 3]);     if (a == b && b == c && c == d) return 0;     if (a == b && c == d) return 1;     if (a == c && b == d) return 2;     if (a == d && b == c) return 3;     return -1;   }   const string ans[4] = { aaaa ,  aabb ,  abab ,  abba };   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     cin >> n >> k;     for (int i = 0; i < (4 * n); i++) cin >> s[i];     for (int i = 0; i < (4 * n); i++) {       int cnt = 0;       bool ok = false;       for (int j = ((int)(s[i]).size()) - 1; j >= 0; j--) {         if (s[i][j] ==  a  || s[i][j] ==  e  || s[i][j] ==  i  ||             s[i][j] ==  o  || s[i][j] ==  u )           cnt++;         if (cnt == k) {           m[i] = j;           ok = true;           break;         }       }       if (!ok) {         puts( NO );         return 0;       }     }     set<int> Set;     for (int i = 0; i < (n); i++) {       Set.insert(rhyme(i * 4));     }     set<int>::iterator it = Set.begin();     if (*it == -1)       puts( NO );     else if (((int)(Set).size()) >= 3)       puts( NO );     else if (((int)(Set).size()) == 2) {       if (*it == 0) {         it++;         cout << ans[*it] << endl;       } else         puts( NO );     } else       cout << ans[*it] << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     long long int a, i, j, k = 1;     scanf( %lld , &a);     for (i = 1; i <= a; i++) {       k = k * 2;     }     k = 2 * (k - 1);     printf( %lld n , k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   namespace number_theory {   long long gcd(long long x, long long y) {     if (x == 0) return y;     if (y == 0) return x;     return gcd(y, x % y);   }   bool isprime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i += 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   bool prime[15000105];   void sieve(long long n) {     for (long long i = 0; i <= n; i++) prime[i] = 1;     for (long long p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (long long i = p * p; i <= n; i += p) prime[i] = false;       }     }     prime[1] = prime[0] = 0;   }   vector<long long> primelist;   bool __primes_generated__ = 0;   void genprimes(long long n) {     __primes_generated__ = 1;     sieve(n + 1);     for (long long i = 2; i <= n; i++)       if (prime[i]) primelist.push_back(i);   }   vector<long long> factors(long long n) {     if (!__primes_generated__) {       cerr <<  Caint genprimes you dope  << endl;       exit(1);     }     vector<long long> facs;     for (long long i = 0;          primelist[i] * primelist[i] <= n && i < primelist.size(); i++) {       if (n % primelist[i] == 0) {         while (n % primelist[i] == 0) {           n /= primelist[i];           facs.push_back(primelist[i]);         }       }     }     if (n > 1) {       facs.push_back(n);     }     sort(facs.begin(), facs.end());     return facs;   }   vector<long long> getdivs(long long n) {     vector<long long> divs;     for (long long i = 1; i * i <= n; i++) {       if (n % i == 0) {         divs.push_back(i);         divs.push_back(n / i);       }     }     {       sort(divs.begin(), divs.end());       divs.erase(unique(divs.begin(), divs.end()), divs.end());     };     return divs;   }   }  // namespace number_theory   void solve() {     long long n, k;     cin >> n >> k;     string s;     cin >> s;     long long win = 0, loss = 0, winning_streak_cnt = 0;     vector<long long> lossing_streak;     for (long long i = 0; i < n; i++) {       if (s[i] ==  W ) {         win++;         if (i == 0 or s[i - 1] ==  L ) winning_streak_cnt++;       } else {         loss++;         if (i == 0 or s[i - 1] ==  W ) lossing_streak.push_back(0);         lossing_streak.back()++;       }     }     if (k >= loss) {       cout << 2 * n - 1 <<   n ;       return;     }     if (win == 0) {       if (k == 0)         cout << 0;       else         cout << 2 * k - 1;       cout <<   n ;       return;     }     win += k;     if (s[0] ==  L ) lossing_streak[0] = 1e8;     if (s[n - 1] ==  L ) lossing_streak.back() = 1e8;     sort(lossing_streak.begin(), lossing_streak.end());     for (long long ls : lossing_streak) {       if (ls > k) break;       k -= ls;       winning_streak_cnt--;     }     cout << 2 * win - winning_streak_cnt <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   int main(int argc, char **argv) {     ifstream from;     const int nmin = 2, nmax = 300, kmin = 1, kmax = 300;     int n, rt, rt1, rt2, i, j, j0, j1, k;     int err = 0;     char ch;     cin >> n;     vector<vector<int>> d(n);     for (i = 0; i < n; i++) d[i].resize(n);     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         cin >> d[i][j];       }     }     cin >> k;     vector<int> a(k);     vector<int> b(k);     vector<int> c(k);     for (i = 0; i < k; i++) {       cin >> a[i] >> b[i] >> c[i];       a[i]--;       b[i]--;     }     vector<long long> q(k);     for (i = 0; i < k; i++) {       if (d[a[i]][b[i]] > c[i]) {         d[a[i]][b[i]] = c[i];         d[b[i]][a[i]] = c[i];       }       q[i] = 0;       for (j0 = 0; j0 < n - 1; j0++) {         for (j1 = j0 + 1; j1 < n; j1++) {           rt1 = d[j0][a[i]] + d[a[i]][b[i]] + d[b[i]][j1];           rt2 = d[j0][b[i]] + d[a[i]][b[i]] + d[a[i]][j1];           rt = (rt1 < rt2) ? rt1 : rt2;           if (rt < d[j0][j1]) {             d[j0][j1] = rt;             d[j1][j0] = rt;           }           q[i] += d[j0][j1];         }       }     }     for (i = 0; i < k - 1; i++) {       cout << q[i] <<    ;     }     cout << q[k - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, i, j, k, l, sum = 0, flag = 0, t, a[200005], ans = 0;   vector<int> tree[800005];   void build(int node, int low, int high) {     if (low == high) {       tree[node].push_back(a[low]);       return;     }     int mid = (low + high) / 2;     build(2 * node, low, mid);     build(2 * node + 1, mid + 1, high);     merge((tree[2 * node]).begin(), (tree[2 * node]).end(),           (tree[2 * node + 1]).begin(), (tree[2 * node + 1]).end(),           back_inserter(tree[node]));     return;   }   int query(int node, int low, int high, int l, int r, int val) {     if (l > r) return 0;     if (low > r || high < l) return 0;     if (l <= low && high <= r)       return tree[node].end() -              lower_bound((tree[node]).begin(), (tree[node]).end(), val);     int mid = (low + high) / 2;     return query(2 * node, low, mid, l, r, val) +            query(2 * node + 1, mid + 1, high, l, r, val);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     build(1, 1, n);     for (i = 1; i <= n; i++) {       ans += query(1, 1, n, i + 1, min(a[i], n), i);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   const long long mod = 1e9 + 7;   class matrix {    public:     vector<vector<long long> > v;     matrix() { v = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; }     vector<long long>& operator[](long long loc) { return v[loc]; }   };   matrix mult(matrix a, matrix b) {     matrix c;     for (long long i = 0; i < 3; i++)       for (long long j = 0; j < 3; j++) {         c.v[i][j] = 0;         for (long long k = 0; k < 3; k++)           c.v[i][j] = (c.v[i][j] + a.v[i][k] * b.v[k][j]) % mod;       }     return c;   }   matrix power(matrix base, long long expo) {     matrix ans;     while (expo) {       if (expo & 1) {         ans = mult(base, ans);       }       base = mult(base, base);       expo = expo >> 1;     }     return ans;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, m;     cin >> n >> m;     vector<long long> b(4, 0);     vector<pair<pair<long long, long long>, long long> > v(n);     multiset<pair<long long, long long> > s;     for (long long i = 0; i < n; i++) {       cin >> v[i].second >> v[i].first.first >> v[i].first.second;       s.insert({v[i].first.first, v[i].second});       s.insert({v[i].first.second + 1, -v[i].second});     }     long long prev = 1;     matrix ans, c;     c[0] = {1, 1, 0};     c[1] = {1, 1, 1};     c[2] = {0, 1, 1};     for (auto& i : s) {       long long loc = abs(i.second);       long long curr = i.first - 1;       if (curr > prev) {         ans = mult(power(c, curr - prev), ans);         prev = curr;       }       long long val = i.second / loc;       loc--;       b[loc] += val;       if (b[loc] <= 0) {         c[loc] = {loc != 2, 1, loc != 0};       } else {         c[loc] = {0, 0, 0};       }     }     ans = mult(power(c, m - prev), ans);     cout << ans[1][1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct p {     int s, n;   };   int comp(struct p a, struct p b) { return (a.s <= b.s); }   int main() {     vector<long long> a, sb, s, r;     long long i, j, k, n, ss, sss, rrr;     cin >> n;     s.resize(n + 2, 0);     r.resize(n + 2, 0);     sb.push_back(0);     for (i = 1; i <= n; i++) {       cin >> k;       a.push_back(k);       sb.push_back(sb.back() + k);     }     ss = sb.back();     if (ss % 3 != 0 || n <= 2) {       cout <<  0  << endl;       return 0;     }     sss = 0;     rrr = 0;     for (i = 0; i < n; i++) {       if (sss == ss / 3 && i != 0) s[i]++;       if (rrr == ss / 3 && i != 0) r[i]++;       sss += a[i];       rrr += a[n - i - 1];       s[i + 1] = s[i];       r[i + 1] = r[i];     }     long long c = s[0], var = 0;     for (i = 1; i < n; i++) {       if (s[i] != c) {         c = s[i];         var += r[n - i - 1];       }     }     cout << var << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2000005;   int n, m;   int in[MAX_N];   int inv[MAX_N];   int out[MAX_N], temp[MAX_N];   int pos2bckt[MAX_N];   int bckt[MAX_N], relabel[MAX_N];   int bpos[MAX_N];   void build() {     for (int i = 0; i < n; i++) out[i] = i;     sort(out, out + n, [](int a, int bckt) { return in[a] < in[bckt]; });     for (int i = 0, c = 0; i < n; i++) {       bckt[i] = c;       if (i + 1 == n || in[out[i]] != in[out[i + 1]]) c++;     }     for (int h = 1; h < n; h <<= 1) {       for (int i = 0; i < n; i++) pos2bckt[out[i]] = bckt[i];       for (int i = n - 1; i >= 0; i--) bpos[bckt[i]] = i;       for (int i = 0; i < n; i++)         if (out[i] >= n - h) temp[bpos[bckt[i]]++] = out[i];       for (int i = 0; i < n; i++)         if (out[i] >= h) temp[bpos[pos2bckt[out[i] - h]]++] = out[i] - h;       for (int i = 0, c = 0; i < n; i++) {         relabel[i] = c;         if (i + 1 == n) break;         if (bckt[i] != bckt[i + 1])           c++;         else if (temp[i + 1] >= n - h || temp[i] >= n - h)           c++;         else if (pos2bckt[temp[i + 1] + h] != pos2bckt[temp[i] + h])           c++;       }       memcpy(out, temp, sizeof(temp[0]) * n);       memcpy(bckt, relabel, sizeof(relabel[0]) * n);     }   }   char str[MAX_N];   int cnt[MAX_N], mmn[MAX_N], rmmn[MAX_N];   int main() {     scanf( %s , str);     while (str[n]) n++;     for (int i = 0; i < n; i++) in[i] = str[i] ==  ) ;     for (int i = 0; i < n; i++) in[i + n] = in[i];     int step = 0, mn = 0;     for (int i = 0; i < n; i++) {       if (in[i] == 1)         step--;       else         step++;       cnt[i + 1] = step;       if (mn > step) mn = step;       mmn[i + 1] = mn;     }     int p = step;     for (int i = n - 1; i >= 0; i--) {       if (in[i] == 1)         step++;       else         step--;       if (p > step) p = step;       rmmn[i] = p;     }     n *= 2;     build();     n /= 2;     int c[2] = {         0,     };     for (int i = 0; i < n; i++) c[in[i]]++;     if (c[0] >= c[1]) {       for (int i = 0; i < 2 * n; i++) {         if (out[i] < n && rmmn[out[i]] - cnt[out[i]] >= 0 &&             cnt[n] - cnt[out[i]] + mmn[out[i]] >= 0) {           for (int j = 0; j < n; j++) str[j] = in[out[i] + j] == 0 ?  (  :  ) ;           for (int j = n, k = 0; k < c[0] - c[1]; j++, k++) str[j] =  ) ;           break;         }       }     } else {       for (int i = 0; i < 2 * n; i++) {         if (out[i] < n && rmmn[out[i]] - cnt[out[i]] >= c[0] - c[1] &&             cnt[n] - cnt[out[i]] + mmn[out[i]] >= c[0] - c[1]) {           for (int j = 0; j < c[1] - c[0]; j++) str[j] =  ( ;           for (int j = c[1] - c[0], k = 0; k < n; j++, k++)             str[j] = in[out[i] + k] == 0 ?  (  :  ) ;           break;         }       }     }     puts(str);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int powr(long long a, long long b) {     if (b == 0) {       return 1;     }     if (b % 2 == 0) {       return powr(((a % 1000000007) * (a % 1000000007)) % 1000000007, b / 2);     } else {       if (b == 1) {         return a;       } else {         return (a * powr(((a % 1000000007) * (a % 1000000007) % 1000000007),                          (b - 1) / 2)) %                1000000007;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long s, b;     cin >> s >> b;     long long a[s];     long long u[b];     for (long long i = 0; i < s; i++) {       cin >> a[i];     }     vector<pair<long long, long long> > p;     long long c, d;     for (long long i = 0; i < b; i++) {       cin >> c >> d;       p.push_back({c, d});       u[i] = c;     }     sort(p.begin(), p.end());     sort(u, u + b);     long long y = 0;     long long sum[b];     for (long long i = 0; i < b; i++) {       y += p[i].second;       sum[i] = y;     }     for (long long i = 0; i < s; i++) {       pair<long long, long long> cur = {a[i], INT_MAX};       auto idx = lower_bound(p.begin(), p.end(), cur);       if (idx == p.begin()) {         cout << 0 <<    ;         continue;       }       idx--;       long long j = idx - p.begin();       cout << sum[j] <<    ;     }     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using llong = long long;   using namespace std;   set<llong> factors;   void f(llong num) {     factors.insert(1);     llong to = sqrt(num);     for (auto i = 2; i <= to; ++i) {       if (num % i == 0) {         factors.insert(i);         factors.insert(num / i);       }     }     factors.insert(num);   }   int main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     llong n;     cin >> n;     f(n);     set<llong> res;     for (auto e : factors) {       res.insert((n + 1 + 1) * (n / e + 1) / 2 - (n + 1));     }     for (auto i : res) cout << i <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct {     int u, v, cu, cv;   } Edge;   const int N = 500010, M = 1000010;   pair<int, int> stk[M];   int top;   Edge e[N];   int cnt;   int fa[M];   int co[N];   int sz[M];   int st[N];   int n, m, k;   int find(int x) {     if (x == fa[x])       return x;     else       return find(fa[x]);   }   void merge(int u, int v) {     int fu = find(u), fv = find(v);     if (sz[fu] > sz[fv]) swap(fu, fv);     stk[++top] = {fu, fv};     fa[fu] = fv;     sz[fv] += sz[fu];   }   int cmp(Edge a, Edge b) {     if (a.cu == b.cu)       return a.cv < b.cv;     else       return a.cu < b.cu;   }   void undo() {     pair<int, int> t = stk[top--];     fa[t.first] = t.first;     sz[t.second] -= sz[t.first];   }   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= n + n; i++) sz[i] = 1, fa[i] = i;     for (int i = 1; i <= n; i++) cin >> co[i];     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       if (co[u] == co[v]) {         int fu = find(u), fv = find(v);         if (fu == fv) {           st[co[u]] = 1;         } else {           int fuu = find(u + n), fvv = find(v + n);           merge(fu, fvv), merge(fv, fuu);         }       } else {         e[++cnt] = {u, v, min(co[u], co[v]), max(co[v], co[u])};       }     }     long long aa = 0;     for (int i = 1; i <= k; i++)       if (!st[i]) aa++;     long long ans = aa * (aa - 1) / 2;     sort(e + 1, e + 1 + cnt, cmp);     int idx = top;     int flag = 0;     for (int i = 1; i <= cnt; i++) {       if (e[i].cv != e[i - 1].cv || e[i].cu != e[i - 1].cu) {         flag = 0;         while (idx != top) undo();       }       if (st[e[i].cv] || st[e[i].cu]) continue;       if (flag) continue;       int fu = find(e[i].u), fv = find(e[i].v);       if (fu == fv) {         ans--;         flag = 1;         continue;       }       int fuu = find(e[i].u + n), fvv = find(e[i].v + n);       merge(fu, fvv), merge(fv, fuu);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mod = 1000000007;   int dv[1000005];   int cnt[1000006];   inline void add(int &r, int a) {     r += a;     if (r >= mod) r -= mod;   }   int mPow(int a, int x) {     int ret = 1;     while (x > 0) {       if (x & 1) ret = 1LL * ret * a % mod;       a = 1LL * a * a % mod;       x >>= 1;     }     return ret;   }   int fact[200006], rfact[200006], C[200006];   int _C(int n, int k) {     if (k > n || k < 0) return 0;     return 1LL * fact[n] * rfact[k] % mod * rfact[n - k] % mod;   }   int dp[1000006], n, k, q;   int rem[55] = {0}, base;   int p[1000006];   int ans = 0, old[1000006];   inline void go3(const vector<pair<int, int>> &v, int pos, int num) {     if (pos == v.size()) {       ++cnt[num];       add(ans, mod - 1LL * p[num] * (old[num] - C[cnt[num]] + mod) % mod);       old[num] = C[cnt[num]];       return;     }     vector<int> tmp(v[pos].second + 1);     for (int i = 0; i <= v[pos].second; ++i) {       tmp[i] = num;       num *= v[pos].first;     }     rem[pos] = 0;     for (int i = v[pos].second; i >= 0; --i) {       go3(v, pos + 1, tmp[i]);       ++rem[pos];     }   }   void go1(const vector<pair<int, int>> &v, int pos, int num) {     if (pos == v.size()) {       if (base != num) {         p[base] -= p[num];       }       return;     }     for (int i = 0; i <= v[pos].second; ++i) {       go1(v, pos + 1, num);       num *= v[pos].first;     }   }   int main() {     scanf( %d%d%d , &n, &k, &q);     fact[0] = rfact[0] = 1;     for (int i = 1; i <= n + q; ++i) {       fact[i] = 1LL * fact[i - 1] * i % mod;       rfact[i] = mPow(fact[i], mod - 2);     }     for (int i = 0; i <= n + q; ++i) {       C[i] = _C(i, k);     }     for (int i = 2; i <= 1000000; ++i) {       if (dv[i] == 0) {         for (int j = i; j <= 1000000; j += i) {           if (dv[j] == 0) dv[j] = i;         }       }     }     for (int i = 1; i <= 1000000; ++i) {       p[i] = i;       int aa = i;       vector<pair<int, int>> v;       while (aa > 1) {         int d = dv[aa], cnt = 0;         while (aa % d == 0) {           aa /= d;           ++cnt;         }         v.emplace_back(make_pair(d, cnt));       }       base = i;       go1(v, 0, 1);     }     for (int i = 0; i < n + q; ++i) {       int aa;       scanf( %d , &aa);       vector<pair<int, int>> v;       while (aa > 1) {         int d = dv[aa], cnt = 0;         while (aa % d == 0) {           aa /= d;           ++cnt;         }         v.emplace_back(make_pair(d, cnt));       }       go3(v, 0, 1);       if (i >= n) {         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3fffffff;   const long long _INF = 0x7ffffffffffffffll;   const double EPS = 1e-9;   const double PI = acos(-1.0);   template <class T, class INT>   inline T pow(T x, INT y) {     T res(1);     for (T tt(x); y; y /= 2) {       if (y & 1) res *= tt;       tt *= tt;     }     return res;   }   template <class T, class INT>   inline T pow(T x, INT y, T p) {     T res(1);     for (T tt(x); y; y /= 2) {       if (y & 1) res = res * tt % p;       tt = tt * tt % p;     }     return res;   }   int toInt(string s) {     int x = 0;     istringstream sin(s);     sin >> x;     return x;   }   template <class T>   inline string toString(T x) {     ostringstream sout;     sout << x;     return sout.str();   }   template <class INT>   inline INT gcd(INT x, INT y) {     return y ? gcd(y, x % y) : x;   }   template <class INT>   inline int calc_bits(INT x) {     return x ? (x & 1) + calc_bits(x >> 1) : 0;   }   const int MAXN = 1000 + 10;   int n, m, cnt, r[MAXN], c[MAXN], u[MAXN], d[MAXN];   string a[MAXN];   double ans;   inline long long calc(int x, int n) {     return (n - x) * (n - x - 1) / 2 + (x + 1) * x / 2;   }   int main(int argc, char* argv[]) {     cin >> n >> m;     for (int i = 0; i < (n); ++i) cin >> a[i];     cnt = n * m;     memset(r, 255, sizeof(r)), memset(c, 255, sizeof(c));     for (int i = 0; i < (n); ++i)       for (int j = 0; j < (m); ++j)         if (a[i][j] ==  X ) r[i] = j, c[j] = i, --cnt;     for (int i = 0; i < (n); ++i) {       u[i] = r[i];       d[i] = m - r[i] - 1;       if (r[i] != -1) {         if (i && r[i - 1] != -1 && r[i - 1] < r[i]) u[i] += u[i - 1];         if (i && r[i - 1] != -1 && r[i - 1] > r[i]) d[i] += d[i - 1];       }     }     for (int i = (n - 1); i > (-1); --i)       if (r[i] != -1) {         if (i < n - 1 && r[i + 1] != -1 && r[i + 1] < r[i]) u[i] += u[i + 1];         if (i < n - 1 && r[i + 1] != -1 && r[i + 1] > r[i]) d[i] += d[i + 1];       }     for (int i = 0; i < (m); ++i) ans += n * n * calc(i, m);     for (int i = 0; i < (n); ++i)       for (int j = 0; j < (n); ++j) {         ans += (r[i] == -1 ? m : m - 1) * (r[j] == -1 ? m : m - 1) * abs(i - j);         if (i == j && r[i] != -1)           ans += 2 * (u[i] * (m - r[i] - 1) + d[i] * r[i]);         if (r[i] != -1) ans -= calc(r[i], m);         if (r[j] != -1) ans -= calc(r[j], m);         if (r[i] != -1 && r[j] != -1) ans += abs(r[i] - r[j]);       }     for (int i = 0; i < (m); ++i) {       u[i] = c[i];       d[i] = n - c[i] - 1;       if (c[i] != -1) {         if (i && c[i - 1] != -1 && c[i - 1] < c[i]) u[i] += u[i - 1];         if (i && c[i - 1] != -1 && c[i - 1] > c[i]) d[i] += d[i - 1];       }     }     for (int i = (m - 1); i > (-1); --i)       if (c[i] != -1) {         if (i < m - 1 && c[i + 1] != -1 && c[i + 1] < c[i]) u[i] += u[i + 1];         if (i < m - 1 && c[i + 1] != -1 && c[i + 1] > c[i]) d[i] += d[i + 1];       }     for (int i = 0; i < (m); ++i)       if (c[i] != -1) ans += 2 * (u[i] * (n - c[i] - 1) + d[i] * c[i]);     cout << setprecision(8) << fixed << ans / cnt / cnt << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1005;   const long long mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     cout << (n + 1) / 2 - 1;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return a * b / (gcd(a, b)); }   void solve() {     long long n, ans = 0;     string s;     cin >> n >> s;     for (long long i = 0; i < n - 2; i++) {       if (s[i] ==  x  && s[i + 1] ==  x  && s[i + 2] ==  x ) ans++;     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n, e = 0, aw = 0, k = 0;     cin >> n;     long a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       k = max(a[i], k);       e += a[i];     }     aw = k * n - e;     while (aw <= e) {       k++;       aw = k * n - e;     }     cout << k;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ans, t, s, a, i, b, k;   int main() {     cin >> k >> a >> b;     s = (0 - a) / k + 1;     while (a <= 0) {       a = a + s * k;       b = s * k + b;     }     ans = b / k - (a - 1) / k;     cout << ans;   }


#include <bits/stdc++.h>   int main() {     int N;     std::cin >> N;     std::set<std::pair<int, int>> doubled;     std::set<std::pair<int, int>> pending;     int to_double = 0;     int l_doubled = 0;     int64_t total_damage = 0;     int t;     int d;     for (int i = 0; i < N; i++) {       std::cin >> t;       std::cin >> d;       total_damage += d;       to_double += t * (d > 0 ? 1 : -1);       if (d > 0) {         pending.insert({d, t});       } else {         auto search = doubled.find({-d, t});         if (search != doubled.end()) {           doubled.erase(search);           l_doubled -= t;           total_damage += d;         } else {           pending.erase(pending.find({-d, t}));         }       }       if (to_double > doubled.size()) {         if (pending.size() > 0) {           auto it_pending = --pending.end();           std::pair<int, int> max = *it_pending;           doubled.insert(max);           pending.erase(it_pending);           l_doubled += max.second;           total_damage += max.first;         }       } else if (to_double < doubled.size()) {         if (doubled.size() > 0) {           auto it_doubled = doubled.begin();           std::pair<int, int> min = *it_doubled;           doubled.erase(it_doubled);           pending.insert(min);           l_doubled -= min.second;           total_damage -= min.first;         }       } else {         if (to_double > 0 && pending.size() > 0) {           auto it_doubled = doubled.begin();           auto it_pending = --pending.end();           std::pair<int, int> max = *it_pending;           std::pair<int, int> min = *it_doubled;           if (max > min) {             doubled.erase(it_doubled);             pending.erase(it_pending);             doubled.insert(max);             pending.insert(min);             l_doubled += max.second - min.second;             total_damage += max.first - min.first;           }         }       }       if (doubled.size() == to_double && l_doubled == to_double &&           to_double > 0) {         auto it_doubled = doubled.begin();         std::pair<int, int> min = *it_doubled;         doubled.erase(it_doubled);         total_damage -= min.first;         l_doubled--;         if (pending.size() > 0) {           auto it_pending = --pending.end();           std::pair<int, int> max = *it_pending;           pending.erase(it_pending);           doubled.insert(max);           total_damage += max.first;         }         pending.insert(min);       }       std::cout << total_damage << std::endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1000000;   long long a1, a2, t0, t1, t2, p1, p2, num, f, T, Tim, tot1, tot2, l, r, ans,       Num;   bool fl;   void check1(long long my) {     num = my / p1;     if (num * a1 >= f) {       if (t1 * f <= T) fl = 1;       return;     }     for (long long i = num; i >= max(0LL, num - maxN); --i) {       long long left_money = my - i * p1, left_time = T - i * tot1,                 left_data = f - i * a1;       if (left_time < 0) return;       if (left_data <= 0) {         fl = 1;         return;       }       if (t2 >= t0) {         Tim = left_data * t0;         if (Tim <= left_time) fl = 1;         return;       }       Num = left_time % tot2 ? left_time / tot2 + 1 : left_time / tot2;       Num = min(num, left_money / p2);       if (Num * a2 >= left_data)         Tim = left_data * t2;       else         Tim = Num * tot2 + (left_data - Num * a2) * t0;       if (Tim <= left_time) {         fl = 1;         return;       }       --Num;       if (Num * a2 >= left_data)         Tim = left_data * t2;       else         Tim = Num * tot2 + (left_data - Num * a2) * t0;       if (Tim <= left_time) {         fl = 1;         return;       }     }   }   void check2(long long my) {     num = my / p2;     if (num * a2 >= f) {       if (t2 * f <= T) fl = 1;       return;     }     for (long long i = num; i >= max(0LL, num - maxN); --i) {       long long left_money = my - i * p2, left_time = T - i * tot2,                 left_data = f - i * a2;       if (left_time < 0) return;       if (left_data <= 0) {         fl = 1;         return;       }       if (t1 >= t0) {         Tim = left_data * t0;         if (Tim <= left_time) fl = 1;         return;       }       Num = left_time % tot1 ? left_time / tot1 + 1 : left_time / tot1;       Num = min(Num, left_money / p1);       if (Num * a1 >= left_data)         Tim = left_data * t1;       else         Tim = Num * tot1 + (left_data - Num * a1) * t0;       if (Tim <= left_time) {         fl = 1;         return;       }       --Num;       if (Num * a1 >= left_data)         Tim = left_data * t1;       else         Tim = Num * tot1 + (left_data - Num * a1) * t0;       if (Tim <= left_time) {         fl = 1;         return;       }     }   }   bool check(long long my) {     fl = 0;     check1(my);     if (fl) return 1;     check2(my);     if (fl) return 1;     return 0;   }   int main() {     scanf( %lld%lld%lld , &f, &T, &t0);     scanf( %lld%lld%lld , &a1, &t1, &p1);     tot1 = a1 * t1;     scanf( %lld%lld%lld , &a2, &t2, &p2);     tot2 = a2 * t2;     if (t0 * f <= T) {       puts( 0 );       return 0;     }     num = T % tot1 ? T / tot1 + 1 : T / tot1;     r = num * p1;     num = T % tot2 ? T / tot2 + 1 : T / tot2;     r = max(r, num * p2);     l = 1;     r *= 2;     ans = -1;     while (l <= r) {       long long mid = (l + r) >> 1;       if (check(mid))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> e[200010];   vector<int> a;   int n;   int siz[200010];   int id[200010];   int d[200010];   int c[200010];   int f[200010];   int dfn;   void dfs(int x, int fa) {     id[x] = ++dfn;     siz[x]++;     for (int i = 0; i < e[x].size(); i++) {       if (e[x][i] == fa) continue;       dfs(e[x][i], x);       siz[x] += siz[e[x][i]];     }   }   void dfs(int x, int fa, int *y) {     int temp = (n - siz[x]);     bool flag = true;     for (int i = 0; i < e[x].size(); i++) {       if (e[x][i] == fa) continue;       dfs(e[x][i], x, y);       if (temp != siz[e[x][i]]) {         flag = false;       }     }     if (flag && siz[x] > 1) {       *y = x;     }   }   bool judge(int x, int fa, int dep) {     if (c[x] != -1 && f[x] != fa && c[x] != fa) return false;     f[x] = -1;     for (int i = 0; i < e[x].size(); i++) {       int nt = e[x][i];       if (nt == fa) continue;       int son_siz = siz[nt];       if (id[x] > id[nt]) son_siz = n - siz[x];       if (d[dep] == -1) {         d[dep] = son_siz;       }       if (d[dep] != son_siz) {         c[x] = nt;         return false;       }       f[x] = nt;     }     for (int i = 0; i < e[x].size(); i++) {       int nt = e[x][i];       if (nt == fa) continue;       if (!judge(nt, x, dep + 1)) {         c[x] = nt;         return false;       }       f[x] = nt;     }     f[x] = -1;     return true;   }   inline bool scan_d(int &num) {     char in;     bool IsN = false;     in = getchar();     if (in == EOF) return false;     while (in !=  -  && (in <  0  || in >  9 )) in = getchar();     if (in ==  - ) {       IsN = true;       num = 0;     } else       num = in -  0 ;     while (in = getchar(), in >=  0  && in <=  9 ) {       num *= 10, num += in -  0 ;     }     if (IsN) num = -num;     return true;   }   int main() {     int x = -1, u, v, k = -1;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scan_d(u);       scan_d(v);       if (k == -1) k = u;       e[u].push_back(v);       e[v].push_back(u);     }     dfs(1, 1);     dfs(1, 1, &x);     for (int i = 1; i <= n; i++) {       if (e[i].size() <= 1) {         a.push_back(i);       }     }     if (x != -1) {       a.push_back(x);     }     memset(d, -1, sizeof(d));     memset(c, -1, sizeof(c));     memset(f, -1, sizeof(f));     for (int i = 0; i < a.size(); i++) {       if (judge(a[i], a[i], 1)) {         printf( %d n , a[i]);         return 0;       }       for (int i = 1;; i++) {         if (d[i] == -1) break;         d[i] = -1;       }     }     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[] = {1, 0, -1, 0};   const int dy[] = {0, 1, 0, -1};   struct Point {     int x, y;   } Q[2000 * 2000], P, np;   int n, m;   int b[2000][2000];   int mark[2000][2000], T;   int L[2000 * 2000];   int flag[2000][2000];   bool out(int x, int y) { return x < 0 || y < 0 || x >= n || y >= m; }   void Mark(int x, int y) {     int head, tail;     int d, i, j, k;     head = tail = 0;     Q[tail].x = x;     Q[tail].y = y;     tail++;     while (head < tail) {       P = Q[head++];       for (d = 0; d < 4; d++) {         np.x = P.x + dx[d];         np.y = P.y + dy[d];         if (out(np.x, np.y) || b[np.x][np.y] == 0) continue;         if (mark[np.x][np.y] != T) {           mark[np.x][np.y] = T;           Q[tail++] = np;         }       }     }   }   int count(int x, int y) {     int i, j, nx, ny;     int cnt(0);     int dx, dy;     for (i = -2; i <= 2; i++)       for (j = -2; j <= 2; j++) {         nx = x + i;         ny = y + j;         if (out(nx, ny)) continue;         if (mark[nx][ny] == mark[x][y]) cnt++;       }     if (cnt != 9) return false;     for (dx = -1; dx <= 1; dx += 2)       for (dy = -1; dy <= 1; dy += 2) {         for (i = 0; i < 3; i++) {           for (j = 0; j < 3; j++) {             nx = x + dx * i;             ny = y + dy * j;             if (out(nx, ny) || b[nx][ny] == 0) break;             if (mark[nx][ny] != mark[x][y]) break;           }           if (j < 3) break;         }         if (i == 3) return true;       }     return false;   }   int remove(int x, int y) {     int head, tail;     int d, i, j, k;     head = tail = 0;     Q[tail].x = x;     Q[tail].y = y;     tail++;     flag[x][y] = true;     for (k = 0; k < 10; k++) {       for (i = tail; head < i; head++) {         P = Q[head];         for (d = 0; d < 4; d++) {           np.x = P.x + dx[d];           np.y = P.y + dy[d];           if (out(np.x, np.y) || b[np.x][np.y] == 0) continue;           if (mark[np.x][np.y] != mark[x][y]) continue;           if (flag[np.x][np.y] == false) {             flag[np.x][np.y] = true;             Q[tail++] = np;           }         }       }     }     return tail <= 40;   }   int main() {     int i, j, k, d;     int cnt, x, y;     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) scanf( %d , b[i] + j);     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (b[i][j] == 0 || mark[i][j]) continue;         T++;         Mark(i, j);       }     }     printf( %d n , T);     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         cnt = 0;         if (!mark[i][j] || flag[i][j]) continue;         for (d = 0; d < 4; d++) {           x = i + dx[d];           y = j + dy[d];           if (out(x, y)) continue;           cnt += b[x][y];         }         if (cnt >= 3) continue;         if (count(i, j) && remove(i, j)) {           L[mark[i][j]]++;         }       }     }     sort(L + 1, L + T + 1);     for (i = 1; i <= T; i++) {       if (i > 1) printf(   );       printf( %d , L[i]);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   const int mn = 55;   const int mm = 2505;   const int mod = 1000000007;   int n, m, T;   int t[mm], g[mm];   int a[mn][mm];   int bc[mn][mn][mm];   int way[mn][mn][mn][3];   int cnt[3];   void init_a() {     memset(a, -2, sizeof a);     a[0][0] = 1;     for (int k = 1; k <= n; k++) {       if (g[k]) continue;       for (int i = cnt[0]; i >= 0; i--) {         for (int j = T - t[k]; j >= 0; j--) {           if (a[i][j] <= 0) continue;           int &ans = a[i + 1][j + t[k]];           if (ans < 0) ans = 0;           ans += a[i][j];           if (ans >= mod) ans -= mod;         }       }       cnt[0]++;     }   }   void init_bc() {     memset(bc, -2, sizeof bc);     bc[0][0][0] = 1;     for (int k = 1; k <= n; k++) {       if (!g[k]) continue;       for (int i = cnt[1]; i >= 0; i--) {         for (int j = cnt[2]; j >= 0; j--) {           for (int l = T - t[k]; l >= 0; l--) {             if (bc[i][j][l] <= 0) continue;             int &ans = bc[i + (g[k] == 1)][j + (g[k] == 2)][l + t[k]];             if (ans < 0) ans = 0;             ans += bc[i][j][l];             if (ans >= mod) ans -= mod;           }         }       }       if (g[k] == 1)         cnt[1]++;       else         cnt[2]++;     }   }   void inc(int &a, int b) {     if (a < 0) a = 0;     a += b;     if (a >= mod) a -= mod;   }   void init_way() {     memset(way, -2, sizeof(way));     way[1][0][0][0] = way[0][1][0][1] = way[0][0][1][2] = 1;     for (int i = 0; i <= cnt[0]; i++) {       for (int j = 0; j <= cnt[1]; j++) {         for (int k = 0; k <= cnt[2]; k++) {           for (int last = 0; last < 3; last++) {             for (int nxt = 0; nxt < 3; nxt++) {               if (nxt == last || way[i][j][k][last] <= 0) continue;               int uans = way[i][j][k][last];               if (nxt == 0)                 inc(way[i + 1][j][k][0], uans);               else if (nxt == 1)                 inc(way[i][j + 1][k][1], uans);               else                 inc(way[i][j][k + 1][2], uans);             }           }         }       }     }   }   inline int getway(int i, int j, int k) {     int ans = 0;     for (int last = 0; last < 3; last++) {       if (way[i][j][k][last] <= 0) continue;       inc(ans, way[i][j][k][last]);     }     return ans;   }   int fact[105];   int main() {     scanf( %d%d , &n, &T);     for (int i = 1; i <= n; i++) scanf( %d%d , &t[i], &g[i]), g[i]--;     fact[0] = 1;     for (int i = 1; i <= 55; i++) fact[i] = (long long)fact[i - 1] * i % mod;     init_a();     init_bc();     init_way();     long long ans = 0;     for (int i = 0; i <= cnt[0]; i++) {       for (int j = 0; j <= cnt[1]; j++) {         for (int k = 0; k <= cnt[2]; k++) {           for (int t = 0; t <= T; t++) {             if (a[i][t] <= 0 || bc[j][k][T - t] <= 0) continue;             ans = (ans + (long long)a[i][t] * bc[j][k][T - t] % mod *                              getway(i, j, k) % mod * fact[i] % mod * fact[j] %                              mod * fact[k]) %                   mod;           }         }       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n);     int i;     for (i = 0; i < n && arr[i] + k <= 5; i++)       ;     cout << (i) / 3;   }


#include <bits/stdc++.h>   using namespace std;   bool isPrime(int n) {     for (int i = 2; (i * i) <= n; i++) {       if (n % i == 0) return 0;     }     return 1;   }   int nerPr(int n) {     for (int i = n;; i++) {       if (isPrime(i)) return i;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> a;     int mn = (int)1e9;     for (int i = 0; i < n; i++) {       int d;       cin >> d;       a.push_back(d);       mn = min(mn, d);       if (d == 1) {         cout <<  -1 n ;         exit(0);       }     }     cout << 1;   }


#include <bits/stdc++.h>   using namespace std;   const long long linf = 4000000000000000000LL;   const long long inf = 1000000007;   const long double pi = 3.1415926535;   void pv(vector<int> a) {     for (auto& x : a) cout << x <<    ;     cout <<   n ;   }   void pv(vector<long long> a) {     for (auto& x : a) cout << x <<    ;     cout <<   n ;   }   void pv(vector<vector<int> > a) {     for (int i = (0); i < (int(a.size())); ++i) {       cout << i <<   n ;       pv(a[i]);       cout <<   n ;     }   }   void pv(vector<vector<long long> > a) {     for (int i = (0); i < (int(a.size())); ++i) {       cout << i <<   n ;       pv(a[i]);     }     cout <<   n ;   }   void pv(vector<string> a) {     for (auto& x : a) cout << x <<   n ;     cout <<   n ;   }   void setIO(string second) {     ios_base::sync_with_stdio(0);     cin.tie(0);     if (int(second.size())) {       freopen((second +  .in ).c_str(),  r , stdin);       if (second !=  test1 ) freopen((second +  .out ).c_str(),  w , stdout);     }   }   int n;   vector<long double> a;   vector<vector<int> > adj;   vector<int> parent;   void dfs(int i, int p) {     parent[i] = p;     for (auto& x : adj[i]) {       if (x == p) continue;       dfs(x, i);     }   }   int main() {     setIO(  );     cin >> n;     a.resize(n);     for (auto& x : a) cin >> x, x = 1 - x;     adj.resize(n);     for (int i = (0); i < (n - 1); ++i) {       int x, y;       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     parent.resize(n);     dfs(0, -1);     vector<long double> b(n, 1);     for (int i = (0); i < (n); ++i)       for (auto& x : adj[i])         if (x != parent[i]) b[i] -= a[x];     long double ans = 0;     for (int i = (0); i < (n); ++i) ans += a[i] * b[i];     int testc;     cin >> testc;     while (testc--) {       int i;       long double x;       cin >> i >> x;       x = 1 - x;       long double y = a[i];       if (parent[i] != -1) {         b[parent[i]] -= x - y;         ans -= (x - y) * a[parent[i]];       }       ans += (x - y) * b[i];       a[i] = x;       cout << fixed << setprecision(20) << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 6;   const int M = 10010;   const int K = 510;   const int LIT = 2500;   const int INF = 1 << 30;   int n, m[N][N], tot, need;   vector<int> v, vis;   int row[N], col[N], dia1, dia2;   int cr[N], cc[N], cd1, cd2;   void init() {     memset(m, 0, sizeof(m));     memset(row, 0, sizeof(row));     memset(col, 0, sizeof(col));     dia1 = dia2 = 0;     memset(cr, 0, sizeof(cr));     memset(cc, 0, sizeof(cc));     cd1 = cd2 = 0;     tot = n * n;     need = 0;     v = vector<int>(n * n);     vis = vector<int>(n * n);     for (int i = 0; i < tot; i++) cin >> v[i];     sort(v.begin(), v.end());     for (int i = 0; i < tot; i++) need += v[i];     need /= n;   }   void insert(int x, int y, int p, int ord) {     m[x][y] = v[p];     vis[p] = (ord > 0) ? 1 : 0;     int tmp = v[p] * ord;     row[x] += tmp;     cr[x] += ord;     col[y] += tmp;     cc[y] += ord;     if (x == y) dia1 += tmp, cd1 += ord;     if (x + y == n + 1) dia2 += tmp, cd2 += ord;   }   void out(int sum) {     printf( %d n , sum);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) printf( %d  , m[i][j]);       printf(  n );     }   }   bool check() {     int sum = dia1;     for (int i = 1; i <= n; i++)       if (sum != row[i]) return 0;     for (int i = 1; i <= n; i++)       if (sum != col[i]) return 0;     if (dia1 != dia2) return 0;     out(sum);     return 1;   }   const int nxt[][2] = {{1, 1}, {1, 2}, {1, 3}, {2, 1}, {3, 1}, {1, 4},                         {4, 1}, {2, 2}, {3, 3}, {4, 4}, {2, 3}, {2, 4},                         {3, 2}, {3, 4}, {4, 2}, {4, 3}};   const int bnd = 16;   int num[N * N];   bool check(int cnt, int sum) {     if (cnt == n) return (sum == need);     if (cnt == n - 1) {       for (int i = 0; i < tot; i++)         if (!vis[i] && sum + v[i] == need) return 1;       return 0;     }     if (cnt == n - 2) {       int p = 0, x = need - sum;       ;       for (int i = 0; i < tot; i++)         if (!vis[i]) num[p++] = v[i];       int l = 0, r = p - 1;       while (l < r) {         int tmp = num[l] + num[r];         if (tmp == x) return 1;         if (tmp < x) l++;         if (tmp > x) r--;       }       return 0;     }     return 1;   }   bool validate() {     if (!check(cd1, dia1)) return 0;     if (!check(cd2, dia2)) return 0;     for (int i = 1; i <= n; i++) {       if (!check(cr[i], row[i])) return 0;       if (!check(cc[i], col[i])) return 0;     }     return 1;   }   bool dfs1(int x, int y) {     if (x > n) return check();     int xx = x, yy = y + 1;     if (yy > n) xx++, yy = 1;     for (int i = 0; i < tot; i++) {       if (vis[i]) continue;       insert(x, y, i, 1);       if (validate() && dfs1(xx, yy)) return 1;       insert(x, y, i, -1);     }     return 0;   }   bool dfs(int p) {     if (p >= bnd) return check();     int x = nxt[p][0], y = nxt[p][1];     for (int i = 0; i < tot; i++) {       if (vis[i]) continue;       insert(x, y, i, 1);       if (validate() && dfs(p + 1)) return 1;       insert(x, y, i, -1);     }     return 0;   }   void solve() {     if (n <= 3)       dfs1(1, 1);     else       dfs(0);   }   int main() {     while (cin >> n) {       init();       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, x, y, ans;   int p[100010], q[100010], mn[100010];   vector<int> t[100010], v[100010];   bool flag[100010];   inline int dist(int x, int y) { return abs(p[x] - q[y]); }   int main() {     scanf( %d%d%d%d , &n, &m, &x, &y);     memset(mn, 63, sizeof(mn));     for (int i = 1; i <= n; i++) scanf( %d , &p[i]);     for (int i = 1; i <= m; i++) scanf( %d , &q[i]);     q[m + 1] = 1e9;     q[0] = -1e9;     int pos = 1;     for (int i = 1; i <= n; i++) {       while (pos <= m && q[pos] <= p[i]) pos++;       pos--;       if (dist(i, pos) == dist(i, pos + 1)) {         t[i].push_back(pos);         t[i].push_back(pos + 1);       } else if (dist(i, pos) < dist(i, pos + 1)) {         t[i].push_back(pos);       } else {         t[i].push_back(pos + 1);       }     }     for (int i = 1; i <= n; i++)       if (t[i].size() == 1) {         int t1 = t[i][0];         v[t1].push_back(i);         mn[t1] = min(mn[t1], dist(i, t1));       }     for (int i = 1; i <= n; i++)       if (t[i].size() == 1) {         int t1 = t[i][0];         if (dist(i, t1) > mn[t1]) flag[i] = 1;       }     for (int i = 1; i <= n; i++)       if (t[i].size() == 2) {         bool flag1 = 0, flag2 = 0;         int cnt1 = 0, cnt2 = 0;         int t1 = t[i][0], t2 = t[i][1], d = dist(i, t1);         for (int j = 0; j < v[t1].size(); j++) {           if (dist(v[t1][j], t1) < d) flag1 = 1;           if (d < dist(v[t1][j], t1))             if (flag[v[t1][j]] == 0) cnt1++;         }         for (int j = 0; j < v[t2].size(); j++) {           if (dist(v[t2][j], t2) < d) flag2 = 1;           if (d < dist(v[t2][j], t2))             if (flag[v[t2][j]] == 0) cnt2++;         }         if (cnt1 + flag1 <= cnt2 + flag2) {           flag[i] = flag1;           for (int j = 0; j < v[t1].size(); j++)             if (d < dist(v[t1][j], t1)) flag[v[t1][j]] = 1;           mn[t1] = min(mn[t1], dist(i, t1));           v[t1].push_back(i);         } else {           flag[i] = flag2;           for (int j = 0; j < v[t2].size(); j++)             if (d < dist(v[t2][j], t2)) flag[v[t2][j]] = 1;           mn[t2] = min(mn[t2], dist(i, t2));           v[t2].push_back(i);         }       }     for (int i = 1; i <= n; i++) ans += flag[i];     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void reset(int& n, int first) { n = n & ~(1 << first); }   bool check(int n, int first) { return (bool)(n & (1 << first)); }   set<int> ax, ay;   multiset<int> bx, by;   set<int>::iterator l, r;   int main() {     int i, j, k, n, w, h;     while (scanf( %d%d%d , &w, &h, &n) == 3) {       ax.clear();       ay.clear();       bx.clear();       by.clear();       ax.insert(0);       ax.insert(h);       ay.insert(0);       ay.insert(w);       bx.insert(h);       by.insert(w);       for (i = 0; i < n; i++) {         char ch;         int v;         scanf( %c%c%d , &ch, &ch, &v);         if (ch ==  H ) {           r = ax.lower_bound(v);           l = --r;           r++;           bx.erase(bx.find(*r - *l));           ax.insert(v);           bx.insert(v - *l);           bx.insert(*r - v);         } else {           r = ay.lower_bound(v);           l = --r;           r++;           by.erase(by.find(*r - *l));           ay.insert(v);           by.insert(v - *l);           by.insert(*r - v);         }         long long ans = (long long)(*bx.rbegin()) * (*by.rbegin());         cout << ans << endl;       }     }   }


#include <bits/stdc++.h>   int main() {     int a, b, c = 0, d, e, i;     scanf( %d , &a);     for (i = 1; i <= a; i++) {       scanf( %d , &b);       if (b == 1) {         c++;       }     }     if (c > 0) {       printf( HARD n );     } else {       printf( EASY n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mini[10], maxi[10], dist[10];   int main() {     int n, i, total;     scanf( %d , &n);     total = 0;     for (i = 0; i < 3; ++i) {       scanf( %d %d , &mini[i], &maxi[i]);       total += mini[i];       dist[i] = mini[i];     }     i = 0;     while (n - total > 0) {       int available, pot;       available = maxi[i] - mini[i];       pot = n - total;       dist[i] += min(available, pot);       total += min(available, pot);       i++;     }     for (i = 0; i < 2; ++i) {       printf( %d  , dist[i]);     }     printf( %d n , dist[2]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 200002;   int val[M];   vector<int> vec[33];   set<int> st;   struct Nod {     int v;     int id;     bool operator<(const Nod &cmp) const {       if (v == cmp.v) return id < cmp.id;       return v > cmp.v;     }   } p[M];   int n;   void init() {     for (int i = 0; i < 32; i++) {       for (int j = 0; j < n; j++) {         if (val[j] & (1 << i)) {           vec[i].push_back(j);         }       }     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &val[i]);       p[i].v = val[i];       p[i].id = i;     }     sort(p, p + n);     init();     long long ans = 0;     for (int i = 0; i < n; i++) {       Nod u = p[i];       set<int>::iterator it = st.upper_bound(u.id);       int L, R;       if (it == st.end()) {         R = n - 1;       } else         R = *it - 1;       if (it == st.begin()) {         L = 0;       } else {         it--;         L = *it + 1;       }       int l = L, r = R;       for (int j = 0; j < 32; j++) {         if ((u.v & (1 << j)) == 0) {           int tl = upper_bound(vec[j].begin(), vec[j].end(), u.id) -                    vec[j].begin() - 1;           if (tl >= 0) l = max(l, vec[j][tl] + 1);           int tr =               upper_bound(vec[j].begin(), vec[j].end(), u.id) - vec[j].begin();           if (tr < vec[j].size()) r = min(r, vec[j][tr] - 1);         }       }       ans += 1ll * (u.id - l + 1) * (r - u.id + 1);       st.insert(u.id);     }     printf( %I64d n , 1ll * n * (n + 1) / 2 - ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[12][2001];   int dp[2][4096];   int sos[4096];   bool use[2001];   pair<int, int> b[2001];   void solve() {     cin >> n >> m;     for (int j = 1; j <= m; j++) b[j].first = 0;     for (int i = 0; i < n; i++) {       for (int j = 1; j <= m; j++) {         cin >> a[i][j];         b[j].first = max(b[j].first, a[i][j]);         b[j].second = j;       }     }     sort(b + 1, b + m + 1);     for (int j = m; j >= max(1, m - n + 1); j--) use[b[j].second] = true;     for (int l = 0; l < (1 << n); l++) dp[0][l] = 0;     int c = 0, p = 1;     for (int j = 1; j <= m; j++) {       if (!use[j]) continue;       c ^= 1;       p ^= 1;       for (int l = 0; l < (1 << n); l++) dp[c][l] = 0;       for (int k = 0; k < n; k++) {         int tmp = a[0][j];         for (int l = 0; l < n - 1; l++) a[l][j] = a[l + 1][j];         a[n - 1][j] = tmp;         for (int l = 0; l < (1 << n); l++) sos[l] = dp[p][l];         for (int i = 0; i < n; i++) {           for (int l = 0; l < (1 << n); l++) {             if (l & (1 << i)) sos[l] = max(sos[l], sos[l ^ (1 << i)] + a[i][j]);           }         }         for (int l = 0; l < (1 << n); l++) dp[c][l] = max(dp[c][l], sos[l]);       }     }     for (int j = m; j >= max(1, m - n + 1); j--) use[b[j].second] = false;     cout << dp[c][(1 << n) - 1] <<   n ;   }   int main() {     ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int x, y, n;   int xs[30], ys[30];   int mem[16777227];   int ALL;   int dt[30][30];   int calc(int mask) {     if (mask == ALL) return 0;     int& res = mem[mask];     if (res != -1) return res;     res = ((int)1e9);     int f = -1;     for (int i = 0; i < n; ++i) {       if ((mask >> i) & 1) continue;       if (f == -1) {         f = i;         res = min(res, calc(mask | (1 << i)) + 2 * dt[n][i]);       } else {         int d = dt[n][i] + dt[n][f] + dt[i][f];         res = min(res, calc(mask | (1 << i) | (1 << f)) + d);       }     }     return res;   }   int sz;   int sol[50];   void build(int mask) {     if (mask == ALL) return;     int& res = mem[mask];     for (int i = 0; i < n; ++i) {       if ((mask >> i) & 1) continue;       if (res == calc(mask | (1 << i)) + 2 * dt[n][i]) {         printf(  %d 0 , i + 1);         build(mask | (1 << i));         return;       }       for (int j = 0; j < n; ++j) {         if (i == j) continue;         if ((mask >> j) & 1) continue;         int d = dt[n][i] + dt[n][j] + dt[i][j];         if (res == calc(mask | (1 << i) | (1 << j)) + d) {           printf(  %d %d 0 , i + 1, j + 1);           build(mask | (1 << i) | (1 << j));           return;         }       }     }     return;   }   inline int dist(int x1, int y1, int x2, int y2) {     return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);   }   int main() {     while (scanf( %d%d , &x, &y) != -1) {       scanf( %d , &n);       ALL = (1 << n) - 1;       for (int i = 0; i < n; ++i) {         scanf( %d%d , xs + i, ys + i);         dt[i][n] = dt[n][i] = dist(xs[i], ys[i], x, y);       }       for (int i = 0; i < n; ++i) {         for (int j = i + 1; j < n; ++j) {           dt[i][j] = dt[j][i] = dist(xs[i], ys[i], xs[j], ys[j]);         }       }       memset(mem, -1, sizeof mem);       int res = calc(0);       printf( %d n0 , res);       build(0);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n;     cin >> n;     string s;     cin >> s;     long long int mx[n], mn[n];     for (long long int i = 0; i < n; i++) {       mx[i] = i + 1, mn[i] = n - i;     }     long long int j = 0;     for (long long int i = 0; i < n - 1; i = j) {       while (j < n && s[i] == s[j]) j++;       if (s[i] ==  < )         reverse(mn + i, mn + j + 1);       else         reverse(mx + i, mx + j + 1);     }     for (long long int x : mn) cout << x <<    ;     cout << endl;     for (long long int x : mx) cout << x <<    ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int T = 1;     cin >> T;     while (T--) {       solve();       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     vector<vector<pair<long long, long long>>> ans(k);     long long gr = k, cnt = 0;     bool f = false;     vector<pair<pair<long long, long long>, long long>> a(n);     long double c = 0;     for (long long i = 1; i <= n; ++i) {       pair<long long, long long> x;       cin >> x.first >> x.second;       if (x.second == 1 && gr > 1) gr--;       if (x.second == 1) cnt++;       if (x.second == 2) f = true;       a[i - 1] = {x, i};     }     sort(a.begin(), a.end(),          greater<pair<pair<long long, long long>, long long>>());     k--;     long long free = 0;     for (long long i = 0; i < n; ++i) {       if (k == -1) {         for (long long j = i; j < n; ++j) {           ans[free].push_back({a[j].first.first, a[j].second});           if (free + 1 < gr) free++;         }         break;       }       if (a[i].first.second == 1) {         ans[k].push_back({a[i].first.first, a[i].second});         k--;       } else {         ans[free].push_back({a[i].first.first, a[i].second});         if (free + 1 < gr) free++;       }     }     cout << fixed << setprecision(1);     k = ans.size();     for (long long i = 0; i < ans.size(); ++i) {       long long mn = 1e9;       sort(ans[i].begin(), ans[i].end());       for (long long j = 0; j < ans[i].size(); ++j) {         if (j == 0 && k - cnt - 1 < i)           c += (long double)ans[i][j].first / 2;         else           c += ans[i][j].first;       }     }     cout << c <<   n ;     for (auto i : ans) {       cout << i.size() <<    ;       for (auto j : i) cout << j.second <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     map<int, int> m;     int ma = -1;     int ans = 0;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (m[x] > ma) {         ma = m[x];         ans = x;       }       m[x]++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   string s;   string change(string s, int l, int r, char c1, char c2) {     for (int i = l - 1; i < r; i++) {       if (s[i] == c1) {         s[i] = c2;       }     }     return s;   }   int main() {     cin >> n >> m;     cin >> s;     for (int i = 0; i < m; i++) {       int l, r;       char c1, c2;       cin >> l >> r >> c1 >> c2;       s = change(s, l, r, c1, c2);     }     cout << s;   }


// #pragma GCC optimize( Ofast,unroll-loops )   // #pragma GCC target( avx,avx2,fma )      #include <bits/stdc++.h>   using namespace std;      #define ll long long   #define ull unsigned long long   #define dd double   #define ld long double   #define sl(n) scanf( %lld , &n)   #define si(n) scanf( %d , &n)   #define sd(n) scanf( %lf , &n)   #define pll pair <ll, ll>   #define pii pair <int, int>   #define mp make_pair   #define pb push_back   #define all(v) v.begin(), v.end()   #define inf (1LL << 61)   #define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)   #define for1(i, stop) for(ll i = 1; i <= stop; ++i)   #define for0(i, stop) for(ll i = 0; i < stop; ++i)   #define rep1(i, start) for(ll i = start; i >= 1; --i)   #define rep0(i, start) for(ll i = (start-1); i >= 0; --i)   #define ms(n, i) memset(n, i, sizeof(n))   #define casep(n) printf( Case %lld: , ++n)   #define pn printf(  n )   #define pf printf   #define EL   n    #define fastio std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);      // === Debug macro starts here ===   #ifndef ONLINE_JUDGE   #define DEBUG   #define SYS_COL system( COLOR )   #endif      int recur_depth = 0;   #ifdef DEBUG   #define dbg(x) {++recur_depth; auto x_=x; --recur_depth; SYS_COL;                    cerr<<string(recur_depth,   t )<<  [91m <<__func__<< :                     <<__LINE__<<  t <<#x<<  =  <<x_<<  [39m <<endl;}      template<typename Ostream, typename Cont>   typename enable_if<is_same<Ostream,ostream>::value,               Ostream&>::type operator<<(Ostream& os,  const Cont& v) {    os<< [ ;    for(auto& x:v){os<<x<< ,  ;}    return os<< ] ;   }   template<typename Ostream, typename ...Ts>   Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){    return os<< { <<p.first<< ,  <<p.second<< } ;   }   #else   #define dbg(x)   #endif   // === Debug macro ends here ===      #define ff first   #define ss second      const ll sz = 1e5 + 10, mod = 1e9 + 7;   ll fact[sz], inv[sz];      ll fastPow(ll x, ll n, ll MOD)   {       ll ret = 1;       while (n)       {           if (n & 1) ret = (ret * x) % MOD;           x = (x * x) % MOD;           n >>= 1;       }       return ret % MOD;   }      inline ll ncr(ll n, ll r)   {       if(n < r) return 0;       ll den = (inv[r] * inv[n-r]) % mod;       return (fact[n] * den) % mod;   }      int main()   {       fact[0] = 1;       for1(i, sz-1) fact[i] = (fact[i-1] * i) % mod;          inv[sz-1] = fastPow(fact[sz-1], mod-2, mod);       rep0(i, sz-1) inv[i] = (inv[i+1] * (i+1)) % mod;          ll t;       cin >> t;          while(t--) {           ll n, k;           sl(n), sl(k);              ll ans = 0;              for1(p, n) {               ll posCell = n - (k-1)*(p-1);               if(posCell <= 0) break;                  ll prob = (fact[p] * inv[n]) % mod;               prob = (prob * fact[n-p]) % mod;                  ans += (ncr(posCell, p) * prob) % mod;               if(ans >= mod) ans -= mod;           }           pf( %lld n , (ans+1)%mod);       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   int a[N], n, l, r, ans;   bool check(int k) {     for (int i = 1; i <= n; ++i) {       if (1LL * k * (i - 1) > a[i]) return false;       if (1LL * k * (n - i) > a[i]) return false;     }     return true;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     l = 0, r = 1e9, ans = 0;     while (l <= r) {       int mid = l + r >> 1;       if (check(mid)) {         ans = mid;         l = mid + 1;       } else         r = mid - 1;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   long long v[N], mn[N];   int main() {     long long n;     long long ans = 0;     cin >> n;     for (long long i = 0; i < n; i++) cin >> v[i];     for (long long i = 0; i < n; i++) mn[i] = v[i] + 1;     for (long long i = 1; i < n; i++) mn[i] = max(mn[i - 1], mn[i]);     for (long long i = n - 2; i >= 0; i--) mn[i] = max(mn[i], mn[i + 1] - 1);     for (long long i = 0; i < n; i++) ans += mn[i] - v[i] - 1;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int P = 1e9 + 7;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long qpow(long long a, long long n) {     long long r = 1 % P;     for (a %= P; n; a = a * a % P, n >>= 1)       if (n & 1) r = r * a % P;     return r;   }   long long inv(long long x) { return x <= 1 ? 1 : inv(P % x) * (P - P / x) % P; }   const int N = 2e5 + 10;   int a[N], h[N], f[N], n, m, k, p;   struct _ {     long long day, id;     bool operator<(const _& rhs) const { return day > rhs.day; }   };   priority_queue<_> q;   bool check(long long x) {     memset(f, 0, sizeof f);     while (!q.empty()) q.pop();     for (int i = 1; i <= n; ++i)       if (x - (long long)a[i] * m < h[i]) q.push({x / a[i], i});     for (int i = 1; i <= m; ++i)       for (int j = 1; j <= k; ++j) {         if (q.empty()) return 1;         _ u = q.top();         q.pop();         if (u.day < i) return 0;         if (x + (long long)p * ++f[u.id] - (long long)m * a[u.id] < h[u.id]) {           q.push({(x + (long long)p * f[u.id]) / a[u.id], u.id});         }       }     return q.empty();   }   int main() {     scanf( %d%d%d%d , &n, &m, &k, &p);     for (int i = 1; i <= n; ++i) scanf( %d%d , h + i, a + i);     long long l = 0, r = 1e15, ans;     while (l <= r)       check((l + r >> 1))                        ? ans = (l + r >> 1),                             r = (l + r >> 1) - 1 : l = (l + r >> 1) + 1;     cout << ans << endl;   }


#include <bits/stdc++.h>   const long long int m = 1000000007;   using namespace std;   int main() {     int tc;     cin >> tc;     while (tc--) {       int x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       if (x1 == x2 || y1 == y2)         cout << abs(x1 - x2) + abs(y2 - y1) <<   n ;       else         cout << abs(x2 - x1) + abs(y2 - y1) + 2 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, q;     cin >> n >> q;     long long int arr[n];     long long int aftern[n];     long long int maxi[n];     for (long long int i = 0; i < n; i++) {       cin >> arr[i];       if (i == 0)         maxi[i] = i;       else {         if (arr[i] > arr[maxi[i - 1]])           maxi[i] = i;         else           maxi[i] = maxi[i - 1];       }     }     long long int i = n - 1;     long long int e = n - 1;     while (i >= 0) {       long long int maxin = maxi[i];       for (long long int j = maxin; j < e; j++) {         aftern[j] = arr[j + 1];       }       aftern[e] = arr[maxin];       i = maxin - 1;       e = i;     }     long long int max_in = maxi[n - 1];     for (long long int i = 0; i < q; i++) {       long long int x;       cin >> x;       if (x > (n - 1)) {         long long int t = x % (n - 1);         if (t != 0)           cout << arr[max_in] <<     << aftern[t - 1] <<   n ;         else           cout << arr[max_in] <<     << aftern[n - 2] <<   n ;       } else {         cout << arr[maxi[x - 1]] <<     << arr[x] <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   template <typename T>   void chmin(T &a, T b) {     if (a > b) a = b;   }   template <typename T>   void chmax(T &a, T b) {     if (a < b) a = b;   }   template <typename T>   void add(T &a, T b) {     a += b;     if (a < 0) a += MOD;     if (a >= MOD) a -= MOD;   }   void FastIn(int &T) {     char C;     bool F = 0;     for (; C = getchar(), C <  0  || C >  9 ;)       if (C ==  - ) F = 1;     for (T = C -  0 ; C = getchar(), C >=  0  && C <=  9 ; T = T * 10 + C -  0 )       ;     F && (T = -T);   }   int in() {     int x;     scanf( %d , &x);     return x;   }   long long lin() {     long long x;     scanf( %lld , &x);     return x;   }   double din() {     double x;     scanf( %lf , &x);     return x;   }   long long p2[63];   void initP2() {     p2[0] = 1;     for (int i = (1); i <= (62); ++i) {       p2[i] = p2[i - 1] * 2;     }   }   int countBitsBaseB(long long n, long long b) {     if (n == 0) return 1;     int ret = 0;     while (n) {       ret++;       n /= b;     }     return ret;   }   int count1(long long n) {     int ret = 0;     while (n) {       ret += n & 1;       n >>= 1;     }     return ret;   }   long long c[1024][1024] = {0};   void initC() {     for (int i = 0; i < (1024); ++i) {       for (int j = 0; j < (i + 1); ++j) {         if (j == 0 || j == i) {           c[i][j] = 1;         } else {           c[i][j] = c[i - 1][j - 1];           add(c[i][j], c[i - 1][j]);         }       }     }   }   bool IsPrime(int n) {     if (n < 2) return false;     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   void init() {     initP2();     initC();   }   const unsigned INVALID = 2000000001;   struct CMD {     int cmd, x, y;   } q[(int)(2e5 + 10)];   struct DSU {     struct INFO {       int x, f, h;       INFO() {}       INFO(int x_, int f_, int h_) : x(x_), f(f_), h(h_) {}     };     int f[(int)(2e5 + 10)];     int h[(int)(2e5 + 10)];     INFO stk[(int)(2e5 + 10) << 1];     int stkSize = 0;     void init(int n) {       for (int i = (1); i <= (n); ++i) {         f[i] = i;         h[i] = 1;       }       stkSize = 0;     }     int find(int x) { return x == f[x] ? x : find(f[x]); }     void merge(int x, int y) {       x = find(x);       y = find(y);       if (x == y) {         return;       }       if (h[x] < h[y]) {         stk[stkSize++] = (INFO(x, f[x], h[x]));         f[x] = y;       } else if (h[y] < h[x]) {         stk[stkSize++] = (INFO(y, f[y], h[y]));         f[y] = x;       } else {         stk[stkSize++] = (INFO(x, f[x], h[x]));         stk[stkSize++] = (INFO(y, f[y], h[y]));         f[x] = y;         h[y]++;       }     }     void undo(int size) {       while (stkSize > size) {         pop();       }     }       private:     void pop() {       stkSize--;       auto info = stk[stkSize];       int x = info.x;       f[x] = info.f;       h[x] = info.h;     }   } dsu;   const int BLOCK = 5000;   int last[(int)(2e5 + 10)];   pair<int, int> GetEdge(int x, int y, int der, int n) {     x += der - 1;     if (x >= n) x -= n;     y += der - 1;     if (y >= n) y -= n;     if (x > y) swap(x, y);     return make_pair(x + 1, y + 1);   }   void Switch(const pair<int, int> &edge, set<pair<int, int>> &edges) {     if (edges.find(edge) != edges.end()) {       edges.erase(edge);     } else {       edges.insert(edge);     }   }   int main() {     init();     int n = in(), m = in();     for (int i = (1); i <= (m); ++i) {       q[i].cmd = in();       q[i].x = in();       q[i].y = in();     }     last[0] = 0;     for (int start = 1; start <= m; start += BLOCK) {       int end = start + BLOCK - 1;       if (end > m) {         end = m;       }       set<pair<int, int>> nowEdges;       nowEdges.clear();       for (int i0 = (start); i0 <= (end); ++i0) {         nowEdges.insert(GetEdge(q[i0].x, q[i0].y, 0, n));         nowEdges.insert(GetEdge(q[i0].x, q[i0].y, 1, n));       }       set<pair<int, int>> possible;       possible.clear();       set<pair<int, int>> impossible;       impossible.clear();       for (int i1 = (1); i1 <= (start - 1); ++i1) {         if (q[i1].cmd == 2) {           continue;         }         auto edge0 = GetEdge(q[i1].x, q[i1].y, last[i1 - 1], n);         if (nowEdges.find(edge0) == nowEdges.end()) {           Switch(edge0, impossible);         } else {           Switch(edge0, possible);         }       }       dsu.init(n);       for (auto edge1 : impossible) {         dsu.merge(edge1.first, edge1.second);       }       for (int i2 = (start); i2 <= (end); ++i2) {         if (q[i2].cmd == 1) {           last[i2] = last[i2 - 1];           Switch(GetEdge(q[i2].x, q[i2].y, last[i2 - 1], n), possible);           continue;         } else {           const int top = dsu.stkSize;           for (auto edge1 : possible) {             dsu.merge(edge1.first, edge1.second);           }           auto queryEdge = GetEdge(q[i2].x, q[i2].y, last[i2 - 1], n);           last[i2] = dsu.find(queryEdge.first) == dsu.find(queryEdge.second);           putchar( 0  + last[i2]);           dsu.undo(top);         }       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long x[5003], a[5003], b[5003], c[5003], d[5003];   vector<int> path;   long long weight[5003][5003];   long long edge(int i, int j) {     long long ans = abs(x[i] - x[j]);     if (j < i) ans += (c[i] + b[j]);     if (i < j) ans += (d[i] + a[j]);     return ans;   }   int main() {     int n, s, e;     cin >> n >> s >> e;     for (int i = 1; i <= n; i++) cin >> x[i];     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++) cin >> c[i];     for (int i = 1; i <= n; i++) cin >> d[i];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) weight[i][j] = edge(i, j);     long long ans = weight[s][e];     path.push_back(s);     path.push_back(e);     for (int i = 1; i <= n; i++) {       if (i == s || i == e) continue;       int insert_at = 0;       long long best = 1e12;       for (int j = 0; j < path.size() - 1; j++) {         long long temp = weight[path[j]][i] + weight[i][path[j + 1]] -                          weight[path[j]][path[j + 1]];         if (temp < best) {           best = temp;           insert_at = j;         }       }       ans += best;       vector<int>::iterator ins = find(path.begin(), path.end(), path[insert_at]);       ins++;       path.insert(ins, i);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T abs(T t) {     return t < 0 ? -t : t;   }   const long long modn = 1000000007;   inline long long mod(long long x) { return x % modn; }   int main() {     long long d1, d2, d3;     cin >> d1 >> d2 >> d3;     long long ans = min(d1 + d2 + d3, d1 * 2 + d2 * 2);     ans = min(ans, min(d1 * 2 + d3 * 2, d2 * 2 + d3 * 2));     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > marks(200002);   vector<pair<int, int> > marksbyy(200002);   vector<vector<int> > partials(2005, vector<int>(2005));   vector<vector<int> > inpart(2005, vector<int>(2005));   int n;   void fillpart() {     sort(marks.begin() + 1, marks.begin() + n + 1);     sort(marksbyy.begin() + 1, marksbyy.begin() + n + 1);     for (int i = 1; i <= n; i++) {       int j = marks[i].second;       inpart[(i - 1) / 100][(j - 1) / 100]++;     }     partials[0][0] = inpart[0][0];     for (int i = 1; i <= 2000; i++) {       partials[0][i] = partials[0][i - 1] + inpart[0][i];     }     for (int i = 1; i <= 2000; i++) {       partials[i][0] = partials[i - 1][0] + inpart[i][0];     }     for (int i = 1; i <= 2000; i++) {       for (int j = 1; j <= 2000; j++) {         partials[i][j] = partials[i - 1][j] + partials[i][j - 1] -                          partials[i - 1][j - 1] + inpart[i][j];       }     }   }   int query(int x, int y) {     int ans = 0;     int biggestpartx = x / 100 - 1;     int biggestparty = y / 100 - 1;     if (biggestpartx >= 0 && biggestparty >= 0) {       ans += partials[biggestpartx][biggestparty];       for (int i = (biggestpartx + 1) * 100 + 1; i <= x; i++) {         if (marks[i].second <= (biggestparty + 1) * 100) {           ans++;         }       }       for (int i = (biggestparty + 1) * 100 + 1; i <= y; i++) {         if (marksbyy[i].second <= x) {           ans++;         }       }     } else {       for (int i = 1; i <= x; i++) {         if (marks[i].second <= y) {           ans++;         }       }     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int q;     cin >> n >> q;     vector<int> arr(n);     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       x = n + 1 - x;       marks[i] = make_pair(x, i);       marksbyy[i] = make_pair(i, x);     }     fillpart();     for (int i = 0; i < q; i++) {       int l, d, r, u;       cin >> l >> d >> r >> u;       u = n + 1 - u;       d = n + 1 - d;       long long int topleft = query(u - 1, l - 1);       long long int top = query(u - 1, r) - topleft;       long long int left = query(d, l - 1) - topleft;       long long int inside = query(d, r) - topleft - top - left;       long long int topright = query(u - 1, n) - top - topleft;       long long int bottomleft = query(n, l - 1) - left - topleft;       long long int bottom =           query(n, r) - inside - bottomleft - topleft - top - left;       long long int right =           query(d, n) - inside - topright - topleft - top - left;       long long int bottomright = query(n, n) - inside - topright - topleft -                                   top - left - bottom - bottomleft - right;       long long int ans = 0;       ans += topleft * (bottom + right + bottomright + inside);       ans += topright * (bottom + left + bottomleft + inside);       ans += bottomleft * (top + right + topright + inside);       ans += bottomright * (top + left + topleft + inside);       ans += inside * (topright + topleft + bottomleft + bottomright + top +                        right + bottom + left + inside - 1);       ans += top * (bottom + left + right + bottomleft + bottomright + inside);       ans += right * (top + left + bottom + topleft + bottomleft + inside);       ans += bottom * (top + left + right + topleft + topright + inside);       ans += left * (top + bottom + right + topright + bottomright + inside);       ans /= 2;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000000;   int a[300005], b[300005];   class SegmentTree {    public:     SegmentTree* left = nullptr;     SegmentTree* right = nullptr;     int start, end, val = 0, lazyadd = 0;     SegmentTree(int s, int e) {       start = s;       end = e;       if (start != end) {         left = new SegmentTree(start, (start + end) / 2);         right = new SegmentTree((start + end) / 2 + 1, end);       }     }     void propogate() {       if (lazyadd) {         left->val += lazyadd;         right->val += lazyadd;         left->lazyadd += lazyadd;         right->lazyadd += lazyadd;         lazyadd = 0;       }     }     void update(int l, int r, int v) {       if (l > end || r < start) {         return;       }       if (l <= start && end <= r) {         val += v;         lazyadd += v;         return;       }       propogate();       left->update(l, r, v);       right->update(l, r, v);       val = min(left->val, right->val);     }     int traverse() {       if (val >= 0) {         return -1;       }       if (start == end) {         return start;       }       propogate();       if (right->val < 0) {         return right->traverse();       }       return left->traverse();     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     int n, m, q, input;     int index, x;     cin >> n >> m;     SegmentTree myTree(1, 1000000);     for (int i = 1; i <= n; i++) {       cin >> a[i];       myTree.update(1, a[i], -1);     }     for (int j = 1; j <= m; j++) {       cin >> b[j];       myTree.update(1, b[j], 1);     }     cin >> q;     for (int w = 0; w < q; w++) {       cin >> input >> index >> x;       if (input == 1) {         myTree.update(1, a[index], 1);         a[index] = x;         myTree.update(1, a[index], -1);       } else {         myTree.update(1, b[index], -1);         b[index] = x;         myTree.update(1, b[index], 1);       }       cout << myTree.traverse() << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, x, len, dir, t, y;   bool fin;   pair<int, int> a[210000];   int loc[210000];   int binary_right(int x, int t) {     int l = x, r = n, mid;     while (l < r) {       mid = (l + r + 1) / 2;       if (a[mid].first <= t)         l = mid;       else         r = mid - 1;     }     return l;   }   int binary_left(int x, int t) {     int l = 1, r = x, mid;     while (l < r) {       mid = (l + r) / 2;       if (a[mid].first >= t)         r = mid;       else         l = mid + 1;     }     return l;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i].first);       a[i].second = i;     }     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) loc[a[i].second] = i;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &x, &len);       x = loc[x];       dir = 1;       fin = 0;       while (!fin) {         t = a[x].first + dir * len;         if (dir == 1) {           y = binary_right(x, t);           if (binary_left(y, a[y].first - (len - a[y].first + a[x].first)) == x) {             if (y == x)               fin = 1;             else               len %= 2 * (a[y].first - a[x].first);           } else {             dir = -1;             len -= (a[y].first - a[x].first);             x = y;           }         } else {           y = binary_left(x, t);           if (binary_right(y, a[y].first + (len - a[x].first + a[y].first)) ==               x) {             if (y == x)               fin = 1;             else               len %= 2 * (a[x].first - a[y].first);           } else {             dir = 1;             len -= (a[x].first - a[y].first);             x = y;           }         }       }       printf( %d n , a[x].second);     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int main() {     while (scanf( %d%d , &n, &k) != EOF) {       if (k > n || k > 26 || (n > 1 && k == 1))         printf( -1 n );       else {         for (int i = 0; i < n - max(0, (k - 2)); i++)           if (i % 2 == 0)             printf( a );           else             printf( b );         for (int i = (2); i <= (k - 1); ++i) printf( %c ,  a  + i);         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[5000006];   int S;   void go(int lf, int rg) {     if (lf < 0) return;     S = max(S, (rg - lf) / 2);     if (a[lf] == a[rg]) {       for (int i = lf; i < rg; ++i) a[i] = a[lf];     } else {       for (int i = lf, j = rg; i < j; ++i, --j) {         a[i] = a[lf];         a[j] = a[rg];       }     }   }   void solve() {     cin >> n;     for (int i = 0; i < (n); ++i) scanf( %d , a + i);     int lst = 0;     S = 0;     for (int i = 1; i <= (n - 2); ++i) {       if (a[i] == a[i - 1] || a[i] == a[i + 1]) {         if (i - lst > 1) go(lst, i);         lst = i;       }     }     if (n - 1 - lst > 1) go(lst, n - 1);     cout << S << endl;     for (int i = 0; i < (n); ++i) printf( %d  , a[i]);   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx )   #pragma GCC optimize( unroll-loops )   using namespace std;   template <typename T1, typename T2>   inline void chkmin(T1 &first, T2 second) {     if (first > second) first = second;   }   template <typename T1, typename T2>   inline void chkmax(T1 &first, T2 second) {     if (first < second) first = second;   }   template <typename T, typename U>   inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {     _out << _p.first <<     << _p.second;     return _out;   }   template <typename T, typename U>   inline istream &operator>>(istream &_in, pair<T, U> &_p) {     _in >> _p.first >> _p.second;     return _in;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const vector<T> &_v) {     if (_v.empty()) {       return _out;     }     _out << _v.front();     for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) {       _out <<     << *_it;     }     return _out;   }   template <typename T>   inline istream &operator>>(istream &_in, vector<T> &_v) {     for (auto &_i : _v) {       _in >> _i;     }     return _in;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const set<T> &_s) {     if (_s.empty()) {       return _out;     }     _out << *_s.begin();     for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {       _out <<     << *_it;     }     return _out;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const multiset<T> &_s) {     if (_s.empty()) {       return _out;     }     _out << *_s.begin();     for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {       _out <<     << *_it;     }     return _out;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) {     if (_s.empty()) {       return _out;     }     _out << *_s.begin();     for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {       _out <<     << *_it;     }     return _out;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) {     if (_s.empty()) {       return _out;     }     _out << *_s.begin();     for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {       _out <<     << *_it;     }     return _out;   }   template <typename T, typename U>   inline ostream &operator<<(ostream &_out, const map<T, U> &_m) {     if (_m.empty()) {       return _out;     }     _out <<  (  << _m.begin()->first <<  :   << _m.begin()->second <<  ) ;     for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {       _out <<  , (  << _it->first <<  :   << _it->second <<  ) ;     }     return _out;   }   template <typename T, typename U>   inline ostream &operator<<(ostream &_out, const unordered_map<T, U> &_m) {     if (_m.empty()) {       return _out;     }     _out <<  (  << _m.begin()->first <<  :   << _m.begin()->second <<  ) ;     for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {       _out <<  , (  << _it->first <<  :   << _it->second <<  ) ;     }     return _out;   }   const int N = 1e5 + 5;   int n, m;   int dsu[N];   vector<pair<int, int>> edge[N];   vector<pair<int, pair<int, int>>> edges, v;   set<pair<int, int>> used;   int get(int i) { return i == dsu[i] ? i : dsu[i] = get(dsu[i]); }   bool merge(int i, int j) {     i = get(i);     j = get(j);     if (i == j) return false;     dsu[i] = j;     return true;   }   const int LOG = 18;   int t;   int tin[N], tout[N];   pair<int, int> up[LOG][N];   void dfs(int i, int p = -1) {     tin[i] = t++;     for (auto j : edge[i]) {       if (j.first == p) continue;       up[0][j.first] = {i, j.second};       dfs(j.first, i);     }     tout[i] = t++;   }   bool is_parent(int a, int b) { return tin[a] <= tin[b] && tout[b] <= tout[a]; }   int lca(int a, int b) {     int ans = 0;     for (int t = 0; t < 2; ++t) {       if (tin[a] > tin[b]) swap(a, b);       if (!is_parent(b, a)) {         for (int t = LOG; t--;) {           int c = up[t][b].first;           if (!is_parent(c, a)) {             chkmax(ans, up[t][b].second);             b = c;           }         }         chkmax(ans, up[0][b].second);         b = up[0][b].first;       }       assert(is_parent(b, a));     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     srand(time(0));     cin >> n >> m;     edges.resize(m);     for (int i = 0; i < m; ++i) {       cin >> edges[i].second.first >> edges[i].second.second >> edges[i].first;     }     v = edges;     sort(edges.begin(), edges.end());     bool was = false;     for (int i = 0; i <= n; ++i) dsu[i] = i;     for (auto i : edges) {       if (merge(i.second.first, i.second.second)) {         used.insert(i.second);         edge[i.second.first].push_back({i.second.second, i.first});         edge[i.second.second].push_back({i.second.first, i.first});       }     }     up[0][1] = {1, 0};     dfs(1);     for (int t = 0; t + 1 < LOG; ++t) {       for (int i = 1; i <= n; ++i) {         up[t + 1][i] = {up[t][up[t][i].first].first,                         max(up[t][i].second, up[t][up[t][i].first].second)};       }     }     for (auto i : v) {       if (used.count(i.second)) {         continue;       }       cout << lca(i.second.first, i.second.second) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[30];   int main() {     int n, k, i, j, m;     string s;     cin >> s;     cin >> k;     map<char, int> mp;     map<char, int>::iterator it;     n = s.size();     for (i = 0; i < n; i++) {       ++mp[s[i]];     }     multimap<int, char> mp2;     multimap<int, char>::iterator it2;     for (it = mp.begin(); it != mp.end(); it++) {       mp2.insert(pair<int, char>(it->second, it->first));     }     map<char, int> mp3;     for (it2 = mp2.begin(); it2 != mp2.end(); it2++) {       if (k - it2->first >= 0) {         mp3[it2->second] = 1;         k -= it2->first;       }     }     string s2 =   ;     for (i = 0; i < n; i++) {       if (mp3[s[i]] == 0) {         s2 += s[i];       }     }     mp3.clear();     n = s2.size();     for (i = 0; i < n; i++) {       ++mp3[s2[i]];     }     cout << mp3.size() << endl;     cout << s2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   int n, m, q[N], a[N];   int main() {     scanf( %d , &m);     for (int i = (0); i < (m); ++i) scanf( %d , &q[i]);     int mn = *min_element(q, q + m);     scanf( %d , &n);     for (int i = (0); i < (n); ++i) scanf( %d , &a[i]);     sort(a, a + n);     int ans = 0;     for (int i = n - 1, c = 0; i >= 0; --i) {       ans += a[i], ++c;       if (c >= mn) c = 0, i -= 2;     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       if (n <= 30) {         cout <<  NO n ;       } else if (n == 36) {         cout <<  YES n ;         cout <<  5 6 10 15               <<   n ;       } else if (n == 40) {         cout <<  YES n ;         cout <<  9 6 10 15               <<   n ;       } else if (n == 44) {         cout <<  YES n ;         cout <<  6 7 10 21               <<   n ;       } else {         cout <<  YES n ;         cout <<  6 10 14   << n - 30 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       unsigned long long a, b;       cin >> a >> b;       if (max(a, b) % min(a, b)) {         cout << -1 << endl;         continue;       }       int dem = 0;       long long p = max(a, b) / min(a, b);       while (p != 1) {         if (p % 8 == 0) {           dem++;           p /= 8;         } else if (p % 4 == 0) {           dem++;           p /= 4;         } else if (p % 2 == 0) {           dem++;           p /= 2;         } else {           dem = -1;           break;         }       }       cout << dem << endl;     }   }