#include <bits/stdc++.h>   using namespace std;   const int dx[8] = {-2, -2, -1, -1, 1, 1, 2, 2};   const int dy[8] = {-1, 1, -2, 2, -2, 2, -1, 1};   int n, m;   int xw, yw, xb, yb;   int xtw, ytw, xtb, ytb;   deque<pair<int, int>> ww, wb, bw, bb;   int dist[1000][1000], parx[1000][1000], pary[1000][1000];   int crap;   void shortestWay(int sx, int sy, int tx, int ty, deque<pair<int, int>> &res) {     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) dist[i][j] = -1;     dist[sx][sy] = 0;     queue<pair<int, int>> q;     q.push({sx, sy});     while (!q.empty()) {       int x = q.front().first, y = q.front().second;       q.pop();       if (x == tx && y == ty) break;       for (int i = 0; i < 8; ++i) {         int xx = x + dx[i], yy = y + dy[i];         if (xx < 0 || yy < 0 || xx >= n || yy >= m) continue;         if (dist[xx][yy] == -1) {           dist[xx][yy] = dist[x][y] + 1;           parx[xx][yy] = x, pary[xx][yy] = y;           q.push({xx, yy});         }       }     }     int cx = tx, cy = ty;     while (cx != sx || cy != sy) {       res.push_front({cx, cy});       int ccx = parx[cx][cy];       cy = pary[cx][cy];       cx = ccx;     }   }   void normal(deque<pair<int, int>> &way, int ox, int oy) {     for (int i = 0; i < way.size(); ++i) {       cout << way[i].first + 1 <<     << way[i].second + 1 <<   n  << flush;       if (way[i].first == ox && way[i].second == oy) exit(0);       if (i < way.size() - 1) {         cin >> ox >> oy;         ox--;         oy--;       }     }   }   void normalWhite() {     cout <<  WHITE n  << flush;     normal(ww, xb, yb);   }   void normalBlack() {     cout <<  BLACK n  << flush;     cin >> xw >> yw;     xw--;     yw--;     normal(bb, xw, yw);   }   void advanced(deque<pair<int, int>> &way, int x, int y, int tx, int ty, int ox,                 int oy) {     if (way.size() > 0) {       normal(way, ox, oy);       cin >> ox >> oy;       ox--;       oy--;       x = way.back().first, y = way.back().second;     }     for (int i = 0; i < 8; ++i) {       int xx = x + dx[i], yy = y + dy[i];       if (xx == ox && yy == oy) {         cout << xx + 1 <<     << yy + 1 <<   n  << flush;         exit(0);       }     }     deque<pair<int, int>> d;     if (tx > x) {       d.push_back({x + 1, y + 2});       d.push_back({x + 3, y + 1});       d.push_back({x + 1, y});     } else {       d.push_back({x - 1, y + 2});       d.push_back({x - 3, y + 1});       d.push_back({x - 1, y});     }     normal(d, ox, oy);   }   void advancedWhite() {     cout <<  WHITE n  << flush;     advanced(wb, xw, yw, xtw, ytw, xb, yb);   }   void advancedBlack() {     cout <<  BLACK n  << flush;     cin >> xw >> yw;     xw--;     yw--;     advanced(bw, xb, yb, xtb, ytb, xw, yw);   }   int main() {     cin >> n >> m >> xw >> yw >> xb >> yb;     xw--;     yw--;     xb--;     yb--;     xtw = n / 2 - 1;     ytw = m / 2 - 1;     xtb = n / 2;     ytb = m / 2 - 1;     shortestWay(xw, yw, xtw, ytw, ww);     shortestWay(xw, yw, xtb, ytb, wb);     shortestWay(xb, yb, xtw, ytw, bw);     shortestWay(xb, yb, xtb, ytb, bb);     if ((xw + yw) % 2 != (xb + yb) % 2) {       if (ww.size() <= bb.size())         normalWhite();       else if (wb.size() >= bb.size() + 2)         normalBlack();       else         advancedWhite();     } else {       if (bb.size() < ww.size())         normalBlack();       else if (bw.size() > ww.size())         normalWhite();       else         advancedBlack();     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class U>   void ckmin(T &a, U b) {     if (a > b) a = b;   }   template <class T, class U>   void ckmax(T &a, U b) {     if (a < b) a = b;   }   int N, M;   bitset<1013> grid[1013];   int dn[1013][1013], rt[1013][1013];   int upd[1013][1013];   int x = -1, y = -1;   int ans = 998244353;   void check(int sx, int sy) {     for (auto i = (0); i < (N + 1); i++) {       for (auto j = (0); j < (M + 1); j++) {         upd[i][j] = 0;       }     }     int cx = x, cy = y;     while (true) {       upd[cx][cy]++;       upd[cx + sx][cy]--;       upd[cx][cy + sy]--;       upd[cx + sx][cy + sy]++;       if (grid[cx + sx][cy]) {         cx++;         continue;       }       if (grid[cx][cy + sy]) {         cy++;         continue;       }       break;     }     for (auto i = (0); i < (N); i++) {       for (auto j = (0); j < (M); j++) {         if (i) upd[i][j] += upd[i - 1][j];         if (j) upd[i][j] += upd[i][j - 1];         if (i && j) upd[i][j] -= upd[i - 1][j - 1];         if (upd[i][j] && !grid[i][j]) return;         if (!upd[i][j] && grid[i][j]) return;       }     }     ckmin(ans, sx * sy);   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> N >> M;     for (auto i = (0); i < (N); i++) {       string temps;       cin >> temps;       for (auto j = (0); j < (M); j++) {         grid[i][j] = (temps[j] ==  X );       }     }     for (auto i = (N)-1; i >= (0); i--) {       for (auto j = (M)-1; j >= (0); j--) {         if (grid[i][j]) {           x = i;           y = j;         }       }     }     for (auto i = (0); i < (N); i++) {       for (auto j = (0); j < (y); j++) {         if (grid[i][j]) {           cout <<  -1 n ;           return 0;         }       }     }     for (auto i = (0); i < (N); i++) {       for (auto j = (M)-1; j >= (0); j--) {         rt[i][j] = (grid[i][j] ? 1 + rt[i][j + 1] : 0);       }     }     for (auto i = (0); i < (M); i++) {       for (auto j = (N)-1; j >= (0); j--) {         dn[j][i] = (grid[j][i] ? 1 + dn[j + 1][i] : 0);       }     }     int dy = rt[x][y], dx = dn[x][y];     for (auto i = (x); i < (x + dx); i++) {       for (auto j = (y); j < (y + dy); j++) {         if (!grid[i][j]) {           cout <<  -1 n ;           return 0;         }       }     }     check(dx, dy);     check(dx, 1);     check(1, dy);     for (auto i = (0); i < (dy); i++) {       if (grid[x + dx][y + i]) {         check(dx, dy - i);         break;       }     }     for (auto i = (0); i < (dx); i++) {       if (grid[x + i][y + dy]) {         check(dx - i, dy);         break;       }     }     if (ans == 998244353) {       cout <<  -1 n ;       return 0;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 7;   const int sz = 10;   map<int, int> mp[11];   int n, k;   unsigned long long a[maxn], ans;   unsigned long long fac[13];   int main() {     fac[0] = 1;     for (int i = 1; i <= 10; i++) fac[i] = 10LL * fac[i - 1];     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %llu , &a[i]);       for (int j = 1; j <= 10; j++) {         int now = (a[i] * fac[j]) % k;         mp[j][now]++;       }     }     for (int i = 1; i <= n; i++) {       int len = 0;       unsigned long long now = a[i];       while (now) {         now /= 10;         len++;       }       int res = a[i] % k;       int p = 0;       if (res == 0) {         int need = 0;         if ((a[i] * fac[len]) % k == need) {           ans += mp[len][need] - 1;         } else {           ans += mp[len][need];         }       } else {         int need = k - res;         if ((a[i] * fac[len]) % k == need) {           ans += mp[len][need] - 1;         } else {           ans += mp[len][need];         }       }     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int mx = 1123;   int limit[26];   const long long mod = 1e9 + 7;   int n;   string s;   struct Node {     int maxstr, minpart;     long long ways;     Node(int maxstr, int minpart, long long ways)         : maxstr(maxstr), minpart(minpart), ways(ways){};     Node() {       ways = -1;       minpart = 1e9;     }   };   Node dp[mx];   Node ways(int on = 0) {     if (on == n) {       return {0, 0, 1};     }     Node &ans = dp[on];     if (ans.ways == -1) {       ans.ways = 0;       int maxsz = 1e9;       for (int i = on; i < n; i++) {         maxsz = min(maxsz, limit[s[i] -  a ]);         if (i - on + 1 <= maxsz) {           auto r = ways(i + 1);           ans.ways += r.ways;           ans.minpart = (i != n - 1) + min(ans.minpart, r.minpart);           ans.maxstr = max(ans.maxstr, max(i - on + 1, r.maxstr));         }       }     }     ans.ways = (ans.ways) % mod;     return ans;   }   int main() {     cin >> n;     cin >> s;     for (int i = 0; i < 26; i++) {       cin >> limit[i];     }     auto ans = ways();     cout << ans.ways << endl;     cout << ans.maxstr << endl;     cout << ans.minpart + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   bool is_prime(int n) {     if (n <= 1) return false;     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   vector<int> gen_primes(int l, int r) {     vector<int> primes;     for (int i = l; i <= r; i++) {       if (is_prime(i)) {         primes.push_back(i);       }     }     return primes;   }   vector<long long> gen_batch(const vector<int>& primes) {     constexpr long long limit = (long long)1e18;     vector<long long> batch;     long long cur = 1;     for (int i = 0; i < primes.size(); i++) {       if (cur <= limit / primes[i]) {         cur *= primes[i];       } else {         batch.push_back(cur);         cur = primes[i];       }     }     if (cur > 1) {       batch.push_back(cur);     }     return batch;   }   vector<long long> get_gcds(const vector<long long>& batch) {     vector<long long> gcds;     for (long long x : batch) {       cout <<  ?   << x << endl;       long long g;       cin >> g;       gcds.push_back(g);     }     return gcds;   }   vector<int> get_candidates(const vector<int>& primes,                              const vector<long long>& gcds) {     vector<int> candidates;     for (long long g : gcds) {       for (int p : primes) {         if (g % p == 0) {           candidates.push_back(p);         }       }     }     return candidates;   }   long long build_one(int c) {     constexpr long long limit = (long long)1e9;     long long cur = 1;     while (cur <= limit / c) cur *= c;     return cur;   }   long long build_two(int c1, int c2) {     long long res1 = build_one(c1);     long long res2 = build_one(c2);     return res1 * res2;   }   void solve() {     auto primes = gen_primes(1, 177);     auto batch = gen_batch(primes);     auto gcds = get_gcds(batch);     auto candidates = get_candidates(primes, gcds);     if (candidates.size() == 0) {       cout <<  ! 1  << endl;       return;     }     vector<pair<int, long long>> divs;     if (candidates.size() == 1) {       long long output = build_one(candidates[0]);       cout <<  ?   << output << endl;       long long g;       cin >> g;       if (candidates[0] == g) {         cout <<  ! 8  << endl;         return;       }       divs.push_back(make_pair(candidates[0], g));     } else {       for (int i = 0; i + 1 < candidates.size(); i += 2) {         long long output = build_two(candidates[i], candidates[i + 1]);         cout <<  ?   << output << endl;         long long g;         cin >> g;         divs.push_back(make_pair(candidates[i], g));         divs.push_back(make_pair(candidates[i + 1], g));       }       if (candidates.size() % 2 == 1) {         long long output = build_one(candidates.back());         cout <<  ?   << output << endl;         long long g;         cin >> g;         divs.push_back(make_pair(candidates.back(), g));       }     }     long long lim = (long long)1e9, res = 1;     for (const pair<int, long long>& d : divs) {       int a = d.first;       long long b = d.second;       long long c = 1;       int tmp = 0;       while (b % a == 0) {         ++tmp;         b /= a;         c *= a;       }       res *= (tmp + 1);       lim /= c;     }     int upto = (int)pow((double)lim, 1.0 / 3);     primes = gen_primes(178, upto);     batch = gen_batch(primes);     gcds = get_gcds(batch);     for (long long g : gcds) {       if (g != 1) {         res *= 2;         break;       }     }     cout <<  !   << 2 * res << endl;   }   int main() {     int tst;     cin >> tst;     while (tst--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void FLASH() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   void SETF() {     cout.ios_base::setf(ios_base::fixed);     cerr.ios_base::setf(ios_base::fixed);   }   void UNSETF() {     cout.ios_base::unsetf(ios_base::fixed);     cerr.ios_base::unsetf(ios_base::fixed);   }   bool sortinrev(const pair<long long int, long long int> &a,                  const pair<long long int, long long int> &b) {     return (a.first > b.first);   }   long long int A[1000000];   long long int B[1000000];   map<int, vector<int> > node;   int main() {     FLASH();     long long int t;     cin >> t;     while (t--) {       string s;       long long int n;       cin >> n >> s;       if (n == 2) {         if (s[0] >= s[1])           cout <<  NO  << endl;         else           cout <<  YES  << endl << 2 << endl << s[0] <<     << s[1] << endl;       } else {         cout <<  YES  << endl;         cout << 2 << endl;         cout << s[0] <<    ;         for (long long int i = 1; i < n; i++) cout << s[i];         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[6];   int m[6];   int w[6];   int h, uh;   int main() {     x[0] = 500;     for (int i = 0; i < 5; i++) {       cin >> m[i];       if (i) x[i] = x[i - 1] + 500;     }     for (int i = 0; i < 5; i++) cin >> w[i];     cin >> h >> uh;     int score = 0;     for (int i = 0; i < 5; i++) {       int bla = 3 * x[i] / 10;       score += max(bla, (x[i] * (250 - m[i])) / 250 - 50 * w[i]);     }     cout << score + 100 * h - 50 * uh << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MM = 1005;   const long long MOD = 1000000007;   int vis[MM][MM] = {0};   int n, m, k;   bool judge(int x, int y) {     if (x - 1 >= 0 && y - 1 >= 0) {       if (vis[x - 1][y - 1] && vis[x - 1][y] && vis[x][y - 1]) return true;     }     if (x - 1 >= 0 && y + 1 < m) {       if (vis[x - 1][y + 1] && vis[x - 1][y] && vis[x][y + 1]) return true;     }     if (x + 1 < n && y - 1 >= 0) {       if (vis[x + 1][y - 1] && vis[x][y - 1] && vis[x + 1][y]) return true;     }     if (x + 1 < n && y + 1 < m) {       if (vis[x + 1][y + 1] && vis[x + 1][y] && vis[x][y + 1]) return true;     }     return false;   }   int main() {     int ans = 0, flag = 0;     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < k; i++) {       int x, y;       scanf( %d%d , &x, &y);       x--;       y--;       vis[x][y] = 1;       if (!flag && judge(x, y)) {         ans = i + 1;         flag = 1;       }     }     if (!flag)       puts( 0 );     else       printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, x, y, a, b;   int main() {     cin >> n >> m >> x >> y >> a >> b;     long long W = min(n, (m * a) / b);     long long divA = a, divB = b;     for (long long i = 2; i * i <= divB; i++) {       while (divB % i == 0) {         if (divA % i == 0) {           divA /= i;         }         divB /= i;       }     }     if (divA % divB == 0) divA /= divB;     W -= (W % divA);     long long H = (W * b) / a;     long long x1 = x - ((W + 1) / 2);     long long y1 = y - ((H + 1) / 2);     long long x2 = x1 + W;     long long y2 = y1 + H;     if (x2 > n) {       x2 = n;       x1 = x2 - W;     }     if (x1 < 0) {       x1 = 0;       x2 = W;     }     if (y2 > m) {       y2 = m;       y1 = y2 - H;     }     if (y1 < 0) {       y1 = 0;       y2 = H;     }     W = x2 - x1;     H = y2 - y1;     cout << x1 <<     << y1 <<     << x2 <<     << y2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 1e4;   int a[maxn], mod;   int b[maxn];   int n;   int pow(int a, int b) {     if (b == 1) return a;     int t = pow(a, b >> 1);     t = 1LL * t * t % mod;     if (b & 1) t = 1LL * t * a % mod;     return t;   }   int ny(int a) { return pow(a, mod - 2); }   int ans, dd;   void solve(int a[], int n) {     if (n == 1) {       ans = a[1];       dd = 1;       return;     }     int cc = a[2] - a[1];     int s = 0;     for (int i = (1); i <= (n); ++i)       if (!binary_search(a + 1, a + n + 1, (a[i] + cc) % mod)) ++s;     cc = 1LL * cc * ny(s) % mod;     ans = -1, dd = mod - cc;     for (int i = (1); i <= (n); ++i)       if (!binary_search(a + 1, a + n + 1, (a[i] + cc) % mod)) {         if (ans == -1)           ans = a[i];         else {           ans = -1;           break;         }       }   }   void init() {     scanf( %d%d , &mod, &n);     for (int i = (1); i <= (n); ++i) scanf( %d , &a[i]);     if (n == mod) {       printf( %d %d n , 0, 1);       return;     }     sort(a + 1, a + n + 1);     if (n * 2 > mod) {       int t = 0;       for (int i = (0); i <= (mod - 1); ++i)         if (!binary_search(a + 1, a + n + 1, i)) b[++t] = i;       solve(b, t);       if (ans != -1) (ans += 1LL * dd * t % mod) %= mod;     } else       solve(a, n);     if (ans == -1)       printf( %d n , ans);     else       printf( %d %d n , ans, dd);   }   int main() {     init();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, rsp, ans, taram;   char first;   int main() {     cin >> n;     cin >> first;     if (first ==  U ) {       taram = 2;       rsp++;     } else       taram = 1;     for (int i = 2; i <= n; i++) {       cin >> first;       if (rsp * 2 == i - 1) {         ans += (first ==  R  && taram == 2);         ans += (first ==  U  && taram == 1);         if ((first ==  R  && taram == 2) || (first ==  U  && taram == 1))           taram = taram % 2 + 1;       }       if (first ==  U ) rsp++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int n, x, y;     cin >> n >> x >> y;     vector<int> arr(n, 0);     for (int i = 0; i < n; ++i) {       cin >> arr[i];     }     sort(arr.begin(), arr.end());     if (x > y) {       cout << n <<   n ;     } else {       int index = -1;       for (int i = 0; i < n; ++i) {         if (arr[i] > x) {           index = i;           break;         }       }       if (index == -1) {         if (n % 2 == 1) {           cout << n / 2 + 1 <<   n ;         } else {           cout << n / 2 <<   n ;         }       } else {         if ((index) % 2 == 1) {           cout << (index) / 2 + 1 <<   n ;         } else {           cout << (index) / 2 <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int a, b;       cin >> a >> b;       long long int x;       x = a % b;       if (x == 0)         cout << x << endl;       else {         long long int r = a / b;         long long int res = (r + 1) * b - a;         cout << res << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int u, int v) {     int tmp;     while (v) {       tmp = v;       v = u % v;       u = tmp;     }     return u;   }   int main() {     int a, b, t;     cin >> a >> b;     if (a > b) {       swap(a, b);     }     if ((t = gcd(a, b)) == 1) {       cout <<  NO  << endl;       return 0;     }     int flag = 1;     for (int i = 1; i <= t; i++) {       for (int j = i; j <= t; j++) {         if (t * t == i * i + j * j) {           flag = 0;           cout <<  YES  << endl;           cout <<  0 0  << endl;           cout << i * a / t <<     << -j * a / t << endl;           cout << j * b / t <<     << i * b / t << endl;           return 0;         }       }     }     if (flag) cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   #define ll long long   #define ld long double   #define vec vector   #define pii pair<int, int>    using namespace std;      const long long MAXVAL = (long long) 1e18 + 1;   const long long MOD = 1000000007ll;   //const long long MOD = 998244353ll;   const int INF = 1000000001;      long long poww(int x, long long pow) {     if (pow == 0ll ) return 1;     if (pow == 1ll) return x % MOD;     long long ans = poww(x, pow >> 1) % MOD;     ans = (ans * ans) % MOD;     if ((pow & 1) == 1) {       ans = (ans * x ) % MOD;     }     return ans % MOD;   }      ll gcd(ll x, ll y) {     if (x == 0) return y;     while (y) {       x %= y;       swap(x, y);     }     return x;   }      ll sq(int x, int y){      return x * 1ll * x + y  * 1ll * y;   }      //vector<int> pi(1000);   //vector<int> w(1000);      //int dsu_get(int x) {     //if (pi[x] == x) return x;     //int res = dsu_get(pi[x]);     //pi[x] = res;     //return res;   //}   //void dsu_merge(int x, int y) {     //if (x == y) return;     //x = dsu_get(x);     //y = dsu_get(y);     //if (x == y) return;     //if (w[x] > w[y]) swap(x, y);     //pi[y] = x;     //w[y] += w[x];   //}      //struct intr {     //int x, a, lb, rb;     //intr(int x_, int a_, int lb_, int rb_) {       //x = x_;       //a = a_;       //lb = lb_;       //rb = rb_;     //}   //};   //   //vec<int> t;      //void init (int nn) {     //n = nn;     //t.assign (n, 0);   //}      //int sum (int r) {     //int result = 0;     //for (; r >= 0; r = (r & (r+1)) - 1) result += t[r];     //return result;   //}      //void inc (int i, int delta) {     //for (; i < n; i = (i | (i+1))) t[i] += delta;   //}   //      int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int q = 1;     //cin >> q;     while (q-- > 0) {        int n,k;       cin >> n >> k;       vec<set<int>> gr(n);       vec<set<int>> gr2(n);       for (int i = 0; i < n; ++i) {         int x;         cin >> x;         if (x == 0) continue;         --x;         gr[x].insert(i);       }       vec<pii> req;       vec<int> pi(n);       for (int i = 0; i < n; ++i) pi[i] = i;       bool fail = false;       vec<int> was(n, 0);       gr2 = gr;       vec<set<int>> gr2t(n);       for (int i  =0; i < n; ++i) {         for (int j : gr2[i]) {           gr2t[j].insert(i);         }       }       //for (int i = 0; i < n; ++i)labels[i] = {i};       vec<int>was2(n, 0);       for (int j = 0; j < k; ++j) {         int x, y;         cin >> x >> y;         --x;         --y;         req.emplace_back(x, y);         //cout <<   req   << j << endl;         if (gr2[y].count(x)) {           //cout <<   y -> x   << y +1 <<     << x+1 << endl;           fail = true;         } else {           //if (gr[x].count(y)) {             //gr[x].erase(gr[x].find(y));           //}           gr2[x].insert(y);           if (pi[y] != y) {             // cannot be             //cout <<   cannot bE   << fail << endl;             fail = true;           }           int top = x;           vec<int> path;           while (top != pi[top]) {             path.push_back(top);             top = pi[top];           }           for (auto& s : path) {             pi[s] = top;           }           pi[y] = pi[x];           was[y] = 2;         }       }       if (fail) {         cout << 0 <<   n ;         continue;       }          function<void(int)>  dfs = [&] (int v) {         //cout <<   cur v   << v + 1 << endl;         was2[v] = 1;         for (int next : gr2[v]) {           if (was2[next] == 0) {             dfs(next);           } else if (was2[next] == 1) {             //cout <<   next gives cycle   << next + 1 << endl;             fail = true;             break;           }         }         was2[v] = 2;         //cout <<   OUT   << v + 1 << endl;       };       for (int i = 0; i < n; ++i) if (was2[i] == 0) dfs(i);       if (fail) {         cout <<  0 n ;         continue;       }       vec<set<int>> grnew(n);       for (int i = 0; i < n; ++i) {           vec<int> path;           int top = i;           while (top != pi[top]) {             path.push_back(top);             top = pi[top];           }           for (int s : path) {             pi[s] = top;           }         for (int out : gr[i]) {           if (pi[out] != pi[i]) {             grnew[pi[i]].insert(pi[out]);           }         }         for (int in : gr2t[i]) {           if (pi[in] != pi[i]) {             grnew[pi[in]].insert(pi[i]);           }         }       }       //for (auto r: req) {         //gr2[r.first].insert(r.second);       //}       vec<int> topo;       bool cycle = false;       vec<int> next;       vec<int> prev;       for (int i =0 ;i < n; ++i) {         prev.push_back(i);         next.push_back(i);       }       for (int i = 0; i < k; ++i) {         int x = req[i].first;         int y = req[i].second;         next[x] = y;         prev[y] = x;       }          function<void(int)>  topo_dfs = [&] (int v) {         //cout <<   cur v   << v + 1 << endl;         was[v] = 1;         for (int next : grnew[v]) {           if (was[next] == 0) {             topo_dfs(next);           } else if (was[next] == 1) {             //cout <<   next gives cycle   << next + 1 << endl;             cycle = true;           }         }         was[v] = 2;         //cout <<   OUT of   << v + 1  << endl;         topo.push_back(v);       };       for (int i = 0; i < n; ++i) {         if (was[i]) continue;         topo_dfs(i);       }       if (cycle) {         cout << 0 <<   n ;       } else {         reverse(topo.begin(), topo.end());         vec<int> ans;         vec<bool> was(n, false);         for (int i = 0 ; i < topo.size(); ++i) {           int x = topo[i];           //cout <<   Cur x   << x + 1 << endl;           if (prev[x] != x) continue;           while (x != next[x]) {             if (was[x]) {               //cout <<  was in   << x + 1 << endl;               fail = true;               break;             }             was[x] = true;             //cout <<   next x   << x + 1 << endl;             ans.push_back(x);             x = next[x];           }           ans.push_back(x);         }         if (fail || ans.size() < n) {           cout << 0 <<   n ;         } else {           for (auto l : ans) {             cout << 1 + l <<    ;           }           cout <<   n ;         }       }           }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string str1, str2;     cin >> str1 >> str2;     int diffcount = 0;     for (int i = 0; i < str1.length(); i++) {       if (str1[i] != str2[i]) diffcount++;     }     if (diffcount % 2 == 1) {       cout <<  impossible ;       return 0;     }     int index = 0;     int toreach = diffcount / 2;     while (diffcount != toreach) {       if (str1[index] != str2[index]) {         if (str1[index] ==  1 )           str1[index] =  0 ;         else           str1[index] =  1 ;         diffcount--;       }       index++;     }     cout << str1;   }


