#include <bits/stdc++.h>   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,avx )   using namespace std;   const int MAXSIZE = 10000020;   int bufpos;   char buf[MAXSIZE];   void init() {     buf[fread(buf, 1, MAXSIZE, stdin)] =   0 ;     bufpos = 0;   }   int readint() {     int val = 0;     for (; !isdigit(buf[bufpos]); bufpos++)       ;     for (; isdigit(buf[bufpos]); bufpos++) val = val * 10 + buf[bufpos] -  0 ;     return val;   }   char readchar() {     for (; isspace(buf[bufpos]); bufpos++)       ;     return buf[bufpos++];   }   int readstr(char *s) {     int cur = 0;     for (; isspace(buf[bufpos]); bufpos++)       ;     for (; !isspace(buf[bufpos]); bufpos++) s[cur++] = buf[bufpos];     s[cur] =   0 ;     return cur;   }   char bf[1 << 25], st[20], *w = bf;   void flush() {     fwrite(bf, 1, w - bf, stdout);     w = bf;   }   inline void pc(register char c) { *w++ = c; }   void print(register int n) {     register char *t = st;     do {       *t++ = n % 10 + 48;     } while (n /= 10);     while (t-- > st) pc(*t);   }   int n, q, fa[66666], aa[66666], kh[66666], a[66666], p[66666], fp[66666],       siz[66666], ck, pa[66666];   vector<int> edge[66666];   int dd[66666];   void dfs(int u) {     siz[u] = 1;     p[++ck] = u;     fp[u] = ck;     pa[ck] = fp[fa[u]];     dd[ck] = dd[pa[ck]] + 1;     for (auto v : edge[u]) {       dfs(v);       siz[u] += siz[v];     }   }   int main() {     init();     n = readint();     q = readint();     for (int i = 1; i <= n; ++i) {       aa[i] = readint();     }     for (int i = 2; i <= n; ++i) {       fa[i] = readint();       edge[fa[i]].push_back(i);     }     dfs(1);     for (int i = 1; i <= n; ++i) {       a[fp[i]] = aa[i];       kh[i] = -50001;     }     for (int i = 1; i <= q; ++i) {       int x = readint();       int y = siz[x];       x = fp[x];       int pp = i + 1, gg = y >> 3, *jj = kh + x, *diao = dd + x, *aa = a + x;       int ans = 0, cnt = 0;       for (int j = 0; j < gg; ++j, jj += 8, diao += 8, aa += 8) {         int w;         w = jj[0] + aa[0] < pp, jj[0] = w ? i : jj[0], ans += w * diao[0],         cnt += w;         w = jj[1] + aa[1] < pp, jj[1] = w ? i : jj[1], ans += w * diao[1],         cnt += w;         w = jj[2] + aa[2] < pp, jj[2] = w ? i : jj[2], ans += w * diao[2],         cnt += w;         w = jj[3] + aa[3] < pp, jj[3] = w ? i : jj[3], ans += w * diao[3],         cnt += w;         w = jj[4] + aa[4] < pp, jj[4] = w ? i : jj[4], ans += w * diao[4],         cnt += w;         w = jj[5] + aa[5] < pp, jj[5] = w ? i : jj[5], ans += w * diao[5],         cnt += w;         w = jj[6] + aa[6] < pp, jj[6] = w ? i : jj[6], ans += w * diao[6],         cnt += w;         w = jj[7] + aa[7] < pp, jj[7] = w ? i : jj[7], ans += w * diao[7],         cnt += w;       }       gg <<= 3;       for (int j = gg; j < y; ++j) {         int w;         w = jj[j - gg] + aa[j - gg] < pp, jj[j - gg] = w ? i : jj[j - gg],         ans += w * diao[j - gg], cnt += w;         ;       }       ans = ans - cnt * dd[x];       print(ans);       pc(   );       print(cnt);       pc(  n );     }     flush();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> a(n);     priority_queue<pair<int, int>, vector<pair<int, int>>,                    greater<pair<int, int>>>         pq;     long long sum = 0;     for (int i = 0; i < n; ++i) {       cin >> a[i];       sum += a[i] / 10;       pq.push(pair<int, int>(10 - (a[i] % 10), i));     }     while (!pq.empty()) {       pair<int, int> t = pq.top();       pq.pop();       int val = t.first;       int ind = t.second;       sum -= a[ind] / 10;       a[ind] += val;       sum += a[ind] / 10;       if (a[ind] <= 100 && k >= val) {         k -= val;         pq.push(pair<int, int>(10 - (a[ind] % 10), ind));       } else {         sum -= a[ind] / 10;         a[ind] -= val;         sum += a[ind] / 10;       }       if (k < 0) break;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   int main() {     string s, ans;     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  . ) ans +=  0 ;       if (s[i] ==  - ) {         i++;         if (s[i] ==  . )           ans +=  1 ;         else           ans +=  2 ;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int l = s.length();     int ans = ((l + 1) * 26) - l;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 mt_rand(time(0));   const int N = 3e5 + 5;   int q, n, s[N], maks[N], dp[N];   map<int, int> mapa[N];   int main() {     scanf( %d , &q);     while (q--) {       scanf( %d , &n);       for (int i = 0; i < n; i++) scanf( %d , &s[i]);       for (int i = 0; i < n; i++) {         maks[i] = -1;         mapa[i].clear();         dp[i] = 0;       }       mapa[0][s[0]] = 0;       for (int i = 1; i < n; i++) {         if (mapa[i - 1].count(s[i])) {           int pos = mapa[i - 1][s[i]];           maks[i] = pos;           swap(mapa[i], mapa[pos - 1]);           if (pos > 0) mapa[i][s[pos - 1]] = pos - 1;         }         mapa[i][s[i]] = i;       }       long long ans = 0;       for (int i = 1; i < n; i++) {         if (maks[i] == -1)           dp[i] = 0;         else if (maks[i] == 0)           dp[i] = 1;         else           dp[i] = 1 + dp[maks[i] - 1];         ans += dp[i];       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MAXN = 1e5 + 5;   ll x;   string s;   int ans[MAXN];   void init() {     ;     ;   }   void solve(int casei) {     ll n = s.length();     s =  #  + s;     for (int i = 1; i <= n; ++i) {       ans[i] = -1;     }     for (int i = 1; i <= n; ++i) {       if (s[i] ==  0 ) {         if (i + x <= n) ans[i + x] = 0;         if (i - x >= 1) ans[i - x] = 0;       }     }     for (int i = 1; i <= n; ++i) {       if (s[i] ==  1 ) {         bool flg = false;         if (i + x <= n && ans[i + x] != 0) ans[i + x] = 1, flg = true;         if (i - x >= 1 && ans[i - x] != 0) ans[i - x] = 1, flg = true;         if (flg == false) {           cout <<  -1 n ;           return;         }       }     }     for (int i = 1; i <= n; ++i) {       if (ans[i] == -1) ans[i] = 1;     }     for (int i = 1; i <= n; ++i) cout << ans[i];     cout << endl;   }   int main() {     int Case = 1;     ios::sync_with_stdio(false);     cin.tie(0);     cin >> Case;     for (int casei = 1; casei <= Case; ++casei) {       cin >> s >> x;       init();       solve(casei);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int v[N];   int n, k;   int main() {     scanf( %d %d , &n, &k);     n--;     for (int i = 1; i <= n; ++i) scanf( %d , v + i), v[i] += v[i - 1];     int ans = 0x3F3F3F3F;     for (int i = k; i <= n; ++i) ans = min(ans, v[i] - v[i - k]);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a, b, c, l, ans;   long long int rec(long long int A, long long int B, long long int C,                     long long int L) {     if (A < B + C) {       return 0;     }     long long int d = min(L, A - B - C);     return ((d + 1) * (d + 2)) / 2;   }   int main() {     while (cin >> a >> b >> c >> l) {       ans = (l + 3) * (l + 2) * (l + 1);       ans /= 6;       for (long long int i = 0; i <= l; i++) {         ans -= rec(a + i, b, c, l - i);         ans -= rec(b + i, a, c, l - i);         ans -= rec(c + i, a, b, l - i);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   std::istream& operator>>(std::istream& i, pair<T, U>& p) {     i >> p.first >> p.second;     return i;   }   template <typename T>   std::istream& operator>>(std::istream& i, vector<T>& t) {     for (auto& v : t) {       i >> v;     }     return i;   }   template <typename T, typename U>   std::ostream& operator<<(std::ostream& o, const pair<T, U>& p) {     o << p.first <<     << p.second;     return o;   }   template <typename T>   std::ostream& operator<<(std::ostream& o, const vector<T>& t) {     if (t.empty()) o <<   n ;     for (size_t i = 0; i < t.size(); ++i) {       o << t[i] <<    n [i == t.size() - 1];     }     return o;   }   template <typename T>   using minheap = priority_queue<T, vector<T>, greater<T>>;   template <typename T>   using maxheap = priority_queue<T, vector<T>, less<T>>;   template <typename T>   bool in(T a, T b, T c) {     return a <= b && b < c;   }   unsigned int logceil(int first) {     return 8 * sizeof(int) - __builtin_clz(first);   }   namespace std {   template <typename T, typename U>   struct hash<pair<T, U>> {     hash<T> t;     hash<U> u;     size_t operator()(const pair<T, U>& p) const {       return t(p.first) ^ (u(p.second) << 7);     }   };   }  // namespace std   template <typename T, typename F>   T bsh(T l, T h, const F& f) {     T r = -1, m;     while (l <= h) {       m = (l + h) / 2;       if (f(m)) {         l = m + 1;         r = m;       } else {         h = m - 1;       }     }     return r;   }   template <typename F>   double bshd(double l, double h, const F& f, double p = 1e-9) {     unsigned int r = 3 + (unsigned int)log2((h - l) / p);     while (r--) {       double m = (l + h) / 2;       if (f(m)) {         l = m;       } else {         h = m;       }     }     return (l + h) / 2;   }   template <typename T, typename F>   T bsl(T l, T h, const F& f) {     T r = -1, m;     while (l <= h) {       m = (l + h) / 2;       if (f(m)) {         h = m - 1;         r = m;       } else {         l = m + 1;       }     }     return r;   }   template <typename F>   double bsld(double l, double h, const F& f, double p = 1e-9) {     unsigned int r = 3 + (unsigned int)log2((h - l) / p);     while (r--) {       double m = (l + h) / 2;       if (f(m)) {         h = m;       } else {         l = m;       }     }     return (l + h) / 2;   }   template <typename T>   T gcd(T a, T b) {     if (a < b) swap(a, b);     return b ? gcd(b, a % b) : a;   }   template <typename T>   class vector2 : public vector<vector<T>> {    public:     vector2() {}     vector2(size_t a, size_t b, T t = T())         : vector<vector<T>>(a, vector<T>(b, t)) {}   };   template <typename T>   class vector3 : public vector<vector2<T>> {    public:     vector3() {}     vector3(size_t a, size_t b, size_t c, T t = T())         : vector<vector2<T>>(a, vector2<T>(b, c, t)) {}   };   template <typename T>   class vector4 : public vector<vector3<T>> {    public:     vector4() {}     vector4(size_t a, size_t b, size_t c, size_t d, T t = T())         : vector<vector3<T>>(a, vector3<T>(b, c, d, t)) {}   };   template <typename T>   class vector5 : public vector<vector4<T>> {    public:     vector5() {}     vector5(size_t a, size_t b, size_t c, size_t d, size_t e, T t = T())         : vector<vector4<T>>(a, vector4<T>(b, c, d, e, t)) {}   };   template <unsigned int N>   class Field {     inline unsigned int pow(unsigned int a, unsigned int p) {       unsigned int r = 1, e = a;       while (p) {         if (p & 1) {           r = ((unsigned long long)r * e) % N;         }         e = ((unsigned long long)e * e) % N;         p >>= 1;       }       return r;     }     inline unsigned int inv(unsigned int a) { return pow(a, N - 2); }       public:     inline Field(int first = 0) : v(first) {}     inline Field<N> pow(int p) { return (*this) ^ p; }     inline Field<N> operator^(int p) { return {(int)pow(v, (unsigned int)p)}; }     inline Field<N>& operator+=(const Field<N>& o) {       if ((long long)v + o.v >= N)         v += o.v - N;       else         v += o.v;       return *this;     }     inline Field<N>& operator-=(const Field<N>& o) {       if (v < o.v)         v -= o.v - N;       else         v -= o.v;       return *this;     }     inline Field<N>& operator*=(const Field<N>& o) {       v = (unsigned long long)v * o.v % N;       return *this;     }     inline Field<N>& operator/=(const Field<N>& o) { return *this *= inv(o.v); }     inline Field<N> operator+(const Field<N>& o) const {       Field<N> r{*this};       return r += o;     }     inline Field<N> operator-(const Field<N>& o) const {       Field<N> r{*this};       return r -= o;     }     inline Field<N> operator*(const Field<N>& o) const {       Field<N> r{*this};       return r *= o;     }     inline Field<N> operator/(const Field<N>& o) const {       Field<N> r{*this};       return r /= o;     }     inline Field<N> operator-() {       if (v)         return {(int)(N - v)};       else         return {0};     };     inline Field<N>& operator++() {       ++v;       if (v == N) v = 0;       return *this;     }     inline Field<N> operator++(int) {       Field<N> r{*this};       ++*this;       return r;     }     inline Field<N>& operator--() {       --v;       if (v == -1) v = N - 1;       return *this;     }     inline Field<N> operator--(int) {       Field<N> r{*this};       --*this;       return r;     }     inline bool operator==(const Field<N>& o) const { return o.v == v; }     inline bool operator!=(const Field<N>& o) const { return o.v != v; }     inline explicit operator unsigned int() const { return v; }     inline static vector<Field<N>> fact(int t) {       vector<Field<N>> F(t + 1, 1);       for (int i = 2; i <= t; ++i) {         F[i] = F[i - 1] * i;       }       return F;     }     inline static vector<Field<N>> invfact(int t) {       vector<Field<N>> F(t + 1, 1);       Field<N> X{1};       for (int i = 2; i <= t; ++i) {         X = X * i;       }       F[t] = 1 / X;       for (int i = t - 1; i >= 2; --i) {         F[i] = F[i + 1] * (i + 1);       }       return F;     }       private:     unsigned int v;   };   template <unsigned int N>   istream& operator>>(std::istream& is, Field<N>& f) {     unsigned int v;     is >> v;     f = v;     return is;   }   template <unsigned int N>   ostream& operator<<(std::ostream& os, const Field<N>& f) {     return os << (unsigned int)f;   }   template <unsigned int N>   Field<N> operator+(int i, const Field<N>& f) {     return Field<N>(i) + f;   }   template <unsigned int N>   Field<N> operator-(int i, const Field<N>& f) {     return Field<N>(i) - f;   }   template <unsigned int N>   Field<N> operator*(int i, const Field<N>& f) {     return Field<N>(i) * f;   }   template <unsigned int N>   Field<N> operator/(int i, const Field<N>& f) {     return Field<N>(i) / f;   }   struct Ring {     static int div(int p, int q, int N) {       long long t = 0, nt = 1, r = N, nr = q;       while (nr) {         long long q = r / nr;         t -= q * nt;         r -= q * nr;         swap(t, nt);         swap(r, nr);       }       t = (t < 0) ? t + N : t;       r = (r < 0) ? r + N : r;       if (gcd(p, N) % r) {         return 0;       }       return (int)(((long long)t * (long long)p / r) % N);     }   };   template <typename T>   struct Fenwick {     explicit Fenwick(unsigned int N = 0, T t = T())         : N(1u << logceil(N)), F(this->N, t), t(t) {}     explicit Fenwick(const vector<T>& A, T t = T())         : N(1u << logceil(A.size())), F(A), t(t) {       F.resize(N);       fill(F.begin() + A.size(), F.end(), t);       for (int i = 0; i < N; i++) {         int j = i + lsb(i + 1);         if (j < N) F[j] += F[i];       }     }     void add(int i, T v) {       while (i <= N) {         F[i] += v;         i += lsb(i + 1);       }     }     T sum(int i) const {       T sum(t);       while (i) {         sum += F[i - 1];         i -= lsb(i);       }       return sum;     }     T range(int i, int j) const {       j++;       T s(t);       while (j > i) {         s += F[j - 1];         j -= lsb(j);       }       while (i > j) {         s -= F[i - 1];         i -= lsb(i);       }       return s;     }     T get(int i) const { return range(i, i); }     void set(int i, T v) { add(i, v - get(i)); }     constexpr int lsb(int i) const { return i & -i; }     unsigned int N;     vector<T> F;     T t;   };   template <typename T>   struct Fenwick2 {     explicit Fenwick2(unsigned int N = 0, T t = T())         : N(1u << logceil(N)), F(this->N, this->N, t), t(t) {}     void add(int first, int second, T v) {       while (first <= N) {         int z = second;         while (z <= N) {           F[first][z] += v;           z += lsb(z + 1);         }         first += lsb(first + 1);       }     }     T sum(int first, int second) {       T sum(t);       while (first <= N) {         int z = second;         while (z <= N) {           sum += F[first][z];           z -= lsb(z + 1);         }         first -= lsb(first + 1);       }       return sum;     }     T range(int x1, int y1, int x2, int y2) {       T ans = sum(x2, y2);       if (x1) ans -= sum(x1 - 1, y2);       if (y1) ans -= sum(x2, y1 - 1);       if (x1 && y1) ans += sum(x1 - 1, y1 - 1);       return ans;     }     constexpr int lsb(int i) const { return i & -i; }     unsigned int N;     vector2<T> F;     T t;   };   class LittleElephantAndRetroStrings {    public:     void solve(istream& cin, ostream& cout) {       int N, K;       cin >> N >> K;       string S;       cin >> S;       vector2<Field<1000000007>> D(2, N - K + 1, 0);       vector<Field<1000000007>> X(N + 1, 1), R(N + 1, 1);       vector<int> W(N + 1, 0);       Field<1000000007> half = Field<1000000007>{1} / 2;       for (int r = 0; r < 2; ++r) {         char z = r ?  B  :  W ;         for (int i = 0; i < N; ++i) {           W[i + 1] = W[i] + (S[i] == z);           X[i + 1] = X[i];           R[i + 1] = R[i];           if (S[i] ==  X ) {             X[i + 1] += X[i];             R[i + 1] *= half;           }         }         Fenwick<Field<1000000007>> F(N, 0), G(N, 0);         Field<1000000007> f = 0, g = 0;         for (int i = 0; i + K <= N; ++i) {           if (W[i + K] == W[i]) {             D[r][i] = X[i];             D[r][i] -= f;             D[r][i] -= X[i] * g;           }           if (i - K >= 0) {             f -= D[r][i - K];             g += D[r][i - K] * R[i];           }           f += D[r][i];         }         for (int i = 0; i + K <= N; ++i) D[r][i] *= R[i + K];         if (r)           for (int i = 1; i + K <= N; ++i) D[1][i] += D[1][i - 1];         else           reverse(S.begin(), S.end());       }       Field<1000000007> ans = 0;       for (int i = 0; i <= N - 2 * K; ++i) {         ans += D[0][i] * D[1][N - 2 * K - i];       }       cout << ans * X[N] << endl;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     LittleElephantAndRetroStrings solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     solver.solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b;   long long res = 0LL;   int mod = 1000000007;   int main() {     cin >> a >> b;     cout << (((((((((a * (a + 1)) / 2 % mod) * (b % mod)) % mod) + a) % mod) %                mod) *               ((b * (b - 1)) / 2 % mod)) %              mod)          << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};   const long long linf = 4000000000000000000LL;   const long long inf = 998244353;   const long double pi = 3.1415926535;   long long maximum(long long x, long long y) {     if (x > y) return x;     return y;   }   long long minimum(long long x, long long y) {     if (x < y) return x;     return y;   }   void pv(vector<int> a) {     for (auto& x : a) cout << x <<    ;     cout <<   n ;   }   void pv(vector<long long> a) {     for (auto& x : a) cout << x <<    ;     cout <<   n ;   }   void pv(vector<vector<int> > a) {     for (int i = (0); i < (a.size()); ++i) {       cout << i <<   n ;       pv(a[i]);       cout <<   n ;     }   }   void pv(vector<vector<long long> > a) {     for (int i = (0); i < (a.size()); ++i) {       cout << i <<   n ;       pv(a[i]);     }     cout <<   n ;   }   void pv(vector<string> a) {     for (auto& x : a) cout << x <<   n ;     cout <<   n ;   }   int modInverse(int a, int m) {     int m0 = m;     int y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       int q = a / m;       int t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   long long power(long long x, long long y) {     long long k = 1 << 30;     long long z = 1;     while (k != 0) {       z *= z;       z %= inf;       if (y >= k) {         z *= x;         z %= inf;         y -= k;       }       k >>= 1;     }     return z;   }   long double area(pair<int, int> x, pair<int, int> y, pair<int, int> z) {     return ((long long)x.second * y.first + (long long)y.second * z.first +             (long long)z.second * x.first - (long long)x.first * y.second -             (long long)y.first * z.second - (long long)z.first * x.second) /            2.0;   }   bool clockwise(pair<int, int> x, pair<int, int> y, pair<int, int> z) {     return area(x, y, z) > 0;   }   struct point {     long double x, y;   };   long double area(point x, point y, point z) {     return (x.y * y.x + y.y * z.x + z.y * x.x - x.x * y.y - y.x * z.y -             z.x * x.y) /            2.0;   }   bool clockwise(point x, point y, point z) { return area(x, y, z) > 0; }   int gcd(int a, int b) {     if (a > b) swap(a, b);     if (a == 0) return b;     return gcd(a, b % a);   }   int popcount(int a) {     int count = 0;     while (a != 0) {       count += (a % 2);       a >>= 1;     }     return count;   }   long long choose(long long n, long long r) {     long long p = 1, k = 1;     if (n - r < r) r = n - r;     if (r != 0) {       while (r) {         p *= n;         k *= r;         long long m = gcd(p, k);         p /= m;         k /= m;         n--;         r--;       }     } else       p = 1;     return p;   }   vector<long long> prefix_hash(string& a, vector<long long>& powers) {     int n = int(a.size());     vector<long long> prefix(n + 1);     for (int i = (0); i < (n); ++i)       prefix[i + 1] = (prefix[i] + powers[i] * (a[i] -  a  + 1)) % inf;     return prefix;   }   void setIO(string second) {     ios_base::sync_with_stdio(0);     cin.tie(0);   }   int n;   vector<vector<int> > adj;   vector<int> v;   void dfs(int i, int p) {     v[i] = 1;     for (auto& x : adj[i]) {       if (x != p) dfs(x, i);     }   }   int main() {     setIO( test3 );     cin >> n;     adj.resize(n);     for (int i = (0); i < (n); ++i) {       int a;       cin >> a;       adj[--a].push_back(i);       adj[i].push_back(a);     }     int ans = 0;     v.resize(n);     for (int i = (0); i < (n); ++i) {       if (!v[i]) {         ans++;         dfs(i, -1);       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int dp[5050][5050], q[5050][5050];   int ans[5050], len;   char s[5050];   void init() {     for (int i = 0; i < len; i++) {       int l = 0;       while (i - l >= 0 && i + l < len && s[i - l] == s[i + l])         dp[i - l][i + l] = 1, l++;       l = 0;       while (i - l >= 0 && i + 1 + l < len && s[i - l] == s[i + l + 1])         dp[i - l][i + l + 1] = 1, l++;     }   }   void solve() {     for (int t = 0; t < len; t++) {       for (int j = 0; j + t < len; j++) {         if (!dp[j][j + t]) continue;         int mid;         if (t % 2 == 0)           mid = (j + j + t) / 2 - 1;         else           mid = (j + j + t) / 2;         if (mid < j)           q[j][j + t] = 1;         else           q[j][j + t] = q[j][mid] + 1;         ans[q[j][j + t]]++;       }     }   }   int main() {     scanf( %s , s);     len = strlen(s);     memset(dp, 0, sizeof(dp)), memset(ans, 0, sizeof(ans)),         memset(q, 0, sizeof(q));     init();     solve();     for (int i = len - 1; i >= 1; i--) ans[i] += ans[i + 1];     for (int i = 1; i <= len; i++) {       if (i == 1)         printf( %d , ans[i]);       else         printf(  %d , ans[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     return x * f;   }   int n, a, b, ans, ansa[1000000], ansb[1000000], cnta, cntb;   bool flag[1000000];   bool check(int k) {     int w = a;     cnta = cntb = 0;     for (int i = 1; i <= k; i++)       if (w >= i)         ansa[++cnta] = i, w -= i;       else         break;     ansa[cnta + 1] = k + 1;     for (int i = cnta; i >= 1; i--) {       if (!w) break;       while (w && ansa[i] + 1 < ansa[i + 1]) ansa[i]++, w--;     }     if (b >= 1ll * k * (k + 1) / 2 - (a - w))       return 1;     else       return 0;   }   int main() {     a = read(), b = read();     n = sqrt((a + b) * 2ll) + 2;     int l = 0, r = n;     while (l <= r) {       int mid = l + r >> 1;       if (check(mid))         ans = mid, l = mid + 1;       else         r = mid - 1;     }     int w = a;     cnta = cntb = 0;     for (int i = 1; i <= ans; i++)       if (w >= i)         ansa[++cnta] = i, w -= i;       else         break;     ansa[cnta + 1] = ans + 1;     for (int i = cnta; i >= 1; i--) {       if (!w) break;       while (w && ansa[i] + 1 < ansa[i + 1]) ansa[i]++, w--;     }     printf( %d n , cnta);     for (int i = 1; i <= cnta; i++) printf( %d  , ansa[i]), flag[ansa[i]] = 1;     cout << endl;     printf( %d n , ans - cnta);     for (int i = 1; i <= ans; i++)       if (!flag[i]) printf( %d  , i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2010;   int n, ans;   double x[maxn], y[maxn];   int main() {     scanf( %d , &n);     for (int i = 1, a, b, c; i <= n; i++) {       scanf( %d %d %d , &a, &b, &c);       x[i] = 1.0 * a * c / (a * a + b * b);       y[i] = 1.0 * b * c / (a * a + b * b);     }     for (int i = 1; i <= n; i++) {       vector<double> V;       int cnt = 0;       for (int j = i + 1; j <= n; j++) {         if (abs(x[i] - x[j]) > 1e-12)           V.push_back((y[i] - y[j]) / (x[i] - x[j]));         else if (abs(y[i] - y[j]) < 1e-12)           cnt++;         else           V.push_back(1e18);       }       ans += cnt * (n - i - cnt);       sort(V.begin(), V.end());       for (int j = 0, k; j < V.size(); j = k) {         for (k = j; k < V.size() && abs(V[j] - V[k]) < 1e-12; k++)           ;         ans += (k - j) * (k - j - 1) / 2;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   int map[55][55];   int to[55][55][4][2];   int rx[] = {0, -1, 0, 1};   int ry[] = {1, 0, -1, 0};   struct node {     int x, y, dp, cp;   };   int main() {     memset(map, 0, sizeof(map));     int n, m, step, i, j;     char str[55];     node now;     now.x = 1, now.y = 1;     now.dp = 0, now.cp = 1;     scanf( %d %d , &n, &step);     scanf( %s , str + 1);     m = strlen(str + 1);     for (i = 1; i <= m; i++) map[1][i] = str[i] -  0 ;     for (i = 2; i <= n; i++) {       for (j = 1; j <= m; j++) scanf( %1d , &map[i][j]);     }     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) {         if (map[i][j] == 0) continue;         for (int dir = 0; dir < 4; dir++) {           int x = i;           int y = j;           while (1) {             x += rx[dir];             y += ry[dir];             if (map[x][y] != map[i][j]) {               x -= rx[dir];               y -= ry[dir];               break;             }           }           to[i][j][dir][0] = x;           to[i][j][dir][1] = y;         }       }     for (i = 0; i < step; i++) {       int x = to[now.x][now.y][now.dp][0];       int y = to[now.x][now.y][now.dp][1];       now.x = x, now.y = y;       now.x = to[x][y][(now.dp + now.cp + 4) % 4][0];       now.y = to[x][y][(now.dp + now.cp + 4) % 4][1];       x = now.x + rx[now.dp];       y = now.y + ry[now.dp];       if (map[x][y]) {         now.x = x, now.y = y;       } else {         if (now.cp == 1) {           now.cp = -1;         } else {           now.cp = 1;           now.dp = (now.dp - 1 + 4) % 4;         }       }     }     printf( %d n , map[now.x][now.y]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     int n;     cin >> s;     n = s.size();     s = s +  b ;     for (int i = 0; i < n; i++) {       cout << (s[i] != s[i + 1] ? 1 : 0) <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     cin >> N;     vector<int> a(N);     for (int i = 0; i < N; ++i) {       scanf( %d , &a[i]);     }     sort(a.begin(), a.end());     int res = 0;     for (int i = 0; i <= N; ++i) {       if (a[i] == a[i + 1]) {         ++res;         ++i;       }     }     cout << res / 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool bi[12][12];   int main() {     int a, b, c, d, e, x, y, z, n, k, N, M;     scanf( %d %d , &N, &M);     scanf( %d %d , &z, &k);     for (a = 0; a < z; a++) {       scanf( %d %d , &x, &y);       bi[x][y] = true;     }     z = 0;     for (a = 1; a <= N; a++) {       for (b = 1; b <= M; b++) {         for (c = a; c <= N; c++) {           for (d = b; d <= M; d++) {             e = 0;             for (x = a; x <= c; x++) {               for (y = b; y <= d; y++)                 if (bi[x][y]) e++;             }             if (e >= k) z++;           }         }       }     }     cout << z << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long int mx = 0, n;     cin >> n;     vector<long int> vec;     for (int i = 0; i < n; i++) {       long int x;       cin >> x;       vec.push_back(x);     }     if (vec.size() == 1) {       cout <<  1  << endl;       return 0;     }     for (int i = 0; i < n; i++) {       long int len = 1, temp = vec[i];       for (int j = i + 1; j < n; j++) {         if (vec[j] >= temp) {           temp = vec[j];           len++;         } else {           break;         }       }       mx = max(mx, len);     }     cout << mx << endl;     return 0;   }


