#include <bits/stdc++.h>   using namespace std;   const int N = 105;   int Q[N], S[N], ok[N + N], Sav[N], mat[N + N][N];   int dp[N + N][N];   int solve(int p, int k) {     if (ok[p]) return k == 0;     if (!k) return 0;     if (dp[p][k] != -1) return dp[p][k];     return dp[p][k] = solve(p - 1, k - 1) | solve(p + 1, k - 1);   }   int main() {     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> Q[i], Sav[Q[i]] = i, mat[100][i] = i;     for (int i = 1; i <= n; i++) cin >> S[i];     for (int i = 99; i >= 0; i--)       for (int j = 1; j <= n; j++) mat[i][j] = mat[i + 1][Sav[j]];     for (int i = 101; i <= 200; i++)       for (int j = 1; j <= n; j++) mat[i][j] = mat[i - 1][Q[j]];     for (int i = 0; i <= 200; i++) {       ok[i] = 1;       for (int j = 1; j <= n; j++) ok[i] &= mat[i][j] == S[j];     }     memset(dp, -1, sizeof(dp));     puts(solve(100, k) ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, a, n, sum = 0, hand = 0;     vector<long long int> v;     cin >> n;     v.clear();     for (i = 0; i < n; i++) {       cin >> a;       if (a % 2 != 0) hand++;       v.push_back(a);       sum += a;     }     long long int value = 1e13;     if (hand % 2 != 0) {       for (i = 0; i < v.size(); i++) {         if (v[i] & 1) value = min(v[i], value);       }       sum -= value;     }     cout << sum << endl;     v.clear();   }


