#include <bits/stdc++.h>   using namespace std;   int uf[55];   int buc[55];   bool chk[55];   int ans[5000][2];   int fh(int idx) {     if (uf[idx] != idx) uf[idx] = fh(uf[idx]);     return uf[idx];   }   vector<int> edge[55];   void dfs(int idx) {     if (chk[idx]) return;     chk[idx] = true;     for (int i = 0; i < edge[idx].size(); i++) {       dfs(edge[idx][i]);     }   }   int main() {     int n, m, g1, g2;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       uf[i] = i;     }     bool b = true;     for (int i = 0; i < m; i++) {       scanf( %d %d , &g1, &g2);       edge[g1].push_back(g2);       edge[g2].push_back(g1);       buc[g1]++;       buc[g2]++;       if (uf[g1] == uf[g2]) {         b = false;       }       uf[fh(g1)] = fh(g2);     }     if (n == 1) {       if (m == 0) {         printf( YES n1 n1 1 );       } else if (m == 1) {         printf( YES n0 );       } else {         printf( NO );       }       return 0;     }     for (int i = 1; i <= n; i++) {       if (buc[i] > 2) {         printf( NO );         return 0;       }     }     if (!b) {       dfs(1);       for (int i = 1; i <= n; i++) {         if (!chk[i]) {           printf( NO );           return 0;         }       }       printf( YES n0 );       return 0;     }     int cnt = 0;     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         if (fh(i) != fh(j) && buc[i] != 2 && buc[j] != 2) {           ans[cnt][0] = i;           ans[cnt][1] = j;           uf[fh(i)] = fh(j);           buc[i]++;           buc[j]++;           cnt++;         }       }     }     for (int i = 1; i <= n; i++) {       if (buc[i] != 2) {         for (int j = i + 1; j <= n; j++) {           if (buc[j] != 2) {             ans[cnt][0] = i;             ans[cnt][1] = j;             cnt++;             break;           }         }         break;       }     }     printf( YES n );     printf( %d n , cnt);     for (int i = 0; i < cnt; i++) {       printf( %d %d n , ans[i][0], ans[i][1]);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int fst[N], v[2 * N], w[2 * N], nxt[2 * N], cnt = 1;   bool vis[2 * N];   int c[N], ans[N], n;   queue<int> q;   void add(int x, int y, int z) {     v[++cnt] = y, w[cnt] = z;     c[y] += z;     nxt[cnt] = fst[x], fst[x] = cnt;   }   void bfs() {     q.push(1);     while (!q.empty()) {       int x = q.front();       q.pop();       for (int i = fst[x]; i; i = nxt[i]) {         int y = v[i];         if (vis[i]) continue;         vis[i] = vis[i ^ 1] = 1, ans[i / 2] = i;         c[y] -= w[i];         if (!c[y] && y != n) q.push(y);       }     }   }   int main() {     int m, x, y, z;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &x, &y, &z);       add(x, y, z), add(y, x, z);     }     for (int i = 1; i <= n; i++) c[i] /= 2;     bfs();     for (int i = 1; i <= m; i++) printf( %d n , ans[i] - i * 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s, t;   double ans;   double solve(string s) {     int a = 0, b = 0, c = 0, p = 0;     for (int i = 0; i < s.size(); i++) {       char e = (b % 2) ?  R  :  L ;       if (s[i] ==  X )         b++;       else if (s[i] == e)         a++, b++, p = 0;       else         a++, b += 2, c += p, p = !p;     }     if (b % 2) b++, c += p;     if (a * 2 > b) a -= c, b -= 2 * c;     return 100.0 * a / b;   }   int main() {     cin >> t;     for (int i = 0; i + 1 < t.size(); i++) {       s += t[i];       if (t[i] == t[i + 1] && t[i] !=  X ) s +=  X ;     }     s += t.back();     if (s[0] == s.back() && s.back() !=  X )       ans = max(solve(s +  X ), solve( X  + s));     else       ans = solve(s);     int f = ans * 1000000;     ans = f / 1000000.0;     printf( %.6lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int N;   int arr[300005];   int segf[4 * 300005];   int segb[4 * 300005];   int pow29[300005];   void inv(long long a, long long b, long long &x, long long &y) {     if (a == 0) {       x = 0;       y = 1;       return;     }     inv((b % a), a, x, y);     long long z = x;     long long zz = y;     x = zz - (b / a) * z;     y = z;   }   void updatef(int start, int end, int i, int node) {     if (start > i || end < i) return;     if (start == end) {       segf[node] += pow29[start];       if (segf[node] >= mod) segf[node] -= mod;       return;     }     updatef(start, (start + end) / 2, i, 2 * node);     updatef((start + end) / 2 + 1, end, i, 2 * node + 1);     segf[node] = segf[2 * node] + segf[2 * node + 1];     if (segf[node] >= mod) segf[node] -= mod;   }   void updateb(int start, int end, int i, int node) {     if (start > i || end < i) return;     if (start == end) {       segb[node] += pow29[N - start];       if (segb[node] >= mod) segb[node] -= mod;       return;     }     updateb(start, (start + end) / 2, i, 2 * node);     updateb((start + end) / 2 + 1, end, i, 2 * node + 1);     segb[node] = segb[2 * node] + segb[2 * node + 1];     if (segb[node] >= mod) segb[node] -= mod;   }   int queryf(int start, int end, int i, int j, int node = 1) {     if (start > j || end < i) return 0;     if (start >= i && end <= j) return segf[node];     return (queryf(start, (start + end) / 2, i, j, 2 * node) +             queryf((start + end) / 2 + 1, end, i, j, 2 * node + 1)) %            mod;   }   int queryb(int start, int end, int i, int j, int node = 1) {     if (start > j || end < i) return 0;     if (start >= i && end <= j) return segb[node];     return (queryb(start, (start + end) / 2, i, j, 2 * node) +             queryb((start + end) / 2 + 1, end, i, j, 2 * node + 1)) %            mod;   }   int main() {     pow29[0] = 1;     for (int g = 1; g <= 300005; g++) pow29[g] = (1LL * 29 * pow29[g - 1]) % mod;     scanf( %d , &N);     for (int g = 1; g <= N; g++) {       scanf( %d , &arr[g]);       arr[g]--;     }     for (int g = 1; g <= N; g++) {       int t = min(arr[g], N - 1 - arr[g]);       int first = queryf(0, N - 1, arr[g], arr[g] + t);       int second = queryb(0, N - 1, arr[g] - t, arr[g]);       long long R = pow29[arr[g]];       long long x = 0, y = 0;       inv(R, mod, x, y);       x %= mod;       x += mod;       x %= mod;       first = (1LL * first * x) % mod;       R = pow29[N - arr[g]], x = 0, y = 0;       inv(R, mod, x, y);       x %= mod;       x += mod;       x %= mod;       second = (1LL * second * x) % mod;       if (first != second) {         if (arr[g] > 0 && arr[g] < N - 1) {           puts( YES );           return 0;         }       }       updatef(0, N - 1, arr[g], 1);       updateb(0, N - 1, arr[g], 1);     }     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     for (int test_case = 0; test_case < T; test_case++) {       int num, round = 1;       vector<int> result;       cin >> num;       while (num > 0) {         if (num % 10 != 0) {           result.push_back((num % 10) * round);         }         num /= 10;         round *= 10;       }       cout << result.size() << endl;       for (int i = 0; i < result.size(); i++) {         cout << result[i] <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 314000000;   int n, m, id[111111], dis[111111], dp[111111];   int val[111111], sum[111111], deg[111111];   int vis[111111];   vector<int> str[111111];   vector<int> to[111111];   vector<int> fr[111111];   int add(int x, int y) {     int s = x + y;     return min(s, inf);   }   void dijkstra() {     priority_queue<pair<int, int>, vector<pair<int, int> >,                    greater<pair<int, int> > >         q;     for (int i = 1; i <= n; i++) {       dis[i] = 0x3f3f3f3f;     }     for (int i = 1; i <= m; i++) {       if (to[i].empty()) {         if (val[i] < dis[id[i]]) {           dis[id[i]] = val[i];           q.push(make_pair(dis[id[i]], id[i]));         }       }     }     while (!q.empty()) {       int x = q.top().second, d = q.top().first;       q.pop();       if (dis[x] != d) continue;       for (int i = 0; i < fr[x].size(); i++) {         deg[fr[x][i]]--;         sum[fr[x][i]] = add(sum[fr[x][i]], dis[x]);         if (!deg[fr[x][i]] && dis[id[fr[x][i]]] > sum[fr[x][i]]) {           dis[id[fr[x][i]]] = sum[fr[x][i]];           q.push(make_pair(dis[id[fr[x][i]]], id[fr[x][i]]));         }       }     }   }   int dfs(int x) {     if (vis[x]) return -2;     if (dp[x] != -1) return dp[x];     vis[x] = 1;     for (int i = 0; i < str[x].size(); i++) {       int y = str[x][i], sum = 0, t = 0;       for (int j = 0; j < to[y].size(); t = ++j) {         if (dis[to[y][j]] == 0x3f3f3f3f) {           break;         }       }       if (t < to[y].size()) {         continue;       }       for (int j = 0; j < to[y].size(); j++) {         int t = dfs(to[y][j]);         if (t == -2) {           vis[x] = 0;           return dp[x] = -2;         }         sum = add(sum, t);       }       sum = add(sum, val[y]);       dp[x] = max(dp[x], sum);     }     vis[x] = 0;     return dp[x];   }   int main() {     scanf( %d%d , &m, &n);     for (int i = 1; i <= m; i++) {       int cnt;       scanf( %d%d , &id[i], &cnt);       str[id[i]].push_back(i);       while (cnt--) {         int x;         scanf( %d , &x);         if (x == -1) {           val[i]++;           sum[i]++;           continue;         }         to[i].push_back(x);         fr[x].push_back(i);       }       deg[i] = to[i].size();     }     dijkstra();     memset(dp, -1, sizeof(dp));     for (int i = 1; i <= n; i++) {       if (dis[i] == 0x3f3f3f3f) {         puts( -1 -1 );       } else {         printf( %d %d n , dis[i], dfs(i));       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace ::std;   const long long maxn = 400;   const long long mod = 1e9 + 7;   const long long inf = 1e17 + 500;   string s[maxn];   long long a[maxn];   string t;   long long n;   long long ger[maxn][maxn];   long long tvi[maxn][maxn];   long long sav[maxn][maxn];   long long tyu[maxn][maxn];   long long star[maxn];   long long m;   long long f(string h) {     long long ans = 0;     for (long long i = 0; i < n; i++) {       if (h.size() >= s[i].size()) {         bool good = 1;         for (long long j = 0; j < s[i].size(); j++) {           if (h[j] != s[i][j]) {             good = 0;           }         }         if (good) {           ans += a[i];         }       }     }     return ans;   }   void tavtosav() {     for (long long i = 0; i < m; i++) {       for (long long j = 0; j < m; j++) {         sav[i][j] = tvi[i][j];       }     }   }   void jelosav() {     for (long long i = 0; i < m; i++) {       for (long long j = 0; j < m; j++) {         long long v = -inf;         for (long long z = 0; z < m; z++) {           v = max(v, sav[i][z] + ger[z][j]);         }         tyu[i][j] = v;       }     }     for (long long i = 0; i < m; i++) {       for (long long j = 0; j < m; j++) {         sav[i][j] = tyu[i][j];       }     }   }   void tavbasavtotav() {     for (long long i = 0; i < m; i++) {       for (long long j = 0; j < m; j++) {         long long v = -inf;         for (long long z = 0; z < m; z++) {           v = max(v, sav[i][z] + tvi[z][j]);         }         tyu[i][j] = v;       }     }     for (long long i = 0; i < m; i++) {       for (long long j = 0; j < m; j++) {         tvi[i][j] = tyu[i][j];       }     }   }   void tav(long long l) {     if (l == 0) {       for (long long i = 0; i < m; i++) {         for (long long j = 0; j < m; j++) {           tvi[i][j] = -inf;         }         tvi[i][i] = 0;       }       return;     }     tav(l / 2);     tavtosav();     if (l & 1) {       jelosav();     }     tavbasavtotav();   }   bool sub(string a, string b) {     for (long long i = 0; i < a.size(); i++) {       if (a[i] != b[i]) {         return 0;       }     }     return 1;   }   map<string, int> ml;   int main() {     long long l;     cin >> n >> l;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     for (long long i = 0; i < n; i++) {       cin >> s[i];       ml[s[i]] += a[i];     }     long long np = 0;     for (long long i = 0; i < n; i++) {       long long v = ml[s[i]];       if (v != 0) {         a[np] = v;         s[np] = s[i];         np++;         ml[s[i]] = 0;       }     }     n = np;     for (long long i = 0; i < n; i++) {       star[i] = t.size();       t += s[i];       t +=  # ;     }     m = t.size();     for (long long i = 0; i < maxn; i++) {       for (long long j = 0; j < maxn; j++) {         ger[i][j] = -inf;       }     }     for (int i = 0; i < t.size(); i++) {       if (t[i] ==  # ) {         ger[i][i] = 0;       } else {         string h;         for (int j = i + 1; t[j] !=  # ; j++) {           h += t[j];         }         ger[i][i + 1] = f(t[i] + h);         for (int j = 0; j < n; j++) {           if (h.size() < s[j].size() && sub(h, s[j])) {             ger[i][star[j]] = f(t[i] + s[j]);           }         }       }     }     tav(l);     long long ans = 0;     for (int i = 0; i < m; i++) {       if (t[i] ==  # ) {         for (int j = 0; j < m; j++) {           ans = max(ans, tvi[j][i]);         }       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int MN = 1000 * 100 + 1000;   const int INF = (1u << 31) - 1;   int l1[MN];   int l2[MN];   int b[MN];   int p[MN];   int n, m, _;   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> _ >> _;     for (int i = 0; i < n; i++) cin >> l1[i];     for (int i = 0; i < m; i++) cin >> l2[i];     sort(l1, l1 + n);     sort(l2, l2 + m);     for (int i = 0; i < m; i++) b[i] = INF;     int now = 0;     for (int i = 0; i < n; i++) {       while (now + 1 < m && abs(l2[now + 1] - l1[i]) < abs(l2[now] - l1[i]))         now++;       if (now + 1 < m && abs(l2[now + 1] - l1[i]) == abs(l2[now] - l1[i]) &&           b[now] != abs(l2[now] - l1[i]) && b[now] != INF)         now++;       p[i] = now;       b[now] = min(b[now], abs(l2[now] - l1[i]));     }     int hung = 0;     for (int i = 0; i < n; i++)       if (b[p[i]] != abs(l2[p[i]] - l1[i])) hung++;     cout << hung << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp1[100010];   int dp2[100010];   int a[100010];   int main(int argc, char const *argv[]) {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       std::cin >> a[i];     }     dp1[0] = 0;     int sum = 0;     for (int i = 1; i <= n; i++) {       sum += a[i];       dp1[i] = dp1[i - 1] + a[i];       if (dp1[i] < -sum) {         dp1[i] = -sum;       }     }     dp2[n + 1] = 0;     sum = 0;     for (int i = n; i >= 1; --i) {       sum += a[i];       dp2[i] = dp2[i + 1] + a[i];       if (dp2[i] < -sum) {         dp2[i] = -sum;       }     }     int ans = 0;     for (int i = 1; i <= n + 1; i++) {       ans = max(ans, dp1[i - 1] + dp2[i]);     }     std::cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using ull = unsigned long long;   const double PI = acos(-1.0);   const int EPS = (1e-10);   const int N = 1e5 * 2 + 10;   const int inf = 1e9 * 2 + 10;   const ll INF = 1e18 * 2 + 10;   const int MOD = 1e9 + 7;   int nxt() {     int x;     cin >> x;     return x;   }   int fcmp(double a, double b) {     return (fabs(a - b) < EPS ? 0 : a > b ? 1 : -1);   }   bool prime[N];   vector<int> adj[N];   int sz[N], link[N];   void sieve() {     fill(&prime[0], &prime[0] + N, 1);     prime[0] = 0;     prime[1] = 1;     for (int i = 2; i * i <= N; ++i)       if (prime[i]) {         for (int j = i * i; j < N; j += i) prime[j] = 0;       }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     sieve();     string s;     cin >> s;     map<char, int> mp;     for (int i = (0); i <= ((int)(s).size() - 1); ++i) mp[s[i]]++;     s =  0  + s;     char k = 0;     for (int i = (0); i <= (256); ++i)       if (mp[k] < mp[i]) k = i;     prime[1] = 1;     for (int i = 2; i + i <= (int)(s).size() - 1; ++i) prime[i] = 0;     for (int i = (1); i <= ((int)(s).size() - 1); ++i)       if (!prime[i]) {         if (mp[k] == 0) {           cout <<  NO n ;           return 0;         }         mp[s[i] = k]--;       }     for (int i = (1); i <= ((int)(s).size() - 1); ++i)       if (prime[i]) {         bool ok = false;         for (int j = (0); j <= (256); ++j)           if (mp[j] > 0) {             mp[s[i] = j]--;             ok = true;             break;           }         if (ok)           continue;         else {           cout <<  NO n ;           return 0;         }       }     s.erase(0, 1);     cout <<  YES n  << s;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define ll long long int   const ll mod = 1e9+7;         void solve(){     int a;     cin>>a;     float arr[a];     float sum=0;       for(int i=0;i<a;i++){           cin>>arr[i];           sum+=arr[i];       }   float avg = sum/(float)a;   sort(arr,arr+a);   int ans=0;    for(int i=0;i<a;i++){          if(arr[i]>arr[0])          ans++;       }   cout<<ans<<endl;      }         int main(){    int t;    cin>>t;    while(t--){      solve();    }   }


