#include <bits/stdc++.h>   using namespace std;   const int BIG = 1000200;   char buf[BIG];   int skip0[BIG], skip1[BIG];   int vpre[BIG];   struct E {     int to;     char sign;     int pw;   };   vector<E> vg[BIG];   int main() {     while (scanf(  %s , buf) != EOF) {       string s(buf);       s =  00  + s;       int N = (int)((s).size());       int prev0 = 0, prev1 = 0;       memset((skip0), (-1), sizeof(skip0));       memset((skip1), (-1), sizeof(skip1));       for (int i = 0; i < (int)(N); ++i) {         skip0[i] = prev0;         skip1[i] = prev1;         if (s[i] ==  0 ) {           prev0 = i;         }         if (s[i] ==  1 ) {           prev1 = i;         }       }       for (int i = 0; i < (int)(BIG); ++i) vg[i].clear();       for (int i = 0; i < (int)(N); ++i) {         if (i == 0) continue;         vg[i].push_back((E){skip1[i],  + , N - 1 - i});         vg[i].push_back((E){skip0[i],  - , N - 1 - i});       }       int start = -1;       for (int i = 0; i < (int)(N); ++i)         if (s[N - 1 - i] ==  1 ) {           start = N - 1 - i;           break;         }       assert(start >= 0);       queue<pair<int, int> > q;       memset((vpre), (-1), sizeof(vpre));       q.push(make_pair(start, -2));       while (!q.empty()) {         int curr = q.front().first;         int prev = q.front().second;         q.pop();         if (vpre[curr] != -1) continue;         vpre[curr] = prev;         if (curr == 0) break;         for (__typeof((vg[curr]).begin()) e = (vg[curr]).begin();              e != (vg[curr]).end(); ++e) {           q.push(make_pair(e->to, curr));         }       }       assert(vpre[0] >= 0);       vector<E> outp;       for (int curr = 0; curr >= 0; curr = vpre[curr]) {         int prev = vpre[curr];         for (__typeof((vg[prev]).begin()) e = (vg[prev]).begin();              e != (vg[prev]).end(); ++e) {           if (e->to == curr) {             outp.push_back(*e);             break;           }         }       }       printf( %d n , (int)((outp).size()));       for (int i = 0; i < (int)((int)((outp).size())); ++i)         printf( %c2^%d n , outp[i].sign, outp[i].pw);     }   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 5e3;   const double eps = 1e-14;   double dp[NMAX + 5][NMAX + 5];   int n, k;   double p[NMAX + 5];   double np[NMAX + 5];   int t[NMAX + 5];   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d %d , &x, &t[i]);       p[i] = x / 100.0;       np[i] = (100 - x) / 100.0;     }     dp[0][0] = 1;     for (int i = 0; i <= n; i++) {       double prob = 1;       for (int j = 1; j <= t[i + 1]; j++) {         prob *= np[i + 1];       }       for (int j = i; j <= k; j++) {         if (dp[i][j] < eps) {           continue;         }         if (j < k) {           dp[i][j + 1] += dp[i][j] * np[i];           dp[i + 1][j + 1] += dp[i][j] * p[i + 1];           if (j <= k - t[i + 1]) {             dp[i + 1][j + t[i + 1]] += dp[i][j] * prob;             if (j <= k - t[i + 1] - 1) {               dp[i + 1][j + t[i + 1] + 1] -= dp[i][j] * prob;             }           }         }       }     }     double ans = 0;     for (int i = 1; i < n; i++) {       double prob = 1;       for (int j = k; j > k - t[i + 1]; j--) {         ans += i * dp[i][j] * prob;         prob *= (1 - p[i + 1]);       }     }     for (int j = 1; j <= k; j++) {       ans += n * dp[n][j];     }     printf( %.9f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(long long a, long long b) {     if (a > b) return true;     return false;   }   long long n, dp[100010], res;   pair<long long, long long> a[100010];   map<long long, long long> m;   map<long long, long long>::iterator it;   int main() {     int t = 1;     while (t--) {       scanf( %lld , &n);       for (int i = 0; i < n; i++) {         scanf( %lld%lld , &a[i].first, &a[i].second);       }       sort(a, a + n);       for (int i = 0; i < n; i++) {         m[a[i].first] = i;         it = m.lower_bound(a[i].first - a[i].second);         if (it == m.begin())           dp[i] = 1;         else {           --it;           dp[i] = 1 + dp[it->second];         }         res = max(dp[i], res);       }       cout << n - res <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, sum1 = 0, sum2 = 0, a[200];     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];       if (a[i] < 0) {         sum2 += a[i];       } else         sum1 += a[i];     }     cout << sum1 - sum2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   int ans[200200], vst[200200], pos[200200], neg[200200];   set<int> s[200200];   priority_queue<pair<int, int> > q;   int main() {     int n, m, k, first;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       scanf( %d , &k);       q.push(pair<int, int>(-k, i));       while (k--) {         scanf( %d , &first);         s[i].insert(first);         if (first > 0)           pos[first] = i;         else           neg[-first] = i;       }     }     for (int i = 1; i <= m; i++) {       if (!pos[i] || !neg[i]) {         int u = pos[i] ? pos[i] : neg[i];         vst[u] = 1;         ans[i] = (pos[i] == u);       }     }     while (!q.empty()) {       int u = q.top().second;       q.pop();       if (vst[u]) continue;       vst[u] = 1;       if (s[u].empty()) {         puts( NO );         return 0;       }       first = *s[u].begin();       if (first > 0) {         ans[first] = 1;         if (neg[first]) {           s[neg[first]].erase(-first);           q.push(pair<int, int>(-s[neg[first]].size(), neg[first]));         }       } else {         first = -first;         ans[first] = 0;         if (pos[first]) {           s[pos[first]].erase(first);           q.push(pair<int, int>(-s[pos[first]].size(), pos[first]));         }       }     }     puts( YES );     for (int i = 1; i <= m; i++) putchar(ans[i] +  0 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[200005];   bool b[200005];   int n, ans = 0;   void solve(int u) {     if (u == 1) {       if (u == n) {         ans = 1;         return;       }       if (s[u] ==  < ) {         b[u] = true;         ans++;       }       solve(u + 1);       if (s[u] ==  > )         if (b[u + 1]) ans++;       return;     }     if (u > n) return;     if (u == n) {       if (s[u] ==  >  | b[u - 1]) {         b[u] = true;         ans++;       }       return;     }     if (s[u] ==  < ) {       if (b[u - 1]) {         b[u] = true;         ans++;       }       solve(u + 1);     } else {       solve(u + 1);       if (b[u + 1]) {         b[u] = true;         ans++;       }     }   }   int main() {     scanf( %d , &n);     scanf( %s , s + 1);     solve(1);     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int x[10][10];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       x[a][b] = x[b][a] = 1;     }     if (n < 7)       cout << m <<   n ;     else {       int sum = 30;       for (int i = 1; i <= 7; i++) {         for (int j = i + 1; j <= 7; j++) {           int ans = 0;           for (int o = 1; o <= 7; o++) {             if (x[i][o] == 1 && x[j][o] == 1) ans++;           }           if (ans < sum) sum = ans;         }       }       cout << m - sum <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     for (long long i = 0; i < n; ++i) {       if (i % 4 < 2)         putchar( a );       else         putchar( b );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int l = s.length();     int fc = 0;     int sc = 0;     for (int i = 0; i < l; i++) {       if (s[i] ==  4 ) fc++;       if (s[i] ==  7 ) sc++;     }     if (!fc && !sc)       cout <<  -1  << endl;     else if (sc > fc)       cout <<  7  << endl;     else       cout <<  4  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long int T;     vector<long int> sweet(3);     cin >> T;     while (T--) {       long int sum = 0;       cin >> sweet[0] >> sweet[1] >> sweet[2];       sort(sweet.begin(), sweet.end());       sum = min((sweet[2] + sweet[1] + sweet[0]) / 2,                 (sweet[2] + sweet[1] + sweet[0]) - sweet[2]);       cout << sum << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   inline bool is_palindrome(const string& s) {     return std::equal(s.begin(), s.end(), s.rbegin());   }   const long long MOD = 1000000007;   const long long INF = 1e9 + 5;   const double eps = 1e-7;   const double PI = acos(-1.0);   inline void debug_vi(vector<int> a) {     for (long long i = (long long)(0); i < (long long)(a.size()); i++)       cout << a[i] <<    ;   }   inline void debug_vll(vector<long long> a) {     for (long long i = (long long)(0); i < (long long)(a.size()); i++)       cout << a[i] <<    ;   }   const int N = 1e5 + 5;   int in[N];   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, s, a, b;     cin >> n >> s;     memset(in, 0, sizeof(in));     for (long long i = (long long)(0); i < (long long)(n - 1); i++) {       cin >> a >> b;       a--;       b--;       in[a]++;       in[b]++;     }     int l = 0;     for (long long i = (long long)(0); i < (long long)(n); i++) {       if (in[i] == 1) {         l++;       }     }     double ans = 2.0 * s / l;     cout << fixed << showpoint << setprecision(15) << ans;     ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   struct node {     int a;     int b;     int sum;   };   int n, q;   int nblock;   node nums[300315];   int acum = 0;   int fib[300315];   long long auxi;   void add(int &a, int b) {     a += b;     if (a > 1000000009) a -= 1000000009;   }   inline int calcf(int x) {     if (x <= 1 || fib[x] != 0) return fib[x];     fib[x] = 0;     add(fib[x], calcf(x - 2));     add(fib[x], calcf(x - 1));     return fib[x];   }   inline int sumfibo(int a, int b, int posx, int posy) {     int x = 0;     auxi = (1LL * calcf(posx - 1) * a) % (1LL * 1000000009);     add(x, int(auxi));     auxi = (1LL * calcf(posx) * b) % (1LL * 1000000009);     add(x, int(auxi));     int y = 0;     auxi = (1LL * calcf(posy) * a) % (1LL * 1000000009);     add(y, int(auxi));     auxi = (1LL * calcf(posy + 1) * b) % (1LL * 1000000009);     add(y, int(auxi));     add(y, 1000000009 - x);     return y;   }   inline void update(int ini, int fin) {     int inc = 1;     int acumblock = 0;     if ((ini - 1) / nblock == (fin - 1) / nblock) {       for (int i = 0; i < nblock; i++) {         int j = i + ini;         if (j <= fin) {           add(acumblock, calcf(inc));           inc++;         }         if (((j - 1) / nblock) == (fin - 1) / nblock) {           add(nums[j].sum, acumblock);         }       }     } else {       int iniblock;       iniblock = ini - ((ini - 1) % nblock);       int l = iniblock;       if (ini % nblock != 1) {         for (int i = ini; i < iniblock + nblock; i++) {           add(acumblock, calcf(inc));           inc++;           add(nums[i].sum, acumblock);         }         l = iniblock + nblock;       }       while (l + nblock <= fin + 1) {         add(nums[l].a, calcf(inc));         add(nums[l].b, calcf(inc + 1));         inc += nblock;         l += nblock;       }       acumblock = 0;       for (int i = 0; i < nblock; i++) {         int j = i + l;         if (j <= fin) {           add(acumblock, calcf(inc));           inc++;         }         if (((j - 1) / nblock) == (fin - 1) / nblock) add(nums[j].sum, acumblock);       }     }   }   inline int get(int ini, int fin) {     int iniblock;     int ans = 0;     if ((ini - 1) / nblock == (fin - 1) / nblock) {       iniblock = ini - ((ini - 1) % nblock);       if (ini % nblock) {         if (fin % nblock)           add(ans, sumfibo(nums[iniblock].a, nums[iniblock].b, ini % nblock,                            fin % nblock));         else           add(ans,               sumfibo(nums[iniblock].a, nums[iniblock].b, ini % nblock, nblock));       } else         add(ans, sumfibo(nums[iniblock].a, nums[iniblock].b, nblock, nblock));       add(ans, nums[fin].sum);       if (ini % nblock != 1) {         add(ans, 1000000009 - nums[ini - 1].sum);       }       return ans;     } else {       iniblock = ini - ((ini - 1) % nblock);       if (ini % nblock)         add(ans,             sumfibo(nums[iniblock].a, nums[iniblock].b, ini % nblock, nblock));       else         add(ans, sumfibo(nums[iniblock].a, nums[iniblock].b, nblock, nblock));       add(ans, nums[iniblock + nblock - 1].sum);       if (ini % nblock != 1) {         add(ans, 1000000009 - nums[ini - 1].sum);       }       int l = iniblock + nblock;       while (l + nblock <= fin + 1) {         add(ans, sumfibo(nums[l].a, nums[l].b, 1, nblock));         add(ans, nums[l + nblock - 1].sum);         l += nblock;       }       if (l <= fin) {         add(ans, nums[fin].sum);         add(ans, sumfibo(nums[l].a, nums[l].b, 1, fin % nblock));       }       return ans;     }   }   int main() {     fib[0] = 0;     fib[1] = 1;     fib[2] = 1;     scanf( %d %d , &n, &q);     nblock = int(sqrt(n * 1.0));     if (nblock * nblock != n) nblock++;     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       add(acum, x);       nums[i].sum = acum;       if (i % nblock == 0) acum = 0;     }     for (int i = 0; i < q; i++) {       int x, y, z;       scanf( %d %d %d , &x, &y, &z);       if (x == 1) {         update(y, z);       } else if (x == 2) {         printf( %d n , get(y, z));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fLL;   const double EPS = 1e-8;   const int MOD = 998244353;   const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};   int mod = MOD;   struct ModInt {     unsigned val;     ModInt() : val(0) {}     ModInt(long long x) : val(x >= 0 ? x % mod : x % mod + mod) {}     ModInt pow(long long exponent) {       ModInt tmp = *this, res = 1;       while (exponent > 0) {         if (exponent & 1) res *= tmp;         tmp *= tmp;         exponent >>= 1;       }       return res;     }     ModInt &operator+=(const ModInt &rhs) {       if ((val += rhs.val) >= mod) val -= mod;       return *this;     }     ModInt &operator-=(const ModInt &rhs) {       if ((val += mod - rhs.val) >= mod) val -= mod;       return *this;     }     ModInt &operator*=(const ModInt &rhs) {       val = (unsigned long long)val * rhs.val % mod;       return *this;     }     ModInt &operator/=(const ModInt &rhs) { return *this *= rhs.inv(); }     bool operator==(const ModInt &rhs) const { return val == rhs.val; }     bool operator!=(const ModInt &rhs) const { return val != rhs.val; }     bool operator<(const ModInt &rhs) const { return val < rhs.val; }     bool operator<=(const ModInt &rhs) const { return val <= rhs.val; }     bool operator>(const ModInt &rhs) const { return val > rhs.val; }     bool operator>=(const ModInt &rhs) const { return val >= rhs.val; }     ModInt operator-() const { return ModInt(-val); }     ModInt operator+(const ModInt &rhs) const { return ModInt(*this) += rhs; }     ModInt operator-(const ModInt &rhs) const { return ModInt(*this) -= rhs; }     ModInt operator*(const ModInt &rhs) const { return ModInt(*this) *= rhs; }     ModInt operator/(const ModInt &rhs) const { return ModInt(*this) /= rhs; }     friend ostream &operator<<(ostream &os, const ModInt &rhs) {       return os << rhs.val;     }     friend istream &operator>>(istream &is, ModInt &rhs) {       long long x;       is >> x;       rhs = ModInt(x);       return is;     }       private:     ModInt inv() const {       unsigned a = val, b = mod;       int x = 1, y = 0;       while (b) {         unsigned tmp = a / b;         a -= tmp * b;         swap(a, b);         x -= tmp * y;         swap(x, y);       }       return ModInt(x);     }   };   ModInt abs(const ModInt &x) { return x.val; }   struct Combinatorics {     Combinatorics(int MAX = 5000000) {       MAX <<= 1;       fact.resize(MAX + 1);       fact_inv.resize(MAX + 1);       fact[0] = 1;       for (int i = (1); i < (MAX + 1); ++i) fact[i] = fact[i - 1] * i;       fact_inv[MAX] = ModInt(1) / fact[MAX];       for (int i = MAX; i > 0; --i) fact_inv[i - 1] = fact_inv[i] * i;     }     ModInt nCk(int n, int k) {       if (n < 0 || n < k || k < 0) return ModInt(0);       return fact[n] * fact_inv[k] * fact_inv[n - k];     }     ModInt nPk(int n, int k) {       if (n < 0 || n < k || k < 0) return ModInt(0);       return fact[n] * fact_inv[n - k];     }     ModInt nHk(int n, int k) {       if (n < 0 || k < 0) return ModInt(0);       return (k == 0 ? ModInt(1) : nCk(n + k - 1, k));     }       private:     vector<ModInt> fact, fact_inv;   };   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int n, m;     cin >> n >> m;     vector<int> a(n);     for (int i = (0); i < (n); ++i) cin >> a[i];     vector<int> w(n);     for (int i = (0); i < (n); ++i) cin >> w[i];     int dislike = 0, like = 0;     for (int i = (0); i < (n); ++i) {       if (a[i] == 0)         dislike += w[i];       else         like += w[i];     }     for (int i = (0); i < (n); ++i) {       vector<vector<vector<ModInt> > > dp(           m + 1, vector<vector<ModInt> >(m + 1, vector<ModInt>(m + 1, 0)));       dp[0][0][0] = 1;       int dl = dislike, l = like;       if (a[i] == 0)         dl -= w[i];       else         l -= w[i];       for (int x = (0); x < (m); ++x) {         for (int y = (0); y < (m + 1); ++y)           for (int z = (0); z < (m + 1); ++z) {             int sum = like + dislike - z + (x - y - z) + (a[i] == 0 ? -y : y);             if (a[i] == 0 && y > w[i]) continue;             if (z > dl || y + z > x || sum <= 0) continue;             dp[x + 1][y + 1][z] +=                 dp[x][y][z] * (w[i] + (a[i] == 0 ? -y : y)) / sum;             dp[x + 1][y][z + 1] += dp[x][y][z] * (dl - z) / sum;             dp[x + 1][y][z] += dp[x][y][z] * (l + (x - y - z)) / sum;           }       }       ModInt ans = 0;       for (int y = (0); y < (m + 1); ++y)         for (int z = (0); z < (m + 1); ++z) {           if (a[i] == 0 && y > w[i]) continue;           if (z > dl || y + z > m) continue;           ans += dp[m][y][z] * (w[i] + (a[i] == 0 ? -y : y));         }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int s, v1, v2, t1, t2;     cin >> s >> v1 >> v2 >> t1 >> t2;     int res1 = (s * v1) + (t1 * 2);     int res2 = (s * v2) + (t2 * 2);     if (res1 < res2) {       cout <<  First ;     }     if (res1 > res2) {       cout <<  Second ;     }     if (res1 == res2) {       cout <<  Friendship ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1200000;   const int inf = 0x3f3f3f3f;   int n, m, k;   vector<int> g[M];   int ans;   int dfs(int u, int f) {     vector<int> v = {0, 0};     for (int to : g[u]) {       if (to == f) continue;       v.push_back(dfs(to, u));     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     int sz = g[u].size();     ans = max(ans, v[0] + v[1] + sz + 1);     return v[0] + sz - 1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     for (int _ = (1); _ <= (t); ++_) {       cin >> n;       int u, v;       for (int i = (1); i <= (n); ++i) g[i].clear();       for (int i = (2); i <= (n); ++i) {         cin >> u >> v;         g[u].push_back(v);         g[v].push_back(u);       }       ans = 0;       dfs(1, 1);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class BIT {    public:     int size;     vector<long long> arr;     BIT(int n) {       size = n + 5;       arr.resize(size);     }     void add(int i, long long v) {       for (int x = i + 1; x < size; x += (x & (-x))) arr[x] += v;     }     long long sum(int i) {       i = min(i, size - 2);       long long res = 0;       for (int x = i + 1; x > 0; x -= (x & (-x))) res += arr[x];       return res;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, w;     cin >> n >> w;     vector<pair<long long, long long>> p(n);     for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;     sort(p.begin(), p.end(),          [&](pair<long long, long long> p0, pair<long long, long long> p1) {            if (abs(p0.first) * abs(p1.second - w) ==                abs(p1.first) * abs(p0.second - w)) {              return abs(p0.first) * abs(p1.second - w + 1) >                     abs(p1.first) * abs(p0.second - w + 1);            } else {              return abs(p0.first) * abs(p1.second - w) <                     abs(p1.first) * abs(p0.second - w);            }          });     vector<int> in(n);     for (int i = 0; i < n; i++) in[i] = i;     sort(in.begin(), in.end(), [&](int i0, int i1) {       pair<long long, long long> p0 = p[i0], p1 = p[i1];       if (abs(p0.first) * abs(p1.second + w) ==           abs(p1.first) * abs(p0.second + w)) {         return abs(p0.first) * abs(p1.second + w - 1) >                abs(p1.first) * abs(p0.second + w - 1);       } else {         return abs(p0.first) * abs(p1.second + w) <                abs(p1.first) * abs(p0.second + w);       }     });     BIT bit(n);     long long res = 0;     for (int i = n - 1; i >= 0; i--) {       res += bit.sum(in[i]);       bit.add(in[i], 1);     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 50;   ;   const int M = 255;   const int mod = 998244353;   const int mo = 123;   const double pi = acos(-1.0);   int n, m;   int ans = 0;   int vis[N];   vector<int> vec;   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       int res = 0;       for (int j = 0, x; j < m; j++) {         scanf( %d , &x);         if (x) res |= (1 << j);       }       if (!vis[res]) {         vec.push_back(res);         vis[res]++;       }     }     bool ok = false;     for (int i = 0; i < vec.size(); i++) {       for (int j = 0; j < vec.size(); j++) {         int x = vec[i] + vec[j];         int y = vec[i] ^ vec[j];         if (x == y) ok = true;       }     }     if (ok)       puts( YES );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   int n, br;   int p[MAXN], niz[MAXN], num[MAXN], bio[MAXN];   inline void ne() {     printf( NO n );     exit(0);   }   void dfs1(int x) {     if (bio[x]) return;     bio[x] = br;     num[br]++;     dfs1(niz[x]);   }   void dfs2(int x) {     if (bio[x]) return;     bio[x] = 1;     if (bio[niz[x]]) return;     printf( %d %d n , x, niz[x]);     dfs2(niz[x]);   }   void dfs3(int x, int y) {     if (bio[x]) return;     bio[x] = 1;     printf( %d %d n , x, y);     dfs3(niz[x], niz[y]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &p[i]);     for (int i = 1; i <= n; i++) niz[p[i]] = p[p[i]];     br = 1;     for (int i = 1; i <= n; i++)       if (!bio[i]) {         dfs1(i);         br++;       }     int poc = 0, val = MAXN, grupa = 0;     for (int i = 1; i <= n; i++)       if (num[bio[i]] < val) {         val = num[bio[i]];         poc = i;         grupa = bio[i];       }     if (num[grupa] > 2) ne();     for (int i = 1; i < br; i++)       if (num[i] % num[grupa] != 0) ne();     printf( YES n );     memset(bio, 0, sizeof(bio));     dfs2(poc);     for (int i = 1; i <= n; i++)       if (!bio[i]) dfs3(i, poc);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> primes;   void sieve() {     vector<bool> isComposite(100000000, false);     for (int i = 2; i * i <= 100000000; i++) {       if (isComposite[i] == false)         for (int j = i * 2; j <= 100000000; j += i) isComposite[j] = true;     }     for (int i = 2; i <= 100000000; i++)       if (isComposite[i] == false) primes.push_back(i);     for (auto it : primes) cout << it <<    ;   }   long long LCM(int n) {     long long lcm = 1;     for (int i = 0; i < primes.size() && primes[i] <= n; i++) {       int pp = primes[i];       while (pp * primes[i] <= n) pp = pp * primes[i];       lcm *= pp;       lcm %= 1000000007;     }     return lcm;   }   int main() {     int t;     cin >> t;     while (t--) {       long long int n;       string keyboard;       string s;       cin >> keyboard;       cin >> s;       map<char, int> mp;       for (int i = 0; i < keyboard.size(); i++) {         mp[keyboard[i]] = i + 1;       }       long long int time = 0;       for (int i = 1; i < s.length(); i++) {         time += abs((mp[s[i]] - mp[s[i - 1]]));       }       cout << time <<   n ;     }   }


