#include <bits/stdc++.h>   using namespace std;   const int N = (int)3e5 + 1;   int n, m, a[N][10], p1 = 1, p2 = 1;   int ok[(1 << 8) + 1];   bool check(int x) {     memset(ok, 0, sizeof(ok));     for (int i = 1; i <= n; ++i) {       int mask = 0;       for (int j = 0; j < m; ++j) {         if (a[i][j] >= x) mask |= (1 << j);       }       for (int j = 0; j < (1 << m); ++j) {         if (ok[j] && (mask | j) == (1 << m) - 1) {           p1 = ok[j];           p2 = i;           return true;         }       }       ok[mask] = i;     }     return false;   }   void solve() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < m; ++j) cin >> a[i][j];     }     int l = 0, r = (int)1e9;     while (l <= r) {       int mid = (l + r) / 2;       if (check(mid)) {         l = mid + 1;       } else         r = mid - 1;     }     cout << p1 <<     << p2;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int num[102];     int a, i, sum = 0, flag = 1;     scanf( %d , &a);     for (i = 0; i < a; i++) {       scanf( %d , &num[i]);     }     if (a < 3) {       printf( -1 n );     } else {       for (i = a - 1; i >= 0; i--) {         if (i == a - 1 && i % 2 && num[i]) {           flag = 0;           break;         }         if (num[i] > 0) {           if (i % 2) {             sum += num[i];             num[i / 2] -= num[i];             num[i] = 0;           } else {             sum += num[i];             if (i) {               num[i - 1] -= num[i];               num[i / 2 - 1] -= num[i];             }             num[i] = 0;           }         }       }       if (flag) {         printf( %d n , sum);       } else {         printf( -1 n );       }     }     return 0;   }


#include <bits/stdc++.h>   #define F(i,j,k) for(int i=(j);i<=(k);++i)   #define D(i,j,k) for(int i=(j);i>=(k);--i)   #define rep(it,s) for(__typeof(s.begin()) it=s.begin();it!=s.end();++it)   #define Rep(a,s) for(auto a:s)   #define PB push_back   #define MP make_pair   #define FF first   #define SS second   typedef long long ll;   typedef unsigned long long ull;   using namespace std;   ll quick_pow(ll x,ll y,ll Mod){       ll res=1;       while(y){           if(y&1)res=res*x%Mod;           x=x*x%Mod,y>>=1;       }       return res;   }   ll inv(ll x,ll Mod){return quick_pow(x,Mod-2,Mod);}   namespace IO{       template <class T>       inline void read(T &x){           x=0;int f=1;char ch=getchar();           while(ch< 0 ||ch> 9 ){if(ch== - )f=-1;ch=getchar();}           while(ch<= 9 &&ch>= 0 )x=x*10+ch- 0 ,ch=getchar();           x*=f;       }   };   using namespace IO;   const int N=100005;   vector<int>ans,vec0,vec1;   bool calc(int x,int y){    if(x==0||x==2)return 0;//没间隔     if(x>1&&y==0)return 0;    if(x%2==0&&y<=1)return 0;    if(x%2==0){     ans.PB(2);     x-=3;    }    while(x>1){     ans.PB(1);     x-=2;    }    return 1;   }   void solve(int x){    int flag=1;    ans.clear();    //Rep(y,vec0){    for(int i=0;i<vec0.size();i++){     int y=vec0[i];     flag&=calc(y-x,x);     if(i+1!=vec0.size())ans.PB(vec1[i]+x);    }    if(flag){     cout<<ans.size()<<  n ;     Rep(y,ans)cout<<y<<   ;     exit(0);    }   }   char s[N];   int cnt0,cnt1;   int main(){       #ifndef ONLINE_JUDGE           freopen( in.txt , r ,stdin);           //freopen( out.txt , w ,stdout);       #endif       scanf( %s n ,s+1);    int n=strlen(s+1);    //if(s[1]== # )vec0.PB(1);    F(i,1,n){     if(s[i]== _ ){      if(cnt1)vec1.PB(cnt1);      cnt1=0,cnt0++;     }     else{      if(!vec0.size())vec0.PB(cnt0+1);      else if(cnt0)vec0.PB(cnt0);      cnt0=0,cnt1++;     }    }    vec0.PB(cnt0+1);    if(cnt1)vec1.PB(cnt1);    //Rep(y,vec0)cout<<y<<   ;cout<<endl;    //Rep(y,vec1)cout<<y<<   ;cout<<endl;    if(!vec1.size()){     cout<<0<<  n n ;     return 0;    }    int mink=1e9;    Rep(y,vec0)mink=min(mink,y);    F(i,0,min(mink,3)){     solve(i);    }    cout<<-1;       return 0;   }


