#include <bits/stdc++.h>   using namespace std;   const int N = 100;   int gi() {     int w = 0;     bool q = 1;     char c = getchar();     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     if (c ==  - ) q = 0, c = getchar();     while (c >=  0  && c <=  9 ) w = w * 10 + c -  0 , c = getchar();     return q ? w : -w;   }   const int mod = 1e9 + 7;   int f[N][N], g[N][N];   int inv[N];   inline void inc(int &x, int y) { (x += y) >= mod ? x -= mod : 0; }   inline int C(int n, int m) {     n += m - 1;     int ans = 1;     for (int i = 1; i <= m; i++)       ans = 1LL * ans * (n - i + 1) % mod * inv[i] % mod;     return ans;   }   int main() {     int n = gi(), m = gi(), i, j, k, t, s, lim = n + 1;     for (inv[0] = inv[1] = 1, i = 2; i < N; i++)       inv[i] = mod - 1LL * (mod / i) * inv[mod % i] % mod;     f[0][1] = 1;     for (i = 0; i <= n; i++)       for (j = 0; j <= lim; j++) {         if (f[i][j])           for (k = 0; k <= i && k + i <= n; k++)             for (t = 0; t <= lim; t++) {               if (k == i)                 if (t < j)                   inc(g[i + k + 1][t], 2LL * f[i][j] * f[k][t] % mod);                 else if (t == j)                   inc(g[i + k + 1][j], 1LL * f[i][j] * f[k][t] % mod);                 else                   break;               else                 inc(g[i + k + 1][min(j, t)], 2LL * f[i][j] * f[k][t] % mod);             }         if (g[i][j])           for (k = n - i; k >= 0; k--)             for (t = lim - j; t >= 0; t--)               if (f[k][t])                 for (s = min((n - k) / i, (lim - t) / j); s; s--)                   inc(f[k + i * s][t + j * s],                       1LL * f[k][t] * C(g[i][j], s) % mod);       }     printf( %d n , f[n][m]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (~scanf( %d , &n)) {       printf( %d n , n);       for (int i = 1; i <= n; i++) printf( 1  );       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool compare(const pair<long long, long long> &a,                const pair<long long, long long> &b) {     return a.second > b.second;   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     long long i, j;     string s;     cin >> s;     long long n = s.length();     long long f = 1;     if (n < 4) {       cout << 0;     } else {       long long sm = 0;       long long fsm = 0;       for (i = 0; i < n - 3; i++) {         if (s[i] ==  b  && s[i + 1] ==  e  && s[i + 2] ==  a  &&             s[i + 3] ==  r ) {           sm = i + 1;         }         fsm += sm;       }       cout << fsm;     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     long long ar[n];     for (long long i = 0; i < n; i++) cin >> ar[i];     sort(ar, ar + n);     long long dist = 0;     for (long long i = 0; i < n; i++) dist += (long long)abs(ar[i] - (i + 1));     cout << dist <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long T = 1;     while (T--) solve();     return 0;   }


