#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const long long LINF = 1e17;   const double PI = 3.141592653589793238;   const int mod = 1000000007;   const double eps = 0.000001;   template <typename T, typename TT>   ostream &operator<<(ostream &s, pair<T, TT> t) {     return s <<  (  << t.first <<  ,  << t.second <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &s, vector<T> t) {     for (int i = 0; i < (t).size(); i++)       s << t[i] << ((i < (t).size() - 1) ?     :   );     return s;   }   template <typename T>   ostream &operator<<(ostream &s, set<T> t) {     for (T x : t) s << x <<    ;     return s;   }   template <typename T>   istream &operator>>(istream &s, vector<T> &t) {     for (int _i = 0; _i < t.size(); _i++) s >> t[_i];     return s;   }   int main(int argc, const char *argv[]) {     int n;     cin >> n;     int q[10][1023], p[10][1023];     for (int i = (0); i < (int)(10); i++)       for (int j = (0); j < (int)(n); j++) q[i][j] = p[i][j] = INF;     for (int i = (0); i < (int)(10); i++) {       vector<int> cq, cp;       for (int j = (0); j < (int)(n); j++) {         if (j & (1 << i))           cp.push_back(j + 1);         else           cq.push_back(j + 1);       }       if (cp.size() > 0) {         cout << cp.size() <<   n  << cp <<   n ;         fflush(stdout);         for (int j = (0); j < (int)(n); j++) cin >> p[i][j];       }       if (cq.size() < n) {         cout << cq.size() <<   n  << cq <<   n ;         fflush(stdout);         for (int j = (0); j < (int)(n); j++) cin >> q[i][j];       }     }     cout <<  -1 n ;     for (int j = (0); j < (int)(n); j++) {       int minv = INF;       for (int i = (0); i < (int)(10); i++) {         if (j & (1 << i))           minv = min(minv, q[i][j]);         else           minv = min(minv, p[i][j]);       }       cout << minv <<    ;     }   }


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


#include <bits/stdc++.h>   using namespace std;   int arr[200005];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     int now = arr[0], cnt = 1;     set<int> sup;     stack<int> sdown;     sup.insert(now);     for (int i = 1; i < n; i++) {       if (arr[i] == now) {         cnt++;         sdown.push(arr[i]);       } else {         now = arr[i];         sup.insert(now);         cnt = 1;       }       if (cnt >= 3) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     cout << sup.size() << endl;     bool flag = true;     for (auto i = sup.begin(); i != sup.end(); i++) {       if (flag) {         cout << *i;         flag = false;       } else         cout <<     << *i;     }     cout << endl;     cout << sdown.size() << endl;     flag = true;     while (!sdown.empty()) {       if (flag) {         cout << sdown.top();         flag = false;       } else         cout <<     << sdown.top() << endl;       sdown.pop();     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct __timestamper {};   int main() {     int n;     scanf( %d , &n);     vector<int> l(n), r(n);     for (int i = 0; i < n; i++) scanf( %d%d , &l[i], &r[i]);     double ans = 0;     for (int i = 1; i <= 10000; i++) {       double prob[3];       prob[0] = 1;       prob[1] = prob[2] = 0;       for (int j = 0; j < n; j++) {         double p = max(r[j] - max(l[j], i) + 1, 0) * 1.0 / (r[j] - l[j] + 1);         prob[2] += prob[1] * p;         prob[1] = prob[1] * (1.0 - p) + prob[0] * p;         prob[0] *= 1.0 - p;       }       ans += prob[2];     }     printf( %.10f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007LL;   const int lmt = 1005;   const long long inf = 1LL << 62;   long long dp[lmt][lmt], a[lmt], req[lmt];   int n;   long long solve(int idx, int left) {     if (idx > n) return 0;     if (dp[idx][left] != -1) return dp[idx][left];     long long ans = min(a[idx], solve(idx + 1, left) + a[idx]);     if (left > 0) ans = max(solve(idx + 1, left - 1), ans);     return dp[idx][left] = ans;   }   void process() {     memset(dp, -1, sizeof(dp));     for (int i = 0; i <= n; i++) {       req[i] = solve(1, i);     }   }   int main() {     int q;     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     process();     while (q--) {       long long val;       scanf( %lld , &val);       for (int i = 0; i <= n; i++) {         if ((req[i] + val) >= 0) {           printf( %d n , i);           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(       (unsigned int)chrono::steady_clock::now().time_since_epoch().count());   const int MAGIC = 239;   const int N = 100010;   vector<int> g[N];   bool in_st[N];   bool was[N];   bool dfs(int v) {     was[v] = true;     in_st[v] = true;     for (int u : g[v]) {       if (was[u]) {         if (!in_st[u]) {           in_st[v] = false;           return false;         }       } else {         if (!dfs(u)) {           in_st[v] = false;           return false;         }       }     }     in_st[v] = false;     return true;   }   vector<int> vis;   int depth[N];   int md[N];   int md2[N];   int mver[N];   int mver2[N];   void Update(int v, int x, int y) {     if (x < md[v]) {       md2[v] = md[v];       mver2[v] = mver[v];       md[v] = x;       mver[v] = y;     } else {       if (x < md2[v]) {         md2[v] = x;         mver2[v] = y;       }     }   }   void solve(int v) {     vis.push_back(v);     was[v] = true;     md[v] = md2[v] = depth[v];     mver[v] = mver2[v] = v;     for (int u : g[v]) {       if (was[u]) {         assert(depth[u] < depth[v]);         Update(v, depth[u], u);       } else {         depth[u] = depth[v] + 1;         solve(u);         Update(v, md[u], mver[u]);         Update(v, md2[u], mver2[u]);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       int n, m;       cin >> n >> m;       for (int i = 0; i < n; i++) {         g[i].clear();       }       for (int i = 0; i < m; i++) {         int x, y;         cin >> x >> y;         --x;         --y;         g[x].push_back(y);       }       vector<int> order(n);       iota(order.begin(), order.end(), 0);       shuffle(order.begin(), order.end(), rng);       int root = -1;       for (int iter = 0; iter < min(n, MAGIC); iter++) {         for (int i = 0; i < n; i++) {           was[i] = in_st[i] = false;         }         if (dfs(order[iter])) {           root = order[iter];           break;         }       }       if (root == -1) {         cout << -1 <<   n ;         continue;       }       for (int i = 0; i < n; i++) {         was[i] = false;       }       vis.clear();       depth[root] = 0;       solve(root);       vector<bool> is_good(n);       for (int i : vis) {         if (i == root) {           is_good[i] = true;         } else {           if (md[i] < depth[i] && md2[i] >= depth[i]) {             is_good[i] = is_good[mver[i]];           } else {             is_good[i] = false;           }         }       }       vector<int> res;       for (int i = 0; i < n; i++) {         if (is_good[i]) {           res.push_back(i);         }       }       if ((int)res.size() * 5 < n) {         cout << -1 <<   n ;         continue;       }       for (int i = 0; i < (int)res.size(); i++) {         if (i > 0) {           cout <<    ;         }         cout << res[i] + 1;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gems[30050], maxi = INT_MIN;   int dp[30005][600], kood;   int solve(int i, int d) {     int change = 300 + (d - kood);     if (i > maxi) return 0;     if (dp[i][change] != -1) return dp[i][change];     if (d == 1) {       return dp[i][change] =                  gems[i] + max(solve(i + d, d), solve(i + d + 1, d + 1));     }     return dp[i][change] =                gems[i] + max(solve(i + d - 1, d - 1),                              max(solve(i + d, d), solve(i + d + 1, d + 1)));   }   int main() {     int n, d, x;     cin >> n >> d;     kood = d;     memset(dp, -1, sizeof(dp));     for (int i = 0; i < n; i++) {       cin >> x;       gems[x]++;       maxi = max(maxi, x);     }     cout << solve(d, d) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   struct node {     int a, b, id;     bool operator<(const node& tem) const { return a > tem.a; }   } vec[maxn];   bool used[maxn];   int n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &vec[i].a);     for (int i = 1; i <= n; i++) scanf( %d , &vec[i].b);     for (int i = 1; i <= n; i++) vec[i].id = i;     sort(vec + 1, vec + 1 + n);     priority_queue<pair<int, int> > q;     int pcou = 1, cnt = 0;     for (int i = 1; i <= n / 2 + 1; i++) {       while (pcou <= n && pcou <= 2 * i - 1) {         q.push(pair<int, int>(vec[pcou].b, vec[pcou].id));         ++pcou;       }       if (!q.empty()) {         ++cnt;         int id = q.top().second;         q.pop();         used[id] = 1;       }     }     printf( %d n , cnt);     for (int i = 1; i <= n; i++)       if (used[i]) printf( %d  , i);     return 0;   }


