#include <bits/stdc++.h>   namespace std {   template <typename...>   using void_t = void;   }   template <typename T, typename _ = void>   struct is_container : std::false_type {};   template <typename... Ts>   struct is_container_helper {};   template <typename T>   struct is_container<       T, typename std::conditional<              false,              is_container_helper<decltype(std::declval<T>().size()),                                  decltype(std::declval<T>().begin()),                                  decltype(std::declval<T>().end()),                                  decltype(std::declval<T>().cbegin()),                                  decltype(std::declval<T>().cend())>,              void>::type> : public std::true_type {};   class IO {     static const int bufSize = 1 << 20;     char inBuf[bufSize], outBuf[bufSize];     char *ip1 = inBuf, *ip2 = inBuf;     int goodReadBit = 1, op1 = -1, op2 = bufSize - 1;     __inline__ __attribute__((always_inline)) int gc() {       return ip1 == ip2 && (ip2 = (ip1 = inBuf) + fread(inBuf, 1, bufSize, stdin),                             ip1 == ip2)                  ? (goodReadBit = 0, EOF)                  : *ip1++;     }     template <typename T>     __inline__ __attribute__((always_inline)) void __RI(T &x) {       int ch = gc(), neg = 1;       x = 0;       for (; !(isdigit(ch) || ch ==  -  || ch == EOF); ch = gc()) {       }       if (ch == EOF) return;       if (ch ==  - ) neg = -1, ch = gc();       for (; isdigit(ch); ch = gc()) x = x * 10 + (ch - 48) * neg;     }     template <typename T>     __inline__ __attribute__((always_inline)) void __RC(T &x) {       int ch;       while (isspace(ch = gc())) {       }       if (ch == EOF) return;       x = ch;     }     __inline__ __attribute__((always_inline)) void __RS(std::string &x) {       char ch;       x.clear();       for (ch = gc(); isspace(ch); ch = gc()) {       }       if (ch == EOF) return;       for (; !isspace(ch) && ch != EOF; ch = gc()) x.push_back(ch);     }       public:     __inline__ __attribute__((always_inline)) IO &R(char &x) {       return __RC(x), (*this);     }     __inline__ __attribute__((always_inline)) IO &R(unsigned char &x) {       return __RC(x), (*this);     }     __inline__ __attribute__((always_inline)) IO &R(std::string &x) {       return __RS(x), (*this);     }     template <typename T1, typename T2>     __inline__ __attribute__((always_inline)) IO &R(std::pair<T1, T2> &x) {       return R(x.first), R(x.second), (*this);     }     template <typename T, typename... Args>     __inline__ __attribute__((always_inline)) IO &RA(T *a, int n) {       for (int i = 0; i < n; ++i) R(a[i]);       return (*this);     }     template <typename T, typename... Args>     __inline__ __attribute__((always_inline)) IO &R(T &x, Args &...args) {       return R(x), R(args...), (*this);     }     template <typename T, typename... Args>     __inline__ __attribute__((always_inline)) IO &RA(T *a, int n, Args... args) {       for (int i = 0; i < n; ++i) RA(a[i], args...);       return (*this);     }     template <typename T>     __inline__ __attribute__((always_inline))     typename std::enable_if<std::is_integral<T>::value, IO>::type &     R(T &x) {       return __RI(x), (*this);     }     template <typename T>     __inline__ __attribute__((always_inline))     typename std::enable_if<is_container<T>::value, IO>::type &     R(T &x) {       for (auto &i : x) R(i);       return (*this);     }     template <typename T>     __inline__ __attribute__((always_inline)) typename std::enable_if<         std::is_void<std::void_t<decltype(std::declval<T>().read())>>::value,         IO>::type &     R(T &x) {       return x.read(), (*this);     }       private:     char space =    ;     __inline__ __attribute__((always_inline)) void pc(const char &x) {       if (op1 == op2) flush();       outBuf[++op1] = x;     }     template <typename T>     __inline__ __attribute__((always_inline)) void __WI(T x) {       static char buf[sizeof(T) * 16 / 5];       static int len = -1;       if (x >= 0) {         do {           buf[++len] = x % 10 + 48, x /= 10;         } while (x);       } else {         pc( - );         do {           buf[++len] = -(x % 10) + 48, x /= 10;         } while (x);       }       while (len >= 0) {         pc(buf[len]), --len;       }     }       public:     __inline__ __attribute__((always_inline)) void flush() {       fwrite(outBuf, 1, op1 + 1, stdout), op1 = -1;     }     __inline__ __attribute__((always_inline)) IO &W(const char &x) {       return pc(x), (*this);     }     __inline__ __attribute__((always_inline)) IO &W(const char *x) {       while (*x !=   0 ) pc(*(x++));       return (*this);     }     __inline__ __attribute__((always_inline)) IO &W(const std::string &x) {       return W(x.c_str()), (*this);     }     template <typename T1, typename T2>     __inline__ __attribute__((always_inline)) IO &W(const std::pair<T1, T2> &x) {       WS(x.first);       W(x.second);       return (*this);     }     __inline__ __attribute__((always_inline)) IO &WL() {       return W(  n ), (*this);     }     template <typename T>     __inline__ __attribute__((always_inline)) IO &WL(const T &x) {       return W(x), W(  n ), (*this);     }     __inline__ __attribute__((always_inline)) IO &WS() {       return W(space), (*this);     }     template <typename T>     __inline__ __attribute__((always_inline)) IO &WS(const T &x) {       return W(x), W(space), (*this);     }     template <typename T>     __inline__ __attribute__((always_inline)) IO &WA(T *a, int n) {       for (int i = 0; i < n; i++) WS(a[i]);       WL();       return (*this);     }     template <typename T, typename... Args>     __inline__ __attribute__((always_inline)) IO &W(const T &x,                                                     const Args &...args) {       W(x), W(space), W(args...);       return (*this);     }     template <typename T, typename... Args>     __inline__ __attribute__((always_inline)) IO &WS(const T &x,                                                      const Args &...args) {       return W(x), W(space), W(args...), W(space), (*this);     }     template <typename... Args>     __inline__ __attribute__((always_inline)) IO &WL(const Args &...args) {       return W(args...), W(  n ), (*this);     }     template <typename T, typename... Args>     __inline__ __attribute__((always_inline)) IO &WA(T *a, int n, Args... args) {       for (int i = 0; i < n; i++) WA(a[i], args...);       return (*this);     }     template <typename T>     __inline__ __attribute__((always_inline))     typename std::enable_if<std::is_integral<T>::value, IO>::type &     W(const T &x) {       return __WI(x), (*this);     }     template <typename T>     __inline__ __attribute__((always_inline))     typename std::enable_if<is_container<T>::value, IO>::type &     W(const T &x) {       for (auto &i : x) WS(i);       WL();       return (*this);     }     template <typename T>     __inline__ __attribute__((always_inline)) typename std::enable_if<         std::is_void<std::void_t<decltype(std::declval<T>().write())>>::value,         IO>::type &     W(const T &x) {       return x.write(), (*this);     }     template <typename T>     __inline__ __attribute__((always_inline)) IO &operator>>(T &x) {       R(x);       return (*this);     }     template <typename T>     __inline__ __attribute__((always_inline)) IO &operator<<(const T &x) {       W(x);       return (*this);     }     int good() { return goodReadBit; }     IO() {}     ~IO() { flush(); }   } io;   const std::int32_t INF = 0x3f3f3f3f;   const std::int64_t INFL = 0x3f3f3f3f3f3f3f3f;   using namespace std;   namespace Math {   template <typename T, typename T2>   T qpow(T a, T2 b, const int &MOD) {     T ans = 1;     for (; b; b >>= 1) {       if (b & 1) ans = (a * ans) % MOD;       a = (a * a) % MOD;     }     return ans;   }   template <typename T>   T exgcd(T l, T r, T &x, T &y) {     if (!r) {       x = 1, y = 0;       return l;     } else {       int d = exgcd(r, l % r, y, x);       y -= l / r * x;       return d;     }   }   template <typename T>   T inv(T a, const int &MOD) {     return qpow(a, MOD - 2, MOD);   }   template <typename T>   T exinv(T a, const int &MOD) {     T x, y;     exgcd(a, MOD, x, y);     x %= MOD;     return x + ((x >> (sizeof(T) * 8 - 1)) & MOD);   }   template <typename T, T MOD>   struct ModInt {     T x;     ModInt(T x = 0) : x(x) {       while (x < 0) x += MOD;     }     ModInt<T, MOD> operator+=(const ModInt<T, MOD> &y) {       x += y.x - MOD;       x += (x >> (sizeof(T) * 8 - 1)) & MOD;       return (*this);     }     ModInt<T, MOD> operator-=(const ModInt<T, MOD> &y) {       x = x - y.x;       x += (x >> (sizeof(T) * 8 - 1)) & MOD;       return (*this);     }     ModInt<T, MOD> operator*=(const ModInt<T, MOD> &y) {       x = x * y.x % MOD;       return (*this);     }     ModInt<T, MOD> operator/=(const ModInt<T, MOD> &y) {       x = x * inv(y.x, MOD) % MOD;       return (*this);     }     ModInt<T, MOD> pow(int64_t p) { return x = qpow(x, p, MOD), *this; }     void write() const { io.W(x); }     void read() {       io.R(x);       x %= MOD;       if (x < 0) x += MOD;     }   };   template <typename T, T MOD>   ModInt<T, MOD> operator+(ModInt<T, MOD> a, const ModInt<T, MOD> &b) {     a += b;     return a;   }   template <typename T, T MOD>   ModInt<T, MOD> operator-(ModInt<T, MOD> a, const ModInt<T, MOD> &b) {     a -= b;     return a;   }   template <typename T, T MOD>   ModInt<T, MOD> operator*(ModInt<T, MOD> a, const ModInt<T, MOD> &b) {     a *= b;     return a;   }   template <typename T, T MOD>   ModInt<T, MOD> operator/(ModInt<T, MOD> a, const ModInt<T, MOD> &b) {     a /= b;     return a;   }   template <typename T, T MOD>   bool operator==(const ModInt<T, MOD> &a, const ModInt<T, MOD> &b) {     return a.x == b.x;   }   }  // namespace Math   using mint = Math::ModInt<int64_t, int(1e9 + 7)>;   int main() {     int n, q;     io.R(n, q);     vector<mint> a(n);     io.R(a);     a.insert(a.begin(), mint(0));     vector<mint> preSum(n + 1), preSquareSum(n + 1);     partial_sum(a.begin(), a.end(), preSum.begin());     partial_sum(a.begin(), a.end(), preSquareSum.begin(),                 [](mint a, mint b) { return a + b * b; });     mint inv2 = mint(1) / mint(2);     mint inv6 = mint(1) / mint(6);     while (q--) {       int l, r, d;       io.R(l, r, d);       mint len = r - l + 1;       mint x = ((preSum[r] - preSum[l - 1]) * mint(2) / len -                 (len - mint(1)) * mint(d)) *                inv2;       mint y = x * x * len + x * (len - mint(1)) * len * mint(d) +                len * (mint(2) * len * len - mint(3) * len + mint(1)) * mint(d) *                    mint(d) * inv6;       mint z = (preSquareSum[r] - preSquareSum[l - 1]);       io.WL(y == z ?  Yes  :  No );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct no {     int r;     int l;     int p;   };   int main() {     int n;     double v;     double a[110];     double b[110];     cin >> n >> v;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       cin >> b[i];       if (b[i] == 0) {         cout << 0.0 << endl;         return 0;       }     }     double cu = a[0], ni = b[0];     double aa = 0;     for (int i = 1; i < n; i++) {       if (b[i] / a[i] < ni / cu) {         cu = a[i];         ni = b[i];       }     }     aa = ni / cu;     double ans = 0;     for (int i = 0; i < n; i++) ans += aa * a[i];     if (ans > v) ans = v;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   typedef long long ll;   #define f(i,a,b) for(i=a;i<b;i++)      using namespace std;      int main()   {       ll n,i,sum=0, count=0;       cin>>n;       vector<ll> a(n);       f(i,0,n) cin>>a[i];       priority_queue <int, vector<int>, greater<int>> p;       f(i,0,n){           if(a[i]>=0) sum+=a[i], count++;           else{                              if(sum+a[i]>=0){                 sum+=a[i], count++;                  p.push(a[i]);               }                else{                   if(!p.empty()&&p.top()<a[i]){                     sum-=p.top();                     p.pop();                     sum+=a[i];                     p.push(a[i]);                   }                }           }       }       cout<<count<<endl;          return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ml, mr, wl, wr;   int main() {     cin >> ml >> mr >> wl >> wr;     if ((ml * 2 + 3 > wr && wr >= ml - 1) || (mr * 2 + 3 > wl && wl >= mr - 1)) {       cout <<  YES ;       return 0;     } else {       cout <<  NO ;       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct que {     int l, r, y, val;     bool operator<(const que &v) const { return y < v.y; }   };   int n, k, x[100010], y[100010], cnt[100010 * 2], pre[100010 * 2];   long long ans[100010];   vector<que> q;   vector<int> h;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d%d , &x[i], &y[i]);     for (int i = 1; i <= 2 * n; i++) pre[i] = -0x3f3f3f3f;     h.push_back(-0x3f3f3f3f);     for (int i = 1; i <= n; i++) {       h.push_back(x[i]);       h.push_back(x[i] + k);     }     sort(h.begin(), h.end());     h.resize(unique(h.begin(), h.end()) - h.begin());     for (int i = 1, l, r; i <= n; i++) {       l = upper_bound(h.begin(), h.end(), x[i]) - h.begin();       r = lower_bound(h.begin(), h.end(), x[i] + k) - h.begin();       q.push_back({l, r, y[i], 1});       q.push_back({l, r, y[i] + k, -1});     }     sort(q.begin(), q.end());     for (auto i : q)       for (int j = i.l; j <= i.r; j++) {         ans[cnt[j]] += 1ll * (h[j] - h[j - 1]) * (i.y - pre[j]);         cnt[j] += i.val;         pre[j] = i.y;       }     for (int i = 1; i <= n; i++) printf( %lld  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   using vi = vector<int>;   using vll = vector<ll>;   using vii = vector<ii>;   const ll MOD = 998244353;   const ll INF = 1e15 + 9;   const int MAXN = 1000006;   int n, m, a[MAXN], p[MAXN], b[MAXN];   int ind[MAXN], seen[MAXN];   ll dp[MAXN], sum[MAXN], negsum[MAXN];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     ++n;     for (int i = 1; i < n; ++i) cin >> a[i];     for (int i = 1; i < n; ++i) cin >> p[i];     cin >> m;     ++m;     for (int i = 1; i < m; ++i) cin >> b[i];     a[n] = n;     b[m] = n;     ++n, ++m;     for (int i = 0, j = 0; i < m; ++i) {       while (j < b[i]) ind[j++] = 2 * i - 1;       ind[j++] = 2 * i;     }     for (int i = 0; i < n; ++i) {       a[i] = ind[a[i]];       sum[i] = sum[seen[a[i]]] + max(p[i], 0);       negsum[i + 1] = negsum[i] + min(p[i], 0);       seen[a[i]] = i;     }     memset(seen, -1, sizeof seen);     seen[0] = 0;     for (int i = 1; i < n; ++i) {       dp[i] = INF;       if ((a[i] & 1) == 0) {         if (seen[a[i] - 2] != -1) {           dp[i] = dp[seen[a[i] - 2]] + sum[seen[a[i] - 1]] + sum[seen[a[i]]] +                   negsum[i] - negsum[seen[a[i] - 2] + 1];           if (seen[a[i]] != -1)             dp[i] = min(dp[i],                         dp[seen[a[i]]] + negsum[i + 1] - negsum[seen[a[i]] + 1]);         }       }       seen[a[i]] = i;     }     if (dp[n - 1] >= INF / 2)       cout <<  NO n ;     else       cout <<  YES n  << dp[n - 1] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T checkmin(T &a, T b) {     return (a < b) ? a : a = b;   }   template <class T>   inline T checkmax(T &a, T b) {     return (a > b) ? a : a = b;   }   template <class T>   T GCD(T a, T b) {     if (a < 0) return GCD(-a, b);     if (b < 0) return GCD(a, -b);     return (a == 0) ? b : GCD(b % a, a);   }   template <class T>   T LCM(T a, T b) {     if (a < 0) return LCM(-a, b);     if (b < 0) return LCM(a, -b);     return (a == 0 || b == 0) ? 0 : a / GCD(a, b) * b;   }   template <class T>   T ExtGCD(T a, T b, T &x, T &y) {     if (a < 0) {       T c = ExtGCD(-a, b, x, y);       x = -x;       return c;     }     if (b < 0) {       T c = ExtGCD(a, -b, x, y);       y = -y;       return c;     }     if (a == 0) {       x = 0, y = 1;       return b;     } else {       T c = ExtGCD(b % a, a, y, x);       x -= b / a * y;       return c;     }   }   template <class T>   inline T sqr(T X) {     return X * X;   }   class TUFSet {    private:     vector<int> S;       public:     TUFSet() {}     TUFSet(int N) { S = vector<int>(N, -1); }     int Find(int X) { return S[X] < 0 ? X : (S[X] = Find(S[X])); }     void Union(int X, int Y) {       X = Find(X);       Y = Find(Y);       if (X == Y) return;       if (S[X] < S[Y])         S[Y] = X;       else {         if (S[X] == S[Y]) --S[Y];         S[X] = Y;       }     }   };   namespace Poor {   int N, M, K;   TUFSet UFS;   vector<int> D;   void Run() {     scanf( %d%d%d , &N, &M, &K);     UFS = TUFSet(N);     for (int i = 0; i < M; ++i) {       int U, V;       scanf( %d%d , &U, &V);       --U, --V;       UFS.Union(U, V);     }     int Ans = 1 % K;     int C = 0;     D = vector<int>(N, 0);     for (int i = 0; i < N; ++i) {       ++D[UFS.Find(i)];       if (UFS.Find(i) == i) ++C;     }     if (C > 1) {       for (int i = 0; i < C - 2; ++i) Ans = ((long long)Ans * N) % K;       for (int i = 0; i < N; ++i)         if (D[i] > 0) Ans = ((long long)Ans * D[i]) % K;     }     printf( %d n , Ans);   }   }  // namespace Poor   int main() {     Poor::Run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int a[1000005];   map<int, int> ht;   map<int, int>::reverse_iterator its;   long long mul(long long a, long long b) {     long long res = 1;     while (b) {       if (b % 2 == 1) res = (res * a) % mod;       a = (a * a) % mod;       b /= 2;     }     return res;   }   int main() {     int n;     scanf( %d , &n);     long long nf = 1;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       ht[a[i]]++;       nf = (nf * i) % mod;     }     int add = 0;     long long ans = 0;     for (its = ht.rbegin(); its != ht.rend(); its++) {       if (add != 0)         ans = (ans + nf * its->second % mod *                          mul((its->second + add) % mod, mod - 2) % mod *                          its->first % mod) %               mod;       add += its->second;     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   #pragma GCC optimize( unroll-loops )   using namespace std;   const long long N = 2e5 + 36;   const long long M = 1e3 + 36;   const long long INF = 2e9 + 7;   const long long MOD = 987654323;   const int X[8] = {1, 1, -1, -1, 2, 2, -2, -2};   const int Y[8] = {2, -2, 2, -2, 1, -1, 1, -1};   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, ans = 0;     cin >> n;     string s, t;     cin >> s >> t;     for (int i(0); i < (n >> 1); ++i) {       if (t[i] == t[n - i - 1]) {         if (s[i] == s[n - i - 1]) {           continue;         } else {           ans += 1;           continue;         }       } else {         if (s[i] == s[n - i - 1]) {           if (t[i] == s[i] || t[n - i - 1] == s[i]) {             ans += 1;             continue;           } else {             ans += 2;             continue;           }         } else {           if (s[i] != t[i] && s[i] != t[n - i - 1] && s[n - i - 1] != t[i] &&               s[n - i - 1] != t[n - i - 1]) {             ans += 2;             continue;           }           if (min(t[i], t[n - i - 1]) == min(s[i], s[n - i - 1]) &&               max(t[i], t[n - i - 1]) == max(s[i], s[n - i - 1])) {             continue;           } else {             ans += 1;             continue;           }         }       }     }     if (n % 2 == 1) {       if (s[(n >> 1)] != t[(n >> 1)]) ans++;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());   long long rand(long long l, long long r) {     return uniform_int_distribution<long long>(l, r)(rd);   }   const int N = 49;   int n, m, d[N][N];   int b[N];   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int(i) = (1); (i) <= (m); ++(i)) {       int a, b;       cin >> a >> b;       if (max(a, b) > 48) continue;       d[a][b] = d[b][a] = 1;     }     n = min(n, 48);     for (int(i) = (1); (i) <= (n); ++(i)) b[i] = i;     shuffle(b + 1, b + 1 + n, rd);     for (int(i) = (1); (i) <= (n); ++(i))       for (int(j) = (i + 1); (j) <= (n); ++(j))         for (int(z) = (j + 1); (z) <= (n); ++(z))           for (int(k) = (z + 1); (k) <= (n); ++(k))             for (int(x) = (k + 1); (x) <= (n); ++(x)) {               int CNT = 0;               vector<int> a;               a.push_back(b[i]), a.push_back(b[j]), a.push_back(b[z]),                   a.push_back(b[k]), a.push_back(b[x]);               for (int(i) = (0); (i) <= ((int)(a).size() - 1); ++(i))                 for (int(j) = (0); (j) <= (i - 1); ++(j))                   if (d[a[i]][a[j]]) ++CNT;               if (CNT == 0 || CNT == 10) {                 cout << b[i] <<     << b[j] <<     << b[z] <<     << b[k] <<                          << b[x] <<   n ;                 return 0;               }             }     cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   const int N = 1e6, M = 1e6;   pair<int, int> adj[M + 7];   long long val[N + 7];   long long sum[N + 7];   long long res = 0;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   void addRes(int numb) { res += 1LL * numb * (numb - 1) / 2; }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1, r1, r2; i <= m; i++) {       cin >> r1 >> r2;       adj[i] = {r1, r2};     }     for (int i = 1; i <= n; i++) {       val[i] = rng();       sum[i] = 0;     }     for (int i = 1; i <= m; i++) {       sum[adj[i].first] += val[adj[i].second];       sum[adj[i].second] += val[adj[i].first];     }     int u, v;     for (int i = 1; i <= m; i++) {       u = adj[i].first;       v = adj[i].second;       if (sum[u] - val[v] == sum[v] - val[u]) res++;     }     int start = 1, finish = 1;     sort(sum + 1, sum + n + 1);     for (int i = 2; i <= n; i++)       if (sum[i] == sum[i - 1]) {         finish = i;         if (i == n) addRes(finish - start + 1);       } else {         addRes(finish - start + 1);         start = finish = i;       }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long pow2(long long n) {     long long x = 1;     for (long long i = 1; i <= n; i++) {       x *= 2;     }     return x;   }   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     cout << 2 * (n - 1) + 1 <<   2  << endl;     cout <<  1 2  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int inf = 1000000005;   long long int llinf = 2000000000000000005LL;   long long int mod = 1000000007;   long long int mod9 = 1000000009;   double pi = 3.1415926535897;   double eps = 1e-15;   int dx[] = {1, -1, 0, 0, 1, -1, 1, -1}, dy[] = {0, 0, 1, -1, 1, 1, -1, -1};   vector<bool> isprime;   vector<int> primes;   void seive(int n, bool wantlist = true) {     isprime.resize(n + 1, true);     isprime[0] = isprime[1] = false;     int sq = sqrt(n + 1);     for (int i = 2; i < sq + 1; i++) {       if (isprime[i]) {         for (int j = i * i; j <= n; j += i) isprime[j] = false;       }     }     for (int i = 2; wantlist && i <= n; i++) {       if (isprime[i]) primes.push_back(i);     }   }   template <class T>   inline T gcd(T a, T b) {     while (b > 0) {       a %= b;       swap(a, b);     }     return a;   }   template <class T>   inline T lcm(T a, T b) {     return a * b / gcd(a, b);   }   template <class T>   inline vector<T> operator+(vector<T>& a, vector<T>& b) {     assert(a.size() == b.size());     int n = a.size();     vector<T> c(n);     for (int i = 0; i < n; i++) c[i] = a[i] + b[i];     return c;   }   int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }   inline long long int bexp(long long int x, long long int n,                             long long int m = mod) {     long long int res = 1;     x %= m;     while (n) {       if (n & 1) res = res * x % m;       x = x * x % m;       n >>= 1;     }     return res;   }   inline bool ispalin(string& str) {     int n = str.length();     for (int i = 0; i < n / 2; i++)       if (str[i] != str[n - i - 1]) return false;     return true;   }   inline void mapper(vector<int>& a, int idx = 0) {     int cc = idx, n = a.size();     map<int, vector<int> > mapp;     for (int i = 0; i < n; i++) mapp[a[i]].push_back(i);     for (auto& p : mapp) {       for (int i : p.second) a[i] = cc;       cc++;     }   }   template <class T>   inline void ri(T& i) {     char c;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       ;     for (i = 0; c >=  0  && c <=  9 ; c = getchar())       i = (i << 3) + (i << 1) + (c - 48);   }   long long int Euclid(long long int a, long long int b, long long int& x,                        long long int& y) {     if (b == 0LL) {       x = (a < 0LL ? -1LL : 1LL);       y = 0LL;       return a * x;     }     long long int q = a / b;     long long int r = a % b;     long long int d = Euclid(b, r, y, x);     y -= q * x;     return d;   }   long double calDistance(long long int x, long long int y) {     long double tx = (long double)(x);     long double ty = (long double)(y);     long double res = tx * tx + ty * ty;     res = sqrt(res);     return res;   }   int main() {     pair<long long int, long long int> a, b, t;     cin >> a.first >> a.second >> b.first >> b.second >> t.first >> t.second;     int n;     cin >> n;     vector<vector<long double> > dis(n, vector<long double>(3, 0.0));     for (int i = 0; i < n; i++) {       pair<long long int, long long int> bottle;       cin >> bottle.first >> bottle.second;       long long int x, y;       x = labs(bottle.first - t.first);       y = labs(bottle.second - t.second);       dis[i][0] = calDistance(x, y);       x = labs(bottle.first - a.first);       y = labs(bottle.second - a.second);       dis[i][1] = calDistance(x, y);       x = labs(bottle.first - b.first);       y = labs(bottle.second - b.second);       dis[i][2] = calDistance(x, y);     }     vector<vector<long double> > AL(n, vector<long double>(2, 0.0));     for (int i = 0; i < n; i++) {       if (!i) {         AL[i][0] = dis[i][0];         AL[i][1] = dis[i][1];       } else {         AL[i][0] = dis[i][0] + AL[i - 1][0];         AL[i][1] = min(AL[i - 1][0] + dis[i][1], AL[i - 1][1] + dis[i][0]);       }     }     vector<vector<long double> > AR(n, vector<long double>(2, 0.0));     for (int i = n - 1; i >= 0; i--) {       if (i == n - 1) {         AR[i][0] = dis[i][0];         AR[i][1] = dis[i][1];       } else {         AR[i][0] = dis[i][0] + AR[i + 1][0];         AR[i][1] = min(AR[i + 1][0] + dis[i][1], AR[i + 1][1] + dis[i][0]);       }     }     vector<vector<long double> > BL(n, vector<long double>(2, 0.0));     for (int i = 0; i < n; i++) {       if (!i) {         BL[i][0] = dis[i][0];         BL[i][1] = dis[i][2];       } else {         BL[i][0] = dis[i][0] + BL[i - 1][0];         BL[i][1] = min(BL[i - 1][0] + dis[i][2], BL[i - 1][1] + dis[i][0]);       }     }     vector<vector<long double> > BR(n, vector<long double>(2, 0.0));     for (int i = n - 1; i >= 0; i--) {       if (i == n - 1) {         BR[i][0] = dis[i][0];         BR[i][1] = dis[i][2];       } else {         BR[i][0] = dis[i][0] + BR[i + 1][0];         BR[i][1] = min(BR[i + 1][0] + dis[i][2], BR[i + 1][1] + dis[i][0]);       }     }     long double ans = min(AL[n - 1][1], BL[n - 1][1]);     for (int i = 0; i < n - 1; i++) {       long double val = min(AL[i][1] + BR[i + 1][1], BL[i][1] + AR[i + 1][1]);       ans = min(val, ans);     }     for (int i = 0; i < n; i++) {       ans += dis[i][0];     }     cout << fixed << setprecision(12) << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long oo = 1000000000000000000LL;   const int N = 100005;   vector<pair<int, int>> ds;   long long data[2][100005];   int x[N], p[N], c[N], st[N];   long long val[N];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , x + i);       ds.push_back({x[i], i});     }     for (int i = 1; i <= m; i++) {       scanf( %d%d , p + i, c + i);       ds.push_back({p[i], -i});     }     sort(ds.begin(), ds.end());     long long* f[2] = {data[0] + 10005, data[1] + 10005};     int flag = 0;     for (int i = -n; i <= n; i++) f[flag][i] = oo;     f[flag][0] = 0;     long long last = ds[0].first;     for (int i = 0; i < ds.size(); i++) {       int old = flag;       flag ^= 1;       if (ds[i].second > 0) {         f[flag][n] = oo;         for (int j = -n; j < n; j++) {           f[flag][j] = oo;           if (f[old][j + 1] < oo)             f[flag][j] = f[old][j + 1] + (ds[i].first - last) * abs(j + 1);         }       } else {         int head = 0, tail = -1, cc = c[-ds[i].second];         for (int j = -n; j <= n; j++) {           if (f[old][j] < oo) {             long long tmp = f[old][j] + abs(j) * (ds[i].first - last);             while (head <= tail && val[tail] > tmp) tail--;             st[++tail] = j;             val[tail] = tmp;           }           while (head <= tail && st[head] + cc < j) head++;           f[flag][j] = oo;           if (head <= tail) f[flag][j] = val[head];         }       }       last = ds[i].first;     }     if (f[flag][0] == oo)       printf( -1 );     else       printf( %lld , f[flag][0]);   }