#include<iostream>   #include <math.h>   using namespace std;    bool issquare(long int num)    {        long int sqrtnum=sqrt(num);        if(num==(sqrtnum*sqrtnum))        {            return true;        }        else{            return false;        }    }    int main()   {   int t;   cin>>t;      for(int i=0;i<t;i++)   {       int flag=0;       long int n;   cin>>n;   if(n%2==0)   {       long int k=n/2;       if(issquare(k))           flag=1;   }   if(flag==0)   {       if(n%4==0)       {           long int l=n/4;           if(issquare(l))           flag=1;       }   }   if(flag==1)   cout<< YES <<endl;   else   cout<< NO <<endl;   }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:200000000 )   using namespace std;   const long long oo = 1LL << 60;   const long long kNumMoves = 4;   const long long kMoves[kNumMoves][2] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}};   long long GetMinMoves(long long x, long long y, long long m) {     if (max(x, y) >= m) return 0;     if ((x + y) <= min(x, y)) return -1;     if (x < y) swap(x, y);     long long cnt = 0;     if (y < 0) {       cnt = (-y / x);       y += cnt * x;     }     if (x < y) swap(x, y);     while (max(x, y) < m) {       long long sum = x + y;       long long mx = max(x, y);       x = (sum < mx) ? mx : sum;       y = (x == sum) ? mx : sum;       ++cnt;     }     return cnt;   }   int main() {     long long x, y, m;     cin >> x >> y >> m;     cout << GetMinMoves(x, y, m) << endl;     int i;     cin >> i;     return 0;   }


#include <bits/stdc++.h>   const int maxn = 2 * 100000;   const int inf = 99999999;   class array {    public:     int num;     int left;     int right;     array() { left = right = inf; }   } a[maxn + 1];   int queue[maxn + 1];   int head = 1, tail = 1;   int main() {     int n;     scanf( %d , &n);     int nowzero = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i].num);       if (!a[i].num) {         nowzero = i;         a[i].left = a[i].right = 0;         for (int j = head; j < tail; j++) {           a[queue[j]].right = nowzero - queue[j];         }         tail = head;       } else {         if (nowzero) a[i].left = i - nowzero;         queue[tail++] = i;       }     }     for (int i = 1; i <= n; i++)       printf( %d%c , a[i].left > a[i].right ? a[i].right : a[i].left,              i == n ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string q1, q2, ans;     cin >> q1 >> q2;     int n, k = 0, c(0), p;     n = q1.length();     for (int i = 0; i < n; i++) {       if (q1[i] != q2[i]) {         c++;         if (c % 2 == 1) {           ans += q1[i];         } else {           ans += q2[i];         }       } else {         ans += q1[i];       }     }     if (c % 2 == 1) {       cout <<  impossible ;     } else {       cout << ans;     }   }


