#include <bits/stdc++.h>   using namespace std;   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 >= 1) {       if (y % 2) res = (res * x) % p;       x = ((x % p) * (x % p)) % p;       y /= 2;     }     return res;   }   void solve() {     long long int n, m;     cin >> n >> m;     cout << power(power(2, m, 1000000007) - 1, n, 1000000007) <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t;     t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     cin >> a >> b >> c >> d;     int m = max(3 * a / 10, a - a / 250 * c);     int v = max(3 * b / 10, b - b / 250 * d);     if (m == v)       cout <<  Tie ;     else if (m > v)       cout <<  Misha ;     else       cout <<  Vasya ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 6;   long long int arr[2000005], brr[2000005], crr[2000005];   void solve(int n, long long int arr[]) {     int cnt = n + arr[0];     for (int i = 1; i < n; i++) {       cnt += abs(arr[i] - arr[i - 1]) + 1;     }     cout << cnt;     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i];     solve(n, arr);     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int INFTY = 20000000;   const int MAX = 500100;   const int MOD = 10000000;   void coutTab(int* tab, int n) {     for (int i = 0; i < n; i++) {       cout << tab[i] <<    ;     }     cout <<   n ;   }   string create(int a, int b, int x, int start) {     if (start == 0)       a--;     else       b--;     string s;     s.push_back(start +  0 );     char l;     for (int i = 0; i < x - 1; i++) {       l = s[s.size() - 1];       if (l ==  1 ) {         s.push_back( 0 );         a--;       } else {         s.push_back( 1 );         b--;       }     }     l = s[s.size() - 1];     if (l ==  0 ) {       while (a--) s.push_back( 0 );       while (b--) s.push_back( 1 );     } else {       while (b--) s.push_back( 1 );       while (a--) s.push_back( 0 );     }     return s;   }   bool check(string s, int x) {     int j = 0;     for (int i = 1; i < s.size(); i++) {       if (s[i - 1] != s[i]) j++;     }     return x == j;   }   int main() {     ios_base::sync_with_stdio(0);     int a, b, x;     cin >> a >> b >> x;     string res = create(a, b, x, 0);     if (!check(res, x)) res = create(a, b, x, 1);     cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct NODE {     int to, next;   } node[200000 + 10];   long long dp[100000 + 10], k[100000 + 10];   int n, tol;   int head[100000 + 10];   void addedge(int from, int to) {     node[tol].to = to;     node[tol].next = head[from];     head[from] = tol++;   }   void tree_dp(int now, int fa) {     priority_queue<long long, vector<long long>, less<long long> > que;     while (!que.empty()) que.pop();     for (int i = head[now]; i != -1; i = node[i].next) {       int v = node[i].to;       if (v != fa) {         k[v]--;         tree_dp(v, now);         que.push(dp[v]);       }     }     while (k[now] && !que.empty()) {       k[now]--;       int p = que.top();       dp[now] += que.top() + 2;       que.pop();     }     for (int i = head[now]; i != -1; i = node[i].next) {       if (k[now] == 0) break;       int v = node[i].to;       if (v != fa) {         long long t = min(k[now], k[v]);         dp[now] += t * 2;         k[now] -= t;       }     }   }   int main() {     while (scanf( %d , &n) != EOF) {       memset(head, -1, sizeof(head));       tol = 0;       for (int i = 1; i <= n; i++) scanf( %I64d , &k[i]);       for (int i = 1; i <= n - 1; i++) {         int u, v;         scanf( %d %d , &u, &v);         addedge(u, v);         addedge(v, u);       }       int root;       scanf( %d , &root);       memset(dp, 0, sizeof(dp));       tree_dp(root, 0);       printf( %I64d n , dp[root]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200004, M = 19;   vector<int> g[N];   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int d[N], fa[N][M], n;   long long w[N][M], a[N], mod = 1000000007;   void bfs() {     d[1] = 1;     for (int i = 0; i < M; i++) w[1][i] = a[1];     queue<int> q;     q.push(1);     while (!q.empty()) {       int u = q.front();       q.pop();       for (int v : g[u]) {         if (d[v]) continue;         d[v] = d[u] + 1;         fa[v][0] = u;         w[v][0] = a[v];         for (int i = 1; i < M; i++) {           fa[v][i] = fa[fa[v][i - 1]][i - 1];           w[v][i] = gcd(w[v][i - 1], w[fa[v][i - 1]][i - 1]);         }         q.push(v);       }     }   }   int main() {     int x, y;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = 1; i < n; i++) {       scanf( %d %d , &x, &y);       g[x].push_back(y);       g[y].push_back(x);     }     bfs();     long long ans = 0;     for (int i = 1; i <= n; i++) {       long long nw = a[i];       int pre = d[i];       for (;;) {         int v = i;         for (int j = M - 1; j >= 0; j--)           if (w[v][j] == 0) v = fa[v][j];         for (int j = M - 1; j >= 0; j--)           if (gcd(nw, w[v][j]) == nw) v = fa[v][j];         ans = (ans + nw * (pre - d[v])) % mod;         if (v == 0) break;         nw = gcd(nw, a[v]);         pre = d[v];       }     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int mera[100001];     int snct[100001];     string s;     cin >> s;     int len = s.length();     stack<int> st;     if (s[0] ==  [ ) {       snct[0] = 1;     } else {       snct[0] = 0;     }     for (int i = 1; i < len; i++) {       snct[i] = snct[i - 1];       if (s[i] ==  [ ) {         snct[i]++;       }     }     for (int i = 0; i < len; i++) {       mera[i] = -1;       if (s[i] ==  (  || s[i] ==  [ ) {         st.push(i);       } else if (s[i] ==  ) ) {         if (!st.empty()) {           int h = st.top();           if (h != -1 && s[h] ==  ( ) {             mera[i] = h;             st.pop();           } else {             st.push(-1);           }         }       } else {         if (!st.empty()) {           int h = st.top();           if (h != -1 && s[h] ==  [ ) {             mera[i] = h;             st.pop();           } else {             st.push(-1);           }         }       }     }     for (int i = 0; i < len; i++) {       if (mera[i] != -1 && mera[i] > 0 && mera[mera[i] - 1] != -1) {         mera[i] = mera[mera[i] - 1];       }     }     int max = 0;     int x = -1;     for (int i = 0; i < len; i++) {       if (mera[i] != -1) {         int c = snct[i];         if (mera[i] > 0) c -= snct[mera[i] - 1];         if (c > max) {           x = i;           max = c;         }       }     }     cout << max << endl;     if (max > 0) cout << s.substr(mera[x], x - mera[x] + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     int a[n], g[n];     int sa = 0, sg = 0;     char ans[n];     for (int i = 0; i < n; ++i) {       cin >> a[i] >> g[i];     }     for (int i = 0; i < n; ++i) {       sa += a[i];       if (sa <= 500) {         ans[i] =  A ;       } else if (sa > 500) {         sa -= 1000;         ans[i] =  G ;       } else {         cout <<  -1 ;         return 0;       }     }     for (int i = 0; i < n; ++i) {       cout << ans[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int INF = MOD;   vector<int> a[200];   int cnt = 0;   bool used[200];   void dfs(int v) {     used[v] = true;     for (int i = 0; i < a[v].size(); i++)       if (!used[a[v][i]]) dfs(a[v][i]);   }   bool flag = false;   vector<pair<int, int> > ans;   int main() {     std::ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     if (m == 3 && (n == 5 || n == 6)) {       cout << -1 << endl;       return 0;     }     if (m == 3 && n == 4) {       cout << -1 <<     << 0 << endl;       cout << 0 <<     << 0 << endl;       cout << 1 <<     << 1 << endl;       cout << 1 <<     << -1 << endl;       return 0;     }     int cnt = n;     for (int i = 0; i < m; i++, cnt--) cout << i <<     << i * i << endl;     for (int i = 0, x = 4 * m * m; cnt > 0; i++, cnt--, x--)       cout << x <<     << m * m - i * i << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     vector<long long> cnt(26);     long long posl = 1e9, posr = 0;     for (auto c : s) {       cnt[c -  a ]++;       posl = min(posl, (long long)(c -  a ));       posr = max(posr, (long long)(c -  a ));     }     for (long long i = posl; i <= posr; i++) {       if (cnt[i] != 1) {         cout <<  No n ;         return;       }     }     cout <<  Yes n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed;     cout.precision(30);     long long t = 1;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long N = 1e6 + 5;   long long solve() {     long long n;     cin >> n;     map<long long, long long> mp;     vector<long long> v(n);     for (long long &x : v) {       cin >> x;       mp[x]++;     }     long long ans = 0;     for (auto it : mp) {       long long usable = (long long)mp.size() - 1;       long long use = min(usable, it.second);       if (it.second > usable + 1) {         ++use;       }       ans = max(ans, use);     }     cout << ans <<   n ;     return 0;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long T = 1;     cin >> T;     for (long long i = 1; i <= T; ++i) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const double EPS = 1e-9;   int n, m, t[210][210], d[210][210];   bool active[210];   vector<pair<int, int> > x_sorted;   double calc(int x, int y) {     double ans = INF;     vector<pair<int, int> > s;     multiset<int> up;     int down = -INF;     for (int i = 1; i <= n; i++) {       int tmp = t[x][y] + d[y][i] - d[x][i];       active[i] = false;       if (tmp < 0)         down = max(down, t[x][y] + d[y][i]);       else if (tmp > 2 * t[x][y]) {         active[i] = true;       } else {         s.push_back(make_pair(tmp, i));         active[i] = true;       }     }     active[0] = true;     s.push_back(make_pair(0, -1));     s.push_back(make_pair(2 * t[x][y], -1));     sort(s.begin(), s.end());     int _x_sorted = 0;     for (int i = 0; i + 1 < s.size(); i++) {       if (s[i].second > -1) {         active[s[i].second] = false;         down = max(down, t[x][y] + d[y][s[i].second]);       }       while (!active[x_sorted[_x_sorted].second]) ++_x_sorted;       int up_best = x_sorted[_x_sorted].first;       int z = down - up_best;       z = max(s[i].first, z);       z = min(s[i + 1].first, z);       ans = min(ans, max(up_best + 0.5 * z, down - 0.5 * z));     }     return ans;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) t[i][j] = INF;     while (m--) {       int x, y, z;       scanf( %d %d %d , &x, &y, &z);       t[x][y] = t[y][x] = z;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) d[i][j] = i == j ? 0 : t[i][j];     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);     double ans = INF;     for (int i = 1; i <= n; i++) {       x_sorted.clear();       for (int j = 1; j <= n; j++) x_sorted.push_back(make_pair(d[i][j], j));       x_sorted.push_back(make_pair(-1, 0));       sort(x_sorted.begin(), x_sorted.end());       reverse(x_sorted.begin(), x_sorted.end());       for (int j = 1; j < i; j++) ans = min(ans, calc(i, j));     }     printf( %.9lf n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i < n + 1; i++) {       for (int j = 1; j < m + 1; j++) {         if (i % 4 == 2) {           if (j == m) {             cout <<  # ;           } else {             cout <<  . ;           }         } else if (i % 4 == 0) {           if (j == 1) {             cout <<  # ;           } else {             cout <<  . ;           }         } else {           cout <<  # ;         }       }       cout <<   n ;     }     return 0;   }


