#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using P = pair<int, int>;   const long long MOD = 1000000007;   const long long INF = 1LL << 60;   const int INT_INF = 1000000000;   int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};   void solve() {     int n;     cin >> n;     vector<ll> a(n);     for (auto &ai : a) cin >> ai;     bool positive;     if (a[0] < 0)       positive = false;     else       positive = true;     ll sum = 0;     ll tmp = a[0];     for (int i = 1; i < n; i++) {       if (positive) {         if (a[i] > 0) {           tmp = max(tmp, a[i]);         } else {           sum += tmp;           tmp = a[i];           positive = false;         }       } else {         if (a[i] > 0) {           sum += tmp;           tmp = a[i];           positive = true;         } else {           tmp = max(tmp, a[i]);         }       }     }     sum += tmp;     cout << sum << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     for (int i = 0; i < t; i++) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a == 0) {       return b;     }     return gcd(b % a, a);   }   int idx[200001] = {0};   vector<int> g[160];   int dp[160][100001] = {0};   int len[160][200001] = {0};   int nless(vector<int>& v, int val) {     if (!(int)v.size()) return 0;     if (v[0] > val) return 0;     int l = 0, r = (int)v.size() - 1;     while (r - l + 1 > 2) {       int x = (l + r) / 2;       if (v[x] > val) {         r = x;       } else {         l = x;       }     }     if (r - l + 1 == 2) {       if (v[r] <= val) {         return r + 1;       } else {         return l + 1;       }     }     if (r - l + 1 == 1) {       return l + 1;     }   }   void solve() {     int n;     cin >> n;     vector<int> v(n);     for (int j = 0; j < n; j++) cin >> v[j];     int num = 1;     vector<int> factors;     factors.push_back(1);     for (int j = 2; j <= sqrt(n); j++) {       if (n % j == 0) {         factors.push_back(j);         num++;         if (j * j != n) {           factors.push_back(n / j);           num++;         }       }     }     sort(factors.begin(), factors.end());     for (int j = 0; j < (int)factors.size(); j++) {       idx[factors[j]] = j;     }     for (int j = 1; j < n; j++) {       g[idx[gcd(j, n)]].push_back(j);     }     for (int j = n - 1; j >= 0; j--) {       for (int i = 0; i < num; i++) {         dp[i][j % factors[i]] = max(dp[i][j % factors[i]], v[j]);       }     }     for (int j = n - 1; j >= 0; j--) {       for (int i = 0; i < num; i++) {         len[i][j] = (v[j] == dp[i][j % factors[i]]) * (1 + len[i][j + 1]);       }     }     for (int j = n - 1; j >= 0; j--) {       for (int i = 0; i < num; i++) {         len[i][j] = min(             n - 1, (v[j] == dp[i][j % factors[i]]) * (1 + len[i][(j + 1) % n]));       }     }     long long int ans = 0;     for (int j = 0; j < n; j++) {       for (int i = 0; i < num; i++) {         int cnt = nless(g[i], len[i][j]);         ans += cnt;       }     }     cout << ans <<   n ;     return;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2 * 1000 + 5;   const long long INF = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000;   int n, k, dp[maxn], a[maxn];   bool check(long long x) {     for (int i = 1; i <= n; i++) {       dp[i] = i - 1;       for (int j = 1; j < i; j++) {         if (abs(a[i] - a[j]) <= (i - j) * x)           dp[i] = min(dp[i], dp[j] + i - j - 1);         if (dp[i] + n - i <= k) return true;       }     }     return false;   }   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     if (n == 1) {       cout << 0 << endl;       return 0;     }     long long l = -1, r = INF + 1, mid;     while (r - l > 1) {       mid = (l + r) >> 1;       if (check(mid))         r = mid;       else         l = mid;     }     cout << r << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     int i = 0;     int cnt[101] = {0};     for (int i = 0; i < n; i++) {       cin >> arr[i];       cnt[arr[i]]++;     }     int a = -1, b = -1;     for (int i = 0; i <= 100; i++) {       if (cnt[i] == n / 2) {         if (a == -1)           a = i;         else           b = i;       }     }     if (a != -1 && b != -1) {       cout <<  YES n ;       cout << a <<     << b;     } else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 2020;   int n, m;   int mp[MAXN][MAXN], realx[MAXN], realy[MAXN], cntx, cnty;   char dir[MAXN];   int len[MAXN];   void unique(int *real, int &cnt) {     std::sort(real, real + cnt);     int t2 = 1;     for (int t1 = 1; t1 < cnt; t1++)       if (real[t1] ^ real[t1 - 1]) real[t2++] = real[t1];     cnt = t2;   }   inline bool legal(int x, int y) {     return x >= 0 && x <= cntx && y >= 0 && y <= cnty;   }   void dfs(int x, int y) {     mp[x][y] = -1;     if (legal(x + 1, y) && !mp[x + 1][y]) dfs(x + 1, y);     if (legal(x - 1, y) && !mp[x - 1][y]) dfs(x - 1, y);     if (legal(x, y + 1) && !mp[x][y + 1]) dfs(x, y + 1);     if (legal(x, y - 1) && !mp[x][y - 1]) dfs(x, y - 1);   }   int main() {     scanf( %d , &n);     register int nowx = 0, nowy = 0;     for (int i = 1; i <= n; i++) {       scanf( %s%d , dir + i, len + i);       switch (dir[i]) {         case  L :           realx[cntx++] = nowx + 1;           realx[cntx++] = nowx -= len[i];           realy[cnty++] = nowy;           realy[cnty++] = nowy + 1;           break;         case  R :           realx[cntx++] = nowx;           realx[cntx++] = (nowx += len[i]) + 1;           realy[cnty++] = nowy;           realy[cnty++] = nowy + 1;           break;         case  U :           realy[cnty++] = nowy;           realy[cnty++] = (nowy += len[i]) + 1;           realx[cntx++] = nowx;           realx[cntx++] = nowx + 1;           break;         case  D :           realy[cnty++] = nowy + 1;           realy[cnty++] = nowy -= len[i];           realx[cntx++] = nowx;           realx[cntx++] = nowx + 1;           break;       }     }     unique(realx, cntx);     unique(realy, cnty);     int curx = std::upper_bound(realx, realx + cntx, nowx = 0) - realx,         cury = std::upper_bound(realy, realy + cnty, nowy = 0) - realy, nxt;     for (int i = 1; i <= n; i++) {       switch (dir[i]) {         case  L :           nxt = std::upper_bound(realx, realx + cntx, nowx -= len[i]) - realx;           while (curx > nxt) mp[curx--][cury] = 1;           break;         case  R :           nxt = std::upper_bound(realx, realx + cntx, nowx += len[i]) - realx;           while (curx < nxt) mp[curx++][cury] = 1;           break;         case  U :           nxt = std::upper_bound(realy, realy + cnty, nowy += len[i]) - realy;           while (cury < nxt) mp[curx][cury++] = 1;           break;         case  D :           nxt = std::upper_bound(realy, realy + cnty, nowy -= len[i]) - realy;           while (cury > nxt) mp[curx][cury--] = 1;           break;       }     }     mp[curx][cury] = 1;     for (int i = 0; i <= cntx; i++) {       if (!mp[i][cnty]) dfs(i, cnty);       if (!mp[i][0]) dfs(i, 0);     }     for (int i = 1; i < cnty; i++) {       if (!mp[cntx][i]) dfs(cntx, i);       if (!mp[0][i]) dfs(0, i);     }     long long ans = 0;     for (int i = 1; i <= cntx; i++)       for (int j = 1; j <= cnty; j++)         if (~mp[i][j])           ans += 1ll * (realx[i] - realx[i - 1]) * (realy[j] - realy[j - 1]);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char func(char c) {     if (c >=  A  && c <=  Z ) c = tolower(c);     if (c ==  o )       c =  0 ;     else if (c ==  l  || c ==  i )       c =  1 ;     return c;   }   int main() {     string s;     int n;     cin >> s >> n;     for (int i = 0; i < n; i++) {       string str;       cin >> str;       if (str.size() != s.size()) continue;       bool ok = true;       for (int j = 0; j < s.size(); j++) {         if (func(s[j]) != func(str[j])) {           ok = false;           break;         }       }       if (ok) {         cout <<  No ;         return 0;       }     }     cout <<  Yes ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e5 + 5;   const long long inf = -1;   const long long m = 1e6;   vector<long long> prime;   bool sieve[m + 2];   void primeSieve() {     memset(sieve, true, sizeof(sieve));     sieve[0] = sieve[1] = false;     prime.push_back(2);     for (long long i = 4; i <= m; i += 2) sieve[i] = false;     long long sqrtn = sqrt(m);     for (long long i = 3; i <= sqrtn; i += 2) {       if (sieve[i]) {         for (long long j = i * i; j <= m; j += 2 * i) sieve[j] = false;       }     }     for (long long i = 3; i <= m; i += 2)       if (sieve[i]) prime.push_back(i);   }   map<pair<long long, long long>, long long> use;   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     primeSieve();     long long n, m, i;     cin >> n >> m;     long long pos =         upper_bound(prime.begin(), prime.end(), n - 2) - prime.begin();     long long need = prime[pos] - (n - 2);     vector<pair<long long, pair<long long, long long>>> v;     long long x = 1;     for (i = 1; i < n; i++) {       if (i + 1 == n) x = need;       v.push_back(make_pair(i, make_pair(i + 1, x)));       use[make_pair(i, i + 1)] = 1;     }     long long sum = (n - 2) + need;     m -= (n - 1);     for (i = 1; i < n; i++) {       if (m == 0) break;       for (long long j = i + 1; j <= n; j++) {         if (m == 0) break;         if (!use[make_pair(i, j)] and m) {           v.push_back(make_pair(i, make_pair(j, mod)));           m--;           use[make_pair(i, j)] = 1;         }       }     }     cout << sum <<     << sum << endl;     for (auto p : v) {       cout << p.first <<     << (p.second).first <<     << (p.second).second            << endl;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   using ll = long long;   using ld = long double;   using pi = pair<int, int>;   using pl = pair<ll, ll>;   using vi = vector<int>;   using vl = vector<ll>;   using vpi = vector<pi>;   using si = set<int>;   using sl = set<ll>;   using qi = queue<int>;   using ql = queue<ll>;   template <class T>   bool uin(T& a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool uax(T& a, T b) {     return a < b ? (a = b, true) : false;   }   template <class T>   bool uin(T& u, T& v, T a, T b) {     return v - u > b - a ? (u = a, v = b, true) : false;   }   template <class T>   bool uax(T& u, T& v, T a, T b) {     return v - u < b - a ? (u = a, v = b, true) : false;   }   namespace input {   template <class T>   void re(complex<T>& x);   template <class T1, class T2>   void re(pair<T1, T2>& p);   template <class T>   void re(vector<T>& a);   template <class T, size_t SZ>   void re(array<T, SZ>& a);   template <class T>   void re(T& x) {     cin >> x;   }   void re(double& x) {     string t;     re(t);     x = stod(t);   }   void re(ld& x) {     string t;     re(t);     x = stold(t);   }   template <class T, class... Ts>   void re(T& t, Ts&... ts) {     re(t);     re(ts...);   }   template <class T>   void re(complex<T>& x) {     T a, b;     re(a, b);     x = cd(a, b);   }   template <class T1, class T2>   void re(pair<T1, T2>& p) {     re(p.f, p.s);   }   template <class T>   void re(vector<T>& a) {     for (int i = 0; i < (((int)(a).size())); ++i) re(a[i]);   }   template <class T, size_t SZ>   void re(array<T, SZ>& a) {     for (int i = 0; i < (SZ); ++i) re(a[i]);   }   }  // namespace input   using namespace input;   namespace output {   void pr(int x) { cout << x; }   void pr(long x) { cout << x; }   void pr(ll x) { cout << x; }   void pr(unsigned x) { cout << x; }   void pr(unsigned long x) { cout << x; }   void pr(unsigned long long x) { cout << x; }   void pr(float x) { cout << x; }   void pr(double x) { cout << x; }   void pr(ld x) { cout << x; }   void pr(char x) { cout << x; }   void pr(const char* x) { cout << x; }   void pr(const string& x) { cout << x; }   void pr(bool x) { pr(x ?  true  :  false ); }   template <class T>   void pr(const complex<T>& x) {     cout << x;   }   template <class T1, class T2>   void pr(const pair<T1, T2>& x);   template <class T>   void pr(const T& x);   template <class T, class... Ts>   void pr(const T& t, const Ts&... ts) {     pr(t);     pr(ts...);   }   template <class T1, class T2>   void pr(const pair<T1, T2>& x) {     pr( { , x.f,  ,  , x.s,  } );   }   template <class T>   void pr(const T& x) {     pr( { );     bool fst = 1;     for (const auto& a : x) pr(!fst ?  ,   :   , a), fst = 0;     pr( } );   }   void ps() { pr(  n ); }   template <class T, class... Ts>   void ps(const T& t, const Ts&... ts) {     pr(t);     if (sizeof...(ts)) pr(   );     ps(ts...);   }   void pc() { pr( ] n ); }   template <class T, class... Ts>   void pc(const T& t, const Ts&... ts) {     pr(t);     if (sizeof...(ts)) pr( ,  );     pc(ts...);   }   }  // namespace output   using namespace output;   inline int bs(bool (*valid)(int), int l, int r, bool order) {     l--, r++;     if (!order) swap(l, r);     while (abs(r - l) > 1) {       int mid = (l + r) >> 1;       if (valid(mid))         r = mid;       else         l = mid;     }     valid(r);     return r;   }   struct dsu {     vector<int> p;     dsu(int n) { p.resize(n + 1); }     inline int get(int x) { return p[x] ? p[x] = get(p[x]) : x; }     inline bool mrg(int x, int y) {       return get(x) == get(y) ? false : p[get(x)] = get(y);     }   };   const int M = 1e9 + 7;   const ll lnf = 1e18 + 3;   const int inf = 1e9 + 3;   const int nax = 1e6 + 5;   typedef decay<decltype(M)>::type T;   struct mi {     T val;     explicit operator T() const { return val; }     mi() { val = 0; }     mi(const ll& v) {       val = (-M <= v && v <= M) ? v : v % M;       if (val < 0) val += M;     }     friend void pr(const mi& a) { pr(a.val); }     friend void re(mi& a) {       ll x;       re(x);       a = mi(x);     }     friend bool operator==(const mi& a, const mi& b) { return a.val == b.val; }     friend bool operator!=(const mi& a, const mi& b) { return !(a == b); }     friend bool operator<(const mi& a, const mi& b) { return a.val < b.val; }     mi operator-() const { return mi(-val); }     mi& operator+=(const mi& m) {       if ((val += m.val) >= M) val -= M;       return *this;     }     mi& operator-=(const mi& m) {       if ((val -= m.val) < 0) val += M;       return *this;     }     mi& operator*=(const mi& m) {       val = (ll)val * m.val % M;       return *this;     }     friend mi pow(mi a, ll p) {       mi ans = 1;       assert(p >= 0);       for (; p; p /= 2, a *= a)         if (p & 1) ans *= a;       return ans;     }     friend mi inv(const mi& a) {       assert(a != 0);       return pow(a, M - 2);     }     mi& operator/=(const mi& m) { return (*this) *= inv(m); }     friend mi operator+(mi a, const mi& b) { return a += b; }     friend mi operator-(mi a, const mi& b) { return a -= b; }     friend mi operator*(mi a, const mi& b) { return a *= b; }     friend mi operator/(mi a, const mi& b) { return a /= b; }   };   vi invs, fac, ifac;   void genFac(int SZ) {     invs.resize(SZ), fac.resize(SZ), ifac.resize(SZ);     invs[1] = fac[0] = ifac[0] = 1;     for (int i = (2); i <= (SZ - 1); ++i)       invs[i] = M - (ll)M / i * invs[M % i] % M;     for (int i = (1); i <= (SZ - 1); ++i) {       fac[i] = (ll)fac[i - 1] * i % M;       ifac[i] = (ll)ifac[i - 1] * invs[i] % M;     }   }   ll comb(int a, int b) {     if (a < b || b < 0) return 0;     return (ll)fac[a] * ifac[b] % M * ifac[a - b] % M;   }   ll p[nax], s, c;   int t, n, q[nax];   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     re(n);     vl a(n);     re(a);     for (int i = 0; i < (n); ++i) {       s = a[i], c = 1;       while (t && p[t] * c >= s * q[t]) s += p[t], c += q[t--];       p[++t] = s, q[t] = c;     }     for (int i = (1); i <= (t); ++i)       for (int j = 0; j < (q[i]); ++j) printf( %.9f n , (double)p[i] / q[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 2000000005;   const int maxt = (1 << 20) + 5;   int all[maxt], dp[2][maxt];   int best[30], a[30][30];   int mask[30][30], cost[30][30];   char str[30][30];   int n, m;   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , str[i]), best[i] = inf;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         scanf( %d , &a[i][j]), best[i] = min(best[i], a[i][j]);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         bool ok = true;         for (int k = 0; k < n; k++)           if (k != i && str[i][j] == str[k][j]) ok = false;         if (ok) best[i] = 0;       }     }     for (int j = 0; j < m; j++) {       for (int c = 0; c < 26; c++) {         mask[j][c] = 0;         cost[j][c] = 0;         int maxc = 0, cnt = 0;         for (int i = 0; i < n; i++)           if (str[i][j] -  a  == c) {             mask[j][c] |= 1 << i;             cost[j][c] += a[i][j];             maxc = max(maxc, a[i][j]);             cnt++;           }         cost[j][c] -= maxc;         if (cnt < 2) mask[j][c] = -1;       }     }     for (int i = 0; i < 1 << n; i++) dp[0][i] = dp[1][i] = inf;     int nw = 0, ls = 1;     dp[nw][0] = 0;     for (int j = 0; j < m; j++)       for (int c = 0; c < 26; c++)         if (mask[j][c] != -1) {           swap(nw, ls);           memcpy(dp[nw], dp[ls], sizeof dp[ls]);           for (int i = 0; i < 1 << n; i++) {             dp[nw][i | mask[j][c]] =                 min(dp[nw][i | mask[j][c]], dp[ls][i] + cost[j][c]);           }         }     for (int i = 0; i < 1 << n; i++) {       all[i] = 0;       for (int j = 0; j < n; j++)         if ((i >> j) & 1)           ;         else           all[i] += best[j];     }     int ans = inf;     for (int i = 0; i < 1 << n; i++) ans = min(ans, all[i] + dp[nw][i]);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[111], maxx;   int main() {     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> a[i];     maxx = a[0];     for (int i = 1; i < n; ++i) maxx = max(maxx, a[i]);     int tot = 0;     for (int i = 0; i < n; ++i) tot += maxx - a[i];     int res2 = maxx + m;     m -= tot;     if (m < 0) m = 0;     int res1 = maxx + m / n;     if (m % n) ++res1;     cout << res1 <<     << res2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e5 + 5;   const long long int M = 1e9 + 7;   queue<pair<long long int, long long int> > pq;   vector<long long int> v;   map<long long int, long long int> mpp;   set<pair<long long int, long long int> > st;   long long int a[N], h[N], indx[N][2];   long long int val[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long int n, l;     cin >> n;     string s;     cin >> s;     long long int a = 0;     long long int b = 0;     for (int i = int(0); i <= int(n - 1); i++) {       if (s[i] ==  8 ) a++;     }     long long int x = n / 11;     if (a < x)       cout << a;     else       cout << x;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops )   #pragma GCC optimize( no-stack-protector,fast-math )   using namespace std;   const long long N = 2e5 + 100, OO = 1e9 + 7, T = 1e6 + 10, M = 1e9 + 7,                   P = 6151, SQ = 280, lg = 20;   long long n;   long long pw(long long x, long long y) {     if (y == 0) return 1;     long long cnt = pw(x, y / 2);     cnt = (cnt * cnt) % n;     cnt = (cnt * (y % 2 == 1 ? x : 1)) % n;     return cnt;   }   int32_t main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     if (n == 1) return cout <<  YES n1 , 0;     if (n == 4) return cout <<  YES n1 n3 n2 n4 n , 0;     for (long long i = 2; i * i <= n; i++)       if (n % i == 0) return cout <<  NO , 0;     cout <<  YES n ;     long long zr = 1;     for (long long i = 1; i < n; i++) {       long long cnt = i * pw(zr, n - 2) % n;       cout << cnt <<   n ;       zr = (zr * cnt) % n;     }     cout << n <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, q = 0, s = 0, t = 0;     cin >> n;     for (int k = 1; k <= n; k++) {       cin >> q;       if (q == 1) {         if (t == 1)           s++;         else {           t++;           s++;         }       } else {         if (t == 1) {           t--;           s++;         }       }     }     if (t == 0 && s != 0) s--;     cout << s;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   const int mod1 = 1000000007;   long long gcd(long long a, long long b) {     long long c = a % b;     while (c != 0) {       a = b;       b = c;       c = a % b;     }     return b;   }   long long issub(string a, string b) {     if (a.find(b) != string::npos)       return 1;     else       return 0;   }   long long expo(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % mod1;       a = a * a % mod1;       b >>= 1;     }     return res;   }   int32_t lcm(long long n1, long long n2) {     long long max = (n1 > n2) ? n1 : n2;     do {       if (max % n1 == 0 && max % n2 == 0) {         return max;       } else         ++max;     } while (true);   }   string operator*(string a, unsigned long long b) {     string output =   ;     while (b--) output += a;     return output;   }   bool isPerfectSquare(long long n) {     for (long long i = 1; i * i <= n; i++) {       if ((n % i == 0) && (n / i == i)) {         return true;       }     }     return false;   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     ;     long long t, a = 0, x;     cin >> t;     map<long long, long long> m;     for (long long i = 0; i < t; i++) {       cin >> x;       m[x]++;       a = max(a, m[x]);     }     cout << a;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 9;   const int Mod = 1e9 + 7;   inline int dcmp(double x) {     if (fabs(x) <= 1e-9) return 0;     return x < 0 ? -1 : 1;   }   inline int scan() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline long long scan(long long x) {     int f = 1;     char ch = getchar();     x = 0;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   struct Point {     int x, y, id;     Point(int x = 0, int y = 0) : x(x), y(y) {}     Point operator-(const Point &a) const { return Point(x - a.x, y - a.y); }     Point operator*(const long long &a) const { return Point(x * a, y * a); }     Point operator+(const Point &a) const { return Point(x + a.x, y + a.y); }     bool operator==(const Point &a) const {       return dcmp(x - a.x) == 0 && dcmp(y - a.y) == 0;     }     bool operator<(const Point &a) const {       if (x == a.x) return y < a.y;       return x < a.x;     }     void read() { scanf( %d%d , &x, &y); }     void out() { cout << x <<     << y << endl; }   };   double Dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }   double dis(Point a) { return sqrt(Dot(a, a)); }   long long Cross(Point a, Point b) { return a.x * 1LL * b.y - a.y * 1LL * b.x; }   bool chk(Point p1, Point p2, Point p3, Point p) {     return abs(Cross(p2 - p, p1 - p)) + abs(Cross(p3 - p, p2 - p)) +                abs(Cross(p1 - p, p3 - p)) ==            abs(Cross(p2 - p1, p3 - p1));   }   int n, k, ti;   int a[200005], vis[200005];   void solve() {     n = scan();     k = scan();     for (int i = 1; i <= n; i++) a[i] = scan();     memset(vis, 0, sizeof(vis));     sort(a + 1, a + 1 + n);     for (int i = 1; i <= n; i++) {       ti = i;       while (ti - 1) {         ti--;         if (vis[ti]) break;         if (a[ti] + k < a[i]) break;         if (a[ti] < a[i])           vis[ti] = 1;         else           break;       }     }     ti = 0;     for (int i = 1; i <= n; i++) {       if (!vis[i]) ti++;     }     cout << ti << endl;   }   int main() {     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O2,no-stack-protector,unroll-loops,fast-math )   const long long maxn = 1e5 + 10, maxm = 5e2 + 10, lg = 21, mod = 1e9 + 7,                   inf = 1e18;   long long n, m, s;   long double dp[101][maxn], ps[maxn];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     if (m == 1) return cout << 1, 0;     dp[0][0] = m - 1;     fill(ps, ps + maxn, m - 1);     for (int i = 1; i <= n; i++) {       long long x;       cin >> x;       s += x;       for (int j = 1; j <= n * m; j++)         dp[i][j] = (ps[j - 1] - (j - m - 1 >= 0 ? ps[j - m - 1] : 0) -                     (j - x >= 0 ? dp[i - 1][j - x] : 0)) /                    (m - 1);       ps[0] = 0;       for (int j = 1; j <= n * m; j++) ps[j] = ps[j - 1] + dp[i][j];     }     cout << fixed << setprecision(18) << ps[s - 1] + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, p;     cin >> n >> p;     long long ans = 5 * 5000000;     for (long long i = 1; i <= 5000000; i++) {       long long left = n - p * i;       if (left < 1)         continue;       else {         long long k = __builtin_popcount(left);         if (k <= i and left >= i) {           cout << i;           return 0;         }       }     }     cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 7;   long long n, a[N], cnt[N];   int32_t main() {     cin >> n;     for (long long i = 0; i < n; i++) cin >> a[i], cnt[a[i]]++;     for (long long i = 1; i < N; i++)       if (cnt[i] > 0) {         if (cnt[i] > n / 2)           cout <<  Bob ;         else           cout <<  Alice ;         return 0;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 410;   int cnt[N];   int temp[N];   long long cost[N][N];   long long dp[N][N];   long long n, m, k;   const long long INF = (1LL) << 60;   vector<int> v[200];   int main() {     while (cin >> n >> m >> k) {       memset(dp, 0, sizeof(dp));       for (int i = 0; i < N; i++)         for (int j = 0; j < N; j++) {           cost[i][j] = INF;           dp[i][j] = INF;         }       for (long long i = 0; i < m; i++) {         long long l, r, c;         cin >> l >> r >> c;         cost[l - 1][r] = min(cost[l - 1][r], c);       }       for (long long i = 0; i <= n; i++)         for (long long j = n; j >= i; j--) {           cost[i][j - 1] = min(cost[i][j - 1], cost[i][j]);           cost[i + 1][j] = min(cost[i + 1][j], cost[i][j]);         }       dp[0][0] = 0;       for (long long i = 1; i <= n; i++) {         for (long long j = 0; j <= i; j++) {           dp[i][j] = dp[i - 1][j];           for (long long k = 0; k < i; k++) {             if (j - i + k >= 0)               dp[i][j] = min(dp[i][j], dp[k][j - i + k] + cost[k][i]);           }         }       }       long long ans = INF;       for (long long i = k; i <= n; i++) ans = min(ans, dp[n][i]);       if (ans == INF)         cout << -1 << endl;       else         cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void print(T& x) {     cout << x;   }   template <class T, class U>   void print(pair<T, U>& p) {     cout <<  ( ;     print(p.first);     cout <<  ,  ;     print(p.second);     cout <<  ) ;   }   template <class T>   void print(vector<T>& v) {     cout <<  { ;     if (((int)(v).size())) print(v[0]);     for (int i = 1; i < ((int)(v).size()); i++) cout <<  ,  , print(v[i]);     cout <<  } n ;   }   const int n = 1e6 + 10;   int N, Q;   vector<vector<pair<int, int>>> T;   int X[n];   int Par[n];   pair<int, int> intv[n];   int newNum[n];   int cmp[n];   struct fenwick_tree {     int n;     vector<int> a, f;     fenwick_tree(int n = 0) : n(n), a(n), f(n + 1) {}     fenwick_tree(vector<int>& a) : fenwick_tree(a.size()) {       for (int i = 0; i < n; i++) setValue(i, a[i]);     }     void changeValue(int i, int d) {       for (a[i++] += d; i <= n; i += i & -i) f[i] += d;     }     void setValue(int i, int v) { changeValue(i, v - a[i]); }     int getSum(int i) {       int s = 0;       for (i++; i; i -= i & -i) s += f[i];       return s;     }     int getSum(int l, int r) { return getSum(r - 1) - getSum(l - 1); }   };   struct sparse_table {     int n;     vector<int> a;     vector<vector<int>> st;     int combine(int dl, int dr) { return a[dl] > a[dr] ? dl : dr; }     sparse_table() {}     sparse_table(vector<int>& a)         : n(a.size()), a(a), st((31 - __builtin_clz(n)) + 1, vector<int>(n)) {       for (int i = 0; i < n; i++) st[0][i] = i;       for (int j = 1; 1 << j <= n; j++)         for (int i = 0; i + (1 << j) <= n; i++)           st[j][i] = combine(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]);     }     int query(int l, int r) {       int s = (31 - __builtin_clz(r - l));       return combine(st[s][l], st[s][r - (1 << s)]);     }   };   struct lowest_common_ancestor {     int n, m = 0;     vector<int> a, v, h;     vector<vector<int>>& e;     sparse_table st;     lowest_common_ancestor(vector<vector<int>>& e, int r)         : n(e.size()), a(n), v(2 * n - 1), h(2 * n - 1), e(e) {       dfs(r);       st = sparse_table(h);     }     void dfs(int i, int p = -1, int d = 0) {       a[i] = m;       v[m] = i;       h[m++] = d;       for (int j : e[i]) {         if (j == p) continue;         dfs(j, i, d - 1);         v[m] = i;         h[m++] = d;       }     }     int lca(int x, int y) {       return v[st.query(min(a[x], a[y]), max(a[x], a[y]) + 1)];     }   };   fenwick_tree BIT(n);   void initDSU() {     for (int i = 0; i < N; i++) {       cmp[i] = i;     }   }   int find(int x) {     if (cmp[x] != x) cmp[x] = find(cmp[x]);     return cmp[x];   }   void combine(int a, int b) { cmp[find(a)] = find(b); }   int newN = 0;   void dfs(int cur, int par) {     newNum[cur] = newN;     int l = newN++;     for (auto [x, w] : T[cur]) {       if (x == par) continue;       Par[x] = cur;       X[x] = X[cur] ^ w;       dfs(x, cur);     }     intv[cur] = make_pair(l, newN - 1);   }   void mark(int x) {     auto [l, r] = intv[x];     BIT.changeValue(l, 1);     BIT.changeValue(r + 1, -1);   }   void markPath(int x, int to) {     while (x != to) {       mark(x);       x = Par[x];     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> N >> Q;     T.resize(N);     vector<tuple<int, int, int>> A;     initDSU();     for (int i = 0; i < Q; i++) {       int u, v, x;       cin >> u >> v >> x;       u--;       v--;       A.emplace_back(u, v, x);       if (find(u) != find(v)) {         T[u].emplace_back(v, x);         T[v].emplace_back(u, x);         combine(u, v);       }     }     for (int i = 1; i < N; i++) {       if (find(i) != find(0)) {         combine(0, i);         T[0].emplace_back(i, 0);         T[i].emplace_back(0, 0);       }     }     initDSU();     dfs(0, -1);     vector<vector<int>> e(N);     for (int i = 0; i < N; i++) {       for (int j = 0; j < ((int)(T[i]).size()); j++)         e[i].push_back(T[i][j].first);     }     lowest_common_ancestor LCA(e, 0);     for (auto [u, v, x] : A) {       if (find(u) != find(v)) {         combine(u, v);         cout <<  YES n ;       } else if ((X[u] ^ X[v] ^ x) == 1) {         int lca = LCA.lca(u, v);         int sum = BIT.getSum(newNum[u]) + BIT.getSum(newNum[v]) -                   2 * BIT.getSum(newNum[lca]);         if (sum == 0) {           cout <<  YES n ;           markPath(v, lca);           markPath(u, lca);         } else           cout <<  NO n ;       } else         cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int dp[1005];   long long ncr[1005][1005];   int ones(int n);   void calc_ncr();   int main() {     string n;     int k;     cin >> n;     cin >> k;     calc_ncr();     dp[1] = 0;     for (int i(2); i < (1001); i++) {       dp[i] = dp[ones(i)] + 1;     }     long long res = 0, num_ones = 0;     int len = n.length();     if (k == 0) {       cout <<  1 n ;       return 0;     }     for (int i(0); i < (len); i++) {       if (n[i] ==  0 ) {         continue;       }       int j = max(num_ones, 1LL);       while (j < 1000) {         if (dp[j] == k - 1) {           res = (res + ncr[len - i - 1][j - num_ones]) % 1000000007;           if (i == 0 && k == 1) {             res = (res + 1000000007 - 1) % 1000000007;           }         }         j++;       }       num_ones++;     }     int count = 0;     for (int i(0); i < (len); i++) {       if (n[i] ==  1 ) {         count++;       }     }     if (dp[count] == k - 1) {       res = (res + 1) % 1000000007;     }     cout << res <<   n ;     return 0;   }   int ones(int n) {     int count = 0;     while (n) {       if (n % 2 == 1) {         count++;       }       n /= 2;     }     return count;   }   void calc_ncr() {     for (int i(0); i < (1001); i++) {       ncr[i][0] = 1;     }     for (int i(1); i < (1001); i++) {       for (int j(1); j < (i + 1); j++) {         ncr[i][j] = (ncr[i - 1][j - 1] + ncr[i - 1][j]) % 1000000007;       }     }   }