#include <cstdio>   #include <cstring>   #include <iostream>   #include <algorithm>      using namespace std;      const int N = 100000;      long long n;      struct ab   {    long long a;    long long b;    bool operator < (const struct ab &c) const    {     return b < c.b;    }   } aa[N + 5];   long long sus[N + 5];      int main()   {    scanf( %lld , &n);    long long su = 0;    for (int i = 1; i <= n; ++i)    {     scanf( %lld%lld , &aa[i].a, &aa[i].b);     su += aa[i].a;    }    sort(aa + 1, aa + n + 1);    sus[n + 1] = 0;    for (int i = n; i >= 1; --i)    {     sus[i] = sus[i + 1] + aa[i].a;    }    long long ans = 0;    long long p = 0, ext = 0;    for (int i = 1; i <= n; ++i)    {     long long cc = aa[i].b - (p + ext);     if (sus[i + 1] <= ext)     {      if (aa[i].b <= p + ext)      {       ans += aa[i].a - (ext - sus[i + 1]);      }      else if (aa[i].b <= p + ext + aa[i].a - (ext - sus[i + 1]))      {       ans += p + ext + aa[i].a - (ext - sus[i + 1]) - aa[i].b;       ans += 2 * cc;      }      else      {       ans += 2 * (aa[i].a - (ext - sus[i + 1]));      }      break;     }     else if (aa[i].b <= p + ext)     {      ans += aa[i].a;      p += aa[i].a;     }     else if (sus[i + 1] - ext >= cc)     {      ans += 2 * cc;      ext += cc;      ans += aa[i].a;      p += aa[i].a;     }     else     {      ans += 2 * (sus[i + 1] - ext);      cc -= sus[i + 1] - ext;      if (cc >= aa[i].a)      {       ans += 2 * aa[i].a;      }      else      {       ans += 2 * cc + (aa[i].a - cc);      }      break;     }    }       // for (int i = 1; i <= n; ++i)   // {   //  if (aa[i].b >= su)   //  {   //   ans += 2 * (su - p - ext);   //   break;   //  }   //  else if (aa[i].b <= p + ext)   //  {   //   ans += aa[i].a;   //   p += aa[i].a;   //  }   //  else if (sus[i + 1] >= aa[i].b - p)   //  {   //   ans += 2 * (aa[i].b - p - ext);   //   ext += aa[i].b - p - ext;   //   ans += aa[i].a;   //   p += aa[i].a;   //  }   //  else if (sus[i + 1] < aa[i].b - p - ext)   //  {   //   ans +=    //  }   // }        printf( %lld , ans);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int iinf = 1e9 + 7;   const long long linf = 1ll << 60;   const double dinf = 1e10;   template <typename T>   inline void scf(T &x) {     bool f = 0;     x = 0;     char c = getchar();     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     if (c ==  - ) {       f = 1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     if (f) x = -x;     return;   }   template <typename T1, typename T2>   void scf(T1 &x, T2 &y) {     scf(x);     return scf(y);   }   template <typename T1, typename T2, typename T3>   void scf(T1 &x, T2 &y, T3 &z) {     scf(x);     scf(y);     return scf(z);   }   const int N = 233;   int n, l, k;   int p[N], a[N];   double dp[N][N][N * 2];   int main() {     scf(n, l, k);     for (int i = (1); i <= (n); i++) scf(p[i]);     for (int i = (1); i <= (n); i++) scf(a[i]);     dp[0][0][k + 200] = 1.0;     for (int i = 0; i < (n); i++)       for (int j = (0); j <= (i); j++)         for (int k = (0); k <= (400); k++)           if (dp[i][j][k] > 1e-20) {             dp[i + 1][j][k] += dp[i][j][k] * (1.0 * (100 - p[i + 1]) / 100.0);             int nxtk = k;             if (a[i + 1] < 0)               nxtk--;             else               nxtk += a[i + 1];             if (nxtk > 400) nxtk = 400;             if (k >= 0)               dp[i + 1][j + 1][nxtk] += dp[i][j][k] * (1.0 * p[i + 1] / 100.0);           }     double ans = 0.0;     for (int j = (l); j <= (n); j++)       for (int k = (200); k <= (400); k++) ans += dp[n][j][k];     printf( %.12f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<int> v1(n), v2(m);       vector<int> v;       for (auto &x : v1) cin >> x;       for (auto &x : v2) cin >> x;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) {           if (v1[i] == v2[j]) v.push_back(v1[i]);         }       if (v.size()) {         cout <<  Yes  <<   n ;         cout << 1 <<     << v[0] <<   n ;       } else         cout <<  No  <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static int LOCAL = 0;   const long long int mod = 1000000007ll;   const long long int MOD = 1000000009ll;   const long long int INF = LLONG_MAX / 10;   const int inf = INT_MAX / 10;   long long int powermod(long long int _a, long long int _b,                          long long int _m = mod) {     long long int _r = 1;     while (_b) {       if (_b % 2 == 1) _r = (_r * _a) % _m;       _b /= 2;       _a = (_a * _a) % _m;     }     return _r;   }   long long int power(long long int _a, long long int _b) {     long long int _r = 1;     while (_b) {       if (_b % 2 == 1) _r = (_r * _a);       _b /= 2;       _a = (_a * _a);     }     return _r;   }   long long int add(long long int a, long long int b, long long int m = mod) {     long long int x = a + b;     while (x >= m) x -= m;     return x;   }   long long int sub(long long int a, long long int b, long long int m = mod) {     long long int x = a - b;     while (x < 0) x += m;     return x;   }   long long int mul(long long int a, long long int b, long long int m = mod) {     return ((a % m) * (b % m)) % m;   }   long long int gcd(long long int a, long long int b) {     while (a && b) a > b ? a %= b : b %= a;     return a + b;   }   long long int lcm(long long int a, long long int b) {     return (max(a, b) / gcd(a, b)) * min(a, b);   }   struct pair_hash {     std::size_t operator()(const std::pair<int, int> &p) const {       auto h1 = std::hash<long long int>{}(p.first);       auto h2 = std::hash<long long int>{}(p.second);       return (int)add(h1, mul(h2, h1, MOD));     }   };   struct cmp {     bool operator()(pair<int, pair<long long int, long long int> > const &l,                     pair<int, pair<long long int, long long int> > const &r) {       return l.second.first < r.second.first;     }   } myobject;   multiset<int> second;   int main() {     int n, x;     cin >> n;     double sum = 0;     for (int i = 1; i <= n; i++) scanf( %d , &x), second.insert(x), sum += x;     double avg = sum / n;     int cnt = 0;     while (!(avg >= 4.50)) {       x = *second.begin();       second.erase(second.begin());       sum -= x;       sum += 5;       avg = sum / n;       cnt++;     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool way[5003][5003];   int dis[5003], counter;   vector<pair<int, int> > edge[5003], child[5003];   priority_queue<pair<int, int> > pq[5003];   void cari(int pos) {     int j, sz;     sz = edge[pos].size();     for (j = 0; j < sz; ++j) {       if (way[pos][edge[pos][j].first]) {         way[pos][edge[pos][j].first] = false;         way[edge[pos][j].first][pos] = false;         child[pos].push_back(edge[pos][j]);         cari(edge[pos][j].first);       }     }   }   void cek(int posisi, int time) {     int i, j, x, size, sz;     sz = child[posisi].size();     for (i = 0; i < sz; ++i) {       x = child[posisi][i].first;       size = child[posisi][i].second;       for (j = 0; j < size; ++j) {         if (pq[x].empty()) break;         pq[posisi].push(pq[x].top());         if (posisi == 1) {           dis[pq[x].top().second] = time;           ++counter;         }         pq[x].pop();       }       cek(x, time);     }   }   int main() {     int i, a, b, c, n, sz, arrive, dummy, division[5003];     scanf( %d , &n);     for (i = 1; i <= n; ++i) scanf( %d , &division[i]);     memset(way, true, sizeof(way));     for (i = 1; i < n; ++i) {       scanf( %d %d %d , &a, &b, &c);       edge[a].push_back(make_pair(b, c));       edge[b].push_back(make_pair(a, c));     }     cari(1);     for (i = 2; i <= n; ++i) pq[i].push(make_pair(-division[i], i));     sz = child[1].size();     dis[1] = 0;     int temp = 1;     counter = 1;     while (counter < n) {       cek(1, temp);       ++temp;     }     for (i = 1; i <= n; ++i) {       if (i != n)         printf( %d  , dis[i]);       else         printf( %d n , dis[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long GCD(long long a, long long b) {     if (b == 0) return a;     return (a % b == 0 ? b : GCD(b, a % b));   }   long long POW(long long base, long long exp) {     long long val;     val = 1;     while (exp > 0) {       if (exp % 2 == 1) {         val = (val * base) % 1000000007;       }       base = (base * base) % 1000000007;       exp = exp / 2;     }     return val;   }   int a[100005];   int pos[100005];   int main() {     int n, i, c, mx;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (i = 1; i <= n; i++) {       pos[a[i]] = i;     }     mx = 0;     for (i = 1; i <= n; i++) {       c = 1;       while (i < n && pos[i + 1] > pos[i]) {         i++;         c++;       }       mx = max(mx, c);     }     printf( %d n , n - mx);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int maxn = 2e5 + 10, mod = 1e9 + 7, inf = 0x3f3f3f3f;   int n, a[maxn];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int _t;     cin >> _t;     while (_t--) {       cin >> n;       for (int i = 1; i <= n; i++) cin >> a[i];       bool isok = true;       sort(a + 1, a + 1 + n);       for (int i = 2; i <= n; i++)         if (a[i] - a[i - 1] > 1) isok = false;       (isok ? cout <<  YES n  : cout <<  NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000ll * 1000 * 1000 + 7;   int main() {     vector<string> name;     string str;     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> str;       name.push_back(str);     }     long long ans = 1ll;     for (int i = 0; i < m; i++) {       set<char> s;       for (int j = 0; j < n; j++) s.insert(name[j][i]);       ans = (ans * s.size()) % mod;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 10;   int T, n, m, sum, du[maxn], K;   vector<pair<int, int> > p[maxn];   struct node {     int x, y;     long long val;     bool operator<(const node i) const { return val < i.val; }   } a[maxn];   queue<int> q2;   int b[maxn], cnt;   long long dis[1000][1000];   long long ans[maxn], sum1, INF;   int main() {     cin >> n >> m >> K;     for (int i = 1; i <= m; i++) {       scanf( %d %d %lld , &a[i].x, &a[i].y, &a[i].val);     }     sort(a + 1, a + m + 1);     int Mx = min(m, K);     memset(dis, 0x3f, sizeof(dis));     INF = dis[0][0];     for (int i = 1; i <= Mx; i++) {       if (!b[a[i].x]) {         cnt++;         b[a[i].x] = cnt;       }       if (!b[a[i].y]) {         cnt++;         b[a[i].y] = cnt;       }       dis[b[a[i].x]][b[a[i].y]] = dis[b[a[i].y]][b[a[i].x]] = a[i].val;     }     for (int i = 1; i <= cnt; i++) dis[i][i] = 0;     for (int k = 1; k <= cnt; k++) {       for (int i = 1; i <= cnt; i++) {         for (int j = 1; j <= cnt; j++) {           dis[i][j] = min(dis[i][k] + dis[k][j], dis[i][j]);         }       }     }     for (int i = 1; i <= cnt; i++) {       for (int j = i + 1; j <= cnt; j++) {         if (i != j && dis[i][j] != INF) {           ans[++sum1] = dis[i][j];         }       }     }     sort(ans + 1, ans + sum1 + 1);     cout << ans[K] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct online_hull {     map<int, int> points;     long long area;     inline online_hull() {       points.clear();       area = 0;     }     inline map<int, int>::iterator prev(map<int, int>::iterator it) {       return it == points.begin() ? it : --it;     }     inline map<int, int>::iterator next(map<int, int>::iterator it) {       return it == points.end() ? it : ++it;     }     inline long long traparea(long long x1, long long y1, long long x2,                               long long y2) {       return (x2 - x1) * (y1 + y2);     }     inline long long triarea(long long x1, long long y1, long long x2,                              long long y2, long long x3, long long y3) {       return traparea(x1, y1, x2, y2) + traparea(x2, y2, x3, y3) +              traparea(x3, y3, x1, y1);     }     inline long long traparea(map<int, int>::iterator a,                               map<int, int>::iterator b) {       return traparea(a->first, a->second, b->first, b->second);     }     inline long long triarea(map<int, int>::iterator it) {       long long sum = 0;       if (it != points.begin()) sum += traparea(prev(it), it);       if (next(it) != points.end()) sum += traparea(it, next(it));       if (it != points.begin() && next(it) != points.end())         sum += traparea(next(it), prev(it));       return sum;     }     inline bool bad(map<int, int>::iterator it) {       if (points.size() < 3 || it == points.begin() || next(it) == points.end())         return false;       return triarea(it) <= 0;     }     inline bool insert(int x, int y) {       if (points.find(x) != points.end()) {         if (y <= points[x]) return false;         area -= triarea(points.find(x));         points.erase(x);       }       map<int, int>::iterator it = points.insert(make_pair(x, y)).first;       if (bad(it)) {         points.erase(it);         return false;       }       area += triarea(it);       while (bad(prev(it))) {         area -= triarea(prev(it));         points.erase(prev(it));       }       while (bad(next(it))) {         area -= triarea(next(it));         points.erase(next(it));       }       return true;     }     inline bool contains(int x, int y) {       if (points.empty()) return false;       map<int, int>::iterator first = points.begin(), last = prev(points.end());       if (x < first->first || x > last->first) return false;       if (x == first->first) return y <= first->second;       if (x == last->first) return y <= last->second;       map<int, int>::iterator it = points.lower_bound(x), p = prev(it);       return triarea(p->first, p->second, x, y, it->first, it->second) <= 0;     }   };   int Q;   online_hull upper, lower;   int main() {     scanf( %d , &Q);     while (Q-- > 0) {       int type, x, y;       scanf( %d %d %d , &type, &x, &y);       if (type == 1) {         upper.insert(x, y);         lower.insert(x, -y);       } else if (type == 2)         puts((upper.contains(x, y) && lower.contains(x, -y)) ?  YES  :  NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> id;   inline int getID(string s) {     if (id.find(s) == id.end()) {       int sz = id.size();       id[s] = sz;     }     return id[s];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, a, b, k, f;     cin >> n >> a >> b >> k >> f;     map<pair<int, int>, int> rcost;     int last = -1, sum = 0;     for (int i = 0; i < n; ++i) {       string u, v;       cin >> u >> v;       int su = getID(u);       int sv = getID(v);       if (last == su) {         rcost[pair<int, int>(min(su, sv), max(su, sv))] += b;         sum += b;       } else {         rcost[pair<int, int>(min(su, sv), max(su, sv))] += a;         sum += a;       }       last = sv;     }     vector<int> diff;     for (auto it = rcost.begin(); it != rcost.end(); it++) {       int cost = it->second;       if (cost > f) {         diff.push_back(cost - f);       }     }     sort(diff.rbegin(), diff.rend());     for (int i = 0; i < min((int)diff.size(), k); ++i) {       sum -= diff[i];     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int two(int n) { return 1 << n; }   inline void set_bit(int& n, int b) { n |= two(b); }   inline void unset_bit(int& n, int b) { n &= ~two(b); }   inline int last_bit(int n) { return n & (-n); }   template <class T>   T gcd(T a, T b) {     return (b != 0 ? gcd<T>(b, a % b) : a);   }   template <class T>   T lcm(T a, T b) {     return (a / gcd<T>(a, b) * b);   }   int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};   const double pi = 2 * acos(0.0);   const int mod = 1000000;   int main() {     std::ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     long long m, n;     cin >> m >> n;     double res = m;     for (int i = 1; i < m; i++) {       res -= pow(i / double(m), n);     }     cout << fixed << setprecision(10) << res;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   const long long inf = 0x3f3f3f3f3f3f3f3f;   const int mod = 998244353;   vector<int> ga[N], gb[N];   int n, a, b;   int ca[N], cb[N];   int dp[N][N][2];   int ha[N], hb[N];   int lfta[N], rgta[N], lftb[N], rgtb[N];   int cnta, cntb;   int faa[N][11], fab[N][11];   void dfsa(int u, int last) {     lfta[u] = ++cnta;     ha[u] = ha[last] + 1;     for (int i = 1; i < 11; i++) faa[u][i] = faa[faa[u][i - 1]][i - 1];     for (auto v : ga[u]) {       if (v == last) continue;       faa[v][0] = u;       dfsa(v, u);     }     rgta[u] = cnta;   }   void dfsb(int u, int last) {     lftb[u] = ++cntb;     hb[u] = hb[last] + 1;     for (int i = 1; i < 11; i++) fab[u][i] = fab[fab[u][i - 1]][i - 1];     for (auto v : gb[u]) {       if (v == last) continue;       fab[v][0] = u;       dfsb(v, u);     }     rgtb[u] = cntb;   }   int costa(int u, int v) {     int x = u;     if (!v) return ha[u] - 1;     for (int i = 10; i >= 0; i--) {       if (!faa[x][i]) continue;       if (lfta[faa[x][i]] <= lfta[v] && rgta[faa[x][i]] >= rgta[v]) continue;       x = faa[x][i];     }     return ha[u] - ha[x] + 1;   }   int costb(int u, int v) {     int x = u;     if (!v) return hb[u] - 1;     for (int i = 10; i >= 0; i--) {       if (!fab[x][i]) continue;       if (lftb[fab[x][i]] <= lftb[v] && rgtb[fab[x][i]] >= rgtb[v]) continue;       x = fab[x][i];     }     return hb[u] - hb[x] + 1;   }   int main() {     int i, j;     cin >> n;     cin >> a;     for (i = 2; i <= a; i++) {       int fa;       cin >> fa;       ga[i].push_back(fa);       ga[fa].push_back(i);     }     for (i = 1; i <= n; i++) cin >> ca[i];     cin >> b;     for (i = 2; i <= b; i++) {       int fa;       cin >> fa;       gb[i].push_back(fa);       gb[fa].push_back(i);     }     for (i = 1; i <= n; i++) cin >> cb[i];     dfsa(1, 0);     dfsb(1, 0);     memset(dp, 0x3f, sizeof(dp));     dp[0][0][0] = dp[0][0][1] = 0;     for (i = 1; i <= n; i++) {       for (j = 0; j < i; j++) {         dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j][0] + costa(ca[i], ca[i - 1]));         dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][1] + costb(cb[i], cb[i - 1]));         dp[i][i - 1][0] =             min(dp[i][i - 1][0], dp[i - 1][j][1] + costa(ca[i], ca[j]));         dp[i][i - 1][1] =             min(dp[i][i - 1][1], dp[i - 1][j][0] + costb(cb[i], cb[j]));       }     }     int ans = 0x3f3f3f3f;     for (i = 0; i < n; i++) {       ans = min(ans, dp[n][i][0]);       ans = min(ans, dp[n][i][1]);     }     cout << (a - 1) + (b - 1) - ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct th {     int id, num;     th() { id = 0, num = 0; }     th(int a, int b) { id = a, num = b; }     bool operator<(const th &a) const {       if (num != a.num) return num < a.num;       return id < a.id;     }   };   set<th> x;   vector<int> ns[1000005];   int n, m;   int hp[1000005];   long long dv = 0;   int a[1000005];   long long sm = 0;   void work(int bg, int n) {     if (!n)       return;     else {       if (bg == m) a[bg] = n;       while (1) {         set<th>::iterator t = x.end();         t--;         if ((*t).num < n) break;         th n1 = (*t);         x.erase(n1);         int nd = n1.num / n;         for (int j = bg; j <= m; j++)           for (int tm = 0; tm < nd; tm++) ns[j].push_back(n1.id);         sm -= nd * n;         n1.num %= n;         x.insert(n1);       }       if (bg == m) return;       set<th>::iterator q = x.begin();       int nt = sm / n;       a[bg] = (*q).num;       ns[bg].push_back((*q).id);       x.erase(q);       sm -= nt * a[bg];       if (a[bg]) {         set<th>::iterator t = x.begin();         for (int j = 1; j < nt; j++) {           th q1 = *t;           t++;           x.erase(q1);           ns[bg].push_back(q1.id);           q1.num -= a[bg];           x.insert(q1);         }       }       work(bg + 1, n - a[bg]);     }   }   int main() {     scanf( %d%d , &n, &m);     long long sum = 0;     for (int i = 1; i <= m; i++) {       scanf( %d , &hp[i]);       sum += hp[i];     }     dv = sum / n;     if (sum % n) dv++;     sum = dv * n;     sm = sum;     for (int i = 1; i < m; i++) sum -= hp[i];     hp[m] = sum;     for (int i = 1; i <= m; i++) x.insert(th(i, hp[i]));     work(1, n);     cout << dv << endl;     for (int i = 1; i <= m; i++) printf( %d  , a[i]);     printf(  n );     for (int j = 1; j <= m; j++)       while (ns[j].size() < dv) ns[j].push_back(1);     for (int i = 1; i <= dv; i++) {       for (int j = 1; j <= m; j++) printf( %d  , ns[j][i - 1]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, m;   int arr[50];   int sub[50];   int result = 0;   int task_tot_time = 0;   void take(int score, int t) {     if (0 >= t) return;     int tt = t;     int ss = score;     for (decltype(0) i = 0; i < k; i++) {       int su = sub[i];       while (su > 0) {         if (arr[i] > tt) break;         ss++;         tt -= arr[i];         su--;       }     }     result = max(result, ss);     if (t >= task_tot_time) {       int task_left = sub[0];       for (decltype(1) i = 1; i < k; i++) task_left = min(task_left, sub[i]);       if (task_left == 0) return;       for (decltype(0) i = 0; i < k; i++) sub[i]--;       result = max(result, score + k + 1);       take(score + k + 1, t - task_tot_time);     }   }   int main() {     scanf( %d , &n) == 0, scanf( %d , &k) == 0, scanf( %d , &m) == 0;     for (decltype(0) i = 0; i < k; i++) {       scanf( %d , &arr[i]) == 0;       task_tot_time += arr[i];     }     for (decltype(0) i = 0; i < k; i++) sub[i] = n;     sort(arr, arr + k);     take(0, m);     printf( %d , result);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 110;   const int MOD = 1e9 + 7;   long long n, k, dp[MAXN][MAXN][MAXN], local[MAXN][MAXN];   vector<int> adj[MAXN];   void add(long long& v, long long u) { v = (v + u) % MOD; }   void dfs(int v, int par = -1) {     dp[v][1][0] = dp[v][0][1] = 1;     for (auto i : adj[v]) {       if (i == par) continue;       dfs(i, v);       for (int w = 0; w < 23; w++)         for (int j = 0; j < 50; j++) {           local[w][j] = dp[v][w][j];           dp[v][w][j] = 0;         }       for (int a = 0; a <= (k + 1); a++)         for (int b = 0; b <= (2 * k + 1); b++)           for (int c = 0; c <= (k + 1); c++)             for (int d = 0; d <= (2 * k + 1); d++) {               int locala = 0;               if (!d) locala = b;               if (!b && d) locala = d + 1;               if (b && d) locala = min(b, d + 1);               int localb = a;               if (localb && locala) {                 if ((localb - 1 + locala - 1) <= k) localb = 0;               }               int localc = c;               if (localc) localc++;               if (localc && locala) {                 if ((locala - 1 + localc - 1) <= k) localc = 0;               }               int locald = 0;               if (!localc) locald = localb;               if (!localb && localc) locald = localc;               if (localb && localc) locald = max(localc, localb);               if (locald <= (k + 1) && locala <= (2 * k + 3))                 add(dp[v][locald][locala], local[a][b] * dp[i][c][d] % MOD);             }     }   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> k;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1);     long long answer = 0;     for (int i = 0; i <= (2 * k + 3); i++) answer = (answer + dp[1][0][i]) % MOD;     cout << answer << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long arr[200200];   int main() {     string a, b;     cin >> a >> b;     long long x = 0, y = 0;     for (int i = 0; i <= b.size() - a.size(); i++) x += (b[i] -  0 );     for (int i = 0; i < a.size(); i++) {       y += (a[i] ==  0 ) ? x : (b.size() - a.size() + 1) - x;       x += b[b.size() - a.size() + 1 + i] - b[i];     }     cout << y;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Heap(int A[], int n, int l, int r) {     int x, i, j;     x = A[l];     i = l;     while (1) {       j = 2 * i;       if (j > r) break;       if (j < r && A[j + 1] >= A[j]) j++;       if (x >= A[j]) break;       A[i] = A[j];       i = j;     }     A[i] = x;   }   void HeapSort(int A[], int n) {     int l, r, temp;     l = n / 2;     while (l >= 0) {       Heap(A, n, l, n - 1);       l--;     }     r = n - 1;     while (r >= 1) {       temp = A[0];       A[0] = A[r];       A[r] = temp;       r--;       Heap(A, n, 0, r);     }   }   int mini(int a, int b, int c = 1000000010) {     if (a <= b && a <= c)       return a;     else if (b <= c && b <= a)       return b;     else       return c;   }   int maxi(int a, int b) {     if (a > b)       return a;     else       return b;   }   unsigned long long int fac(unsigned long long int a) {     unsigned long long int r = 1;     for (int i = 2; i <= a; i++) r *= i;     return r;   }   bool issimple(unsigned long long n) {     for (unsigned long long i = 2; i <= sqrt(n); i++)       if (n % i == 0) return false;     return true;   }   unsigned long long nod(unsigned long long a, unsigned long long b) {     unsigned long long temp;     while (b) {       a %= b;       temp = a;       a = b;       b = temp;     }     return a;   }   unsigned long long nok(unsigned long long a, unsigned long long b,                          unsigned long long nod) {     return a / nod * b;   }   int main() {     int x, y, count, t, i, n, k, m;     bool flag;     cin >> t;     while (t--) {       cin >> n;       count = n / 2 + n % 2;       cout << count << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long dot(complex<long long> c1, complex<long long> c2) {     return imag(c1 * conj(c2));   }   double dot(complex<double> c1, complex<double> c2) {     return imag(c1 * conj(c2));   }   long long point(complex<long long> c1, complex<long long> c2) {     return real(c1 * conj(c2));   }   double point(complex<double> c1, complex<double> c2) {     return real(c1 * conj(c2));   }   void solve() {     long double n, pi2, alpha, res;     pi2 = acos(0.0);     cin >> n;     alpha = pi2 * (n - 1.0) / n;     res = tan(alpha);     cout << res << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t, cases;     cin >> cases;     cout << fixed << setprecision(10);     for (t = 0; t < cases; t++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 45;   int nd, nm, G[N][N];   int cntClique, pts[N], res[N], cnt[N];   map<string, int> H;   int n;   vector<int> v;   bool dfs(int pos, int num) {     for (int i = pos + 1; i <= n; ++i) {       if (cnt[i] + num <= cntClique) return false;       if (G[pos][i]) {         int ok = 1;         for (int id = 1; id <= num; ++id) {           if (!G[i][pts[id]]) {             ok = 0;             break;           }         }         if (ok) {           pts[num + 1] = i;           if (dfs(i, num + 1)) return true;         }       }     }     if (num > cntClique) {       for (int i = 1; i <= num; ++i) {         res[i] = pts[i];       }       cntClique = num;       return true;     }     return false;   }   void maxClique() {     cntClique = -1;     for (int i = n; i > 0; --i) {       pts[1] = i;       dfs(i, 1);       cnt[i] = cntClique;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     memset(G, 1, sizeof G);     cin >> nd >> nm;     for (int i = 1; i <= nd; ++i) {       int op;       string s;       cin >> op;       if (op == 1) {         v.clear();       } else {         cin >> s;         if (!H.count(s)) {           H[s] = ++n;         }         int y = H[s];         for (auto& x : v) {           G[x][y] = 0;           G[y][x] = 0;         }         v.push_back(y);       }     }     maxClique();     if (cntClique < 0) {       cout <<  0 ;     } else {       cout << cntClique;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void _print(long long int t) { cerr << t; }   void _print(int t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   bool cmp(pair<long long int, long long int> a,            pair<long long int, long long int> b) {     if (a.first != b.first)       return a.first > b.first;     else       return a.second > b.second;   }   long long int binarySearch(vector<long long int> v, long long int l,                              long long int r, long long int x) {     while (l <= r) {       long long int mid = l + (r - l) / 2;       if (v[mid] == x)         return mid;       else if (v[mid] < x)         l = mid + 1;       else         r = mid - 1;     }     return -1;   }   long long int power(long long int x, long long int n) {     if (n == 0)       return 1;     else if (n % 2 == 0)       return power(x * x, n / 2);     else       return x * power(x * x, (n - 1) / 2);   }   long long int ModularExpo(long long int x, long long int y, long long int p) {     long long int 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;   }   void solve() {     long long int n;     cin >> n;     for (long long int i = 0; i < n; i++) cout << i + 2 <<    ;     cout <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 100001;   int n, m, x, y, b, r, p, l, ri;   long long ans;   vector<int> B, R, P;   int bef(int x, int c) {     if (!c) return (lower_bound(B.begin(), B.end(), x) - B.begin() - 1);     return (lower_bound(R.begin(), R.end(), x) - R.begin() - 1);   }   int aft(int x, int c) {     if (!c) return (lower_bound(B.begin(), B.end(), x) - B.begin());     return (lower_bound(R.begin(), R.end(), x) - R.begin());   }   long long get(int x) {     long long mn = ri - B[x];     for (int i = x; i < b && B[i] < ri; i++) {       long long left = B[i] - l, right = 0;       if (i + 1 != b && B[i + 1] < ri) right = ri - B[i + 1];       mn = min(mn, left + right);     }     return mn;   }   long long get1(int x) {     long long mn = ri - R[x];     for (int i = x; i < r && R[i] < ri; i++) {       long long left = R[i] - l, right = 0;       if (i + 1 != r && R[i + 1] < ri) right = ri - R[i + 1];       mn = min(mn, left + right);     }     return mn;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n;     for (int i = 0; i < n; i++) {       char c;       cin >> x >> c;       if (c ==  B )         B.push_back(x);       else if (c ==  R )         R.push_back(x);       else         P.push_back(x);     }     b = B.size();     r = R.size();     p = P.size();     if (!P.size()) {       if (b) ans = B[b - 1] - B[0];       if (r) ans += R[r - 1] - R[0];       cout << ans;       return 0;     }     x = bef(P[0], 0);     y = bef(P[0], 1);     if (x >= 0) ans += P[0] - B[0];     if (y >= 0) ans += P[0] - R[0];     x = aft(P[p - 1], 0);     y = aft(P[p - 1], 1);     if (x != B.size()) ans += B[b - 1] - P[p - 1];     if (y != R.size()) ans += R[r - 1] - P[p - 1];     for (int i = 0; i < p - 1; i++) {       l = P[i];       ri = P[i + 1];       long long dist = ri - l;       int x = aft(l, 0), y = aft(l, 1);       if ((x == b || B[x] > ri) && (y == r || R[y] > ri)) {         ans += dist;         continue;       }       long long mn = 2 * dist;       long long k = dist;       if (x < b && B[x] < ri) k += get(x);       if (y < r && R[y] < ri) k += get1(y);       ans += min(mn, k);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2 * int(1e9);   const long long INFll = 1ll * int(1e9) * int(1e9);   const int MOD = 1000000007;   template <typename T>   ostream& operator<<(ostream& out, pair<T, T>& a) {     out << a.first <<     << a.second;     return out;   }   template <typename T>   istream& operator>>(istream& in, pair<T, T>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T>   ostream& operator<<(ostream& out, vector<pair<T, T> > a) {     for (int i = 0; i < a.size(); ++i) out << a[i] << endl;     return out;   }   template <typename T>   istream& operator>>(istream& in, vector<T>& a) {     for (int i = 0; i < a.size(); ++i) in >> a[i];     return in;   }   template <typename T>   ostream& operator<<(ostream& out, vector<T> a) {     for (int i = 0; i < a.size(); ++i)       if (i == a.size() - 1)         out << a[i];       else         out << a[i] <<    ;     return out;   }   struct IN {     bool any;     operator bool() const { return any; }   } CIN;   inline IN& operator>>(IN& in, int& x) {     x = 0, in.any = 0;     char c;     while ((c = getchar()) > 0) {       if (c < 48 || c > 57)         if (in.any)           return in;         else           continue;       in.any = 1, x = x * 10 + c -  0 ;     }     return in;   }   int main() {     ios_base::sync_with_stdio(0);     int q;     CIN >> q;     while (q--) {       int n, m;       CIN >> n >> m;       vector<vector<int> > a(n, vector<int>(m));       for (int i = 0; i < n; ++i)         for (int j = 0; j < m; ++j) CIN >> a[i][j];       int sum = 0;       for (int j = 0; j < m; ++j) sum += abs(a[n / 2][j] - a[n / 2 - 1][j]);       if (sum / long double(m) > 17)         cout <<  YES n ;       else         cout <<  NO n ;       if (0) cerr << sum / long double(m) << endl;     }     if (0)       cerr << fixed << setprecision(0)            <<  TIME =   << clock() / (long double)CLOCKS_PER_SEC * 1000 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   void dir(char& smb, int& x, int& y) {     if (smb ==  L )       x--;     else if (smb ==  R )       x++;     else if (smb ==  U )       y++;     else       y--;   }   void solve() {     int n;     cin >> n;     string s;     cin >> s;     map<pair<int, int>, int> mpp;     int x = 0, y = 0;     mpp[make_pair(0, 0)] = 0;     int mn = n + 5, l = -1, r = n + 1;     for (int i = 1; i < n + 1; i++) {       char smb = s[i - 1];       dir(smb, x, y);       auto it = mpp.find(make_pair(x, y));       if (it != mpp.end()) {         pair<pair<int, int>, int> p = *it;         int ind = p.second;         if (i - ind - 1 < mn) {           mn = i - ind - 1;           l = ind;           r = i - 1;         }       }       mpp[make_pair(x, y)] = i;     }     if (l == -1)       cout <<  -1 n ;     else       cout << l + 1 <<     << r + 1 <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tc;     cin >> tc;     while (tc--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, x1, y1, x2, y2;     cin >> n >> m >> x1 >> y1 >> x2 >> y2;     int x = abs(x1 - x2), y = abs(y1 - y2);     if (x <= 4 && y <= 4 && x + y <= 6)       cout <<  First  << endl;     else       cout <<  Second  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   template <typename T>   void print(vector<T> v) {     for (T &i : v) cout << i <<    ;     cout <<   n ;   }   void solve() {     unsigned long long int n, x;     cin >> n >> x;     vector<unsigned long long int> v(n);     for (unsigned long long int &i : v) cin >> i;     sort(v.begin(), v.end());     unsigned long long int sum = 0;     for (unsigned long long int i : v) {       sum += i * x;       if (x > 1) x--;     }     cout << sum <<   n ;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int tcs = 1;     while (tcs--) solve();     return 0;   }