/** try <3 **/      #include<bits/stdc++.h>      using namespace std;      #define task  sol    #define lb lower_bound   #define ub upper_bound   #define fi first   #define se second   #define pb push_back   #define mp make_pair   #define zs(v) ((int)(v).size())   #define BIT(x, i) (((x) >> (i)) & 1)   #define CNTBIT __builtin_popcountll   #define ALL(v) (v).begin(),(v).end()   #define endl   n       typedef long double ld;   typedef long long ll;   typedef pair<int,int> pii;      void gogo()   {       int x;       cin>>x;          ll s=0, ans=0;          for(int i=1;i<=x;++i)       {           s+=i;           ans=i;           if(s>=x) break;       }          if(!(s==x||s>x+1)) ++ans;       cout<<ans<<  n ;   }   int main()   {       ios_base::sync_with_stdio(0); cin.tie(0);       if(fopen(task .inp , r ))       {           freopen(task .inp , r ,stdin);           freopen(task .out , w ,stdout);       }       int t;       cin>>t;       while(t--) gogo();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a[60], b[60];     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     cin >> m;     for (int i = 0; i < m; i++) cin >> b[i];     int BG = -1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (!(b[j] % a[i])) {           if (b[j] / a[i] > BG) {             BG = b[j] / a[i];           }         }       }     }     int ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (!(b[j] % a[i]) && b[j] / a[i] == BG) {           ans++;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   int main(void) {     int t, h, m;     scanf( %d , &t);     while (t--) {       scanf( %d%d , &h, &m);       printf( %d n , (23 - h) * 60 + (60 - m));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Max = 1000000100;   vector<long long> s;   void dfs(long long temp) {     if (temp > Max) {       return;     }     long long x = temp * 10 + 4;     if (temp > Max) {       return;     }     s.push_back(x);     dfs(x);     long long y = temp * 10 + 7;     if (temp > Max) {       return;     }     s.push_back(y);     dfs(y);   }   int main() {     dfs(0);     s.push_back(0);     sort(s.begin(), s.end());     long long l, r, x, y;     int n;     cin >> l >> r >> x >> y >> n;     long long temp = l > x ? x : l;     int i = lower_bound(s.begin(), s.end(), temp) - s.begin();     double sum = 0;     while (true) {       long long a = s[i - 1] + 1;       long long b = s[i];       long long c = s[i + n - 1];       long long d = s[i + n] - 1;       if (a > r && a > y) break;       if (c > r && c > y) break;       long long A = a > l ? a : l;       long long B = b < r ? b : r;       long long C = c > x ? c : x;       long long D = d < y ? d : y;       int shabi;       int z = 0;       if (n == 1 && B == C) {         int o = lower_bound(s.begin(), s.end(), B) - s.begin();         if (s[o] == B) z = 1;       }       if (z) shabi = D;       if (A <= B && C <= D) {         if (z)           sum += (double)(B - A) / (double)(r - l + 1) * (double)(D - C + 1) /                  (double)(y - x + 1);         else           sum += (double)(B - A + 1) / (double)(r - l + 1) * (double)(D - C + 1) /                  (double)(y - x + 1);       }       A = a > x ? a : x;       B = b < y ? b : y;       C = c > l ? c : l;       D = d < r ? d : r;       if (A <= B && C <= D) {         if (z)           sum += (double)(B - A + 1) / (double)(y - x + 1) * (double)(D - C) /                  (double)(r - l + 1);         else           sum += (double)(B - A + 1) / (double)(y - x + 1) * (double)(D - C + 1) /                  (double)(r - l + 1);       }       if (z) {         sum += (double)(shabi - A + 1) / (double)(y - x + 1) * (double)(1) /                (double)(r - l + 1);       }       i++;     }     printf( %.12lf , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fact[1000001], power[1000001];   long long powerr(long long x, long long y);   long long mpower(long long x, long long y, long long p);   long long gcdExtended(long long a, long long b);   bool isPrime(long long n);   long long func(long long n) {     long long x = sqrt(n);     if (n % x == 0) x = x + 1;     long long i;     for (i = 2; i < n / 2; i++) {       if (n % i == 0 && isPrime(i) == true) {         return i;       }     }     return n;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t, j, k, l, h, p, q, r, x, i, y, z, a, b, c, d, f, n, m,         M = 1000000007;     char ch, ch2, ch3;     string s1, s2, s3;     vector<long long> v, w;     set<long long> S;     t = 1;     while (t--) {       cin >> n >> m >> x >> y;       cout << x <<     << y;       cout <<   n ;       z = 0;       for (j = x - 1; j < n; j++) {         if (z == 0) {           for (k = z; k < m; k++) {             if (j == x - 1 && k == y - 1)               continue;             else {               cout << j + 1 <<     << k + 1;               cout <<   n ;             }           }           z = m - 1;         } else {           for (k = m - 1; k >= 0; k--) {             if (j == x - 1 && k == y - 1)               continue;             else {               cout << j + 1 <<     << k + 1;               cout <<   n ;             }           }           z = 0;         }       }       for (j = x - 2; j >= 0; j--) {         if (z == 0) {           for (k = z; k < m; k++) {             if (j == x - 1 && k == y - 1)               continue;             else {               cout << j + 1 <<     << k + 1;               cout <<   n ;             }           }           z = m - 1;         } else {           for (k = m - 1; k >= 0; k--) {             if (j == x - 1 && k == y - 1)               continue;             else {               cout << j + 1 <<     << k + 1;               cout <<   n ;             }           }           z = 0;         }       }     }   }   long long gcdExtended(long long a, long long b) {     if (b == 0) {       return a;     } else       return gcdExtended(b, a % b);   }   long long mpower(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long powerr(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = res * x;       y = y >> 1;       x = x * x;     }     return res;   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     long long p = sqrt(n);     for (int i = 5; i <= p; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e5 + 5;   const long long int M = 1e3;   const long long int mod = 1e7 + 7;   const long long int m1 = 1e9 + 7;   const long long int m2 = 1e9 + 9;   const long long int p1 = 402653189;   const long long int p2 = 1610612741;   const int LN = 32;   long long int powermodm(long long int x, long long int n, long long int M) {     long long int result = 1;     while (n > 0) {       if (n % 2 == 1) result = (result * x) % M;       x = (x * x) % M;       n = n / 2;     }     return result;   }   long long int power(long long int _a, long long int _b) {     long long int _r = 1;     while (_b) {       if (_b % 2 == 1) _r = (_r * _a);       _b /= 2;       _a = (_a * _a);     }     return _r;   }   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long int lcm(long long int a, long long int b) {     return (max(a, b) / gcd(a, b)) * min(a, b);   }   long long int dx[4] = {-1, 1, 0, 0};   long long int dy[4] = {0, 0, 1, -1};   long long int pw[LN], fact[N], invfact[N];   void pre() {     fact[0] = 1;     for (int i = 0; i < LN; i++) pw[i] = power(2, i);     for (int i = 1; i < N; i++) fact[i] = (i * fact[i - 1]) % mod;     for (int i = 0; i < N; i++) invfact[i] = powermodm(fact[i], mod - 2, mod);   }   long long int n, m, a[N], st[N], en[N], tme[N], curr, lazy[4 * N];   vector<long long int> adj[N];   bitset<M> B[4 * N], fin, bset;   void dfs(long long int node, long long int par) {     st[node] = ++curr;     tme[curr] = node;     for (auto it : adj[node]) {       if (it == par) continue;       dfs(it, node);     }     en[node] = curr;   }   void build(long long int pos, long long int left, long long int right) {     if (left == right) {       B[pos].set(a[tme[left]] % m);       return;     }     long long int mid = (left + right) >> 1;     build(2 * pos + 1, left, mid);     build(2 * pos + 2, mid + 1, right);     B[pos] = B[2 * pos + 1] | B[2 * pos + 2];   }   void apply(bitset<M> &tmp, long long int shift) {     tmp = (tmp << shift) | (tmp >> (m - shift));   }   void update(long long int pos, long long int left, long long int right,               long long int start, long long int end, long long int val) {     if (lazy[pos] != 0) {       apply(B[pos], lazy[pos]);       if (left != right) {         lazy[2 * pos + 1] = (lazy[2 * pos + 1] + lazy[pos]) % m;         lazy[2 * pos + 2] = (lazy[2 * pos + 2] + lazy[pos]) % m;       }       lazy[pos] = 0;     }     if (left > end || right < start)       return;     else if (start <= left && right <= end) {       apply(B[pos], val);       if (left != right) {         lazy[2 * pos + 1] = (lazy[2 * pos + 1] + val) % m;         lazy[2 * pos + 2] = (lazy[2 * pos + 2] + val) % m;       }       return;     }     long long int mid = (left + right) >> 1;     update(2 * pos + 1, left, mid, start, end, val);     update(2 * pos + 2, mid + 1, right, start, end, val);     B[pos] = B[2 * pos + 1] | B[2 * pos + 2];   }   void query(long long int pos, long long int left, long long int right,              long long int start, long long int end) {     if (lazy[pos] != 0) {       apply(B[pos], lazy[pos]);       if (left != right) {         lazy[2 * pos + 1] = (lazy[2 * pos + 1] + lazy[pos]) % m;         lazy[2 * pos + 2] = (lazy[2 * pos + 2] + lazy[pos]) % m;       }       lazy[pos] = 0;     }     if (left > end || right < start)       return;     else if (start <= left && right <= end) {       bset |= B[pos];       return;     }     long long int mid = (left + right) >> 1;     query(2 * pos + 1, left, mid, start, end);     query(2 * pos + 2, mid + 1, right, start, end);   }   bool pri[1005];   vector<long long int> prm;   void fun() {     for (long long int i = 2; i < m; i++) pri[i] = true;     for (long long int i = 2; i < m; i++) {       if (pri[i]) {         prm.push_back(i);         for (long long int j = 2 * i; j < m; j += i) pri[j] = false;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long int i, j;     fin.set();     cin >> n >> m;     fun();     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i < n; i++) {       long long int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1, 0);     build(0, 1, n);     long long int q;     cin >> q;     while (q--) {       long long int x;       cin >> x;       if (x == 1) {         long long int node, val;         cin >> node >> val;         update(0, 1, n, st[node], en[node], val % m);       } else {         bset.reset();         long long int node;         cin >> node;         query(0, 1, n, st[node], en[node]);         long long int ans = 0;         for (i = 0; i < prm.size(); i++) {           if (bset[prm[i]]) ans++;         }         printf( %lld n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a < b) {       int temp;       temp = a;       a = b;       b = temp;     }     while (a % b) {       int r = a % b;       a = b;       b = r;       r = a % b;     }     return b;   }   int fun(int a, int n) {     int sum = 0;     for (;;) {       sum = sum + a % n;       a = a / n;       if (a == 0) break;     }     return sum;   }   int main() {     int i, j, m, n, a, qum = 0;     while (scanf( %d , &a) != EOF) {       for (i = 2; i <= (a - 1); i++) {         qum += fun(a, i);       }       m = gcd(qum, a - 2);       qum = qum / m;       a = (a - 2) / m + 2;       printf( %d/%d n , qum, a - 2);       qum = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class Point {    public:     int x;     int y;     Point(int x = 0, int y = 0) : x(x), y(y) {}     friend Point operator-(Point a, Point b) {       return Point(b.x - a.x, b.y - a.y);     }   };   int getBit(int mask, int num) { return ((mask & (1 << num)) ? 1 : 0); }   int innerProduct(Point a, Point b) { return a.x * b.x + a.y * b.y; }   int sqr(int x) { return x * x; }   int squareDist(Point a, Point b) { return sqr(a.x - b.x) + sqr(b.y - a.y); }   bool checkEdges(vector<Point> figure) {     figure.push_back(figure.front());     figure.push_back(*(figure.begin() + 1));     for (int i = 0; i + 2 < figure.size(); ++i)       if (innerProduct(figure[i + 1] - figure[i],                        figure[i + 2] - figure[i + 1]) != 0)         return false;     return true;   }   bool checkEdgesEquality(vector<Point> figure) {     figure.push_back(figure.front());     for (int i = 0; i + 2 < figure.size(); ++i)       if (squareDist(figure[i], figure[i + 1]) !=           squareDist(figure[i + 1], figure[i + 2]))         return false;     return true;   }   bool checkRectangleEdges(vector<Point> figure) {     figure.push_back(figure.front());     if (squareDist(figure[0], figure[1]) == squareDist(figure[2], figure[3]) &&         squareDist(figure[1], figure[2]) == squareDist(figure[3], figure[4]))       return true;     else       return false;   }   bool checkSquare(vector<Point> square) {     vector<int> sm;     sm.push_back(0);     sm.push_back(1);     sm.push_back(2);     sm.push_back(3);     do {       vector<Point> sq;       for (int i = 0; i < 4; ++i) sq.push_back(square[sm[i]]);       if (checkEdges(sq) && checkEdgesEquality(sq)) return true;     } while (next_permutation(sm.begin(), sm.end()));     return false;   }   bool checkRectangle(vector<Point> rectangle) {     vector<int> sm;     sm.push_back(0);     sm.push_back(1);     sm.push_back(2);     sm.push_back(3);     do {       vector<Point> sq;       for (int i = 0; i < 4; ++i) sq.push_back(rectangle[sm[i]]);       if (checkEdges(sq) && checkRectangleEdges(sq)) return true;     } while (next_permutation(sm.begin(), sm.end()));     return false;   }   bool check(vector<Point> square, vector<Point> rectangle) {     if (checkSquare(square) && checkRectangle(rectangle)) return true;     return false;   }   int main() {     vector<Point> v;     int a, b;     for (int i = 0; i < 8; ++i) {       cin >> a >> b;       v.push_back(Point(a, b));     }     int i = 0;     while (i < 1 << 8) {       vector<Point> square, rectangle;       vector<int> resSquare, resRectangle;       for (int j = 0; j < 8; ++j) {         if (getBit(i, j))           square.push_back(v[j]);         else           rectangle.push_back(v[j]);       }       if (square.size() == 4 && rectangle.size() == 4 &&           check(square, rectangle)) {         for (int j = 0; j < 8; ++j) {           if (getBit(i, j))             resSquare.push_back(j);           else             resRectangle.push_back(j);         }         cout <<  YES  << endl;         for (int j = 0; j < 4; ++j) cout << resSquare[j] + 1 <<    ;         cout << endl;         for (int j = 0; j < 4; ++j) cout << resRectangle[j] + 1 <<    ;         return 0;       }       ++i;     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     while (cin >> n >> m) {       vector<int> f(n);       vector<int> v[100005];       vector<int> b(m);       vector<int> a(m);       vector<int> used(100005, 0);       for (int i = 0; i < n; i++) {         cin >> f[i];         v[f[i]].push_back(i + 1);       }       for (int i = 0; i < m; i++) cin >> b[i];       int sizeA = 0;       int state = -1;       for (int i = 0; i < m; i++) {         if (v[b[i]].size()) {           a[sizeA++] = v[b[i]][0];           used[b[i]]++;         } else {           sizeA = 0;           break;         }       }       if (sizeA < m) {         cout <<  Impossible  << endl;         continue;       }       for (int i = 0; i < 100005 && state == -1; i++) {         if (used[i] && v[i].size() > 1) {           state = 1;         }       }       if (state == 1 || sizeA > m) {         cout <<  Ambiguity  << endl;       } else {         cout <<  Possible  << endl;         for (int i = 0; i < m; i++) {           if (i) cout <<    ;           cout << a[i];         }         cout << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     cin >> N;     string A, B;     cin >> A >> B;     int ans = 0;     for (int x = 0; x < N - 1 - x; x++) {       vector<char> v;       v = {A[x], A[N - 1 - x], B[x], B[N - 1 - x]};       sort(v.begin(), v.end());       if (v[0] == v[1] && v[2] == v[3]) continue;       if ((v[0] == v[1] && v[1] == v[2]) || (v[1] == v[2] && v[2] == v[3])) {         ans++;         continue;       }       bool flag = true;       for (int y = 1; y < 4; y++)         if (v[y] == v[y - 1] && A[x] != A[N - 1 - x]) {           cerr << v[y] <<     << v[y - 1] << endl;           ans++;           flag = false;           break;         }       if (flag) ans += 2;     }     if (N % 2 && A[N / 2] != B[N / 2]) ans++;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int N = 10e6 + 6;   int p[N];   int nx[N];   int n;   priority_queue<int> r;   bool vis[N];   int main(void) {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> p[i];       nx[p[i] - 1] = i;     }     r.push(1);     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         vis[i] = true;         if (nx[p[i]] > i and nx[p[i]] > 0 and nx[p[i]] <= n) {           int j = nx[p[i]];           int ct = 2;           while (nx[p[j]] > j and nx[p[j]] > 0 and nx[p[j]] <= n) {             vis[j] = true;             j = nx[p[j]];             ct++;           }           r.push(ct);         }       }     }     memset(vis, false, sizeof(vis));     cout << n - r.top() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long Getint() {     char ch = getchar();     long long x = 0, fh = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fh = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       (x *= 10) += ch ^ 48;       ch = getchar();     }     return x * fh;   }   const long long mod = 998244353;   const int N = 400005;   inline long long Inc(long long x, long long y) {     return (x += y) >= mod ? x - mod : x;   }   inline long long Dec(long long x, long long y) {     return (x -= y) < 0 ? x + mod : x;   }   inline long long Ksm(long long x, long long y) {     long long tmp = 1;     while (y) {       if (y & 1) tmp = tmp * x % mod;       y >>= 1;       if (y) x = x * x % mod;     }     return tmp;   }   long long K, n, fc[N], fiv[N], inv[N];   vector<int> G[N];   int lst, rev[N];   long long pwi[2][25], wn[N];   inline void initpw() {     for (int i = 1, k = 0; i < N; i <<= 1, k++) {       pwi[0][k] = Ksm(3, (mod - 1) / (i << 1));       pwi[1][k] = Ksm(3, -(mod - 1) / (i << 1) + mod - 1);     }   }   inline int Make(int len) { return 1 << int(ceil(log2(len))); }   inline int Trans(int len) {     int l = ceil(log2(len));     len = 1 << l;     for (int i = 0; i <= len - 1; i++)       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << l - 1);     return lst = len;   }   inline void NTT(vector<long long> &F, int fir, int len, int f) {     if (lst != len) Trans(len);     if (f == 1) F.resize(len);     for (int i = 0; i <= len - 1; i++)       if (rev[i] < i) swap(F[rev[i]], F[i]);     for (int i = 1, k = 0; i < len; i <<= 1, k++) {       long long wi = f == 1 ? pwi[0][k] : pwi[1][k];       wn[0] = 1;       for (int j = 1; j <= i - 1; j++) wn[j] = wn[j - 1] * wi % mod;       for (int j = 0; j < len; j += i << 1) {         for (int k = 0; k < i; k++) {           long long x = F[j + k], y = F[i + j + k] * wn[k] % mod;           F[j + k] = Inc(x, y);           F[i + j + k] = Dec(x, y);         }       }     }     if (f == 1) return;     long long iv = inv[len];     for (int i = 0; i <= fir - 1; i++) F[i] = F[i] * iv % mod;     F.resize(fir);   }   inline vector<long long> operator*(vector<long long> A, vector<long long> B) {     if (A.size() == 0) return A;     if (B.size() == 0) return B;     int len = A.size() + B.size() - 1, l = Make(len);     NTT(A, A.size(), l, 1);     NTT(B, B.size(), l, 1);     for (int i = 0; i <= l - 1; i++) A[i] = A[i] * B[i] % mod;     NTT(A, len, l, -1);     return A;   }   vector<long long> F[N], Lt;   map<int, long long> mp[N];   inline long long Div(int u, int sz) {     if (mp[u].count(sz)) return mp[u][sz];     vector<long long> A = F[u];     vector<long long> C(A.size() - 1);     long long iv = inv[sz];     for (int i = int(A.size()) - 1; i >= 1; i--) {       C[i - 1] = A[i] * iv % mod;       A[i - 1] = Dec(A[i - 1], C[i - 1]);     }     long long tmp = 0;     for (int i = 0; i <= int(C.size()) - 1; i++) {       if (i > K) break;       (tmp += C[i] * fiv[K - i]) %= mod;     }     return mp[u][sz] = tmp;   }   inline vector<long long> CDQ1(int l = 0, int r = int(Lt.size()) - 1) {     if (r < l) {       vector<long long> t(1);       t[0] = 1;       return t;     } else if (l == r) {       vector<long long> t(2);       t[1] = Lt[l];       t[0] = 1;       return t;     }     int mid = l + r >> 1;     return CDQ1(l, mid) * CDQ1(mid + 1, r);   }   int sz[N];   long long dp[N];   void Dfs1(int u, int fa) {     sz[u] = 1;     dp[u] = 0;     for (int v : G[u]) {       if (v == fa) continue;       Dfs1(v, u);       sz[u] += sz[v];       dp[u] = Inc(dp[u], dp[v]);     }     Lt.clear();     for (int v : G[u]) {       if (v == fa) continue;       Lt.push_back(sz[v]);     }     if (fa) Lt.push_back(n - sz[u]);     F[u] = CDQ1();     if (fa) {       dp[u] = Inc(dp[u], Div(u, n - sz[u]));     } else {       for (int i = 0; i <= int(F[u].size()) - 1; i++) {         if (i > K) break;         (dp[u] += F[u][i] * fiv[K - i]) %= mod;       }     }   }   long long Ans = 0;   void Dfs2(int u, int fa) {     long long su = 0;     for (int v : G[u]) {       if (v == fa) continue;       Dfs2(v, u);       (Ans += su * dp[v]) %= mod;       su = Inc(su, dp[v]);     }     for (int v : G[u]) {       if (v == fa) continue;       long long val = Div(u, sz[v]);       (Ans += val * dp[v]) %= mod;     }   }   int main() {     int x, y, z;     fc[0] = fc[1] = inv[0] = inv[1] = fiv[0] = fiv[1] = 1;     for (int i = 2; i <= N - 1; i++) {       fc[i] = fc[i - 1] * i % mod;       inv[i] = (mod - mod / i) * inv[mod % i] % mod;       fiv[i] = fiv[i - 1] * inv[i] % mod;     }     initpw();     n = Getint();     K = Getint();     for (int i = 2; i <= n; i++) {       x = Getint();       y = Getint();       G[x].push_back(y);       G[y].push_back(x);     }     if (K == 1) {       cout << n * (n - 1) / 2 % mod <<   n ;       return 0;     }     Dfs1(1, 0);     Dfs2(1, 0);     Ans = Ans % mod * Ksm(fc[K], 2) % mod;     cout << (Ans % mod + mod) % mod <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   #pragma warning(disable : 4786)   using namespace std;   int MIN(int a, int b) { return a < b ? a : b; }   int MAX(int a, int b) { return a > b ? a : b; }   int GCD(int a, int b) {     while (b) b ^= a ^= b ^= a %= b;     return a;   }   int LCM(int a, int b) { return a * (b / GCD(a, b)); }   void SWAP(int &a, int &b) {     a = a ^ b;     b = a ^ b;     a = a ^ b;   }   const double PI = acos(-1);   const double ESP = 1e-11;   int arr[100100], brr[100010], crr[100010];   int main() {     int ind, i, j, N, T, result, cnt, counter, temp, temp1, idx, index, a, b, c,         d, e, f, g, h, n, m, k;     memset(crr, -1, sizeof(crr));     while (scanf( %d , &n) != EOF) {       for (i = 0; i < n; i++) {         counter = 0;         scanf( %d%d , &a, &e);         b = a;         c = sqrt(b);         memset(brr, NULL, sizeof(brr));         cnt = 0;         {           for (j = 1; j <= c; j++) {             f = j;             g = b / j;             if (b % f == 0) {               if (crr[f] == -1 || crr[f] < i - e) {                 counter += 1;               }               if (f != g && (crr[g] == -1 || crr[g] < i - e)) {                 counter += 1;               }               crr[f] = i;               if (b % g == 0) {                 crr[g] = i;               }             }           }           f = b;           if (crr[f] == -1 || crr[f] < i - e) {             crr[f] = i;             counter += 1;           }           printf( %d n , counter);         }       }       memset(arr, NULL, sizeof(arr));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 555;   int n, m;   int a[maxn], b[maxn];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= m; i++) scanf( %d , b + i);     int i1 = 1, i2 = 1;     int res = 0;     while (i1 <= n && i2 <= m) {       if (a[i1] <= b[i2])         i1++, i2++, res++;       else         i1++;     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int q, r, g, b, w;     cin >> q;     while (q--) {       vector<int> a(4);       int odd = 0, even = 0;       for (int i = 0; i < 4; i++) {         cin >> a[i];         if (a[i] % 2)           odd += 1;         else           even += 1;       }       if (odd <= 1)         cout <<  YES n ;       else {         if (min(a[0], min(a[1], a[2])) >= 1) {           odd = 0, even = 0;           for (int i = 0; i < 3; i++) {             a[i] -= 1;             if (a[i] % 2)               odd += 1;             else               even += 1;           }           a[3] += 1;           if (a[3] % 2)             odd += 1;           else             even += 1;           if (odd <= 1)             cout <<  YES n ;           else             cout <<  NO n ;         } else {           cout <<  NO n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, etime, cnt[2], f[2];   int main() {     int t;     scanf( %d , &t);     while (t--) {       scanf( %d%d%d%d , &n, &etime, f, f + 1);       vector<int> v = {etime};       vector<pair<int, bool> > p(n);       cnt[0] = cnt[1] = 0;       for (int i = 0; i < n; i++) {         scanf( %d , &p[i].second);         cnt[p[i].second]++;       }       for (int i = 0; i < n; i++) {         scanf( %d , &p[i].first);         v.push_back(p[i].first - 1);       }       sort(p.begin(), p.end());       sort(v.begin(), v.end());       v.resize(unique(v.begin(), v.end()) - v.begin());       int mx = 0, must_cnt = 0, i = 0;       long long must = 0;       for (int x : v) {         while (i < p.size() && p[i].first <= x) {           cnt[p[i].second]--;           must_cnt++;           must += f[p[i].second];           i++;         }         if (x >= must) {           int max_points = must_cnt, rem = x - must;           for (int j = 0; j < 2; j++) {             int take = min(cnt[j], rem / f[j]);             rem -= take * f[j];             max_points += take;           }           mx = max(mx, max_points);         }       }       printf( %d n , mx);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n = 0;     long long k = 0;     long long wynik = 0;     long long wynik2 = 0;     long long wynik3 = 0;     cin >> n >> k;     if (k == 1) {       cout <<  1 ;       return 0;     }     if (k == 2) {       wynik = n * (n - 1) / 2 + 1;       cout << wynik;       return 0;     }     if (k == 3) {       wynik = n * (n - 1) / 2;       wynik2 = n * (n - 1) * (n - 2) / 3 + 1;       cout << wynik2 + wynik;       return 0;     }     if (k == 4) {       wynik = n * (n - 1) / 2;       wynik2 = n * (n - 1) * (n - 2) / 3 + 1;       wynik3 = (n * (n - 1) * (n - 2) * (n - 3) / 24) * 9;       cout << wynik + wynik2 + wynik3;     }   }