#include<bits/stdc++.h>   using namespace std;   vector<int> vec[200001];   int ans[200001],arr[200001];   struct data   {    int l,r,mini,maxi,d;   };   data tree[1000001];   void pushup(int x)   {       tree[x].maxi=max(tree[x<<1].maxi,tree[(x<<1)+1].maxi);       tree[x].mini=min(tree[x<<1].mini,tree[(x<<1)+1].mini);       return;   }   void pushdown(int x)   {    int mid=(tree[x].l+tree[x].r)>>1;    int d=tree[x].d;    tree[x<<1].d+=d;    tree[(x<<1)+1].d+=d;    tree[x<<1].maxi+=d;    tree[(x<<1)+1].maxi+=d;    tree[x<<1].mini+=d;    tree[(x<<1)+1].mini+=d;    tree[x].d=0;    pushup(x);    return;    }   void revise(int i,int l,int r,int d)   {        if(l<=tree[i].l&&r>=tree[i].r)    {     tree[i].d+=d;     tree[i].maxi+=d;     tree[i].mini+=d;     return ;    }    int mid=(tree[i].l+tree[i].r)>>1;    if(tree[i].d!=0)    {     pushdown(i);    }    if(mid>=l)    {     revise(i<<1,l,r,d);    }    if(mid<r)    {     revise((i<<1)+1,l,r,d);    }    pushup(i);       }   int query_max(int i,int l,int r)   {    if(r==0)    {     return 0;    }    int mid=(tree[i].l+tree[i].r)>>1;        if(l<=tree[i].l&&r>=tree[i].r)    {     return tree[i].maxi;    }    if(tree[i].d!=0)    {     pushdown(i);    }    pushup(i);    int ans=-1e9;    if(mid>=l)    {     ans=max(ans,query_max((i<<1),l,r));    }    if(mid<r)    {     ans=max(ans,query_max(((i<<1)+1),l,r));    }    pushup(i);    return ans;   }   int query_min(int i,int l,int r)   {    if(r==0)    {     return 0;    }    int mid=(tree[i].l+tree[i].r)>>1;        if(l<=tree[i].l&&r>=tree[i].r)    {     return tree[i].mini;    }    if(tree[i].d!=0)    {     pushdown(i);    }    pushup(i);    int ans=1e9;    if(mid>=l)    {     ans=min(ans,query_min((i<<1),l,r));    }    if(mid<r)    {     ans=min(ans,query_min(((i<<1)+1),l,r));    }    pushup(i);    return ans;   }   void init(int i,int l,int r)   {    tree[i].l=l;    tree[i].r=r;    tree[i].maxi=0;    tree[i].d=0;    tree[i].mini=0;    if(l==r)    {     return;    }    int mid=(l+r)>>1;    init((i<<1),l,mid);    init((i<<1)+1,mid+1,r);    return;   }   int main()   {    int n;    cin>>n;    for(int i=1 ; i<=n ; i++)    {     cin>>arr[i];     vec[arr[i]].push_back(i);    }    init(1,1,n);    for(int i=1;  i<=n ; i++)    {     revise(1,i,n,-1);    }    for(int i=1 ; i<=n ; i++)    {     ans[i]=0;    }    for(int i=1;  i<=n ; i++)    {     for(int j=0 ; j<vec[i].size() ; j++)     {      revise(1,vec[i][j],n,2);      int k=vec[i][j];      int a=query_max(1,1,k-1);      int b=query_min(1,k,n);      a=max(a,0);      int c=b-a;      int tmp=(floor)((double)(c-1)/(double)2);      //cout<<vec[i][j]<<   <<a<<   <<b<<  n ;      ans[k]=max(ans[k],abs(tmp));      revise(1,vec[i][j],n,-2);     }          for(int j=0 ; j<vec[i].size() ; j++)     {      int k=vec[i][j];      revise(1,k,n,2);     }     for(int j=0 ; j<vec[i].size() ; j++)     {      int k=vec[i][j];      int a=query_min(1,1,k-1);      int b=query_max(1,k,n);      a=min(0,a);      int c=b-a;      //cout<<c<<  n ;      int tmp=(floor)((double)(c-1)/(double)2);      //cout<<vec[i][j]<<   <<tmp<<   <<b<<  n ;      ans[k]=max(ans[k],abs(tmp));     }    }    for(int i=1;  i<=n ; i++)    {     cout<<ans[i]<<   ;    }    cout<<  n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF(0x3f3f3f3f3f3f3f3fll);   const long long inf(0x3f3f3f3f);   template <typename T>   void read(T &res) {     bool flag = false;     char ch;     while (!isdigit(ch = getchar())) (ch ==  - ) && (flag = true);     for (res = ch - 48; isdigit(ch = getchar());          res = (res << 1) + (res << 3) + ch - 48)       ;     flag && (res = -res);   }   template <typename T>   void Out(T x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) Out(x / 10);     putchar(x % 10 +  0 );   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   long long pow_mod(long long x, long long n, long long mod) {     long long res = 1;     while (n) {       if (n & 1) res = res * x % mod;       x = x * x % mod;       n >>= 1;     }     return res;   }   long long fact_pow(long long n, long long p) {     long long res = 0;     while (n) {       n /= p;       res += n;     }     return res;   }   long long mult(long long a, long long b, long long p) {     a %= p;     b %= p;     long long r = 0, v = a;     while (b) {       if (b & 1) {         r += v;         if (r > p) r -= p;       }       v <<= 1;       if (v > p) v -= p;       b >>= 1;     }     return r;   }   long long quick_pow(long long a, long long b, long long p) {     long long r = 1, v = a % p;     while (b) {       if (b & 1) r = mult(r, v, p);       v = mult(v, v, p);       b >>= 1;     }     return r;   }   bool CH(long long a, long long n, long long x, long long t) {     long long r = quick_pow(a, x, n);     long long z = r;     for (long long i = 1; i <= t; i++) {       r = mult(r, r, n);       if (r == 1 && z != 1 && z != n - 1) return true;       z = r;     }     return r != 1;   }   bool Miller_Rabin(long long n) {     if (n < 2) return false;     if (n == 2) return true;     if (!(n & 1)) return false;     long long x = n - 1, t = 0;     while (!(x & 1)) {       x >>= 1;       t++;     }     srand(time(NULL));     long long o = 8;     for (long long i = 0; i < o; i++) {       long long a = rand() % (n - 1) + 1;       if (CH(a, n, x, t)) return false;     }     return true;   }   void exgcd(long long a, long long b, long long &x, long long &y) {     if (!b) {       x = 1, y = 0;       return;     }     exgcd(b, a % b, x, y);     long long t = x;     x = y, y = t - (a / b) * y;   }   long long inv(long long a, long long b) {     long long x, y;     return exgcd(a, b, x, y), (x % b + b) % b;   }   long long crt(long long x, long long p, long long mod) {     return inv(p / mod, mod) * (p / mod) * x;   }   long long fac(long long x, long long a, long long b) {     if (!x) return 1;     long long ans = 1;     for (long long i = 1; i <= b; i++)       if (i % a) ans *= i, ans %= b;     ans = pow_mod(ans, x / b, b);     for (long long i = 1; i <= x % b; i++)       if (i % a) ans *= i, ans %= b;     return ans * fac(x / a, a, b) % b;   }   long long C(long long n, long long m, long long a, long long b) {     long long N = fac(n, a, b), M = fac(m, a, b), Z = fac(n - m, a, b), sum = 0,               i;     for (i = n; i; i = i / a) sum += i / a;     for (i = m; i; i = i / a) sum -= i / a;     for (i = n - m; i; i = i / a) sum -= i / a;     return N * pow_mod(a, sum, b) % b * inv(M, b) % b * inv(Z, b) % b;   }   long long exlucas(long long n, long long m, long long p) {     long long t = p, ans = 0, i;     for (i = 2; i * i <= p; i++) {       long long k = 1;       while (t % i == 0) {         k *= i, t /= i;       }       ans += crt(C(n, m, i, k), p, k), ans %= p;     }     if (t > 1) ans += crt(C(n, m, t, t), p, t), ans %= p;     return ans % p;   }   const long long N = 3e5 + 10;   signed main() {     std::ios::sync_with_stdio(false);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       cout << n <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   int const maxn = 3000005;   string st[maxn];   int ab[200], ac[200], ad[200];   char b[maxn], c[maxn], d[maxn];   int main() {     cin >> b >> c;     int lenc = strlen(c);     for (int i = 0; i < lenc; i++) {       ac[c[i] -  a ]++;     }     int tw = 0, t = 0;     int lenb = strlen(b);     for (int i = 0; i < lenb; i++) {       if (b[i] ==  ? )         tw++;       else         ab[b[i] -  a ]++;     }     while (tw > 0) {       for (int i = 0; i < 26; i++) {         if (tw == 0) break;         if (ab[i] >= ac[i]) {           ab[i] -= ac[i];         } else {           if (tw >= ac[i] - ab[i]) {             tw -= ac[i] - ab[i];             ad[i] += ac[i] - ab[i];             ab[i] = 0;           } else {             ad[0] += tw;             tw = 0;           }         }       }     }     for (int i = 0; i < 26; i++) {       for (int j = 0; j < ad[i]; j++) {         d[t++] = (char)(i +  a );       }     }     t = 0;     for (int i = 0; i < lenb; i++) {       if (b[i] ==  ? ) {         cout << d[t++];       } else         cout << b[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   int a[N], n;   double f(double x) {     double sum = 0, mn = 0, mx = 0, ans = 0;     for (int i = 0; i < n; i++) {       mn = min(mn, sum);       mx = max(mx, sum);       sum += a[i] - x;       ans = max(ans, abs(sum - mn));       ans = max(ans, abs(sum - mx));     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     double l = -1e4 - 7, r = 1e4 + 7;     int t = 230;     while (t--) {       double mid1 = (2 * r + l) / 3;       double mid2 = (2 * l + r) / 3;       if (f(mid1) < f(mid2))         l = mid2;       else         r = mid1;     }     cout << setprecision(9) << fixed << f(l) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, ans;   int a[6][6];   int convert(char c) {     if (c ==  R ) return 1;     if (c ==  G ) return 2;     if (c ==  B ) return 3;     if (c ==  Y ) return 4;     if (c ==  W ) return 5;   }   void xuly(int state) {     int i, j, dem, c1, c2;     bool val[10], col[10];     int temp[15];     dem = 0;     for (i = 0; i < 5; i++)       if (state & (1 << i)) {         dem++;         val[i + 1] = true;       } else         val[i + 1] = false;     for (i = 5; i < 10; i++)       if (state & (1 << i)) {         dem++;         col[i - 4] = true;       } else         col[i - 4] = false;     memset(temp, 0, sizeof(temp));     for (i = 1; i <= 5; i++)       for (j = 1; j <= 5; j++)         if (a[i][j]) {           if (val[i] && col[j]) continue;           if (val[i])             temp[i]++;           else if (col[j])             temp[j + 5]++;           else             temp[11]++;         }     for (i = 1; i <= 11; i++)       if (temp[i] > 1) return;     ans = min(ans, dem);   }   void solve() {     int i, j;     ans = 10;     for (i = 0; i < (1 << 11); i++) xuly(i);     cout << ans << endl;   }   void input() {     int i;     char s[10];     scanf( %d , &n);     memset(a, 0, sizeof(a));     for (i = 0; i < n; i++) {       scanf( %s , &s);       a[convert(s[0])][s[1] -  0 ]++;     }     solve();   }   int main() {     input();     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int a;     int b;     int dado[] = {1, 2, 3, 4, 5, 6};     cin >> a >> b;     int r1, r2, r3;     r1 = r2 = r3 = 0;     for (int i = 0; i < 6; ++i)       abs(dado[i] - a)<abs(dado[i] - b) ? r1++ : abs(dado[i] - a)> abs(dado[i] -                                                                        b)           ? r2++           : r3++;     cout << r1 <<     << r3 <<     << r2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long unsigned int combi(long unsigned int a) {     if (a == 0 || a == 1) return 0;     return ((a * (a - 1)) / 2);   }   int main() {     int n = 0;     cin >> n;     char arr[n];     int letras[26];     char temp = 0;     long unsigned int res = 0;     for (int i = 0; i < 26; i++) {       letras[i] = 0;     }     for (int i = 0; i < n; i++) {       cin >> temp;       cin.ignore(256,   n );       letras[temp - 97]++;     }     for (int i = 0; i < 26; i++) {       res += (combi(letras[i] - (letras[i] / 2)) + (combi(letras[i] / 2)));     }     printf( %lu , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   bool ckmin(T &a, U b) {     return b < a ? a = b, true : false;   }   template <typename T, typename U>   bool ckmax(T &a, U b) {     return b > a ? a = b, true : false;   }   int tt;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> tt;     while (tt--) {       int n, x, y, un = -1;       cin >> n >> x >> y;       set<int> second;       vector<int> v(n, 0), res(n, -1);       map<int, vector<int>> m;       vector<pair<int, vector<int>>> a, b;       for (int i = 0; i < n; ++i) {         cin >> v[i];         v[i]--;         m[v[i]].push_back(i);       }       for (int i = 0; i <= n; ++i) second.insert(i);       for (auto i : v) {         if (second.find(i) != second.end()) second.erase(i);       }       un = (*second.begin());       for (auto i : m) a.push_back(i);       sort(a.begin(), a.end(),            [](const pair<int, vector<int>> &a, const pair<int, vector<int>> &b) {              return (int)(a.second).size() < (int)(b.second).size();            });       int cnt = 0, pp = 0;       map<int, vector<int>> tmp;       while (cnt < n - x) {         if ((int)(a[pp].second).size()) {           tmp[a[pp].first].push_back(a[pp].second.back());           a[pp].second.pop_back();           cnt++;         }         pp++;         if (pp >= (int)(a).size()) pp -= (int)(a).size();       }       for (auto i : tmp) {         b.push_back(i);       }       for (auto i : a) {         for (auto j : i.second) {           res[j] = i.first;         }       }       vector<pair<int, int>> xx, yy;       for (auto i : b) {         for (auto j : i.second) {           xx.push_back(make_pair(i.first, j));           yy.push_back(make_pair(i.first, j));         }       }       rotate(yy.begin(), yy.begin() + ((int)(yy).size() / 2), yy.end());       vector<int> store;       for (int i = 0; i < (int)(yy).size(); ++i) {         if (xx[i].first == yy[i].first) store.push_back(i);       }       if ((int)(store).size() > n - y) {         cout <<  NO n ;         continue;       }       for (auto i : store) {         xx[i].first = un;         res[yy[i].second] = un;       }       int rem = n - y - (int)(store).size();       for (int i = 0; i < (int)(yy).size(); ++i) {         if (rem && xx[i].first != un) {           rem--;           xx[i].first = un;           res[yy[i].second] = un;         } else {           res[yy[i].second] = xx[i].first;         }       }       cout <<  YES n ;       for (auto i : res) cout << i + 1 <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9 * 2;   int n, m, ind;   long long L[55], M[55], R[55], A[55], ans = -inf, un;   bool all = 1;   vector<int> a[55];   void calc() {     for (int i = 0; i < n; i++) {       R[i] = M[i] = L[i] = -inf;       for (int j = 0; j < a[i].size(); j++) {         A[i] += (long long)a[i][j];         if (A[i] > L[i]) L[i] = A[i];       }       long long sum = 0;       for (int j = a[i].size() - 1; j >= 0; j--) {         sum += (long long)a[i][j];         if (sum > R[i]) R[i] = sum;       }       sum = 0;       for (int j = 0; j < a[i].size(); j++) {         sum = max(sum + (long long)a[i][j], (long long)a[i][j]);         M[i] = max(M[i], sum);       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       int l;       scanf( %d , &l);       for (int j = 0; j < l; j++) {         int x;         scanf( %d , &x);         a[i].push_back(x);       }     }     calc();     for (int i = 0; i < m; i++) {       scanf( %d , &ind), ind--;       ans = max(un + L[ind], ans);       un = max(un + A[ind], R[ind]);       ans = max(ans, M[ind]);     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double calc(pair<double, double> v1, pair<double, double> v2) {     double dx = v1.first - v2.first;     double dy = v1.second - v2.second;     return sqrt(dx * dx + dy * dy);   }   int main() {     int a, b, c;     scanf( %d%d%d , &a, &b, &c);     double x1, y1, x2, y2;     scanf( %lf%lf%lf%lf , &x1, &y1, &x2, &y2);     double dist = fabs(x1 - x2) + fabs(y1 - y2);     if (a == 0 || b == 0) {       printf( %.10f n , dist);       return 0;     }     vector<pair<double, double>> v1, v2;     double xl1 = (-1.0 * c - 1.0 * b * y1) / a;     double yl1 = (-1.0 * c - 1.0 * a * x1) / b;     v1.push_back({xl1, y1});     v1.push_back({x1, yl1});     double xl2 = (-1.0 * c - 1.0 * b * y2) / a;     double yl2 = (-1.0 * c - 1.0 * a * x2) / b;     v2.push_back({xl2, y2});     v2.push_back({x2, yl2});     for (auto p1 : v1)       for (auto p2 : v2)         dist =             min(dist, calc(p1, p2) + fabs(x1 - p1.first) + fabs(y1 - p1.second) +                           fabs(x2 - p2.first) + fabs(y2 - p2.second));     printf( %.10f n , dist);   }


