#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   const long long INF = 1e15 + 7;   const long long N = 2e5 + 10;   const long long mod = 998244353;   long long pow(long long x, long long y) {     long long res = 1;     while (y > (long long)0) {       if (y & (long long)1) res = ((res) * (x));       y = y >> (long long)1;       x = ((x) * (x));     }     return res;   }   long long powm(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > (long long)0) {       if (y & (long long)1) res = (res * x) % p;       y >>= (long long)1;       x = (x * x) % p;     }     return res;   }   void solve() {     long long n;     cin >> n;     string s;     cin >> s;     long long w = 0, b = 0;     vector<long long> v;     for (long long i = 0; i < n; i++) {       if (s[i] ==  B )         b++;       else         w++;     }     if (b % 2 != 0 && w % 2 != 0) {       cout << -1 << endl;       return;     }     if (b % 2 == 0) {       for (long long i = 0; i < n - 1; i++) {         if (s[i] ==  B ) {           s[i] =  W ;           if (s[i + 1] ==  B )             s[i + 1] =  W ;           else             s[i + 1] =  B ;           v.push_back(i + 1);         }       }     } else if (w % 2 == 0) {       for (long long i = 0; i < n - 1; i++) {         if (s[i] ==  W ) {           s[i] =  B ;           if (s[i + 1] ==  B )             s[i + 1] =  W ;           else             s[i + 1] =  B ;           v.push_back(i + 1);         }       }     }     cout << v.size() << endl;     for (auto i : v) cout << i <<    ;     cout << endl;     return;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long ts = 1;     while (ts--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   void magic(int n) {     int cnt = 0;     set<vector<vector<int>>> s;     vector<pair<int, string>> ans;     map<int, int> mp;     function<void(vector<vector<int>>)> f = [&](const vector<vector<int>> &x) {       if (s.find(x) != s.end()) return;       s.insert(x);       if (x.size() == 1) {         ++cnt;         ans.push_back({0,   });         for (auto &i : x)           for (auto j : i) {             ans.back().second.push_back( 0  + j);             ans.back().first += j;           }         return;       }       for (size_t i = 1; i < x.size(); ++i) {         vector<vector<int>> y = x;         y.erase(y.begin() + i);         for (auto &z : x[i]) y[i - 1].push_back(z);         for (auto &z : y[i - 1]) z ^= 1;         f(y);       }     };     vector<vector<int>> a(n, vector<int>(1, 1));     f(a);     cout << cnt <<   n ;     sort(ans.begin(), ans.end());     for (auto i : ans) {       cout << i.first <<     << i.second <<   n ;       ++mp[i.first];     }     for (auto i : mp) {       cout << i.first <<     << i.second <<   n ;     }   }   void brute(vector<long long> a) {     long long ans = numeric_limits<long long>::min();     set<vector<long long>> s;     function<void(vector<long long>)> f = [&](const vector<long long> &x) {       if (x.size() == 1) {         ans = max(ans, x[0]);         return;       }       if (s.find(x) != s.end()) return;       s.insert(x);       for (size_t i = 1; i < x.size(); ++i) {         vector<long long> y = x;         y.erase(y.begin() + i);         y[i - 1] = -x[i - 1] - x[i];         f(y);       }     };     f(a);     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n;     cin >> n;     vector<pair<long long, int>> a(n);     for (auto &i : a) cin >> i.first, i.second = &i - &a[0];     long long sum = 0;     for (auto i : a) sum += -i.first;     for (auto &i : a) i.first *= 2;     sort(a.rbegin(), a.rend());     int t = n % 3;     if (t == 2)       t = 0;     else if (t == 0)       t = 2;     a.insert(a.begin(), {0, 0});     for (int i = 1; i <= n; ++i) a[i].first += a[i - 1].first;     auto get = [&](int p) { return a[p].first - a[p - 1].first; };     long long rans = numeric_limits<long long>::min();     for (; t <= n; t += 3) {       if (n > 1 && (n & 1) && t == (n + 1) / 2) {         bool bad = true;         for (int i = 1; i <= t; ++i) bad &= ~a[i].second & 1;         rans = max(rans, sum + a[t].first + bad * (-get(t) + get(t + 1)));       } else         rans = max(rans, sum + a[t].first);     }     cout << rans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long num;     cin >> n;     set<long> s;     while (n > 0) {       cin >> num;       while (num % 2 == 0) {         num = num / 2;       }       while (num % 3 == 0) {         num = num / 3;       }       s.insert(num);       n--;     }     if (s.size() == 1) {       cout <<  Yes ;     } else {       cout <<  No ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   template <typename t1>   t1 gcd(t1 a, t1 b) {     return b == 0 ? a : gcd(b, a % b);   }   template <typename t1>   t1 lcm(t1 a, t1 b) {     return a * (b / gcd(a, b));   }   int main() {     int n, d, h;     while (cin >> n >> d >> h) {       if (h == 1 && d == 1 && n > 2)         cout << -1 << endl;       else if (d < h)         cout << -1 << endl;       else if (n <= d || d > 2 * h)         cout << -1 << endl;       else if (h == d) {         {           int l = h;           int now = 1;           while (l--) {             cout << now <<     << now + 1 << endl;             now++;           }           now++;           int nnn = 2;           int tem = d + 1;           while (now <= n) {             cout << nnn <<     << now++ << endl;           }         }       } else {         int l = h;         int now = 1;         while (l--) {           cout << now <<     << now + 1 << endl;           now++;         }         now++;         int rem = d - h;         while (now <= n) {           int flag = 0;           int noww = 1;           int nrem = rem;           while (nrem--) {             if (now > n) {               flag = 1;               break;             }             cout << noww <<     << now << endl;             noww = now;             now++;           }           if (flag) break;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int start;   int tail;   int head[150500], to[150500], nxt[150500], wei[150500], cost[150500], tot = 1;   int dis[5050], pre[5050], pres[5050];   bool vis[5050];   queue<int> que;   int n, sum, k;   int used, flow;   char str[105];   int numstr[30], numstr1[105][30], num[105];   void add(int x, int y, int z, int w) {     tot++, to[tot] = y, nxt[tot] = head[x], head[x] = tot, cost[tot] = w,            wei[tot] = z;     tot++, to[tot] = x, nxt[tot] = head[y], head[y] = tot, cost[tot] = -w,            wei[tot] = 0;   }   bool spfa() {     memset(dis, inf, sizeof(dis));     memset(vis, 0, sizeof(vis));     dis[start] = 0;     que.push(start);     int now;     do {       now = que.front();       vis[now] = 0;       que.pop();       for (int i = head[now]; i; i = nxt[i]) {         if (dis[to[i]] > dis[now] + cost[i] && wei[i]) {           dis[to[i]] = dis[now] + cost[i];           pre[to[i]] = now;           pres[to[i]] = i;           if (!vis[to[i]]) {             que.push(to[i]);             vis[to[i]] = 1;           }         }       }     } while (!que.empty());     return dis[tail] != inf;   }   void f() {     int now = tail;     int low = inf;     while (now != start) {       low = min(low, wei[pres[now]]);       now = pre[now];     }     used += low * dis[tail];     flow += low;     now = tail;     while (now != start) {       wei[pres[now]] -= low;       wei[pres[now] ^ 1] += low;       now = pre[now];     }   }   int main() {     int len;     cin >> str;     len = strlen(str);     for (int i = 0; i < strlen(str); i++) {       numstr[str[i] -  a  + 1]++;     }     cin >> k;     start = 0, tail = 30;     for (int i = 1; i <= k; i++) {       cin >> str >> num[i];       for (int j = 0; j < strlen(str); j++) {         numstr1[i][str[j] -  a  + 1]++;       }     }     for (int i = 1; i <= 26; i++) {       if (!numstr[i]) continue;       add(start, i, numstr[i], 0);       for (int j = 1; j <= k; j++) {         if (!numstr1[j][i]) continue;         add(i, j + 30, numstr1[j][i], j);       }     }     for (int i = 1; i <= k; i++) {       add(i + 30, tail, num[i], 0);     }     while (spfa()) {       f();     }     if (flow != len) {       cout << -1 << endl;     } else {       cout << used << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   int n, u;   int e[N];   double ans = -1;   int search(int l, int r, int k) {     int m, p = -1;     while (l <= r) {       m = (l + r) / 2;       if (e[m] <= k) {         p = m;         l = m + 1;       } else         r = m - 1;     }     return p;   }   void solve() {     for (int i = 0; i < n - 2; i++) {       int k = search(i + 2, n - 1, e[i] + u);       if (k == -1) continue;       ans = max(ans, 1.0 * (e[k] - e[i + 1]) / (e[k] - e[i]));     }     if (ans > 0)       printf( %.9f n , ans);     else       puts( -1 );   }   int main() {     cin >> n >> u;     for (int i = 0; i < n; i++) {       cin >> e[i];     }     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 600005;   int n, m, l, r, ma, a[N], f[N][22];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &l, &r);       a[l] = max(a[l], r);       ma = max(ma, r);     }     for (int i = 1; i <= ma; i++) a[i] = max(a[i], a[i - 1]);     for (int i = 0; i <= ma; i++) f[i][0] = a[i];     for (int i = 1; i <= 20; i++)       for (int j = 0; j <= ma; j++) f[j][i] = f[f[j][i - 1]][i - 1];     while (m--) {       cin >> l >> r;       int ans = 0;       for (int i = 20; i >= 0; i--)         if (f[l][i] < r) {           ans += 1 << i;           l = f[l][i];         }       if (a[l] >= r)         printf( %d n , ans + 1);       else         cout << -1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1000000 + 5;   const long long MOD = 1000000007;   long long n, m, k;   long long ans;   long long v[N], sum[N];   long long Pow(long long x, long long k) {     long long z = 1;     for (; k; k >>= 1, (x *= x) %= MOD)       if (k & 1) (z *= x) %= MOD;     return z;   }   int main() {     scanf( %I64d %I64d %I64d , &n, &m, &k);     long long a, b, flag = 0, st = 0, ed = 0;     for (long long i = 1; i <= m; i++) {       scanf( %I64d %I64d , &a, &b);       if (a >= b) flag = 1;       if (b - a == 1 || b - a == k + 1)         ;       else         flag = 1;       if (b - a == k + 1) {         v[a] = 1;         if (!st) st = a;         ed = a;       }     }     if (flag || (ed - st >= k + 1))       printf( 0 n );     else {       for (long long i = 1; i <= n; i++) sum[i] = sum[i - 1] + v[i];       n -= ++k;       for (long long i = 1; i <= n; i++)         if (!st || (!v[i] && abs(i - st) + 1 <= k && abs(i - ed) + 1 <= k)) {           long long tmp = st ? ((((i) < (st) ? (i) : (st)) + k - 1) < (n)                                     ? (((i) < (st) ? (i) : (st)) + k - 1)                                     : (n))                              : n;           long long r = ((k - 1) < (tmp - i) ? (k - 1) : (tmp - i));           (ans += Pow(2, r - (sum[i + r] - sum[i]))) %= MOD;         }       printf( %I64d n , ans + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int _ = 1e5 + 7, P = 1e9 + 7;   int N, A[_], prm[_], cprm, phi[_], cnt[_];   bool nprm[_];   vector<int> lst[_];   void sieve() {     phi[1] = 1;     for (int i = 2; i <= 1e5; ++i) {       if (!nprm[i]) {         prm[++cprm] = i;         phi[i] = i - 1;       }       for (int j = 1; prm[j] * i <= 1e5; ++j) {         nprm[prm[j] * i] = 1;         if (i % prm[j] == 0) {           phi[i * prm[j]] = phi[i] * prm[j];           break;         }         phi[i * prm[j]] = phi[i] * (prm[j] - 1);       }     }     for (int i = 1; i <= 1e5; ++i)       for (int j = i; j <= 1e5; j += i) lst[j].push_back(i);   }   int main() {     ios::sync_with_stdio(0);     sieve();     cin >> N;     for (int i = 1; i <= N; ++i) cin >> A[i];     int ans = 0;     vector<int> vis;     for (int d = 1; d <= N; ++d) {       for (int t = d; t <= N; t += d)         for (auto v : lst[A[t]])           if (!(cnt[v]++)) vis.push_back(v);       for (auto t : vis) {         ans = (ans + 1ll * phi[d] * phi[t] % P * cnt[t] * cnt[t]) % P;         cnt[t] = 0;       }       vis.clear();     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     pair<int, int> a[555555];     double n, k, t, l = -1, r = 1e12, c, maxx, yes = 0;     int i;     cin >> n;     for (i = 0; i < n; i++) scanf( %d%d , &a[i].first, &a[i].second);     for (k = 0; k < 300; k++) {       maxx = -1e30;       c = (l + r) * 0.5;       t = 0;       for (i = 0; i < n; i++)         if (a[i].second > 0)           maxx = max(maxx, a[i].first + a[i].second * c);         else if (maxx >= a[i].first + a[i].second * c) {           t = 1;           break;         }       if (t) {         yes = 1;         r = c;       } else         l = c;     }     cout.precision(20);     if (yes == 0) r = -1;     cout << r;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cin.ignore();     string arr;     getline(cin, arr);     int mx = 0;     int cur = 0;     for (int i = 0; i < n; i++) {       if (arr[i] ==    ) {         mx = max(mx, cur);         cur = 0;         continue;       }       if (isupper(arr[i])) {         cur++;       }     }     mx = max(mx, cur);     cout << mx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, j, k, l, x, y, z, m, n, a, b, ans, p, q, r;   int numbers[800000];   int gcd(int x, int y) {     if (y == 0)       return x;     else       return gcd(y, x % y);   }   int main() {     scanf( %d %d %d , &a, &b, &n);     ans = gcd(a, b);     m = sqrt(ans);     for (i = 1, k = 0; i <= m; i++) {       if (ans % i == 0) {         p = ans / i;         numbers[k] = p;         k++;         numbers[k] = i;         k++;       }     }     sort(numbers, numbers + k);     p = 0;     q = 0;     for (i = 1; i <= n; i++) {       scanf( %d %d , &x, &y);       if (x > ans) {         printf( -1 n );         continue;       }       p = lower_bound(numbers, numbers + k, (x)) - numbers;       q = lower_bound(numbers, numbers + k, (y)) - numbers;       r = 0;       for (j = q + 1; j >= p - 1; j--) {         if (numbers[j] >= x && numbers[j] <= y) {           printf( %d n , numbers[j]);           r = 1;           break;         }       }       if (!r) printf( -1 n );     }     return 0;   }