#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 lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = ((res % p) * (x % p)) % p;       y = y >> 1;       x = ((x % p) * (x % p)) % p;     }     return res % p;   }   long long raichu(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = ((res) * (x));       y = y >> 1;       x = ((x) * (x));     }     return res;   }   bool isprime(long long n) {     if (n < 2)       return false;     else if (n == 2)       return true;     else if (n % 2 == 0)       return false;     else {       long long z = sqrt(n);       for (int i = 0; i < z - 1; i++)         if (n % (i + 2) == 0) return false;       return true;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tests = 1, Tests;     Tests = tests;     while (tests--) {       int n;       long long A;       cin >> n >> A;       vector<int> d(n);       for (int i = 0; i < n; i++) cin >> d[i];       long long sum = 0;       for (int i = 0; i < n; i++) sum += d[i];       for (int i = 0; i < n; i++) {         long long mi = 1, ma = d[i];         long long left = A - (sum - d[i]);         if (left > 1) {           mi = left;         }         left = A - (n - 1);         if (left < d[i]) {           ma = left;         }         cout << d[i] - (ma - mi + 1) <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     scanf( %d%d%d , &a, &b, &c);     for (int i = 1, _b = a; i <= _b; i++) {       int j = a / i;       if (b % i == 0 && c % j == 0 && b / i == c / j) {         printf( %d n , 4 * (i + j + b / i));         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int tt = 1;     while (tt--) {       int n;       cin >> n;       int a[n - 1];       cout <<  ? 2 3  << endl << endl;       int m;       cin >> m;       for (int i = 0; i < n - 1; i++) {         cout <<  ?   << 1 <<     << i + 2 << endl << endl;         cin >> a[i];       }       int b[n];       for (int i = 2; i < n; i++) b[i] = a[i - 1] - a[i - 2];       b[1] = m - b[2];       b[0] = a[0] - b[1];       cout <<  !  ;       for (int i = 0; i < n; i++) cout << b[i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100 + 5;   double p[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> p[i];     sort(p + 1, p + n + 1);     reverse(p + 1, p + n + 1);     double one = 0, none = 1;     for (int i = 1; i <= n; i++) {       double nw = one * (1 - p[i]) + p[i] * none;       if (nw > one) {         one = nw;         none *= (1 - p[i]);       } else         break;     }     cout << setprecision(9) << one << endl;   }