#include<iostream>   #include<algorithm>   using namespace std;   class node{       public:           int a;           int b;   };   bool com(node a,node b){       return a.a<b.a;   }   int main(){       int times=0;       cin>>times;       while(times--){           int t=0;           cin>>t;           node *arr=new node[t+5]();           for(int i=0;i<t;i++){               scanf( %d ,&arr[i].a);               arr[i].b=i+1;           }           if(t==1){               cout<<arr[0].a<<endl;               continue;           }           sort(arr,arr+t,com);           bool fl=false;           for(int i=0;i<t;i++){               if(i==0){                   if(arr[i].a!=arr[i+1].a){                       cout<<arr[i].b<<endl;                       fl=true;                       break;                   }               }               if(i==t-1){                   if(arr[i].a!=arr[i-1].a){                       cout<<arr[i].b<<endl;                       fl=true;                       break;                   }               }               if(arr[i].a!=arr[i+1].a&&arr[i].a!=arr[i-1].a){                   cout<<arr[i].b<<endl;                       fl=true;                       break;               }           }           if(!fl)           cout<<-1<<endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long double l, v1, v2;   long double a[100000];   long double p[100001];   vector<pair<long double, int> > events;   int main() {     cout << fixed << setprecision(12);     cin >> n >> l >> v1 >> v2;     long double dist = l * v2 / (v1 + v2);     events.push_back(make_pair(0, 0));     events.push_back(make_pair(2 * l, 0));     for (int i = 0; i < n; ++i) {       cin >> a[i];       events.push_back(make_pair(a[i] - dist, 1));       events.push_back(make_pair(a[i] + 2 * l - dist, 1));       events.push_back(make_pair(a[i], -1));     }     sort(events.begin(), events.end());     memset(p, 0, sizeof p);     int choc = 0, i = 0;     while (events[i].second != 0) {       choc += events[i].second;       ++i;     }     ++i;     while (events[i].second != 0) {       p[choc] += events[i].first - events[i - 1].first;       choc += events[i].second;       ++i;     }     p[choc] += events[i].first - events[i - 1].first;     for (int i = 0; i <= n; ++i) cout << (p[i] / 2 / l) << endl;   }