#include <bits/stdc++.h>   using namespace std;   int a[10];   int main() {     cin >> a[1] >> a[2] >> a[3];     sort(a + 1, a + 1 + 3);     cout << max(a[3] - a[1] - a[2] + 1, 0) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     double x, y;     Point() : x(0), y(0) {}     Point(double _x, double _y) : x(_x), y(_y) {}     bool operator<(const Point &b) const { return tie(x, y) < tie(b.x, b.y); }     bool operator==(const Point &b) const { return tie(x, y) == tie(b.x, b.y); }     Point operator+(const Point &b) const { return Point(x + b.x, y + b.y); }     Point operator-(const Point &b) const { return Point(x - b.x, y - b.y); }     double operator*(const Point &b) const { return x * b.x + y * b.y; }     double operator%(const Point &b) const { return x * b.y - y * b.x; }     Point operator*(const double &b) const { return Point(x * b, y * b); }     double abs() { return sqrt(abs2()); }     double abs2() { return x * x + y * y; }   };   long long cross(Point o, Point a, Point b) { return (a - o) % (b - o); }   vector<Point> convex_hull(vector<Point> &pt) {     sort(pt.begin(), pt.end());     int top = 0;     vector<Point> stk(2 * pt.size());     for (int i = 0; i < (int)pt.size(); i++) {       while (top >= 2 && cross(stk[top - 2], stk[top - 1], pt[i]) <= 0) top--;       stk[top++] = pt[i];     }     for (int i = pt.size() - 2, t = top + 1; i >= 0; i--) {       while (top >= t && cross(stk[top - 2], stk[top - 1], pt[i]) <= 0) top--;       stk[top++] = pt[i];     }     stk.resize(top - 1);     return stk;   }   int N, R;   int ans;   vector<Point> convexP, chp, sol;   int dis2(Point a, Point b) {     return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);   }   void DFS(int i, int prv, int val) {     if (i >= N) {       if (val > ans) {         ans = val;         sol = chp;       }       return;     }     for (int j = prv; j < (int)convexP.size(); j++) {       int c = 0;       for (auto pt : chp) c += (pt - convexP[j]).abs2();       chp.push_back(convexP[j]);       DFS(i + 1, j, val + c);       chp.pop_back();     }   }   int main() {     vector<Point> pt;     cin >> N >> R;     if (N % 2 == 0) {       for (int i = 0; i < N / 2; i++) {         sol.push_back(Point(R, 0));         sol.push_back(Point(-R, 0));       }       for (int i = 0; i < N; i++)         for (int j = 0; j < i; j++) ans += (sol[i] - sol[j]).abs2();     } else {       for (int i = -R; i <= R; i++) {         for (int j = -R; j <= R; j++) {           if (i * i + j * j <= R * R) {             pt.push_back(Point(i, j));           }         }       }       convexP = convex_hull(pt);       ans = 0;       DFS(0, 0, 0);     }     cout << ans << endl;     for (auto p : sol) cout << p.x <<     << p.y << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string str;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> str;     int ans = 0;     for (int i = 0; i < n; i += 2) {       int cnt = 0;       if (str[i] ==  a )         cnt++;       else         cnt--;       if (str[i + 1] ==  a )         cnt++;       else         cnt--;       if (cnt != 0) {         if (str[i] ==  a )           str[i] =  b ;         else           str[i] =  a ;         ans++;       }     }     cout << ans <<   n ;     cout << str <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       long long n;       cin >> n;       string s;       cin >> s;       cout << n + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   const int N = 2e5 + 5;   vector<pair<long long, long long> > v;   long long n, m, k;   void solve() {     sort(v.rbegin(), v.rend());     long long sum = 0;     vector<long long> index;     for (long long i = 0; i < m * k; i++) {       sum += v[i].first;       index.push_back(v[i].second);     }     sort(index.begin(), index.end());     cout << sum <<   n ;     for (int i = 0; i < k - 1; i++) cout << index[(i + 1) * m - 1] <<    ;   }   int main() {     fast();     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       long long t;       cin >> t;       v.push_back(make_pair(t, i + 1));     }     solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k, a, b, v, ans;     while (scanf( %d%d%d%d , &k, &a, &b, &v) != EOF) {       ans = 0;       while (a > 0) {         if (b >= k - 1) {           b -= (k - 1);           a -= v * k;           ans++;         } else {           b = b + 1;           a -= v * b;           ans++;           b = 0;         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr int kN = int(3E2 + 10), kC = int(2E6 + 10);   vector<pair<int, int>> v[kC], nv[kC];   int ans[kC], a[kN][kN], pos[kN][kN], p[kN * kN], up[kN * kN], dwn[kN * kN],       lft[kN * kN], rht[kN * kN], nans[kC];   bool have[kN * kN];   int Find(int n) { return p[n] == n ? n : p[n] = Find(p[n]); }   bool merge(int l, int r) {     l = Find(l), r = Find(r);     if (l == r)       return false;     else {       p[l] = r;       return true;     }   }   int main() {     int n, m, q, x, y, c, now = 0, tmp;     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) a[i][j] = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) pos[i][j] = now++;     for (int i = 1; i < n; i++)       for (int j = 1; j <= m; j++) {         up[pos[i][j]] = pos[i + 1][j];         dwn[pos[i + 1][j]] = pos[i][j];       }     for (int i = 1; i <= m; i++) up[pos[n][i]] = dwn[pos[1][i]] = -1;     for (int i = 1; i <= n; i++)       for (int j = 1; j < m; j++) {         lft[pos[i][j]] = pos[i][j + 1];         rht[pos[i][j + 1]] = pos[i][j];       }     for (int i = 1; i <= n; i++) lft[pos[i][m]] = rht[pos[i][1]] = -1;     for (int i = 1; i <= q; i++) {       scanf( %d%d%d , &x, &y, &c);       if (a[x][y] == c)         continue;       else {         nv[a[x][y]].push_back({pos[x][y], i});         a[x][y] = c;         v[a[x][y]].push_back({pos[x][y], i});       }     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) nv[a[i][j]].push_back({pos[i][j], q + 1});     ans[0] = nans[q + 1] = 0;     for (int i = 0; i <= c; i++) {       for (int j = 0; j < now; j++) p[j] = j;       for (int j = 0; j < now; j++) have[j] = false;       tmp = 0;       for (pair<int, int> j : v[i]) {         ans[j.second]++;         tmp++;         have[j.first] = true;         if (up[j.first] >= 0 && have[up[j.first]])           if (merge(j.first, up[j.first])) {             tmp--;             ans[j.second]--;           }         if (lft[j.first] >= 0 && have[lft[j.first]])           if (merge(j.first, lft[j.first])) {             ans[j.second]--;             tmp--;           }         if (rht[j.first] >= 0 && have[rht[j.first]])           if (merge(j.first, rht[j.first])) {             ans[j.second]--;             tmp--;           }         if (dwn[j.first] >= 0 && have[dwn[j.first]])           if (merge(j.first, dwn[j.first])) {             ans[j.second]--;             tmp--;           }       }       reverse(nv[i].begin(), nv[i].end());       if (tmp) {         ans[v[i].back().second + 1] -= tmp;         nans[v[i].back().second] -= tmp;       }       for (int j = 0; j < now; j++) p[j] = j;       for (int j = 0; j < now; j++) have[j] = false;       for (pair<int, int> j : nv[i]) {         nans[j.second - 1]++;         have[j.first] = true;         if (up[j.first] >= 0 && have[up[j.first]])           if (merge(j.first, up[j.first])) nans[j.second - 1]--;         if (lft[j.first] >= 0 && have[lft[j.first]])           if (merge(j.first, lft[j.first])) nans[j.second - 1]--;         if (rht[j.first] >= 0 && have[rht[j.first]])           if (merge(j.first, rht[j.first])) nans[j.second - 1]--;         if (dwn[j.first] >= 0 && have[dwn[j.first]])           if (merge(j.first, dwn[j.first])) nans[j.second - 1]--;       }     }     for (int i = q; i >= 1; i--) nans[i] += nans[i + 1];     for (int i = 1; i <= q; i++) ans[i] += ans[i - 1];     for (int i = 1; i <= q; i++) printf( %d n , ans[i] + nans[i]);   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> graph[80005];   bool vis[100005];   long long int size[100005];   long long int arr[100005];   long long int ans2;   long long int ans;   int dfs1(int node) {     vis[node] = true;     int ret = 1;     for (int i = 0; i < graph[node].size(); i++) {       if (vis[graph[node][i]]) continue;       ret += dfs1(graph[node][i]);     }     return (size[node] = ret);   }   void dfs2(int node, long long int cum) {     vis[node] = true;     long long int rem = n - size[node];     int i;     long long int sum = 0, sqsum = 0, temp;     for (i = 0; i < graph[node].size(); i++) {       if (vis[graph[node][i]]) continue;       temp = size[graph[node][i]];       sum += temp;       sqsum += temp * temp;     }     long long int paths = (sum * sum - sqsum) / 2 + sum;     ans += (rem * (rem - 1) / 2) * paths;     ans2 += cum * paths;     for (i = 0; i < graph[node].size(); i++) {       if (vis[graph[node][i]]) continue;       temp = size[graph[node][i]];       dfs2(graph[node][i], cum + (-(sum - temp) + (sqsum - temp * temp)) / 2);     }   }   int main() {     int i, a, b;     scanf( %d , &n);     for (i = 0; i < n - 1; i++) {       scanf( %d , &a);       scanf( %d , &b);       graph[a].push_back(b);       graph[b].push_back(a);     }     memset(vis, 0, sizeof(vis));     dfs1(1);     ans = 0;     ans2 = 0;     memset(vis, 0, sizeof(vis));     dfs2(1, 0);     ans = 2 * ans - ans2;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   signed main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long arr[n];       long long sum = 0;       for (long long i = 0; i < n; i++) {         cin >> arr[i];         sum += arr[i];       }       sum = 2 * sum;       if (sum % n) {         cout << 0 <<   n ;         continue;       }       sum /= n;       long long ans = 0;       unordered_map<long long, long long, custom_hash> mp1;       for (long long i = 0; i < n; i++) {         ans += mp1[sum - arr[i]];         mp1[arr[i]]++;       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   char ff[1005][1005];   int main() {     int t;     scanf( %d , &t);     for (int i = 0; i < t; i++) {       int zz[1005];       int n, m, x, y;       int ww = 0;       int w = 0;       scanf( %d%d%d%d , &n, &m, &x, &y);       for (int j = 1; j <= n; j++) {         char f[1005];         scanf( %s , f);         memset(zz, 0, sizeof(zz));         for (int z = 0; z < strlen(f); z++) {           ff[j][z + 1] = f[z];           if (ff[j][z + 1] == ff[j][z] && ff[j][z] ==  .  && zz[z + 1] == 0 &&               zz[z] == 0) {             ww++;             zz[z + 1] = 1;             zz[z] = 1;           }           if (ff[j][z + 1] ==  . ) w++;         }       }       if (y >= 2 * x) {         printf( %d n , x * w);       } else         printf( %d n , ww * y + x * (w - ww * 2));     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000;   const int MAX = 100000 + 100;   const int inf = 999999999;   const int p1 = 104393321, p2 = 104393329;   int n, m;   int par[MAX], sizeofcom[MAX], size[MAX], a[MAX], b[MAX], d[MAX];   bool lucky(int x) {     while (x > 0) {       if (x % 10 == 7 || x % 10 == 4)         x /= 10;       else         return false;     }     return true;   }   int find(int k) {     if (par[k] == k)       return k;     else       par[k] = find(par[k]);     return par[k];   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> m;     for (int i = (0); i < int(n); ++i) par[i] = i;     int x, y;     for (int i = (0); i < int(m); ++i) {       cin >> x >> y;       x--;       y--;       par[find(x)] = find(y);     }     for (int i = (0); i < int(n); ++i) sizeofcom[find(i)]++;     for (int i = (0); i < int(n + 1); ++i) size[sizeofcom[i]]++;     for (int i = (1); i < int(n + 1); ++i)       if (lucky(i) && size[i]) {         cout << 0 << endl;         return 0;       }     int sz = 0;     for (int i = (1); i < int(n + 1); ++i) {       int tmp = 1;       while (tmp <= size[i]) {         a[sz] = tmp * i;         b[sz++] = tmp;         size[i] -= tmp;         tmp *= 2;       }       if (size[i]) {         a[sz] = size[i] * i;         b[sz++] = size[i];       }     }     int ans = inf;     for (int i = (1); i < int(n + 1); ++i) d[i] = inf;     d[a[0]] = 1;     for (int j = (1); j < int(sz); ++j) {       for (int i = (n); i > int(0); --i) {         if (a[j] <= i) d[i] = min(d[i], d[i - a[j]] + b[j]);         if (lucky(i) && d[i] != inf) ans = min(ans, d[i]);       }     }     if (ans == inf)       cout << -1 << endl;     else       cout << ans - 1 << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   int main() {     string s1, s2, s;     int n, m;     scanf( %d%d , &n, &m);     map<string, string> mp;     for (int i = 0; i < m; ++i) {       cin >> s1 >> s2;       if (s2.size() >= s1.size())         mp[s1] = s1;       else         mp[s1] = s2;     }     for (int i = 0; i < n; ++i) {       cin >> s;       cout << mp[s] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int INF = 2e9;   const long long int LONGINF = 4e18;   long long int inv[200200], fct[200200], invfct[200200];   long long int c[2222];   long long int C(long long int n, long long int k) {     return fct[n] * invfct[n - k] % mod * invfct[k] % mod;   }   void solve(int n) {     int m, g;     long long int c, ans = 0;     scanf( %d%d , &m, &g);     inv[1] = 1;     fct[0] = 1;     fct[1] = 1;     invfct[0] = 1;     invfct[1] = 1;     for (int i = (2); i < (200200); i++) {       inv[i] = -((long long int)mod / i * inv[mod % i] % mod) + mod;       fct[i] = fct[i - 1] * i % mod;       invfct[i] = invfct[i - 1] * inv[i] % mod;     }     if (m == 0) {       if (n % 2 == 1 - g) {         printf( 1 );       } else {         printf( 0 );       }       return;     }     c = C(n + m - 1, n);     for (int i = 0; i < (n + 1); i++) {       if (m == 1 && i == n) {         if ((n + 1) % 2 == g) {           ans++;           ans %= mod;         }         continue;       }       if (i % 2 == g) {         ans += c;         ans %= mod;       }       c = c * inv[n + m - i - 1] % mod * (n - i) % mod;       ;     }     printf( %I64d , ans);   }   int main() {   #pragma comment(linker,  /STACK:268435456 )     int n;     long long int a;     char c[200200];     string s;     while (scanf( %d , &n) == 1) solve(n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[110], s[110];   int main() {     int n, m;     cin >> n >> m;     for (int i = (1); i < (n + 1); i++) cin >> x[i];     for (int i = (1); i < (n + 1); i++) s[i] = s[i - 1] + x[i];     int v = 0;     while (m--) {       int l, r;       cin >> l >> r;       if (s[r] - s[l - 1] > 0) v += s[r] - s[l - 1];     }     cout << v <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   vector<vector<int>> g;   vector<int> vis, cap;   void dfs(int s) {     vis[s] = 1;     cap[s] = 1;     for (int i : g[s]) {       if (vis[i] == 0) {         dfs(i);       }     }   }   int32_t main() {     {       ios_base::sync_with_stdio(false);       cin.tie(NULL);     }     int n, m;     cin >> n >> m;     vector<vector<int>> a(n);     g.resize(m + 1);     vis.assign(m + 1, 0);     cap.assign(m + 1, 0);     for (int i = 0; i < n; i++) {       int k;       cin >> k;       a[i].resize(k);       for (int j = 0; j < k; j++) {         cin >> a[i][j];       }     }     for (int i = 1; i < n; i++) {       int k0 = a[i - 1].size(), k1 = a[i].size();       int j = 0, f = 0;       while (j < k0 and j < k1) {         if (a[i - 1][j] == a[i][j]) {           j++;           continue;         }         f = 1;         if (a[i - 1][j] < a[i][j]) {           g[a[i][j]].push_back(a[i - 1][j]);         } else {           cap[a[i - 1][j]] = 1;         }         break;       }       if (f == 0) {         if (a[i].size() < a[i - 1].size()) {           cout <<  No ;           return 0;         }       }     }     for (int i = 1; i <= m; i++) {       if (vis[i] == 0 and cap[i] == 1) {         dfs(i);       }     }     for (int i = 1; i < n; i++) {       int k0 = a[i - 1].size(), k1 = a[i].size();       int j = 0;       while (j < k0 and j < k1) {         if (a[i - 1][j] == a[i][j]) {           j++;           continue;         }         if (a[i - 1][j] < a[i][j]) {           if (cap[a[i][j]] == 1 and cap[a[i - 1][j]] != 1) {             cout <<  No ;             return 0;           }         } else {           if (cap[a[i][j]] == 1) {             cout <<  No ;             return 0;           }         }         break;       }     }     {       cout <<  Yes n ;       vector<int> ans;       for (int i = 1; i <= m; i++) {         if (cap[i] == 1) {           ans.push_back(i);         }       }       cout << ans.size() <<   n ;       for (int i : ans) {         cout << i <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void read(T& num) {     char CH;     bool F = false;     for (CH = getchar(); CH <  0  || CH >  9 ; F = CH ==  - , CH = getchar())       ;     for (num = 0; CH >=  0  && CH <=  9 ;          num = num * 10 + CH -  0 , CH = getchar())       ;     F && (num = -num);   }   int stk[70], tp;   template <class T>   inline void print(T p) {     if (!p) {       puts( 0 );       return;     }     while (p) stk[++tp] = p % 10, p /= 10;     while (tp) putchar(stk[tp--] +  0 );     putchar(  n );   }   const long long mod = 1e9 + 7;   const double PI = acos(-1.0);   const int inf = 1e9;   const int N = 1e5 + 10;   const int maxn = 1e3 + 20;   const double eps = 1e-12;   int check(int x) {     int l = 1, r = 1000005;     if (x == 0) return 0;     while (l <= r) {       int mid = (l + r) >> 1;       if ((long long)mid * (mid - 1) < (long long)2 * x)         l = mid + 1;       else         r = mid - 1;     }     return l;   }   int main() {     int a, b, c, d;     read(a);     read(b);     read(c);     read(d);     int x = check(a), y = check(d);     if (x == 0 && (b || c)) x = 1;     if (y == 0 && (b || c)) y = 1;     if ((long long)x * (x - 1) != (long long)2 * a ||         (long long)y * (y - 1) != (long long)2 * d ||         (long long)x * y != (long long)b + c)       cout <<  Impossible n ;     else {       if (x == 0 && y == 0)         printf( 0 );       else if (x == 0) {         for (int i = 1; i <= y; i++) printf( 1 );       } else if (y == 0) {         for (int i = 1; i <= x; i++) printf( 0 );       } else {         int t = b / y, f = y - b % y;         for (int i = 1; i <= t; i++) printf( 0 ), x--;         for (int i = 1; i <= f; i++) printf( 1 ), y--;         if (x > 0) {           printf( 0 );           x--;         }         for (int i = 1; i <= y; i++) printf( 1 );         for (int i = 1; i <= x; i++) printf( 0 );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   struct edge {     int from, to, next;   } e[N * 20], e2[N * 10];   int head[N], ecnt, vis[N], fa[N][18], dep[N], ok[N * 10], ecnt2;   map<pair<int, int>, int> mp;   inline void adde(int from, int to) {     e[++ecnt] = (edge){from, to, head[from]}, head[from] = ecnt;     e[++ecnt] = (edge){to, from, head[to]}, head[to] = ecnt;   }   int fir, sec;   vector<int> G[N];   void dfs(int u, int f) {     fa[u][0] = f, dep[u] = dep[f] + 1, vis[u] = 1;     for (int i = 1; i <= 17; i++) fa[u][i] = fa[fa[u][i - 1]][i - 1];     for (auto v : G[u])       if (!vis[v]) {         adde(v, u);         int a = v, b = u;         if (a > b) swap(a, b);         ok[mp[pair<int, int>(a, b)]] = 1, dfs(v, u);       }   }   inline int LCA(int a, int b) {     if (dep[a] < dep[b]) swap(a, b);     for (int i = 17; i >= 0; i--)       if (dep[fa[a][i]] >= dep[b]) a = fa[a][i];     if (a == b) return a;     for (int i = 17; i >= 0; i--)       if (fa[a][i] != fa[b][i]) a = fa[a][i], b = fa[b][i];     return fa[a][0];   }   set<int> add[N], del[N], fuck[N];   bool flg;   inline void mark(int a, int b, int id) {     int lca = LCA(a, b);     add[a].insert(id), add[b].insert(id), del[lca].insert(id);   }   void dfs2(int u, int f) {     for (int i = head[u]; i && !flg; i = e[i].next)       if (e[i].to != f) dfs2(e[i].to, u);     if (flg) return;     for (auto v : add[u]) fuck[u].insert(v);     for (int i = head[u]; i; i = e[i].next)       if (e[i].to != f && fuck[e[i].to].size())         fuck[u].insert(*fuck[e[i].to].begin());     for (auto v : del[u]) fuck[u].erase(v);     if (fuck[u].size() >= 2) {       fir = *fuck[u].begin(), fuck[u].erase(fuck[u].begin()),       sec = *fuck[u].begin();       flg = true;     }   }   int tmp[N], to, stk[N], top, hh, tmp2[N * 10];   void dfs3(int u) {     if (u == to) {       hh = 1, printf( %d  , top);       for (int i = 1; i <= top; i++) printf( %d  , stk[i]);       puts(  );       return;     }     tmp[u] = 1;     for (auto v : G[u])       if (!tmp[v]) {         int a = u, b = v;         if (a > b) swap(a, b);         int t = mp[pair<int, int>(a, b)];         if (tmp2[t]) continue;         if (!ok[t] && t != fir && t != sec) continue;         tmp2[t] = 1, stk[++top] = v, dfs3(v), top--;         if (hh) return;       }   }   inline void work(int a1, int a2, int b1, int b2) {     static int p[5];     p[1] = LCA(a1, b1), p[2] = LCA(a1, b2), p[3] = LCA(a2, b1),     p[4] = LCA(a2, b2);     sort(p + 1, p + 5, [](int a, int b) { return dep[a] > dep[b]; });     int A = p[1], B = p[2];     hh = 0, to = B, stk[top = 1] = A, dfs3(A), hh = 0, top = 1, dfs3(A), hh = 0,     top = 1, dfs3(A);   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1, a, b; i <= m; i++) {       scanf( %d%d , &a, &b);       if (a > b) swap(a, b);       G[a].push_back(b), G[b].push_back(a), e2[++ecnt2] = (edge){a, b, 0},                                             mp[pair<int, int>(a, b)] = ecnt2;     }     for (int i = 1; i <= n; i++)       if (!vis[i]) dfs(i, 0);     for (int i = 1; i <= ecnt2; i++)       if (!ok[i]) mark(e2[i].from, e2[i].to, i);     for (int i = 1; i <= n; i++)       if (!fa[i][0]) {         dfs2(i, 0);         if (flg) {           puts( YES ), work(e2[fir].from, e2[fir].to, e2[sec].from, e2[sec].to);           return 0;         }       }     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   const int P = 1e9 + 7;   template <typename T>   void chkmax(T &x, T y) {     x = max(x, y);   }   template <typename T>   void chkmin(T &x, T y) {     x = min(x, y);   }   template <typename T>   void read(T &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     x *= f;   }   template <typename T>   void write(T x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   template <typename T>   void writeln(T x) {     write(x);     puts(  );   }   int n, bit[MAXN], cnt[MAXN], a[MAXN];   int main() {     read(n), bit[0] = 1;     for (int i = 1; i <= n; i++) {       bit[i] = bit[i - 1] * 2 % P;       read(a[i]);       if (a[i] != -1) cnt[a[i]]++;     }     int ans = bit[n - 1] - 1;     for (int i = 1; i <= n; i++)       if (a[i] == -1) ans = (ans - (bit[cnt[i]] - 1)) % P;     writeln((ans + P) % P);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long minn;     int p, min_ind;     node(long long a = 0, int b = 0, int c = 0) { minn = a, p = b, min_ind = c; }   };   struct lazy_node {     long long sv, snx, av, anx;     lazy_node(long long a = -1, int b = 0, long long c = 0, int d = 0) {       sv = a, snx = b;       av = c, anx = d;     }   };   const int max_N = 100000 + 10;   const int X = 1e8;   int a[max_N], n;   set<pair<int, int> > s;   set<pair<int, int> >::iterator it, itt;   long long pw42[15];   node seg[4 * max_N];   lazy_node lazy[4 * max_N];   inline int find_pw(long long x) {     return lower_bound(pw42, pw42 + 12, x) - pw42;   }   inline node merge(int ind) {     if (seg[2 * ind].minn < seg[2 * ind + 1].minn) return seg[2 * ind];     return seg[2 * ind + 1];   }   inline void split1(int l, int r) {     it = s.upper_bound(make_pair(l, X)), itt = s.upper_bound(make_pair(r, X));     it--, itt--;     pair<int, int> t = make_pair((it->first), (itt->second));     while (it != s.end() && (it->first) <= r) {       s.erase(it);       it = s.lower_bound(make_pair(l, X));     }     s.insert(make_pair(l, r));     if (l > t.first) s.insert(make_pair(t.first, l - 1));     if (r < t.second) s.insert(make_pair(r + 1, t.second));   }   inline void split2(int l, int r) {     it = s.upper_bound(make_pair(l, X));     itt = s.upper_bound(make_pair(r, X));     pair<int, int> t1 = *(--it), t2 = *(--itt);     s.erase(it);     if (t1 != t2) {       itt = s.upper_bound(make_pair(r, X));       s.erase(--itt);     }     if (l > t1.first) s.insert(make_pair(t1.first, l - 1));     if (r < t2.second) s.insert(make_pair(r + 1, t2.second));     s.insert(make_pair(l, min(r, t1.second)));     s.insert(make_pair(max(l, t2.first), r));   }   void build(int st = 0, int en = n, int ind = 1) {     if (en - st == 1) {       int t = find_pw(a[st]);       seg[ind] = node(pw42[t] - a[st], t, st);       return;     }     int mid = (st + en) / 2;     build(st, mid, 2 * ind);     build(mid, en, 2 * ind + 1);     seg[ind] = merge(ind);   }   inline void shift(int ind) {     lazy_node t = lazy[ind];     lazy[ind] = lazy_node();     int i1 = 2 * ind, i2 = 2 * ind + 1;     if (t.sv != -1) {       seg[i1] = node(t.sv, t.snx, seg[i1].min_ind);       seg[i2] = node(t.sv, t.snx, seg[i2].min_ind);       lazy[i1] = lazy_node(t.sv, t.snx);       lazy[i2] = lazy_node(t.sv, t.snx);     }     seg[i1].minn -= t.av, seg[i2].minn -= t.av;     seg[i1].p += t.anx, seg[i2].p += t.anx;     lazy[i1].av += t.av, lazy[i2].av += t.av;     lazy[i1].anx += t.anx, lazy[i2].anx += t.anx;   }   void modify1(int l, int r, long long val, int nx, int st = 0, int en = n,                int ind = 1) {     if (l >= en || r <= st) return;     if (l <= st && r >= en) {       seg[ind] = node(val, nx, st);       lazy[ind] = lazy_node(val, nx);       return;     }     shift(ind);     int mid = (st + en) / 2;     modify1(l, r, val, nx, st, mid, 2 * ind);     modify1(l, r, val, nx, mid, en, 2 * ind + 1);     seg[ind] = merge(ind);   }   void modify2(int o, int l, int r, long long val, int st = 0, int en = n,                int ind = 1) {     if (l >= en || r <= st) return;     if (l <= st && r >= en) {       seg[ind].minn -= val, seg[ind].p += o;       lazy[ind].av += val, lazy[ind].anx += o;       return;     }     shift(ind);     int mid = (st + en) / 2;     modify2(o, l, r, val, st, mid, 2 * ind);     modify2(o, l, r, val, mid, en, 2 * ind + 1);     seg[ind] = merge(ind);   }   inline void relax() {     while (seg[1].minn < 0) {       int x = seg[1].p;       it = s.upper_bound(make_pair(seg[1].min_ind, X));       pair<int, int> t = *(--it);       modify2(1, t.first, t.second + 1, pw42[x] - pw42[x + 1]);     }   }   long long calc(int x, int st = 0, int en = n, int ind = 1) {     if (en - st == 1) return pw42[seg[ind].p] - seg[ind].minn;     shift(ind);     int mid = (st + en) / 2;     if (x < mid) return calc(x, st, mid, 2 * ind);     return calc(x, mid, en, 2 * ind + 1);   }   int main() {     int q, l, r, x, t;     scanf( %d %d , &n, &q);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       s.insert(make_pair(i, i));     }     pw42[0] = 1;     for (int i = 1; i < 12; i++) pw42[i] = pw42[i - 1] * 42;     build();     while (q--) {       scanf( %d , &t);       if (t == 1) {         scanf( %d , &x);         printf( %lld n , calc(x - 1));       } else {         scanf( %d %d %d , &l, &r, &x);         l--;         if (t == 2) {           int nx = find_pw(x);           modify1(l, r, pw42[nx] - x, nx);           split1(l, r - 1);         } else {           split2(l, r - 1);           do {             modify2(0, l, r, x);             relax();           } while (!seg[1].minn);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int rain(int n, int *T, int i) {     int r = 1;     int d = i + 1, g = i - 1, ex = i;     while ((g >= 0) && (T[g] <= T[i])) {       r++;       i = g;       g--;     }     i = ex;     while ((d < n) && (T[d] <= T[i])) {       r++;       i = d;       d++;     }     return r;   }   int max(int n, int *T) {     int x;     x = rain(n, T, 0);     for (int i = 1; i < n; i++) {       if (rain(n, T, i) > x) x = rain(n, T, i);     }     return x;   }   int main() {     int *T;     int n;     cin >> n;     T = new int[n];     for (int i = 0; i < n; i++) cin >> T[i];     cout << max(n, T);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[131100];   int cal(int l, int r, char t) {     int cnt = 0;     for (int i = l; i <= r; i++) {       if (s[i] != t) cnt++;     }     return cnt;   }   int dfs(int l, int r, char t) {     if (l == r) return cal(l, r, t);     int ret = 1e9;     int mid = (l + r) >> 1;     ret = min(ret, dfs(l, mid, t + 1) + cal(mid + 1, r, t));     ret = min(ret, dfs(mid + 1, r, t + 1) + cal(l, mid, t));     return ret;   }   int main() {     int _;     scanf( %d , &_);     while (_--) {       int n;       scanf( %d , &n);       scanf( %s , s);       char temp =  a ;       printf( %d n , dfs(0, n - 1, temp));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mo = 1e9 + 7;   char s[2010], ss[2010];   long long dp[2010][2010], a[2010];   long long m, d, jo;   int len;   long long dfs(int pos, long long sum, bool limit) {     if (pos == len) return sum == 0;     if (!limit && dp[pos][sum] != -1) return dp[pos][sum];     int up = limit ? a[pos] : 9;     long long tmp = 0;     for (int i = 0; i <= up; i++) {       if (pos & 1) {         if (i == d)           tmp =               (tmp + dfs(pos + 1, (sum * 10 + i) % m, limit && i == a[pos])) % mo;       } else if (i != d)         tmp = (tmp + dfs(pos + 1, (sum * 10 + i) % m, limit && i == a[pos])) % mo;     }     if (!limit) dp[pos][sum] = tmp;     return tmp;   }   int solve(char *s) {     int pos = strlen(s) - 1;     len = 0;     while (len <= pos) {       a[len] = s[len] -  0 ;       len++;     }     long long as = dfs(0, 0, true);     return as;   }   int main() {     int le, ri;     while (scanf( %lld%lld , &m, &d) != EOF) {       memset(dp, -1, sizeof(dp));       scanf( %s%s , s, ss);       int l = strlen(s);       long long spc = 1, sm = 0;       for (int i = 0; i < l; i++) {         if ((i % 2 == 0) && ((s[i] & 15) == d)) {           spc = 0;           break;         } else if ((i & 1) && ((s[i] & 15) != d)) {           spc = 0;           break;         }         sm = (sm * 10 + (s[i] & 15)) % m;       }       if (spc) spc = (sm == 0);       printf( %lld n , (solve(ss) - solve(s) + spc + mo) % mo);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   long long M;   int A[200002], B[200002];   map<int, int> MP;   vector<pair<long long, long long> > ST;   long long getover(pair<long long, long long> p, int i2) {     if (p.second >= ST[i2].second) return 0;     return (ST[i2].second - p.second) / (p.first - ST[i2].first) +            ((ST[i2].second - p.second) % (p.first - ST[i2].first) != 0);   }   long long getover(int i1, int i2) {     if (ST[i1].second >= ST[i2].second) return 0;     return (ST[i2].second - ST[i1].second) / (ST[i1].first - ST[i2].first) +            ((ST[i2].second - ST[i1].second) % (ST[i1].first - ST[i2].first) != 0);   }   int main() {     cin.sync_with_stdio(false);     cin >> N >> M;     int bestinit = 0;     for (int i = 1; i <= N; ++i) {       cin >> A[i] >> B[i];       if (B[i] == 0) bestinit = max(bestinit, A[i]);       if (MP.find(A[i]) == MP.end()) MP[A[i]] = 0x3f3f3f3f;       MP[A[i]] = min(MP[A[i]], B[i]);     }     ST.push_back(make_pair(bestinit, 0));     for (map<int, int>::iterator it = MP.begin(); it != MP.end(); ++it) {       if (it->first <= bestinit) continue;       int step = (1 << 17), now = 0;       for (; step; step >>= 1)         if (now + step < int(ST.size()) &&             1LL * ST[now + step - 1].first *                         (getover(now + step, now + step - 1) - 1) +                     ST[now + step - 1].second <                 it->second)           now += step;       step = (1 << 30);       int pos = 0;       for (; step; step >>= 1)         if (ST[now].first * (pos + step - 1) + ST[now].second < it->second)           pos += step;       int rem = ST[now].first * pos + ST[now].second - it->second;       pair<long long, long long> pnow =           make_pair(it->first, rem - 1LL * it->first * pos);       while (ST.size() >= 2 && getover(pnow, ST.size() - 1) <=                                    getover(ST.size() - 1, ST.size() - 2))         ST.pop_back();       ST.push_back(pnow);     }     int step = (1 << 17), now = 0;     for (; step; step >>= 1)       if (now + step < int(ST.size()) &&           1LL * ST[now + step - 1].first *                       (getover(now + step, now + step - 1) - 1) +                   ST[now + step - 1].second <               M)         now += step;     long long times = 100000000 + M / ST.back().first;     long long astep = 1;     while (astep <= times) astep *= 2;     long long pos = 0;     for (; astep; astep >>= 1)       if (ST[now].first * (pos + astep - 1) + ST[now].second < M) pos += astep;     cout << pos <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int b[200010];   int main() {     long long n;     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , &b[i]);     sort(b, b + n);     int m = b[n - 1] - b[0];     int m1 = b[n - 1], m2 = b[0];     long long c1 = 0, c2 = 0;     for (int i = 0; i < n; i++) {       if (b[i] == m1) c1++;       if (b[i] == m2) c2++;     }     printf( %d  , m);     if (m1 == m2)       cout << n * (n - 1) / 2 << endl;     else       cout << c1 * c2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long int binomialCoeff(long long int n, long long int k) {     long long int C[n + 1][k + 1];     long long int i, j;     for (i = 0; i <= n; i++) {       for (j = 0; j <= min(i, k); j++) {         if (j == 0 || j == i)           C[i][j] = 1;         else           C[i][j] = ((C[i - 1][j - 1]) % 998244353 + (C[i - 1][j]) % 998244353) %                     998244353;       }     }     return C[n][k];   }   long long int digsum(long long int a) {     long long int sum = 0;     while (a > 0) {       sum += a % 10;       a = a / 10;     }     return sum;   }   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int fact(int a) {     if (a == 1)       return a;     else       return a * fact(a - 1);   }   int max3(int a, int b, int c) { return max(a, max(b, c)); }   int main() {     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       int temp;       int each = 0;       for (long long int i = 1; i <= n; i++) {         cin >> temp;         each += temp;       }       cout << (int)(ceil((double)(each) / (double)(n))) << endl;     }     return 0;   }