#include <bits/stdc++.h>   const long long INF32 = 1e9;   const long long INF64 = 1e17;   const int RANGE = 1e6 + 5;   using namespace std;   template <class T>   void read(T &Val) {     T tmp = 0;     char ch = getchar();     int flag = 1;     while (!(ch >=  0  && ch <=  9 )) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while ((ch >=  0  && ch <=  9 )) {       tmp = tmp * 10 + ch -  0 ;       ch = getchar();     }     Val = flag * tmp;   }   int q, cnt;   int n, m;   char data[300][300];   int bigX[] = {0, 1, -1, 0, 1, -1, 1, -1}, bigY[] = {1, 0, 0, -1, 1, -1, -1, 1};   void check(int x, int y) {     if (x < 0 or y < 0 or x >= m or y >= n or data[y][x] !=  1 ) return;     data[y][x] =  2 ;     cnt++;     for (int i = 0; i < 8; i++) check(x + bigX[i], y + bigY[i]);   }   int tell_square(int y, int x, int d) {     int yy = y + d, xx = x + d;     if (yy >= n or xx >= m) return 0;     for (int i = x; i <= xx; i++) {       if (data[y][i] !=  2  or data[yy][i] !=  2 ) return 0;     }     for (int i = y; i <= yy; i++) {       if (data[i][x] !=  2  or data[i][xx] !=  2 ) return 0;     }     return 1;   }   int tell_rombus(int y, int x, int d) {     int yy = y + d * 2, lxx = x - d, rxx = x + d;     if (yy >= n or rxx >= m or lxx < 0) return 0;     for (int i = 0; i <= d; i++) {       if (data[y + i][x + i] !=  2  or data[y + i + d][x + i - d] !=  2 ) {         return 0;       }     }     for (int i = 0; i <= d; i++) {       if (data[y + i][x - i] !=  2  or data[y + i + d][x - i + d] !=  2 ) {         return 0;       }     }     return 1;   }   int main() {     read(q);     while (q--) {       read(n), read(m);       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) cin >> data[i][j];       }       int ans = 0;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (data[i][j] ==  0  or data[i][j] ==  2 ) continue;           cnt = 0;           check(j, i);           if ((cnt % 4) != 0 or cnt / 4 > 250) continue;           ans = ans + tell_rombus(i, j, cnt / 4) + tell_square(i, j, cnt / 4);         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     string s;     while (t--) {       cin >> s;       vector<int> E, O;       int io = 0, ie = 0, prev = -1;       for (int i = 0; i < s.size(); ++i) {         if ((s[i] - 48) % 2 == 0) {           if (io < O.size() && ie < E.size() && prev == 1) {             while (io < O.size() && ie < E.size()) {               if (O[io] < E[ie])                 cout << O[io++];               else                 cout << E[ie++];             }           }           E.push_back(s[i] - 48);           prev = 0;         } else {           if (io < O.size() && ie < E.size() && prev == 0) {             while (io < O.size() && ie < E.size()) {               if (O[io] < E[ie])                 cout << O[io++];               else                 cout << E[ie++];             }           }           O.push_back(s[i] - 48);           prev = 1;         }       }       if (io < O.size() && ie < E.size()) {         while (io < O.size() && ie < E.size()) {           if (O[io] < E[ie])             cout << O[io++];           else             cout << E[ie++];         }       }       while (io < O.size()) cout << O[io++];       while (ie < E.size()) cout << E[ie++];       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using uint = unsigned int;   using ll = long long;   using ull = unsigned long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <typename T1, typename T2>   ostream &operator<<(ostream &out, const pair<T1, T2> &item) {     out <<  (  << item.first <<  ,   << item.second <<  ) ;     return out;   }   template <typename T>   ostream &operator<<(ostream &out, const vector<T> &v) {     for (const auto &item : v) out << item <<    ;     return out;   }   const double EPS = 1e-9;   int v[10];   int a[10][5];   vector<vector<int>> permutations;   double dist(const pair<pii, int> &a, const pair<pii, int> &b) {     return sqrt(1.0 * (a.first.first - b.first.first) *                     (a.first.first - b.first.first) +                 1.0 * (a.first.second - b.first.second) *                     (a.first.second - b.first.second) +                 1.0 * (a.second - b.second) * (a.second - b.second));   }   void check() {     vector<pair<pii, int>> b;     for (int i = 0; i < 8; ++i) {       const auto &p = permutations[v[i]];       b.push_back({{a[i][p[0]], a[i][p[1]]}, a[i][p[2]]});     }     for (int i = 0; i < 8; ++i)       for (int j = i + 1; j < 8; ++j)         if (b[i] == b[j]) return;     auto c1 = *min_element(b.begin(), b.end());     auto c2 = *max_element(b.begin(), b.end());     double aux = dist(c1, c2) / sqrt(3.0);     if (abs(aux - round(aux)) > EPS) return;     int d = round(aux);     vector<int> v1, v2;     for (int i = 0; i < 8; ++i) {       if (abs(dist(c1, b[i]) - d) < EPS) v1.push_back(i);       if (abs(dist(c2, b[i]) - d) < EPS) v2.push_back(i);     }     if (v1.size() != 3 || v2.size() != 3) return;     cout <<  YES n ;     for (int i = 0; i < 8; ++i)       cout << b[i].first.first <<     << b[i].first.second <<     << b[i].second            <<   n ;     exit(0);   }   void bkt(int k) {     if (k == 8) {       check();       return;     }     for (int i = 0; i < permutations.size(); ++i) {       v[k] = i;       bkt(k + 1);     }   }   int main() {     ios_base::sync_with_stdio(false);     vector<int> p = {0, 1, 2};     do {       permutations.push_back(p);     } while (next_permutation(p.begin(), p.end()));     for (int i = 0; i < 8; ++i)       for (int j = 0; j < 3; ++j) cin >> a[i][j];     bkt(1);     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int du[maxn];   set<int> g[maxn];   int b1[maxn], b2[maxn], ans[maxn], vis[maxn];   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     set<pair<int, int> > s;     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       b1[i] = x, b2[i] = y;       du[x]++, du[y]++;       g[x].insert(y);       g[y].insert(x);     }     for (int i = 1; i <= n; i++) s.insert(make_pair(du[i], i));     for (int i = m - 1; i >= 0; i--) {       while (s.size() >= 1) {         pair<int, int> itt = (*s.begin());         if (itt.first >= k) break;         for (set<int>::iterator it = g[itt.second].begin();              it != g[itt.second].end(); it++) {           int u = *it;           if (vis[u] == 1) continue;           s.erase(make_pair(du[u], u));           du[u]--;           s.insert(make_pair(du[u], u));           g[u].erase(itt.second);         }         s.erase(itt);         vis[itt.second] = 1;       }       ans[i] = s.size();       if (vis[b1[i]] == 0 && vis[b2[i]] == 0) {         s.erase(make_pair(du[b1[i]], b1[i]));         du[b1[i]]--;         s.insert(make_pair(du[b1[i]], b1[i]));         g[b1[i]].erase(b2[i]);         s.erase(make_pair(du[b2[i]], b2[i]));         du[b2[i]]--;         s.insert(make_pair(du[b2[i]], b2[i]));         g[b2[i]].erase(b1[i]);       }     }     for (int i = 0; i < m; i++) printf( %d n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t = 0;     cin >> t;     long long a = 0, b = 0;     for (int i = 0; i < t; i++) {       cin >> a >> b;       long long dif = abs(a - b);       long long res = dif / 5;       dif = dif % 5;       res += dif / 2;       dif %= 2;       res += dif;       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int lala = 2e9 + 1;   int max(int a, int b) { return a > b ? a : b; }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     pair<int, int> arr[100005];     int dp[3][100005];     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second;     arr[n].first = lala, arr[n].second = 0;     dp[0][0] = 0;     dp[1][0] = 1;     dp[2][0] = arr[0].first + arr[0].second < arr[1].first ? 1 : 0;     for (int i = 1; i < n; i++) {       dp[0][i] = max(dp[0][i - 1], max(dp[1][i - 1], dp[2][i - 1]));       if (arr[i].first - arr[i].second > arr[i - 1].first) {         if (arr[i].first - arr[i].second > arr[i - 1].first + arr[i - 1].second) {           dp[1][i] = dp[0][i] + 1;         } else {           dp[1][i] = dp[1][i - 1] + 1;         }       } else {         dp[1][i] = dp[0][i];       }       if (arr[i].first + arr[i].second < arr[i + 1].first) {         dp[2][i] = dp[0][i] + 1;       } else {         dp[2][i] = dp[0][i];       }     }     cout << max(dp[0][n - 1], max(dp[1][n - 1], dp[2][n - 1])) << endl;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   double eps = 1e-10;   const int maxn = 30005;   char s[105][105];   int num[105][105], ans[105];   int main() {     ios::sync_with_stdio;     cin.tie(0);     double a, b, c, d;     cin >> a >> b >> c >> d;     double l = 0, r = 1e9 + 7;     for (int i = 1; i <= 100; i++) {       double mid = (l + r) / 2.0;       double maxia = max(max((a + mid) * (d + mid), (a + mid) * (d - mid)),                          max((a - mid) * (d + mid), (a - mid) * (d - mid)));       double minia = min(min((a + mid) * (d + mid), (a + mid) * (d - mid)),                          min((a - mid) * (d + mid), (a - mid) * (d - mid)));       double maxib = max(max((b + mid) * (c + mid), (b + mid) * (c - mid)),                          max((b - mid) * (c + mid), (b - mid) * (c - mid)));       double minib = min(min((b + mid) * (c + mid), (b + mid) * (c - mid)),                          min((b - mid) * (c + mid), (b - mid) * (c - mid)));       if (maxia >= minib && maxia <= maxib || minia >= minib && minia <= maxib ||           maxib >= minia && maxib <= maxia || minib >= minia && minib <= maxia)         r = mid;       else         l = mid;     }     printf( %.10lf n , l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, long long> mp[15];   long long k, a[200010];   int n, l[200010], r[200010];   long long ans = 0;   int itos(long long x) {     int now = 0;     while (x) {       now++;       x /= 10;     }     return now;   }   void add(int p) {     long long now = a[p];     for (int i = 1; i <= 10; i++) {       now *= 10;       now %= k;       mp[i][now]++;       if (i == l[p]) r[p] = now;     }   }   void sub(long long x) {     long long now = x;     for (int i = 1; i <= 10; i++) {       now *= 10;       now %= k;       mp[i][now]--;     }   }   int cal(int p) {     int anss = 0;     if (a[p] % k == 0)       anss = mp[l[p]][0] - (r[p] == 0);     else       anss = mp[l[p]][k - (a[p] % k)] - (r[p] == k - (a[p] % k));     return anss;   }   int main() {     cin.tie(0), cout.sync_with_stdio(false);     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];       l[i] = itos(a[i]);       add(i);     }     for (int i = 0; i < n; i++) ans += cal(i);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( unroll-loops ,  omit-frame-pointer ,  inline )   #pragma GCC option( arch=native ,  tune=native ,  no-zero-upper )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )   #pragma GCC optimize( Ofast )   using namespace std;   const long double pi = acos(-1);   const long long int M = 1e9 + 7, N = 1e7 + 5, INF = 1e18;   void solve() {     long long int x, y, z, a, b, c, f1, f2, f3, f4, f5, f6, s = 0;     cin >> x >> y >> z >> a >> b >> c >> f1 >> f2 >> f3 >> f4 >> f5 >> f6;     if (y < 0) s += f1;     if (y > b) s += f2;     if (z > c) s += f4;     if (z < 0) s += f3;     if (x > a) s += f6;     if (x < 0) s += f5;     cout << s <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007, MAX = 100003;   const long long INF = 1LL << 60;   int par[MAX];   long long mini[MAX], cost[MAX];   void init(int n) {     for (int i = 0; i < n; i++) {       par[i] = i;       mini[i] = cost[i];     }   }   int root(int a) {     if (par[a] == a)       return a;     else       return par[a] = root(par[a]);   }   void unite(int a, int b) {     if (root(a) != root(b)) {       mini[root(a)] = min(mini[root(a)], mini[root(b)]);       par[root(b)] = root(a);     }   }   bool check(int a, int b) { return root(a) == root(b); }   int main() {     int N, M;     cin >> N >> M;     for (int i = 0; i < N; i++) {       scanf( %lld , &cost[i]);     }     init(N);     for (int i = 0; i < M; i++) {       int a, b;       scanf( %d%d , &a, &b);       a--;       b--;       unite(a, b);     }     set<pair<int, int>> SE;     for (int i = 0; i < N; i++) {       SE.insert({root(i), mini[root(i)]});     }     long long ans = 0;     for (auto it = SE.begin(); it != SE.end(); it++) {       ans += (*it).second;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int k, a[1001], i, j, poz, submisii_interesante, f[1001];   double ecran, fully_tested, n, timp = 1;   struct coada {     int x, y, z;   };   vector<coada> v;   int main() {     cin >> n >> k;     for (i = 1; i <= n; ++i) {       cin >> a[i];       if (k) {         v.push_back({0, a[i], i});         k--;         poz = i + 1;       }     }     while (!v.empty()) {       if (timp > 0 && double(timp) == int(timp)) {         for (size_t i = 0; i < v.size(); ++i) {           v[i].x++;           if (v[i].x == v[i].y) {             fully_tested++;             ecran = round((100 * fully_tested) / n);             v.erase(v.begin() + i, v.begin() + i + 1);             if (poz <= n) {               v.push_back({-1, a[poz], poz});               poz++;             }             i--;           }         }       }       if (double(timp - 0.5) == int(timp - 0.5)) {         for (size_t i = 0; i < v.size(); ++i) {           if (v[i].x + 1 == ecran && ecran) {             f[v[i].z]++;             if (f[v[i].z] == 1) {               submisii_interesante++;             }           }         }       }       timp = timp + 0.5;     }     cout << submisii_interesante;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   const int tam = 100010;   const int MOD = 1000000007;   const int MOD1 = 998244353;   const double DINF = 1e100;   const double EPS = 1e-9;   const double PI = acos(-1);   void solve() {     int n;     cin >> n;     vector<int> ar(n);     bool bo = true;     for (int i = 0; i < n; i++) {       cin >> ar[i];       bo &= ar[i] & 1 ^ i;     }     if (!bo) {       cout << -1 <<   n ;       return;     }     int a, b;     vector<int> res;     for (int i = n; i > 1; i -= 2) {       for (int j = 0; j < i; j++) {         if (ar[j] == i) a = j + 1;         if (ar[j] == i - 1) b = j + 1;       }       if (a == i && b == i - 1) {         continue;       }       if (a != 1) {         res.push_back(a);         reverse(ar.begin(), ar.begin() + a);         for (int j = 0; j < i; j++)           if (ar[j] == i - 1) b = j + 1;       }       if (b != 2) {         res.push_back(b - 1);         reverse(ar.begin(), ar.begin() + b - 1);         res.push_back(b + 1);         reverse(ar.begin(), ar.begin() + b + 1);         res.push_back(3);         reverse(ar.begin(), ar.begin() + 3);       }       res.push_back(i);       reverse(ar.begin(), ar.begin() + i);     }     cout << res.size() <<   n ;     for (int x : res) cout << x <<    ;     if (res.size()) cout <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mv = pow(10, 5) + 1;   void pfn() {     char x[mv], y[mv];     cin >> x >> y;     int ly = strlen(y) - 1, i;     i = ly;     while (i >= 0 && y[i] !=  1 ) i--;     int lx = strlen(x) - 1 - ly + i;     i = lx;     while (i >= 0 && x[i] !=  1 ) i--;     cout << lx - i <<   n ;   }   int main() {     int t;     cin >> t;     while (t--) pfn();   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   long long int mod = 1000000007;   long long int maxn = 200001;   long long int binpow(long long int a, long long int b, long long int mod) {     long long int res = 1;     while (b > 0) {       if (b % 2) {         res = (res * a) % mod;         b--;       }       a = (a * a) % mod;       b /= 2;     }     return res % mod;   }   long long int binpow(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b % 2) {         res = (res * a);         b--;       }       a = (a * a);       b /= 2;     }     return res;   }   bool isPrime(long long int n) {     if (n == 1) return false;     for (long long int i = 2; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   long long int mulmod(long long int a, long long int b) {     return ((a % mod) * (b % mod)) % mod;   }   long long int addmod(long long int a, long long int b) {     return (((a % mod) + (b % mod)) + mod) % mod;   }   void solve();   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int t = 2;     cin >> t;     for (long long int tt = 1; tt <= t; tt++) {       solve();     }   }   void solve() {     long long int n;     cin >> n;     string s1, s2;     cin >> s1 >> s2;     vector<long long int> oper;     bool zero;     if (s1[0] ==  0 )       zero = true;     else       zero = false;     for (long long int i = 0; i < n - 1; i++) {       if (s1[i] != s1[i + 1]) {         oper.push_back(i + 1);         zero = !zero;       }     }     if (!zero) oper.push_back(n);     s1 = string(n,  0 );     zero = true;     for (long long int i = n - 1; i >= 0; i--) {       if (s2[i] ==  1  and zero == true) {         oper.push_back(i + 1);         zero = false;       }       if (s2[i] ==  0  and zero == false) {         oper.push_back(i + 1);         zero = true;       }     }     cout << oper.size() <<    ;     for (long long int i = 0; i < oper.size(); i++) cout << oper[i] <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int wh, a, b, c, cst;     node(int WH, int A, int B, int C, int CST) {       wh = WH;       a = A;       b = B;       c = C;       cst = CST;     }     bool operator<(const node &t) const { return cst < t.cst; }   };   vector<node> v1, v2;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int a, b, c, d;       cin >> a >> b >> c >> d;       v1.push_back(node(i + 1, a, b, c, d));     }     for (int i = 0; i < n; i++) {       bool b = true;       for (int j = 0; j < n; j++)         if (v1[i].a < v1[j].a && v1[i].b < v1[j].b && v1[i].c < v1[j].c)           b = false;       if (b) v2.push_back(v1[i]);     }     sort(v2.begin(), v2.end());     cout << v2[0].wh << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD(1000000009);   const int INF((1 << 30) - 1);   const int MAXN(100005);   int a[MAXN], na = 0;   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       int low = 0, high = na - 1, mid, pos = na;       while (low <= high) {         mid = (low + high) / 2;         if (a[mid] > x)           pos = mid, high = mid - 1;         else           low = mid + 1;       }       a[pos] = x;       if (pos == na) na++;     }     printf( %d , na);   }


#include <bits/stdc++.h>   using namespace std;   long long v[100005];   long long st[400005];   void init(int idx, int a, int b) {     if (a == b) {       st[idx] = v[a];     } else {       int m = (a + b) / 2;       init(idx * 2 + 1, a, m);       init(idx * 2 + 2, m + 1, b);       st[idx] = max(st[idx * 2 + 1], st[idx * 2 + 2]);     }   }   long long query(int idx, int a, int b, int i, int j) {     if (i > b || j < a)       return -1;     else if (j >= b && i <= a)       return st[idx];     int m = (a + b) / 2;     long long x0 = query(idx * 2 + 1, a, m, i, j);     long long x1 = query(idx * 2 + 2, m + 1, b, i, j);     return max(x0, x1);   }   int main() {     int n;     int qry;     ios_base ::sync_with_stdio(0);     cin.tie(0);     char c;     int x, y;     cin >> n;     for (int i = 0; i < n; ++i) cin >> v[i];     init(0, 0, n - 1);     for (int i = 0; i < n; ++i) {       long long mn = query(0, 0, n - 1, i + 1, n - 1);       if (v[i] > mn)         cout << 0 <<    ;       else         cout << mn - v[i] + 1 <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;      int main() {       ios::sync_with_stdio(0);       int t;       cin >> t;       for (int tc=1; tc<=t; tc++) {           int n, x;           cin >> n >> x;           vector<int> v(n);           for (int i=0; i<n; i++) {               cin >> v[i];           }           vector<int> ans;           int sum = 0;           bool ok = true;           for (int i=0; i<n; i++) {               int val = v[i];               if (sum + val == x) {                   if (i == n-1) {                       ok = false;                       break;                   }                   swap(v[i], v[n-1]);                   val = v[i];               }               ans.push_back(val);               sum += val;           }           if (!ok) {               cout <<  NO n ;               continue;           }           cout <<  YES n ;           for (int i=0; i<n; i++) {               cout << ans[i] <<    n [i+1==n];           }       }   }