#include <bits/stdc++.h>   int main() {     int a[4], i, test, flag = 1, flag2 = 1;     double test2, testn;     for (i = 0; i < 4; i++) scanf( %d , &a[i]);     test = a[1] - a[0];     if (a[2] - a[1] == test && a[3] - a[2] == test) {       printf( %d , a[3] + test);       flag = 0;       flag2 = 0;     }     if (flag) {       test2 = (double)a[1] / a[0];       if (fabs((double)a[2] / a[1] - test2) < 0.001 &&           fabs((double)a[3] / a[2] - test2) < 0.001) {         testn = a[3] * test2;         if (fabs(testn - (int)testn) < 0.001) {           printf( %.0f , testn);           flag2 = 0;         }       }     }     if (flag2) printf( 42 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   const ll MOD = 998244353;   const ll INF = 1e15 + 373;   template <typename T>   using vector2 = vector<vector<T>>;   template <typename T>   vector2<T> init_vector2(size_t n0, size_t n1, T e = T()) {     return vector2<T>(n0, vector<T>(n1, e));   }   template <typename T>   using vector3 = vector<vector<vector<T>>>;   template <typename T>   vector3<T> init_vector3(size_t n0, size_t n1, size_t n2, T e = T()) {     return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     os <<  [ ;     for (T e : v) {       os << e <<  ,  ;     }     os <<  ] ;     return os;   }   class Point {    public:     ll y, x;     Point() : y(0), x(0) {}     Point(ll y, ll x) : y(y), x(x) {}     bool operator==(const Point& p) { return this->y == p.y && this->x == p.x; }     ll distance(const Point& p) {       return abs(this->y - p.y) + abs(this->x - p.x);     }     friend ostream& operator<<(ostream& os, const Point& p) {       os <<  (  << p.x <<  ,   << p.y <<  ) ;       return os;     }   };   signed main() {     ll n;     cin >> n;     vector<Point> ps(n + 1);     for (ll i = 0; i < (ll)(n); ++i) {       ll x, y;       cin >> x >> y;       ps[i] = Point(y, x);     }     ps[n] = Point(0, 0);     vector<ll> levels(n + 1);     for (ll i = 0; i < (ll)(n + 1); ++i) {       levels[i] = max(ps[i].y, ps[i].x);     }     sort(levels.begin(), levels.end());     levels.erase(unique(levels.begin(), levels.end()), levels.end());     map<ll, ll> levelmap;     for (ll i = 0; i < (ll)(levels.size()); ++i) {       levelmap[levels[i]] = i;     }     vector<Point> minX(levels.size(), Point(0, 0));     vector<Point> minY(levels.size(), Point(0, 0));     for (ll i = 0; i < (ll)(n); ++i) {       ll lev = levelmap[max(ps[i].y, ps[i].x)];       if (minX[lev] == Point(0, 0) || ps[i].x < minX[lev].x ||           (ps[i].x == minX[lev].x && ps[i].y >= minX[lev].y)) {         minX[lev] = ps[i];       }       if (minY[lev] == Point(0, 0) || ps[i].y < minY[lev].y ||           (ps[i].y == minY[lev].y && ps[i].x >= minY[lev].x)) {         minY[lev] = ps[i];       }     }     vector<vector<ll>> dp(levels.size(), vector<ll>(2));     dp[levels.size() - 1][0] =         minX[levels.size() - 1].distance(minY[levels.size() - 1]);     dp[levels.size() - 1][1] =         minY[levels.size() - 1].distance(minX[levels.size() - 1]);     for (ll i = levels.size() - 2; i >= 0; i--) {       dp[i][0] = min(minX[i].distance(minY[i]) + minY[i].distance(minX[i + 1]) +                          dp[i + 1][0],                      minX[i].distance(minY[i]) + minY[i].distance(minY[i + 1]) +                          dp[i + 1][1]);       dp[i][1] = min(minY[i].distance(minX[i]) + minX[i].distance(minX[i + 1]) +                          dp[i + 1][0],                      minY[i].distance(minX[i]) + minX[i].distance(minY[i + 1]) +                          dp[i + 1][1]);     }     cout << dp[0][0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 500;   int n;   long long a[maxn], ans;   long long dfs(int l, int r, int now) {     if (l == r) {       return 1;     }     long long fenge = r + 1;     for (int i = l; i <= r; i++) {       if (a[i] & (1 << now)) {         fenge = i;         break;       }     }     long long ans = 0;     if (fenge == l || fenge == r + 1) {       ans = dfs(l, r, now - 1);     } else {       ans = max(dfs(l, fenge - 1, now - 1), dfs(fenge, r, now - 1)) + 1;     }     return ans;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     ans = dfs(1, n, 30);     cout << n - ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int test;     cin >> test;     while (test--) {       int n, m;       cin >> n >> m;       int array[n];       for (int i = 0; i < n; i++) cin >> array[i];       int sum = 0;       for (int i = 0; i < n; i++) {         sum += array[i];       }       double average = sum / double(n);       double value = m / double(n);       if (value <= average)         cout << m << endl;       else         cout << average * n << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     int r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   int GCD(int a, int b) {     if (a == 0)       return b;     else       return GCD(b % a, a);   }   long long int power(long long int a, long long int b) {     long long int r = 1;     while (b) {       if (b & 1) {         r = r * a;         b--;       }       a = a * a;       b >>= 1;     }     return r;   }   int palindrome(char *s, int len) {     int i, j, k, count = 0, c = 0;     for (i = 0, j = len - 1; i < len, j >= 0; i++, j--) {       if (s[i] == s[j]) count++;     }     if (count == len)       return 1;     else       return 0;   }   long long int binary(char *s, long long int len) {     long long int i, j, k, r = 0, p = 0, num;     for (i = len - 1; i >= 0; i--) {       num = s[i] -  0 ;       r += (num * power(2, p));       p++;     }     return r;   }   int binary_search(int *ara, int size, int n) {     int high, mid, low;     low = 0;     high = size - 1;     while (low <= high) {       mid = (low + high) / 2;       if (ara[mid] == n) {         return 1;       } else if (n > ara[mid])         low = mid + 1;       else if (n < ara[mid])         high = mid - 1;     }     return -1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int i, j, k, n, T, q, a, b, num;     string s1, s2;     cin >> a >> b;     int ara[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};     long long sum = 0;     for (i = a; i <= b; i++) {       num = i;       while (num) {         int mod = num % 10;         sum = sum + (ara[mod]);         num /= 10;       }     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     ;     cin >> t;     while (t--) {       int s;       vector<int> v;       cin >> s;       for (int i = 0; i < s; i++) {         int x;         cin >> x;         v.push_back(x);       }       int f = 0;       for (int i = 0; i < s - 1; i++) {         if (v[i] != v[i + 1]) f = 1;       }       if (f == 1)         cout <<  1  << endl;       else         cout << s << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 200000;   const int MAX_L = MAX_N * 2;   vector<int> nbrs[MAX_N];   int ps[MAX_N], cis[MAX_N], vs[MAX_L];   bool used[MAX_N];   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d%d , &u, &v);       u--, v--;       nbrs[u].push_back(v);       nbrs[v].push_back(u);     }     ps[0] = -1;     int l = 0;     for (int u = 0; u >= 0;) {       vector<int> &nbru = nbrs[u];       if (cis[u] == 0) {         vs[l++] = u;         used[u] = true;       }       while (cis[u] < nbru.size() && used[nbru[cis[u]]]) cis[u]++;       if (cis[u] < nbru.size()) {         int v = nbru[cis[u]++];         ps[v] = u;         u = v;       } else {         int v = ps[u];         if (v >= 0) vs[l++] = v;         u = v;       }     }     int q = l / k, r = l % k;     for (int i = 0, j = 0; i < k; i++) {       int ci = q + ((i < r) ? 1 : 0);       printf( %d , ci);       while (ci--) printf(  %d , vs[j++] + 1);       putchar(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     scanf( %d , &n);     if (n % 5 == 0) {       cout << n / 5;     } else       cout << n / 5 + 1;     return 0;   }


#include <bits/stdc++.h>   const int INF = (int)1e9;   const int long minINF = (int)-1e9;   const int mod = (int)1e9 + 7;   const int MAXN = (int)2e6 + 5;   using namespace std;   long long arr[MAXN];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int N;     cin >> N;     for (int i = 0; i < N; i++) cin >> arr[i];     long long f, x;     cin >> x >> f;     long long ans = 0;     for (int i = 0; i < N; i++) {       ans += arr[i] / (f + x) * f;       if (arr[i] % (f + x) > x) {         ans += f;       }     }     cout << ans <<   n ;   }


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