#include <bits/stdc++.h>   using namespace std;   long long MOD_EXPO(long long b, long long p, long long m) {     if (p == 0) return 1;     long long ret = MOD_EXPO(b, p / 2, m) % m;     ret = (ret * ret) % m;     return ((p & 1) ? (ret * b) % m : ret % m);   }   long long POWER(long long N, long long K) {     long long i, ans = 1;     for (i = 1; i <= K; i++) ans *= N;     return ans;   }   int SET(int N, int pos) { return (N | (1 << pos)); }   int RESET(int N, int pos) { return (N & !(1 << pos)); }   bool CHECK(int N, int pos) { return (N & (1 << pos)); }   int dx4[] = {1, -1, 0, 0};   int dy4[] = {0, 0, 1, -1};   int dx6[] = {0, 0, 1, -1, 0, 0};   int dy6[] = {1, -1, 0, 0, 0, 0};   int dz6[] = {0, 0, 0, 0, 1, -1};   int dx8[] = {1, -1, 0, 0, -1, 1, -1, 1};   int dy8[] = {0, 0, 1, -1, 1, 1, -1, -1};   int dkx8[] = {-1, 1, -1, 1, -2, -2, 2, 2};   int dky8[] = {2, 2, -2, -2, 1, -1, 1, -1};   int tc = 1;   const double eps = 1e-9;   const double pi = acos(-1.0);   const long long int mx = 1e3;   const long long int mod = 1e9 + 7;   int dp[5][mx + 5];   int n, arr[mx + 5];   string str;   int rec(int i, int prev) {     if (i > n) return 0;     int &ret = dp[prev][i];     if (ret != -1) return ret;     ret = INT_MAX;     if (prev != 0) ret = min(ret, rec(i + 1, 0) + (arr[i] != 0));     if (prev != 1) ret = min(ret, rec(i + 1, 1) + (arr[i] != 1));     return ret;   }   int main() {     int i;     while (cin >> n >> str) {       for (i = 1; i <= n; i++) arr[i] = (str[i - 1] -  0 );       memset(dp, -1, sizeof(dp));       cout << rec(1, 2) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, k = 0;     cin >> x;     while (x) {       k += x % 2;       x /= 2;     }     cout << k;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 1005;   char a[MaxN];   int b[MaxN];   bool prime(int x) {     for (int i = 2; i < x / 2; i++) {       if (x % 2 == 0) {         return false;       }     }     return true;   }   int main() {     string s;     int i, n, Max, j;     char v;     Max = 0;     for (i = 0; i < MaxN; i++) {       a[i] =    ;       b[i] = 0;     }     cin >> s;     for (i = 0; i < s.length(); i++) {       b[s[i]]++;       if (b[s[i]] > Max) {         Max = b[s[i]];         v = s[i];       }     }     for (i = 2; i <= s.length(); i++) {       if (prime(i)) {         if (i == 2) {           int ind = 1;           while (ind * i <= s.length()) {             if (a[ind * i] ==    ) {               a[ind * i] = (char)v;               b[v]--;               if (b[v] < 0) {                 cout <<  NO  << endl;                 return 0;               }             }             ind++;           }         } else {           if (i * 2 <= s.length()) {             int ind = 1;             while (ind * i <= s.length()) {               if (a[ind * i] ==    ) {                 a[ind * i] = (char)v;                 b[v]--;                 if (b[v] < 0) {                   cout <<  NO  << endl;                   return 0;                 }               }               ind++;             }           }         }       }     }     cout <<  YES  << endl;     for (i = 1; i <= s.length(); i++) {       if (a[i] ==    ) {         for (j = 0; j < MaxN; j++) {           if (b[j]) {             a[i] = (char)j;             b[j]--;             break;           }         }       }       cout << a[i];     }     cin.get();     cin.get();   }