#include <bits/stdc++.h>   using namespace std;   int n, i, j, k, m;   char ss[111], c;   bool a[111];   string s[111], t;   bool eq(string a, string b) {     for (int i = 0; i < a.length(); i++)       if (a[i] <=  Z ) a[i] = a[i] -  A  +  a ;     for (int i = 0; i < b.length(); i++)       if (b[i] <=  Z ) b[i] = b[i] -  A  +  a ;     return a == b;   }   int main() {     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %s , ss);       s[i] = ss;     }     scanf( %s , ss);     t = ss;     m = t.length();     scanf( %s , ss);     c = ss[0];     for (i = 0; i < m; i++)       for (j = 0; j < n; j++)         if (i + s[j].length() <= m && eq(s[j], t.substr(i, s[j].length())))           for (k = 0; k < s[j].length(); k++) a[i + k] = true;     for (i = 0; i < m; i++)       if (a[i]) {         if (c ==  a ) {           if (t[i] == c)             t[i] =  b ;           else if (t[i] ==  A )             t[i] =  B ;           else if (t[i] <=  Z )             t[i] =  A ;           else             t[i] =  a ;         } else if (t[i] == c)           t[i] =  a ;         else if (t[i] == c -  a  +  A )           t[i] =  A ;         else if (t[i] <=  Z )           t[i] = c -  a  +  A ;         else           t[i] = c;       }     puts(t.c_str());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-12;   const int INF = 999999999;   const int kMod = 1000000007;   const int kMaxN = 100010;   char a[kMaxN], b[kMaxN];   int p10[kMaxN], p2[kMaxN], seq[kMaxN];   int F[kMaxN], S[kMaxN];   int P10(int n) {     int &res = p10[n];     if (res != -1) return res;     return res = (n == 0) ? 1 : ((long long)P10(n - 1) * 10) % kMod;   }   int P2(int n) {     int &res = p2[n];     if (res != -1) return res;     return res = (n == 0) ? 1 : ((long long)P2(n - 1) * 2) % kMod;   }   int ComSeq(int n) {     int &res = seq[n];     if (res != -1) return res;     if (n == 0) return res = 0;     return res = ((long long)ComSeq(n - 1) * 10 + 1) % kMod;   }   int ComS(int n) {     int &res = S[n];     if (res != -1) return res;     if (n == 0) return res = 0;     res = ((long long)ComS(n - 1) * 20) % kMod;     res = (res + (long long)P2(n - 1) * 11) % kMod;     return res;   }   int ComG(int n) {     int res = ((long long)ComS(n) * 2) % kMod;     res = (res - (long long)ComSeq(n) * 11) % kMod;     return res;   }   int ComF(int n) {     int &res = F[n];     if (res != -1) return res;     res = 0;     if (n == 0) return res;     int p = ((long long)P10(n - 1) * 4) % kMod;     int w1 = (p + (long long)ComSeq(n - 1) * 7) % kMod;     res = (res + (((long long)p * p) % kMod) * (P2(n - 1) - 1)) % kMod;     res = (res + p * (long long)ComG(n - 1)) % kMod;     res = (res + ComF(n - 1)) % kMod;     p = ((long long)P10(n - 1) * 7) % kMod;     int w2 = (p + (long long)ComSeq(n - 1) * 4) % kMod;     res = (res + (((long long)p * p) % kMod) * (P2(n - 1) - 1)) % kMod;     res = (res + p * (long long)ComG(n - 1)) % kMod;     res = (res + ComF(n - 1)) % kMod;     res = (res + (long long)w1 * w2) % kMod;     return res;   }   int Solve(const char a[]) {     int n = strlen(a);     int res = 0;     int prefix = 0;     for (int i = n - 1; i >= 0; --i) {       int d = a[n - 1 - i] -  0 ;       int next_prefix = (prefix + (long long)P10(i) * d) % kMod;       if (d == 7) {         int p = (prefix + (long long)P10(i) * 4) % kMod;         if (i > 0) {           res = (res + (((long long)p * p) % kMod) * (P2(i) - 1)) % kMod;           res = (res + (long long)p * ComG(i)) % kMod;           res = (res + ComF(i)) % kMod;         }         int w1 = (p + (long long)ComSeq(i) * 7) % kMod;         int w2 = (next_prefix + (long long)ComSeq(i) * 4) % kMod;         res = (res + (long long)w1 * w2) % kMod;       }       prefix = next_prefix;     }     return res;   }   int main() {     scanf( %s , a);     scanf( %s , b);     memset(p10, -1, sizeof(p10));     memset(p2, -1, sizeof(p2));     memset(seq, -1, sizeof(seq));     memset(F, -1, sizeof(F));     memset(S, -1, sizeof(S));     int res = Solve(b);     res = (res - Solve(a)) % kMod;     if (res < 0) res += kMod;     printf( %d n , res);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void Int(T &n) {     n = 0;     int f = 1;     int ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch -  0 ;     n = n * f;   }   template <typename T>   T gcd(T a, T b) {     return !b ? a : gcd(b, a % b);   }   template <typename T>   inline void umin(T &a, T b) {     a = a < b ? a : b;   }   template <typename T>   inline void umax(T &a, T b) {     a = a > b ? a : b;   }   template <typename T, typename W>   inline void Int(T &x, W &y) {     Int(x), Int(y);   }   template <typename T, typename W, typename Q>   inline void Int(T &x, W &y, Q &z) {     Int(x, y), Int(z);   }   const int N = 1e5 + 7;   const int inf = 1e9 + 7;   int dp[N];   int lev[N];   vector<int> g[N];   vector<pair<int, int>> edges;   int dfs(int u, int p = -1) {     dp[u] = 0;     for (int v : g[u]) {       if (lev[v] == 0) {         lev[v] = lev[u] + 1;         edges.push_back({u, v});         dp[u] += dfs(v, u);       } else if (lev[u] > lev[v] && v != p) {         ++dp[u];         --dp[v];         edges.push_back({u, v});       }     }     if (p != -1 && dp[u] == 0) {       printf( 0 n );       exit(0);     }     return dp[u];   }   int solve() {     int n, m;     Int(n, m);     for (int i = 1; i <= m; ++i) {       int u, v;       Int(u, v);       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= n; ++i) {       if (!lev[i]) {         lev[i] = 1;         dfs(i);       }     }     for (auto [u, v] : edges) {       printf( %d %d n , u, v);     }     return 0;   }   int main() {     int tests = 1, CaseNo = 0;     while (tests--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n;     cin >> n;     int r, c;     int diff = 1000000;     for (int a = 1; a * a <= n; a++)       for (int b = a; a * b <= n; b++)         if (a * b == n && b - a < diff) r = a, c = b;     cout << r <<     << c;   }


#include <bits/stdc++.h>   const long long oo = 1e16;   using namespace std;   const int N = 1000005;   long long n, dp[N];   long long num(long long n) {     if (n == 0) return 0;     if (dp[n] != -1) return dp[n];     string s = to_string(n);     long long res = oo;     for (int i = 0; i < s.size(); i++)       if (s[i] !=  0 ) res = min(res, 1 + num(n - (s[i] -  0 )));     return dp[n] = res;   }   int main() {     cin >> n;     memset(dp, -1, sizeof(dp));     cout << num(n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m;     cin >> n >> m;     long long start = 0, end = 6 * (n + m);     while (start <= end) {       long long mid = (start + end) / 2;       long long val1 = (mid / 2) - (mid / 6);       long long val2 = (mid / 3) - (mid / 6);       if ((mid / 6) >= (max(n - val1, 0LL) + max(m - val2, 0LL))) {         end = mid - 1;       } else {         start = mid + 1;       }     }     cout << start << endl;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       int flag = 1;       int st;       char c = s[0];       for (int i = 1; i < n; i++) {         if (s[i] == c)           continue;         else {           st = i;           flag = 0;           break;         }       }       if (flag == 1) {         cout << (n + 2) / 3 << endl;         continue;       }       int ans = 0;       int m = 1;       c = s[st];       int val = (st + 1) % n;       for (int i = val; i != st; i = ((i + 1) % n)) {         if (s[i] == c) {           m++;         } else {           if (m >= 3) ans += (m) / 3;           c = s[i];           m = 1;         }       }       if (m >= 3) ans += (m / 3);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace Solve {   const int MAXN = 3005;   inline int mymin(int a, int b) { return a < b ? a : b; }   inline int mymax(int a, int b) { return a > b ? a : b; }   int Log[MAXN], maxid[MAXN][20];   void getLog() {     Log[1] = 0;     for (int i = 2; i <= 3000; i++) {       if (i & 1)         Log[i] = Log[i - 1];       else         Log[i] = Log[i >> 1] + 1;     }     return;   }   void getST(int *A, int n) {     for (int i = 1; i <= n; i++) maxid[i][0] = i;     for (int k = 1; k <= 12; k++) {       for (int i = 1; i + (1 << k) - 1 <= n; i++) {         int f = i + (1 << (k - 1));         if (A[maxid[i][k - 1]] > A[maxid[f][k - 1]])           maxid[i][k] = maxid[i][k - 1];         else           maxid[i][k] = maxid[f][k - 1];       }     }     return;   }   struct Data {     int id, val;     Data(int a = 0, int b = 0) : id(a), val(b) {}     bool operator<(const Data &B) const { return val > B.val; }   } A[MAXN];   int N, D[MAXN], awd[MAXN];   int Qmaxid(int l, int r) {     if (l > r) return 0;     int k = Log[r - l + 1];     int f = r - (1 << k) + 1;     if (D[maxid[l][k]] > D[maxid[f][k]]) return maxid[l][k];     return maxid[f][k];   }   void work() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) scanf( %d , &A[i].val), A[i].id = i;     sort(A + 1, A + N + 1);     A[0].val = 0;     for (int i = 1; i <= N; i++) D[i] = A[i - 1].val - A[i].val;     D[N + 1] = A[N].val;     getLog();     getST(D, N + 1);     int mxi = -1, mxj = -1, mxk = -1, ansi = -1, ansj = -1, ansk = -1;     for (int i = 1; i < N; i++) {       if (A[i].val - A[i + 1].val < mxi) continue;       for (int j = i + 1; j < N; j++) {         if (i > 2 * (j - i)) continue;         if (j - i > 2 * i) break;         if (A[i].val - A[i + 1].val == mxi && A[j].val - A[j + 1].val < mxj)           continue;         int milen = mymin(i, j - i);         int mxlen = mymax(i, j - i);         int low = j + ((mxlen + 1) >> 1) + 1, upp = j + (milen << 1) + 1;         if (low > N + 1) continue;         if (upp > N + 1) upp = N + 1;         int mxid = Qmaxid(low, upp);         if (A[i].val - A[i + 1].val == mxi && A[j].val - A[j + 1].val == mxj &&             D[mxid] < mxk)           continue;         mxi = A[i].val - A[i + 1].val;         mxj = A[j].val - A[j + 1].val;         mxk = D[mxid];         ansi = i, ansj = j, ansk = mxid - 1;       }     }     for (int i = 1; i <= ansi; i++) awd[A[i].id] = 1;     for (int i = ansi + 1; i <= ansj; i++) awd[A[i].id] = 2;     for (int i = ansj + 1; i <= ansk; i++) awd[A[i].id] = 3;     for (int i = ansk + 1; i <= N; i++) awd[A[i].id] = -1;     for (int i = 1; i <= N; i++) printf( %d  , awd[i]);     printf(  n );     return;   }   }  // namespace Solve   int main() {     Solve::work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005, K = 105, P = 998244353;   using ll = long long;   ll dp[N][K], sum[N], cnt[N][K];   inline bool cmp(int a, int b) { return a == -1 || b == -1 || a == b; }   int n, kk, len, a[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> kk >> len;     if (len == 1) {       puts( 0 );       return 0;     }     for (int i = 1; i <= n; i++) {       cin >> a[i];       for (int j = 1; j <= kk; j++) cnt[i][j] = cnt[i - 1][j] + cmp(a[i], j);     }     sum[0] = 1;     if (a[1] == -1) {       for (int i = 1; i <= kk; i++) dp[1][i] = 1;       sum[1] = kk;     } else       sum[1] = 1, dp[1][a[1]] = 1;     for (int i = 2; i <= n; i++)       for (int j = 1; j <= kk; j++)         if (cmp(a[i], j)) {           dp[i][j] = sum[i - 1];           if (i >= len && cnt[i][j] - cnt[i - len][j] == len) {             dp[i][j] = ((dp[i][j] - sum[i - len] + dp[i - len][j]) % P + P) % P;           }           sum[i] = (sum[i] + dp[i][j]) % P;         }     cout << sum[n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1000 + 5;   const int mod = 1000 * 1000 * 1000 + 7;   int a[65], b[65];   int main() {     ios_base::sync_with_stdio(false);     long long l, r;     cin >> l >> r;     for (int i = 0; l > 0; l /= 2, i++) a[i] = l % 2;     for (int i = 0; r > 0; r /= 2, i++) b[i] = r % 2;     int i;     for (i = 60; i >= 0 && a[i] == b[i]; i--)       ;     if (i == -1)       cout << 0 << endl;     else       cout << (1ll << (i + 1)) - 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct seg {     vector<int> id;     map<pair<int, int>, int> st;     int getid(int l, int r) {       int L = lower_bound(id.begin(), id.end(), l) - id.begin();       int R = upper_bound(id.begin(), id.end(), r) - id.begin() - 1;       if (L > R) return -1;       return st[make_pair(L, R)];     }   } tr[20000];   vector<pair<int, int> > res;   int cur;   int merge(int x, int y) {     if (x == -1 || y == -1)       return max(x, y);     else {       res.emplace_back(x, y);       cur++;       return cur;     }   }   int blk, tot, Tid = 0;   int n, q, a[5000], Id[5000], l[5000], r[5000];   int solve(int l, int r, vector<int> id) {     Tid++;     int k;     tr[k = Tid].id = id;     if (l == r) {       tr[Tid].st[pair<int, int>(0, 0)] = id[0];       return Tid;     }     int mid = (l + r) >> 1;     vector<int> lid, rid;     for (auto x : id)       if (a[x] <= mid)         lid.push_back(x);       else         rid.push_back(x);     int ls = solve(l, mid, lid), rs = solve(mid + 1, r, rid);     for (int i = 0; i < id.size(); i++)       for (int j = i; j < id.size(); j++)         tr[k].st[pair<int, int>(i, j)] =             merge(tr[ls].getid(id[i], id[j]), tr[rs].getid(id[i], id[j]));     return k;   }   int main() {     scanf( %d%d , &n, &q);     blk = sqrt(q);     cur = n;     for (int i = 1; i <= (tot = n / blk); i++)       l[i] = r[i - 1] + 1, r[i] = i * blk;     if (tot * blk != n) l[++tot] = r[tot - 1] + 1, r[tot] = n;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= tot; i++) {       vector<int> id;       for (int j = 1; j <= n; j++)         if (l[i] <= a[j] && a[j] <= r[i]) id.push_back(j);       Id[i] = solve(l[i], r[i], id);     }     vector<int> ans;     for (int l, r; q--;) {       scanf( %d%d , &l, &r);       int rest = -1;       for (int i = 1; i <= tot; i++) rest = merge(rest, tr[Id[i]].getid(l, r));       ans.push_back(rest);     }     printf( %d n , cur);     for (auto x : res) printf( %d %d n , x.first, x.second);     for (int x : ans) printf( %d  , x);   }