#include <bits/stdc++.h>   using namespace std;   int n, m, c;   vector<int> l;   vector<int> r;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> c;     while (l.size() + r.size() < n) {       int val;       cin >> val;       if (val <= c / 2) {         bool temp = 0;         for (int i = 0; i < (int)l.size(); i++) {           if (l[i] > val) {             l[i] = val;             temp = 1;             cout << i + 1 << endl;             break;           }         }         if (!temp) {           l.push_back(val);           cout << l.size() << endl;         }       } else {         bool temp = 0;         for (int i = 0; i < (int)r.size(); i++) {           if (r[i] < val) {             r[i] = val;             cout << n - i << endl;             temp = 1;             break;           }         }         if (!temp) {           r.push_back(val);           cout << n - r.size() + 1 << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1E-9;   const double Exp = 2.718281828459045;   const double Pi = 3.1415926535897932;   const int Max_Bit = 63;   const int INF = 2000000000;   const long long LINF = 1000000000000000007ll;   const int MOD = 1000000007;   const int NMAX = 100005;   const int MMAX = 505;   const int KMAX = 6;   const string CODE =  CODEFORCES ;   const int go[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};   int n, a[NMAX], l[NMAX], r[NMAX];   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     int q, u, v;     scanf( %d%d , &n, &q);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i + 1]);     }     for (int i = 0; i < n - 1; ++i) {       a[i + 1] = abs(a[i + 2] - a[i + 1]);     }     a[0] = INF;     a[n] = INF;     for (int i = 1; i < n; ++i) {       l[i] = i - 1;       while (a[i] >= a[l[i]]) {         l[i] = l[l[i]];       }     }     for (int i = n - 1; i > 0; i--) {       r[i] = i + 1;       while (a[i] > a[r[i]]) {         r[i] = r[r[i]];       }     }     for (int i = 0; i < q; ++i) {       long long ans = 0;       scanf( %d%d , &u, &v);       for (int j = u; j < v; ++j) {         ans += (j - max(l[j], u - 1)) * 1ll * (min(r[j], v) - j) * 1ll * a[j];       }       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       long long dp[500005] = {0};       dp[3] = 8;       long long fac = 2;       for (long long i = 5; i <= 500000; i += 2) {         dp[i] = dp[i - 2] + fac * (i + i + i - 2 + i - 2);         ++fac;       }       cout << dp[n] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   string str;   long long int n, k;   int main() {     string temp;     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int a, b, i, j, cnt = 0;     cin >> str;     n = str.size();     cin >> k;     for (i = 0; i < k; i++) {       cin >> temp;       for (j = 0; j < n; j++) {         a = 0, b = 0;         while (j < n && (str[j] == temp[0] || str[j] == temp[1])) {           if (str[j] == temp[0])             a++;           else             b++;           j++;         }         cnt += min(a, b);       }     }     cout << cnt <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000 * 1000 * 1000 + 7;   const double PI = 3.14159265358979323846264;   const pair<long long int, long long int> steps[] = {       {1, 0}, {0, 1}, {-1, 0}, {0, -1}, {1, -1}, {1, 1}, {-1, -1}, {-1, 1}};   template <typename... T>   void read(T&... args) {     ((cin >> args), ...);   }   template <typename... T>   void write(T&&... args) {     ((cout << args <<    ), ...);   }   void fio() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   void setUpLocal() {}   const long long int maxN = 2 * 1e3;   const long long int gp_size = maxN;   vector<long long int> gp[gp_size];   long long int vis[gp_size];   long long int cnt[gp_size];   void dfs(long long int i) {     vis[i] = 1;     for (long long int child : gp[i])       if (!vis[child]) dfs(child);   }   long long int modPow(long long int n, long long int k) {     long long int ret = 1;     while (k) {       if (k & 1) ret = ret * n % mod;       k >>= 1;       n = n * n % mod;     }     return ret;   }   void solve() {     long long int n, m, k;     cin >> n >> m >> k;     for (long long int i = 1; i <= n - k + 1; i++) {       for (long long int f = i, b = i + k - 1; f <= b; f++, b--) {         gp[f].push_back(b);         gp[b].push_back(f);       }     }     long long int cc = 0;     for (long long int i = 1; i <= n; i++) {       if (!vis[i]) {         cc++;         dfs(i);       }     }     cout << modPow(m, cc);   }   int32_t main() {     fio();     setUpLocal();     return solve(), 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double EPS = 1e-9;   const int oo = 210000000;   int n;   vector<int> p[4];   vector<int> g[201];   int solve(int x) {     bool used[201];     for (int i = 1; i <= n; i++) used[i] = 0;     int ans = 0, m = 0;     while (m < n) {       bool flag1 = 0;       for (int i = 0; i < p[x].size(); i++) {         int cur = p[x][i];         if (used[cur]) continue;         bool flag = 1;         for (int j = 0; j < g[cur].size(); j++)           if (!used[g[cur][j]]) {             flag = 0;             break;           }         if (flag) {           flag1 = 1;           m++;           used[cur] = 1;         }       }       if (!flag1) {         x++;         if (x > 3) x = 1;         ans++;       }     }     return ans;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       int tmp;       cin >> tmp;       p[tmp].push_back(i);     }     for (int i = 1; i <= n; i++) {       int k;       cin >> k;       for (int j = 0; j < k; j++) {         int tmp1;         cin >> tmp1;         g[i].push_back(tmp1);       }     }     int ans = oo;     ans = min(ans, solve(1));     ans = min(ans, solve(2));     ans = min(ans, solve(3));     cout << ans + n << endl;     return (0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a >> b >> c;     if (a == b)       cout <<  YES ;     else if (b - a > 0 && c > 0) {       if ((b - a) % c == 0)         cout <<  YES ;       else         cout <<  NO ;     } else if (b - a > 0 && c < 0) {       cout <<  NO ;     } else if (b - a < 0 && c > 0) {       cout <<  NO ;     } else if (b - a < 0 && c < 0) {       if ((a - b) % c == 0)         cout <<  YES ;       else         cout <<  NO ;     } else if (c == 0)       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using db = double;   using vi = vector<int>;   const int l = 20;   const int maxn = 300006;   int e[maxn][l];   int tote;   map<int, int> S;   int a[maxn];   int yy[maxn];   int rr[maxn];   int h[maxn][1000 / l];   int n, q;   int app[maxn];   int sum[maxn];   int Get(int a, int b) { return e[h[a][b / l]][b % l]; }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       S[a[i]] = 0;     }     int tot = 0;     for (auto &p : S) {       rr[tot] = p.first;       p.second = tot;       tot++;     }     for (int i = 1; i <= n; ++i) a[i] = S[a[i]];     int m = (int)sqrt(n * 5) + 3;     for (int i = 1; i <= n; ++i) app[a[i]]++;     vi big;     for (int i = 0; i < tot; ++i)       if (app[i] > m / 5 - 3) {         big.push_back(i);         yy[i] = big.size() - 1;       } else         yy[i] = -1;     int maxs = big.size() / l;     memset(h, 0, sizeof(h));     memset(e, 0, sizeof(e));     tote = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j <= maxs; ++j) h[i][j] = h[i - 1][j];       if (yy[a[i]] != -1) {         int no = yy[a[i]];         tote++;         for (int j = 0; j < l; ++j) e[tote][j] = e[h[i - 1][no / l]][j];         e[tote][no % l]++;         h[i][no / l] = tote;       }     }     for (int i = 1; i <= q; ++i) {       int l, r, k;       scanf( %d%d%d , &l, &r, &k);       int ans = -1;       for (auto x : big)         if (Get(r, yy[x]) - Get(l - 1, yy[x]) > (r - l + 1) / k)           if (ans == -1 || x < ans) ans = x;       if (r - l + 1 <= m) {         vi tr;         for (int i = l; i <= r; ++i) {           tr.push_back(a[i]);           sum[a[i]]++;         }         for (auto x : tr)           if (sum[x] > (r - l + 1) / k)             if (ans == -1 || x < ans) ans = x;         for (auto x : tr) sum[x] = 0;       }       printf( %d n , (ans == -1) ? -1 : rr[ans]);     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   const ll INF = 1e16 + 2;   signed main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     vector<pair<ll, ll>> pts;     pts.emplace_back();     ll ax, ay, bx, by;     cin >> pts[0].first >> pts[0].second >> ax >> ay >> bx >> by;     ll x, y, t;     cin >> x >> y >> t;     while (pts.back().first < INF && pts.back().second < INF)       pts.emplace_back(pts.back().first * ax + bx, pts.back().second * ay + by);     int m = pts.size();     vector<int> dp(m);     for (int i = 0; i < m; i++) {       ll len;       len = abs(pts[i].first - x) + abs(pts[i].second - y);       ll cur_t = t;       if (len > cur_t) {         dp[i] = 0;         continue;       }       cur_t -= len;       dp[i] = 1;       for (int j = i - 1; j >= 0; j--) {         len = abs(pts[j].first - pts[j + 1].first) +               abs(pts[j].second - pts[j + 1].second);         if (cur_t >= len) dp[i] = i - j + 1;         cur_t -= len;       }       len = abs(pts[i].first - x) + abs(pts[i].second - y);       cur_t = t - len;       len = abs(pts[i].first - pts[0].first) + abs(pts[i].second - pts[0].second);       if (cur_t < 2 * len) continue;       cur_t -= 2 * len;       dp[i] = max(dp[i], i + 1);       for (int j = i + 1; j < m; j++) {         ll len = abs(pts[j].first - pts[j - 1].first) +                  abs(pts[j].second - pts[j - 1].second);         if (cur_t >= len) dp[i] = max(dp[i], i + 1 + j - i);         cur_t -= len;       }     }     ll ans = *max_element(dp.begin(), dp.end());     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   int n, a[maxn], tot, b[maxn], ans;   inline int read() {     int ret = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -f;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       ret = ret * 10 + ch -  0 ;       ch = getchar();     }     return ret * f;   }   inline int BinarySearch(int l, int x) {     int L = l, R = tot, mid;     while (L <= R) {       mid = L + R >> 1;       b[mid] >= x ? R = mid - 1 : L = mid + 1;     }     return L;   }   int main() {     n = read();     for (int i = 1; i <= n; i++) a[i] = read();     sort(a + 1, a + 1 + n);     int cnt = 1;     for (int i = 2; i <= n + 1; i++) {       if (a[i] != a[i - 1]) {         b[++tot] = cnt;         cnt = 1;       } else         cnt++;     }     sort(b + 1, b + 1 + tot);     for (int i = 1; i <= tot; i++) {       for (int j = b[i - 1] + 1; j <= b[i]; j++) {         int now = j, lst = j, ret = BinarySearch(i + 1, 2 * lst);         while (ret <= tot) {           lst *= 2;           now += lst;           ret = BinarySearch(ret + 1, 2 * lst);         }         if (now > ans) ans = now;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1E9;   int N, M, MB, LASTB;   unsigned long long LASTM;   vector<int> adj[100005];   int LB, lb[100005], revlb[100005], tr[100005], a[100005], primes[1000], P;   class mask {    public:     unsigned long long v[16];     mask() { memset(v, 0, sizeof(v)); }     void set(int b) { v[b / 64] |= 1ULL << (b % 64); }     bool has(int b) { return (v[b / 64] & (1ULL << (b % 64))) > 0; }     void add(unsigned long long v2[16], int l, int r, unsigned long long v,              int shift) {       int len = r - l + 1;       l += shift;       r += shift;       int li, lm, ri, rm;       bool cross = (l < M) ^ (r < M);       if (l >= M) l -= M;       if (r >= M) r -= M;       li = l / 64;       ri = r / 64;       lm = l % 64;       rm = r % 64;       if (!cross) {         if (li == ri) {           v2[li] |= v << lm;         } else {           v2[li] |= v << lm;           v2[ri] |= v >> (len - rm - 1);         }       } else {         if (li == MB - 1) {           v2[li] |= (v << lm) & LASTM;           v2[ri] |= v >> (len - rm - 1);         } else {           v2[li] |= v << lm;           v2[MB - 1] |= (v >> (64 - lm)) & LASTM;           v2[ri] |= v >> (len - rm - 1);         }       }     }     void shift(int shift) {       unsigned long long v2[16] = {};       for (int i = (0); i < (MB); i++) {         add(v2, i * 64, min(M - 1, (i + 1) * 64 - 1), v[i], shift);       }       memcpy(v, v2, sizeof(v));     }     void combine(const mask &ano) {       for (int i = (0); i < (MB); i++) v[i] |= ano.v[i];     }   };   mask val[1 << 20];   int lz[1 << 20];   void build(int k, int nl, int nr) {     if (nl == nr) {       val[k].set(a[revlb[nl]]);       return;     }     int nm = (nl + nr) >> 1;     build(2 * k + 1, nl, nm);     build(2 * k + 2, nm + 1, nr);     val[k] = val[2 * k + 1];     val[k].combine(val[2 * k + 2]);   }   void add(int k, int nl, int nr, int l, int r, int v);   void relax(int k, int nl, int nr) {     int nm = (nl + nr) >> 1;     add(2 * k + 1, nl, nm, nl, nm, lz[k]);     add(2 * k + 2, nm + 1, nr, nm + 1, nr, lz[k]);     lz[k] = 0;   }   void add(int k, int nl, int nr, int l, int r, int v) {     if (r < nl || l > nr) return;     if (l <= nl && nr <= r) {       val[k].shift(v);       lz[k] = (lz[k] + v) % M;       return;     }     int nm = (nl + nr) >> 1;     if (lz[k]) relax(k, nl, nr);     add(2 * k + 1, nl, nm, l, r, v);     add(2 * k + 2, nm + 1, nr, l, r, v);     val[k] = val[2 * k + 1];     val[k].combine(val[2 * k + 2]);   }   mask get(int k, int nl, int nr, int l, int r) {     if (r < nl || l > nr) return mask();     if (l <= nl && nr <= r) return val[k];     if (lz[k]) relax(k, nl, nr);     int nm = (nl + nr) >> 1;     mask ml = get(2 * k + 1, nl, nm, l, r);     mask mr = get(2 * k + 2, nm + 1, nr, l, r);     ml.combine(mr);     return ml;   }   void dfs(int x, int p) {     lb[x] = LB;     revlb[LB] = x;     tr[x] = LB++;     int sz = adj[x].size();     for (int i = (0); i < (sz); i++) {       int y = adj[x][i];       if (y == p) continue;       dfs(y, x);     }     tr[x] = LB - 1;   }   int main() {     cin >> N >> M;     for (int p = (2); p < (M); p++) {       bool ok = 1;       for (int i = 2; i * i <= p; i++) {         if (p % i == 0) {           ok = 0;           break;         }       }       if (ok) primes[P++] = p;     }     MB = (M + 64 - 1) / 64;     LASTB = M % 64 == 0 ? 64 : M % 64;     LASTM = (1ULL << LASTB) - 1ULL;     for (int i = (0); i < (N); i++) {       scanf( %d , a + i);       a[i] %= M;     }     for (int i = (0); i < (N - 1); i++) {       int a, b;       scanf( %d%d , &a, &b);       a--;       b--;       adj[a].push_back(b);       adj[b].push_back(a);     }     dfs(0, -1);     build(0, 0, N - 1);     int Q;     cin >> Q;     while (Q--) {       int t, x, val;       scanf( %d%d , &t, &x);       x--;       if (t == 1) {         scanf( %d , &val);         add(0, 0, N - 1, lb[x], tr[x], val % M);       } else {         mask m = get(0, 0, N - 1, lb[x], tr[x]);         int ans = 0;         for (int i = (0); i < (P); i++)           if (m.has(primes[i])) ans++;         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       string s;       int n, l = 0, r = 0, u = 0, d = 0;       cin >> s;       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  L )           l++;         else if (s[i] ==  R )           r++;         else if (s[i] ==  U )           u++;         else           d++;       }       int a = min(l, r);       int b = min(u, d);       if (a == 0 && b == 0) {         cout << 0 << endl;       } else if (a == 0) {         cout << 2 << endl;         cout <<  UD  << endl;       } else if (b == 0) {         cout << 2 << endl;         cout <<  LR  << endl;       } else {         cout << 2 * (a + b) << endl;         for (int i = 0; i < a; i++) {           cout <<  L ;         }         for (int i = 0; i < b; i++) {           cout <<  U ;         }         for (int i = 0; i < a; i++) {           cout <<  R ;         }         for (int i = 0; i < b; i++) {           cout <<  D ;         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string bin;     cin >> bin;     int i = 0;     for (; i + 1 < bin.length(); i++)       if (bin[i] ==  0 ) break;     cout << bin.substr(0, i) + bin.substr(i + 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 7;   const string alpha =  abcdefghijklmnopqrstuvwxyz ;   long long power(long long x, long long y) {     long long res = 1;     x = x;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   template <typename T>   T gcd(T a, T b) {     if (a == 0) return b;     return gcd(b % a, a);   }   template <typename T>   T powm(T a, T b, long long m) {     T cnt = 1;     while (b > 0) {       if (b % 2 == 1) cnt = (cnt * a) % m;       b /= 2;       a = (a * a) % m;     }     return cnt % m;   }   long long ncr(long long n, long long r) {     long long res = 1;     if (r > n) return 0;     if (r > n - r) r = n - r;     for (long long i = 0; i < r; i++) {       res *= (n - i);       res /= (i + 1);     }     return res;   }   long long sqr(long long x) { return x * x; }   void solve() {     long long int n;     cin >> n;     vector<long long> a(n), b(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];       a[i] = a[i] * (i + 1) * (n - i);     }     for (int i = 0; i < n; ++i) {       cin >> b[i];     }     sort((a).begin(), (a).end());     sort((b).rbegin(), (b).rend());     long long ans = 0;     for (int i = 0; i < n; ++i) {       a[i] %= 998244353;       ans = (ans + a[i] * b[i]) % 998244353;     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tc;     tc = 1;     while (tc--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   int main() {     cin >> M >> N;     if (M == N) {       cout << N <<  1  <<     << N <<  2 ;       return 0;     }     if (N - M == 1) {       cout << M <<  9  <<     << N <<  0 ;       return 0;     }     if (M == 9 && N == 1) {       cout <<  9 10 ;       return 0;     }     cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, ctr{};     cin >> n;     string vec;     cin >> vec;     int likh = count(vec.begin(), vec.end(),  8 );     if (likh > 0) {       int m = min(likh, n % 11);       int len = n - m;       len = len / 10;       ctr = min(len, likh);     }     cout << ctr <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e5 + 5;   char s[MAX_N];   vector<int> v;   int main() {     scanf( %s , s + 1);     int n = strlen(s + 1);     int tot = 0;     for (int i = 1; i <= n; i++) {       if (s[i] ==  ( )         tot++;       else if (s[i] ==  ) )         tot--;     }     if (tot <= 0) {       printf( -1 n );       return 0;     }     int res = 0;     for (int i = 1; i <= n; i++) {       if (s[i] ==  ( )         res++;       else if (s[i] ==  ) )         res--;       else         res--, v.push_back(1), tot--;       if (res < 0) {         printf( -1 n );         return 0;       }     }     if (tot < 0) {       printf( -1 n );       return 0;     }     v[v.size() - 1] += tot;     res = 0;     int pos = -1;     for (int i = n; i; i--) {       if (s[i] ==  # ) {         pos = i;         break;       }     }     for (int i = 1; i <= n; i++) {       if (s[i] ==  ( )         res++;       else if (s[i] ==  ) )         res--;       else {         if (i == pos)           res -= 1 + tot;         else           res--;       }       if (res < 0) {         printf( -1 n );         return 0;       }     }     for (int i = 0; i < v.size(); i++) printf( %d n , v[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int dis[40];   long long adj[40];   vector<long long> v1;   vector<long long> v2;   void bt(int l, int r, long long mask) {     if (l == r) {       v1.emplace_back(mask);       return;     }     bt(l + 1, r, mask);     if (adj[l] & mask) return;     bt(l + 1, r, mask | (1ll << l));   }   long long f[1 << 21];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int m;     cin >> m;     long long ans = 1;     for (int i = 0; i < n; ++i) ans *= 2;     for (int i = 0; i < m; ++i) {       int x;       cin >> x;       --x;       int y;       cin >> y;       --y;       adj[x] |= (1ll << y);       adj[y] |= (1ll << x);     }     long long cnt1 = 1;     long long cnt01 = 1;     long long cnt02 = 1;     for (int j = 0; j < n; ++j)       if (adj[j] == 0) cnt01 *= 2;     fill(dis, dis + n, -1);     for (int i = 0; i < n; ++i)       if (dis[i] < 0) {         cnt1 *= 2;         cnt02 *= 2;         int S = 0;         queue<int> qu;         qu.push(i);         dis[i] = 0;         while (qu.size()) {           int u = qu.front();           qu.pop();           S++;           for (int v = 0; v < n; ++v)             if (adj[u] >> v & 1) {               if (dis[v] < 0) dis[v] = dis[u] ^ 1, qu.push(v);               if (dis[v] == dis[u]) cnt02 = 0;             }         }       }     if (ans == cnt1) ans = 0;     ans -= cnt1;     ans += cnt01 * 2;     ans += cnt02;     m = n / 2;     bt(m, n, 0);     v1.swap(v2);     bt(0, m, 0);     for (long long x : v2) {       int M = 0;       for (int i = 0; i < m; ++i) {         if (adj[i] & x)           continue;         else           M |= (1 << i);       }       f[M]++;     }     for (int i = 0; i < m; ++i)       for (int j = 0; j < (1 << m); ++j)         if (j >> i & 1) f[j ^ (1 << i)] += f[j];     for (long long x : v1) ans -= f[x], ans -= f[x];     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long n, m;     cin >> n >> m;     vector<long long> a(n), b(m);     for (long long i = 0; i < n; ++i) cin >> a[i];     for (long long i = 0; i < m; ++i) cin >> b[i];     long long tot = 0;     for (long long i = 0; i < n; ++i) tot ^= a[i];     for (long long i = 0; i < m; ++i) tot ^= b[i];     if (tot == 0) {       cout <<  YES n ;       for (long long i = 0; i < n - 1; ++i) {         for (long long j = 0; j < m - 1; ++j) {           cout << 0 <<    ;         }         cout << a[i] <<   n ;       }       long long last = a[n - 1];       for (long long j = 0; j < m - 1; ++j) {         cout << b[j] <<    ;         last ^= b[j];       }       cout << last <<   n ;     } else {       cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   int sum(int a, int b) {     int s = a + b;     if (s >= mod) s -= mod;     return s;   }   int sub(int a, int b) {     int s = a - b;     if (s < 0) s += mod;     return s;   }   int mult(int a, int b) { return (1LL * a * b) % mod; }   int n, k;   int len;   const int maxN = (int)1e5 + 10;   const int maxK = 105;   int dp[maxN][maxK];   int sum_pref[maxN];   int a[maxN];   int f[maxN][maxK];   int all[maxN];   bool can(int l, int r, int color) {     return (all[r] - all[l - 1] == f[r][color] - f[l - 1][color]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     srand(239);     cin >> n >> k >> len;     for (int i = 1; i <= n; i++) {       cin >> a[i];       for (int color = 1; color <= k; color++) {         f[i][color] = f[i - 1][color];         f[i][color] += (color == a[i]);       }       all[i] = all[i - 1] + (a[i] > 0);     }     if (len == 1) {       cout << 0;       return 0;     }     sum_pref[0] = 1;     for (int i = 1; i <= n; i++) {       for (int color = 1; color <= k; color++) {         if (a[i] != -1 && a[i] != color) continue;         dp[i][color] = sum_pref[i - 1];         if (i >= len && can(i - len + 1, i, color)) {           dp[i][color] =               sub(dp[i][color], sub(sum_pref[i - len], dp[i - len][color]));         }         sum_pref[i] = sum(sum_pref[i], dp[i][color]);       }     }     cout << sum_pref[n];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char **argv) {     string i, o;     cin >> i >> o;     sort(i.begin(), i.end());     if (i ==  0  && i == o) {       cout <<  OK  << endl;       return 0;     }     unsigned int z;     for (z = 0; z < i.length() && i[z] ==  0 ; ++z)       ;     while (!i.empty() && i[0] ==  0 ) i = i.substr(1);     while (z--) i.insert(i.empty() ? 0 : 1,  0 );     cout << ((i == o) ?  OK  :  WRONG_ANSWER ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long k = 2;   struct node {     vector<node*> to;     node() { to.resize(k, 0); }     long long cnt = 0;   };   node* root = new node();   inline bool getbit(long long a, long long pos) { return a & (1 << pos); }   void addstring(long long b) {     vector<long long> a;     for (long long i = 0; i < 30; ++i) {       a.push_back(getbit(b, i));     }     reverse(a.begin(), a.end());     node* cur = root;     for (long long i = 0; i < a.size(); ++i) {       long long c = a[i];       if (cur->to[c] == 0) {         cur->to[c] = new node();       }       cur = cur->to[c];       cur->cnt++;     }   }   long long get(long long b) {     vector<long long> a;     long long ans = 0;     for (long long i = 0; i < 30; ++i) {       a.push_back(getbit(b, i));     }     reverse(a.begin(), a.end());     node* cur = root;     for (long long i = 0; i < a.size(); ++i) {       long long bet = a[i];       if (cur->to[bet] && cur->to[bet]->cnt > 0) {         cur = cur->to[bet];         ans += bet * (1 << (29 - i));         cur->cnt--;       } else {         cur = cur->to[1 - bet];         ans += (1 - bet) * (1 << (29 - i));         cur->cnt--;       }     }     return ans;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<long long> a(n);     vector<long long> b(n);     for (long long i = 0; i < n; ++i) {       cin >> a[i];     }     for (long long i = 0; i < n; ++i) {       cin >> b[i];       addstring(b[i]);     }     for (long long i = 0; i < n; ++i) {       cout << (get(a[i]) ^ a[i]) <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long k4, k7, i, l;     char s[100];     long long n;     gets(s);     l = strlen(s);     k4 = 0;     k7 = 0;     for (i = 0; i < l; i++) {       if (s[i] ==  4 ) k4++;       if (s[i] ==  7 ) k7++;     }     if (k4 == 0 && k7 == 0)       cout << -1;     else if (k7 > k4)       cout << 7;     else       cout << 4;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a[1000005];   int main() {     long long int i, j, k, l, n, m;     cin >> n >> m;     if (n / m < 3) {       cout << -1;       return 0;     }     j = 1;     long long int f = 0;     long long int x, y;     x = 1, y = n - 1;     while (y - x >= 4 && j < m) {       a[x] = a[x + 1] = a[y] = j;       j++;       x += 2;       y--;     }     while (x <= y) {       a[x] = j;       x++;     }     a[n] = j;     for (i = 1; i <= n; i++) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void vout(T x) {     cout << x << endl;     exit(0);   }   int gcd(int a, int b) {     while (a && b) {       if (a > b)         a %= b;       else         b %= a;     }     return a + b;   }   const long long inf = -1e18;   const long long mod = 1e9;   long long dp[300][300], a[400];   int n, k, x;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k >> x;     if (n / k > x) vout(-1);     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 0; i < 300; ++i) {       for (int j = 0; j < 300; ++j) dp[i][j] = inf;     }     dp[0][x] = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < x; ++j) {         for (int t = max(0, i - k); t <= i; ++t) {           if (dp[t][j + 1] >= 0) dp[i][j] = max(dp[i][j], dp[t][j + 1] + a[i]);         }       }     }     long long ans = 0;     for (int i = n - k + 1; i <= n; ++i) ans = max(ans, dp[i][0]);     vout(ans);     return 0;   }