#include <bits/stdc++.h>   int main() {     long long n, m;     int dig[10];     char cn[12], cm[12];     while (scanf( %s n%s , &cn, &cm) != EOF) {       if (strlen(cn) != strlen(cm)) {         printf( WRONG_ANSWER n );         continue;       }       n = atol(cn);       m = atol(cm);       for (int i = 0; i < 10; i++) dig[i] = 0;       if (n < 10) {         if (n == m)           printf( OK n );         else           printf( WRONG_ANSWER n );       } else {         while (n) {           dig[n % 10]++;           n /= 10;         }         long long ret = 0;         for (int i = 1; i <= 9; i++) {           if (dig[i]) {             ret *= 10;             ret += i;             dig[i]--;             break;           }         }         for (int i = 0; i <= 9; i++) {           while (dig[i]) {             ret *= 10;             ret += i;             dig[i]--;           }         }         if (ret == m)           printf( OK n );         else           printf( WRONG_ANSWER n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void input(long &n) { scanf( %ld , &n); }   void output(long n) { printf( %ld , n); }   void input(long &n, long a[]) {     input(n);     for (long i = 1; i <= n; i++) input(a[i]);   }   bool test(long n, long a[], long id1, long id2, long tid, vector<long> &st1,             vector<long> &st2) {     st1.clear();     st2.clear();     st1.push_back(a[id1]);     st1.push_back(a[id2]);     long isize2;     if (tid == -1) {       isize2 = 0;     } else {       isize2 = 1;       st2.push_back(a[tid]);     }     long seed = a[id2] - a[id1];     long seed2 = 0;     long nextnum2 = 0;     long nextnum = a[id2] + seed;     for (long i = id2 + 1; i <= n; i++) {       if (isize2 >= 2 && a[i] == nextnum && a[i] == nextnum2) {         if (i == n) {           nextnum += seed;           st1.push_back(a[i]);         } else if (nextnum + seed == a[i + 1]) {           nextnum += seed;           st1.push_back(a[i]);         } else if (nextnum2 + seed2 == a[i + 1]) {           st2.push_back(a[i]);           nextnum2 += seed2;           isize2++;         } else           return false;       } else if (a[i] == nextnum) {         nextnum += seed;         st1.push_back(a[i]);       } else {         if (isize2 >= 2) {           if (nextnum2 == a[i]) {             st2.push_back(a[i]);             isize2++;             nextnum2 += seed2;           } else if (isize2 == 2) {             st2.push_back(st2[1]);             isize2++;             st2[1] = st1.back();             st1.pop_back();             if (st2[2] - st2[1] != st2[1] - st2[0]) return false;             seed2 = st2[2] - st2[1];             nextnum2 = st2[2] + seed2;             i--;           } else             return false;         } else {           st2.push_back(a[i]);           isize2++;           if (isize2 == 2) {             seed2 = st2[1] - st2[0];             nextnum2 = st2[1] + seed2;           }         }       }     }     if (seed == 0 && st1.size() > 2) return false;     if (seed2 == 0 && st2.size() > 2) return false;     if (isize2 == 0) return false;     return true;   }   bool solve(long n, long a[], vector<long> &st1, vector<long> &st2) {     if (n == 2) {       st1.push_back(a[1]);       st2.push_back(a[2]);       return true;     } else if (n == 3 && a[1] == a[2] && a[2] == a[3]) {       st1.push_back(a[1]);       st1.push_back(a[1]);       st2.push_back(a[1]);       return true;     } else if (n == 4 && a[1] == a[2] && a[2] == a[3] && a[3] == a[4]) {       st1.push_back(a[1]);       st1.push_back(a[1]);       st2.push_back(a[1]);       st2.push_back(a[1]);       return true;     }     if (test(n, a, 1, 3, 2, st1, st2)) return true;     if (test(n, a, 2, 3, 1, st1, st2)) return true;     if (test(n, a, 1, 2, -1, st1, st2)) return true;     return false;   }   void output(bool res, vector<long> &st1, vector<long> &st2) {     if (res) {       for (vector<long>::iterator it = st1.begin(); it < st1.end(); it++)         printf( %ld  , *it);       printf(  n );       for (vector<long>::iterator it = st2.begin(); it < st2.end(); it++)         printf( %ld  , *it);     } else       cout <<  No solution n ;   }   long n, a[30010 + 1];   vector<long> st1, st2;   int main() {     input(n, a);     bool res = solve(n, a, st1, st2);     output(res, st1, st2);   }