#include <bits/stdc++.h>   int main(int argc, char *argv[]) {     std::string s;     std::cin >> s;     int yes = 0;     int len = s.length();     if (len < 3) {       std::cout <<  No ;       return 0;     }     for (int i = 0; i < len - 2; i++) {       std::string ss = s.substr(i, 3);       if (ss ==  ABC  || ss ==  ACB  || ss ==  BAC  || ss ==  BCA  ||           ss ==  CAB  || ss ==  CBA ) {         yes = 1;         break;       }     }     if (yes) {       std::cout <<  Yes ;     } else {       std::cout <<  No ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> v(n);       vector<int> ans(n);       for (int i = 0; i < n; i++) cin >> v[i];       int flagie = 1;       for (int i = 1; i < n; i++)         if (v[i] != v[i - 1]) flagie = 0;       if (flagie == 1) {         cout << 1 << endl;         for (auto x : ans) cout << 1 <<    ;         cout << endl;       } else {         if (n % 2 == 0) {           ans[0] = 1;           for (int i = 1; i < n; i++) {             ans[i] = 3 - ans[i - 1];           }           cout << 2 << endl;           for (auto x : ans) cout << x <<    ;           cout << endl;         } else {           if (v[0] == v[n - 1]) {             cout << 2 << endl;             ans[0] = 1;             for (int i = 1; i < n; i++) {               ans[i] = 3 - ans[i - 1];             }             for (auto x : ans) cout << x <<    ;             cout << endl;           } else {             int i;             for (i = 0; i < n - 1; i++) {               if (v[i] == v[i + 1]) break;             }             if (i == n - 1) {               ans[0] = 1;               for (int i = 1; i < n; i++) {                 ans[i] = 3 - ans[i - 1];               }               ans[n - 1] = 3;               cout << 3 << endl;               for (auto x : ans) cout << x <<    ;               cout << endl;             } else {               int flag = 1;               ans[0] = 1;               for (int i = 1; i < n; i++) {                 if (v[i] == v[i - 1] && flag == 1) {                   ans[i] = ans[i - 1];                   flag = 0;                 } else {                   ans[i] = 3 - ans[i - 1];                 }               }               cout << 2 << endl;               for (auto x : ans) cout << x <<    ;               cout << endl;             }           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   namespace patch {   template <typename T>   std::string to_string(const T& n) {     std::ostringstream stm;     stm << n;     return stm.str();   }   }  // namespace patch   int m, lim, len;   long long dp[1 << 18][101];   string s;   long long fac[19];   int freq[10];   long long solve(int mask, int mod) {     if (mask == lim) {       if (mod == 0) return 1;       return 0;     }     if (dp[mask][mod] != -1) return dp[mask][mod];     long long ans = 0;     for (int i = 0; i < len; ++i) {       if (!(mask & (1 << i))) {         if (mask == 0) {           if (s[i] ==  0 ) continue;         }         ans += solve(mask | (1 << i), (mod * 10 + (s[i] -  0 )) % m);       }     }     return dp[mask][mod] = ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     fac[0] = fac[1] = 1;     for (int i = 2; i <= 18; ++i) fac[i] = fac[i - 1] * (long long)i;     memset(dp, -1, sizeof dp);     cin >> s >> m;     len = s.size();     for (int i = 0; i < len; ++i) {       freq[s[i] -  0 ]++;     }     lim = (1 << len) - 1;     long long ans = solve(0, 0);     for (int i = 0; i < 10; ++i) {       if (freq[i]) ans /= fac[freq[i]];     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long Mod = 1e9 + 7;   const long long INF = (long long)(1e18) + 5;   const long long N = 2e5 + 5, M = 18;   int n, m, p;   int a[N];   tuple<long long, long long, long long> b[N];   long long suf_s[N], suf_c[N];   long long dp[N], prev_dp[N];   void solve(int i, int j, int l, int r) {     if (j < i) return;     int mid = i + j >> 1;     long long best = INF, idx = -1;     long long cnt = 0, sum = 0;     if (mid < l) {       sum += suf_s[mid] - suf_s[l];       cnt += suf_c[mid] - suf_c[l];     }     for (int k = max(mid, l); k <= r; k++) {       auto [t, c, s] = b[k];       sum += s;       cnt += c;       long long cur = sum + cnt * t + prev_dp[k + 1];       if (cur < best) best = cur, idx = k;     }     dp[mid] = best;     solve(i, mid - 1, l, idx);     solve(mid + 1, j, idx, r);   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m >> p;     for (int i = 1; i < n; i++) cin >> a[i], a[i] += a[i - 1];     map<long long, long long> cnt, sum;     long long ans2 = 0;     for (int i = 0; i < m; i++) {       int h, t;       cin >> h >> t;       h--;       cnt[t - a[h]]++;       sum[t - a[h]] += a[h] - t;     }     m = 0;     for (auto [i, j] : cnt) b[m++] = {i, j, sum[i]};     for (int i = m; i >= 0; i--) {       auto [t, c, s] = b[i];       suf_s[i] = s + suf_s[i + 1];       suf_c[i] = c + suf_c[i + 1];     }     for (int i = 0; i < m; i++) dp[i] = INF;     while (p--) {       swap(dp, prev_dp);       solve(0, m - 1, 0, m - 1);     }     cout << dp[0] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1e9 + 9;   const long long N = 500500;   signed main(void) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.precision(10);     cout << fixed;     long long v;     cin >> v;     if (v == 2) {       cout << 2;       return 0;     }     cout << 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void dfs(bool* visit, vector<int>* am, int n, int sv, vector<int>& v) {     visit[sv] = true;     v.push_back(sv);     for (int p = 0; p < am[sv].size(); ++p) {       if (visit[am[sv][p]] == false) {         dfs(visit, am, n, am[sv][p], v);       }     }     return;   }   int main() {     int n, m;     cin >> n >> m;     int* arr = new int[n];     vector<int>* graph = new vector<int>[n];     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       graph[a - 1].push_back(b - 1);       graph[b - 1].push_back(a - 1);     }     bool* visit = new bool[n]();     long long count = 1;     for (int cur = 0; cur < n; ++cur) {       if (visit[cur] == false) {         vector<int> v;         dfs(visit, graph, n, cur, v);         int p = v.size() - 1;         for (int j = 1; j <= p; ++j) {           count = count * 2;         }       }     }     cout << count << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int n, m;     cin >> n >> m;     char a, b;     int flag1, flag2;     cin >> s;     for (int i = 0; i < m; i++) {       cin >> flag1 >> flag2 >> a >> b;       for (int j = flag1 - 1; j <= flag2 - 1; j++) {         if (s[j] == a) {           s[j] = b;         }       }     }     cout << s << endl;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   int n, m;   int a[300000];   int s[300000];   int main() {     int i, j, k, l;     cin >> n >> m;     for (i = 0; i < n; i++) scanf( %d , &a[i]);     m--;     int ans = 0;     if (a[m] != 0) ans = 1, a[m] = 0;     if (n == 1) return !printf( %d , ans);     for (i = 0; i < n; i++) s[a[i]]++;     int z = 0;     int now = 0;     int mi = 0x3f3f3f3f;     for (i = 1; i < n; i++) {       if (s[i] == 0) z++;       now += s[i];       mi = min(mi, max(n - 1 - now, z));     }     cout << ans + mi;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i;     printf( 9 ? ?>> ? ?0 n );     for (i = 8; i >= 0; i--) printf( %d ? ?<>%d n , i, i + 1);     printf(  ? ?<>1 n );     for (i = 9; i >= 0; i--) printf( ?%d>>%d? n , i, i);     printf( >>? n );   }