#include <bits/stdc++.h>   using namespace std;   long a[200001];   long b[200001];   long n;   int main() {     cin >> n;     int k = 1;     for (int i = 1; i <= n; i++) {       cin >> a[k];       if (a[k] != 0) k++;     }     k = 1;     for (int i = 1; i <= n; i++) {       cin >> b[k];       if (b[k] != 0) k++;     }     long j = 1;     while (b[1] != a[j]) {       j++;     }     for (int i = 2; i <= n - 1; i++) {       j++;       if (j == n) j = 1;       if (b[i] != a[j]) {         cout <<  No  << endl;         return 0;       }     }     cout <<  Yes  << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   const int MAX = 1e6 + 5;   const long long MOD = 1000000007;   struct state {     int len, link, cnt;     int nx[26];   } st[MAX << 1];   int id, last, cur;   vector<int> v[MAX];   inline void sa_init() {     st[0].link = -1;     memset(st[0].nx, 0, sizeof st[0].nx);     id = last = st[0].cnt = 0;   }   inline void sa_extend(int c) {     int clone;     st[last].nx[c] = cur = ++id;     st[cur].len = st[last].len + 1;     v[st[cur].len].push_back(cur);     st[cur].cnt = 1;     int p = last;     while (1) {       if ((p = st[p].link) == -1) {         st[cur].link = 0;         break;       }       if (st[p].nx[c]) {         int q = st[p].nx[c];         if (st[p].len + 1 == st[q].len)           st[cur].link = q;         else {           clone = ++id;           st[clone] = st[q];           st[clone].cnt = 0;           st[clone].len = st[p].len + 1;           v[st[clone].len].push_back(clone);           st[q].link = st[cur].link = clone;           while (p != -1 && st[p].nx[c] == q) {             st[p].nx[c] = clone;             p = st[p].link;           }         }         break;       } else         st[p].nx[c] = cur;     }     last = cur;     return;   }   inline int lcs(string &s, string &t) {     sa_init();     for (char c : s) sa_extend(c -  a );     int best = 0, len = 0;     cur = 0;     for (char c : t) {       c -=  a ;       while (cur && !st[cur].nx[c]) cur = st[cur].link, len = st[cur].len;       if (st[cur].nx[c]) {         cur = st[cur].nx[c];         best = max(best, ++len);       }     }     return best;   }   bool vis[MAX << 1];   vector<int> del;   inline int solve(string &s) {     int n = s.size(), ans = 0, len = 0;     del.clear();     s += s;     cur = 0;     for (char c : s) {       c -=  a ;       while (cur && !st[cur].nx[c]) cur = st[cur].link, len = st[cur].len;       if (st[cur].nx[c]) {         cur = st[cur].nx[c], ++len;         if (len == n) {           if (!vis[cur]) ans += st[cur].cnt, vis[cur] = 1, del.push_back(cur);           --len;           if (len == st[st[cur].link].len) cur = st[cur].link;         }       }     }     for (int i : del) vis[i] = 0;     return ans;   }   string s;   int q;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     sa_init();     cin >> s;     for (char c : s) sa_extend(c -  a );     for (int i = s.size(); i >= 1; --i)       for (int j : v[i]) st[st[j].link].cnt += st[j].cnt;     cin >> q;     while (q--) {       cin >> s;       cout << solve(s) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int n;   const int MAXN = 2e5;   pair<ll, int> arr[MAXN];   ll sum[MAXN];   ll ans = 1e18;   void init() { ans = 1e18; }   void input() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i].first;     }     for (int j = 0; j < n; j++) {       cin >> arr[j].second;     }     sort(arr, arr + n);   }   void make_sum() {     sum[0] = arr[0].second;     for (int i = 1; i < n; i++) {       sum[i] = sum[i - 1] + arr[i].second;     }     ans = sum[n - 1];   }   void solve() {     for (int i = 0; i < n; i++) {       ans = min(ans, max(arr[i].first, sum[n - 1] - sum[i]));       if (ans == 3) {       }     }   }   void output() { cout << ans << endl; }   int main() {     int number_of_testcases = 1;     cin >> number_of_testcases;     while (number_of_testcases--) {       init();       input();       make_sum();       solve();       output();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a;   int s, kh;   int main() {     while (cin >> a) {       if (a ==  ( )         s++;       else if (s > 0) {         kh += 2;         s--;       }     }     cout << kh;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long int fibonocci(unsigned long long int n) {     unsigned long long int f, f1, f2, i;     f1 = 1;     f2 = 2;     i = 2;     while (1) {       f = f1 + f2;       if (f > n) {         return i - 1;       }       f1 = f2;       f2 = f;       i++;     }   }   int main() {     unsigned long long int n, i, x;     cin >> n;     if (n == 2) {       cout << 1;       return 0;     }     x = fibonocci(n);     cout << x;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     register int s = 0, f = 0;     register char ch = getchar();     while (!isdigit(ch)) {       f |= (ch ==  - );       ch = getchar();     }     while (isdigit(ch)) {       s = (s << 1) + (s << 3) + (ch ^ 48);       ch = getchar();     }     return f ? -s : s;   }   inline void write(int x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) {       write(x / 10);     }     putchar(x % 10 +  0 );   }   long long a[1005], n, ans;   signed main() {     cin >> n;     for (auto i = 1; i <= n; i += 1) {       cin >> a[i];     }     for (auto i = 1; i <= n; i += 2) {       long long sum = 0;       long long mn = a[i] - 1;       for (auto j = i + 1; j <= n; j += 2) {         sum += a[j - 1];         sum -= a[j];         if (sum < 0) {           ans += min(a[j] + sum + 1, mn + 1);           break;         } else {           ans += min(a[j], max(0LL, mn - sum + 1));           if (j == i + 1) {             mn = min(a[i], sum);           } else {             mn = min(mn, sum);           }         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int h[15][15];   int dist[15][15];   double expect[15][15];   unordered_map<int, pair<int, int> > dist2pos;   int main() {     for (int i = 0; i < 10; i++)       for (int j = 0; j < 10; ++j) cin >> h[i][j];     for (int i = 0; i < 10; ++i)       for (int j = 0; j < 10; ++j) {         if (i % 2 == 0) {           dist[i][j] = i + j + 9 * i;         } else {           dist[i][j] = i + 9 - j + 9 * i;         }         dist2pos[dist[i][j]] = make_pair(i, j);       }     bool left = true;     expect[0][0] = 0.0;     int x = 0, y = 1;     while (true) {       double e = 0.0;       if (dist[x][y] < 6) {         for (int dice = 1; dice <= dist[x][y]; ++dice) {           int xx = dist2pos[dist[x][y] - dice].first;           int yy = dist2pos[dist[x][y] - dice].second;           e += (1.0 / 6.0) * (expect[xx][yy] + 1);         }         e += (6 - dist[x][y]) / 6.0;         e /= (dist[x][y] / 6.0);         expect[x][y] = e;       } else {         for (int dice = 1; dice <= min(6, dist[x][y]); ++dice) {           int xx = dist2pos[dist[x][y] - dice].first;           int yy = dist2pos[dist[x][y] - dice].second;           double next_e;           if (h[xx][yy] == 0) {             next_e = expect[xx][yy];           } else {             int xxx = xx - h[xx][yy];             int yyy = yy;             next_e = min(expect[xx][yy], expect[xxx][yyy]);           }           e = e + (1.0 / 6.0) * next_e;         }         e += 1.0;         expect[x][y] = e;       }       if (x == 9 && y == 0) break;       auto p = dist2pos[dist[x][y] + 1];       x = p.first;       y = p.second;     }     cout << fixed << setprecision(6) << expect[9][0] << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int nums[200];   int arr[200][200];   int counter;   int line;   int main() {     int n;     cin >> n;     line = 0;     counter = 0;     int sum = 0;     int nums[200];     int arr[200][200];     memset(arr, 0, sizeof arr);     memset(nums, 0, sizeof nums);     while (sum + (++counter) <= n) {       sum += counter;     }     cout << counter << endl;     counter--;     int i;     int ct = counter;     int j;     arr[0][0] = 1;     arr[1][0] = 1;     for (i = 1; i <= counter; i++) {       arr[i][i] = arr[i - 1][i - 1] + ct;       ct = ct - 1;       arr[i + 1][i] = arr[i][i];     }     for (i = 0; i <= counter; i++) {       for (int j = i + 1; j < counter; j++) {         arr[i][j] = arr[i][j - 1] + 1;         arr[j + 1][i] = arr[i][j];       }     }     for (i = 0; i <= counter; i++) {       for (j = 0; j < counter; j++) {         cout << arr[i][j] <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> A[300005];   long long B[300005];   int main() {     long long n;     scanf( %lld , &n);     for (long long i = 1; i <= n; ++i) {       scanf( %lld , &A[i].first);       A[i].second = i;     }     sort(A + 1, A + n + 1);     long long val = 1;     for (long long i = 1; i <= n; ++i) {       val = max(val, A[i].first);       B[A[i].second] = val;       val++;     }     for (long long i = 1; i <= n; ++i) {       printf( %lld  , B[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T, n;     cin >> T;     while (T--) {       cin >> n;       long long ans = 0;       for (int i = 1; i <= n / 2; i++) {         ans += i * 1ll * i;       }       cout << ans * 8 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:10000000000 )   #pragma GCC optimize( O3 )   using namespace std;   const int MOD = 1000000007;   const int INF = 1000000007LL;   const long long INF2 = 1000000007LL * 1000000007LL;   const long double EPS = 1e-9;   const int SIZE = 3010;   mt19937 rng(time(0));   uniform_int_distribution<int> uid(-1000000000, 1000000000);   struct fenwick {     int n;     vector<int> a;     fenwick() {}     fenwick(int n_) {       n = n_;       a.resize(n, 0);     }     int query(int r) {       if (r < 0) return 0;       int sum = 0;       for (int i = r; i >= 0; i = (i & (i + 1)) - 1) sum += a[i];       return sum;     }     int query(int l, int r) { return query(r) - query(l - 1); }     void increase(int ind, int val = 1) {       for (int i = ind; i < n; i = i | (i + 1)) a[i] += val;     }   };   int a[SIZE][SIZE], n, m;   int zl[SIZE][SIZE], zr[SIZE][SIZE], zld[SIZE][SIZE];   int get_num_diag(int i, int j) {     int num = i + j;     return num;   }   vector<vector<pair<int, int> > > endColumn;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     cin >> n >> m;     endColumn.resize(n + m + 10);     for (int i = 1; i <= n; ++i) {       cin >> s;       for (int j = 1; j <= m; ++j) {         a[i][j] = s[j - 1] ==  z ;         if (a[i][j]) zl[i][j] = a[i][j] + zl[i][j - 1];       }     }     for (int i = n; i >= 1; --i) {       for (int j = m; j >= 1; --j) {         if (a[i][j]) {           zr[i][j] = a[i][j] + zr[i][j + 1];           zld[i][j] = a[i][j] + zld[i + 1][j - 1];           endColumn[j + zr[i][j] - 1].push_back({i, j});         }       }     }     vector<fenwick> f(n + m + 10, fenwick(n + 10));     long long ans = 0;     for (int j = m; j >= 1; --j) {       for (auto& j : endColumn[j]) {         int i2 = j.first, j2 = j.second;         f[i2 + j2].increase(i2);       }       for (int i = 1; i <= n; ++i) {         if (!a[i][j]) continue;         int len = min(zl[i][j], zld[i][j]) - 1;         long long rs = f[i + j].query(i, i + len);         ans += rs;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   std::string input() {     static char buf[1000];     scanf( %s , buf);     return std::string(buf);   }   int main() {     int inv[5] = {0, 1, 3, 2, 4};     int n, m;     std::cin >> n >> m;     static int a[500][1000];     for (int i = 0; i < m; i++) {       a[i][i + n] = 1;     }     for (int i = 0; i < n; i++) {       std::string s = input();       for (int j = 0; j < m; j++) {         a[j][i] = s[j] -  a ;       }     }     const int h = m;     const int w = n + m;     int r = 0;     for (int j = 0; j < n && r < h; j++) {       int p = r;       for (int i = r; i < h; i++) {         if (a[i][j] != 0) {           p = i;           break;         }       }       std::swap(a[p], a[r]);       if (a[r][j] == 0) continue;       for (int jj = j + 1; jj < w; jj++) {         a[r][jj] = a[r][jj] * inv[a[r][j]] % 5;       }       a[r][j] = 1;       for (int ii = 0; ii < h; ii++) {         if (ii != r) {           for (int jj = j + 1; jj < w; jj++) {             a[ii][jj] += 2500 - a[ii][j] * a[r][jj];             a[ii][jj] %= 5;           }           a[ii][j] = 0;         }       }       r++;     }     int q;     std::cin >> q;     while (q--) {       std::string b = input();       std::vector<int> v(m);       for (int i = 0; i < m; i++) {         v[i] = b[i] -  a ;       }       std::vector<int> u(m);       for (int i = 0; i < m; i++) {         for (int j = 0; j < m; j++) {           u[i] += a[i][n + j] * v[j];         }         u[i] %= 5;       }       bool any = false;       for (int i = r; i < m; i++) {         if (u[i] != 0) {           any = true;         }       }       constexpr long long MOD2 = 1e9 + 7;       long long ans = 1;       for (int i = r; i < n; i++) {         ans *= 5;         ans %= MOD2;       }       if (any) {         puts( 0 );         continue;       }       printf( %d n , (int)ans);     }   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000000;   const int mod = 1000000007;   const int sze = 100005;   int main() {     long long n;     char ch;     scanf( %I64d%c , &n, &ch);     bool flag = true;     long long term;     if (((n + 3) % 4) == 0) {       term = (n + 3) / 4;     } else if (((n + 2) % 4) == 0) {       term = (n + 2) / 4;       flag = false;     } else if (((n + 1) % 4) == 0) {       term = (n + 1) / 4;     } else if (((n) % 4) == 0) {       term = (n) / 4;       flag = false;     }     long long ans;     ans = (term - 1) * 16;     if (flag == false) {       ans = ans + 7;     }     if (ch ==  f ) {       ans = ans + 1;     } else if (ch ==  e ) {       ans = ans + 2;     } else if (ch ==  d ) {       ans = ans + 3;     } else if (ch ==  a ) {       ans = ans + 4;     } else if (ch ==  b ) {       ans = ans + 5;     } else {       ans = ans + 6;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using ll = long long int;   using namespace std;   int main() {     ll t;     cin >> t;     while (t--) {       ll p, q;       cin >> p >> q;       if (p % q != 0)         cout << p <<   n ;       else {         ll x = 1;         for (ll i = 1; i <= sqrt(q); i++) {           if (q % i == 0) {             ll pnew = p;             while (i != 1 && pnew % i == 0) {               pnew = pnew / i;               if (pnew % q != 0) {                 x = max(x, pnew);                 break;               }             }             pnew = p;             while (pnew % (q / i) == 0) {               pnew = pnew / (q / i);               if (pnew % q != 0) {                 x = max(x, pnew);                 break;               }             }           }         }         cout << x <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   char a[105][105];   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) {         cin >> a[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int k = 1; k <= 2; k++) {         for (int j = 1; j <= m; j++) {           cout << a[j][i] << a[j][i];         }         cout << endl;       }     }     return 0;   }