#include<bits/stdc++.h>   using namespace std;   #define ll long long   #define ull unsigned long long   #define f(i,x,y) for(int i=x;i<=y;i++)   #define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);   //priority_queue<int>Q;   //unordered_map<string,int> Q;   const int MAX=3e5+10;   ll a[MAX];   void solve() {    ll n;    cin>>n;    for(int i=1; i<=n*2; i++) {     cin>>a[i];    }    int flag1=1;    sort(a+1,a+1+n*2,greater<ll>());    ll last;    int v=-1;    ll flag=0;    ll cnt=n;    for(int i=1; i<=n*2; i+=2) {     if(a[i]!=a[i+1]||a[i]<2||a[i]%2) {      flag1=0;      cout<< NO <<endl;      break;     }     a[i]-=flag;     if((v!=-1&&a[i]>=last*cnt)||a[i]<=0) {      flag1=0;      cout<< NO <<endl;      break;     }     if(a[i]%cnt==0) {      v=1;      last=a[i]/cnt;     } else {      flag1=0;      cout<< NO <<endl;      break;     }     if(last&1)     {      flag1=0;      cout<< NO <<endl;         break;     }     flag+=last;     cnt--;    }    if(flag1)     cout<< YES <<endl;   }   int main() {    IOS;    int t;    cin>>t;    while(t--) {     solve();    }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using ld = long double;   const ll llinf = (1ll << 61) - 1;   const double eps = 1e-6, ldeps = 1e-9;   struct Dbg {     static constexpr auto &os = cout;     template <class C>     static auto dud(C *x) -> decltype(os << *x, 0);     template <class C>     static char dud(...);     template <class C>     typename enable_if<sizeof dud<C>(0) != 1, Dbg &>::type operator<<(         const C &x) {       os << x;       return *this;     }     template <class C>     Dbg &dump(C b, C e) {       *this <<   n[ ;       int cur = 0;       for (C i = b; i != e and cur < 26; i++, cur++)         *this <<  ,   + 2 * (i == b) << *i;       return *this <<  ] ;     }     template <class C>     typename enable_if<sizeof dud<C>(0) == 1, Dbg &>::type operator<<(         const C &x) {       return dump(begin(x), end(x));     }     template <class C, size_t X>     typename enable_if<sizeof(C) != 1, Dbg &>::type operator<<(C (&x)[X]) {       return dump(begin(x), end(x));     }     template <class B, class C>     Dbg &operator<<(const pair<B, C> &x) {       return *this <<  {  << x.first <<  ,   << x.second <<  } ;     }     template <class C, size_t Y>     struct TP {       void operator()(Dbg &os, const C &t) {         TP<C, Y - 1>()(os, t);         os <<  ,   << get<Y - 1>(t);       }     };     template <class C>     struct TP<C, 1> {       void operator()(Dbg &os, const C &t) { os << get<0>(t); }     };     template <class... C>     Dbg &operator<<(const tuple<C...> &t) {       os <<  { , TP<decltype(t), sizeof...(C)>()(*this, t);       return *this <<  } ;     }     Dbg &operator<<(ostream &(*x)(std::ostream &)) {       os << x;       return *this;     }   } dbg;   void err(istringstream *iss) { delete iss; }   template <class C, class... Args>   void err(istringstream *iss, const C &val, const Args &...args) {     string name;     *iss >> name;     if (name.back() ==  , ) name.pop_back();     dbg << name <<   =   << val <<  ;  , err(iss, args...);   }   int n, m, K, T, Q, cn;   const int inf = 1000000007, mxnm = 1000005;   vector<vector<int> > a;   vector<pair<int, int> > pos[mxnm];   int maxrow[mxnm], maxcol[mxnm];   template <class C>   C compress(vector<C> &v) {     int sz = int(v.size());     vector<pair<C, int> > tmp(sz);     for (int i = 0; i < sz; i++) {       tmp[i] = {v[i], i};     }     sort(begin(tmp), end(tmp));     int cur = 1;     for (int i = 0; i < sz; i++) {       cur += i and tmp[i].first != tmp[i - 1].first;       v[tmp[i].second] = cur;     }     return cur;   }   int os[mxnm], lastrow[mxnm], lastcol[mxnm];   class DSU {     vector<int> dsupar, siz;       public:     int cntDSU;     void reset() {       int sz = int(dsupar.size());       for (int i = 0; i < sz; i++) dsupar[i] = i, siz[i] = 1;     }     DSU(int N, int noOfSets = -1) {       dsupar.resize(N + 5), siz.resize(N + 5);       reset();       cntDSU = noOfSets == -1 ? N : noOfSets;     }     int find(int x) { return dsupar[x] == x ? x : dsupar[x] = find(dsupar[x]); }     void union_(int u, int v) {       if ((u = find(u)) == (v = find(v))) return;       if (siz[u] < siz[v]) swap(u, v);       dsupar[v] = u, siz[u] += siz[v], siz[v] = 0, os[u] = max(os[u], os[v]);       cntDSU--;     }   } dsu(mxnm);   signed main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.precision(11);     cin >> n >> m;     a.resize(n + 5, vector<int>(m + 5));     vector<int> a2(n * m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a2[i * m + j];       }     }     int o = compress(a2);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         pos[a2[i * m + j]].push_back({i, j});         a[i][j] = a2[i * m + j];       }     }     memset(lastrow, -1, sizeof(lastrow)), memset(lastcol, -1, sizeof(lastcol));     for (int i = 1; i <= o; i++) {       for (auto &j : pos[i]) {         os[j.first * m + j.second] = max(maxrow[j.first], maxcol[j.second]) + 1;       }       for (auto &j : pos[i]) {         if (lastrow[j.first] == -1)           lastrow[j.first] = j.second;         else           dsu.union_(j.first * m + j.second, j.first * m + lastrow[j.first]);         if (lastcol[j.second] == -1)           lastcol[j.second] = j.first;         else           dsu.union_(j.first * m + j.second, lastcol[j.second] * m + j.second);       }       for (auto &j : pos[i]) {         a[j.first][j.second] = os[dsu.find(j.first * m + j.second)];         lastrow[j.first] = lastcol[j.second] = -1;       }       for (auto &j : pos[i]) {         maxrow[j.first] = max(maxrow[j.first], a[j.first][j.second]),         maxcol[j.second] = max(maxcol[j.second], a[j.first][j.second]);       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << a[i][j] <<    n [j == m - 1];       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s;   int main() {     cin >> n >> s;     int sol = n;     for (int i = 1; i < n; i++) {       if (s[i] != s[i - 1] and s[i - 1] !=  D ) {         sol--;         s[i] =  D ;       }     }     cout << sol << endl;   }