#include <bits/stdc++.h>   using namespace std;   bool isPrime(int n) {     for (int i = 2; i < int(sqrt(n) + 1); i++)       if (n % i == 0) return 0;     return 1;   }   int main() {     int n;     cin >> n;     if (isPrime(n)) return !(cout << 1 <<   n );     if (n & 1) {       if (isPrime(n - 2))         cout << 2 <<   n ;       else         cout << 3 <<   n ;     } else       cout << 2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 1000000007;   const int z = 0;   using namespace std;   int main() {     int k, l, m, n, d, ans = 0;     cin >> k >> l >> m >> n >> d;     for (int i = 1; i <= d; i++) {       if (i % k == 0 or i % l == 0 or i % m == 0 or i % n == 0) {         ans++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tt, c = 0;     cin >> tt;     while (tt) {       int n = tt;       set<int> data;       while (n % 2 == 0) {         data.insert(2);         n = n / 2;       }       for (int i = 3; i <= sqrt(n); i = i + 2) {         while (n % i == 0) {           data.insert(i);           n = n / i;         }       }       if (n > 2) data.insert(n);       if (data.size() == 2) {         c++;       }       tt--;     }     cout << c << endl;     cerr <<  Time :   << (float)clock() / CLOCKS_PER_SEC <<   s  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using P = pair<int, int>;   constexpr int INF = 1001001001;   constexpr int mod = 1000000007;   template <class T>   inline bool chmax(T& x, T y) {     if (x < y) {       x = y;       return true;     }     return false;   }   template <class T>   inline bool chmin(T& x, T y) {     if (x > y) {       x = y;       return true;     }     return false;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, k;     cin >> n >> k;     vector<int> a(n + 2), ban(k + 2);     a[0] = -1e+7, a[n + 1] = INF;     ban[0] = 0, ban[k + 1] = n + 1;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       a[i] -= i;     }     for (int i = 1; i <= k; ++i) cin >> ban[i];     int ans = 0;     for (int i = 0; i <= k; ++i) {       int lb = a[ban[i]], ub = a[ban[i + 1]];       if (ub - lb < 0) {         cout << -1 << endl;         return 0;       }       vector<int> vals;       int cnt = 0;       int s = ban[i] + 1, t = ban[i + 1];       for (int j = s; j < t; ++j) {         if (a[j] < lb || a[j] > ub)           ++cnt;         else           vals.emplace_back(a[j]);       }       int m = vals.size();       vector<int> dp(m, INF);       for (int j = 0; j < m; ++j) {         *upper_bound(dp.begin(), dp.end(), vals[j]) = vals[j];       }       cnt += dp.end() - lower_bound(dp.begin(), dp.end(), INF);       ans += cnt;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[1000];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     long int answer = 0;     for (int i = 0; i < (n - 1); i++) {       if (a[i] == 1 && a[i + 1] == 2) {         answer += 3;       } else if (a[i] == 1 && a[i + 1] == 3) {         answer += 4;       } else if (a[i] == 2 && a[i + 1] == 1) {         answer += 3;       } else if (a[i] == 2 && a[i + 1] == 3) {         cout <<  Infinite ;         return 0;       } else if (a[i] == 3 && a[i + 1] == 1) {         answer += 4;         if (i < n - 2 && a[i + 2] == 2) {           answer -= 1;         }       } else if (a[i] == 3 && a[i + 1] == 2) {         cout <<  Infinite ;         return 0;       }     }     cout <<  Finite  << endl;     cout << answer;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int a = (s.size() + 1) / 2 - 1;     int b = s.size() / 2 - 1;     bool f00 = false, f01 = false, f10 = false, f11 = false;     int cq = 0, c0 = 0, c1 = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  0 )         c0++;       else if (s[i] ==  1 )         c1++;       else         cq++;     }     if (cq + c1 >= a + 2) f11 = true;     if (c1 <= a) f00 = true;     if (c1 <= a + 1 and c1 + cq >= a + 1) {       int q1 = (a + 1) - c1;       int q0 = cq - q1;       if (s.back() ==  ? ) {         if (q1) f01 = true;         if (q0) f10 = true;       } else if (s.back() ==  0 )         f10 = true;       else         f01 = true;     }     if (f00) printf( 00 n );     if (f01) printf( 01 n );     if (f10) printf( 10 n );     if (f11) printf( 11 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     double a, b, Zero = 0.5, One = 1.0;     scanf( %d , &t);     while (t--) {       scanf( %lf%lf , &a, &b);       if (a == 0 && b == 0)         printf( %.10lf n , One);       else if (a == 0)         printf( %.10lf n , Zero);       else if (b == 0)         printf( %.10lf n , One);       else if (a >= 4 * b) {         float area = 0.5 * 4 * b * b;         area = 2 * a * b - area;         area /= 2 * a * b;         printf( %.10lf n , area);       } else {         float area = 0.5 * a * a * 0.25 + a * b;         area /= 2 * a * b;         printf( %.10lf n , area);       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = 1e5 + 5, M = 100 + 5, OO = 0x3f3f3f3f, mod = 1e9 + 7, base = 131,             MOD2 = 1000136437;   const double EPS = 1e-9;   long double w, h, theta;   complex<double> rotate(complex<double> &p, double a) {     return p * polar(1.0, a);   }   int doubleComp(const double &a, const double &b) {     return fabs(a - b) < EPS ? 0 : a < b ? -1 : 1;   }   bool lineInter(const complex<double> &A, const complex<double> &B,                  const complex<double> &P, const complex<double> &Q,                  complex<double> &R, bool isSegA = false, bool isSegB = false) {     double d1 = ((conj(P - A) * (B - A)).imag());     double d2 = ((conj(Q - A) * (B - A)).imag());     if (fabs(d1 - d2) < EPS) return false;     R = (d1 * Q - d2 * P) / (d1 - d2);     if (isSegA &&         doubleComp(hypot(A.real() - B.real(), A.imag() - B.imag()),                    hypot(A.real() - R.real(), A.imag() - R.imag()) +                        hypot(B.real() - R.real(), B.imag() - R.imag())) != 0)       return false;     if (isSegB &&         doubleComp(hypot(P.real() - Q.real(), P.imag() - Q.imag()),                    hypot(P.real() - R.real(), P.imag() - R.imag()) +                        hypot(Q.real() - R.real(), Q.imag() - R.imag())) != 0)       return false;     return true;   }   void polygonCut(const complex<double> &a, const complex<double> &b,                   const vector<complex<double> > &v,                   vector<complex<double> > &ret) {     ret.clear();     for (int i = 0; i < (int)(v).size(); i++) {       int j = (i + 1) % (int)(v).size();       if (((conj(((b) - (a))) * (((v[i]) - (a)))).imag()) >= 0)         ret.push_back(v[i]);       complex<double> r;       if (lineInter(a, b, v[i], v[j], r, 0, 1)) ret.push_back(r);     }   }   void polygonIntersection(const vector<complex<double> > &poly1,                            const vector<complex<double> > &poly2,                            vector<complex<double> > &ret) {     vector<complex<double> > r2;     ret = poly1;     for (int i = 0; i < (int)(poly2).size(); i++) {       int j = (i + 1) % (int)(poly2).size();       polygonCut(poly2[i], poly2[j], ret, r2);       ret = r2;     }   }   double areaPolygon(vector<complex<double> > p) {     double area = 0.0;     for (int i = 0, n = (int)(p).size(); i < n; i++)       area += ((conj(p[i]) * (p[(i + 1) % n])).imag());     return abs(area) / 2.0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> w >> h >> theta;     vector<complex<double> > p, p2, ans;     w /= 2;     h /= 2;     p.push_back(complex<double>(w, h));     p.push_back(complex<double>(-w, h));     p.push_back(complex<double>(-w, -h));     p.push_back(complex<double>(w, -h));     p2 = p;     theta = (theta / 180.0) * (2 * acos(0));     for (auto &i : p2) i = rotate(i, theta);     polygonIntersection(p, p2, ans);     cout << fixed << setprecision(6) << areaPolygon(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char buf[1 << 21], *p1 = buf, *p2 = buf;   int read() {     int w = 0, f = 1;     char c =    ;     while (c <  0  || c >  9 )       c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++),       f = c ==  -  ? -1 : f;     while (c >=  0  && c <=  9 )       w = w * 10 + c - 48,       c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++);     return w * f;   }   int n, m, a[1000005];   long long val[1000005 << 2], mod;   vector<long long> minn[1000005 << 2];   const long long inf = 1e18;   void pushup(int p, int l, int r, int mid) {     int ls = p << 1, rs = p << 1 | 1, it1 = 0, it2 = 0;     while (it1 <= mid - l + 1) {       while (it2 <= r - mid) {         long long L = max(minn[ls][it1], minn[rs][it2] - val[ls] + mod * it1),                   R = it1 == mid - l + 1 ? inf : minn[ls][it1 + 1] - 1;         if (L > R) break;         minn[p][it1 + it2] = min(minn[p][it1 + it2], L), it2++;       }       it2 = max(it2 - 1, 0), it1++;     }     val[p] = val[ls] + val[rs];   }   void build(int p, int l, int r) {     minn[p].resize(r - l + 2);     minn[p][0] = -inf;     for (int i = 1; i <= r - l + 1; i++) minn[p][i] = inf;     if (l == r) {       minn[p][1] = mod - a[l];       val[p] = a[l];       return;     }     int mid = (l + r) >> 1;     build(p << 1, l, mid);     build(p << 1 | 1, mid + 1, r);     pushup(p, l, r, mid);   }   long long query(int p, int x, int y, long long v, int l, int r) {     if (x <= l && r <= y) {       int L = 0, R = r - l + 1, res = 0;       while (L <= R) {         int mid = (L + R) >> 1;         if (minn[p][mid] <= v)           res = mid, L = mid + 1;         else           R = mid - 1;       }       return v + val[p] - mod * res;     }     int mid = (l + r) >> 1;     if (y <= mid) return query(p << 1, x, y, v, l, mid);     if (x > mid) return query(p << 1 | 1, x, y, v, mid + 1, r);     return query(p << 1 | 1, x, y, query(p << 1, x, y, v, l, mid), mid + 1, r);   }   signed main() {     n = read(), m = read(), mod = read();     for (int i = 1; i <= n; i++) a[i] = read();     build(1, 1, n);     int l, r;     while (m--) {       l = read(), r = read();       printf( %lld n , query(1, l, r, 0, 1, n));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[601000];   long long m;   long long ans = 0;   long long len;   long long ll;   long long mod = 1;   long long reget(long long x) {     long long reans = (10 * (ll - ((long long)(s[x] -  0 ) * mod) % m + m) % m +                        (long long)(s[x] -  0 ) + m) %                       m;     return reans;   }   long long get(long long l, long long r) {     long long t = l;     long long temp = 0;     while (t <= r) {       if (temp >= m) temp = (temp % m + m) % m;       while (temp < m && t <= r) {         temp = temp * 10 + (long long)(s[t] -  0 );         t++;       }     }     temp = (temp + m) % m;     return temp;   }   int main() {     cin >> s;     len = strlen(s);     cin >> m;     ans = get(0, len - 1);     for (long long i = 1; i < len; i++) mod = (mod * 10 + m) % m;     ll = ans;     for (long long i = 0; i < len - 1; i++) {       ll = reget(i);       if (s[i + 1] ==  0 ) continue;       ans = min(ll, ans);     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   const long long int N = 2e5 + 10;   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long int n;     cin >> n;     string second;     cin >> second;     set<char> x;     if (n > 26) {       cout << -1 << endl;       return 0;     }     for (int i = 0; i < n; i++) {       x.insert(second[i]);     }     cout << n - x.size() << endl;   }