#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   const long long mod = 1e9 + 7;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     unsigned long long n;     cin >> n;     unsigned long long c = 2 * 3 * 4 * 5 * 7 * 3;     if (c > n) {       cout <<  0 n ;       return 0;     }     cout << n / c <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   //using namespace atcoder;   struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;   #define FOR(i, begin, end) for(int i=(begin);i<(end);i++)   #define REP(i, n) FOR(i,0,n)   #define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)   #define IREP(i, n) IFOR(i,0,n)   #define Sort(v) sort(v.begin(), v.end())   #define Reverse(v) reverse(v.begin(), v.end())   #define all(v) v.begin(),v.end()   #define SZ(v) ((int)v.size())   #define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))   #define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))   #define chmax(a, b) a = max(a, b)   #define chmin(a, b) a = min(a, b)   #define bit(n) (1LL<<(n))   #define debug(x) cout << #x <<  =  << x << endl;   #define vdebug(v) { cout << #v <<  =  << endl; REP(i_debug, v.size()){ cout << v[i_debug] <<  , ; } cout << endl; }   #define mdebug(m) { cout << #m <<  =  << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] <<  , ; } cout << endl;} }   #define pb push_back   #define fi first   #define se second   #define int long long   #define INF 1000000000000000000   template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }   template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }   template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout <<  (  << p.first <<  ,  << p.second <<  ) ; return os; }   template<typename T> void Out(T x) { cout << x << endl; }   template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }      using vec = vector<int>;   using mat = vector<vec>;   using Pii = pair<int, int>;   using v_bool = vector<bool>;   using v_Pii = vector<Pii>;      //int dx[4] = {1,0,-1,0};   //int dy[4] = {0,1,0,-1};   //char d[4] = { D , R , U , L };      const int mod = 1000000007;   //const int mod = 998244353;      struct edge{int to, cost, id;};      class Graph   {   public:       int N;       vector<vector<edge>> G;          Graph(int N): N(N){           G = vector<vector<edge>>(N, vector<edge>(0));       }          void add_Directed_edge(int from, int to, int cost = 1, int id = 0){           G[from].push_back(edge({to, cost, id}));       }          void add_Undirected_edge(int v1, int v2, int cost = 1, int id = 0){           add_Directed_edge(v1, v2, cost, id);           add_Directed_edge(v2, v1, cost, id);       }          //二部グラフ判定       vector<int> color;       bool is_bipartite(){           color = vec(N, -1);           REP(i, N) if(color[i] == -1){               if(!dfs_for_check_bipartite(i, 0)) return false;           }           return true;       }       bool dfs_for_check_bipartite(int v, int c){           if(color[v] != -1){               if(color[v] == c) return true;               else return false;           }           color[v] = c;           for(auto e: G[v]) if(!dfs_for_check_bipartite(e.to, (c + e.cost) & 1)) return false;           return true;       }             vec bellman_ford(int s, bool &ok){           ok = false;           vec d(N);           fill(d.begin(), d.end(), INF);           d[s] = 0;           REP(t, N){               bool update = false;               REP(v, N){                   REP(i, G[v].size()){                       edge e = G[v][i];                       if(d[v] != INF && d[e.to] > d[v] + e.cost){                           d[e.to] = d[v] + e.cost;                           update = true;                       }                   }               }               if(!update){                   ok = true;                   break;               }           }           return d;       }      };      void imp(){       Out( NO );       exit(0);   }      signed main(){          int n, m; cin >> n >> m;       Graph G(n);       REP(_, m){           int i, j, b; cin >> i >> j >> b;           i--; j--;           if(b == 0){               G.add_Directed_edge(i, j, 1);               G.add_Directed_edge(j, i, 1);           }else{               G.add_Directed_edge(i, j, 1);               G.add_Directed_edge(j, i, -1);           }       }          if(!G.is_bipartite()) imp();          vec ans(n);       int M = -1;       REP(s, n){           bool ok;           vec d = G.bellman_ford(s, ok);           if(!ok) continue;           int mm = INF, MM = -INF;           REP(i, n){               chmin(mm, d[i]);               chmax(MM, d[i]);           }           if(MM - mm > M){               M = MM - mm;               REP(i, n) ans[i] = d[i] - mm;           }       }          if(M == -1) imp();       Out( YES );       Out(M);       REP(i, n) cout << ans[i] <<    ;       cout << endl;          return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, y, neg, pos;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y;       if (x < 0)         neg++;       else         pos++;     }     if (pos <= 1 || neg <= 1)       cout <<  Yes ;     else       cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, i, x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     cout << (x2 - x1) * (y2 - y1) + 1 <<   n ;   }   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long tt;     cin >> tt;     while (tt--) {       solve();     }     cerr <<   Execution :   << (1.0 * clock()) / CLOCKS_PER_SEC <<  s  n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1e5 + 5;   long double N, t;   long double Pow(long double b, long long e) {     if (e == 0) return 1;     long double ret = Pow(b, e / 2);     ret *= ret;     if (e % 2) return ret * b;     return ret;   }   int main() {     cin >> N >> t;     N *= Pow(1.000000011, t);     printf( %.12lf , (double)N);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long i, j, c = 0, k, n, x = 0, y = 0;     char ch;     string s;     cin >> n;     cin >> s;     for (i = 0; i < n - 1; i++) {       if (s[i] ==  U ) {         y = y + 1;       }       if (s[i] ==  R ) {         x = x + 1;       }       if (x == y) {         ch = s[i];         if (s[i + 1] == ch) {           c++;         }       }     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, m, k, fa[N], cnt[N], vis[N];   vector<int> G[N];   vector<pair<int, int> > p, q[N];   int findset(int x) { return x == fa[x] ? x : fa[x] = findset(fa[x]); }   void dfs(int x) {     vis[x] = 1;     for (auto it : G[x]) dfs(it);     for (auto it : q[x])       if (vis[it.first]) cnt[it.second]++;     vis[x] = 0;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i <= n; i++) fa[i] = i;     int opt, x, y;     while (m--) {       scanf( %d %d , &opt, &x);       if (opt == 1)         scanf( %d , &y), fa[x] = y, G[y].push_back(x);       else if (opt == 2)         p.push_back({findset(x), x});       else {         scanf( %d , &y);         q[x].push_back({p[y - 1].first, k});         q[p[y - 1].second].push_back({x, k});         k++;       }     }     for (int i = 1; i <= n; i++)       if (fa[i] == i) dfs(i);     for (int i = 0; i < k; i++) printf( %s n , cnt[i] == 2 ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, lcnt;   long long m, p, q;   int a[100005], lsum[100005];   long long sum[100005], rmax[100005], lmin[100005], ls[100005];   long long ans1, ans2, ans;   set<int> unu;   inline long long Min(long long x, long long y) { return x < y ? x : y; }   inline long long Max(long long x, long long y) { return x > y ? x : y; }   inline int lowbit(int k) { return k & -k; }   struct ta {     long long t[100005];     void add(int k, long long x) {       for (; k <= lcnt; k += lowbit(k)) t[k] += x;     }     inline long long query(int k) {       long long ans = 0;       for (; k; k -= lowbit(k)) ans += t[k];       return ans;     }   } tsum, tnum;   struct ta2 {     int t[100005];     void build() {       for (int i = 1; i <= lcnt; i++) t[i] = n + 1;     }     void add(int k, int x) {       for (; k <= lcnt; k += lowbit(k)) t[k] = Min(t[k], x);     }     inline int query(int k) {       int ans = n + 1;       for (; k; k -= lowbit(k)) ans = Min(ans, t[k]);       return ans;     }   } tmin;   struct subs {     int l, r;     long long w;     bool operator>(const subs k) const {       if (w != k.w)         return w > k.w;       else if (r != k.r)         return r > k.r;       else         return l > k.l;     }     bool operator<(const subs k) const {       if (w != k.w)         return w < k.w;       else if (r != k.r)         return r < k.r;       else         return l < k.l;     }     bool operator==(const subs k) const {       return (k.l == l) && (k.r == r) && (k.w == w);     }     bool operator!=(const subs k) const {       return (k.l != l) || (k.r != r) || (k.w != w);     }   };   struct heap {     subs h[100005];     int top;     void pushdown(int k) {       while ((k << 1) <= top) {         int v = k << 1;         if (v + 1 <= top)           if (h[v | 1] > h[v]) v++;         if (h[v] > h[k])           swap(h[v], h[k]);         else           break;         k = v;       }     }     void pushup(int k) {       while (k > 1) {         int v = k >> 1;         if (h[v] < h[k])           swap(h[v], h[k]);         else           break;         k = v;       }     }     void push(subs k) {       h[++top] = k;       pushup(top);     }     void pop() {       h[1] = h[top--];       pushdown(1);     }   } subsq;   void del(int k);   struct sg1 {     bool b[400005];     void cover(int L, int R, int l, int r, int index) {       if (L > R) return;       if (b[index]) return;       if (l == r) {         del(l);         b[index] = true;         return;       }       if (L <= ((l + r) >> 1)) cover(L, R, l, ((l + r) >> 1), index << 1);       if (R > ((l + r) >> 1)) cover(L, R, ((l + r) >> 1) + 1, r, index << 1 | 1);       b[index] = b[index << 1] && b[index << 1 | 1];     }   } s1;   struct t {     long long max[100005][17], min[100005][17];     int lo[100005];     void build(int l, int r, int index) {       lo[1] = 0;       for (int i = 2; i <= n; i++)         if ((1 << (lo[i - 1] + 1)) == i)           lo[i] = lo[i - 1] + 1;         else           lo[i] = lo[i - 1];       for (int i = 0; i <= n; i++) max[i][0] = min[i][0] = sum[i];       for (int i = 1; i <= lo[n]; i++)         for (int j = 0; j + (1 << i) - 1 <= n; j++)           max[j][i] = Max(max[j][i - 1], max[j + (1 << (i - 1))][i - 1]),           min[j][i] = Min(min[j][i - 1], min[j + (1 << (i - 1))][i - 1]);     }     long long query(int l, int r) {       int tmp = lo[r - l + 1];       return Max(max[l][tmp], max[r - (1 << tmp) + 1][tmp]) -              Min(min[l][tmp], min[r - (1 << tmp) + 1][tmp]);     }   } s2;   struct node3 {     int l, r, s;   };   struct sg3 {     node3 t[4000005];     int root[100005], cnt;     void ins(int &rt, int l, int r, int k) {       if (rt == 0) rt = ++cnt;       t[rt].s++;       if (l == r) return;       if (k <= ((l + r) >> 1))         ins(t[rt].l, l, ((l + r) >> 1), k);       else         ins(t[rt].r, ((l + r) >> 1) + 1, r, k);     }     void build() {       for (int i = 0; i <= n; i++) ins(root[lsum[i]], 0, n, i);     }     inline int qsum(int rt, int l, int r, int k) {       if (rt == 0) return 0;       if (r == k) return t[rt].s;       if (k <= ((l + r) >> 1))         return qsum(t[rt].l, l, ((l + r) >> 1), k);       else         return t[t[rt].l].s + qsum(t[rt].r, ((l + r) >> 1) + 1, r, k);     }     inline int query(int rt, int l, int r, int k) {       if (l == r) return r;       if (k <= t[t[rt].l].s)         return query(t[rt].l, l, ((l + r) >> 1), k);       else         return query(t[rt].r, ((l + r) >> 1) + 1, r, k - t[t[rt].l].s);     }   } s3;   struct sg4 {     node3 t[4000005];     int cnt, root[100005];     void ins(int &rt, int Rt, int l, int r, int k) {       rt = ++cnt;       if (l == r) return;       if (k <= ((l + r) >> 1)) {         t[rt].r = t[Rt].r;         ins(t[rt].l, t[Rt].l, l, ((l + r) >> 1), k);       } else {         t[rt].l = t[Rt].l;         ins(t[rt].r, t[Rt].r, ((l + r) >> 1) + 1, r, k);       }     }     void build() {       ins(root[0], 0, 1, lcnt, lsum[0]);       for (int i = 1; i <= n; i++) ins(root[i], root[i - 1], 1, lcnt, lsum[i]);     }     inline int query(int rt, int l, int r, int k) {       if ((k > r) || (rt == 0)) return 0;       if (l == r) return l;       if (k > ((l + r) >> 1))         return query(t[rt].r, ((l + r) >> 1) + 1, r, k);       else {         int tmp = query(t[rt].l, l, ((l + r) >> 1), k);         if (tmp)           return tmp;         else           return query(t[rt].r, ((l + r) >> 1) + 1, r, k);       }     }   } s4;   struct splaynode {     int l, r, size, fa;     subs s;     long long sum;   };   struct Splay {     splaynode t[100005];     int root, top, cnt, stack[100005];     inline int newnode() { return stack[top--]; }     void pushup(int rt) {       t[rt].size = t[t[rt].l].size + t[t[rt].r].size + 1;       t[rt].sum = t[t[rt].l].sum + t[t[rt].r].sum + t[rt].s.w;     }     void rorate(int k, int i) {       int tmp = t[k].fa;       t[k].fa = t[tmp].fa;       if (t[t[tmp].fa].l == tmp)         t[t[tmp].fa].l = k;       else         t[t[tmp].fa].r = k;       t[tmp].fa = k;       if (i == 0) {         if (t[k].l > 0) t[t[k].l].fa = tmp;         t[tmp].r = t[k].l;         t[k].l = tmp;       } else {         if (t[k].r > 0) t[t[k].r].fa = tmp;         t[tmp].l = t[k].r;         t[k].r = tmp;       }       pushup(tmp);       pushup(k);     }     void splay(int k, int g) {       while (t[k].fa != g) {         int tmp = t[k].fa;         if (t[tmp].fa == g)           if (t[tmp].r == k)             rorate(k, 0);           else             rorate(k, 1);         else {           int Tmp = t[tmp].fa;           if (t[Tmp].l == tmp) {             if (t[tmp].l == k)               rorate(tmp, 1);             else               rorate(k, 0);             rorate(k, 1);           } else {             if (t[tmp].r == k)               rorate(tmp, 0);             else               rorate(k, 1);             rorate(k, 0);           }         }       }       if (g == 0) root = k;     }     void build(int l, int r, int &rt) {       rt = ++cnt;       t[rt].s = (subs){((l + r) >> 1) + 1, ((l + r) >> 1), 0};       if (((l + r) >> 1) > l) {         build(l, ((l + r) >> 1) - 1, t[rt].l);         t[t[rt].l].fa = rt;       }       if (r > ((l + r) >> 1)) {         build(((l + r) >> 1) + 1, r, t[rt].r);         t[t[rt].r].fa = rt;       }       pushup(rt);     }     inline long long query(int k) {       if (k > t[root].size) return -8333583335000000000ll;       if (k == t[root].size) return t[root].sum;       int p = root;       while (t[t[p].r].size != k) {         if (k < t[t[p].r].size)           p = t[p].r;         else           k -= t[t[p].r].size + 1, p = t[p].l;       }       splay(p, 0);       return t[t[p].r].sum;     }     void ins(subs k) {       if (root == 0) {         root = newnode();         t[root].l = t[root].r = t[root].fa = 0;         t[root].s = k;         pushup(root);         return;       }       int p = root, v;       while (true) {         if (k < t[p].s)           if (t[p].l)             p = t[p].l;           else {             t[p].l = v = newnode();             break;           }         else if (t[p].r)           p = t[p].r;         else {           t[p].r = v = newnode();           break;         }       }       t[v].fa = p;       t[v].l = t[v].r = 0;       t[v].s = k;       pushup(v);       splay(v, 0);     }     void del(subs k) {       if (t[root].size == 1) {         root = 0;         return;       }       int p = root;       while (t[p].s != k) {         if (k < t[p].s)           p = t[p].l;         else           p = t[p].r;       }       splay(p, 0);       int tmp = t[p].l;       if (tmp == 0) {         t[t[p].r].fa = 0;         root = t[p].r;         stack[++top] = p;         return;       }       while (t[tmp].r) tmp = t[tmp].r;       splay(tmp, root);       t[tmp].fa = 0;       root = tmp;       if (t[p].r) t[t[p].r].fa = tmp, t[tmp].r = t[p].r;       pushup(tmp);       stack[++top] = p;     }   } s;   inline long long read() {     long long ret = 0, p = 1;     char c = getchar();     while ((c <  0 ) || (c >  9 )) {       if (c ==  - ) p = -1;       c = getchar();     }     while ((c >=  0 ) && (c <=  9 ))       ret = (ret << 1) + (ret << 3) + c -  0 , c = getchar();     return ret * p;   }   inline int find(long long k) {     int l = 0, r = lcnt + 1;     while (r - l > 1) {       if (ls[((l + r) >> 1)] > k)         r = ((l + r) >> 1);       else         l = ((l + r) >> 1);     }     return l;   }   inline long long checknum(long long std) {     long long ans = 0;     for (int i = 0; i <= n; i++) {       ans += tnum.query(find(sum[i] - std));       tnum.add(lsum[i], 1);     }     for (int i = 0; i <= n; i++) tnum.add(lsum[i], -1);     return ans;   }   void del(int k) {     set<int>::iterator p = unu.find(k), st = unu.begin(), ed = unu.end();     ed--;     if (p != st) {       set<int>::iterator pre = p;       pre--;       s.del((subs){(*pre) + 1, k - 1, s2.query((*pre), k - 1)});     }     if (p != ed) {       set<int>::iterator nex = p;       nex++;       s.del((subs){k + 1, (*nex) - 1, s2.query(k, (*nex) - 1)});     }     if ((p != st) && (p != ed)) {       set<int>::iterator pre = p, nex = p;       pre--;       nex++;       s.ins((subs){(*pre) + 1, (*nex) - 1, s2.query((*pre), (*nex) - 1)});     }     unu.erase(k);   }   inline subs Next(subs now) {     int l = now.l, r = now.r, L, R = r;     int tmp = s3.qsum(s3.root[lsum[l]], 0, n, l);     if (tmp == 1) {       int S = s4.query(s4.root[r - 1], 1, lcnt, lsum[l] + 1);       if (S == 0) return (subs){0, R, -8333583335000000000ll};       int Sum = s3.qsum(s3.root[S], 0, n, r - 1);       L = s3.query(s3.root[S], 0, n, Sum);     } else       L = s3.query(s3.root[lsum[l]], 0, n, tmp - 1);     return (subs){L, R, sum[R] - sum[L]};   }   inline long long checksum(long long std, long long rest) {     long long ans = 0;     tmin.build();     for (int i = 0; i <= n; i++) {       int t = find(sum[i] - std);       rest -= tnum.query(t);       ans += tnum.query(t) * sum[i];       ans += tsum.query(t);       s1.cover(tmin.query(t) + 1, i, 1, n, 1);       tnum.add(lsum[i], 1);       tsum.add(lsum[i], -sum[i]);       tmin.add(lsum[i], i);     }     for (int i = 0; i <= n; i++) tnum.add(lsum[i], -1);     std--;     ans += rest * std;     tnum.add(lsum[0], 1);     for (int i = 1; i <= n; i++) {       int Tmp = find(sum[i] - std);       if (ls[Tmp] != sum[i] - std) {         Tmp++;         tnum.add(lsum[i], 1);         int p = s4.query(s4.root[i - 1], 1, lcnt, Tmp);         if (p == 0) continue;         int L = s3.query(s3.root[p], 0, n, s3.qsum(s3.root[p], 0, n, i - 1));         subsq.push((subs){L, i, sum[i] - sum[L]});       } else {         int tmp = tnum.query(Tmp) - tnum.query(Tmp - 1);         tnum.add(lsum[i], 1);         if (tmp == 0) {           Tmp++;           int p = s4.query(s4.root[i - 1], 1, lcnt, Tmp);           if (p == 0) continue;           int L = s3.query(s3.root[p], 0, n, s3.qsum(s3.root[p], 0, n, i - 1));           subsq.push((subs){L, i, sum[i] - sum[L]});         } else if (tmp <= rest) {           int L = s3.query(s3.root[Tmp], 0, n, 1);           s1.cover(L + 1, i, 1, n, 1);           rest -= tmp;           Tmp++;           int p = s4.query(s4.root[i - 1], 1, lcnt, Tmp);           if (p == 0) continue;           L = s3.query(s3.root[p], 0, n, s3.qsum(s3.root[p], 0, n, i - 1));           subsq.push((subs){L, i, sum[i] - sum[L]});         } else {           int L;           if (rest) {             L = s3.query(s3.root[Tmp], 0, n, tmp - rest + 1);             s1.cover(L + 1, i, 1, n, 1);           }           L = s3.query(s3.root[Tmp], 0, n, tmp - rest);           subsq.push((subs){L, i, sum[i] - sum[L]});           rest = 0;         }       }     }     return ans;   }   void upans2() {     if (unu.empty()) {       ans2 = -8333583335000000000ll;       return;     }     ans2 = s.query(q - 1);     if (ans2 == -8333583335000000000ll) return;     set<int>::iterator p = unu.begin();     ans2 -= lmin[(*p) - 1];     p = unu.end();     p--;     ans2 += rmax[(*p)];   }   void work() {     for (int i = 1; i <= n; i++) unu.insert(i);     long long l = ls[1] - ls[lcnt] - 5, r = ls[lcnt] - ls[1] + 5;     while (r - l > 1) {       if (checknum(((l + r) >> 1)) >= p)         l = ((l + r) >> 1);       else         r = ((l + r) >> 1);     }     ans1 = checksum(r, p);     upans2();     if (ans2 > -8333583335000000000ll)       ans = ans1 + ans2;     else       ans = -8333583335000000000ll;   }   void pre() {     n = read();     m = read();     for (int i = 1; i <= n; i++) {       a[i] = read();       ls[i] = sum[i] = sum[i - 1] + a[i];     }     ls[n + 1] = 0;     sort(ls + 1, ls + 2 + n);     ls[0] = -8333583335000000000ll;     for (int i = 1; i <= n + 1; i++)       if (ls[i] != ls[i - 1]) ls[++lcnt] = ls[i];     for (int i = 0; i <= n; i++) lsum[i] = find(sum[i]);     lmin[0] = sum[0];     for (int i = 1; i <= n; i++) lmin[i] = Min(lmin[i - 1], sum[i]);     rmax[n] = sum[n];     for (int i = n - 1; i >= 0; i--) rmax[i] = Max(rmax[i + 1], sum[i]);     s2.build(1, n - 1, 1);     s3.build();     s4.build();     s.build(1, n - 1, s.root);     if (m > n)       p = m - n, q = n;     else       p = 0, q = m;     work();   }   void doit() {     q--;     p++;     for (; q; q--, p++) {       subs tmp = subsq.h[1], Tmp = Next(tmp);       if (Tmp.w > -8333583335000000000ll)         subsq.h[1] = Next(tmp), subsq.pushdown(1);       else         subsq.pop();       s1.cover(tmp.l + 1, tmp.r, 1, n, 1);       ans1 += tmp.w;       upans2();       if (ans2 > -8333583335000000000ll) ans = Max(ans, ans1 + ans2);     }     ans1 += subsq.h[1].w;     s1.cover(subsq.h[1].l + 1, subsq.h[1].r, 1, n, 1);     if (s1.b[1]) ans = ans1;     printf( %I64d , ans);   }   int main() {     pre();     doit();   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200 * 1000 + 100;   int n, m, p;   int a[maxn];   int b[maxn];   map<int, int> numb;   map<int, int> numa;   vector<int> ans;   int sum = 0;   void add(int x) {     int val = numa[x] + 1;     numa[x] = val;     if (numb[x] >= val) sum++;   }   void remove(int x) {     int val = numa[x] - 1;     numa[x] = val;     if (numb[x] > val) sum--;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> p;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < m; ++i) {       cin >> b[i];       numb[b[i]]++;     }     for (int i = 0; i < p; ++i) {       numa.clear();       sum = 0;       for (int j = i; j < i + (long long)p * (long long)m && j < n; j += p)         add(a[j]);       for (int q = i; (long long)q + (long long)p * (long long)(m - 1) < n;            q += p) {         if (sum == m) ans.push_back(q);         if ((long long)q + (long long)p * (long long)m < n) {           add(a[q + p * m]);           remove(a[q]);         }       }     }     sort((ans).begin(), (ans).end());     cout << (int)(ans).size() << endl;     for (int i = 0; i < (int)(ans).size(); ++i) cout << ans[i] + 1 <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using dbl = double;   using ldb = long double;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using vi = vector<int>;   using mii = map<int, int>;   using msi = map<string, int>;   using umii = unordered_map<int, int>;   using umsi = unordered_map<string, int>;   using iii = tuple<int, int, int>;   using lll = tuple<ll, ll, ll>;   ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }   ll lcm(ll a, ll b) {     if (!a || !b) return a + b;     return a * (b / gcd(a, b));   }   const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     int tc;     cin >> tc;     while (tc--) {       int n;       string s;       cin >> n;       cin >> s;       int a = 0, b = 0;       for (int i = 0; i < n; i++) {         if (s[i] !=  < ) {           break;         }         a++;       }       for (int i = n - 1; i >= 0; i--) {         if (s[i] !=  > ) {           break;         }         b++;       }       cout << min(a, b) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x, y, a, b, n;   void init() {     scanf( %d , &n);     puts( YES );     for (int i = 1; i <= n; i++) {       scanf( %d%d%d%d , &x, &y, &a, &b);       printf( %d n , 2 * abs(x % 2) + abs(y % 2) + 1);     }   }   int main() {     init();     return 0;   }