#include <bits/stdc++.h>   using namespace std;   int n;   double sv[500050];   struct info {     int x, v;   } A[500050];   int main() {     scanf( %d , &n);     int l = 0;     for (int i = 0; i < n; i++) scanf( %d %d , &A[i].x, &A[i].v);     int st = n, nd = -1;     for (int i = 0; i < n; i++)       if (A[i].v > 0) {         st = i;         break;       }     for (int i = n - 1; i >= 0; i--)       if (A[i].v < 0) {         nd = i;         break;       }     if (st > nd)       puts( -1.000000000000 );     else {       int it = 100;       double low = 0, high = 1e20, mid;       while (it--) {         mid = (low + high) / 2;         double mx = -1e20, mn = 1e20;         int i;         for (i = 0; i < n; i++)           if (A[i].v > 0) sv[i] = mx = max(mx, A[i].v * mid + A[i].x);         for (i = n - 1; i >= 0; i--) {           if (A[i].v < 0)             mn = min(mn, A[i].v * mid + A[i].x);           else if (sv[i] > mn)             break;         }         if (i >= 0)           high = mid;         else           low = mid;       }       printf( %.12lf n , mid);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ex(long long a, long long b) {     long long tmp = 1;     for (int i = 0; i < b; i++) {       tmp = tmp * a;     }     return tmp;   }   int main() {     long long r, l, tmp, ans = -1;     bool good = 1;     cin >> l >> r;     for (long long i = l; i <= r; i++) {       for (long long k = 0; k <= 5; k++) {         for (long long j = 0; j <= 5; j++) {           if (i / (ex(10, j)) % 10 == (i / (ex(10, k))) % 10 && ex(10, k) <= i &&               ex(10, j) <= i && j != k) {             good = 0;           }         }       }       if (good) {         ans = i;       }       good = 1;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   long long ar[1000001], dp[1001][1001];   long long calc(long long idx, long long rem) {     if (rem == 0 && idx != 0) return 1;     if (idx >= n) return 0;     long long &b = dp[idx][rem];     if (b != -1)       return b;     else       b = 0;     b |= calc(idx + 1, (rem + ar[idx]) % m);     b |= calc(idx + 1, rem);     return b;   }   void solve() {     cin >> n >> m;     for (long long i = 0; i < (n); ++i) {       cin >> ar[i];       ar[i] %= m;       if (ar[i] == 0) {         cout <<  YES n ;         return;       }     }     if (n >= m) {       cout <<  YES n ;       return;     } else {       for (long long i = 0; i < (1001); ++i)         for (long long j = 0; j < (1001); ++j) dp[i][j] = -1;       if (calc(0, m)) {         cout <<  YES n ;       } else         cout <<  NO n ;     }   }   int32_t main() {     ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long pow(long long a, long long b, long long MOD) {     long long x = 1, y = a;     while (b > 0) {       if (b % 2 == 1) {         x = (x * y);         if (x > MOD) x %= MOD;       }       y = (y * y);       if (y > MOD) y %= MOD;       b /= 2;     }     return x;   }   long long modInverse(long long a, long long m) { return pow(a, m - 2, m); }   long long arr[(int)1e5 + 1 + 1], val[(int)1e5 + 1];   int main() {     long long n;     while (cin >> n) {       for (int i = 0; i < n; i++) {         cin >> arr[i];         val[i] = 1;       }       long long ans = 1;       for (int i = 1; i < n; i++) {         if (arr[i] >= arr[i - 1]) {           val[i] = max(val[i], val[i - 1] + 1);         }         ans = max(ans, val[i]);       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n;     cin >> n;     vector<long long int> s(2 * n);     for (int i = 0; i < 2 * n; i++) cin >> s[i];     sort(s.begin(), s.end());     if (s[0] == s[2 * n - 1]) {       cout << -1 <<   n ;       return;     }     for (int i = 0; i < 2 * n; i++) cout << s[i] <<    ;     cout <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 10, LG = 45;   long long n, ts, Mx, B[N], S[N];   struct Node {     int32_t l, r, c;     Node() { l = r = c = 0; }   };   vector<Node> A;   inline long long Creat() { return (ts++); }   inline void Add(long long val, long long tp) {     long long id = 0;     A[id].c += tp;     for (long long i = LG - 1; ~i; i--) {       bool b = (val >> i) & 1;       if (!A[id].l) A[id].l = Creat();       if (!A[id].r) A[id].r = Creat();       if (!b) id = A[id].l;       if (b) id = A[id].r;       A[id].c += tp;     }   }   inline long long Get(long long val) {     long long id = 0, ret = 0;     for (long long i = LG - 1; ~i; i--) {       if (!A[id].l) A[id].l = Creat();       if (!A[id].r) A[id].r = Creat();       bool b = (val >> i) & 1, w = 0;       if ((!b && A[A[id].r].c) || (b && !A[A[id].l].c))         id = A[id].r, ret |= (1ll << i), w = 1;       if (!w) id = A[id].l;     }     return (val ^ ret);   }   int32_t main() {     scanf( %lld , &n);     A.resize(2e7, Node());     Creat();     Add(0, 2);     for (long long i = 1; i <= n; i++) scanf( %lld , &B[i]);     for (long long i = n; i; i--) S[i] = S[i + 1] ^ B[i], Add(S[i], 1);     for (long long i = 0, r = 0; i <= n; i++, r ^= B[i])       Mx = max(Mx, Get(r)), Add(S[i + 1], -1);     return !printf( %lld , Mx);   }