#include <bits/stdc++.h>   using namespace std;   int t, i;   int c[32650];   void ciu();   unsigned long long int p, q;   unsigned long long int minim = 0xffffffffffffffff;   vector<unsigned long long int> v;   int main() {     cin >> t;     ciu();     while (t--) {       minim = 0xffffffffffffffff;       cin >> p >> q;       if (p % q != 0)         cout << p <<   n ;       else {         for (i = 0; i < v.size() && v[i] * v[i] <= q; i++)           if (q % v[i] == 0) {             unsigned long long int exp = 0, rez = 1;             while (q % v[i] == 0) {               q /= v[i];               exp++;               rez *= v[i];             }             if (rez != 1) {               unsigned long long int expx = 0, rezx = 1;               unsigned long long int cp = p;               cp /= rez;               while (cp % v[i] == 0) {                 cp /= v[i];                 expx++;                 rezx *= v[i];               }               rezx *= v[i];               if (rezx < minim) minim = rezx;             }           }         if (q != 1) {           unsigned long long int expq = 0, rezq = 1;           unsigned long long int cp = p;           cp /= q;           while (cp % q == 0) {             cp /= q;             expq++;             rezq *= q;           }           rezq *= q;           if (rezq < minim) minim = rezq;         }         cout << p / minim <<   n ;       }     }     return 0;   }   void ciu() {     int i, j;     for (i = 2; i * i < 32650; i++)       if (!c[i])         for (j = i * i; j < 32650; j += i) c[j] = 1;     for (i = 2; i < 32650; i++)       if (!c[i]) v.push_back(i);   }