#include  bits/stdc++.h       #define ll long long int   #define MOD 1000000007   using namespace std;         ll randNum(ll a , ll b){    return a + rand() % (b-a+1);   }      template<class t>   void print(t *a , int n){    for(int i =0 ; i<n ; i++) cout<<a[i]<<   ;    cout<<endl;   }      template<class t>   void print(vector<t> &v){    for(int i=0 ; i<v.size() ; i++) cout<<v[i]<<   ;    cout<<endl;   }         ll gcd(ll a, ll b)   {     if (b == 0)       return a;     return gcd(b, a % b);   }         ll lcm(ll a, ll b)   {       return (a / gcd(a, b)) * b;   }         ll gcdExtended(ll a, ll b, ll *x, ll *y)    {              if (a == 0)        {            *x = 0, *y = 1;            return b;        }             ll x1, y1;       ll gcd = gcdExtended(b%a, a, &x1, &y1);             *x = y1 - (b/a) * x1;        *y = x1;             return gcd;    }       ll modInverse(ll b, ll m)    {        ll x, y;       ll g = gcdExtended(b, m, &x, &y);             if (g != 1)            return -1;             return (x%m + m) % m;    }         ll modDivide(ll a, ll b, ll m)    {        a = a % m;        ll inv = modInverse(b, m);        if (inv == -1)           return -1;        else          return (inv * a) % m;    }       //precompute factorial array if multiple queries are present   unsigned long long nCrModPFermat(unsigned long long n, int r, int p){           if (n < (unsigned long long)r)           return 0;       if (r == 0)           return 1;           unsigned long long fac[n + 1];       fac[0] = 1;       for (unsigned long long i = 1; i <= n; i++)           fac[i] = (fac[i - 1] * i) % p;           return (fac[n] * modInverse(fac[r], p) % p               * modInverse(fac[n - r], p) % p)              % p;   }             //--------         void testcase(){    int n;    cin>>n;    vector<int> v(n);    for(int i=0 ; i<n ; i++) cin>>v[i];    vector<int> prevmax(n) , prevmaxindex(n);    prevmax[0] = v[0];    prevmaxindex[0] = 0;    for(int i=1 ; i<n ; i++) {     if(v[i] > prevmax[i-1]){      prevmax[i] = v[i];      prevmaxindex[i] = i;     }     else{      prevmax[i] = prevmax[i-1];      prevmaxindex[i] = prevmaxindex[i-1];     }     //prevmax[i] = max(v[i] , prevmax[i-1]);    }        int end = n-1;    vector<int> ansindex;    while(end >= 0){     int index = prevmaxindex[end];     ansindex.push_back(index);     end = index-1;    }        for(int i=0 ; i<ansindex.size() ; i++){     if(i == 0){      for(int j=ansindex[i] ; j<n ; j++) cout<<v[j]<<   ;     }     else{      for(int j = ansindex[i] ; j<ansindex[i-1] ; j++) cout<<v[j]<<   ;     }    }    cout<<endl;   }      int main(){    cin.sync_with_stdio(false);    cin.tie(NULL);    cout.tie(NULL);       int tt;       cin>>tt;       tt++;       while(--tt){           testcase();       }       return 0;          }