#include <bits/stdc++.h>   using namespace std;   int fuck[2010], de[2010], n;   char mp[2010][2010];   int check() {     sort(fuck + 1, fuck + 1 + n);     int sum = 0;     for (int i = 1; i < n; i++) {       sum += fuck[i];       if (sum == i * (i - 1) / 2) return 0;     }     return 1;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %s , mp[i] + 1);       for (int j = 1; j <= n; j++) {         if (mp[i][j] ==  1 ) de[i]++, fuck[i] = de[i];       }     }     if (check()) {       cout << 0 <<     << 1;       return 0;     }     if (n <= 6) {       int minn = 1e9, res = 0;       for (int i = 1; i < (1 << n); i++) {         int now = 0;         for (int j = 1; j <= n; j++) {           if ((1 << (j - 1)) & i) {             now++;             de[j] = n - 1 - de[j];             for (int k = 1; k <= n; k++) {               if (k == j) continue;               if (mp[j][k] ==  1 ) {                 mp[j][k] =  0 ;                 mp[k][j] =  1 ;                 de[k]++;               } else {                 mp[j][k] =  1 ;                 mp[k][j] =  0 ;                 de[k]--;               }             }           }         }         for (int j = 1; j <= n; j++) fuck[j] = de[j];         for (int j = 1; j <= n; j++) {           if ((1 << (j - 1)) & i) {             de[j] = n - 1 - de[j];             for (int k = 1; k <= n; k++) {               if (k == j) continue;               if (mp[j][k] ==  1 ) {                 mp[j][k] =  0 ;                 mp[k][j] =  1 ;                 de[k]++;               } else {                 mp[j][k] =  1 ;                 mp[k][j] =  0 ;                 de[k]--;               }             }           }         }         if (now > minn) continue;         if (check()) {           if (now < minn)             minn = now, res = 1;           else             res++;         }       }       if (minn == 1e9)         cout << -1;       else {         for (int i = 1; i <= minn; i++) res *= i;         cout << minn <<     << res;       }     } else {       int res = 0;       for (int j = 1; j <= n; j++) {         de[j] = n - 1 - de[j];         for (int k = 1; k <= n; k++) {           if (k == j) continue;           if (mp[j][k] ==  1 ) {             mp[j][k] =  0 ;             mp[k][j] =  1 ;             de[k]++;           } else {             mp[j][k] =  1 ;             mp[k][j] =  0 ;             de[k]--;           }         }         for (int j = 1; j <= n; j++) fuck[j] = de[j];         de[j] = n - 1 - de[j];         for (int k = 1; k <= n; k++) {           if (k == j) continue;           if (mp[j][k] ==  1 ) {             mp[j][k] =  0 ;             mp[k][j] =  1 ;             de[k]++;           } else {             mp[j][k] =  1 ;             mp[k][j] =  0 ;             de[k]--;           }         }         if (check()) res++;       }       cout << 1 <<     << res << endl;     }   }