#include<bits/stdc++.h>   using namespace std;   #define sfd(x) scanf( %d ,&x)   #define sfd2(x,y) scanf( %d%d ,&x,&y)   #define sfd3(x,y,z) scanf( %d%d%d ,&x,&y,&z)   #define sfs(x) scanf( %s ,x)   #define sfll(x) scanf( %lld ,&x)   #define sfll2(x,y) scanf( %lld%lld ,&x,&y)   #define pfd(x) printf( %d ,x)   #define pfs(x) printf( %s ,x)   #define pfll(x) printf( %lld ,x)   #define nl printf(  n )   #define sp printf(   )   #define pfyes printf( YES )   #define pfno printf( NO )   #define pf0 printf( 0 )   #define FOR(i,a,b,in) for(int i=a;i<=b;i+=in)   #define RFOR(i,a,b,de) for(int i=a;i>=b;i-=de)   #define rep(i,n) for(int i=0;i<n;i++)   #define pb push_back   #define mkp make_pair   #define mod 998244353   typedef long long int ll;   typedef vector<int> vi;   typedef pair<int,int> pii;   // ------------------------//   ll power(long long x, int y, int p)   {       ll res = 1;     x = x % p;       if (x == 0) return 0;      while (y > 0)       {           if (y & 1)               res = (res*x) % p;           y = y>>1;            x = (x*x) % p;       }       return res;   }   int main()   {    int t;    sfd(t);    while(t--)    {     int n;     sfd(n);     char s[n+1];     sfs(s);     int c0 = 0;     int c1 = 0;     int cx = 0;     rep(i,n)     {      if(s[i]== 1 )      {       cx+=1;      }      else      {       c1+=(cx/2);       cx=0;       c0+=1;      }     }     c1+=(cx/2);     ll v1=1,v2=1,v3=1;     for(int i=1;i<=c0;i++)     {      v1=(v1*i)%mod;     }     for(int i=1;i<=c1;i++)     {      v2=(v2*i)%mod;     }     for(int i=1;i<=c0+c1;i++)     {      v3=(v3*i)%mod;     }     v1=(v1*v2)%mod;     ll ans = (v3*power(v1,mod-2,mod))%mod;     pfll(ans);     nl;         }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int fen1[200002];   void upd1(int pos, int val) {     for (; pos <= 200000; pos |= (pos + 1)) fen1[pos] += val;   }   int fnd1(int pos) {     int ret = 0;     for (; pos >= 0; pos = (pos & (pos + 1)) - 1) ret += fen1[pos];     return ret;   }   int fen2[200002];   void upd2(int pos, int val) {     for (; pos >= 0; pos = (pos & (pos + 1)) - 1) fen2[pos] += val;   }   int fnd2(int pos) {     int ret = 0;     for (; pos <= 200000; pos |= (pos + 1)) ret += fen2[pos];     return ret;   }   int now[200002];   int main() {     int n, k, a, b, q;     scanf( %d%d%d%d%d , &n, &k, &a, &b, &q);     while (q--) {       int t;       scanf( %d , &t);       if (t == 1) {         int d, aa;         scanf( %d%d , &d, &aa);         --d;         int add = max(0, min(aa, b - now[d]));         upd1(d, add);         add = max(0, min(aa, a - now[d]));         upd2(d, add);         now[d] += aa;       } else {         int p;         scanf( %d , &p);         --p;         int ans = fnd1(p - 1) + fnd2(p + k);         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, m, k;       cin >> n >> m >> k;       k = n * m / 2 - k;       if (n % 2 == 1) {         swap(n, m);         k = n * m / 2 - k;       }       if (m % 2 == 1) {         if ((k >= n / 2 && (k - n / 2) % (2) == 0)) {           cout <<  YES  <<   n ;           continue;         } else {           cout <<  NO  <<   n ;           continue;         }       } else {         if (k % 2 == 0)           cout <<  YES  <<   n ;         else           cout <<  NO  <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   struct node {     long long num;     int p;   } nd[maxn];   long long sum[maxn], f[maxn];   bool cp1(node a, node b) { return a.num < b.num; }   int main() {     int n, k;     ios::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> nd[i].num;       nd[i].p = i;     }     sort(nd + 1, nd + 1 + n, cp1);     cin >> k;     sum[0] = 0;     for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + nd[i].num;     f[1] = 0;     for (int i = 2; i <= k; i++)       f[i] = nd[i].num * (i - 1) - sum[i - 1] + f[i - 1];     long long mm = f[k];     int p = 1;     for (int i = k + 1; i <= n; i++) {       f[i] = nd[i].num * (k - 1) + f[i - 1] + nd[i - k].num * (k - 1) -              2 * (sum[i - 1] - sum[i - k]);       if (f[i] < mm) {         mm = f[i];         p = i - k + 1;       }     }     for (int i = 0; i < k; i++)       printf( %d%c , nd[i + p].p, i == k - 1 ?   n  :    );   }