#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<long long, long long> &a,                  const pair<long long, long long> &b) {     return (a.second < b.second);   }   inline long long mx(long long a, long long b) {     if (a > b)       return a;     else       return b;   }   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long solve(long long x, long long n) {     long long r;     if (x <= n)       r = (x - 1) / 2;     else       r = (n - (x - n) + 1) / 2;     if (r > 0)       return r;     else       return 0;   }   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     long long i;     for (i = 9; i <= n + n - 1; i = i * 10 + 9)       ;     long long k = i / 10;     long long ans = 0;     for (long long i = 0; i <= 9; i++) {       if (i * (k + 1) + k <= n + n - 1)         ans += solve(i * (k + 1) + k, n);       else         break;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     long long a = n, b = m;     while (1) {       if (a <= 0 || b <= 0) break;       if (a >= 2 * b) {         a %= 2 * b;         continue;       }       if (b >= 2 * a) {         b %= 2 * a;         continue;       }       break;     }     cout << a <<     << b << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int l, r, k;     cin >> l >> r >> k;     if (k == 1 || l == r || (r - l == 1 && l % 2 && (l ^ r) >= l)) {       cout << l <<   n1 n  << l << endl;       return 0;     }     long long int num = 1, ind;     for (int i = 0;; i++) {       if (num > l) {         ind = i;         break;       }       num *= 2;     }     if (num + num / 2 <= r && k >= 3) {       cout <<  0 n3 n             << num - 1 <<     << num + num / 2 <<     << num + num / 2 - 1 << endl;       return 0;     }     if (r - l == 1) {       cout << (l ^ (l + 1)) <<   n2 n  << l <<     << l + 1 << endl;       return 0;     }     if (l % 2) l++;     if (l + 3 <= r && k >= 4) {       cout <<  0 n4 n             << l <<     << l + 1 <<     << l + 2 <<     << l + 3 << endl;     } else {       cout <<  1 n2 n  << l <<     << l + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5, MOD = 1e9 + 7;   char s[N], buf[1 << 20];   int ppp, qqq;   inline char gc() {     if (ppp == qqq) ppp = 0, qqq = fread(buf, 1, 1 << 20, stdin);     return buf[ppp++];   }   inline void rs() {     char x;     int t = 0;     while ((x = getchar()) <  a  || x >  z )       ;     s[++t] = x;     while ((x = getchar()) >=  a  && x <=  z ) s[++t] = x;   }   inline int rd() {     char x;     while ((x = getchar()) <  0  || x >  9 )       ;     int t = x -  0 ;     while ((x = getchar()) >=  0  && x <=  9 ) t = t * 10 + x -  0 ;     return t;   }   int bg[N], nx[N * 2], to[N * 2], tl, hs1[N], hs2[N], p29[N], pinv[N], lg2[N];   inline void add(int x, int y) {     nx[++tl] = bg[x];     bg[x] = tl;     to[tl] = y;   }   inline int qpow(int x, int y) {     int ret = 1;     while (y) {       if (y & 1) ret = 1ll * ret * x % MOD;       x = 1ll * x * x % MOD;       y >>= 1;     }     return ret;   }   int dep[N], mxd[N], son[N], top[N], up[N], dw[N], fa[N][20], num[N], dfn;   void dfs1(int now, int f, int depth) {     dep[now] = depth;     fa[now][0] = f;     mxd[now] = depth;     for (int i = 1; i < 20; i++) {       if (!fa[fa[now][i - 1]][i - 1]) break;       fa[now][i] = fa[fa[now][i - 1]][i - 1];     }     hs1[now] = (hs1[f] + 1ll * (s[now] -  a ) * p29[depth - 1]) % MOD;     hs2[now] = (29ll * hs2[f] + s[now] -  a ) % MOD;     for (int i = bg[now]; i; i = nx[i]) {       int aim = to[i];       if (aim == f) continue;       dfs1(aim, now, depth + 1);       if (mxd[aim] > mxd[son[now]]) son[now] = aim;       mxd[now] = max(mxd[now], mxd[aim]);     }   }   void dfs2(int now, int tp) {     top[now] = tp, num[now] = ++dfn;     if (now == tp) {       int len = mxd[now] - dep[now], tmp = now;       for (int i = 0; i <= len; i++) dw[dfn + i] = tmp, tmp = son[tmp];       tmp = now;       for (int i = 0; i <= len; i++) up[dfn + i] = tmp, tmp = fa[tmp][0];     }     if (son[now]) dfs2(son[now], tp);     for (int i = bg[now]; i; i = nx[i]) {       int aim = to[i];       if (aim == fa[now][0] || aim == son[now]) continue;       dfs2(aim, aim);     }   }   inline int lca(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     int i, dt = dep[x] - dep[y];     for (i = 0; i < dt; i++) {       if ((1 << i) > dt) break;       if ((1 << i) & dt) x = fa[x][i];     }     if (x == y) return x;     for (i = 19; i >= 0; i--) {       if (fa[x][i] == fa[y][i]) continue;       x = fa[x][i], y = fa[y][i];     }     return fa[x][0];   }   inline int kth_anc(int x, int k) {     if (k == 0) return x;     x = fa[x][lg2[k]], k -= 1 << lg2[k];     int tp = top[x], dt = dep[x] - dep[tp] - k;     if (dt >= 0)       return dw[num[tp] + dt];     else       return up[num[tp] - dt];   }   int main() {     int n = rd(), q, i;     rs();     for (i = 1; i < n; i++) {       int x = rd(), y = rd();       add(x, y), add(y, x);     }     p29[0] = pinv[0] = 1, lg2[0] = -1;     for (i = 1; i <= n; i++) {       p29[i] = 1ll * p29[i - 1] * 29 % MOD, pinv[i] = qpow(p29[i], MOD - 2);       lg2[i] = lg2[i >> 1] + 1;     }     dfs1(1, 0, 1);     dfs2(1, 1);     q = rd();     for (i = 1; i <= q; i++) {       int a = rd(), b = rd(), c = rd(), d = rd();       int ac1 = lca(a, b), ac2 = lca(c, d);       int len1 = dep[a] + dep[b] - dep[ac1] * 2 + 1,           len2 = dep[c] + dep[d] - dep[ac2] * 2 + 1;       int dis1 = dep[a] - dep[ac1] + 1, dis2 = dep[c] - dep[ac2] + 1;       int l = 1, r = min(len1, len2), ans = 0;       while (l <= r) {         int mid = (l + r) >> 1;         int h1 = 0, h2 = 0;         if (mid > dis1) {           int rem = mid - dis1;           int lf =               1ll * (hs1[a] - hs1[fa[ac1][0]] + MOD) * pinv[dep[ac1] - 1] % MOD;           int rp = kth_anc(b, dep[b] - dep[ac1] - rem);           int rt = (0ll + hs2[rp] -                     1ll * hs2[ac1] * p29[dep[rp] - dep[ac1]] % MOD + MOD) %                    MOD;           h1 = (1ll * lf * p29[rem] + rt) % MOD;         } else {           int lp = kth_anc(a, mid - 1);           h1 = 1ll * (hs1[a] - hs1[fa[lp][0]] + MOD) * pinv[dep[lp] - 1] % MOD;         }         if (mid > dis2) {           int rem = mid - dis2;           int lf =               1ll * (hs1[c] - hs1[fa[ac2][0]] + MOD) * pinv[dep[ac2] - 1] % MOD;           int rp = kth_anc(d, dep[d] - dep[ac2] - rem);           int rt = (0ll + hs2[rp] -                     1ll * hs2[ac2] * p29[dep[rp] - dep[ac2]] % MOD + MOD) %                    MOD;           h2 = (1ll * lf * p29[rem] + rt) % MOD;         } else {           int lp = kth_anc(c, mid - 1);           h2 = 1ll * (hs1[c] - hs1[fa[lp][0]] + MOD) * pinv[dep[lp] - 1] % MOD;         }         if (h1 == h2)           ans = mid, l = mid + 1;         else           r = mid - 1;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   vector<int> v;   int main(int argc, char const *argv[]) {     cin >> s;     int n = s.size();     sort(s.begin(), s.end());     for (int i = 0; i < n; i++) {       if (s[i] >  0 ) {         swap(s[0], s[i]);         break;       }     }     string q;     cin >> q;     for (int i = 0; i < n; i++) {       if (q.size() != s.size() or q[i] != s[i]) {         cout <<  WRONG_ANSWER  << endl;         return 0;       }     }     cout <<  OK  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[105];     int n;     cin >> n;     for (int x = 0; x < n; x++) {       cin >> arr[x];     }     sort(arr, arr + n);     for (int x = 0; x < n; x++) {       cout << arr[x] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   using uint = unsigned int;   using ll = long long;   using ull = unsigned long long;   using pii = pair<int, int>;   template <typename T1, typename T2>   ostream &operator<<(ostream &out, const pair<T1, T2> &item) {     out <<  (  << item.first <<  ,   << item.second <<  ) ;     return out;   }   template <typename T>   ostream &operator<<(ostream &out, const vector<T> &v) {     for (const auto &item : v) out << item <<    ;     return out;   }   int n, lpd[5100000];   int last[5100000][8];   int st[15][2 * 200010];   void update(int p, int nr, int pos) {     if (st[nr][p += n] >= pos) return;     for (st[nr][p] = pos; p > 1; p >>= 1)       st[nr][p >> 1] = max(st[nr][p], st[nr][p ^ 1]);   }   int query(int nr, int l, int r) {     int res;     for (res = -1, l += n, r += n; l < r; l >>= 1, r >>= 1) {       if (l & 1) res = max(res, st[nr][l++]);       if (r & 1) res = max(res, st[nr][--r]);     }     return res;   }   void process(int a, int i) {     int p, e;     vector<int> d;     while (a > 1) {       for (e = 0, p = lpd[a]; a % p == 0; ++e) a /= p;       if (e & 1) d.push_back(p);     }     int n = d.size();     for (int cfg = 0; cfg < (1 << n); ++cfg) {       int j, val, s;       for (s = 0, val = 1, j = 0; j < n; ++j)         if (cfg & (1 << j)) val *= d[j], ++s;       for (int nr = 0; nr <= 7; ++nr) update(i, n - s + nr, last[val][nr]);       last[val][n - s] = i;     }   }   int main() {     ios_base::sync_with_stdio(false);     int i, q, a, l, r, ans;     for (i = 1; i < 5100000; ++i) lpd[i] = i;     for (i = 2; i < 5100000; ++i) {       if (lpd[i] != i) continue;       for (ll j = 1LL * i * i; j < 5100000; j += i) lpd[j] = min(lpd[j], i);     }     cin >> n >> q;     memset(st, -1, sizeof st);     memset(last, -1, sizeof last);     for (i = 0; i < n; ++i) {       cin >> a;       process(a, i);     }     while (q--) {       cin >> l >> r;       for (ans = 0; ans <= 14; ++ans)         if (query(ans, l - 1, r) >= l - 1) {           cout << ans <<   n ;           break;         }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef bool mat[55][55][35];   mat adja, adjb;   char a[55], b[55], x[55], y[55], z[55];   int dp[55][55], k;   inline void upd(int &u, int v) { u = min(u, v); }   inline void work(char *str, int n, mat adj) {     memset(adj, false, 55 * 55 * 35);     for (int i = 0; i < n; i++) adj[i][i][str[i] -  a ] = true;     for (int len = 1; len < n; len++) {       for (int l = 0; l + len < n; l++) {         int r = l + len;         for (int p = l; p < r; p++) {           for (int i = 0; i < k; i++)             adj[l][r][x[i] -  a ] |=                 adj[l][p][y[i] -  a ] & adj[p + 1][r][z[i] -  a ];         }       }     }   }   int main() {     scanf( %s%s%d , a, b, &k);     int n = strlen(a), m = strlen(b);     for (int i = 0; i < k; i++) scanf( %*c%c%*c%*c%c%c , x + i, y + i, z + i);     work(a, n, adja);     work(b, m, adjb);     memset(dp, 0x3f, sizeof(dp));     dp[0][0] = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         for (int t = 0; t < 26; t++) {           for (int u = i; u < n; u++) {             for (int v = j; v < m; v++) {               if (adja[i][u][t] && adjb[j][v][t])                 upd(dp[u + 1][v + 1], dp[i][j] + 1);             }           }         }       }     }     printf( %d n , dp[n][m] == 0x3f3f3f3f ? -1 : dp[n][m]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int P1, P2, P3, T1, T2;   int interval(int r, int l) {     int t = l - r;     int sum = 0;     if (t > T1) {       sum = T1 * P1;       t = t - T1;       if (t > T2) {         sum = T2 * P2 + sum;         t = t - T2;         sum = sum + t * P3;       } else {         sum = sum + t * P2;       }     } else       sum = P1 * t;     return sum;   }   int main() {     int n;     cin >> n >> P1 >> P2 >> P3 >> T1 >> T2;     int left[n], right[n];     for (int i = 0; i < n; i++) {       cin >> left[i] >> right[i];     }     int sum = 0;     for (int i = 0;; i++) {       sum = sum + P1 * (right[i] - left[i]);       if (i == n - 1)         break;       else {         sum = sum + interval(right[i], left[i + 1]);       }     }     cout << sum;   }