#include<bits/stdc++.h>   #define ll long long   #define ld long double   #define pb push_back   #define x first   #define y second   #define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);   using namespace std;      //modulo op      const ll mod = 1e9 + 7;      ll add(ll a, ll b) {    return (a + b) % mod;   }      ll sub(ll a, ll b) {    return ((a - b) % mod + mod) % mod;   }      ll mul(ll a, ll b) {    return (a * b) % mod;   }      ll normalize(ll a) {    return (a % mod + mod) % mod;   }   //end of modulo op   ll power(ll a, ll b) {    if (b == 0)     return 1;    ll val = power(a, b / 2);    val = mul(val, val);    if (b & 1)     val = mul(val, a);    return val;   }      const int maxn = 2e5 + 7;   ll fact[maxn], ifact[maxn];      void precalc() {    fact[0] = 1;    ifact[0] = 1;    for (int i = 1; i < maxn; i++) {     fact[i] = mul(i, fact[i - 1]);     ifact[i] = power(fact[i], mod - 2);    }   }      ll ncr(ll n, ll r) {    return mul(fact[n], mul(ifact[n - r], ifact[r]));   }         void solve() {    ll n, l, r;    cin >> n >> l >> r;    ll double_op_limit = min(1 - l, r - n);    ll ans = mul(add(ncr(n, n / 2), n & 1 == 1 ? ncr(n, n / 2 + 1) : 0), double_op_limit);    // cout << double_op_limit <<     << ans << endl;    for (ll i = double_op_limit + 1; i <= double_op_limit + n; i++) {     ll left_fixed = max(l + i - 1, 0LL);     ll right_fixed = n - min(n, r - i);     // cout << i <<     << left_fixed <<     << right_fixed << endl;     if (left_fixed > (n + 1) / 2 || right_fixed > (n + 1) / 2)      break;     ll rem = n - left_fixed - right_fixed;     if (rem < 0)      break;     if (left_fixed == (n + 1) / 2) {      ans = add(ans, 1);      break;     }     ans = add(ans, ncr(rem, n / 2 - left_fixed));     if (n & 1)      ans = add(ans, ncr(rem, n / 2 + 1 - left_fixed));     // cout << ans << endl;    }    cout << ans;   }      int main()   {    fastread;    precalc();    int t;    cin >> t;    while (t--) {     solve();     cout <<   n ;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   __attribute__((constructor)) void Init() {     ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed;   }   constexpr int N = 5e3;   char A[N + 2], B[N + 2];   int16_t dp[2][N + 1];   int main() {     int n, m, t = 0, ans = 0;     cin >> n >> m >> &A[1] >> &B[1];     for (int i = 1; i <= n; ++i, t = 1 - t) {       for (int j = 1; j <= m; ++j) {         int s = dp[1 - t][j - 1] + 4 * (A[i] == B[j]) - 2;         dp[t][j] = max(0, max(s, max(dp[t][j - 1], dp[1 - t][j]) - 1));         ;         ans = max<int>(ans, dp[t][j]);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     cin.tie(nullptr)->sync_with_stdio(false);     long long _;     for (cin >> _; _--;) {       long long n, m, k;       cin >> n >> m >> k;       long long mn = (n % 2 == 1 ? m / 2 : 0);       long long mx = n * m / 2 - (m % 2 == 1 ? n / 2 : 0);       if (mn <= k and k <= mx and (k - mn) % 2 == 0)         cout <<  YES n ;       else         cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000007;   const long long INF2 = 1000000000000000007;   const int MOD = 774254531;   const int MOD1 = 892237699;   const int SIZE = 150010;   const double eps = 1e-6;   long long n, m;   long long ar[1010][1010], res;   string st, b, minn;   long long gcd(long long a, long long b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         cin >> ar[i][j];       }     }     res = sqrt(ar[0][1] * ar[0][2] / ar[1][2]);     cout << res <<    ;     for (int i = 1; i < n; ++i) {       cout << ar[0][i] / res <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   string name[maxn], s;   vector<int> G[maxn];   int tot, a[maxn], maxd, dep[maxn];   int dfs(int &p, int d) {     maxd = max(maxd, d);     int ret = ++tot;     dep[ret] = d;     while (s[p] !=  , ) {       name[ret].push_back(s[p++]);     }     ++p;     int son = 0;     while (s[p] !=  , ) {       son = son * 10 + s[p++] -  0 ;     }     ++p;     for (int i = 0; i < son; ++i) G[ret].push_back(dfs(p, d + 1));     return ret;   }   void bfs() {     queue<int> que;     cout << maxd;     int t = 0;     for (int i = 0; i < G[0].size(); ++i) que.push(G[0][i]);     while (!que.empty()) {       int p = que.front();       que.pop();       if (dep[p] != t) {         ++t;         cout << endl;       } else         cout <<    ;       cout << name[p];       for (int i = 0; i < G[p].size(); ++i) que.push(G[p][i]);     }     cout << endl;   }   int main() {     cin >> s;     s.push_back( , );     maxd = 0;     int p = 0;     while (p < s.size()) G[0].push_back(dfs(p, 1));     bfs();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double C = 1e6;   struct cir {     int x, y, z;   } a[5];   int disf(cir x, cir y) {     return (x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y);   }   bool kcr(cir x, cir y) {     return disf(x, y) <= (x.z + y.z) * (x.z + y.z) &&            disf(x, y) >= (x.z - y.z) * (x.z - y.z);   }   bool cr(cir x, cir y) {     return disf(x, y) < (x.z + y.z) * (x.z + y.z) &&            disf(x, y) > (x.z - y.z) * (x.z - y.z);   }   bool in(long double x, long double y, cir _) {     return (_.x - x) * (_.x - x) + (_.y - y) * (_.y - y) < _.z * _.z;   }   pair<pair<long double, long double>, pair<long double, long double> > check(       int i, int j) {     bool flag = 0;     if (a[i].y == a[j].y) flag = 1, swap(a[i].x, a[i].y), swap(a[j].x, a[j].y);     long double k = 1. * (a[i].x - a[j].x) / (a[j].y - a[i].y);     long double g = (a[i].z * a[i].z - a[j].z * a[j].z - a[i].x * a[i].x +                      a[j].x * a[j].x - a[i].y * a[i].y + a[j].y * a[j].y) /                     (2. * (a[j].y - a[i].y));     long double aa = k * k + 1;     long double bb = 2 * ((g - a[i].y) * k - a[i].x);     long double cc =         a[i].x * a[i].x + (g - a[i].y) * (g - a[i].y) - a[i].z * a[i].z;     long double x1 =         (-bb - sqrt(max(bb * bb - 4 * aa * cc, (long double)0))) / (2 * aa);     long double x2 =         (-bb + sqrt(max(bb * bb - 4 * aa * cc, (long double)0))) / (2 * aa);     long double y1 = k * x1 + g;     long double y2 = k * x2 + g;     if (flag)       swap(x1, y1), swap(x2, y2), swap(a[i].x, a[i].y), swap(a[j].x, a[j].y);     x1 = (round(x1 * C)) / C;     x2 = (round(x2 * C)) / C;     y1 = (round(y1 * C)) / C;     y2 = (round(y2 * C)) / C;     return pair<pair<long double, long double>, pair<long double, long double> >(         pair<long double, long double>(x1, y1),         pair<long double, long double>(x2, y2));   }   int main() {     int n;     cin >> n;     if (n == 1)       return cout << 2, 0;     else if (n == 2) {       for (int i = 1; i <= 2; ++i) cin >> a[i].x >> a[i].y >> a[i].z;       if (cr(a[1], a[2]))         return cout << 4, 0;       else         return cout << 3, 0;     }     for (int i = 1; i <= 3; ++i) cin >> a[i].x >> a[i].y >> a[i].z;     set<pair<long double, long double> > g[5];     int c = 3;     for (int i = 1; i <= 3; ++i)       for (int j = i + 1; j <= 3; ++j)         if (kcr(a[i], a[j])) {           pair<pair<long double, long double>, pair<long double, long double> >               t = check(i, j);           g[0].insert(t.first);           g[0].insert(t.second);           g[i].insert(t.first);           g[i].insert(t.second);           g[j].insert(t.first);           g[j].insert(t.second);           if (c > 1) --c;         }     int e = 0, v = g[0].size() + 6;     for (int i = 1; i <= 3; ++i) e += g[i].size() + 2;     cout << e - v + c + 1;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int arr[n];     int ar[m];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int j = 0; j < m; j++) {       cin >> ar[j];     }     for (int k = 0; k < n; k++) {       for (int l = 0; l < m; l++) {         if (ar[l] == arr[k]) {           cout << arr[k] <<    ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(0);     long long n, h, k;     cin >> n >> h >> k;     vector<long long> mas(n);     for (int i = 0; i < n; i++) cin >> mas[i];     long long time = 0, currVolume = 0;     bool have = false;     for (int i = 0; i < n; i++) {       long long top = mas[i];       if (currVolume + top <= h)         currVolume += top;       else {         time += (currVolume / k);         if (currVolume < k) {           ++time;           currVolume = 0;         }         currVolume = currVolume % k;         if (currVolume + top <= h) {           currVolume += top;         } else {           ++time;           currVolume = top;         }       }     }     if (currVolume % k != 0) ++time;     time += currVolume / k;     cout << time;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   char s[200010], p[200010];   int a[200010], n, t;   bool ok(int len) {     int i = 1, j = 1;     while (i <= n) {       if (a[i] <= len) {         i++;         continue;       }       if (s[i] == p[j]) {         i++;         j++;       } else {         i++;       }       if (j == t + 1) return true;     }     return false;   }   int main() {     scanf( %s , &s[1]);     n = strlen(s + 1);     scanf( %s , &p[1]);     t = strlen(p + 1);     int l = 0, r = n, ans;     for (int i = 1; i <= n; i++) {       int b;       scanf( %d , &b);       a[b] = i;     }     while (l + 1 < r) {       int m = (l + r) >> 1;       if (ok(m)) {         l = m;       } else {         r = m;       }     }     printf( %d n , l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, p =    ;     cin >> s;     int i, j = 0, f = 0, start, end;     for (i = s.size() - 1; i >= 0 && f == 0; i--) {       if (s[i] !=  0 ) {         end = i;         f = 1;       }     }     f = 0;     for (i = 0; i < s.size() && f == 0; i++) {       if (s[i] !=  0 ) {         start = i;         f = 1;       }     }     j = 0;     for (i = end; i >= start; i--) {       p[j] = s[i];       j++;     }     j = 0;     f = 0;     for (i = start; i <= end && f == 0; i++) {       if (p[j] != s[i])         f = 1;       else         j++;     }     if (f)       cout <<  NO  << endl;     else       cout <<  YES  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 15;   map<pair<int, int>, int> H;   int t[N];   vector<int> adj[N];   int sum[N];   void update(int x, int add) {     if (x == 0) return;     while (x < N) sum[x] += add, x += x & (-x);   }   int q(int x) {     int ret = 0;     while (x) ret += sum[x], x = x & (x - 1);     return ret;   }   int main() {     int n, i, p, x, y, tot, j;     scanf( %d%d , &n, &p);     for (i = 0; i < n; ++i) {       scanf( %d%d , &x, &y);       if (x > y) swap(x, y);       ++t[x], ++t[y];       if (!H.count(make_pair(x, y))) adj[x].push_back(y);       ++H[make_pair(x, y)];     }     long long ret = 0;     for (i = 1; i <= n; ++i) update(t[i], 1);     for (i = 1; i <= n; ++i) {       update(t[i], -1);       if (t[i] >= p)         ret += n - i;       else {         tot = q(n) - q(p - t[i] - 1);         ret += tot;         for (j = 0; j < adj[i].size(); ++j) {           x = adj[i][j];           if (t[i] + t[x] < p) continue;           y = H[make_pair(i, x)];           if (t[x] + t[i] - y < p) --ret;         }       }     }     cout << ret << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int ans[100100];   struct by {     int l, r, id, i, num;   } a[100100 * 2];   bool cmp(by a, by b) {     if (a.r != b.r) return a.r < b.r;     return a.id < b.id;   }   struct byy {     int i, l;     byy() {}     byy(int i, int l) : i(i), l(l) {}     bool operator<(const byy &rhs) const {       if (l != rhs.l) return l < rhs.l;       return i < rhs.i;     }   };   set<byy> s;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &a[i].l, &a[i].r);       a[i].i = i;       a[i].id = 0;     }     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &a[i + n].l, &a[i + n].r, &a[i + n].num);       a[i + n].i = i;       a[i + n].id = 1;     }     sort(a + 1, a + m + n + 1, cmp);     int cnt = 0;     for (int i = 1; i <= m + n; i++) {       if (!a[i].id)         s.insert(byy(a[i].i, a[i].l));       else {         while (s.size() && a[i].num--) {           set<byy>::iterator p = s.lower_bound(byy(0, a[i].l));           if (p == s.end()) break;           byy now = *p;           s.erase(p);           ans[now.i] = a[i].i;           cnt++;         }       }     }     if (cnt == n) {       printf( YES n );       for (int i = 1; i <= n; i++) printf( %d  , ans[i]);       printf(  n );     } else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = 2 * acos(0);   unsigned long long int binpow(unsigned long long int b,                                 unsigned long long int n) {     if (n == 0) return 1;     if (n == 1) return b;     if (n & 1)       return binpow(b, n - 1) * b;     else       return binpow(b * b, n / 2);   }   long long int bigmod(long long int b, long long int n, long long int m) {     if (n == 0) return 1;     if (n % 2 == 0) {       long long int x = bigmod(b, n / 2, m) % m;       return (x * x) % m;     } else       return ((b % m) * bigmod(b, n - 1, m) % m) % m;   }   void start() {}   long long int to_num(string &s) {     stringstream second;     second << s;     long long int n;     second >> n;     return n;   }   long long int get(long long int n) {     long long int s = 0;     while (n) {       s += (n % 10);       n /= 10;     }     return s;   }   void solve() {     long long int n, cn = 0;     cin >> n;     string s = to_string(n), tmp =   ;     for (long long int i = 0; i < s.size() - 1; i++) {       tmp +=  9 ;     }     if (n < 10) {       cout << n <<   n ;       return;     }     cn = (s.size() - 1) * 9;     long long int left = n - to_num(tmp);     cn += get(left);     cout << cn <<   n ;   }   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     start();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 1;   const long long INF = 1e9 + 7;   const long long inf = 1e18;   vector<long long> adj[N];   long long vis[N];   long long ans[N];   long long ct;   void dfs(long long node) {     vis[node] = ct;     ans[ct]++;     for (auto it : adj[node]) {       if (!vis[it]) {         dfs(it);       }     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long x;       cin >> x;       long long count = 0, temp;       while (x--) {         long long a;         cin >> a;         if (count == 0) {           temp = a;         }         if (count > 0) {           adj[temp].push_back(a);           adj[a].push_back(temp);           temp = a;         }         count++;       }       count = 0;     }     for (long long i = 1; i <= n; i++) {       if (!vis[i]) {         ct++;         dfs(i);       }       cout << ans[vis[i]] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 30;   const int maxn = 100007;   int n, m, T;   int top, k[10004], ans[maxn];   struct student {     int t, x, i;     void get(int l) {       scanf( %d%d , &t, &x);       i = l;     }     bool operator<(const student &b) const {       if (t == b.t) return x < b.x;       return t < b.t;     }   } s[maxn], bus[maxn];   inline bool cmp(const student &a, const student &b) { return a.x < b.x; }   void geton(int &st) {     top = 0;     memset(k, 0, sizeof(k));     for (int rest = m; st <= n && rest; st++, rest--) {       bus[++top] = s[st];       k[s[st].x]++;       if (s[st].t > T) T = s[st].t;     }   }   void getoff() {     int t1 = 0, t2 = 0;     sort(bus + 1, bus + top + 1, cmp);     for (int i = 1; i <= top; i++) {       if (bus[i].x != bus[i - 1].x) {         T += t1;         t1 = k[bus[i].x] / 2 + 1;       }       ans[bus[i].i] = bus[i].x + T;     }     T += bus[top].x * 2 + t1;   }   int main() {     int st = 1, ti;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) s[i].get(i);     sort(s + 1, s + n + 1);     while (st <= n) {       geton(st);       getoff();     }     for (int i = 1; i <= n - 1; i++) printf( %d  , ans[i]);     printf( %d n , ans[n]);     return 0;   }


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


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   inline long long read() {     char c = getchar();     long long x = 0;     bool f = 0;     for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     if (f) x = -x;     return x;   }   long long res, n, m, k;   vector<pair<long long, long long> > e[200005];   vector<long long> v[13];   const long long b1 = 19491001;   unsigned long long pw[200005], sumn, sum[13][13], qwq;   void dfs(long long u) {     if (u == k + 1) {       res += (qwq == sumn);       return;     }     for (register long long i = (0); i <= (u - 1); ++i) {       qwq += sum[u][i];       dfs(u + 1);       qwq -= sum[u][i];     }   }   signed main() {     n = read(), m = read(), k = read();     pw[0] = 1;     for (register long long i = (1); i <= (n); ++i)       pw[i] = pw[i - 1] * b1, sumn += pw[i];     for (register long long i = (1); i <= (m); ++i) {       long long u = read(), v = read(), w = read();       e[u].push_back(make_pair(w, v));     }     for (register long long i = (1); i <= (n); ++i)       sort(e[i].begin(), e[i].end()), v[e[i].size()].push_back(i);     for (register long long i = (1); i <= (k); ++i)       for (register long long j = (0); j <= (i - 1); ++j) {         unsigned long long now = 0;         for (long long p = 0; p < v[i].size(); ++p)           now += pw[e[v[i][p]][j].second];         sum[i][j] = now;       }     dfs(1);     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const long long MAX = 1e9 + 7;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int a[n];     set<int> s;     for (int i = 0; i < n; i++) s.insert(i + 1);     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i]) s.erase(a[i]);     }     int prev = -1;     for (int i = 0; i < n; i++) {       if (a[i] == 0) {         auto it = s.begin();         while (it != s.end() && *it == (i + 1)) it++;         if (it == s.end()) {           it = s.begin();           a[i] = a[prev];           a[prev] = *it;         } else {           a[i] = *it;           s.erase(it);           prev = i;         }       }     }     for (int i = 0; i < n; i++) {       cout << a[i] <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int box[300010];   bool check(int times) {     int mi = 0;     for (int i = 0; i < n; ++i) {       if (box[i] + times < m) {         if (mi > box[i] + times) return false;         mi = max(mi, box[i]);       } else {         if (mi >= box[i])           continue;         else if (box[i] + times - m >= mi)           continue;         else           mi = box[i];       }     }     return true;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %d , &box[i]);     }     int l = 0, r = m, mid, ans = -1;     while (l <= r) {       mid = (l + r) / 2;       if (check(mid)) {         ans = mid;         r = mid - 1;       } else {         l = mid + 1;       }     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     for (int i = 0; i < q; i++) {       int n;       cin >> n;       int ans = 0;       int ct_4 = n / 4;       int rem = n % 4;       if (rem == 1) {         ct_4 -= 2;         ans = ct_4 + 1;       } else if (rem == 2) {         ct_4 -= 1;         ans = ct_4 + 1;       } else if (rem == 3) {         ct_4 -= 3;         ans = ct_4 + 2;       } else {         ans = ct_4;       }       if (ct_4 < 0) {         cout << -1 << endl;       } else {         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int ri() {     int x;     scanf( %d , &x);     return x;   }   template <typename T>   inline bool smax(T &a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <typename T>   inline bool smin(T &a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   const int maxn = 30005;   int n, mod, m = 0;   int a[maxn], id[maxn];   int fib[maxn];   struct seg {     int l, r, d, off;     int x0, x1;     seg *ls, *rs;     seg(int l_, int r_)         : l(l_), r(r_), d(0), off(0), ls(NULL), rs(NULL), x0(0), x1(0) {       if (l < r) {         int mid = (l + r) >> 1;         ls = new seg(l, mid);         rs = new seg(mid + 1, r);       }     }     inline void shift(int x) {       off += x;       d += x;       if (x > 0) {         int tmp = (x0 * fib[x - 1] + x1 * fib[x]) % mod;         x1 = (x0 * fib[x] + x1 * fib[x + 1]) % mod;         x0 = tmp;       } else if (x < 0) {         x = -x;         if (x % 2 == 0) {           int tmp = (x0 * fib[x + 1] - x1 * fib[x]);           x1 = (x1 * fib[x - 1] - x0 * fib[x]);           x0 = tmp;         } else {           int tmp = (x1 * fib[x] - x0 * fib[x + 1]);           x1 = (x0 * fib[x] - x1 * fib[x - 1]);           x0 = tmp;         }         x0 %= mod;         if (x0 < 0) x0 += mod;         x1 %= mod;         if (x1 < 0) x1 += mod;       }     }     inline void down() {       if (d == 0) return;       if (ls) ls->shift(d);       if (rs) rs->shift(d);       d = 0;     }     void add(int pos, int x) {       if (l == r) {         x0 = (x0 + fib[off] * x) % mod;         x1 = (x1 + fib[off + 1] * x) % mod;         return;       }       down();       int mid = (l + r) >> 1;       if (mid < pos) {         rs->add(pos, x);       } else {         ls->add(pos, x);       }       x0 = (ls->x0 + rs->x0);       x1 = (ls->x1 + rs->x1);       if (x0 >= mod) x0 -= mod;       if (x1 >= mod) x1 -= mod;       off = ls->off;     }     void move(int x, int lo, int hi) {       if (x == 0) return;       if (lo <= l && r <= hi) {         shift(x);         return;       }       down();       int mid = (l + r) >> 1;       if (lo <= mid) ls->move(x, lo, hi);       if (hi > mid) rs->move(x, lo, hi);       x0 = (ls->x0 + rs->x0);       x1 = (ls->x1 + rs->x1);       if (x0 >= mod) x0 -= mod;       if (x1 >= mod) x1 -= mod;       off = ls->off;     }   } * tree;   struct query {     int id, l, r;   } q[30000];   int res[30000];   int cnt[maxn];   inline void insert(int x) {     if ((++cnt[id[x]]) == 1) {       tree->move(1, id[x], m);       tree->add(id[x], a[x] % mod);     }   }   inline void remove(int x) {     if ((--cnt[id[x]]) == 0) {       tree->add(id[x], -a[x] % mod);       tree->move(-1, id[x], m);     }   }   int main() {     scanf( %d%d , &n, &mod);     vector<pair<int, int> > v;     for (int i = 0; i < (n); i++) {       scanf( %d , a + i);       v.push_back(pair<int, int>(a[i], i));     }     sort(v.begin(), v.end());     id[v[0].second] = 0;     for (int i = (1); i < (v.size()); i++)       if (v[i].first != v[i - 1].first) {         id[v[i].second] = ++m;       } else {         id[v[i].second] = m;       }     fib[1] = fib[2] = 1;     for (int i = (3); i < (maxn); i++) fib[i] = (fib[i - 1] + fib[i - 2]) % mod;     int Q = ri();     for (int i = 0; i < (Q); i++) {       q[i].id = i;       scanf( %d%d , &q[i].l, &q[i].r);       q[i].l--;       q[i].r--;     }     const int sqr = 300;     sort(q, q + Q, [](query a, query b) {       return a.l / sqr == b.l / sqr ? (((a.l / sqr) & 1) ? a.r > b.r : a.r < b.r)                                     : a.l / sqr < b.l / sqr;     });     int L = q[0].l, R = q[0].l - 1;     tree = new seg(0, m);     for (int i = 0; i < (Q); i++) {       while (R < q[i].r) insert(++R);       while (L > q[i].l) insert(--L);       while (R > q[i].r) remove(R--);       while (L < q[i].l) remove(L++);       res[q[i].id] = tree->x0;     }     for (int i = 0; i < (Q); i++) printf( %d n , (res[i] % mod + mod) % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     cout.tie(0);     ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int cntR = 0, cntS = 0, cntP = 0;       for (int i = 0; i < s.size(); ++i) {         if (s[i] ==  R )           cntR += 1;         else if (s[i] ==  S )           cntS += 1;         else           cntP += 1;       }       int n = s.size();       if (cntR >= cntS && cntR >= cntP) {         cout << string(n,  P ) << endl;       } else if (cntS >= cntR && cntS >= cntP) {         cout << string(n,  R ) << endl;       } else         cout << string(n,  S ) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long red[210];   long long green[210];   long long blue[210];   long long dp[210][210][210];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     int r, g, b;     cin >> r >> g >> b;     for (int i = 1; i <= r; i++) cin >> red[i];     for (int i = 1; i <= g; i++) cin >> green[i];     for (int i = 1; i <= b; i++) cin >> blue[i];     sort(red, red + r + 1);     sort(green, green + g + 1);     sort(blue, blue + b + 1);     for (int i = 0; i <= r; i++) {       for (int j = 0; j <= g; j++) {         for (int k = 0; k <= b; k++) {           if (i > 0 && j > 0)             dp[i][j][k] =                 max(dp[i][j][k], dp[i - 1][j - 1][k] + red[i] * green[j]);           if (j > 0 && k > 0)             dp[i][j][k] =                 max(dp[i][j][k], dp[i][j - 1][k - 1] + green[j] * blue[k]);           if (i > 0 && k > 0)             dp[i][j][k] =                 max(dp[i][j][k], dp[i - 1][j][k - 1] + red[i] * blue[k]);         }       }     }     cout << dp[r][g][b] <<   n ;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, b, p;     cin >> n >> b >> p;     int a[10 + n], useP = 0, i, useB = 0;     for (i = 0; i < n; i++) {       cin >> a[i];     }     for (i = 0; i < n; i++) {       if (a[i] == 1)         useB++;       else {         if ((p - useP) <= 0)           useB++;         else           useP++;       }     }     b -= useB;     p -= useP;     if (b > p) {       if (p < 0)         cout << abs(p) << endl;       else         cout <<  0  << endl;     } else {       if (b < 0)         cout << abs(b) << endl;       else         cout <<  0  << endl;     }     return 0;   }


#include <bits/stdc++.h>   char s[10000];   int main() {     int n;     scanf( %d , &n);     scanf( %s , s);     int t, d;     bool succ = false;     for (t = 0; t < n && !succ; ++t) {       for (d = 1; t + 4 * d < n; ++d) {         if (s[t] ==  *  && s[t + d] ==  *  && s[t + d + d] ==  *  &&             s[t + 3 * d] ==  *  && s[t + 4 * d] ==  * ) {           succ = true;           break;         }       }     }     if (succ)       printf( yes n );     else       printf( no n );     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const long long INF = 4e18 + 5;   const int inf = 1e9 + 5;   const int maxn = 1e6 + 5;   int h, m, a;   int MAIN() {     scanf( %d:%d , &h, &m);     scanf( %d , &a);     int tot = h * 60 + m + a;     tot %= (24 * 60);     printf( %02d:%02d n , tot / 60, tot % 60);     return 0;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     int ret = MAIN();     return ret;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<long> v(n);     long mul = 1;     for (int i = 0; i < n; ++i) cin >> v[i];     if (n > 1000) {       cout <<  0 n ;       return 0;     }     for (int i = 0; i < n - 1; ++i)       for (int j = i + 1; j < n; ++j)         mul = ((abs((v[j] - v[i])) % m) * (mul % m)) % m;     cout << mul;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e3 + 9;   bool p[N][N];   priority_queue<pair<pair<int, int>, pair<int, int> > > q;   int cu;   int n, m, si, sj, ml, mr, a, b, ti, tj;   char c;   bool valid(int i, int j) {     return i > 0 && i <= n && j > 0 && j <= m && p[i][j];   }   void add(int x, int y, int i, int j) {     p[i][j] = 0;     ++cu;     q.push({{x, y}, {i, j}});   }   int main() {     scanf( %d %d %d %d %d %d , &n, &m, &si, &sj, &mr, &ml);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         p[i][j] = ((cin >> c, c) ==  .  ? true : false);     add(0, 0, si, sj);     auto cr = q.top();     while (!q.empty()) {       cr = q.top();       a = -cr.first.first;       b = -cr.first.second;       ti = cr.second.first;       tj = cr.second.second;       q.pop();       if (valid(ti + 1, tj)) add(-a, -b, ti + 1, tj);       if (valid(ti - 1, tj)) add(-a, -b, ti - 1, tj);       if (valid(ti, tj + 1) && b + 1 <= ml) add(-a, -(b + 1), ti, tj + 1);       if (valid(ti, tj - 1) && a + 1 <= mr) add(-(a + 1), -b, ti, tj - 1);     }     printf( %d n , cu);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t, n, a, b, x, l, m, e, d, s;     cin >> t;     while (t--) {       cin >> n >> x >> a >> b;       if (a > b) {         l = a;         s = b;       } else {         l = b;         s = a;       }       d = n - l;       if (x <= d) {         cout << l + x - s <<   n ;         continue;       } else         m = x - d;       e = s - 1;       if (m >= e) {         cout << n - 1 <<   n ;         continue;       } else {         s = s - m;         cout << n - s <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     for (int i = 0; i < s.length(); i++)       if (s[i] >  4 ) s[i] =  9  - s[i] +  0 ;     if (s[0] ==  0 ) s[0] =  9 ;     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const nmax = 1000;   int const modulo = 7340033;   int dp[40][5 + nmax];   int dp2[40][5 + nmax];   int main() {     dp[0][0] = 1;     dp[1][1] = 1;     dp[1][0] = 1;     for (int i = 2; i <= 32; i++) {       dp[i][0] = 1;       for (int j = 0; j <= nmax; j++)         for (int h = 0; h <= nmax - j; h++) {           dp2[i][j + h] += 1LL * dp[i - 1][j] * dp[i - 1][h] % modulo;           if (modulo <= dp2[i][j + h]) dp2[i][j + h] -= modulo;         }       for (int j = 0; j <= nmax; j++)         for (int h = 0; h <= nmax - j; h++) {           dp[i][1 + j + h] += 1LL * dp2[i][j] * dp2[i][h] % modulo;           if (modulo <= dp[i][1 + j + h]) dp[i][1 + j + h] -= modulo;         }     }     int q;     cin >> q;     for (int testcase = 1; testcase <= q; testcase++) {       int n, k;       cin >> n >> k;       int p = 0;       while (1 < n && n % 2 == 1) {         p++;         n /= 2;       }       cout << dp[p][k] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int d = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) {       d = (d << 3) + (d << 1) + c -  0 ;       c = getchar();     }     return d;   }   const int N = 1e5 + 5;   const long long INF = 1e14;   int n, m, k;   int from[N * 2], ver[N * 2], nxt[N * 2], edge[N * 2], head[N], cnt;   int v[N * 2], h[N], nx[N * 2], cnt1;   long long dis[N][2], ed[N * 2];   int po[N];   bool pl[N];   inline void add(int x, int y, int z) {     from[++cnt] = x, ver[cnt] = y, edge[cnt] = z, nxt[cnt] = head[x],     head[x] = cnt;   }   void spfa() {     for (int i = 1; i <= n; i++) dis[i][0] = dis[i][1] = INF;     queue<int> q;     for (int i = 1; i <= k; i++) {       q.push(po[i]);       pl[po[i]] = true;       dis[po[i]][0] = po[i];       dis[po[i]][1] = 0;     }     while (!q.empty()) {       int x = q.front();       q.pop();       pl[x] = false;       for (int i = head[x]; i; i = nxt[i]) {         int y = ver[i];         if (dis[y][1] > dis[x][1] + edge[i]) {           dis[y][1] = dis[x][1] + edge[i];           dis[y][0] = dis[x][0];           if (!pl[y]) {             q.push(y);             pl[y] = true;           }         }       }     }   }   long long prim() {     long long ans = dis[1][1], nm = dis[1][0];     int tot = 1;     priority_queue<pair<long long, int>, vector<pair<long long, int> >,                    greater<pair<long long, int> > >         q;     pl[nm] = true;     for (int i = h[nm]; i; i = nx[i]) q.push(make_pair(ed[i], v[i]));     while (tot < k) {       while (pl[q.top().second]) q.pop();       int x = q.top().second;       long long len = q.top().first;       pl[x] = true;       ans += len;       tot++;       for (int i = h[x]; i; i = nx[i]) q.push(make_pair(ed[i], v[i]));     }     return ans;   }   int main() {     n = read(), m = read();     for (int i = 1; i <= m; i++) {       int u = read(), v = read(), w = read();       add(u, v, w);       add(v, u, w);     }     k = read();     for (int i = 1; i <= k; i++) po[i] = read();     spfa();     for (int i = 1; i <= cnt; i += 2) {       int x = from[i], y = ver[i];       v[++cnt1] = dis[y][0], nx[cnt1] = h[dis[x][0]], h[dis[x][0]] = cnt1;       ed[cnt1] = dis[x][1] + edge[i] + dis[y][1];       v[++cnt1] = dis[x][0], nx[cnt1] = h[dis[y][0]], h[dis[y][0]] = cnt1;       ed[cnt1] = dis[y][1] + edge[i] + dis[x][1];     }     cout << prim();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double sum;     int n, m, k, i;     while (scanf( %d %d %d , &n, &m, &k) == 3) {       sum = 1;       if (k + n < m) {         printf( 0 n );         continue;       } else {         for (i = 0; i <= k; i++) {           sum *= (m - i);           sum /= (n + i + 1);         }         printf( %.6lf n , 1 - sum);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N, K, C;     int fiestas[1000];     int i, j, t;     scanf( %d%d%d , &N, &K, &C);     for (i = 0; i < C; i++) scanf( %d , &fiestas[i]);     sort(fiestas, fiestas + C);     fiestas[C] = (1 << 30);     i = 0;     t = 0;     int res = 0;     while (t <= N) {       t = min(t + K, fiestas[i]);       if (t == fiestas[i]) i++;       if (t <= N) res++;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct vahag {     int hor, ver;   };   vahag a[25][25];   const int N = 100005;   int n, m, i, j, k, q, s, w, v, ans;   string t, p;   int bfs(int i, int j) {     int qanak = 0;     bool mark[25][25] = {0};     queue<int> xx, yy;     xx.push(i);     yy.push(j);     mark[i][j] = 1;     while (!xx.empty()) {       qanak++;       int x = xx.front();       int y = yy.front();       if (x + a[x][y].ver >= 1 && x + a[x][y].ver <= n &&           mark[x + a[x][y].ver][y] == 0) {         mark[x + a[x][y].ver][y] = 1;         xx.push(x + a[x][y].ver);         yy.push(y);       }       if (y + a[x][y].hor >= 1 && y + a[x][y].hor <= m &&           mark[x][y + a[x][y].hor] == 0) {         mark[x][y + a[x][y].hor] = 1;         xx.push(x);         yy.push(y + a[x][y].hor);       }       xx.pop();       yy.pop();     }     return qanak;   }   int main() {     cin >> n >> m;     cin >> t >> p;     for (i = 0; i < t.length(); i++) {       if (t[i] ==  < )         for (j = 0; j < p.length(); j++) a[i + 1][j + 1].hor = -1;       else         for (j = 0; j < p.length(); j++) a[i + 1][j + 1].hor = 1;     }     for (j = 0; j < p.length(); j++) {       if (p[j] ==  ^ )         for (i = 0; i < t.length(); i++) a[i + 1][j + 1].ver = -1;       else         for (i = 0; i < t.length(); i++) a[i + 1][j + 1].ver = 1;     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         int pop = bfs(i, j);         if (pop != n * m) {           cout <<  NO  << endl;           return 0;         }       }     }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int containsDigit(long long int number, long long int digit) {     while (number != 0) {       int curr_digit = number % 10;       if (curr_digit == digit) return 1;       number /= 10;     }     return 0;   }   long long int soltn(long long int x, long long int n) {     if (x >= 0)       return x % n;     else       return n + x % n;   }   long long int bin_srch(long long int L[], long long int N, long long int item) {     long long int flag = -2;     int l = 0, u = N - 1, m;     while (l <= u) {       m = (l + u) / 2;       if (item == L[m]) {         flag = m - 1;         break;       } else if (item > L[m])         l = m - 1;       else         u = m + 1;     }     return flag;   }   long long int modExp(long long int b, long long int p) {     long long int res = 1;     while (p > 0) {       if (p & 1) {         res = (res * b) % 1000000007;       }       b = (b * b) % 1000000007;       p >>= 1;     }     return res;   }   long long int properdiv(long long int x, long long int y) {     if (x % y == 0)       return x / y;     else       return x / y + 1;   }   long long int coda(long long int n, long long int d) {     long long int count = 0;     while (n != 0) {       if (n % 10 == d) count++;       n /= 10;     }     return count;   }   long long int mdls(long long int x) { return max(x, -x); }   int main() {     long long int i, j, k, N;     cin >> N;     string s;     cin >> s;     long long int z = 0, e = 0, n = 0, r = 0, o = 0;     for (long long int i = 0; i < N; i++) {       if (s[i] ==  z )         z++;       else if (s[i] ==  e )         e++;       else if (s[i] ==  r )         r++;       else if (s[i] ==  o )         o++;       else if (s[i] ==  n )         n++;     }     long long int one = min(min(o, n), e);     e = e - min(min(o, n), e);     o = o - min(min(o, n), e);     n = n - min(min(o, n), e);     long long int zero = min(min(z, e), min(r, o));     for (long long int i = 0; i < one; i++) cout << 1 <<    ;     for (long long int i = 0; i < zero; i++) cout << 0 <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   multiset<long long> s[200004];   long long a[200005];   long long su[200005];   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long n, k;     cin >> n >> k;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     long long x;     for (long long i = 0; i < n; i++) {       x = 0;       while (true) {         s[a[i]].insert(x);         su[a[i]] += x;         if (s[a[i]].size() > k) {           set<long long>::iterator pointer = s[a[i]].end();           pointer--;           su[a[i]] -= *pointer;           s[a[i]].erase(pointer);         }         if (a[i] == 0) break;         a[i] /= 2;         x++;       }     }     long long minn = 1e9;     for (long long i = 0; i < 200005; i++) {       if (s[i].size() == k) {         minn = min(minn, su[i]);       }     }     cout << minn;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long q, n, t1, t2, t[200005];   int main() {     cin >> q;     while (q--) {       cin >> n;       for (int i = 0; i < n + 1; ++i) t[i] = 0;       for (int i = 0; i < n; ++i) cin >> t1, ++t[t1];       sort(t, t + n + 1);       reverse(t, t + n + 1);       long long i = 1, tp = t[0], u = t[0];       while (tp > 0 && i < n + 1) {         tp = min(tp - 1, t[i]);         u += tp;         ++i;       }       cout << u << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int tc, cs = 1;     scanf( %lld , &tc);     while (tc--) {       long long a, b, c, d;       scanf( %lld %lld , &a, &b);       scanf( %lld %lld , &c, &d);       if ((b - a) % (c + d) == 0)         cout << (b - a) / (c + d) << endl;       else         cout << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a[200100];   int cnt[200100];   vector<int> res;   int main() {     int n;     scanf( %d , &n);     int q;     for (int i = 1; i <= n; i++) {       scanf( %d , &q);       a[q].push_back(i);     }     int pos = 0;     while (true) {       if (cnt[pos] < a[pos].size()) {         res.push_back(a[pos][cnt[pos]]);         cnt[pos]++;         pos++;       } else         pos -= 3;       if (pos < 0) break;     }     if (res.size() != n) {       puts( Impossible );     } else {       puts( Possible );       for (int i = 0; i < n; i++) {         printf( %d  , res[i]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e9 + 7;   long long int h[200009], a[200009];   int main() {     long long int n, m, i, b, j, c, d, x, y, z, k, sum = 0, l, r = 1;     vector<long long int> v;     vector<long long int>::iterator it;     cin >> n;     cout << (n / 2) + 1;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200000 + 77, LOG = 32;   int T, n, a[N], tim = 1;   int dp[N * LOG], is[N * LOG], le[N * LOG], ri[N * LOG];   inline void Add(int x) {     int cur = 1;     is[cur] = 1;     for (int i = 29; i >= 0; --i) {       if ((x >> i) & 1) {         if (ri[cur] == 0) ri[cur] = ++tim;         cur = ri[cur];       } else {         if (le[cur] == 0) le[cur] = ++tim;         cur = le[cur];       }       is[cur] = 1;     }   }   void Solve(int v) {     if (v == 0) return;     dp[v] = is[v];     Solve(le[v]);     Solve(ri[v]);     dp[v] = max(max(dp[le[v]] + is[ri[v]], dp[ri[v]] + is[le[v]]), dp[v]);   }   inline void Test() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , a + i), Add(a[i]);     Solve(1);     printf( %d n , n - dp[1]);   }   int main() {     T = 1;     while (T--) Test();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long int md[500];   signed main() {     ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long int n;     cin >> n;     for (long long int i = 0; i < 500; i++) md[i] = -1;     for (long long int i = 0; i <= 8; i++) {       for (long long int j = 0; j <= 48; j++) {         long long int val = 4 * i + 9 * j;         val %= 49;         if (i + j > n) continue;         md[val] = max(md[val], n - i - j);       }     }     long long int ans = 0;     for (long long int i = 0; i < 500; i++) {       ans += md[i] + 1;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005, M = N * 4;   int n, q, a[N], t, l, r, k;   struct sgt {     long long p[M], s[M];     void B(int l, int r, int k, bool t) {       if (l == r) {         if (((l & 1) && !t) || (!(l & 1) && t))           p[k] = min(0, a[l] - a[l - 1]), s[k] = a[l] - a[l - 1];         return;       }       int mid = l + r >> 1;       B(l, mid, k << 1, t);       B(mid + 1, r, k << 1 | 1, t);       p[k] = min(p[k << 1], s[k << 1] + p[k << 1 | 1]);       s[k] = s[k << 1] + s[k << 1 | 1];     }     void C(int l, int r, int x, int y, int k) {       if (l == r) {         s[k] += y;         p[k] = min(0ll, s[k]);         return;       }       int mid = l + r >> 1;       if (x <= mid)         C(l, mid, x, y, k << 1);       else         C(mid + 1, r, x, y, k << 1 | 1);       p[k] = min(p[k << 1], s[k << 1] + p[k << 1 | 1]);       s[k] = s[k << 1] + s[k << 1 | 1];     }     pair<int, int> G(int l, int r, int x, int y, int k) {       if (l == x && y == r) return make_pair(p[k], s[k]);       int mid = l + r >> 1;       pair<int, int> L, R;       if (y <= mid) return G(l, mid, x, y, k << 1);       if (x > mid) return G(mid + 1, r, x, y, k << 1 | 1);       L = G(l, mid, x, mid, k << 1);       R = G(mid + 1, r, mid + 1, y, k << 1 | 1);       return make_pair(min(L.first, L.second + R.first), L.second + R.second);     }     void C(int x, int y) { C(1, n, x, y, 1); }     long long G(int x, int y) { return G(1, n, x, y, 1).first; }     long long sum(int x, int y) { return G(1, n, x, y, 1).second; }   };   struct s_t {     sgt p0, p1;     long long G(int x) { return p0.sum(1, x) + p1.sum(1, x); }     void B() {       p0.B(1, n, 1, 0);       p1.B(1, n, 1, 1);     }     void C(int x, int y) {       if (x > n)         return;       else if (x & 1)         p0.C(x, y);       else         p1.C(x, y);     }     bool c(int l, int r) {       long long val = G(l);       if (l == r) {         if (val > 1)           return 0;         else           return 1;       }       if (l & 1) {         long long tmp = G(r);         if (!(r & 1)) tmp = 0;         if (p1.sum(l + 1, r) != tmp) return 0;         if (p1.G(l + 1, r) < 0) return 0;         if (p0.G(l + 1, r) + val < 0) return 0;       } else {         long long tmp = G(r);         if (r & 1) tmp = 0;         if (p0.sum(l + 1, r) != tmp) return 0;         if (p0.G(l + 1, r) < 0) return 0;         if (p1.G(l + 1, r) + val < 0) return 0;       }       return 1;     }   } s;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), a[i]--;     s.B(), scanf( %d , &q);     for (int _ = 1; _ <= q; _++) {       scanf( %d , &t);       scanf( %d , &l);       scanf( %d , &r);       l++, r++;       if (t == 1)         scanf( %d , &k), s.C(l, k), s.C(r + 1, -k);       else         printf( %d n , s.c(l, r));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct UnionFind {     vector<int> data;     UnionFind(int sz) { data.assign(sz, -1); }     bool unite(int x, int y) {       x = find(x), y = find(y);       if (x == y) return (false);       if (data[x] > data[y]) swap(x, y);       data[x] += data[y];       data[y] = x;       return (true);     }     int find(int k) {       if (data[k] < 0) return (k);       return (data[k] = find(data[k]));     }     int size(int k) { return (-data[find(k)]); }   };   int N, M, D[300000];   int A[300000], B[300000];   map<pair<int, int>, int> conv;   vector<int> tree[300000];   vector<int> ans;   bool dfs(int idx, int par = -1) {     bool ret = D[idx] == 1;     for (auto &to : tree[idx]) {       if (to == par) continue;       auto p = dfs(to, idx);       if (p) ans.push_back(conv[minmax(idx, to)]);       ret ^= p;     }     return (ret);   }   int main() {     scanf( %d %d , &N, &M);     for (int i = 0; i < N; i++) {       scanf( %d , &D[i]);     }     for (int i = 0; i < M; i++) {       scanf( %d %d , &A[i], &B[i]);       --A[i], --B[i];       conv[minmax(A[i], B[i])] = i;     }     UnionFind uf(N);     int root = 0;     bool found = false;     for (int i = 0; i < M; i++) {       if (uf.unite(A[i], B[i])) {         tree[A[i]].push_back(B[i]);         tree[B[i]].push_back(A[i]);       }     }     for (int i = 0; i < N; i++) {       if (D[i] == -1) {         root = i;         found = true;       }     }     if (!dfs(root) || found) {       sort(begin(ans), end(ans));       cout << ans.size() << endl;       for (auto &idx : ans) cout << idx + 1 << endl;     } else {       cout << -1 << endl;     }   }


#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   using namespace std;   const int N = 1000100;   bool isp[N];   void prep() {     for (int(i) = (2); (i) < (N); ++(i)) isp[i] = true;     for (int i = 2; i * i < N; i++)       if (isp[i])         for (int j = i * i; j < N; j += i) isp[j] = false;   }   int a, b, k;   bool f(int len) {     if (len > b - a + 1) return false;     int np = 0;     for (int i = 0; i < len; i++) np += isp[a + i];     if (np < k) return false;     for (int i = a + len; i <= b; i++) {       np -= isp[i - len];       np += isp[i];       if (np < k) return false;     }     return true;   }   int main() {     ios::sync_with_stdio(false);     prep();     cin >> a >> b >> k;     int lo = 1, hi = b - a + 2;     while (lo != hi) {       int mi = (lo + hi) / 2;       if (f(mi))         hi = mi;       else         lo = mi + 1;     }     if (lo == 0 || lo > b - a + 1) lo = -1;     cout << lo <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace polynomials {   int const p = 998244353, G = 3;   int const N = (1 << 18) + 1;   int w[N], iv[N], r[N], last;   int mod(int x) { return x >= p ? x - p : x; }   int pw(int x, int y) {     int res = 1;     while (y) {       if (y & 1) res = 1ll * res * x % p;       x = 1ll * x * x % p;       y >>= 1;     }     return res;   }   void init(int n) {     int lim = 1;     while (lim < n) lim <<= 1;     iv[1] = 1;     for (int i = 2; i <= lim; i++) iv[i] = mod(p - 1ll * (p / i) * iv[p % i] % p);     for (int i = 1; i < lim; i <<= 1) {       int wn = pw(G, (p - 1) / (i << 1));       for (int j = 0, ww = 1; j < i; j++, ww = 1ll * ww * wn % p) w[i + j] = ww;     }   }   void ntt(vector<int> &f, int n, int op) {     f.resize(n);     for (int i = 1; i < n; i++)       r[i] = (r[i >> 1] >> 1) | ((i & 1) ? (n >> 1) : 0);     for (int i = 1; i < n; i++)       if (i < r[i]) swap(f[i], f[r[i]]);     for (int i = 1; i < n; i <<= 1)       for (int j = 0; j < n; j += i << 1)         for (int k = 0; k < i; k++) {           int x = f[j + k], y = 1ll * f[i + j + k] * w[i + k] % p;           f[j + k] = mod(x + y);           f[i + j + k] = mod(x - y + p);         }     if (op == -1) {       reverse(&f[1], &f[n]);       for (int i = 0; i < n; i++) f[i] = 1ll * f[i] * iv[n] % p;     }   }   }  // namespace polynomials   using namespace polynomials;   int g[50005], g0[50005], g1[50005], g2[50005], f0[50005], f1[50005], f2[50005];   vector<int> mul(vector<int> x, vector<int> y) {     int lim = 1, n = x.size() + y.size() - 1;     while (lim < n) lim <<= 1;     ntt(x, lim, 1), ntt(y, lim, 1);     for (int i = 0; i < lim; i++) x[i] = 1ull * x[i] * y[i] % p;     ntt(x, lim, -1);     x.resize(n);     return x;   }   void solve(int l, int r) {     if (l == r) return;     int mid = (l + r) >> 1;     solve(l, mid);     vector<int> x = mul(vector<int>(f0 + l, f0 + mid + 1),                         vector<int>(g0, g0 + r - l + 1)),                 y = mul(vector<int>(f1 + l, f1 + mid + 1),                         vector<int>(g1, g1 + r - l + 1)),                 z = mul(vector<int>(f2 + l, f2 + mid + 1),                         vector<int>(g2, g2 + r - l + 1)),                 t = mul(vector<int>(f1 + l, f1 + mid + 1),                         vector<int>(g2, g2 + r - l + 1)),                 h = mul(vector<int>(f0 + l, f0 + mid + 1),                         vector<int>(g1, g1 + r - l + 1));     for (int i = mid + 1; i <= r; i++)       f0[i] = (1ull * f0[i] + x[i - l] + y[i - l]) % p,       f1[i] = (1ull * f1[i] + t[i - l] + h[i - l]) % p,       f2[i] = (1ull * f2[i] + y[i - l] + z[i - l]) % p;     solve(mid + 1, r);   }   int main() {     int n;     scanf( %d , &n);     g[0] = g[2] = 1;     for (int i = 4; i <= n; i++) g[i] = mod(g[i - 2] + g[i - 4]);     for (int i = 1; i <= n; i++)       g0[i] = 1ll * (i - 1) * (i - 1) * g[i - 1] % p, f0[i] = g0[i];     for (int i = 2; i <= n; i++)       g1[i] = 1ll * (i - 1) * (i - 1) * g[i - 2] % p, f1[i] = g1[i];     for (int i = 3; i <= n; i++)       g2[i] = 1ll * (i - 1) * (i - 1) * g[i - 3] % p, f2[i] = g2[i];     init(n << 2);     solve(1, n);     int ans = 1ull * n * (g0[n] + g2[n]) % p;     for (int i = 2; i <= n - 2; i++)       ans = (ans + (1ull * g0[i] * f0[n - i] + 2ull * g1[i] * f1[n - i] +                     1ull * g2[i] * f2[n - i]) %                        p * i) %             p;     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1};   const int dc[] = {0, 1, 0, -1, 1, -1, -1, 1};   const double eps = 1e-9;   const int INF = 0x7FFFFFFF;   const long long INFLL = 0x7FFFFFFFFFFFFFFFLL;   const double pi = acos(-1);   template <class T>   T take(queue<T> &O) {     T tmp = O.front();     O.pop();     return tmp;   }   template <class T>   T take(stack<T> &O) {     T tmp = O.top();     O.pop();     return tmp;   }   template <class T>   T take(priority_queue<T> &O) {     T tmp = O.top();     O.pop();     return tmp;   }   inline void getint(int &num) { scanf( %d , &num); }   inline void getint(long long &num) { cin >> num; }   long long x[3], y[3];   long long cross() {     return (x[1] - x[0]) * (y[2] - y[0]) - (x[2] - x[0]) * (y[1] - y[0]);   }   int main() {     for (int(i) = (0), _t = (3); i < (_t); ++(i)) {       getint(x[i]);       getint(y[i]);     }     long long tmp = cross();     if (tmp == 0LL)       cout <<  TOWARDS ;     else if (tmp > 0LL)       cout <<  LEFT ;     else       cout <<  RIGHT ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[500000 + 10];   int n, t;   int mh;   int h, s;   int go(int mid) {     int num = mid;     int cnt = 0;     int en = mh;     int last;     if (mid < h) {       int u = 0;       for (int i = 0; i < n; i++) {         if (a[i] ==  S ) {           u++;           if (u == h - mid) {             en = max(en, i);             break;           }         }       }     }     for (int i = 0; i <= en; i++) {       cnt++;       if (a[i] ==  H ) {         num--;         if (num == -1) {           if (cnt + (en - i) * 2 <= t) return 1;           last = i;         }       } else if (a[i] ==  S ) {         num++;         if (num == 0) cnt += (i - last) * 2;       }     }     if (cnt <= t)       return 1;     else       return 0;   }   int main() {     while (scanf( %d %d , &n, &t) != EOF) {       scanf( %s , a);       for (int i = n - 1; i >= 0; i--) {         if (a[i] ==  H ) {           mh = i;           break;         }       }       if (mh + 1 > t) {         printf( -1 n );         continue;       }       for (int i = 0; i < n; i++) {         if (a[i] ==  H )           h++;         else if (a[i] ==  S )           s++;       }       int l = max(0, h - s), r = h;       int mid;       while (l < r) {         mid = (l + r) / 2;         if (go(mid))           r = mid;         else           l = mid + 1;       }       printf( %d n , l);     }   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> adj[1001];   int vis[1001];   int main() {     long long k, b, n, t, m = 1;     cin >> k >> b >> n >> t;     while (n >= 1 && k * m + b <= t) m = k * m + b, n--;     cout << n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[160][160];   int main() {     int n;     scanf( %d , &n);     dp[1][1] = 1;     dp[0][0] = 1;     for (int i = 2; i <= n; i++) {       for (int j = 0; j <= n; j++) {         if (j == 0)           dp[i][j] = dp[i - 2][j];         else           dp[i][j] = (dp[i - 2][j] + dp[i - 1][j - 1]) % 2;       }     }     cout << n << endl;     for (int i = 0; i <= n; i++) cout << dp[n][i] <<    ;     cout << endl;     cout << n - 1 << endl;     for (int i = 0; i <= n - 1; i++) cout << dp[n - 1][i] <<    ;     return 0;   }


#include <bits/stdc++.h>   namespace my_std {   using namespace std;   template <typename T>   inline void read(T &t) {     t = 0;     char f = 0, ch = getchar();     double d = 0.1;     while (ch >  9  || ch <  0 ) f |= (ch ==  - ), ch = getchar();     while (ch <=  9  && ch >=  0 ) t = t * 10 + ch - 48, ch = getchar();     if (ch ==  . ) {       ch = getchar();       while (ch <=  9  && ch >=  0 ) t += d * (ch ^ 48), d *= 0.1, ch = getchar();     }     t = (f ? -t : t);   }   template <typename T, typename... Args>   inline void read(T &t, Args &...args) {     read(t);     read(args...);   }   void file() {}   inline long long mul(long long a, long long b) {     long long d = (long long)(a * (double)b / 998244353 + 0.5);     long long ret = a * b - d * 998244353;     if (ret < 0) ret += 998244353;     return ret;   }   }  // namespace my_std   using namespace my_std;   long long fac[500500], _fac[500500];   long long ksm(long long x, long long y) {     long long ret;     for (ret = 1; y; y >>= 1, x = x * x % 998244353)       if (y & 1) ret = ret * x % 998244353;     return ret;   }   long long inv(long long x) { return ksm(x, 998244353 - 2); }   void init() {     fac[0] = _fac[0] = 1;     for (long long i = (1); i <= (500500 - 5); i++)       _fac[i] = inv(fac[i] = fac[i - 1] * i % 998244353);   }   const long long g = 3;   long long r[500500], limit;   void NTT(long long *a, long long type) {     for (long long i = (0); i <= (limit - 1); i++)       if (r[i] < i) swap(a[i], a[r[i]]);     for (long long mid = 1; mid < limit; mid <<= 1) {       long long Wn = ksm(g, (998244353 - 1) / mid >> 1);       if (type == -1) Wn = inv(Wn);       for (long long len = mid << 1, j = 0; j < limit; j += len) {         long long w = 1;         for (long long k = 0; k < mid; k++, w = 1ll * w * Wn % 998244353) {           long long x = a[j + k], y = 1ll * w * a[mid + j + k];           a[j + k] = (x + y + 998244353) % 998244353;           a[j + k + mid] = (x - y + 998244353) % 998244353;         }       }     }     if (type == -1) {       long long t = inv(limit);       for (long long i = (0); i <= (limit - 1); i++)         a[i] = (1ll * a[i] * t % 998244353 + 998244353) % 998244353;     }   }   void NTT(long long *a, long long *b, long long len) {     limit = 1;     long long l = -1;     while (limit <= len * 2) limit <<= 1, ++l;     for (long long i = (1); i <= (limit - 1); i++)       r[i] = (r[i >> 1] >> 1) | ((i & 1) << l);     for (long long i = (len); i <= (limit); i++) a[i] = b[i] = 0;     NTT(a, 1);     NTT(b, 1);     for (long long i = (0); i <= (limit); i++)       a[i] = 1ll * a[i] * b[i] % 998244353;     NTT(a, -1);   }   long long X[500500], a[500500], b[500500];   void work(long long len) {     if (len == 1) return (void)(X[1] = 1);     if (len & 1) {       work(len - 1);       X[len] = 0;       for (long long i = (len); i >= (1); i--)         (X[i] = X[i - 1] + 1ll * X[i] * (len - 1) % 998244353) %= 998244353;       return;     }     long long n = len >> 1;     work(n);     for (long long i = n, w = 1; i >= 0; i--, w = 1ll * w * n % 998244353)       a[i] = 1ll * w * _fac[n - i] % 998244353;     for (long long i = (0); i <= (n); i++) b[i] = fac[i] * X[i] % 998244353;     for (long long i = (n + 1); i <= (n << 2); i++) a[i] = b[i] = 0;     NTT(a, b, n + 1);     for (long long i = (0); i <= (n); i++)       a[i] = 1ll * a[i + n] * _fac[i] % 998244353;     for (long long i = (n + 1); i <= (limit); i++) a[i] = 0;     NTT(X, a, n + 1);   }   long long n, A, B;   signed main() {     file();     init();     read(n, A, B);     if (n == 1) return puts(A == B && A == 1 ?  1  :  0 ), 0;     work(n - 1);     cout << 1ll * X[A + B - 2] * fac[A + B - 2] % 998244353 * _fac[A - 1] %                 998244353 * _fac[B - 1] % 998244353;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, temp;     cin >> n;     map<int, int> a, b;     for (int i = 0; i < n; i++) {       cin >> temp;       a[temp]++;     }     for (int i = 0; i < n; i++) {       cin >> temp;       b[temp]++;     }     int ans = 0, sum = 0;     vector<int> bal(6);     for (int i = 1; i < 6; i++) {       if ((a[i] + b[i]) % 2) {         cout << -1;         return 0;       }       bal[i] = a[i] - b[i];       bal[i] /= 2;       sum += bal[i];       if (bal[i] > 0) ans += bal[i];     }     if (sum) {       cout << -1;       return 0;     }     cout << abs(ans);     return 0;   }