#include <bits/stdc++.h>   int n, a, b, p;   char s[51];   int main(void) {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %s , &a, s);       b = 0;       p = a / 2;       for (int j = 0; j < a; j++) {         if (s[j] ==  ( ) {           b++;         } else {           if (b > 0) {             b--;             p--;           }         }       }       printf( %d n , p);     }   }


#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::pair;   using std::set;   using std::sort;   using std::string;   using std::vector;   int main() {     int n, m;     cin >> n >> m;     vector<vector<pair<string, int>>> byreg(m);     for (int i = 0; i < n; i++) {       string a;       int b, c;       cin >> a >> b >> c;       byreg[b - 1].push_back(make_pair(a, c));     }     for (int i = 0; i < m; i++) {       sort(byreg[i].begin(), byreg[i].end(),            [](pair<string, int> &l, pair<string, int> &r) {              return l.second > r.second;            });     }     for (int i = 0; i < m; i++) {       if (byreg[i].size() > 2) {         if (byreg[i][0].second == byreg[i][2].second ||             byreg[i][1].second == byreg[i][2].second) {           cout <<  ? n ;         } else           cout << byreg[i][0].first <<     << byreg[i][1].first <<   n ;       } else         cout << byreg[i][0].first <<     << byreg[i][1].first <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1010;   const int INF = 100000000;   string str[maxn];   int dp[maxn][maxn];   int n, m, ans;   int flag[maxn][maxn];   int dir[4][2] = {0, -1, 0, 1, 1, 0, -1, 0};   char ch[5] = { D ,  I ,  M ,  A };   vector<pair<int, int> > q;   bool Ok(int ki, int kj) {     if (ki >= 0 && ki < n && kj >= 0 && kj < m) return true;     return false;   }   int dfs(int ki, int kj, int d, int f) {     int Ans = 1;     for (int i = 0; i < 4; i++) {       int ti = ki + dir[i][0];       int tj = kj + dir[i][1];       if (Ok(ti, tj) && str[ti][tj] == ch[d + 1 < 4 ? d + 1 : 0]) {         if (flag[ti][tj] < f) {           int k = flag[ti][tj];           flag[ti][tj] = f;           if (dp[ti][tj] > 0)             Ans = max(Ans, dp[ti][tj] + 1);           else             Ans = max(Ans, dfs(ti, tj, d + 1 < 4 ? d + 1 : 0, f) + 1);           flag[ti][tj] = k;         } else {           Ans = INF;           break;         }       }     }     dp[ki][kj] = Ans;     return Ans;   }   void solve() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       cin >> str[i];       for (int j = 0; j < m; j++) {         if (str[i][j] ==  D ) q.push_back(pair<int, int>(i, j));       }     }     for (int i = 0; i < q.size(); i++) {       if (dp[q[i].first][q[i].second] == 0)         ans = max(ans, dfs(q[i].first, q[i].second, 0, i + 1) / 4);     }     if (ans == 0)       cout <<  Poor Dima!  << endl;     else if (ans >= 2500000)       cout <<  Poor Inna!  << endl;     else       cout << ans << endl;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   std::mt19937 rng(       (int)std::chrono::steady_clock::now().time_since_epoch().count());   const int ms = 110000;   const int bs = 1000;   const int MOD = 998244353;   void add(int &a, int b) { a = a + b < MOD ? a + b : a + b - MOD; }   int *pivot;   bool comp(int x1, int x2) { return pivot[x1] < pivot[x2]; }   int tmp[2][bs];   struct Bucket {     Bucket() { dirty = size = 0; }     void push_back(int x) {       p[size] = size;       lazy[size] = 0;       dp[size] = x;       values[size++] = 0;     }     void clean() {       for (int i = size - 2; i >= 0; i--) {         add(lazy[i], lazy[i + 1]);       }       for (int i = 0; i < size; i++) {         add(dp[p[i]], lazy[i]);         lazy[i] = 0;       }       if (dirty) {         for (int i = 0; i < size; i++) {           values[i] += dirty;         }         dirty = 0;       }     }     void sort() {       clean();       pivot = values;       std::sort(p, p + size, comp);     }     int getID(int x) {       if (x < values[p[0]] + dirty) {         return -1;       }       int l = 0, r = size - 1;       while (l != r) {         int mid = (l + r + 1) / 2;         if (values[p[mid]] + dirty <= x) {           l = mid;         } else {           r = mid - 1;         }       }       return l;     }     void upd(int x, int l, int r, int val) {       if (l == 0 && r == size) {         int id = getID(x);         if (id != -1) {           add(lazy[id], val);         }       } else {         for (int i = l; i < r; i++) {           if (values[i] + dirty <= x) {             add(dp[i], val);           } else {           }         }       }     }     void upd2(int l, int r, int val) {       if (l == 0 && r == size) {         dirty += val;       } else {         for (int i = l; i < r; i++) {           values[i] += val;         }         clean();         pivot = values;         int s0 = 0, s1 = 0;         for (int i = 0; i < size; i++) {           if (l <= p[i] && p[i] < r) {             tmp[0][s0++] = p[i];           } else {             tmp[1][s1++] = p[i];           }         }         std::merge(tmp[0], tmp[0] + s0, tmp[1], tmp[1] + s1, p, comp);       }     }     int values[bs], p[bs], lazy[bs], dp[bs];     int dirty;     int size;   };   Bucket b[ms / bs + 2];   std::vector<int> pos[ms];   int a[ms];   int pt[ms];   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     int n, k;     std::cin >> n >> k;     for (int i = 1; i <= n; i++) {       pos[i].push_back(-1);     }     for (int i = 0; i < n; i++) {       std::cin >> a[i];       pos[a[i]].push_back(i);       b[i / bs].push_back(i == 0 ? 1 : 0);     }     b[n / bs].push_back(0);     for (int i = 1; i <= n; i++) {       pos[i].push_back(n);       pos[i].push_back(n);     }     auto upd2 = [&](int l, int r, int val) {       if (l >= r) return;       int bl = l / bs, br = (r - 1) / bs;       if (bl == br) {         b[bl].upd2(l - bl * bs, r - bl * bs, val);         return;       }       b[bl].upd2(l - bl * bs, bs, val);       for (int i = bl + 1; i < br; i++) {         b[i].upd2(0, bs, val);       }       b[br].upd2(0, r - br * bs, val);     };     auto upd = [&](int l, int r, int val) {       if (l >= r) return;       int bl = l / bs, br = (r - 1) / bs;       if (bl == br) {         b[bl].upd(k, l - bl * bs, r - bl * bs, val);         return;       }       b[bl].upd(k, l - bl * bs, bs, val);       for (int i = bl + 1; i < br; i++) {         b[i].upd(k, 0, bs, val);       }       b[br].upd(k, 0, r - br * bs, val);     };     for (int i = 1; i <= n; i++) {       upd2(pos[i][1] + 1, pos[i][2] + 1, 1);     }     for (int i = 0; i < n; i++) {       b[i / bs].clean();       int dp = b[i / bs].dp[i % bs];       upd(i + 1, n + 1, dp);       {         int v = a[i];         upd2(pos[v][pt[v] + 1] + 1, pos[v][pt[v] + 2] + 1, -1);         pt[v]++;         upd2(pos[v][pt[v] + 1] + 1, pos[v][pt[v] + 2] + 1, 1);       }     }     b[n / bs].clean();     std::cout << b[n / bs].dp[n % bs] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   long long int inverse(long long int i) {     if (i == 1) return 1;     return (MOD - ((MOD / i) * inverse(MOD % i)) % MOD + MOD) % MOD;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long m, n, x;     cin >> m >> n;     cout << flush;     long long a[n];     for (int i = 0; i < n; i++) {       cout << 1 << endl;       cout << flush;       cin >> x;       if (x == 0)         exit(0);       else if (x == 1)         a[i] = 1;       else         a[i] = 0;     }     long long l = 2, r = m, mid, j = 0;     while (1) {       mid = (l + r) / 2;       cout << mid << endl;       cout << flush;       cin >> x;       if (x == 0 || x == -2)         exit(0);       else {         if (x == 1) {           if (a[j] == 1)             l = mid + 1;           else             r = mid - 1;         } else if (x == -1) {           if (a[j] == 1)             r = mid - 1;           else             l = mid + 1;         }       }       j++;       j %= n;     }   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-8;   const int inf = 1 << 30;   const int mod = int(1e9) + 7;   const int base = 257;   const int maxn = 2005;   int n, m, d[maxn][maxn], ans = -1, sx = -1, sy = -1;   char c[maxn][maxn];   int get(int xa, int ya, int xb, int yb) {     int res = d[xb][yb];     res -= d[xa - 1][yb];     res -= d[xb][ya - 1];     res += d[xa - 1][ya - 1];     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> c[i][j];         d[i][j] = d[i][j - 1] + (c[i][j] ==  X );       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if (c[i][j] ==  X  && sx == -1) sx = i, sy = j;         d[i][j] += d[i - 1][j];       }     for (int x = 1; x <= n; x++)       for (int y = 1; y <= m; y++) {         if (get(sx, sy, sx + x - 1, sy + y - 1) == x * y) {           int sxx = sx, syy = sy;           vector<pair<int, int> > v;           v.push_back(make_pair(sxx, syy));         go:;           int sum1 = get(sxx + 1, syy, sxx + 1 + x - 1, syy + y - 1);           int sum2 = get(sxx, syy + 1, sxx + x - 1, syy + 1 + y - 1);           if (sum1 == x * y && sum2 == x * y) continue;           if (sum1 == x * y) {             sxx++;             v.push_back(make_pair(sxx, syy));             goto go;           } else if (sum2 == x * y) {             syy++;             v.push_back(make_pair(sxx, syy));             goto go;           } else {             int tot = 1ll * get(v[0].first, v[0].second, v[0].first + x - 1,                                 v[0].second + y - 1);             for (int i = 1; i < v.size(); i++) {               tot += get(v[i].first, v[i].second, v[i].first + x - 1,                          v[i].second + y - 1);               tot -= get(v[i].first, v[i].second, v[i - 1].first + x - 1,                          v[i - 1].second + y - 1);             }             if (d[n][m] == tot) {               if (ans == -1)                 ans = x * y;               else                 ans = min(ans, x * y);             } else               continue;           }         }       }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int dp[205][205][205];   long long int n, k;   string s, t;   char c1, c2;   long long int solve(long long int pos, long long int k, long long int cnt) {     if (pos >= n) {       return 0;     }     if (dp[pos][k][cnt] != -1) return dp[pos][k][cnt];     long long int ans = 0;     ans = max(solve(pos + 1, k, cnt), ans);     if (c1 == s[pos] && k >= 0) {       ans = max(solve(pos + 1, k, cnt + 1), ans);     } else if (c1 != s[pos] && k >= 1) {       ans = max(solve(pos + 1, k - 1, cnt + 1), ans);     }     if (c2 == s[pos] && k >= 0) {       ans = max(cnt + solve(pos + 1, k, cnt), ans);     } else if (c2 != s[pos] && k >= 1) {       ans = max(cnt + solve(pos + 1, k - 1, cnt), ans);     }     return dp[pos][k][cnt] = ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> n >> k;     cin >> s >> t;     c1 = t[0];     c2 = t[1];     for (int i = 0; i < 205; i++)       for (int j = 0; j < 205; j++)         for (int p = 0; p < 205; p++) dp[i][j][p] = -1;     if (c1 != c2) {       cout << solve(0, k, 0) << endl;     } else {       long long int cnt = 0;       for (int i = 0; i < n; i++) {         if (s[i] == c1) cnt++;       }       long long int ans = min(cnt + k, n);       ans = ans * (ans - 1) / 2;       cout << ans;     }   }