#include<bits/stdc++.h>   #define int long long   using namespace std;   const int mod=1e9+7;   const int N=3e5+100;   int fa[N];   //并查集,表示i的祖父fa[i]   int begi;   //记录可以随意放的点的位置(只有一个)   int n,m;   int a[N],b[N],c[N],in[N],ans[N];   //a[i]和b[i]表示i必须在a[i]的左边，b[i]的右边   //c[i]表示在缩成一个点的一段中的开头(b[i]的限制中能无限制的放位置)   //in[i]表示入度,ans[i]表示答案   vector<int>g[N],h[N];   //h[i]存储i必须在h[i][1..n]左边   //g[i]表示缩点之后i必须在g[i][1..n]左边   bool vis[N];   //判断序列是否合法   int find(int x)//并查集搜爸爸   {    if(fa[x]==x)return x;    return fa[x]=find(fa[x]);   }   signed main()   {    scanf( %lld%lld ,&n,&m);    for(int i=1;i<=n;i++)    fa[i]=i;     for(int i=1;i<=n;i++)     {     int x,y;     scanf( %lld ,&x);     if(x==0)begi=i;//储存无限制放的点的位置       else h[x].push_back(i);//记录顺序    }    while(m--)//判能否组成序列    {     int x,y;     scanf( %lld%lld ,&x,&y);   //  cout<<x<<   <<y<<endl;      a[x]=y;     b[y]=x;     x=find(x),y=find(y);    // cout<<x<<   <<y<<endl;     if(x==y)//如果成环     {      puts( 0 );      return 0;     }     fa[x]=y;//合并     //无义，相当于把两个集合合并，用来判环后就没用了     //如果一个集合内的元素互相指向，就矛盾了    }     for(int i=1;i<=n;i++)    {     if(b[i]==0)c[find(i)]=i;     //缩点，也就是把一段互相关联的区间缩成一个点去做     //c[find(i)]也就是这一段区间的开头     //也就是说这一个开头不受这一段区间内的点的限制     //反而这个点可以限制这个区间内的其他点     for(int j=0;j<h[i].size();j++)     {      int x=h[i][j];      if(find(i)!=find(x))         {          g[find(i)].push_back(find(x));       //因为把一段缩成一个点       //所以需要把这一段区间内的点的限制关系都转移到这一个点上          in[find(x)]++;       //这一个点的入度(做拓扑排序)         }     }    }    queue<int>q;    //拓扑排序专属队列    q.push(find(begi));    //从无限制的点开始    int ct=0;    while(!q.empty())    {     int x=q.front();     q.pop();     int t=c[x];     //找到缩点     while(t)//把这缩点里面的一个区间记录到答案内     {      ans[++ct]=t;      t=a[t];     }     for(int i=0;i<g[x].size();i++)//拓扑排序pd操作     {      int y=g[x][i];      in[y]--;      if(in[y]==0)q.push(y);      }     }    if(ct!=n)//如果答案数不等于n,就相当于不合法    {     puts( 0 );     return 0;    }    vis[begi]=1;    //判断序列前后关系是否合法    //因为begi没有限制，所以第一个判    for(int i=1;i<=n;i++)    //按答案顺序说    {     if(vis[ans[i]]==0)//如果按照限制关系还没被判断(就相当于i要在j的左边，可j先比i出现了)               return puts( 0 ),0;      for(int j=0;j<h[ans[i]].size();j++)//类似拓扑，把能在接下来队列里的点判为1          vis[h[ans[i]][j]]=1;    }    for(int i=1;i<=n;i++)//输出    {     printf( %lld  ,ans[i]);    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long pw(long long base, long long e) {     return e ? pw(base * base, e / 2) * (e % 2 ? base : 1) : 1;   }   const int maxn = 1e6 + 10, mod = 1e9 + 7, maxlg = 21, lim = 1e6;   const long long INF = 1e9;   long long fen[maxn];   vector<int> r[maxn];   int n;   int ans[maxn];   pair<int, int> a[maxn];   vector<pair<int, int> > query[maxn];   void update(int ind) {     for (; ind < maxn; ind += ind & -ind) {       fen[ind]++;     }   }   int get(int ind) {     long long res = 0;     for (; ind; ind -= ind & -ind) {       res += fen[ind];     }     return res;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int q, cnt, m;     cin >> n >> q;     for (int i = 0; i < n; i++) {       cin >> a[i].first >> a[i].second;       r[a[i].second].push_back(a[i].first);     }     for (int j = 0; j < q; j++) {       cin >> m;       int prev, cur;       prev = 0;       while (m--) {         cin >> cur;         if (cur - prev > 1) {           query[cur - 1].push_back({prev + 1, j});         }         prev = cur;       }       if (lim > prev) {         query[lim].push_back({prev + 1, j});       }     }     for (int i = 1; i <= lim; i++) {       if (r[i].size()) {         for (auto l : r[i]) {           update(l);         }       }       if (query[i].size()) {         int val = get(i);         for (auto d : query[i]) {           ans[d.second] += val - get(d.first - 1);         }       }     }     for (int i = 0; i < q; i++) {       cout << n - ans[i] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int k, d, sk, t;   void sp(int t) {     for (int j = 0; j < k; j++) {       d = k / 2 + j % 2;       sk = j % 2;       if (t % 2 == 0) {         while (d > sk) {           if (d % 2 == 0) {             printf( bb );           } else {             printf( ww );           }           d--;         }       } else {         while (d > sk) {           if (d % 2 == 0) {             printf( ww );           } else {             printf( bb );           }           d--;         }       }       printf(  n );     }     printf(  n );   }   int main() {     scanf( %d , &k);     if (k % 2 == 1) {       printf( %d n , -1);     } else {       for (int i = 0; i < k / 2; i++) {         t = k / 2 + i % 2;         sp(t);         sp(t);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     long long sumx = 0;     long long sumy = 0;     for (long long i = 0; i < n; i++) {       long long a, b;       cin >> a >> b;       sumx += a;       sumy += b;     }     for (long long i = 0; i < n; i++) {       long long a, b;       cin >> a >> b;       sumx += a;       sumy += b;     }     cout << sumx / n <<     << sumy / n <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long arr[n + 5], mx = 0, mn = INT_MIN;       for (int i = 0; i < n; i++) cin >> arr[i];       if (arr[n - 1] > 0)         arr[n] = -1;       else         arr[n] = 1;       bool p = false, o = false;       long long sum = 0;       for (int i = 0; i <= n; i++) {         if (arr[i] > 0) {           if (o) {             sum += mn;             mn = INT_MIN;           }           p = true;           o = false;           mx = max(mx, arr[i]);         } else {           if (p) {             sum += mx;             mx = 0;           }           o = true;           p = false;           mn = max(mn, arr[i]);         }       }       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct SegmentTreeLazy {     typedef long long T;     const T inf = (T)1e18;     const T not_found = -2;     SegmentTreeLazy(vector<T> &v) {       n = static_cast<int>(v.size());       int pow2 = 1;       while (pow2 < n) pow2 <<= 1;       mx.resize(2 * pow2, -inf);       mn.resize(2 * pow2, inf);       change.resize(2 * pow2);       mode.resize(2 * pow2);       build(v, 1, 0, n);     }     int query_zero_idx(int L, int R) { return query_zero_idx(1, 0, n, L, R); }     void set(int L, int R, T x) { update(Mode::assign, 1, 0, n, L, R, x); }     void inc(int L, int R, T x) { update(Mode::increment, 1, 0, n, L, R, x); }       private:     int n;     enum class Mode { increment, assign };     vector<T> mx;     vector<T> mn;     vector<T> change;     vector<Mode> mode;     inline int left(int p) { return p << 1; }     inline int right(int p) { return (p << 1) + 1; }     void build(vector<T> &v, int pos, int lo, int hi) {       if (lo + 1 < hi) {         int mid = lo + (hi - lo) / 2;         build(v, left(pos), lo, mid);         build(v, right(pos), mid, hi);         mx[pos] = max(mx[left(pos)], mx[right(pos)]);         mn[pos] = min(mn[left(pos)], mn[right(pos)]);       } else {         mx[pos] = mn[pos] = v[lo];       }     }     T query_zero_idx(int pos, int lo, int hi, int L, int R) {       if (R <= lo or hi <= L) return not_found;       if (L <= lo and hi <= R) {         if (mx[pos] < 0 or mn[pos] > 0)           return not_found;         else if (mx[pos] == 0 and mn[pos] == 0)           return lo;         else if (lo + 1 == hi)           return -1;       }       propagate(pos, lo, hi);       int mid = lo + (hi - lo) / 2;       int idx = query_zero_idx(left(pos), lo, mid, L, R);       if (idx != not_found) return idx;       return query_zero_idx(right(pos), mid, hi, L, R);     }     void update(Mode m, int pos, int lo, int hi, int L, int R, T x) {       if (R <= lo or hi <= L) {         return;       }       if (L <= lo and hi <= R) {         if (m == Mode::assign) {           mx[pos] = x;           mn[pos] = x;           change[pos] = x;           mode[pos] = Mode::assign;         } else {           mx[pos] += x;           mn[pos] += x;           change[pos] += x;         }       } else {         propagate(pos, lo, hi);         int mid = lo + (hi - lo) / 2;         update(m, left(pos), lo, mid, L, R, x);         update(m, right(pos), mid, hi, L, R, x);         mx[pos] = max(mx[left(pos)], mx[right(pos)]);         mn[pos] = min(mn[left(pos)], mn[right(pos)]);       }     }     void propagate(int pos, int lo, int hi) {       if (mode[pos] == Mode::assign or change[pos]) {         int mid = lo + (hi - lo) / 2;         update(mode[pos], left(pos), lo, mid, lo, mid, change[pos]);         update(mode[pos], right(pos), mid, hi, mid, hi, change[pos]);         change[pos] = 0;         mode[pos] = Mode::increment;       }     }   };   void solve() {     int n, q, p;     long long sum = 0, x;     cin >> n >> q;     vector<long long> diff, v;     diff.reserve(n);     for (int i = 0; i < n; ++i) {       cin >> x;       v.push_back(x);       diff.push_back(x - sum);       sum += x;     }     SegmentTreeLazy st(diff);     int king = st.query_zero_idx(0, n);     for (int i = 0; i < q; ++i) {       cin >> p >> x;       p -= 1;       st.inc(p, p + 1, x - v[p]);       st.inc(p + 1, n, v[p] - x);       v[p] = x;       if (king == st.not_found or king >= p) {         king = st.query_zero_idx(p, n);       }       cout << king + 1 <<   n ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 4e5;   vector<long long> coords;   vector<pair<pair<long long, bool>, pair<long long, long long> > > sweep;   map<long long, long long> ind;   struct nodo {     int may, pos;   };   struct segTree {     int n, h, d[N];     nodo t[N << 1];     void init() {       h = sizeof(int) * 8 - __builtin_clz(n);       for (long long i = 0; i < n; i++) t[i + n].pos = i;     }     void apply(int p, int v) {       t[p].may = t[p].may + v;       if (p < n) d[p] += v;     }     void push(int p) {       for (int s = h; s > 0; s--) {         int i = p >> s;         if (d[i] != 0) {           apply(i << 1, d[i]);           apply(i << 1 | 1, d[i]);           d[i] = 0;         }       }     }     void build(int p) {       while (p > 1) {         p >>= 1;         if (t[p << 1].may > t[p << 1 | 1].may) {           t[p].pos = t[p << 1].pos;           t[p].may = t[p << 1].may + d[p];         } else {           t[p].may = t[p << 1 | 1].may + d[p];           t[p].pos = t[p << 1 | 1].pos;         }       }     }     void upd(int l, int r, int v) {       l += n, r += n;       int l0 = l, r0 = r;       push(l);       push(r - 1);       for (; l < r; l >>= 1, r >>= 1) {         if (l & 1) apply(l++, v);         if (r & 1) apply(--r, v);       }       build(l0);       build(r0 - 1);     }     pair<long long, long long> que() {       int l = 0, r = n;       nodo ans;       ans.may = -1;       l += n, r += n;       push(l);       push(r - 1);       for (; l < r; l >>= 1, r >>= 1) {         if (l & 1) {           if (t[l].may > ans.may) {             ans = t[l];           }           l++;         }         if (r & 1) {           if (t[r - 1].may > ans.may) {             ans = t[r - 1];           }           r--;         }       }       return make_pair(ans.may, ans.pos);     }   } st;   int main() {     int n;     cin >> n;     for (long long i = 0; i < n; i++) {       int x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       sweep.push_back(make_pair(make_pair(x1, 0), make_pair(y1, y2)));       sweep.push_back(make_pair(make_pair(x2, 1), make_pair(y1, y2)));       coords.push_back(y1);       coords.push_back(y2);     }     sort((sweep).begin(), (sweep).end());     sort((coords).begin(), (coords).end());     coords.resize(unique((coords).begin(), (coords).end()) - coords.begin());     int i = 0;     for (long long y : coords) ind[y] = i++;     st.n = (coords).size();     st.init();     for (auto elem : sweep) {       long long x = elem.first.first;       long long y1 = elem.second.first;       long long y2 = elem.second.second;       bool t = elem.first.second;       if (!t) {         st.upd(ind[y1], ind[y2] + 1, +1);         pair<long long, long long> cur = st.que();         if (cur.first >= n - 1) {           cout << x <<     << coords[cur.second] << endl;           return 0;         }       } else {         st.upd(ind[y1], ind[y2] + 1, -1);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3E4 + 5;   const int M = 500;   int n, d, a[N], x, ans, r, L, w, f[N][M * 2 + 5];   int main() {     cin >> n >> L;     for (int i = 1; i <= n; i++) scanf( %d , &r), a[r]++;     memset(f, -10, sizeof(f));     f[L][M] = a[L];     for (int i = 1; i <= r; i++)       for (int j = L - M; j <= L + M; j++)         if ((w = f[i][j - L + M]) >= 0) {           ans = max(ans, w);           for (int k = j - 1; k <= j + 1; k++)             if (k > 0 && (x = i + k) <= r) {               f[x][k - L + M] = max(f[x][k - L + M], w + a[x]);             }         }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, char> > vec[103];   bool dp[103][103][2][300];   bool declared[103][103][2][300];   bool f(int u1, int u2, int turn, char round) {     if (declared[u1][u2][turn][round]) return dp[u1][u2][turn][round];     if (turn == 1) {       for (int i = 0; i < vec[u1].size(); i++) {         int v = vec[u1][i].first;         char c = vec[u1][i].second;         if (c >= round && f(v, u2, 0, c) == false) {           declared[u1][u2][turn][round] = 1;           return dp[u1][u2][turn][round] = 1;         }       }       declared[u1][u2][turn][round] = 1;       return dp[u1][u2][turn][round] = 0;     } else {       for (int i = 0; i < vec[u2].size(); i++) {         int v = vec[u2][i].first;         char c = vec[u2][i].second;         if (c >= round && f(u1, v, 1, c) == false) {           declared[u1][u2][turn][round] = 1;           return dp[u1][u2][turn][round] = 1;         }       }       declared[u1][u2][turn][round] = 1;       return dp[u1][u2][turn][round] = 0;     }     return 0;   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       char c;       cin >> u >> v >> c;       vec[u].push_back({v, c});     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (f(i, j, 1,  a ) == 1)           cout <<  A ;         else           cout <<  B ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mx = 223456;   long long n, a[mx], b[mx], sum1, sum2, ca, cb;   int32_t main() {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     for (long long i = 0; i < n; i++) {       cin >> b[i];     }     sort(a, a + n);     sort(b, b + n);     ca = n - 1;     cb = n - 1;     for (long long i = 0; i < n * 2; i++) {       long long y = 0;       if (i % 2 == 0) {         if (ca >= 0 && cb >= 0) {           if (a[ca] > b[cb]) {             sum1 += a[ca];             ca--;           } else {             cb--;           }           y = 1;         }         if (ca < 0 && y == 0) {           cb--;           y = 1;         }         if (cb < 0 && y == 0) {           sum1 += a[ca];           ca--;           y = 1;         }       } else {         if (ca >= 0 && cb >= 0) {           if (a[ca] < b[cb]) {             sum2 += b[cb];             cb--;           } else {             ca--;           }           y = 1;         }         if (cb < 0 && y == 0) {           ca--;           y = 1;         }         if (ca < 0 && y == 0) {           sum2 += b[cb];           cb--;           y = 1;         }       }     }     cout << sum1 - sum2;     return 0;   }