#include <bits/stdc++.h>   using namespace std;   int a1, a2;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> a1 >> a2;     int res = 0;     if (a1 == 1 && a2 == 1) {       cout << 0 <<   n ;       return 0;     }     while (a1 > 0 && a2 > 0) {       if (a1 < a2)         ++a1, a2 -= 2;       else         ++a2, a1 -= 2;       ++res;     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b = 1, c = 2, o = 1, j, k;     cin >> a;     int p = a / 2;     for (k = 0; k < a; k++) {       for (j = 0; j < p; j++) {         cout << c <<    ;         c += 2;       }       for (j = 0; j < a - p * 2; j++) {         cout << b <<    ;         b += 2;       }       for (int j = 0; j < p; j++) {         cout << c <<    ;         c += 2;       }       cout << endl;       if (p == 0) o = 0;       if (o == 0)         p++;       else         p--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void aayush() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int main() {     aayush();     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       if (n % 4 == 0) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, h;   pair<int, int> arr[100010];   int res[100010];   int ptr = -1;   int cnt, bits;   int main() {     cin >> n >> h;     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i].first);       arr[i].second = i;       res[i] = 1;     }     sort(arr, arr + n);     int ans = arr[n - 1].first + arr[n - 2].first - arr[0].first - arr[1].first;     for (int i = n - 2; i >= 0; i--) {       int mx = arr[i].first + arr[n - 1].first + h;       if (i < n - 2) mx = max(mx, arr[n - 1].first + arr[n - 2].first);       int init = min(7, i);       int col[7];       if (i <= 6) {         col[i] = 2;         for (int j = i + 1; j < min(n, 7); j++) col[j] = 1;       }       for (int j = 0; j < (1 << init); j++) {         for (int k = 0; k < init; k++) {           col[k] = ((j & (1 << k)) ? 1 : 2);         }         int mn = 1000000000;         for (int k = 0; k < min(n, 7); k++) {           for (int l = k + 1; l < min(n, 7); l++) {             int val = arr[k].first + arr[l].first;             if (col[k] != col[l]) val += h;             mn = min(mn, val);           }         }         int dif = mx - mn;         if (dif < ans) {           ans = dif;           ptr = i;           cnt = init;           bits = j;         }       }     }     if (ptr != -1) {       for (int i = 0; i < cnt; i++) {         res[arr[i].second] = ((bits & (1 << i)) ? 1 : 2);       }       res[arr[ptr].second] = 2;       for (int i = ptr + 1; i < n; i++) res[arr[i].second] = 1;     }     cout << ans << endl;     for (int i = 0; i < n; i++) {       if (i) printf(   );       printf( %d , res[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long add(long long a, long long b) {     return (a % 1000000007 + b % 1000000007) % 1000000007;   }   inline long long mul(long long a, long long b) {     return (a % 1000000007 * b % 1000000007) % 1000000007;   }   long long pwr(long long a, long long b) {     if (!b) return 1ll;     long long t = pwr(a, b / 2);     t = mul(t, t);     if (b & 1) t = mul(t, a);     return t;   }   long long modinv(long long a, long long b = 1000000007) {     return pwr(a, b - 2);   }   long long gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, a, b, c, d;       cin >> n >> a >> b >> c >> d;       int x = a - b, y = a + b;       int p = c - d, q = c + d;       int mn = x * n, flag = 1;       for (int i = 1; i <= n; i++) {         if (mn <= q && mn >= p) {           flag = 0;           break;         }         if (mn < p) {           int diff = p - mn;           mn += min(diff, 2 * b);         }       }       if (mn <= q && mn >= p) {         flag = 0;       }       if (flag)         cout <<  No n ;       else         cout <<  Yes n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, a, b, i, a1, b1, y, y1, ans, ans1, ans2, x;     cin >> n >> a >> b;     for (i = 1; i <= n; i++) {       cin >> x;       y = x * a;       ans = y % b;       if (a != 0)         cout << ans / a <<    ;       else         cout << x <<    ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   int dp[100005][30] = {0};   int A[40][40] = {0};   int main() {     string s, b;     cin >> s;     int k;     cin >> k;     for (int i = 0; i < k; i++) {       cin >> b;       int x, y;       x = b[0] -  a ;       y = b[1] -  a ;       A[x][y] = A[y][x] = 1;     }     int n = s.length();     for (int i = 1; i <= n; i++)       for (int k = 0; k < 26; k++) {         dp[i][k] = dp[i - 1][k];         for (int j = 0; j < 26; j++)           if (!A[k][j] && s[i - 1] -  a  == k)             dp[i][k] = max(dp[i][k], dp[i - 1][j] + 1);       }     int res = 0;     for (int i = 0; i < 26; i++) {       res = max(res, dp[n][i]);     }     cout << n - res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   const long long oo = ((long long)1e18) + 7;   int N, M, T, K, Q;   vector<int> G[MAXN];   int num[MAXN];   int dep[MAXN];   int pa[MAXN][25];   int LOG = 20;   int cnt = 0;   int child[MAXN];   int DFS(int u, int par, int depth) {     num[u] = ++cnt;     dep[num[u]] = depth;     pa[num[u]][0] = num[par];     for (auto v : G[u])       if (v != par) {         child[num[u]] += DFS(v, u, dep[num[u]] + 1);       }     return child[num[u]];   }   int LCA(int u, int v) {     if (u == v) return u;     if (dep[u] < dep[v]) swap(u, v);     for (int i = LOG; i >= 0; i--)       if (dep[pa[u][i]] >= dep[v]) u = pa[u][i];     if (u == v) return u;     for (int i = LOG; i >= 0; i--)       if (pa[u][i] != pa[v][i]) {         u = pa[u][i];         v = pa[v][i];       }     return pa[u][0];   }   int findParent(int u, int k) {     if (k == 0) return u;     int i = 0;     while (k > 0) {       if (k & 1) u = pa[u][i];       i++;       k >>= 1;     }     return u;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     if (fopen( 519E                 .inp ,                r )) {       freopen(            519E             .inp ,            r , stdin);       freopen(            519E             .out ,            w , stdout);     }     cin >> N;     for (int i = 1; i < N; i++) {       int u, v;       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     for (int i = 1; i <= N; i++) child[i] = 1;     dep[0] = -1;     DFS(1, 0, 0);     for (int k = 1; k <= LOG; k++)       for (int i = 1; i <= N; i++) pa[i][k] = pa[pa[i][k - 1]][k - 1];     cin >> Q;     while (Q--) {       int u, v;       cin >> u >> v;       u = num[u];       v = num[v];       if (dep[u] < dep[v]) swap(u, v);       int p = LCA(u, v);       if (u == v) {         cout << N <<   n ;         continue;       }       int diff1 = dep[u] - dep[p];       int diff2 = dep[v] - dep[p];       if ((diff1 + diff2) & 1) {         cout << 0 <<   n ;         continue;       }       int avg = (diff1 + diff2) >> 1;       int mid = findParent(u, avg);       if (mid == p) {         int fakeParent1 = findParent(u, diff1 - 1);         int fakeParent2 = findParent(v, diff2 - 1);         cout << (child[mid] - child[fakeParent1] - child[fakeParent2]) + N -                     child[mid]              <<   n ;         continue;       }       diff1 = dep[u] - dep[mid];       int fakeParent1 = findParent(u, diff1 - 1);       cout << child[mid] - child[fakeParent1] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   bool checkPal(string s) {     for (int i = 0, j = s.size() - 1; i <= j; i++, j--) {       if (s[i] != s[j]) {         return false;       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     for (int i = 0; i < t; i++) {       string s;       cin >> s;       map<char, int> m;       for (int j = 0; j < s.size(); j++) {         m[s[j]]++;       }       string ch =   ;       for (auto it = m.rbegin(); it != m.rend(); it++) {         pair<int, int> p = *it;         char c = p.first;         int cnt = p.second;         for (int j = 0; j < cnt; j++) {           ch += c;         }       }       if (!checkPal(ch)) {         cout << ch << endl;       } else {         cout << -1 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[1000010];   pair<long long, long long> st[1000010];   bool check(pair<long long, long long> a, pair<long long, long long> b,              pair<long long, long long> c) {     double k1 = 1.0 * (b.second - a.second) / (b.first - a.first);     double k2 = 1.0 * (c.second - b.second) / (c.first - b.first);     if (k1 > k2) return 1;     return 0;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       a[i] += a[i - 1];     }     int top = 0;     st[top++] = make_pair(0, 0);     for (int i = 1; i <= n; i++) {       pair<long long, long long> tmp = make_pair(i, a[i]);       while (top > 1 && check(st[top - 2], st[top - 1], tmp)) top--;       st[top++] = tmp;     }     for (int i = 0; i < top - 1; i++) {       long long l = st[i].first, r = st[i + 1].first,                 tot = st[i + 1].second - st[i].second;       for (int j = l + 1; j <= r; j++) {         printf( %.9f n , 1.0 * tot / (r - l));       }     }     return 0;   }