#include <bits/stdc++.h>   using namespace ::std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long add(long long a, long long b, long long m = 1000000007) {     return (a % m + b % m + 2 * m) % m;   }   long long mul(long long a, long long b, long long m = 1000000007) {     return ((a % m + m) * (b % m + m)) % m;   }   int main(void) {     int n;     scanf( %d , &(n));     if (n % 2 == 0)       puts( Mahmoud );     else       puts( Ehab );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Rd(int &res) {     res = 0;     char p;     while (p = getchar(), p <  0 )       ;     do {       res = (res * 10) + (p ^ 48);     } while (p = getchar(), p >=  0 );   }   void Max(int &x, int y) {     if (x < y) x = y;   }   struct W {     int to, nx, d;   } Lis[100005 << 1];   int Head[100005], tot = 1;   void Add(int x, int y, int d) {     Lis[tot].to = y, Lis[tot].nx = Head[x], Lis[tot].d = d;     Head[x] = tot++;   }   int n, P;   long long ans;   int q[100005], sz, cntson[100005], Mxson[100005], phi;   int fast(int x, int p) {     int re = 1;     while (p) {       if (p & 1) re = (long long)re * x % P;       x = (long long)x * x % P, p >>= 1;     }     return re;   }   bool vis[100005];   void dfs_pre(int x, int f) {     cntson[x] = 1, Mxson[x] = 0, q[sz++] = x;     for (int i = Head[x], to; i && (to = Lis[i].to, 1); i = Lis[i].nx)       if (to != f && !vis[to])         dfs_pre(to, x), cntson[x] += cntson[to], Max(Mxson[x], cntson[to]);   }   map<pair<int, int>, int> mp;   map<int, int> pm;   void dfs_pro(int x, int f, int v1, int c, int v2, int fac) {     mp[pair<int, int>(v1, c)]++, pm[v2]++;     for (int i = Head[x], to; i && (to = Lis[i].to, 1); i = Lis[i].nx)       if (to != f && !vis[to])         dfs_pro(to, x, (v1 * 10LL + Lis[i].d) % P, c + 1,                 (v2 + (long long)fac * Lis[i].d) % P, fac * 10LL % P);   }   void dfs(int x) {     sz = 0;     dfs_pre(x, x);     int pl = cntson[x], rt = x;     for (int i = 0; i < sz; i++) {       int p = q[i];       Max(Mxson[p], cntson[x] - cntson[p]);       if (Mxson[p] < pl) pl = Mxson[p], rt = p;     }     mp.clear(), pm.clear();     dfs_pro(rt, rt, 0, 0, 0, 1);     ans--;     for (map<pair<int, int>, int>::iterator it = mp.begin(); it != mp.end();          it++) {       int lp = (long long)(P - (it->first).first) *                fast(fast(10, (it->first).second), phi) % P;       map<int, int>::iterator it1 = pm.find(lp);       if (it1 != pm.end()) ans += (long long)(it->second) * (it1->second);     }     for (int i = Head[rt], to; i && (to = Lis[i].to, 1); i = Lis[i].nx)       if (!vis[to]) {         mp.clear(), pm.clear();         dfs_pro(to, rt, Lis[i].d % P, 1, Lis[i].d % P, 10 % P);         for (map<pair<int, int>, int>::iterator it = mp.begin(); it != mp.end();              it++) {           int lp = (long long)(P - (it->first).first) *                    fast(fast(10, (it->first).second), phi) % P;           map<int, int>::iterator it1 = pm.find(lp);           if (it1 != pm.end()) ans -= (long long)(it->second) * (it1->second);         }       }     vis[rt] = 1;     for (int i = Head[rt], to; i && (to = Lis[i].to, 1); i = Lis[i].nx)       if (!vis[to]) dfs(to);   }   int main() {     Rd(n), Rd(P);     if (P == 1) {       cout << (long long)n * (n - 1) << endl;       return 0;     }     phi = P;     int t = P;     for (int i = 2; (long long)i * i <= phi; i++)       if (t % i == 0) {         phi = phi / i * (i - 1);         while (t % i == 0) t /= i;       }     if (t > 1) phi = phi / t * (t - 1);     phi--;     for (int i = 1, x, y, z; i < n; i++)       Rd(x), Rd(y), Rd(z), x++, y++, Add(x, y, z), Add(y, x, z);     dfs(1);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 70, M = 11, MA = 1030;   long long int dp[M][N][M][MA], dps[M][N][MA], dpt[M][N], n, q, b, l, r, x;   vector<long long int> v;   long long int get(long long int a, long long int b) {     long long int x = a, ans, mask = 0, l;     v.resize(0);     while (x > 0) {       v.push_back(x % b);       x /= b;     }     l = (long long int)v.size();     ans = dpt[b][l];     reverse(v.begin(), v.end());     for (auto y : v) {       for (int j = b - 1; j > y; j--) ans -= dp[b][l][j][mask];       mask ^= (1 << y);       l--;     }     return ans;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     for (long long int bi = 2; bi <= 10; bi++) {       for (int l = 2; l <= 65; l++) {         for (int c = 0; c < bi; c++) {           dp[bi][1][c][(1ll << c)] = 1;           for (int mask = 0; mask < (1ll << bi); mask++)             dps[bi][1][mask] += dp[bi][1][c][mask];         }         dpt[bi][1] = 0;       }     }     for (long long int bi = 2; bi <= 10; bi++) {       for (int l = 2; l <= 65; l++) {         dpt[bi][l] = dpt[bi][l - 1];         for (int c = 0; c < bi; c++) {           for (int i = 0; i < bi; i++)             for (int mask = 0; mask < (1ll << bi); mask++) {               x = mask, x ^= (1ll << c);               dp[bi][l][c][mask] += dp[bi][l - 1][i][x];             }           for (int mask = 0; mask < (1ll << bi); mask++)             dps[bi][l][mask] += dp[bi][l][c][mask];           if (c != 0) dpt[bi][l] += dp[bi][l][c][0];         }       }     }     cin >> q;     for (int i = 1; i <= q; i++) {       cin >> b >> l >> r;       l--;       cout << get(r, b) - get(l, b) <<   n ;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math,O3 )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx )   using namespace std;   template <class U, class V>   istream& operator>>(istream& is, pair<U, V>& p) {     is >> p.first >> p.second;     return is;   }   template <class T>   istream& operator>>(istream& is, vector<T>& v) {     for (auto& x : v) {       is >> x;     }     return is;   }   template <class T>   ostream& operator<<(ostream& os, vector<T>& v) {     for (auto& x : v) {       os << x <<    ;     }     return os;   }   const int N = 1e5 + 5;   int n, x, y;   vector<int> b;   int freq[N];   int match_indices[N];   set<pair<int, int>> cnt;   vector<int> match_colors[N];   void init() {     cnt.clear();     for (int i = 0; i < n + 3; ++i) {       freq[i] = 0;       match_indices[i] = 0;       match_colors[i].clear();     }   }   void buildFreq() {     for (int x : b) {       ++freq[x];     }     for (int i = 1; i <= n + 1; ++i) {       if (freq[i] != 0) {         cnt.emplace(freq[i], i);       }     }   }   int getMissingElement() {     for (int i = 1; i <= n + 1; ++i) {       if (freq[i] == 0) return i;     }     assert(false);     return -1;   }   void buildMatchIndices() {     for (int i = 0; i < x; ++i) {       auto it = cnt.end();       --it;       auto curr = *it;       cnt.erase(it);       --curr.first;       ++match_indices[curr.second];       if (curr.first != 0) {         cnt.emplace(curr);       }     }   }   bool buildMatchColors() {     if (y == 0) return true;     if (cnt.empty()) return false;     int y = ::y;     vector<int> v1;     for (auto p : cnt) {       while (p.first--) {         v1.emplace_back(p.second);       }     }     auto v2 = v1;     rotate(begin(v2), begin(v2) + ((int)(v1.size())) - cnt.rbegin()->first,            end(v2));     for (int i = 0; i < ((int)(v1.size())); ++i) {       if (v1[i] == v2[i]) continue;       if (y == 0) break;       --y;       match_colors[v1[i]].emplace_back(v2[i]);     }     return y == 0;   }   void check(const vector<int>& a) {     int x = ::x;     int y = ::y;     y += x;     for (int i = 0; i < n; ++i) {       x -= (a[i] == b[i]);     }     assert(x == 0);     multiset<int> ms(begin(a), end(a));     for (int i = 0; i < n; ++i) {       auto it = ms.find(b[i]);       if (it == end(ms)) continue;       ms.erase(it);       --y;     }     assert(y == 0);   }   void solve() {     if (y < x) {       cout <<  NO  << endl;       return;     }     y -= x;     init();     buildFreq();     buildMatchIndices();     if (!buildMatchColors()) {       cout <<  NO  << endl;       return;     }     int missing_element = getMissingElement();     vector<int> res(n, missing_element);     for (int i = 0; i < n; ++i) {       if (match_indices[b[i]] > 0) {         --match_indices[b[i]];         res[i] = b[i];         continue;       }       if (!match_colors[b[i]].empty()) {         res[i] = match_colors[b[i]].back();         match_colors[b[i]].pop_back();       }     }     check(res);     cout <<  YES  << endl;     cout << res << endl;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) {       cin >> n >> x >> y;       b.resize(n);       cin >> b;       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int A[1 << 21], B[1 << 21];   long long level_index1[21];   long long level_index2[21];   long long mergesort(int begin, int end, int level) {     if (begin == end) return 0;     long long inv_index = 0;     int middle = (begin + end) / 2;     inv_index += mergesort(begin, middle, level + 1);     inv_index += mergesort(middle + 1, end, level + 1);     int left = begin;     int right = middle + 1;     long long ct = 0;     long long ct2 = 0;     for (int k = begin; k <= end; ++k) {       if (right > end || (left <= middle && (A[left] <= A[right]))) {         B[k] = A[left++];       } else {         B[k] = A[right++];         ct += (middle - left + 1);       }     }     left = begin, right = middle + 1;     for (int k = begin; k <= end; ++k) {       if (right > end || (left <= middle && (A[left] < A[right]))) {         left++;         ct2 += (end - right + 1);       } else {         right++;       }     }     for (int k = begin; k <= end; ++k) A[k] = B[k];     level_index1[level] += ct;     level_index2[level] += ct2;     return inv_index + ct;   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     int fim = 1 << n;     for (int i = 0; i < fim; ++i) cin >> A[i];     for (int lvl = 0; lvl <= n; ++lvl) {       level_index1[lvl] = level_index2[lvl] = 0;     }     mergesort(0, fim - 1, 0);     int m;     cin >> m;     while (m--) {       int q;       cin >> q;       long long ans = 0;       q = n - q;       for (int lvl = 0; lvl < q; ++lvl) {         ans += level_index1[lvl];       }       for (int lvl = q; lvl < n; ++lvl) {         swap(level_index1[lvl], level_index2[lvl]);         ans += level_index1[lvl];       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = (0); i < (n); ++i) {       long long t, T, x, cost;       cin >> t >> T >> x >> cost;       if (t >= T) {         ans += cost + m * x;         continue;       }       long long aux1 = cost;       if (m > (T - t)) aux1 += m * x;       long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1;       aux2 *= cost;       ans += min(aux1, aux2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, minn = 1000000, indx;     cin >> n;     int arr[n + 1];     for (int i = 1; i <= n; i++) cin >> arr[i];     for (int i = 1; i < n; i++) {       if (abs(arr[i] - arr[i + 1]) < minn) {         minn = abs(arr[i] - arr[i + 1]);         indx = i;       }     }     if (abs(arr[1] - arr[n]) < minn)       cout << n <<     << 1 << endl;     else       cout << indx <<     << indx + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   const int maxn = 300 + 10;   char st[maxn][maxn];   int n, m, p;   int main() {     scanf( %d%d%d , &n, &m, &p);     for (int i = 1; i <= n; i++) scanf( %s , st[i] + 1);     for (int k = 1; k <= n; k++) {       for (int i = 1 + k; i + k <= n; i++)         for (int j = 1 + k; j + k <= m; j++)           if (st[i][j] ==  *  && st[i - k][j] ==  *  && st[i + k][j] ==  *  &&               st[i][j - k] ==  *  && st[i][j + k] ==  * ) {             p--;             if (!p) {               printf( %d %d n%d %d n%d %d n%d %d n%d %d n , i, j, i - k, j, i + k,                      j, i, j - k, i, j + k);               return 0;             }           }     }     printf( -1 n );   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y) {     int temp;     if (y == 0) return 1;     temp = power(x, y / 2);     if (y % 2 == 0)       return temp * temp;     else       return x * temp * temp;   }   long long int fun(long long int n) {     if (n == 0)       return 0;     else {       return n % 10 + fun(n / 10);     }   }   int main() {     long long int t;     cin >> t;     for (int _ = 0; _ < t; _++) {       long long int n, k, a, b;       cin >> k >> n >> a >> b;       if (k - (n * b) <= 0)         cout <<  -1 n ;       else {         long long int ans = 0;         if ((k - (n * b)) % (a - b) == 0) {           ans = ((k - (n * b)) / (a - b)) - 1;         } else {           ans = (k - (n * b)) / (a - b);         }         ans = min(n, ans);         cout << ans <<   n ;       }     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   template <typename T, size_t N>   int SIZE(const T (&t)[N]) {     return N;   }   template <typename T>   int SIZE(const T &t) {     return t.size();   }   string to_string(const string s, int x1 = 0, int x2 = 1e9) {     return     + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) :   ) +    ;   }   string to_string(const char *s) { return to_string((string)s); }   string to_string(const bool b) { return (b ?  true  :  false ); }   string to_string(const char c) { return string({c}); }   template <size_t N>   string to_string(const bitset<N> &b, int x1 = 0, int x2 = 1e9) {     string t =   ;     for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1);          __iii__ <= __jjj__; ++__iii__) {       t += b[__iii__] +  0 ;     }     return     + t +    ;   }   template <typename A, typename... C>   string to_string(const A(&v), int x1 = 0, int x2 = 1e9, C... coords);   int l_v_l_v_l = 0, t_a_b_s = 0;   template <typename A, typename B>   string to_string(const pair<A, B> &p) {     l_v_l_v_l++;     string res =  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;     l_v_l_v_l--;     return res;   }   template <typename A, typename... C>   string to_string(const A(&v), int x1, int x2, C... coords) {     int rnk = rank<A>::value;     string tab(t_a_b_s,    );     string res =   ;     bool first = true;     if (l_v_l_v_l == 0) res +=   n ;     res += tab +  [ ;     x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v));     auto l = begin(v);     advance(l, x1);     auto r = l;     advance(r, (x2 - x1) + (x2 < SIZE(v)));     for (auto e = l; e != r; e = next(e)) {       if (!first) {         res +=  ,  ;       }       first = false;       l_v_l_v_l++;       if (e != l) {         if (rnk > 1) {           res +=   n ;           t_a_b_s = l_v_l_v_l;         };       } else {         t_a_b_s = 0;       }       res += to_string(*e, coords...);       l_v_l_v_l--;     }     res +=  ] ;     if (l_v_l_v_l == 0) res +=   n ;     return res;   }   void dbgm() { ; }   template <typename Heads, typename... Tails>   void dbgm(Heads H, Tails... T) {     cout << to_string(H) <<   |  ;     dbgm(T...);   }   const long long MOD = (int)1e9 + 7;   string ascii_lowercase =  abcdefghijklmnopqrstuvwxyz ;   string ascii_uppercase =  ABCDEFGHIJKLMNOPQRSTUVWXYZ ;   long long inv(long long a, long long b) {     return 1 < a ? b - inv(b % a, a) * b / a : 1;   }   const long long INF = 1e6;   unordered_map<int, int, custom_hash> mp;   long long gcd(long long a, long long b, long long &x, long long &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long d = gcd(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return d;   }   long long distsq(long long x1, long long y1, long long x2, long long y2) {     return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);   }   long long n, m;   double get(double x1, double y1, double x2, double y2, double x3, double y3) {     if (x3 == x1) {       return (x2 - x1) * (x2 - x1);     }     if (y3 == y1) {       return (y2 - y1) * (y2 - y1);     }     double m = (y3 - y1) / (x3 - x1);     double c = y1 - m * x1;     double mm = -1 / m;     double interx = (-m * c + m * y2 + x2) / (1 + m * m);     double dx = interx - x2;     double dy = mm * dx;     return dx * dx + dy * dy;   }   double px[1005];   double py[1005];   double ans = -1;   int main() {     cin >> n;     for (int i = 0; i < (n); i++) {       cin >> px[i] >> py[i];     }     double curr;     for (int i = 0; i < (n); i++) {       curr = get(px[i], py[i], px[(i + 1) % n], py[(i + 1) % n], px[(i + 2) % n],                  py[(i + 2) % n]);       if (ans < 0) ans = curr;       ans = min(ans, curr);     }     printf( %.12f n , sqrt(ans) / 2.0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 7;   long long M = 1e9 + 7;   long long dp[N];   long long g[N][30];   int n;   vector<int> a;   int ch[N][N];   int main() {     ch[0][0] = 1;     cin >> n;     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= i; j++) {         if (j == 0) {           ch[j][i] = 1;           continue;         }         ch[j][i] = (ch[j - 1][i - 1] + ch[j][i - 1]) % M;       }     }     for (int i = 1; i <= n; i++) {       char c;       cin >> c;       if (!a.size())         a.push_back(c -  a  + 1);       else if (a.back() != c -  a  + 1)         a.push_back(c -  a  + 1);     }     dp[0] = 1;     for (int i = 0; i < a.size(); i++) {       for (int j = a.size(); j >= 2; j--) {         dp[j] += -g[j][a[i]] - g[j - 1][a[i]] + dp[j - 1];         g[j][a[i]] = dp[j - 1] - g[j - 1][a[i]];         dp[j] %= M;         g[j][a[i]] %= M;       }       if (g[1][a[i]] == 0) dp[1]++;       g[1][a[i]] = 1;     }     long long res = 0;     for (int i = 1; i <= n; i++) {       dp[i] = (((dp[i] % M) + M) % M);       res = (res + ch[i - 1][n - 1] * dp[i]) % M;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool a[2001][2001], w[2001][2001];   int n, fi, fj, si, sj, dist, s, clr = 4;   inline bool val(int x, int y) { return (x > 0 && y > 0 && x < n && y < n); }   inline void clear(int x, int y) {     s = 0;     for (int i = 0; i < clr; i++)       for (int j = 0; j < clr; j++)         if (a[i + x][j + y]) s++;     if (s <= clr)       for (int i = 0; i < clr; i++)         for (int j = 0; j < clr; j++) a[i + x][j + y] = 0;   }   void dfs(int x, int y) {     w[x][y] = 1;     s++;     if (((x - fi) * (x - fi)) + ((y - fj) * (y - fj)) > dist)       dist = ((x - fi) * (x - fi)) + ((y - fj) * (y - fj));     if (val(x - 1, y) && a[x - 1][y] && !w[x - 1][y]) dfs(x - 1, y);     if (val(x + 1, y) && a[x + 1][y] && !w[x + 1][y]) dfs(x + 1, y);     if (val(x, y - 1) && a[x][y - 1] && !w[x][y - 1]) dfs(x, y - 1);     if (val(x, y + 1) && a[x][y + 1] && !w[x][y + 1]) dfs(x, y + 1);   }   int main() {     ios_base::sync_with_stdio(0);     int i, j, x, as = 0, ac = 0;     cin >> n;     for (i = 0; i < n; i++)       for (j = 0; j < n; j++) cin >> a[i][j];     for (i = 0; i < n; i += clr)       for (j = 0; j < n; j += clr) clear(i, j);     for (i = 0; i < n; i++)       for (j = 0; j < n; j++)         if (!w[i][j] && a[i][j]) {           dist = s = 0;           fi = i, fj = j;           dfs(i, j);           if (dist < 200.0) {             a[i][j] = 0;             continue;           }           s *= 1.2;           double d = sqrt(dist), sq = ((d / sqrt(2.0)) * (d / sqrt(2.0))),                  circ = ((d / 2.0) * (d / 2.0)) * M_PI;           if (abs(s - sq) < abs(s - circ))             as++;           else             ac++;         }     cout << ac <<     << as;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 999999999;   const long long INFL = 99999999999999999LL;   const double EPSILON = 0.00000001;   const long long MOD = 1000000007;   long long a[100005];   int32_t main() {     long long n, t;     scanf( %I64d , &n);     ;     scanf( %I64d , &t);     ;     for (long long i = 0; i < n; i++) scanf( %I64d , &a[i]);     ;     long long ans = 0;     long long l = 0, r = 0;     long long cur = 0;     long long s = 0;     while (l < n) {       while (r < n and s + a[r] <= t) {         s += a[r];         r++;         cur++;         ans = ((ans) > (cur) ? (ans) : (cur));       }       l++;       if (l > r)         r++;       else {         s -= a[l - 1];         cur--;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int fr[200004];   struct cmp {     bool operator()(int a, int b) const { return a > b; }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     auto make = [](vector<int>& a, int pos) {       swap(a[pos + 2], a[pos + 1]);       swap(a[pos + 1], a[pos]);     };     int t;     cin >> t;     while (t--) {       int n, i, j, k, l;       cin >> n;       vector<int> v(n);       vector<pair<int, int>> p(n);       for (i = 0; i < n; i++) {         cin >> v[i];         p[i] = {v[i], i};       }       sort(p.begin(), p.end());       for (i = 0; i < n; i++) v[p[i].second] = i;       int cnt = 0;       for (i = 0; i < n - 1; i++) {         for (j = i + 1; j < n; j++)           if (v[j] < v[i]) cnt++;       }       if (cnt & 1) {         for (i = 0; i < n - 1; i++)           if (p[i].first == p[i + 1].first) {             swap(v[p[i].second], v[p[i + 1].second]);             break;           }       }       vector<int> ans;       for (i = 0; i < n - 2; i++) {         int pos = min_element(v.begin() + i, v.end()) - v.begin();         while (pos > i + 1) {           make(v, pos - 2);           ans.push_back(pos - 2);           pos = pos - 2;         }         if (pos != i) {           make(v, i);           make(v, i);           ans.push_back(i);           ans.push_back(i);           pos = i;         }       }       for (i = 0; i < 3; i++) {         if (is_sorted(v.begin(), v.end())) {           break;         }         make(v, n - 3);         ans.push_back(n - 3);       }       if (!is_sorted(v.begin(), v.end())) {         cout << -1 <<   n ;         continue;       }       cout << ans.size() <<   n ;       for (int x : ans) cout << x + 1 <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int x, y;     cin >> x >> y;     if (x == 1) {       if (y <= 1) {         cout <<  yes  << endl;         return;       } else {         cout <<  no  << endl;         return;       }     } else if (x == 2 || x == 3) {       if (y <= 3) {         cout <<  yes  << endl;         return;       } else {         cout <<  no  << endl;         return;       }     } else if (x > 3) {       cout <<  yes  << endl;       return;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int q;     cin >> q;     while (q--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Bitset {     int sz, len;     vector<unsigned int> v;     Bitset(int szz) {       len = szz;       sz = szz + 31 >> 5;       v.clear();       v.resize(sz, 0);     }     Bitset operator<<=(int x) {       int d = x >> 5, r = x & 31;       for (int i = sz - 1; i >= d; i--) v[i] = v[i - d];       for (int i = d - 1; i >= 0; i--) v[i] = 0;       if (r) {         for (int i = sz - 1; i >= 1; i--)           v[i] = ((v[i] & ((1u << 32 - r) - 1)) << r) | (v[i - 1] >> 32 - r);         v[0] = (v[0] & ((1u << 32 - r) - 1)) << r;       }     }     Bitset operator|(const Bitset &b) {       Bitset rlt = Bitset(len);       for (int i = 0; i < sz; i++) rlt.v[i] = v[i] | b.v[i];       return rlt;     }     Bitset operator^(const Bitset &b) {       Bitset rlt = Bitset(len);       for (int i = 0; i < sz; i++) rlt.v[i] = v[i] ^ b.v[i];       return rlt;     }     vector<int> get() {       vector<int> rlt;       for (int i = 0; i < sz; i++)         if (v[i]) {           for (int j = 0; j < 32; j++)             if (v[i] & (1u << j)) rlt.push_back((i << 5) | j);         }       return rlt;     }     bool bit(int x) { return v[x >> 5] & (1u << (x & 31)); }   };   int n, s, a[70707], id[70707], in[70707];   bool vis[70707];   set<int> st[70707];   bool cmp(int i, int j) {     return a[i] != a[j] ? a[i] < a[j] : !vis[i] && vis[j];   }   int main() {     Bitset val = Bitset(70707), nwb = Bitset(70707), tmp = Bitset(70707);     scanf( %d %d , &n, &s);     int I = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (a[i] > s) return puts( -1 ), 0;       if (a[i] > a[I]) I = i;     }     vis[I] = 1;     s -= a[I];     val.v[0] = 1;     for (int i = 1; i <= n && s; i++)       if (!vis[i] && a[i] <= s) {         tmp = val;         tmp <<= a[i];         nwb = val ^ (val | tmp);         val = val | tmp;         vector<int> v = nwb.get();         for (int j = 0; j < v.size(); j++) {           if (v[j] <= s) st[i].insert(v[j]);         }       }     if (!val.bit(s)) return puts( -1 ), 0;     for (int i = n; i >= 1; i--) {       if (st[i].find(s) != st[i].end()) {         s -= a[i];         vis[i] = 1;       }     }     for (int i = 1; i <= n; i++) id[i] = i;     sort(id + 1, id + n + 1, cmp);     for (int i = 1; i <= n; i++) {       if (!vis[id[i]]) {         in[id[i + 1]] = id[i];       }     }     for (int i = 1; i <= n; i++) {       printf( %d  , a[i] - a[in[i]]);       if (in[i])         printf( 1 %d n , in[i]);       else         puts( 0 );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, t, i, j, k;   long long a[2000005];   long long ans, sum;   int main() {     scanf( %d%d , &n, &m);     for (i = 1; i <= m * 2; i++) {       scanf( %d , &t);       a[t]++;     }     for (i = 1; i <= n; i++) ans += a[i] * (n - 1 - a[i]);     printf( %lld n , (long long)n * (n - 1) * (n - 2) / 6 - ans / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long T, n, k;     cin >> T;     while (T--) {       cin >> n >> k;       long long ans = 0;       while (n) {         if (n % k != 0)           ans += n % k, n -= n % k;         else           ans++, n /= k;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[100][100];   int row[100];   vector<pair<pair<int, int>, pair<int, int> > > v;   int pos[30000][2];   int main() {     int n;     int sum = 0;     while (scanf(  %d , &n) == 1) {       v.clear();       sum = 0;       for (int i = 1; i <= n; i++) scanf(  %d , &row[i]);       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= row[i]; j++) {           scanf(  %d , &arr[i][j]);           pos[arr[i][j]][0] = i;           pos[arr[i][j]][1] = j;         }         sum += row[i];       }       int cnt = 1;       int swcnt = 0;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= row[i]; j++) {           if (arr[i][j] != cnt) {             swcnt++;             int r = pos[cnt][0];             int c = pos[cnt][1];             int val = arr[i][j];             arr[i][j] = cnt;             arr[r][c] = val;             pos[val][0] = r;             pos[val][1] = c;             pos[cnt][0] = i;             pos[cnt][1] = j;             v.push_back(make_pair(make_pair(i, j), make_pair(r, c)));           }           cnt++;         }       }       printf( %d n , swcnt);       for (int i = 0; i < ((int)v.size()); i++)         printf( %d %d %d %d n , v[i].first.first, v[i].first.second,                v[i].second.first, v[i].second.second);     }   }