#include <bits/stdc++.h>   const long long INF = 0x3f3f3f3f;   using namespace std;   void sol() {     long long n, m;     while (cin >> n >> m) {       string s;       cin.ignore();       cin >> s;       long long x[6][n];       string a[6] = { abc ,  acb ,  bca ,  bac ,  cab ,  cba };       memset(x, 0, sizeof(x));       ;       for (long long i = 0; i < s.size(); i++) {         if (i) {           for (long long j = 0; j < 6; j++) {             x[j][i] = x[j][i - 1];             if (s[i] != a[j][i % 3]) x[j][i]++;           }         } else {           for (long long j = 0; j < 6; j++) {             x[j][i] = 0;             if (s[i] != a[j][i % 3]) x[j][i]++;           }         }       }       while (m--) {         long long a, b;         cin >> a >> b;         long long ans = INF;         if (a > 1) {           for (long long i = 0; i < 6; i++) {             ans = (x[i][b - 1] - x[i][a - 2] < ans ? x[i][b - 1] - x[i][a - 2]                                                    : ans);           }         } else {           for (long long i = 0; i < 6; i++) {             ans = (x[i][b - 1] < ans ? x[i][b - 1] : ans);           }         }         cout << ans <<   n ;       }     }   }   signed main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     long long t = 1;     while (t--) {       sol();       cout.flush();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};   const int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};   const int OO = INT_MAX;   long long tolong(string s) {     stringstream ss;     ss << s;     long long n;     ss >> n;     return n;   }   string toString(long long s) {     stringstream ss;     ss << s;     string n;     ss >> n;     return n;   }   int main() {     string x;     cin >> x;     long long n = tolong(x);     if (x == toString(n)) {       if (n >= -128 && n <= 127) {         cout <<  byte ;       } else if (n >= -32768 && n <= 32767) {         cout <<  short ;       } else if (n >= -2147483648 && n <= 2147483647) {         cout <<  int ;       } else {         cout <<  long ;       }     } else {       cout <<  BigInteger ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int pow1(long long int a, long long int b) {     long long int ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % 1000000007;       a = (a * a) % 1000000007;       b = b >> 1;     }     return ans;   }   int n, m;   pair<int, int> a[100005];   vector<int> v[100005];   bool vis[100005] = {0};   void dfs(int x) {     vis[x] = 1;     for (int i = 0; i < v[x].size(); i++)       if (!vis[v[x][i]]) dfs(v[x][i]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i + 1;     }     sort(a, a + n);     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     long long int sum = 0;     for (int i = 0; i < n; i++) {       if (!vis[a[i].second]) {         sum += a[i].first;         dfs(a[i].second);       }     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, r, f[60005];   int dp[105][60005];   struct node {     int a, b, sign;   } pro[105];   bool cmp(node a, node b) {     if (a.sign == b.sign) {       if (a.sign == 1)         return a.a < b.a;       else         return a.a + a.b > b.a + b.b;     }     return a.sign < b.sign;   }   int main() {     scanf( %d%d , &n, &r);     for (register int i = 1; i <= n; i++) {       scanf( %d%d , &pro[i].a, &pro[i].b);       if (pro[i].b >= 0)         pro[i].sign = 1;       else         pro[i].sign = 2, pro[i].a = max(pro[i].a, abs(pro[i].b));     }     sort(pro + 1, pro + 1 + n, cmp);     int s = r, sum = 0;     vector<node> aa;     for (register int i = 1; i <= n; i++) {       if (pro[i].sign == 1 && s >= pro[i].a)         s += pro[i].b, sum++;       else         aa.push_back(pro[i]);     }     dp[0][s] = sum;     for (int i = 0; i < (int)(aa.size()); i++)       for (register int j = 0; j <= s; j++) {         if (j >= aa[i].a)           dp[i + 1][j + aa[i].b] = max(dp[i + 1][j + aa[i].b], dp[i][j] + 1);         dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);       }     sum = 0;     for (register int i = 0; i <= s; i++) sum = max(sum, dp[(int)(aa.size())][i]);     printf( %d n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000000;   struct sTree {     int pl, pr;     int val, cnt, debt;   } tree[4000009];   int treeSize;   int NewNode(int LL, int RR) {     int cur = ++treeSize;     tree[cur].cnt = RR - LL + 1;     return cur;   }   void CalcDebt(int LL, int RR, int cur);   void Add(int L, int R, int d, int LL, int RR, int cur) {     if (L <= LL && R >= RR) {       tree[cur].debt += d;       tree[cur].val += d;       return;     }     int M = LL + (RR - LL) / 2;     if (!tree[cur].pl) tree[cur].pl = NewNode(LL, M);     if (!tree[cur].pr) tree[cur].pr = NewNode(M + 1, RR);     CalcDebt(LL, RR, cur);     if (L <= M && LL <= R) {       Add(L, R, d, LL, M, tree[cur].pl);     }     if (L <= RR && M + 1 <= R) {       Add(L, R, d, M + 1, RR, tree[cur].pr);     }     if (tree[tree[cur].pl].val < tree[tree[cur].pr].val) {       tree[cur].val = tree[tree[cur].pl].val;       tree[cur].cnt = tree[tree[cur].pl].cnt;     } else if (tree[tree[cur].pl].val > tree[tree[cur].pr].val) {       tree[cur].val = tree[tree[cur].pr].val;       tree[cur].cnt = tree[tree[cur].pr].cnt;     } else {       tree[cur].val = tree[tree[cur].pl].val;       tree[cur].cnt = tree[tree[cur].pl].cnt + tree[tree[cur].pr].cnt;     }   }   int Get(int cur) {     if (tree[cur].val == 0) {       return 2 * inf + 1 - tree[cur].cnt;     }     return 2 * inf + 1;   }   void CalcDebt(int LL, int RR, int cur) {     int M = LL + (RR - LL) / 2;     Add(LL, M, tree[cur].debt, LL, M, tree[cur].pl);     Add(M + 1, RR, tree[cur].debt, M + 1, RR, tree[cur].pr);     tree[cur].debt = 0;   }   int n;   struct event {     char type;     int p, L, R;   } e[200009];   bool operator<(event a, event b) {     if (a.p != b.p) return a.p < b.p;     return a.type < b.type;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       int x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       x1 += inf, y1 += inf, x2 += inf, y2 += inf;       e[2 * i].type =  + ;       e[2 * i].p = min(x1, x2) - 1;       e[2 * i].L = min(y1, y2);       e[2 * i].R = max(y1, y2);       e[2 * i + 1].type =  - ;       e[2 * i + 1].p = max(x1, x2);       e[2 * i + 1].L = min(y1, y2);       e[2 * i + 1].R = max(y1, y2);     }     sort(e, e + 2 * n);     int root = NewNode(0, 2 * inf);     long long ans = 0;     int prev = -1;     for (int i = 0; i < 2 * n; i++) {       int j = i;       while (j + 1 < 2 * n && e[j + 1].p == e[i].p) j++;       ans += 1LL * Get(root) * (e[i].p - prev);       for (int k = i; k <= j; k++) {         if (e[k].type ==  + ) {           Add(e[k].L, e[k].R, 1, 0, 2 * inf, root);         } else {           Add(e[k].L, e[k].R, -1, 0, 2 * inf, root);         }       }       i = j;       prev = e[i].p;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m;     cin >> n >> m;     map<int, int> a;     long long x;     for (long long i = 0; i < m; i++) {       cin >> x;       a[x]++;     }     long long mini = INT_MAX;     for (long long i = 1; i <= n; i++) {       if (mini > a[i]) {         mini = a[i];       }     }     cout << mini << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x;     string s1, s2;     int cnt = 0;     cin >> x >> ws;     for (int i = x; i; i--) {       cin >> s1;       cin >> s2;       if (s2.compare( soft ) == 0) cnt++;     }     if (x - cnt > cnt) cnt = x - cnt;     for (int i = 0; i < 100; ++i) {       if (i * i / 2 + i % 2 >= cnt && i * i >= x) {         cout << i << endl;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1, c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f ^= 1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return f ? x : -x;   }   const int N = 200005;   int n, m;   char s[N];   struct H {     int a, b;   };   H h[N][26], pw[N];   const int mul1 = 233, mod1 = 998244353;   const int mul2 = 19260817, mod2 = 1000000007;   vector<H> cal(int x, int l) {     vector<H> ans;     for (int i = 0; i < 26; ++i) {       H a = (H){};       a.a = (h[x + l][i].a - 1LL * h[x][i].a * pw[l].a % mod1 + mod1) % mod1;       a.b = (h[x + l][i].b - 1LL * h[x][i].b * pw[l].b % mod2 + mod2) % mod2;       ans.push_back(a);     }     sort(ans.begin(), ans.end(), [&](H a, H b) {       if (a.a != b.a) return a.a < b.a;       return a.b < b.b;     });     return ans;   }   int main() {     n = read(), m = read();     scanf( %s , s);     pw[0].a = pw[0].b = 1;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < 26; ++j) {         h[i + 1][j].a = 1LL * h[i][j].a * mul1 % mod1;         h[i + 1][j].b = 1LL * h[i][j].b * mul2 % mod2;       }       h[i + 1][s[i] -  a ].a = (h[i + 1][s[i] -  a ].a + 1) % mod1;       h[i + 1][s[i] -  a ].b = (h[i + 1][s[i] -  a ].b + 1) % mod2;       pw[i + 1].a = 1LL * pw[i].a * mul1 % mod1;       pw[i + 1].b = 1LL * pw[i].b * mul2 % mod2;     }     for (; m--;) {       int x = read() - 1, y = read() - 1, l = read();       vector<H> a = cal(x, l), b = cal(y, l);       bool ok = 1;       for (int i = 0; i < 26; ++i) {         if (a[i].a != b[i].a || a[i].b != b[i].b) ok = 0;       }       puts(ok ?  YES  :  NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int cir = 0;     bool ans = true;     int now;     for (int i = 0; i < n; i++) {       if (!i) {         scanf( %d , &now);         continue;       }       int temp;       scanf( %d , &temp);       if (temp > now) {         if (cir != 0) {           ans = false;         }         now = temp;       } else if (temp == now) {         if (cir == 0) {           cir = 1;         } else if (cir == 1) {         } else {           ans = false;         }       } else {         if (cir == 0 || cir == 1) {           cir = 2;         }       }       now = temp;     }     if (ans)       printf( YES n );     else       printf( NO n );   }