#include <bits/stdc++.h>   const int long long N = 10e8 + 7;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       vector<int> odd, even;       for (int i = 0; i < n; i++) {         cin >> arr[i];         if (arr[i] % 2 == 0)           even.push_back(arr[i]);         else           odd.push_back(arr[i]);       }       int p = int(odd.size()), q = even.size();       if (p % 2 == 0 && q % 2 == 0) {         cout <<  YES  <<   n ;         continue;       }       bool flag = 0;       for (int i = 0; i < p; i++) {         for (int j = 0; j < q; j++) {           if (int(abs(even[j] - odd[i])) == 1) flag = 1;         }         if (flag) break;       }       if (flag)         cout <<  YES  <<   n ;       else         cout <<  NO  <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   set<int> st;   set<int>::iterator it;   int n, m, used[N], hmm[N];   vector<int> graph[N], vec, b[N];   void lmao() {     if (st.size() == 0) {       return;     }     it = st.begin();     int u = *it;     for (int i = 0; i < graph[u].size(); i++) {       int v = graph[u][i];       st.erase(v);     }     st.erase(u);     lmao();     for (int i = 0; i < b[u].size(); i++) {       int v = b[u][i];       if (hmm[v]) return;     }     hmm[u] = 1;     vec.push_back(u);   }   int main() {     cin.tie(0), ios::sync_with_stdio(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) st.insert(i);     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       graph[u].push_back(v);       b[v].push_back(u);     }     lmao();     cout << vec.size() <<   n ;     for (int i = 0; i < vec.size(); i++) cout << vec[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   void sort_vec(vector<int> x, vector<int> b, int cnt) {     int index;     int max = 101;     for (; cnt > 0; cnt--) {       for (int j = 0; j < x.size(); j++) {         if (x[j] < max) {           index = j;           max = x[j];         }       }       cout << x[index] <<     << b[index] << endl;       x[index] = 101;       b[index] = 101;     }   }   int main() {     int x, y, a, b;     cin >> x >> y >> a >> b;     vector<int> va;     vector<int> vb;     int cnt = 0;     for (int i = b; i <= y; i++) {       for (int j = a; j <= x; j++) {         if (j <= i) continue;         cnt++;         va.push_back(j);         vb.push_back(i);       }     }     cout << cnt << endl;     int index, tmp = 101;     while (cnt > 0) {       tmp = 101;       for (int i = 0; i < va.size(); i++) {         if (va[i] < tmp) {           tmp = va[i];           index = i;         }       }       cout << va[index] <<     << vb[index] << endl;       va.erase(va.begin() + index, va.begin() + index + 1);       vb.erase(vb.begin() + index, vb.begin() + index + 1);       cnt--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 410;   int cl[maxn * maxn];   int po[maxn * maxn];   int pre[maxn * maxn * 2];   int cnt[maxn * maxn * 2];   short cc[maxn * maxn * 2];   short F[maxn][maxn];   short g[maxn][maxn];   int a[maxn][maxn];   int b[maxn][maxn];   int pos[maxn][maxn];   int n, m;   int find(int x) { return cnt[x] ? x : pre[x] = find(pre[x]); }   inline void init(int x, short f[][maxn], int a[][maxn]) {     int tot = maxn * maxn;     for (int i = x; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cl[a[i][j]] = 0, po[a[i][j]] = a[i][j] + 1;         cc[a[i][j] + 1] = 0;         cnt[a[i][j] + 1] = 1;       }     }     for (int i = 0; i <= m; i++) f[x - 1][i] = 0;     for (int j = 1; j <= m; j++) {       for (int i = x; i <= n; i++) {         if (cl[a[i][j]] != j) {           pos[i][j] = tot;           cnt[tot] = 1;           cc[tot] = j;           pre[tot] = po[a[i][j]];           po[a[i][j]] = tot;           tot++;         } else {           pos[i][j] = po[a[i][j]];           cnt[pos[i][j]]++;         }         cl[a[i][j]] = j;       }     }     for (int i = n; i >= x; i--) {       for (int j = m; j > 0; j--) {         int p = pos[i][j];         cnt[p]--;         f[i][j] = cc[find(p)];       }     }     for (int i = x; i <= n; i++) {       for (int j = 1; j <= m; j++) {         f[i][j] = max(f[i][j], max(f[i - 1][j], f[i][j - 1]));       }     }   }   int main() {     int w = 0;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &a[i][j]);         b[i][m - j + 1] = a[i][j];       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       init(i, F, a);       init(i, g, b);       for (int j = i; j <= n; j++) {         int r = 1;         for (int k = 1; k <= m; k++) {           for (int len = m - g[j][m - k + 1]; r <= len; r++) {             if (F[j][r] >= k) break;           }           ans = max(ans, (j - i + 1) * (r - k));         }       }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int N;   int mov[2][4] = {{-1, 0, 0, 1}, {0, -1, 1, 0}};   long long X[31], Y[31];   vector<int> graph[31];   void BuildTree(int node, int parent, int dir, long long dist) {     if (graph[node].size() > 4) {       cout <<  NO n ;       exit(0);     }     for (int i = 0, j = 0; i < graph[node].size(); i++)       if (graph[node][i] != parent) {         if (dir == 3 - j) j = (j + 1) % 4;         X[graph[node][i]] = X[node] + dist * mov[0][j];         Y[graph[node][i]] = Y[node] + dist * mov[1][j];         BuildTree(graph[node][i], node, j, dist / 2);         j = (j + 1) % 4;       }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cin >> N;     for (int i = 0; i < N - 1; i++) {       int u, v;       cin >> u >> v;       graph[u].push_back(v);       graph[v].push_back(u);     }     BuildTree(1, 1, -1, 1ll << 30);     cout <<  YES n ;     for (int i = 1; i <= N; i++) cout << X[i] <<     << Y[i] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[2 * (int)(1e5 + 51)], b[2 * (int)(1e5 + 51)];   bool visited[2 * (int)(1e5 + 51)];   vector<int> g[2 * (int)(1e5 + 51)];   void dfs(int x) {     visited[x] = 1;     for (auto v : g[x]) {       if (!visited[v]) dfs(v);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 1; i <= n; i++) {         int x;         cin >> x;         a[i] = {x, i};       }       for (int i = 1; i <= n; i++) {         int x;         cin >> x;         b[i] = {x, i};       }       sort(a + 1, a + 1 + n);       reverse(a + 1, a + 1 + n);       sort(b + 1, b + 1 + n);       reverse(b + 1, b + 1 + n);       for (int i = 1; i < n; i++) g[a[i + 1].second].push_back({a[i].second});       for (int i = 1; i < n; i++)         if (((int)g[b[i + 1].second].size() &&              g[b[i + 1].second][0] != b[i].second) ||             !(int)g[b[i + 1].second].size())           g[b[i + 1].second].push_back(b[i].second);       dfs(b[1].second);       dfs(a[1].second);       string ans =   ;       for (int i = 1; i <= n; i++) {         if (visited[i])           ans +=  1 ;         else           ans +=  0 ;         visited[i] = 0;         g[i].clear();       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long po(long long x, long long y) {     if (y == 0)       return 1;     else       return x * po(x, y - 1);   }   vector<long long> a[7], b[7];   void solve(long long l, long long r, long long d) {     if (l == r) return;     long long m = (l + r) >> 1;     for (long long i = l; i <= m; i++) a[d].push_back(i);     for (long long i = m + 1; i <= r; i++) b[d].push_back(i);     solve(l, m, d + 1);     solve(m + 1, r, d + 1);   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       for (long long i = 0; i < 7; i++) {         a[i].clear();         b[i].clear();       }       solve(1, n, 0);       long long ans = 0;       for (long long i = 0; i < 7; i++) {         if (a[i].empty() || b[i].empty()) break;         cout << a[i].size() <<     << b[i].size() <<    ;         for (auto it : a[i]) cout << it <<    ;         for (auto it : b[i]) cout << it <<    ;         cout << endl;         long long x;         cin >> x;         ans = max(ans, x);       }       cout <<  -1   << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, y, n;     cin >> x >> y >> n;     long long a = -1, b = -1;     for (int i = 1; i <= n; i++) {       int t = x * i * 1.0 / y;       if (abs(t * y - i * x) > abs((t + 1) * y - i * x)) t++;       if (a == -1 || (abs(t * y - i * x) * b < abs(a * y - b * x) * i))         a = t, b = i;     }     cout << a <<  /  << b;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, i;   void input() {     cin >> n;     return;   }   void output() { return; }   void lolicon() {     n = abs(n);     while (!(i * (i + 1) / 2 >= n && (i * (i + 1) / 2 - n) % 2 == 0)) i++;     cout << i;   }   int main() {     ios_base::sync_with_stdio(false);     input();     lolicon();     output();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 1e9 + 7;   const long long INF = LLONG_MAX / 2;   const long long N = 1e4;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       string s;       cin >> s;       sort(s.begin(), s.end());       char last = s[n - 1];       vector<string> a(k);       for (long long i = 0; i < k; i++) a[i].append(1, s[i]);       long long i = k, j = 0;       if (count(a.begin(), a.end(), a[0]) == k && s[i] == last)         while (i < n) {           a[j % k].append(1, s[i]);           i++;           j++;         }       else         a[j].append(s.substr(k, n - k));       cout << *max_element(a.begin(), a.end()) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double PI = acosl(-1);   bool compare_int(int a, int b) { return (a > b); }   bool compare_string(string a, string b) { return a.size() < b.size(); }   bool compare_pair(const pair<int, int> &a, const pair<int, int> &b) {     if (a.second == b.second)       return a.first > b.first;     else       return (a.second > b.second);   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int r, c;     cin >> r >> c;     if (r == 1 and c == 1) {       cout << 0 << endl;       return 0;     }     if (r == 1) {       for (int i = 1; i <= c; i++) cout << i + 1 <<    ;       return 0;     }     if (c == 1) {       for (int i = 1; i <= r; i++) cout << i + 1 << endl;       return 0;     }     for (int i = 1; i <= r; i++) {       for (int j = 1; j <= c; j++) {         cout << i * (r + j);         j == c ? cout << endl : cout <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, n1, n2, mn, mx;   int A[100001];   int main() {     cin >> n >> n1 >> n2;     for (int i = 0; i < n; i++) {       cin >> A[i];     }     sort(A, A + n);     mn = min(n1, n2);     mx = max(n1, n2);     double s1 = 0;     double s2 = 0;     int nr = 0;     int k = 0;     for (int i = n - 1; k < mn; i--, k++) {       s1 = s1 + A[i];       nr = i;     }     k = 0;     for (int i = nr - 1; k < mx; i--, k++) {       s2 = s2 + A[i];     }     cout << fixed << s1 / mn + s2 / mx << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double res;   long long n, m, k, i, j, x = 1, y, t, a[1000001], b[1000001];   int main() {     cin >> n;     for (i = 1; i <= n; i++) {       cin >> t;       if (t == 1) {         cin >> k >> m;         a[k] += m;         y += k * m;         printf( %.10f , (double)y / x);         cout << endl;       }       if (t == 2) {         cin >> k;         y += k;         x++;         b[x] = k;         printf( %.10f , (double)y / x);         cout << endl;       }       if (t == 3) {         a[x - 1] += a[x];         y -= a[x] + b[x];         a[x] = 0;         x--;         printf( %.10f , (double)y / x);         cout << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const signed long long int INF = 1e9;   int main() {     int n;     cin >> n;     vector<signed long long int> a(n);     for (int i(0); i < n; i++) {       scanf( %lld , &a[i]);     }     int s, f;     scanf( %d %d , &s, &f);     vector<signed long long int> d(n + 1);     d[0] = a[0];     for (int i(1); i < n; i++) {       d[i] = d[i - 1] + a[i];     }     signed long long int ans = 0;     signed long long int tp = INF;     for (int i(0); i < n; i++) {       int l = (i + s - 1 + n) % n;       int r = (i + f - 2 + n) % n;       signed long long int tmp = 0;       if (l <= r) {         tmp += d[r];         if (l - 1 >= 0) tmp -= d[l - 1];       } else {         tmp += d[r];         tmp += d[n - 1];         if (l - 1 >= 0) tmp -= d[l - 1];       }       if (ans <= tmp) {         signed long long int ti;         if (i == 0)           ti = 1;         else           ti = n - 1 - i + 2;         if (ans == tmp) {           tp = min(tp, ti);         } else {           ans = tmp;           tp = ti;         }       }     }     cout << tp;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   void per() { cerr << endl; }   template <typename Head, typename... Tail>   void per(Head H, Tail... T) {     cerr << H <<    ;     per(T...);   }   template <class T>   bool uin(T& a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool uax(T& a, T b) {     return a < b ? (a = b, true) : false;   }   template <class U, class V>   ostream& operator<<(ostream& out, const pair<U, V>& a) {     return out <<  (  << a.first <<  ,   << a.second <<  ) ;   }   template <class U, class V>   istream& operator>>(istream& in, pair<U, V>& a) {     return in >> a.first >> a.second;   }   template <typename W,             typename T = typename enable_if<!is_same<W, string>::value,                                             typename W::value_type>::type>   ostream& operator<<(ostream& out, const W& v) {     out <<  {  ;     for (const auto& first : v) out << first <<  ,  ;     return out <<  } ;   }   template <class T>   void readArr(T from, T to) {     for (auto i = from; i != to; ++i) cin >> *i;   }   mt19937 mrand(1337);   unsigned int myRand32() { return mrand() & (unsigned int)(-1); }   unsigned long long myRand64() {     return ((unsigned long long)myRand32() << 32) ^ myRand32();   }   const int mod = 1000000007;   void add(int& a, int b) {     a += b;     if (a >= mod) a -= mod;   }   void dec(int& a, int b) {     a -= b;     if (a < 0) a += mod;   }   int mult(int a, int b) { return a * (long long)b % mod; }   int bp(int a, int b) {     int res = 1;     while (b > 0) {       if (b & 1) res = mult(res, a);       a = mult(a, a);       b >>= 1;     }     return res;   }   struct Vertex {     int l;     int r;     int father;     int cnt;   };   Vertex rmq[4000007];   int ptr = 0;   vector<int> want[4000007];   int create(int vertex) {     rmq[ptr++] = {-1, -1, vertex, 0};     want[ptr - 1] = {};     return ptr - 1;   }   void go(int vertex, long long l, long long r, long long l1, long long r1) {     if (l1 >= r1) return;     if (l == l1 && r == r1) {       rmq[vertex].cnt = 1;       return;     }     if (rmq[vertex].l == -1) {       rmq[vertex].l = create(vertex);     }     if (rmq[vertex].r == -1) {       rmq[vertex].r = create(vertex);     }     long long mid = (l + r) / 2;     go(rmq[vertex].l, l, mid, l1, min(r1, mid));     go(rmq[vertex].r, mid, r, max(l1, mid), r1);     rmq[vertex].cnt = rmq[rmq[vertex].l].cnt + rmq[rmq[vertex].r].cnt;   }   struct Node {     int p, r, f;   };   struct DSU {     static const int SZ = 10000007;     Node t[SZ];     DSU() { reset(SZ); }     void reset(int n) {       for (int i = 0; i < n; ++i) {         t[i].p = i;         t[i].r = 0;         t[i].f = 1;       }     }     int get(int v) {       if (t[v].p == v) return v;       return t[v].p = get(t[v].p);     }     int get_func(int v) { return t[get(v)].f; }     void merge(int a, int b) {       a = get(a), b = get(b);       if (a != b) {         if (t[a].r < t[b].r) swap(a, b);         t[b].p = a;         t[a].f += t[b].f;         if (t[a].r == t[b].r) ++t[a].r;       }     }   };   DSU dsu;   bool good(int vertex) {     if (vertex == -1) return false;     if (rmq[vertex].cnt) return false;     return true;   }   void restore(int vertex) {     if (good(rmq[vertex].father)) dsu.merge(vertex, rmq[vertex].father);     if (good(rmq[vertex].l)) dsu.merge(vertex, rmq[vertex].l);     if (good(rmq[vertex].r)) dsu.merge(vertex, rmq[vertex].r);     for (auto to : want[vertex]) dsu.merge(vertex, to);     int W = vertex;     vector<int> bits;     while (true) {       int t = rmq[vertex].father;       if (t == -1) break;       if (rmq[t].l == vertex)         bits.push_back(0);       else         bits.push_back(1);       vertex = t;     }     reverse(bits.begin(), bits.end());     int start = 0;     for (int i = 0; i < bits.size() && start != -1; ++i) {       bits[i] ^= 1;       int now = start;       for (int j = i; j < bits.size(); ++j) {         int first = bits[j];         if (first == 0) {           if (rmq[now].l == -1) {             break;           }           now = rmq[now].l;         } else {           if (rmq[now].r == -1) {             break;           }           now = rmq[now].r;         }       }       if (good(now)) {         dsu.merge(W, now);       } else         want[now].push_back(W);       bits[i] ^= 1;       if (bits[i] == 0) start = rmq[start].l;       if (bits[i] == 1) start = rmq[start].r;     }   }   void go_back(int vertex, long long l, long long r, long long l1, long long r1) {     if (l1 >= r1) return;     if (l == l1 && r == r1) {       rmq[vertex].cnt = 0;       restore(vertex);       return;     }     long long mid = (l + r) / 2;     go_back(rmq[vertex].l, l, mid, l1, min(r1, mid));     go_back(rmq[vertex].r, mid, r, max(l1, mid), r1);     int W = rmq[vertex].cnt;     rmq[vertex].cnt = rmq[rmq[vertex].l].cnt + rmq[rmq[vertex].r].cnt;     if (rmq[vertex].cnt == 0 && W != 0) restore(vertex);   }   int n, m;   int gg(long long first) {     int now = 0;     for (int i = n - 1; i >= 0; --i) {       int t = (((1LL << i) & first) > 0);       if (t == 0) {         if (rmq[now].l == -1) return now;         now = rmq[now].l;       } else {         if (rmq[now].r == -1) return now;         now = rmq[now].r;       }     }     return now;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     create(-1);     rmq[0].l = create(0);     rmq[0].r = create(0);     vector<tuple<int, long long, long long> > queries;     cin >> n >> m;     for (int i = 0; i < m; ++i) {       string s;       cin >> s;       if (s ==  ask ) {         long long l, r;         cin >> l >> r;         queries.push_back(make_tuple(0, l, r));       } else {         long long l, r;         cin >> l >> r;         queries.push_back(make_tuple(1, l, r));         go(0, 0, (1ll << n), l, r + 1);       }     }     vector<int> ans;     dsu.reset(ptr);     for (int i = 0; i < ptr; ++i) {       if (!rmq[i].cnt) {         restore(i);       }     }     reverse(queries.begin(), queries.end());     for (auto first : queries) {       int tp = get<0>(first);       long long l = get<1>(first);       long long r = get<2>(first);       if (tp == 1) {         go_back(0, 0, (1ll << n), l, r + 1);       } else {         int A = gg(l), B = gg(r);         if (dsu.get(A) == dsu.get(B) && !rmq[A].cnt && !rmq[B].cnt)           ans.push_back(1);         else           ans.push_back(0);       }     }     reverse(ans.begin(), ans.end());     for (auto first : ans) cout << first <<   n ;   }