#include <bits/stdc++.h>   int A[50], B[50];   int main() {     int N, M, i, j, Max, now, Cnt;     while (scanf( %d , &N) != EOF) {       for (i = 0; i < N; ++i) {         scanf( %d , &A[i]);       }       scanf( %d , &M);       for (i = 0; i < M; ++i) {         scanf( %d , &B[i]);       }       for (Max = i = 0; i < N; ++i) {         for (j = 0; j < M; ++j) {           now = B[j] / A[i];           if (now * A[i] == B[j] && Max < now) {             Max = now;           }         }       }       for (Cnt = i = 0; i < N; ++i) {         for (j = 0; j < M; ++j) {           now = B[j] / A[i];           if (now * A[i] == B[j] && Max == now) {             ++Cnt;           }         }       }       printf( %d n , Cnt);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 5;     int arr[5], sum = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       sum += arr[i];     }     if (sum == 0)       cout << -1 << endl;     else if (sum % 5 != 0)       cout << -1 << endl;     else {       int s = sum / 5;       int a = 0, b = 0;       for (int i = 0; i < n; i++) {         if (arr[i] > s)           a += s - arr[i];         else           b += arr[i] - s;       }       if (a == b)         cout << s << endl;       else         cout << -1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 840;   long long cnt[10];   long long f[10][N];   int main() {     long long w;     cin >> w;     for (int i = 1; i <= 8; i++) cin >> cnt[i];     memset(f, 0xcf, sizeof f);     f[0][0] = 0;     long long res = 0;     for (int i = 1; i <= 8; i++) {       for (int j = 0; j < 840 / i && j <= cnt[i]; j++) {         for (int k = 0; k < 840; k++) {           int a = (k + j * i) / 840;           int b = (k + j * i) % 840;           f[i][b] = max(f[i][b], f[i - 1][k] + a + (cnt[i] - j) * i / 840);           if (b <= w) res = max(res, min(f[i][b], (w - b) / 840) * 840 + b);         }       }     }     cout << res << endl;     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--) {       long long int n, a, b;       cin >> n >> a >> b;       string s;       cin >> s;       long long int ans = n * (a + 2 * b) + 2 * a;       int st = 0, en = 0;       while (en < n and s[en] ==  0 ) en++;       if (en == n) {         ans = n * a + (n + 1) * b;         cout << ans <<   n ;         continue;       }       ans -= (en - 1) * b;       while (en != n) {         st = en;         while (s[st] !=  0 ) st++;         en = st;         while (en < n and s[en] ==  0 ) en++;         if (en == n) {           ans -= (en - st - 1) * b;           break;         }         if (en - st != 1 and 2 * a < (en - st - 1) * b)           ans += 2 * a - (en - st - 1) * b;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   const int kN = 18;   const int kT = 1 << kN;   const int kInf = 0x3f3f3f3f;   int a[kT];   bool fan_of[kT];   std::map<std::pair<int, int>, int> cal[4];   int Cal(int l, int r, int st) {     if (r == l + 2) {       int cnt_fan = (int)fan_of[l] + fan_of[l + 1], cnt_st = (st & 1) + (st >> 1);       return cnt_fan == cnt_st ? std::min(cnt_st, 1) : -kInf;     }     std::pair<int, int> tmp = std::make_pair(l, r);     if (cal[st].count(tmp)) return cal[st][tmp];     int mid = (l + r) >> 1, ret = -kInf;     for (int i = 0; i < 4; ++i)       for (int j = 0; j < 4; ++j) {         int v1 = ((i << 1) | (i & 2) | j) & 3, v2 = ((j << 1) | (j & 2) | i) & 3;         if (v1 == st || v2 == st) {           ret = std::max(ret, Cal(l, mid, i) + Cal(mid, r, j));         }       }     return cal[st][tmp] = ret + st;   }   int main() {     int n, k, t, ans = 0;     scanf( %d%d , &n, &k);     t = 1 << n;     for (int i = 1; i <= k; ++i) scanf( %d , a + i), fan_of[--a[i]] = true;     for (int i = 0; i < 4; ++i) ans = std::max(ans, Cal(0, t, i));     printf( %d , ans + !(!k));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long d[111111];   long long sum[111111];   int q[111111];   long long cat[111111];   long long dp[101][100001];   long long getDP(int i, int j, int k) {     return (long long)j * cat[j] + dp[i - 1][k] - j * cat[k];   }   long long getUP(int i, int j, int k) {     return (long long)dp[i - 1][j] - dp[i - 1][k];   }   long long getDOWN(int j, int k) { return (long long)cat[j] - cat[k]; }   int main() {     int i, j, k, n, m, p, h;     cin >> n >> m >> p;     for (i = 2; i <= n; i++) {       cin >> d[i];       d[i] += d[i - 1];     }     for (i = 1; i <= m; i++) {       cin >> h >> cat[i];       cat[i] -= d[h];     }     sort(cat + 1, cat + 1 + m);     for (i = 1; i <= m; i++) sum[i] = sum[i - 1] + cat[i];     for (i = 1; i <= p; i++)       for (j = 1; j <= m; j++) dp[i][j] = 999999999999999;     dp[1][m] = (long long)m * cat[m] - sum[m];     for (i = 2; i <= p; i++) {       int head, tail;       head = tail = 0;       q[tail++] = m;       for (j = m; j >= 1; j--) {         while (head + 1 < tail && (getUP(i, q[head + 1], q[head]) <=                                    j * getDOWN(q[head + 1], q[head])))           head++;         dp[i][j] = min(dp[i][j], getDP(i, j, q[head]));         while (head + 1 < tail &&                getUP(i, j, q[tail - 1]) * getDOWN(q[tail - 1], q[tail - 2]) >                    getUP(i, q[tail - 1], q[tail - 2]) * getDOWN(j, q[tail - 1]))           tail--;         q[tail++] = j;       }     }     long long ans = dp[p][1];     for (i = 1; i <= m; i++) ans = min(ans, dp[p][i]);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 5;   struct BIT {     int a[N], n;     void Init(int n) { this->n = n; }     void add(int p, int v) {       for (p = p + 1; p <= n; p += p & -p) a[p] += v;       return;     }     int query(int p) {       int res = 0;       for (p = p + 1; p >= 1; p -= p & -p) res += a[p];       return res;     }   } * TA;   struct Node {     int val, idx;     Node(int v, int i) {       val = v;       idx = i;     }   };   void update(Node &des, Node src) {     des.val += src.val;     TA->add(des.idx, src.val);   }   int main() {     int n, q;     cin >> n >> q;     TA = new BIT();     TA->Init(n);     deque<Node> Q;     for (int i = 0; i < n; i++) TA->add(i, 1), Q.push_back(Node(1, i));     int s = 0;     for (int i = 0; i < q; i++) {       int f;       scanf( %d , &f);       if (f == 1) {         int p;         scanf( %d , &p);         if (2 * p <= Q.size()) {           if (s == 0) {             for (int i = 0; i < p; i++) {               update(Q[2 * p - 1 - i], Q[i]);             }             for (int i = 0; i < p; i++) Q.pop_front();           } else {             for (int i = (int)Q.size() - 1; i >= Q.size() - p; i--) {               update(Q[2 * (Q.size() - p) - 1 - i], Q[i]);             }             for (int i = 0; i < p; i++) Q.pop_back();           }         } else {           if (s == 0) {             for (int i = (int)Q.size() - 1; i >= p; i--) {               update(Q[2 * p - 1 - i], Q[i]);             }             int d = (int)Q.size() - p;             for (int i = 0; i < d; i++) Q.pop_back();           } else {             for (int i = 0; i < Q.size() - p; i++) {               update(Q[2 * (Q.size() - p) - 1 - i], Q[i]);             }             int d = (int)Q.size() - p;             for (int i = 0; i < d; i++) Q.pop_front();           }           s = s ^ 1;         }       } else {         int L, R;         scanf( %d %d , &L, &R);         --R;         if (s == 1) {           int ll = L, rr = R;           L = Q[Q.size() - rr - 1].idx;           R = Q[Q.size() - ll - 1].idx;         } else {           L = Q[L].idx, R = Q[R].idx;         }         printf( %d n , TA->query(R) - TA->query(L - 1));       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     while (cin >> s) {       string integer;       string decimal;       bool isnegative = false;       bool isdecimal = false;       int pos = 0;       if (s[0] ==  - ) {         isnegative = true;         pos++;       }       for (; pos < s.size(); pos++) {         if (s[pos] ==  . ) {           isdecimal = true;         } else if (!isdecimal) {           integer += s[pos];         } else {           decimal += s[pos];         }       }       reverse(integer.begin(), integer.end());       string integerWithComma;       for (int i = 0; i < integer.size(); i++) {         integerWithComma += integer[i];         if (i != integer.size() - 1 && i % 3 == 2) {           integerWithComma +=  , ;         }       }       reverse(integerWithComma.begin(), integerWithComma.end());       string decimalProcess;       if (decimal.size() == 0) {         decimalProcess =  .00 ;       } else if (decimal.size() == 1) {         decimalProcess =  .  + decimal +  0 ;       } else {         decimalProcess =  .  + decimal.substr(0, 2);       }       if (isnegative) {         cout <<  ( ;       }       cout <<  $ ;       cout << integerWithComma;       cout << decimalProcess;       if (isnegative) {         cout <<  ) ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string op, s1, s2;   map<string, int> mp;   int solve(string s) {     int ast, amp;     ast = count(s.begin(), s.end(),  * );     amp = count(s.begin(), s.end(),  & );     return ast - amp;   }   string remove(string s) {     s.erase(remove(s.begin(), s.end(),  * ), s.end());     s.erase(remove(s.begin(), s.end(),  & ), s.end());     return s;   }   int main() {     int N;     cin >> N;     mp[ void ] = 0;     while (N--) {       cin >> op;       if (op ==  typedef ) {         cin >> s1 >> s2;         int d = solve(s1);         s1 = remove(s1);         if (mp.find(s1) != mp.end() && mp[s1] >= 0)           mp[s2] = mp[s1] + d;         else           mp[s2] = -1;       } else {         cin >> s1;         int d = solve(s1);         s1 = remove(s1);         if (mp.find(s1) != mp.end() && mp[s1] >= 0) {           d += mp[s1];           if (d >= 0) {             cout <<  void ;             for (int i = 0; i < d; i++) cout <<  * ;             cout << endl;           } else             cout <<  errtype  << endl;         } else           cout <<  errtype  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long power(unsigned long long x, unsigned long long y) {     if (y == 0) return 1;     unsigned long long tmp = power(x, y / 2);     tmp *= tmp;     if (y % 2) tmp *= x;     return tmp;   }   unsigned long long get(unsigned long long n) {     if (n <= 9) return n;     unsigned long long cnt, temp, d = 0;     unsigned long long tmp = n;     while (tmp / 10) {       tmp /= 10;       d++;     }     stringstream s;     s << n;     string str = s.str();     unsigned long long x = str[0] -  0 ;     temp = power(10, d);     n -= (str[0] -  0 ) * temp;     n /= 10;     if (str[0] <= str[str.size() - 1])       cnt = n + 1;     else       cnt = n;     cnt += ((power(10, d - 1)) * (x - 1));     return cnt + get(power(10, d) - 1);   }   int main() {     unsigned long long l, r;     cin >> l >> r;     cout << get(r) - get(l - 1) << endl;   }