#include <bits/stdc++.h>   using namespace std;   int c[3];   void solve() {     int m, n;     cin >> m >> n;     vector<vector<int>> matrix(m, vector<int>(n));     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         cin >> matrix[i][j];       }     }     for (int i = m - 1; i >= 0; --i) {       for (int j = n - 1; j >= 0; --j) {         if (matrix[i][j] != 0) {           continue;         } else {           int check;           check = matrix[i][j + 1] - 1;           if (check >= matrix[i + 1][j]) check = matrix[i + 1][j] - 1;           matrix[i][j] = check;         }       }     }     for (int i = m - 1; i >= 0; --i) {       for (int j = n - 1; j >= 0; --j) {         if (i != 0 && j != 0) {           if ((matrix[i][j] <= matrix[i][j - 1]) ||               (matrix[i][j] <= matrix[i - 1][j])) {             cout <<  -1  << endl;             return;           }         }       }     }     int sum = 0;     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         sum += matrix[i][j];       }     }     cout << sum << endl;     return;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t, x, y, f1, f2, f3, f4, LIMH = 100000, LIML = -100000;     cin >> t;     while (t--) {       int q;       cin >> q;       int hiX, loX, hiY, loY;       hiX = LIMH;       hiY = LIMH;       loX = LIML;       loY = LIML;       for (int i = 0; i < q; i++) {         cin >> x >> y >> f1 >> f2 >> f3 >> f4;         if (!f1 && x > loX) loX = x;         if (!f2 && y < hiY) hiY = y;         if (!f3 && x < hiX) hiX = x;         if (!f4 && y > loY) loY = y;       }       if (loX > hiX || loY > hiY)         cout << 0 << endl;       else         cout << 1 <<     << loX <<     << loY << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     string str;     for (int o = 0; o < t; o++) {       cin >> str;       int n = str.length();       int pre = 0, suf = 0, total = 0;       if (str[0] ==  1 ) {         pre = 0;       } else {         pre = 1;         for (int i = 1; i < n; i++) {           if (str[i] ==  0 ) {             pre = pre + 1;           } else {             break;           }         }       }       if (str[n - 1] ==  1 ) {         suf = 0;       } else {         suf = 1;         for (int j = n - 2; j > 0; j--) {           if (str[j] ==  0 ) {             suf = suf + 1;           } else {             break;           }         }       }       for (int k = 0; k < n; k++) {         if (str[k] ==  0 ) {           total = total + 1;         }       }       int ans = total - suf - pre;       if (pre == total) {         cout <<  0  << endl;       } else {         cout << ans << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 1;   int n, m, s;   int b[maxn];   int p[maxn];   int ansn, anst;   bool ok(int k) {     int i = n - 1;     int j = k - 1;     int tansn = 0, tanst = 0;     int ss = s;     while (j >= 0) {       if (i >= 0 && b[i] >= p[j]) {         tanst += p[j];         tansn++;         j--;         i--;       } else if (i >= 0 && p[j] > b[i] && ss >= p[j] - b[i]) {         tanst += b[i];         tansn++;         ss -= (p[j] - b[i]);         j--;         i--;       } else if (i >= 0)         i--;       else         j--;     }     if (ss > 0) tanst = max(0, tanst - ss);     if (tansn == k && tansn > ansn) {       ansn = tansn;       anst = tanst;     }     return tansn == k;   }   int main() {     scanf( %d %d %d , &n, &m, &s);     for (int i = 0; i < n; i++) scanf( %d , b + i);     for (int i = 0; i < m; i++) scanf( %d , p + i);     sort(b, b + n);     sort(p, p + m);     int l = 0;     int r = m + 1;     int mid;     while (l + 1 < r) {       mid = (l + r) / 2;       if (ok(mid))         l = mid;       else         r = mid;     }     printf( %d %d n , ansn, anst);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     char ch[6] =  aaaaa ;     int ara[4] = {0};     cin >> s;     map<char, int> ms, ms2;     for (int i = 0; i < s.size(); i += 4) {       for (int j = 0; j < 4 && (i + j) < s.size(); j++) {         if (s[i + j] ==  ! ) {           ara[j]++;         } else {           ch[j] = s[i + j];           if (!ms2[ch[j]]) ms2[ch[j]] = j;         }       }     }     int sz = s.size();     for (int i = 0; i < 4; i++) {       if (ch[i] ==  a ) {         if (!ms2[ R ]) {           ch[i] =  R ;           ms2[ R ] = 1;         } else if (!ms2[ G ]) {           ch[i] =  G ;           ms2[ G ] = 1;         } else if (!ms2[ B ]) {           ch[i] =  B ;           ms2[ B ] = 1;         } else if (!ms2[ Y ]) {           ch[i] =  Y ;           ms2[ Y ] = 1;         }       }       ms[ch[i]] = ara[i];     }     cout << ms[ R ] <<     << ms[ B ] <<     << ms[ Y ] <<     << ms[ G ];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int DBG = 0, INF = int(1e9);   string toString(long long k) {     stringstream ss;     ss << k;     string res;     ss >> res;     return res;   }   int toInt(string s) {     stringstream ss;     ss << s;     int res;     ss >> res;     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cout.setf(ios::fixed);     cout << setprecision(10);     int n, a, d;     cin >> n >> a >> d;     vector<pair<int, int> > V(n);     for (int _n = (n), i = 0; i < _n; ++i) cin >> V[i].first >> V[i].second;     double prev = -1;     for (int _n = (n), i = 0; i < _n; ++i) {       double accTime = double(V[i].second) / double(a);       double accDst = double(V[i].second) * accTime * 0.5;       if (accDst >= d) {         double t = sqrt((2. * double(d)) / double(a));         prev = max(t + double(V[i].first), prev);       } else {         double remDst = d - accDst;         double remTime = remDst / double(V[i].second);         prev = max(accTime + remTime + double(V[i].first), prev);       }       cout << prev << endl;     }     return 0;   }


