#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000005;   const int inf = 0x3f3f3f3f;   long long a[maxn];   int q[maxn];   int main() {     int n;     cin >> n;     long long p = 0;     long long pans = 0;     for (int i = (1); i < (n + 1); i++) {       cin >> a[i];       pans += abs(a[i] - i);       if (i < a[i]) {         p++;         q[a[i] - i]--;       }     }     long long ans1 = pans, ans2 = 0;     int cur = n;     for (int i = (1); i < (n + 1); i++) {       pans -= p;       pans += n - p - 1;       pans = pans - abs(a[cur] - n) + abs(a[cur] - 1);       if (ans1 > pans) ans1 = pans, ans2 = i;       p += q[i];       if (1 < a[cur]) {         p++;         q[a[cur] - 1 + i]--;       }       cur--;     }     cout << ans1 <<     << ans2 << endl;     return 0;   }


#include <bits/stdc++.h>   int main(void) {     int n;     char s[102];     scanf( %d n , &n);     gets(s);     if (s[0] ==  S  && s[n - 1] ==  F ) {       printf( YES );     } else {       printf( NO );     }   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e5 + 7;   const long long mod = 1e9 + 7;   const long long INF = 1e9 + 7;   const long long mlog = 22;   const long long SQ = 400;   long long T[maxn * 4];   long long a[maxn], b[maxn];   long long x[maxn], y[maxn], k[maxn];   void add(long long L, long long R, long long col, long long l, long long r,            long long id) {     if (r == R && l == L) {       T[id] = col;       return;     }     long long mid = (l + r) / 2;     if (L < mid) add(L, min(mid, R), col, l, mid, 2 * id + 0);     if (R > mid) add(max(L, mid), R, col, mid, r, 2 * id + 1);   }   long long get(long long idx, long long l, long long r, long long id) {     if (r - l <= 1) return T[id];     long long mid = (l + r) / 2;     if (idx < mid)       return max(T[id], get(idx, l, mid, 2 * id + 0));     else       return max(T[id], get(idx, mid, r, 2 * id + 1));   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(), cout.tie();     long long n, m;     cin >> n >> m;     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = 1; i <= n; i++) cin >> b[i];     long long t;     for (long long i = 1; i <= m; i++) {       cin >> t;       if (t == 1) {         cin >> x[i] >> y[i] >> k[i];         add(y[i], y[i] + k[i], i, 1, n + 1, 1);       } else {         long long index;         cin >> index;         long long next = get(index, 1, n + 1, 1);         if (next == 0)           cout << b[index] <<   n ;         else           cout << a[x[next] + index - y[next]] <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   vector<pair<int, int> > VX[5];   vector<pair<int, int> > VY[5];   int X[101010];   int Y[101010];   int C[101010];   void ref() {     for (int i = 1; i <= N; i++) swap(X[i], Y[i]);   }   bool f(int m, int a, int b, int c) {     int x1 = VX[a][m - 1].first + 1;     int x2 = VX[c][N / 3 - m].first - 1;     int cnt = 0;     for (auto& i : VX[b]) {       if (x1 <= i.first && i.first <= x2) cnt++;     }     return cnt >= m;   }   bool g(int m, int a, int b, int c) {     int y = VY[c][m - 1].second + 1;     int x;     int cnt = 0;     for (auto& i : VX[a]) {       if (i.second < y) continue;       cnt++;       if (cnt >= m) {         x = i.first + 1;         break;       }     }     if (cnt < m) return false;     cnt = 0;     for (auto& i : VX[b]) {       if (i.second >= y && i.first >= x) cnt++;     }     return cnt >= m;   }   bool h(int m, int a, int b, int c) {     int y = VY[c][N / 3 - m].second - 1;     int x;     int cnt = 0;     for (auto& i : VX[a]) {       if (i.second > y) continue;       cnt++;       if (cnt >= m) {         x = i.first + 1;         break;       }     }     if (cnt < m) return false;     cnt = 0;     for (auto& i : VX[b]) {       if (i.second <= y && i.first >= x) cnt++;     }     return cnt >= m;   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       scanf( %d%d%d , &X[i], &Y[i], &C[i]);     }     int l = 1, r = N / 3;     while (l <= r) {       int m = l + r >> 1;       bool ok = false;       for (int z = 0; z < 2; z++) {         for (int i = 1; i <= 3; i++) {           VX[i].clear();           VY[i].clear();         }         for (int i = 1; i <= N; i++) {           VX[C[i]].emplace_back(X[i], Y[i]);           VY[C[i]].emplace_back(X[i], Y[i]);         }         for (int i = 1; i <= 3; i++) {           sort(VX[i].begin(), VX[i].end());           sort(VY[i].begin(), VY[i].end(),                [&](const pair<int, int> a, const pair<int, int> b) {                  return a.second < b.second;                });         }         if (f(m, 1, 2, 3)) {           ok = true;           break;         }         if (f(m, 1, 3, 2)) {           ok = true;           break;         }         if (f(m, 2, 1, 3)) {           ok = true;           break;         }         if (f(m, 2, 3, 1)) {           ok = true;           break;         }         if (f(m, 3, 1, 2)) {           ok = true;           break;         }         if (f(m, 3, 2, 1)) {           ok = true;           break;         }         if (g(m, 1, 2, 3)) {           ok = true;           break;         }         if (g(m, 1, 3, 2)) {           ok = true;           break;         }         if (g(m, 2, 1, 3)) {           ok = true;           break;         }         if (g(m, 2, 3, 1)) {           ok = true;           break;         }         if (g(m, 3, 1, 2)) {           ok = true;           break;         }         if (g(m, 3, 2, 1)) {           ok = true;           break;         }         if (h(m, 1, 2, 3)) {           ok = true;           break;         }         if (h(m, 1, 3, 2)) {           ok = true;           break;         }         if (h(m, 2, 1, 3)) {           ok = true;           break;         }         if (h(m, 2, 3, 1)) {           ok = true;           break;         }         if (h(m, 3, 1, 2)) {           ok = true;           break;         }         if (h(m, 3, 2, 1)) {           ok = true;           break;         }         ref();       }       if (ok)         l = m + 1;       else         r = m - 1;     }     printf( %d n , r * 3);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, w, h;   set<int> Set[2];   set<int>::iterator iter;   priority_queue<int> qu[2];   int vis[2][200010], point[2][200010];   char s[10];   int main() {     int i, j, k, l, r, p, a, b;     long long ans;     scanf( %d%d%d , &w, &h, &k);     Set[0].insert(0);     Set[0].insert(h);     Set[1].insert(0);     Set[1].insert(w);     point[0][h] = 0;     point[1][w] = 0;     qu[0].push(h);     qu[1].push(w);     for (i = 1; i <= k; i++) {       scanf( %s%d , s, &p);       if (s[0] ==  H ) {         iter = Set[0].lower_bound(p);         r = *iter;         l = point[0][r];         vis[0][r - l]++;         qu[0].push(r - p);         qu[0].push(p - l);         point[0][r] = p;         point[0][p] = l;         Set[0].insert(p);       } else {         iter = Set[1].lower_bound(p);         r = *iter;         l = point[1][r];         vis[1][r - l]++;         qu[1].push(r - p);         qu[1].push(p - l);         point[1][r] = p;         point[1][p] = l;         Set[1].insert(p);       }       while (true) {         a = qu[0].top();         if (vis[0][a] == 0) break;         vis[0][a]--;         qu[0].pop();       }       while (true) {         b = qu[1].top();         if (vis[1][b] == 0) break;         vis[1][b]--;         qu[1].pop();       }       ans = (long long)a * (long long)b;       printf( %I64d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   const int mod = 1e9 + 7;   vector<int> vec[350];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int k = 1;     for (int i = 1; i <= n; ++i) {       if (i & 1) {         for (int j = 1; j <= n; ++j) vec[j].push_back(k++);       } else {         for (int j = n; j >= 1; j--) vec[j].push_back(k++);       }     }     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) printf( %d%c , vec[i][j - 1],    n [j == n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Tp>   inline void outarr(Tp _begin, Tp _end, const char* _delim =    ) {     for (Tp current = _begin; current != _end; ++current) {       std::cout << *current << _delim;     }     std::cout <<   n ;   }   using ll = long long;   using pii = std::pair<int, int>;   constexpr int INF = 0x3f3f3f3f;   constexpr int MOD = static_cast<const int>(1e9 + 7);   constexpr int g_mod = 998244353;   int arr[200000];   int fact[200001];   int ifact[200001];   int Add(int x, int y) {     x += y;     return x < g_mod ? x : x - g_mod;   }   int Sub(int x, int y) {     x -= y;     return x >= 0 ? x : x + g_mod;   }   int Mul(int x, int y) { return int(1LL * x * y % g_mod); }   int FastPow(int x, int p) {     int res = 1;     while (p > 0) {       if (p & 1) {         res = Mul(res, x);       }       p >>= 1;       x = Mul(x, x);     }     return res;   }   int Inv(int x) { return FastPow(x, g_mod - 2); }   void Init(int n) {     fact[0] = 1;     for (int i = 1; i <= n; ++i) {       fact[i] = Mul(i, fact[i - 1]);     }     ifact[n] = Inv(fact[n]);     for (int i = n - 1; i >= 0; --i) {       ifact[i] = Mul(i + 1, ifact[i + 1]);     }   }   int C(int k, int n) { return Mul(fact[n], Mul(ifact[k], ifact[n - k])); }   int Func(int len) {     if (len & 1) {       return 0;     }     return C(len >> 1, len);   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     int n, k;     cin >> n >> k;     Init(n);     for (int i = 0; i < (n); ++i) {       cin >> arr[i];     }     int len = distance(arr, unique(arr, arr + n));     if (arr[0] == arr[len - 1]) {       --len;     }     if (len == 0) {       return cout << (0) <<   n , 0;       ;     }     const int inv2 = Inv(2);     int k2 = (k - 2) % g_mod;     int ans = 0;     for (int i = 0; i < (len); ++i) {       int cur =           Mul(Sub(FastPow(2, len - i - 1), Mul(Func(len - i), inv2)), C(i, len));       ans = Add(ans, Mul(FastPow(k2, i), cur));     }     ans = Mul(ans, FastPow(k % g_mod, n - len));     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fastxp(long long b, long long e) {     if (e == 1)       return b;     else {       long long ans = fastxp(b, e / 2);       ans = (ans * ans) % 998244353;       if (e % 2 == 1) {         ans = (ans * b) % 998244353;       }       return ans;     }   }   int main() {     ios::sync_with_stdio(false);     long long i, j, l, r;     cin >> i >> j >> l >> r;     long long v = fastxp(r - l + 1, i * j);     if ((i * j) % 2 == 1) {       cout << v << endl;     } else {       if ((r - l) % 2 == 1) {         cout << (v * fastxp(2, 998244353 - 2)) % 998244353 << endl;       } else {         cout << ((v + 1) * fastxp(2, 998244353 - 2)) % 998244353 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   const int N = 3e5 + 7;   const int LG = 19;   int go[N][LG];   int a[N];   int last[LG];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, q;     cin >> n >> q;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int j = 0; j < LG; j++) {       go[n][j] = n;       last[j] = n;     }     for (int i = n - 1; i >= 0; i--) {       for (int j = 0; j < LG; j++) {         go[i][j] = n;       }       for (int j = 0; j < LG; j++) {         if ((a[i] >> j) & 1) {           for (int k = 0; k < LG; k++) {             go[i][k] = min(go[i][k], go[last[j]][k]);           }           last[j] = i;           go[i][j] = i;         }       }     }     for (int i = 0; i < q; i++) {       int x, y;       cin >> x >> y;       x--, y--;       bool good = false;       for (int j = 0; j < LG; j++) {         good |= (((a[y] >> j) & 1) && go[x][j] <= y);       }       cout << (good ?  Shi  :  Fou ) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 9;   const long long maxn = 3e2 + 9;   long long a[maxn][maxn];   pair<long long, long long> q[N];   long long front, rear;   long long dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   bool vis[maxn][maxn];   void solve() {     memset(vis, 0, sizeof(vis));     long long n, m;     cin >> n >> m;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= m; j++) {         cin >> a[i][j];       }     }     if (a[1][1] > 2 || a[n][m] > 2 || a[1][m] > 2 || a[n][1] > 2) {       cout <<  NO  << endl;       return;     }     a[1][1] = a[n][m] = a[1][m] = a[n][1] = 2;     for (long long i = 2; i <= n - 1; i++) {       if (a[i][1] > 3 || a[i][m] > 3) {         cout <<  NO  << endl;         return;       } else {         a[i][1] = a[i][m] = 3;       }     }     for (long long i = 2; i <= m - 1; i++) {       if (a[1][i] > 3 || a[n][i] > 3) {         cout <<  NO  << endl;         return;       } else {         a[1][i] = a[n][i] = 3;       }     }     for (long long i = 2; i <= n - 1; i++) {       for (long long j = 2; j <= m - 1; j++) {         if (a[i][j] > 4) {           cout <<  NO  << endl;           return;         } else {           a[i][j] = 4;         }       }     }     cout <<  YES  << endl;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= m; j++) {         cout << a[i][j] <<    ;       }       cout << endl;     }   }   signed main() {     long long _;     cin >> _;     while (_--) solve();   }