#include<bits/stdc++.h>   #include<algorithm>   #define ll long long   using namespace std;   int main(){    ios_base::sync_with_stdio(false);       cin.tie(NULL);       int testcases;       cin>>testcases;       while(testcases--){        int n,k;        cin>>n>>k;        unsigned ll sum = 0 ;        cin>>sum;        unsigned ll diff = 0;        for (int i = 0; i < n-1; ++i)        {         ll current;         cin>>current;         double thiscase = (1.00*sum) / current ;         if(thiscase < (100.00/k)){          ll currentdiff = ceil((100.00*current) / k) - sum;          diff += currentdiff;          sum += currentdiff;         }           sum+= current;        }        cout<<diff<<  n ;       }   return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   long long ans = 0;   vector<int> graph[100005];   int depth[100005];   int parent[100005];   int weight[100005];   int ancestor[100005][17];   int comp[100005];   vector<int> comp_members[100005];   int comp_root[100005];   long long ansv[100005];   void merge_comp(int a, int b) {     if (comp_members[a].size() > comp_members[b].size()) swap(a, b);     ans -= (long long)(comp_members[a].size()) * ansv[a];     ans -= (long long)(comp_members[b].size()) * ansv[b];     for (int i = 0; i < comp_members[a].size(); i++) {       int x = comp_members[a][i];       comp_members[b].push_back(x);       comp[x] = b;     }     if (depth[comp_root[a]] < depth[comp_root[b]]) {       long long up_p2_sum = ((long long)(n - 1) * (long long)((n - 1) - 1)) -                             ansv[a] -                             ((long long)(weight[comp_root[b]]) *                              (long long)((weight[comp_root[b]]) - 1));       ansv[b] += ((long long)(n - weight[comp_root[b]]) *                   (long long)((n - weight[comp_root[b]]) - 1)) -                  up_p2_sum;       comp_root[b] = comp_root[a];     } else {       long long down_p2_sum = ((long long)(n - 1) * (long long)((n - 1) - 1)) -                               ansv[a] -                               ((long long)(n - weight[comp_root[a]]) *                                (long long)((n - weight[comp_root[a]]) - 1));       ansv[b] += ((long long)(weight[comp_root[a]]) *                   (long long)((weight[comp_root[a]]) - 1)) -                  down_p2_sum;     }     ans += (long long)(comp_members[b].size()) * ansv[b];     comp_members[a].clear();   }   void merge_chain(int from, int to) {     while (comp[from] != comp[to]) {       from = comp_root[comp[from]];       merge_comp(comp[from], comp[parent[from]]);     }   }   void dfs(int node, int prt) {     ansv[node] += ((long long)(n - 1) * (long long)((n - 1) - 1));     depth[node] = depth[prt] + 1;     parent[node] = prt;     weight[node] = 1;     for (int i = 0; i < graph[node].size(); i++) {       int nxt = graph[node][i];       if (nxt == prt) continue;       dfs(nxt, node);       weight[node] += weight[nxt];       ansv[node] -= ((long long)(weight[nxt]) * (long long)((weight[nxt]) - 1));     }     long long above = n - weight[node];     ansv[node] -= ((long long)(above) * (long long)((above)-1));     ans += ansv[node];   }   int lca(int A, int B) {     if (depth[A] < depth[B]) swap(A, B);     for (int i = 0; i < 17; i++) {       if ((depth[A] - depth[B]) & (1 << i)) A = ancestor[A][i];     }     if (A == B) return A;     for (int i = 17 - 1; i >= 0; i--) {       if (ancestor[A][i] != ancestor[B][i]) {         A = ancestor[A][i];         B = ancestor[B][i];       }     }     return parent[A];   }   void inputtree(int siz, int root = 1) {     for (int i = 1; i < siz; i++) {       int u, v;       scanf( %d%d , &u, &v);       graph[u].push_back(v);       graph[v].push_back(u);     }     dfs(root, 0);     for (int i = 1; i <= siz; i++) ancestor[i][0] = parent[i];     for (int pwr = 1; pwr < 17; pwr++) {       for (int i = 1; i <= siz; i++) {         ancestor[i][pwr] = ancestor[ancestor[i][pwr - 1]][pwr - 1];       }     }   }   int main() {     scanf( %d , &n);     inputtree(n);     for (int i = 1; i <= n; i++) {       comp[i] = i;       comp_members[i].push_back(i);       comp_root[i] = i;     }     printf( %lld n , ans);     scanf( %d , &q);     for (int qry = 1; qry <= q; qry++) {       int u, v;       scanf( %d%d , &u, &v);       int lcanode = lca(u, v);       merge_chain(u, lcanode);       merge_chain(v, lcanode);       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = pow(10, 9) + 7;   int main() {     ios_base::sync_with_stdio(false);     int k;     cin >> k;     string s;     cin >> s;     int n = s.length();     int l = 0, r = 0;     long long ans = 0LL;     long long count1 = 0;     while (l < n && k != 0) {       long long countL = 0, countr = 0;       bool found = false;       while (r < n) {         if (s[r] ==  1 ) count1++;         r++;         if (count1 == k) {           found = true;           break;         }       }       while (r < n && s[r] !=  1 ) {         countr++;         r++;       }       while (l < n && s[l] !=  1 ) {         countL++;         l++;       }       if (found) ans += (countL + 1) * (countr + 1);       count1--;       l++;     }     long long z = 0LL;     if (k == 0) {       for (int i = 0; i < n; i++) {         if (s[i] ==  0 )           z++;         else {           ans += (z * (z + 1)) / 2;           z = 0;         }       }     }     cout << (ans + (z * (z + 1)) / 2);     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, k, i, j, t;     vector<int> b, a;     vector<bool> v;     cin >> n >> k;     v.resize(n, false);     for (i = 0; i < n; i++) {       cin >> x;       b.push_back(x);       if (x == 0) {         v[i] = true;         a.push_back(i + 1);       }     }     for (i = n - 1; i >= 0; i--) {       if (!v[i]) {         t = 0;         for (j = 0; j < (int)a.size(); j++) {           if (a[j] >= i + 1 + k) {             t++;           }           if (t == b[i]) {             break;           }         }         a.insert(a.begin() + j + 1, i + 1);       }     }     for (i = 0; i < n; i++) {       cout << a[i] <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     long long a[n + 2][n + 2], i, j;     string s;     memset(a, 0, sizeof(a));     for (i = 1; i <= n; i++) {       cin >> s;       for (j = 1; j <= n; j++) a[i][j] = (s[j - 1] ==  B  ? 1 : 0);     }     long long left[n + 2][n + 2], right[n + 2][n + 2], top[n + 2][n + 2],         bot[n + 2][n + 2];     memset(left, 0, sizeof(left));     memset(right, 0, sizeof(right));     memset(bot, 0, sizeof(bot));     memset(top, 0, sizeof(top));     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) left[i][j] = left[i][j - 1] + a[i][j];       for (j = n; j >= 1; j--) right[i][j] = right[i][j + 1] + a[i][j];     }     for (j = 1; j <= n; j++) {       for (i = 1; i <= n; i++) top[i][j] = top[i - 1][j] + a[i][j];       for (i = n; i >= 1; i--) bot[i][j] = bot[i + 1][j] + a[i][j];     }     long long row[n + 2], col[n + 2];     memset(row, 0, sizeof(row));     memset(col, 0, sizeof(col));     for (i = 1; i <= n; i++) row[i] = row[i - 1] + (right[i][1] == 0);     for (j = 1; j <= n; j++) col[j] = col[j - 1] + (bot[1][j] == 0);     long long dpcol[n + 2][n + 2];     memset(dpcol, 0, sizeof(dpcol));     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) {         dpcol[i][j] = (top[i - 1][j] == 0);         if (i + k <= n) dpcol[i][j] = dpcol[i][j] && (bot[i + k][j] == 0);       }     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) dpcol[i][j] += dpcol[i][j - 1];     }     long long dprow[n + 2][n + 2];     memset(dprow, 0, sizeof(dprow));     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) {         dprow[i][j] = (left[i][j - 1] == 0);         if (j + k <= n) dprow[i][j] = dprow[i][j] && (right[i][j + k] == 0);       }     }     for (j = 1; j <= n; j++)       for (i = 1; i <= n; i++) dprow[i][j] += dprow[i - 1][j];     long long ans = 0;     for (i = 1; i <= n - k + 1; i++) {       for (j = 1; j <= n - k + 1; j++) {         long long temp = col[j - 1] + col[n] - col[j + k - 1] + row[i - 1] +                          row[n] - row[i + k - 1];         temp += (dpcol[i][j + k - 1] - dpcol[i][j - 1]);         temp += (dprow[i + k - 1][j] - dprow[i - 1][j]);         ans = max(ans, temp);       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   bool compare(T x, U y) {     return (abs(x - y) <= 1e-9);   }   const int MOD = 1e9 + 7;   void solve() {     long long a, b;     cin >> a >> b;     if (b == a) {       cout << 1;       return;     }     if ((b - a) >= 10)       cout << 0;     else {       long long c = a + 1;       long long prod = 1;       while (c <= b) {         prod = (prod * c) % 10;         c++;       }       cout << prod;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     while (t--) {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int solve(string &s) {     int len = s.length();     int ret = 0;     for (int i = 0; i < len; ++i) {       if (s[i] ==  V  && i + 1 < len && s[i + 1] ==  K ) {         ++ret;       }     }     return ret;   }   int main() {     string s;     while (cin >> s) {       int ans = solve(s);       int len = s.length();       char c;       for (int i = 0; i < len; ++i) {         c = s[i];         if (s[i] ==  V ) {           s[i] =  K ;         } else {           s[i] =  V ;         }         ans = max(ans, solve(s));         s[i] = c;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100000], k, i, n, j;   char c;   int main() {     string s;     cin >> k;     i = 0;     int p = 0;     getline(cin, s);     getline(cin, s);     for (j = 0; j < s.length(); j++) {       c = s[j];       p++;       if (c ==  ?  || c ==  .  || c ==  ! ) {         if (p > k) {           cout <<  Impossible  << endl;           return 0;         }         a[i] = p;         p = -1;         i++;       }     }     n = i;     int g = 0, res = 0;     for (i = 0; i < n; i++) {       if (i == 0) {         if (g + a[i] <= k) g += a[i];       } else if (g + a[i] + 1 <= k)         g += (a[i] + 1);       else {         res++;         g = a[i];       }     }     cout << res + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int inf = INT_MAX >> 1;   double PI = 3.1415926535897932384626433832795;   set<vector<char> > st;   int ans = 0;   void rotX(vector<char> &c);   void rotY(vector<char> &c);   void solve(string s) {     vector<char> c(6);     for (int i = 0; i < s.size(); i++) c[i] = s[i];     bool found = 0;     set<vector<char> > ss;     for (int i = 0; i < 4; i++) {       rotX(c);       for (int j = 0; j < 4; j++) {         rotY(c);         if (st.find(c) != st.end()) {           found = 1;           break;         }         ss.insert(c);       }     }     if (!found) {       for (auto it : ss) st.insert(it);       ans++;     }   }   int main() {     string s;     cin >> s;     sort(s.begin(), s.end());     do {       solve(s);     } while (next_permutation(s.begin(), s.end()));     printf( %d n , ans);     return 0;   }   void rotX(vector<char> &c) {     swap(c[0], c[1]);     swap(c[0], c[4]);     swap(c[0], c[3]);   }   void rotY(vector<char> &c) {     swap(c[0], c[5]);     swap(c[0], c[4]);     swap(c[0], c[2]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     long n;     cin >> t;     int a[t];     for (int i = 0; i < t; i++) {       cin >> a[i];     }     for (int i = 0; i < t; i++) {       if (a[i] <= 2) {         cout << 0 << endl;       } else {         n = (a[i] / 2.0);         if (a[i] % 2 == 0) {           cout << n - 1 << endl;         } else {           cout << n << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   char str[120][120];   int n;   int grid[26][26];   int ru[26], vis[26];   char ans[30];   int cheat;   void cmp(int a, int b) {     int lena = strlen(str[a]);     int lenb = strlen(str[b]);     int len = min(lena, lenb);     for (int i = 0; i < len; i++) {       if (str[a][i] != str[b][i]) {         int from = str[a][i] -  a ;         int to = str[b][i] -  a ;         grid[from][to] = 1;         return;       }     }     if (lena > lenb) cheat = 1;   }   void topoSort() {     int i, j, t = 0;     for (i = 0; i < 26; i++) {       for (j = 0; j < 26; j++) {         if (i != j && grid[i][j]) {           ru[j]++;         }       }     }     while (1) {       int found = 0;       for (i = 0; i < 26; i++) {         if (!vis[i] && ru[i] == 0) {           found = 1;           char ch = i +  a ;           ans[t++] = ch;           for (j = 0; j < 26; j++) {             if (grid[i][j]) {               ru[j]--;             }           }           vis[i] = 1;           break;         }       }       if (!found) break;     }     if (strlen(ans) != 26)       cout <<  Impossible  << endl;     else       printf( %s n , ans);   }   int main() {     memset(grid, 0, sizeof(grid));     memset(ru, 0, sizeof(ru));     memset(vis, 0, sizeof(vis));     cin >> n;     int i, j;     for (i = 0; i < n; i++) {       scanf( %s , str[i]);     }     for (i = 0; i < n; i++) {       for (j = i + 1; j < n; j++) {         cheat = 0;         cmp(i, j);         if (cheat) {           cout <<  Impossible  << endl;           return 0;         }       }     }     topoSort();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int tt;     cin >> tt;     while (tt--) {       long long n;       cin >> n;       string s = to_string(n);       int c = 0;       for (int i = 0; i < s.size(); i++) {         if (s[i] !=  0 ) c++;       }       cout << c;       cout <<   n ;       for (int i = 0; i < s.size(); ++i) {         if (!(s[i] ==  0 )) {           cout << s[i];           int temp = s.size() - i - 1;           while (temp--) cout << 0;           cout <<    ;         }       }     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = (int)5e5 + 100;   const int M = (int)2e6 + 100;   const int inf = (int)1e9 + 100;   string s, t;   long long mod = 998244353;   bool was[3001][3001];   long long table[3001][3001];   long long f(int x, int y) {     if (x < 0) return 1;     if (was[x][y]) return table[x][y];     was[x][y] = 1;     long long o = 0;     if (y == t.length()) {       o += 2 * f(x - 1, y) % mod;       o %= mod;       return table[x][y] = o;     }     if (s[x] == t[y]) {       o += f(x - 1, y + 1);       o %= mod;     }     if (x + 1 + y <= t.length()) {       if (s[x] == t[y + x]) {         o += f(x - 1, y);         o %= mod;       }     } else {       o += f(x - 1, y);       o %= mod;     }     return table[x][y] = o;   }   int main() {     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     srand(time(0));     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> s >> t;     long long ans = 0;     int i;     for ((i) = (t.length() - 1); (i) < (s.length()); (i)++) {       ans += f(i, 0);       ans %= mod;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353LL;   typedef struct EDGE {     int from, to, type, vis;     EDGE() { vis = 0; }     EDGE(int _f, int _t, int _ty) : from(_f), to(_t), type(_ty) { vis = 0; }   } Edge;   char s[2010];   vector<Edge> edges;   vector<int> G[2010];   int n, vis[2010], tot, nodes[2010];   inline void addEdge(int from, int to, int type) {     edges.push_back(Edge(from, to, type));     edges.push_back(Edge(to, from, type));     G[from].push_back(tot++);     G[to].push_back(tot++);   }   void build(int k) {     for (int i = 0; i <= n + k; i++) {       G[i].clear();       vis[i] = 0;       nodes[i] = -1;     }     edges.clear();     tot = 0;     nodes[0] = 0;     nodes[n + 1] = 1;     int u, v;     for (int i = 0; i < n; i++) {       if (s[i] ==  ? ) continue;       if (i < n - k)         addEdge(0, i + 1, s[i] -  0 );       else         addEdge(i + 1 + k, i + 1, s[i] -  0 );     }     u = 1;     v = n;     while (u < v) {       addEdge(u, v, 0);       u++;       v--;     }     u = n + 1;     v = n + k;     while (u < v) {       addEdge(u, v, 0);       u++;       v--;     }   }   long long dfs(int u) {     vis[u] = 1;     int Gs = G[u].size();     for (int i = 0; i < Gs; i++) {       Edge &e = edges[G[u][i]];       Edge &eo = edges[G[u][i] ^ 1];       if (e.vis) continue;       if (nodes[e.to] != -1 && nodes[e.to] ^ e.type != nodes[u]) return 0;       nodes[e.to] = nodes[u] ^ e.type;       e.vis = 1;       eo.vis = 1;       if (!dfs(e.to)) return 0;     }     return 1LL;   }   long long qpow(long long a, long long t) {     long long ret = 1LL;     while (t) {       ret = t & 1 ? ret * a % mod : ret;       a = a * a % mod;       t >>= 1;     }     return ret;   }   void disp(int N) {     for (int i = 0; i <= N; i++) {       cout << i <<  (  << vis[i] <<  )  ;     }     cout << endl;   }   int main() {     while (cin >> s) {       n = strlen(s);       long long ans = 0;       for (int k = 1; k < n; k++) {         build(k);         int cur = dfs(0) && dfs(n + 1) ? 0 : -1;         for (int i = 0; cur >= 0 && i <= n + k; i++) {           if (!vis[i]) {             nodes[i] = 0;             cur = dfs(i) ? cur + 1 : -1;           }         }         ans = cur >= 0 ? (ans + qpow(2LL, cur)) % mod : ans;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int seed = 131;   const long long LLMAX = 2e18;   const int MOD = 1e9 + 7;   const double eps = 1e-8;   const int MAXN = 1e6 + 10;   const int hmod1 = 0x48E2DCE7;   const int hmod2 = 0x60000005;   inline long long sqr(long long x) { return x * x; }   inline int sqr(int x) { return x * x; }   inline double sqr(double x) { return x * x; }   long long __gcd(long long a, long long b) {     return b == 0 ? a : __gcd(b, a % b);   }   long long qpow(long long a, long long n) {     long long sum = 1;     while (n) {       if (n & 1) sum = sum * a % MOD;       a = a * a % MOD;       n >>= 1;     }     return sum;   }   inline int dcmp(double x) {     if (fabs(x) < eps) return 0;     return (x > 0 ? 1 : -1);   }   long long p1[MAXN], p2[MAXN], hash1[MAXN], hash2[MAXN];   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s, t;     cin >> s >> t;     long long n = s.size(), m = t.size(), zero = 0, one = 0, ans = 0;     s =  #  + s, t =  #  + t;     for (long long i = 1; i <= n; i++) {       if (s[i] ==  0 )         zero++;       else         one++;     }     p1[0] = p2[0] = 1;     for (long long i = 1; i <= m; i++) {       p1[i] = p1[i - 1] * seed % hmod1;       p2[i] = p2[i - 1] * seed % hmod2;       hash1[i] = (hash1[i - 1] * seed + (t[i] -  a  + 1)) % hmod1;       hash2[i] = (hash2[i - 1] * seed + (t[i] -  a  + 1)) % hmod2;     }     for (long long len0 = 1; len0 < m; len0++)       if ((m - zero * len0) % one == 0) {         long long len1 = (m - zero * len0) / one, sum00 = -1, sum01 = -1,                   sum10 = -1, sum11 = -1, flag = 0;         if (len1 <= 0) continue;         for (long long i = 1, j = 0; i <= n && !flag; i++) {           if (s[i] ==  0 ) {             j += len0;             if (sum00 == -1) {               sum00 =                   (hash1[j] - hash1[j - len0] * p1[len0] % hmod1 + hmod1) % hmod1;               sum01 =                   (hash2[j] - hash2[j - len0] * p2[len0] % hmod2 + hmod2) % hmod2;             } else if (sum00 != (hash1[j] - hash1[j - len0] * p1[len0] % hmod1 +                                  hmod1) %                                     hmod1 ||                        sum01 != (hash2[j] - hash2[j - len0] * p2[len0] % hmod2 +                                  hmod2) %                                     hmod2)               flag = 1;           } else {             j += len1;             if (sum10 == -1) {               sum10 =                   (hash1[j] - hash1[j - len1] * p1[len1] % hmod1 + hmod1) % hmod1;               sum11 =                   (hash2[j] - hash2[j - len1] * p2[len1] % hmod2 + hmod2) % hmod2;             } else if (sum10 != (hash1[j] - hash1[j - len1] * p1[len1] % hmod1 +                                  hmod1) %                                     hmod1 ||                        sum11 != (hash2[j] - hash2[j - len1] * p2[len1] % hmod2 +                                  hmod2) %                                     hmod2)               flag = 1;           }         }         if ((sum00 != sum10 || sum01 != sum11) && !flag) ans++;       }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   template <class T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   pair<long long, long long> p[100011];   int n;   int a, b, c, d;   long long arr[100011];   long long dp[100011];   void solve() {     cin >> n;     scanf(  %d / %d %d / %d , &a, &b, &c, &d);     for (int i = 1; i <= n; i++) {       int u, v;       gn(u);       gn(v);       p[i] = pair<long long, long long>((long long)c * u - (long long)d * v,                                         (long long)b * v - (long long)a * u);     }     sort(p + 1, p + n + 1,          [&](pair<long long, long long> u, pair<long long, long long> v) {            if (u.first == v.first) return u.second > v.second;            return u.first < v.first;          });     int nn = 0;     for (int i = 1; i <= n; i++) {       arr[nn++] = p[i].second;       if (p[i].first < 0) arr[nn - 1] = 0;     }     int ans = 0;     for (int i = 0; i <= nn + 2; i++) dp[i] = 1e18;     for (int i = 0; i < nn; i++) {       if (arr[i] <= 0) continue;       int id = lower_bound(dp, dp + nn, arr[i]) - dp;       dp[id] = arr[i];       smax(ans, id + 1);     }     cout << ans << endl;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct option {     int s;     int t;     bool operator<(const option &next) const {       if (this->s == next.s)         return this->t < next.t;       else         return this->s < next.s;     }   };   vector<int> num1;   vector<int> num2;   vector<option> oLis;   int n, sum1, sum2;   int winner;   bool solve(int);   int main() {     scanf( %d , &n);     int a;     sum1 = 0;     sum2 = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &a);       if (a == 1)         sum1++;       else         sum2++;       if (i == n - 1) winner = a;       num1.push_back(sum1);       num2.push_back(sum2);     }     if (sum1 == sum2) {       printf( 0 n );       return 0;     }     int sum = sum1 > sum2 ? sum1 : sum2;     for (int i = 1; i <= sum; i++) solve(i);     sort(oLis.begin(), oLis.end());     printf( %d n , oLis.size());     for (int i = 0; i < (int)oLis.size(); i++)       printf( %d %d n , oLis[i].s, oLis[i].t);     return 0;   }   bool solve(int x) {     int tmp1, tmp2;     int pos1, pos2;     int score1, score2;     bool flag = true;     pos1 = 0;     pos2 = 0;     score1 = 0;     score2 = 0;     for (int i = 0; i < n; i++) {       tmp1 = lower_bound(num1.begin(), num1.end(), pos1 + x) - num1.begin();       tmp2 = lower_bound(num2.begin(), num2.end(), pos2 + x) - num2.begin();       if (tmp1 != n || tmp2 != n) {         if (tmp1 < tmp2) {           score1++;           pos1 = num1[tmp1];           pos2 = num2[tmp1];         } else {           score2++;           pos1 = num1[tmp2];           pos2 = num2[tmp2];         }       } else {         tmp1 = tmp2 = n - 1;         if (num1[tmp1] != pos1 || num2[tmp2] != pos2) flag = false;         break;       }     }     if (flag) {       if ((winner == 1 && score2 > score1) || (winner == 2 && score1 > score2) ||           (score1 == score2))         return false;       option tem;       tem.s = score1 > score2 ? score1 : score2;       tem.t = x;       oLis.push_back(tem);       return true;     }     return false;   }