#include <bits/stdc++.h>   const long long mod = 998244353;   const long long inf = 1e18 + 10;   using namespace std;   long long modpow(long long a, long long b) {     long long res = 1;     while (b) {       if (b % 2) {         res *= a;       }       a *= a;       res %= mod;       a %= mod;       b /= 2;     }     return res;   }   long long nCr(long long n, long long r) {     long long f = 1;     for (long long i = 2; i <= n; i++) {       f *= i;       f %= mod;     }     long long q = 1;     for (long long i = 2; i <= r; i++) {       q *= i;       q %= mod;     }     long long q2 = 1;     for (long long i = 2; i <= n - r; i++) {       q2 *= i;       q2 %= mod;     }     q = modpow(q, mod - 2);     q2 = modpow(q2, mod - 2);     f *= q;     f %= mod;     f *= q2;     f %= mod;     return f;   }   int32_t main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     long long a[2 * n];     for (long long i = 0; i < 2 * n; i++) cin >> a[i];     sort(a, a + 2 * n);     long long l = 0, r = 0;     for (long long i = 0; i < n; i++) l += a[i];     for (long long i = n; i < 2 * n; i++) r += a[i];     long long ans = r - l;     ans %= mod;     cout << ((ans * nCr(2 * n, n)) % mod) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const unsigned int N = 150;   unsigned int n, p, q, now[N], c[N], ans;   inline unsigned int read() {     unsigned 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 = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   unsigned int gcd(unsigned int a, unsigned int b) {     return !b ? a : gcd(b, a % b);   }   signed main() {     n = read();     p = read();     q = read();     for (unsigned int i = 0; i <= min(p, n - 1); i++) {       for (unsigned int j = 1; j <= i; j++) now[j] = n - j + 1;       for (unsigned int j = 1; j <= i; j++) {         unsigned int x = j;         for (unsigned int k = i; k >= 1; k--) {           unsigned int g = gcd(now[k], x);           if (g != 1) {             now[k] /= g;             x /= g;             if (x == 1) break;           }         }       }       c[i] = 1;       for (unsigned int j = 1; j <= i; j++) c[i] = c[i] * now[j];     }     for (unsigned int i = 1; i <= q; i++) {       unsigned int res = 0, em = 1;       for (unsigned int j = 0; j <= min(p, n - 1); j++) {         res += em * c[j];         em = em * i;       }       ans ^= (res * i);     }     cout << ans << endl;     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     cin >> n >> x;     int eq = 0;     int minPos = 1, maxPos;     for (int i(0); i < n; i++) {       int a;       cin >> a;       if (a < x)         minPos++;       else if (a == x)         eq++;     }     int c = 0;     if (eq == 0) {       c++;       maxPos = minPos;     } else       maxPos = minPos + eq - 1;     while ((minPos > (n + c + 1) / 2) || (maxPos < (n + c + 1) / 2)) {       if (maxPos < (n + c + 1) / 2) {         minPos++;         maxPos++;       };       c++;     }     cout << c << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100100;   const long long oo = 1e18;   int N;   long long P[MAX], D[MAX];   int L[MAX], R[MAX];   void init_L() {     stack<int> S;     for (int i = 0; i <= N + 1; ++i) {       while (S.size() >= 2) {         int x = S.top();         S.pop();         if (D[x] >= P[i] - P[S.top()]) {           S.push(x);           break;         }       }       if (!S.empty()) L[i] = S.top();       S.push(i);     }   }   void init_R() {     stack<int> S;     for (int i = N + 1; i >= 0; --i) {       while (S.size() >= 2) {         int x = S.top();         S.pop();         if (D[x] >= P[S.top()] - P[i]) {           S.push(x);           break;         }       }       if (!S.empty()) R[i] = S.top();       S.push(i);     }   }   long long low(int x) {     if (x == N + 1) return -1e10;     long long ret = P[R[x]] - D[x];     return ret < P[x] ? ret : +oo;   }   long long high(int x) {     if (x == 0) return +1e10;     long long ret = P[L[x]] + D[x];     return ret > P[x] ? ret : -oo;   }   bool check(long long W) {     multiset<long long> S;     for (int a = 0, b = 0; a <= N; ++a) {       for (; b <= N + 1 && P[b] - P[a] <= W; ++b) S.insert(low(b));       S.erase(S.find(low(a)));       if (!S.empty() && high(a) >= *S.begin()) return true;     }     return false;   }   int main() {     scanf( %d , &N);     for (int i = 0; i <= N + 1; ++i) scanf( %lld , P + i);     for (int i = 1; i <= N; ++i) scanf( %lld , D + i), D[i] *= 2;     D[0] = D[N + 1] = oo;     init_L();     init_R();     if (R[0] != N + 1) {       puts( 0 );       return 0;     }     long long lo = 1, hi = 1e10;     while (lo < hi) {       long long mid = (lo + hi) / 2;       check(mid) ? hi = mid : lo = mid + 1;     }     printf( %.1lf n , lo / 2.0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double C = 0.57721566490153286060651209;   const double pi = acos(-1.0);   const int mod = 1e9 + 7;   const int maxn = 1e5 + 10;   int a[maxn];   int b[maxn];   int used[maxn];   int main() {     int n;     scanf( %d , &n);     int k = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       b[a[i]]++;       if (b[a[i]] & 1)         k++;       else         k--;     }     if (k > 1) {       printf( 0 n );       return 0;     }     long long pos = 0;     for (int i = 1; i <= n / 2; ++i)       if (a[i] != a[n - i + 1]) {         pos = i;         break;       } else         b[a[i]] -= 2;     if (!pos) {       printf( %lld n , 1LL * n * (n + 1) / 2);       return 0;     }     int len = 0;     for (int i = pos; i <= n; ++i) {       used[a[i]]++;       if (used[a[i]] * 2 > b[a[i]]) {         if (i < n - i + 1 || (i == n - i + 1 && b[a[i]] % 2 == 0) ||             a[i] != a[n - i + 1])           break;       }       len++;     }     memset(used, 0, sizeof used);     for (int i = n - pos + 1; i >= 1; --i) {       used[a[i]]++;       if (used[a[i]] * 2 > b[a[i]])         if (i > n - i + 1 || (i == n - i + 1 && b[a[i]] % 2 == 0) ||             a[i] != a[n - i + 1])           break;       len++;     }     printf( %lld n , pos * (pos + len));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(n);     int ans = 0, cnt = 0;     for (int i = 0; i < n; i++) {       cin >> v[i];     }     for (int i = 0; i < n; i++) {       if (v[i] == i)         ans++;       else if (v[v[i]] == i) {         cnt = 1;       }     }     cout << min(ans + cnt + 1, n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   long long arr[200001];   vector<long long> v;   string s;   int find(int i) {     int curr = v[i];     int num = i;     for (int j = i + 1; j < n; j++)       if (v[j] == curr)         num = j;       else         break;     return num;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> arr[i];     cin >> s;     for (int i = 0; i < n; i++) {       int a = s[i] -  a ;       v.push_back(a);     }     int count = 1;     long long d = 0;     int prev;     for (int i = 0; i < n; i++) {       int nx = find(i);       int dis = nx - i + 1;       if (dis <= k) {         for (int j = i; j <= nx; j++) d += arr[j];       } else {         sort(arr + i, arr + nx + 1);         for (int j = nx; j >= nx - k + 1; j--) d += arr[j];       }       i = nx;     }     cout << d;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[500010], ar;   bool vis[500010];   int u, v, n, m, s, res = 0;   void dfs(int cur) {     vis[cur] = true;     for (auto i : adj[cur])       if (!vis[i]) dfs(i);     ar.push_back(cur);   }   int main() {     scanf( %d%d%d , &n, &m, &s);     for (int i = 0; i < m; ++i) {       scanf( %d%d , &u, &v);       adj[u].push_back(v);     }     dfs(s);     for (int i = 1; i <= n; ++i) {       if (!vis[i]) dfs(i);     }     memset(vis, false, sizeof vis);     for (int i = n - 1; i >= 0; --i) {       if (!vis[ar[i]]) {         if (s != ar[i]) res++;         dfs(ar[i]);       }     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   long long a[100005];   long long count[100005];   int vis[100005];   struct Element {     long long l, r;     Element(long long l, long long r) : l(l), r(r) {}   };   Element getCount(long long k, int n) {     long long lower = 0, upper = 0;     int met = 0;     for (int i = 1; i <= n; i++) {       long long l = 1, r = a[i];       long long res = 0;       while (l <= r) {         long long m = (l + r) / 2;         long long value = a[i] - 3ll * m * m + 3 * m - 1;         if (value >= k) {           res = m;           l = m + 1;         } else           r = m - 1;       }       lower += res, upper += res;       count[i] = res;       long long value = a[i] - 3ll * res * res + 3 * res - 1;       if (value == k) {         vis[i] = 1;         count[i]--;         if (!met)           met = 1;         else           lower--;       } else         vis[i] = 0;     }     return Element(lower, upper);   }   int main() {     int n;     long long k;     scanf( %d%lld , &n, &k);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     long long l = -3e18, r = 1e10;     while (l <= r) {       long long m = (l + r) / 2;       Element u = getCount(m, n);       if (u.l > k)         l = m + 1;       else if (u.r < k)         r = m - 1;       else {         break;       }     }     long long need = k;     for (int i = 1; i <= n; i++) need -= count[i];     for (int i = 1; i <= n; i++) {       if (need && vis[i]) {         need--;         count[i]++;       }       printf( %lld  , count[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, s, k, a[2010], b[2010], nxt[2010], sum[2010], dp[2010][2010];   inline int read() {     int s = 0, w = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) w = -1;     for (; isdigit(c); c = getchar()) s = (s << 1) + (s << 3) + (c ^ 48);     return s * w;   }   bool check(int mid) {     for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + (a[i] <= b[mid]);     memset(dp, 0, sizeof(dp));     for (int i = 1; i <= s; ++i) {       for (int j = 1; j <= n; ++j) dp[i][j] = max(dp[i][j], dp[i - 1][j]);       for (int j = 1; j <= n; ++j)         if (nxt[j])           dp[i][nxt[j]] =               max(dp[i][nxt[j]], dp[i - 1][j - 1] + sum[nxt[j]] - sum[j - 1]);       for (int j = 1; j <= n; ++j) dp[i][j] = max(dp[i][j - 1], dp[i][j]);     }     return dp[s][n] >= k;   }   int main() {     n = read(), m = read(), s = read(), k = read();     for (int i = 1; i <= n; ++i) a[i] = read(), b[i] = a[i];     sort(b + 1, b + 1 + n);     for (int i = 1; i <= m; ++i) {       int l = read(), r = read();       for (int j = l; j <= r; ++j) nxt[j] = max(nxt[j], r);     }     int l = 1, r = n, ans = -1;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid))         ans = b[mid], r = mid - 1;       else         l = mid + 1;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   string a;   int b[10000];   int memo[2000][2000];   int dp(int i, int d) {     if (abs(d) == k && i == a.length()) return 0;     if (i == a.length() || abs(d) == k) return 1;     if (memo[i][d] != -1) return memo[i][d];     int x;     if (a[i] ==  L )       x = dp(i + 1, d - 1);     else if (a[i] ==  W )       x = dp(i + 1, d + 1);     else if (a[i] ==  D )       x = dp(i + 1, d);     else {       b[i] =  W  -  A ;       x = dp(i + 1, d + 1);       if (x == 1) {         b[i] =  L  -  A ;         x = dp(i + 1, d - 1);       }       if (x == 1) {         b[i] =  D  -  A ;         x = dp(i + 1, d);       }     }     return memo[i][d] = x;   }   int main() {     memset(memo, -1, sizeof(memo));     cin >> n >> k >> a;     if (dp(0, 0) == 1)       cout <<  NO ;     else {       for (int i = 0; i < a.length(); i++) {         if (a[i] !=  ? )           cout << a[i];         else           cout << (char)(b[i] +  A );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e3 + 5;   const double eps = 1e-10;   struct TARGET {     int x, y, t;     double p;   } mp[MAX_N];   int n;   double dis[MAX_N][MAX_N];   double dp[MAX_N];   bool MAP_CMP(TARGET a, TARGET b) { return a.t < b.t; }   void input() {     scanf( %d , &n);     for (int i = 0; i < n; i++)       scanf( %d%d%d%lf , &mp[i].x, &mp[i].y, &mp[i].t, &mp[i].p);   }   int sqr(int x) { return x * x; }   void solve() {     sort(mp, mp + n, MAP_CMP);     for (int i = 0; i < n; i++)       for (int j = 0; j < i; j++)         dis[i][j] = dis[j][i] = sqr(mp[i].x - mp[j].x) + sqr(mp[i].y - mp[j].y);     for (int i = 0; i < n; i++) dp[i] = mp[i].p;     for (int i = 0; i < n; i++)       for (int j = 0; j < i; j++) {         if (1ll * (mp[i].t - mp[j].t) * (mp[i].t - mp[j].t) >= dis[i][j])           dp[i] = max(dp[i], dp[j] + mp[i].p);       }     double ans = 0.0;     for (int i = 0; i < n; i++)       if (dp[i] > ans) ans = dp[i];     printf( %.6f n , ans);   }   int main() {     input();     solve();     return 0;   }


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