#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--) {       int n;       cin >> n;       int a[n], b[n];       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) cin >> b[i];       sort(a, a + n);       sort(b, b + n);       for (int i = 0; i < n; i++) cout << a[i] <<    ;       cout << endl;       for (int i = 0; i < n; i++) cout << b[i] <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> tst[100005];   int rep[100005];   int idx[100005];   int arr[100005];   pair<int, int> sw[1000000];   int ns;   int num, id;   int islucky(int x) {     for (; x > 0; x /= 10)       if (x % 10 != 4 and x % 10 != 7) return 0;     return 1;   }   int main() {     int i, j;     int a, b, c, d;     int n;     ns = 0;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &arr[i]);       tst[i] = pair<int, int>(arr[i], i);     }     sort(tst, tst + n);     for (i = 0; i < n; i++) {       rep[i] = tst[i].first;       idx[i] = tst[i].second;       arr[tst[i].second] = i;     }     num = -1;     for (i = 0; i < n; i++) {       if (islucky(rep[i])) {         num = i;         id = idx[i];         break;       }     }     if (num == -1) {       for (i = 0; i < n - 1; i++)         if (arr[i] > arr[i + 1]) {           printf( -1 n );           return 0;         }     }     for (i = 0; i < n; i++) {       if (i == num or i == arr[i]) continue;       a = i;       b = id;       c = idx[i];       d = arr[i];       if (a != b) sw[ns++] = pair<int, int>(a, b);       if (a != c) sw[ns++] = pair<int, int>(a, c);       idx[num] = id = c;       idx[i] = a;       idx[arr[i]] = b;       swap(arr[a], arr[b]);       swap(arr[a], arr[c]);     }     printf( %d n , ns);     for (i = 0; i < ns; i++) printf( %d %d n , sw[i].first + 1, sw[i].second + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, k;     cin >> n >> k;     vector<pair<int, int> > v;     string a;     cin >> a;     int balance_max = 0;     int balance_min = 0;     v.push_back(pair<int, int>(0, 0));     for (int i = 0; i < n - 1; i++) {       if (a[i] ==  W ) {         balance_min++;         if (balance_max < k - 1) balance_max++;       } else if (a[i] ==  L ) {         balance_max--;         if (balance_min > 1 - k) balance_min--;       } else if (a[i] ==  ? ) {         if (balance_max < k - 1) balance_max++;         if (balance_min > 1 - k) balance_min--;       }       v.push_back(pair<int, int>(balance_min, balance_max));       if (balance_max < balance_min) {         cout <<  NO  << endl;         return 0;       }     }     if (a[n - 1] ==  W ) {       balance_min++;       balance_max++;     } else if (a[n - 1] ==  L ) {       balance_min--;       balance_max--;     } else if (a[n - 1] ==  ? ) {       balance_min--;       balance_max++;     }     v.push_back(pair<int, int>(balance_min, balance_max));     int pos = k;     string solve =   ;     if (balance_max == k) {       pos = k;     } else if (balance_min == -k) {       pos = -k;     } else {       cout <<  NO  << endl;       return 0;     }     for (int i = n - 1; i >= 0; i--) {       if (a[i] ==  L ) {         pos++;         solve +=  L ;       } else if (a[i] ==  W ) {         pos--;         solve +=  W ;       } else if (a[i] ==  D ) {         solve +=  D ;       } else if (a[i] ==  ? ) {         if (v[i].second < pos) {           pos--;           solve +=  W ;         } else if (v[i].first > pos) {           pos++;           solve +=  L ;         } else           solve +=  D ;       }     }     reverse(solve.begin(), solve.end());     cout << solve << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3,  Ofast ,  inline )   using namespace std;   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   const long long maxn = (long long)1e6 + 5;   const long long mod = 998244353;   const long long inf = 0x3f3f3f3f;   long long T = 1;   struct edge {     long long u, v, colu, colv;     bool operator<(const edge &b) const {       if (colu != b.colu) return colu < b.colu;       return colv < b.colv;     };   } v[maxn];   long long tot = 0;   struct node {     long long u, v, fa, siz;   };   stack<node> s;   long long pre[maxn];   long long find(long long x) {     while (x != pre[x]) x = pre[x];     return pre[x];   }   long long siz[maxn];   void unite(long long u, long long v) {     u = find(u), v = find(v);     if (siz[u] > siz[v]) swap(u, v);     s.push({u, v, pre[u], siz[u]});     if (u != v) {       pre[u] = v;       siz[v] += siz[u];       siz[u] = 0;     }   }   void restore() {     node now = s.top();     s.pop();     if (now.u != now.v) {       pre[now.u] = now.fa;       siz[now.u] = now.siz;       siz[now.v] -= now.siz;     }   }   long long col[maxn];   bool no[maxn];   void solve() {     long long n, m, k;     cin >> n >> m >> k;     long long cnt = k;     for (long long i = 1; i <= n; ++i) cin >> col[i];     for (long long i = 1; i <= 2 * n; ++i) pre[i] = i, siz[i] = 1;     for (long long i = 1; i <= m; ++i) {       long long x, y;       cin >> x >> y;       if (col[x] != col[y]) {         v[++tot] = edge({x, y, col[x], col[y]});         if (col[x] > col[y]) swap(v[tot].colu, v[tot].colv);         continue;       }       if (no[col[x]]) continue;       if (find(x) == find(y)) {         --cnt;         no[col[x]] = true;         continue;       }       unite(x, y + n);       unite(y, x + n);     }     long long ans = (cnt - 1) * cnt / 2;     bool flag = false;     sort(v + 1, v + tot + 1);     long long last = s.size();     for (long long i = 1; i <= tot; ++i) {       edge now = v[i];       if (no[now.colu] || no[now.colv]) continue;       if (now.colu != v[i - 1].colu || now.colv != v[i - 1].colv) {         while (s.size() != last) restore();         flag = false;       }       if (flag) continue;       if (find(now.u) == find(now.v)) {         --ans;         flag = true;         continue;       }       unite(now.u, now.v + n);       unite(now.v, now.u + n);     }     cout << ans;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000000;   const long long longinf = 1000000000000000000;   const double PI = 3.141592653589793;   const long long mod = 1000000007;   long long d[100][2];   void solve() {     int n;     cin >> n;     vector<long long> v(n);     for (int i = 0; i < n; ++i) {       cin >> v[i];     }     vector<long long> sm(n + 1, 0);     for (int i = n - 1; i >= 0; --i) {       sm[i] = sm[i + 1] + v[i];     }     d[n][0] = 0;     d[n][1] = 0;     for (int i = n - 1; i >= 0; --i) {       for (int h = 0; h <= 1; ++h) {         d[i][h] = max(d[i + 1][h], v[i] + sm[i + 1] - d[i + 1][h ^ 1]);       }     }     cout << sm[0] - d[0][0] <<     << d[0][0] << endl;   }   int main() {     cout.precision(20);     cin.tie(0);     iostream::sync_with_stdio(false);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mx=2e5+10;   const int INF=0x3f3f3f;   long long tes[mx][2][2];   bool flg[mx][2][2];   int hd[mx],nx[mx*2],t[mx*2],vl[mx*2];   int sum;      struct Node   {       int x,y,z;       long long jud;       bool operator < (const Node &nd) const       {           return jud>nd.jud;       }   };      void add(int x,int y,int z)   {       t[++sum]=y;       nx[sum]=hd[x];       vl[sum]=z;       hd[x]=sum;   }      void chg()   {       priority_queue<Node> q;       q.push({1,0,0,0});       memset(tes,0x3f,sizeof(tes));       tes[1][0][0]=0;       while(!q.empty())       {           Node upp=q.top();           q.pop();           int x=upp.x,y=upp.y,z=upp.z;           if(flg[x][y][z])               continue;           flg[x][y][z]=1;           for(int i=hd[x];i;i=nx[i])           {               int a=vl[i],b=t[i];               if(tes[b][y][z]>tes[x][y][z]+a)               {                   tes[b][y][z]=tes[x][y][z]+a;                   q.push({b,y,z,tes[b][y][z]});               }               if(!y)               {                   if(tes[b][y^1][z]>tes[x][y][z])                   {                       tes[b][y^1][z]=tes[x][y][z];                       q.push({b,y^1,z,tes[b][y^1][z]});                   }               }               if(!z)               {                   if(tes[b][y][z^1]>tes[x][y][z]+a*2)                   {                       tes[b][y][z^1]=tes[x][y][z]+a*2;                       q.push({b,y,z^1,tes[b][y][z^1]});                   }               }               if(!y&&!z)               {                   if(tes[b][y^1][z^1]>tes[x][y][z]+a)                   {                       tes[b][y^1][z^1]=tes[x][y][z]+a;                       q.push({b,y^1,z^1,tes[b][y^1][z^1]});                   }               }           }       }   }      int main()   {       int n,m;       scanf( %d %d ,&n,&m);       for(int i=1;i<=m;i++)       {           int x,y,z;           scanf( %d %d %d ,&x,&y,&z);           add(x,y,z);           add(y,x,z);       }       chg();       for(int i=2;i<=n;i++)           cout<<tes[i][1][1]<<   ;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 2e5 + 5;   pair<long long, long long> a[MAXN];   long long s;   long long n;   bool check(long long x) {     long long sum = 0, cnt = 0;     vector<long long> nums;     for (long long i = 0; i < n; i++) {       if (a[i].first >= x) {         sum += a[i].first;         cnt++;       } else {         if (a[i].second < x) {           sum += a[i].first;         } else {           nums.push_back(a[i].first);         }       }     }     long long left = max((long long)0, (n + 1) / 2 - cnt);     if (left > nums.size()) return 0;     for (long long i = 0; i < nums.size() - left; i++) {       sum += nums[i];     }     for (long long i = nums.size() - left; i < nums.size(); i++) {       sum += x;     }     return (sum <= s);   }   int main() {     long long q;     cin >> q;     while (q--) {       cin >> n >> s;       for (long long i = 0; i < n; i++) {         cin >> a[i].first >> a[i].second;       }       sort(a, a + n);       long long l = 1, r = 1e9 + 100;       while (l + 1 < r) {         long long m = (l + r) >> 1;         if (check(m)) {           l = m;         } else {           r = m;         }       }       cout << l <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, res, tmp, m;   vector<int> v;   bool check(int val) {     int m = n - val;     return m % (2 * k + 1) <= k;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> k;     int i = min(n, k + 1);     while (!check(i)) i--;     while (i <= n) {       if (i <= n) v.push_back(i);       i += 2 * k + 1;     }     if (v[v.size() - 1] + k < n) v.push_back(n);     cout << v.size() <<   n ;     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 300 + 5;   int n, m, p;   int grid[MAX][MAX];   int dp[MAX][MAX];   vector<pair<int, int> > pos[MAX * MAX];   vector<int> col[MAX];   int main() {     scanf( %d %d %d , &n, &m, &p);     for (int i = int(0); i < int(n); i++) {       for (int j = int(0); j < int(m); j++) {         scanf( %d , &grid[i][j]);         if (grid[i][j] == 1) {           dp[i][j] = i + j;         } else {           dp[i][j] = 1 << 30;         }         pos[grid[i][j]].emplace_back(i, j);       }     }     bool visited[MAX];     for (int i = int(1); i < int(p); i++) {       memset(visited, false, sizeof visited);       for (int c = int(0); c < int(m); c++) {         col[c].clear();       }       for (auto &each : pos[i + 1]) {         col[each.second].push_back(each.first);       }       for (auto &each : pos[i]) {         visited[each.first] = true;       }       for (int r = int(0); r < int(n); r++) {         if (visited[r]) {           int best = 1 << 30;           for (int c = int(0); c < int(m); c++) {             best++;             if (grid[r][c] == i) {               best = min(best, dp[r][c]);             }             for (auto &each : col[c]) {               dp[each][c] = min(dp[each][c], best + abs(each - r));             }           }           best = 1 << 30;           for (int c = int(m - 1); c >= int(0); c--) {             best++;             if (grid[r][c] == i) {               best = min(best, dp[r][c]);             }             for (auto &each : col[c]) {               dp[each][c] = min(dp[each][c], best + abs(each - r));             }           }         }       }     }     printf( %d n , dp[pos[p][0].first][pos[p][0].second]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef vector<int> vi;   typedef vector<int> vll;   typedef pair<int, int> pii;   #define F first   #define S second   #define PB push_back   #define MP make_pair   #define ALL(v) v.begin(), v.end()   #define rALL(v) v.rbegin(), v.rend()   #define INF 1000000007LL   #define MOD 998244353LL      const int LIM = 2e5 + 5;      void solve()   {       int n, x, f, res = 0;       cin >> n;       for(int i = 0; i < n; i++)       {           cin >> x;           f = 0;           for(int j = 1; j * j <= x; j++)               if(j * j == x)               {                   f = 1;                   break;               }           if(f == 0)               res = 1;       }          if(res)           cout <<  YES n ;       else           cout <<  NO n ;          }      int main()   {       ios_base::sync_with_stdio(false);       cin.tie(NULL);          int t = 1;       cin >> t;       while (t--)       {           solve();       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     int n;     cin >> n;     cin >> a >> b;     int ans = 0;     for (int i = 0; i < n - 1; i++) {       if (a[i] != b[i]) {         ans++;         if (a[i + 1] != b[i + 1] && a[i] != a[i + 1]) {           swap(a[i], a[i + 1]);         } else           a[i] = b[i];       }     }     if (a[n - 1] != b[n - 1]) ans++;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef int matrix[140][140];   const int modp = 12345;   int k, N, mod[30], base[30], cnt[30], num[30][30];   int legal[140], ans;   long long n;   matrix a, b;   void mul(matrix a, matrix b) {     matrix c;     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++) c[i][j] = 0;     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++)         for (int k = 0; k < N; k++)           c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % modp;     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++) a[i][j] = c[i][j];   }   int gcd(int x, int y) {     if (y == 0) return x;     return gcd(y, x % y);   }   int main() {     cin >> n >> k;     for (int i = 0; i < 26; i++) mod[i] = 1;     for (int i = 1; i <= k; i++) {       char type[4];       int p, x;       scanf( %s , type);       p = type[0] -  A ;       scanf( %d , &x);       mod[p] *= x / gcd(x, mod[p]);       cnt[p]++;       num[p][cnt[p]] = x;     }     base[0] = 1;     for (int i = 0; i < 26; i++) base[i + 1] = base[i] * mod[i];     N = base[26];     for (int i = 0; i < N; i++) {       legal[i] = 1;       for (int j = 0; j < 26; j++)         if (cnt[j]) {           int res = 0, zt;           zt = i + base[j];           if ((i / base[j] + 1) % mod[j] == 0) zt -= base[j + 1];           b[i][zt]++;           for (int k = 1; k <= cnt[j]; k++)             if ((i / base[j]) % num[j][k] == 0) res = 1;           legal[i] &= res;         }     }     a[0][0] = 1;     for (; n; n >>= 1) {       if (n & 1) mul(a, b);       mul(b, b);     }     for (int i = 0; i < N; i++)       if (legal[i]) ans = (ans + a[0][i]) % modp;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cout.precision(30);     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<pair<long long, long long>> ps(n);     for (int i = 0; i < n; i++) {       cin >> ps[i].first >> ps[i].second;     }     sort(ps.begin(), ps.end(),          [&](pair<long long, long long> a, pair<long long, long long> b) {            return make_pair(a.second, a.first) < make_pair(b.second, b.first);          });     vector<long long> hadv(n, 0), hadh(n, 0);     vector<pair<long long, long long>> v, h;     vector<pair<pair<long long, long long>, pair<long long, long long>>> verts;     long long cury = ps[0].second;     for (int i = 1; i < n; i++) {       if (cury != ps[i].second) {         cury = ps[i].second;       } else {         hadv[i - 1] = 1;         hadv[i] = 1;         verts.push_back({ps[i - 1], ps[i]});       }     }     for (int i = 0; i < n; i++) {       if (!hadv[i]) v.push_back(ps[i]), v.push_back(ps[i]);     }     sort(ps.begin(), ps.end());     vector<pair<pair<long long, long long>, pair<long long, long long>>> hors;     long long curx = ps[0].first;     for (int i = 1; i < n; i++) {       if (curx != ps[i].first) {         curx = ps[i].first;       } else {         hadh[i - 1] = 1;         hadh[i] = 1;         hors.push_back({ps[i - 1], ps[i]});       }     }     for (int i = 0; i < n; i++) {       if (!hadh[i]) h.push_back(ps[i]), h.push_back(ps[i]);     }     swap(hors, verts);     swap(h, v);     auto inter = [&](pair<long long, long long> a, pair<long long, long long> b,                      pair<long long, long long> c, pair<long long, long long> d) {       if (c.first < a.first && a.first < d.first) {         if (a.second < c.second && c.second < b.second) return true;       }       return false;     };     vector<vector<long long>> g(verts.size());     for (int i = 0; i < verts.size(); i++) {       for (int j = 0; j < hors.size(); j++) {         if (inter(verts[i].first, verts[i].second, hors[j].first, hors[j].second))           g[i].push_back(j);       }     }     vector<long long> to(hors.size(), -1);     vector<long long> used(verts.size(), 0);     vector<long long> from(verts.size(), -1);     function<bool(int)> dfs = [&](int v) {       if (used[v]) return false;       used[v] = 1;       for (int u : g[v]) {         if (to[u] == -1 || dfs(to[u])) {           to[u] = v;           from[v] = u;           return true;         }       }       return false;     };     for (int i = 0; i < verts.size(); i++) {       used.assign(verts.size(), 0);       dfs(i);     }     used.assign(verts.size(), 0);     vector<long long> used1(hors.size(), 0);     function<void(int)> dfs1 = [&](int v) {       if (used[v]) return;       used[v] = 1;       for (int u : g[v]) {         if (!used1[u]) {           used1[u] = 1;           dfs1(to[u]);         }       }     };     vector<long long> free(verts.size(), 1);     for (int i : to)       if (i != -1) free[i] = 0;     for (int i = 0; i < verts.size(); i++)       if (free[i]) dfs1(i);     for (int i = 0; i < verts.size(); i++) {       auto a = verts[i].first, b = verts[i].second;       if (i == 0 || verts[i - 1].second != verts[i].first) {         if (i > 0) v.push_back(verts[i - 1].second);         v.push_back(a);       }       if (!used[i]) v.push_back(a), v.push_back(b);     }     if (!verts.empty()) v.push_back(verts.back().second);     for (int i = 0; i < hors.size(); i++) {       auto a = hors[i].first, b = hors[i].second;       if (i == 0 || hors[i - 1].second != hors[i].first) {         if (i > 0) h.push_back(hors[i - 1].second);         h.push_back(a);       }       if (used1[i]) h.push_back(a), h.push_back(b);     }     if (!hors.empty()) h.push_back(hors.back().second);     cout << h.size() / 2 << endl;     for (int i = 0; i < h.size(); i++)       cout << h[i].first <<     << h[i].second << ((i % 2) ?   n  :    );     cout << v.size() / 2 << endl;     for (int i = 0; i < v.size(); i++)       cout << v[i].first <<     << v[i].second << ((i % 2) ?   n  :    );     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T in() {     char ch;     T n = 0;     bool ng = false;     while (1) {       ch = getchar();       if (ch ==  - ) {         ng = true;         ch = getchar();         break;       }       if (ch >=  0  && ch <=  9 ) break;     }     while (1) {       n = n * 10 + (ch -  0 );       ch = getchar();       if (ch <  0  || ch >  9 ) break;     }     return (ng ? -n : n);   }   template <typename T>   inline T Dist(T x1, T y1, T x2, T y2) {     return sqrt((x1 - x2 * x1 - x2) + (y1 - y2 * y1 - y2));   }   template <typename T>   inline T POW(T B, T P) {     if (P == 0) return 1;     if (P & 1)       return B * POW(B, P - 1);     else       return (POW(B, P / 2) * POW(B, P / 2));   }   template <typename T>   inline T ABS(T a) {     if (a < 0)       return -a;     else       return a;   }   template <typename T>   inline T Gcd(T a, T b) {     if (a < 0) return Gcd(-a, b);     if (b < 0) return Gcd(a, -b);     return (b == 0) ? a : Gcd(b, a % b);   }   template <typename T>   inline T Lcm(T a, T b) {     if (a < 0) return Lcm(-a, b);     if (b < 0) return Lcm(a, -b);     return a * (b / Gcd(a, b));   }   long long Bigmod(long long base, long long power, long long MOD) {     long long ret = 1;     while (power) {       if (power & 1) ret = (ret * base) % MOD;       base = (base * base) % MOD;       power >>= 1;     }     return ret;   }   long long ModInverse(long long number, long long MOD) {     return Bigmod(number, MOD - 2, MOD);   }   int Set(int N, int pos) { return N = N | (1 << pos); }   int Reset(int N, int pos) { return N = N & ~(1 << pos); }   bool Chkbit(int N, int pos) { return (bool)(N & (1 << pos)); }   bool isVowel(char ch) {     ch = toupper(ch);     if (ch ==  A  || ch ==  U  || ch ==  I  || ch ==  O  || ch ==  E )       return true;     return false;   }   bool isConst(char ch) {     if (isalpha(ch) && !isVowel(ch)) return true;     return false;   }   int toInt(string s) {     int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   long long int toLlint(string s) {     long long int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   struct z {     long long int lft, rgt;     z() {}     z(long long int _, long long int __) { lft = _, rgt = __; }   };   int h, q;   z Solve(long long int lev, long long int l, long long int r) {     long long int now = l, now1 = r;     for (int i = lev + 1; i <= h; i++) {       now *= 2LL;       now1 *= 2LL;       now1 += 1LL;     }     return z(now, now1);   }   vector<z> A, B;   bool cmp(z a, z b) { return ((a.rgt - a.lft) > (b.rgt - b.lft)); }   bool cmp1(z a, z b) { return (a.lft < b.lft); }   vector<z> C;   int main() {     h = in<int>(), q = in<int>();     for (int i = 0; i < q; i++) {       long long int a, l, r, id;       a = in<long long int>(), l = in<long long int>(), r = in<long long int>(),       id = in<long long int>();       if (id)         A.push_back(Solve(a, l, r));       else         B.push_back(Solve(a, l, r));     }     sort(B.begin(), B.end(), cmp1);     long long int lf, rg;     if (A.size() == 0) {       z tp = Solve(1, 1, 1);       lf = tp.lft, rg = tp.rgt;     } else {       z tp = Solve(1, 1, 1);       lf = tp.lft, rg = tp.rgt;       for (int i = 0; i < A.size(); i++) {         long long int l = A[i].lft, r = A[i].rgt;         if (lf > r || rg < l) {           printf( Game cheated! n );           return 0;         }         lf = max(lf, l);         rg = min(rg, r);       }     }     if (B.size() == 0) {       if (lf == rg) {         cout << lf << endl;       } else         printf( Data not sufficient! n );       return 0;     }     for (int i = 0; i < B.size(); i++) {       long long int lf1 = B[i].lft, rg1 = B[i].rgt;       if (rg1 < lf || lf1 > rg)         continue;       else {         C.push_back(z(max(lf, lf1), min(rg, rg1)));       }     }     if (C.size() == 0) {       if (lf == rg) {         cout << lf << endl;       } else         printf( Data not sufficient! n );       return 0;     }     sort(C.begin(), C.end(), cmp1);     long long int ans = -1;     if (C[0].lft - 1 == lf) {       ans = lf;     } else if (lf + 1 < C[0].lft) {       printf( Data not sufficient! n );       return 0;     }     long long int Rgt = C[0].rgt;     for (int i = 1; i < C.size(); i++) {       long long int lf1 = C[i].lft, rg1 = C[i].rgt;       if (Rgt + 1 < C[i].lft) {         long long int dff = C[i].lft - Rgt - 1;         if (dff == 1) {           if (ans == -1) {             ans = Rgt + 1;           } else {             printf( Data not sufficient! n );             return 0;           }         } else {           printf( Data not sufficient! n );           return 0;         }       }       Rgt = max(Rgt, C[i].rgt);     }     if (rg >= Rgt + 1) {       if (rg == Rgt + 1) {         if (ans == -1) {           ans = rg;         } else {           printf( Data not sufficient! n );           return 0;         }       } else {         printf( Data not sufficient! n );         return 0;       }     }     if (ans == -1) {       printf( Game cheated! n );       return 0;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   double eps = 1e-10;   using namespace std;   long long m, h1, a1, x_1, y_1, h2, a2, x_2, y_2, len1, len2, l1, l2, i1 = -1,                                                                        i2 = -1;   int idx1[1000006], idx2[1000006], cycle1[1000006], cycle2[1000006];   bool check(long long x) {     if (x < l2) {       if (cycle2[x] == a2)         return 1;       else         return 0;     }     x -= l2;     x %= len2;     return (cycle2[x + l2] == a2);   }   int main() {     cin >> m >> h1 >> a1 >> x_1 >> y_1 >> h2 >> a2 >> x_2 >> y_2;     for (int i = 0; i <= 1000000; i++) idx1[i] = idx2[i] = -1;     idx1[h1] = 0, idx2[h2] = 0;     cycle1[0] = h1, cycle2[0] = h2;     for (int i = 1; i <= m + 1; i++) {       int height = (x_1 * cycle1[i - 1] + y_1) % m;       if (idx1[height] != -1) {         len1 = i - idx1[height];         l1 = idx1[height];         break;       } else {         cycle1[i] = height;         idx1[height] = i;       }     }     for (int i = 1; i <= m + 1; i++) {       int height = (x_2 * cycle2[i - 1] + y_2) % m;       if (idx2[height] != -1) {         len2 = i - idx2[height];         l2 = idx2[height];         break;       } else {         cycle2[i] = height;         idx2[height] = i;       }     }     for (int i = 0; i < l1; i++) {       if (cycle1[i] == a1) {         if (check(i)) {           cout << i << endl;         } else {           puts( -1 );         }         return 0;       }     }     for (int i = l1; i < len1 + l1; i++) {       if (cycle1[i] == a1) {         i1 = i - l1;         break;       }     }     if (i1 == -1) {       puts( -1 );       return 0;     }     for (int k1 = 0; k1 < 1000002; k1++) {       long long t = l1 + (long long)k1 * len1 + i1;       if (check(t)) {         cout << t << endl;         return 0;       }     }     puts( -1 );   }