#include <bits/stdc++.h>   using namespace std;   string s;   struct substring {     int f, b;     bool operator>(const substring &o) const {       int cmp = s.compare(f, b - f + 1, s, o.f, o.b - o.f + 1);       return cmp != 0 ? cmp > 0 : f > o.f;     }   };   string kthSubstring(int k) {     priority_queue<substring, vector<substring>, greater<substring>> pq;     int len = s.length();     for (int i = 0; i < len; i++) {       pq.push({i, i});     }     while (!pq.empty()) {       int f = pq.top().f, b = pq.top().b;       pq.pop();       if (--k == 0) return s.substr(f, b - f + 1);       if (++b < len) {         pq.push({f, b});       }     }     return   ;   }   int main() {     int k;     cin >> s >> k;     int len = s.length();     long long possible = ((long long)len * (len + 1)) / 2;     if (k > possible)       cout <<  No such line.  <<   n ;     else       cout << kthSubstring(k) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000005;   map<long long, pair<int, int> > mm;   int a[maxn];   int b[maxn];   long long s[maxn], s1[maxn];   int main() {     int i, j, n;     cin >> n;     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);       s[i] = s[i - 1] + a[i];     }     for (i = 1; i <= n; i++) {       scanf( %d , &b[i]);       s1[i] = s1[i - 1] + b[i];     }     int p = n;     if (s[n] <= s1[n]) {       i = n;       while (i >= 0) {         if (s[i] < s1[p]) {           p--;           continue;         }         if (mm.find(s[i] - s1[p]) != mm.end()) {           pair<int, int> p2 = mm[s[i] - s1[p]];           printf( %d n , p2.first - i);           for (j = i + 1; j <= p2.first; j++) printf( %d  , j);           printf(  n );           printf( %d n , p2.second - p);           for (j = p + 1; j <= p2.second; j++) printf( %d  , j);           printf(  n );           return 0;         }         mm[s[i] - s1[p]] = make_pair(i, p);         i--;       }     } else {       i = n;       while (i >= 0) {         if (s1[i] < s[p]) {           p--;           continue;         }         if (mm.find(s1[i] - s[p]) != mm.end()) {           pair<int, int> p2 = mm[s1[i] - s[p]];           printf( %d n , p2.second - p);           for (j = p + 1; j <= p2.second; j++) printf( %d  , j);           printf(  n );           printf( %d n , p2.first - i);           for (j = i + 1; j <= p2.first; j++) printf( %d  , j);           printf(  n );           return 0;         }         mm[s1[i] - s[p]] = make_pair(i, p);         i--;       }     }     printf( -1 n );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 5;   int n;   int fa[N], r[N];   int rt[N], ls[N * 30], rs[N * 30], siz[N * 30], tot;   long long sum[N * 30], ans;   void update(int &rt, int l, int r, int p) {     if (!rt) rt = ++tot;     if (l == r) {       siz[rt] = 1, sum[rt] = p;       return;     }     int mid = (l + r) >> 1;     if (p <= mid)       update(ls[rt], l, mid, p);     else       update(rs[rt], mid + 1, r, p);     siz[rt] = siz[ls[rt]] + siz[rs[rt]];     sum[rt] = sum[ls[rt]] + sum[rs[rt]];   }   int merge(int x, int y) {     if (!x || !y) return x | y;     ans -= sum[ls[x]] * siz[rs[x]] + sum[ls[y]] * siz[rs[y]];     ls[x] = merge(ls[x], ls[y]);     rs[x] = merge(rs[x], rs[y]);     ans += sum[ls[x]] * siz[rs[x]];     siz[x] += siz[y];     sum[x] += sum[y];     return x;   }   inline int findf(int x) { return x == fa[x] ? x : fa[x] = findf(fa[x]); }   void unify(int x, int y) {     x = findf(x), y = findf(y);     fa[y] = x;     ans -= sum[rt[x]] * x + sum[rt[y]] * y;     rt[x] = merge(rt[x], rt[y]);     ans += sum[rt[x]] * x;     r[x] = r[y];   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= 400000; i++) fa[i] = i, r[i] = i;     for (int i = 1, a, b; i <= n; i++) {       scanf( %d%d , &a, &b);       int p = rt[a] ? r[findf(a)] + 1 : a;       ans -= 1ll * a * b;       ans += 1ll * p * b;       update(rt[p], 1, n, b);       if (rt[p - 1]) unify(p - 1, p);       if (rt[p + 1]) unify(p, p + 1);       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     scanf( %d%d%d%d , &a, &b, &c, &d);     double r = (1 - 1.0 * a / b) * (1 - 1.0 * c / d);     r = 1.0 / (1 - r);     printf( %.10f n , r * a / b);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p, v, t, no = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> p >> v >> t;       if (p + v + t >= 2) {         no++;       }     }     cout << no <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, t, a, b, da, db;     scanf( %d%d%d%d%d%d , &x, &t, &a, &b, &da, &db);     if (x == 0 || (x <= a && x > a - da * t && (a - x) % da == 0) ||         (x <= b && x > b - db * t && (b - x) % db == 0)) {       cout <<  YES  << endl;       return 0;     }     for (int i = 0; i < t; i++) {       for (int j = 0; j < t; j++) {         if ((a - j * da) + (b - i * db) == x) {           printf( YES );           return 0;         }       }     }     printf( NO );   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 100005;   int n, k;   char s[NMAX];   int sum[NMAX];   int get(int l, int r) {     l = max(1, l);     r = min(r, n);     return sum[r] - sum[l - 1];   }   int main() {     cin.sync_with_stdio(false);     cin >> n >> k;     cin >> (s + 1);     for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + (s[i] ==  0 );     int ans = 1 << 30;     for (int i = 1; i <= n; i++)       if (s[i] ==  0 ) {         int l = 1;         int r = n;         int sol = -1;         while (l <= r) {           int mi = (l + r) / 2;           if (get(i - mi, i - 1) + get(i + 1, i + mi) >= k) {             sol = mi;             r = mi - 1;           } else             l = mi + 1;         }         if (sol != -1) ans = min(ans, sol);       }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     register int x = 0, f = 1;     register char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + (ch ^ 48), ch = getchar();     return x * f;   }   const int P = 998244353;   const int N = 1e7 + 5;   long long fsp(long long x, int y = P - 2) {     long long ans = 1;     while (y) {       if (y & 1) ans = ans * x % P;       x = x * x % P, y >>= 1;     }     return ans;   }   long long inv[N];   int n, m, a[N], b[N], f[N];   void Add(int &x, int y) {     x += y;     if (x < 0) x += P;     if (x >= P) x -= P;   }   int main() {     n = read();     for (int i = 1; i <= n; i++) a[i] = read(), m += a[i];     b[n] = m;     inv[1] = 1;     for (int i = 2; i <= m; i++) inv[i] = (P - P / i) * inv[P % i] % P;     long long im = fsp(m), in = fsp(n - 1);     for (int i = 1; i < m; i++) {       long long inv1 = inv[m - i] * m % P * (n - 1) % P;       long long inv2 = (1 - im * in % P * (m - i) % P * (n - 2) % P + P) % P;       f[i + 1] =           inv1 * (inv2 * f[i] % P - i * im % P * (f[i - 1] + 1) % P + P) % P;     }     int ans = 0;     for (int i = 1; i <= n; i++) Add(ans, f[a[i]]);     for (int i = 1; i <= n; i++) Add(ans, P - f[b[i]]);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(time(0));   bool isPrime(long long a) {     long long i;     for (i = 2; i * i <= a; i++) {       if (a % i == 0) {         return 0;       }     }     return (a != 1);   }   bool isPalindrom(const string &s, int l, int r) {     for (int i = 0; i < (r - l + 1) / 2; i++) {       if (s[l + i] != s[r - i]) {         return 0;       }     }     return 1;   }   template <class type1>   type1 gcd(type1 a, type1 b) {     type1 t;     while (b) {       t = b;       b = a % b;       a = t;     }     return a;   }   long long positiveMod(long long v, long long md) {     v = v % md;     if (v < 0) {       v += md;     }     return v;   }   class information {    public:     vector<pair<long long, long long> > dat;     vector<long long> *stL, *stR;     long long iq, n;     void build() {       n = dat.size();       sort(dat.begin(), dat.end());       stL = new vector<long long>[4 * n];       stR = new vector<long long>[4 * n];       buildSt(1, 0, n - 1);     }     void buildSt(long long v, long long l, long long r) {       if (l == r) {         stL[v].push_back(dat[l].first - dat[l].second);         stR[v].push_back(dat[l].first + dat[l].second);       } else {         long long mid = (l + r) / 2;         buildSt(v * 2, l, mid);         buildSt(v * 2 + 1, mid + 1, r);         int i1, i2;         i1 = i2 = 0;         while (i1 != stL[v * 2].size() || i2 != stL[v * 2 + 1].size()) {           if (i1 == stL[v * 2].size()) {             stL[v].push_back(stL[v * 2 + 1][i2]);             i2++;           } else if (i2 == stL[v * 2 + 1].size()) {             stL[v].push_back(stL[v * 2][i1]);             i1++;           } else {             if (stL[v * 2][i1] < stL[v * 2 + 1][i2]) {               stL[v].push_back(stL[v * 2][i1]);               i1++;             } else {               stL[v].push_back(stL[v * 2 + 1][i2]);               i2++;             }           }         }         i1 = i2 = 0;         while (i1 != stR[v * 2].size() || i2 != stR[v * 2 + 1].size()) {           if (i1 == stR[v * 2].size()) {             stR[v].push_back(stR[v * 2 + 1][i2]);             i2++;           } else if (i2 == stR[v * 2 + 1].size()) {             stR[v].push_back(stR[v * 2][i1]);             i1++;           } else {             if (stR[v * 2][i1] > stR[v * 2 + 1][i2]) {               stR[v].push_back(stR[v * 2][i1]);               i1++;             } else {               stR[v].push_back(stR[v * 2 + 1][i2]);               i2++;             }           }         }       }     }     long long getSum(long long v, long long l, long long r, long long tl,                      long long tr, long long val) {       if (l == tl && tr == r) {         long long mid, res = 0;         l = 0;         r = stL[v].size();         while (l != r) {           mid = (l + r) / 2;           if (stL[v][mid] > val) {             r = mid;           } else {             l = mid + 1;           }         }         res += stL[v].size() - l;         l = 0;         r = stR[v].size();         while (l != r) {           mid = (l + r) / 2;           if (stR[v][mid] >= val) {             l = mid + 1;           } else {             r = mid;           }         }         res += stR[v].size() - l;         return res;       } else {         long long mid = (l + r) / 2;         if (tr <= mid) {           return getSum(v * 2, l, mid, tl, tr, val);         } else if (tl > mid) {           return getSum(v * 2 + 1, mid + 1, r, tl, tr, val);         } else {           return getSum(v * 2, l, mid, tl, mid, val) +                  getSum(v * 2 + 1, mid + 1, r, mid + 1, tr, val);         }       }     }     long long getCount(long long x, long long rad) {       long long l, r, i, j, st, en, mid;       l = 0;       r = n;       while (l != r) {         mid = (l + r) / 2;         if (dat[mid].first >= x - rad) {           r = mid;         } else {           l = mid + 1;         }       }       st = l;       l = -1;       r = n - 1;       while (l != r) {         mid = (l + r + 1) / 2;         if (dat[mid].first <= x + rad) {           l = mid;         } else {           r = mid - 1;         }       }       en = r;       if (en < st) {         return 0;       } else {         return (en - st + 1) - getSum(1, 0, n - 1, st, en, x);       }     }   };   vector<information> inf;   vector<pair<long long, pair<long long, long long> > > inp;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, k, i, j, a, b, c, l, r, res = 0;     cin >> n >> k;     for (i = 0; i < n; i++) {       cin >> a >> b >> c;       inp.push_back({c, {a, b}});     }     sort(inp.begin(), inp.end());     for (i = 0; i < n;) {       l = i;       r = i;       while (r < n) {         if (inp[r].first == inp[l].first) {           r++;         } else {           break;         }       }       information t;       t.iq = inp[l].first;       for (j = l; j < r; j++) {         t.dat.push_back(inp[j].second);       }       inf.push_back(t);       inf.back().build();       i = r;     }     for (i = 0; i < inf.size(); i++) {       a = 0;       for (auto it : inf[i].dat) {         a += inf[i].getCount(it.first, it.second);         for (j = i - 1; j >= 0; j--) {           if ((inf[i].iq - inf[j].iq) > k) {             break;           } else {             res += inf[j].getCount(it.first, it.second);           }         }       }       res += (a - inf[i].n) / 2;     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, k, t, sum = 0, a, b, p;     cin >> t;     while (t--) {       bool fg = 0;       p = 0;       k = 0;       sum = 0;       cin >> a >> b;       string s;       cin >> s;       n = s.size();       for (long long int i = 0; i <= n - 1; i++) {         if (s[i] ==  1 ) {           if (fg == 0) {             p += a;             fg = 1;             k = 0;           } else if (k > 0) {             p += min(k * b, a);             k = 0;             continue;           }         } else           k++;       }       cout << p << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a;   int main() {     scanf( %d%d , &n, &m);     if (n == 1)       printf( 1 n );     else {       if (m > n / 2)         printf( %d n , m - 1);       else         printf( %d n , m + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b, res;   int main() {     cin >> n >> a >> b;     for (int i = 1; i <= min(a, b); i++) {       if (a / i + b / i >= n) {         res = i;       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const string ALICE =  Alice , BOB =  Bob ;   void solve_case() {     int N, K;     cin >> N >> K;     if (K % 3 != 0) {       cout << (N % 3 != 0 ? ALICE : BOB) <<   n ;       return;     }     N %= K + 1;     cout << (N % 3 == 0 && N < K ? BOB : ALICE) <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int T;     cin >> T;     while (T-- > 0) solve_case();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     if (2 * m >= n)       cout << 0;     else       cout << n - 2 * m;     cout <<    ;     for (long long i = 0; i <= n; i++) {       if ((i * (i - 1)) / 2 >= m) {         cout << n - i;         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int P = 1e9 + 7, INF = 0x3f3f3f3f;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long qpow(long long a, long long n) {     long long r = 1 % P;     for (a %= P; n; a = a * a % P, n >>= 1)       if (n & 1) r = r * a % P;     return r;   }   long long inv(long long first) {     return first <= 1 ? 1 : inv(P % first) * (P - P / first) % P;   }   inline int rd() {     int first = 0;     char p = getchar();     while (p <  0  || p >  9 ) p = getchar();     while (p >=  0  && p <=  9 ) first = first * 10 + p -  0 , p = getchar();     return first;   }   const int N = 1e6 + 10;   int n, m, k, a[N], deg1[N], deg2[N];   int L[N], R[N], vis[N];   int first[N], second[N], b[N];   vector<int> g1[N], g2[N];   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; ++i) {       scanf( %d , a + i);       if (a[i])         L[i] = R[i] = a[i];       else         L[i] = 1, R[i] = k;     }     for (int i = 1; i <= m; ++i) {       scanf( %d%d , first + i, second + i);       g2[first[i]].push_back(second[i]), ++deg2[second[i]];       g1[second[i]].push_back(first[i]), ++deg1[first[i]];     }     queue<int> q;     for (int i = 1; i <= n; ++i)       if (!deg1[i]) q.push(i);     int cnt = 0;     while (q.size()) {       int u = q.front();       q.pop();       if (L[u] > R[u]) return puts( -1 ), 0;       ++cnt;       for (auto &v : g1[u]) {         L[v] = max(L[v], L[u] + 1);         if (!--deg1[v]) q.push(v);       }     }     if (cnt != n) return puts( -1 ), 0;     for (int i = 1; i <= n; ++i)       if (!deg2[i]) q.push(i);     while (q.size()) {       int u = q.front();       q.pop();       if (L[u] > R[u]) return puts( -1 ), 0;       for (auto &v : g2[u]) {         R[v] = min(R[v], R[u] - 1);         if (!--deg2[v]) q.push(v);       }     }     for (int i = 1; i <= n; ++i) b[i] = i;     sort(b + 1, b + 1 + n, [](int a, int b) { return L[a] < L[b]; });     int now = 1;     set<pair<int, int> > s;     for (int i = 1; i <= k; ++i) {       while (now <= n && L[b[now]] <= i) {         s.insert(pair<int, int>(R[b[now]], b[now]));         ++now;       }       int ok = 0;       while (s.size()) {         int id = s.begin()->second;         if (ok && R[id] > i) break;         ok = 1;         s.erase(s.begin());         a[id] = i;       }       if (!ok) return puts( -1 ), 0;     }     for (int i = 1; i <= n; ++i) printf( %d  , a[i] ? a[i] : L[i]);     putchar(10);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int M = 22;   int n, a[N];   long long f[N][M][2];   vector<int> v[N];   long long ans = 0;   void dfs(int x, int tr) {     ans += a[x];     for (int i = 0; i < M; i++) {       f[x][i][(a[x] >> i) & 1]++;     }     for (auto u : v[x])       if (u != tr) {         dfs(u, x);         for (int i = 0; i < M; i++) {           ans += (1 << i) * (f[x][i][0] * f[u][i][1] + f[x][i][1] * f[u][i][0]);           f[x][i][((a[x] >> i) & 1) ^ 0] += f[u][i][0];           f[x][i][((a[x] >> i) & 1) ^ 1] += f[u][i][1];         }       }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     dfs(1, 0);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int DIM = 1005;   bitset<DIM> oki;   int val[DIM], nxt[DIM];   int main(void) {     ios ::sync_with_stdio(false);     cin.tie();     cout.tie();     int n, m, ans = 0;     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> val[i], nxt[i] = -1;     for (int i = 1; i <= m; ++i) {       int x;       cin >> x;       for (int j = 1; j <= n; ++j)         if (nxt[x] < nxt[j]) ans += val[j];       nxt[x] = i;     }     cout << ans << endl;     return 0;   }