// Problem: A. Puzzle From the Future   // Contest: Codeforces - Codeforces Round #696 (Div. 2)   // URL: https://codeforces.ml/contest/1474/problem/A   // Memory Limit: 256 MB   // Time Limit: 1000 ms   //    // Powered by CP Editor (https://cpeditor.org)      #define _CRT_SECURE_NO_WARNINGS   #include <bits/stdc++.h>   using namespace std;   typedef long long ll;   #define forn(i,x,n) for(int i = x;i <= n;++i)       const int N = 1e5+7;   char s[N],ans[N];      int main()   {       int T;scanf( %d ,&T);       while(T--)       {     int n;scanf( %d ,&n);     scanf( %s ,s + 1);     int last = -1;     forn(i,1,n)     {      int c = s[i] -  0 ;      if(c + 1 == last) ans[i] =  0 ,last = c;      else ans[i] =  1 ,last = c + 1;     }     forn(i,1,n) printf( %c ,ans[i]);     puts(  );       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename U, typename V>   void Min(U &a, const V &b) {     if (a > b) a = b;   }   template <typename U, typename V>   void Max(U &a, const V &b) {     if (a < b) a = b;   }   template <typename U, typename V>   void add(U &a, const V &b) {     a = (a + b) % 1000000007;   }   template <typename U>   U gcd(U a, U b) {     if (a == 0) return b;     if (b == 0) return a;     if (a >= b)       return gcd(a % b, b);     else       return gcd(a, b % a);   }   int pow(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = 1LL * ans * a % 1000000007;       a = 1LL * a * a % 1000000007;       b >>= 1;     }     return ans;   }   struct node {     int k, d, t, K;     bool operator<(const node &a) const { return t < a.t; }   };   vector<node> a[505][505];   int dx[] = {1, 0}, dy[] = {0, 1};   long long dp[2][505][2][505];   const long long INF = 1e18;   int main() {     int T, m, n, i, j, k, K;     scanf( %d%d%d , &n, &m, &T);     int t, d;     while (T--) {       scanf( %d%d%d%d%d , &i, &j, &d, &t, &K);       a[i][j].push_back({0, d, t, K});       a[i + d][j - d].push_back({1, d, t + 1, K});       a[i + d][j].push_back({2, d, t + 2, K});       a[i][j + d].push_back({3, d, t + 3, K});     }     int now = 0;     for (int k = 0; k < m + 1; k++)       for (int i = 0; i < max(n, m) + 1; i++)         for (int j = 0; j < 2; j++) dp[now][k][j][i] = INF;     dp[0][0][0][0] = 0;     dp[0][0][1][0] = 0;     for (int len = 0; len < n + m - 1; len++) {       for (int j = 0; j < m; j++)         for (int k = 0; k < 2; k++)           for (int l = 0; l < max(n, m) + 1; l++) dp[1 - now][j][k][l] = INF;       for (int j = 0; j < m; j++) {         i = len - j;         if (i < 0) break;         if (i >= n) continue;         sort(a[i][j].begin(), a[i][j].end());         t = i + j;         for (int k = 0; k < 2; k++) {           for (int l = 0; l < ((k == 0) ? i + 1 : j + 1); l++)             if (dp[now][j][k][l] < INF) {               long long &w = dp[now][j][k][l];               for (auto &o : a[i][j]) {                 if (o.t > t) break;                 if ((t - o.t) % 4) {                   continue;                 }                 if (o.k < 2 || o.d > l) {                   w += o.K;                   continue;                 }                 int ok = 0;                 if (o.k == 2) {                   int tt = t - o.d - o.t + 2 - k;                   if (tt >= 0 && tt % 4 == 0) {                     ok = 1;                   }                 } else if (o.k == 3 && k == 1) {                   int tt = t - o.d - o.t + 3;                   if (tt >= 0 && tt % 4 == 0) {                     ok = 1;                   }                 }                 if (!ok) w += o.K;               }               for (int r = 0; r < 2; r++) {                 int first = i + dx[r], second = j + dy[r];                 if (first < 0 || first >= n || second < 0 || second >= m)                   continue;                 int nd = r == k ? l + 1 : 1;                 Min(dp[1 - now][second][r][nd], w);               }             }         }       }       now = 1 - now;     }     long long ans = INF;     for (int i = 0; i < 2; i++)       for (int j = 0; j < max(n, m) + 1; j++) Min(ans, dp[1 - now][m - 1][i][j]);     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int Q = 100100, rt = 223, inf = 1 << 29;   int ans[Q], todo[Q];   pair<int, int> look[Q];   int a[Q], b[Q];   string s;   unordered_map<int, unordered_set<int>> post;   map<pair<int, int>, int> ans2;   unordered_map<int, vector<int>> matches;   int f(int x, int xs, int y, int ys) { return max(x + xs, y + ys) - min(x, y); }   int S[100000][5];   map<string, int> intern;   int interned_size[500000];   int cnt = 1;   int get(const string& s) {     auto it = intern.find(s);     if (it == end(intern)) {       interned_size[cnt] = s.size();       return intern[s] = cnt++;     }     return it->second;   }   int brute(int a, int b) {     int res = inf;     vector<int>&ma = matches[a], &mb = matches[b];     for (int i = 0; i < ma.size(); ++i) {       int j = lower_bound(begin(mb), end(mb), ma[i]) - begin(mb);       if (j < mb.size())         res = min(res, f(ma[i], interned_size[a], mb[j], interned_size[b]));     }     return res;   }   int main() {     cin >> s;     for (int i = 0; i < s.size(); ++i) {       for (int w = 1; w <= 4; ++w) {         S[i][w] = get(s.substr(i, w));         matches[S[i][w]].push_back(i);       }     }     int q;     cin >> q;     fill(ans, ans + q, inf);     for (int i = 0; i < q; ++i) {       string as, bs;       cin >> as >> bs;       int a = get(as), b = get(bs);       if (max(matches[a].size(), matches[b].size()) < rt) {         ans[i] = min(brute(a, b), brute(b, a));       } else {         if (matches[a].size() < matches[b].size()) swap(a, b);         post[a].insert(b);         look[i] = make_pair(a, b);         todo[i] = 1;       }     }     for (auto& it : post) {       const int a = it.first;       auto& m = it.second;       int last = matches[a][0];       for (int i = last; i < s.size(); ++i) {         for (int w = 1; w <= 4; ++w)           if (S[i][w] == a) last = i;         for (int w = 1; w <= 4; ++w) {           int b = S[i][w];           if (m.find(b) == end(m)) continue;           auto st = make_pair(a, b);           int sol = f(last, interned_size[a], i, interned_size[b]);           auto fi = ans2.find(st);           if (fi == end(ans2) || sol < fi->second) ans2[st] = sol;         }       }       last = matches[a].back();       for (int i = last; i >= 0; --i) {         for (int w = 1; w <= 4; ++w)           if (S[i][w] == a) last = i;         for (int w = 1; w <= 4; ++w) {           int b = S[i][w];           if (m.find(b) == end(m)) continue;           auto st = make_pair(a, b);           int sol = f(last, interned_size[a], i, interned_size[b]);           auto fi = ans2.find(st);           if (fi == end(ans2) || sol < fi->second) ans2[st] = sol;         }       }     }     for (int i = 0; i < q; ++i) {       if (todo[i]) ans[i] = ans2.find(look[i]) != end(ans2) ? ans2[look[i]] : inf;       cout << (ans[i] == inf ? -1 : ans[i]) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 7E5 + 10;   const int BASE = 1E6 + 3;   int n, p;   long long f[MAX];   long long power(int x, int n) {     if (n == 0) return 1;     long long tmp = power(x, n / 2);     tmp = tmp * tmp;     if (n % 2) tmp = tmp * x;     tmp %= BASE;     return tmp;   }   long long C(int k, int n) {     return f[n] * power((f[n - k] * f[k]) % BASE, BASE - 2);   }   void init() {     f[0] = 1;     for (int i = 1; i < n + p; i++) f[i] = (f[i - 1] * i) % BASE;   }   int main() {     scanf( %d%d , &n, &p);     init();     long long res = 0;     for (int i = 1; i <= n; i++) res = (res + C(p - 1, i + p - 1)) % BASE;     printf( %I64d , res);   }