#include<bits/stdc++.h>   #define ll int   #define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);   using namespace std;   ll n, m, i, j, k = 0, t, w, flag, x, y, z, sum;   string s1, s2, s;   int main()   {       FAST_IO;       cin >> n >> m >> k;       ll h[n + 1][m], l[n][m + 1];       vector<vector<ll> >re ( n + 1, vector<ll> ( m + 1, 0 ) );       vector<vector<ll> >temp ( n + 1, vector<ll> ( m + 1, 0 ) );          for ( i = 1; i <= n; i++ )           for ( j = 1; j < m; j++ )               cin >> h[i][j];          for ( i = 1; i < n; i++ )           for ( j = 1; j <= m; j ++ )               cin >> l[i][j];          for ( t = 1; t <= k / 2; t++ )       {           for ( i = 1; i <= n; i++ )           {               for ( j = 1; j <= m; j++ )               {                   temp[i][j] = ( int ) 1e9;;                   if ( i != n )                       temp[i][j] = min ( temp[i][j], re[i + 1][j] + l[i][j] * 2 );                   if ( i != 1 )                       temp[i][j] = min ( temp[i][j], re[i - 1][j] + l[i - 1][j] * 2 );                   if ( j != m )                       temp[i][j] = min ( temp[i][j], re[i][j + 1] + h[i][j] * 2 );                   if ( j != 1 )                       temp[i][j] = min ( temp[i][j], re[i][j - 1] + h[i][j - 1] * 2 );               }           }           swap ( re, temp );       }       for ( i = 1; i <= n; cout << endl, i++ )           for ( j = 1; j <= m; j++ )           {               if ( j > 1 ) cout <<    ;               cout << ( k % 2 ? -1 : re[i][j] );           }      }