#include <bits/stdc++.h>   using namespace std;   int a[26], b[26];   long long int q;   int comp(long long int k) {     long long int qs = q;     for (int i = 0; i < 26; i++) qs -= max(b[i] * k - a[i], 0LL);     return qs >= 0;   }   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     cout.precision(10);     string s, t;     cin >> s;     cin >> t;     for (char c : s)       if (c ==  ? )         q++;       else         a[c -  a ]++;     for (char c : t) b[c -  a ]++;     int l = 0, r = 10E5 + 1;     while (r - l > 1) {       int p = (l + r) / 2;       if (comp(p))         l = p;       else         r = p;     }     for (int i = 0; i < 26; i++) b[i] *= l;     int j = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  ? ) {         while (b[j] - a[j] <= 0 && j < 26) j++;         if (j < 26) {           s[i] = j +  a ;           b[j]--;         } else           s[i] =  a ;       }     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3005;   queue<int> q;   vector<int> G[MAXN];   int d[MAXN][MAXN];   bool vis[MAXN];   void bfs(int s) {     memset(vis, 0, sizeof(vis));     vis[s] = true;     d[s][s] = 0;     q.push(s);     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i < G[u].size(); i++) {         int v = G[u][i];         if (!vis[v]) {           vis[v] = true;           d[s][v] = d[s][u] + 1;           q.push(v);         }       }     }   }   int main() {     int n, m, s1, t1, l1, s2, t2, l2;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int a, b;       scanf( %d%d , &a, &b);       G[a].push_back(b);       G[b].push_back(a);     }     scanf( %d%d%d%d%d%d , &s1, &t1, &l1, &s2, &t2, &l2);     for (int i = 1; i <= n; i++) bfs(i);     if (d[s1][t1] > l1 || d[s2][t2] > l2) {       printf( -1 );       return 0;     }     int ans = max(0, m - d[s1][t1] - d[s2][t2]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         int d1 = d[s1][i] + d[i][j] + d[j][t1],             d2 = min(d[s2][i] + d[j][t2], d[s2][j] + d[i][t2]) + d[i][j];         if (d1 <= l1 && d2 <= l2) ans = max(ans, m - d1 - d2 + d[i][j]);       }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   priority_queue<pair<int, char> > pr;   bool is_prime(int n) {     if (n == 1) return 0;     for (int i = 2; i * i <= n; i++)       if (n % i == 0) return 0;     return 1;   }   vector<int> prime, pos[1004];   map<int, int> mark, mark2;   map<int, int>::iterator it;   bool vis[10000];   void solve(int n, int prm, int idx) {     vis[prm] = 1;     int rng = n / prm;     for (int j = 1; j <= rng; j++) {       int x = prm * j;       if (!mark2[x]) pos[idx].push_back(x);       mark2[x] = 1;       for (int k = 2; k * k <= x; k++) {         if (x % k == 0) {           while (x % k == 0) x /= k;           if (!vis[k] && k <= n) solve(n, k, idx);         }       }       if (x > 1 && !vis[x]) solve(n, x, idx);     }   }   int main() {     int n;     string tmp, str;     str +=  1 ;     cin >> tmp;     str += tmp;     n = tmp.size();     char ans[10000];     for (int i = 0; i <= n; i++) ans[i] =  1 ;     for (int i = 2; i <= n / 2; i++)       if (is_prime(i)) prime.push_back(i);     bool flg = 1;     int sz = 0;     for (int i = 0; i < prime.size(); i++)       if (!vis[prime[i]]) solve(n, prime[i], sz++);     for (int i = 1; i <= n; i++) mark[str[i]]++;     for (it = mark.begin(); it != mark.end(); it++)       pr.push(make_pair(it->second, it->first));     for (int i = 0; i < sz; i++) {       if (pos[i].size() <= pr.top().first) {         for (int j = 0; j < pos[i].size(); j++) ans[pos[i][j]] = pr.top().second;         int x = pr.top().first - pos[i].size();         char ch = pr.top().second;         pr.pop();         pr.push(make_pair(x, ch));       } else {         flg = 0;         break;       }     }     if (flg) {       printf( YES n );       for (int i = 1; i <= n; i++) {         if (ans[i] ==  1 ) {           while (!pr.top().first) pr.pop();           ans[i] = pr.top().second;           int x = pr.top().first - 1;           char ch = pr.top().second;           pr.pop();           pr.push(make_pair(x, ch));         }       }       for (int i = 1; i <= n; i++) printf( %c , ans[i]);       printf(  n );     } else       printf( NO n );   }