#include <bits/stdc++.h>   using namespace std;   void FastIO() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cout.precision(15);   }   string fun(string str) {     int i, l = str.length();     for (i = 0; i < l; i++) {       if (str[i] ==  + )         str[i] =  * ;       else         str[i] =  + ;     }     return str;   }   string s[10][1000];   int main() {     FastIO();     int i, n, j;     cin >> n;     if (n == 0) {       cout <<  +  <<   n ;       return 0;     }     s[0][0] =  ++ ;     s[0][1] =  +* ;     if (n == 1) {       cout << s[0][0] <<   n ;       cout << s[0][1] <<   n ;       return 0;     }     for (i = 1; i < 9; i++) {       for (j = 0; j < (1 << i); j++) s[i][j] = s[i - 1][j] + s[i - 1][j];       for (j = (1 << i); j < (1 << (i + 1)); j++)         s[i][j] = s[i - 1][j - (1 << i)] + fun(s[i - 1][j - (1 << i)]);       if (i == (n - 1)) {         for (j = 0; j < (1 << n); j++) cout << s[i][j] <<   n ;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[410][42];   char a[42], t[42];   int main() {     int n;     while (~scanf( %d , &n)) {       int ans = n, g = 0;       for (int k = 0; k < n; k++) {         scanf( %s , t);         while (true) {           int k = 0;           for (int i = 0; t[i] !=   0 ;) {             if (t[i] ==  u )               a[k++] =  o , a[k++] =  o , i++;             else if (t[i] ==  k ) {               int num = -1;               for (int j = i; t[j] !=   0 ; j++) {                 if (t[j] ==  k )                   continue;                 else if (t[j] ==  h ) {                   num = j + 1;                   break;                 } else                   break;               }               if (num == -1)                 a[k++] =  k , i++;               else                 a[k++] =  h , i = num;             } else               a[k++] = t[i], i++;           }           a[k] =   0 ;           if (strcmp(a, t) == 0)             break;           else             strcpy(t, a);         }         bool flag = false;         for (int j = 0; j < g; j++)           if (strcmp(s[j], t) == 0) {             ans--;             flag = true;             break;           }         if (!flag) strcpy(s[g++], t);       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> arr(n), lefts(n), rights(n);     for (int &x : arr) cin >> x;     stack<int> positions;     for (int i = 0; i < n; ++i) {       while (!positions.empty() && arr[positions.top()] <= arr[i])         positions.pop();       if (positions.empty()) {         lefts[i] = -1;       } else {         lefts[i] = positions.top();       }       positions.push(i);     }     while (!positions.empty()) positions.pop();     for (int i = n - 1; i >= 0; --i) {       while (!positions.empty() && arr[positions.top()] <= arr[i])         positions.pop();       if (positions.empty()) {         rights[i] = n;       } else {         rights[i] = positions.top();       }       positions.push(i);     }     while (!positions.empty()) positions.pop();     vector<int> inv(n);     for (int i = 0; i < n; ++i) {       inv[arr[i]] = i;     }     long long res = 0;     for (int i = 0; i < n; ++i) {       int distL = i - lefts[i];       int distR = rights[i] - i;       if (distL < distR) {         for (int j = lefts[i] + 1; j < i; ++j) {           if (arr[j] > arr[i]) continue;           int Right = arr[i] - arr[j];           int pos = inv[Right];           if (pos > i && pos < rights[i]) {             ++res;           }         }       } else {         for (int j = i + 1; j < rights[i]; ++j) {           if (arr[j] > arr[i]) continue;           int Left = arr[i] - arr[j];           int pos = inv[Left];           if (pos < i && pos > lefts[i]) {             ++res;           }         }       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 400000;   long long l[500000], r[500000], k[500000], b[500000], a[500000], pref1[500000],       pref2[500000], s = MX;   long long f(long long b1, long long a1, long long b2, long long a2) {     return (b1 - b2) / (a1 - a2);   }   void add(long long kx, long long bx) {     if (s == MX) {       l[s] = -2e18;       r[s] = 2e18;       b[s] = bx;       k[s] = kx;       s--;       return;     }     if (f(bx, kx, b[s + 1], k[s + 1]) > r[s + 1]) {       s++;       add(kx, bx);       return;     }     l[s] = -2e18;     r[s] = f(bx, kx, b[s + 1], k[s + 1]);     b[s] = bx;     k[s] = kx;     l[s + 1] = r[s] + 1;     s--;     return;   }   int main() {     ios::sync_with_stdio(0);     long long n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     pref1[0] = a[0];     pref2[0] = a[0];     for (int i = 1; i < n; i++) {       pref1[i] = pref1[i - 1] + a[i];       pref2[i] = pref2[i - 1] + a[i] * (i + 1);     }     long long ans = 0;     for (long long i = 0; i < n; i++) {       ans = max(ans, pref2[i]);       long long lt = s + 1, rt = MX;       while (lt < rt) {         long long mid = (lt + rt) / 2;         if (lt == rt - 1) mid++;         if (pref1[i] < l[mid])           rt = mid - 1;         else           lt = mid;       }       long long q = 0, t = 0;       if (i > 0) {         q = pref2[i - 1];         t = pref1[i - 1];       }       if (lt <= MX) ans = max(ans, pref2[i] - b[lt] + pref1[i] * k[lt]);       add(-i - 1, -(pref1[i] * (i + 1) - pref2[i]));     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   bool isPrime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   unsigned int countBits(unsigned int n) {     unsigned int count = 0;     while (n) {       count++;       n >>= 1;     }     return count;   }   bool isPerfectSquare(long double x) {     long double sr = sqrt(x);     return ((sr - floor(sr)) == 0);   }   int subArraySum(int arr[], int n) {     int curr_sum = arr[0], start = 0, i, count = 0, len;     len = 0;     for (i = 1; i <= n; i++) {       len++;       while (curr_sum > len && start < i - 1) {         curr_sum = curr_sum - arr[start];         start++;         len++;       }       if (curr_sum == len) {         count++;       }       if (i < n && i > 0) {         curr_sum = curr_sum + arr[i];       }     }     return count;   }   void printDigit(int N, vector<long long int>& arr) {     int i = 0;     int j, r;     while (N != 0) {       r = N % 10;       arr.push_back(r);       i++;       N = N / 10;     }   }   void solver(vector<long long int> arr, long long int start,               long long int& count, long long int a1) {     long long int sum = 0;     for (long long int i = start + 1; i < arr.size() - 1; i++) {       sum += arr[i];       if (sum == a1) count++;     }   }   bool checkDivisibility(long long int n, int digit) {     if (digit == 0) return true;     return (digit != 0 && n % digit == 0);   }   bool allDigitsDivide(long long int n) {     long long int temp = n;     while (temp > 0) {       int digit = temp % 10;       if (!(checkDivisibility(n, digit))) return false;       temp /= 10;     }     return true;   }   bool isPrime(int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   bool isPowerOfTwo(unsigned long long x) { return x && (!(x & (x - 1))); }   int nextPrime(int N) {     if (N <= 1) return 2;     int prime = N;     bool found = false;     while (!found) {       prime++;       if (isPrime(prime)) found = true;     }     return prime;   }   bool sortcol(const vector<long long int>& v1, const vector<long long int>& v2) {     return v1[0] < v2[0];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long int b = 0, q, c, x, y, start = 0, end = 0, count = 0, neg = 0,                   pos = 0, count1 = 0, a1 = 0, b1 = 0, c1 = 0, x1, y1, n1, m,                   ans = 0, sum = 0, k;     long long int n;     string s1, s2(  ), s3(  );     bool check2 = false, check3 = false;     long long int x3, x2, y3, y2;     int curr1 = 0, curr = 0;     vector<int> arr(130, 0);     vector<int> arr1;     stack<char> s;     long long int vb;     bool check1 = false, check4 = false;     vector<double> arrv;     unordered_map<long long int, long long int> map1;     unordered_map<long long int, long long int> map2;     long long int a, l = 0, d = 0, u = 0, v, g, sub;     cin >> s1;     n = s1.length();     for (int i = 0; i < n; i++) {       arr[s1[i]]++;     }     for (int i = 0; i < arr.size(); i++) {       if (arr[i] % 2 != 0) count++;     }     if (count == 0 || count == 1)       cout <<  First ;     else if (count % 2 != 0)       cout <<  First ;     else       cout <<  Second ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int x, int1, int2, int3, tempsum, lastsum = -1;     string s, s1, s2, s3;     cin >> s;     x = s.size();     for (int d1 = 1; d1 < x - 1 && d1 < 8; d1++) {       for (int d2 = 1; d2 < x - d1 && d2 < 8; d2++) {         s1 = s.substr(0, d1);         s2 = s.substr(d1, d2);         s3 = s.substr(d1 + d2, x - d1 - d2);         if ((s2.size() > 1 && s2[0] ==  0 ) || (s3.size() > 1 && s3[0] ==  0 ) ||             (s1.size() > 1 && s1[0] ==  0 ) || x - d1 - d2 > 7)           continue;         stringstream convert1, convert2, convert3;         convert1 << s1;         convert1 >> int1;         convert2 << s2;         convert2 >> int2;         convert3 << s3;         convert3 >> int3;         if (int1 > 1000000 || int2 > 1000000 || int3 > 1000000) continue;         tempsum = int1 + int2 + int3;         lastsum = max(tempsum, lastsum);       }     }     cout << lastsum << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   const long double pi = 2 * acos(0.0);   using namespace std;   int power(int a, int n) {     if (n == 0) {       return 1;     }     int p = power(a, n / 2) % 1000000007;     p = (p * p) % 1000000007;     if (n % 2 == 1) {       p = (p * a) % 1000000007;     }     return p;   }   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   const int N = 1e6 + 5;   vector<int> sieve(N, 0);   void si() {     sieve[1] = 1;     for (int i = 2; i < N; i++) {       if (sieve[i] == 0) {         sieve[i] = i;         for (int j = 2 * i; j < N; j += i) {           sieve[j] = i;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     if (n == 1) {       cout << 0 <<   n ;       return 0;     }     vector<int> a(n + 1);     ;     for (int i = 0; i < n; i++) cin >> a[i];     ;     a[n] = 0;     int k = (n + 1) / 2;     int dp[n + 1][k + 1][2];     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= k; j++) {         dp[i][j][0] = 1e9;         dp[i][j][1] = 1e9;       }     }     dp[1][0][0] = 0;     dp[1][1][1] = a[1] - min(a[0] - 1, a[1]);     for (int i = 0; i <= n; i++) {       dp[i][0][0] = 0;     }     vector<int> ans(k, 1e9);     for (int i = 2; i <= n; i++) {       for (int j = 1; j <= k; j++) {         dp[i][j][0] = min(dp[i - 1][j][0], dp[i - 1][j][1]);         int z = 1e9;         if (i - 3 >= 0) {           z = dp[i - 2][j - 1][1];           if (a[i - 3] > a[i - 1]) {             z += a[i - 3] - a[i - 1];           }           z += a[i] - min(a[i], a[i - 1] - 1);         }         dp[i][j][1] = min(dp[i - 1][j - 1][0] + a[i] - min(a[i], a[i - 1] - 1) +                               a[i - 2] - min(a[i - 2], a[i - 1] - 1),                           z);         dp[i][j][1] = min(dp[i][j][1], (int)(1e9));         ans[j - 1] = min(ans[j - 1], dp[i][j][1]);         ans[j - 1] = min(ans[j - 1], dp[i][j][0]);       }     };     for (int i = 0; i < k; i++) cout << ans[i] <<    ;     ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class T2>   T2 fac(T n) {     return n < 2 ? 1 : fac<T, T2>(n - 1) * n;   }   template <class T>   T nb_combinaisons(T k, T n) {     if (n < k) return nb_combinaisons<T>(n, k);     return fac<T, long long int>(n) /            (fac<T, long long int>(n - k) * fac<T, long long int>(k));   }   string itoa_2(long long int n) {     string s;     stringstream ss;     ss << n;     ss >> s;     while (s.size() != 9) s =  0  + s;     return s;   }   int pgcd(int a, int b) {     if (a == 0) return b;     if (b == 0) return a;     return pgcd(b, a % b);   }   int main() {     int A, B, n;     cin >> A >> B >> n;     if (A == 0) {       if (B != 0) {         cout <<  No solution ;         return 0;       } else {         cout <<  0 ;         return 0;       }     }     if (B % A != 0) {       cout <<  No solution ;       return 0;     }     int z = B / A;     for (int c = -1000; c <= 1000; c++) {       int alpha = pow((double)c, n);       if (alpha == z) {         cout << c;         return 0;       }     }     cout <<  No solution ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 110;   int N, M, U = 110, D = 0, L = 110, R = 0, cnt;   char s[maxn][maxn];   inline int gi() {     char ch;     int ret = 0, f = 1;     do ch = getchar();     while (!(ch >=  0  && ch <=  9 ) && ch !=  - );     if (ch ==  - ) f = -1, ch = getchar();     do ret = ret * 10 + ch -  0 , ch = getchar();     while (ch >=  0  && ch <=  9 );     return ret * f;   }   int main() {     N = gi();     M = gi();     for (int i = 1; i <= N; ++i) scanf( %s , s[i] + 1);     for (int i = 1; i <= N; ++i)       for (int j = 1; j <= M; ++j)         if (s[i][j] ==  B ) {           ++cnt;           U = min(i, U);           D = max(i, D);           L = min(j, L);           R = max(j, R);         }     int W = max(R - L + 1, D - U + 1);     if (!cnt)       puts( 1 );     else if (W > N || W > M)       puts( -1 );     else       printf( %d n , W * W - cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int pre[N];   void solve() {     string s;     int n, k, ans = 0;     cin >> n >> k >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  1 ) {         if (i == 0)           pre[i] = 1;         else           pre[i] = pre[i - 1] + 1;       } else {         if (i == 0)           pre[i] = 0;         else           pre[i] = pre[i - 1];       }     }     for (int i = 0; i < n; i++) {       if (s[i] ==  1 ) {         i += k;         continue;       }       int l = i - k - 1;       int r = i + k;       l = max(0, l);       r = min(r, n - 1);       if (pre[l] == pre[r]) {         ans++;         i = r;       }     }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int tc = 1;     cin >> tc;     while (tc--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const double pi = acos(-1.0);   const int N = 1e5 + 10;   const int mod = 100;   int main() {     string str;     int n, ans;     cin >> n >> str;     ans = n;     for (int i = 0; i < n - 1; i++) {       if (str[i] ==  U  && str[i + 1] ==  R ) {         ans--;         i++;       } else if (str[i] ==  R  && str[i + 1] ==  U ) {         i++;         ans--;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 850;   int capacity[N][N], p[N], visit[N], n, source, sink, max_flow;   pair<int, int> a[N];   vector<int> adj[N];   double f[N], cost[N][N], res;   double dis(pair<int, int> a, pair<int, int> b) {     return sqrt((a.first - b.first) * (a.first - b.first) +                 (a.second - b.second) * (a.second - b.second));   }   void add(int u, int v, int cap, double c) {     adj[u].push_back(v);     adj[v].push_back(u);     capacity[u][v] = cap;     cost[u][v] = c;     cost[v][u] = -c;   }   int bfs() {     for (int i = 0; i <= 2 * n + 1; i++) {       visit[i] = 2;       f[i] = 1e9;     }     f[source] = 0;     deque<int> q;     q.push_back(source);     int check = 0;     while (!q.empty()) {       int u = q.front();       q.pop_front();       visit[u] = 0;       if (u == sink) check = 1;       for (int v : adj[u])         if (capacity[u][v] > 0 && f[v] > f[u] + cost[u][v]) {           f[v] = f[u] + cost[u][v];           p[v] = u;           if (visit[v] == 1) continue;           if (visit[v] == 2)             q.push_back(v);           else             q.push_front(v);         }     }     return check;   }   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     source = 0;     sink = 2 * n + 1;     for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;     for (int i = 1; i <= n; i++) add(source, i, 2, 0);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (a[i].second > a[j].second) add(i, j + n, 1, dis(a[i], a[j]));     for (int i = n + 1; i <= 2 * n; i++) add(i, sink, 1, 0);     while (bfs()) {       int flow_path = 1e9, v = sink;       while (v != source) {         flow_path = min(flow_path, capacity[p[v]][v]);         v = p[v];       }       v = sink;       max_flow += flow_path;       res += flow_path * f[sink];       while (v != source) {         capacity[p[v]][v] -= flow_path;         capacity[v][p[v]] += flow_path;         v = p[v];       }     }     cout << fixed << setprecision(9);     if (max_flow != n - 1)       cout << -1;     else       cout << res;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a >> b >> c;     string ans =   ;     int f;     if (a > b) {       ans +=  0 ;       a--;       f = 0;     } else {       ans +=  1 ;       f = 1;       b--;     }     for (int i = 1; i < c; i++) {       if (f) {         ans +=  0 ;         a--;         f = f ^ 1;       } else {         ans +=  1 ;         b--;         f = f ^ 1;       }     }     if (!f) {       while (a--) {         ans +=  0 ;       }       f = f ^ 1;       while (b--) {         ans +=  1 ;       }     } else {       while (b--) {         ans +=  1 ;       }       while (a--) {         ans +=  0 ;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200200;   int n;   int a[maxn], b[maxn], c[3][maxn];   int sum[maxn];   int lowbit(int x) { return x & (-x); }   void add(int p, int v = 1) {     for (int i = p; i <= n; i += lowbit(i)) sum[i] += v;   }   int get(int p) {     int ret = 0;     for (int i = p; i; i -= lowbit(i)) ret += sum[i];     return ret;   }   bool on[maxn];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       a[i]++;       int before = get(a[i]);       c[0][i] = a[i] - 1 - before;       add(a[i]);     }     memset(sum, 0, sizeof(sum));     for (int i = 0; i < n; i++) {       scanf( %d , b + i);       b[i]++;       int before = get(b[i]);       c[1][i] = b[i] - 1 - before;       c[2][i] = c[0][i] + c[1][i];       add(b[i]);     }     for (int i = n - 1; i > 0; i--) {       int j = n - 1 - i;       if (c[2][i] > j) {         c[2][i] -= j + 1;         c[2][i - 1]++;       }     }     c[2][0] %= n;     memset(sum, 0, sizeof(sum));     memset(on, true, sizeof(on));     for (int i = 1; i <= n; i++) add(i);     vector<int> vi;     for (int i = 0; i < n; i++) {       int goal = c[2][i];       int low = 0, high = n, ans = -1;       while (low <= high) {         int mid = (low + high) / 2;         int s = get(mid);         if (s == goal) {           if (on[mid + 1] == true) {             ans = mid + 1;             break;           } else             low = mid + 1;         } else if (s < goal)           low = mid + 1;         else if (s > goal)           high = mid - 1;       }       on[ans] = false;       add(ans, -1);       vi.push_back(ans - 1);     }     for (int i = 0; i < n; i++) printf( %d  , vi[i]);     putchar(10);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     bool remove = true;     int ans = 0;     while (remove) {       remove = false;       int idx;       char c =   0 ;       if (s.size() > 1) {         for (int i = 0; i < s.size(); i++) {           if (i > 0) {             if (i == s.size() - 1) {               if (s[i] - 1 == s[i - 1]) {                 remove = true;                 if (c < s[i]) {                   idx = i;                   c = s[i];                 }               }             } else {               if (s[i] - 1 == s[i - 1] || s[i] - 1 == s[i + 1]) {                 remove = true;                 if (c < s[i]) {                   idx = i;                   c = s[i];                 }               }             }           } else {             if (s[i] - 1 == s[i + 1]) {               remove = true;               if (c < s[i]) {                 idx = i;                 c = s[i];               }             }           }         }       }       if (remove) {         s.erase(s.begin() + idx);         ans++;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 50;   long long g[maxn];   int ans, n;   inline int ctz(long long s) {     return s ? __builtin_ctzll(s) : 8 * sizeof(long long);   }   void BronKerbosch(long long clique, long long allow, long long forbid) {     if (!allow && !forbid) {       ans = max(ans, __builtin_popcountll(clique));       return;     }     if (!allow) return;     int pivot = ctz(allow | forbid);     long long choose = allow & ~g[pivot];     for (int u = ctz(choose); u < n; u += ctz(choose >> (u + 1)) + 1) {       BronKerbosch(clique | (1LL << u), allow & g[u], forbid & g[u]);       allow ^= 1LL << u;       forbid |= 1LL << u;     }   }   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int k;     long long x;     cin >> n >> k;     memset(g, 0, sizeof(g));     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> x;         g[i] ^= (x << j);       }     }     BronKerbosch(0LL, (1LL << n) - 1, 0LL);     printf( %.9f n , 1.0 * k * k * (ans - 1) / (2 * ans));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 10;   int m, k, n, s, tot, del, a[N], b[N], c[N], d[N];   int main() {     scanf( %d%d%d%d , &m, &k, &n, &s);     del = m - k * n;     for (int i = 1; i <= m; i++) scanf( %d , &a[i]);     for (int i = 1, x; i <= s; i++) {       scanf( %d , &x);       b[x]++;       if (b[x] == 1) tot++;     }     for (int l = 1, r = 1; r <= m; r++) {       ++c[a[r]];       tot -= c[a[r]] == b[a[r]];       while (!tot && r - l + 1 > k && l <= m && c[a[l]] > b[a[l]]) --c[a[l]], l++;       if (!tot && r - l + 1 >= k) {         int del2 = (l - 1) % k + r - l + 1 - k;         if (del2 > del) continue;         printf( %d n , del2);         if (!del2) return 0;         for (int i = 1; i <= (l - 1) % k && del2; i++) printf( %d  , i), del2--;         for (int i = l; i <= r && del2; i++)           if (d[a[i]] + 1 > b[a[i]])             printf( %d  , i), del2--;           else             d[a[i]]++;         return 0;       }     }     printf( -1 );   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)3e5 + 7;   int n, k;   int x[N], y[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> x[i];     }     for (int i = 1; i <= n; i++) {       cin >> y[i];     }     long long f, s;     f = s = 0;     for (int i = 1; i <= n; i++) {       f = max(0LL, x[i] + f - y[i] * 1LL * k);       s = max(0LL, y[i] + s - x[i] * 1LL * k);       if (f > k || s > k) {         puts( NO );         return 0;       }     }     puts( YES );   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > a;   bool g[100][100];   bool used[100];   int n;   void dfs(int v) {     used[v] = true;     for (int i = 0; i < n; i++)       if (g[v][i] && !used[i]) dfs(i);   }   int main() {     int m;     cin >> n >> m;     bool now = false;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) g[i][j] = false;     for (int i = 0; i < n; i++) used[i] = false;     a.resize(n);     for (int i = 0; i < n; i++) {       int num;       cin >> num;       if (num != 0) now = true;       a[i].resize(num);       for (int j = 0; j < num; j++) {         cin >> a[i][j];         a[i][j]--;       }     }     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++)         for (int i1 = 0; i1 < a[i].size(); i1++)           for (int j1 = 0; j1 < a[j].size(); j1++)             if (a[i][i1] == a[j][j1]) {               g[i][j] = true;               g[j][i] = true;             }     int result = 0;     for (int i = 0; i < n; i++)       if (!used[i]) {         dfs(i);         result++;       }     if (!now) result++;     cout << result - 1;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 512;   const int T = 101;   int n, m;   long long a[M][M];   long long b[M][M];   int t;   int x[T], y[T];   void solve(int xl, int xr, int yl, int yr) {     if (xl == xr && yl == yr) {       b[xl][yl] = a[xl][yl];     } else if (xl != xr) {       int tm = (xr - xl + 1);       int um = (yr - yl + 1);       for (int i = xl; i < xl + tm / 2; i++) {         for (int j = yl; j <= yr; j++) a[i + tm / 2][j] ^= a[i][j];       }       solve(xl + tm / 2, xr, yl, yr);       for (int i = xl; i < xl + tm / 2; i++) {         for (int j = yl; j <= yr; j++) a[i + tm / 2][j] ^= a[i][j];       }       for (int i = xl + tm / 2; i <= xr; i++) {         for (int j = yl; j <= yr; j++) {           for (int k = 1; k <= t; k++) {             if ((i + x[k]) % tm < tm / 2)               a[xl + (i + x[k]) % tm][yl + (j + y[k]) % um] ^= b[i][j];           }         }       }       solve(xl, xl + tm / 2 - 1, yl, yr);       for (int i = xl + tm / 2; i <= xr; i++) {         for (int j = yl; j <= yr; j++) {           for (int k = 1; k <= t; k++) {             if ((i + x[k]) % tm < tm / 2)               a[xl + (i + x[k]) % tm][yl + (j + y[k]) % um] ^= b[i][j];           }           b[i][j] ^= b[i - tm / 2][j];         }       }     } else {       int tm = (xr - xl + 1);       int um = (yr - yl + 1);       for (int i = xl; i <= xr; i++) {         for (int j = yl; j < yl + um / 2; j++) a[i][j + um / 2] ^= a[i][j];       }       solve(xl, xr, yl + um / 2, yr);       for (int i = xl; i <= xr; i++) {         for (int j = yl; j < yl + um / 2; j++) a[i][j + um / 2] ^= a[i][j];       }       for (int i = xl; i <= xr; i++) {         for (int j = yl + um / 2; j <= yr; j++) {           for (int k = 1; k <= t; k++) {             if ((j + y[k]) % um < um / 2)               a[xl + (i + x[k]) % tm][yl + (j + y[k]) % um] ^= b[i][j];           }         }       }       solve(xl, xr, yl, yl + um / 2 - 1);       for (int i = xl; i <= xr; i++) {         for (int j = yl + um / 2; j <= yr; j++) {           for (int k = 1; k <= t; k++) {             if ((j + y[k]) % um < um / 2)               a[xl + (i + x[k]) % tm][yl + (j + y[k]) % um] ^= b[i][j];           }           b[i][j] ^= b[i][j - um / 2];         }       }     }   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     m = 1 << n;     for (int i = 0; i < m; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];       }     }     cin >> t;     for (int i = 1; i <= t; i++) {       cin >> x[i] >> y[i];     }     solve(0, m - 1, 0, m - 1);     int ans = 0;     for (int i = 0; i < m; i++) {       for (int j = 0; j < m; j++) {         ans += (b[i][j] != 0);       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 2;   int pos[MAX], a[MAX];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, c = 0, k;     cin >> n;     for (int i = 1; i < n + 1; i++) cin >> k, a[k] = i, pos[i] = k;     for (int i = 1; i < n + 1; i++) {       if (pos[i] != i) {         c++;         int j = pos[i];         int k = a[i];         pos[k] = j;         a[j] = k;         a[i] = i;         pos[i] = i;       }     }     if ((3 * n + c) & 1)       cout <<  Um_nik ;     else       cout <<  Petr ;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000000], psum[1000000];   map<long long, long long> mp, pp;   vector<long long> v;   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < (2 * k + 2); i++) {         psum[i] = 0;       }       for (int i = 0; i < n / 2; i++) {         int mn = min(a[i], a[n - i - 1]);         int mx = max(a[i], a[n - i - 1]);         psum[1] += 2;         psum[mn + 1] -= 1;         psum[mn + mx] -= 1;         psum[mx + mn + 1] += 1;         psum[mx + k + 1] += 1;       }       int ans = INT_MAX, sum = 0;       for (int i = 1; i <= (2 * k + 1); i++) psum[i] += psum[i - 1];       for (int i = 1; i < (2 * k + 1); i++) ans = min(ans, psum[i]);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using vi = vector<int>;   using vvi = vector<vi>;   using ll = long long;   using vll = vector<ll>;   using vpi = vector<pair<int, int>>;   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     int speedlim = 301;     bool overtake = true;     int speed = -1;     int noovertakes = 0;     vi speedsigns(302, 0);     int ignore = 0;     for (int i = 0; i < n; ++i) {       int t;       cin >> t;       switch (t) {         case 1:           int newspeed;           cin >> newspeed;           assert(newspeed <= 300 && newspeed >= 1);           if (newspeed > speed && newspeed > speedlim) {             ignore += speedsigns[newspeed];             for (int i = newspeed + 1; i < speedsigns.size(); ++i) {               speedsigns[i] -= speedsigns[newspeed];             }             for (int i = 0; i <= newspeed; ++i) {               speedsigns[i] = 0;             }           }           speed = newspeed;           break;         case 2:           if (!overtake) {             ignore += noovertakes;             noovertakes = 0;           }           break;         case 3:           int newspeedlim;           cin >> newspeedlim;           assert(newspeedlim <= 300 && newspeedlim >= 1);           if (newspeedlim < speed)             ++ignore;           else {             for (int i = 0; i <= newspeedlim; ++i) speedsigns[i] = 0;             for (int i = newspeedlim + 1; i < speedsigns.size(); ++i)               ++speedsigns[i];           }           speedlim = newspeedlim;           break;         case 4:           overtake = true;           noovertakes = 0;           break;         case 5:           speedlim = 301;           for (int& si : speedsigns) si = 0;           break;         case 6:           overtake = false;           ++noovertakes;           break;       }     }     cout << ignore <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     cin >> n >> m >> k;     if (n <= m && n <= k) {       cout <<  YES ;     } else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<pair<string, string>, pair<int, int> > mp;   set<pair<string, string> > st;   int main() {     int n, d;     cin >> n >> d;     for (int i = 0; i < n; ++i) {       string s, q;       int x;       cin >> s >> q;       scanf( %d , &x);       if (mp.count({q, s})) {         pair<int, int> a = mp[{q, s}];         int y = x - a.first;         if (y <= d && y > 0) st.insert({min(s, q), max(s, q)});         y = x - a.second;         if (y <= d && y > 0) st.insert({min(s, q), max(s, q)});       }       if (!mp.count({s, q}))         mp[{s, q}] = {x, x};       else {         pair<int, int> a = mp[{s, q}];         if (x != a.first) a.second = a.first, a.first = x;         mp[{s, q}] = a;       }     }     cout << st.size() << endl;     for (set<pair<string, string> >::iterator it = st.begin(); it != st.end();          it++)       printf( %s %s n , it->first.c_str(), it->second.c_str());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int len[500020];   vector<int> s[500020];   vector<int> g[500020];   int col[500020];   set<int> FK;   int c;   int rt;   void dfs(int u, int p) {     if (p) {       vector<int> t;       int k = c;       for (auto v : s[u]) {         if (!col[v]) continue;         FK.erase(col[v]);         t.push_back(col[v]);       }       k = 0;       set<int>::iterator it = FK.begin();       for (auto v : s[u]) {         if (col[v]) continue;         col[v] = *it;         ++it;       }       for (auto v : t) {         FK.insert(v);       }       t.clear();     }     for (auto v : g[u]) {       if (v == p) continue;       dfs(v, u);     }   }   int main() {     scanf( %d%d , &n, &m);     rt = 0;     int tmp = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d , &len[i]);       for (int j = 1; j <= len[i]; ++j) {         int v;         scanf( %d , &v);         s[i].push_back(v);       }       if (len[i] > tmp) {         tmp = len[i], rt = i;       }     }     for (int i = 1; i < n; ++i) {       int u, v;       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     int t = 0;     for (auto v : s[rt]) {       col[v] = ++t;     }     c = max(tmp, 1);     for (int i = 1; i <= c; ++i) FK.insert(i);     dfs(rt, 0);     for (int i = 1; i <= m; ++i)       if (!col[i]) col[i] = 1;     printf( %d n , c);     for (int i = 1; i <= m; ++i) printf( %d%c , col[i], i == m ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long rate[2000002];   int n, k;   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> rate[i];     long long p = 0, c;     int del = 0;     vector<int> vec;     for (int i = 1; i <= n; i++) {       if (i - del > 1)         c = (-rate[i - 1] * ((n - del) - (i - del))) * (i - del - 1) + p;       else         c = 0;       if (c < k)         del++, vec.push_back(i);       else         p += rate[i - 1] * (i - del - 1);     }     for (int i = 0; i < vec.size(); i++) cout << vec[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct wektor {     int roz;     int *tab;     int roztab;     wektor() {       tab = new int[1];       roz = 0;       roztab = 1;     }     ~wektor() { delete[] tab; }     int size() { return roz; }     bool empty() { return roz == 0; }     void pop_back() { roz--; }     int &operator[](int ind) { return tab[ind]; }     int operator[](int ind) const { return tab[ind]; }     int back() { return tab[roz - 1]; }     void resize(int cos) {       if (cos > roztab) {         int *tmp;         tmp = new int[2 * cos];         for (int i = 0; i < roz; i++) {           tmp[i] = tab[i];         }         delete[] tab;         tab = tmp;         roztab = 2 * cos;       } else {         if (cos < roz) {           roz = cos;         }       }     }     void push_back(int elem) {       resize(roz + 1);       tab[roz] = elem;       roz = roz + 1;       ;     }   };   wektor slo[100005];   int vis[100005];   int gleb[100005];   double wynik;   void dfs(int v, int g) {     wynik += double(1) / g;     vis[v] = 1;     for (int i = 0; i < slo[v].size(); i++) {       int aktv = slo[v][i];       if (vis[aktv] == 0) {         dfs(aktv, g + 1);       }     }   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n - 1; i++) {       int a, b;       cin >> a >> b;       slo[a].push_back(b);       slo[b].push_back(a);     }     dfs(1, 1);     printf( %.7lf n , wynik);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double kEps(1e-8);   #pragma gcc optimize(2)   int gcd(int x, int y) {     while (y ^= x ^= y ^= x %= y)       ;     return x;   }   void write(int x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   int qpow(int m, int n) {     int res = 1;     while (n) {       if (n & 1) {         res *= m;       }       n >>= 1;       m *= m;     }     return res;   }   int max(int a, int b) {     if (a > b) {       return a;     } else       return b;   }   int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x * f;   }   signed main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long ans = 1;       map<long long, long long> mp;       for (long long i = 2; i < n; ++i) {         if (i * i > n) {           break;         } else {           if (i * i <= n) {             ans++;           }           if (i * i * i <= n) {             ans++;           }           mp[i * i]++;           mp[i * i * i]++;         }       }       long long temp = 0;       for (auto it : mp) {         if (it.second > 1) {           temp++;         }       }       mp.clear();       cout << ans - temp <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int SIZE = 100005;   const int MSIZE = 10000;   const int INF = 1 << 30;   set<int>::iterator it;   int main() {     int n, a, b;     int p[SIZE];     set<int> fi, se;     map<int, int> mp;     bool flag[SIZE];     while (cin >> n >> a >> b) {       fi.clear(), se.clear(), mp.clear();       memset(flag, 0, sizeof(flag));       for (int i = 0; i < n; i++) {         scanf( %d , &p[i]);         fi.insert(p[i]);         mp[p[i]] = i;       }       vector<int> v;       for (it = fi.begin(); it != fi.end(); it++) {         if (fi.find(a - *it) == fi.end()) {           se.insert(*it);           v.push_back(*it);         }       }       for (int i = 0; i < v.size(); i++) {         fi.erase(v[i]);         se.insert(v[i]);       }       bool mark = 0;       while (!se.empty()) {         it = se.begin();         int x = *it;         if (se.find(b - x) != se.end()) {           flag[mp[x]] = flag[mp[b - x]] = 1;           se.erase(x);           if ((x)*2 != b) se.erase(b - x);         } else if (fi.find(b - x) != fi.end()) {           flag[mp[x]] = flag[mp[b - x]] = 1;           fi.erase(b - x);           se.erase(x);           if ((b - x) * 2 != a) {             fi.erase(a - (b - x));             se.insert(a - (b - x));           }         } else {           puts( NO );           mark = 1;           break;         }       }       if (mark) continue;       puts( YES );       for (int i = 0; i < n; i++) printf( %d  , flag[i]);       puts(  );     }   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     int n, a, d;     cin >> n >> a >> d;     int t, v;     double T, P = 0, D;     while (n--) {       cin >> t >> v;       T = 1.0 * v / a;       if (T * v <= 2 * d) {         D = (1.0 * d - T * v * 0.5) / v;         T = T + D;       } else {         T = sqrt(2.0 * d / a);       }       T += t;       if (T < P) T = P;       printf( %.7f n , T);       P = T;     }     return EXIT_SUCCESS;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   long long fac[2000001];   long long PowMod(long long a, long long b, long long mod) {     long long ret = 1LL;     while (b) {       if (b & 1) ret = (ret * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return ret;   }   void cfac() {     fac[0] = 1;     for (long long i = 1; i <= 200000; i++) fac[i] = i * fac[i - 1] % mod;   }   long long Lucas(long long n, long long m, long long p = mod) {     long long ret = 1;     if (n == 0) return 1;     while (n && m) {       long long a = n % p, b = m % p;       if (a < b) return 0;       ret = (ret * fac[a] * PowMod(fac[b] * fac[a - b] % p, p - 2, p)) % p;       n /= p;       m /= p;     }     return ret;   }   long long pre[2002][2002];   long long dp[2002];   struct data {     long long x, y;     bool operator<(const data& b) const { return y == b.y ? x < b.x : y < b.y; }   } Q[2002];   int main() {     ios::sync_with_stdio(0);     cfac();     int h, w, n, l;     cin >> h >> w >> n;     for (int i = 0; i < n; i++) {       cin >> Q[i].x >> Q[i].y;     }     sort(Q, Q + n);     long long ans = 0LL;     for (int i = 0; i < n; i++) {       dp[i] += Lucas(Q[i].x - 1 + Q[i].y - 1, Q[i].x - 1);       dp[i] %= mod;       if (dp[i] < 0) dp[i] += mod;       for (int j = i + 1; j < n; j++) {         if (Q[j].x < Q[i].x) continue;         long long temp =             Lucas(Q[j].x + Q[j].y - Q[i].y - Q[i].x, Q[j].x - Q[i].x);         pre[i][j] = temp;         dp[j] -= temp * dp[i];         dp[j] %= mod;         if (dp[j] < 0) dp[j] += mod;       }     }     long long temp = Lucas(h + w - 2, h - 1);     for (int i = n - 1; i >= 0; i--) {       temp -= dp[i] * Lucas(h + w - Q[i].x - Q[i].y, h - Q[i].x);       temp %= mod;       if (temp < 0) temp += mod;       temp %= mod;       if (temp < 0) temp += mod;     }     cout << temp << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1002][102];   int main() {     int n, m, k, x;     cin >> n >> m >> k;     cout << m * (m - 1) / 2 << endl;     for (int i = 0; i < m; i++) {       for (int j = i + 1; j < m; j++) {         if (!k)           cout << i + 1 <<     << j + 1 << endl;         else           cout << j + 1 <<     << i + 1 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.precision(10);     int n;     cin >> n;     int m;     cin >> m;     std::vector<std::vector<long long> > re(n, std::vector<long long>(m, 0));     long long ta = 0;     for (int i = 0; i < n; ++i) {       cin >> re[i][0];       ta ^= re[i][0];     }     long long tb = 0;     long long a;     for (int i = 0; i < m; ++i) {       cin >> a;       re[0][i] ^= a;       tb ^= a;     }     if (tb != ta) {       cout <<  NO ;       exit(0);     }     re[0][0] ^= ta;     cout <<  YES n ;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) cout << re[i][j] <<   n  [j != m - 1];   }