#include <bits/stdc++.h>   using namespace std;   // #include <atcoder/all>   // using namespace atcoder;      #define rep(i,n) for (int i = 0; i < (n); ++i)   #define STRING(str) #str   #define ll long long   #define ld long double      template <typename T>   void print(T x, string name) {    cout << name+ :   << x << endl;   }      template <typename T >   void print_vec_1d(vector<T> x, string name) {    cout << name << endl;    cout <<  [  ;    for (int i=0;i<x.size();i++) {     cout << x[i];     if (i != x.size()-1) cout <<  ,  ;     else cout <<   ]  << endl;    }   }      template <typename T >   void print_vec_2d(vector<vector<T>> x, string name) {    cout << name << endl;    cout <<  [  ;    for (int i=0;i<x.size();i++) {     cout <<  [  ;     for (int j=0;j<x[i].size();j++) {      cout << x[i][j];      if (j != x[i].size()-1) cout <<  ,  ;      else {       cout <<   ] ;       if (!((i == x.size()-1) && (j == x[i].size()-1))) {        cout <<  ,  << endl;       }      }     }    }    cout <<   ]  << endl;   }      template <typename T >   void print_vec_3d(vector<vector<vector<T>>> x, string name) {    cout << name << endl;    cout <<  [  ;    for (int i=0;i<x.size();i++) {     cout <<  [  ;     for (int j=0;j<x[i].size();j++) {      cout <<  [  ;      for (int k=0;k<x[i][j].size();k++) {       cout << x[i][j][k];       if (k != x[i][j].size()-1) cout <<  ,  ;       else {        cout <<   ] ;        if (!((i == x.size()-1) && (j == x[i].size()-1) && (k == x[i][j].size()-1))) {         cout <<  ,  << endl;        }       }      }      if (j != x[i].size()-1) cout <<  ,  ;      else {       cout <<   ] ;       if (!((i == x.size()-1) && (j == x[i].size()-1))) {        cout <<  ,  << endl;       }      }     }    }    cout <<   ]  << endl;   }      int main() {    // ios::sync_with_stdio(0);    // cin.tie(0);       int n;    cin >> n;    int ind_2;    cout <<  ? 1   << n <<   n ;    cin >> ind_2;    ind_2--;       int a1, a2;    if (ind_2 != 0 && ind_2 != n-1) {     cout <<  ? 1   << ind_2+1 <<   n ;     cin >> a1;     a1--;        int a2;     cout <<  ?   << ind_2+1 <<     << n <<   n ;     cin >> a2;     a2--;    }       bool left_flag;    if (ind_2 == n-1) {     left_flag = true;    } else if (ind_2 == 0) {     left_flag = false;    } else if (ind_2 == a1) {     left_flag = true;    } else { // ind_2 == a2     left_flag = false;    }    if (left_flag) {     // ? ? ? 1 ? ? ? 2 ? ? ? ?     int ok = 0;     int ng = ind_2;     while (abs(ok-ng) > 1) {      int mid = (ok+ng)/2;      int b;      cout <<  ?   << mid+1 <<     << ind_2+1 <<   n ;      cin >> b;      b--;      if (b == ind_2) {       ok = mid;      } else {       ng = mid;      }     }     cout <<  !   << ok+1 <<   n ;    } else {     // ? ? ? ? ? ? ? 2 ? 1 ? ?     int ok = n-1;     int ng = ind_2;     while (abs(ok-ng) > 1) {      int mid = (ok+ng)/2;      int b;      cout <<  ?   << ind_2+1 <<     << mid+1 <<   n ;      cin >> b;      b--;      if (b == ind_2) {       ok = mid;      } else {       ng = mid;      }     }     cout <<  !   << ok+1 <<   n ;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INFint = 2147483647;   const long long INF = 9223372036854775807ll;   const long long MOD = 1000000007ll;   long long cnt[100000];   int main() {     ios_base::sync_with_stdio(0);     long long a;     cin >> a;     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       long long sum = 0;       for (int j = i; j < s.size(); j++) {         sum += s[j] -  0 ;         cnt[sum]++;       }     }     long long ans = 0;     if (a == 0) {       ans = cnt[0] * cnt[0];       for (int i = 1; i < 100000; i++) {         ans += cnt[0] * cnt[i] * 2;       }     } else {       for (int i = 1; i < 100000; i++) {         if (i <= a) {           if (a % i == 0 && a / i < 100000) ans += cnt[i] * cnt[a / i];         } else           break;       }     }     cout << ans << endl;     fprintf(stderr,   nTIME = %lf n , 1.0 * clock() / CLOCKS_PER_SEC);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void debug(T a, T b) {     ;   }   template <class T>   void chmin(T& a, const T& b) {     if (a > b) a = b;   }   template <class T>   void chmax(T& a, const T& b) {     if (a < b) a = b;   }   namespace std {   template <class S, class T>   ostream& operator<<(ostream& out, const pair<S, T>& a) {     out <<  (  << a.first <<  ,  << a.second <<  ) ;     return out;   }   }  // namespace std   long long int readL() {     long long int res;     scanf( %I64d , &res);     return res;   }   void printL(long long int res) { printf( %I64d , res); }   const int INF = 5e8;   int n, m;   vector<int> g[100005];   pair<int, int> mst2[100005];   pair<int, int> es[100005];   int idx[100005], rev[100005];   vector<int> g2[100005];   int res[100005];   bool cut[100005];   int size[100005], whole;   int gsize(int v, int p) {     size[v] = 1;     for (auto to : g2[v]) {       if (cut[to] || to == p) continue;       size[v] += gsize(to, v);     }     return size[v];   }   int root, cost;   void groot(int v, int p) {     int C = whole - size[v];     for (auto to : g2[v]) {       if (cut[to] || to == p) continue;       groot(to, v);       chmax(C, size[to]);     }     if (cost > C) {       cost = C;       root = v;     }   }   void dfs(int v, int rank) {     whole = gsize(v, -1);     cost = INF;     groot(v, -1);     v = root;     res[v] = rank;     if (whole == 1) return;     cut[v] = 1;     for (auto to : g2[v]) {       if (cut[to]) continue;       dfs(to, rank + 1);     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < (m); ++i) {       int a, b;       scanf( %d%d , &a, &b);       --a;       --b;       if (a > b) swap(a, b);       es[i] = {a, b};     }     es[m++] = {0, n - 1};     sort(es, es + m, [&](pair<int, int> a, pair<int, int> b) {       return a.second - a.first < b.second - b.first;     });     set<pair<pair<int, int>, int> > range;     int cnt = 0;     for (int i = 0; i < (m); ++i) {       int a = es[i].first, b = es[i].second;       auto it = range.lower_bound({{a, -1}, -1});       pair<int, int> last = {-1, -1};       while (it != range.end() && it->first.second <= b) {         last = it->first;         g[cnt].push_back(it->second);         g[it->second].push_back(cnt);         range.erase(it++);       }       if (last.second == b)         mst2[cnt] = {last.first, b};       else         mst2[cnt] = {b - 1, b};       range.insert({{a, b}, cnt});       ++cnt;     }     for (int i = 0; i < (cnt); ++i)       if (mst2[i].second > mst2[i].first) swap(mst2[i].first, mst2[i].second);     for (int i = 0; i < (cnt); ++i) idx[i] = i;     sort(idx, idx + cnt, [&](int a, int b) { return mst2[a] < mst2[b]; });     for (int i = 0; i < (cnt); ++i) rev[idx[i]] = i;     for (int i = 0; i < (cnt); ++i)       for (auto to : g[i]) g2[rev[i]].push_back(rev[to]);     dfs(0, 0);     for (int i = 0; i < (cnt); ++i) printf( %d n , res[i] + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   double p[110], S = 0, P = 1, ans;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lf , &p[i]);     sort(p + 1, p + n + 1);     for (int i = n; i >= 1; i--)       if (1.0 - S >= 1e-12) {         ans += P * p[i] * (1 - S);         S += p[i] / (1.0 - p[i]);         P *= (1.0 - p[i]);       }     printf( %.12lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int x[N], p[N], n, d, ind[N];   long long ans = 0;   vector<pair<int, int> > tank;   int head, cur;   bool cmp(int a, int b) { return x[a] < x[b]; }   bool use(int dis) {     while (dis) {       if (head == (int)tank.size()) return 1;       int tmp = min(dis, tank[head].first);       dis -= tmp;       tank[head].first -= tmp;       cur -= tmp;       if (tank[head].first == 0) head++;     }     return 0;   }   void sale(int p) {     while ((int)tank.size() > head && tank.back().second > p) {       ans -= 1LL * tank.back().second * tank.back().first;       cur -= tank.back().first;       tank.pop_back();     }   }   void buy(int p) {     ans += 1LL * p * (n - cur);     tank.push_back(make_pair(n - cur, p));     cur = n;   }   int main() {     int m;     scanf( %d%d%d , &d, &n, &m);     for (int i = 1; i <= m; ++i) scanf( %d%d , &x[i], &p[i]), ind[i] = i;     x[m + 1] = d;     p[m + 1] = 0;     ind[m + 1] = m + 1;     sort(ind + 1, ind + 1 + m, cmp);     tank.push_back(make_pair(n, 0));     cur = n;     for (int i = 1; i <= m + 1; ++i) {       int dis = x[ind[i]] - x[ind[i - 1]];       if (use(dis)) return 0 * puts( -1 );       sale(p[ind[i]]);       buy(p[ind[i]]);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e5 + 1, INF = 1e17, MOD = 1e9 + 7;   long long n;   string s, t =  UDRL ;   map<char, long long> m;   int32_t main() {     ios_base::sync_with_stdio(0);     cin >> n >> s;     for (long long i = 0; i < n; ++i) {       m[s[i]]++;     }     cout << 2 * (min(m[t[0]], m[t[1]]) + min(m[t[2]], m[t[3]])) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char buffer[100000], *p1, *p2;   template <class T>   void read(T& x) {     char ch = ((p1 == p2 &&                 (p2 = (p1 = buffer) + fread(buffer, 1, 100000, stdin), p1 == p2))                    ? EOF                    : *p1++);     x = 0;     bool f = 1;     while (!( 0  <= ch && ch <=  9 ) && ch !=  - )       ch = ((p1 == p2 &&              (p2 = (p1 = buffer) + fread(buffer, 1, 100000, stdin), p1 == p2))                 ? EOF                 : *p1++);     if (ch ==  - )       f = 0,       ch = ((p1 == p2 &&              (p2 = (p1 = buffer) + fread(buffer, 1, 100000, stdin), p1 == p2))                 ? EOF                 : *p1++);     while ( 0  <= ch && ch <=  9 )       x = (x << 1) + (x << 3) + ch -  0 ,       ch = ((p1 == p2 &&              (p2 = (p1 = buffer) + fread(buffer, 1, 100000, stdin), p1 == p2))                 ? EOF                 : *p1++);     x = (f) ? x : -x;   }   int n, m;   int a[605];   bool vis[605][605];   int dp[605][605];   int DP(int l, int r) {     if (l >= r) return 1;     if (vis[l][r]) return dp[l][r];     vis[l][r] = 1;     int& ans = dp[l][r];     int mi = n + 1, mip = -1;     for (register int i = l; i <= r; i++)       if (mi > a[i]) mi = a[i], mip = i;     int le = 0, ri = 0;     for (register int i = l - 1; i < mip; i++)       le += (long long int)DP(l, i) * DP(i + 1, mip - 1) % 998244353,           le %= 998244353;     for (register int i = r + 1; i > mip; i--)       ri += (long long int)DP(i, r) * DP(mip + 1, i - 1) % 998244353,           ri %= 998244353;     return ans = (long long int)le * ri % 998244353;   }   int main() {     read(n), read(m);     for (register int i = 1; i <= n; i++) read(a[i]);     printf( %d , DP(1, n));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const int N = 1000000 + 10;   const int M = 1000;   const string st2 =  ABCDEFGHIJKLMNOPQRSTUVWXYZ ;   const string s1 =  abcdefghijklmnopqrstuvwxyz ;   pair<int, int> a[N];   int b[N];   string ans[N], da[N];   int main() {     cin >> b[1] >> b[2] >> b[3] >> b[4] >> b[5] >> b[6];     int n;     cin >> n;     da[1] =  S ;     da[2] =  M ;     da[3] =  L ;     da[4] =  XL ;     da[5] =  XXL ;     da[6] =  XXXL ;     for (int i = 1; i <= n; i++) {       string second;       cin >> second;       if (second ==  S )         a[i] = make_pair(1, 0);       else if (second ==  M )         a[i] = make_pair(2, 0);       else if (second ==  L )         a[i] = make_pair(3, 0);       else if (second ==  XL )         a[i] = make_pair(4, 0);       else if (second ==  XXL )         a[i] = make_pair(5, 0);       else if (second ==  XXXL )         a[i] = make_pair(6, 0);       else if (second[0] ==  S )         a[i] = make_pair(1, 1);       else if (second[0] ==  M )         a[i] = make_pair(2, 1);       else if (second[0] ==  L )         a[i] = make_pair(3, 1);       else if (second[1] ==  L )         a[i] = make_pair(4, 1);       else if (second[2] ==  L )         a[i] = make_pair(5, 1);       else         a[i] = make_pair(6, 1);     }     for (int i = 1; i <= n; i++)       if (a[i].second == 0) {         if (b[a[i].first] != 0) {           ans[i] = da[a[i].first];           b[a[i].first]--;         }       }     for (int i = 1; i <= 6; i++) {       for (int j = 1; j <= n; j++)         if (ans[j] ==    && a[j].second == 1) {           if (a[j].first + 1 == i && b[i] > 0) {             b[i]--;             ans[j] = da[i];           }         }       for (int j = 1; j <= n; j++)         if (ans[j] ==    && a[j].second == 1) {           if (a[j].first == i && b[i] > 0) {             b[i]--;             ans[j] = da[i];           }         }     }     for (int i = 1; i <= n; i++)       if (ans[i] ==   ) {         cout <<  NO  << endl;         return 0;       }     cout <<  YES  << endl;     for (int i = 1; i <= n; i++) cout << ans[i] << endl;   }