#include <bits/stdc++.h>   using namespace std;   int n, t, k, cnt = 0;   int a[200005], st[200005];   struct hehe {     int x, y;   } e[200005];   void add(int x, int y) {     cnt++;     e[cnt].x = x;     e[cnt].y = y;   }   void solve() {     int i, j;     int minn = 1, maxx = 1;     a[0] = 1;     st[0] = 1;     for (i = 1; i <= t; i++) {       maxx = maxx + a[i] - 1;       st[i] = st[i - 1] + a[i - 1];       if (a[i] >= a[i - 1]) minn += a[i] - a[i - 1];     }     if (minn > k || maxx < k) {       printf( -1 n );       return;     }     printf( %d n , n);     for (i = st[1]; i <= st[1] + a[1] - 1; i++) add(1, i);     for (i = 1; i <= t - 1; i++) {       if (minn < k) {         for (j = 1; j <= a[i + 1] - a[i] && j <= a[i + 1]; j++)           add(st[i], st[i + 1] + j - 1);         int zuida;         if (a[i + 1] >= a[i])           zuida = a[i] - 1;         else           zuida = a[i + 1] - 1;         if (minn + zuida < k) {           int delta = max(0, a[i + 1] - a[i]);           minn += zuida;           for (j = st[i + 1] + delta; j <= st[i + 1] + a[i + 1] - 1; j++)             add(st[i], j);         } else {           int delta = max(0, a[i + 1] - a[i]);           int xiaid;           int zhiqian;           if (a[i + 1] >= a[i])             zhiqian = 0;           else             zhiqian = a[i] - a[i + 1];           for (j = 1; j <= a[i] - (zhiqian + (k - minn)); j++) {             xiaid = st[i + 1] + delta + j - 1;             add(st[i] + j - 1, xiaid);           }           for (j = xiaid + 1; j <= st[i + 1] + a[i + 1] - 1; j++) add(st[i], j);           minn = k;         }       } else {         for (j = 1; j <= a[i + 1] - a[i]; j++) add(st[i], st[i + 1] + j - 1);         int id = st[i];         int delta = max(0, a[i + 1] - a[i]);         for (j = st[i + 1] + delta; j <= st[i + 1] + a[i + 1] - 1; j++) {           add(id, j);           id++;         }       }     }     for (i = 1; i <= cnt; i++) cout << e[i].x <<     << e[i].y << endl;   }   int main() {     while (scanf( %d%d%d , &n, &t, &k) != EOF) {       int i;       cnt = 0;       for (i = 1; i <= t; i++) scanf( %d , &a[i]);       solve();     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   long long qp(long long a, long long b, long long mod) {     long long t = 1;     while (b) {       if (b & 1) t = t * a % mod;       b >>= 1;       a = a * a % mod;     }     return t;   }   struct DOT {     int x;     int y;   };   inline void read(int &x) {     int k = 0;     char f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) k = k * 10 + c -  0 ;     x = k * f;   }   void ex() {     puts( -1 );     exit(0);   }   const int dx[4] = {-1, 0, 1, 0};   const int dy[4] = {0, 1, 0, -1};   const int inf = 0x3f3f3f3f;   const long long Linf = 0x3f3f3f3f3f3f3f3fll;   const long long mod = 1e9 + 7;   const double pi = acos(-1.0);   const double eps = 1e-7;   const int maxn = 5e5 + 344;   int n, k;   map<int, int> mp;   int a[maxn], b[maxn];   int main() {     scanf( %d%d , &n, &k);     int rembk = k;     long long sum = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       sum += a[i];       mp[a[i]]++;     }     int tot = 0;     sort(a + 1, a + 1 + n);     for (int i = 1; i <= n; i++) {       if (a[i] != a[i - 1]) {         b[++tot] = a[i];       }     }     int mov = 0;     int mnto = b[1];     for (int i = 1; i <= tot; i++) {       if (1ll * mov * (b[i] - b[i - 1]) <= 1ll * k) {         k -= mov * (b[i] - b[i - 1]);         mnto = b[i];         mov += mp[b[i]];       } else         break;     }     mnto += k / mov;     k = rembk;     mov = 0;     int mxto = b[tot];     b[tot + 1] = b[tot];     for (int i = tot; i >= 1; i--) {       if (1ll * mov * (b[i + 1] - b[i]) <= 1ll * k) {         k -= mov * (b[i + 1] - b[i]);         mxto = b[i];         mov += mp[b[i]];       } else         break;     }     mxto -= k / mov;     if (mxto <= mnto) {       if (sum % n == 0) {         puts( 0 );       } else         puts( 1 );     } else {       printf( %d n , mxto - mnto);     }   }