#include <bits/stdc++.h>   using namespace std;   long long int diff(long long int x, long long int y) {     if (x > y) {       return x - y;     } else {       return y - x;     }   }   int main() {     long long int n;     cin >> n;     long long int arr[n];     for (long long int i = 0; i < n; i++) {       cin >> arr[i];     }     long long int count = 0;     long long int ans = 0;     for (long long int i = 0; i < n; i++) {       if (arr[i] == 1) {         count++;         if (count > ans) {           ans = count;         }       } else {         count = 0;       }     }     if (count != 0) {       for (int i = 0; i < n; i++) {         if (arr[i] == 1) {           count++;           if (count > ans) {             ans = count;           }         } else {           break;         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<unsigned int> black[33], white[33];   unsigned int masks[33];   string parseipB(unsigned int x, int mask) {     string s =   ;     for (int i = 0; i < 4; ++i) {       for (int j = 0; j < 8; ++j) {         s += to_string(1 & x >> 8 * i + j);       }       if (i != 3) s +=  . ;     }     s +=  /  + to_string(mask);     return s;   }   string parseip(unsigned int x, int mask) {     string s =   ;     for (int i = 0; i < 4; ++i) {       int val = 0;       for (int j = 7; j >= 0; --j) {         val += (1 & x >> 8 * i + j) << 7 - j;       }       s += to_string(val);       if (i != 3) s +=  . ;     }     s +=  /  + to_string(mask);     return s;   }   int main() {     masks[0] = 0;     for (int i = 1; i < 33; ++i) {       masks[i] = masks[i - 1] | (1 << (i - 1));     }     int n;     scanf( %d n , &n);     bool hasblacks = false, haswhites = false;     for (int i = 0; i < n; ++i) {       char sign, sub;       int arr[4];       int mask;       scanf( %c%d.%d.%d.%d , &sign, &arr[0], &arr[1], &arr[2], &arr[3]);       scanf( %c , &sub);       if (sub ==  / ) {         scanf( %d n , &mask);       } else {         mask = 32;       }       unsigned int val = 0;       for (int j = 0; j < 4; ++j) {         unsigned int oct = 0;         for (int k = 7; k >= 0; --k) {           oct += (1 & arr[j] >> 7 - k) << k;         }         val += (oct << (8 * j));       }       if (sign ==  - ) {         hasblacks = true;         black[mask].insert(val);       } else {         haswhites = true;         white[mask].insert(val);       }     }     if (hasblacks && !haswhites) {       cout <<  1 n0.0.0.0/0 n ;       return 0;     }     if (!hasblacks && haswhites) {       cout <<  0 n ;       return 0;     }     bool ok = true;     for (int i = 32; i >= 0; --i) {       for (unsigned int x : white[i]) {         for (int j = 32; j >= 0; --j) {           if (black[j].count(masks[j] & x) != 0) {             ok = false;             break;           }         }       }       for (unsigned int x : black[i]) {         for (int j = 32; j >= 0; --j) {           if (white[j].count(masks[j] & x) != 0) {             ok = false;             break;           }         }       }     }     if (!ok) {       cout <<  -1 n ;       return 0;     }     vector<pair<unsigned int, unsigned int> > ans;     for (int i = 32; i > 0; --i) {       for (unsigned int x : white[i]) {         white[i - 1].insert(masks[i - 1] & x);       }       for (unsigned int x : black[i]) {         bool shift = white[i].count(x ^ (1 << i - 1)) == 0;         if (shift) {           black[i - 1].insert(masks[i - 1] & x);         } else {           ans.push_back(pair<unsigned int, unsigned int>(x, i));         }       }     }     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); ++i) {       unsigned int val = ans[i].first;       int mask = ans[i].second;       cout << parseip(val, mask) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int sz = 1e6 + 9;   int n, m, k;   long long tr[sz], tr_sum, tr_cnt;   long long ret[sz], ret_sum, ret_cnt;   int d, first, t, c;   vector<pair<pair<int, int>, pair<int, int>>> v;   vector<pair<long long, long long>> home;   long long home_ans[sz];   long long ans = 1e18;   int days[sz];   int main() {     cin >> n >> m >> k;     for (int i = 0; i < m; ++i) {       cin >> d >> first >> t >> c;       v.push_back(make_pair(make_pair(d, first), make_pair(t, c)));     }     sort(v.begin(), v.end());     for (int i = v.size() - 1; i >= 0; i--) {       d = v[i].first.first;       first = v[i].first.second;       t = v[i].second.first;       c = v[i].second.second;       if (first) continue;       if (!ret[t]) {         ret[t] = c;         ret_sum += c;         ret_cnt++;       } else if (ret[t] > c) {         ret_sum -= ret[t];         ret[t] = c;         ret_sum += c;       }       if (ret_cnt == n) home.push_back(make_pair(d, ret_sum));     }     sort(home.begin(), home.end());     int tmp = 0;     for (auto u : home) days[tmp++] = u.first;     for (int i = home.size() - 1; i >= 0; i--) {       if (i == home.size() - 1)         home_ans[i] = home[i].second;       else         home_ans[i] = min(home_ans[i + 1], home[i].second);     }     for (int i = 0; i < v.size(); ++i) {       d = v[i].first.first;       first = v[i].first.second;       t = v[i].second.first;       c = v[i].second.second;       if (t) continue;       if (!tr[first]) {         tr[first] = c;         tr_sum += c;         tr_cnt++;       } else if (tr[first] > c) {         tr_sum -= tr[first];         tr[first] = c;         tr_sum += c;       }       if (tr_cnt == n) {         int pos = lower_bound(days, days + home.size(), d + 1 + k) - days;         if (pos >= home.size()) continue;         ans = min(ans, tr_sum + home_ans[pos]);       }     }     if (ans == 1e18)       cout << -1;     else       cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[2005];   int vi[2005];   void dfs(int cu) {     int j, l = v[cu].size();     vi[cu] = 1;     for (j = 0; j < l; j++) {       if (!vi[v[cu][j]]) dfs(v[cu][j]);     }   }   int main() {     int n, m, k, cn = 0, i, j;     scanf( %d%d , &n, &m);     scanf( %d , &k);     long long an = 1;     for (i = 1; i + k - 1 <= n; i++) {       for (j = i; j < i + k / 2; j++) {         v[j].push_back(2 * i + k - 1 - j);         v[2 * i + k - 1 - j].push_back(j);       }     }     for (i = 1; i < n + 1; i++) {       if (!vi[i]) dfs(i), cn++;     }     for (i = 0; i < cn; i++) an = (an * m) % 1000000007LL;     printf( %lld , an);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   vector<pair<int, int> > L, R;   int whereL[30013], whereR[30013];   long long cost[30013][2];   long long dp[30013];   const long long INF = -3.1e16;   inline long long match(int a, int b) {     if (a <= 0 || b <= 0 || a > n || b > n) return INF;     return (long long)L[a].first * R[b].first;   }   inline void update(int i) {     if (i <= 0 || i > n) return;     cost[i][0] = match(i, i + 1) + match(i + 1, i);     cost[i][1] = max(match(i, i + 1) + match(i + 1, i + 2) + match(i + 2, i),                      match(i, i + 2) + match(i + 1, i) + match(i + 2, i + 1));   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 0; i <= n; i++) {       L.push_back(make_pair(0, i));       R.push_back(make_pair(0, i));     }     for (int i = 1; i <= n; i++) scanf( %d , &L[i].first);     for (int i = 1; i <= n; i++) scanf( %d , &R[i].first);     sort(L.begin(), L.end());     sort(R.begin(), R.end());     for (int i = 1; i <= n; i++) {       whereL[L[i].second] = i;       whereR[R[i].second] = i;     }     for (int i = 1; i <= n; i++) update(i);     for (int Q = 0; Q < q; Q++) {       int a, b;       scanf( %d%d , &a, &b);       swap(R[whereR[a]].second, R[whereR[b]].second);       swap(whereR[a], whereR[b]);       for (int i = -2; i <= 0; i++) {         update(whereL[a] + i);         update(whereR[a] + i);         update(whereL[b] + i);         update(whereR[b] + i);       }       dp[n + 1] = 0;       for (int i = n; i; i--) {         dp[i] = max(dp[i + 2] + cost[i][0], dp[i + 3] + cost[i][1]);         if (L[i].second != R[i].second)           dp[i] = max(dp[i], (long long)L[i].first * R[i].first + dp[i + 1]);       }       printf( %I64d n , dp[1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5e6 + 10;   const int MAX = 1e5 + 10;   const double eps = 1e-6;   priority_queue<int> q, Q;   long long s[MAX];   int main() {     long long n, k;     cin >> n >> k;     int cnt = 0;     while (n > 0) {       long long b = 1;       int a = 0;       while (b * 2 <= n) b *= 2, a++;       cnt++;       q.push(a);       Q.push(a);       n -= b;     }     if (cnt > k) {       cout <<  No  << endl;       return 0;     }     int temp = cnt;     while (temp < k) {       int a = Q.top();       Q.pop();       a--;       Q.push(a);       Q.push(a);       temp++;     }     temp = Q.top();     while (cnt < k) {       int a = q.top();       if (temp == a) break;       q.pop();       a--;       q.push(a);       q.push(a);       cnt++;     }     temp = 0;     while (q.size()) {       s[temp++] = q.top();       q.pop();     }     while (cnt < k) {       s[cnt - 1] = s[cnt - 1] - 1;       s[cnt] = s[cnt - 1];       cnt++;     }     cout <<  Yes  << endl;     for (int i = 0; i < cnt; i++) {       if (i == 0)         cout << s[i];       else         cout <<     << s[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   int a, b, c, d, i, j, n, m, k;   int cnt[6];   map<string, int> q;   const int di[] = {0, 1, -1, 2, -2, 3, -3, 4, -4};   const char *name[] = { S ,  M ,  L ,  XL ,  XXL };   int main() {     for (int _n((5) - 1), i(0); i <= _n; i++) scanf( %d , &cnt[i]);     q[ S ] = 0;     q[ M ] = 1;     q[ L ] = 2;     q[ XL ] = 3;     q[ XXL ] = 4;     scanf( %d , &n);     for (int _n((n)-1), i(0); i <= _n; i++) {       string s;       cin >> s;       a = q[s];       for (int _n((9) - 1), j(0); j <= _n; j++) {         if (a + di[j] >= 0 && a + di[j] < 5 && cnt[a + di[j]]) {           printf( %s n , name[a + di[j]]);           --cnt[a + di[j]];           break;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7, MAXN = 1e5 + 10;   int n, l, r, a[MAXN], b[MAXN];   vector<int> aa, bb;   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> l >> r;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       if (l <= i && i <= r) aa.push_back(a[i]);     }     for (int i = 1; i <= n; ++i) {       cin >> b[i];       if (l <= i && i <= r) bb.push_back(b[i]);     }     for (int i = 1; i < l; ++i)       if (a[i] != b[i]) {         cout <<  LIE ;         return 0;       }     for (int i = r + 1; i <= n; ++i)       if (a[i] != b[i]) {         cout <<  LIE ;         return 0;       }     sort(aa.begin(), aa.end());     sort(bb.begin(), bb.end());     if (aa == bb)       cout <<  TRUTH ;     else       cout <<  LIE ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 200000 + 10;   const int ALPHA = 30;   const int NUM = 12;   int T;   char a[MAX];   struct Node {     Node *ch[ALPHA], *p;     int cc[NUM];     int len;     Node() {       memset(ch, 0, sizeof ch);       p = 0;       len = 0;       memset(cc, 0, sizeof cc);     }   }* Root = new Node;   int L[NUM], R[NUM];   vector<Node*> all;   int cmp(Node* a, Node* b) { return a->len < b->len; }   void add(Node* v, int id, int len) {     if (v->ch[id] && v->ch[id]->len == len) return;     Node* u = new Node;     all.push_back(u);     u->len = len;     for (; v && !v->ch[id]; v = v->p) v->ch[id] = u;     if (!v)       u->p = Root;     else {       Node* nu = v->ch[id];       if (nu->len == v->len + 1)         u->p = nu;       else {         Node* nnu = new Node;         all.push_back(nnu);         *nnu = *nu;         memset(nnu->cc, 0, sizeof nnu->cc);         u->p = nnu;         nu->p = nnu;         nnu->len = v->len + 1;         for (; v && v->ch[id] == nu; v = v->p) v->ch[id] = nnu;       }     }     return;   }   void init(char* a, int n, int l, int r, int lab) {     L[lab] = l;     R[lab] = r;     int i;     Node* now = Root;     for ((i) = (1); (i) <= (n); ++(i)) {       int id = a[i] -  a ;       add(now, id, i);       now = now->ch[id];       ++now->cc[lab];     }   }   int main() {     int i, first, second;     scanf( %s , a + 1);     init(a, strlen(a + 1), 1, strlen(a + 1), 0);     scanf( %d , &T);     for ((i) = (1); (i) <= (T); ++(i)) {       scanf( %s%d%d , a + 1, &first, &second);       init(a, strlen(a + 1), first, second, i);     }     int j;     long long ans = 0;     sort(all.begin(), all.end(), cmp);     for (i = (int)all.size() - 1; i >= 0; --i) {       int flag = 1;       for ((j) = (0); (j) <= (T); ++(j)) {         all[i]->p->cc[j] += all[i]->cc[j];         flag = flag && (all[i]->cc[j] <= R[j] && all[i]->cc[j] >= L[j]);       }       if (flag) ans += all[i]->len - all[i]->p->len;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dp[1000006][2];   long long pre[1000006][2];   void chkMinLog(long long& goal, long long t1, bool t2, bool curr) {     if (dp[t1][t2] > goal) {       dp[t1][t2] = goal;       pre[t1][t2] = curr;     }   }   void solve() {     long long n;     cin >> n;     vector<long long> a(n + 2);     for (long long i = (1); i <= (n); i++) cin >> a[i];     for (long long i = (1); i <= (n); i++)       for (long long j = (0); j <= (1); j++) dp[i][j] = 1e18;     a[0] = n + 1;     dp[0][0] = dp[0][1] = -n - 1;     for (long long i = (0); i <= (n - 1); i++)       for (long long isPos = (0); isPos <= (1); isPos++) {         long long sv = (isPos ? 1 : -1) * a[i], v = dp[i][isPos];         if (-a[i + 1] > v) chkMinLog(sv, i + 1, false, isPos);         if (a[i + 1] > v) chkMinLog(sv, i + 1, true, isPos);         if (-a[i + 1] > sv) chkMinLog(v, i + 1, false, isPos);         if (a[i + 1] > sv) chkMinLog(v, i + 1, true, isPos);       }     if (dp[n][0] <= n || dp[n][1] <= n) {       cout <<  YES  << endl;       long long ti = n, ts = 0;       if (dp[n][1] <= n) ts = 1;       while (ti >= 1) {         if (ts == 0) a[ti] = -a[ti];         ts = pre[ti][ts], ti--;       }       for (long long i = (1); i <= (n); i++) cout << a[i] <<    ;       cout << endl;     } else {       cout <<  NO  << endl;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long T = 1;     cin >> T;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 0x3f3f3f3f;   const int N = 5e5 + 10;   int a[8008];   int n, ans = 0;   string s, ss, sss;   map<string, int> mp;   void str() {     cin >> ss;     int sum = 0;     string x =   ;     for (int i = 0; i < ss.length(); i++) {       if (ss[i] ==  & )         sum--;       else if (ss[i] ==  * )         sum++;       else         x += ss[i];     }     ans = mp[x];     if (ans > 0)       ans += sum;     else       ans = 0;   }   int main() {     mp[ void ] = 1;     cin >> n;     while (n--) {       cin >> s;       ans = 0;       if (s ==  typedef ) {         str();         cin >> sss;         mp[sss] = ans;       } else {         str();         ans--;         if (ans < 0)           cout <<  errtype  << endl;         else {           cout <<  void ;           for (int i = 0; i < ans; i++) cout <<  * ;           cout << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200000;   pair<int, bool> p[N * 2];   pair<int, int> t[N];   int main() {     int n;     scanf( %d , &n);     int l, r;     for (int i = 0; i < n; ++i) {       scanf( %d%d , &l, &r);       t[i] = make_pair(l, r);       p[i * 2].first = l;       p[i * 2].second = false;       p[i * 2 + 1].first = r + 1;       p[i * 2 + 1].second = true;     }     sort(p, p + n * 2);     int current = 0;     vector<int> v;     for (int i = 0; i < n * 2; ++i) {       if (!p[i].second)         ++current;       else         --current;       if ((i == n * 2 - 1 || p[i + 1].first != p[i].first) && current == 1)         v.push_back(p[i].first);     }     for (int i = 0; i < n; ++i) {       int it = lower_bound(v.begin(), v.end(), t[i].first) - v.begin();       if (it == v.size() || (v[it] > t[i].second)) {         printf( %d n , i + 1);         return 0;       }     }     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, L, a[1005], b[1005], ans[1005], cc;   double dp[1005], dis[1005][1005];   int pre[1005];   inline bool check(double K) {     dp[0] = 0;     for (int i = 1; i <= n; ++i) {       dp[i] = -1e9;       for (int j = 0; j < i; ++j) {         double v = dp[j] + K * b[i] - dis[j][i];         if (v > dp[i]) dp[i] = v, pre[i] = j;       }     }     return dp[n] >= 0;   }   void output(int x) {     if (!x) return;     output(pre[x]);     printf( %d  , x);   }   int main() {     scanf( %d%d , &n, &L);     for (int i = 1; i <= n; ++i) scanf( %d%d , a + i, b + i);     for (int i = 0; i <= n; ++i)       for (int j = i + 1; j <= n; ++j) dis[i][j] = sqrt(abs(a[j] - a[i] - L));     double l = 0, r = 1e9, mid;     while (l + 1e-8 <= r) {       mid = (l + r) / 2;       if (check(mid))         r = mid;       else         l = mid;     }     check(r);     output(n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> o, p, e;   int n, i, j, x;   int a[200000], b[200000];   struct T {     int i;   } t;   bool operator<(T t1, T t2) {     if ((t2.i - x - a[b[t2.i]] + 2 * n) % n !=         (t1.i - x - a[b[t1.i]] + 2 * n) % n)       return (t2.i - x - a[b[t2.i]] + 2 * n) % n <              (t1.i - x - a[b[t1.i]] + 2 * n) % n;     return t1.i < t2.i;   }   priority_queue<T> qp;   set<T> qo;   set<T>::iterator it;   int main() {     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &x);       a[x - 1] = i;     }     for (i = 0; i < n; i++) {       scanf( %d , &b[i]);       b[i]--;     }     x = 0;     for (i = 0; i < n; i++)       if (a[b[i]] < i) {         t.i = i;         qp.push(t);       } else if (a[b[i]] > i) {         t.i = i;         qo.insert(t);       } else         e.push_back(i);     for (i = 0; i < n; i++) {       x = 1999999999;       if (e.size())         printf( 0 n );       else {         if (qp.size()) {           t = qp.top();           x = min(x, (t.i - i + n) % n - a[b[t.i]]);         }         if (qo.size()) {           it = qo.begin();           j = it->i;           x = min(x, a[b[j]] - (j - i + n) % n);         }         printf( %d n , x);       }       x = i + 1;       for (j = 0; j < e.size(); j++) {         if (e[j] != i) {           t.i = e[j];           qo.insert(t);         } else {           t.i = e[j];           qp.push(t);         }       }       e.clear();       while (!qp.empty()) {         t = qp.top();         if ((t.i - i - 1 + n) % n == a[b[t.i]]) {           e.push_back(t.i);           qp.pop();         } else           break;       }       t.i = i;       it = qo.find(t);       if (it != qo.end()) {         qo.erase(t);         if (a[b[i]] == n - 1)           e.push_back(i);         else {           t.i = i;           qp.push(t);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int l, r;     cin >> l >> r;     for (int i = l; i < r + 1; i++) {       vector<int> cnts(10);       int x = i;       while (x > 0) {         cnts[x % 10]++;         x /= 10;       }       bool good = true;       for (int j = 0; j < 10; j++) {         if (cnts[j] > 1) {           good = false;         }       }       if (good) {         cout << i << endl;         return 0;       }     }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void file() {}   void fast() {     std::ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);   }   long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }   int dx[] = {-1, 0, 0, 1, 1, 1, -1, -1};   int dy[] = {0, 1, -1, 0, 1, -1, 1, -1};   int n, m, mem[100005][26];   string s;   bool a[26][26];   int solve(int i, int last) {     if (i == n) return 0;     int &ret = mem[i][last];     if (~ret) return ret;     if (a[s[i] -  a ][last]) return ret = 1 + solve(i + 1, last);     return ret = min(solve(i + 1, s[i] -  a ), 1 + solve(i + 1, last));   }   int main() {     file();     fast();     cin >> s;     n = s.size();     cin >> m;     while (m--) {       char c1, c2;       cin >> c1 >> c2;       a[c1 -  a ][c2 -  a ] = a[c2 -  a ][c1 -  a ] = 1;     }     memset(mem, -1, sizeof mem);     int mn = 1e9;     for (int i = 0; i < n; i++) mn = min(mn, i + solve(i, s[i] -  a ));     cout << mn;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     register int x = 0, f = 1;     register char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = 0;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + (ch ^  0 );       ch = getchar();     }     return f ? x : -x;   }   int n, m, yt, Y[200005];   struct subway {     int x, y;   } sbw[100005];   struct rabbit {     int x, y, dis;   } rbt[100005];   struct BIT {     int tr[200005];     void modify(int x, int v) {       for (; x <= yt; x += x & -x) tr[x] = max(tr[x], v);     }     int query(int x) {       int ans = -1000000000;       for (; x; x -= x & -x) ans = max(ans, tr[x]);       return ans;     }   } bit;   struct node {     int x, y, id;   } q[200005];   void work() {     memset(bit.tr, -0x3f, sizeof bit.tr);     yt = 0;     for (int i = (1), _ed_ = (n); i <= _ed_; ++i) {       Y[++yt] = rbt[i].y;     }     for (int i = (1), _ed_ = (m); i <= _ed_; ++i) {       Y[++yt] = sbw[i].y;     }     sort(Y + 1, Y + yt + 1), yt = unique(Y + 1, Y + yt + 1) - Y - 1;     for (int i = (1), _ed_ = (n); i <= _ed_; ++i)       q[i] = (node){rbt[i].x, rbt[i].y, i};     for (int i = (1), _ed_ = (m); i <= _ed_; ++i)       q[n + i] = (node){sbw[i].x, sbw[i].y, n + i};     sort(q + 1, q + n + m + 1,          [&](node a, node b) { return a.x == b.x ? a.id > b.id : a.x < b.x; });     for (int i = (1), _ed_ = (n + m); i <= _ed_; ++i) {       if (q[i].id > n)         bit.modify(lower_bound(Y + 1, Y + yt + 1, q[i].y) - Y, q[i].x + q[i].y);       else         rbt[q[i].id].dis =             min(rbt[q[i].id].dis,                 q[i].x + q[i].y -                     bit.query(lower_bound(Y + 1, Y + yt + 1, q[i].y) - Y));     }   }   int rt[100005], tcnt, tr[6000005], ls[6000005], rs[6000005];   void pushup(int p) { tr[p] = tr[ls[p]] + tr[rs[p]]; }   void insert(int& x, int y, int l, int r, int pos) {     x = ++tcnt;     tr[x] = tr[y], ls[x] = ls[y], rs[x] = rs[y];     if (l == r) return ++tr[x], void();     int mid = (l + r) >> 1;     if (pos <= mid)       insert(ls[x], ls[y], l, mid, pos);     else       insert(rs[x], rs[y], mid + 1, r, pos);     pushup(x);   }   int query(int x, int y, int l, int r, int L, int R) {     if (L > R || x == y) return 0;     if (L <= l && r <= R) return tr[x] - tr[y];     int mid = (l + r) >> 1, ans = 0;     if (L <= mid) ans += query(ls[x], ls[y], l, mid, L, R);     if (ans) return ans;     if (mid < R) ans += query(rs[x], rs[y], mid + 1, r, L, R);     return ans;   }   int lower(int x) {     int l = 1, r = m, ans = r + 1;     while (l <= r) {       int mid = (l + r) >> 1;       if (sbw[mid].x >= x)         ans = mid, r = mid - 1;       else         l = mid + 1;     }     return ans;   }   int upper(int x) {     int l = 1, r = m, ans = r + 1;     while (l <= r) {       int mid = (l + r) >> 1;       if (sbw[mid].x > x)         ans = mid, r = mid - 1;       else         l = mid + 1;     }     return ans - 1;   }   int query(int x, int y) {     int l = 0, r = 1000000000, ans, L, R, D, U;     while (l <= r) {       int mid = (l + r) >> 1;       L = lower(x - mid), R = upper(x + mid),       D = lower_bound(Y + 1, Y + yt + 1, y - mid) - Y,       U = upper_bound(Y + 1, Y + yt + 1, y + mid) - Y - 1;       if (L <= R && query(rt[R], rt[L - 1], 1, yt, D, U))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     return ans;   }   struct square {     int x1, y1, x2, y2;     square(int x1 = 0, int y1 = 0, int x2 = 0, int y2 = 0)         : x1(x1), y1(y1), x2(x2), y2(y2) {}     void merge(square o) {       x1 = max(x1, o.x1), y1 = max(y1, o.y1);       x2 = min(x2, o.x2), y2 = min(y2, o.y2);     }     bool valid() {       if (x1 == x2 && y1 == y2 && (x1 + y1) & 1) return 0;       return x1 <= x2 && y1 <= y2;     }   };   bool check(int tim) {     int p = n;     while (p && rbt[p].dis > tim) --p;     square nw(-1000000000, -1000000000, 1000000000, 1000000000);     for (int i = (n), _ed_ = (p + 1); i >= _ed_; --i)       nw.merge(           square(rbt[i].x - tim, rbt[i].y - tim, rbt[i].x + tim, rbt[i].y + tim));     int L, R, D, U;     while (p && nw.valid()) {       int t = tim - rbt[p].dis, x1 = nw.x1, y1 = nw.y1, x2 = nw.x2, y2 = nw.y2;       if (x1 == x2) {         if ((x1 + y1) & 1) ++y1;         if ((x2 + y2) & 1) --y2;       } else if (y1 == y2) {         if ((x1 + y1) & 1) ++x1;         if ((x2 + y2) & 1) --x2;       }       if (x1 <= x2 && y1 <= y2) {         L = lower(x1 - t), R = upper(x2 + t),         D = lower_bound(Y + 1, Y + yt + 1, y1 - t) - Y,         U = upper_bound(Y + 1, Y + yt + 1, y2 + t) - Y - 1;         if (L <= R && query(rt[R], rt[L - 1], 1, yt, D, U)) return 1;       }       nw.merge(           square(rbt[p].x - tim, rbt[p].y - tim, rbt[p].x + tim, rbt[p].y + tim));       --p;     }     if (nw.valid()) return 1;     return 0;   }   int main() {     n = read(), m = read();     for (int i = (1), _ed_ = (n); i <= _ed_; ++i)       rbt[i] = (rabbit){read(), read(), 1000000000};     for (int i = (1), _ed_ = (m); i <= _ed_; ++i)       sbw[i] = (subway){read(), read()};     for (int i = (1), _ed_ = (n); i <= _ed_; ++i) {       rbt[i].x *= -1;     }     for (int i = (1), _ed_ = (m); i <= _ed_; ++i) {       sbw[i].x *= -1;     }     work();     for (int i = (1), _ed_ = (n); i <= _ed_; ++i) {       rbt[i].y *= -1;     }     for (int i = (1), _ed_ = (m); i <= _ed_; ++i) {       sbw[i].y *= -1;     }     work();     for (int i = (1), _ed_ = (n); i <= _ed_; ++i) {       rbt[i].x *= -1;     }     for (int i = (1), _ed_ = (m); i <= _ed_; ++i) {       sbw[i].x *= -1;     }     work();     for (int i = (1), _ed_ = (n); i <= _ed_; ++i) {       rbt[i].y *= -1;     }     for (int i = (1), _ed_ = (m); i <= _ed_; ++i) {       sbw[i].y *= -1;     }     work();     for (int i = (1), _ed_ = (n); i <= _ed_; ++i) {       int x = rbt[i].x, y = rbt[i].y;       rbt[i].x = x + y, rbt[i].y = x - y;     }     for (int i = (1), _ed_ = (m); i <= _ed_; ++i) {       int x = sbw[i].x, y = sbw[i].y;       sbw[i].x = x + y, sbw[i].y = x - y;     }     sort(sbw + 1, sbw + m + 1,          [&](subway a, subway b) { return a.x == b.x ? a.y < b.y : a.x < b.x; });     yt = 0;     for (int i = (1), _ed_ = (m); i <= _ed_; ++i) Y[++yt] = sbw[i].y;     sort(Y + 1, Y + yt + 1), yt = unique(Y + 1, Y + yt + 1) - Y - 1;     for (int i = (1), _ed_ = (m); i <= _ed_; ++i)       insert(rt[i], rt[i - 1], 1, yt,              lower_bound(Y + 1, Y + yt + 1, sbw[i].y) - Y);     sort(rbt + 1, rbt + n + 1, [&](rabbit a, rabbit b) { return a.dis < b.dis; });     int l = 0, r = rbt[n].dis, ans;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 100005;   int A[NMAX];   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     bool ok = true;     if (n % 2 == 1) {       if ((n - 1) % 4 == 0) {         for (int i = 1; i <= n / 2; i += 2) {           A[i] = i + 1;           A[i + 1] = n - i + 1;           A[n - i + 1] = n - i;           A[n - i] = i;         }         A[n / 2 + 1] = n / 2 + 1;       } else {         ok = false;       }     } else {       if (n % 4 == 0) {         for (int i = 1; i <= n / 2; i += 2) {           A[i] = i + 1;           A[i + 1] = n - i + 1;           A[n - i + 1] = n - i;           A[n - i] = i;         }       } else {         ok = false;       }     }     if (!ok) {       cout <<  -1 n ;     } else {       for (int i = 1; i <= n; ++i) {         cout << A[i] <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class S, class T>   pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {     return pair<S, T>(s.first + t.first, s.second + t.second);   }   template <class S, class T>   pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {     return pair<S, T>(s.first - t.first, s.second - t.second);   }   template <class S, class T>   ostream &operator<<(ostream &os, pair<S, T> p) {     os <<  (  << p.first <<  ,   << p.second <<  ) ;     return os;   }   template <class T>   bool chmax(T &a, const T &b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool chmin(T &a, const T &b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   const long long inf = 1000000001;   const long long INF = 2e18;   const long long MOD = 1000000007;   const double pi = 3.14159265358979323846;   int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};   int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};   vector<vector<int> > child(5010), parent(5010);   vector<int> color(5010, -1);   int n, m, s;   vector<int> roots, roots2;   void dfs1(int now, int col) {     color[now] = col;     for (long long i = 0; i < (long long)(child[now].size()); i++) {       if (color[child[now][i]] < 0) {         dfs1(child[now][i], col);       }     }   }   void dfs2(int now) {     color[now] = -2;     if (parent[now].size() == 0) {       roots.push_back(now);       return;     }     bool flag = true;     for (long long i = 0; i < (long long)(parent[now].size()); i++) {       if (color[parent[now][i]] == -1) {         dfs2(parent[now][i]);         flag = false;       }     }     if (flag) {       roots2.push_back(now);     }     return;   }   int main() {     cin >> n >> m >> s;     s--;     for (long long i = 0; i < (long long)(m); i++) {       int u, v;       cin >> u >> v;       u--;       v--;       child[u].push_back(v);       parent[v].push_back(u);     }     dfs1(s, s);     int ans = 0;     for (long long i = 0; i < (long long)(n); i++) {       if (color[i] >= 0) {         continue;       }       roots.clear();       dfs2(i);       ans += roots.size();       for (long long j = 0; j < (long long)(roots.size()); j++) {         dfs1(roots[j], roots[j]);       }     }     for (long long i = 0; i < (long long)(roots2.size()); i++) {       if (color[roots2[i]] < 0) {         ans++;         dfs1(roots2[i], roots2[i]);       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   deque<int> d;   string mot;   int n;   void f(int i) {     if (i == n)       return;     else {       f(i + 1);       if (mot[i] ==  l ) {         d.push_back(i + 1);       } else {         d.push_front(i + 1);       }     }   }   int main() {     cin >> mot;     n = mot.size();     f(0);     for (int i = 0; i < n; i++) cout << d[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     printf( INTERCAL n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int neg = 1, num = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) neg = -1;     for (; isdigit(c); c = getchar()) num = (num << 1) + (num << 3) + c -  0 ;     return neg * num;   }   int n, a, b;   char s[300010];   int main() {     n = read();     a = read();     b = read();     scanf( %s , s + 1);     int las = 0, sum = 0;     s[n + 1] =  * ;     for (int i = 1; i <= n + 1; i++)       if (s[i] ==  * ) {         int x = (i - las - 1) / 2, y = i - las - 1 - x;         if (a > b) swap(a, b);         sum += min(a, x) + min(b, y);         a = max(0, a - x);         b = max(0, b - y);         las = i;       }     printf( %d , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int num1 = 0;   string s1, s2;   int counter = 0;   int ques = 0;   int main() {     cin >> s1 >> s2;     int num2 = 0;     for (int i = 0; i < s1.length(); i++)       if (s1[i] ==  + )         num1++;       else         num1--;     for (int i = 0; i < s2.length(); i++)       if (s2[i] ==  + )         num2++;       else if (s2[i] ==  - )         num2--;       else         ques++;     float num = 0;     int limit = (1 << ques);     for (int i = 0; i < limit; i++) {       int sum = num2;       for (int j = 0; j < ques; j++) {         if ((1 << j) & i)           sum++;         else           sum--;       }       if (sum == num1) counter++;     }     if (ques != 0) {       num = (float)counter / (1 << ques);     } else if (num2 == num1)       num = 1;     printf( %0.12f n , num);   }