#include<bits/stdc++.h>   using namespace std;   typedef unsigned long long int ull;   typedef long long int ll;   typedef long double ld;   #define fr(i,a,b) for(ll i=a; i<b; i++)   #define rf(i,a,b) for(ll i=a; i>=b; i--)   #define pb push_back   #define mp make_pair   #define show(a) for(auto el:a)cout<<el<<      #define ff first   #define ss second   #define pairv vector<pair<ll,ll>>   #define vec vector <ll>    #define all(a) a.begin(),a.end()   #define fam(v,i) for(auto i=v.begin();i!=v.end();i++)   #define fai(v,i) for(auto i : v)   #define mo 1000000007   #define nn cout<<  n ;   #define Y cout<< YES n ;   #define N cout<< NO n ;   #define cout_dec cout << fixed << setprecision(9)    #define casepr(ti)  cout<< case # <<ti+1<< :     #define fill(a,b) memset(a, b, sizeof(a))   ll pow1(ll n,ll p)   {   if(p==0) return 1;    ll x=pow1(n, p/2);   x=(x*x)%mo;   if(p%2==0)   return x;   else   return (x*n)%mo;   }   bool sortbysec(const pair<ll,ll> &a,    const pair<ll,ll> &b)    {    return (a.second < b.second);    }    bool compare(const pair<ll, ll>&p1, const pair<ll,ll>&p2)   {   if(p1.ff < p2.ff) return true;   if(p1.ff == p2.ff) return p1.ff < p2.ss;   return false;   }   ll const maxn=200007;   ll nxt[maxn];   void seive()   {         for (ll i = 2; i < maxn; ++i) {           if (nxt[i] == 0) {               nxt[i] = i;               for (ll j = i * i; j < maxn; j += i) {                   if(j>=maxn)                   {                       break;                   }                   if (nxt[j] == 0) nxt[j] = i;               }           }       }   }   int main()   {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);          int test=1;       cin>>test;       for(int ti=0;ti<test;ti++)       {           ll i,j,k,e,f,n,c=0,x=0;           cin>>n;           ll m=n+2;           ll b[n+2];           fr(i,0,n+2)           cin>>b[i];           sort(b,b+m);           fr(i,0,n)           {               c=c+b[i];           }           if(c== b[n] || c==b[n+1])           {               fr(i,0,n)               {                   cout<<b[i]<<   ;                  }                               nn                   continue;           }           x=-1;           fr(i,0,n)           {               if(c-b[i]+b[n]==b[n+1])               {                   x=i;                   break;               }           }           if(x==-1)           {               cout<<-1;                          }           else           {               fr(i,0,n+1)               {                   if(i==x)                   {                       continue;                   }                   cout<<b[i]<<   ;               }           }                                        nn                  }               return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300000 + 10;   int n, a[MAXN], p[MAXN];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i], p[a[i]] = i;     for (int i = 0; i < n; i++) {       for (int j = min(i + 100, n - 1); j > i; j--) {         int nx = 2 * a[j] - a[i], nxt = 2 * a[i] - a[j];         if (nx > 0 && nx <= n && p[nx] > j) return cout <<  YES  << endl, 0;         if (nxt > 0 && nxt <= n && p[nxt] < i) return cout <<  YES  << endl, 0;       }     }     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream& operator<<(ostream& os, vector<T> V) {     os <<  [  ;     for (auto v : V) os << v <<    ;     return os <<  ] ;   }   template <class T>   ostream& operator<<(ostream& os, set<T> S) {     os <<  {  ;     for (auto s : S) os << s <<    ;     return os <<  } ;   }   template <class L, class R>   ostream& operator<<(ostream& os, pair<L, R> P) {     return os <<  (  << P.first <<  ,  << P.second <<  ) ;   }   template <class L, class R>   ostream& operator<<(ostream& os, map<L, R> M) {     os <<  {  ;     for (auto m : M) os <<  (  << m.F <<  :  << m.S <<  ) ;     return os <<  } ;   }   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const int R = 65;   char G[R][R];   int solve() {     int n, m;     cin >> n >> m;     bool all = true, none = true;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         cin >> G[i][j];         if (G[i][j] ==  A )           none = false;         else           all = false;       }     }     if (all) return 0;     if (none) return -1;     bool row = true;     for (int i = 1; i <= m; ++i)       if (G[1][i] ==  P ) row = false;     if (row) return 1;     row = true;     for (int i = 1; i <= m; ++i)       if (G[n][i] ==  P ) row = false;     if (row) return 1;     row = true;     for (int i = 1; i <= n; ++i)       if (G[i][1] ==  P ) row = false;     if (row) return 1;     row = true;     for (int i = 1; i <= n; ++i)       if (G[i][m] ==  P ) row = false;     if (row) return 1;     if (G[1][1] ==  A ) return 2;     if (G[1][m] ==  A ) return 2;     if (G[n][1] ==  A ) return 2;     if (G[n][m] ==  A ) return 2;     for (int i = 2; i <= n - 1; ++i) {       bool eq = true;       for (int j = 1; j <= m; ++j) {         if (G[i][j] ==  P ) eq = false;       }       if (eq) return 2;     }     for (int i = 2; i <= m - 1; ++i) {       bool eq = true;       for (int j = 1; j <= n; ++j) {         if (G[j][i] ==  P ) eq = false;       }       if (eq) return 2;     }     bool any = false;     for (int i = 2; i <= n - 1; ++i) {       if (G[i][1] ==  A  || G[i][m] ==  A ) any = true;     }     for (int i = 2; i <= m - 1; ++i) {       if (G[1][i] ==  A  || G[n][i] ==  A ) any = true;     }     if (any) return 3;     return 4;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << fixed << setprecision(25);     int t;     cin >> t;     while (t--) {       int ans = solve();       if (ans != -1)         cout << ans <<   n ;       else         cout <<  MORTAL               <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define     mod     1000000007   #define     int      long long    #define     pb      push_back   #define     endl      n    #define     ff      first   #define     ss      second   #define     FIO     ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);   #define     all(x)  (x).begin(),(x).end()   int32_t main()   {         FIO         int t; cin >> t;         while(t--)         {               int n, x, t; cin >> n >> x >> t;               if(x > t) cout << 0 << endl;               else                {                     int a = t/x;                     int ans=0;                     if(a>n)                           ans+= (n*(n-1))/2;                     else                     {                           ans+= (n-a) * a;                           ans+= (a*(a-1))/2;                     }                     cout << ans << endl;               }         }   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 2e5 + 7;   long long parent[MAXN], rank1[MAXN];   vector<pair<long long, pair<long long, long long>>> edges;   void makest(long long v) {     parent[v] = v;     rank1[v] = 0;   }   long long find(long long v) {     if (v == parent[v]) return v;     return parent[v] = find(parent[v]);   }   void merge(long long a, long long b) {     a = find(a);     b = find(b);     if (a != b) {       if (rank1[a] < rank1[b]) swap(a, b);       parent[b] = a;       if (rank1[a] == rank1[b]) rank1[a]++;     }   }   signed main() {     long long n, m, mini = 1e14, node, ans = 0;     cin >> n >> m;     long long a[n + 1];     for (long long i = 1; i <= n; ++i) {       cin >> a[i];       if (mini > a[i]) {         mini = a[i];         node = i;       }     }     for (long long i = 1; i <= n; ++i) {       makest(i);     }     long long x, y, z;     for (long long i = 1; i <= m; ++i) {       cin >> x >> y >> z;       edges.push_back({z, {x, y}});     }     for (long long i = 1; i <= n; ++i) {       if (i != node) {         edges.push_back({mini + a[i], {i, node}});       }     }     sort(edges.begin(), edges.end());     for (auto t : edges) {       x = t.second.first;       y = t.second.second;       z = t.first;       if (find(x) != find(y)) {         ans += z;         merge(x, y);       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, n, k, h;   int main() {     int arr[3];     cin >> arr[0] >> arr[1] >> arr[2];     int y = 1, b = 2, r = 3;     while (y < arr[0] && b < arr[1] && r < arr[2]) {       y++;       r++;       b++;     }     cout << y + b + r;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10, SQ = 780;   const long long inf = 1e18;   long long dp[2][SQ];   vector<int> v[maxn];   int n, m;   long long ans;   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       if ((a = n + 1 - a) >= (SQ - 1))         ans += 3;       else         v[b].push_back(a);     }     for (int i = 1; i < SQ; i++) dp[0][i] = inf;     dp[0][0] = 0;     for (int i = 1; i <= n; i++) {       dp[i & 1][SQ - 1] = inf;       sort(v[i].begin(), v[i].end());       int num = 0;       for (int j = SQ - 2; j >= 0; j--) {         dp[i & 1][j] = min(dp[i & 1][j + 1],                            num + min(dp[(i + 1) & 1][0] + (j == 0 ? 0 : 2) +                                          1ll * ((j * (j + 1)) / 2),                                      dp[(i + 1) & 1][j + 1]));         if (!v[i].empty() && v[i].back() == j) num += 3, v[i].pop_back();       }     }     ans += dp[n & 1][0];     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long modex(long long a, long long b) {     long long ans = 1LL;     while (b) {       if (b % 2) {         ans *= a;         ans %= 1000000009;       }       a *= a;       a %= 1000000009;       b /= 2LL;     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m, x, y;     cin >> n >> m;     if (m <= 20) {       x = 1LL << m;       if (x <= n) {         cout << 0 <<   n ;         return 0;       }     }     x = modex(2LL, m);     y = 1LL;     for (int i = 1; i <= n; i++) {       if (i >= x)         y *= (x - i + 1000000009);       else         y *= (x - i);       y %= 1000000009;     }     cout << y <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b;       cin >> a >> b;       if ((abs(a - b)) % 2) {         cout << -1 << endl;         continue;       }       if (a == b && b == 0) {         cout << 0 << endl;         continue;       }       if (a == b)         cout << 1 << endl;       else         cout << 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int ckmax(int &a, int b) { return a < b ? a = b, 1 : 0; }   inline int ckmin(int &a, int b) { return a > b ? a = b, 1 : 0; }   int n, r, x[1010];   double y[1010];   int main() {     scanf( %d%d , &n, &r);     for (int i = 1; i <= n; ++i) {       scanf( %d , x + i);       y[i] = r;       for (int j = 1; j < i; ++j) {         if (abs(x[i] - x[j]) <= 2 * r) {           int d = abs(x[i] - x[j]);           double l = sqrt(4 * r * r - d * d);           y[i] = max(y[i], y[j] + l);         }       }       printf( %.10f  , y[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   ostream& operator<<(ostream& o, pair<A, B> a) {     return o << a.first <<     << a.second;   }   template <typename A, typename B>   istream& operator>>(istream& o, pair<A, B>& a) {     return o >> a.first >> a.second;   }   const int mod = 1e9 + 7, abc = 864197532, N = 300087, K = 111;   long long int modpow(long long int a, int b) {     long long int ans = 1;     for (; b; b >>= 1, a = a * a % mod) {       if (b & 1) ans = ans * a % mod;     }     return ans;   }   int inter(vector<int> l, vector<int> r) {     int ll = *max_element(l.begin(), l.end()),         rr = *min_element(r.begin(), r.end());     if (ll <= rr) return rr - ll + 1;     return 0;   }   void add(long long int& a, long long int b) {     a += b;     if (a >= mod) a -= mod;   }   void del(long long int& a, long long int b) {     a -= b;     if (a < 0) a += mod;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> l(n), r(n), sz(n), inv(n);     for (int i = 0; i < n; ++i) cin >> l[i];     long long int al = 1;     for (int i = 0; i < n; ++i) {       cin >> r[i];       sz[i] = r[i] - l[i] + 1;       al = al * sz[i] % mod;       inv[i] = modpow(sz[i], mod - 2);     }     long long int square = 0, sum = 0;     for (int i = 0; i + 1 < n; ++i) {       add(sum, inter({l[i], l[i + 1]}, {r[i], r[i + 1]}) * al % mod * inv[i] %                    mod * inv[i + 1] % mod);     }     square = sum;     for (int i = 0; i + 2 < n; ++i) {       add(square, inter({l[i], l[i + 1], l[i + 2]}, {r[i], r[i + 1], r[i + 2]}) *                       al % mod * inv[i] % mod * inv[i + 1] % mod * inv[i + 2] %                       mod * 2 % mod);     }     long long int now = 0;     for (int i = 0; i + 1 < n; ++i)       add(now, 1ll * inter({l[i], l[i + 1]}, {r[i], r[i + 1]}) * inv[i] % mod *                    inv[i + 1] % mod);     for (int i = 0; i + 1 < n; ++i) {       if (i - 1 >= 0)         del(now, 1ll * inter({l[i - 1], l[i]}, {r[i - 1], r[i]}) * inv[i - 1] %                      mod * inv[i] % mod);       del(now, 1ll * inter({l[i], l[i + 1]}, {r[i], r[i + 1]}) * inv[i] % mod *                    inv[i + 1] % mod);       if (i + 2 < n)         del(now, 1ll * inter({l[i + 1], l[i + 2]}, {r[i + 1], r[i + 2]}) *                      inv[i + 1] % mod * inv[i + 2] % mod);       add(square, now * inter({l[i], l[i + 1]}, {r[i], r[i + 1]}) % mod * inv[i] %                       mod * inv[i + 1] % mod * al % mod);       if (i - 1 >= 0)         add(now, 1ll * inter({l[i - 1], l[i]}, {r[i - 1], r[i]}) * inv[i - 1] %                      mod * inv[i] % mod);       add(now, 1ll * inter({l[i], l[i + 1]}, {r[i], r[i + 1]}) * inv[i] % mod *                    inv[i + 1] % mod);       if (i + 2 < n)         add(now, 1ll * inter({l[i + 1], l[i + 2]}, {r[i + 1], r[i + 2]}) *                      inv[i + 1] % mod * inv[i + 2] % mod);     }     cout << ((square + mod - sum * n * 2 % mod) * modpow(al, mod - 2) +              1ll * n * n) %                 mod;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[1005];   long long dp[1005];   long long dpsum[1005];   bool b[1005];   long long ch[1005][1005];   long long gc(int c, int x) {     if (x == 0 || c == x) return 1;     if (!ch[c][x]) {       ch[c][x] = (gc(c - 1, x - 1) + gc(c - 1, x)) % 998244353;     }     return ch[c][x];   }   int getdp(int x) {     if (!b[x]) {       b[x] = 1;       if (a[x] > 0) {         for (int i = x + a[x] + 1; i <= n + 1; ++i) {           dp[x] =               (dp[x] + gc(i - x - 2, a[x] - 1) * (1LL + dpsum[i])) % 998244353;         }       }     }     return dp[x];   }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     long long ans = 0;     for (int i = n; i >= 1; --i) {       dpsum[i] = dpsum[i + 1] + getdp(i);       dpsum[i] %= 998244353;     }     for (int i = 1; i <= n; ++i) {       ans = ans + getdp(i);       ans %= 998244353;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     short n, pos, l, r;     cin >> n >> pos >> l >> r;     if (1 == l && n == r) {       cout <<  0 ;       return 0;     }     if (1 == l) {       cout << abs(r - pos) + 1;       return 0;     }     if (n == r) {       cout << abs(pos - l) + 1;       return 0;     }     short time = 0;     if (abs(r - pos) <= abs(pos - l)) {       time += abs(r - pos) + 1;       pos = r;       time += abs(pos - l) + 1;     } else {       time += abs(pos - l) + 1;       pos = l;       time += abs(r - pos) + 1;     }     cout << time;     return 0;   }