#include <bits/stdc++.h>   int main() {     int n, m;     while (scanf( %d %d , &n, &m) != EOF) {       if (n * m < 2) {         printf( 0 n );       } else {         printf( %d n , n * m / 2);       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <class A, class B>   A cvt(B x) {     stringstream s;     s << x;     A r;     s >> r;     return r;   }   typedef vector<int> VI;   typedef vector<pair<int, int> > VII;   typedef vector<string> VS;   struct Treap {     int val, priority;     int maxVal, size;     Treap *left;     Treap *right;     Treap() {       val = priority = maxVal = size = 0;       left = right = 0;     }     Treap(int _val, int _priority, int _maxVal, int _size) {       val = _val;       maxVal = _maxVal;       size = _size;       priority = _priority;       left = right = 0;     }   };   int SZ(Treap *&t) { return t ? t->size : 0; }   int MAX(Treap *&t) { return t ? t->maxVal : 0; }   void Adjust(Treap *&T) {     T->size = 1 + SZ(T->left) + SZ(T->right);     T->maxVal = max(T->val, max(MAX(T->left), MAX(T->right)));   }   void rotateLeft(Treap *&T) {     Treap *t = T->left;     T->left = t->right;     Adjust(T);     t->right = T;     Adjust(t);     T = t;   }   void rotateRight(Treap *&T) {     Treap *t = T->right;     T->right = t->left;     Adjust(T);     t->left = T;     Adjust(t);     T = t;   }   void Balance(Treap *&T) {     if (T->left) {       if (T->left->priority > T->priority) rotateLeft(T);     }     if (T->right) {       if (T->right->priority > T->priority) rotateRight(T);     }   }   void insert(Treap *&T, int val, int where, int pri) {     if (!T)       T = new Treap(val, pri, val, 1);     else {       if (SZ(T->right) >= where) {         insert(T->right, val, where, pri);       } else if (max(T->val, MAX(T->right)) > val) {         insert(T->right, val, where, pri);       } else         insert(T->left, val, where - SZ(T->right) - 1, pri);       Adjust(T);       Balance(T);     }   }   int idx[101010];   void print(Treap *&T) {     if (T) {       print(T->left);       printf( %d  , idx[T->val]);       print(T->right);     }   }   int main() {     int n, a, c;     scanf( %d , &n);     Treap *T = NULL;     for (int i = (int)0; i < (int)n; ++i) {       scanf( %d%d , &a, &c);       idx[a] = i + 1;       insert(T, a, c, rand() % 101010);     }     print(T);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Dinic {     struct Edge {       int to, flow, next;     };     vector<Edge> edges;     vector<int> head, act, h;     int S, D;     void AddEdge(int from, int to, int f, int rev_f = 0) {       edges.push_back({to, f, (int)edges.size()});       swap(edges.back().next, head[from]);       edges.push_back({from, rev_f, (int)edges.size()});       swap(edges.back().next, head[to]);     }     bool bfs() {       fill(h.begin(), h.end(), -1);       h[S] = 0;       vector<int> q = {S};       for (int it = 0; it < q.size() && h[D] == -1; it++) {         int nod = q[it];         for (int i = head[nod]; i != -1; i = edges[i].next)           if (edges[i].flow && h[edges[i].to] == -1)             h[edges[i].to] = 1 + h[nod], q.push_back(edges[i].to);       }       return h[D] != -1;     }     int dfs(int nod, int flow) {       if (flow == 0 || nod == D) return flow;       while (act[nod] != -1) {         Edge& e = edges[act[nod]];         int d;         if (e.flow && h[e.to] == 1 + h[nod] &&             (d = dfs(e.to, min(flow, e.flow))) != 0) {           e.flow -= d;           edges[act[nod] ^ 1].flow += d;           return d;         }         act[nod] = edges[act[nod]].next;       }       return 0;     }     int GetFlow() {       int f = 0;       while (bfs()) {         act = head;         int d;         while ((d = dfs(S, 1e9)) != 0) f += d;       }       return f;     }     Dinic(int dim = 0, int s = 0, int d = 0)         : head(dim + 1, -1), h(dim + 1), S(s), D(d) {}   };   struct FlowWithMinRestrictions {     struct Edge {       int from, to, flowmin, flowmax, id;     };     vector<Edge> edges;     int S, D, n;     void AddEdge(int from, int to, int flowmin, int flowmax) {       edges.push_back({from, to, flowmin, flowmax, 0});     }     vector<int> Solve(bool& feasible, int& flow) {       feasible = 1;       flow = 0;       int news = n + 1, newd = n + 2;       Dinic first_flow(n + 2, news, newd);       first_flow.AddEdge(D, S, 1e9);       int s_minime = 0;       for (auto& i : edges) {         if (i.flowmax < i.flowmin) {           feasible = 0;           return vector<int>();         }         s_minime += i.flowmin;         i.id = first_flow.edges.size();         first_flow.AddEdge(i.from, i.to, i.flowmax - i.flowmin);         first_flow.AddEdge(news, i.to, i.flowmin);         first_flow.AddEdge(i.from, newd, i.flowmin);       }       if (first_flow.GetFlow() != s_minime) {         feasible = 0;         return vector<int>();       }       Dinic curent_flow(n, S, D);       for (auto& i : edges) {         int dif = i.flowmax - i.flowmin;         int passed = dif - first_flow.edges[i.id].flow;         int nid = curent_flow.edges.size();         curent_flow.AddEdge(i.from, i.to, first_flow.edges[i.id].flow, passed);         i.id = nid;       }       curent_flow.GetFlow();       vector<int> ans(edges.size());       for (int i = 0; i < edges.size(); i++) {         int cntflow = curent_flow.edges[edges[i].id ^ 1].flow + edges[i].flowmin;         ans[i] = cntflow;         if (edges[i].from == S) flow += cntflow;         if (edges[i].to == S) flow -= cntflow;       }       return ans;     }     FlowWithMinRestrictions(int n = 0, int s = 0, int d = 0) : n(n), S(s), D(d) {}   };   namespace ProbD {   const int NMAX = 200010;   map<int, int> nrmx, nrmy;   FlowWithMinRestrictions flow;   pair<int, int> shields[NMAX];   int idshield[NMAX];   int n, S, D;   int difmax[NMAX];   int nr_on_poz[NMAX];   int cnt = 0;   void normalize() {     for (int i = 0; i < n; i++)       nrmx[shields[i].first] = nrmy[shields[i].second] = 0;     for (auto& i : nrmx) i.second = cnt++;     for (auto& i : nrmy) i.second = cnt++;     S = cnt++;     D = cnt;     fill(difmax, difmax + cnt + 1, 1e9);   }   void solve() {     int r, b;     int nrc;     cin >> n >> nrc >> r >> b;     for (int i = 0; i < n; i++) cin >> shields[i].first >> shields[i].second;     normalize();     flow = FlowWithMinRestrictions(cnt, S, D);     for (int i = 0; i < n; i++) {       shields[i].first = nrmx[shields[i].first],       shields[i].second = nrmy[shields[i].second];       idshield[i] = flow.edges.size();       nr_on_poz[shields[i].first]++, nr_on_poz[shields[i].second]++;       flow.AddEdge(shields[i].first, shields[i].second, 0, 1);     }     while (nrc--) {       int t, p, val;       cin >> t >> p >> val;       if (t == 1 && nrmx.find(p) != nrmx.end())         difmax[nrmx[p]] = min(difmax[nrmx[p]], val);       else if (t == 2 && nrmy.find(p) != nrmy.end())         difmax[nrmy[p]] = min(difmax[nrmy[p]], val);     }     vector<pair<int, pair<int, int>>> verif;     for (auto i : nrmx) {       int nr = nr_on_poz[i.second];       int dmax = difmax[i.second];       int vmax = (dmax + nr) / 2;       int vmin = max(0, (nr - dmax + 1) / 2);       verif.push_back({(int)flow.edges.size(), {vmin, vmax}});       flow.AddEdge(S, i.second, vmin, vmax);     }     for (auto i : nrmy) {       int nr = nr_on_poz[i.second];       int dmax = difmax[i.second];       int vmax = (dmax + nr) / 2;       int vmin = max(0, (nr - dmax + 1) / 2);       verif.push_back({(int)flow.edges.size(), {vmin, vmax}});       flow.AddEdge(i.second, D, vmin, vmax);     }     int f;     bool posibil;     auto ans = flow.Solve(posibil, f);     if (!posibil) {       cout <<  -1 n ;       return;     }     for (auto i : verif)       assert(ans[i.first] >= i.second.first && ans[i.first] <= i.second.second);     cout << 1LL * f * min(r, b) + 1LL * (n - f) * max(r, b) <<   n ;     string s =  rb ;     if (r < b) s =  br ;     for (int i = 0; i < n; i++) cout << s[ans[idshield[i]]];     cout <<   n ;   }   }  // namespace ProbD   int main() {     ios_base::sync_with_stdio(0);     ProbD::solve();     return 0;     FILE* in = fopen( cuplaj.in ,  r );     int n, m;     fscanf(in,  %d%d , &n, &m);     FlowWithMinRestrictions flow(n, 1, n);     while (m--) {       int a, b, c, d;       fscanf(in,  %d%d%d%d , &a, &b, &c, &d);       flow.AddEdge(a, b, c, d);     }     bool feasible;     int f;     auto ans = flow.Solve(feasible, f);     ofstream out( flux.out );     out << feasible <<   n  << f <<   n ;     for (auto i : ans) out << i <<    ;     return 0;   }