#include <bits/stdc++.h>   using namespace std;   char s[111][3];   int main() {     char t[3];     scanf( %s , t);     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %s , s[i]);     }     for (int i = 0; i < n; i++) {       if (t[0] == s[i][0] && t[1] == s[i][1]) {         puts( YES );         return 0;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (t[0] == s[i][1] && t[1] == s[j][0]) {           puts( YES );           return 0;         }       }     }     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct hash {     int head[8592637], next[8592637], t;     unsigned long long lk[8592637];     double x[8592637];     double find(unsigned long long s) {       for (int i = head[s % 8592637]; i; i = next[i])         if (lk[i] == s) return x[i];       return -1;     }     void ins(unsigned long long s, double f) {       if (find(s) > -1) return;       lk[++t] = s, x[t] = f, next[t] = head[s % 8592637], head[s % 8592637] = t;     }   } H;   int N, a[105], F[256], b[105];   inline int G(int x) { return !!x; }   inline void get(int x, int* a) {     a[0] = (x >> 4) & 3, a[1] = (x >> 2) & 3, a[2] = x & 3;   }   inline int BG(int a, int b, int c) {     if (a > c) swap(a, c);     return (((a << 2) + b) << 2) + c;   }   void init() {     scanf( %d , &N), F[ G ] = 1, F[ B ] = 2, F[ R ] = 3;     char s[4];     for (int i = 1; i <= N; i++)       scanf( %s , s), a[i] = BG(F[s[0]], F[s[1]], F[s[2]]);   }   unsigned long long Hash(int n) {     unsigned long long s = 0;     for (int i = 1; i <= n; i++) b[i] = a[i];     sort(b + 1, b + n);     for (int i = 1; i <= n; i++) (s *= 31415927) += b[i];     return s;   }   double dfs(int n) {     unsigned long long s = Hash(n);     double f = H.find(s), c[4] = {0, 1e9, 1e9, 1e9};     if (f > -1) return f;     for (int i = 1; i < n; i++) {       int x[3], y[3], nn = n, ai = a[i], an = a[n];       get(ai, x), get(an, y);       if (G(x[0]) + G(x[1]) + G(x[2]) == 1) continue;       if (y[0] && y[1] && y[2]) nn++, y[0] = y[1] = y[2] = 0;       for (int j = 0; j < 3; j++)         if (x[j]) {           int t = x[j];           if (G(x[0]) + G(x[1]) + G(x[2]) == 2 && j == 1) continue;           if (G(x[0]) + G(x[1]) + G(x[2]) == 2 && !x[1]) break;           x[j] = 0, a[i] = BG(x[0], x[1], x[2]);           if (G(x[0]) + G(x[1]) + G(x[2]) == 1 || !x[1]) a[i] = 0;           x[j] = t;           for (int k = 0; k < 3; k++)             if (!y[k])               y[k] = t, a[nn] = BG(y[0], y[1], y[2]), y[k] = 0,               c[t] = min(c[t], dfs(nn));         }       a[i] = ai, a[n] = an;     }     if (c[1] == 1e9 && c[2] == 1e9 && c[3] == 1e9) return H.ins(s, 0), 0;     double t = 1.0 / 6;     if (c[1] == 1e9) t += 1.0 / 3, c[1] = 0;     if (c[2] == 1e9) t += 1.0 / 3, c[2] = 0;     if (c[3] == 1e9) t += 1.0 / 6, c[3] = 0;     f = (c[1] / 3 + c[2] / 3 + c[3] / 6 + 1) / (1 - t), H.ins(s, f);     return f;   }   int main() {     init();     printf( %.6lf n , dfs(N));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, k;   int a[N];   void solve(int l, int r) {     if (k <= 0) {       return;     }     if (l == r - 1) {       return;     }     int mid = (l + r) / 2;     swap(a[mid - 1], a[mid]);     --k;     --k;     solve(l, mid);     solve(mid, r);   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) a[i] = i + 1;     if (k % 2 == 0) {       puts( -1 );       return 0;     }     if (k > ((n)*2 - 1)) {       puts( -1 );       exit(0);     }     --k;     solve(0, n);     for (int i = 0; i < n; i++) printf( %d  , a[i]);   }