#include<bits/stdc++.h>   using namespace std;      int main()   {       ios_base::sync_with_stdio(false);       cin.tie(NULL);              int t,n;       cin>>t;       while(t--)       {           cin>>n;           string str;           cin>>str;                      int cnt_t=0,cnt_m=0;                      for(int i=0;i<n;i++)           {               if(str[i]== T )               {                   cnt_t++;               }               else               {                   cnt_m++;               }           }                      if(cnt_t!=2*cnt_m)           {               cout<< NO <<endl;           }                      else           {               int x=0,y=0;                              int flag=0;                              // forward check                              for(int i=0;i<n;i++)               {                   if(str[i]== T )                   {                       x++;                   }                   if(str[i]== M )                   {                       y++;                   }                   if(y>x)                   {                       cout<< NO <<endl;                       flag=1;                       break;                   }               }                              if(flag==0)               {                   x=0;                   y=0;                                                         // backward check                   for(int i=n-1;i>=0;i--)                   {                       if(str[i]== T )                       {                           x++;                       }                       if(str[i]== M )                       {                           y++;                       }                       if(y>x)                       {                           cout<< NO <<endl;                           flag=1;                           break;                       }                   }               }                              if(flag==0)               {                   cout<< YES <<endl;               }           }                  }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool pal(string s) {     long long n = s.size();     for (long long i = 0; i < n / 2; i++)       if (s[i] != s[n - i - 1]) return false;     return true;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long test = 1;     while (test--) {       long long n, k, x, ab = 1e10, p, c = 0, f;       cin >> n >> k >> x;       vector<long long> v(n);       for (long long i = 0; i < n; i++) {         cin >> v[i];         if (abs(v[i]) < abs(ab)) {           ab = abs(v[i]);           p = i;         }         if (v[i] < 0) c++;       }       if (c % 2 == 0) {         f = abs(ab) / x + 1;         f = min(f, k);         k -= f;         if (v[p] < 0)           v[p] += f * x;         else           v[p] -= f * x;       }       set<pair<long long, long long> > s;       for (long long i = 0; i < n; i++) s.insert({abs(v[i]), i});       while (k > 0) {         k--;         p = s.begin()->second;         if (v[p] < 0) {           v[p] -= x;           s.erase(s.begin());           s.insert({abs(v[p]), p});         } else {           v[p] += x;           s.erase(s.begin());           s.insert({v[p], p});         }       }       for (long long i = 0; i < n; i++) cout << v[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 550;   char grid[maxn][maxn];   int rdp[maxn][maxn], cdp[maxn][maxn], dp[maxn][maxn];   int val[maxn][maxn];   int main() {     int n, m, q, c1, c2, r1, r2;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , grid[i]);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (!i)           rdp[i][j] = 0;         else {           rdp[i][j] = rdp[i - 1][j];           if (grid[i][j] ==  .  && grid[i - 1][j] ==  . ) rdp[i][j]++;         }         if (!j)           cdp[i][j] = 0;         else {           cdp[i][j] = cdp[i][j - 1];           if (grid[i][j] ==  .  && grid[i][j - 1] ==  . ) cdp[i][j]++;         }       }     }     scanf( %d , &q);     while (q--) {       scanf( %d%d%d%d , &r1, &c1, &r2, &c2);       r1--, c1--, r2--, c2--;       int ans = 0;       for (int i = r1; i <= r2; i++) ans += cdp[i][c2] - cdp[i][c1];       for (int j = c1; j <= c2; j++) ans += rdp[r2][j] - rdp[r1][j];       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     float H, L;     cin >> H >> L;     float x;     x = ((L * L) - (H * H)) / (2 * H);     printf( %0.6f , x);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100, maxp = 20;   int n, a[maxp][maxp], ma[(1 << maxp)], cur[1 << maxp], dp[1 << maxp], cnt[maxn],       f[maxp][maxn];   int ans, mp, p;   char s[maxn];   vector<int> pos[20];   void solve() {     dp[mp] = 1;     for (int i = mp; i >= 0; i--) {       if (!dp[i]) continue;       for (int j = 0; j < p; j++)         if ((i >> j) & 1) dp[(i ^ (1 << j))] = ma[(i ^ (1 << j))];     }     return;   }   void init() {     for (int i = 1; i <= n; i++) {       cnt[s[i] -  a ]++;       pos[s[i] -  a ].push_back(i);       for (int c = 0; c < p; c++) f[c][i + 1] = f[c][i] + (s[i] == ( a  + c));     }     for (int i = 0; i <= mp; i++) ma[i] = 1;     for (int i = 0; i < p; i++) {       for (int j = 0; j <= i; j++) {         memset(cur, 0, sizeof(cur));         if (a[i][j]) continue;         int pos1 = 0, pos2 = 0;         while (pos1 < pos[i].size() && pos2 < pos[j].size()) {           if (i == j && pos[i][pos1] == pos[j][pos2]) {             pos2++;             continue;           }           int m = 0;           if (pos[i][pos1] < pos[j][pos2]) {             for (int c = 0; c < p; c++) {               if (f[c][pos[j][pos2]] - f[c][pos[i][pos1] + 1] != 0) {                 m |= (1 << c);               }             }             pos1++;           } else {             for (int c = 0; c < p; c++) {               int pp1 = f[c][pos[j][pos2] + 1];               int pp2 = f[c][pos[i][pos1]];               if (f[c][pos[i][pos1]] - f[c][pos[j][pos2] + 1] != 0) {                 m = m ^ (1 << c);               }             }             pos2++;           }           if ((m >> i) & 1) continue;           if ((m >> j) & 1) continue;           m = m ^ (mp);           cur[m] = 1;         }         for (int i = 0; i <= mp; i++) cur[i] = !cur[i];         for (int ii = mp; ii > 0; ii--) {           if (cur[ii]) continue;           for (int jj = 0; jj < p; jj++) {             if (jj != i && jj != j && (ii >> jj) & 1) {               cur[(ii ^ (1 << jj))] = 0;             }           }           ma[ii] &= cur[ii];         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> p;     ans = n;     mp = (1 << p) - 1;     for (int i = 1; i <= n; i++) cin >> s[i];     for (int i = 0; i < p; i++)       for (int j = 0; j < p; j++) cin >> a[i][j];     init();     solve();     for (int i = 0; i <= mp; i++) {       int res = 0;       if (!dp[i]) continue;       for (int j = 0; j < p; j++)         if ((i >> j) & 1) {           res += cnt[j];         }       ans = min(ans, res);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long n, l, r, ans = 0;   bool kk(long long x, long long i) {     if (x == 1) {       if (i == 1)         return 1;       else         return 0;     } else {       long long t = 1, g;       while (t <= x) t *= 2;       t--;       g = t / 2;       if (g + 1 == i) {         if (x % 2)           return 1;         else           return 0;       } else {         if (i <= g)           return kk(x / 2, i);         else {           return kk(x / 2, i - g - 1);         }       }     }   }   int main() {     long long i, j;     cin >> n >> l >> r;     if (n == 0) {       cout << 0;       return 0;     }     for (i = l; i <= r; i++) {       if (kk(n, i) == 1) ans++;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 1061109567;   const long long LINF = 4557430888798830399ll;   void TestCase() {     long long d;     scanf( %lld , &d);     d %= 360;     if (d < 0) d += 360;     int ans = INF, cnt = 0;     for (int i = 0; i < 4; ++i) {       int nd = abs(d - 90 * i);       if (min(nd, 360 - nd) < ans) {         ans = min(nd, 360 - nd);         cnt = i;       }     }     printf( %d n , cnt);   }   int main() {     int t = 1;     for (int i = 1; i <= t; ++i) {       TestCase();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[3010][3010], t[3010][3010], S[3010], T[3010];   int nxt[3010], len, pos, tl, tr, p[3010], pre[3010][3010], n, len_s[3010];   void change(int id) {     int n = strlen(s[id] + 1), j = 0;     for (int i = 1; i <= n; i++) {       while (j && S[j + 1] != s[id][i]) j = nxt[j];       if (S[j + 1] == s[id][i]) j++;       if (j == len) {         for (int k = 1; k <= len; k++) s[id][i - len + k] = T[k];         break;       }     }   }   void check(int id) {     int j = 0, diff = 0;     for (int i = 1; i <= len_s[id]; i++) {       while (j && S[j + 1] != s[id][i]) j = nxt[j];       if (S[j + 1] == s[id][i]) j++;       if (j == len && pre[id][i] - pre[id][i - len]) {         p[id] = i - len + 1;         break;       } else if (j == len)         j = nxt[j];     }   }   void get_S() {     int mx = 0;     for (int i = 1; i <= tl - 1; i++) {       int flag = 1;       for (int j = 1; j <= n; j++)         if (p[j] && (p[j] - i <= 0 || s[j][p[j] - i] != s[pos][tl - i])) {           flag = 0;           break;         }       if (flag)         mx++;       else         break;     }     tl -= mx;     mx = 0;     for (int i = 1; i <= n; i++)       if (p[i]) p[i] = p[i] + len - 1;     for (int i = 1; i <= len_s[pos] - tr; i++) {       int flag = 1;       for (int j = 1; j <= n; j++)         if (p[j] && (p[j] + i > len_s[j] || s[j][p[j] + i] != s[pos][tr + i])) {           flag = 0;           break;         }       if (flag)         mx++;       else         break;     }     tr += mx;     len = tr - tl + 1;     for (int i = 1; i <= len; i++) {       S[i] = s[pos][i + tl - 1];       T[i] = t[pos][i + tl - 1];     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , s[i] + 1);       len_s[i] = strlen(s[i] + 1);     }     for (int i = 1; i <= n; i++) scanf( %s , t[i] + 1);     for (int i = 1; i <= n; i++) {       int lef = len_s[i] + 1, righ = 0;       for (int j = 1; j <= len_s[i]; j++)         if (s[i][j] != t[i][j]) {           lef = min(lef, j);           righ = max(righ, j);           pre[i][j] = pre[i][j - 1] + 1;         } else           pre[i][j] = pre[i][j - 1];       if (righ - lef + 1 > len) {         len = righ - lef + 1;         for (int j = lef; j <= righ; j++) {           S[j - lef + 1] = s[i][j];           T[j - lef + 1] = t[i][j];         }         pos = i;         tl = lef;         tr = righ;       }     }     int j = 0;     for (int i = 2; i <= len; i++) {       while (j && S[j + 1] != S[i]) j = nxt[j];       if (S[j + 1] == S[i]) j++;       nxt[i] = j;     }     for (int i = 1; i <= n; i++) check(i);     get_S();     j = 0;     for (int i = 2; i <= len; i++) {       while (j && S[j + 1] != S[i]) j = nxt[j];       if (S[j + 1] == S[i]) j++;       nxt[i] = j;     }     for (int i = 1; i <= n; i++) {       change(i);       int len = strlen(s[i] + 1);       for (int j = 1; j <= len; j++)         if (s[i][j] != t[i][j]) {           puts( NO );           return 0;         }     }     puts( YES );     puts(S + 1);     puts(T + 1);     return 0;   }