#include <bits/stdc++.h>   bool g[1111][1111];   int main() {     int n, m;     memset(g, false, sizeof(g));     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d%d , &u, &v);       g[u][v] = true;     }     int count = 0;     for (int i = 2; i < n; i++) {       bool flag = false;       for (int j = 1; j <= n; j++)         if (g[i][j] == true) {           flag = true;           break;         }       if (flag) continue;       count++;     }     for (int j = 2; j < n; j++) {       bool flag = false;       for (int i = 1; i <= n; i++)         if (g[i][j]) {           flag = true;           break;         }       if (flag) continue;       count++;     }     if (n & 1) {       int i, j;       for (i = 1; i <= n; i++)         if (g[i][n / 2 + 1]) break;       for (j = 1; j <= n; j++)         if (g[n / 2 + 1][j]) break;       if (i > n && j > n)         if (count) count--;     }     printf( %d n , count);     return 0;   }


#include <bits/stdc++.h>   const int N = 517;   const int mod = 998244353;   using namespace std;   inline int read() {     int x = 0;     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) x = (x << 1) + (x << 3) + ch -  0 , ch = getchar();     return x;   }   int n, k;   long long dp[N][N], ans;   int main() {     n = read(), k = read();     dp[0][0] = 1;     for (int i = 1, I = (n) + 1; i < I; ++i)       for (int j = 1, I = (i) + 1; j < I; ++j)         for (int k = i - j, I = (i - 1) + 1; k < I; ++k)           dp[i][j] = (dp[i][j] + dp[k][min(j, k)]) % mod;     for (int i = n, I = (1) - 1; i > I; --i)       dp[n][i] = (dp[n][i] - dp[n][i - 1] + mod) % mod;     for (int i = 1, I = (n) + 1; i < I; ++i)       for (int j = 1, I = (n) + 1; j < I; ++j)         if (i * j < k) ans = (ans + dp[n][i] * dp[n][j]) % mod;     printf( %lld n , (ans << 1) % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t;   long long sx, sy, ex, ey;   int main(void) {     cin >> t >> sx >> sy >> ex >> ey;     int ans = 0;     for (int i = 0; i < t; i++) {       char c;       cin >> c;       if (sx == ex && sy == ey) {         cout << ans <<   n ;         return 0;       }       if (c ==  N  && sy < ey) sy++;       if (c ==  W  && sx > ex) sx--;       if (c ==  S  && sy > ey) sy--;       if (c ==  E  && sx < ex) sx++;       ans++;     }     if (sx == ex && sy == ey) {       cout << ans <<   n ;       return 0;     }     cout <<  -1 n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans = 0, c;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> c;       ans += c;     }     c = (n == 1 ? 1 : n - 1);     if (ans == c)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INT_INF = 1e9;   const long long LL_INF = 1e18;   const int MAXN = 200003;   int n, m;   int A[MAXN];   long long calc(int m) {     long long ret = 0;     map<int, int> dp;     int sum = 0;     dp[sum] = 1;     long long add = 0;     for (int i = 1; i <= n; i++) {       if (A[i] < m) {         sum--;         add -= dp[sum];       } else if (A[i] >= m) {         add += dp[sum];         sum++;       }       ret += add;       dp[sum]++;     }     return ret;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1, x; i <= n; i++) {       scanf( %d , &x);       A[i] = x;     }     long long ret1 = calc(m);     long long ret2 = calc(m + 1);     printf( %lld , ret1 - ret2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-12;   const int INF = 1 << 30;   const long long LINF = 1ll << 61;   const int BUFFER_SZ = 1 << 20;   const int MOD = 1000 * 1000 * 1000 + 7;   char BUFFER[BUFFER_SZ];   int gi() {     int x;     scanf( %d , &x);     return x;   }   double gd() {     double x;     scanf( %lf , &x);     return x;   }   long long gll() {     long long x;     scanf( %lld , &x);     return x;   }   vector<int> gvi(int n) {     vector<int> a;     while (n-- > 0) a.push_back(gi());     return a;   }   string gs() {     scanf( %s , BUFFER);     return string(BUFFER);   }   template <class T>   void print(vector<T> &x, string format) {     format +=  %c ;     for (int i = 0; i < x.size(); ++i)       printf(format.c_str(), x[i], i + 1 == x.size() ?   n  :    );   }   void solve() {     int n = gi();     vector<int> a = gvi(n);     for (int i = 0; i < a.size(); ++i) {       for (int j = i + 1; j < a.size(); ++j) {         for (int k = j + 1; k < a.size(); ++k) {           if (a[i] == a[j] + a[k]) {             printf( %d %d %d n , i + 1, j + 1, k + 1);             return;           }           if (a[j] == a[i] + a[k]) {             printf( %d %d %d n , j + 1, i + 1, k + 1);             return;           }           if (a[k] == a[i] + a[j]) {             printf( %d %d %d n , k + 1, i + 1, j + 1);             return;           }         }       }     }     printf( -1 n );   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     long long n, m, i, ans = 0, z, j;     pair<long long, long long> a[105];     vector<pair<long long, long long> > q;     cin >> n >> m;     for (i = 1; i <= n; i++) a[i].second = 0;     for (i = 1; i <= n; i++) cin >> a[i].first;     for (j = 1; j <= m; j++) {       cin >> z;       a[z].second = 1;     }     for (i = 1; i <= n; i++) q.push_back(a[i]);     sort(q.begin(), q.end());     for (i = 0; i < n; i++)       if (q[i].second == 0) ans += q[i].first;     for (i = n - 1; i >= 0; i--)       if (q[i].second == 1) ans = ans + max(ans, q[i].first);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 998244353;   long long p[400001];   long long n;   vector<long long> a(100001);   bool check(long long x) {     long long cnt[n + 1];     for (int i = 1; i < n + 1; i++) cnt[i] = 0;     for (int i = 0; i < n; i++) cnt[a[i]]++;     set<pair<long long, long long>, greater<pair<long long, long long> > > ss;     for (int i = 1; i < n + 1; i++) {       if (cnt[i] > 0) ss.insert({cnt[i], i});     }     vector<long long> b;     for (int i = 0; i < n; i++) {       if (i >= x && cnt[b[i - x]] >= 1) {         ss.insert({cnt[b[i - x]], b[i - x]});       }       if (ss.empty()) return false;       b.push_back(ss.begin()->second);       cnt[ss.begin()->second]--;       ss.erase(ss.begin());     }     return true;   }   int main() {     long long t;     cin >> t;     while (t-- > 0) {       cin >> n;       for (int i = 0; i < n; i++) cin >> a[i];       long long l = 0, h = n;       long long ans;       while (l + 1 < h) {         long long mid = (l + h) / 2;         if (check(mid)) {           ans = mid;           l = mid;         } else           h = mid;       }       cout << ans - 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, long long> m;   long long n, p;   int main() {     cin >> n;     while (cin >> n) m[n]++;     for (n = 1; n < 11; n++) p += m[n] * m[n * -1];     cout << p + m[0] * (m[0] - 1) / 2;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[100], s, sum = 0;     cin >> n >> s;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (int i = 0; i < n - 1; i++) sum += a[i];     if (sum <= s)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int ar[1000];     int i;     for (i = 0; i < n; scanf( %d , &ar[i++]))       ;     int b = 0, e = n - 1;     int s = 0, d = 0;     i = 1;     while (b <= e) {       if (ar[b] > ar[e]) {         if (i == 1)           s = s + ar[b];         else           d = d + ar[b];         b++;       } else {         if (i == 1)           s = s + ar[e];         else           d = d + ar[e];         e--;       }       i = i * -1;     }     printf( %d %d , s, d);     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 5;   const long long infll = 1e18 + 5ll;   const long double eps = 1e-9;   const int maxn = 1e5 + 100;   const long long maxlog = 21;   const int P = 97;   const int mod = 1e9 + 9;   int n, m, lvl[maxn], up[maxlog][maxn], sub[maxn], par[maxn], ans[maxn];   std::vector<int> g[maxn];   bool ban[maxn];   void dfs1(int v = 1, int pr = 0) {     lvl[v] = lvl[pr] + 1;     up[0][v] = pr;     for (int i = 1; i < 20; ++i) up[i][v] = up[i - 1][up[i - 1][v]];     for (auto to : g[v])       if (pr != to) {         dfs1(to, v);       }   }   int nn;   void dfs2(int v, int pr) {     sub[v] = 1;     ++nn;     for (auto to : g[v]) {       if (to != pr && !ban[to]) {         dfs2(to, v);         sub[v] += sub[to];       }     }   }   int getCentroid(int v, int pr) {     for (auto to : g[v]) {       if (to != pr && !ban[to] && sub[to] * 2 > nn) {         return getCentroid(to, v);       }     }     return v;   }   void decompose(int v, int pr) {     nn = 0;     dfs2(v, pr);     int centroid = getCentroid(v, pr);     par[centroid] = pr;     ban[centroid] = 1;     for (auto to : g[centroid]) {       if (to == pr || ban[to]) continue;       decompose(to, centroid);     }   }   int lca(int a, int b) {     if (lvl[a] > lvl[b]) swap(a, b);     int d = lvl[b] - lvl[a];     for (int i = 0; i < maxlog; ++i)       if (d & (1 << i)) b = up[i][b];     if (a == b) return b;     for (int i = maxlog - 1; i >= 0; --i)       if (up[i][a] != up[i][b]) a = up[i][a], b = up[i][b];     return up[0][a];   }   int dist(int u, int v) { return lvl[u] + lvl[v] - 2 * lvl[lca(u, v)]; }   void upd(int v) {     int x = v;     while (x != 0) {       ans[x] = min(ans[x], dist(x, v));       x = par[x];     }   }   int query(int v) {     int x = v, res = inf;     while (x != 0) {       res = min(res, ans[x] + dist(x, v));       x = par[x];     }     return res;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);     if (fopen( sorting                 .in ,                r ))       freopen(            sorting             .in ,            r , stdin),           freopen(                sorting                 .out ,                w , stdout);     ;     cin >> n >> m;     for (int i = 1, u, v; i < n; ++i) {       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     dfs1();     decompose(1, 0);     memset(ans, inf, sizeof ans);     upd(1);     for (int i = 1, t, v; i <= m; ++i) {       cin >> t >> v;       if (t == 1) {         upd(v);       } else {         cout << query(v) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, ed, x, y;   int l[200005], qd[200005], qn[200005], p[200005];   void bd(int x, int y) { qd[++ed] = y, qn[ed] = l[x], l[x] = ed; }   int notinE(int x, int y) {     for (int i = (l[x]); i; i = qn[i])       if (qd[i] == y) return 0;     return 1;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = (0); i < (m); i++)       scanf( %d%d , &x, &y), bd(x - 1, y - 1), bd(y - 1, x - 1);     for (int i = (0); i < (n); i++) p[i] = i;     for (int i = (0); i < (75); i++) {       random_shuffle(p, p + n);       p[n] = p[0];       int ok = 1;       for (int j = (1); j <= (m); j++)         if (!notinE(p[j - 1], p[j])) {           ok = 0;           break;         }       if (ok) {         for (int j = (1); j <= (m); j++)           printf( %d %d n , p[j - 1] + 1, p[j] + 1);         return 0;       }     }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cmpfunc(const void *a, const void *b) { return (*(int *)a - *(int *)b); }   long long int gcd(long long int m, long long int n) {     if (n == 0) return m;     return gcd(n, m % n);   }   long long int fastpow(long long int a, long long int b, long long int m) {     long long int r = 1;     while (b > 0) {       if (b % 2 == 1) r = (r * a) % m;       b = b >> 1;       a = (a * a) % m;     }     return r;   }   int prime(long long int x) {     if (x == 1) return 0;     if (x <= 3) return 1;     if (x % 6 == 1 || x % 6 == 5) {       long long int y = sqrt(x), i;       for (i = 2; i <= y; i++)         if (x % i == 0) return 0;       return 1;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long int n, t;     cin >> n >> t;     if (n == 1 && t == 10)       cout << -1 << endl;     else if (t <= 9) {       for (long long int i = 0; i < n; i++) cout << t;       cout << endl;     } else {       cout << 1;       for (long long int i = 1; i < n; i++) cout << 0;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long blockSize;   long long cnt[100005];   long long ans[100005];   struct Query {     long long L, R, idx;   };   bool compare(Query x, Query y) {     if (x.L / blockSize != y.L / blockSize)       return x.L / blockSize < y.L / blockSize;     return x.R < y.R;   }   void queryResults(long long a[], long long n, Query q[], long long m) {     blockSize = (long long)sqrt(n);     sort(q, q + m, compare);     long long currL = 0, currR = 0;     long long currCnt = 0;     for (long long i = 0; i < m; i++) {       long long L = q[i].L, R = q[i].R;       while (currL < L) {         if (a[currL] > 100000) {           currL++;           continue;         }         if (cnt[a[currL]] == a[currL]) currCnt--;         cnt[a[currL]]--;         if (cnt[a[currL]] == a[currL]) currCnt++;         currL++;       }       while (currL > L) {         if (a[currL - 1] > 100000) {           currL--;           continue;         }         if (cnt[a[currL - 1]] == a[currL - 1]) currCnt--;         cnt[a[currL - 1]]++;         if (cnt[a[currL - 1]] == a[currL - 1]) currCnt++;         currL--;       }       while (currR <= R) {         if (a[currR] > 100000) {           currR++;           continue;         }         if (cnt[a[currR]] == a[currR]) currCnt--;         cnt[a[currR]]++;         if (cnt[a[currR]] == a[currR]) currCnt++;         currR++;       }       while (currR > R + 1) {         if (a[currR - 1] > 100000) {           currR--;           continue;         }         if (cnt[a[currR - 1]] == a[currR - 1]) currCnt--;         cnt[a[currR - 1]]--;         if (cnt[a[currR - 1]] == a[currR - 1]) currCnt++;         currR--;       }       ans[q[i].idx] = currCnt;     }     for (long long i = 0; i < m; i++) cout << ans[i] << endl;   }   int main() {     long long n, m;     cin >> n >> m;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     Query q[m];     for (long long i = 0; i < m; i++) {       cin >> q[i].L >> q[i].R;       q[i].L--;       q[i].R--;       q[i].idx = i;     }     queryResults(a, n, q, m);     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4101)   using namespace std;   const double pi = acos(-1.0);   const int INF = 1000000000;   const int MAX = 100007;   const int MAX2 = 2000000;   const int inf = (int)1e9 + 5;   const long long mod = 1e9 + 7;   const int BASE = 10;   const int ST = 1000003;   const int CNT = 100;   const double eps = 1e-6;   const long long base = 2204234849;   const long long l_inf = (long long)4e18;   const int logn = 30;   int main() {     long long n, a, b, c, d, maxim1, maxim2;     cin >> n >> a >> b >> c >> d;     long long sum1 = a + b, sum2 = b + d, sum3 = c + a, sum4 = d + c;     int minim = min(sum1, min(sum2, min(sum3, sum4)));     int kol = 0;     maxim1 = minim + n;     int maxim = max(sum1, max(sum2, max(sum3, sum4)));     if (maxim > maxim1) {       cout << 0;       return 0;     }     cout << n * (maxim1 - maxim);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }   long long fun(long long n) {     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) return i;     }     return n;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, c = 0;     cin >> n;     if (n % 2 != 0) {       n = n - fun(n);       c++;     }     cout << c + n / 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 5009;   string s[MAX];   int n, m, b[MAX], ans, a[MAX];   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < m; i++) {       memset(a, 0, sizeof a);       for (int j = 0; j < n; j++)         if (s[j][i] ==  1 )           b[j]++, a[b[j]]++;         else           b[j] = 0;       for (int i = m; i >= 0; i--) a[i] += a[i + 1], ans = max(ans, a[i] * i);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 200 * 1000 + 10;   pair<int, int> a[maxN];   int nx[maxN];   stack<int> curr;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int d, n, m;     cin >> d >> n >> m;     for (int i = 0; i < m; i++) cin >> a[i].first >> a[i].second;     sort(a, a + m);     a[m].first = d;     curr.push(m);     for (int i = m - 1; i >= 0; i--) {       while (curr.size() > 1 && a[curr.top()].second >= a[i].second) curr.pop();       nx[i] = curr.top();       curr.push(i);     }     int fuel = n;     long long cost = 0;     for (int i = 0; i <= m; i++) {       fuel -= a[i].first - (i ? a[i - 1].first : 0);       if (fuel < 0) {         cout << -1 << endl;         return 0;       }       if (i == m) break;       int x = min(n - fuel, max(0, a[nx[i]].first - a[i].first - fuel));       fuel += x;       cost += a[i].second * 1ll * x;     }     cout << cost << endl;   }