#include <bits/stdc++.h>   using namespace std;   long long int scs(long long int a) {     long long int u = 0;     while (a) {       u++;       a /= 10;     }     return u;   }   long long int mul(long long int a, long long int b, long long int m) {     if (b == 1) return a % m;     if (b == 0) return 1 % m;     a %= m;     b %= m;     long long int q = mul(a, b / 2, m);     if (b % 2 == 0)       return (q + q) % m;     else       return (q + q + a) % m;   }   long long int mu(long long int a, long long int n, long long int m) {     if (n == 0) return 1 % m;     long long int q = mu(a, n / 2, m);     if (n % 2 == 0)       return mul(q, q, m);     else       return mul(mul(q, q, m), a, m);   }   long long int mu5[20];   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     long long int t;     cin >> t;     mu5[0] = 1;     for (int i = 1; i <= 19; i++) mu5[i] = mu5[i - 1] * 5;     for (int z = 1; z <= t; z++) {       long long int a;       cin >> a;       long long int n = scs(a);       long long int v = 0, m = 0;       for (int mmm = 0; mmm <= 6; mmm++) {         m = mmm;         long long int b = (-a) % (1LL << (m + n)) * mu5[m] % (1LL << (m + n)) *                           (1LL << m) % (1LL << (m + n));         b %= (1LL << (m + n));         if (b < 0) b += (1LL << (m + n));         bool q = 0;         while (b < mu5[m] * (1LL << m)) {           v = (b + mu5[m] * (1LL << m) * a) / (1LL << (m + n));           if (v % 5 != 0) {             q = 1;             break;           }           b += (1LL << (m + n));         }         if (q == 1) {           break;         }       }       v %= mu5[m + n];       long long int mm[4] = {1, 2, 4, 3};       long long int res = 0;       for (int i = 0; i <= 3; i++) {         if (mm[i] == v % 5) res = i;       }       for (int i = 2; i <= m + n; i++) {         long long int r = res;         for (int u = 0; u <= 4; u++) {           if (mu(2, r + u * 4 * mu5[i - 2], mu5[i]) == v % mu5[i]) {             res = r + u * 4 * mu5[i - 2];             break;           }         }       }       res += m + n;       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isPowerOfTwo(long long n) {     if (n == 0) return false;     return (ceil(log2(n)) == floor(log2(n)));   }   long long power(long long x, unsigned long long y) {     if (y == 0)       return 1;     else if (y % 2 == 0)       return power(x, y / 2) * power(x, y / 2);     else       return x * power(x, y / 2) * power(x, y / 2);   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   signed main() {     long long n;     cin >> n;     priority_queue<long long> a, b, c, d;     for (long long i = 0; i < n; i++) {       string s;       long long x;       cin >> s >> x;       if (s ==  11 ) a.push(x);       if (s ==  10 ) b.push(x);       if (s ==  01 ) c.push(x);       if (s ==  00 ) d.push(x);     }     long long ans = 0;     long long x = 0, y = 0, z = 0;     ;     while (!a.empty()) {       ans += a.top();       x++;       y++;       a.pop();       z++;     }     while (!b.empty() && !c.empty()) {       ans += b.top();       ans += c.top();       x++;       y++;       z += 2;       b.pop();       c.pop();     }     long long p = 2 * x - z;     if (b.empty() == true) {       while (!c.empty()) {         d.push(c.top());         c.pop();       }     } else {       while (!b.empty()) {         d.push(b.top());         b.pop();       }     }     while (p > 0 && !d.empty()) {       p--;       ans += d.top();       d.pop();     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxx = 1000 + 50;   long long DP[maxx];   int main() {     int n, m;     cin >> n >> m;     int t = abs(n - m);     DP[1] = 1;     DP[2] = 3;     for (int i = 3; i <= 1000; i++) DP[i] = DP[i - 1] + i;     int ans = 0;     ans = 2 * DP[(t / 2)];     if (t % 2 == 1) ans += (t / 2) + 1;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f, maxn = 10;   int Pow(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = (long long)ans * a % 1000000007;       a = (long long)a * a % 1000000007;       b >>= 1;     }     return ans;   }   int main() {     int n, k;     while (~scanf( %d%d , &n, &k)) {       int ans = (long long)Pow(k, k - 1) * Pow(n - k, n - k) % 1000000007;       printf( %d n , ans);     }     return 0;   }