#include <cstdio>   #include <cassert>   #include <utility>   #include <functional>   #define X first   #define Y second   const int mod = 998244353;   template<int k>   struct node{     node <k-1>* chd[2];     int cnt;     int lazy;     int has[2];     int get_cnt(){       assert(this!=NULL);       return cnt;     }     int get_has(int d){       assert(this!=NULL);       push();       assert(has[d]<(1<<(k+1)));       return has[d];     }     node():chd{NULL, NULL}, has{0, 0}, cnt(0),lazy(0){};     node(node<k-1>* l,node <k-1>* r):chd{l,r},cnt(0),lazy(0),has{0,0}{       if(l){         cnt+=l->get_cnt();         has[0]|=l->get_has(0)|(1<<k);         has[1]|=l->get_has(1);       }       if(r){         cnt+=r->get_cnt();         has[0]|=r->get_has(0);         has[1]|=r->get_has(1)|(1<<k);       }       assert(has[0]<(1<<(k+1)));       assert(has[1]<(1<<(k+1)));     }     void push(){       assert(lazy<(1<<(k+1)));       if(!lazy) return;       if(lazy&(1<<k)){         std::swap(chd[0],chd[1]);         if((has[0]^has[1])&(1<<k)){    has[0]^=(1<<k);    has[1]^=(1<<k);         }         lazy^=(1<<k);       }       int flip=(has[0]^has[1])&lazy;       has[0]^=flip;       has[1]^=flip;       if(chd[0]) chd[0]->lazy^=lazy;       if(chd[1]) chd[1]->lazy^=lazy;       lazy=0;       assert(has[0]<(1<<(k+1)));       assert(has[1]<(1<<(k+1)));     }   };      template<>   struct node<-1>{     int lazy;     node():lazy(0){     }     int get_cnt(){       assert(this!=NULL);       return 1;     }     int get_has(int d){       assert(this!=NULL);       return 0;     }   };      template<int k>   node<k>* create(int x){     if(x&(1<<k)){       return new node<k>(NULL,create<k-1>(x));     }else{       return new node<k>(create<k-1>(x),NULL);     }   }   template<> node<-1>*create(int x)   {       return new node<-1>();   }   template<int k> std::pair <node<k - 1>*, node< k - 1>*> destruct(node <k>*a)   {     assert(a!=NULL);       a -> push();       auto res = std::make_pair(a -> chd[0], a -> chd[1]);       delete a;       return res;   }   template <int k> node <k>* join(node<k -1>* l, node <k - 1>* r)   {       if(l == NULL && r == NULL)       {           return NULL;       }       return new node<k>(l, r);   }   template<int k> node<k>* merge(node<k> *a, node<k> *b)   {       if(!a)       {           return b;       }       if(!b)       {           return a;       }       auto aa = destruct(a);       auto bb = destruct(b);       node <k - 1> *l = merge<k - 1>(aa.X, bb.X);       node <k - 1> *r = merge<k - 1>(aa.Y, bb.Y);       return join<k>(l, r);   }   template<>node<-1>* merge(node<-1>*a, node<-1>* b)   {       if(!a)       {           return b;       }       if(!b)       {           return a;       }       delete b;       return a;   }   template<int k>   std::pair<node<k>*,node<k>*> split(node<k>* a,int thres){     if(a==NULL){       return {NULL,NULL};     }     if(thres<=0) return {NULL,a};     if(thres>=(1<<(k+1))) return {a,NULL};     assert(k>=0);     auto aa =destruct(a);     if(thres<(1<<k)){       node<k-1>* l,*r;       std::tie(l,r)=split<k-1>(aa.first,thres);       return std::make_pair(join<k>(l,NULL),join<k>(r,aa.second));     }else if(thres>(1<<k)){       node<k-1>* l,*r;       std::tie(l,r)=split<k-1>(aa.second, thres-(1<<k));       return std::make_pair(join<k>(aa.first,l),join<k>(NULL,r));     }else{       return std::make_pair(join<k>(aa.first,NULL),join<k>(NULL,aa.second));     }   }      template<>   std::pair<node<-1>*,node<-1>*> split<-1>(node<-1>* a,int thres){     assert(0);   }   template<int k> node<k>* update(node<k> *a, int val)   {       if(a == NULL) return NULL;       a -> push();     assert(val<(1<<(k+1)));       if((val & a -> has[0] & a -> has[1]) == 0)       {           a -> lazy ^= (val & a ->has[0]);           return a;       }       node<k - 1>*l, *r;       std::tie(l, r) = destruct(a);       l = update<k - 1>(l, val & ~(1 << k));       r = update<k - 1>(r, val & ~(1 << k));       if(val & (1 << k))       {           return join<k>(NULL, merge<k - 1>(l, r));       }       else       {           return join<k>(l, r);       }   }   template<>node<-1>*update(node<-1>*a, int val)   {       return a;   }      int main()   {     //  ifstream cin( input1.txt.4c );   //    ios_base::sync_with_stdio(0);     //  cin.tie(0);       //cout.tie(0);       node<19>* root = NULL;       int n, q;       //cin >> n >> q;       scanf( %d %d , &n, &q);      // printf( A n );       for(int i = 0; i< n; i++)       {           int a;           scanf( %d , &a);         //  root = create<19> (a);           root = merge(root, create<19>(a));       }       while(q--)       {           int t, l, r;           scanf( %d%d%d , &t, &l, &r);           node<19>*left, *right;           std::tie(left, root) = split(root, l);           std::tie(root, right) = split(root, r + 1);           if(t == 4)           {               if(root)               {                   printf( %d n , root -> cnt);                  // return 0;               }               else               {                   printf( 0 n );                   //return 0;               }           }           else           {               int x;               scanf( %d , &x);               if(root != NULL)               {                   if(t == 1)                   {                       root -> lazy ^= ((1 << 20) - 1);                       root = update(root, x ^ ((1 << 20) - 1));                       root -> lazy ^= ((1 << 20) - 1);                   }                   else if(t == 2)                   {                       root = update(root, x);                   }                   else                   {                       root -> lazy ^=x;                   }               }           }           root = merge(root, left);           root = merge(root, right);       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long double a, b, c;     cin >> a >> b >> c;     vector<int_fast64_t> am;     int_fast64_t k = 1, max = pow(10, 9);     int_fast64_t f = pow(k, a) * b + c;     while (k <= 81 && f <= max) {       int_fast64_t sum = 0, n = f;       while (f != 0) {         sum += f % 10;         f /= 10;       }       if (sum == k) am.emplace_back(n);       k++;       f = pow(k, a) * b + c;     }     cout << am.size() <<   n ;     for (int_fast64_t i = 0; i < am.size(); i++) {       cout << am[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   using lli = int64_t;   const int maxN = 100010;   vector<int> adj[maxN];   int input[maxN];   bool visited[maxN];   int cost = INT_MAX;   void dfs(int node) {     visited[node] = true;     cost = min(cost, input[node]);     for (auto child : adj[node]) {       if (!visited[child]) {         dfs(child);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int T = 1;     for (int t = 1; t <= T; t++) {       int n, m;       cin >> n >> m;       for (int i = 1; i <= n; i++) {         cin >> input[i];       }       for (int i = 1; i <= m; i++) {         int u, v;         cin >> u >> v;         adj[u].push_back(v);         adj[v].push_back(u);       }       int64_t total_cost = 0;       for (int i = 1; i <= n; i++) {         cost = input[i];         if (!visited[i]) {           dfs(i);           total_cost += cost;         }       }       cout << total_cost <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int SIZE = 200010;   const long long INF = 1e17;   const long long INF_half = 1e16 + 1e10;   struct data {     long long v, c;     data(long long _v = 0, long long _c = 0) : v(_v), c(_c) {}     bool operator<(const data& b) const {       return c < b.c || (c == b.c && v > b.v);     }     void scan() { scanf( %I64d%I64d , &v, &c); }   } a[SIZE];   long long S;   struct Line {     long long x, y;     long long v;     Line(long long _x = 0, long long _y = 0, long long _v = 0)         : x(_x), y(_y), v(_v) {}     long long inter(const Line& b) {       long long ll, rr;       ll = b.x;       rr = (INF - b.y) / b.v + b.x;       while (ll < rr) {         long long mm = (ll + rr) >> 1;         if (b.y + (mm - b.x) * b.v >= y + (mm - x) * v)           rr = mm;         else           ll = mm + 1;       }       if (rr == (INF - b.y) / b.v + b.x) return INF;       return ll;     }   } ss[SIZE];   long long over_pos[SIZE];   int sn;   void add_line(pair<long long, long long> st, long long v) {     if (st.second >= INF) return;     if (sn == 0) {       ss[sn++] = Line(st.first, st.second, v);     } else {       Line now = Line(st.first, st.second, v);       while (sn > 1) {         long long tmp = ss[sn - 2].inter(now);         if (tmp == INF) return;         if (tmp <= over_pos[sn - 1]) {           if (tmp == over_pos[sn - 1] && tmp < ss[sn - 1].inter(now)) break;           sn--;         } else           break;       }       over_pos[sn] = ss[sn - 1].inter(now);       if (over_pos[sn] < INF) ss[sn++] = now;     }   }   pair<long long, long long> get_time(long long t) {     int ll = 0, rr = sn - 1;     while (ll < rr) {       int mm = (ll + rr) >> 1;       if (ss[mm].y + (over_pos[mm + 1] - 1 - ss[mm].x) * ss[mm].v < t)         ll = mm + 1;       else         rr = mm;     }     if (ss[ll].y >= t) return make_pair(ss[ll].x, ss[ll].y - t);     long long need = (t - ss[ll].y + ss[ll].v - 1) / ss[ll].v;     return make_pair(ss[ll].x + need, ss[ll].y + ss[ll].v * need - t);   }   int main() {     int n;     scanf( %d%I64d , &n, &S);     for (int i = 0; i < (n); ++i) {       a[i].scan();     }     sort(a, a + n);     long long now = a[0].v;     add_line(make_pair(0LL, 0LL), a[0].v);     for (int i = 1; i < n; i++) {       if (a[i].v <= now) continue;       pair<long long, long long> t = get_time(a[i].c);       add_line(t, a[i].v);       now = max(now, a[i].v);     }     pair<long long, long long> an = get_time(S);     printf( %I64d n , an.first);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int max(int a, int b) {     if (a > b)       return a;     else       return b;   }   int main() {     long int x, y, z, w, mx;     cin >> x >> y >> z >> w;     mx = max(w, max(z, max(x, y)));     if (mx == w) {       cout << (mx - z) <<     << (mx - y) <<     << (mx - x);     } else if (mx == z) {       cout << (mx - w) <<     << (mx - y) <<     << (mx - x);     } else if (mx == y) {       cout << (mx - z) <<     << (mx - w) <<     << (mx - x);     } else {       cout << (mx - z) <<     << (mx - y) <<     << (mx - w);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, f1;     int b[100005], i, j;     scanf( %d%d , &n, &m);     map<int, int> Q, q;     for (i = 1; i <= n; i++) {       scanf( %d , &f1);       q[f1]++;       Q[f1] = i;     }     for (i = 1; i <= m; i++) {       scanf( %d , &b[i]);     }     int flag = 0, f = 0;     for (i = 1; i <= m; i++) {       if (q[b[i]] == 0) {         f = 1;         break;       }       if (q[b[i]] >= 2) {         flag = 1;         q[b[i]]--;       }     }     if (f == 1)       printf( Impossible n );     else if (flag == 1)       printf( Ambiguity n );     else {       printf( Possible n );       for (i = 1; i <= m; i++) {         if (i == 1) {           printf( %d , Q[b[i]]);         } else           printf(  %d , Q[b[i]]);       }       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 100;   char s[N];   int n, m, t[N];   int a[N * 4], b[N * 4], ab[N * 4], ba[N * 4], aba[N * 4], tag[N * 4];   void pushup(int now) {     a[now] = max(a[(now << 1)], a[(now << 1 | 1)]);     b[now] = min(b[(now << 1)], b[(now << 1 | 1)]);     ab[now] = max(ab[(now << 1)],                   max(ab[(now << 1 | 1)], a[(now << 1)] - 2 * b[(now << 1 | 1)]));     ba[now] = max(ba[(now << 1)],                   max(ba[(now << 1 | 1)], a[(now << 1 | 1)] - 2 * b[(now << 1)]));     aba[now] = max(max(aba[(now << 1)], aba[(now << 1 | 1)]),                    max(ab[(now << 1)] + a[(now << 1 | 1)],                        ba[(now << 1 | 1)] + a[(now << 1)]));   }   void build(int now, int l, int r) {     if (l + 1 == r) {       a[now] = b[now] = t[l];       ab[now] = ba[now] = -t[l];       return;     }     int mid = (l + r) >> 1;     build((now << 1), l, mid);     build((now << 1 | 1), mid, r);     pushup(now);   }   void down(int now, int val) {     a[now] += val;     b[now] += val;     ab[now] -= val;     ba[now] -= val;     tag[now] += val;   }   void pushdown(int now) {     down((now << 1), tag[now]);     down((now << 1 | 1), tag[now]);     tag[now] = 0;   }   void Insert(int now, int l, int r, int a, int b, int val) {     if (a <= l && b >= r - 1) {       down(now, val);       return;     }     int mid = (l + r) >> 1;     pushdown(now);     if (a < mid) Insert((now << 1), l, mid, a, b, val);     if (b >= mid) Insert((now << 1 | 1), mid, r, a, b, val);     pushup(now);   }   int main() {     int x, y, z;     scanf( %d%d , &n, &m);     n = n * 2 - 2;     scanf( %s , s + 1);     for (int i = 1; i <= n; ++i)       if (s[i] ==  ( )         t[i] = t[i - 1] + 1;       else         t[i] = t[i - 1] - 1;     build(1, 1, n + 1);     printf( %d n , aba[1]);     for (int i = 0; i < m; ++i) {       scanf( %d%d , &x, &y);       if (x > y) swap(x, y);       if (s[x] ==  ( )         z = -2;       else         z = 2;       Insert(1, 1, n + 1, x, y - 1, z);       swap(s[x], s[y]);       printf( %d n , aba[1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e9 + 1;   const long double pi = 3.1415926535897;   void solve() {     int n, ans(0);     cin >> n;     int a[n], b[5001] = {0};     for (int i = 0; i < n; i++) {       cin >> a[i];       if (b[a[i]] == 0) b[a[i]] = 1;     }     for (int i = 1; i < n + 1; i++)       if (!b[i]) ans++;     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, x = 0, i, j;     vector<pair<int, int> > v;     map<int, vector<int> > mp;     map<int, vector<int> >::iterator it;     scanf( %d %d , &n, &m);     for (i = 0; i < m; i++) {       int x, y;       scanf( %d %d , &x, &y);       x--;       y--;       mp[x].push_back(y);     }     for (it = mp.begin(); it != mp.end(); it++)       sort(it->second.begin(), it->second.end());     v.push_back(make_pair(0, 0));     for (it = mp.begin(); it != mp.end(); it++) {       vector<pair<int, int> > w;       if (x < it->first) {         int y = v[0].first;         v.clear();         v.push_back(make_pair(y, n - 1));       }       for (i = 0, j = 0; i < v.size() && j < it->second.size();) {         if (v[i].second < it->second[j]) {           w.push_back(make_pair(v[i].first, it->second[j] - 1));           while (i < v.size() && v[i].second < it->second[j]) i++;           if (i < v.size()) {             v[i].first = max(v[i].first, it->second[j] + 1);             if (v[i].first > v[i].second) i++;           }         } else if (v[i].first > it->second[j]) {           j++;         } else {           if (v[i].first != it->second[j])             w.push_back(make_pair(v[i].first, it->second[j] - 1));           if (v[i].second != it->second[j]) {             v[i].first = it->second[j] + 1;           } else {             i++;           }           j++;         }       }       if (i < v.size()) w.push_back(make_pair(v[i].first, n - 1));       if (w.size() == 0) {         puts( -1 );         return 0;       }       v.swap(w);       x = it->first + 1;     }     if (x == n && v.back().second != n - 1) {       puts( -1 );     } else {       printf( %d n , (n - 1) * 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int marcg[112], marcb[112], n, m, b, g, xi;   int main() {     scanf( %d %d , &n, &m);     scanf( %d , &b);     for (int i = 0; i < b; i++) {       scanf( %d , &xi);       marcb[xi] = 1;     }     scanf( %d , &g);     for (int i = 0; i < g; i++) {       scanf( %d , &xi);       marcg[xi] = 1;     }     int mud = 1;     while (mud != 0) {       mud = 0;       for (int i = 0; i < n * m; i++) {         if (marcg[i % m] == marcb[i % n]) continue;         marcg[i % m] = 1;         marcb[i % n] = 1;         mud = 1;       }     }     int ok = 0;     for (int i = 0; i < m; i++) {       if (marcg[i] == 0) ok = 1;     }     if (ok != 0) {       printf( No n );       return 0;     }     for (int i = 0; i < n; i++) {       if (marcb[i] == 0) ok = 1;     }     if (ok != 0) {       printf( No n );       return 0;     }     printf( Yes n );   }