#include <bits/stdc++.h>   using namespace std;   bool debug = true;   template <typename T1, typename T2>   ostream& operator<<(ostream& os, pair<T1, T2> ptt) {     os << ptt.first <<  ,  << ptt.second;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, vector<T> vt) {     os <<  { ;     for (int i = 0; i < vt.size(); i++) {       os << vt[i] <<    ;     }     os <<  } ;     return os;   }   int n, k;   int a[200005];   int main(int argc, char* argv[]) {     int t;     cin >> t;     while (t--) {       cin >> n >> k;       for (int i = 0; i < n; i++) {         cin >> a[i];       }       int mx = 0;       for (int i = 0; i < n - k; i++) {         if (a[i + k] - a[i] < a[mx + k] - a[mx]) {           mx = i;         }       }       cout << (a[mx + k] + a[mx]) / 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   long long n, k, m;   long long dp[1010][110][2], pw[1010], PW[1010];   long long Solve(long long p, long long r, int f) {     if (p <= 0) return f;     if (~dp[p][r][f]) return dp[p][r][f];     if (f) return (9LL * PW[p - 1]) % m;     long long res = 0;     for (int i = ((p == 1) ? 1 : 0); i <= (9); ++i) {       long long nr = (r + (long long)i * pw[n - p]) % k;       res = (res + Solve(p - 1, nr, f || (!nr && i))) % m;     }     return dp[p][r][f] = res;   }   int main() {     scanf( %I64d%I64d%I64d , &n, &k, &m);     pw[0] = PW[0] = 1;     for (int i = 1; i <= (n); ++i)       pw[i] = (pw[i - 1] * 10) % k, PW[i] = (PW[i - 1] * 10) % m;     memset(dp, -1, sizeof(dp));     printf( %I64d n , Solve(n, 0, 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c, d, e, i, j, ii, jj, zx, xc, p[10009], ji, F[10009], G[10009];   pair<int, int> k[10009];   vector<int> v;   vector<int>::iterator it;   int ask(int q, int w) {     int qw = 0;     cout <<  ?   << q <<     << w << endl;     cin >> qw;     return qw;   }   int fun(int q) {     int qw = 0;     if (q != k[0].first) {       qw = ask(q, k[0].first);     } else {       qw = ask(q, k[0].second);     }     for (j = 1; j <= ji; j++) {       if (q != k[j].first) {         e = ask(q, k[j].first);       } else {         e = ask(q, k[j].second);       }       qw &= e;     }     return qw;   }   void answer() {     cout <<  ! ;     for (j = 1; j <= a; j++) {       cout <<     << p[j];     }     exit(0);   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> a;     for (j = 0;; j++) {       if ((1 << j) >= a) break;       ji = j;     }     while (1) {       for (j = 0; j <= ji; j++) {         if (k[j].first == 0) break;       }       if (j == ji + 1) break;       c = rand() % a + 1;       d = rand() % a + 1;       if (c == d) continue;       e = ask(c, d);       for (jj = 0; jj <= ji; jj++) {         if ((e & (1 << jj)) == 0) {           k[jj].first = c;           k[jj].second = d;         }       }     }     for (i = 1; i <= a; i++) {       c = rand() % (a - i + 1) + 1;       G[i] = c;       v.push_back(i);     }     for (i = 1; i <= a; i++) {       F[i] = v[G[i] - 1];       it = v.begin() + (G[i] - 1);       v.erase(it);     }     p[F[1]] = fun(F[1]);     c = F[1];     for (i = 2; i <= a; i++) {       e = ask(c, F[i]);       if (p[c] == e) {         c = F[i];         p[c] = fun(c);       }     }     p[c] = 0;     for (i = 1; i <= a; i++) {       if (i == c) continue;       p[i] = ask(i, c);     }     answer();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   struct Node {     int u, w, next;   };   struct Node node[300010];   int p;   int f[100010], g[100010], num[100010], isgo[100010];   int judge(int n) {     while (n) {       if (n % 10 != 4 && n % 10 != 7) return 0;       n /= 10;     }     return 1;   }   void dfs(int u) {     isgo[u] = 1;     num[u] = 1;     f[u] = 0;     for (int now = node[u].next; now != -1; now = node[now].next) {       int v = node[now].u, w = node[now].w;       if (isgo[v] == 1) continue;       dfs(v);       if (w == 1)         f[u] += num[v];       else         f[u] += f[v];       num[u] += num[v];     }   }   void dp(int u) {     isgo[u] = 1;     for (int now = node[u].next; now != -1; now = node[now].next) {       int v = node[now].u;       int w = node[now].w;       if (isgo[v] == 1) continue;       if (w == 1)         g[v] = num[1] - num[v];       else         g[v] = g[u] + f[u] - f[v];       dp(v);     }   }   void add(int u, int v, int w) {     p++;     node[p].u = v, node[p].w = w;     node[p].next = node[u].next;     node[u].next = p;   }   int main() {     while (scanf( %d , &n) != EOF) {       for (int i = 1; i <= n; i++) node[i].next = -1;       p = n;       for (int i = 1; i < n; i++) {         int u, v, w;         scanf( %d %d %d , &u, &v, &w);         w = judge(w);         add(u, v, w), add(v, u, w);       }       memset(isgo, 0, sizeof(isgo));       dfs(1);       memset(isgo, 0, sizeof(isgo));       g[1] = 0;       dp(1);       long long ans = 0;       for (int i = 1; i <= n; i++)         ans +=             1LL * f[i] * (f[i] - 1) + 1LL * g[i] * (g[i] - 1) + 2LL * f[i] * g[i];       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 5e5 + 10;   const long long mod = 998244353;   const long long base = 1e9;   mt19937_64 rnd;   struct Hashing {     vector<vector<vector<long long>>> f;     vector<long long> mod;     vector<vector<long long>> mu;     vector<long long> chr;     long long num;     long long base;     void init(long long num1) {       num = num1;       vector<long long> vt = {999244369, 999254351, 999154309, 989154311,                               989254411, 997254397, 991294387, 991814399,                               994114351, 994914359, 994024333};       random_shuffle(vt.begin(), vt.end());       base = 317;       for (int i = 1; i <= 26; i++) chr.push_back(abs((long long)(rnd())));       for (int i = 0; i < num; i++) {         f.emplace_back();         mod.push_back(vt[i]);         vector<long long> pt;         pt.push_back(1);         for (int j = 1; j < maxn; j++) {           pt.push_back((pt.back() * base) % mod[i]);         }         mu.push_back(pt);       }     }     long long add(string s) {       long long n = s.length();       long long id = f[0].size();       for (int j = 0; j < num; j++) {         vector<long long> vt1;         vt1.push_back(0);         for (int i = 1; i <= n; i++) {           vt1.push_back((vt1.back() * base + chr[s[i - 1] -  a ]) % mod[j]);         }         f[j].push_back(vt1);       }       return id;     }     long long get_hash(long long id, long long l, long long r) {       long long i = num - 1;       return ((f[i][id][r] - f[i][id][l - 1] * mu[i][r - l + 1]) % mod[i] +               mod[i]) %              mod[i];     }   };   int mn[maxn];   int mn1[maxn];   int nxt[maxn];   int par[maxn];   int find_par(int u) {     if (par[u] < 0) return u;     return par[u] = find_par(par[u]);   }   void dsu(int x, int y) {     x = find_par(x);     y = find_par(y);     if (x == y) return;     if (par[x] > par[y]) swap(x, y);     par[x] += par[y];     nxt[x] = max(nxt[x], nxt[y]);     par[y] = x;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     if (fopen( t.inp ,  r )) {       freopen( test.inp ,  r , stdin);       freopen( test.out ,  w , stdout);     }     int n, m, k;     cin >> n >> m >> k;     string s;     cin >> s;     string t;     cin >> t;     Hashing man;     man.init(1);     int id_s = man.add(s);     int id_t = man.add(t);     mn[0] = 1;     mn1[0] = n - k + 1;     for (int i = 1; i <= m; i++) {       mn[i] = base;       mn1[i] = -base;       nxt[i] = i;       par[i] = -1;     }     for (int i = 1; i <= n; i++) {       long long l = 1, h = min(n - i + 1, m);       while (l <= h) {         long long mid = (l + h) / 2;         if (man.get_hash(id_s, i, i + mid - 1) == man.get_hash(id_t, 1, mid))           l = mid + 1;         else           h = mid - 1;       }       if (h == m) {         if (i + 2 * k - 1 <= n) {           cout <<  Yes                 <<   n ;           cout << i <<     << i + k <<   n ;           return 0;         } else {           cout <<  Yes                 <<   n ;           cout << n - 2 * k + 1 <<     << n - k + 1 <<   n ;           return 0;         }       }       if (h && i + h - 1 >= k) {         int ed = h;         int st = max(k - i, 0) + 1;         int nw = st;         while (nw <= ed) {           if (mn[nw] != base) {             nw = nxt[find_par(nw)] + 1;           } else {             mn[nw] = i + nw - k;             if (nw > 1 && mn[nw - 1] != base) dsu(nw, nw - 1);             if (nw < m && mn[nw + 1] != base) dsu(nw, nw + 1);             nw++;           }         }       }     }     for (int i = 1; i <= m; i++) nxt[i] = i, par[i] = -1;     for (int i = n; i >= 1; i--) {       int l = 1, h = min(i, m);       while (l <= h) {         int mid = (l + h) / 2;         if (man.get_hash(id_s, i - mid + 1, i) ==             man.get_hash(id_t, m - mid + 1, m))           l = mid + 1;         else           h = mid - 1;       }       if (h == m) {         if (i - 2 * k + 1 >= 1) {           cout <<  Yes                 <<   n ;           cout << i - 2 * k + 1 <<     << i - k + 1 <<   n ;           return 0;         } else {           cout <<  Yes                 <<   n ;           cout << 1 <<     << 1 + k <<   n ;           return 0;         }       }       if (h && i - h + 1 <= n - k + 1) {         int st = max(0, i - (n - k + 1)) + 1;         int ed = h;         int nw = st;         while (nw <= ed) {           if (mn1[nw] != -base) {             nw = nxt[find_par(nw)] + 1;           } else {             mn1[nw] = i - nw + 1;             if (nw > 1 && mn1[nw - 1] != -base) dsu(nw, nw - 1);             if (nw < m && mn1[nw + 1] != -base) dsu(nw, nw + 1);             nw++;           }         }       }     }     for (int i = 1; i <= m; i++) {       if (mn[i] + k - 1 < mn1[m - i] && i <= k && m - i <= k) {         cout <<  Yes               <<   n ;         cout << mn[i] <<     << mn1[m - i] <<   n ;         return 0;       }     }     cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool row[1100], col[1100];   int main() {     int n, m;     while (scanf( %d %d , &n, &m) != EOF) {       memset(row, true, sizeof(row));       memset(col, true, sizeof(col));       while (m--) {         int x, y;         scanf( %d %d , &x, &y);         row[x] = false;         col[y] = false;       }       int res = 0;       for (int i = 2; i <= n - 1; i++) {         if (n % 2 && i == n / 2 + 1) {           continue;         }         if (col[i]) {           res++;         }         if (row[i]) {           res++;         }       }       if (n % 2 && (col[n / 2 + 1] || row[n / 2 + 1])) {         res++;       }       printf( %d n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, s;   long long row, col;   long long sr, sc;   long long tr, tc;   int main() {     scanf( %I64d %I64d %I64d , &n, &m, &s);     row = n / s + 1;     if (n % s == 0) row--;     col = m / s + 1;     if (m % s == 0) col--;     sr = n - ((row - 1) * s + 1);     sc = m - ((col - 1) * s + 1);     tr = (sr + 1) * row;     tc = (sc + 1) * col;     printf( %I64d n , min(n * m, tr * tc));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005];   int main() {     int n, x;     scanf( %d%d , &n, &x);     int sum = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       sum += a[i];     }     if (n == 1) {       if (a[0] == x)         printf( YES n );       else         printf( NO n );       return 0;     }     if (sum + n - 1 == x)       printf( YES n );     else       printf( NO n );   }