#include <bits/stdc++.h>   using namespace std;   const int MAXSIZE = 300010;   int rank1[MAXSIZE];   int parent[MAXSIZE];   int visited[MAXSIZE];   int diameter[MAXSIZE];   int N;   vector<int> V[MAXSIZE];   int maxL = 0, last = 0;   int FindSet(int x) {     if (x != parent[x]) parent[x] = FindSet(parent[x]);     return parent[x];   }   void Union(int root1, int root2) {     int x = FindSet(root1), y = FindSet(root2);     if (x == y) return;     if (rank1[x] > rank1[y])       parent[y] = x;     else {       parent[x] = y;       if (rank1[x] == rank1[y]) ++rank1[y];     }   }   void Union1(int root1, int root2) {     int x = FindSet(root1), y = FindSet(root2);     if (x == y) return;     if (rank1[x] > rank1[y])       parent[y] = x;     else {       parent[x] = y;       if (rank1[x] == rank1[y]) ++rank1[y];     }     diameter[FindSet(x)] =         max((double)max(diameter[x], diameter[y]),             ceil(diameter[x] / 2.0) + ceil(diameter[y] / 2.0) + 1);   }   void Init() {     memset(rank1, 0, sizeof(rank1));     for (int i = 0; i < MAXSIZE; ++i) parent[i] = i;   }   void dfs(int v, int path, int p) {     if (path > maxL) {       maxL = path;       last = v;     }     for (int i = 0; i < V[v].size(); i++) {       int to = V[v][i];       if (to != p) dfs(V[v][i], path + 1, v);     }   }   int nextInt() {     int x = 0, p = 1;     char c;     do {       c = getchar();     } while (c <= 32);     if (c ==  - ) {       p = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * p;   }   void solve() {     int m, q;     N = nextInt();     m = nextInt();     q = nextInt();     Init();     for (int i = 0; i < m; i++) {       int p, q;       p = nextInt();       q = nextInt();       p--, q--;       Union(p, q);       V[p].push_back(q);       V[q].push_back(p);     }     memset(diameter, -1, sizeof(diameter));     memset(visited, 0, sizeof(visited));     for (int i = 0; i < N; i++) {       int setIbelongs = FindSet(i);       if (!visited[setIbelongs]) {         visited[setIbelongs] = 1;         maxL = -1;         dfs(i, 0, -1);         maxL = -1;         dfs(last, 0, -1);         diameter[setIbelongs] = maxL;       }     }     int x, y, p;     while (q--) {       p = nextInt();       x = nextInt();       x--;       if (p == 1) {         printf( %d n , diameter[FindSet(x)]);       } else {         y = nextInt();         y--;         Union1(x, y);       }     }   }   int main() {     Init();     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int NN = 200005;   vector<int> vv[NN];   void _addedge(int x, int y) { vv[x].push_back(y); }   int dfn[NN], low[NN], stk[NN], blo[NN], block, Cnt, Now;   int ins[NN];   void tarjan(int n) {     int i, j;     low[n] = dfn[n] = ++Cnt, ins[stk[++Now] = n] = 1;     for (i = 0; i < vv[n].size(); i++)       if (dfn[j = vv[n][i]] == 0)         tarjan(j), low[n] = min(low[n], low[j]);       else if (ins[j])         low[n] = min(low[n], low[j]);     if (dfn[n] == low[n] && ++block) do         blo[i = stk[Now--]] = block, ins[i] = 0;       while (i != n);   }   int uu[NN];   vector<int> ans[NN];   bool vs[NN];   void check(int n) {     for (int i = 1; i <= n; i++) {       for (int j = 0; j < vv[i].size(); j++)         if (blo[i] != blo[vv[i][j]]) vs[blo[i]] = 1;     }     for (int i = 1; i <= n; i++) ans[blo[i]].push_back(i);     int best = n + 1;     int index = 0;     for (int i = 1; i <= block; i++)       if (!vs[i]) {         if (best > ans[i].size()) {           best = ans[i].size();           index = i;         }       }     printf( %d n , ans[index].size());     for (int i = 0; i < ans[index].size(); i++)       printf( %d%c , ans[index][i], i == ans[index].size() ?   n  :    );   }   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) scanf( %d , &uu[i]);     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d %d , &x, &y);       int v1 = uu[x], v2 = uu[y];       if (v1 < v2) {         if (v1 + 1 == v2) _addedge(x, y);         if (v1 == 0 && v2 == k - 1) _addedge(y, x);       }       if (v2 < v1) {         if (v2 + 1 == v1) _addedge(y, x);         if (v2 == 0 && v1 == k - 1) _addedge(x, y);       }     }     for (int i = 1; i <= n; i++)       if (dfn[i] == 0) tarjan(i);     check(n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1500 + 5, inf = 1e9 + 7;   int n, m;   pair<int, int> mark[M][M];   bool A[M][M];   inline int state(int i, int j) { return (i * M + j); }   void dfs(int i, int j, int i2, int j2) {     i = (i % n + n) % n, j = (j % m + m) % m;     if (!A[i][j]) return;     if (mark[i][j] == make_pair(i2, j2)) return;     if (mark[i][j].first < inf && mark[i][j] != make_pair(i2, j2)) {       cout <<  Yes n ;       exit(0);     }     mark[i][j] = make_pair(i2, j2);     int dx[] = {1, 0, -1, 0};     int dy[] = {0, 1, 0, -1};     for (int k = 0; k < 4; k++) dfs(i + dx[k], j + dy[k], i2 + dx[k], j2 + dy[k]);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     for (int i = 0; i < M; i++)       for (int j = 0; j < M; j++) mark[i][j] = make_pair(inf + 1, inf + 1);     int root;     cin >> n >> m;     string s;     for (int i = 0; i < n; i++) {       cin >> s;       for (int j = 0; j < m; j++)         if (s[j] !=  # ) {           A[i][j] = 1;           if (s[j] ==  S ) root = state(i, j);         }     }     dfs(root / M, root % M, root / M, root % M);     cout <<  No n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 211;   vector<pair<int, int> > con[maxn];   vector<pair<int, int> > edge;   bool vis[maxn];   int n, w, tmx, tv, ans;   void dfs(int x, int dis) {     vis[x] = 1;     if (dis > tmx) tmx = dis, tv = x;     for (int i = 0; i < con[x].size(); i++)       if (!vis[con[x][i].first] && w != con[x][i].second)         dfs(con[x][i].first, dis + 1);   }   int go(int x) {     memset(vis, 0, sizeof(vis));     tmx = tv = 0, dfs(x, 0);     memset(vis, 0, sizeof(vis));     tmx = 0, dfs(tv, 0);     return tmx;   }   int main() {     scanf( %d , &n);     int x, y;     for (int i = 1; i < n; i++) {       scanf( %d %d , &x, &y);       con[x].push_back(make_pair(y, i));       con[y].push_back(make_pair(x, i));       edge.push_back(make_pair(x, y));     }     for (w = 1; w < n; w++)       ans = max(ans, go(edge[w - 1].first) * go(edge[w - 1].second));     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k, sum = 0, i, j, ara[100000], mid, low, high;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &j);       sum += j;       ara[i] = sum;     }     scanf( %d , &m);     for (i = 0; i < m; i++) {       scanf( %d , &k);       low = 0;       high = n - 1;       for (j = 0;; j++) {         mid = (high + low) / 2;         if (ara[mid] == k) {           printf( %d n , mid + 1);           break;         } else if (ara[mid] > k)           high = mid;         else if (ara[mid] < k)           low = mid + 1;         if (high == low) {           printf( %d n , low + 1);           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long pow(long long b, long long e, long long m) {     long long t = 1;     for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0;     return t;   }   template <class T>   inline bool chkmin(T &a, T b) {     return a > b ? a = b, true : false;   }   template <class T>   inline bool chkmax(T &a, T b) {     return a < b ? a = b, true : false;   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <typename T>   T gcd(T x, T y) {     for (T t; x; t = x, x = y % x, y = t)       ;     return y;   }   template <class edge>   struct Graph {     vector<vector<edge> > adj;     Graph(int n) {       adj.clear();       adj.resize(n + 5);     }     Graph() { adj.clear(); }     void resize(int n) { adj.resize(n + 5); }     void add(int s, edge e) { adj[s].push_back(e); }     void del(int s, edge e) { adj[s].erase(find(iter(adj[s]), e)); }     vector<edge> &operator[](int t) { return adj[t]; }   };   string S, T;   map<pair<char, char>, int> f;   int main() {     ios_base::sync_with_stdio(false);     cin >> S >> T;     int n = (int)((S).size()), m = (int)((T).size()), L = 0, R = 0;     long long ans = 0;     for (int i = 0; i < n; ++i) {       for (; R < m - 1 && T[R] != S[i]; ++R) ++f[make_pair(T[R], T[R + 1])];       ans += R - L + 1;       if (i < n - 1 && S[i] != S[i + 1]) ans -= f[make_pair(S[i + 1], S[i])];       if (T[L] == S[i]) --f[make_pair(T[L], T[L + 1])], ++L;       if (R < m - 1) ++f[make_pair(T[R], T[R + 1])], ++R;       if (L == m) break;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = (int)1e5 + 15;   bool isAns = 1;   int n, m;   vector<vector<int>> gr;   vector<int> a, b;   void in() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     gr.resize(n + 5);     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       gr[a].push_back(b);       gr[b].push_back(a);     }   }   void solution() {     if (n == 1) {       isAns = 0;       return;     }     a.resize(n + 1);     int last = 2;     int ind = -1;     for (int i = 1; i <= n; ++i) {       if (gr[i].size() != n - 1) {         ind = i;         a[i] = 1;         int cur = n;         for (auto it : gr[i]) {           a[it] = cur--;         }         break;       }     }     if (ind == -1) {       isAns = 0;       return;     }     for (int i = 1; i <= n; ++i) {       if (a[i] == 0) {         a[i] = last++;       }     }     b = a;     pair<int, int> res = {0, 0};     int i = ind;     int L = 1, R = n;     for (auto it : gr[i]) {       if (a[i] < a[it])         R = min(R, a[it] - 1);       else         L = max(L, a[it] + 1);     }     for (int j = L; j <= R; ++j) {       if (j != a[i]) {         res = {i, j};         break;       }     }     if (res.first == 0) {       isAns = 0;     } else {       b[res.first] = res.second;     }   }   void out() {     if (!isAns) {       cout <<  NO n ;     } else {       cout <<  YES n ;       for (int i = 1; i <= n; ++i) {         cout << a[i] <<    ;       }       cout <<   n ;       for (int i = 1; i <= n; ++i) {         cout << b[i] <<    ;       }       cout <<   n ;     }   }   int main() {     in();     solution();     out();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   const long long mod = 1e9 + 7;   struct Matrix {     int n, m;     long long a[10][10];     Matrix() { memset(this->a, 0, sizeof(this->a)); }     Matrix(int n, int m) {       this->n = n;       this->m = m;       memset(this->a, 0, sizeof(this->a));     }   };   Matrix operator*(Matrix a, Matrix b) {     Matrix out = Matrix(a.n, b.m);     for (int i = 0; i < a.n; i++) {       for (int j = 0; j < b.m; j++) {         for (int p = 0; p < a.m; p++) {           out.a[i][j] = (out.a[i][j] + a.a[i][p] * b.a[p][j]) % mod;         }       }     }     return out;   }   Matrix fastPow(Matrix x, long long p) {     Matrix answer = Matrix(x.n, x.m), current = x;     for (int i = 0; i < x.n; i++) {       answer.a[i][i] = 1;     }     while (p != 0) {       if (p % 2 != 0) {         answer = answer * current;       }       p /= 2;       current = current * current;     }     return answer;   }   string fString[35];   void precalcStrings() {     fString[1] =  a ;     fString[2] =  b ;     for (int i = 3; i <= 30; i++) {       fString[i] = fString[i - 1] + fString[i - 2];     }   }   int match(string s, string pattern) {     vector<int> f;     f.assign(pattern.size() + 1, 0);     int len = 0;     f[0] = 0;     for (int i = 1; i < pattern.size(); i++) {       if (pattern[len] == pattern[i]) {         len++;         f[i] = len;       } else {         while (pattern[len] != pattern[i] && len != 0) len = f[len - 1];         if (pattern[len] == pattern[i]) {           len++;           f[i] = len;         } else {           f[i] = 0;         }       }     }     len = 0;     int answer = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] == pattern[len]) {         len++;         if (len == pattern.size()) {           answer++;           len = f[pattern.size() - 1];         }       } else {         while (s[i] != pattern[len] && len != 0) len = f[len - 1];         if (s[i] == pattern[len]) {           len++;         } else {           len = 0;         }       }     }     return answer;   }   string getPrefix(string s, int len) {     string out =   ;     for (int i = 0; i < len; i++) out += s[i];     return out;   }   string getSuffix(string s, int len) {     string out =   ;     for (int i = s.size() - len; i < s.size(); i++) out += s[i];     return out;   }   long long k;   string s;   int val[2];   string prefix;   string suffix[2];   long long dp[MAXN];   void solve() {     if (k < 30) {       cout << match(fString[k], s) <<   n ;       return;     }     int n = s.size();     int ind;     for (int i = 1; i < 30; i++) {       if (fString[i].size() > s.size()) {         ind = i;         break;       }     }     prefix = getPrefix(fString[ind], n - 1);     suffix[0] = getSuffix(fString[ind], n - 1);     suffix[1] = getSuffix(fString[ind + 1], n - 1);     val[0] = match(suffix[0] + prefix, s);     val[1] = match(suffix[1] + prefix, s);     Matrix A = Matrix(1, 4);     A.a[0][0] = match(fString[ind], s);     A.a[0][1] = match(fString[ind + 1], s);     A.a[0][2] = val[1];     A.a[0][3] = val[0];     Matrix B = Matrix(4, 4);     B.a[0][0] = 0;     B.a[0][1] = 1;     B.a[0][2] = 0;     B.a[0][3] = 0;     B.a[1][0] = 1;     B.a[1][1] = 1;     B.a[1][2] = 0;     B.a[1][3] = 0;     B.a[2][0] = 0;     B.a[2][1] = 1;     B.a[2][2] = 0;     B.a[2][3] = 1;     B.a[3][0] = 0;     B.a[3][1] = 0;     B.a[3][2] = 1;     B.a[3][3] = 0;     cout << (A * fastPow(B, k - ind - 1)).a[0][1] <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     precalcStrings();     int T;     cin >> k >> T;     while (T--) {       cin >> s;       solve();     }   }