#include <bits/stdc++.h>   using namespace std;   long long mod;   long long power(long long a, long long p) {     long long res = 1;     while (p) {       if (p & 1) res = res * a % mod;       a = a * a % mod;       p >>= 1;     }     return res;   }   long long inv(long long a) { return power(a, mod - 2); }   class matrix {    public:     vector<vector<long long>> a;     int n;     matrix() {}     matrix(int n) { init(n); }     void init(int n) {       this->n = n;       a.resize(n);       for (int i = 0; i < n; i++) a[i].resize(n, 0);     }     long long getDigonal() {       long long res = 1;       for (int i = 0; i < n; i++) res = res * a[i][i] % mod;       return res;     }   };   const int dy[4] = {-1, -1, 1, 1}, dx[4] = {-1, 1, -1, 1};   const int cy[4] = {-1, -1, 0, 0}, cx[4] = {-1, 0, -1, 0};   const int bn[4] = {1, 0, 0, 1};   int n, m, vis[201][201], g = 0, arr[201][201];   char str[201][201];   bool go(int y, int x, int i, int j) {     return y >= 0 && x >= 0 && y <= n && x <= m && i >= 0 && j >= 0 && i < n &&            j < m;   }   void bfs(int si, int sj) {     queue<pair<int, int>> que;     que.push(pair<int, int>(si, sj));     vis[si][sj] = g;     while (!que.empty()) {       int i = que.front().first, j = que.front().second;       que.pop();       for (int k = 0; k < 4; k++) {         int yy = i + dy[k], xx = j + dx[k];         int ii = i + cy[k], jj = j + cx[k];         if (go(yy, xx, ii, jj) && vis[yy][xx] == -1 && arr[ii][jj] == bn[k]) {           vis[yy][xx] = g;           que.push(pair<int, int>(yy, xx));         }       }     }   }   long long LU_Det(matrix a) {     int n = a.n;     long long res = 1;     matrix U = a, L(n);     for (int i = 0; i < n; i++) {       for (int k = i; k < n; k++)         if (U.a[k][i] != 0) {           if (k != i) {             swap(U.a[i], U.a[k]);             res = res * (mod - 1) % mod;           }           break;         }       long long val = inv(U.a[i][i]);       L.a[i][i] = U.a[i][i];       res = res * U.a[i][i] % mod;       for (int j = 0; j < n; j++) U.a[i][j] = (U.a[i][j] * val) % mod;       for (int k = i + 1; k < n; k++) {         long long val = -U.a[k][i];         L.a[k][i] = -val;         for (int j = 0; j < n; j++) {           U.a[k][j] = (U.a[k][j] + U.a[i][j] * val) % mod;           if (U.a[k][j] < 0) U.a[k][j] += mod;         }       }     }     return res % mod;   }   long long solve(int s) {     int t = s;     g = 0;     memset(vis, -1, sizeof(vis));     for (int i = 0; i <= n; i++, t ^= 1) {       for (int j = t; j <= m; j += 2)         if (vis[i][j] == -1) bfs(i, j), g++;     }     matrix a(g);     t = s;     for (int i = 0; i <= n; i++, t ^= 1) {       for (int j = t; j <= m; j += 2) {         for (int k = 0; k < 4; k++) {           int yy = i + dy[k], xx = j + dx[k];           int ii = i + cy[k], jj = j + cx[k];           if (go(yy, xx, ii, jj) && arr[ii][jj] == -1 &&               vis[i][j] != vis[yy][xx]) {             a.a[vis[i][j]][vis[yy][xx]]--;           }         }       }     }     for (int i = 0; i < g; i++) {       for (int j = 0; j < g; j++)         if (i != j) {           a.a[i][i] -= a.a[i][j];         }       for (int j = 0; j < g; j++) a.a[i][j] = (a.a[i][j] + mod) % mod;     }     matrix b(g - 1);     for (int i = 0; i < g - 1; i++)       for (int j = 0; j < g - 1; j++) b.a[i][j] = a.a[i][j];     long long ans = (LU_Det(b) % mod + mod) % mod;     return ans;   }   int main() {     scanf( %d%d%lld , &n, &m, &mod);     for (int i = 0; i < n; i++) scanf( %s , str[i]);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (str[i][j] ==  / )           arr[i][j] = 0;         else if (str[i][j] ==  * )           arr[i][j] = -1;         else           arr[i][j] = 1;       }     printf( %lld n , (solve(0) + solve(1)) % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, long long> m;   map<long long, long long>::iterator it;   long long ans[200500];   int main() {     long long n, i, x, y, pr = -1, cur = 0;     cin >> n;     for (i = 0; i < n; i++) {       cin >> x >> y;       m[x]++;       m[y + 1]--;     }     for (it = m.begin(); it != m.end(); it++) {       if (it->second < 0) {         ans[cur] += (it->first - pr);       } else {         if (cur != 0) {           ans[cur] += (it->first - pr);         }       }       cur += it->second;       pr = it->first;     }     for (i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005;   int dp[maxn][maxn];   int n, ans;   int tim[maxn];   int dfs(int i, int j) {     if (dp[i][j]) return dp[i][j];     int ti = tim[i], tj = tim[j], tk = tim[j + 1];     if (j == n + 1) return dp[i][j] = ti;     if (j == n) return dp[i][j] = max(ti, tj);     int choseij = max(ti, tj) + dfs(j + 1, j + 2),         choseik = max(ti, tk) + dfs(j, j + 2),         chosejk = max(tj, tk) + dfs(i, j + 2);     dp[i][j] = min(min(choseij, choseik), chosejk);     return dp[i][j];   }   void print_ans(int i, int j) {     int ti = tim[i], tj = tim[j], tk = tim[j + 1];     if (j == n + 1) {       cout << i << endl;       return;     }     if (j == n) {       cout << i <<     << j << endl;       return;     }     int choseij = max(ti, tj) + dp[j + 1][j + 2],         choseik = max(ti, tk) + dp[j][j + 2],         chosejk = max(tj, tk) + dp[i][j + 2];     if (dp[i][j] == choseij) {       cout << i <<     << j << endl;       print_ans(j + 1, j + 2);       return;     }     if (dp[i][j] == choseik) {       cout << i <<     << j + 1 << endl;       print_ans(j, j + 2);       return;     }     if (dp[i][j] == chosejk) {       cout << j <<     << j + 1 << endl;       print_ans(i, j + 2);       return;     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> tim[i];     ans = dfs(1, 2);     cout << ans << endl;     print_ans(1, 2);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     char a[3][3];     for (int i = 0; i < 3; i++)       for (int j = 0; j < 3; j++) cin >> a[i][j];     for (int i = 0; i < 3; i++)       for (int j = 0; j < 3; j++)         if (a[i][j] != a[2 - i][2 - j]) {           cout <<  NO ;           return 0;         }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 205;   long long dp[maxn][maxn][maxn];   long long n;   string s, t;   long long recur(long long pos, long long changes, long long sum) {     if (pos == n) return 0;     if (dp[pos][changes][sum] != -1) return dp[pos][changes][sum];     long long res = recur(pos + 1, changes, sum);     if (s[pos] == t[0]) res = max(res, recur(pos + 1, changes, sum + 1));     if (s[pos] == t[1]) res = max(res, recur(pos + 1, changes, sum) + sum);     if (s[pos] == t[0] && s[pos] == t[1])       res = max(res, recur(pos + 1, changes, sum + 1) + sum);     if (changes > 0) {       res = max(res, recur(pos + 1, changes - 1, sum + 1));       res = max(res, recur(pos + 1, changes - 1, sum) + sum);       if (t[0] == t[1])         res = max(res, recur(pos + 1, changes - 1, sum + 1) + sum);     }     dp[pos][changes][sum] = res;     return res;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     for (long long i = 0; i < maxn; i++)       for (long long j = 0; j < maxn; j++)         for (long long k = 0; k < maxn; k++) dp[i][j][k] = -1;     long long k;     cin >> n >> k >> s >> t;     long long res = recur(0, k, 0);     cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     double x, y, t, val;   } pnt[2050];   struct Edge {     int u, v, next;   } edge[2050 * 2050];   int head[2050], tot = 0;   void add(int u, int v) {     edge[tot].u = u;     edge[tot].v = v;     edge[tot].next = head[u];     head[u] = tot++;   }   double Dist(node x, node y) {     return sqrt((x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y));   }   int ru[2050];   double Max(double x, double y) {     if (x > y) return x;     return y;   }   int mark[2050];   int n;   double dis[2050];   double spfa(int x) {     for (int i = 1; i <= n; i++) {       mark[i] = false;       dis[i] = 0;     }     queue<int> Q;     Q.push(x);     dis[x] = pnt[x].val;     mark[x] = true;     while (!Q.empty()) {       int k = Q.front();       Q.pop();       mark[k] = false;       for (int i = head[k]; i != -1; i = edge[i].next) {         if (dis[edge[i].v] < dis[k] + pnt[edge[i].v].val) {           dis[edge[i].v] = dis[k] + pnt[edge[i].v].val;           if (mark[edge[i].v] == false) {             Q.push(edge[i].v);             mark[edge[i].v] = true;           }         }       }     }     double maxn = dis[x];     for (int i = 1; i <= n; i++) {       if (dis[i] > maxn) {         maxn = dis[i];       }     }     return maxn;   }   int main() {     int i, j;     while (scanf( %d , &n) != EOF) {       for (i = 1; i <= n; i++) {         scanf( %lf%lf%lf%lf , &pnt[i].x, &pnt[i].y, &pnt[i].t, &pnt[i].val);       }       memset(head, -1, sizeof(head));       memset(ru, 0, sizeof(ru));       tot = 0;       for (i = 1; i <= n; i++) {         for (j = 1; j <= n; j++) {           if (i == j) continue;           if (Dist(pnt[i], pnt[j]) + pnt[i].t <= pnt[j].t) {             add(i, j);             ru[j]++;           }         }       }       double maxn = 0;       for (i = 1; i <= n; i++) {         if (ru[i] == 0) {           maxn = Max(maxn, spfa(i));         }       }       printf( %.7f n , maxn);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool sorting(const pair<long long int, long long int>& a,                const pair<long long int, long long int>& b) {     if (a.first != b.first) {       return (a.first > b.first);     } else       return (!(a.second >= b.second));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, k;     cin >> n >> k;     pair<long long int, long long int> v[n];     for (int i = 0; i < n; ++i) {       cin >> v[i].first >> v[i].second;     }     sort(v, v + n, sorting);     long long int ans = 0;     for (int i = 0; i < n; ++i) {       if (v[k - 1].first == v[i].first && v[k - 1].second == v[i].second) {         ans++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int x1, y1;   } ar[500101];   bool cmp(node &b1, node &b2) {     if (b1.x1 == b2.x1) return b1.y1 < b2.y1;     return b1.x1 < b2.x1;   }   int main() {     long long q, i, j, k, v, c = 0, p1, p2, t, n, x, y, p;     cin >> n;     for (i = 0; i < n; i++) {       cin >> ar[i].x1 >> ar[i].y1;     }     sort(ar, ar + n, cmp);     for (i = 0; i < n; i++) {       if (i == 0) {         p = min(ar[i].x1, ar[i].y1);       } else {         p1 = min(ar[i].x1, ar[i].y1);         if (p1 >= p) {           p = p1;         } else if (ar[i].x1 > ar[i].y1) {           p = ar[i].x1;         } else {           p = ar[i].y1;         }       }     }     cout << p << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int k, res;   string s;   int cs(int x) {     int dem(0);     while (x != 0) {       x /= 10;       dem++;     }     return dem;   }   int main() {     int t;     cin >> t;     while (t--) {       cin >> k;       res = 0;       int ii;       for (int i = 1; i <= 100000000; ++i) {         ii = i;         res += cs(i);         if (k <= res) break;         k -= res;       }       res = 0;       for (int i = 1; i <= ii; ++i) {         res += cs(i);         if (res >= k) {           res -= cs(i);           ii = i;           break;         }       }       ostringstream convert;       convert.clear();       convert << ii;       s = convert.str();       cout << s[k - res - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nmax = 100005;   int n, cnt, one, two1, two2, p[nmax];   vector<int> v[nmax];   bitset<nmax> viz;   int main() {     cin.sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) cin >> p[i];     for (int i = 1; i <= n; i++)       if (!viz[i]) {         cnt++;         for (int j = i; !viz[j]; j = p[j]) {           viz[j] = 1;           v[cnt].push_back(j);         }       }     for (int i = 1; i <= n; i++)       if (v[i].size() == 1) {         one = v[i][0];         break;       }     if (one) {       printf( YES n );       for (int i = 1; i <= n; i++)         if (i != one) printf( %d %d n , i, one);       return 0;     }     for (int i = 1; i <= n; i++)       if (v[i].size() == 2) {         two1 = v[i][0];         two2 = v[i][1];         break;       }     if (two1) {       for (int i = 1; i <= cnt; i++)         if (v[i].size() & 1) {           printf( NO n );           return 0;         }       printf( YES n );       printf( %d %d n , two1, two2);       for (int i = 1; i <= cnt; i++)         if (v[i][0] != two1)           for (int j = 0; j < (int)v[i].size(); j++) {             if (j & 1)               printf( %d %d n , two1, v[i][j]);             else               printf( %d %d n , two2, v[i][j]);           }       return 0;     }     printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int p = 1000000007;   long long n;   int k, ans;   int inv[123];   int F[55][55][10110];   int exp(int a, int b, int c) {     int d = 1;     while (b) {       if (b & 1) d = 1LL * d * a % c;       b >>= 1;       a = 1LL * a * a % c;     }     return d;   }   int f(int lim, int now, int k) {     if (F[lim][now][k] != 0) return F[lim][now][k];     if (k == 1) return inv[now + 1];     int res = 0;     for (int i = lim; i <= now; i++) res = (res + f(lim, i, k - 1)) % p;     res = 1LL * res * inv[now + 1] % p;     F[lim][now][k] = res;     return res;   }   int main() {     scanf( %I64d%d , &n, &k);     int res = 1;     inv[1] = 1;     for (int i = 2; i <= 100; i++) inv[i] = -1LL * inv[p % i] * (p / i) % p;     for (int i = 2; 1LL * i * i <= n; i++)       if (n % i == 0) {         int c = 0, inv = exp(i, p - 2, p), ans = 0;         int u = 1;         while (n % i == 0) n /= i, c++, u = 1LL * u * i % p;         for (int j = c; j >= 0; j--) {           ans = (ans + 1LL * u * f(j, c, k)) % p;           u = 1LL * u * inv % p;         }         res = 1LL * res * ans % p;       }     if (n != 1) {       res = 1LL * res * (f(0, 1, k) % p + 1LL * n % p * f(1, 1, k) % p) % p;     }     if (res < 0) res += p;     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   string a[33];   int z[33][33];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         z[i + 1][j + 1] = z[i + 1][j] + z[i][j + 1] - z[i][j] + (a[i][j] ==  1 );       }     int sol = 0;     for (int p = 0; p < n; p++)       for (int q = 0; q < m; q++)         for (int r = p + 1; r <= n; r++)           for (int s = q + 1; s <= m; s++) {             int c = 0;             c += z[p][q];             c += z[r][s];             c -= z[p][s];             c -= z[r][q];             if (c == 0) {               sol = max(sol, r - p + s - q);             }           }     cout << 2 * sol <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     cin >> n >> m >> k;     vector<int> arr(n);     for (int i = 0; i < n; i++) cin >> arr[i];     vector<int> temp;     for (int i = 1; i < n; i++) {       int val = arr[i] - arr[i - 1] - 1;       temp.push_back(val);     }     sort(temp.begin(), temp.end());     long long int ans = arr[n - 1] - arr[0] + 1;     for (int i = 1; i < k; i++) {       ans = ans - temp[n - 1 - i];     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string s, ans, temp;     cin >> s;     int flag = 0;     for (int i = 0; i < k; i++) {       for (int j = i; j < n; j += k) {         if (s[i] != s[j]) {           flag = 1;           break;         }       }       if (flag) break;     }     if (!flag) {       cout << s.length() << endl;       cout << s << endl;       return 0;     }     for (int i = 0; i < k; i++) temp += s[i];     for (int i = 0; i < n / k; i++) ans += temp;     int i = 0;     while (ans.length() < s.length()) {       ans += temp[i];       i++;     }     if (ans >= s) {       cout << ans.length() << endl;       cout << ans << endl;       return 0;     }     i = 0, flag = 0;     for (i = k - 1; i >= 0; i--) {       if (s[i] <  9 ) {         s[i] = s[i] + 1;         flag = 1;         break;       }     }     if (flag) {       i++;       for (i; i < k; i++) s[i] =  0 ;     }     temp.clear(), ans.clear();     for (int i = 0; i < k; i++) temp += s[i];     for (int i = 0; i < n / k; i++) ans += temp;     i = 0;     while (ans.length() < s.length()) {       ans += temp[i];       i++;     }     cout << ans.length() << endl;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int a[100100];   int num[100100];   int main() {     set<int> s;     int n;     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = n; i >= 1; i--) {       s.insert(a[i]);       num[i] = s.size();     }     s.clear();     long long sum = 0;     for (int i = 1; i <= n; i++) {       if (s.find(a[i]) == s.end()) {         s.insert(a[i]);         sum += num[i + 1];       }     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m;     cin >> n >> m;     int a[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cin >> a[i][j];     }     int b[m][n];     bool flag = false;     int index = -1;     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         cin >> b[i][j];         if (b[i][j] == a[0][0] && !flag) {           flag = true;           index = i;         }       }     }     for (int i = 0; i < n; i++) {       int curr = b[index][i];       for (int j = 0; j < n; j++) {         if (a[j][0] == curr) {           for (int k = 0; k < m; k++) cout << a[j][k] <<    ;           cout << endl;         }       }     }   }   int main() {     long long int t = 1;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long u, long long v) {     if (u < v) swap(u, v);     while (v != 0) {       int r = u % v;       u = v;       v = r;     }     return u;   }   pair<int, int> row[200000], col[200000];   int main(void) {     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < 200000; ++i) {       row[i] = make_pair(0, -1);       col[i] = make_pair(0, -1);     }     int t = 0;     for (int i = 0; i < k; ++i) {       t++;       int q;       cin >> q;       if (q == 1) {         int r, a;         cin >> r >> a;         r--;         row[r] = make_pair(a, t);       } else if (q == 2) {         int c, a;         cin >> c >> a;         c--;         col[c] = make_pair(a, t);       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (row[i].second > col[j].second)           cout << row[i].first;         else           cout << col[j].first;         if (j != m - 1) cout <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   int dizi[100015];   int main() {     int i, m, n, fark, k, j;     scanf( %d %d %d %d , &m, &n, &k, &j);     for (i = 1;; i++) {       j = (j * m + n) % k;       if (dizi[j]) {         printf( %d , i - dizi[j]);         break;       }       dizi[j] = i;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, i, j, k, a1, a2, a3, a4, res, ans, sum;   bool k1, k2, k3;   long long l, r, M;   string s, q, s1, s2;   long long a[5000000];   int main() {     cin >> n >> a4;     for (i = 1; i <= n; i++) cin >> a1 >> a2, a[i] = a1 * a2;     for (i = 2; i <= n; i++) a[i] += a[i - 1];     for (i = 1; i <= a4; i++) {       cin >> j;       l = 1;       r = n;       while (l + 1 < r) {         m = (l + r) / 2;         if (a[m] >= j)           r = m;         else           l = m + 1;       }       if (a[l] >= j)         cout << l << endl;       else         cout << r << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int sum(int a) {     int sum = a;     while (a) {       sum += a % 10;       a /= 10;     }     return sum;   }   int main() {     vector<int> v;     int a;     cin >> a;     int b = a;     while (a) {       int check = sum(a);       if (check == b)         v.push_back(a);       else if (check + 100 < b)         break;       a--;     }     cout << v.size() << endl;     reverse(v.begin(), v.end());     for (auto i : v) {       cout << i << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, Cnt = 0;   double A[4005], C[4005], Ans = 0.0, Anx;   double Abs(double x) { return x < 0 ? -x : x; }   int main() {     scanf( %d , &N);     for (int i = 1; i <= 2 * N; i++) scanf( %lf , &A[i]), C[i] = A[i] - (int)A[i];     for (int i = 1; i <= 2 * N; i++) {       if (C[i] == 0) Cnt++;       Ans += -C[i];     }     Anx = Abs(Ans + 1.0 * N);     for (int i = max(N - Cnt, 0); i <= N; i++) {       Anx = min(Anx, Abs(Ans + i));     }     printf( %.3f n , Anx);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s, s1 =   , s2 =   ;     cin >> n >> s;     reverse(s.begin(), s.end());     for (int i = 0; i < s.size(); ++i) {       if (i % 2 == 0)         s1 += s[i];       else         s2 += s[i];     }     reverse(s1.begin(), s1.end());     cout << s2 << s1;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:10000000000 )   #pragma GCC optimize( O3 )   using namespace std;   const int MOD = 1000000007;   const int INF = 1000000007LL;   const long long INF2 = 1LL << 62LL;   const long double EPS = 1e-9;   const int SIZE = 200010;   mt19937 rng(time(0));   uniform_int_distribution<int> uid(-1000000000, 1000000000);   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tt;     cin >> tt;     for (int rep_iter = 0; rep_iter < tt; ++rep_iter) {       int n, x, y, ost;       cin >> n >> x >> y;       vector<int> b(n, -1);       set<int> used_color;       map<int, vector<int> > pos;       for (int i2 = 0; i2 < n; ++i2) {         int a;         cin >> a;         used_color.insert(a);         pos[a].push_back(i2);       }       for (int i = 1; i <= n + 1; ++i) {         if (!(used_color.find(i) != used_color.end())) {           ost = i;           break;         }       }       set<pair<int, int> > colors;       for (auto& i : pos) colors.insert({i.second.size(), i.first});       for (int rep_iter = 0; rep_iter < x; ++rep_iter) {         auto p = *(--colors.end());         colors.erase(--colors.end());         --p.first;         int color = p.second;         int j = pos[color].back();         pos[color].pop_back();         b[j] = color;         if (p.first) colors.insert(p);       }       y -= x;       int m = n - x;       int real_y;       if (colors.size())         real_y = min(m, (m - (--colors.end())->first) * 2);       else         real_y = m;       if (real_y < y) {         cout <<  NO n ;         continue;       }       cout <<  YES n ;       vector<int> v;       int j = -1;       for (auto& i : colors) {         if (i.first) j = v.size();         for (int rep_iter = 0; rep_iter < i.first; ++rep_iter)           v.push_back(i.second);       }       for (auto& color : v) {         if (!y) break;         --y;         int color_move = v[j];         j = (j + 1) % v.size();         while (color_move == color) {           color_move = v[j];           j = (j + 1) % v.size();         }         int k = pos[color].back();         pos[color].pop_back();         b[k] = color_move;       }       for (auto& i : b) {         if (i == -1) i = ost;       }       for (auto& i : b) cout << i <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( O3 )   #pragma GCC optimize( O2 )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     for (long long i = 0; i < v.size(); ++i) os << v[i] <<    ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const set<T>& v) {     for (auto it : v) os << it <<    ;     return os;   }   template <typename T, typename S>   ostream& operator<<(ostream& os, const pair<T, S>& v) {     os << v.first <<     << v.second;     return os;   }   const long long mod = 1e9 + 7;   const long long inf = 2e18;   const long long ninf = -2e18;   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;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     time_t t1, t2;     t1 = clock();     long long n, m, ta, tb, k;     cin >> n >> m >> ta >> tb >> k;     vector<long long> arra(n);     for (long long i = 0; i < n; i++) {       cin >> arra[i];     }     vector<long long> arrb(m);     for (long long i = 0; i < m; i++) {       cin >> arrb[i];     }     if (n <= k || m <= k) {       cout << -1 <<   n ;       return 0;     }     long long ans = -1;     for (long long i = 0; i <= k; i++) {       long long curr = arra[i] + ta;       long long req = lower_bound(arrb.begin(), arrb.end(), curr) - arrb.begin();       long long rem = k - i;       if (req + rem > m - 1) {         ans = inf;         break;       }       long long ap = arrb[req + rem] + tb;       ans = max(ap, ans);     }     if (ans != inf) {       cout << ans <<   n ;     } else       cout << -1 <<   n ;     t2 = clock();     cerr <<   n  << t2 - t1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> arr;   int n, k;   long long sum[5500];   double mx = -1e9;   int main() {     cin >> n >> k;     for (int x, i = 1; i <= n; i++) {       cin >> x;       arr.push_back(x);       sum[i] = sum[i - 1] + x;     }     for (int i = 1; i <= n; i++) {       for (int j = i + k - 1; j <= n; j++) {         mx = max(mx, (sum[j] - sum[i - 1]) / (double(j - i + 1)));       }     }     printf( %0.15lf , mx);   }


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