#include <bits/stdc++.h>   using namespace std;   char arr[500001];   char inv(char temp) {     if (temp ==  0 ) return  1 ;     return  0 ;   }   string invert(string temp) {     int n = temp.length();     if (n % 2 == 1) {       for (int i = 1; i < n; i += 2) temp[i] = inv(temp[i]);     } else {       for (int i = 1; i < n / 2; i += 2) temp[i] = inv(temp[i]);       for (int i = n - 2; i >= n / 2; i -= 2) temp[i] = inv(temp[i]);     }     return temp;   }   int main() {     string ans =   , cur;     int n, a, b, c, i, j, temp = 1;     long long res = 0;     cin >> n;     cin >> arr[0];     cur = arr[0];     for (i = 1; i < n; i++) {       cin >> arr[i];       if (arr[i] != arr[i - 1]) {         temp++;         cur += arr[i];       } else {         if (temp <= 2)           ans += cur;         else {           res = fmax(res, (cur.length() - 1) / 2);           ans += invert(cur);         }         temp = 1;         cur = arr[i];       }     }     if (temp <= 2)       ans += cur;     else {       ans += invert(cur);       res = fmax(res, (cur.length() - 1) / 2);     }     cout << res << endl;     for (i = 0; i < ans.size(); i++) cout << ans[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   long long i, j;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, d;     cin >> n >> d;     string s;     cin >> s;     long long p = 0, tot = 0;     while (1) {       long long f = 0;       for (i = min(p + d, n - 1); i > p; i--) {         if (s[i] ==  1 ) {           tot++;           p = i;           f = 1;           break;         }       }       if (f == 0) {         cout << -1 << endl;         return 0;       }       if (p == n - 1) {         cout << tot << endl;         return 0;       }     }   }


#include <bits/stdc++.h>   template <typename T, typename S>   inline bool upmin(T& a, const S& b) {     return a > b ? a = b, 1 : 0;   }   template <typename T, typename S>   inline bool upmax(T& a, const S& b) {     return a < b ? a = b, 1 : 0;   }   using namespace std;   const int dx[4] = {-1, 0, 1, 0};   const int dy[4] = {0, 1, 0, -1};   const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};   const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};   inline bool is_down(char x) { return ( a  <= x && x <=  z ); }   inline bool is_upper(char x) { return ( A  <= x && x <=  Z ); }   inline bool is_digit(char x) { return ( 0  <= x && x <=  9 ); }   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = 10 * x + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline long long readll() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = 10 * x + ch -  0 ;       ch = getchar();     }     return x * f;   }   long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }   long long power(long long x, long long y) {     long long t = 1;     for (; y; y >>= 1, x = x * x % (1000000007))       if (y & 1) t = t * x % (1000000007);     return t;   }   long long n, k;   int main() {     n = read();     k = read();     string s, t;     cin >> s;     cin >> t;     long long cnt = 1, ans = 0;     for (int i = 0; i <= n - 1; i++) {       cnt = (cnt - 1) * 2 + (t[i] -  a ) - (s[i] -  a ) + 1;       if (cnt >= k) {         ans += (n - i) * k;         break;       } else {         ans += cnt;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int MAXN = 1e6;   int solve(int a, int b, int c) {     if (b < a) swap(a, b);     int dis = b - a;     int statr = 1;     int all = dis * 2;     int res = 0;     if (a - dis >= 1 || c > 2 * dis) return -1;     if (c > dis) res = c - dis;     if (c <= dis) res = c + dis;     return res;   }   int main() {     int t;     cin >> t;     while (t--) {       int a, b, c;       cin >> a >> b >> c;       cout << solve(a, b, c) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, q;     cin >> n >> m;     if (m)       q = min(m, n - m);     else       q = 1;     cout << q << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, mn = 200, c = 0, x, y, i;   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> x >> y;       mn = min(mn, y);       c += x * mn;     }     cout << c;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   int n;   pair<int, int> Cd[N + 10];   int cop[2 * N + 10], lnk[2 * N + 10];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       scanf( %d , &Cd[i].first), Cd[i].second = i * 2 - 1;     sort(Cd + 1, Cd + 1 + n);     int L = 1, R = n, LEN = Cd[n].first;     cop[1] = Cd[n].second;     cop[++LEN] = Cd[n].second + 1;     int I = n - 1;     for (int i = n - 1, j = 2; i >= 1 && j <= Cd[n].first; I = --i, j++) {       int u = Cd[i].second, v = u + 1;       cop[j] = u;       lnk[u] = -1;       if (j + Cd[i].first > LEN) {         LEN++;         cop[LEN] = v;         lnk[v] = -1;       } else         lnk[v] = j + Cd[i].first - 1;     }     for (int i = I; i >= 1; i--) {       int u = Cd[i].second, v = u + 1;       if (Cd[i].first == 1) {         lnk[u] = lnk[v] = -1;         printf( %d %d n , cop[1], u);         printf( %d %d n , u, v);       } else {         lnk[u] = 1;         lnk[v] = 1 + (Cd[i].first - 2);       }     }     for (int i = 2; i <= LEN; i++) printf( %d %d n , cop[i], cop[i - 1]);     for (int i = 1; i <= 2 * n; i++)       if (lnk[i] > 0) printf( %d %d n , i, cop[lnk[i]]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef pair<long long, long long> ll;   typedef vector<long long> vl;   typedef vector<ll> vll;   typedef vector<vl> vvl;   template <typename T>   ostream &operator<<(ostream &o, vector<T> v) {     if (v.size() > 0) o << v[0];     for (unsigned i = 1; i < v.size(); i++) o <<     << v[i];     return o <<   n ;   }   template <typename U, typename V>   ostream &operator<<(ostream &o, pair<U, V> p) {     return o <<  (  << p.first <<  ,   << p.second <<  )  ;   }   template <typename T>   istream &operator>>(istream &in, vector<T> &v) {     for (unsigned i = 0; i < v.size(); i++) in >> v[i];     return in;   }   template <typename T>   istream &operator>>(istream &in, pair<T, T> &p) {     in >> p.first;     in >> p.second;     return in;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.precision(20);     long long k, b, n;     cin >> k >> b >> n;     vl a(n);     cin >> a;     map<long long, long long> ma;     ma[0]++;     long long tot = 0;     long long ans = 0;     long long z = 0;     for (long long i = (0); i < (long long)n; i++) {       tot += a[i];       tot %= (k - 1);       if (a[i] == 0)         z++;       else         z = 0;       long long tmp = (tot + k - 1 - b) % (k - 1);       if (b == k - 1 or b == 0) {         if (b == 0)           ans += z;         else           ans += ma[tmp] - z;       } else         ans += ma[tmp];       ma[tot]++;     }     cout << ans <<   n ;     return 0;   }