#include <bits/stdc++.h>   bool isRight(int *c) {     int sides[3] = {0};     sides[0] = (c[4] - c[2]) * (c[4] - c[2]) + (c[5] - c[3]) * (c[5] - c[3]);     sides[1] = (c[4] - c[0]) * (c[4] - c[0]) + (c[5] - c[1]) * (c[5] - c[1]);     sides[2] = (c[2] - c[0]) * (c[2] - c[0]) + (c[3] - c[1]) * (c[3] - c[1]);     std::sort(sides, sides + 3);     if (sides[0] > 0 && sides[2] == sides[0] + sides[1]) {       return 1;     } else {       return 0;     }   }   int main() {     int points[6] = {0};     for (int k = 0; k < 6; k++) {       scanf( %d , points + k);     }     std::string output =  NEITHER ;     if (isRight(points)) {       output =  RIGHT ;     } else {       for (int k = 0; k < 6; k++) {         ++points[k];         if (isRight(points)) {           output =  ALMOST ;           break;         }         points[k] -= 2;         if (isRight(points)) {           output =  ALMOST ;           break;         }         ++points[k];       }     }     std::cout << output << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long n, m, k, q, bst, onemove, pmove;   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m >> k;     bst = 1e9;     for (int i = 1; i <= n; i++) {       cin >> q;       if (q < bst && i % 2 == 1) bst = q;     }     if (n % 2 == 0) {       cout << 0 << endl;       return 0;     } else {       onemove = n + 1;       onemove /= 2;       pmove = m / onemove;       if (pmove == 0)         bst = 0;       else if (bst / pmove >= k)         bst = pmove * k;       cout << bst << endl;     }     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); }   long long int read_int() {     char r;     bool start = false, neg = false;     long long int ret = 0;     while (true) {       r = getchar();       if ((r -  0  < 0 || r -  0  > 9) && r !=  -  && !start) {         continue;       }       if ((r -  0  < 0 || r -  0  > 9) && r !=  -  && start) {         break;       }       if (start) ret *= 10;       start = true;       if (r ==  - )         neg = true;       else         ret += r -  0 ;     }     if (!neg)       return ret;     else       return -ret;   }   int main() {     map<long long, long long> x;     map<long long, long long> y;     map<pair<long long, long long>, long long> z;     long long n, a, b, ans = 0;     n = read_int();     while (n--) {       a = read_int();       b = read_int();       ans += (x[a]++);       ans += (y[b]++);       ans -= z[make_pair(a, b)]++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int inf = 0x3f3f3f3f;   const long long Inf = 0x3f3f3f3f3f3f3f3f;   const int maxn = 1e3 + 4;   const int maxm = 1e5 + 4;   vector<int> v;   int n, k, b[maxn];   int main() {     ios::sync_with_stdio(false);     int i, j, kase;     cin >> n >> k;     for (i = 1; i <= n; ++i) cin >> b[i];     v.push_back(n);     auto it = v.begin();     for (i = n - 1; i >= 1; --i) {       it = v.begin();       int num = 0;       while (num < b[i]) {         if (*it >= i + k) num++;         it++;       }       v.insert(it, i);     }     for (i = 0; i < v.size(); ++i) {       if (i) cout <<    ;       cout << v[i];     }     cout << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   vector<tuple<long long int, long long int, long long int> > v;   vector<long long int> v1, v3;   vector<pair<char, long long int> > v2;   long long int i, j, k, n, sum = 0, p, r, ct = 0, q, sum1 = 0, sum2, t;   set<long long int> s, s1;   priority_queue<long long int> g;   const int maxn = 1e3 + 100, inf = 1e9 + 100;   long long int dp[maxn][3];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> t;     while (t--) {       q = 0;       cin >> n;       long long int a[n];       map<long long int, long long int> m, m1;       for (i = 1; i < n + 1; i++) {         cin >> a[i];         m[a[i]] = i;       }       p = m[1];       for (i = 1; i < n + 1; i++) {         if (m[i] != p) {           q = 1;           break;         } else {           a[m[i]] = -1;         }         if (m[i] == n && i < n)           p = m[i + 1];         else if (m[i] < n && a[m[i] + 1] != -1)           p++;         else if (m[i] < n && a[m[i] + 1] == -1)           p = m[i + 1];       }       if (q != 1)         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;     point(int a = 0, int b = 0) {       x = a;       y = b;     }   };   struct cmpx {     bool operator()(point a, point b) {       if (a.x == b.x) return a.y < b.y;       return a.x < b.x;     }   };   struct cmpy {     bool operator()(point a, point b) {       if (a.y == b.y) return a.x < b.x;       return a.y < b.y;     }   };   bool ltx(point a, point b) {     if (a.x == b.x) return a.y < b.y;     return a.x < b.x;   }   int conq(set<point, cmpx>& sx, set<point, cmpy>& sy) {     if (sx.size() == 1) return 1;     set<point, cmpx> sx1;     set<point, cmpy> sy1;     set<point, cmpx>::iterator itx1;     set<point, cmpx>::reverse_iterator itx2;     set<point, cmpy>::iterator ity1;     set<point, cmpy>::reverse_iterator ity2;     itx1 = sx.begin();     itx2 = sx.rbegin();     ity1 = sy.begin();     ity2 = sy.rbegin();     int t;     do {       t = itx1->x;       itx1++;       if (itx1->x - t > 1) {         while (sx.begin()->x <= t) {           sx1.insert(*sx.begin());           sy1.insert(*sx.begin());           sy.erase(*sx.begin());           sx.erase(*sx.begin());         }         return conq(sx, sy) + conq(sx1, sy1);       }       t = itx2->x;       itx2++;       if (t - itx2->x > 1) {         while (sx.rbegin()->x >= t) {           sx1.insert(*sx.rbegin());           sy1.insert(*sx.rbegin());           sy.erase(*sx.rbegin());           sx.erase(*sx.rbegin());         }         return conq(sx, sy) + conq(sx1, sy1);       }       t = ity1->y;       ity1++;       if (ity1->y - t > 1) {         while (sy.begin()->y <= t) {           sx1.insert(*sy.begin());           sy1.insert(*sy.begin());           sx.erase(*sy.begin());           sy.erase(*sy.begin());         }         return conq(sx, sy) + conq(sx1, sy1);       }       t = ity2->y;       ity2++;       if (t - ity2->y > 1) {         while (sy.rbegin()->y >= t) {           sx1.insert(*sy.rbegin());           sy1.insert(*sy.rbegin());           sx.erase(*sy.rbegin());           sy.erase(*sy.rbegin());         }         return conq(sx, sy) + conq(sx1, sy1);       }     } while (ltx(*itx1, *itx2));     return 1;   }   int main() {     int n, i, x, y;     set<point, cmpx> sx;     set<point, cmpy> sy;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d%d , &x, &y);       sx.insert(point(x, y));       sy.insert(point(x, y));     }     printf( %d , conq(sx, sy));   }