#include <bits/stdc++.h>   using namespace std;   template <class htpe, class cmp>   using heap = priority_queue<htpe, vector<htpe>, cmp>;   template <class htpe>   using min_heap = heap<htpe, greater<htpe> >;   template <class htpe>   using max_heap = heap<htpe, less<htpe> >;   const int INF = 1791791791;   const long long INFLL = 1791791791791791791ll;   bool query(int x, int y) {     cout << 1 <<     << x <<     << y << endl;     cout.flush();     string s;     cin >> s;     return s ==  TAK ;   }   bool is_two_answers(int a, int b) { return query(a, b) && query(b, a); }   int find_on_segment(int l, int r, int tr) {     l--;     while (l < r - 1) {       int mid = (l + r + tr) >> 1;       if (!query(mid, mid + 1))         l = mid;       else         r = mid;     }     return r;   }   int main() {     int n, k;     cin >> n >> k;     int a = find_on_segment(1, n, 0);     int b = find_on_segment(a + 1, n, 1);     if (a + 1 > n || !is_two_answers(a, b)) b = find_on_segment(1, a - 1, 0);     cout << 2 <<     << a <<     << b << endl;     cout.flush();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string to_string(const string& s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (long long i = 0; i < static_cast<long long>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <class A, class B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <class A, class B, class C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <class A, class B, class C, class D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   template <class A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <class Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << to_string(arg1) <<   n ;   }   template <class Arg1, class... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << to_string(arg1) <<   |  ;     __f(comma + 1, args...);   }   const long long inf = (long long)4e18;   long long sum(long long x) {     long long s = 0;     for (; x; x /= 10) {       s += (x % 10);     }     return s;   }   long long to_int(string s) {     long long res = 0;     for (long long i = 0; i < (long long)s.size(); i++) {       res *= 10;       res += s[i] -  0 ;     }     return res;   }   void solve() {     long long n, k;     cin >> n >> k;     long long ans = inf;     for (long long d = 0; d < 10; d++) {       for (long long cnt = 0; cnt < 18; cnt++) {         long long cur = cnt * 9 + d;         if (cur > n) break;         long long x = 0;         for (long long i = 0; i < cnt; i++) {           x += 9;           x *= 10;         }         x += d;         long long su = 0;         for (long long i = 0; i <= k; i++) {           su += sum(x + i);         }         69;         su -= max(0LL, k + 1 - (10 - d));         if (su > n) continue;         for (long long d1 = 0; d1 < 9; d1++) {           long long p = min(k + 1, 10 - d);           long long new_su = su + d1 * p + (d1 + 1) * (k + 1 - p);           if (new_su > n) continue;           if (new_su == n) {             if (d1 > 0) {               string tmp = to_string(d1) + to_string(x);               ans = min(ans, to_int(tmp));             } else {               ans = min(ans, x);             }             continue;           }           long long rem = n - new_su;           if (rem % (k + 1) != 0) continue;           rem /= (k + 1);           long long f = rem % 9;           rem -= f;           for (long long it = 0; it < rem / 9; it++) {             f *= 10;             f += 9;           }           if (f > 0) {             f *= 10;             f += d1;           }           69;           if (f == 0) {             ans = min(ans, x);           } else {             string q = to_string(f) + to_string(x);             ans = min(ans, to_int(q));           }         }       }     }     if (ans == inf) {       cout <<  -1 n ;     } else {       cout << ans <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     long long tt;     cin >> tt;     while (tt--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 13e9;   const long long dd = 1e6 + 7;   int main() {     int n, s, r = -1;     cin >> n >> s;     s *= 100;     for (int i = 0; i < (long long)n; i++) {       int x, y;       cin >> x >> y;       x = x * 100 + y;       if (x <= s) r = max((100 - y) % 100, r);     }     cout << r;   }