#include <bits/stdc++.h>   using namespace std;   int n, a[3];   int dp[310][310];   string name[2] = { BitAryo ,  BitLGM };   int mem(int x, int y) {     if (dp[x][y] != -1) return dp[x][y];     int mn = 1;     for (int i = 1; i <= x; i++) mn = min(mn, mem(x - i, y));     for (int i = 1; i <= y; i++) mn = min(mn, mem(x, y - i));     for (int i = 1; i <= min(x, y); i++) mn = min(mn, mem(x - i, y - i));     return dp[x][y] = 1 - mn;   }   int main() {     memset(dp, -1, sizeof dp);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     if (n == 1) cout << name[(a[0] == 0 ? 0 : 1)] << endl;     if (n == 2) cout << name[mem(a[0], a[1])] << endl;     if (n == 3) cout << name[((a[0] ^ a[1] ^ a[2]) == 0 ? 0 : 1)] << endl;     return 0;   }


#include <bits/stdc++.h>   struct Point {     double x, y;   };   struct Polygon {     Point p[100000];     int n;     inline double get(int i, double x) {       if (i < 0) return p[0].y;       if (i >= n - 1) return p[n - 1].y;       return p[i].y +              (x - p[i].x) * (p[i + 1].y - p[i].y) / (p[i + 1].x - p[i].x);     }     double area() {       double sum = 0;       for (int i = 0; i < n - 1; i++)         sum += (p[i + 1].x - p[i].x) * (p[i + 1].y + p[i].y) / 2;       return sum;     }   };   Polygon poly[2];   Polygon inp;   Polygon ta;   Polygon tb;   void intersect(Polygon& res, Polygon& a, Polygon& b) {     ta.n = tb.n = res.n = 0;     int ai = 0, bi = 0;     while (ai < a.n || bi < b.n) {       if (ai < a.n && (bi >= b.n || a.p[ai].x < b.p[bi].x)) {         tb.p[tb.n].x = a.p[ai].x;         tb.p[tb.n++].y = b.get(bi - 1, a.p[ai].x);         ta.p[ta.n++] = a.p[ai++];       } else {         ta.p[ta.n].x = b.p[bi].x;         ta.p[ta.n++].y = a.get(ai - 1, b.p[bi].x);         tb.p[tb.n++] = b.p[bi++];       }     }     for (int i = 0, next = 0; i < ta.n; i = next) {       while (next < ta.n && ta.p[next].x - ta.p[i].x < 1e-6) next++;       res.p[res.n].x = ta.p[i].x;       res.p[res.n++].y = (ta.p[i].y > tb.p[i].y ? ta.p[i].y : tb.p[i].y);       if (next < ta.n &&           (ta.p[i].y - tb.p[i].y) * (ta.p[next].y - tb.p[next].y) < -1e-6) {         double t = (tb.p[i].y - ta.p[i].y) /                    (ta.p[next].y - ta.p[i].y - tb.p[next].y + tb.p[i].y);         res.p[res.n].x = ta.p[i].x + t * (ta.p[next].x - ta.p[i].x);         res.p[res.n++].y = ta.p[i].y + t * (ta.p[next].y - ta.p[i].y);       }     }   }   int main() {     int n;     scanf( %d%d , &n, &inp.n);     inp.n++;     for (int i = 0; i < inp.n; i++) inp.p[i].x = i;     int cur = 0;     double prev = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < inp.n; j++) scanf( %lf , &inp.p[j].y);       if (i == 0)         memcpy(&poly[1 - cur], &inp, sizeof inp);       else         intersect(poly[1 - cur], poly[cur], inp);       cur = 1 - cur;       double area = poly[cur].area();       printf( %lf n , area - prev);       prev = area;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int from, to, vis, next;   } e[400020];   int top, head[200020];   vector<int> g[200020];   int in[200020], gg[200020];   int n, m, k;   int ans[200020], cnt;   void add_edge(int from, int to) {     e[++top].to = to;     e[top].from = from;     e[top].next = head[from];     head[from] = top;   }   void add(int from, int to) {     add_edge(from, to);     add_edge(to, from);   }   queue<int> q;   void del(int pos) {     if (!gg[pos]) cnt--;     q.push(pos);     gg[pos] = 1;     while (!q.empty()) {       int now = q.front();       q.pop();       for (int i = head[now]; ~i; i = e[i].next) {         if (e[i].vis || gg[e[i].to]) continue;         in[e[i].to]--;         e[i].vis = 1;         e[i ^ 1].vis = 1;         if (in[e[i].to] < k) {           cnt--;           gg[e[i].to] = 1;           q.push(e[i].to);         }       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &k);     cnt = n;     top = -1;     memset(head, -1, sizeof(head));     int from, to;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &from, &to);       in[from]++, in[to]++;       add(from, to);     }     for (int i = 1; i <= n; i++) {       if (head[i] == -1) cnt--, gg[i] = 1;     }     for (int i = 1; i <= n; i++) {       if (in[i] < k && !gg[i]) del(i);     }     int ttt = m;     for (int i = 2 * m - 1; i >= 1; i -= 2) {       ans[ttt--] = cnt;       if (e[i].vis) continue;       in[e[i].from]--;       in[e[i].to]--;       e[i].vis = e[i ^ 1].vis = 1;       if (!gg[e[i].from] && in[e[i].from] < k) del(e[i].from);       if (!gg[e[i].to] && in[e[i].to] < k) del(e[i].to);     }     for (int i = 1; i <= m; i++) printf( %d n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> s;   vector<long long>::iterator it;   long long n, m, a;   long long sum = 0;   int main() {     cin >> n >> m;     for (long long i = 0; i < n; ++i) {       cin >> a;       s.push_back(a);       sum += a;     }     if (m > sum)       cout << -1 << endl;     else {       sort(s.begin(), s.end(), greater<long long>());       long long l = 1, r = n;       while (l <= r) {         long long mid = (l + r) / 2, ans = 0, temp = 0;         it = s.begin();         while (it != s.end()) {           long long cnt = 0;           while (cnt < mid && it != s.end()) {             ans += max((long long)0, *it - temp);             ++it, ++cnt;           }           ++temp;         }         if (ans < m)           l = mid + 1;         else           r = mid - 1;       }       cout << l << endl;     }   }