#include <bits/stdc++.h>   const int MAX = 1e3 + 5;   using namespace std;   int edge, mx, ans, seen[MAX], a, n, m, k, spec[MAX], check[MAX][MAX];   vector<int> adj[MAX];   vector<int> cur;   void dfs(int node) {     if (seen[node] == 1) return;     seen[node] = 1;     cur.push_back(node);     for (int i = int(0); i <= int(adj[node].size() - 1); i++) dfs(adj[node][i]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m >> k;     for (int i = int(1); i <= int(k); i++) cin >> a, spec[a] = 1;     for (int i = int(1); i <= int(m); i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);       check[u][v] = check[v][u] = 1;     }     for (int i = int(1); i <= int(n); i++)       if (spec[i] == 1) {         dfs(i);         mx = max(int(cur.size()), mx);         int comb = (cur.size() == 1 ? 0 : (cur.size() * (cur.size() - 1) / 2));         for (int i = int(0); i <= int(cur.size() - 1); i++) {           for (int j = int(i + 1); j <= int(cur.size() - 1); j++)             edge += check[cur[i]][cur[j]];         }         ans += comb - edge;         cur.clear();         edge = 0;       }     for (int i = int(1); i <= int(n); i++) {       if (seen[i] == 1) continue;       dfs(i);       int comb = (cur.size() == 1 ? 0 : (cur.size() * (cur.size() - 1) / 2));       for (int i = int(0); i <= int(cur.size() - 1); i++) {         for (int j = int(i + 1); j <= int(cur.size() - 1); j++)           edge += check[cur[i]][cur[j]];       }       ans += comb - edge;       ans += mx * int(cur.size());       mx += cur.size();       cur.clear();       edge = 0;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int po(int a) {     if (a == 0) return 1;     long long int x = po(a / 2);     x = x * x;     x %= 1000000007;     if (a % 2 == 0) {       return x;     } else {       x = x * 2;       x %= 1000000007;       return x;     }   }   int main() {     int x, y;     cin >> x >> y;     if (y % x != 0) {       cout << 0 << endl;     } else {       y = y / x;       vector<int> val;       for (int i = 1; i * i <= y; i++) {         if (y % i == 0) {           val.push_back(i);           if (i * i != y) {             val.push_back(y / i);           }         }       }       sort(val.begin(), val.end());       vector<int> ans(val.size(), 0);       ans[0] = 1;       for (int i = 1; i < val.size(); i++) {         ans[i] = po(val[i] - 1);         for (int j = 0; j < i; j++) {           if (val[i] % val[j] != 0) continue;           ans[i] -= ans[j];           ans[i] = ans[i] % 1000000007;         }       }       if (ans[val.size() - 1] < 0) {         ans[val.size() - 1] += 1000000007;       }       cout << ans[val.size() - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e6 + 5;   const double delta = 1e-6;   const long long mod = 1e9 + 7;   struct ev {     double coord;     int type;     int mincost;   };   const bool operator<(const ev& f, const ev& s) { return f.coord < s.coord; }   void init() {}   class fenwick {     vector<int> sums;       public:     fenwick(int n) { sums.resize(n + 3); }     void add(int pos, int delta) {       for (pos++; pos < sums.size(); pos += pos & (-pos)) sums[pos] += delta;     }     int size() { return sums.size() - 2; }     int pref_sum(int pos) {       if (pos < -1) return 0;       int answer = 0;       for (pos++; pos > 0; pos -= pos & (-pos)) answer += sums[pos];       return answer;     }     int get_sum(int left, int right) {       return pref_sum(right) - pref_sum(left - 1);     }   };   const bool cmppp(const pair<int, int>& f, const pair<int, int>& s) {     return (f.second == s.second) ? (f.first < s.first) : (f.second > s.second);   }   vector<int> unique_xs;   void compress() {     sort(unique_xs.begin(), unique_xs.end());     unique_xs = vector<int>(unique_xs.begin(),                             unique(unique_xs.begin(), unique_xs.end()));   }   int get_num(int dt) {     return lower_bound(unique_xs.begin(), unique_xs.end(), dt) -            unique_xs.begin();   }   class dsu {    public:     vector<int> a;     vector<int> sizes;     dsu(int n, vector<int>& sizes) : sizes(sizes) {       a.resize(n);       for (int i = 0; i < n; i++) {         a[i] = i;       }     }     int get_parent(int x) { return (a[x] == x) ? x : (a[x] = get_parent(a[x])); }     void unite(int l, int r) {       int par_1 = get_parent(l);       int par_2 = get_parent(r);       if (par_1 == par_2) return;       if (sizes[par_1] < sizes[par_2]) swap(par_1, par_2);       sizes[par_1] += sizes[par_2];       sizes[par_2] = 0;       a[par_2] = par_1;     }   };   bool is_prime(int number) {     for (int i = 2; i * i <= number; i++) {       if (number % i == 0) {         return false;       }     }     return true;   }   string s;   string left_answer =   ;   string right_answer =   ;   void squeeze(int& l, int& r) {     if (l == r) {       left_answer += s[l];       l++;       return;     }     if (s[l] == s[r]) {       left_answer += s[l];       right_answer += s[r];       l++;       r--;       return;     }     if (l + 1 >= r && s[l] != s[r]) {       left_answer += s[l];       l++;       r--;       return;     }     if (s[l + 1] == s[r]) {       left_answer += s[l + 1];       right_answer += s[r];       l += 2;       r--;       return;     }     if (s[l] == s[r - 1]) {       left_answer += s[l];       right_answer += s[r - 1];       l++;       r -= 2;       return;     }     l++;     r--;   }   void solve() {     cin >> s;     int left = 0;     int right = s.size() - 1;     while (left <= right) {       squeeze(left, right);     }     reverse(right_answer.begin(), right_answer.end());     cout << left_answer << right_answer <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     srand(58164);     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   int n, k;   long long quick(long long A, long long B) {     if (B == 0) return 1;     long long tmp = quick(A, B >> 1);     tmp *= tmp;     tmp %= MOD;     if (B & 1) tmp *= A, tmp %= MOD;     return tmp;   }   int fact[100000 + 20], invfact[100000 + 20];   int suf[100000 + 20];   int tot;   int rest = 0;   long long c(int A, int B) {     if (B == 0) return 1;     if (B < 0) return 0;     if (A < B) return 0;     return 1ll * fact[A] * invfact[A - B] % MOD * invfact[B] % MOD;   }   int main() {     scanf( %d%d , &n, &k);     string s;     cin >> s;     for (int i = n - 1; i >= 1; --i) suf[i] = suf[i + 1] + (s[i - 1] -  0 );     fact[0] = 1;     for (int i = 1; i <= n; ++i) {       fact[i] = 1ll * fact[i - 1] * i % MOD;     }     invfact[n] = quick(fact[n], MOD - 2);     for (int i = n - 1; i >= 0; --i)       invfact[i] = 1ll * invfact[i + 1] * (i + 1) % MOD;     tot = 0;     int bad = 0, ten = 1;     for (int i = 1; i <= n - 2; ++i) {       tot -= bad;       tot += MOD;       tot %= MOD;       tot = 10ll * tot % MOD;       bad += 1ll * ten * (s[n - 1 - i] -  0 ) % MOD;       bad %= MOD;       ten = 10ll * ten % MOD;       (tot += suf[i + 1]) %= MOD;       (rest += 1ll * tot * c(n - 2 - i, k - 2) % MOD) %= MOD;     }     int tmp = 0;     for (int i = 1; i <= n - 1; ++i) {       tmp = 10ll * tmp % MOD;       (tmp += (s[i - 1] -  0 )) %= MOD;       (rest += 1ll * tmp * c(n - 1 - i, k - 1) % MOD) %= MOD;     }     int z = 1;     tmp = 0;     for (int i = 1; i <= n; ++i) {       (tmp += 1ll * (s[n - i] -  0 ) * z % MOD) %= MOD;       z = 10ll * z % MOD;       (rest += 1ll * tmp * c(n - 1 - i, k - (i != n)) % MOD) %= MOD;     }     cout << rest << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     char **a = new char *[n];     for (int i = 0; i < n; i++) {       a[i] = new char[m + 1];       cin >> a[i];     }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         for (int k = 0; k < n; k++)           for (int l = 0; l < m; l++) {             if (i == k && j == l) {               continue;             }             if (a[i][j] ==  W  || a[k][l] ==  W ) {               continue;             }             bool found1 = true;             for (int i1 = j; i1 <= l; i1++) {               if (a[i][i1] ==  W ) {                 found1 = false;                 break;               }             }             for (int i1 = i; i1 <= k; i1++) {               if (a[i1][l] ==  W ) {                 found1 = false;                 break;               }             }             if (found1) {               continue;             }             found1 = true;             for (int i1 = i; i1 <= k; i1++) {               if (a[i1][j] ==  W ) {                 found1 = false;                 break;               }             }             for (int i1 = j; i1 <= l; i1++) {               if (a[k][i1] ==  W ) {                 found1 = false;                 break;               }             }             if (found1) {               continue;             } else {               cout <<  NO ;               return 0;             }           }     cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 gen(chrono::system_clock::now().time_since_epoch().count());   const int N = 1e6 + 10;   const long long MOD = 1e9 + 7;   const long long p1 = 57, M1 = 1e9 + 3;   const int rx[4] = {-1, 0, 1, 0};   const int ry[4] = {0, 1, 0, -1};   const int hx[8] = {-2, -2, -1, 1, 2, 2, 1, -1};   const int hy[8] = {-1, 1, 2, 2, 1, -1, -2, -2};   const long double eps = 1e-7;   const double pi = acos(-1.0);   const long long INF = 1e14 + 1000;   struct segtree {     vector<pair<int, int> > t;     vector<int> lazy;     int nw;     segtree(int n) {       nw = (1 << (32 - __builtin_clz(n) - (__builtin_popcount(n) == 1)));       t.resize(nw << 1, {0, 1});       lazy.resize(nw << 1);       for (int i = nw - 1; i > 0; i--) {         t[i].second = t[i * 2].second + t[i * 2 + 1].second;       }     }     void push(int v) {       t[v * 2].first += lazy[v];       t[v * 2 + 1].first += lazy[v];       lazy[v * 2] += lazy[v];       lazy[v * 2 + 1] += lazy[v];       lazy[v] = 0;     }     void upd(int v, int cl, int cr, int l, int r, int x) {       if (cl >= l && cr <= r) {         t[v].first += x;         lazy[v] += x;         return;       }       if (cl >= r || cr <= l) return;       push(v);       int mid = (cl + cr) / 2;       upd(v * 2, cl, mid, l, r, x);       upd(v * 2 + 1, mid, cr, l, r, x);       if (t[v * 2].first < t[v * 2 + 1].first) {         t[v] = t[v * 2];       } else if (t[v * 2 + 1].first < t[v * 2].first) {         t[v] = t[v * 2 + 1];       } else {         t[v] = t[v * 2];         t[v].second += t[v * 2 + 1].second;       }     }     void upd(int l, int r, int x) { upd(1, 1, nw + 1, l, r + 1, x); }     int kol(int v, int cl, int cr, int l, int r) {       if (cl >= l && cr <= r) {         if (t[v].first == 0)           return t[v].second;         else           return 0;       }       if (cl >= r || cr <= l) return 0;       push(v);       int mid = (cl + cr) / 2;       return kol(v * 2, cl, mid, l, r) + kol(v * 2 + 1, mid, cr, l, r);     }     int kol(int l, int r) { return kol(1, 1, nw + 1, l, r + 1); }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i]--;     }     vector<int> pos[n];     long long res = 0;     segtree sgt(n);     for (int i = 0; i < n; i++) {       pos[a[i]].push_back(i);       int sz = pos[a[i]].size();       if (sz == 1) {         sgt.upd(1, i + 1, 1);       } else if (sz == 2) {         sgt.upd(1, pos[a[i]][0] + 1, -1);         sgt.upd(1, i + 1, 1);       } else if (sz == 3) {         sgt.upd(1, pos[a[i]][1] + 1, -1);         sgt.upd(pos[a[i]][0] + 2, i + 1, 1);       } else if (sz == 4) {         sgt.upd(pos[a[i]][0] + 2, pos[a[i]][2] + 1, -1);         sgt.upd(1, pos[a[i]][0] + 1, 1);         sgt.upd(pos[a[i]][1] + 2, i + 1, 1);       } else {         sgt.upd(1, pos[a[i]][sz - 5] + 1, -1);         sgt.upd(pos[a[i]][sz - 4] + 2, pos[a[i]][sz - 2] + 1, -1);         sgt.upd(1, pos[a[i]][sz - 4] + 1, 1);         sgt.upd(pos[a[i]][sz - 3] + 2, i + 1, 1);       }       res += sgt.kol(1, i + 1);     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, k;     cin >> n >> k;     string s;     cin >> s;     string ans =   ;     long long int reqd = k / 2, op = 0, cl = 0;     for (auto x : s) {       if (op < reqd) {         if (x ==  ( ) {           ans.push_back(x);           op++;         }       }       if (cl < reqd) {         if (x ==  ) ) {           ans.push_back(x);           cl++;         }       }       if (op == reqd and cl == reqd) {         break;       }     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     int64_t n, m, d;     cin >> n >> m >> d;     vector<pair<int64_t, int64_t> > a1(n), a2(m);     for (auto &e : a1) {       cin >> e.first >> e.second;       e.second = -e.second;     }     for (auto &e : a2) {       cin >> e.first >> e.second;       e.second = -e.second;     }     sort(a1.begin(), a1.end());     sort(a2.begin(), a2.end());     reverse(a1.begin(), a1.end());     reverse(a2.begin(), a2.end());     vector<int64_t> p2c(m), p2w(m);     int64_t ans = 0;     for (int64_t i = 0; i < m; i++) {       p2c[i] = a2[i].first;       p2w[i] = -a2[i].second;       if (i > 0) {         p2c[i] += p2c[i - 1];         p2w[i] += p2w[i - 1];       }     }     int64_t Len = 0, C = 0;     for (int64_t i = 0; i < n; i++) {       C += a1[i].first;       d += a1[i].second;       int64_t idx = upper_bound(p2w.begin(), p2w.end(), d) - p2w.begin();       if (idx == 0) break;       ans = max(ans, C + p2c[idx - 1]);     }     cout << ans;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chkmin(T &x, T y) {     return y < x ? x = y, 1 : 0;   }   template <typename T>   inline bool chkmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   const int INF = 0x3f3f3f3f;   const int N = 2e3 + 10, mod = 1e9 + 7;   int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   int vis[N][N];   char Map[N][N];   struct node {     int x, y;   } dis[N][N];   deque<node> Q;   inline int read() {     int x = 0, flag = 1;     char ch = getchar();     while (!isdigit(ch) && ch !=  - ) ch = getchar();     if (ch ==  - ) flag = -1, ch = getchar();     while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch -  0 ), ch = getchar();     return x * flag;   }   int main() {     int n = read(), m = read(), X = read(), Y = read(), L = read(), R = read();     for (int i = (1), iend = (n); i <= iend; i++) scanf( %s , Map[i] + 1);     int cnt = 1;     Q.push_back((node){X, Y}), vis[X][Y] = true;     while (!Q.empty()) {       node cur = Q.front();       Q.pop_front();       int x = cur.x, y = cur.y;       for (int i = (0), iend = (3); i <= iend; i++) {         int Nx = x + dir[i][0], Ny = y + dir[i][1], curdL = dis[x][y].x,             curdR = dis[x][y].y;         if (Nx <= 0 || Ny <= 0 || Nx > n || Ny > m || vis[Nx][Ny] ||             Map[Nx][Ny] ==  * )           continue;         if (i == 2) curdR++;         if (i == 3) curdL++;         if (curdL > L || curdR > R) continue;         if (i == 2 || i == 3)           Q.push_back((node){Nx, Ny});         else           Q.push_front((node){Nx, Ny});         dis[Nx][Ny] = (node){curdL, curdR};         vis[Nx][Ny] = true, cnt++;       }     }     printf( %d n , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   long long int tmp = 85;   long long int a[MAXN], b[MAXN], ind[MAXN];   vector<long long int> o;   long long int n, d, x;   long long int getNextX() {     x = (x * 37 + 10007) % 1000000007;     return x;   }   int main() {     cin >> n >> d >> x;     for (long long int i = 0; i < n; i = i + 1) {       a[i] = i + 1;     }     for (long long int i = 0; i < n; i = i + 1) {       swap(a[i], a[getNextX() % (i + 1)]);     }     for (long long int i = 0; i < n; i = i + 1) {       if (i < d)         b[i] = 1;       else         b[i] = 0;     }     for (int i = 0; i < n; i = i + 1) {       swap(b[i], b[getNextX() % (i + 1)]);     }     for (int i = 0; i < n; i++) {       ind[a[i]] = i;     }     for (int i = 0; i < n; i++) {       if (b[i] == 1) {         o.push_back(i);       }     }     for (int i = 0; i < n; i++) {       long long int cur = n;       bool check = false;       while (cur >= 0 and cur >= n - tmp) {         if (ind[cur] <= i and b[i - ind[cur]] == 1) {           cout << cur << endl;           check = true;           break;         }         cur--;       }       if (check == true) {         continue;       }       long long int cur_ans = 0;       for (int j = 0; j < o.size(); j++) {         if (o[j] <= i) {           cur_ans = max(cur_ans, a[i - o[j]]);         }       }       cout << cur_ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int a = 1;     for (int i = 1; i < s.size(); i++) {       if (s[i] ==  1 ) {         a += 10;       } else {         a += s[i] -  0 ;       }     }     cout << a <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     string s;     cin >> s;     long long i;     bool flag = true;     for (i = 0; i < s.length(); i++) {       if (s[i] ==  0 ) {         s.erase(i, 1);         flag = false;         break;       }     }     if (flag) {       s.erase(s.begin());     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   int add(int x, int y) {     x += y;     while (x >= MOD) x -= MOD;     while (x < 0) x += MOD;     return x;   }   int mul(int x, int y) { return (x * 1ll * y) % MOD; }   int power(int n, int m, int p) {     int res = 1;     while (m > 0) {       if (m & 1) res = (res * 1ll * n) % p;       n = (n * 1ll * n) % p;       m /= 2;     }     return res;   }   int solve() {     int n;     cin >> n;     int d = power(100, MOD - 2, MOD);     vector<int> arr(n), p(n), q(n);     for (int i = 0; i < n; i++) {       cin >> arr[i];       p[i] = mul(arr[i], d);       q[i] = mul(100 - arr[i], d);     }     int cur = 1, res = 0, x = 0;     for (int i = 0; i < n; i++) {       int tmp = mul(cur, p[i]), tmq = mul(cur, q[i]);       res = add(res, add(tmp, tmq));       x = add(x, tmq);       cur = tmp;     }     res = mul(res, power(add(1, -x), MOD - 2, MOD));     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << solve() <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void itval(istream_iterator<string> it) {}   template <typename T, typename... Args>   void itval(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a << endl;     itval(++it, args...);   }   const long long int MOD = 1e9 + 7;   template <typename T>   inline void print(T x) {     cout << x <<   n ;   }   template <typename T>   inline void printvec(T x) {     for (auto a : x) cout << a <<    ;     cout <<   n ;   }   struct custom {     bool operator()(const pair<long long int, long long int> &p1,                     const pair<long long int, long long int> &p2) const {       return p1.first < p2.first;     }   };   long long int get_pow(long long int a, long long int b, long long int M = MOD) {     long long int res = 1;     while (b) {       if (b & 1) res = (res * a) % M;       a = (a * a) % M;       b >>= 1;     }     return res;   }   const long long int N = 2e5 + 5, inf = 4e18, M = 302;   void solve() {     long long int c, p, q, a, b;     cin >> c >> p >> q >> a >> b;     long long int x = c / a;     long long int ans = 0;     for (long long int i = (long long int)max(0ll, x - 10000);          i < (long long int)(x + 10000); i++) {       if (i * a <= c) {         ans = max(ans, i * p + ((c - i * a) / b) * q);       } else         break;     }     long long int y = c / b;     for (long long int i = (long long int)max(0ll, y - 10000);          i < (long long int)(y + 10000); i++) {       if (i * b <= c) {         ans = max(ans, i * q + ((c - i * b) / a) * p);       } else         break;     }     if (p * b == q * a) {       long long int x = c / a / 2;       for (long long int i = (long long int)max(0ll, x - 10000);            i < (long long int)(x + 10000); i++) {         if (i * a <= c) {           ans = max(ans, i * p + ((c - i * a) / b) * q);         } else           break;       }       long long int y = c / b / 2;       for (long long int i = (long long int)max(0ll, y - 10000);            i < (long long int)(y + 10000); i++) {         if (i * b <= c) {           ans = max(ans, i * q + ((c - i * b) / a) * p);         } else           break;       }     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int test = 1;     clock_t z = clock();     for (long long int tes = (long long int)0; tes < (long long int)(test);          tes++) {       solve();     }     fprintf(stderr,  Total Time:%.4f n , (double)(clock() - z) / CLOCKS_PER_SEC),         fflush(stderr);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INFL = 1LL << 60;   const long long INF = 1 << 30;   long long MOD = 1000000007;   vector<long long> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};   vector<long long> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};   void pres(double A, long long x = 10) {     cout << fixed << setprecision(x) << A << endl;   }   void BinarySay(long long x, long long y = 60) {     for (long long i = 0; i < (y); i++) cout << (x >> (y - 1 - i) & 1);     cout << endl;   }   long long cnt_bit(long long x) { return __builtin_popcountll(x); }   long long pow_long(long long x, long long k) {     long long res = 1;     while (k > 0) {       if (k % 2) res *= x;       x *= x;       k /= 2;     }     return res;   }   long long pow_mod(long long x, long long k) {     long long res = 1;     while (k > 0) {       if (k % 2) {         res *= x;         res %= MOD;       }       x *= x;       x %= MOD;       k /= 2;     }     return res;   }   long long inverse(long long x) { return pow_mod(x, MOD - 2); };   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long x, long long y) { return x / gcd(x, y) * y; };   vector<long long> Row[100010];   vector<long long> Col[100010];   void solve() {     long long N, M, K;     cin >> N >> M >> K;     for (long long i = 0; i < (K); i++) {       long long a, b;       cin >> a >> b;       Row[a].push_back(b);       Col[b].push_back(a);     }     for (long long i = 0; i <= M + 1; i++) {       Row[0].push_back(i);       Col[i].push_back(0);       Row[N + 1].push_back(i);       Col[i].push_back(N + 1);     }     for (long long i = 0; i <= N + 1; i++) {       Col[0].push_back(i);       Row[i].push_back(0);       Col[M + 1].push_back(i);       Row[i].push_back(M + 1);     }     for (long long i = 0; i < (N + 1); i++) {       sort(Row[i].begin(), Row[i].end());       Row[i].erase(unique(Row[i].begin(), Row[i].end()), Row[i].end());     }     for (long long i = 0; i < (M + 1); i++) {       sort(Col[i].begin(), Col[i].end());       Col[i].erase(unique(Col[i].begin(), Col[i].end()), Col[i].end());     }     long long Cnt = 0;     for (long long i = 1; i <= N; i++) {       long long x = *lower_bound(Row[i].begin(), Row[i].end(), 1);       if (x == 1) break;       Cnt++;     }     if (Cnt == N * M - K) {       cout <<  Yes  << endl;       return;     }     long long y = 1, x = 1;     long long dir = 1;     long long cnt = 1;     long long L = 0, R = M + 1, U = 1, D = N + 1;     while (true) {       long long dif = -cnt;       if (dir == 1) {         long long nx = *lower_bound(Row[y].begin(), Row[y].end(), x);         nx = min(nx - 1, R - 1);         cnt += nx - x;         x = nx;         R = x;       }       if (dir == 2) {         long long ny = *lower_bound(Col[x].begin(), Col[x].end(), y);         ny = min(ny - 1, D - 1);         cnt += ny - y;         y = ny;         D = y;       }       if (dir == 3) {         auto itr = lower_bound(Row[y].begin(), Row[y].end(), x);         itr--;         long long nx = *itr;         nx = max(nx + 1, L + 1);         cnt += x - nx;         x = nx;         L = x;       }       if (dir == 4) {         auto itr = lower_bound(Col[x].begin(), Col[x].end(), y);         itr--;         long long ny = *itr;         ny = max(ny + 1, U + 1);         cnt += y - ny;         y = ny;         U = y;       }       dif += cnt;       if (dif == 0) break;       dir++;       if (dir == 5) dir = 1;     }     if (cnt == N * M - K) {       cout <<  Yes  << endl;     } else {       cout <<  No  << endl;     }   }   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int n, x, m, tmp, ans, sum, t;   int a[N], b[N], h[N];   string s, p;   map<string, int> pol;   vector<int> nei[N];   bool mark[N];   void read_input() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] > 1 && tmp == 0) tmp = i;       sum += a[i];     }     if (sum == n) {       cout << (n % 2 ?  First n  :  Second n );       return;     }     cout << (tmp % 2 ?  First n  :  Second n );   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       sum = 0;       tmp = 0;       read_input();     }     return 0;   }