// Author: wlzhouzhuan   #pragma GCC optimize( Ofast )   #pragma GCC target( avx )   #include <bits/stdc++.h>   using namespace std;      #define ull unsigned long long       namespace IO {     const int SIZE = 1 << 23;     char ibuf[SIZE], *iS, *iT;     char obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1;     bool flush() {       fwrite(obuf, 1, oS - obuf, stdout);       oS = obuf;       return true;     }     #define gc() (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)     #define pc(x) (*oS++ = x)      int read() {       int x = 0, f = 0;       char c = gc();       while (!isdigit(c)) f |= c ==  - , c = gc();       while (isdigit(c)) x = 10 * x + c -  0 , c = gc();       return f ? -x : x;     }     char qu[55]; int qlen;     template <class T> void print(T x) {       if (!x) pc( 0 );       if (x < 0) pc( - ), x = -x;       while (x) qu[++qlen] = x % 10 +  0 , x /= 10;       while (qlen) pc(qu[qlen--]);     }     template <class T> void print(T x, char charset) {       print(x), pc(charset);     }     struct Flusher {       ~Flusher() {         flush();       }     } flusher;   }   using namespace IO;      const int N = 1005;   const int mod = 998244353;      int qpow(int a, int b = mod - 2) {     int res = 1;     while (b > 0) {       if (b & 1) res = 1ll * res * a % mod;       a = 1ll * a * a % mod;       b >>= 1;     }     return res;   }      ull mul(ull a, ull b) {     return (static_cast<unsigned long long>(a) * b) % mod;   }   int a[N], m, n;   ull fz = 1, sumfz = 0, fm = 1, ans = 0;   int j = 0;   void run(int t) {     for (; j < t; j++) {       fz = mul(fz, 2 * n - j);       sumfz = mul(sumfz, (n - j)) + fz;       fm = mul(fm, n - j);     }   }   int main() {     m = read();     for (int i = 1; i <= m; i++) {       a[i] = read(), n += a[i];     }     sort(a + 1, a + m + 1);     for (int i = 1; i <= m; i++) {       run(a[i]);       ans = (ans + mul(sumfz, qpow(fm))) % mod;     }     run(n);     ans = (ans + mod - mul(sumfz, qpow(fm))) % mod;     print((mod - ans) % mod,   n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     if (n > m) swap(m, n);     long long cc = 0;     for (int i = 1; i <= n; i++) {       cc += (m + i) / 5 - i / 5;     }     cout << cc << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char c[101];     int count = 0;     int sum = 0;     while (cin.getline(c, 101)) {       if (c[0] ==  + ) {         count++;         continue;       }       if (c[0] ==  - ) {         count--;         continue;       }       int x = 0;       for (; c[x] !=  : ; x++) {       }       sum += (strlen(c) - (x + 1)) * count;     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   const int SIZE = 2e5 + 5;   const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};   const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};   void fastio() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   void solveTest() {     long long n, m;     cin >> n >> m;     --m;     vector<long long> a(n);     long long mn = INT_MAX;     for (int i = 0; i < n; i++) {       cin >> a[i];       mn = min(mn, a[i]);     }     for (int i = 0; i < n; i++) {       a[i] -= mn;     }     long long cnt = (1ll * mn) * n;     while (a[m] != 0) {       a[m]--;       cnt++;       if (m == 0)         m = n - 1;       else         m--;     }     a[m] = cnt;     for (int i = 0; i < n; i++) {       cout << a[i] <<    ;     }     return;   }   int main() {     fastio();     int t = 1;     while (t--) {       solveTest();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   int log2(long long x) {     int ret = 0;     while (x > 0) {       x /= 2;       ret++;     }     return ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     clock_t ck;     ck = clock();     cin >> n >> k;     if (k == 1) {       cout << n <<   n ;       return 0;     }     int exp = log2(n);     cout << (1ll << exp) - 1 <<   n ;     ck = clock() - ck;     cerr <<  It took   << 1.0 * ck / CLOCKS_PER_SEC <<   sec n ;     return 0;   }