#include <bits/stdc++.h>   using namespace std;   int ar[300005];   char ch[300005];   int n, m, ii, k;   int pre[300005];   vector<pair<int, int>> v;   void solve() {     v.clear();     scanf( %d%d%s , &n, &m, ch);     for (int i = 1; i <= n; i++) {       pre[i] = pre[i - 1];       if (i & 1) {         if (ch[i - 1] ==  + )           pre[i]++;         else           pre[i]--;       } else {         if (ch[i - 1] ==  - )           pre[i]++;         else           pre[i]--;       }       v.push_back({pre[i] + n, i});     }     sort(v.begin(), v.end());     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       int len = y - x + 1;       if (pre[y] - pre[x - 1] == 0) {         printf( 0 n );         continue;       }       if (len & 1)         printf( 1 n );       else         printf( 2 n%d  , x), x++;       int val = pre[y] - pre[x - 1];       if (x % 2 == 0) val *= -1;       int extra = val - (val / 2);       if (x % 2 == 0) extra *= -1;       val = pre[x - 1] + extra + n;       auto it = lower_bound(v.begin(), v.end(), make_pair(val, x));       printf( %d n , it->second);     }   }   int main() {     int t = 1;     scanf( %d , &t);     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>      using namespace std;   const int mod = 1e9 + 7;   namespace math   {          int inc(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }       int qpow(int a, int x, int mo)       {           int res = 1;           while (x)           {               if (x & 1)                   res = 1ll * res * a % mod;               a = 1ll * a * a % mod;               x >>= 1;           }           return res;       }       vector<int> Fac, invFac;       void Finit(int n)       {           Fac.resize(n + 1);           invFac.resize(n + 1);           Fac[0] = 1;           invFac[0] = 1;           for (int i = 1; i <= n; i++)               Fac[i] = 1ll * Fac[i - 1] * i % mod;           invFac[n] = qpow(Fac[n], mod - 2, mod);           for (int i = n - 1; i >= 1; i--)               invFac[i] = 1ll * invFac[i + 1] * (i + 1) % mod;       }       int C(int n, int m)       {           if (m == 0)               return 1;           if (n < m || m < 0)               return 0;           return (int)(1ll * Fac[n] * invFac[m] % mod * invFac[n - m] % mod);       }       int A(int n, int m)       {           if (n < m || m < 0)               return 0;           return (int)(1ll * Fac[n] * invFac[n - m] % mod);       }   }   using namespace math;   void solve()   {       int n, l, r;       cin >> n >> l >> r;       Finit(n);       int ans = 0;       int up = r - n, dn = 1 - l;       if (dn < up)       {           if (n & 1)           {               ans = inc(ans, 2ll * dn * C(n, n / 2) % mod);           }           else           {               ans = inc(ans, 1ll * dn * C(n, n / 2) % mod);           }           for (int i = 1; i <= n; i++)           {               int need_add = i;               int need_del = max(0, dn - up + i);               if (n - need_del - need_add < 0)                   break;               ans = inc(ans, 1ll * C(n - need_del - need_add, n / 2 - need_add) % mod);               if (n & 1)                   ans = inc(ans, 1ll * C(n - need_del - need_add, n / 2 + 1 - need_add) % mod);           }       }       else       {           if (n & 1)           {               ans = inc(ans, 2ll * up * C(n, n / 2) % mod);           }           else           {               ans = inc(ans, 1ll * up * C(n, n / 2) % mod);           }              for (int i = 1; i <= n; i++)           {               int need_del = i;               int need_add = max(0, up - dn + i);                  if (n - need_del - need_add < 0)                   break;               ans = inc(ans, 1ll * C(n - need_del - need_add, n / 2 - need_add) % mod);               if (n & 1)                   ans = inc(ans, 1ll * C(n - need_del - need_add, n / 2 + 1 - need_add) % mod);               //cout << ans << endl;           }       }       cout << ans << endl;   }   int main()   {       ios::sync_with_stdio(false);       cin.tie(nullptr);       int T = 1;       cin >> T;       while (T--)       {           solve();       }   }


#include <bits/stdc++.h>   using namespace std;   const long long p = 1e9 + 7;   long long read() {     long long s = 0;     char c = getchar(), lc =  + ;     while (c <  0  ||  9  < c) lc = c, c = getchar();     while ( 0  <= c && c <=  9 ) s = s * 10 + c -  0 , c = getchar();     return lc ==  -  ? -s : s;   }   void write(long long x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x < 10)       putchar(x +  0 );     else {       write(x / 10);       putchar(x % 10 +  0 );     }   }   void print(long long x, char c =   n ) {     write(x);     putchar(c);   }   inline void add(long long &x, long long y) {     x += y;     if (x >= p) x -= p;   }   inline long long lowbit(long long x) { return x & -x; }   inline long long calc(long long x1, long long x2, long long y1, long long y2,                         long long k) {     if (x2 - x1 < y2 - y1) swap(x1, y1), swap(x2, y2);     long long tmp = x2 - x1;     x2 = (x1 = (x1 ^ y1) & ~(tmp - 1)) + tmp;     x1++;     x2 = min(x2, k);     if (x1 > x2 || y1 > y2) return 0;     return (x1 + x2) * (x2 - x1 + 1) / 2 % p * (y2 - y1) % p;   }   inline long long solve(long long x, long long y, long long k) {     long long ret = 0;     for (long long i = x; i; i &= i - 1)       for (long long j = y; j; j &= j - 1)         add(ret, calc(i - lowbit(i), i, j - lowbit(j), j, k));     return ret;   }   signed main() {     long long q = read();     while (q--) {       long long x1 = read(), y1 = read(), x2 = read(), y2 = read(), k = read();       print((solve(x2, y2, k) - solve(x1 - 1, y2, k) - solve(x2, y1 - 1, k) +              solve(x1 - 1, y1 - 1, k) + p + p) %             p);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Nmax = 100000 + 10;   int n;   int nr[Nmax];   char s[Nmax], ans[Nmax];   bool ok(int L, int R) {     int i, sum;     if (L > R) return 0;     for (i = 1; i <= n; ++i) nr[i] = s[i] -  0 ;     if (L == 1 && nr[R] == 0) return 0;     if (L == 2 && nr[1] != 1) return 0;     for (nr[L] += nr[L - 1] * 10; true; L++, R--) {       if (L == R) {         ans[L] = nr[L] / 2 +  0 ;         return nr[L] % 2 == 0;       }       if (L + 1 == R) {         sum = nr[L];         if (nr[L] == nr[R] + 11) sum--;         ans[L] = ans[R] = sum / 2 +  0 ;         if (sum & 1) ans[L]++;         return (nr[L] == nr[R] || nr[L] == nr[R] + 11);       }       if (nr[L] - nr[R] != 0 && nr[L] - nr[R] != 1 && nr[L] - nr[R] != 10 &&           nr[L] - nr[R] != 11)         return 0;       sum = nr[L];       if (nr[L] == nr[R])         ;       if (nr[L] == nr[R] + 1 || nr[L] == nr[R] + 11) sum--, nr[L + 1] += 10;       if (nr[L] == nr[R] + 10 || nr[L] == nr[R] + 11) {         if (nr[R] == 9) return 0;         for (i = R - 1; i >= L && nr[i] == 0; --i) nr[i] = 9;         if (i == L) return 0;         nr[i]--;       }       ans[L] = ans[R] = sum / 2 +  0 ;       if (sum & 1) ans[L]++;       int mata = 5;     }     return 1;   }   int main() {     gets(s + 1);     n = strlen(s + 1);     if (ok(1, n))       puts(ans + 1);     else if (ok(2, n))       puts(ans + 2);     else       puts( 0 );     return 0;   }