#include <bits/stdc++.h>   using pi = std::pair<int, int>;   using vec = std::vector<pi>;   const int N = 300007, P = 1019260817;   char str[N];   int n, fa[N], size[N], dep[N], son[N], top[N], dfn[N], id[N], pw[N], ipw[N],       h[N][2];   std::vector<int> e[N];   int sgn(int x) { return x < 0 ? -1 : 1; }   int sub(int a, int b) { return a -= b, a += a >> 31 & P; }   int mul(int a, int b) { return 1ll * a * b % P; }   int read() {     int x = 0, c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) (x *= 10) += c & 15, c = getchar();     return x;   }   void dfs1(int u, int f) {     size[u] = 1, dep[u] = dep[fa[u] = f] + 1,     h[u][0] = (str[u] + 233ll * h[f][0]) % P,     h[u][1] = (h[f][1] + 1ll * str[u] * pw[dep[u] - 1]) % P;     for (int v : e[u])       if (v ^ f)         dfs1(v, u), size[u] += size[v],             son[u] = size[v] > size[son[u]] ? v : son[u];   }   void dfs2(int u, int t) {     static int T;     top[u] = t, id[dfn[u] = ++T] = u;     if (son[u]) dfs2(son[u], t);     for (int v : e[u])       if (v ^ fa[u] && v ^ son[u]) dfs2(v, v);   }   vec split(int u, int v) {     vec l, r;     while (top[u] ^ top[v])       dep[top[u]] > dep[top[v]] ? (l.push_back({u, top[u]}), u = fa[top[u]])                                 : (r.push_back({top[v], v}), v = fa[top[v]]);     l.push_back({u, v}), std::reverse(r.begin(), r.end()),         l.insert(l.end(), r.begin(), r.end());     return l;   }   int ask(int x, int fx, int d) {     return fx == 1                ? mul(sub(h[x][1], h[fa[id[dfn[x] - d + 1]]][1]), ipw[dep[x] - d])                : sub(h[id[dfn[x] + d - 1]][0], mul(h[fa[x]][0], pw[d]));   }   int cal(int u, int fu, int v, int fv, int lim) {     if (ask(u, fu, lim) == ask(v, fv, lim)) return lim;     int l = 1, r = lim - 1;     for (int mid; l <= r;)       mid = (l + r) / 2,       ask(u, fu, mid) == ask(v, fv, mid) ? l = mid + 1 : r = mid - 1;     return r;   }   void solve() {     int a = read(), b = read(), c = read(), d = read(), ans = 0;     vec l = split(a, b), r = split(c, d);     for (int pl = 0, pr = 0, l1, l2, f1, f2, d, x;          pl < (int)l.size() && pr < (int)r.size();) {       l1 = abs(dep[l[pl].first] - dep[l[pl].second]) + 1,       l2 = abs(dep[r[pr].first] - dep[r[pr].second]) + 1,       f1 = sgn(dep[l[pl].first] - dep[l[pl].second]),       f2 = sgn(dep[r[pr].first] - dep[r[pr].second]), d = std::min(l1, l2);       ans += x = cal(l[pl].first, f1, r[pr].first, f2, d);       if (d ^ x) break;       (l1 == d ? ++pl : l[pl].first = id[dfn[l[pl].first] - f1 * d]),           (l2 == d ? ++pr : r[pr].first = id[dfn[r[pr].first] - f2 * d]);     }     printf( %d n , ans);   }   int main() {     n = read(), scanf( %s , str + 1), pw[0] = ipw[0] = 1;     for (int i = 1; i <= n; ++i)       pw[i] = mul(233, pw[i - 1]), ipw[i] = mul(78741179, ipw[i - 1]);     for (int i = 1, u, v; i < n; ++i)       u = read(), v = read(), e[u].push_back(v), e[v].push_back(u);     dfs1(1, 0), dfs2(1, 1);     for (int m = read(); m; --m) solve();   }