#include <bits/stdc++.h>   const double eps = (1e-9);   using namespace std;   int dcmp(long double a, long double b) {     return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;   }   int getBit(long long num, int idx) { return ((num >> idx) & 1ll) == 1; }   int setBit1(int num, int idx) { return num | (1 << idx); }   long long setBit0(long long num, int idx) { return num & ~(1ll << idx); }   long long flipBit(long long num, int idx) { return num ^ (1ll << idx); }   void M() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int countNumBit1(int mask) {     int ret = 0;     while (mask) {       mask &= (mask - 1);       ++ret;     }     return ret;   }   const int N = 300009;   int arr[N], key[N], n, power[32], ans[N];   string ret;   struct trie {     trie* child[3];     int isleaf;     trie() {       isleaf = 0;       memset(child, 0, sizeof(child));     }   };   string to_bin(int n) {     string ret =   , ans =   ;     while (n) {       ret += (char)((n % 2) +  0 );       n /= 2;     }     int rem = 30 - ((int)(ret).size());     while (rem--) {       ret +=  0 ;     }     for (int i = ((int)(ret).size()) - 1; i >= 0; i--) {       ans += ret[i];     }     return ans;   }   int to_dec(string s) {     int ans = 0;     for (int i = ((int)(s).size()) - 1; i >= 0; i--) {       ans += power[((int)(s).size()) - 1 - i] * (s[i] -  0 );     }     return ans;   }   void insertt(trie* cur, int id, string s) {     if (id == ((int)(s).size())) {       cur->isleaf++;       return;     }     int ch = s[id] -  0 ;     if (cur->child[ch] == 0) {       cur->child[ch] = new trie();     }     insertt(cur->child[ch], id + 1, s);   }   bool removee(trie* cur, int id, string s) {     if (id == ((int)(s).size())) {       cur->isleaf--;       return (cur->isleaf == 0 && (cur->child[0] == 0 && cur->child[1] == 0));     }     int ch = s[id] -  0 ;     bool ret = removee(cur->child[ch], id + 1, s);     if (ret) {       cur->child[ch] = 0;       return (cur->isleaf == 0 && cur->child[0] == 0 && cur->child[1] == 0);     }     return 0;   }   void findd(trie* cur, int id, string s) {     if (id == ((int)(s).size())) {       return;     }     int ch = s[id] -  0 ;     int opch = (s[id] ==  0  ?  1  :  0 ) -  0 ;     if (cur->child[ch] != 0) {       ret += (char)(ch +  0 );       findd(cur->child[ch], id + 1, s);     } else if (cur->child[opch] != 0) {       ret += (char)(opch +  0 );       findd(cur->child[opch], id + 1, s);     }   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     power[0] = 1;     for (int i = 1; i <= 30; i++) power[i] = power[i - 1] * 2;     trie* root = new trie();     int no;     for (int i = 0; i < n; i++) {       cin >> no;       string st = to_bin(no);       insertt(root, 0, st);     }     for (int i = 0; i < n; i++) {       string st = to_bin(arr[i]);       ret =   ;       findd(root, 0, st);       removee(root, 0, ret);       ans[i] = arr[i] ^ (to_dec(ret));     }     for (int i = 0; i < n; i++) {       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int log2(int x) { return 31 - __builtin_clz(x); }   int main(void) {     std::ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     int n, q;     cin >> n >> q;     vector<long long> a(n);     for (int i = 0; i < (int)(n); i++) {       cin >> a[i];     }     for (int i = 0; i < (int)(n); i++) {       int b;       cin >> b;       a[i] = b - a[i];       if (i) {         a[i] += a[i - 1];       }     }     vector<vector<long long> > mn(20, vector<long long>(n)),         mx(20, vector<long long>(n));     copy(a.begin(), a.end(), mn[0].begin());     copy(a.begin(), a.end(), mx[0].begin());     for (int k = 1; k < 20; k++) {       for (int i = 0; i + (1 << (k - 1)) < n; i++) {         mn[k][i] = min(mn[k - 1][i], mn[k - 1][i + (1 << (k - 1))]);         mx[k][i] = max(mx[k - 1][i], mx[k - 1][i + (1 << (k - 1))]);       }     }     int l, r;     while (q--) {       cin >> l >> r;       --l;       int k = log2(r - l);       long long _min = min(mn[k][l], mn[k][r - (1 << k)]);       long long _max = max(mx[k][l], mx[k][r - (1 << k)]);       long long start = l ? a[l - 1] : 0;       if (start != a[r - 1] || _min < start) {         cout <<  -1 n ;       } else {         cout << _max - start <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int weight[11];   int total = 0;   int bd2 = 0;   int mem[11][5001];   int m;   bool wasal = false;   int arr[1001];   int knapsack(int i, int prev, int totalPrev, int me, int all, int counter) {     arr[counter - 1] = prev;     if (i == m) {       wasal = true;       bd2 = all;       return 0;     }     int choice2 = 0;     if (!wasal) {       for (int j = 0; j < total && !wasal; j++) {         if (weight[j] != prev && me + weight[j] > totalPrev && !wasal) {           if (totalPrev == -1) {             totalPrev = 0;           }           choice2 += knapsack(i + 1, weight[j], me + weight[j], totalPrev,                               me + weight[j] + totalPrev, counter + 1) +                      1;         }       }       return choice2;     }     return 0;   }   int main() {     string c;     cin >> c;     for (int i = 0; i < c.size(); i++) {       if (c.at(i) ==  1 ) {         weight[total] = i + 1;         total++;       }     }     memset(arr, false, sizeof(arr));     cin >> m;     int num = knapsack(0, 0, -1, 0, 0, 0);     if (wasal) {       cout <<  YES  << endl;       for (int i = 0; i < m; i++) {         if (i != 0) {           cout <<     << arr[i];         } else {           cout << arr[i];         }       }     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T cross(complex<T> a, complex<T> b) {     return imag(conj(a) * b);   }   template <typename T>   T dot(complex<T> a, complex<T> b) {     return real(conj(a) * b);   }   struct __Query {     static bool query;   };   bool __Query::query = false;   template <typename T>   struct Point {     complex<T> p;     mutable function<const complex<T> *()> succ;     bool operator<(const Point &rhs) const {       const complex<T> &q = rhs.p;       if (!__Query::query) {         if (real(p) != real(q)) return real(p) < real(q);         return imag(p) < imag(q);       }       const complex<T> *s = succ();       if (!s) return false;       return dot(p - *s, q) < 0;     }   };   template <typename T, int turn>   struct half_hull : public set<Point<T>> {     using set<Point<T>>::begin;     using set<Point<T>>::insert;     using set<Point<T>>::end;     using set<Point<T>>::lower_bound;     using set<Point<T>>::empty;     using set<Point<T>>::erase;     using typename set<Point<T>>::iterator;     complex<T> extreme(const complex<T> &p) const {       assert(!empty() && turn * imag(p) >= 0);       __Query::query = true;       auto pos = lower_bound(Point<T>{p});       __Query::query = false;       assert(pos != end());       return pos->p;     }     void insert(const complex<T> &p) {       auto y = insert(Point<T>{p}).first;       if (y == end()) return;       y->succ = [=] { return next(y) == end() ? nullptr : &next(y)->p; };       if (bad(y)) {         erase(y);         return;       }       while (y != begin() && bad(prev(y))) erase(prev(y));       while (next(y) != end() && bad(next(y))) erase(next(y));     }       private:     bool bad(iterator y) {       if (y == begin() || y == end()) return false;       auto x = prev(y), z = next(y);       if (z == end()) return false;       return cross(y->p - x->p, z->p - x->p) * turn >= 0;     }   };   template <typename T>   struct convex_hull_trick {     void insert(const complex<T> &p) {       lower_hull.insert(p);       upper_hull.insert(p);     }     complex<T> extreme(const complex<T> &p) const {       if (std::imag(p) < 0) return lower_hull.extreme(p);       return upper_hull.extreme(p);     }     long long get(const complex<T> &p) const {       if (upper_hull.empty()) return 0LL;       return dot(p, extreme(p));     }       private:     half_hull<T, +1> upper_hull;     half_hull<T, -1> lower_hull;   };   long long solve(vector<vector<int>> &adj, int root = 0) {     int n = adj.size();     vector<long long> sz(n), sz2(n), ssz(n);     long long ans = 0;     function<void(int, int)> dfs = [&](int u, int p) {       sz[u] = 1;       for (auto v : adj[u])         if (v != p) {           dfs(v, u);           sz[u] += sz[v];         }     };     function<void(int, int)> dfs2 = [&](int u, int p) {       sz2[u] += sz[u] * sz[u];       for (auto v : adj[u])         if (v != p) {           sz2[v] += sz2[u];           ssz[v] += ssz[u] + sz[v] * sz[u];           dfs2(v, u);         }     };     function<long long(int, int)> dfs3 = [&](int u, int p) {       convex_hull_trick<long long> cht;       long long ret = -sz2[u] + ssz[u];       for (auto v : adj[u])         if (v != p) {           long long temp = dfs3(v, u);           ret = max(ret, temp);           long long r = sz[v] * n + sz2[u] - ssz[v] + temp;           ans = max(ans, r);           ans = max(ans, r + cht.get({1LL, -sz[v]}));           cht.insert({r, sz[v]});         }       return ret;     };     dfs(root, -1);     dfs2(root, -1);     dfs3(root, -1);     return ans;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n;     cin >> n;     vector<vector<int>> adj(n);     for (int i = 1, u, v; i < n; ++i) {       cin >> u >> v;       --u, --v;       adj[u].push_back(v);       adj[v].push_back(u);     }     long long ans = n * (n - 1LL) / 2 + solve(adj);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, a[100005], sum, en;   bool cheak(long long mid) {     long long sum = 0, cnt = m;     for (int i = 1; i <= n; ++i) {       if (a[i]) {         sum += a[i];         while (sum > mid - i) {           sum -= (mid - i);           cnt--;           if (cnt < 0) return 0;         }       }     }     if (!cnt) return sum <= 0;     return 1;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> a[i];     long long l = 0, r = 1e17, ans;     while (l < r) {       long long mid = (l + r) / 2;       if (cheak(mid))         ans = mid, r = mid;       else         l = mid + 1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n;     int a[n], i;     for (i = 0; i < n; ++i) cin >> a[i];     cin >> m;     int b[m];     for (i = 0; i < m; ++i) cin >> b[i];     sort(a, a + n, greater<int>());     sort(b, b + m, greater<int>());     cout << a[0] <<     << b[0] << endl;     return 0;   }