#include <bits/stdc++.h>   const int MAXN = 200010;   const int mod = 1000000007;   void reduce(int& x) { x += x >> 31 & mod; }   int mul(int a, int b) { return (long long)a * b % mod; }   int remod(long long x) {     x %= mod;     return x + (x >> 63 & mod);   }   int n;   int A[MAXN], W[MAXN];   long long rt[MAXN];   void mdfc(int x, int v) {     for (; x <= n; x += x & -x) rt[x] += v;   }   long long qry(int x) {     long long res = 0;     for (; x; x &= x - 1) res += rt[x];     return res;   }   long long qry(int l, int r) { return qry(r) - qry(l - 1); }   int tr[MAXN];   void mdfv(int x, int v) {     for (v -= mod; x <= n; x += x & -x) reduce(tr[x] += v);   }   int qryv(int x) {     int res = 0;     for (; x; x &= x - 1) reduce(res += tr[x] - mod);     return res;   }   int qryv(int l, int r) {     int x = qryv(r) - qryv(l - 1);     return x + (x >> 31 & mod);   }   void add(int x, int v) { mdfc(x, v), mdfv(x, remod(mul(A[x], v))); }   int main() {     std::ios_base::sync_with_stdio(false), std::cin.tie(0);     int T;     std::cin >> n >> T;     for (int i = 1; i <= n; ++i) std::cin >> A[i], A[i] -= i;     for (int i = 1; i <= n; ++i) std::cin >> W[i], add(i, W[i]);     while (T-- > 0) {       int x, y;       std::cin >> x >> y;       if (x < 0)         x = -x, add(x, y - W[x]), W[x] = y;       else {         int l = x, r = y, at = -1;         long long sm = qry(l, r);         while (l <= r) {           int mid = l + r >> 1;           if (qry(x, mid) * 2 >= sm)             at = mid, r = mid - 1;           else             l = mid + 1;         }         l = x, r = y;         int X = A[at];         long long ans = qry(l, at) % mod * X - qryv(l, at);         ans += qryv(at + 1, r) - qry(at + 1, r) % mod * X;         std::cout << remod(ans) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     long n;     scanf( %ld n , &n);     std::vector<long> blocks(n + 2);     for (long p = 1; p <= n; p++) {       scanf( %ld , &blocks[p]);     }     for (long p = 1; p <= n; p++) {       blocks[p] = std::min(blocks[p], 1 + blocks[p - 1]);     }     for (long p = n; p >= 0; p--) {       blocks[p] = std::min(blocks[p], 1 + blocks[p + 1]);     }     long final(0);     for (long p = 1; p <= n; p++) {       final = std::max(final, blocks[p]);     }     printf( %ld n , final);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2000010;   int a[N], pos[N], cnt[N];   long long ans[N], res;   struct node {     int l, r, idx;     bool operator<(const node& x) const {       if (pos[l] == pos[x.l]) return r < x.r;       return l < x.l;     }   } q[N];   int L, R, n, m, k;   void update(int x, int add) {     if (add > 0) {       res += cnt[a[x] ^ k];       cnt[a[x]]++;     } else {       cnt[a[x]]--;       res -= cnt[a[x] ^ k];     }   }   int main() {     scanf( %d%d%d , &n, &m, &k);     int sz = sqrt(n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       a[i] ^= a[i - 1];       pos[i] = i / sz;     }     for (int i = 1; i <= m; ++i) {       scanf( %d%d , &q[i].l, &q[i].r);       q[i].idx = i;     }     sort(q + 1, q + m + 1);     cnt[0] = 1;     L = 1, R = 0, res = 0;     for (int i = 1; i <= m; ++i) {       while (q[i].l < L) update(--L - 1, 1);       while (q[i].l > L) update(L++ - 1, -1);       while (q[i].r < R) update(R--, -1);       while (q[i].r > R) update(++R, 1);       ans[q[i].idx] = res;     }     for (int i = 1; i <= m; ++i) printf( %I64d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long p, k;   long long r[20005];   int i, j;   int main() {     scanf( %I64d%I64d , &p, &k);     while (p) {       r[i] = p % (-k);       p = p / (-k);       while (r[i] < 0) {         r[i] = r[i] + k;         p++;       }       i++;     }     if (i == 0) i++;     for (j = 0; j < i; j++)       if (r[j] >= k) {         printf( -1 n );         return 0;       }     printf( %d n , i);     for (j = 0; j < i; j++) printf(j == i - 1 ?  %I64d n  :  %I64d  , r[j]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200 + 5;   string s;   int dist[maxn * maxn];   bool a[maxn][maxn], chek[maxn * maxn];   vector<int> v[maxn * maxn];   void bfs(int x) {     chek[x] = true;     queue<int> q;     q.push(x);     while (!q.empty()) {       x = q.front();       q.pop();       for (int i = 0; i < (int)v[x].size(); i++)         if (chek[v[x][i]] == false) {           q.push(v[x][i]);           chek[v[x][i]] = true;           dist[v[x][i]] = dist[x] + 1;         }     }   }   int main() {     int x = 102, y = 102, ii, jj, e[4][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};     cin >> s;     ii = x;     jj = y;     a[ii][jj] = true;     for (int i = 0; i < (int)s.size(); i++) {       if (s[i] ==  U )         ii--;       else if (s[i] ==  D )         ii++;       else if (s[i] ==  R )         jj++;       else if (s[i] ==  L )         jj--;       a[ii][jj] = true;     }     for (int i = 0; i < maxn; i++)       for (int j = 0; j < maxn; j++)         for (int d = 0; d < 4; d++) {           if (a[i][j] == false) {             chek[i * maxn + j] = true;             continue;           }           if (i + e[d][0] >= 0 && i + e[d][0] < maxn && j + e[d][1] < maxn &&               j + e[d][1] >= 0)             if (a[i + e[d][0]][j + e[d][1]] == true)               v[i * maxn + j].push_back((i + e[d][0]) * maxn + j + e[d][1]);         }     bfs(x * maxn + y);     if (dist[ii * maxn + jj] < (int)s.size()) {       cout <<  BUG  << endl;       return 0;     }     cout <<  OK  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long const N = 2e5 + 70;   long long n, k, a[N], cnt[N], ans, fi = -1, la = -1;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (long long i = 0; i <= n; i++) {       cin >> a[i];       cnt[i] = a[i];     }     for (long long i = 0; i < n + 50; i++) {       if (cnt[i] < 0) {         cnt[i + 1] += cnt[i];         cnt[i] = -cnt[i];       }       cnt[i + 1] += cnt[i] / 2;       cnt[i] &= 1;       if (cnt[i]) {         if (fi == -1) fi = i;         la = i;       }     }     if (cnt[n + 50]) {       fi = la = -1;       memset(cnt, 0, sizeof cnt);       for (long long i = 0; i <= n; i++) a[i] = -a[i], cnt[i] = a[i];       for (long long i = 0; i < n + 50; i++) {         if (cnt[i] < 0) {           cnt[i + 1] += cnt[i];           cnt[i] = -cnt[i];         }         cnt[i + 1] += cnt[i] / 2;         cnt[i] &= 1;         if (cnt[i]) {           if (fi == -1) fi = i;           la = i;         }       }     }     if (la - fi >= 35) return cout <<  0 n , 0;     long long res = 0;     for (long long i = fi; i <= la; i++) res += (1 << (i - fi)) * cnt[i];     long long cur = res;     for (long long i = fi; i >= 0 && cur <= 2e9; i--) {       if (i <= n && a[i] - cur >= -k && (i != n || a[i] - cur != 0)) ans++;       cur *= 2;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[310];   long long fac[310], rev[310];   bool mmp[310][310];   long long mod = (long long)1e9 + 7;   long long qmod(long long a, long long p) {     long long ret = 1;     while (p) {       if (p & 1) ret = (ret * a) % mod;       a = (a * a) % mod;       p /= 2;     }     return ret;   }   void Init() {     fac[0] = 1;     for (int i = 1; i < 310; ++i) fac[i] = fac[i - 1] * i;     rev[0] = 1;     for (int i = 1; i < 310; ++i) rev[i] = qmod(fac[i], mod - 2);   }   long long C(int n, int m) { return fac[n] * rev[m] % mod * rev[n - m] % mod; }   bool isSqure(long long q) {     long long sq = (long long)sqrt(q);     return sq * sq == q;   }   void input() {     istream& in = cin;     in >> n;     for (int i = 1; i <= n; ++i) in >> a[i];   }   bool vis[310];   int dfs(int p) {     if (vis[p]) return 0;     vis[p] = 1;     int ret = 1;     for (int i = 1; i <= n; ++i) {       if (mmp[p][i]) {         ret += dfs(i);       }     }     return ret;   }   int num[310];   long long dp[310][310][310];   bool END[310];   void add(long long& a, long long b) {     a %= mod;     b %= mod;     a = (a + b) % mod;   }   int main() {     input();     Init();     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j) {         if (isSqure(a[i] * a[j])) {           mmp[i][j] = mmp[j][i] = 1;         }       }     vector<int> block;     for (int i = 1; i <= n; ++i) {       int ret = dfs(i);       if (ret) block.push_back(ret);     }     sort(block.begin(), block.end());     reverse(block.begin(), block.end());     int sum = 0;     for (int p : block) {       for (int i = 1; i <= p; ++i) num[sum + i] = i;       sum += p;       END[sum] = 1;     }     dp[0][0][0] = 1;     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= n + 1; ++j)         for (int k = 0; k <= n + 1; ++k) {           long long& ref = dp[i - 1][j][k];           if (dp[i - 1][j][k] == 0) continue;           int allslot = i;           int prewa = j - k;           int nowwa = k;           int nookwaslot = (num[i] - 1) * 2 - 2 * nowwa;           int okslot = allslot - j - nookwaslot;           if (!END[i]) {             if (j > 0) add(dp[i][j - 1][k], dp[i - 1][j][k] * prewa);             add(dp[i][j + 1][k + 1], dp[i - 1][j][k] * nowwa);             add(dp[i][j][k], dp[i - 1][j][k] * okslot);             add(dp[i][j + 1][k + 1], dp[i - 1][j][k] * nookwaslot);           } else {             if (j > 0) add(dp[i][j - 1][0], dp[i - 1][j][k] * prewa);             add(dp[i][j + 1][0], dp[i - 1][j][k] * nowwa);             add(dp[i][j][0], dp[i - 1][j][k] * okslot);             add(dp[i][j + 1][0], dp[i - 1][j][k] * nookwaslot);           }         }     cout << dp[n][0][0] << endl;     return 0;   }


#include <bits/stdc++.h>   const int MOD = 998244353;   int add(int x, int y) {     int res = x + y;     return res < MOD ? res : res - MOD;   }   int mul(int x, int y) { return (long long)x * y % MOD; }   int pow(int base, int p) {     int res = 1;     while (p > 0) {       if (p & 1) res = mul(res, base);       base = mul(base, base);       p /= 2;     }     return res;   }   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     std::vector<int> dp(std::min(k, n) + 1, 0);     dp[1] = n;     for (int i = 2; i <= k; ++i)       for (int j = std::min(i, n); j >= 1; --j)         dp[j] = add(mul(dp[j - 1], n - j + 1), mul(dp[j], j));     int res = 0;     for (int i = 1; i < dp.size(); ++i)       res = add(res, mul(dp[i], pow(pow(m, MOD - 2), i)));     printf( %d n , res);   }