#include <bits/stdc++.h>   using namespace std;   int x[5011], a, b, c, n;   int main() {     cin >> n;     printf( ? 1 2 n );     fflush(stdout);     scanf( %d , &a);     printf( ? 1 3 n );     fflush(stdout);     scanf( %d , &b);     printf( ? 2 3 n );     fflush(stdout);     scanf( %d , &c);     int q = a - c;     x[1] = (q + b) / 2;     x[2] = a - x[1];     x[3] = b - x[1];     for (int i = 4; i <= n; i++) {       printf( ? %d %d n , i - 1, i);       fflush(stdout);       scanf( %d , &q);       x[i] = q - x[i - 1];     }     printf( !  );     for (int i = 1; i <= n; i++) {       printf( %d  , x[i]);     }     fflush(stdout);   }


#include <bits/stdc++.h>   using namespace std;   auto start = std::chrono::system_clock::now();   inline void skj() {     std::chrono::time_point<std::chrono::system_clock> end;     end = std::chrono::system_clock::now();     std::chrono::duration<double> elapsed_seconds = end - start;     std::time_t end_time = std::chrono::system_clock::to_time_t(end);     cerr <<  Time taken   << elapsed_seconds.count() * 1000 <<   n ;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   inline long long binexp(long long a, long long b, long long m) {     if (a == 0) {       return 0;     }     long long res = 1;     a %= m;     while (b) {       if (b & 1) res = (res * 1ll * a) % m;       a = (a * 1ll * a) % m;       b >>= 1;     }     return res;   }   inline long long binmul(long long a, long long b, long long m) {     a %= m;     long long res = 0;     while (b) {       if (b & 1) {         res = (res + a) % m;       }       a = (a + a) % m;       b >>= 1;     }     return res;   }   const long long N = 3e5 + 5;   long long seg[4 * N], lazy[4 * N];   void updateRange(long long node, long long start, long long end, long long l,                    long long r, long long val) {     if (lazy[node] != 0) {       seg[node] += lazy[node];       if (start != end) {         lazy[node * 2] += lazy[node];         lazy[node * 2 + 1] += lazy[node];       }       lazy[node] = 0;     }     if (start > end or start > r or end < l) return;     if (start >= l and end <= r) {       seg[node] += val;       if (start != end) {         lazy[node * 2] += val;         lazy[node * 2 + 1] += val;       }       return;     }     long long mid = (start + end) / 2;     updateRange(node * 2, start, mid, l, r, val);     updateRange(node * 2 + 1, mid + 1, end, l, r, val);     seg[node] = min(seg[node * 2], seg[node * 2 + 1]);   }   long long queryRange(long long node, long long start, long long end,                        long long l, long long r) {     if (start > end or start > r or end < l) return 0;     if (lazy[node] != 0) {       seg[node] += lazy[node];       if (start != end) {         lazy[node * 2] += lazy[node];         lazy[node * 2 + 1] += lazy[node];       }       lazy[node] = 0;     }     if (start >= l and end <= r) return seg[node];     long long mid = (start + end) / 2;     long long p1 = queryRange(node * 2, start, mid, l, r);     long long p2 = queryRange(node * 2 + 1, mid + 1, end, l, r);     return min(p1, p2);   }   inline void solve_me_senpai() {     long long n, m;     cin >> n >> m;     long long a = 5, b = 4;     string as =  5 , bs =  5 ;     while (a <= n or b <= n) {       a += 5, b += 4;       as.push_back( 5 );       bs.push_back( 4 );     }     reverse(as.begin(), as.end());     reverse(bs.begin(), bs.end());     cout << as <<     << bs <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     long long a = 1;     while (t--) {       solve_me_senpai();       a++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 300000;   const long long inf = 1LL << 60;   struct edge {     long long from, to, dist;     edge(long long u, long long v, long long d) : from(u), to(v), dist(d) {}   };   struct HeapNode {     long long d;     long long u;     HeapNode(long long a, long long b) : d(a), u(b) {}     bool operator<(const HeapNode &rhs) const { return d > rhs.d; }   };   struct Dijkstra {     int n, m;     vector<edge> edges;     vector<int> G[maxn];     bool done[maxn];     long long d[maxn];     int p[maxn];     void init(int n) {       this->n = n;       for (int i = 0; i < n; ++i) G[i].clear();       edges.clear();     }     void add_edge(int from, int to, long long dist) {       edges.push_back(edge(from, to, dist));       m = edges.size();       G[from].push_back(m - 1);     }     void dijkstra(int s) {       priority_queue<HeapNode> Q;       for (int i = 0; i < n; ++i) d[i] = inf;       d[s] = 0;       Q.push(HeapNode(0, s));       memset(done, 0, sizeof(done));       while (!Q.empty()) {         HeapNode x = Q.top();         Q.pop();         int u = x.u;         if (done[u]) continue;         done[u] = true;         for (unsigned i = 0; i < G[u].size(); ++i) {           edge &e = edges[G[u][i]];           if (d[e.to] > d[u] + e.dist) {             d[e.to] = d[u] + e.dist;             p[e.to] = G[u][i];             Q.push(HeapNode(d[e.to], e.to));           }         }       }     }   } graph;   int main() {     int n, m;     scanf( %d %d , &n, &m);     graph.init(n + 10);     const int s = n + 5;     for (int i = 0; i < m; ++i) {       long long x, y, w;       scanf( %lld %lld %lld , &x, &y, &w);       graph.add_edge(x, y, w * 2);       graph.add_edge(y, x, w * 2);     }     for (int i = 1; i <= n; ++i) {       long long a;       scanf( %lld , &a);       graph.add_edge(s, i, a);     }     graph.dijkstra(s);     for (int i = 1; i <= n; ++i) printf( %lld  , graph.d[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   int pr[100002];   int lv[100002];   int st[100002], head;   int P(int x) {     head = 0;     while (pr[x] != -1) {       st[head++] = x;       x = pr[x];     }     while (head > 0) {       pr[st[--head]] = x;     }     return x;   }   void Union(int x, int y) {     x = P(x);     y = P(y);     if (x == y) return;     if (lv[x] > lv[y]) {       int t = x;       x = y;       y = t;     }     pr[x] = y;     if (lv[x] == lv[y]) {       lv[y]++;     }   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     int a, b;     int i;     int sol = 1;     for (i = 0; i < n; i++) {       pr[i] = -1;       lv[i] = 0;     }     for (i = 0; i < m; i++) {       scanf( %d %d , &a, &b);       a--;       b--;       if (P(a) != P(b)) {         Union(a, b);       } else         sol = (sol * 2) % 1000000009;       int pr;       pr = (sol - 1 + 1000000009) % 1000000009;       printf( %d n , pr);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, n;     cin >> a >> b >> n;     a = a * 10;     int f = 0;     for (int i = 0; i < 10; i++) {       if ((a + i) % b == 0) {         cout << a + i;         string s(n - 1,  0 );         cout << s << endl;         f = 1;         break;       }     }     if (!f) cout << -1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 10000;   const long long INFFLUJO = 1e14;   const double INFCOSTO = 1e14;   struct edge {     int u, v;     long long cap, flow;     double cost;     long long rem() { return cap - flow; }   };   int nodes;   vector<int> G[MAXN];   vector<edge> e;   void addEdge(int u, int v, long long cap, double cost) {     G[u].push_back(((int)e.size()));     e.push_back((edge){u, v, cap, 0, cost});     G[v].push_back(((int)e.size()));     e.push_back((edge){v, u, 0, 0, -cost});   }   double dist[MAXN], mnCost;   int pre[MAXN];   long long cap[MAXN], mxFlow;   bool in_queue[MAXN];   void flow(int s, int t) {     memset(in_queue, 0, sizeof(in_queue));     mxFlow = mnCost = 0;     while (1) {       fill(dist, dist + nodes, INFCOSTO);       dist[s] = 0;       memset(pre, -1, sizeof(pre));       pre[s] = 0;       memset(cap, 0, sizeof(cap));       cap[s] = INFFLUJO;       queue<int> q;       q.push(s);       in_queue[s] = 1;       while (((int)q.size())) {         int u = q.front();         q.pop();         in_queue[u] = 0;         for (auto it : G[u]) {           edge &E = e[it];           if (E.rem() && dist[E.v] > dist[u] + E.cost + 1e-9) {             dist[E.v] = dist[u] + E.cost;             pre[E.v] = it;             cap[E.v] = min(cap[u], E.rem());             if (!in_queue[E.v]) q.push(E.v), in_queue[E.v] = 1;           }         }       }       if (pre[t] == -1) break;       mxFlow += cap[t];       mnCost += cap[t] * dist[t];       for (int v = t; v != s; v = e[pre[v]].u) {         e[pre[v]].flow += cap[t];         e[pre[v] ^ 1].flow -= cap[t];       }     }   }   int x[500], y[500];   int main() {     int n;     scanf( %d , &n);     int mx = -1100000;     for (int i = 0; i < int(n); i++) {       scanf( %d %d , x + i, y + i);       mx = max(mx, y[i]);     }     int cnt = 0;     for (int i = 0; i < int(n); i++)       if (y[i] == mx) cnt++;     if (cnt > 1)       printf( -1 n );     else {       nodes = 2 * n + 2;       for (int i = 0; i < int(n); i++)         for (int j = 0; j < int(n); j++)           if (y[i] > y[j]) {             addEdge(i, n + j, 1,                     sqrt(1ll * (x[i] - x[j]) * (x[i] - x[j]) +                          1ll * (y[i] - y[j]) * (y[i] - y[j])));           }       for (int i = 0; i < int(n); i++) addEdge(2 * n, i, 2, 0);       for (int i = 0; i < int(n); i++)         if (y[i] != mx) addEdge(n + i, 2 * n + 1, 1, 0);       flow(2 * n, 2 * n + 1);       if (mxFlow != n - 1)         printf( -1 n );       else         printf( %.10lf n , mnCost);     }   }