#include<bits/stdc++.h>   using namespace std;      int n;   inline int lst(int i){return i==1?n:i-1;}   inline int nxt(int i){return i==n?1:i+1;}   inline int lst(int i,int d){return (((i-d-1)%n+n)%n+1);}   inline int nxt(int i,int d){return ((i+d-1)%n+1);}      inline int getval(){    fflush(stdout);    int val;    scanf( %d ,&val);    return val;   }   inline int curval(int i){    printf( ? %d n n ,i);    return getval();   }   inline int lstval(int i){    printf( ? %d n n ,lst(i));    return getval();   }   inline int nxtval(int i){    printf( ? %d n n ,nxt(i));    return getval();   }      int k;   int a[200],b[200];      inline void ansis(int ans)   {    printf( ! %d n ,ans);    exit(0);   }   inline void findit(int pos,int val,int len)   {    if (val>k){     int lef=1,rig=len,mid;     while (lef<=rig){      mid=((lef+rig)>>1);      int curpos=lst(pos,mid);      int cur=curval(curpos);      if (cur==k) ansis(curpos);      if (cur>k) lef=mid+1; else rig=mid-1;     }    }else{     int lef=1,rig=len,mid;     while (lef<=rig){      mid=((lef+rig)>>1);      int curpos=nxt(pos,mid);      int cur=curval(curpos);      if (cur==k) ansis(curpos);      if (cur<k) lef=mid+1; else rig=mid-1;     }    }   }   int main()   {    scanf( %d%d ,&n,&k);    curval(1);    int pos=1;    for (int t=1;t<=950;t+=2){     int val1=curval(pos);     if (val1!=k) {      findit(pos,val1,t);      return 0;     }     int val2=nxtval(pos);     if (val2!=k) {      findit(nxt(pos),val2,t+1);      return 0;     }     pos=nxt(pos,t*2+1);    }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 77;   int n, q;   long long a[N];   vector<long long> V, Ps;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %lld , a + i);     if (n == 1) {       int q;       scanf( %d , &q);       long long x, y;       while (q--) {         scanf( %lld %lld , &x, &y);         x = y - x + 1;         printf( %lld  , x);       }       return 0;     }     sort(a + 1, a + 1 + n);     for (int i = 2; i <= n; ++i) V.push_back(a[i] - a[i - 1]);     sort(V.begin(), V.end());     Ps.push_back(V[0]);     for (int i = 3; i <= n; ++i) Ps.push_back(Ps.back() + V[i - 2]);     int sz = V.size();     scanf( %d , &q);     while (q--) {       long long x, y;       scanf( %lld %lld , &x, &y);       x = y - x + 1;       int id = upper_bound(V.begin(), V.end(), x - 1) - V.begin() - 1;       long long A = 0;       if (id == -1) {         A = n * x;       } else {         A = (n - id - 1) * x + Ps[id];       }       printf( %lld  , A);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> prefix_function(string s) {     int n = (int)s.length();     vector<int> pi(n);     for (int i = 1; i < n; ++i) {       int j = pi[i - 1];       while (j > 0 && s[i] != s[j]) j = pi[j - 1];       if (s[i] == s[j]) ++j;       pi[i] = j;     }     return pi;   }   int main() {     int t, n, x = 0;     cin >> t >> n;     string s;     cin >> s;     cout << s;     vector<int> v = prefix_function(s);     s = s.substr(v[v.size() - 1], s.size() - v[v.size() - 1]);     for (int i = 1; i < n; i++) {       cout << s;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b;     cin >> a >> b;     long long d = abs(a - b);     long long p1 = (d + 1) / 2, p2 = d / 2;     long long s1 = (p1 * (p1 + 1)) / 2, s2 = (p2 * (p2 + 1)) / 2;     cout << s1 + s2;   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   int a[200010];   int last[200010];   int x = -1, y = -1, z = -1;   stack<int> t;   int main() {     scanf( %d%d , &n, &q);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       if (a[i] == 0) {         z = i;         if (i) a[i] = a[i - 1];       } else {         if (x == -1) x = i;         if (a[i] == q) y = i;       }     }     if (x == -1) {       cout <<  YES  << endl;       for (int i = 0; i < n; i++) cout << q <<    ;       return 0;     }     for (int i = x - 1; i >= 0; i--) a[i] = a[i + 1];     if (y == -1) {       if (z == -1) {         cout <<  NO  << endl;         return 0;       }       a[z] = q;     }     for (int i = 0; i < n; i++) last[a[i]] = i;     for (int i = 0; i < n; i++) {       if (!t.empty() && t.top() > a[i]) {         cout <<  NO  << endl;         return 0;       } else if (t.empty() || t.top() < a[i])         t.push(a[i]);       if (last[a[i]] == i) t.pop();     }     cout <<  YES  << endl;     for (int i = 0; i < n; i++) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   char c[99];   int i, x;   int main() {     for (;;) {       scanf( %s , c);       fflush(stdout);       ;       if (*c ==  e ) break;       for (i = 2; i <= 1 << 30; i <<= 1) {         printf( ? %d %d n , i, i >> 1);         fflush(stdout);         ;         scanf( %s , c);         fflush(stdout);         ;         if (*c ==  y  || i == 1 << 30) break;       }       if (*c ==  x ) {         puts( ! 1 );         fflush(stdout);         ;         continue;       }       int l = i >> 1, r = i, m;       for (; l + 1 < r;) {         m = (l + r) >> 1;         printf( ? %d %d n , l, m);         fflush(stdout);         ;         scanf( %s , c);         fflush(stdout);         ;         if (*c ==  y )           l = m;         else           r = m;       }       printf( ! %d n , r);       fflush(stdout);       ;     }     return 0;   }