#include <bits/stdc++.h>   using namespace std;   int id(string s) {     if (s ==  C )       return 1;     else if (s ==  C# )       return 2;     else if (s ==  D )       return 3;     else if (s ==  D# )       return 4;     else if (s ==  E )       return 5;     else if (s ==  F )       return 6;     else if (s ==  F# )       return 7;     else if (s ==  G )       return 8;     else if (s ==  G# )       return 9;     else if (s ==  A )       return 10;     else if (s ==  B )       return 11;     else if (s ==  H )       return 12;   }   int Distance(string s, string t) {     int a = id(s);     int b = id(t);     if (b < a) b += 12;     return b - a;   }   int main() {     string x, y, z;     int i, j, k;     vector<string> v;     cin >> x >> y >> z;     v.push_back(x);     v.push_back(y);     v.push_back(z);     for (i = 0; i < 3; i++) {       for (j = 0; j < 3; j++) {         for (k = 0; k < 3; k++) {           if (Distance(v[i], v[j]) == 4 and Distance(v[j], v[k]) == 3) {             cout <<  major ;             return 0;           } else if (Distance(v[i], v[j]) == 3 and Distance(v[j], v[k]) == 4) {             cout <<  minor ;             return 0;           }         }       }     }     cout <<  strange ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     string n;     cin >> n;     vector<string> vec;     int si = n.size();     for (int i = 0; i < si; i++) {       if (n[i] ==  0 ) continue;       string s =   ;       s += n[i];       for (int j = i + 1; j < si; j++) {         s +=  0 ;       }       vec.push_back(s);     }     cout << vec.size() <<   n ;     for (int i = 0; i < int(vec.size()); i++) {       cout << vec[i] <<    ;     }   }   int main() {     int t;     cin >> t;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static int aQWEs = []() -> int {     ios::sync_with_stdio(false);     cin.tie(NULL);     return 0;   }();   long long int power(long long int a, long long int p,                       long long int m = 1000000007) {     a %= m;     long long int val = 1;     while (p > 0) {       if (p & 1) {         val = (val * a) % m;       }       a = (a * a) % m;       p >>= 1;     }     return (val);   }   int dfs(const vector<int>& v, std::vector<bool>& vis, int cur, int depth) {     vis[cur] = 1;     if (!vis[v[cur]]) return dfs(v, vis, v[cur], depth + 1);     return depth;   }   int main() {     long long int i, j;     int T = 1;     while (T--) {       int n;       cin >> n;       std::vector<int> v(n + 1);       std::vector<bool> vis(n + 1);       int ans = 0;       for (i = 1; i <= n; ++i) {         cin >> v[i];       }       for (i = 1; i <= n; ++i) {         if (!vis[i]) ans += dfs(v, vis, i, 0);       }       if (!((3 * n - ans) & 1)) {         cout <<  Petr n ;       } else         cout <<  Um_nik n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int M = 3e5 + 10;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   int n, q;   int cnt[M];   string ss;   void solve() {     cin >> n >> q;     cin >> ss;     for (int i = 1; i <= n; i++) {       if (i % 2)         cnt[i] = ss[i - 1] ==  +  ? 1 : -1;       else         cnt[i] = ss[i - 1] ==  -  ? 1 : -1;       cnt[i] += cnt[i - 1];     }     int l, r;     while (q--) {       cin >> l >> r;       int ans = cnt[r] - cnt[l - 1];       if (ans == 0)         cout << 0 << endl;       else if ((r - l + 1) % 2)         cout << 1 << endl;       else         cout << 2 << endl;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     ;     int T;     cin >> T;     while (T--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int findLengthOfLNDS(vector<pair<int, float> > &plants_data) {     if (plants_data.size() == 0) return 0;     vector<int> m;     m.push_back(0);     for (int i = 1; i < plants_data.size(); i++) {       if (plants_data[m.back()].first <= plants_data[i].first) {         m.push_back(i);       } else {         int b = 0, e = m.size() - 1, mid = 0, replace_at = 0;         while (b <= e) {           mid = (b + e) / 2;           if (plants_data[i].first >= plants_data[m[mid]].first) {             b = mid + 1;           } else {             e = mid - 1;           }         }         if (plants_data[m[mid]].first <= plants_data[i].first) {           replace_at = mid + 1;         } else {           replace_at = mid;         }         m[replace_at] = i;       }     }     return m.size();   }   int main() {     int no_plants, no_species;     vector<pair<int, float> > plants_data;     cin >> no_plants >> no_species;     for (int i = 0; i < no_plants; i++) {       int speci;       float location;       cin >> speci >> location;       plants_data.push_back(make_pair(speci, location));     }     cout << no_plants - findLengthOfLNDS(plants_data);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n0, n1, n2;       cin >> n0 >> n1 >> n2;       if (n1 == 0 && n2 == 0) {         cout << string(n0 + 1,  0 ) << endl;         continue;       }       string result = string(n2 + 1,  1 );       char turn =  0 ;       while (n1--) {         result += turn;         if (turn ==  0 ) {           turn =  1 ;         } else {           turn =  0 ;         }       }       if (result[result.size() - 1] ==  0 ) {         result += string(n0,  0 );       } else {         result = result.substr(0, result.size() - 1);         result = result + string(n0,  0 ) +  1 ;       }       cout << result << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   string s;   bool flag;   void solve() {     int n, k;     cin >> n >> k;     unordered_set<int> s;     queue<int> q;     vector<int> a(n);     for (auto i = 0; i < n; i++) cin >> a[i];     ;     for (auto i = 0; i < n; i++) {       if (s.find(a[i]) == s.end()) {         if (s.size() >= k) {           int kk = q.front();           s.erase(kk);           q.pop();         }         s.insert(a[i]);         q.push(a[i]);       }     }     stack<int> st;     while (!q.empty()) {       int aa = q.front();       st.push(aa);       q.pop();     }     cout << st.size() << endl;     while (!st.empty()) {       int aa = st.top();       st.pop();       cout << aa <<    ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int modn = (int)1e9 + 7, N = (int)1e5 + 10;   int a[N], p[N][6], q[N], c[6][6][6], n, m;   inline void add(int &x, int y) {     x += y;     if (x >= modn) x %= modn;   }   struct zz {     int power, x, s, t, tot;     int v[N << 2], ls[N << 2], rs[N << 2], b[N << 2];     void build(int l, int r, int now) {       b[now] = -1;       if (l == r) {         v[now] = (long long)a[l] * p[l][power] % modn;         return;       }       int mid = (l + r) >> 1;       ls[now] = ++tot;       rs[now] = ++tot;       build(l, mid, ls[now]);       build(mid + 1, r, rs[now]);       add(v[now], v[ls[now]]);       add(v[now], v[rs[now]]);     }     void push(int l, int r, int now) {       if (b[now] != -1 && l != r) {         int mid = (l + r) >> 1;         v[ls[now]] =             (long long)b[now] * (p[mid][power] - p[l - 1][power] + modn) % modn;         v[rs[now]] =             (long long)b[now] * (p[r][power] - p[mid][power] + modn) % modn;         b[rs[now]] = b[ls[now]] = b[now];         b[now] = -1;       }     }     void make(int l, int r, int now) {       if (l >= s && r <= t) {         b[now] = x;         v[now] = (long long)x * (p[r][power] - p[l - 1][power] + modn) % modn;         return;       }       push(l, r, now);       int mid = (l + r) >> 1;       if (mid >= s) make(l, mid, ls[now]);       if (mid < t) make(mid + 1, r, rs[now]);       v[now] = 0;       add(v[now], v[ls[now]]);       add(v[now], v[rs[now]]);     }     int ask(int l, int r, int now) {       if (l >= s && r <= t) return v[now];       push(l, r, now);       int mid = (l + r) >> 1, ret = 0;       if (mid >= s) add(ret, ask(l, mid, ls[now]));       if (mid < t) add(ret, ask(mid + 1, r, rs[now]));       v[now] = 0;       add(v[now], v[ls[now]]);       add(v[now], v[rs[now]]);       return ret;     }   } T[6];   inline void read(int &ret) {     ret = 0;     char x = getchar();     while (x <  0  || x >  9 ) x = getchar();     while (x >=  0  && x <=  9 ) {       ret = ret * 10 + x -  0 ;       x = getchar();     }   }   inline int spj() {     static int l, r, k, ch[6], pp[6];     int ret = 0;     read(l);     read(r);     read(k);     pp[0] = 1;     for (int i = 0; i <= k; ++i) {       if (i != 0) pp[i] = (long long)pp[i - 1] * (modn - l) % modn;       T[i].s = l;       T[i].t = r;       ch[i] = T[i].ask(1, n, 0);     }     for (int i = 0; i <= k; ++i)       for (int j = 0; i + j <= k; ++j)         add(ret, (long long)ch[i] * c[i][j][k - i - j] % modn * pp[j] % modn);     return ret;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) read(a[i]);     for (int i = 1; i <= n; ++i) {       p[i][0] = 1;       for (int j = 1; j < 6; ++j) p[i][j] = (long long)p[i][j - 1] * i % modn;     }     for (int i = 0; i < 6; ++i) T[i].power = i;     for (int i = 0; i < 6; ++i) T[i].build(1, n, 0);     for (int i = 1; i <= n; ++i)       for (int j = 0; j < 6; ++j) add(p[i][j], p[i - 1][j]);     q[0] = 1;     for (int i = 1; i < 6; ++i) q[i] = q[i - 1] * i;     for (int i = 0; i < 6; ++i)       for (int j = 0; j < 6; ++j)         for (int k = 0; k < 6; ++k)           if (i + j + k < 6) c[i][j][k] = q[i + j + k] / q[i] / q[j] / q[k];     for (int i = 1; i <= m; ++i) {       int l, r, x;       char cc = getchar();       while (cc !=  ?  && cc !=  = ) cc = getchar();       if (cc ==  = ) {         read(l);         read(r);         read(x);         for (int i = 0; i < 6; ++i) {           T[i].s = l;           T[i].t = r;           T[i].x = x;           T[i].make(1, n, 0);         }       } else         printf( %d n , spj());     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = int(1e5) + 10;   const int K = 11;   const int MOD = int(1e9) + 7;   const int INF = int(2e9) + 5;   const long long INF64 = 1e18;   int dp[N];   void solve() {     string s;     cin >> s;     stack<int> st;     int n = s.length();     for (int i = 0; i < n; i++) {       if (s[i] ==  (  || s[i] ==  [  || s[i] ==  { ) {         st.push(i);       } else {         if (st.empty()) continue;         int t = st.top();         if (s[i] ==  )  && s[t] ==  ( ) {           dp[i] = i - t + 1;           if (t > 0) dp[i] += dp[t - 1];           st.pop();         } else if (s[i] ==  ]  && s[t] ==  [ ) {           dp[i] = i - t + 1;           if (t > 0) dp[i] += dp[t - 1];           st.pop();         } else if (s[i] ==  }  && s[t] ==  { ) {           dp[i] = i - t + 1;           if (t > 0) dp[i] += dp[t - 1];           st.pop();         } else {           while (!st.empty()) st.pop();         }       }     }     int i = n - 1;     int mx = 0, index = -1;     while (i >= 0) {       if (dp[i] == 0) {         i--;         continue;       }       int cnt = 0, t = i;       int x = dp[i];       for (int j = 0; j < x; j++) {         if (s[i] ==  [ ) cnt++;         i--;       }       if (cnt > mx) {         mx = cnt;         index = t;       }     }     if (mx == 0) {       cout << 0 <<   n ;       return;     }     cout << mx <<   n ;     cout << s.substr(index + 1 - dp[index], dp[index]);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200005];   int main() {     int n;     int i;     while (scanf( %d , &n) != EOF) {       for (i = 0; i < n; i++) {         scanf( %d , &a[i]);       }       sort(a, a + n);       int p = (n - 2) / 2;       int ans = 1e9;       for (i = 0; i < n - p - 1; i++) {         int dis = a[i + p + 1] - a[i];         if (ans > dis) ans = dis;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e3 + 10;   const int B = 1e3 + 10;   bool vis[N], inque[2 * N];   int n, k;   vector<int> v;   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < k; i++) {       int t;       scanf( %d , &t);       if (!vis[t]) {         vis[t] = true;         v.push_back(t);       }     }     for (int i = 0; i < v.size(); i++) {       v[i] -= n;     }     queue<pair<int, int>> Q;     Q.push(make_pair(0, 0));     inque[B] = true;     while (!Q.empty()) {       pair<int, int> t = Q.front();       Q.pop();       inque[t.first + B] = 0;       for (int i = 0; i < v.size(); i++) {         int u = v[i] + t.first;         if (u < -1000 || u > 1000) continue;         if (!inque[u + B]) {           if (u == 0) {             printf( %d n , t.second + 1);             return 0;           }           inque[u + B] = true;           Q.push(make_pair(u, t.second + 1));         }       }     }     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100005];   long long req = 1e18;   long long steps(long long n) {     long long c = 1;     if (n == 1) return 1e6;     while (req > 1) {       req /= n;       c++;     }     req = 1e18;     return c;   }   long long pow_exp(long long a, long long n) {     long long res = 1;     while (n) {       if (n % 2) res = (res * a);       a = (a * a);       n /= 2ll;     }     return res;   }   int main() {     long long t = 1;     while (t--) {       long long n;       cin >> n;       long long ans = 0;       for (long long i = 0; i < n; i++) cin >> a[i], ans += (a[i] - 1ll);       sort(a, a + n);       if (n == 1) {         cout << a[0] - 1ll << endl;         continue;       }       long long st = 2;       while (steps(st) >= n - 1) {         long long sol = 0;         for (long long i = 0; i < n; i++) {           long long u = pow_exp(st, i);           sol += abs(u - a[i]);         }         ans = min(ans, sol);         if (pow_exp(st, n - 1) > a[n - 1]) break;         st++;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct matrix {     long long a[100][100];     void init() { memset(a, 0, sizeof(a)); }     friend matrix operator*(matrix x, matrix y) {       matrix ans;       ans.init();       for (int i = 0; i < 100; i++)         for (int j = 0; j < 100; j++) {           for (int k = 0; k < 100; k++)             ans.a[i][j] += (x.a[i][k] * y.a[k][j]) % 1000000007;           ans.a[i][j] %= 1000000007;         }       return ans;     }     friend matrix operator^(matrix x, long long y) {       matrix ans;       if (y == 0) {         memset(ans.a, 0, sizeof(ans.a));         for (int i = 0; i < 100; i++) ans.a[i][i] = 1;         return ans;       } else         while ((y & 1) == 0) y >>= 1, x = x * x;       ans = x;       y >>= 1;       for (; y != 0; y >>= 1) {         x = x * x;         if ((y & 1) != 0) ans = ans * x;       }       return ans;     }   } x;   int n, m, Mod, a[1000010];   int main() {     x.init();     matrix h, t;     h.init();     t.init();     scanf( %d%d%d , &n, &m, &Mod);     for (int i = 1; i <= n; i++) {       int v;       scanf( %d , &v);       h.a[0][v % Mod]++;     }     for (int i = 1; i <= n; i++) {       int v;       scanf( %d , &v);       a[i] = v;       for (int j = 0; j < Mod; j++) x.a[j][(j + v) % Mod]++;     }     matrix ans = h * (x ^ (m - 2));     for (int i = 1; i <= n; i++) {       int v;       scanf( %d , &v);       int d = (Mod - (v + a[i]) % Mod) % Mod;       t.a[d][0]++;     }     ans = ans * t;     printf( %I64d n , ans.a[0][0]);   }