#include<bits/stdc++.h>   using namespace std;      #define ll long long int   #define M 1000000007      int main()   {       ios_base::sync_with_stdio(false);       cin.tie(0),cout.tie(0);       int t,n,x;       cin>>t;       string str= 2020 ;       while(t--)       {           int a,b,c,d,e,c1,c2,c3;           cin>>c1>>c2>>c3;           cin>>a>>b>>c>>d>>e;           bool flag=true;           int te=min(c1,a);           c1-=te;           a-=te;           te=min(c2,b);           c2-=te;           b-=te;           te=min(c3,c);           c3-=te;           c-=te;           te=min(c1,d);           c1-=te;           d-=te;           te=min(c2,e);           c2-=te;           e-=te;           te=min(c3,d);           c3-=te;           d-=te;           te=min(c3,e);           c3-=te;           e-=te;           if(a||b||c||d||e)               cout<< no ;           else               cout<< yes ;           cout<<endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     string s[n];     for (int i = 0; i < n; i++) cin >> s[i];     vector<vector<int>> row(n), col(m);     for (int i = n - 1; i >= 0; i--) {       for (int j = 0; j < m; j++) {         if (s[i][j] ==  # ) {           row[i].push_back(j);           col[j].push_back(i);         }       }     }     deque<pair<int, int>> q;     int rw[n];     int rvis[n];     for (int i = 0; i < n; i++) {       rw[i] = INT_MAX;       rvis[i] = 0;     }     int cw[m];     int cvis[m];     for (int i = 0; i < m; i++) {       cw[i] = INT_MAX;       cvis[i] = 0;     }     rw[n - 1] = 0;     q.push_back(make_pair(0, n - 1));     while (q.size() > 0) {       int type = q.front().first;       int num = q.front().second;       q.pop_front();       if (type == 0) {         if (rvis[num] == 1)           continue;         else           rvis[num] = 1;         if (num == 0) break;         for (int i = 0; i < row[num].size(); i++) {           int cn = row[num][i];           if (cvis[cn] == 0 && cw[cn] > rw[num] + 1) {             cw[cn] = rw[num] + 1;             q.push_back(make_pair(1, cn));           }         }       } else if (type == 1) {         if (cvis[num] == 1)           continue;         else           cvis[num] = 1;         for (int i = 0; i < col[num].size(); i++) {           int rn = col[num][i];           if (rvis[rn] == 0 && rw[rn] > cw[num] + 1) {             rw[rn] = cw[num] + 1;             q.push_back(make_pair(0, rn));           }         }       }     }     if (rw[0] == INT_MAX)       cout << -1;     else       cout << rw[0];   }


#include <bits/stdc++.h>   using namespace std;   class Solution {    public:     long long maximize(vector<int>& nums, int x) {       int n = nums.size();       vector<vector<long long>> dp(3, vector<long long>(n + 1, 0));       long long res = 0;       for (int i = 0; i < n; ++i) {         long long num = nums[i];         dp[0][i + 1] = max(0LL, dp[0][i] + num);         dp[1][i + 1] = max(0LL, max(dp[0][i], dp[1][i]) + num * x);         dp[2][i + 1] = max(0LL, max(dp[2][i], dp[1][i]) + num);       }       for (int j = 0; j < 3; ++j) {         for (int i = 0; i <= n; ++i) {           res = max(res, dp[j][i]);         }       }       return res;     }   };   int main(int argc, char** argv) {     ios::sync_with_stdio(false);     cin.tie(0);     Solution sol;     int n, x;     cin >> n >> x;     vector<int> nums(n);     for (int i = 0; i < n; ++i) {       cin >> nums[i];     }     cout << sol.maximize(nums, x) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   int main() {     int i, n, sum;     while (scanf( %d , &n) != EOF) {       sum = 0;       while (n != 1) {         sum += n;         for (i = 2; i <= n; i++) {           if (n % i == 0) {             n /= i;             break;           }         }       }       cout << sum + 1 << endl;     }     return 0;   }