#include <bits/stdc++.h>   const int M = 1e9 + 7, N = 2 * 1e5 + 3;   using namespace std;   int main() {     long long a, b, f, k, b0;     cin >> a >> b >> f >> k;     b0 = b;     int ans = 0;     if (b < f || b < a - f) {       cout << -1;       return 0;     }     b0 = b - f;     if (b0 < 0) {       cout << -1;       return 0;     }     bool q = 1;     while (k > 1) {       if (q) {         if (b0 < (a - f) * 2) b0 = b, ans++;         b0 -= (a - f) * 2;         if (b0 < 0) {           cout << -1;           return 0;         }         q = 0;         k--;       } else {         if (b0 < 2 * f) b0 = b, ans++;         b0 -= 2 * f;         if (b0 < 0) {           cout << -1;           return 0;         }         q = 1;         k--;       }     }     if (q && b0 < a - f || !q && b0 < f)       cout << ans + 1;     else       cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e5 + 7;   const long long inf = 0x3f3f3f3f3f3f3f;   const long long mod = 20000311;   int n;   vector<int> a(100), b(100);   vector<int> step[100], ves[100];   void solve(int n) {     int st = 0;     for (int i = 0; i < step[n].size(); i++) {       ves[i].clear();       for (int j = st; j < st + step[n][i]; j++) ves[i].push_back(a[j]);       st += step[n][i];     }     a.clear();     for (int i = step[n].size() - 1; i >= 0; i--)       for (auto j : ves[i]) a.push_back(j);   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i], b[a[i]] = i;     if (n == 1) {       cout << 0 <<   n ;       return 0;     }     step[1].push_back(b[1]), step[1].push_back(n - b[1]);     solve(1);     int flag = n % 2 == 0;     for (int go = 2; go + flag <= n; go++) {       if (go % 2 == 0) {         for (int i = 1; i < go; i++) step[go].push_back(1);         int cnt = 1;         while (a[cnt] != go) cnt++;         if (cnt - go + 2) step[go].push_back(cnt - go + 2);         if (n - cnt - 1) step[go].push_back(n - cnt - 1);         solve(go);       } else {         int cnt = n - 1;         while (a[cnt] != go) cnt--;         if (cnt) step[go].push_back(cnt);         if (n - go + 1 - cnt) step[go].push_back(n - go + 1 - cnt);         for (int i = 1; i < go; i++) step[go].push_back(1);         solve(go);       }     }     int tot = 0, st = 1;     if (b[1] == 0) st = 2;     cout << n - flag - st + 1 <<   n ;     for (int i = st; i <= n - flag; i++) {       cout << step[i].size() <<    ;       for (auto j : step[i]) cout << j <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 3;   struct tree {     int l, r, minn, lazy;     long long sum;   } tre[MAXN << 2];   int n, m;   long long a[MAXN];   void build(int i, int l, int r) {     tre[i].l = l, tre[i].r = r;     tre[i].lazy = 0;     if (l == r) {       tre[i].minn = a[l];       tre[i].sum = a[l];       return;     }     int mid = l + r >> 1;     build(i << 1, l, mid);     build(i << 1 | 1, mid + 1, r);     tre[i].minn = min(tre[i << 1].minn, tre[i << 1 | 1].minn);     tre[i].sum = tre[i << 1].sum + tre[i << 1 | 1].sum;   }   void pushdown(int i) {     if (tre[i].lazy) {       tre[i << 1].minn = tre[i].lazy, tre[i << 1 | 1].minn = tre[i].lazy;       tre[i << 1].lazy = tre[i << 1 | 1].lazy = tre[i].lazy;       tre[i << 1].sum = 1ll * (tre[i << 1].r - tre[i << 1].l + 1) * tre[i].lazy;       tre[i << 1 | 1].sum =           1ll * (tre[i << 1 | 1].r - tre[i << 1 | 1].l + 1) * tre[i].lazy;       tre[i].lazy = 0;     }   }   int find_(int i, int l, int r, long long x) {     if (tre[i].l >= l && tre[i].r <= r) {       if (tre[i].minn > x) return 0;       if (tre[i].l == tre[i].r) {         if (tre[i].minn <= x) return tre[i].r;         return 0;       }       pushdown(i);       tre[i].minn = min(tre[i << 1].minn, tre[i << 1 | 1].minn);       tre[i].sum = tre[i << 1].sum + tre[i << 1 | 1].sum;       if (tre[i << 1].minn > x) return find_(i << 1 | 1, l, r, x);       return find_(i << 1, l, r, x);     }     if (tre[i].l == tre[i].r) return 0;     pushdown(i);     int ans = 0;     if (tre[i << 1].r >= l) ans = find_(i << 1, l, r, x);     if (!ans && tre[i << 1 | 1].l <= r) {       ans = find_(i << 1 | 1, l, r, x);     }     tre[i].minn = min(tre[i << 1].minn, tre[i << 1 | 1].minn);     tre[i].sum = tre[i << 1].sum + tre[i << 1 | 1].sum;     return ans;   }   void modify(int i, int l, int r, int delta) {     if (tre[i].l > r || tre[i].r < l) return;     if (tre[i].l >= l && tre[i].r <= r) {       tre[i].lazy = delta;       tre[i].minn = delta;       tre[i].sum = 1ll * (tre[i].r - tre[i].l + 1) * delta;       return;     }     pushdown(i);     modify(i << 1, l, r, delta);     modify(i << 1 | 1, l, r, delta);     tre[i].minn = min(tre[i << 1].minn, tre[i << 1 | 1].minn);     tre[i].sum = tre[i << 1].sum + tre[i << 1 | 1].sum;   }   bool flag;   void que(int i, long long &delta, int &tot) {     if (tre[i].l == tre[i].r) {       if (delta >= tre[i].sum) tot = max(tot, tre[i].r), delta -= tre[i].sum;       return;     }     pushdown(i);     tre[i].minn = min(tre[i << 1].minn, tre[i << 1 | 1].minn);     tre[i].sum = tre[i << 1].sum + tre[i << 1 | 1].sum;     if (tre[i << 1].sum <= delta) {       tot = max(tot, tre[i << 1].r);       delta -= tre[i << 1].sum;       que(i << 1 | 1, delta, tot);     } else {       que(i << 1, delta, tot);     }   }   void query(int i, int l, int r, long long &delta, int &tot) {     if (tre[i].l > r || tre[i].r < l || flag) return;     if (tre[i].l >= l && tre[i].r <= r) {       if (tre[i].sum <= delta) {         tot = max(tre[i].r, tot);         delta -= tre[i].sum;         return;       }       if (tre[i].l == tre[i].r) {         if (tre[i].sum <= delta) {           tot = max(tot, tre[i].r), delta -= tre[i].sum;         } else           flag = 1;         return;       }       flag = 1;       que(i, delta, tot);       pushdown(i);       tre[i].minn = min(tre[i << 1].minn, tre[i << 1 | 1].minn);       tre[i].sum = tre[i << 1].sum + tre[i << 1 | 1].sum;       return;     }     pushdown(i);     tre[i].minn = min(tre[i << 1].minn, tre[i << 1 | 1].minn);     tre[i].sum = tre[i << 1].sum + tre[i << 1 | 1].sum;     query(i << 1, l, r, delta, tot);     query(i << 1 | 1, l, r, delta, tot);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     build(1, 1, n);     for (int i = 1; i <= m; i++) {       int x, op;       long long y;       scanf( %d%d%lld , &op, &x, &y);       if (op == 1) {         int tot = find_(1, 1, x, y);         if (!tot) continue;         modify(1, tot, x, y);       } else {         int an = 0;         while (x <= n) {           int tot = find_(1, x, n, y);           int tot1 = 0;           flag = 0;           query(1, tot, n, y, tot1);           if (tot == 0 || tot1 == 0) break;           an += tot1 - tot + 1, x = tot1 + 1;         }         printf( %d n , an);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int vis[5][5];   int ac[5][5], bc[5][5];   pair<int, int> sum[100];   pair<int, int> cal(int a, int b) {     if (a == 1) {       if (b == 1)         return pair<int, int>(0, 0);       else if (b == 2)         return pair<int, int>(0, 1);       return pair<int, int>(1, 0);     } else if (a == 2) {       if (b == 1)         return pair<int, int>(1, 0);       else if (b == 2)         return pair<int, int>(0, 0);       return pair<int, int>(0, 1);     } else {       if (b == 1)         return pair<int, int>(0, 1);       else if (b == 2)         return pair<int, int>(1, 0);       return pair<int, int>(0, 0);     }   }   int main() {     long long k, pa = 0, pb = 0;     int a, b;     scanf( %lld%d%d , &k, &a, &b);     for (int i = 1; i <= 3; i++)       for (int j = 1; j <= 3; j++) scanf( %d , &ac[i][j]);     for (int i = 1; i <= 3; i++)       for (int j = 1; j <= 3; j++) scanf( %d , &bc[i][j]);     int sz = 1;     vis[a][b] = sz++;     sum[1] = cal(a, b);     int last = 1;     for (int i = 1; i <= k; i++) {       int na = ac[a][b];       int nb = bc[a][b];       if (vis[na][nb]) {         last = vis[na][nb];         break;       }       a = na, b = nb;       vis[a][b] = sz;       sum[sz] = pair<int, int>(sum[sz - 1].first + cal(a, b).first,                                sum[sz - 1].second + cal(a, b).second);       sz++;     }     sz--;     if (sz == k) {       printf( %d %d n , sum[sz].first, sum[sz].second);       return 0;     }     pa += sum[last - 1].first;     pb += sum[last - 1].second;     k -= last - 1;     long long dv = k / (sz - last + 1);     pa += dv * (sum[sz].first - sum[last - 1].first);     pb += dv * (sum[sz].second - sum[last - 1].second);     k %= (sz - last + 1);     if (k != 0) {       pa += (sum[last + k - 1].first - sum[last - 1].first);       pb += (sum[last + k - 1].second - sum[last - 1].second);     }     printf( %lld %lld n , pa, pb);   }


#include <bits/stdc++.h>   using namespace std;   int n, m, q, a[501][501], x, y, s, ans;   vector<int> v;   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> q;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> a[i][j];     for (int p = 1; p <= q; p++) {       cin >> x >> y;       if (a[x][y] == 1)         a[x][y] = 0;       else         a[x][y] = 1;       for (int i = 1; i <= n; i++) {         s = 0;         for (int j = 1; j <= m; j++) {           if (a[i][j] == 1)             s++;           else             s = 0;           ans = max(ans, s);         }       }       v.push_back(ans);       ans = 0;     }     for (int i = 0; i < v.size(); i++) cout << v[i] << endl;   }