#include <bits/stdc++.h>   using namespace std;   default_random_engine generator;   uniform_int_distribution<int> distribution(1, INT_MAX);   vector<vector<long long> > one(int sz) {     vector<vector<long long> > ret;     ret.resize(sz);     for (int i = 0; i < ret.size(); i++) {       ret[i].resize(sz);       for (int j = 0; j < ret.size(); j++) {         ret[i][j] = (i == j);       }     }     return ret;   }   vector<vector<long long> > mult(vector<vector<long long> > a,                                   vector<vector<long long> > b) {     vector<vector<long long> > ret;     ret.resize(a.size());     for (int i = 0; i < ret.size(); i++) {       ret[i].resize(a.size());       for (int j = 0; j < ret.size(); j++) {         ret[i][j] = 0;       }     }     for (int k = 0; k < ret.size(); k++) {       for (int i = 0; i < a.size(); i++) {         for (int j = 0; j < b.size(); j++) {           ret[i][j] = (ret[i][j] + a[i][k] * b[k][j]);           ret[i][j] %= 998244353;         }       }     }     return ret;   }   vector<vector<long long> > pw(vector<vector<long long> > a, long long b) {     if (b == 0) return one((int)a.size());     if (b % 2) return mult(a, pw(a, b - 1));     return pw(mult(a, a), b / 2);   }   long long my_rand(long long a = 0, long long b = INT_MAX) {     return a + distribution(generator) % b;   }   inline int mul(int a, int b) { return int(a * 1ll * b % 998244353); }   inline int norm(int a) {     if (a >= 998244353) a -= 998244353;     if (a < 0) a += 998244353;     return a;   }   inline int binPow(int a, int k) {     int ans = 1;     while (k > 0) {       if (k & 1) ans = mul(ans, a);       a = mul(a, a);       k >>= 1;     }     return ans;   }   inline int subtract(int a, int b) { return norm(a - b); }   inline int inv(int a) { return binPow(a, 998244353 - 2); }   long long ceil_int(long long a, long long b) { return a / b + (a % b != 0); }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   int main() {     generator.seed(chrono::system_clock::now().time_since_epoch().count());     cin.sync_with_stdio(false);     cin.tie(0);     int x;     cin >> x;     int cnt = 0;     vector<int> op;     int ok = 0;     do {       int k = x;       int pos = -1;       int j = 0;       while (k > 0) {         if ((k & 1) == 0) {           pos = j;         }         j++;         k >>= 1;       }       if (pos == -1)         break;       else if (cnt % 2 == 0)         op.push_back(pos + 1);       if (cnt % 2 == 0) {         x = x ^ ((1 << (pos + 1)) - 1);       } else {         x++;       }       cnt++;     } while (1);     cout << cnt << endl;     for (int i = 0; i < op.size(); i++) {       cout << op[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O3 )   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast,unroll-loops,no-stack-protector,fast-math )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   const long long mod = 1e9 + 7;   const long long N = 1e5 + 5;   void solve(void) {     long long a, flag = 0;     string b;     cin >> a >> b;     long long n = b.length();     for (long long i = 0; i < n; i++) {       if (b[i] !=  9 ) {         flag = 1;         break;       }     }     n -= flag;     cout << n * a <<   n ;   }   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << fixed << setprecision(10);     ;     long long ___ = 1;     cin >> ___;     while (___--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3,  Ofast ,  inline )   #pragma GCC target( avx,avx2 )   using namespace std;   template <class t>   inline t read(t &x) {     char c = getchar();     bool f = 0;     x = 0;     while (!isdigit(c)) f |= c ==  - , c = getchar();     while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     if (f) x = -x;     return x;   }   template <class t>   inline void write(t x) {     if (x < 0)       putchar( - ), write(-x);     else {       if (x > 9) write(x / 10);       putchar( 0  + x % 10);     }   }   const int mod = 1e9, N = 2e5 + 5;   int tr0[N << 2], tr1[N << 2], tg[N << 2], n, m, f[N], sum[N];   int trans(int x, int len) {     if (!len) return tr0[x];     if (len == 1) return tr1[x];     return (1ll * tr0[x] * f[len - 2] + 1ll * tr1[x] * f[len - 1]) % mod;   }   void pushup(int x, int l, int r) {     int mid = l + r >> 1;     tr0[x] = tr0[x << 1] + trans(x << 1 | 1, mid - l + 1);     if (tr0[x] > mod) tr0[x] -= mod;     tr1[x] = tr1[x << 1] + trans(x << 1 | 1, mid - l + 2);     if (tr1[x] > mod) tr1[x] -= mod;   }   void build(int x, int l, int r) {     if (l == r) {       tr0[x] = read(tr1[x]);       return;     }     int mid = l + r >> 1;     build(x << 1, l, mid);     build(x << 1 | 1, mid + 1, r);     pushup(x, l, r);   }   void add(int x, int len, int v) {     tg[x] += v;     if (tg[x] > mod) tg[x] -= mod;     tr0[x] = (tr0[x] + 1ll * sum[len - 1] * v) % mod;     tr1[x] = (tr1[x] + 1ll * (sum[len] - 1 + mod) * v) % mod;   }   void pushdown(int x, int l, int r) {     if (!tg[x]) return;     int mid = l + r >> 1;     add(x << 1, mid - l + 1, tg[x]);     add(x << 1 | 1, r - mid, tg[x]);     tg[x] = 0;   }   void mfy(int x, int l, int r, int p, int v) {     if (l == r) {       tr0[x] = tr1[x] = v;       return;     }     pushdown(x, l, r);     int mid = l + r >> 1;     if (p <= mid)       mfy(x << 1, l, mid, p, v);     else       mfy(x << 1 | 1, mid + 1, r, p, v);     pushup(x, l, r);   }   void up(int x, int l, int r, int p, int q, int v) {     if (p <= l && r <= q) {       add(x, r - l + 1, v);       return;     }     pushdown(x, l, r);     int mid = l + r >> 1;     if (p <= mid) up(x << 1, l, mid, p, q, v);     if (q > mid) up(x << 1 | 1, mid + 1, r, p, q, v);     pushup(x, l, r);   }   int que(int x, int l, int r, int p, int q) {     if (p <= l && r <= q) return trans(x, l - p);     pushdown(x, l, r);     int mid = l + r >> 1, res = 0;     if (p <= mid) res += que(x << 1, l, mid, p, q);     if (q > mid) res += que(x << 1 | 1, mid + 1, r, p, q);     if (res > mod) res -= mod;     return res;   }   signed main() {     read(n);     read(m);     f[0] = f[1] = 1;     sum[0] = 1;     sum[1] = 2;     for (int i = 2; i <= n; i++) {       f[i] = f[i - 1] + f[i - 2];       if (f[i] > mod) f[i] -= mod;       sum[i] = sum[i - 1] + f[i];       if (sum[i] > mod) sum[i] -= mod;     }     build(1, 1, n);     while (m--) {       int op;       read(op);       if (op == 1) {         int p, v;         read(p);         read(v);         mfy(1, 1, n, p, v);       }       if (op == 2) {         int l, r;         read(l);         read(r);         write(que(1, 1, n, l, r));         puts(  );       }       if (op == 3) {         int l, r, v;         read(l);         read(r);         read(v);         up(1, 1, n, l, r, v);       }     }   }