#include <bits/stdc++.h>   #pragma GCC optimize( -O2 )   using namespace std;   void err(istream_iterator<string> it) { cerr << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   t ;     err(++it, args...);   }   template <typename T1, typename T2>   ostream& operator<<(ostream& c, pair<T1, T2>& v) {     c <<  (  << v.F <<  ,  << v.S <<  ) ;     return c;   }   template <template <class...> class TT, class... T>   ostream& operator<<(ostream& out, TT<T...>& c) {     out <<  {  ;     for (auto& x : c) out << x <<    ;     out <<  } ;     return out;   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   const int N = 200005;   long long xx[N];   void solve() {     long long n, x, y;     cin >> n;     long long ans = n;     for (long long i = 1; i <= n - 1; i++) {       cin >> x >> y;       ans = (((ans * (++xx[x])) % 998244353) * (++xx[y])) % 998244353;     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       solve();     }     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static const double EPS = 1e-9;   int ROUND(double x) { return (int)(x + 0.5); }   bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }   bool ISEQUAL(double x, double y) {     return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y)));   }   double SQSUM(double x, double y) { return x * x + y * y; }   template <class T>   bool INRANGE(T x, T a, T b) {     return a <= x && x <= b;   }   long long get(long long tmp) {     long long a = 0;     long long b = 0;     long long base = 1;     while (tmp) {       a += base * (tmp % 10);       b += base * (9 - (tmp % 10));       tmp /= 10;       base *= 10;     }     long long c = a * b;     return c;   }   int main() {     int tmp1, tmp2;     scanf( %d %d  , &tmp1, &tmp2);     long long l = tmp1, r = tmp2;     vector<long long> res;     res.push_back(get(l));     res.push_back(get(r));     for (long long i = 5; i <= r; i *= 10) {       if (INRANGE(i, l, r)) {         res.push_back(get(i));       }     }     sort(res.rbegin(), res.rend());     cout << res[0] << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 3e5 + 5, mod = 1e8, inf = 1e9 + 5;   long double pi = acos(-1);   long long n, m, k, dp[N][15], a[N];   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     long long maxans = 0;     for (int i = 0; i <= m; i++) {       dp[0][i] = -1e12;     }     for (int i = 1; i <= n; i++) {       long long ans = 0;       for (int j = 1; j <= m; j++) {         if (j == 1) {           dp[i][j] = max(a[i] - k, dp[i - 1][m] + a[i] - k);         } else           dp[i][j] = dp[i - 1][j - 1] + a[i];         maxans = max(maxans, dp[i][j]);       }     }     cout << maxans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   long long a[maxn], x[maxn], y[maxn], c[7], d[7], ans;   int n, m;   bool cmp(long long x, long long y) { return x > y; }   void sol(int pos, int num, int flag) {     memset(d, 0, sizeof(d));     if (flag) {       for (int i = 1; i <= pos; i++) {         long long w = y[i];         for (int j = 0; j < 4 - num; j++) {           w -= a[(c[j] - 1) * m + i];         }         d[num] = w;         sort(d, d + num + 1, cmp);       }       long long ac = 0;       for (int i = 0; i < num; i++) {         ac += d[i];       }       for (int j = 0; j < 4 - num; j++) {         ac += x[c[j]];       }       ans = max(ans, ac);     } else {       for (int i = 1; i <= pos; i++) {         long long w = x[i];         for (int j = 0; j < 4 - num; j++) {           w -= a[(i - 1) * m + c[j]];         }         d[num] = w;         sort(d, d + num + 1, cmp);       }       long long ac = 0;       for (int i = 0; i < num; i++) {         ac += d[i];       }       for (int j = 0; j < 4 - num; j++) {         ac += y[c[j]];       }       ans = max(ans, ac);     }   }   int main() {     scanf( %d%d , &n, &m);     long long sum = 0;     for (int i = 1; i <= n * m; i++) {       scanf( %lld , &a[i]);       sum += a[i];     }     memset(d, 0, sizeof(d));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         x[i] += a[(i - 1) * m + j];       }       d[4] = x[i];       sort(d, d + 5, cmp);     }     for (int i = 0; i < 4; i++) {       ans += d[i];     }     long long xxx = 0;     memset(d, 0, sizeof(d));     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) {         y[i] += a[(j - 1) * m + i];       }       d[4] = y[i];       sort(d, d + 5, cmp);     }     for (int i = 0; i < 4; i++) {       xxx += d[i];     }     ans = max(xxx, ans);     if (n <= 4 || m <= 4) {       printf( %lld n , sum);       return 0;     }     for (int i = 1; i <= n; i++) {       c[0] = i;       sol(m, 3, 1);     }     for (int i = 1; i <= m; i++) {       c[0] = i;       sol(n, 3, 0);     }     if (n > m) {       for (int i = 1; i <= m; i++) {         for (int j = i + 1; j <= m; j++) {           c[0] = i;           c[1] = j;           sol(n, 2, 0);         }       }     } else {       for (int i = 1; i <= n; i++) {         for (int j = i + 1; j <= n; j++) {           c[0] = i;           c[1] = j;           sol(m, 2, 1);         }       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void umax(T &x, T y) {     if (y > x) x = y;   }   template <class T>   inline void umin(T &x, T y) {     if (y < x) x = y;   }   const int N = 2e5 + 5, B = 0x7fffffff;   struct edge {     int u, v, l, r;   } a[N];   vector<pair<int, pair<int, int>>> g[N];   int n, m;   int ans;   bool bfs(int x, int ql, int qr) {     bool vis[N];     memset(vis, 0, sizeof vis);     queue<int> Q;     Q.push(x);     vis[x] = 1;     while (!Q.empty()) {       int fr = Q.front();       Q.pop();       for (pair<int, pair<int, int>> ss : g[fr]) {         if (vis[ss.first] != 1 && ss.second.first <= ql &&             qr <= ss.second.second) {           vis[ss.first] = 1;           Q.push(ss.first);         }       }     }     return vis[n];   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d%d , &a[i].u, &a[i].v, &a[i].l, &a[i].r);       int x = a[i].u;       int y = a[i].v;       int l = a[i].l;       int r = a[i].r;       g[x].push_back({y, {l, r}});       g[y].push_back({x, {l, r}});     }     for (int i = 1; i <= m; i++) {       int l = 1, r = 1e9, ann = -1;       while (l <= r) {         int mid = (l + r) >> 1;         if (bfs(1, a[i].l, mid))           l = mid + 1, ann = mid;         else           r = mid - 1;       }       if (ann != -1) umax(ans, (ann - a[i].l) + 1);     }     if (ans == 0)       puts( Nice work, Dima! );     else       printf( %d , ans);     return !!0;   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long int INF = 1e17;   long long int NINF = (INF * -1);   priority_queue<pair<long long int, long long int>,                  vector<pair<long long int, long long int>>,                  greater<pair<long long int, long long int>>>       pq;   vector<long long int> indegree;   vector<vector<pair<long long int, long long int>>> adj;   vector<long long int> distances;   vector<vector<long long int>> arr;   vector<bool> visited;   vector<long long int> level, height;   vector<long long int> ans;   long long int dfs(long long int src, long long int parent = -1,                     long long int l = 0) {}   void solve() {     long long int n;     cin >> n;     string a;     string b;     cin >> a >> b;     vector<long long int> ab, ba;     vector<pair<long long int, long long int>> ans;     for (long long int i = 0; i < n; i++) {       if (a[i] == b[i]) {         continue;       }       if (a[i] ==  a  and b[i] ==  b ) {         if (ab.size() != 0) {           ans.push_back({ab.back(), i + 1});           ab.pop_back();         } else {           ab.push_back(i + 1);         }       } else {         if (ba.size() != 0) {           ans.push_back({ba.back(), i + 1});           ba.pop_back();         } else {           ba.push_back(i + 1);         }       }     }     if (ab.size() == 1 and ba.size() == 1) {       ans.push_back({ba.back(), ba.back()});       ans.push_back({ba.back(), ab.back()});       ab.pop_back();       ba.pop_back();     }     if (ab.size() != 0 || ba.size() != 0) {       cout <<  -1 n ;       return;     }     cout << ans.size();     cout <<   n ;     ;     for (auto i : ans) {       cout << i.first <<     << i.second;       cout <<   n ;       ;     }     return;   }   signed main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename T1>   T amax(T& a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T amin(T& a, T1 b) {     if (b < a) a = b;     return a;   }   const long long N = 200005, INF = 2000000000000000000;   void solve() {     long long n, m;     cin >> n >> m;     long long i = 0, j = 0;     char v[50][50];     long long a = 1000000, b = 10000, c = 0, d = 0;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         cin >> v[i][j];         if (v[i][j] ==  * ) {           a = min(i, a);           b = min(j, b);           c = max(i, c);           d = max(j, d);         }       }     }     for (i = a; i < c + 1; i++) {       for (j = b; j < d + 1; j++) {         cout << v[i][j];       }       cout <<   n ;     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     solve();   }