#include <bits/stdc++.h>   using namespace std;   struct inf {     long long v;     long long b;   };   bool cmp(struct inf a, struct inf c) { return a.b > c.b; }   int main() {     struct inf a[300005];     long long n, k, i, j, sum = 0, ans = -1, temp;     cin >> n >> k;     for (i = 0; i < n; i++) {       cin >> a[i].v >> a[i].b;     }     sort(a, a + n, cmp);     priority_queue<long long, vector<long long>, greater<long long>> q;     for (i = 0; i < n; i++) {       if (i < k) {         sum += a[i].v;         q.push(a[i].v);         ans = max(ans, sum * a[i].b);       } else {         temp = q.top();         if (temp < a[i].v) {           sum -= temp;           q.pop();           q.push(a[i].v);           sum += a[i].v;           ans = max(ans, sum * a[i].b);         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void count() {}   int ans[1000001], h = 0;   int main() {     count();     int n;     cin >> n;     int a[301], b[301];     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 1; i <= n; ++i) {       cin >> b[i];     }     for (int i = 1; i <= n; ++i) {       if (a[i] != b[i]) {         int id;         for (int j = i + 1; j <= n; ++j) {           if (b[j] == a[i]) {             id = j;             break;           }         }         for (int j = id; j > i; --j) {           ans[h++] = j;           swap(b[j], b[j - 1]);         }       }     }     cout << h << endl;     for (int i = 0; i < h; ++i) {       cout << ans[i] - 1 <<     << ans[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int count = 1;     bool res = false;     for (int i = 0; i < s.length() - 1; i++) {       if (s.at(i) == s.at(i + 1)) {         count++;         if (count > 6) {           res = true;           break;         }       } else {         count = 1;       }     }     if (res) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, x, y;     long long white, black;     cin >> n;     cin >> x >> y;     white = (x - 1) + (y - 1);     black = (n - x) + (n - y);     if (white == black) {       cout <<  White ;     } else {       white > black ? cout <<  Black  : cout <<  White ;     }     cout << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC optimize(4)   using namespace std;   const int N = 1000 + 7;   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int mod = 998244353;   const double eps = 1e-8;   const double PI = acos(-1);   template <class T, class S>   inline void add(T &a, S b) {     a += b;     if (a >= mod) a -= mod;   }   template <class T, class S>   inline void sub(T &a, S b) {     a -= b;     if (a < 0) a += mod;   }   template <class T, class S>   inline bool chkmax(T &a, S b) {     return a < b ? a = b, true : false;   }   template <class T, class S>   inline bool chkmin(T &a, S b) {     return a > b ? a = b, true : false;   }   const int MN = 64;   struct Vec {     int a[MN];     Vec() {       for (int i = 0; i < MN; i++) {         a[i] = 0;       }     }   };   struct Matrix {     int a[MN][MN];     Matrix(int v = 0) {       for (int i = 0; i < MN; i++) {         for (int j = 0; j < MN; j++) {           a[i][j] = (i == j) ? v : 0;         }       }     }     inline Matrix operator*(const Matrix &B) const {       Matrix C(0);       for (int i = 0; i < MN; i++) {         for (int k = 0; k < MN; k++) {           if (!a[i][k]) continue;           for (int j = 0; j < MN; j++) {             C.a[i][j] += 1LL * a[i][k] * B.a[k][j] % mod;             if (C.a[i][j] >= mod) C.a[i][j] -= mod;           }         }       }       return C;     }     Vec operator*(const Vec &B) const {       Vec C;       for (int i = 0; i < MN; i++) {         for (int j = 0; j < MN; j++) {           add(C.a[i], 1LL * a[i][j] * B.a[j] % mod);         }       }       return C;     }   } M[30], M2[4];   int n, m, a[N];   int ret[N][4];   vector<pair<int, int> > V[N];   int f[4][4];   int dp[N][4];   bool vis[4];   int v[3];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       int x, y, c;       scanf( %d%d%d , &x, &y, &c);       V[x].push_back(make_pair(y, c));     }     for (int i = 1; i <= n; i++) {       sort((V[i]).begin(), (V[i]).end());     }     for (int i = 1; i <= n; i++) {       V[i].push_back(make_pair(a[i] + 1, 1));     }     for (int i = 1; i <= 3; i++) {       for (int j = 1; j <= 3; j++) {         scanf( %d , &f[i][j]);       }     }     for (int mask = 0; mask < MN; mask++) {       for (int i = 0; i < 3; i++) {         v[i] = mask >> (i * 2) & 3;       }       for (int color = 1; color <= 3; color++) {         memset(vis, 0, sizeof(vis));         if (f[color][1]) vis[v[0]] = true;         if (f[color][2]) vis[v[1]] = true;         if (f[color][3]) vis[v[2]] = true;         int sg = -1;         for (int i = 0; i < 4; i++) {           if (!vis[i]) {             sg = i;             break;           }         }         int nmask = sg + (v[0] << 2) + (v[1] << 4);         add(M[0].a[nmask][mask], 1);         add(M2[color].a[nmask][mask], 1);       }     }     for (int i = 1; i < 30; i++) {       M[i] = M[i - 1] * M[i - 1];     }     for (int i = 1; i <= n; i++) {       Vec tmp;       tmp.a[63] = 1;       int last = 0;       for (auto &t : V[i]) {         int cnt = t.first - last - 1;         for (int j = 0; j < 30; j++) {           if (cnt >> j & 1) {             tmp = M[j] * tmp;           }         }         if (t.first != a[i] + 1) {           tmp = M2[t.second] * tmp;         }         last = t.first;       }       for (int j = 0; j < MN; j++) {         add(ret[i][j & 3], tmp.a[j]);       }     }     dp[0][0] = 1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < 4; j++) {         for (int k = 0; k < 4; k++) {           add(dp[i + 1][j ^ k], 1LL * dp[i][j] * ret[i + 1][k] % mod);         }       }     }     printf( %d n , dp[n][0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 15;   int prime[maxn];   bool visit[maxn] = {false};   vector<int> prim;   vector<int> nu;   void init() {     int pos = 0;     for (int i = 2; i < maxn; i++) {       if (visit[i] == false) {         prime[pos++] = i;       }       for (int j = 0; j < pos && prime[j] * i < maxn; j++) {         visit[prime[j] * i] = true;         if (i % prime[j] == 0) {           break;         }       }     }   }   bool isprime(long long test) {     for (int i = 2; i <= sqrt(test); i++) {       if (test / 2 == 0) {         return false;       }     }     return true;   }   void find(long long test) {     for (int i = 0; prime[i] <= sqrt(test); i++) {       int num = 0;       while (test % prime[i] == 0) {         num++;         test /= prime[i];       }       if (num != 0) {         prim.push_back(prime[i]);         nu.push_back(num);       }     }     if (isprime(test) && test > 1) {       prim.push_back(test);       nu.push_back(1);     }   }   int main() {     int t;     init();     cin >> t;     long long p, q;     while (t--) {       cin >> p >> q;       prim.clear();       nu.clear();       find(q);       if (p % q != 0) {         cout << p << endl;       } else {         long long maxans = -100;         for (int i = 0; i < prim.size(); i++) {           int tmpnum = 0;           long long test = p;           long long ans = p;           while (test % prim[i] == 0) {             test /= prim[i];             tmpnum++;           }           int reducenum = tmpnum - nu[i] + 1;           ans = ans / pow(prim[i], reducenum);           maxans = max(ans, maxans);         }         cout << maxans << endl;       }     }   }


#include <bits/stdc++.h>   int n;   int a[100001];   typedef struct {     int len;   } segment;   int main(void) {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     if (n <= 2) {       printf( %d , n);       return 0;     }     segment max;     max.len = 2;     segment temp;     temp.len = 2;     for (int i = 2; i < n; ++i) {       if (a[i] == a[i - 1] + a[i - 2])         temp.len++;       else {         if (max.len < temp.len) max.len = temp.len;         temp.len = 2;       }     }     if (temp.len > max.len) max.len = temp.len;     printf( %d , max.len);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int lowbit(int a) { return a & (-a); }   int getans(char c, int l, int r, string &s) {     if (l == r) {       return s[l] != c;     }     int len = r - l + 1;     int cnt = 0;     for (int i = l; i < l + len / 2; i++) {       if (s[i] != c) cnt++;     }     int ans = cnt + getans(c + 1, l + len / 2, r, s);     cnt = 0;     for (int i = l + len / 2; i <= r; i++) {       if (s[i] != c) cnt++;     }     ans = min(ans, cnt + getans(c + 1, l, l + len / 2 - 1, s));     return ans;   }   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       cout << getans( a , 0, n - 1, s) <<   n ;     }   }