#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int mo = 1000000007;   inline void gn(long long &x) {     int sg = 1;     char c;     while (((c = getchar()) <  0  || c >  9 ) && c !=  - )       ;     c ==  -  ? (sg = -1, x = 0) : (x = c -  0 );     while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ;     x *= sg;   }   inline void gn(int &x) {     long long t;     gn(t);     x = t;   }   inline void gn(unsigned long long &x) {     long long t;     gn(t);     x = t;   }   inline void gn(double &x) {     double t;     scanf( %lf , &t);     x = t;   }   inline void gn(long double &x) {     double t;     scanf( %lf , &t);     x = t;   }   template <class T1, class T2>   inline void gn(T1 &r, T2 &s) {     gn(r), gn(s);   }   template <class T1, class T2, class T3>   inline void gn(T1 &r, T2 &s, T3 &t) {     gn(r), gn(s), gn(t);   }   template <class T1, class T2, class T3, class T4>   inline void gn(T1 &r, T2 &s, T3 &t, T4 &u) {     gn(r), gn(s), gn(t), gn(u);   }   inline void gs(char *s) { scanf( %s , s); }   inline void gc(char &c) {     while ((c = getchar()) > 126 || c < 33)       ;   }   inline void pc(char c) { putchar(c); }   const int DX[] = {1, 0, -1, 0}, DY[] = {0, 1, 0, -1};   long long powmod(long long a, long long b) {     long long res = 1;     a %= mo;     for (; b; b >>= 1) {       if (b & 1) res = res * a % mo;       a = a * a % mo;     }     return res;   }   long long powmod(long long a, long long b, long long mo) {     long long res = 1;     a %= mo;     for (; b; b >>= 1) {       if (b & 1) res = res * a % mo;       a = a * a % mo;     }     return res;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   const int N = 5055, M = 111111;   int l, m, n, t, C, x, y, prex;   vector<int> a[N];   int dis[N][N];   void bfs(int k) {     for (int i = (1); i <= (n); ++i) dis[k][i] = inf;     dis[k][k] = 0;     queue<int> Q;     Q.push(k);     while (!Q.empty()) {       int p = Q.front();       Q.pop();       for (auto i : a[p]) {         if (dis[k][i] == inf) {           dis[k][i] = dis[k][p] + 1;           Q.push(i);         }       }     }   }   int p[9];   void update() {     printf( %d %d %d n , p[0], p[1], p[2]);     fflush(stdout);     if (p[0] == x || p[1] == x || p[2] == x) exit(0);     prex = x;     scanf( %d , &x);     if (p[0] == x || p[1] == x || p[2] == x) exit(0);   }   void go(int &x, int y) {     for (auto i : a[x])       if (dis[i][y] == dis[x][y] - 1) {         x = i;         break;       }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = (1); i <= (m); ++i)       scanf( %d%d , &x, &y), a[x].push_back(y), a[y].push_back(x);     for (int i = (1); i <= (n); ++i) bfs(i);     p[0] = p[1] = p[2] = 1;     x = -1;     while (1) {       update();       int q[9];       int ans = inf;       for (int i = (0); i <= (((int)(a[x]).size()) - 1); ++i)         for (int j = (0); j <= (((int)(a[x]).size()) - 1); ++j)           for (int k = (0); k <= (((int)(a[x]).size()) - 1); ++k) {             int res =                 dis[p[0]][a[x][i]] + dis[p[1]][a[x][j]] + dis[p[2]][a[x][k]];             if (i != j) res -= n;             if (j != k) res -= n;             if (i != k) res -= n;             if (res < ans)               ans = res, q[0] = a[x][i], q[1] = a[x][j], q[2] = a[x][k];           }       for (int i = (0); i <= (2); ++i)         if (dis[p[i]][x] == 1) q[i] = x;       for (int i = (0); i <= (2); ++i) go(p[i], q[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, q;   pair<int, int> a[400004];   long long ans[200004], d[400004], sum;   int fa[400004], l[400004], r[400004], s[400004];   vector<pair<int, int> > v, ask;   int F(int x) { return fa[x] == x ? x : fa[x] = F(fa[x]); }   long long got(int v) { return d[r[v]] - d[r[v] - s[v]]; }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n + m; i++) scanf( %d , &a[i].first), a[i].second = i;     sort(a + 1, a + n + m + 1);     for (int i = 1; i <= n + m; i++) {       d[i] = d[i - 1] + a[i].first;       fa[i] = i, s[i] = (a[i].second <= n), l[i] = r[i] = i;       if (s[i] == 1) sum += a[i].first;       if (i > 1) v.push_back({a[i].first - a[i - 1].first, i});     }     for (int i = 1; i <= q; i++) {       int k;       scanf( %d , &k);       ask.push_back({k, i});     }     sort(v.begin(), v.end());     sort(ask.begin(), ask.end());     int it = 0;     for (auto qr : ask) {       while (it < v.size() && v[it].first <= qr.first) {         int p = v[it].second;         int U = F(p - 1), V = F(p);         sum -= got(U) + got(V);         fa[U] = V, s[V] += s[U], l[V] = l[U];         sum += got(V);         it++;       }       ans[qr.second] = sum;     }     for (int i = 1; i <= q; i++) printf( %lld n , ans[i]);   }


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


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 111 * 1000;   int par[MAXN], sz[MAXN];   int find(int i) {     if (par[i] == i) return i;     return par[i] = find(par[i]);   }   void un(int a, int b) {     sz[find(a)] += sz[find(b)];     par[find(b)] = find(a);   }   int n;   int mark[MAXN];   int sum[MAXN], tot[MAXN];   vector<int> adj[MAXN];   int dfs(int pos, int par = -1) {     if (mark[pos]) return 0;     mark[pos]++;     for (__typeof((adj[pos]).begin()) it = (adj[pos]).begin();          it != (adj[pos]).end(); ++it)       if (*it != par) sum[pos] += dfs(*it, pos);     return sum[pos];   }   void stot(int pos, int val) {     if (mark[pos] != 1) return;     mark[pos]++;     tot[pos] = val;     for (__typeof((adj[pos]).begin()) it = (adj[pos]).begin();          it != (adj[pos]).end(); ++it)       stot(*it, val);   }   int main() {     for (register int i = (0); i < (int)(MAXN); ++i) par[i] = i, sz[i] = 1;     cin >> n;     vector<pair<pair<int, int>, pair<int, int> > > E(n - 1);     for (register int i = (0); i < (int)(n - 1); ++i)       cin >> E[i].second.first >> E[i].second.second >> E[i].first.first,           E[i].second.first--, E[i].second.second--, E[i].first.second = i + 1;     sort((E).begin(), (E).end());     int lo = 0;     long long mb = 0;     vector<long long> res;     while (lo < ((int)(E).size())) {       int hi = lo;       while (hi < ((int)(E).size()) && E[lo].first.first == E[hi].first.first)         hi++;       set<int> st;       for (register int i = (lo); i < (int)(hi); ++i) {         int x = find(E[i].second.first), y = find(E[i].second.second);         if (x != y) {           st.insert(x);           st.insert(y);           adj[x].push_back(y);           adj[y].push_back(x);           sum[x] = sz[x];           sum[y] = sz[y];         }       }       for (__typeof((st).begin()) it = (st).begin(); it != (st).end(); ++it) {         if (!mark[*it]) {           int tmp = dfs(*it);           stot(*it, tmp);         }       }       for (__typeof((st).begin()) it = (st).begin(); it != (st).end(); ++it)         mark[*it] = false, adj[*it].clear();       for (register int i = (lo); i < (int)(hi); ++i) {         int x = E[i].second.first, y = E[i].second.second;         if (find(x) == find(y)) continue;         int mn = min(sum[find(x)], sum[find(y)]);         long long cnt = 2LL * mn * (tot[find(x)] - mn);         if (cnt > mb) {           mb = cnt;           res.clear();         }         if (cnt == mb) res.push_back(E[i].first.second);       }       for (register int i = (lo); i < (int)(hi); ++i) {         int x = E[i].second.first, y = E[i].second.second;         if (find(x) == find(y)) continue;         un(x, y);       }       lo = hi;     }     cout << mb <<     << ((int)(res).size()) << endl;     for (register int i = (0); i < (int)(((int)(res).size())); ++i)       cout << res[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cout << x; }   void __print(long x) { cout << x; }   void __print(long long x) { cout << x; }   void __print(unsigned x) { cout << x; }   void __print(unsigned long x) { cout << x; }   void __print(unsigned long long x) { cout << x; }   void __print(float x) { cout << x; }   void __print(double x) { cout << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cout <<      << x <<     ; }   void __print(const char *x) { cout <<     << x <<    ; }   void __print(const string &x) { cout <<     << x <<    ; }   void __print(bool x) { cout << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cout <<  { ;     __print(x.first);     cout <<  , ;     __print(x.second);     cout <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cout <<  { ;     for (auto &i : x) cout << (f++ ?  ,  :   ), __print(i);     cout <<  } ;   }   void _print() { cout <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cout <<  ,  ;     _print(v...);   }   void c_p_c();   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int testcase = 1;     while (testcase--) c_p_c();     return 0;   }   void c_p_c() {     long long int n, m;     cin >> n >> m;     vector<vector<long long int>> a(n, vector<long long int>(m, 0));     ;     vector<vector<long long int>> b(n, vector<long long int>(m, 1));     ;     for (long long int i = 0; i < n; ++i) {       for (long long int j = 0; j < m; ++j) {         cin >> a[i][j];         if (!a[i][j]) {           for (long long int k = 0; k < n; ++k) {             b[k][j] = 0;           }           for (long long int k = 0; k < m; ++k) {             b[i][k] = 0;           }         }       }     }     for (long long int i = 0; i < n; ++i) {       for (long long int j = 0; j < m; ++j) {         if (a[i][j]) {           long long int ans = 0;           for (long long int k = 0; k < n; ++k) {             ans += b[k][j];           }           for (long long int k = 0; k < m; ++k) {             ans += b[i][k];           }           if ((bool)(ans) == 0) {             cout <<  NO ;             return;           }         }       }     }     cout <<  YES n ;     for (long long int i = 0; i < n; ++i) {       for (long long int j = 0; j < m; ++j) {         cout << (bool)(b[i][j]) <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5001;   const int B = 27;   int zhu[B], n, m;   char s[N], t[N];   void solve() {     memset(zhu, 0, sizeof(zhu));     n = strlen(s);     m = strlen(t);     for (int i = 0; i < n; ++i) zhu[s[i] -  a ]++;     int r = -1, p;     if (n > m)       p = m;     else       p = min(n, m) - 1;     for (int i = t[0] -  a  + 1; i < 26; ++i)       if (zhu[i]) r = 0;     for (int i = 1; i <= p; ++i) {       zhu[t[i - 1] -  a ]--;       if (zhu[t[i - 1] -  a ] < 0) break;       if (i == m) {         r = m;         continue;       }       for (int j = t[i] -  a  + 1; j < 26; ++j)         if (zhu[j]) r = i;     }     if (r == -1) {       printf( -1 n );       return;     } else {       memset(zhu, 0, sizeof(zhu));       for (int i = 0; i < n; ++i) zhu[s[i] -  a ]++;       for (int i = 0; i < r; ++i) {         printf( %c , t[i]);         zhu[t[i] -  a ]--;       }       if (r < m)         for (int i = t[r] -  a  + 1; i < 26; ++i)           if (zhu[i]) {             printf( %c , i +  a );             zhu[i]--;             break;           }       for (int i = 0; i < 26; ++i)         while (zhu[i]--) printf( %c , i +  a );       printf(  n );     }   }   int main() {     while (~scanf( %s%s , s, t)) solve();   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     char ch = getchar();     int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int fac[2000010], inv[2000010], f[2000010];   inline int Power(int x, int y, int Q) {     int ret = 1;     while (y) {       if (y & 1) ret = 1ll * ret * x % Q;       x = (1ll * x * x) % Q;       y >>= 1;     }     return ret;   }   int main() {     int n = read(), m = read(), a = read(), Q = read();     int p = 1;     for (int i = a; i != 1; i = (1ll * i * a % Q), p++)       ;     fac[1] = 1;     for (int i = (2); i <= (max(n, m)); i++) fac[i] = 1ll * fac[i - 1] * i % p;     inv[0] = inv[1] = 1;     for (int i = (2); i <= (max(n, m)); i++)       inv[i] = 1ll * (p - p / i) * inv[p % i] % p;     for (int i = (2); i <= (max(n, m)); i++)       inv[i] = 1ll * inv[i - 1] * inv[i] % p;     f[0] = 1;     for (int i = (1); i <= (m); i++) {       f[i] = (f[i - 1] + (1ll * fac[m] * inv[m - i] % p * inv[i] % p)) % p;     }     for (int i = (m + 1); i <= (n); i++) f[i] = f[i - 1];     for (int i = n; i >= 1; i--) printf( %d  , Power(a, f[i - 1], Q));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x;   int dist[501][501];   bool color[501];   unsigned short num_red;   unsigned short ans[501][501][501], best[501][501], sizes[501];   unsigned short inf = ~0;   vector<unsigned short> edge[501];   void dfs(unsigned short& now, unsigned short& before) {     for (int i = 0; i < edge[now].size(); i++) {       unsigned short& next = edge[now][i];       if (next == before) continue;       dfs(next, now);     }     for (int i = 1; i <= n; i++)       if (dist[now][i] <= x) {         sizes[now] = 1;         ans[now][i][1] = !color[i];         for (int j = 0; j < edge[now].size(); j++) {           unsigned short& next = edge[now][j];           if (next == before) continue;           int num_node;           if (num_red < sizes[now] + sizes[next])             num_node = num_red;           else             num_node = sizes[now] + sizes[next];           for (unsigned short k = num_node;; k--) {             unsigned short temp = inf;             int num_node_1 = k - sizes[now];             if (num_node_1 < 0) num_node_1 = 0;             int num_node_2 = k;             if (k > sizes[next]) num_node_2 = sizes[next];             for (unsigned short j = num_node_1; j <= num_node_2; j++) {               if (temp > ans[now][i][k - j] + best[next][j])                 temp = ans[now][i][k - j] + best[next][j];             }             num_node_1++;             for (unsigned short j = num_node_1; j <= num_node_2; j++) {               if (temp > ans[now][i][k - j + 1] + ans[next][i][j] - !color[i])                 temp = ans[now][i][k - j + 1] + ans[next][i][j] - !color[i];             }             ans[now][i][k] = temp;             if (!k) break;           }           sizes[now] += sizes[next];         }       }     for (unsigned short i = 1; i <= num_red; i++) {       best[now][i] = inf;       for (unsigned short j = 1; j <= n; j++) {         best[now][i] = min(best[now][i], ans[now][j][i]);       }     }   }   int main() {     num_red = 0;     memset(ans, 0xff, sizeof ans);     memset(best, 0xff, sizeof best);     memset(dist, 0x3f3f, sizeof dist);     cin >> n >> x;     unsigned short col;     for (int i = 1; i <= n; i++) {       cin >> col;       num_red += col;       color[i] = col == 1;     }     unsigned short a, b;     int cost;     for (int i = 1; i < n; i++) {       cin >> a >> b >> cost;       edge[a].push_back(b);       edge[b].push_back(a);       dist[a][b] = dist[b][a] = cost;     }     for (int k = 1; k <= n; k++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           dist[i][j] = i == j ? 0 : min(dist[i][j], dist[i][k] + dist[k][j]);         }       }     }     unsigned short start = 1;     unsigned short before = 0;     dfs(start, before);     if (best[1][num_red] == inf)       cout << -1 << endl;     else       cout << best[1][num_red] << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   int main() {     int T, i, j, k, ca = 0, n, m;     int x1, y1, x2, y2;     while (~scanf( %d%d%d%d , &x1, &y1, &x2, &y2)) {       scanf( %d , &n);       int ans = 0, a, b, c;       while (n--) {         scanf( %d%d%d , &a, &b, &c);         long long first = 1LL * a * x1 + 1LL * b * y1 + c,                   second = 1LL * a * x2 + 1LL * b * y2 + c;         if (first > 0 && second < 0)           ans++;         else if (first < 0 && second > 0)           ans++;       }       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e9 + 7;   vector<long long int> v;   long long int calcmulti(string s, long long int l, long long int r) {     long long int ans = 1;     string z =   ;     for (long long int i = l; i <= r; i++) {       if (s[i] ==  * ) {         ans *= stoll(z);         z =   ;       } else         z += s[i];     }     ans *= stoll(z);     return ans;   }   long long int calc(string s, long long int ss, long long int st) {     if (ss == st) return s[ss] -  0 ;     long long int mid = (ss + st) / 2, mindist = MAXN;     for (long long int i = mid; i <= st; i++) {       if (s[i] ==  + ) {         mindist = min(mindist, i);         break;       }     }     for (long long int i = mid; i >= ss; i--) {       if (s[i] ==  + ) {         mindist = min(mindist, i);         break;       }     }     if (mindist == MAXN) return calcmulti(s, ss, st);     return calc(s, ss, mindist - 1) + calc(s, mindist + 1, st);   }   long long int change(string s, long long int ss, long long int st) {     string z;     long long int ans = calc(s, ss, st);     for (long long int i = 0; i <= ss - 1; i++) z += s[i];     z += to_string(ans);     for (long long int i = st + 1; i <= (long long int)s.length() - 1; i++)       z += s[i];     return calc(z, 0, (long long int)z.length() - 1);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int ans = 0;     string s;     cin >> s;     for (long long int i = 0; i < s.length(); i++)       if (s[i] ==  * ) v.push_back(i);     if (v.size() == 0) {       cout << calc(s, 0, (long long int)s.length() - 1);       return 0;     }     if (v.size() == 1) {       cout << max(change(s, 0, v[0] - 1),                   max(change(s, v[0] + 1, (long long int)s.length() - 1),                       calc(s, 0, (long long int)s.length() - 1)));       ;       return 0;     }     ans = max(ans, calc(s, 0, (long long int)s.length() - 1));     for (long long int i = 0; i < (long long int)v.size(); i++) {       ans = max(ans, change(s, 0, v[i] - 1));       ans = max(ans, change(s, v[i] + 1, (long long int)s.length() - 1));       for (long long int j = i + 1; j < (long long int)v.size(); j++) {         ans = max(ans, change(s, v[i] + 1, v[j] - 1));       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     unsigned n(0);     cin >> n;     vector<unsigned> array(n, 0);     for (unsigned it(0); it != n; ++it) {       array[it] = it + 1;     }     --n;     for (unsigned it(n); it > 0; --it) {       swap(array[it], array[it - 1]);     }     ++n;     for (unsigned it(0); it != n; ++it) {       cout << array[it] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long tab[70];   void Tab() {     for (int i = 0; i < 64; i++) tab[i] = pow(2, i);   }   long long Sum(long long n) {     long long m = n + 1;     if ((long long)(m) % 2 == 0)       m /= 2;     else       n /= 2;     long long sum = m * n;     return sum;   }   long long Sum1(long long n) {     long long sum1 = pow(2, n) - 1;     return sum1;   }   int Find(long long n) {     int i = 0;     for (; i < 64; i++) {       if (tab[i] > n) break;     }     return i;   }   int main() {     Tab();     long long ans, sum, sum1;     int t;     long long n;     cin >> t;     while (t--) {       ans = 0;       cin >> n;       sum = Sum(n);       long long site = Find(n);       sum1 = Sum1(site);       ans = sum - sum1 - sum1;       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:200000000 )   using namespace std;   const long long oo = 1LL << 60;   const long long kNumMoves = 4;   const long long kMoves[kNumMoves][2] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}};   struct Line {     Line() : m(0), c(0) {}     Line(long long slope, long long yOrd) : m(slope), c(yOrd) {}     long long m;     long long c;   };   class ConvexHullOptimization {    public:     ConvexHullOptimization(int n) : cur(0), lines(n), count(0) {}     void Add(long long m, long long c) {       Line newLine(m, c);       while (!KeepCurrentTop(newLine)) --count;       lines[count++] = newLine;     }     void Reset() { cur = count = 0; }     long long GetValue(long long x) {       if (cur >= count) cur = count - 1;       while ((cur < count - 1) && ((lines[cur].m * x + lines[cur].c) >=                                    (lines[cur + 1].m * x + lines[cur + 1].c)))         ++cur;       return lines[cur].m * x + lines[cur].c;     }       private:     bool KeepCurrentTop(const Line& l3) {       if ((count - cur) < 2) return true;       Line l2 = lines[count - 1];       Line l1 = lines[count - 2];       long double newCost = (l3.c - l1.c) * (long double)(l1.m - l2.m);       long double oldCost = (l2.c - l1.c) * (long double)(l1.m - l3.m);       return newCost > oldCost;     }     int cur;     int count;     vector<Line> lines;   };   int n, m, p;   vector<long long> d, t, accum;   long long GetMinWaitingTime() {     vector<vector<long long> > dp(m, vector<long long>(2, 0));     for (int i = 0; i < int(m); ++i) dp[i][0] = (i + 1) * t[i] - accum[i];     long long res = oo;     ConvexHullOptimization chOpt(m + 1);     for (int i = 1; i < int(p); ++i) {       int curIdx = (i & 1);       int prevIdx = curIdx ^ 1;       chOpt.Reset();       chOpt.Add(-1, accum[0] + dp[0][prevIdx]);       for (int k = 1; k < int(m); ++k) {         dp[k][curIdx] = dp[k][prevIdx];         dp[k][curIdx] =             min(dp[k][curIdx], (k + 1) * t[k] - accum[k] + chOpt.GetValue(t[k]));         chOpt.Add(-(k + 1), accum[k] + dp[k][prevIdx]);       }       res = min(res, dp[m - 1][curIdx]);     }     return res;   }   int main() {     cin >> n >> m >> p;     d.resize(n, 0);     for (int i = 0; i < int(n - 1); ++i) cin >> d[i + 1];     accum.resize(n, 0);     for (int i = 0; i < int(n - 1); ++i) accum[i + 1] = accum[i] + d[i + 1];     t.resize(m);     for (int i = 0; i < int(m); ++i) {       int h;       cin >> h >> t[i];       t[i] -= accum[--h];     }     sort(t.begin(), t.end());     long long mn = t.front();     for (int i = 0; i < int(m); ++i) t[i] -= mn;     accum.clear();     accum.resize(m, 0);     accum[0] = t[0];     for (int i = 0; i < int(m - 1); ++i) accum[i + 1] = accum[i] + t[i + 1];     long long res = GetMinWaitingTime();     cout << res;     int i;     cin >> i;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, in[5100], st[5100], f[5100], ans = 9999999999999;   signed main() {     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> in[i];     }     memset(f, 0x7f, sizeof(f));     memcpy(st, in, sizeof(in));     sort(st + 1, st + n + 1);     for (long long i = 1; i <= n; i++) f[i] = 0;     for (long long i = 1; i <= n; i++) {       for (long long o = 1; o <= n; o++) {         f[o] = min(f[o - 1], f[o] + abs(in[i] - st[o]));       }     }     for (long long i = 1; i <= n; i++) {       ans = min(ans, f[i]);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   double f[4][207][207];   struct node {     int x, y;   };   node a[207];   bool cmp(const node& x, const node& y) { return x.y > y.y; }   int n, m, bm;   int main() {     while (scanf( %d %d %d , &n, &m, &bm) != EOF) {       int i, j, k, r, w;       int sum = 0;       memset(f, 0, sizeof(f));       sum = bm;       for (i = 1; i <= n; i++) {         scanf( %d  , &a[i].x);       }       for (i = 1; i <= n; i++) scanf( %d , &a[i].y);       sort(a + 1, a + n + 1, cmp);       double ans = 0;       memset(f, 0, sizeof(f));       f[0][0][bm] = 1;       for (i = 0; i < n; i++) {         w = (i + 1) & 1;         r = (i)&1;         memset(f[w], 0, sizeof(f[w]));         for (j = 0; j <= i; j++)           for (k = 0; k <= 200; k++) {             int h = k + a[i + 1].y;             if (h < 0) continue;             if (h > 200) h = 200;             f[w][j + 1][h] += f[r][j][k] * (double)a[i + 1].x / 100;           }         for (j = 0; j <= i; j++)           for (k = 0; k <= 200; k++) {             int h = k + a[i].y;             f[w][j][k] += f[r][j][k] * (1 - (double)a[i + 1].x / 100);           }       }       w = n & 1;       for (j = m; j <= n; j++)         for (k = 0; k <= 200; k++) ans += f[w][j][k];       printf( %f n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x, cnt;   int main() {     cin >> x;     while (x > 0) {       if (x % 2 == 1) {         cnt++;       }       x /= 2;     }     cout << cnt << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int num1 = n / 3;     long long int num2 = n - (2 * num1);     if (num1 % 3 != 0 && num2 % 3 != 0)       cout << num1 <<     << num1 <<     << num2;     else if (num1 - 1 > 0 && (num1 - 1) % 3 != 0 && (num2 + 2) % 3 != 0)       cout << num1 - 1 <<     << num1 - 1 <<     << num2 + 2;     else if (num2 - 2 > 0 && (num1 + 1) % 3 != 0 && (num2 - 2) % 3 != 0)       cout << num1 + 1 <<     << num1 + 1 <<     << num2 - 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, c[5555], num[5555], ans[5555];   int main() {     while (~scanf( %d , &n)) {       for (int i = 1; i <= n; i++) scanf( %d , &c[i]);       memset(num, 0, sizeof(num));       memset(ans, 0, sizeof(ans));       for (int i = 1; i <= n; i++) {         memset(num, 0, sizeof(num));         num[c[i]]++, ans[c[i]]++;         int Max = c[i];         for (int j = i + 1; j <= n; j++) {           num[c[j]]++;           if (num[c[j]] > num[Max] || num[c[j]] == num[Max] && c[j] < Max)             Max = c[j];           ans[Max]++;         }       }       for (int i = 1; i <= n; i++) printf( %d%c , ans[i], i == n ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T in() {     char ch;     T n = 0;     bool ng = false;     while (1) {       ch = getchar();       if (ch ==  - ) {         ng = true;         ch = getchar();         break;       }       if (ch >=  0  && ch <=  9 ) break;     }     while (1) {       n = n * 10 + (ch -  0 );       ch = getchar();       if (ch <  0  || ch >  9 ) break;     }     return (ng ? -n : n);   }   template <typename T>   inline T POW(T B, T P) {     if (P == 0) return 1;     if (P & 1)       return B * POW(B, P - 1);     else       return (POW(B, P / 2) * POW(B, P / 2));   }   template <typename T>   inline T Gcd(T a, T b) {     if (a < 0) return Gcd(-a, b);     if (b < 0) return Gcd(a, -b);     return (b == 0) ? a : Gcd(b, a % b);   }   template <typename T>   inline T Lcm(T a, T b) {     if (a < 0) return Lcm(-a, b);     if (b < 0) return Lcm(a, -b);     return a * (b / Gcd(a, b));   }   long long Bigmod(long long base, long long power, long long MOD) {     long long ret = 1;     while (power) {       if (power & 1) ret = (ret * base) % MOD;       base = (base * base) % MOD;       power >>= 1;     }     return ret;   }   bool isVowel(char ch) {     ch = toupper(ch);     if (ch ==  A  || ch ==  U  || ch ==  I  || ch ==  O  || ch ==  E )       return true;     return false;   }   template <typename T>   long long int isLeft(T a, T b, T c) {     return (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y);   }   long long ModInverse(long long number, long long MOD) {     return Bigmod(number, MOD - 2, MOD);   }   bool isConst(char ch) {     if (isalpha(ch) && !isVowel(ch)) return true;     return false;   }   int toInt(string s) {     int sm;     stringstream second(s);     second >> sm;     return sm;   }   int a[3][77];   int Ln[3];   int n;   int dp[77][77][77][2];   int lol(int v, int k, int x, int f) {     if ((v + k + x) == n) return 0;     int &res = dp[v][k][x][f];     if (res != -1) return res;     res = 20000;     int np = v + k + x + 1;     if (v < Ln[1]) {       int tp = 0;       int ps = a[1][v];       for (int i = x; i < Ln[0]; i++) {         if (a[0][i] < ps)           tp++;         else           break;       }       for (int i = k; i < Ln[2]; i++) {         if (a[2][i] < ps)           tp++;         else           break;       }       res = min(res, tp + lol(v + 1, k, x, 1));     }     if (!f) {       if (k < Ln[2]) {         int tp = 0;         int ps = a[2][k];         for (int i = x; i < Ln[0]; i++) {           if (a[0][i] < ps)             tp++;           else             break;         }         for (int i = v; i < Ln[1]; i++) {           if (a[1][i] < ps)             tp++;           else             break;         }         res = min(res, tp + lol(v, k + 1, x, 0));       }     }     if (x < Ln[0]) {       int tp = 0;       int ps = a[0][x];       for (int i = v; i < Ln[1]; i++) {         if (a[1][i] < ps)           tp++;         else           break;       }       for (int i = k; i < Ln[2]; i++) {         if (a[2][i] < ps)           tp++;         else           break;       }       res = min(res, tp + lol(v, k, x + 1, 0));     }     return res;   }   map<char, int> mp;   int main() {     mp[ V ] = 1;     mp[ K ] = 2;     string s;     cin >> n;     cin >> s;     for (int i = 1; i <= n; i++) {       int tp = mp[s[i - 1]];       a[tp][Ln[tp]] = i;       Ln[tp]++;     }     memset(dp, -1, sizeof(dp));     cout << lol(0, 0, 0, 0) << endl;     return 0;   }


#include<bits/stdc++.h>   using namespace std;      #define all(x)       (x).begin(), (x).end()   #define acarr(arr, n, type)     type *arr=new type[n]; for(long long i=0; i<n; ++i) cin >> arr[i];   #define ll       long long   #define TF(ok)      cout << (ok ?  YES n  :  NO n )   #define ld       long double   #define vi       vector<int> v1   #define pb       push_back      int solve(){        ll ans=0, tab=0;       vector<int> v1(3);    for (int i=0; i<3; i++){     cin >> v1[i];     ans+=v1[i];    }       if (ans%9==0){     tab= ans/9;     for (int i=0; i<3; i++){      if (v1[i]<tab){       cout <<  NO n  ;       return 0;      }     }     cout <<  YES n ;    }    else{     cout <<  NO n  ;    }          return 0;   }         int main(){    ios::sync_with_stdio(false);    cin.tie(0);    int q;     q=1;   cin >> q;    while(q--){     solve();    }       return 0;   }      /*   ~ Check for overflow    ~ Division by 0    ~ Uninitialized    ~   */


#include <bits/stdc++.h>   using namespace std;   const long long INF = numeric_limits<long long>::max() / 4;   struct MinCostMaxFlow {     int N;     vector<vector<long long> > cap, flow, cost;     vector<int> found;     vector<long long> dist, pi, width;     vector<pair<int, int> > dad;     MinCostMaxFlow(int N)         : N(N),           cap(N, vector<long long>(N)),           flow(N, vector<long long>(N)),           cost(N, vector<long long>(N)),           found(N),           dist(N),           pi(N),           width(N),           dad(N) {}     void AddEdge(int from, int to, long long cap, long long cost) {       this->cap[from][to] = cap;       this->cost[from][to] = cost;     }     void Relax(int s, int k, long long cap, long long cost, int dir) {       long long val = dist[s] + pi[s] - pi[k] + cost;       if (cap && val < dist[k]) {         dist[k] = val;         dad[k] = make_pair(s, dir);         width[k] = min(cap, width[s]);       }     }     long long Dijkstra(int s, int t) {       fill(found.begin(), found.end(), false);       fill(dist.begin(), dist.end(), INF);       fill(width.begin(), width.end(), 0);       dist[s] = 0;       width[s] = INF;       while (s != -1) {         int best = -1;         found[s] = true;         for (int k = 0; k < N; k++) {           if (found[k]) continue;           Relax(s, k, cap[s][k] - flow[s][k], cost[s][k], 1);           Relax(s, k, flow[k][s], -cost[k][s], -1);           if (best == -1 || dist[k] < dist[best]) best = k;         }         s = best;       }       for (int k = 0; k < N; k++) pi[k] = min(pi[k] + dist[k], INF);       return width[t];     }     pair<long long, long long> GetMaxFlow(int s, int t) {       long long totflow = 0, totcost = 0;       while (long long amt = Dijkstra(s, t)) {         totflow += amt;         for (int x = t; x != s; x = dad[x].first) {           if (dad[x].second == 1) {             flow[dad[x].first][x] += amt;             totcost += amt * cost[dad[x].first][x];           } else {             flow[x][dad[x].first] -= amt;             totcost -= amt * cost[x][dad[x].first];           }         }       }       return make_pair(totflow, totcost);     }   };   const int N = 105;   char s[N];   int b[N];   int main() {     int n;     cin >> n;     scanf( %s , s + 1);     int sum = 0;     int cnt[26];     for (int i = 0; i < 26; i++) cnt[i] = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , b + i);       sum += b[i];       cnt[s[i] -  a ]++;     }     MinCostMaxFlow mcmf(1 + 26 + n / 2 + 1 + 1);     for (int i = 1; i <= 26; i++) {       mcmf.AddEdge(1, i + 1, cnt[i - 1], 0);     }     for (int i = 1; i <= n / 2; i++) {       mcmf.AddEdge(27 + i, 1 + 26 + n / 2 + 1, 2, 0);     }     for (int i = 1; i <= n / 2; i++) {       for (int j = 0; j < 26; j++) {         char k =  a  + j;         if (s[i] == k && s[n - i + 1] == k) {           mcmf.AddEdge(2 + j, 27 + i, 1, sum - max(b[i], b[n - i + 1]));         } else if (s[i] == k) {           mcmf.AddEdge(2 + j, 27 + i, 1, sum - b[i]);         } else if (s[n - i + 1] == k) {           mcmf.AddEdge(2 + j, 27 + i, 1, sum - b[n - i + 1]);         } else {           mcmf.AddEdge(2 + j, 27 + i, 1, sum);         }       }     }     auto e = mcmf.GetMaxFlow(1, 1 + 26 + n / 2 + 1);     cout << n * sum - e.second << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     scanf( %d %d %d , &a, &b, &c);     bool valid = false;     int bo1, bo2, bo3;     for (int i = 0; i <= a; i++) {       bo1 = i;       bo3 = a - i;       bo2 = c - bo3;       if (bo1 + bo3 != a || bo1 + bo2 != b || bo2 + bo3 != c) continue;       if (bo1 < 0 || bo2 < 0 || bo3 < 0) continue;       valid = true;       break;     }     if (!valid)       puts( Impossible );     else       printf( %d %d %d n , bo1, bo2, bo3);     return 0;   }


#include <bits/stdc++.h>   const int mod = 998244353;   const int N = 1e6 + 7;   using namespace std;   long long n, m, k, i, j, t, sig = 0, ans;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   map<pair<int, int>, set<long long>> mp;   long long x[1005], y[1005];   struct node {     int x, pos;   } p[500007];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     long long ans = 0, sum = 0;     for (i = 1; i <= n; i++) cin >> x[i] >> y[i];     for (i = 1; i <= n - 1; i++) {       for (j = i + 1; j <= n; j++) {         long long x1 = x[i], x2 = x[j], y1 = y[i], y2 = y[j];         int b = x1 - x2, a = y1 - y2;         long long d = gcd(a, b);         a /= d, b /= d;         if (a < 0 || (!a && b < 0)) {           a = -a, b = -b;         }         pair<int, int> line(a, b);         long long c = a * x1 - b * y1;         if (!mp[line].count(c)) {           sum++;           mp[line].insert(c);           ans += sum - mp[line].size();         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     for (int i = 0; i < q; i++) {       int a, b, c;       cin >> a;       cin >> b;       cin >> c;       int p1, p2;       cin >> p1;       cin >> p2;       int min_no = min(b, c);       if (a <= 1) {         cout << 0 <<   n ;         continue;       }       if (b * 2 + c * 2 > a) {         int p = 0;         if (p2 >= p1) {           if (c * 2 > a) {             cout << (a / 2) * p2 <<   n ;             continue;           } else {             p += c * p2;             if ((a - c * 2) <= 1) {               cout << p <<   n ;               continue;             }             p += ((a - c * 2) / 2) * p1;             cout << p <<   n ;             continue;           }         } else if (p1 > p2) {           if (b * 2 > a) {             cout << (a / 2) * p1 <<   n ;             continue;           } else {             p += b * p1;             if ((a - b * 2) <= 1) {               cout << p <<   n ;               continue;             }             p += ((a - b * 2) / 2) * p2;             cout << p <<   n ;             continue;           }         }       } else {         int p = 0;         p += (p2 * c) + (p1 * b);         cout << p <<   n ;         continue;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, h, t, u, v, tim, d[100100], w[100100], W[100100];   vector<int> e[100100], ans;   int main() {     scanf( %d%d%d%d , &n, &m, &h, &t);     for (int i = 0; i < m; i++)       scanf( %d%d , &u, &v), e[u].push_back(v), e[v].push_back(u);     for (int i = 1; i < n + 1; i++) d[i] = e[i].size();     for (int i = 1; i < n + 1; i++) {       if (d[i] <= h) continue;       for (int j : e[i]) w[j] = i;       for (int j : e[i]) {         tim++;         int p = d[i] - 1 - h, q = 0;         ans.clear();         for (int k : e[j]) {           if (k != i)             if (p && w[k] == i)               p--, q++, ans.push_back(k), W[k] = tim;             else if (w[k] != i)               q++, ans.push_back(k), W[k] = tim;           if (q == t) break;         }         if (q == t) {           puts( YES );           printf( %d %d n , i, j);           int p = 0;           for (int k : e[i])             if (k != j && W[k] != tim) {               p++, printf( %d  , k);               if (p == h) break;             }           puts(  );           for (int k : ans) printf( %d  , k);           return 0;         }       }     }     puts( NO );   }


#include <bits/stdc++.h>   int main() {     int x, y;     scanf( %d%d , &x, &y);     double r = sqrt(x * x + y * y);     int rmin = r;     if ((double)rmin == r) {       printf( black );       return 0;     }     if (x == 0 || y == 0) {       printf( black );       return 0;     }     double tan = (double)y / (double)x;     if (rmin % 2 == 1 && tan > 0)       printf( white );     else if (rmin % 2 == 1 && tan < 0)       printf( black );     else if (rmin % 2 == 0 && tan > 0)       printf( black );     else if (rmin % 2 == 0 && tan < 0)       printf( white );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   int n, m, a, b, g;   int dis[N];   long long ans, c[N];   long long sum(int u) { return 1LL * u * (u + 1) / 2; }   long long query(int u) {     return sum(u / g + 1) * g - 1LL * (u / g + 1) * ((g - ((u + 1) % g)) % g);   }   int gcd(int u, int v) {     if (v == 0) {       return u;     }     return gcd(v, u % v);   }   set<pair<int, int> > s;   int main() {     scanf( %d%d%d , &n, &a, &b);     g = gcd(a, b);     if (n > a + b - g) {       ans += query(n) - query(a + b - g);       n = a + b - g;     }     memset(dis, 0x3f, sizeof dis);     dis[0] = 0;     s.insert({0, 0});     while (!s.empty()) {       auto u = *s.begin();       s.erase(s.begin());       if (dis[u.second] != u.first) {         continue;       }       ++c[u.first];       if (u.second >= b && u.first < dis[u.second - b]) {         dis[u.second - b] = u.first;         s.insert({u.first, u.second - b});       }       if (u.second + a <= n && max(u.first, u.second + a) < dis[u.second + a]) {         dis[u.second + a] = max(u.first, u.second + a);         s.insert({max(u.first, u.second + a), u.second + a});       }     }     for (int i = 1; i <= n; i++) {       c[i] += c[i - 1];     }     for (int i = 0; i <= n; i++) {       ans += c[i];     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, first, a[1111];   int b[1111], ub = -1, pos;   vector<int> c[1111];   vector<int> d;   int can[1111];   void go(int p, int v) {     if (v == -1) return;     if (v == first) ub = p;     c[p].push_back(v);     go(p, a[v]);   }   int main() {     scanf( %d%d , &n, &first);     --first;     for (int i = 0; i < n; ++i) b[i] = -1;     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);       a[i]--;       b[a[i]] = i;     }     for (int i = 0; i < n; ++i) {       c[i].clear();       if (b[i] == -1) {         go(i, i);       }     }     assert(ub >= 0);     d.clear();     for (int i = 0; i < c[ub].size(); ++i) {       if (c[ub][i] == first) pos = c[ub].size() - i;     }     for (int i = 0; i < n; ++i) {       if (i == ub) continue;       if (c[i].size() != 0) d.push_back(c[i].size());     }     sort(d.begin(), d.end());     for (int i = 0; i < n; ++i) can[i] = 0;     can[0] = 1;     for (int i = 0; i < d.size(); ++i) {       for (int j = n - 1; j >= 0; --j) {         if ((j + d[i] < n) && (can[j] == 1)) can[j + d[i]] = 1;       }     }     for (int i = 0; i < n; ++i) {       if (can[i]) cout << i + pos << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, maxi = 0;     cin >> n;     if (n == 1) {       cout <<  1  << endl;       return 0;     }     vector<int> a(n, 0);     vector<int> right(n, 0);     vector<int> left(n, 0);     vector<int> ans(n, 0);     for (i = 0; i < n; i++) scanf(  %d , &a[i]);     for (i = 1; i < n; i++)       if (a[i] > a[i - 1]) left[i] += left[i - 1] + 1;     for (i = n - 2; i >= 0; i--)       if (a[i] < a[i + 1]) right[i] += right[i + 1] + 1;     for (i = 1; i < n - 1; i++) {       if (a[i - 1] < a[i] && a[i] < a[i + 1])         ans[i] = left[i] + right[i] + 1;       else if (a[i + 1] > a[i - 1] + 1)         ans[i] = left[i - 1] + right[i + 1] + 3;       else         ans[i] = max(left[i - 1], right[i + 1]) + 2;     }     ans[0] = (a[0] < a[1]) ? right[0] + 1 : right[1] + 2;     ans[n - 1] = (a[n - 1] > a[n - 2]) ? left[n - 1] + 1 : left[n - 2] + 2;     for (i = 0; i < n; i++)       if (ans[i] > maxi) maxi = ans[i];     cout << maxi << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, sum, as, b[100005], len, ia, la;   pair<int, int> a[100005];   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i].first;       a[i].second = i + 1;       sum += a[i].first;     }     sort(a, a + n);     la = n / 2;     for (int i = 0; i < n / 2; ++i) as += a[i].first;     for (int d = (sum - a[n - 1].first + 1) / 2; as < d;          as -= a[ia++].first, as += a[la++].first)       ;     cout << la - ia << endl;     for (int i = 0; i < n; ++i) {       if (i < ia || i >= la)         b[len++] = a[i].second;       else {         if (i - ia) cout <<    ;         cout << a[i].second;       }     }     cout << endl;     cout << len << endl;     for (int i = 0; i < len; ++i) {       if (i) cout <<    ;       cout << b[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   const double PI = acos(-1);   int N;   long long A;   struct point {     long long x, y;   } p[100001];   struct line {     double start, end;   } q[100001];   inline long long sqr(long long x) { return x * x; }   inline double tan_360(double x, double y) {     if (x == 0) return PI * (y > 0 ? 0.5 : 1.5);     if (y == 0) return PI * (x > 0 ? 0.0 : 1.0);     double ans = atan(y / x);     if (x > 0 && y > 0) return ans;     if (x < 0 && y > 0) return ans + PI;     if (x < 0 && y < 0) return ans + PI;     return ans + PI * 2;   }   bool check(double mid) {     int L = 0;     for (int i = 1; i <= N; i++)       if (sqrt(sqr(A + p[i].x) + sqr(p[i].y)) <=           mid - sqrt(sqr(A - p[i].x) + sqr(p[i].y)))         return true;     for (int i = 1; i <= N; i++) {       double R1 = mid, R2 = sqrt(sqr(A - p[i].x) + sqr(p[i].y)),              dis = sqrt(sqr(A + p[i].x) + sqr(p[i].y));       if (R1 + R2 > dis && R1 + dis > R2 && R2 + dis > R1) {         double mid_angle = tan_360(p[i].x + A, p[i].y),                dif = acos((R1 * R1 + dis * dis - R2 * R2) / (2 * R1 * dis));         q[++L] = {mid_angle < dif ? mid_angle - dif + 2 * PI : mid_angle - dif,                   mid_angle + dif >= 2 * PI ? mid_angle + dif - 2 * PI                                             : mid_angle + dif};         if (q[L].start > q[L].end) std::swap(q[L].start, q[L].end);       }     }     std::sort(q + 1, q + L + 1, [](const line &a, const line &b) {       return a.start < b.start || a.start == b.start && a.end < b.end;     });     static int stack[100001];     int D = 0;     for (int i = 1; i <= L; i++) {       while (D && q[stack[D]].end < q[i].start) D--;       if (D && q[stack[D]].end < q[i].end) return true;       stack[++D] = i;     }     return false;   }   int main() {     scanf( %d%lld , &N, &A);     for (int i = 1; i <= N; i++) scanf( %lld%lld , &p[i].x, &p[i].y);     double l = 0, r = A * 2;     for (int T = 55; T--;) {       double mid = (l + r) / 2;       (check(mid) ? r : l) = mid;     }     printf( %.10lf n , l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1000100;   struct node {     int w, flag;     int a, b;     int id;     long long num;   } a[M];   int n, pos[M], m, s[M];   bool cmp(const node &x, const node &y) {     if (x.w == y.w) return x.flag > y.flag;     return x.w < y.w;   }   int fa[M];   bool cmp1(const node &x, const node &y) { return x.id < y.id; }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &a[i].w, &a[i].flag);       a[i].id = i;     }     sort(a + 1, a + 1 + m, cmp);     for (int i = 1; i <= n; i++) fa[i] = i;     int k = 1;     for (int i = 1; i <= m; i++)       if (a[i].flag) {         a[i].a = k;         pos[k] = i;         a[i].num = (long long)(k - 1) * k / 2 + 1;         a[i].b = ++k;       }     bool flag = 0;     for (int i = 1; i <= m; i++)       if (a[i].flag)         if (a[i].num < (long long)i) {           flag = 1;           break;         }     if (flag) {       printf( -1 n );       return 0;     }     pos[n] = m + 1;     int h = 3, s1 = 1;     for (int i = 1; i < n; i++) {       for (int j = pos[i] + 1; j < pos[i + 1];) {         a[j].a = s1;         a[j].b = h;         s1++;         if (s1 == h - 1) {           s1 = 1;           h++;         }         j++;       }     }     if (flag) {       printf( -1 n );       return 0;     }     sort(a + 1, a + 1 + m, cmp1);     for (int i = 1; i <= m; i++) printf( %d %d n , a[i].a, a[i].b);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 605;   int nask(vector<int> tmp) {     if (!tmp.size() || tmp.size() == 1) return 0;     cout <<  ?   << tmp.size() << endl;     for (int i = (0), iend = ((int)tmp.size() - 1); i <= iend; i++)       cout << tmp[i] <<    ;     cout << endl;     cout.flush();     int ans;     cin >> ans;     if (ans == -1) exit(0);     return ans;   }   int dask(int u, vector<int> tar) {     int cntsig = nask(tar);     tar.push_back(u);     int cnttot = nask(tar);     return cnttot - cntsig;   }   int n;   bool vis[maxn];   int bl[maxn];   int find(int u, vector<int> tmp) {     vector<int> c1, c2;     if (tmp.size() == 1) return tmp[0];     for (int i = (0), iend = ((int)(tmp.size()) - 1); i <= iend; i++) {       if (c1.size() < tmp.size() / 2)         c1.push_back(tmp[i]);       else         c2.push_back(tmp[i]);     }     if (dask(u, c1))       return find(u, c1);     else       return find(u, c2);   }   vector<int> half[2];   vector<int> side[maxn];   void dfs(int u) {     half[bl[u]].push_back(u);     while (1) {       vector<int> tmp;       for (int i = (1), iend = (n); i <= iend; i++)         if (!vis[i]) tmp.push_back(i);       if (dask(u, tmp) == 0) return;       int tar = find(u, tmp);       side[u].push_back(tar);       side[tar].push_back(u);       vis[tar] = 1;       bl[tar] = bl[u] ^ 1;       dfs(tar);     }   }   int stk[maxn], top;   vector<int> ans;   void cfs(int u, int tar) {     stk[++top] = u;     if (u == tar) {       for (int i = (1), iend = (top); i <= iend; i++) ans.push_back(stk[i]);       return;     }     for (int i = (0), iend = (side[u].size() - 1); i <= iend; i++) {       int v = side[u][i];       if (!vis[v]) {         vis[v] = 1;         cfs(v, tar);       }     }     top--;   }   void ans_out(int u, int v) {     memset(vis, 0, sizeof(vis));     vis[u] = 1;     cfs(u, v);     cout <<  N   << ans.size() << endl;     for (int i = (0), iend = ((int)(ans.size()) - 1); i <= iend; i++)       cout << ans[i] <<    ;     return;   }   int main() {     ios::sync_with_stdio(0);     cin >> n;     vis[1] = 1;     dfs(1);     if (!nask(half[0]) && !nask(half[1])) {       cout <<  Y   << half[0].size() << endl;       for (int i = (0), iend = ((int)(half[0].size()) - 1); i <= iend; i++)         cout << half[0][i] <<    ;       return 0;     } else {       for (int i = (0), iend = (1); i <= iend; i++)         for (int j = (0), jend = ((int)(half[i].size()) - 1); j <= jend; j++) {           vector<int> tmp;           int u = half[i][j];           for (int k = (0), kend = ((int)(half[i].size()) - 1); k <= kend; k++)             if (half[i][k] != u) tmp.push_back(half[i][k]);           if (dask(u, tmp)) {             for (int k = (0), kend = ((int)(tmp.size()) - 1); k <= kend; k++) {               vector<int> gg;               gg.push_back(u);               gg.push_back(tmp[k]);               if (nask(gg)) {                 ans_out(u, tmp[k]);                 return 0;               }             }           }         }     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[200010];   int prv[200010];   int f[200010][10];   void FillAll(int l, int r, int x, int y) {     for (int i = x, j = l; i <= y; i++) {       int ci = (r - j + 1) / (y - i + 1);       ci = max(ci, 2);       ci = min(ci, 5);       for (int jj = j; jj < j + ci; jj++) a[jj] = i;       j += ci;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);     }     for (int i = 1; i <= n; i++) prv[i] = a[i - 1] ? i - 1 : prv[i - 1];     memset(f, -1, sizeof f);     f[0][5] = 0;     int last = 0;     for (int i = 1; i <= n; i++)       if (a[i]) {         last = i;         int j = prv[i];         int space = i - j - 1;         if (a[i] > a[j]) {           for (int ki = 0; ki < min(5, space + 1); ki++)             for (int kj1 = 1; kj1 <= 5 && f[i][ki + 1] == -1; kj1++)               if (f[j][kj1] >= 0) {                 for (int kj2 = max(0, 2 - kj1); kj2 <= min(space - ki, 5 - kj1);                      kj2++) {                   int least = kj2 + 2 * (a[i] - a[j] - 1) + ki;                   int most = kj2 + 5 * (a[i] - a[j] - 1) + ki;                   if (least <= space && space <= most) {                     f[i][ki + 1] = kj2;                     break;                   }                 }               }         }         if (a[i] == a[j]) {           int ki = space + 1;           for (int kj = 1; kj <= 5 - ki; kj++)             if (f[j][kj] >= 0) f[i][ki + kj] = 0;         }         if (a[i] < a[j]) {           printf( -1 );           return 0;         }       }     if (last) {       int had = last == n - 1;       for (int i = last; i; i = prv[i]) {         int j = prv[i];         if (a[i] != a[j]) {           int lbound = max(1, 2 - had);           int rbound = 5 - had;           if (i == last) {             lbound = 1 + (last == n);             rbound = 5 - (last == n - 1);           }           bool isRet = 0;           for (int ki = rbound; ki >= lbound; ki--)             if (f[i][ki] >= 0) {               for (int k = i - ki + 1; k <= i; k++) a[k] = a[i];               for (int k = j + 1; k <= j + f[i][ki]; k++) a[k] = a[j];               FillAll(j + f[i][ki] + 1, i - ki, a[j] + 1, a[i] - 1);               had = f[i][ki];               isRet = 1;               break;             }           if (!isRet) {             printf( -1 );             return 0;           }         } else {           for (int k = j + 1; k < i; k++) a[k] = a[i];           had += i - j;         }       }       if (a[last] != a[last - 1]) {         a[last + 1] = a[last];         last++;       }       if (last > n) {         printf( -1 );         return 0;       }     }     for (int i = last + 1; i <= n; i++)       if (i == 1 || a[i - 1] == a[i - 2])         a[i] = a[i - 1] + 1;       else         a[i] = a[i - 1];     if (a[n] != a[n - 1]) a[n] = a[n - 1];     printf( %d n , a[n]);     for (int i = 1; i <= n; i++) printf( %d  , a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const int N = 1e6 + 5;   long long p[N];   long long cnt[N];   vector<long long> a[N];   long long qmi(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % mod;       b >>= 1;       a = a * a % mod;     }     return ans % mod;   }   int main() {     long long n, k, z;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> k;       for (int j = 1; j <= k; j++) {         cin >> z;         a[i].push_back(z);         cnt[z]++;       }     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       long long m = a[i].size();       long long temp = 0;       for (int j = 0; j < m; j++) {         temp += cnt[a[i][j]];       }       long long cur = qmi((long long)n * n * m % mod, mod - 2) * temp % mod;       ans = (cur + ans) % mod;       ans %= mod;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Iinf = 1e9;   const long long LLinf = 1e18;   const double eps = 1e-6;   const long long mod = 1e9 + 7;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     int s, x1, x2;     cin >> s >> x1 >> x2;     int t1, t2;     cin >> t1 >> t2;     int p, d;     cin >> p >> d;     if (d > 0) {       if (x1 > x2) {         cout << min(t1 * (s * 2 - p - x1 + abs(x1 - x2)), t2 * abs(x1 - x2));       } else if (p > x2) {         cout << min(t1 * (s * 2 - p + x1 + abs(x1 - x2)), t2 * abs(x1 - x2));       } else if (p <= x1) {         cout << min(t1 * (x1 - p + abs(x1 - x2)), t2 * abs(x1 - x2));       } else if (p > x1) {         cout << min(t1 * (s * 2 - p + x1 + abs(x1 - x2)), t2 * abs(x1 - x2));       }     } else {       if (x1 > x2) {         if (p >= x1) {           cout << min(t1 * (p - x1 + abs(x1 - x2)), t2 * (x1 - x2));         } else {           cout << min(t1 * (p + s + s - x1 + abs(x1 - x2)), t2 * abs(x1 - x2));         }       } else {         cout << min(t1 * (p + x1 + abs(x1 - x2)), t2 * abs(x1 - x2));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int n = 1 << 17;   double sum[n * 2], lazy_mul[n * 2], lazy_add[n * 2];   void push(int i, int l, int r) {     if (lazy_mul[i] != 1 || lazy_add[i] != 0) {       sum[i] = sum[i] * lazy_mul[i] + lazy_add[i] * (r - l);       if (i < n) {         for (int j : {i * 2, i * 2 + 1}) {           lazy_mul[j] *= lazy_mul[i];           lazy_add[j] *= lazy_mul[i];           lazy_add[j] += lazy_add[i];         }       }       lazy_mul[i] = 1;       lazy_add[i] = 0;     }   }   void fma(double mul, double add, int a, int b, int l = 0, int r = n,            int i = 1) {     push(i, l, r);     if (a >= r || b <= l) return;     if (a <= l && b >= r) {       lazy_mul[i] = mul;       lazy_add[i] = add;       push(i, l, r);       return;     }     int m = l + r >> 1;     fma(mul, add, a, b, l, m, i * 2);     fma(mul, add, a, b, m, r, i * 2 + 1);     sum[i] = sum[i * 2] + sum[i * 2 + 1];   }   double querySum(int a, int b, int l = 0, int r = n, int i = 1) {     push(i, l, r);     if (a >= r || b <= l) return 0;     if (a <= l && b >= r) {       return sum[i];     }     int m = l + r >> 1;     return querySum(a, b, l, m, i * 2) + querySum(a, b, m, r, i * 2 + 1);   }   int main() {     fill_n(lazy_mul, n * 2, 1.);     ios::sync_with_stdio(0);     cin.tie(0);     int n, q;     cin >> n >> q;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       fma(1, a, i, i + 1);     }     while (q--) {       int type;       cin >> type;       if (type == 1) {         int l1, r1, l2, r2;         cin >> l1 >> r1 >> l2 >> r2;         l1--, l2--;         double e1 = querySum(l1, r1) / (r1 - l1);         double e2 = querySum(l2, r2) / (r2 - l2);         double p1 = 1. / (r1 - l1);         fma(1 - p1, p1 * e2, l1, r1);         double p2 = 1. / (r2 - l2);         fma(1 - p2, p2 * e1, l2, r2);       } else {         int l, r;         cin >> l >> r;         l--;         cout << setprecision(20) << querySum(l, r) <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m;     cin >> n >> m;     int arr[n];     int a = 0, b = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] == 1)         a++;       else         b++;     }     vector<pair<int, int>> v(m);     for (int i = 0; i < m; i++) cin >> v[i].first >> v[i].second;     for (int i = 0; i < m; i++) {       if ((v[i].second - v[i].first + 1) % 2 == 1)         cout <<  0  << endl;       else {         int c = v[i].second - v[i].first + 1;         int d = c / 2;         if (d <= a && d <= b)           cout <<  1  << endl;         else           cout <<  0  << endl;       }     }   }   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     int t;     t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   string str;   int main() {     cin >> str;     bool chk = false;     for (int i = 0; i <= str.length(); i++) {       for (char ch =  a ; ch <=  z ; ch++) {         string temp1 = str.substr(0, i) + ch + str.substr(i);         string temp2 = temp1;         reverse(temp2.begin(), temp2.end());         if (temp1.compare(temp2) == 0) {           cout << temp1 << endl;           chk = true;           break;         }       }       if (chk == true) {         break;       }     }     if (chk == false) {       cout <<  NA n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   const int M = 55;   const int K = 200010;   const int LIT = 2500;   const int INF = 1 << 30;   const int dir[6][2] = {{2, 0}, {-2, 0}, {1, 1}, {-1, 1}, {1, -1}, {-1, -1}};   bool check(long long x, long long y, long long n) {     long long dist = x * x + 3 * y * y;     long long cmp = 4 * n * n;     return dist <= cmp;   }   bool inside(long long x, long long y, long long n) {     for (int j = 0; j < 6; j++) {       long long xx = x + dir[j][0];       long long yy = y + dir[j][1];       if (!check(xx, yy, n)) return 0;     }     return 1;   }   void solve(int n) {     long long x = 0, y = 0;     long long res = 1;     while (1) {       y += 2;       if (!inside(x, y, n)) break;       res += 2;     }     while (y >= 0) {       x += 3, y++;       while (y >= 0) {         if (inside(x, y, n)) {           res += (y + 1) * 2;           break;         }         y -= 2;       }     }     cout << res << endl;   }   int main() {     int n;     while (cin >> n) {       solve(n);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   long long n, x;   void printbin(long long a) {     for (int i = 20; i >= 0; i--) {       long long c = a & (1LL << i);       cout << bool(c);     }     cout <<   n ;   }   int main() {     cin >> n >> x;     long long reversed = 0;     reversed |= 1LL << 17;     if (n == 1) {       cout <<  YES n  << x;       return 0;     }     if (n == 2 && x == 0) {       cout <<  NO n ;       return 0;     }     if (n == 2) {       cout <<  YES n  << 0 <<     << x <<   n ;       return 0;     }     cout <<  YES n ;     long long value = 0;     long long test = 0;     for (int i = 1; i <= n - 3; i++) {       cout << i <<    ;       value ^= i;       test ^= i;     }     reversed = x ^ value;     reversed |= 1LL << 17;     long long temp2 = 1LL << 17;     if (reversed == 1LL << 17) {       reversed |= 1LL << 18;       long long temp = 1LL << 18;       cout << reversed <<     << temp <<     << (temp ^ reversed) <<   n ;     } else {       cout << reversed <<     << temp2 <<     << 0 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   namespace mist {   const int W = 103, N = W * W, M = 404;   int MOD;   long long inv(int x) {     return (x == 1 || x == -1) ? x : (-(MOD / x) * inv(MOD % x) % MOD);   }   struct calculator {     int s[M][M];     int n;     void reset(int init_n) {       n = init_n;       memset(s, 0, sizeof(s));     }     void add(int x, int y) { s[x][y]--, s[y][x]--, s[x][x]++, s[y][y]++; }     int calc() {       n--;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) s[i][j] %= MOD;       int sign = 1, row = 1, drow;       for (int col = 1; col <= n; col++) {         for (drow = row; drow <= n && !s[drow][col]; drow++)           ;         if (drow > n) return 0;         if (drow != row) {           sign *= -1;           for (int i = 1; i <= n; i++) std::swap(s[row][i], s[drow][i]);         }         for (int i = row + 1; i <= n; i++)           if (s[i][col]) {             int x = -s[i][col] * inv(s[row][col]) % MOD;             for (int j = 1; j <= n; j++)               s[i][j] = (s[i][j] + (long long)x * s[row][j]) % MOD;           }         row++;       }       int ret = 1;       for (int i = 1; i <= n; i++) ret = (long long)ret * s[i][i] % MOD;       ret *= sign;       return (ret + MOD) % MOD;     }   } C;   struct dus {     int q[N];     void reset(int n) {       for (int i = 1; i <= n; i++) q[i] = i;     }     int ask(int p) { return p == q[p] ? p : q[p] = ask(q[p]); }     bool uni(int u, int v) { return ask(u) == ask(v); }     bool link(int u, int v) {       if (uni(u, v)) return 0;       q[ask(u)] = ask(v);       return 1;     }   } d;   char G[W][W];   int n, m;   int mp(int x, int y) { return x * (m + 1) + y; }   bool initialize() {     scanf( %d%d%d , &n, &m, &MOD);     for (int i = 1; i <= n; i++) scanf( %s , G[i] + 1);     int total_number = (n + 1) * (m + 1);     d.reset(total_number), d.reset(total_number);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (G[i][j] ==  / ) {           int u = mp(i - 1, j), v = mp(i, j - 1), flag = 1;           flag = d.link(u, v);           if (!flag) return 0;         } else if (G[i][j] ==     ) {           int u = mp(i - 1, j - 1), v = mp(i, j), flag = 1;           flag = d.link(u, v);           if (!flag) return 0;         }     return 1;   }   int id[N], tot;   int part0() {     tot = 0;     for (int i = 0; i <= n; i++)       for (int j = 0; j <= m; j++)         if (!((i + j) & 1) && d.q[mp(i, j)] == mp(i, j)) id[mp(i, j)] = ++tot;     C.reset(tot);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (G[i][j] ==  * ) {           int u, v;           if ((i + j) & 1)             u = mp(i - 1, j), v = mp(i, j - 1);           else             u = mp(i, j), v = mp(i - 1, j - 1);           u = id[d.ask(u)], v = id[d.ask(v)];           C.add(u, v);         }     return C.calc();   }   int part1() {     tot = 0;     for (int i = 0; i <= n; i++)       for (int j = 0; j <= m; j++)         if (((i + j) & 1) && d.q[mp(i, j)] == mp(i, j)) id[mp(i, j)] = ++tot;     C.reset(tot);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (G[i][j] ==  * ) {           int u, v;           if ((i + j) & 1)             u = mp(i, j), v = mp(i - 1, j - 1);           else             u = mp(i - 1, j), v = mp(i, j - 1);           u = id[d.ask(u)], v = id[d.ask(v)];           C.add(u, v);         }     return C.calc();   }   void solve() {     if (!initialize()) return void(printf( 0 n ));     int ans = (part0() + part1()) % MOD;     ans = (ans + MOD) % MOD;     printf( %d n , ans);   }   }  // namespace mist   int main() {     mist::solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e2 + 5;   const int mod = 1e9 + 7;   const long long inf = 1e18;   int n, ans, pos, pos1;   int un[N], un1[N], cl[N], cl1[N], tr;   string t, s;   int calc(string e) {     un[0] = cl[0] = 0, tr = 0;     for (int i = 0; i < n; i++) {       if (i) un[i] = un[i - 1], cl[i] = cl[i - 1];       if (e[i] ==  ( )         un[i]++;       else {         if (un[i])           un[i]--;         else           cl[i]++;       }     }     if (cl[n - 1] == 0 and un[n - 1] == 0) tr = 1;     un1[0] = cl1[0] = 0;     for (int i = n - 1; i >= 0; i--) {       un1[i] = un1[i + 1], cl1[i] = cl1[i + 1];       if (e[i] ==  ) )         un1[i]++;       else {         if (un1[i])           un1[i]--;         else           cl1[i]++;       }     }     int jog = 0;     for (int i = n - 1; i >= 1; i--)       if (un[i - 1] == 0 and un1[i] == 0 and cl[i - 1] == cl1[i]) jog++;     return jog + tr;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> s;     ans = calc(s);     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         t = s;         swap(t[i], t[j]);         if (ans < calc(t)) {           ans = calc(t);           pos = i, pos1 = j;         }       }     }     cout << ans <<   n  << pos + 1 <<     << pos1 + 1;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXS = 100000;   inline long long get(long long n, long long ma, long long b) {     return max(ma, (6 * n + b - 1) / b) * b;   }   int main() {     long long n, a, b;     cin >> n >> a >> b;     if (a * b >= 6 * n) {       cout << a * b << endl;       cout << a <<     << b << endl;     } else {       long long best = b;       for (int i = b; i <= MAXS; i++)         if (get(n, a, best) > get(n, a, i)) best = i;       long long best2 = a;       for (int i = a; i <= MAXS; i++)         if (get(n, b, best2) > get(n, b, i)) best2 = i;       if (get(n, a, best) < get(n, b, best2)) {         a = max(a, (6 * n + best - 1) / best);         b = best;       } else {         a = best2;         b = max(b, (6 * n + best2 - 1) / best2);       }       cout << a * b << endl;       cout << a <<     << b << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300010;   pair<int, int> c[MAXN];   int n, x[2];   bool check(int pos, int fst, int snd) {     int a = c[pos].first;     int k = (x[fst] + a - 1) / a;     if (pos + k >= n) {       return false;     }     int val = c[pos + k].first;     int dk = (x[snd] + val - 1) / val;     if (pos + k + dk > n) {       return false;     }     if (fst == 0) {       printf( Yes n );       printf( %d %d n , k, dk);       for (int i = 0; i < k; ++i) {         printf( %d  , c[pos + i].second + 1);       }       printf(  n );       for (int i = 0; i < dk; ++i) {         printf( %d  , c[pos + k + i].second + 1);       }       printf(  n );     } else {       printf( Yes n );       printf( %d %d n , dk, k);       for (int i = 0; i < dk; ++i) {         printf( %d  , c[pos + k + i].second + 1);       }       printf(  n );       for (int i = 0; i < k; ++i) {         printf( %d  , c[pos + i].second + 1);       }       printf(  n );     }     return true;   }   int main() {     scanf( %d%d%d , &n, &x[0], &x[1]);     for (int i = 0; i < n; ++i) {       scanf( %d , &c[i].first);       c[i].second = i;     }     sort(c, c + n);     for (int i = 0; i < n; ++i) {       if (check(i, 0, 1) || check(i, 1, 0)) {         return 0;       }     }     printf( No n );     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long x2, y2;   long long euler(long long a, long long b) {     if (b == 0) {       x2 = 1;       y2 = 0;       return a;     } else {       long long res = euler(b, a % b);       long long temp = x2;       x2 = y2;       y2 = temp - (a / b) * y2;       return res;     }   }   int main() {     int T;     long long x, y, m, n, vx, vy;     long long k1, k2;     long long res, res1, res2, xx, yy;     cin >> n >> m >> x >> y >> vx >> vy;     if (!vx) {       if ((!x) || (x == n)) {         cout << x <<     << (vy > 0 ? m : 0) << endl;       } else         cout <<  -1  << endl;       return 0;     }     if (!vy) {       if ((!y) || (y == m)) {         cout << (vx > 0 ? n : 0) <<     << y << endl;       } else         cout <<  -1  << endl;       return 0;     }     k1 = (vx == 1 ? ((n - x) % n) : (x % n));     k2 = (vy == 1 ? ((m - y) % m) : (y % m));     long long g = euler(n, m);     if (abs(k1 - k2) % g) {       cout <<  -1  << endl;       return 0;     }     long long lcm = m * n / g;     res1 = (k2 * x2) % m;     res1 = res1 * (n / g);     res2 = (k1 * y2) % n;     res2 = res2 * (m / g);     res = (res1 + res2) % lcm;     res = (res + lcm) % lcm;     xx = x + res * vx;     yy = y + res * vy;     cout << ((xx % (2 * n)) + 2 * n) % (2 * n) <<              << ((yy % (2 * m)) + 2 * m) % (2 * m) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MAX = 1e5 + 5;   int n, s, h, m;   vector<pair<int, int> > a;   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     cin >> n >> s;     for (int i = 0; i < n; i++) {       cin >> h >> m;       a.push_back(make_pair(h, m));     }     bool done = false;     if (a[0].first * 60 + a[0].second >= s + 1)       cout <<  0 0 ;     else {       for (int i = 0; i < n - 1; i++) {         int gap =             (a[i + 1].first - a[i].first) * 60 + (a[i + 1].second - a[i].second);         if (gap >= 2 * (s + 1)) {           done = true;           if (a[i].second + s + 1 >= 60) {             int mins = s + 1 - (60 - a[i].second);             if (mins == 60)               cout << a[i].first + 2 <<   0 ;             else               cout << a[i].first + 1 <<     << mins;           } else             cout << a[i].first <<     << a[i].second + s + 1;           break;         }       }       if (!done) {         if (a[n - 1].second + s + 1 >= 60) {           int mins = s + 1 - (60 - a[n - 1].second);           if (mins == 60)             cout << a[n - 1].first + 2 <<   0 ;           else             cout << a[n - 1].first + 1 <<     << mins;         } else           cout << a[n - 1].first <<     << a[n - 1].second + s + 1;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   template <class T>   using vec = std::vector<T>;   bool __hack = std::ios::sync_with_stdio(false);   auto __hack1 = cin.tie(nullptr);   struct Input {     Input(istream &in) : in(&in) {}     template <class T>     T next() const {       T x;       *in >> x;       return x;     }     int ni() const { return next<int>(); }     istream *in;   };   Input in(cin);   class Output {    private:     ostream *out;     template <typename T>     void printSingle(const T &value) {       *out << value;     }       public:     Output(ostream &out) : out(&out) {}     inline void print() {}     template <typename T, typename... Ts>     inline void print(const T &f, const Ts &...args) {       printSingle(f);       if (sizeof...(args) != 0) {         *out <<    ;         print(args...);       }     }     template <typename... Ts>     inline void println(const Ts &...args) {       print(args...);       *out <<   n ;     }     template <typename... Ts>     inline void operator()(const Ts &...args) {       println(args...);     }     template <typename T>     ostream &operator<<(const T &x) {       *out << x;       return *out;     }   };   Output out(cout);   namespace template_util {   constexpr int bytecount(uint64_t x) { return x ? 1 + bytecount(x >> 8) : 0; }   template <int N>   struct bytetype {};   template <uint64_t N>   struct minimal_uint : bytetype<bytecount(N)> {};   }  // namespace template_util   void solveOne() {     auto n = in.ni();     auto m = in.ni();     vec<pair<int, int>> edges(m);     for (int i = 0; i < (m); ++i) {       auto x = in.ni() - 1;       auto y = in.ni() - 1;       if (x > y) swap(x, y);       edges[i] = {x, y};     }     vec<int> used(3 * n, 0);     vec<int> takenEdges;     for (int i = 0; i < (m); ++i) {       if (!used[edges[i].first] && !used[edges[i].second]) {         takenEdges.push_back(i);         used[edges[i].first] = true;         used[edges[i].second] = true;       }       if (takenEdges.size() == n) {         out( Matching );         for (const auto &e : takenEdges) {           out << e + 1 <<    ;         }         out();         return;       }     }     out( IndSet );     int cnt = 0;     for (int i = 0; i < (3 * n); ++i) {       if (!used[i]) {         out << i + 1 <<    ;         ++cnt;       }       if (cnt == n) break;     }     out();   }   void solve(istream &inStream, ostream &outStream) {     in = Input(inStream);     out = Output(outStream);     auto tests = in.ni();     while (tests--) {       solveOne();     }   }   int main() {     solve(cin, cout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m, x;     cin >> n >> m >> x;     x--;     if (n > m) {       cout << 0 << endl;       return 0;     }     vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, 0));     dp[0][0] = 1;     for (int i = 0; i < m; i++) {       vector<vector<long long>> ndp(n + 1, vector<long long>(n + 1, 0));       for (int j = 0; j <= n; j++)         for (int k = 0; j + k <= n; k++) {           if (i != x) (ndp[j][k] += dp[j][k]) %= mod;           if (j + k + 1 <= n) (ndp[j + 1][k] += dp[j][k]) %= mod;           if (i != x && j) (ndp[j - 1][k + 1] += dp[j][k]) %= mod;           if (j + k + 1 <= n) (ndp[j][k + 1] += dp[j][k]) %= mod;         }       swap(dp, ndp);     }     long long ans = dp[0][n];     for (int i = 1; i <= n; i++) (ans *= i) %= mod;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int s;   struct DSU {     int p[505];     void init() {       for (int i = 1; i <= n; i++) p[i] = i;     }     int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }     int count() {       int count = 0;       for (int i = 1; i <= n; i++)         if (p[i] == i) count++;       return count;     }     void link(int a, int b) { p[find(a)] = find(b); }   } L[10050], R[10050];   DSU hebing(DSU L, DSU R) {     DSU a = L;     for (int i = 1; i <= n; i++) a.link(i, R.find(i));     return a;   }   int l[10050], r[10050];   int main() {     cin >> n >> m;     L[0].init();     for (int i = 1; i <= m; i++) {       cin >> l[i];       cin >> r[i];       L[i] = L[i - 1];       L[i].link(l[i], r[i]);     }     R[m + 1].init();     for (int i = m; i >= 1; i--) {       R[i] = R[i + 1];       R[i].link(l[i], r[i]);     }     cin >> k;     while (k--) {       int x1, y1;       cin >> x1 >> y1;       DSU h = hebing(L[x1 - 1], R[y1 + 1]);       cout << h.count() << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     map<int, int, greater<int>> input;     map<int, int, greater<int>> output;     map<int, int, greater<int>> input_reverse;     map<int, int, greater<int>> output_reverse;     int N;     scanf( %d , &N);     ;     int i = N;     int index = 1;     while (i--) {       int x;       scanf( %d , &x);       input[index] = x;       input_reverse[x] = index++;     }     index = 1;     while (N--) {       int x;       scanf( %d , &x);       output[index] = x;       output_reverse[x] = index++;     }     map<int, int, greater<int>>::iterator it1;     int val = 0;     int count_val = 0;     it1 = input.begin();     while (!input.empty()) {       int x = (*it1).second;       if (x != (*(output.begin())).second) {         val = val + count_val + 1;         count_val = 0;       } else {         count_val++;       }       it1++;       input.erase((*(input_reverse.find(x))).second);       output.erase((*(output_reverse.find(x))).second);     }     printf( %d n , val);   }


#include <bits/stdc++.h>   namespace FastIO {   bool IOerror = 0;   inline char nc() {     static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;     if (p1 == pend) {       p1 = buf;       pend = buf + fread(buf, 1, 100000, stdin);       if (pend == p1) {         IOerror = 1;         return -1;       }     }     return *p1++;   }   inline bool blank(char ch) {     return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;   }   template <class T>   inline bool read(T &x) {     bool sign = 0;     char ch = nc();     x = 0;     for (; blank(ch); ch = nc())       ;     if (IOerror) return false;     if (ch ==  - ) sign = 1, ch = nc();     for (; ch >=  0  && ch <=  9 ; ch = nc()) x = x * 10 + ch -  0 ;     if (sign) x = -x;     return true;   }   template <class T, class... U>   bool read(T &h, U &...t) {     return read(h) && read(t...);   }   };  // namespace FastIO   using namespace std;   using namespace FastIO;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int INF = 0x3f3f3f3f;   const int N = 1e5 + 10;   struct node {     int l, r, sum;     bitset<1010> f;   } tree[N * 15];   int root[N], cnt;   int n, m, q;   bitset<1010> base;   void ins(int &x, int pre, int l, int r, int i, int j, int op) {     x = ++cnt;     tree[x] = tree[pre];     if (l == r) {       if (op == 1) tree[x].f.set(j);       if (op == 2) tree[x].f.reset(j);       if (op == 3) tree[x].f ^= base;       tree[x].sum = tree[x].f.count();       return;     }     int mid = (l + r) / 2;     if (i <= mid)       ins(tree[x].l, tree[pre].l, l, mid, i, j, op);     else       ins(tree[x].r, tree[pre].r, mid + 1, r, i, j, op);     tree[x].sum = tree[tree[x].l].sum + tree[tree[x].r].sum;     return;   }   signed main() {     read(n, m, q);     for (int i = 1; i <= m; i++) base.set(i);     for (int i = 1; i <= q; i++) {       int op, x, y;       read(op);       if (op <= 2) {         read(x, y);         ins(root[i], root[i - 1], 1, n, x, y, op);       }       if (op == 3) {         read(x);         ins(root[i], root[i - 1], 1, n, x, 0, op);       }       if (op == 4) {         read(x);         root[i] = root[x];       }       printf( %d n , tree[root[i]].sum);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long L[100005];   long long P[100005][40];   long long T[100005];   vector<long long> graph[100005];   long long mx = 0, hh;   void dfs(long long src, long long par) {     if (src == -1)       L[par] = 0;     else       L[par] = L[src] + 1;     if (mx < L[par]) {       hh = par;       mx = max(mx, L[par]);     }     T[par] = src;     long long len = graph[par].size();     for (long long i = 0; i < (long long)graph[par].size(); i++) {       long long v = graph[par][i];       if (v != src) {         dfs(par, v);       }     }   }   void dfs1(long long src, long long par) {     if (src == -1)       L[par] = 0;     else       L[par] = L[src] + 1;     if (mx < L[par]) {       hh = par;       mx = max(mx, L[par]);     }     long long len = graph[par].size();     for (long long i = 0; i < (long long)graph[par].size(); i++) {       long long v = graph[par][i];       if (v != src) {         dfs1(par, v);       }     }   }   int main() {     long long i, j, n, m, t, a, b, c, d, e, f, x, y;     scanf( %lld , &t);     for (long long cz = 0; cz < t; cz++) {       scanf( %lld%lld%lld%lld%lld , &n, &a, &b, &c, &d);       for (i = 0; i < n - 1; i++) {         scanf( %lld%lld , &x, &y);         graph[x].push_back(y);         graph[y].push_back(x);       }       mx = 0;       dfs(-1, a);       long long cc, dd;       cc = L[b];       for (i = 0; i <= n; i++) {         L[i] = 0;       }       mx = 0;       dfs1(-1, hh);       if (c * 2 >= min(d, mx) || cc <= c) {         printf( Alice n );       } else         printf( Bob n );       for (i = 0; i <= n; i++) {         graph[i].clear();         L[i] = 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   int size(T &a) {     return (int)a.size();   }   template <typename T>   T sqr(T a) {     return a * a;   }   const int INF = int(1e9);   struct pt {     int cnt;     long long sumr;     long long suml;     long long f;     int pr;     int x;     int lefm;     int rim;     pt *L, *R;   };   const int MAXN = int(1e5);   pt buf[MAXN * 2];   int sz = 0;   pt *init(int x) {     buf[sz].cnt = 1;     buf[sz].L = buf[sz].R = NULL;     buf[sz].x = x;     buf[sz].pr = (rand() << 20) + rand();     buf[sz].suml = 0;     buf[sz].sumr = 0;     buf[sz].f = 0;     buf[sz].lefm = buf[sz].rim = x;     return &buf[sz++];   }   int getcnt(pt *p) { return p == NULL ? 0 : p->cnt; }   int getlefm(pt *p) { return p == NULL ? 2 * INF : p->lefm; }   int getrim(pt *p) { return p == NULL ? -2 * INF : p->rim; }   long long getf(pt *p) { return p == NULL ? 0 : p->f; }   long long getsuml(pt *p) { return p == NULL ? 0 : p->suml; }   long long getsumr(pt *p) { return p == NULL ? 0 : p->sumr; }   void update(pt *&p) {     if (p == NULL) return;     p->cnt = getcnt(p->L) + getcnt(p->R) + 1;     p->lefm = min(getlefm(p->L), p->x);     p->rim = max(getrim(p->R), p->x);     int n1 = getcnt(p->L);     int n2 = getcnt(p->R);     p->f = getf(p->L) + getf(p->R);     p->f += getsumr(p->L) + (long long)n1 * (p->x - getrim(p->L));     p->f += getsuml(p->R) + (long long)n2 * (getlefm(p->R) - p->x);     p->f += (long long)n1 * n2 * ((p->x - getrim(p->L)) + (getlefm(p->R) - p->x));     p->f += getsumr(p->L) * n2 + getsuml(p->R) * n1;     p->suml = getsuml(p->L) + (p->x - p->lefm) + getsuml(p->R) +               (long long)(n2 ? (getlefm(p->R) - p->lefm) : 0) * n2;     p->sumr = getsumr(p->R) + (p->rim - p->x) + getsumr(p->L) +               (long long)(n1 ? (p->rim - getrim(p->L)) : 0) * n1;   }   void merge(pt *a, pt *b, pt *&p) {     if (a == NULL) {       p = b;     } else if (b == NULL) {       p = a;     } else if (a->pr < b->pr) {       merge(a, b->L, b->L);       p = b;       update(p);     } else {       merge(a->R, b, a->R);       p = a;       update(p);     }   }   void split(pt *t, pt *&a, pt *&b, int by) {     if (t == NULL) {       a = b = NULL;     } else {       if (t->x <= by) {         split(t->R, t->R, b, by);         a = t;         update(a);       } else {         split(t->L, a, t->L, by);         b = t;         update(b);       }     }   }   int curx[MAXN];   void remove(pt *&t, int x) {     pt *p, *q;     pt *a, *b;     split(t, p, q, x);     split(p, a, b, x - 1);     merge(a, q, t);   }   void insert(pt *&t, pt *i) {     pt *p, *q;     split(t, p, q, i->x);     merge(p, i, t);     merge(t, q, t);   }   long long query(pt *&t, int l, int r) {     pt *p, *q, *a, *b;     split(t, p, q, r);     split(p, a, b, l - 1);     long long res = getf(b);     merge(a, b, t);     merge(t, q, t);     return res;   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int i = (0); i < (n); ++i) cin >> curx[i];     pt *root = NULL;     for (int i = (0); i < (n); ++i) {       insert(root, init(curx[i]));     }     int q;     cin >> q;     for (int iter = (0); iter < (q); ++iter) {       int t;       cin >> t;       if (t == 1) {         int p, d;         cin >> p >> d;         --p;         remove(root, curx[p]);         curx[p] += d;         insert(root, init(curx[p]));       } else {         int l, r;         cin >> l >> r;         cout << query(root, l, r) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 200001;   int main() {     long long n, k, d;     scanf( %lld%lld%lld , &n, &k, &d);     if (d < k) return puts( NO ), 0;     long long dv = d / k;     if (dv + 1 > n || (dv + (d % k == 0 ? 0 : 2)) > n) return puts( NO ), 0;     vector<long long> an;     puts( YES );     if (d % k == 0) {       for (int j = 0; j < k; ++j) {         if (j & 1)           printf( 1  );         else           printf( %lld  , 1ll + dv);       }       return 0;     }     long long lst = 1;     for (int j = 0; j < (d % k); ++j) {       if (j & 1)         printf( 1  ), lst = 1ll;       else         printf( %lld  , 2ll + dv), lst = 2ll + dv;     }     for (int j = 0; j < k - (d % k); ++j) {       if (j & 1)         printf( %lld  , lst);       else         printf( %lld  , lst - dv >= 1 ? lst - dv : lst + dv);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int s, x;     cin >> s >> x;     long long int i, c = 1, f = 0;     long long int a = (s - x) / 2;     if ((s - x) % 2 != 0)       cout << 0;     else {       for (i = 0; i < 64; i++) {         long long int x1 = ((x >> i) & 1);         long long int a1 = ((a >> i) & 1);         if (x1 == 0 && a1 == 1) f = 1;         if (x1 == 1 && a1 == 0) c = c * 2;         if (x1 == 1 && a1 == 1) {           f = 1;           c = 0;         }       }       if (f == 1)         cout << c;       else         cout << (c - 2);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, t, n, m, a[105], ans[105] = {0};     cin >> n >> m;     for (__typeof(0) i = 0; i <= m - 1; i++) cin >> a[i];     for (__typeof(0) i = 0; i <= m - 1; i++) {       int tem = a[i];       for (int j = tem; j <= n; j++) {         if (ans[j] == 0) ans[j] = a[i];       }     }     for (__typeof(1) i = 1; i <= n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 100000 + 10;   long long n, arr[MX];   struct node {     long long bit_[3];     node() { memset(bit_, 0, sizeof(bit_)); }   };   vector<node> tree;   void add(long long inode, long long ptr, long long num) {     if (ptr < 0) return;     long long q = (num >> ptr) & 1;     if (tree[inode].bit_[q] == 0) {       tree.push_back(node());       tree[inode].bit_[q] = (int)tree.size() - 1;     }     add(tree[inode].bit_[q], ptr - 1, num);   }   long long find_fit(long long x) {     int ptr = 45;     long long nd = 0;     long long sol = 0;     while (ptr >= 0) {       sol *= 2;       long long q = !((x >> ptr) & 1);       if (q == 1) {         if (tree[nd].bit_[1] != 0) {           nd = tree[nd].bit_[1];           sol++;         } else           nd = tree[nd].bit_[0];       } else {         if (tree[nd].bit_[0] != 0)           nd = tree[nd].bit_[0];         else {           nd = tree[nd].bit_[1];           sol++;         }       }       ptr--;     }     return sol;   }   int main() {     tree.push_back(node());     cin >> n;     long long q = 0;     add(0, 45, 0);     for (int i = 0; i < n; i++) {       cin >> arr[i];       q ^= arr[i];       add(0, 45, q);     }     q = 0;     long long ans = 0;     for (int i = n - 1; i >= 0; i--) {       q ^= arr[i];       long long p = find_fit(q);       ans = max(ans, p ^ q);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long y, z;     long long x;     int choice;   };   node g[2000001];   int cmp(node head, node a) {     if (head.y != a.y) return head.y < a.y;     if (head.z != a.z) return head.z < a.z;     return head.x > a.x;   }   struct info {     int choice;     long long x;   } f[2000001];   int m, n;   int has = 0;   struct self {     int x, y, z;   } s[33];   long long ans;   int choicex, choicey;   int ipow(int i, int k) {     if (k == 0) return 1;     return i * ipow(i, k - 1);   }   int bs(long long y, long long z) {     int l = 1, r = has, mid, ret = 0;     while (l <= r) {       mid = (l + r) >> 1;       if (g[mid].y > y || (g[mid].y == y && g[mid].z >= z)) {         ret = mid;         r = mid - 1;       } else         l = mid + 1;     }     if (g[ret].y == y && g[ret].z == z)       return ret;     else       return 0;   }   void rep(int i, int u) {     if (i == 1) {       int t = u % 3;       if (t == 0) printf( LM n );       if (t == 1) printf( LW n );       if (t == 2) printf( MW n );       return;     }     rep(i - 1, u / 3);     int t = u % 3;     if (t == 0) printf( LM n );     if (t == 1) printf( LW n );     if (t == 2) printf( MW n );   }   void p(int i, int u) {     while (i <= m) {       int t = u % 3;       u /= 3;       i++;       if (t == 0) printf( LM n );       if (t == 1) printf( LW n );       if (t == 2) printf( MW n );     }   }   void print(int l, int r) {     rep(n, l);     p(n + 1, r);   }   int main() {     ans = -1e14;     scanf( %d , &m);     for (int i = 1; i <= m; i++) scanf( %d%d%d , &s[i].x, &s[i].y, &s[i].z);     if (m % 2 == 0)       n = m / 2;     else       n = m / 2 + 1;     for (int i = 0; i < ipow(3, n); i++) {       int v = i;       long long x = 0, y = 0, z = 0;       for (int j = n; j >= 1; j--) {         int k = v % 3, li = j;         long long a = x, b = y;         if (k == 0) {           x += s[li].x;           y += s[li].y;         }         if (k == 1) {           x += s[li].x;           z += s[li].z;         }         if (k == 2) {           y += s[li].y;           z += s[li].z;         }         v /= 3;       }       y -= x;       z -= x;       has++;       g[has].x = x;       g[has].y = y;       g[has].z = z;       g[has].choice = i;     }     sort(g + 1, g + has + 1, cmp);     for (int i = 0; i < ipow(3, m - n); i++) {       int v = i;       long long x = 0, y = 0, z = 0;       for (int j = n + 1; j <= m; j++) {         int k = v % 3, li = j;         if (k == 0) {           x += s[li].x;           y += s[li].y;         }         if (k == 1) {           x += s[li].x;           z += s[li].z;         }         if (k == 2) {           y += s[li].y;           z += s[li].z;         }         v /= 3;       }       y -= x;       z -= x;       int pos = bs(-y, -z);       if (pos != 0)         if (g[pos].x + x > ans) {           ans = g[pos].x + x;           choicex = g[pos].choice;           choicey = i;         }     }     if (ans != -1e14)       print(choicex, choicey);     else       printf( Impossible n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int test;     cin >> test;     while (test--) {       int n, m;       cin >> n >> m;       string S;       cin >> S;       vector<int> P(m);       vector<int> cnt(n);       for (int i = 0; i < m; i++) {         cin >> P[i];         cnt[0]++;         cnt[P[i]]--;       }       vector<int> res(26);       for (int i = 0; i < n; i++) res[S[i] -  a ]++;       res[S[0] -  a ] += cnt[0];       for (int i = 1; i < n; i++) {         cnt[i] += cnt[i - 1];         res[S[i] -  a ] += cnt[i];       }       for (int i = 0; i < 26; i++) cout << res[i] <<     << flush;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   struct node {     long long x, s[8];     int id;   } a[N];   int n, p, t;   long long f[N][(1 << 8) + 5];   bool cmp(node a, node b) { return a.x > b.x; }   int main() {     scanf( %d%d%d , &n, &p, &t);     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i].x);       a[i].id = i;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= p; j++) scanf( %lld , &a[i].s[j]);     sort(a + 1, a + n + 1, cmp);     memset(f, -1, sizeof(f));     f[0][0] = 0;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < (1 << p); j++) {         f[i][j] = f[i - 1][j];         int sum = 0;         for (int k = 0; k < p; k++)           if (j & (1 << k)) sum++;         int tmp = i - 1 - sum;         if (tmp < t && f[i - 1][j] != -1) f[i][j] += a[i].x;         for (int k = 0; k < p; k++) {           if (((j & (1 << k))) && f[i - 1][j ^ (1 << k)] != -1)             f[i][j] = max(f[i][j], f[i - 1][j ^ (1 << k)] + a[i].s[k + 1]);         }       }     }     printf( %lld , f[n][(1 << p) - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fLL;   long long N, L, v1, v2, k;   long long d;   pair<double, double> get_it(double mid) {     double end = mid * v2;     double pass = mid;     for (int i = 1; i < d; i++) {       double add = (end - pass * v1) / (v2 + v1);       end = (pass + add) * v1 + mid * v2;       pass += add + mid;     }     return {pass, end};   }   bool check(double mid) { return (get_it(mid).second >= L); }   void test_case() {     cin >> N >> L >> v1 >> v2 >> k;     d = (N + k - 1) / k;     double l = 0, r = INF;     for (int i = 0; i < 100; i++) {       double m = l + (r - l) / 2;       if (check(m))         r = m;       else         l = m;     }     cout << fixed << setprecision(10);     cout << get_it(l).first <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int tt = 1;     while (tt--) {       test_case();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cd(int a, int b) { return a - a / b; }   int main() {     int cnt1, cnt2, x, y;     cin >> cnt1 >> cnt2 >> x >> y;     long long int l = 1, r = 1000000000009;     while (l < r) {       int mid = l + (r - l) / 2;       if (cnt1 <= cd(mid, x) && cnt2 <= cd(mid, y) &&           cnt1 + cnt2 <= cd(mid, x * y))         r = mid;       else         l = mid + 1;     }     cout << r;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll inf = 1e18;   template <typename T>   void printvector(const vector<T>& foo) {     for (auto el : foo) cout << el <<    ;     cout << endl;   }   bool calc(vector<int>& permuration, const vector<vector<int>>& sets,             vector<bool>& used) {     if (permuration.size() == sets.size() + 1) {       for (auto el : permuration) cout << el <<    ;       cout <<   n ;       return true;     }     if (permuration.empty()) {       for (int i = 0; i < sets.size(); i++) {         permuration.push_back(sets[i][0]);         permuration.push_back(sets[i][1]);         used[i] = true;         if (calc(permuration, sets, used)) return true;         swap(permuration[0], permuration[1]);         if (calc(permuration, sets, used)) return true;         used[i] = false;         permuration.pop_back();         permuration.pop_back();       }     }     vector<int> last_elements;     for (size_t next = 0; next < sets.size(); next++) {       if (used[next]) continue;       const auto& row = sets[next];       if (row.size() > permuration.size() + 1) break;       while (last_elements.size() < row.size() - 1) {         last_elements.push_back(             permuration[permuration.size() - last_elements.size() - 1]);       }       sort(last_elements.begin(), last_elements.end());       vector<int> diff;       set_difference(row.begin(), row.end(), last_elements.begin(),                      last_elements.end(), back_inserter(diff));       if (diff.size() > 1) continue;       used[next] = true;       permuration.push_back(diff[0]);       if (calc(permuration, sets, used)) return true;       used[next] = false;       permuration.pop_back();       return false;     }     return false;   }   int main() {     int test;     cin >> test;     while (test--) {       int n;       cin >> n;       vector<vector<int>> sets(n - 1);       for (auto& row : sets) {         int k;         cin >> k;         row.resize(k);         for (auto& el : row) cin >> el;       }       sort(sets.begin(), sets.end(),            [](const vector<int>& a, const vector<int>& b) {              return a.size() < b.size();            });       vector<int> permutation;       vector<bool> used(n, false);       calc(permutation, sets, used);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 110000;   int len, k, n;   long long a[N];   long long resolve() {     int pK = k;     set<pair<long long, int>> av;     set<pair<long long, int>> changed;     long long sumP = 0;     for (int i = 0; i < len; i++) {       av.insert({a[i], i});       sumP += a[i];     }     while (true) {       if (!av.size()) break;       auto lowest = *av.begin();       if (lowest.first >= 0) break;       if (pK == 0) break;       av.erase(av.begin());       changed.insert({-lowest.first, lowest.second});       sumP -= lowest.first;       sumP += (-lowest.first);       pK--;     }     long long best = sumP;     for (int i = 1; i <= n - len; i++) {       if (av.count({a[i - 1], i - 1})) {         av.erase(av.find({a[i - 1], i - 1}));         sumP -= a[i - 1];       } else {         changed.erase(changed.find({-a[i - 1], i - 1}));         sumP -= (-a[i - 1]);         pK++;       }       int j = i + len - 1;       av.insert({a[j], j});       sumP += a[j];       while (pK > 0) {         if (av.size()) {           auto x = *av.begin();           if (x.first < 0) {             av.erase(av.begin());             changed.insert({-x.first, x.second});             sumP -= x.first;             sumP += (-x.first);             pK--;           } else             break;         } else           break;       }       while (pK == 0) {         if (!av.size() || !changed.size()) break;         auto x = *av.begin();         auto y = *changed.begin();         if (x.first > 0) break;         if (x.first * -1 > y.first) {           changed.erase(changed.begin());           av.erase(av.begin());           changed.insert({x.first * -1, x.second});           av.insert({y.first * -1, y.second});           sumP -= y.first;           sumP += (-y.first);           sumP -= x.first;           sumP += (-x.first);         } else           break;       }       best = max(best, sumP);     }     return best;   }   int main() {     scanf( %d %d , &n, &len);     for (int i = 0; i < n; i++) scanf( %lld , a + i);     scanf( %d , &k);     long long ans = resolve();     for (int i = 0; i < n; i++) a[i] *= -1;     ans = max(ans, resolve());     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, k, l, c, d, p, nl, np;     cin >> n >> k >> l >> c >> d >> p >> nl >> np;     long long totlime = c * d;     long long totdrink = k * l;     totdrink = totdrink / nl;     long long totsalt = p / np;     long long mn = min(totlime, totdrink);     mn = min(mn, totsalt);     cout << mn / n <<   n ;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, ans, v[1009], m, c[1009];   vector<int> e;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> v[i];     for (int i = 2; i <= n; i++) {       if (v[i] == 0 and v[i - 1] == 1 and v[i + 1] == 1) c[++m] = i + 1;     }     ans = m;     for (int i = 1; i < m; i++) {       if (c[i] + 2 == c[i + 1]) {         ans--;         c[i] = -1e9, c[i + 1] - 1e9;         i++;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n, ys, ans;   int main() {     cin >> n;     ys = 0;     ans = 0;     for (int i = n; i > 0; i /= 8) {       ys = i % 8;       if (ys == 1) ans++;     }     cout << ans << endl;     return 0;   }