#include <bits/stdc++.h>   #pragma optimization_level 3   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math,O3 )   using namespace std;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   int inf = INT32_MAX;   struct Node {     Node *l = 0, *r = 0;     vector<int> m1, m2;     Node(Node *a, Node *b) {       m1 = vector<int>(9);       m2 = vector<int>(9);       l = a, r = b;       for (int q = 0; q < 9; q++) m1[q] = min(l->m1[q], r->m1[q]);       for (int q = 0; q < 9; q++)         m2[q] = min(max(l->m1[q], r->m1[q]), min(l->m2[q], r->m2[q]));     }     Node(Node *a, Node *b, int c) {       m1 = vector<int>(9);       m2 = vector<int>(9, inf);       l = a, r = b;       for (int q = 0, v = c; q < 9; q++, c /= 10) m1[q] = c % 10 ? v : inf;     }   };   Node *build(int l, int r, vector<int> &m) {     if (l == r) return new Node(0, 0, m[l - 1]);     int md = (l + r) / 2;     return new Node(build(l, md, m), build(md + 1, r, m));   }   pair<int, int> que(int l, int r, int l1, int r1, Node *n, int c) {     if (l == l1 && r == r1) return {n->m1[c], n->m2[c]};     int md = (l1 + r1) / 2;     if (r <= md) return que(l, r, l1, md, n->l, c);     if (l > md) return que(l, r, md + 1, r1, n->r, c);     pair<int, int> p1 = que(l, md, l1, md, n->l, c);     pair<int, int> p2 = que(md + 1, r, md + 1, r1, n->r, c);     return {min(p1.first, p2.first),             min(max(p1.first, p2.first), min(p1.second, p2.second))};   }   void upd(int l, int r, int p, Node *n, int v) {     if (l == r) {       for (int q = 0, c = v; q < 9; q++, v /= 10) n->m1[q] = v % 10 ? c : inf;       return;     }     int md = (l + r) / 2;     if (p <= md)       upd(l, md, p, n->l, v);     else       upd(md + 1, r, p, n->r, v);     for (int q = 0; q < 9; q++) n->m1[q] = min(n->l->m1[q], n->r->m1[q]);     for (int q = 0; q < 9; q++)       n->m2[q] =           min(max(n->l->m1[q], n->r->m1[q]), min(n->l->m2[q], n->r->m2[q]));   }   int a, z;   vector<int> m;   int main() {     cin.tie(0);     cout.tie(0);     cin.sync_with_stdio(0);     cout.sync_with_stdio(0);     ;     cin >> a >> z;     m = vector<int>(a);     for (int q = 0; q < a; q++) cin >> m[q];     Node *n = build(1, a, m);     for (; z; z--) {       int t, x, y;       cin >> t >> x >> y;       if (t == 1)         upd(1, a, x, n, y);       else {         int o = inf;         for (int q = 0; q < 9; q++) {           pair<int, int> p = que(x, y, 1, a, n, q);           if (p.second == inf) continue;           o = min(o, p.first + p.second);         }         cout << (o == inf ? -1 : o) <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 3e3 + 555;   struct node {     long long x, y, v;     bool operator<(const node& n) const {       if (x != n.x)         return x < n.x;       else         return y < n.y;     }   };   long long pre[maxn][maxn];   node ori[maxn];   inline long long cal(long long hang1, long long lie1, long long hang2,                        long long lie2) {     hang1 = min(hang1, 1000ll);     lie1 = min(lie1, 1000ll);     hang2 = max(hang2, 1ll);     lie2 = max(lie2, 1ll);     return pre[hang1][lie1] - pre[hang1][lie2 - 1] - pre[hang2 - 1][lie1] +            pre[hang2 - 1][lie2 - 1];   }   long long buxuan[maxn];   long long f[maxn];   void init() {     f[0] = 1;     for (long long i = 1; i < maxn; i++) f[i] = f[i - 1] * i % mod;   }   inline long long qpow(long long a, long long n) {     long long base = a;     long long res = 1;     while (n) {       if (n & 1) res = res * base % mod;       base = base * base % mod;       n >>= 1;     }     return res;   }   long long C(long long n, long long m) {     if (n < m) return 0;     return f[n] * qpow(f[m], mod - 2) % mod * qpow(f[n - m], mod - 2) % mod;   }   void solve() {     long long n, m, r;     scanf( %lld %lld %lld , &n, &m, &r);     for (long long i = 1; i <= n; i++) {       scanf( %lld %lld %lld , &ori[i].x, &ori[i].y, &ori[i].v);       pre[ori[i].x][ori[i].y] = 1;     }     sort(ori + 1, ori + n + 1);     long long ans = 0;     for (long long i = 1; i <= 1000; i++)       for (long long j = 1; j <= 1000; j++) pre[i][j] += pre[i][j - 1];     for (long long j = 1; j <= 1000; j++)       for (long long i = 1; i <= 1000; i++) pre[i][j] += pre[i - 1][j];     long long base = C(n, m);     for (long long i = 1; i <= n; i++) {       long long wai =           n - cal(ori[i].x + r, ori[i].y + r, ori[i].x - r, ori[i].y - r);       long long cnt = C(wai, m);       buxuan[i] = cnt;       ans += ori[i].v * ori[i].v % mod * (base - cnt) % mod;       ans %= mod;     }     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j < i; j++) {         long long wai =             n - cal(ori[i].x + r, ori[i].y + r, ori[i].x - r, ori[i].y - r);         wai -= cal(ori[j].x + r, ori[j].y + r, ori[j].x - r, ori[j].y - r);         if (ori[i].x - ori[j].x <= r * 2) {           if (abs(ori[j].y - ori[i].y) <= r * 2) {             if (ori[j].y < ori[i].y)               wai = wai +                     cal(ori[j].x + r, ori[j].y + r, ori[i].x - r, ori[i].y - r) %                         mod;             else               wai = wai +                     cal(ori[j].x + r, ori[i].y + r, ori[i].x - r, ori[j].y - r) %                         mod;           }         }         long long cnt = (base - buxuan[i] - buxuan[j] + C(wai, m)) % mod;         cnt += mod;         cnt %= mod;         ans += ori[i].v * ori[j].v % mod * 2 % mod * cnt % mod;         ans %= mod;       }     }     printf( %lld n , ans);   }   signed main() {     init();     solve();   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   void self_max(long long& a, const long long& b) { a = max(a, b); }   void self_min(long long& a, const long long& b) { a = min(a, b); }   inline void preprocessing() {}   inline void solve() {     long long n;     cin >> n;     if (n == 1) {       cout <<  1 0  <<   n ;       return;     }     vector<long long> factors;     long long value = 1;     long long len = ceil(sqrt(n)) + 1;     long long originalN = n;     for (long long i = 2; i < len; ++i) {       if (n == 1) break;       if (n % i == 0) {         long long cnt = 0;         while (n % i == 0) {           ++cnt;           n /= i;         }         factors.emplace_back(cnt);         value *= i;       }     }     long long maxCount = 0;     for (const long long& factor : factors)       if (factor > maxCount) maxCount = factor;     if (maxCount < 2) {       cout << originalN <<   0  <<   n ;       return;     }     long long operations = ceil(log2(maxCount));     long long u = exp2(operations);     for (const long long& factor : factors) {       if (factor != u) {         ++operations;         break;       }     }     if (n == 1)       cout << value <<     << operations <<   n ;     else       cout << value * n <<     << operations + 1 <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     preprocessing();     solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, c;     cin >> a >> b >> c;     vector<long> v;     for (int i = 1; i <= 81; i++) {       long long sum = i;       for (int j = 2; j <= a; j++) sum *= i;       sum *= b;       sum += c;       if (sum > 0 && sum < 1000000000) {         long long cn = sum, cnt = 0;         while (cn) {           cnt += cn % 10;           cn /= 10;         }         if (cnt == i) v.push_back(sum);       }     }     cout << v.size() << endl;     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-7;   const int maxn = 100 + 10;   int n;   complex<double> p[maxn];   int sign(double x) {     if (x < -eps) return -1;     return x > eps;   }   double cross(complex<double> a, complex<double> b) {     return (conj(a) * b).imag();   }   double dot(complex<double> a, complex<double> b) {     return (conj(a) * b).real();   }   double scross(complex<double> a, complex<double> b) {     return sign((conj(a) * b).imag());   }   double sdot(complex<double> a, complex<double> b) {     return sign((conj(a) * b).real());   }   bool inside(complex<double> a, complex<double> b, complex<double> c,               complex<double> d) {     return scross(b - a, d - a) == scross(c - b, d - b) &&            scross(b - a, d - a) == scross(a - c, d - c);   }   complex<double> rotate(complex<double> a, complex<double> b) {     return (b - a) * complex<double>(0, 1) + a;   }   complex<double> crosspoint(complex<double> a, complex<double> b,                              complex<double> c, complex<double> d) {     c = (c - a) / (b - a);     d = (d - a) / (b - a);     double dx = c.real() - d.real();     double dy = c.imag() - d.imag();     double x = c.real() - (dx * c.imag()) / dy;     return complex<double>(x, 0) * (b - a) + a;   }   complex<double> center(complex<double> a, complex<double> b,                          complex<double> c) {     complex<double> mab = (a + b) / 2.0;     complex<double> mac = (a + c) / 2.0;     complex<double> hab = rotate(mab, a);     complex<double> hac = rotate(mac, a);     return crosspoint(mab, hab, mac, hac);   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; ++i) {       double t1, t2;       cin >> t1 >> t2;       p[i] = complex<double>(t1, t2);     }     double ans = -1;     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j)         for (int k = 0; k < n; ++k) {           if (scross(p[i] - p[j], p[i] - p[k]) == 0) continue;           complex<double> cent = center(p[i], p[j], p[k]);           if (!inside(p[i], p[j], p[k], cent)) {             if (scross(p[k] - p[j], cent - p[j]) != 0) continue;             bool bo = false;             for (int i2 = 0; i2 < n; ++i2)               if (i2 != i && i2 != j && i2 != k &&                   scross(p[i] - p[i2], cent - p[i2]) == 0) {                 bo = true;                 break;               }             if (!bo) continue;           }           bool bo2 = false;           double r = abs(cent - p[i]);           for (int i2 = 0; i2 < n; ++i2)             if (i2 != i && i2 != j && i2 != k && abs(cent - p[i2]) < r - eps) {               bo2 = true;               break;             }           if (bo2) continue;           ans = max(ans, r);         }     if (sign(ans - (-1)) == 0)       cout << -1 << endl;     else       cout << setprecision(6) << fixed << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int leftColors[10], rightColors[10];     int leftParent[10], rightParent[10];     int components;     node() { components = 0; }   };   int n;   node merge(node l, node r) {     node ans;     ans.components = l.components + r.components;     for (int e = 0; e < n; e++) ans.leftParent[e] = l.leftParent[e];     for (int e = 0; e < n; e++) ans.leftColors[e] = l.leftColors[e];     for (int e = 0; e < n; e++) ans.rightParent[e] = r.rightParent[e];     for (int e = 0; e < n; e++) ans.rightColors[e] = r.rightColors[e];     for (int e = 0; e < n; e++) {       if (l.rightColors[e] == r.leftColors[e] &&           l.rightParent[e] != r.leftParent[e]) {         ans.components--;         int tmp = l.rightParent[e];         for (int f = 0; f < n; f++)           if (ans.leftParent[f] == tmp) ans.leftParent[f] = r.leftParent[e];         for (int f = 0; f < n; f++)           if (ans.rightParent[f] == tmp) ans.rightParent[f] = r.leftParent[e];         for (int f = 0; f < n; f++)           if (l.leftParent[f] == tmp) l.leftParent[f] = r.leftParent[e];         for (int f = 0; f < n; f++)           if (l.rightParent[f] == tmp) l.rightParent[f] = r.leftParent[e];       }     }     return ans;   }   const int maxn = 100100;   node tree[maxn << 2];   int grid[11][maxn];   void build(int id, int l, int r) {     if (l == r) {       for (int e = 0; e < n; e++) {         if (e && grid[e][l] == tree[id].leftColors[e - 1])           tree[id].leftParent[e] = tree[id].leftParent[e - 1],           tree[id].rightParent[e] = tree[id].rightParent[e - 1],           tree[id].leftColors[e] = tree[id].leftColors[e - 1],           tree[id].rightColors[e] = tree[id].rightColors[e - 1];         else {           tree[id].leftParent[e] = l * 20 + e;           tree[id].rightParent[e] = l * 20 + e;           tree[id].leftColors[e] = grid[e][l];           tree[id].rightColors[e] = grid[e][l];           tree[id].components++;         }       }     } else {       int mid = (l + r) >> 1;       build(id + id, l, mid);       build(id + id + 1, mid + 1, r);       tree[id] = merge(tree[id + id], tree[id + id + 1]);     }   }   node query(int id, int l, int r, int x, int y) {     if (x <= l && r <= y) return tree[id];     int mid = (l + r) >> 1;     if (y <= mid) return query(id + id, l, mid, x, y);     if (x > mid) return query(id + id + 1, mid + 1, r, x, y);     return merge(query(id + id, l, mid, x, y),                  query(id + id + 1, mid + 1, r, x, y));   }   int main() {     int m, q;     scanf( %d %d %d , &n, &m, &q);     for (int e = 0; e < n; e++)       for (int f = 0; f < m; f++) scanf( %d , &grid[e][f]);     build(1, 0, m - 1);     for (int e = 0; e < q; e++) {       int l, r;       scanf( %d %d , &l, &r);       printf( %d n , query(1, 0, m - 1, l - 1, r - 1).components);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long DP[100005][25], arr[100005], freq[100005], l = 1, r, ans;   void alter_range(long long l1, long long r1) {     while (l1 < l) {       l--;       ans += freq[arr[l]]++;     }     while (r < r1) {       r++;       ans += freq[arr[r]]++;     }     while (l < l1) {       ans -= --freq[arr[l]];       l++;     }     while (r1 < r) {       ans -= --freq[arr[r]];       r--;     }   }   void make_layer(long long layer, long long l1, long long r1, long long a,                   long long b) {     if (l1 > r1) return;     long long i, j, mid = (l1 + r1) >> 1, &curr = DP[mid][layer], best = mid,                     better;     for (i = a; i <= min(b, mid); i++) {       alter_range(i, mid);       better = DP[i - 1][layer - 1] + ans;       if (curr > better) {         curr = better;         best = i;       }     }     make_layer(layer, l1, mid - 1, a, best);     make_layer(layer, mid + 1, r1, best, b);   }   int main() {     long long i, j, n, k;     scanf( %lld %lld , &n, &k);     for (i = 1; i <= n; i++) scanf( %lld , &arr[i]);     for (i = 0; i <= n; i++)       for (j = 0; j <= k; j++) DP[i][j] = 1e18;     DP[0][0] = 0;     for (i = 1; i <= k; i++) make_layer(i, 1, n, 1, n);     printf( %lld n , DP[n][k]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int fuckAbs(long long int a) { return a >= 0 ? a : -a; }   int main(void) {     long long int t, n, m, ans, dx, dy, sx, sy, x1, y1, x2, y2;     cin >> t;     while (t--) {       cin >> n >> m >> x1 >> y1 >> x2 >> y2;       ans = n * m;       dx = n - max(x1, x2) + min(x1, x2);       dy = m - max(y1, y2) + min(y1, y2);       ans -= dx * dy * 2;       sx = sy = 0;       if (dx > fuckAbs(x1 - x2)) sx = dx - fuckAbs(x1 - x2);       if (dy > fuckAbs(y1 - y2)) sy = dy - fuckAbs(y1 - y2);       ans += sx * sy;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     int x;     cin >> x;     bool f1 = 0, f2 = 0;     long long su = 0;     for (int i = 0; i < n; i++) {       int k;       cin >> k;       su += k;       if (k == x) {         f1 = 1;       } else         f2 = 1;     }     if (!f1 && su == n * x) {       cout << 1;       return;     }     if (f1 && f2) cout << 1;     if (f1 && !f2) cout << 0;     if (!f1 && f2) cout << 2;   }   int main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     cout << fixed << setprecision(12);     int t = 1;     cin >> t;     for (int i = 1; i <= t; i++) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, j, m, s, ans;   long long n, k, t;   double sum;   int main() {     scanf( %lld%lld , &n, &k);     sum = (1.0 + k) * k / 2;     if (sum > n) {       puts( -1 );       return 0;     }     t = sum;     for (int i = 1; (long long)i * i <= n; i++)       if (n % i == 0) {         int k = i;         if (n / k - t >= 0) ans = max(ans, k);         k = n / i;         if (n / k - t >= 0) ans = max(ans, k);       }     for (int i = 1; i < k; i++) {       printf( %lld  , (long long)i * ans);       n -= (long long)i * ans;     }     printf( %lld n , n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   void pg() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int32_t main() {     pg();     long long t;     cin >> t;     while (t--) {       long long n, x;       cin >> n >> x;       long long arr[n];       long long sum = 0;       for (long long i = 0; i < n; i++) {         cin >> arr[i];         sum += arr[i];       }       sort(arr, arr + n);       long long cum = 0;       bool flag = 0;       for (long long i = 0; i < n; i++) {         if (((sum - cum) / (n - i)) >= x) {           cout << n - i << endl;           flag = 1;           break;         }         cum += arr[i];       }       if (flag == 0) {         cout << 0 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int n, x;       cin >> n >> x;       long long int a[n];       a[0] = 0;       string s;       cin >> s;       for (int i = 0; i < n; i++) {         char ch;         ch = s[i];         if (i == 0) {           if (ch ==  1 )             a[i]--;           else             a[i]++;         } else {           if (ch ==  1 )             a[i] = a[i - 1] - 1;           else             a[i] = a[i - 1] + 1;         }       }       long long int as = 0;       for (int i = 0; i < n; i++) {         long long int k = (x - a[i]) * a[n - 1];         if (k >= 0) {           if (abs(x - a[i]) == 0 ||               (a[n - 1] != 0 && abs(x - a[i]) % abs(a[n - 1]) == 0)) {             as++;           }         }       }       long long int count = 0;       for (int i = 0; i < n; i++) {         if (a[i] == x) {           count++;         }       }       as = max(as, count);       if (as != 0 && a[n - 1] == 0) {         cout << -1 <<   n ;       } else {         if (x == 0) as++;         cout << as <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e7 + 10, maxl = 20, mod = 1e9 + 7, base = 737,                   inf = 2e18 + 13;   int a, n, res[maxn], t[maxn];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> a >> n;     for (int i = 2; i < a + n; i++)       if (!t[i]) {         t[i] = i;         for (long long j = 1ll * i * i; j < a + n; j += i) t[j] = i;       }     res[1] = 1;     for (int i = 2; i < a + n; i++) {       res[i] = res[i / t[i]];       if (res[i] % t[i])         res[i] *= t[i];       else         res[i] /= t[i];     }     long long ans = 0;     for (int i = a; i < a + n; i++) ans += res[i];     cout << ans << endl;     return 0;   }