#include<bits/stdc++.h>   #define int long long   #define reg register   using namespace std;   const int maxn=5e5+5;   const int mod=1e9+7;   const int INF=2e9;   inline int read()   {       int x=0,f=1;       char ch=getchar();       while(ch< 0  || ch> 9 )       {           if(ch== - )           f=-1;           ch=getchar();       }       while(ch>= 0  && ch<= 9 )       {           x=x*10+ch- 0 ;           ch=getchar();       }       return x*f;   }   int T;   int d;   int prime[maxn];   int tot=0;   int check[maxn];   void Pre(int maxx)   {    check[1]=1;    for(int i=2;i<=maxx;i++)    {     if(check[i]==0)     prime[++tot]=i;     for(int j=1;j<=tot && prime[j]*i<=maxx;j++)     {      check[i*prime[j]]=1;      if(i%prime[j]==0)      break;     }    }   }   signed main()   {     Pre(500000);    //for(int i=1;i<=20;i++)    //cout<<prime[i]<<   ;    T=read();    //cout<<tot<<endl;    while(T--)    {     d=read();    /* if(d==2)     {      printf( 15 n );      continue;     }     else     if(d==1)     {      printf( 6 n );      continue;     }*/     int l=1,r=tot;     while(l<r)     {      int mid=(l+r)>>1;      if(prime[mid]-1>=d)      r=mid;      else      l=mid+1;     }     int ans1=l;     //cout<<ans1<<endl;     l=ans1+1,r=tot;     while(l<r)     {      int mid=(l+r)>>1;      if(prime[mid]-prime[ans1]>=d)      r=mid;      else      l=mid+1;     }     int ans2=l;     printf( %lld n ,prime[ans1]*prime[ans2]);    }    return 0;   }   /*   4   3 3 2 1   6   3 4 5 1 6 2      0   */


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int idx[2 * n + 1], chk = 2 * n;       vector<long long int> coin;       coin.push_back(0LL);       for (long long int i = 1; i <= 2 * n; i++) {         long long int x;         cin >> x;         idx[x] = i;       }       for (long long int i = 2 * n; i >= 1; i--) {         if (idx[i] <= chk) {           coin.push_back(chk - idx[i] + 1);           chk = idx[i] - 1;         }       }       long long int cost = n, coin_no = coin.size() - 1;       long long int dp[coin_no + 1][cost + 1];       memset(dp, 0, sizeof(dp));       for (long long int i = 0; i <= coin_no; i++) dp[i][0] = 1;       for (long long int i = 1; i <= coin_no; i++) {         for (long long int j = 1; j <= cost; j++) {           dp[i][j] = dp[i - 1][j];           if (coin[i] <= j) dp[i][j] |= dp[i - 1][j - coin[i]];         }       }       if (dp[coin_no][cost])         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, p[10];   map<long long, string> m;   set<long long> s[10];   template <class T>   string toString(T x) {     ostringstream os;     os << x;     return os.str();   }   int getlen(long long x) {     int ans = 0;     while (x) {       ans++;       x /= 10;     }     return max(ans, 1);   }   string get(long long x) {     if (m.count(x)) return m[x];     return toString(x);   }   void relaxPower(long long x, string str) {     if (x > n || str.length() >= getlen(x)) return;     if (m.count(x) && m[x].length() <= str.length()) return;     s[m[x].length()].erase(x);     m[x] = str;     s[str.length()].insert(x);   }   void getPowers() {     for (long long x = 2; x * x <= n; x++) {       long long rs = x * x;       int p = 2;       while (rs <= n) {         string tmp = toString(x) +  ^  + toString(p);         relaxPower(rs, tmp);         rs *= x;         p++;       }     }   }   void getPowerAndPower(int len) {     for (int i = 1; i <= len; i++)       for (int j = i; i + j + 1 <= len; j++)         for (auto x : s[i])           for (auto y : s[j]) relaxPower(x * y, get(x) +  *  + get(y));   }   void getSimpleAndPower(int len) {     for (int i = 1; i + 2 <= len; i++) {       for (long long x = 1; x < p[len - i - 1]; x++)         for (long long y : s[i]) relaxPower(x * y, toString(x) +  *  + get(y));     }   }   void precalc() {     getPowers();     getPowerAndPower(7);     getSimpleAndPower(7);   }   string ans;   void relaxAnswer(string str) {     if (str.length() < ans.length()) ans = str;   }   void checkAnswer() {     for (int i = 1; i * 2 + 1 < ans.length(); i++) {       for (long long x = 1; x <= p[i]; x++) {         relaxAnswer(get(n - x) +  +  + get(x));         if (n % x == 0) relaxAnswer(get(n / x) +  *  + get(x));       }       for (auto x : s[i]) {         relaxAnswer(get(n - x) +  +  + get(x));         if (n % x == 0) relaxAnswer(get(n / x) +  *  + get(x));       }     }   }   int main() {     p[0] = 1;     for (int i = 1; i < 10; i++) p[i] = p[i - 1] * 10;     cin >> n;     precalc();     ans = get(n);     checkAnswer();     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, v;     cin >> n >> v;     map<int, int> s;     for (int i = 1; i <= n; i++) {       long long a;       cin >> a;       for (int j = 0; j < a; j++) {         long long b;         cin >> b;         if (v > b) {           s[i] = 1;         }       }     }     cout << s.size() << endl;     for (map<int, int>::iterator it = s.begin(); it != s.end(); it++)       cout << it->first <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   enum { AABB, ABAB, ABBA, AAAA };   int n, k;   string s1, s2, s3, s4;   bool isvow(char c) {     return (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u );   }   string suf(string s) {     static int sp = 0;     auto i = s.end(), beg = s.begin();     int tk = 0;     while (tk < k && i > beg) {       --i;       tk += isvow(*i);     }     string res(i, s.end());     if (tk < k) {       res = string(sp++,    );     }     return res;   }   void foo() {     cout <<  NO n ;     exit(0);   }   int main(void) {     int i;     cin >> n >> k;     int ans = AAAA;     for (i = 0; i < n; ++i) {       cin >> s1 >> s2 >> s3 >> s4;       auto suf1 = suf(s1), suf2 = suf(s2), suf3 = suf(s3), suf4 = suf(s4);       if (suf1 == suf2 && suf2 == suf3 && suf3 == suf4) {       } else if (suf1 == suf2 && suf3 == suf4) {         if (ans == AAAA || ans == AABB) {           ans = AABB;         } else {           foo();         }       } else if (suf1 == suf3 && suf2 == suf4) {         if (ans == AAAA || ans == ABAB) {           ans = ABAB;         } else {           foo();         }       } else if (suf1 == suf4 && suf2 == suf3) {         if (ans == AAAA || ans == ABBA) {           ans = ABBA;         } else {           foo();         }       } else {         foo();       }     }     switch (ans) {       case AABB:         cout <<  aabb n ;         break;       case ABAB:         cout <<  abab n ;         break;       case ABBA:         cout <<  abba n ;         break;       case AAAA:         cout <<  aaaa n ;         break;       default:         foo();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   struct outputer;   struct outputable {};   template <typename T>   inline auto sqr(T x) -> decltype(x * x) {     return x * x;   }   template <typename T1, typename T2>   inline bool umx(T1& a, T2 b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <typename T1, typename T2>   inline bool umn(T1& a, T2 b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   const int N = 200000;   struct Input {     int n;     int a[N];     vector<int> e[N];     bool read() {       if (!(cin >> n)) {         return 0;       }       for (int i = int(0); i < int(n); ++i) {         scanf( %d , &a[i]);         --a[i];       }       for (int i = int(0); i < int(n - 1); ++i) {         int x, y;         scanf( %d%d , &x, &y);         --x;         --y;         e[x].emplace_back(y);         e[y].emplace_back(x);       }       return 1;     }     void init(const Input& input) { *this = input; }   };   struct Data : Input {     int ans;     void write() { cout << ans << endl; }   };   namespace Main {   struct Solution : Data {     int mx;     array<int, 2> calc(int v, int pr) {       array<int, 2> res{0, 0};       if (a[v] != -1) {         res[a[v]] = 1;       }       for (int to : e[v]) {         if (to == pr) {           continue;         }         array<int, 2> cur = calc(to, v);         for (int t = int(0); t < int(2); ++t) {           umx(mx, res[t] + cur[!t]);         }         for (int t = int(0); t < int(2); ++t) {           umx(res[t], cur[t]);           if (a[v] == t) {             umx(res[t], cur[!t] + 1);           }         }       }       for (int t = int(0); t < int(2); ++t) {         umx(mx, res[t]);       }       return res;     }     void solve() {       mx = 0;       calc(0, -1);       ans = mx / 2 + 1;     }     void clear() {       for (int i = int(0); i < int(n); ++i) {         e[i] = vector<int>();       }     }   };   }  // namespace Main   Main::Solution sol;   int main() {     cout.setf(ios::showpoint | ios::fixed);     cout.precision(20);     int t;     cin >> t;     for (int i = int(0); i < int(t); ++i) {       sol.read();       sol.solve();       sol.write();       sol.clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 400010;   vector<pair<int, long long> > forc[N];   vector<pair<int, pair<int, long long> > > other[N];   vector<pair<int, pair<int, long long> > > centroid[N];   long long dist[N];   int sub[N];   bool alive[N];   int belongs[N];   vector<pair<int, int> > g[N];   int perm[N], pos[N];   int v_goes_to[N];   vector<int> all;   void dfs(int v, int pr) {     all.push_back(v);     sub[v] = 1;     int sz = g[v].size();     for (int j = 0; j < sz; j++) {       int u = g[v][j].first;       if (!alive[u] || u == pr) {         continue;       }       int len = g[v][j].second;       dist[u] = dist[v] + len;       belongs[u] = (belongs[v] == -1 ? u : belongs[v]);       dfs(u, v);       sub[v] += sub[u];     }   }   void build(int v) {     all.clear();     dfs(v, -1);     {       int old_v = v;       int total = sub[v];       int pr = -1;       while (true) {         bool found = false;         int sz = g[v].size();         for (int j = 0; j < sz; j++) {           int u = g[v][j].first;           if (!alive[u] || u == pr) {             continue;           }           if (2 * sub[u] >= total) {             pr = v;             v = u;             found = true;             break;           }         }         if (!found) {           break;         }       }       v_goes_to[old_v] = v;     }     all.clear();     dist[v] = 0;     belongs[v] = -1;     dfs(v, -1);     int cnt = all.size();     for (int i = 0; i < cnt; i++) {       int u = all[i];       centroid[u].push_back(make_pair(v, make_pair(belongs[u], dist[u])));     }     for (int i = 0; i < cnt; i++) {       int u = all[i];       forc[v].push_back(make_pair(pos[u], dist[u]));     }     sort(forc[v].begin(), forc[v].end());     for (int j = 1; j < cnt; j++) {       forc[v][j].second += forc[v][j - 1].second;     }     for (int i = 1; i < cnt; i++) {       int u = all[i];       other[v].push_back(make_pair(belongs[u], make_pair(pos[u], dist[u])));     }     sort(other[v].begin(), other[v].end());     for (int j = 1; j < cnt - 1; j++) {       other[v][j].second.second += other[v][j - 1].second.second;     }     vector<int> children;     for (int i = 0; i < cnt; i++) {       int u = all[i];       if (belongs[u] == u) {         children.push_back(u);       }     }     alive[v] = false;     for (int i = 0; i < (int)children.size(); i++) {       build(children[i]);     }   }   int main() {     int n, tt;     scanf( %d %d , &n, &tt);     for (int i = 0; i < n; i++) {       scanf( %d , perm + i);       perm[i]--;       pos[perm[i]] = i;     }     for (int i = 0; i < n - 1; i++) {       int x, y, z;       scanf( %d %d %d , &x, &y, &z);       x--;       y--;       g[x].push_back(make_pair(y, z));       g[y].push_back(make_pair(x, z));     }     for (int i = 0; i < n; i++) {       alive[i] = true;     }     build(0);     int last = 0;     while (tt--) {       int com;       scanf( %d , &com);       if (com == 1) {         int from, to, ver;         scanf( %d %d %d , &from, &to, &ver);         from ^= last;         to ^= last;         ver ^= last;         from--;         to--;         ver--;         long long ans = 0;         for (pair<int, pair<int, long long> > p : centroid[ver]) {           int v = p.first;           int bel = p.second.first;           long long d = p.second.second;           long long sumd = 0;           int cnt = 0;           {             int pf = lower_bound(forc[v].begin(), forc[v].end(),                                  make_pair(from, -1LL)) -                      forc[v].begin();             int pt = lower_bound(forc[v].begin(), forc[v].end(),                                  make_pair(to + 1, -1LL)) -                      forc[v].begin();             if (pf < pt) {               sumd += forc[v][pt - 1].second;               if (pf > 0) {                 sumd -= forc[v][pf - 1].second;               }               cnt += pt - pf;             }           }           {             int pf = lower_bound(other[v].begin(), other[v].end(),                                  make_pair(bel, make_pair(from, -1LL))) -                      other[v].begin();             int pt = lower_bound(other[v].begin(), other[v].end(),                                  make_pair(bel, make_pair(to + 1, -1LL))) -                      other[v].begin();             if (pf < pt) {               sumd -= other[v][pt - 1].second.second;               if (pf > 0) {                 sumd += other[v][pf - 1].second.second;               }               cnt -= pt - pf;             }           }           ans += sumd + cnt * d;         }         printf( %lld n , ans);         last = ans & ((1 << 30) - 1);       } else {         int x;         scanf( %d , &x);         x ^= last;         x--;         int v1 = perm[x];         int v2 = perm[x + 1];         int c1 = centroid[v1].size();         int c2 = centroid[v2].size();         int i1 = 0;         int i2 = 0;         while (i1 < c1 && i2 < c2 &&                centroid[v1][i1].first == centroid[v2][i2].first) {           pair<int, pair<int, long long> > p = centroid[v1][i1];           int v = p.first;           int bel1 = p.second.first;           int bel2 = centroid[v2][i2].second.first;           long long d2 = centroid[v2][i2].second.second;           {             int at = lower_bound(forc[v].begin(), forc[v].end(),                                  make_pair(pos[v1], -1LL)) -                      forc[v].begin();             forc[v][at].second = (at == 0 ? 0LL : forc[v][at - 1].second) + d2;           }           {             if (bel1 == bel2) {               int at = lower_bound(other[v].begin(), other[v].end(),                                    make_pair(bel1, make_pair(pos[v1], -1LL))) -                        other[v].begin();               other[v][at].second.second =                   (at == 0 ? 0LL : other[v][at - 1].second.second) + d2;             } else {               if (v != v1) {                 int at = lower_bound(other[v].begin(), other[v].end(),                                      make_pair(bel1, make_pair(pos[v1], -1LL))) -                          other[v].begin();                 other[v][at].second.first = pos[v2];               }               if (v != v2) {                 int at = lower_bound(other[v].begin(), other[v].end(),                                      make_pair(bel2, make_pair(pos[v2], -1LL))) -                          other[v].begin();                 other[v][at].second.first = pos[v1];               }             }           }           i1++;           i2++;         }         for (int rot = 0; rot < 2; rot++) {           while (i1 < c1) {             pair<int, pair<int, long long> > p = centroid[v1][i1];             int v = p.first;             int bel = p.second.first;             {               int at = lower_bound(forc[v].begin(), forc[v].end(),                                    make_pair(pos[v1], -1LL)) -                        forc[v].begin();               forc[v][at].first = pos[v2];             }             if (v != v1) {               int at = lower_bound(other[v].begin(), other[v].end(),                                    make_pair(bel, make_pair(pos[v1], -1LL))) -                        other[v].begin();               other[v][at].second.first = pos[v2];             }             i1++;           }           swap(v1, v2);           swap(c1, c2);           swap(i1, i2);         }         swap(perm[x], perm[x + 1]);         pos[perm[x]] = x;         pos[perm[x + 1]] = x + 1;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, A, B, inf = 1e9, f[110][110], x, y, K, g[110][110], Cnt[110],                   d[110][110];   bool vis[110][110], V[110][110], Must[110][110];   vector<int> E1[110], E2[110], E[110][110];   queue<pair<int, int> > h;   void read(int &x) {     char ch = getchar();     int mark = 1;     for (; ch !=  -  && (ch <  0  || ch >  9 ); ch = getchar())       ;     if (ch ==  - ) mark = -1, ch = getchar();     for (x = 0; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch - 48;     x *= mark;   }   int main() {     read(n);     read(m);     read(A);     read(B);     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) f[i][j] = f[j][i] = inf;     for (int i = 1; i <= m; i++) {       read(x);       read(y);       f[x][y] = 1;       E1[x].push_back(y);       E2[y].push_back(x);     }     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) f[i][j] = min(f[i][j], f[i][k] + f[k][j]);     read(K);     for (int i = 1; i <= K; i++) {       read(x);       read(y);       int dis = f[x][y];       if (dis == inf) continue;       memset(Cnt, 0, sizeof(Cnt));       for (int j = 1; j <= n; j++)         if (f[x][j] + f[j][y] == dis) {           V[i][j] = 1;           Cnt[f[x][j]]++;           for (int k = 0; k < E1[j].size(); k++) {             int v = E1[j][k];             if (f[x][j] + 1 + f[v][y] == dis) E[i][v].push_back(j), d[i][j]++;           }         }       for (int j = 1; j <= n; j++)         if (V[i][j] && Cnt[f[x][j]] == 1) Must[i][j] = 1;     }     for (int i = 1; i <= K; i++)       if (V[i][B]) {         vis[B][i] = 1, g[B][i] = 1;         h.push(make_pair(B, i));       }     for (int _ = 1; _ <= K; _++) {       while (h.size()) {         pair<int, int> now = h.front();         h.pop();         int u = now.first, x = now.second;         for (int i = 0; i < E[x][u].size(); i++) {           int v = E[x][u][i];           d[x][v]--;           if (d[x][v] == 0 && !vis[v][x]) {             vis[v][x] = 1;             g[v][x] = g[u][x];             h.push(make_pair(v, x));           }         }       }       for (int i = 1; i <= K; i++)         if (vis[A][i] && Must[i][A]) {           printf( %d n , _);           return 0;         }       for (int i = 1; i <= n; i++)         for (int j = 1; j <= K; j++)           if (vis[i][j] && Must[j][i] && g[i][j] == _) {             for (int k = 1; k <= K; k++)               if (!vis[i][k] && V[k][i]) {                 g[i][k] = g[i][j] + 1;                 vis[i][k] = 1;                 h.push(make_pair(i, k));               }           }     }     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string S;   signed long long mo = 1000000007;   int N;   string qs[100005];   signed long long memo[20][100005];   signed long long dig[20][100005];   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> qs[0];     cin >> N;     N++;     qs[0] =  0->  + qs[0];     for (i = 1; i < N; i++) cin >> qs[i];     for (i = 0; i < 10; i++) memo[i][N] = i, dig[i][N] = 10;     for (i = N - 1; i >= 0; i--) {       for (j = 0; j < 10; j++)         memo[j][i] = memo[j][i + 1], dig[j][i] = dig[j][i + 1];       int from = qs[i][0] -  0 ;       memo[from][i] = 0;       dig[from][i] = 1;       for (j = qs[i].size() - 1; j >= 3; j--) {         int nn = qs[i][j] -  0 ;         memo[from][i] = (memo[from][i] + memo[nn][i + 1] * dig[from][i]) % mo;         dig[from][i] = (dig[from][i] * dig[nn][i + 1]) % mo;       }     }     cout << memo[0][0] << endl;   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false);     for (i = 0; i < argc - 1; i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < s.size(); i++) ungetc(s[s.size() - 1 - i], stdin);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double pi = acos(-1);   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int N = 2e5 + 5;   int n, m, idx;   char s[N], ans[N];   bool st[10];   set<int> all;   bool check(int x) {     if (x == 2) return 0;     for (int i = 2; i <= x / i; ++i)       if (x % i == 0) return 1;     return 0;   }   void dfs(int i, int sum) {     if (i > n) {       all.insert(sum);       return;     }     ans[++idx] = s[i];     dfs(i + 1, sum * 10 + s[i] -  0 );     --idx;     dfs(i + 1, sum);   }   int main() {     st[2] = st[3] = st[5] = st[7] = 1;     int t;     cin >> t;     while (t--) {       cin >> n >> s + 1;       int cnt[10] = {0};       idx = 0;       for (int i = 1; i <= n; ++i) {         if (!st[s[i] -  0 ]) {           ans[++idx] = s[i];           goto out;         }       }       for (int i = 1; i <= n; ++i) {         cnt[s[i] -  0 ]++;         if (cnt[s[i] -  0 ] > 1) {           ans[++idx] = s[i];           ans[++idx] = s[i];           goto out;         }       }       all.clear();       dfs(1, 0);       for (int i : all)         if (check(i)) {           int k = i;           while (k) {             ans[++idx] = k % 10 +  0 ;             k /= 10;           }           reverse(ans + 1, ans + 1 + idx);           break;         }     out:       printf( %d n , idx);       for (int i = 1; i <= idx; ++i) printf( %c , ans[i]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> a[100001];   long long start = 0;   long long h;   long long res;   long long c[100001];   long long n;   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> h;     for (int i = 1; i <= n; ++i) {       cin >> a[i].first;       a[i].second = i;     }     sort(a + 1, a + n + 1);     res = a[n].first + a[n - 1].first - a[1].first - a[2].first;     for (int i = n; i >= 2; --i) {       long long curmax, curmin;       if (i == n)         curmax =             max(a[n].first + a[n - 1].first + h, a[n - 1].first + a[n - 2].first);       else         curmax =             max(a[n].first + a[n - 1].first, a[n].first + a[i - 1].first + h);       if (i != 2)         curmin = min(a[i].first + a[1].first + h, a[1].first + a[2].first);       else         curmin = min(a[2].first + a[1].first + h, a[2].first + a[3].first);       long long curdif = curmax - curmin;       if (curdif < res) {         res = curdif;         start = i - 1;       }     }     for (int i = 1; i <= start; ++i) {       c[a[i].second] = 1;     }     cout << res << endl;     for (int i = 1; i <= n; ++i) {       if (c[i])         cout << c[i] <<    ;       else         cout << 2 <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   clock_t timeStart, timeFinish;   void timeBegin() { timeStart = clock(); }   void timeEnd() { timeFinish = clock(); }   void timeDuration() {     double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC);     cout <<  Time taken by program is :   << fixed << time_taken          << setprecision(5);     cout <<   sec   << endl;   }   int blo[1000005];   bool fun(const pair<pair<int, int>, int> &x,            const pair<pair<int, int>, int> &y) {     if (blo[x.first.first] != blo[y.first.first]) {       return blo[x.first.first] < blo[y.first.first];     }     if (blo[x.first.first] % 2) {       return x.first.second > y.first.second;     } else {       return x.first.second < y.first.second;     }   }   void solve() {     int n;     cin >> n;     int x[n + 3], y[n + 3];     vector<pair<pair<int, int>, int>> v;     for (int i = 1; i <= n; i++) {       cin >> x[i] >> y[i];       v.push_back({{x[i], y[i]}, i});     }     for (int i = 0; i <= 1000000; i++) {       blo[i] = i / 1000;     }     sort(v.begin(), v.end(), fun);     for (int i = 0; i < n; i++) cout << v[i].second <<    ;     cout <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) solve();     return 0;   }