#include <bits/stdc++.h>   using namespace std;   long double PI = acosl(-1);   bool compare_int(int a, int b) { return (a > b); }   bool compare_string(string a, string b) { return a.size() < b.size(); }   bool compare_pair(const pair<int, int> &a, const pair<int, int> &b) {     if (a.second == b.second)       return a.first < b.first;     else       return (a.second > b.second);   }   bool cmp(pair<string, int> x, pair<string, int> y) {     return (x.second < y.second);   }   void NA() {     printf( NO n );     exit(0);   }   void YA() {     printf( YES n );     exit(0);   }   const int N = 300005;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, x, y, q;     cin >> n;     int sz = sqrt(n);     long long int a[n + 1], tmp[n + 1];     for (int i = 0; i < n; i++) cin >> a[i];     cin >> q;     vector<long long int> res(q);     vector<pair<int, pair<int, int> > > v;     for (int i = 0; i < q; i++) {       cin >> x >> y;       v.push_back({y, {x, i}});     }     sort(v.begin(), v.end());     int pre = -1;     for (int i = 0; i < q; i++) {       x = v[i].second.first - 1;       y = v[i].first;       int id = v[i].second.second;       if (y >= sz) {         for (int i = x; i < n; i += y) res[id] += a[i];       } else {         if (pre != y) {           memset(tmp, 0, sizeof tmp);           for (int i = n - 1; i >= 0; i--) {             tmp[i] += a[i];             if (i + y < n) tmp[i] += tmp[i + y];           }           pre = y;         }         res[id] = tmp[x];       }     }     for (int i = 0; i < q; i++) {       cout << res[i] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   set<int> st[2];   map<int, int> mp;   int ar[110];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> ar[i];       mp[ar[i]]++;     }     int idx = 0;     map<int, int>::iterator it1;     for (it1 = mp.begin(); it1 != mp.end(); it1++) {       if (it1->second == 1) {         st[idx].insert(it1->first);         idx = !idx;       }     }     if (st[0].size() == st[1].size()) {       string ans(n,  A );       for (int i = 0; i < n; i++) {         if (st[1].count(ar[i])) ans[i] =  B ;       }       cout <<  YES n ;       for (int i = 0; i < n; i++) cout << ans[i];       return 0;     } else {       string res(n,  A );       for (int i = 0; i < n; i++) {         if (st[1].count(ar[i])) {           res[i] =  B ;         }       }       int id = -1;       map<int, int>::iterator it;       for (it = mp.begin(); it != mp.end(); it++) {         if (it->second >= 3) {           id = it->first;           break;         }       }       if (id == -1) {         cout <<  NO ;         return 0;       }       bool flag = false;       for (int i = 0; i < n; i++) {         if (ar[i] == id) {           if (!flag) {             flag = true;             res[i] =  B ;           }         }       }       cout <<  YES n ;       for (int i = 0; i < n; i++) {         cout << res[i];       }       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int len;   set<string> v;   bool check[111111][5];   void fuck(string father, int now) {     if (now - 2 > 4) {       string now1 = s.substr(now - 2, 2);       if (now1 != father) {         v.insert(now1);         if (check[now - 2][2] == true)           check[now - 2][2] = false, fuck(now1, now - 2);       }     }     if (now - 3 > 4) {       string now2 = s.substr(now - 3, 3);       if (now2 != father) {         v.insert(now2);         if (check[now - 3][3] == true)           check[now - 3][3] = false, fuck(now2, now - 3);       }     }   }   int main() {     cin >> s;     memset(check, true, sizeof(check));     len = s.length();     fuck(  , len);     cout << v.size() << endl;     for (set<string>::iterator it = v.begin(); it != v.end(); it++)       cout << *it << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline char nc() {     return getchar();     static char buf[100000], *l = buf, *r = buf;     return l == r && (r = (l = buf) + fread(buf, 1, 100000, stdin), l == r)                ? EOF                : *l++;   }   template <class T>   void read(T &x) {     x = 0;     int f = 1, ch = nc();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = nc();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 -  0  + ch;       ch = nc();     }     x *= f;   }   int N, M, D, A[100050][50];   int cnt, id[100050][50];   pair<int, int> bel[5000050];   int head[5000050];   int head1[5000050];   struct edge {     int to, nex;     edge(int to = 0, int nex = 0) : to(to), nex(nex) {}   };   vector<edge> G;   vector<edge> G1;   inline void addedge(int u, int v) {     G.push_back(edge(v, head[u])), head[u] = G.size() - 1;   }   inline void addedge1(int u, int v) {     G1.push_back(edge(v, head1[u])), head1[u] = G1.size() - 1;   }   int dfn[5000050], low[5000050], dfc;   int sccno[5000050], val[5000050], scnt;   int vis[100050];   int stk[5000050], top;   void tarjan(int u) {     low[u] = dfn[u] = ++dfc;     stk[++top] = u;     for (int i = head[u]; ~i; i = G[i].nex) {       int v = G[i].to;       if (!dfn[v]) {         tarjan(v);         low[u] = min(low[u], low[v]);       } else if (!sccno[v]) {         low[u] = min(low[u], dfn[v]);       }     }     if (low[u] == dfn[u]) {       ++scnt;       while (true) {         int x = stk[top--];         sccno[x] = scnt;         int a = bel[x].first, b = bel[x].second;         if (A[a][b] && vis[a] != scnt) {           vis[a] = scnt;           ++val[scnt];         }         if (x == u) break;       }     }   }   void find_scc() {     for (int i = 1; i <= cnt; ++i)       if (!dfn[i]) {         tarjan(i);       }     memset(head1, -1, sizeof(head1));     for (int u = 1; u <= cnt; ++u) {       for (int i = head[u]; ~i; i = G[i].nex) {         int v = G[i].to;         if (sccno[u] != sccno[v]) {           addedge1(sccno[u], sccno[v]);         }       }     }   }   int f[5000050];   void dp(int u) {     if (f[u]) return;     for (int i = head1[u]; ~i; i = G1[i].nex) {       int v = G1[i].to;       dp(v);       f[u] = max(f[u], f[v]);     }     f[u] += val[u];   }   int solve() {     find_scc();     int u = sccno[id[1][0]];     dp(u);     return f[u];   }   char str[60];   int main() {     read(N), read(M), read(D);     for (int i = 1; i <= N; ++i) {       for (int j = 0; j < D; ++j) {         id[i][j] = ++cnt;         bel[cnt] = pair<int, int>(i, j);       }     }     memset(head, -1, sizeof(head));     for (int i = 1; i <= M; ++i) {       int u, v;       read(u), read(v);       for (int j = 1; j < D; ++j) {         addedge(id[u][j - 1], id[v][j]);       }       addedge(id[u][D - 1], id[v][0]);     }     for (int i = 1; i <= N; ++i) {       scanf( %s , str);       for (int j = 0; j < D; ++j) {         A[i][j] = str[j] ==  1 ;       }     }     printf( %d n , solve());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mn = 1e6 + 10;   int a[mn * 3];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) a[i] = i;     for (int i = 2; i <= n; i++) {       int v = a[i - 1];       for (int j = i - 1; j < n + i - 1; j += i) {         swap(v, a[min(j + i, n + i - 1)]);       }     }     for (int i = n; i <= n + n - 1; i++) printf( %d  , a[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 106, INF = 0x3f3f3f3f;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, a[N << 1];   int couple[N][2];   int main() {     n = read();     for (int i = 1; i <= n << 1; i++) {       a[i] = read();       if (!couple[a[i]][0])         couple[a[i]][0] = i;       else         couple[a[i]][1] = i;     }     int ans = 0;     for (int i = 1; i <= (n << 1); i += 2) {       if (a[i] == a[i + 1])         continue;       else {         ans += couple[a[i]][1] - couple[a[i]][0] - 1;         for (int j = couple[a[i]][1] - 1; j >= i; j--)           if (couple[a[j]][0] == j)             a[++couple[a[j]][0]] = a[j];           else             a[++couple[a[j]][1]] = a[j];         a[couple[a[i]][1] = i + 1] = a[i];       }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long fact[1000001];   long long pow(long long a, long long b, long long m) {     long long ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans;   }   long long modinv(long long k) { return pow(k, 998244353 - 2, 998244353); }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     fact[0] = 1;     for (long long i = 1; i < 1000001; i++)       fact[i] = (fact[i - 1] * i) % 998244353;     long long ans = 0;     ans += fact[n];     if (n - 2 > 0) ans = (ans + (n - 2) * fact[n]) % 998244353;     for (long long i = 1; i < n - 1; i++) {       ans = (ans - fact[n] * modinv(fact[n - i])) % 998244353;     }     cout << (ans + 998244353) % 998244353 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100010], cewa, now;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     now = 0;     for (int i = 0; i < n; i++) {       if (now > a[i]) {         cewa++;         now -= a[i];       }       now += a[i];     }     cout << n - cewa <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int destroy(list<int> row) {     int totalDestroyed = 0, lastDestroyed = -1;     int combo = 1;     while (lastDestroyed != 0) {       lastDestroyed = 0;       combo = 1;       list<int>::iterator it = row.begin();       list<int>::iterator prev = it++;       for (; it != row.end(); ++it) {         if (*prev == *it) {           combo++;         } else {           if (combo >= 3) {             it = row.erase(prev, it);             lastDestroyed += combo;           }           prev = it;           combo = 1;         }       }       totalDestroyed += lastDestroyed;     }     totalDestroyed += (combo >= 3 ? combo : 0);     return totalDestroyed > 0 ? totalDestroyed - 1 : 0;   }   int main() {     int N, K, X;     cin >> N >> K >> X;     list<int> row;     int ball;     for (int i = 0; i < N; ++i) {       cin >> ball;       row.push_back(ball);     }     int maxDestroyed = 0;     for (list<int>::iterator it = row.begin(); it != row.end(); ++it) {       it = row.insert(it, X);       int destroyed = destroy(row);       maxDestroyed = max(maxDestroyed, destroyed);       it = row.erase(it);     }     cout << maxDestroyed;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 112;   const long long mod = 1e9 + 7;   int R;   long long p1, p2, p3, p4, s;   int lim[N];   long long F[N][N];   long long ksm(long long a, long long b = mod - 2) {     long long ret = 1;     for (; b; b >>= 1, a = a * a % mod)       if (b & 1) ret = ret * a % mod;     return ret;   }   struct node {     long long a[N];     node() { memset(a, 0, sizeof a); }   } a[N][N];   node operator*(long long x, node a) {     node c;     for (int i = 0; i <= 2 * R + 1; i++) c.a[i] = a.a[i] * x % mod;     return c;   }   node operator+(node a, node b) {     node c;     for (int i = 0; i <= 2 * R + 1; i++) c.a[i] = (a.a[i] + b.a[i]) % mod;     return c;   }   node operator-(node a, node b) {     node c;     for (int i = 0; i <= 2 * R + 1; i++) c.a[i] = (a.a[i] - b.a[i] + mod) % mod;     return c;   }   void solve() {     int n = 2 * R;     for (int i = 0; i <= n; i++) {       int maxx = i;       for (int j = i + 1; j <= n; j++)         if (abs(F[j][i]) > abs(F[maxx][i])) maxx = j;       swap(F[maxx], F[i]);       for (int j = 0; j <= n; j++) {         if (j != i) {           long long x = F[j][i] * ksm(F[i][i]) % mod;           for (int k = i; k <= n + 1; k++)             F[j][k] = (F[j][k] - F[i][k] * x) % mod;         }       }     }     for (int i = 0; i <= n; i++) F[i][n + 1] = F[i][n + 1] * ksm(F[i][i]) % mod;   }   int main() {     scanf( %d%lld%lld%lld%lld , &R, &p1, &p2, &p3, &p4);     s = p1 + p2 + p3 + p4;     s = ksm(s);     p1 = p1 * s % mod;     p2 = p2 * s % mod;     p3 = p3 * s % mod;     p4 = p4 * s % mod;     int T = R + 3;     p4 = ksm(p4);     for (int i = 0; i <= R; i++)       for (int j = 0; j * j + i * i <= R * R; j++) lim[i] = j;     for (int j = -R; j <= R + 1; j++)       for (int i = -R; i <= R; i++) {         int lt = lim[abs(i)];         if (j == -lt)           a[i + T][-lt + T].a[i + R] = 1;         else if (j > -lt && j <= lt + 1) {           a[i + T][j + T] =               (a[i + T][j - 1 + T] - p1 * a[i - 1 + T][j - 1 + T] -                p2 * a[i + T][j - 2 + T] - p3 * a[i + 1 + T][j - 1 + T]);           (a[i + T][j + T].a[2 * R + 1])--;           (a[i + T][j + T].a[2 * R + 1]) = (a[i + T][j + T].a[2 * R + 1]) % mod;           a[i + T][j + T] = p4 * a[i + T][j + T];         }       }     for (int i = -R; i <= R; i++) {       for (int j = 0; j <= 2 * R + 1; j++)         F[i + R][j] = a[i + T][lim[abs(i)] + 1 + T].a[j];       F[i + R][2 * R + 1] = -F[i + R][2 * R + 1];     }     solve();     long long ans = 0;     for (int i = 0; i <= 2 * R; i++)       ans = (ans + a[T][T].a[i] * F[i][2 * R + 1]) % mod;     ans = (ans + a[T][T].a[2 * R + 1]) % mod;     ans = (ans + mod) % mod;     cout << ans;     return 0;   }