#include <algorithm>     #include <iostream>     #include <sstream>     #include <string>     #include <vector>     #include <queue>     #include <set>     #include <map>     #include <cstdio>     #include <cstdlib>     #include <cctype>     #include <cmath>     #include <cstring>   #include <list>     #include <cassert>   #include <climits>   #include <bitset>   #include <chrono>   #include <random>   using namespace std;      #define PB push_back     #define MP make_pair     #define SZ(v) ((int)(v).size())     #define FOR(i,a,b) for(int i=(a);i<(b);++i)     #define REP(i,n) FOR(i,0,n)     #define FORE(i,a,b) for(int i=(a);i<=(b);++i)     #define REPE(i,n) FORE(i,0,n)     #define FORSZ(i,a,v) FOR(i,a,SZ(v))     #define REPSZ(i,v) REP(i,SZ(v))     std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count());   typedef long long ll;   ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }      template<typename Item, typename Sum, typename Lazy> struct SplayTree {    struct Node { int par, ch[2]; Item item; Sum sum; Lazy lazy; Node(Item item, Sum sum, Lazy lazy) :par(-1), item(item), sum(sum), lazy(lazy) { ch[0] = ch[1] = -1; } };    vector<Node> nodes;       void reset() { nodes.clear(); }    void apply(int x, Lazy lazy) { nodes[x].item += lazy; nodes[x].sum += lazy; nodes[x].lazy += lazy; }    void push(int x) { REP(z, 2) if (nodes[x].ch[z] != -1) apply(nodes[x].ch[z], nodes[x].lazy); nodes[x].lazy = Lazy(); }    void update(int x) { nodes[x].sum = Sum(); if (nodes[x].ch[0] != -1) nodes[x].sum += nodes[nodes[x].ch[0]].sum; nodes[x].sum += Sum(nodes[x].item); if (nodes[x].ch[1] != -1) nodes[x].sum += nodes[nodes[x].ch[1]].sum; }    void connect(int x, int p, int z) { if (x != -1) nodes[x].par = p; if (p != -1) nodes[p].ch[z] = x; }    int disconnect(int p, int z) { int x = nodes[p].ch[z]; nodes[p].ch[z] = -1; if (x != -1) nodes[x].par = -1; return x; }    void rotate(int x) {     int p = nodes[x].par, g = nodes[p].par, z = nodes[p].ch[0] == x ? 0 : 1, y = nodes[x].ch[1 - z]; push(p), push(x);     connect(y, p, z), connect(p, x, 1 - z), connect(x, g, g == -1 ? -1 : nodes[g].ch[0] == p ? 0 : 1); update(p);    }    void splay(int x, int y = -1) { if (nodes[x].par == y) return; while (nodes[x].par != y) { int p = nodes[x].par, g = nodes[p].par; if (g != y) rotate((nodes[p].ch[0] == x) == (nodes[g].ch[0] == p) ? p : x); rotate(x); } update(x); }    int first(int x) { if (x == -1) return x; splay(x); while (nodes[x].ch[0] != -1) x = nodes[x].ch[0]; splay(x); return x; }    int last(int x) { if (x == -1) return x; splay(x); while (nodes[x].ch[1] != -1) x = nodes[x].ch[1]; splay(x); return x; }       int add(Item item) { nodes.PB(Node(item, Sum(item), Lazy())); return SZ(nodes) - 1; };    int join(int l, int r) { if (l == -1) return r; l = last(l); push(l); connect(r, l, 1); update(l); return l; }    void split(int x, int v, int& l, int& r) {     if (x == -1) { l = r = -1; return; } else splay(x);     l = r = -1;     while (x != -1) { push(x); if (nodes[x].item.l() < v) l = x, x = nodes[x].ch[1]; else r = x, x = nodes[x].ch[0]; }     if (l != -1) splay(l); if (r != -1) splay(r, l);     if (l == -1) return;     assert(nodes[l].par == -1 && nodes[l].ch[1] == r && (r == -1 || nodes[r].ch[0] == -1));     push(l); disconnect(l, 1); update(l);     if (nodes[l].item.r() < v) return;     Item splitted = nodes[l].item.split(v);     if (nodes[l].ch[0] != -1 && nodes[nodes[l].ch[0]].item.r() == nodes[l].item.r()) l = disconnect(l, 0);     if (r == -1 || splitted.l() != nodes[r].item.l()) r = join(add(splitted), r);     update(l);    }    void gather(int x, vector<Item>& ret) { push(x); if (nodes[x].ch[0] != -1) gather(nodes[x].ch[0], ret); ret.PB(nodes[x].item); if (nodes[x].ch[1] != -1) gather(nodes[x].ch[1], ret); }    vector<Item> all(int x) { vector<Item> ret; if (x != -1) splay(x), gather(x, ret); return ret; }   };      const int MAXRECT = 200000;   const int INF = 1000000000;   struct Rect { int lt, rt, lx, rx; };      int nrect, sx;   Rect rect[MAXRECT];      struct Line {    int ly, ry, lcost, slope;    Line() {}    Line(int ly, int ry, int lcost, int slope) :ly(ly), ry(ry), lcost(lcost), slope(ly == ry ? 0 : slope) {}    int rcost() { return lcost + slope * (ry - ly); }    int len() { return ry - ly; }    void setly(int nly) { lcost += (nly - ly) * slope; ly = nly; if (ly == ry) slope = 0; }    void setry(int nry) { ry = nry; if (ly == ry) slope = 0; }    int l() { return ly; }    int r() { return ry; }    Line split(int y) {     assert(ly < y && y <= ry);     auto ret = Line(y, ry, lcost + (y - ly) * slope, slope);     setry(y - 1);     return ret;    }   };   struct SumLine { SumLine() {} SumLine(Line line) {} };   SumLine& operator+=(SumLine& a, const SumLine& b) { return a; }   struct LazyLine {};   Line& operator+=(Line& a, const LazyLine& b) { return a; }   SumLine& operator+=(SumLine& a, const LazyLine& b) { return a; }   LazyLine& operator+=(LazyLine& a, const LazyLine& b) { return a; }      SplayTree<Line, SumLine, LazyLine> linetree;      void printfunc(int lineroot,int tline) {    if (lineroot == -1) {     printf(  BLOCKED );    } else {     auto alllines = linetree.all(lineroot);     for (auto line : alllines) printf(  (%d,%d)..(%d,%d) , line.ly == -INF ? -INF : line.ly + tline, line.ly == -INF ? INF : line.lcost, line.ry == +INF ? +INF : line.ry + tline, line.ry == +INF ? INF : line.rcost());    }    puts(  );   }      int t;      int rtrimfunc(int node, int nry) {    while(true) {     node = linetree.last(node);     if (linetree.nodes[node].item.ry <= nry) break;     if (linetree.nodes[node].item.ly < nry || linetree.nodes[node].item.ly == nry && linetree.nodes[node].ch[0] == -1) {      linetree.nodes[node].item.setry(nry);      break;     }     node = linetree.disconnect(node, 0);     assert(node != -1);    }    return node;   }   int lgrowfunc(int node, int nly) {    node = linetree.first(node);    assert(nly <= linetree.nodes[node].item.ly);    if (nly == linetree.nodes[node].item.ly) return node;    if (linetree.nodes[node].item.slope == -1 || linetree.nodes[node].item.ly == linetree.nodes[node].item.ry) {     linetree.nodes[node].item.slope = -1;     linetree.nodes[node].item.setly(nly);     linetree.update(node);    } else {     Line line(nly, linetree.nodes[node].item.ly, linetree.nodes[node].item.lcost + linetree.nodes[node].item.ly - nly, -1);     node = linetree.join(linetree.add(line), node);    }    return node;   }   int rgrowfunc(int node, int nry) {    node = linetree.last(node);    assert(nry >= linetree.nodes[node].item.ry);    if (nry == linetree.nodes[node].item.ry) return node;    if (linetree.nodes[node].item.slope == +1 || linetree.nodes[node].item.ly == linetree.nodes[node].item.ry) {     linetree.nodes[node].item.slope = +1;     linetree.nodes[node].item.setry(nry);     linetree.update(node);    } else {     Line line(linetree.nodes[node].item.ry, nry, linetree.nodes[node].item.rcost(), +1);     node = linetree.join(node, linetree.add(line));    }    return node;   }   int shiftfunc(int node, int dt) {    if (dt == 0) return node;    node = linetree.first(node);    int ply = linetree.nodes[node].item.ly;    if (ply != -INF) node = lgrowfunc(node, ply - dt);    node = linetree.last(node);    int pry = linetree.nodes[node].item.ry;    if (pry != +INF) node = rtrimfunc(node, pry - dt);    return node;   }   int mergefunc(int l, int r) {    //printf( merging n );    //printfunc(l, t);    //printfunc(r, t);    l = linetree.last(l);    r = linetree.first(r);    while (l != -1 && r != -1 && linetree.nodes[l].item.rcost() > linetree.nodes[r].item.lcost) {     assert(linetree.nodes[l].item.ry == linetree.nodes[r].item.ly);     if (linetree.nodes[l].item.slope == -1 || linetree.nodes[l].item.ly == linetree.nodes[l].item.ry) {      r = lgrowfunc(r, linetree.nodes[l].item.ly);      l = linetree.disconnect(l, 0);     } else {      assert(linetree.nodes[l].item.slope == 1);      if (linetree.nodes[r].item.lcost + linetree.nodes[l].item.len() <= linetree.nodes[l].item.lcost) {       r = lgrowfunc(r, linetree.nodes[l].item.ly);       l = linetree.disconnect(l, 0);      } else {       int y = linetree.nodes[r].item.lcost - linetree.nodes[l].item.lcost + linetree.nodes[l].item.ly + linetree.nodes[l].item.ry; assert(y % 2 == 0); y /= 2;       assert(y > linetree.nodes[l].item.ly && y < linetree.nodes[l].item.ry);       r = lgrowfunc(r, y);       linetree.nodes[l].item.setry(y);      }     }     l = linetree.last(l);     r = linetree.first(r);    }    while (l != -1 && r != -1 && linetree.nodes[l].item.rcost() < linetree.nodes[r].item.lcost) {     assert(linetree.nodes[l].item.ry == linetree.nodes[r].item.ly);     if (linetree.nodes[r].item.slope == +1 || linetree.nodes[r].item.ly == linetree.nodes[r].item.ry) {      l = rgrowfunc(l, linetree.nodes[r].item.ry);      r = linetree.disconnect(r, 1);     } else {      assert(linetree.nodes[r].item.slope == -1);      if (linetree.nodes[l].item.rcost() + linetree.nodes[r].item.len() <= linetree.nodes[r].item.rcost()) {       l = rgrowfunc(l, linetree.nodes[r].item.ry);       r = linetree.disconnect(r, 1);      } else {       int y = linetree.nodes[r].item.rcost() - linetree.nodes[l].item.rcost() + linetree.nodes[r].item.ly + linetree.nodes[r].item.ry; assert(y % 2 == 0); y /= 2;       assert(y > linetree.nodes[r].item.ly && y < linetree.nodes[r].item.ry);       l = rgrowfunc(l, y);       linetree.nodes[r].item.setly(y);      }     }     l = linetree.last(l);     r = linetree.first(r);    }    int ret = linetree.join(l, r);    //printf( ->  ); printfunc(ret, t);    return ret;   }      struct Region {    int lx, rx, blockcnt, lineroot, tline;    Region(int lx, int rx, int blockcnt, int lineroot, int tline) :lx(lx), rx(rx), blockcnt(blockcnt), lineroot(lineroot), tline(tline) {};    int l() { return lx; }    int r() { return rx; }    void norm() { if (lineroot != -1) { lineroot = shiftfunc(lineroot, t - tline); tline = t; } }    Region split(int x) {     assert(lx < x && x <= rx);      norm();     auto ret = Region(x, rx, blockcnt, -1, tline);     rx = x - 1;     if (lineroot != -1) linetree.split(lineroot, x - t, lineroot, ret.lineroot);     return ret;    };   };   struct SumRegion {    int mnblockcnt;    SumRegion() { mnblockcnt = INT_MAX; }    SumRegion(Region region) { mnblockcnt = region.lineroot == -1 ? INT_MAX : region.blockcnt; }   };   SumRegion& operator+=(SumRegion& a, const SumRegion& b) { a.mnblockcnt = min(a.mnblockcnt, b.mnblockcnt); return a; }   struct LazyRegion {    int lazyblockcnt;    LazyRegion() { lazyblockcnt = 0; }    LazyRegion(int lazyblockcnt) :lazyblockcnt(lazyblockcnt) {}   };   Region& operator+=(Region& a, const LazyRegion& b) { a.blockcnt += b.lazyblockcnt; return a; }   SumRegion& operator+=(SumRegion& a, const LazyRegion& b) { if (a.mnblockcnt != INT_MAX) a.mnblockcnt += b.lazyblockcnt; return a; }   LazyRegion& operator+=(LazyRegion& a, const LazyRegion& b) { a.lazyblockcnt += b.lazyblockcnt; return a; }         SplayTree<Region, SumRegion, LazyRegion> regiontree;      void print(int regionroot) {    auto allregions = regiontree.all(regionroot);    for (auto region : allregions) {     //region.norm();     printf( [%d..%d] = %d: , region.lx, region.rx, region.blockcnt); if (region.lineroot!=-1 && region.tline != t) printf(  (delay %d) , t - region.tline);     printfunc(region.lineroot, region.tline);    }   }      int killzeroes(int node) {    regiontree.splay(node);    while (regiontree.nodes[node].sum.mnblockcnt == 0) {     //printf( killing n ); print(node);     while (regiontree.nodes[node].item.blockcnt != 0 || regiontree.nodes[node].item.lineroot == -1) {      //printf( node=%d n , node);      if (regiontree.nodes[node].ch[0] != -1 && regiontree.nodes[regiontree.nodes[node].ch[0]].sum.mnblockcnt == 0) {       node = regiontree.nodes[node].ch[0];      } else {       node = regiontree.nodes[node].ch[1];      }      assert(node != -1 && regiontree.nodes[node].sum.mnblockcnt == 0);     }     //printf( found node=%d n , node);     assert(regiontree.nodes[node].item.lineroot != -1);     regiontree.splay(node);     regiontree.nodes[node].item.lineroot = -1;     regiontree.update(node);    }    return node;   }      int rgrow(int node, int x) {    int l, r; regiontree.split(node, x + 1, l, r);    l = regiontree.last(l);    r = regiontree.first(r);    //printf( growing n );    //printf( l n ); print(l);    //printf( r n ); print(r);    if (l == -1 || regiontree.nodes[l].item.lineroot == -1) return regiontree.join(l, r);    while (r != -1 && regiontree.nodes[r].item.lineroot == -1 && regiontree.nodes[r].item.blockcnt == 0) {     //printf( step n );     assert(regiontree.nodes[l].item.rx + 1 == regiontree.nodes[r].item.lx);     regiontree.nodes[l].item.rx = regiontree.nodes[r].item.rx;     r = regiontree.disconnect(r, 1);     r = regiontree.first(r);    }    if (r != -1 && regiontree.nodes[r].item.lineroot != -1) {     assert(regiontree.nodes[l].item.rx + 1 == regiontree.nodes[r].item.lx);     regiontree.nodes[l].item.rx = regiontree.nodes[r].item.lx;     regiontree.nodes[l].item.norm();     regiontree.nodes[l].item.lineroot = rgrowfunc(regiontree.nodes[l].item.lineroot, regiontree.nodes[l].item.rx - t);     regiontree.nodes[r].item.norm();     regiontree.nodes[l].item.lineroot = mergefunc(regiontree.nodes[l].item.lineroot, regiontree.nodes[r].item.lineroot);     regiontree.nodes[l].item.rx = regiontree.nodes[r].item.rx;     r = regiontree.disconnect(r, 1);    } else {     regiontree.nodes[l].item.norm();     regiontree.nodes[l].item.lineroot = rgrowfunc(regiontree.nodes[l].item.lineroot, regiontree.nodes[l].item.rx - t);    }    int ret = regiontree.join(l, r);    //printf( after rgrow n ); print(ret);    return ret;   }      int lgrow(int node, int x) {    //printf( lgrow %d n , x);    int l, r; regiontree.split(node, x, l, r);    l = regiontree.last(l);    r = regiontree.first(r);    if (r == -1 || regiontree.nodes[r].item.lineroot == -1) return regiontree.join(l, r);    while (l != -1 && regiontree.nodes[l].item.lineroot == -1 && regiontree.nodes[l].item.blockcnt == 0) {     assert(regiontree.nodes[l].item.rx + 1 == regiontree.nodes[r].item.lx);     regiontree.nodes[r].item.lx = regiontree.nodes[l].item.lx;     l = regiontree.disconnect(l, 0);     l = regiontree.last(l);    }    if (l != -1 && regiontree.nodes[l].item.lineroot != -1) {     assert(regiontree.nodes[l].item.rx + 1 == regiontree.nodes[r].item.lx);     regiontree.nodes[l].item.rx = regiontree.nodes[r].item.lx;     regiontree.nodes[l].item.norm();     regiontree.nodes[l].item.lineroot = rgrowfunc(regiontree.nodes[l].item.lineroot, regiontree.nodes[l].item.rx - t);     regiontree.nodes[r].item.norm();     regiontree.nodes[l].item.lineroot = mergefunc(regiontree.nodes[l].item.lineroot, regiontree.nodes[r].item.lineroot);     regiontree.nodes[l].item.rx = regiontree.nodes[r].item.rx;     r = regiontree.disconnect(r, 1);    } else {     regiontree.nodes[r].item.norm();     regiontree.nodes[r].item.lineroot = lgrowfunc(regiontree.nodes[r].item.lineroot, regiontree.nodes[r].item.lx - t);    }    return regiontree.join(l, r);   }      int solve() {    //REP(i, nrect) printf( t=%d..%d y=%d..%d to %d..%d n , rect[i].lt, rect[i].rt, rect[i].lx - rect[i].lt, rect[i].rx - rect[i].lt, rect[i].lx - rect[i].rt, rect[i].rx - rect[i].rt);       linetree.reset();    regiontree.reset();    int linedn = linetree.add(Line(-INF, sx, abs(-INF - sx), -1));    int lineup = linetree.add(Line(sx, +INF, 0, +1));    int lineroot = linetree.join(linedn, lineup);    int regionroot = regiontree.add(Region(-INF, +INF, 0, lineroot, 0));       vector<pair<int, int>> e;    REP(i, nrect) e.PB(MP(2 * rect[i].lt + 1, i)), e.PB(MP(2 * rect[i].rt + 0, i));    sort(e.begin(), e.end());    //printf( INITIAL n ); print(regionroot);    REPSZ(i, e) {     t = e[i].first >> 1; int kind = e[i].first & 1, idx = e[i].second;     if (kind == 0) { // release rect      int l, m, r;      regiontree.split(regionroot, rect[idx].lx + 1, l, m);      regiontree.split(m, rect[idx].rx, m, r);      regiontree.apply(m, LazyRegion(-1));      regionroot = regiontree.join(regiontree.join(l, m), r);      regionroot = rgrow(regionroot, rect[idx].lx);      regionroot = lgrow(regionroot, rect[idx].rx);     }     if (kind == 1) { // block rect      int l, m, r;      regiontree.split(regionroot, rect[idx].lx + 1, l, m);      //printf( L n ); print(l);      //printf( M n ); print(m);      regiontree.split(m, rect[idx].rx, m, r);      //printf( M n ); print(m);      //printf( R n ); print(r);      m = killzeroes(m);      //printf( M n ); print(m);      regiontree.apply(m, LazyRegion(1));      regionroot = regiontree.join(regiontree.join(l, m), r);     }     //printf( after %s rect %d (t=%d) n , kind == 0 ?  releasing  :  blocking , idx + 1, t); print(regionroot);     //if (i == 0) exit(0);    }    //printf( FINAL (t=%d) n ,t); print(regionroot);       auto finalregions = regiontree.all(regionroot);    assert(SZ(finalregions) == 1);    auto finalregion = finalregions[0];    finalregion.norm();    assert(finalregion.lineroot != -1);    auto finalfunc = linetree.all(finalregion.lineroot);    int ret = INT_MAX;    for (auto func : finalfunc) ret = min(ret, min(func.lcost, func.rcost()));    return ret;   }      void run() {    scanf( %d , &nrect);    scanf( %d , &sx);    REP(i, nrect) scanf( %d%d%d%d , &rect[i].lt, &rect[i].rt, &rect[i].lx, &rect[i].rx), --rect[i].lt, ++rect[i].rt, --rect[i].lx, ++rect[i].rx;    printf( %d n , solve());   }      void stress() {    int mxrect = 100, mxdim = 100;    REP(rep, 10000) {     nrect = rnd() % mxrect + 1;     int tdim = rnd() % mxdim + 1;     int xdim = rnd() % mxdim + 1;     sx = rnd() % (xdim + 1);     REP(i, nrect) {      rect[i].lt = rnd() % tdim; rect[i].rt = rnd() % tdim; if (rect[i].lt > rect[i].rt) swap(rect[i].lt, rect[i].rt); rect[i].rt += 2;      rect[i].lx = rnd() % xdim; rect[i].rx = rnd() % xdim; if (rect[i].lx > rect[i].rx) swap(rect[i].lx, rect[i].rx); rect[i].rx += 2;     }     //printf( %d n%d n , nrect, sx); REP(i, nrect) printf( %d %d %d %d n , rect[i].lt + 1, rect[i].rt - 1, rect[i].lx + 1, rect[i].rx - 1);     solve();     printf( . );    }   }      int main() {    run();    //stress();    return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     vector<long long> l(n + 5), r(n + 5);     for (long long i = 1; i < n + 1; ++i) cin >> l[i];     for (long long i = 1; i < n + 1; ++i) cin >> r[i];     vector<pair<long long, long long> > v;     for (long long i = 1; i < n + 1; ++i) v.push_back({l[i] + r[i], i});     sort(v.begin(), v.end());     long long x = n, ans[n + 5];     for (long long i = 0; i < (long long)v.size(); ++i) {       ans[v[i].second] = x;       while (i + 1 < (long long)v.size() && v[i].first == v[i + 1].first) {         ++i;         ans[v[i].second] = x;       }       x--;     }     for (long long i = 1; i < n + 1; ++i) {       long long c1 = 0;       for (long long j = 1; j < i; ++j)         if (ans[i] < ans[j]) ++c1;       long long c2 = 0;       for (long long j = i + 1; j < n + 1; ++j)         if (ans[j] > ans[i]) ++c2;       if (c1 == l[i] && c2 == r[i]) continue;       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     for (long long i = 1; i < n + 1; ++i) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 5;   constexpr int LOGMAX = 31 - __builtin_clz(MAX) + 5;   int N;   char T[MAX];   int sa[MAX], tsa[MAX], ra[MAX], tra[MAX];   int lcp[MAX], plcp[MAX], phi[MAX], c[MAX], st[LOGMAX][MAX];   long long pref[MAX];   void sort(int k) {     memset(c, 0, sizeof c);     for (int i = int(0); i < int(N); i++) {       c[i + k < N ? ra[i + k] : 0]++;     }     int sum = 0, maxi = max(300, N);     for (int i = int(0); i < int(maxi); i++) {       int t = c[i];       c[i] = sum;       sum += t;     }     for (int i = int(0); i < int(N); i++) {       int cur = sa[i] + k < N ? ra[sa[i] + k] : 0;       tsa[c[cur]++] = sa[i];     }     memcpy(sa, tsa, sizeof(int) * N);   }   void build_sa() {     for (int i = int(0); i < int(N); i++) {       ra[i] = T[i];       sa[i] = i;     }     for (int k = 1; k < N; k *= 2) {       sort(k);       sort(0);       int r = tra[sa[0]] = 0;       for (int i = int(1); i < int(N); i++) {         if (ra[sa[i]] == ra[sa[i - 1]]) {           int cur = (sa[i] + k) < N ? ra[sa[i] + k] : 0;           int prev = (sa[i - 1] + k) < N ? ra[sa[i - 1] + k] : 0;           if (cur == prev) {             tra[sa[i]] = r;           } else {             tra[sa[i]] = ++r;           }         } else {           tra[sa[i]] = ++r;         }       }       if (tra[sa[N - 1]] == N - 1) {         break;       }       memcpy(ra, tra, sizeof(int) * N);     }   }   void build_lcp() {     phi[sa[0]] = -1;     for (int i = int(1); i < int(N); i++) {       phi[sa[i]] = sa[i - 1];     }     int l = 0;     for (int i = int(0); i < int(N); i++) {       if (phi[i] == -1) {         plcp[i] = 0;         continue;       }       while (T[i + l] == T[phi[i] + l]) {         l++;       }       plcp[i] = l;       l = max(l - 1, 0);     }     for (int i = int(0); i < int(N); i++) {       lcp[i] = plcp[sa[i]];     }   }   inline long long in_range(int left, int right) {     return pref[right] - pref[left - 1];   }   inline int min_query(int left, int right) {     int sz = right - left + 1;     int lg = 31 - __builtin_clz(sz);     return min(st[lg][left], st[lg][right - (1 << lg) + 1]);   }   string roll(int l, int r, int len, long long k) {     int left = l + 1, right = r;     int edge = l;     while (left <= right) {       int mid = (left + right) / 2;       if (min_query(l + 1, mid) >= len) {         edge = mid;         left = mid + 1;       } else {         right = mid - 1;       }     }     long long total = in_range(l, edge) - 1LL * (len - 1) * (edge - l + 1);     if (total < k) {       return roll(edge + 1, r, len, k - total);     } else if (k > (edge - l + 1)) {       return roll(l, r, len + 1, k - (edge - l + 1));     }     int pos = l + k - 1;     string ans =   ;     for (int i = int(0); i < int(len); i++) {       ans += T[sa[pos] + i];     }     return ans;   }   int main() {     scanf( %s , T);     N = strlen(T);     long long k;     scanf( %lld , &k);     if ((1LL * N * (N + 1)) / 2 < k) {       puts( No such line. );       return 0;     }     T[N++] =  $ ;     build_sa();     build_lcp();     for (int i = int(1); i < int(N); i++) {       pref[i] = pref[i - 1] + N - sa[i] - 1;       st[0][i] = lcp[i];     }     for (int i = int(1); i < int(LOGMAX); i++) {       for (int j = 1; j + (1 << i) - 1 < N; j++) {         st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);       }     }     printf( %s n , roll(1, N - 1, 1, k).c_str());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int INF = 1e16;   int a[2][111111];   int main(void) {     int n;     cin >> n;     for (int e = 0; e < 2; e++)       for (int p = 0; p < n; p++) cin >> a[e][p];     long long int tot = 0;     for (int e = 0; e < n; e++) tot += a[0][e];     sort(a[1], a[1] + n);     long long int kk = 0;     kk += a[1][n - 1] + a[1][n - 2];     if (kk >= tot)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int dp[2][100010], bit, n;   long long a[100010];   inline int comp(long long x, long long y) {     return (x % (1ll << (bit + 1))) > (y % (1ll << (bit + 1)));   }   int main() {     long long mx = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %lld , &a[i]);       mx = max(mx, a[i]);     }     int cur = 0;     memset(dp, 0x3f, sizeof(dp));     dp[0][0] = 0;     for (int i = 0; i < 63; i++) {       cur ^= 1;       int cnt1 = 0, cnt2 = 0;       memset(dp[cur], 0x3f, sizeof(dp[cur]));       for (int j = 0; j < n; j++) {         if (a[j] & (1ll << i)) cnt2++;       }       for (int j = 0; j <= n; j++) {         if (dp[cur ^ 1][j] != 0x3f3f3f3f) {           dp[cur][j + cnt2] =               min(dp[cur][j + cnt2], dp[cur ^ 1][j] + j - cnt1 + cnt2);           dp[cur][cnt1] =               min(dp[cur][cnt1], dp[cur ^ 1][j] + cnt1 + (n - j - cnt2));         }         if (a[j] & (1ll << i)) {           cnt1++;           cnt2--;         }       }       if ((1ll << i) > mx) break;       bit = i;       sort(a, a + n, comp);     }     printf( %d n , dp[cur][0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, ar[1000005], br[1000005];   int main() {     scanf( %lld %lld , &n, &k);     long long min_ = 0, max_ = 0;     for (int i = 1; i < n + 1; i++) {       ar[i] = br[i] = i;       min_ += i;       max_ += max((long long)i, n - i + 1);     }     if (k < min_) {       cout <<  -1 ;       return 0;     } else {       long long tot = min_;       long long t = n - 1;       k -= min_;       for (int i = 1; i < n + 1; i++) {         if (i >= n + 1 - i) break;         if (k > t) {           tot += t;           min_ += t;           swap(br[i], br[n + 1 - i]);         } else {           tot += k;           min_ += k;           swap(br[i], br[i + k]);           break;         }         k -= t;         t -= 2;       }       cout << tot <<   n ;     }     for (int i = 1; i < n + 1; i++) cout << ar[i] <<    ;     cout <<   n ;     for (int i = 1; i < n + 1; i++) cout << br[i] <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int read();   int n;   char t[102];   int w[102][102], rnk[102][102], pos[102];   vector<int> p[102];   queue<int> q;   void init(int t) {     for (int i = 1; i <= n; ++i) {       p[i].clear(), p[i + n].clear();       for (int j = 1; j <= n; ++j) p[i].push_back(j + n), p[i + n].push_back(j);       sort(p[i].begin(), p[i].end(),            [&](int a, int b) { return w[i][a - n] > w[i][b - n] ^ t; });       sort(p[i + n].begin(), p[i + n].end(),            [&](int a, int b) { return w[a][i] < w[b][i] ^ t; });       q.push(i), pos[i] = 0, pos[i + n] = n;       for (int j = 0; j < n; ++j)         rnk[j][p[i][j]] = j, rnk[i + n][p[i + n][j]] = j;     }     while (!q.empty()) {       int u = q.front(), v;       while (pos[v = p[u][pos[u]]] < rnk[v][u]) ++pos[u];       if (pos[v] < n) q.push(p[v][pos[v]]);       pos[v] = rnk[v][u], q.pop();     }   }   int main() {     for (int T = read(); T; --T) {       n = read();       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= n; ++j) w[i][j] = read();       puts( B ), fflush(stdout), scanf( %s , t);       if (t[0] ==  I )         for (int i = 1; i <= n; ++i)           for (int j = 1; j <= n; ++j) w[i][j] = -w[i][j];       int u;       for (init((u = read()) > n); ~u; u = read())         printf( %d n , p[u][pos[u]]), fflush(stdout);     }     return 0;   }   int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) f = (c ==  - ) ? -1 : f, c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x * f;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, a, n2, m2;     cin >> n >> m >> a;     if ((a * (n / a)) == n)       n2 = n / a;     else       n2 = (n / a) + 1;     if ((a * (m / a)) == m)       m2 = m / a;     else       m2 = (m / a) + 1;     cout << n2 * m2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     sort(v.begin(), v.end());     int out = n;     int cur = n / 2;     for (int i = 0; i < n / 2 && cur < n; i++) {       while (true) {         if (v[i] * 2 <= v[cur]) {           out--, cur++;           break;         } else {           cur++;           if (cur == n) break;         }       }     }     cout << out << endl;     return 0;   }