#include <bits/stdc++.h>   const int maxn = 1e5 + 500;   const int mod = 1e9 + 7;   const int inf = 123456789;   using namespace std;   int n, t, a, b, c;   vector<int> v[maxn], ans2[maxn];   vector<int> ans;   set<int> st[maxn];   int vis[maxn];   map<tuple<int, int>, int> mp;   void add(int a, int b, int i) {     if (mp.find({a, b}) != mp.end()) {       int x = mp[{a, b}];       ans2[x].push_back(i);       ans2[i].push_back(x);       mp.erase({a, b});     } else {       mp[{a, b}] = i;     }   }   void ins(int a, int b) {     if (st[a].count(b)) {       st[a].erase(b);     } else {       st[a].insert(b);     }     if (st[b].count(a)) {       st[b].erase(a);     } else {       st[b].insert(a);     }   }   void dfs(int x, int fa) {     vis[x] = 1;     ans.push_back(x);     for (int i : v[x]) {       if (i == fa || vis[i]) continue;       dfs(i, x);       if (x == 1) break;     }   }   void dfs1(int x, int fa) {     for (int i : ans2[x]) {       if (i != fa) {         dfs1(i, x);       }     }     cout << x <<    ;   }   void init(int x) {     ans.clear();     mp.clear();     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= x; i++) {       ans2[i].clear();       v[i].clear();       st[i].clear();     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       cin >> n;       init(n);       for (int i = 1; i < n - 1; i++) {         cin >> a >> b >> c;         if (a > b) swap(a, b);         if (a > c) swap(a, c);         if (b > c) swap(b, c);         ins(a, b);         ins(a, c);         ins(b, c);         add(a, b, i);         add(a, c, i);         add(b, c, i);       }       for (int i = 1; i <= n; i++) {         for (int it : st[i]) {           v[i].push_back(it);         }       }       dfs(1, 0);       for (int i : ans) {         cout << i <<    ;       }       cout <<   n ;       dfs1(1, 0);       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int Tn;     cin >> Tn;     while (Tn--) {       int n, x;       cin >> n >> x;       int mx = 0, flag = 0;       while (n--) {         int t;         cin >> t;         if (t == x) flag = 1;         mx = max(mx, t);       }       if (!flag)         printf( %d n , max((x - 1) / mx + 1, 2));       else         printf( %d n , 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1010;   long long c[2][2][MAXN][MAXN] = {0};   int n, m;   long long val;   int lowbit(int x) { return x & -x; }   void add(int a, int b) {     for (int i = a; i <= n; i += lowbit(i))       for (int j = b; j <= n; j += lowbit(j)) c[a & 1][b & 1][i][j] ^= val;   }   long long sum(int a, int b) {     long long ans = 0;     for (int i = a; i >= 1; i -= lowbit(i))       for (int j = b; j >= 1; j -= lowbit(j)) ans ^= c[a & 1][b & 1][i][j];     return ans;   }   int main() {     scanf( %d%d , &n, &m);     int x1, x2, y1, y2, op;     long long ans;     for (int i = 1; i <= m; i++) {       scanf( %d , &op);       if (op == 1) {         scanf( %d%d%d%d , &x1, &y1, &x2, &y2);         ans =             sum(x2, y2) ^ sum(x2, y1 - 1) ^ sum(x1 - 1, y2) ^ sum(x1 - 1, y1 - 1);         printf( %I64d n , ans);       } else {         scanf( %d%d%d%d%I64d , &x1, &y1, &x2, &y2, &val);         add(x1, y1);         add(x2 + 1, y1);         add(x1, y2 + 1);         add(x2 + 1, y2 + 1);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr int maxn = 1010;   constexpr int dx[5] = {0, 0, 1, -1};   constexpr int dy[5] = {1, -1, 0, 0};   using Node = struct { int x, y, v; };   char G[maxn][maxn];   bool vis[maxn][maxn];   int n, m;   vector<Node> p, ret;   inline bool ok(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }   void gao(int x, int y) {     int tot = 1;     bool flag = true;     bool yes = false;     while (flag) {       flag = false;       int cnt = 0;       for (int i = 0; i < 4; i++) {         int tx = x + dx[i] * tot;         int ty = y + dy[i] * tot;         if (ok(tx, ty) && G[tx][ty] ==  * ) cnt++;       }       if (cnt != 4) break;       for (int i = 0; i < 4; i++) {         int tx = x + dx[i] * tot;         int ty = y + dy[i] * tot;         vis[tx][ty] = 1;       }       flag = true;       yes = true;       tot++;     }     if (yes) {       vis[x][y] = 1;       ret.push_back({x + 1, y + 1, tot - 1});     }   }   signed main() {     while (~scanf( %d%d , &n, &m)) {       p.clear();       ret.clear();       memset(vis, 0, sizeof(vis));       for (int i = 0; i < n; i++) scanf( %s , G[i]);       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (G[i][j] ==  * ) p.push_back({i, j, 0});         }       }       if (p.size() == 0) {         printf( 0 n );         continue;       }       for (auto t : p) gao(t.x, t.y);       if (ret.size() == 0) {         printf( -1 n );         continue;       }       bool flag = 0;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (!vis[i][j] && G[i][j] ==  * ) {             flag = 1;           }         }       }       if (flag) {         printf( -1 n );         continue;       }       printf( %d n , ret.size());       for (auto t : ret) {         printf( %d %d %d n , t.x, t.y, t.v);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[1003][1003][11][2];   string s, t;   int n, m;   int k;   int rec(int i, int j, int how_k, int op) {     if (how_k > k) return -1e9;     if (i >= n || j >= m) {       if (how_k == k && !op) return 0;       return -1e9;     }     if (s[i] != t[j] && op) return -1e9;     int &ret = dp[i][j][how_k][op];     if (ret != -1) return ret;     ret = -1e9;     if (s[i] == t[j]) {       if (op) {         ret = max(ret, rec(i + 1, j + 1, how_k + 1, 0) + 1);         ret = max(ret, rec(i + 1, j + 1, how_k, op) + 1);       } else {         ret = max(ret, rec(i + 1, j + 1, how_k + 1, op) + 1);         ret = max(ret, rec(i + 1, j + 1, how_k, 1) + 1);       }     }     ret = max(ret, rec(i + 1, j, how_k + (op == 1), 0));     ret = max(ret, rec(i, j + 1, how_k + (op == 1), 0));     return ret;   }   int main() {     cin >> n >> m >> k;     memset(dp, -1, sizeof dp);     cin >> s >> t;     cout << rec(0, 0, 0, 0);     return 0;   }