#include <cstdio>   #include <algorithm>   #include <vector>      typedef long long LL;   const int Inf = 0x3f3f3f3f;   const int Mod = 998244353;   const int MN = 405;      int N, M;   std::vector<int> G[MN];   int Dis[MN][MN];      int Calc(int x, int y) {    for (int i = 2; i <= N; ++i)     if ((Dis[x][i] ^ Dis[y][i] ^ Dis[x][1] ^ Dis[y][1]) & 1)      return 0;    int cnt = 0;    for (int i = 1; i <= N; ++i)     if (Dis[x][i] + Dis[y][i] == Dis[x][y])      ++cnt;    if (cnt != Dis[x][y] + 1) return 0;    int Ans = 1;    for (int i = 1; i <= N; ++i) {     if (Dis[x][i] + Dis[y][i] == Dis[x][y]) continue;     int c = 0;     for (int v : G[i]) {      if (Dis[x][v] != Dis[x][i] - 1) continue;      if (Dis[y][v] != Dis[y][i] - 1) continue;      ++c;     }     if (!c) return 0;     Ans = (LL)Ans * c % Mod;    }    return Ans;   }      int main() {    scanf( %d%d , &N, &M);    for (int i = 1; i <= N; ++i)     for (int j = 1; j <= N; ++j)      Dis[i][j] = i == j ? 0 : Inf;    for (int i = 1; i <= M; ++i) {     int u, v;     scanf( %d%d , &u, &v);     G[u].push_back(v);     G[v].push_back(u);     Dis[u][v] = 1;     Dis[v][u] = 1;    }    for (int k = 1; k <= N; ++k)     for (int i = 1; i <= N; ++i)      for (int j = 1; j <= N; ++j)       Dis[i][j] = std::min(Dis[i][j], Dis[i][k] + Dis[k][j]);   // for (int i = 1; i <= N; ++i)   //  for (int j = 1; j <= N; ++j)   //   printf( %d%s , Dis[i][j], j == N ?   n  :  ,  );    for (int i = 1; i <= N; ++i)     for (int j = 1; j <= N; ++j)      printf( %d%c , Calc(i, j),    n [j == N]);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = (int)1e9 + 7;   long long modPow(long long n, long long k) {     long long res = 1;     for (n %= mod; k; k >>= 1) {       if (k & 1) res = res * n % mod;       n = n * n % mod;     }     return res;   }   long long modInv(const long long x) { return modPow(x, mod - 2); }   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr), cout.tie(nullptr);     int n;     cin >> n;     vector<int> l(n + 1, 0), r(n + 1, 0);     for (int i = 1; i <= n; ++i) cin >> l[i];     for (int i = 1; i <= n; ++i) cin >> r[i];     const auto sz = [&](const int i) {       assert(l[i] <= r[i]);       return r[i] - l[i] + 1LL;     };     long long ans = 0;     vector<long long> dp(n);     for (int i = 0; i < n; ++i) {       const long long c = max(0, min(r[i], r[i + 1]) - max(l[i], l[i + 1]) + 1);       dp[i] = 1 - c * modInv(sz(i)) % mod * modInv(sz(i + 1)) % mod;       (ans += dp[i]) %= mod;     }     for (int i = 0; i + 1 < n; ++i) {       const int L = max(l[i], max(l[i + 1], l[i + 2]));       const int R = min(r[i], min(r[i + 1], r[i + 2]));       const long long c = max(0, R - L + 1);       const long long temp =           1 - (1 - dp[i]) - (1 - dp[i + 1]) +           c * modInv(sz(i) * sz(i + 1) % mod * sz(i + 2) % mod);       (ans += 2 * temp) %= mod;     }     long long sum = 0;     for (int i = 2; i < n; ++i) {       (sum += dp[i - 2]) %= mod;       (ans += 2 * dp[i] * sum) %= mod;     }     cout << (ans % mod + mod) % mod;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct segnode {     int l, r, mid, s, h;     segnode *ls, *rs;     segnode(void) { l = r = mid = s = h = 0; }     segnode(int x, int y) { l = x, r = y, mid = (l + r) >> 1, s = h = 0; }     void build(void) {       if (l == r) return;       ls = new segnode(l, mid);       rs = new segnode(mid + 1, r);       ls->build();       rs->build();     }     void upd(int x, int y) {       if (l == r) {         s = y > 0, h = y;         return;       }       if (x <= mid)         ls->upd(x, y);       else         rs->upd(x, y);       s = ls->s + rs->s;     }     int findx(int x, int &dh) {       if (l == r) {         dh = h;         return l;       }       if (x <= ls->s)         return ls->findx(x, dh);       else         return rs->findx(x - ls->s, dh);     }     int findy(int x) {       if (l == r) return h;       if (x <= mid)         return ls->findy(x);       else         return rs->findy(x);     }     void mupd(int x, int y) {       if (l == r) {         s = y;         return;       }       if (x <= mid)         ls->mupd(x, y);       else         rs->mupd(x, y);       s = max(ls->s, rs->s);     }     int mget(int x, int y) {       if (x <= l && r <= y) return s;       int t = 0;       if (x <= mid) t = ls->mget(x, y);       if (y > mid) t = max(rs->mget(x, y), t);       return t;     }     void print(void) {       printf( [%d,%d %d %d] n , l, r, mid, s);       if (l == r) return;       ls->print();       rs->print();     }   };   segnode sy, sx;   segnode ty, tx;   int n, m, mm;   void init(void) {     mm = m + 11;     sy = segnode(0, mm);     sx = segnode(0, n);     ty = segnode(0, mm);     tx = segnode(0, n);     sy.build();     sx.build();     ty.build();     tx.build();   }   void msort(int *x, int *y, int n) {     pair<int, int> a[20];     for (int i = 1; i <= n; i++) a[i].first = x[i], a[i].second = y[i];     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) x[i] = a[i].first, y[i] = a[i].second;   }   int main(void) {     scanf( %d%d , &n, &m);     init();     for (int t = 1, x, y, z; t <= m; t++) {       scanf( %d%d , &x, &y);       static int ti[20], hi[20];       if (x == 1) {         scanf( %d , &z);         int dz = z;         z = z - t + m;         tx.upd(y, z), ty.upd(z, y);         int dt = 0;         for (int i = 1; i <= dz; i++) {           int id = i - t + m;           ti[++dt] = ty.findy(id), hi[dt] = id;           if (!ti[dt])             dt--;           else             sy.mupd(id, 0), sx.mupd(ti[dt], 0);         }         msort(hi, ti, dt);         for (int i = dt; i >= 1; i--) {           int s = sx.mget(ti[i] + 1, n) + 1;           sy.mupd(hi[i], s), sx.mupd(ti[i], s);         }       } else {         for (int i = 1; i <= y; i++) {           int h, id = tx.findx(i, h);           ti[i] = id, hi[i] = h;           sy.mupd(h, 0), sx.mupd(id, 0);           if (i == y) tx.upd(id, 0), ty.upd(h, 0);         }         for (int i = y - 1; i >= 1; i--) {           int s = sy.mget(hi[i] + 1, mm) + 1;           sy.mupd(hi[i], s), sx.mupd(ti[i], s);         }       }       printf( %d n , sy.mget(0, mm));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   struct node {     int a, k;     bool operator<(const node& e) const { return k < e.k; }   } a[300100];   int main() {     while (scanf( %d , &n) != EOF) {       for (int i = 0; i < n; i++) scanf( %d %d , &a[i].k, &a[i].a);       sort(a, a + n);       int ans = a[0].a;       for (int i = 1; i < n; i++) {         int u = 0;         while (ans != 1 && u + a[i - 1].k < a[i].k) {           u++;           ans = (ans + 3) / 4;         }         ans = max(ans, a[i].a);       }       if (ans == 1)         printf( %d n , a[n - 1].k + 1);       else {         int p = a[n - 1].k;         while (ans != 1) {           p++;           ans = (ans + 3) / 4;         }         printf( %d n , p);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int MAXN = 1e18 + 7;   const long long int MAXNN = 300005;   long long int int_pow(long long int base, long long int exp) {     long long int result = 1;     while (exp) {       if (exp & 1) result *= base;       exp /= 2;       base *= base;     }     return result;   }   vector<long long int> g[MAXNN];   vector<long long int> w[MAXNN];   set<pair<long long int, long long int> > st;   long long int dist[MAXNN];   long long int par[MAXNN];   bool mark[MAXNN];   map<pair<long long int, long long int>, long long int> mpw;   map<pair<long long int, long long int>, long long int> mpn;   void diekstra(long long int n, long long int s) {     fill_n(dist, MAXNN, MAXN);     dist[s] = 0;     for (long long int i = 1; i <= n; i++) st.insert({dist[i], i});     while (!st.empty()) {       set<pair<long long int, long long int> >::iterator it = st.begin();       long long int x = it->second;       mark[x] = 1;       st.erase(it);       for (long long int i = 0; i < (long long int)g[x].size(); i++) {         long long int y = g[x][i];         if (!mark[y]) {           st.erase({dist[y], y});           if (dist[y] >= dist[x] + w[x][i]) {             par[y] = x;           }           dist[y] = min(dist[y], dist[x] + w[x][i]);           st.insert({dist[y], y});         }       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(par, -1, sizeof par);     long long int n, m, u, v, z, stpoint = 0, ans = 0;     cin >> n >> m;     for (long long int i = 0; i < m; i++) {       cin >> u >> v >> z;       if (u > v) swap(u, v);       mpn[{u, v}] = i + 1;       mpw[{u, v}] = z;       g[u].push_back(v);       g[v].push_back(u);       w[u].push_back(z);       w[v].push_back(z);     }     cin >> stpoint;     diekstra(n, stpoint);     for (long long int i = 1; i <= n; i++) {       if (i == stpoint) continue;       u = i, v = par[i];       if (u > v) swap(u, v);       ans += mpw[{u, v}];     }     cout << ans <<   n ;     for (long long int i = 1; i <= n; i++) {       if (i == stpoint) continue;       u = i, v = par[i];       if (u > v) swap(u, v);       cout << mpn[{u, v}] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long a[10000000];   int main() {     long long n, i, j, m, l, r, cnt = 0;     string s, s2, s3 =   , s4 =   , s5 =   ;     cin >> s >> s2;     n = s.size();     for (i = 0; i < n - 1; i++) {       if (s[i] == s2[i])         s3 += s[i];       else         break;     }     for (i = n - 1; i > 0; i--) {       if (s[i] == s2[i - 1])         s4 += s[i];       else         break;     }     l = s3.size();     r = s4.size();     if (l + 1 < n - r)       cout <<  0  << endl;     else {       s5 = s5 + s[l];       cnt = 0;       for (i = l; i >= 0; i--) {         if (s5[0] == s[i]) {           a[cnt] = i + 1;           ++cnt;         } else           break;       }       for (i = l + 1; i < n; i++) {         if (s5[0] == s[i]) {           a[cnt] = i + 1;           ++cnt;         } else           break;       }       sort(a, a + cnt);       cout << cnt << endl;       for (i = 0; i < cnt; i++) {         cout << a[i] <<    ;       }     }   }


#include <bits/stdc++.h>      using namespace std;      long long dp[2][300000];      long long dfs(int previous,bool previousMax,int N, vector<vector<int> > & adj, vector<pair<long long,long long> > &vals) {    if(dp[previousMax][N]!=-1) return dp[previousMax][N];    long long res1 = 0;    long long res2 = 0;    if(previous != -1) {     res1 = abs((previousMax?vals[previous].second:vals[previous].first)-vals[N].first);     res2 = abs((previousMax?vals[previous].second:vals[previous].first)-vals[N].second);    }       for(auto &z:adj[N]) {     if(z != previous) {      res1 += dfs(N,false,z,adj,vals);      res2 += dfs(N,true,z,adj,vals);     }    }    dp[previousMax][N] = max(res1,res2);    return max(res1,res2);   }      int main() {    ios_base::sync_with_stdio(false);    cin.tie(0);    int T;    cin>>T;        while(T--) {     int N;     cin>>N;     vector<pair<long long int,long long int> > vals(N);     for(int c=0;c<N;c++) cin>>vals[c].first>>vals[c].second;        vector<vector<int> > adj(N);        for(int c=0;c<2;c++) for(int c2=0;c2<N;c2++) dp[c][c2] = -1;        for(int c=1;c<N;c++) {      int f,t;      cin>>f>>t;      f--;      t--;      adj[f].push_back(t);      adj[t].push_back(f);     }        cout<<max(dfs(-1,false,0,adj,vals),dfs(-1,false,0,adj,vals))<<  n ;    }   }


#include <bits/stdc++.h>   using namespace std;   int n;   char a[1000];   int mp[105][150];   int jishu[105][5];   int flag;   int main() {     scanf( %d , &n);     memset(mp, 0, sizeof(mp));     getchar();     for (int i = 1; i <= n; i++) {       memset(a, 0, sizeof(a));       gets(a);       flag = 0;       for (unsigned int j = 0; j < strlen(a); j++) {         if (mp[i][a[j]] == 0) {           jishu[i][flag] = a[j];           flag++;         }         mp[i][a[j]]++;         if (flag > 2) {           memset(mp[i], 0, sizeof(mp[i]));           memset(jishu[i], 0, sizeof(jishu[i]));           break;         }       }     }     int re = 0;     int linshi = 0;     for (int j =  a ; j <=  z ; j++)       for (int k =  a ; k <=  z ; k++) {         linshi = 0;         for (int l = 1; l <= n; l++) {           if ((jishu[l][0] == j && jishu[l][1] == k) ||               (jishu[l][0] == k && jishu[l][1] == j)) {             linshi += (mp[l][j] + mp[l][k]);           } else {             if (jishu[l][1] < 97 || jishu[l][1] > 123) {               if (jishu[l][0] == j) {                 linshi += mp[l][j];               }               if (jishu[l][0] == k && j != k) {                 linshi += mp[l][k];               }             }           }         }         re = max(re, linshi);       }     cout << re << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   int main(void) {     int t;     long long n, k, o;     cin >> t;     while (t--) {       cin >> n >> k;       for (o = 0; n;) {         if (n % k) {           o += n % k;           n -= n % k;         } else {           o++;           n /= k;         }       }       cout << o << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;      // Template {{{   #define MOD     1000000007   #define MAX     1e9   #define MIN                 -1e9   #define PI     acos(-1.0)   #define mid(s,e)   (s+(e-s)/2)   #define clz(n)    __builtin_clzll(n)   #define all(x)              (x).begin(), (x).end()   #define pb                  push_back      using ll = long long;   using vi = vector<int>;   using vvi = vector<vi>;   using vll = vector<ll>;   using vvll = vector<vll>;   using vb = vector<bool>;   using vd = vector<double>;   using vs = vector<string>;       using pii = pair<int, int>;   using pll = pair<ll, ll>;   using pdd = pair<double, double>;       using vpii = vector<pii>;   using vpll = vector<pll>;   using vpdd = vector<pdd>;      void __print(int x) {cerr << x;}   void __print(long x) {cerr << x;}   void __print(long long x) {cerr << x;}   void __print(unsigned x) {cerr << x;}   void __print(unsigned long x) {cerr << x;}   void __print(unsigned long long x) {cerr << x;}   void __print(float x) {cerr << x;}   void __print(double x) {cerr << x;}   void __print(long double x) {cerr << x;}   void __print(char x) {cerr <<      << x <<     ;}   void __print(const char *x) {cerr <<     << x <<    ;}   void __print(const string &x) {cerr <<     << x <<    ;}   void __print(bool x) {cerr << (x ?  true  :  false );}      template<typename T, typename V>   void __print(const pair<T, V> &x) {cerr <<  { ; __print(x.first); cerr <<  , ; __print(x.second); cerr <<  } ;}   template<typename T>   void __print(const T &x) {int f = 0; cerr <<  { ; for (auto &i: x) cerr << (f++ ?  ,  :   ), __print(i); cerr <<  } ;}   void _print() {cerr <<  ] n ;}   template <typename T, typename... V>   void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr <<  ,  ; _print(v...);}   template<typename T>   void printVec(const T &v, char sep=   ) {for (auto &i: v) cout << i << sep;}   template<typename T>   void printVecPair(const T &v, char sep=   ) {for (auto &i: v) cout << i.first <<    << i.second<< sep;}         #ifndef ONLINE_JUDGE   #define debug(x...) cerr <<  [  << #x <<  ] = [ ; _print(x)   #else   #define debug(x...)   #endif   // }}}      void solve() {       int n;       cin>>n;       vll c(n), a(n), b(n);       for(ll& i: c) cin>>i;       for(ll& i: a) cin>>i;       for(ll& i: b) cin>>i;       ll ans = 0; ll tot = c[n-1]-1;       for(int i=n-2;i>=0;i--) {           if(a[i+1] > b[i+1]) swap(a[i+1],b[i+1]);           if(a[i+1] == b[i+1]) {               ans = max(tot+2,ans);               tot = c[i] - 1;               continue;           }           if(a[i+1] == -1 || b[i+1] == -1) {               ans = max(tot+2,ans);               tot = 0;               continue;           }           tot += 2;           ll c1 = c[i] - (a[i+1] - 1) - (c[i] - b[i+1]) - 1;            ll c2 = (a[i+1] - 1) + (c[i] - b[i+1]);           ans = max(tot+c1,ans);                      tot+=c2;           if(c[i] > tot) tot = c[i] - 1;             }                 cout<<ans<<endl;                }      int main() {       int t;       cin>>t;       while(t--) solve();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 4e6;   const long double SADAT = 7.84e-17;   const long long INF = 1e9;   const long long mod = 1e9 + 7;   const long double PI = 4 * atan((long double)1);   long long pw(long long a, long long b) {     return (!b ? 1                : (b & 1 ? a * pw(a * a % mod, b / 2) % mod                         : pw(a * a % mod, b / 2) % mod));   }   long long c, d, n, m, k;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> c >> d >> n >> m >> k;     long long w = n * m - k;     long long mn = 1e9;     for (long long i = 0; i < 10005; i++) {       mn = min(mn, c * i + max(w - n * i, (long long)0) * d);     }     cout << mn;     return (0);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   struct info {     int x, y, z;   };   vector<info> ans;   int dep[N], n, m, fa[N];   vector<int> g[N], edge[N];   void dfs(int x) {     dep[x] = dep[fa[x]] + 1;     for (int v : g[x]) {       if (!dep[v]) {         fa[v] = x;         dfs(v);       } else if (v != fa[x] && dep[v] < dep[x]) {         edge[v].push_back(x);       }     }   }   int solve(int x) {     for (int i = 0; i < edge[x].size() >> 1; i++) {       ans.push_back((info){edge[x][i << 1], x, edge[x][i << 1 | 1]});     }     int res = 0;     if (edge[x].size() & 1) {       res = edge[x].back();     }     edge[x].clear();     if (res) {       edge[x].push_back(res);     }     for (int v : g[x]) {       if (fa[v] == x) {         int t = solve(v);         if (t) {           ans.push_back((info){x, v, t});         } else {           edge[x].push_back(v);         }       }     }     for (int i = 0; i < edge[x].size() >> 1; i++) {       ans.push_back((info){edge[x][i << 1], x, edge[x][i << 1 | 1]});     }     return (edge[x].size() & 1) ? edge[x].back() : 0;   }   int main(void) {     scanf( %d%d , &n, &m);     for (int i = 1, u, v; i <= m; i++) {       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= n; i++) {       if (!dep[i]) {         dfs(i);         solve(i);       }     }     printf( %d n , ans.size());     for (info cur : ans) {       printf( %d %d %d n , cur.x, cur.y, cur.z);     }     return 0;   }


#include <bits/stdc++.h>   inline int in();   inline void wr(int);   inline int gcd(int, int);   int main(int argc, char** argv) {     register int T = in();     while (T--) {       register int p1 = in(), p2 = in(), k = in();       if (p1 > p2) p1 ^= p2 ^= p1 ^= p2;       if (k == 1) {         puts( REBEL );         continue;       }       register int g = gcd(p1, p2);       p1 /= g, p2 /= g;       if ((k - 1) * 1ll * p1 + 1 < p2)         puts( REBEL );       else         puts( OBEY );     }   }   inline int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }   inline int in() {     register char c = getchar();     register int x = 0, f = 1;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = -1;     for (; c >=  0  && c <=  9 ; c = getchar())       x = (x << 1) + (x << 3) + (c & 15);     return x * f;   }   inline void wr(int x) {     if (x < 0) putchar( - ), x = -x;     if (x / 10) wr(x / 10);     putchar(x % 10 +  0 );   }


#include <bits/stdc++.h>   using namespace std;   struct pt {     long long int x, y;   };   istream &operator>>(istream &input_stream, pt &a) {     input_stream >> a.x >> a.y;     return input_stream;   }   ostream &operator<<(ostream &output_stream, pt a) {     output_stream << a.x <<     << a.y;     return output_stream;   }   long long int crossprod(pt a, pt b) { return a.x * b.y - a.y * b.x; }   long long int dotprod(pt a, pt b) { return a.x * b.x + a.y * b.y; }   pt norm(pt b, pt a) {     a.x -= b.x;     a.y -= b.y;     return a;   }   long long int dist(pt a) { return (a.x) * (a.x) + (a.y) * (a.y); }   vector<pt> points;   long long int crossprod2(pt a, pt b, pt c) {     return (b.x - a.x) * (c.y - b.y) - (b.y - a.y) * (c.x - b.x);   }   bool cmp(pt a, pt b) {     a = norm(points[0], a);     b = norm(points[0], b);     return (crossprod(a, b) > 0) || (crossprod(a, b) == 0 && dist(a) < dist(b));   }   struct line {     long double a, b, c;   };   line build(pt b, pt c) {     line d;     d.a = b.y - c.y;     d.b = c.x - b.x;     d.c = -(d.a * b.x + d.b * b.y);     return d;   }   struct ptl {     long double x, y;   };   ptl norml(ptl c, ptl b) {     b.x -= c.x;     b.y -= c.y;     return b;   }   long double dotprodl(ptl c, ptl b) { return c.x * b.x + c.y * b.y; }   long double crossprodl(ptl c, ptl b) { return b.x * c.y - b.y * c.x; }   long double dist(ptl b) { return b.x * b.x + b.y * b.y; }   long double det(long double a, long double b, long double c, long double d) {     return a * d - b * c;   }   ptl interpoint(line m, line n) {     long double zn = det(m.a, m.b, n.a, n.b);     ptl res;     res.x = -det(m.c, m.b, n.c, n.b) / zn;     res.y = -det(m.a, m.c, n.a, n.c) / zn;     return res;   }   ptl interseqt(pt a, pt b, pt c, pt d) {     ptl res;     res.x = 0;     res.y = 0;     if (crossprod(norm(a, b), norm(c, d)) == 0) {       return res;     }     line m = build(a, b);     line n = build(c, d);     ptl e = interpoint(m, n);     ptl cc;     cc.x = c.x;     cc.y = c.y;     ptl dd;     dd.x = d.x;     dd.y = d.y;     ptl bb;     bb.x = b.x;     bb.y = b.y;     ptl aa;     aa.x = a.x;     aa.y = a.y;     if (dotprodl(norml(aa, e), norml(aa, bb)) >= 0 &&         dotprodl(norml(bb, e), norml(bb, aa)) >= 0)       if (dotprodl(norml(cc, e), norml(cc, dd)) >= 0) return e;     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     pt need;     cin >> n >> need.x >> need.y;     points.resize(n);     for (int i = 0; i < n; ++i) cin >> points[i];     long long int mx = points[0].x, my = points[0].y;     long long int min_x = points[0].x;     long long int min_y = points[0].y;     for (int i = 0; i < n; ++i) {       mx = max(mx, points[i].x);       my = max(my, points[i].y);     }     pt c;     c.x = 0;     c.y = my;     points.push_back(c);     c.y = 0;     c.x = mx;     points.push_back(c);     n = ((long long int)(points).size());     for (int i = 1; i < n; i++) {       if (points[i].x < min_x) {         min_x = points[i].x;         min_y = points[i].y;         swap(points[i], points[0]);       } else if (points[i].x == min_x && points[i].y < min_y) {         min_y = points[i].y;         swap(points[i], points[0]);       }     }     sort(points.begin() + 1, points.end(), cmp);     vector<pt> ans;     ans.push_back(points[0]);     ans.push_back(points[1]);     for (int i = 2; i < n; i++) {       while (((long long int)(ans).size()) > 1 &&              crossprod2(ans[((long long int)(ans).size()) - 2],                         ans[((long long int)(ans).size()) - 1], points[i]) <= 0)         ans.pop_back();       ans.push_back(points[i]);     }     ans.push_back(points[0]);     pt nul;     nul.x = 0;     nul.y = 0;     line ch = build(nul, need);     long double res = 1e18;     for (int i = 0; i < ((long long int)(ans).size()) - 1; ++i) {       ptl seqt = interseqt(ans[i], ans[i + 1], nul, need);       if (seqt.x == 0 || seqt.y == 0) continue;       res = min(res, max(need.x / seqt.x, need.y / seqt.y));     }     cout << setprecision(20) << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct rua {     char s[100001];     int n, a[100001], b[100001], x, y;     void _() {       int cnt = 0;       for (int i = 1; i <= n; i++)         if (s[i] ==  A )           a[i] = ++cnt, b[i] = b[i - 1];         else           a[i] = cnt = 0, b[i] = b[i - 1] + 1;     }     void get(int l, int r) {       x = b[r] - b[l - 1];       if (!x)         y = r - l + 1;       else         y = a[r];     }   } s, t;   int Q, a, b, c, d;   int main() {     scanf( %s , s.s + 1), s.n = strlen(s.s + 1);     scanf( %s , t.s + 1), t.n = strlen(t.s + 1);     s._(), t._();     scanf( %d , &Q);     while (Q--) {       scanf( %d%d%d%d , &a, &b, &c, &d);       s.get(a, b), t.get(c, d);       if (!s.x && t.x)         if (s.y > t.y)           s.x += 2, s.y = t.y;         else           s.y--;       if (s.y < t.y) {         printf( 0 );         continue;       }       if ((s.y - t.y) % 3) s.x += 2;       if (s.x > t.x || (t.x - s.x) & 1) {         printf( 0 );         continue;       }       printf( 1 );     }     return printf(  n ), 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<int, int> > adj[100005];   int dp[300005];   int x[300005];   int main() {     ios_base::sync_with_stdio(0);     int i, j;     cin >> n >> m;     while (m--) {       int u, v, e;       cin >> u >> v >> e;       adj[e].push_back(make_pair(u, v));     }     for (i = 1; i <= 1e5; i++) {       for (j = 0; j < adj[i].size(); j++) {         int u = adj[i][j].second;         x[u] = 0;       }       for (j = 0; j < adj[i].size(); j++) {         int u = adj[i][j].first;         int v = adj[i][j].second;         x[v] = max(x[v], dp[u] + 1);       }       for (j = 0; j < adj[i].size(); j++) {         int u = adj[i][j].second;         dp[u] = max(dp[u], x[u]);       }     }     int res = 0;     for (i = 1; i <= n; i++) res = max(res, dp[i]);     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, c, i, l;     cin >> n;     int ar[n];     l = 0;     for (i = 0; i < n; i++) {       cin >> ar[i];       if (ar[i] == 1) l++;     }     c = 0;     if (l == n) {       cout << c << endl;       exit(0);     }     for (i = 1; i < n - 1; i++) {       if (ar[i - 1] == 1 && ar[i + 1] == 1 && ar[i] == 0) {         c++;         ar[i + 1] = 0;       }     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[6][6];   char tl[2] = { x ,  o };   int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};   int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};   bool judge(int x, int y, int nu) {     for (int i = 0; i < 8; i++) {       int xx = x + dx[i];       int yy = y + dy[i];       if (a[xx][yy] == tl[nu]) {         xx = x - dx[i];         yy = y - dy[i];         if (a[xx][yy] ==  . ) return true;       }       if (a[xx][yy] ==  . ) {         xx = xx + dx[i];         yy = yy + dy[i];         if (a[xx][yy] == tl[nu]) return true;       }     }     return false;   }   void solve() {     int num1 = 0, num2 = 0;     for (int i = 1; i <= 4; i++)       for (int j = 1; j <= 4; j++) {         cin >> a[i][j];         if (a[i][j] ==  x ) num1++;         if (a[i][j] ==  o ) num2++;       }     for (int i = 0; i < 6; i++) a[i][0] = a[0][i] = a[6][i] = a[i][6] =  * ;     int be = 0;     if (num2 < num1) be = 1;     for (int i = 1; i <= 4; i++)       for (int j = 1; j <= 4; j++) {         if (a[i][j] == tl[be] && judge(i, j, be)) {           cout <<  YES  << endl;           return;         }       }     cout <<  NO  << endl;     return;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> arr[200010];   int a, b, ans = 1;   int main() {     pair<int, int> arr[200010];     int n;     cin >> n;     for (int i = 0; i < n; i++)       cin >> a >> b, arr[i].first = a + b, arr[i].second = a - b;     sort(arr, arr + n);     int tmp = arr[0].first;     for (int i = 1; i < n; i++)       if (arr[i].second >= tmp) ans++, tmp = arr[i].first;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[210000][3];   set<pair<int, int> > st;   int nxt[210000][2];   int x[210000];   vector<pair<int, int> > re;   map<long long, int> mp;   int pp[210000];   long long hsh(int x, int y, int z) {     if (y > z) swap(y, z);     if (x > y) swap(x, y);     if (y > z) swap(y, z);     return ((long long)x << 40) + ((long long)y << 20) + z;   }   void init() {     cin >> n;     mp.clear();     st.clear();     re.clear();     for (int i = 0; i < n + 2; i++) nxt[i][0] = nxt[i][1] = 0;     pair<int, int> tmp;     for (int i = 0; i < n - 2; i++) {       scanf( %d%d%d , &a[i][0], &a[i][1], &a[i][2]);       mp[hsh(a[i][0], a[i][1], a[i][2])] = i + 1;       for (int j = 0; j < 3; j++) {         tmp = {a[i][j], a[i][(j + 1) % 3]};         if (tmp.first > tmp.second) swap(tmp.first, tmp.second);         if (st.count(tmp)) {           st.erase(tmp);           re.push_back(tmp);         } else           st.insert(tmp);       }     }     for (auto p : st) {       int x = p.first;       int y = p.second;       if (nxt[x][0])         nxt[x][1] = y;       else         nxt[x][0] = y;       if (nxt[y][0])         nxt[y][1] = x;       else         nxt[y][0] = x;     }     int pos = 1, lst = nxt[pos][0];     int cnt = 1;     while (1) {       printf( %d  , pos);       pp[pos] = cnt;       x[cnt++] = pos;       if (nxt[pos][0] == lst)         lst = pos, pos = nxt[pos][1];       else         lst = pos, pos = nxt[pos][0];       if (pos == 1) break;     }     cout << endl;     for (int i = 1; i <= n; i++) {       nxt[x[i]][0] = x[i - 1];       nxt[x[i]][1] = x[i + 1];     }     nxt[x[1]][0] = x[n];     nxt[x[n]][1] = x[1];   }   bool cmp(pair<int, int> p1, pair<int, int> p2) {     int x1 = pp[p1.second] - pp[p1.first];     int x2 = pp[p2.second] - pp[p2.first];     if (x1 < 0) x1 += n;     if (x2 < 0) x2 += n;     if (x1 > n / 2) x1 = n - x1;     if (x2 > n / 2) x2 = n - x2;     return x1 < x2;   }   bool visit[210000];   void work() {     for (int i = 1; i <= n - 2; i++) visit[i] = 1;     sort(re.begin(), re.end(), cmp);     int t;     for (auto p : re) {       int x = p.first;       int y = p.second;       int t;       if (nxt[x][0] == nxt[y][1]) {         t = nxt[x][0];         nxt[x][0] = y;         nxt[y][1] = x;       } else {         t = nxt[x][1];         nxt[x][1] = y;         nxt[y][0] = x;       }       int xx = mp[hsh(x, y, t)];       cout << xx <<    ;       visit[xx] = 0;     }     for (int i = 1; i <= n - 2; i++)       if (visit[i]) cout << i;     cout << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       init();       work();     }     return ~~(0 ^ 0 ^ 0);   }


#include <bits/stdc++.h>   template <class T>   const T& min(const T& a, const T& b, const T& c) {     return min(a, min(b, c));   }   template <class T>   const T& max(const T& a, const T& b, const T& c) {     return max(a, max(b, c));   }   using namespace std;   int gcd(long long a, long long b) {     while (true) {       if (a < b) swap(a, b);       if (b == 0) return a;       a = a % b;     }   }   int main() {     int n, k;     cin >> n >> k;     if (k > n) {       cout <<  -1 ;       return 0;     }     if (k == 1) {       if (n == 1)         cout <<  a ;       else         cout <<  -1 ;       return 0;     }     if (k == 2) {       for (__typeof(n) i = 0; i < n; i++) {         cout << (((i % 2) == 0) ?  a  :  b );       }       return 0;     }     int written = 0;     for (__typeof(n - (k - 2)) i = 0; i < n - (k - 2); i++) {       cout << (((i % 2) == 0) ?  a  :  b );     }     for (__typeof(k - 2) i = 0; i < k - 2; i++) {       char c =  c  + i;       cout << c;     }   }   template <class T>   string toStr(T t) {     std::stringstream strstream;     string resStr;     strstream << t;     strstream >> resStr;     return resStr;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^  0 ), ch = getchar();     return f ? -x : x;   }   inline void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) write(x / 10);     putchar(x % 10 + 48);   }   inline void writebl(long long x) {     write(x);     putchar(   );   }   inline void writeln(long long x) {     write(x);     putchar(  n );   }   const long long N = 4e6 + 5;   long long ch[N][3], cnt = 1, val[N];   void ins(long long x) {     long long u = 1;     for (long long i = (30); i >= (0); --i) {       long long v = (x >> i) & 1;       if (!ch[u][v]) ch[u][v] = ++cnt;       u = ch[u][v];     }   }   long long n, a[N];   long long dfs(long long u) {     long long r1 = 0, r2 = 0;     if (!ch[u][0] && !ch[u][1]) return 1;     if (!ch[u][0]) return dfs(ch[u][1]);     if (!ch[u][1]) return dfs(ch[u][0]);     return max(dfs(ch[u][0]), dfs(ch[u][1])) + 1;   }   signed main() {     n = read();     for (long long i = (1); i <= (n); ++i) a[i] = read(), ins(a[i]);     writeln(n - dfs(1));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, digit;     int S = 0, max = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> digit;       S += digit;       if (digit > max) max = digit;     }     S = abs(S - max);     cout << abs(S - max) + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int X, Y, Z;   bool run(vector<long long int> &x, vector<long long int> &y,            vector<long long int> &z, long long int mid) {     long long int bound[4][2];     long long int t0 = x[0] + y[0] + z[0];     long long int t1 = -x[0] + y[0] + z[0];     long long int t2 = x[0] - y[0] + z[0];     long long int t3 = x[0] + y[0] - z[0];     bound[0][0] = t0 - mid;     bound[0][1] = t0 + mid;     bound[1][0] = t1 - mid;     bound[1][1] = t1 + mid;     bound[2][0] = t2 - mid;     bound[2][1] = t2 + mid;     bound[3][0] = t3 - mid;     bound[3][1] = t3 + mid;     for (int i = 1; i < x.size(); i++) {       long long int t0 = x[i] + y[i] + z[i];       long long int t1 = -x[i] + y[i] + z[i];       long long int t2 = x[i] - y[i] + z[i];       long long int t3 = x[i] + y[i] - z[i];       bound[0][0] = max(t0 - mid, bound[0][0]);       bound[0][1] = min(t0 + mid, bound[0][1]);       bound[1][0] = max(t1 - mid, bound[1][0]);       bound[1][1] = min(t1 + mid, bound[1][1]);       bound[2][0] = max(t2 - mid, bound[2][0]);       bound[2][1] = min(t2 + mid, bound[2][1]);       bound[3][0] = max(t3 - mid, bound[3][0]);       bound[3][1] = min(t3 + mid, bound[3][1]);     }     bool bad = false;     for (int j = 0; j < 4; j++) {       if (bound[j][0] > bound[j][1]) {         bad = true;       }     }     if (bad) return false;     for (int parity = 0; parity < 2; parity++) {       bool ans = false;       long long int b[4][2];       b[0][0] = (bound[0][0] - 3 * parity);       b[0][1] = (bound[0][1] - 3 * parity);       if (b[0][0] & 1) b[0][0]++;       if (b[0][1] & 1) b[0][1]--;       b[1][0] = (bound[1][0] - parity);       b[1][1] = (bound[1][1] - parity);       if (b[1][0] & 1) b[1][0]++;       if (b[1][1] & 1) b[1][1]--;       b[2][0] = (bound[2][0] - parity);       b[2][1] = (bound[2][1] - parity);       if ((b[2][0] & 1)) b[2][0]++;       if ((b[2][1] & 1)) b[2][1]--;       b[3][0] = (bound[3][0] - parity);       b[3][1] = (bound[3][1] - parity);       if (b[3][0] & 1) b[3][0]++;       if (b[3][1] & 1) b[3][1]--;       bool bad = false;       for (int j = 0; j < 4; j++) {         if (b[j][0] > b[j][1]) {           bad = true;         }       }       if (bad) continue;       long long int initVal = b[1][0] + b[2][0] + b[3][0];       long long int val[4] = {0, b[1][0], b[2][0], b[3][0]};       if (initVal > b[0][1]) {         continue;       } else if (initVal < b[0][0]) {         long long int needed = b[0][0] - initVal;         if ((b[1][1] - val[1]) >= needed) {           val[1] += needed;           needed = 0;         } else {           needed -= (b[1][1] - val[1]);           val[1] += (b[1][1] - val[1]);         }         if ((b[2][1] - val[2]) >= needed) {           val[2] += needed;           needed = 0;         } else {           needed -= (b[2][1] - val[2]);           val[2] += (b[2][1] - val[2]);         }         if ((b[3][1] - val[3]) >= needed) {           val[3] += needed;           needed = 0;         } else {           needed -= (b[3][1] - val[3]);           val[3] += (b[3][1] - val[3]);         }         if (needed <= 0) {           ans = true;         }       } else {         ans = true;       }       if (ans) {         long long int A = (val[1]) + parity;         long long int B = (val[2]) + parity;         long long int C = (val[3]) + parity;         assert(((B + C)) % 2 == 0 && ((A + C)) % 2 == 0 && ((B + A)) % 2 == 0);         X = (B + C) / 2;         Y = (A + C) / 2;         Z = (A + B) / 2;         return true;       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<long long int> x(n), y(n), z(n);       for (int i = 0; i < n; i++) {         cin >> x[i] >> y[i] >> z[i];       }       long long int L = 0, R = 3e18;       long long int ax, ay, az;       ax = ay = az = -1e18;       while (L <= R) {         long long int mid = (L + R) >> 1;         if (run(x, y, z, mid)) {           R = mid - 1;           ax = X, ay = Y, az = Z;         } else {           L = mid + 1;         }       }       long long int actAns = -9e18;       long long int xt = 185097714347307042;       long long int yt = 169326667661285082;       long long int zt = 370218498415077464;       cout << ax <<     << ay <<     << az << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int sol = 0;     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= i; ++j) {         for (int k = i - j; k <= j; ++k) {           if (((k ^ j) ^ i) == 0 && k + j > i) ++sol;         }       }     }     cout << sol <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   long long ans;   long long matriz[505][505];   int main() {     ans = 0;     cin >> n >> k;     long long aux = (n - k + 1) * n;     aux = n * n - aux + 1;     long long curr1 = 1;     long long curr2 = aux;     for (int i = 0; i < n; ++i) {       int j = 0;       for (; j < k - 1; ++j) {         matriz[i][j] = curr1;         curr1++;       }       ans += curr2;       matriz[i][j] = curr2;       curr2++;       j++;       for (; j < n; ++j) {         matriz[i][j] = curr2;         curr2++;       }     }     cout << ans << endl;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n - 1; ++j) {         cout << matriz[i][j] <<    ;       }       cout << matriz[i][n - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int IN() {     int x = 0, f = 0, ch;     for (; (ch = getchar()) <  0  || ch >  9 ;) f = (ch ==  - );     for (; ch >=  0  && ch <=  9 ; (ch = getchar())) x = x * 10 + ch -  0 ;     return f ? -x : x;   }   int M, edge[1005][1005], son[1005][1005], idx[1005][1005];   inline void Plu(int& a, int b) {     a += b;     if (a >= 1000000007) a -= 1000000007;   }   struct Tree {     int N, D, st[1005];     int F[1005][15], G[1 << 15];     struct Lin {       int v, next;     } E[1005 << 1];     void Link(int u, int v) {       E[++D] = (Lin){v, st[u]};       st[u] = D;       E[++D] = (Lin){u, st[v]};       st[v] = D;     }     void Init(int kind) {       N = IN();       for (int i = 2, lim = N; i <= lim; i++) {         int u = IN(), v = IN();         Link(u, v);         if (kind) {           edge[u][++*edge[u]] = v;           edge[v][++*edge[v]] = u;         }       }       if (kind) M = N;     }     void DFS(int u, int f) {       for (int i = st[u], v; i; i = E[i].next)         if ((v = E[i].v) != f) DFS(v, u);       for (int a = 1, lim = M; a <= lim; a++) {         int U = (1 << *son[a]) - 1;         for (int j = 0, lim = U; j <= lim; j++) G[j] = 0;         G[0] = 1;         for (int i = st[u], v; i; i = E[i].next)           if ((v = E[i].v) != f) {             for (int s = U, lim = 0; s >= lim; s--)               if (G[s]) {                 for (int j = 1, lim = *son[a]; j <= lim; j++) {                   int b = son[a][j], t = 1 << (idx[a][b] - 1);                   if (!(t & s)) Plu(G[s | t], 1ll * G[s] * F[v][b] % 1000000007);                 }               }           }         F[u][a] = G[U];       }     }     int Work(int Rt) {       for (int i = 1, lim = N; i <= lim; i++)         for (int j = 1, lim = M; j <= lim; j++) F[i][j] = 0;       DFS(1, 0);       int ret = 0;       for (int i = 1, lim = N; i <= lim; i++) Plu(ret, F[i][Rt]);       return ret;     }   } A, B;   int Pow(int a, int b) {     int ret = 1;     for (; b; b >>= 1, a = 1ll * a * a % 1000000007)       if (b & 1) ret = 1ll * ret * a % 1000000007;     return ret;   }   void DFS(int u, int f) {     for (int i = 1, lim = *edge[u]; i <= lim; i++) {       int v = edge[u][i];       if (v != f) {         son[u][++*son[u]] = v;         idx[u][v] = *son[u];         DFS(v, u);       }     }   }   int main(int argc, char* argv[]) {     A.Init(0);     B.Init(1);     int retA = 0, retB = 0;     for (int i = 1, lim = M; i <= lim; i++) {       for (int j = 0, lim = M; j <= lim; j++)         for (int k = 0, lim = M; k <= lim; k++) son[j][k] = idx[j][k] = 0;       DFS(i, 0);       Plu(retA, A.Work(i));       Plu(retB, B.Work(i));     }     cout << 1ll * retA * Pow(retB, 1000000007 - 2) % 1000000007 << endl;     cerr << retA <<     << retB << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:200000000 )   const double EPS = 1E-9;   const int INF = 1000000000;   const long long INF64 = (long long)1E18;   const double PI = 3.1415926535897932384626433832795;   const int NMAX = 310000;   set<pair<int, int> > q[3][3];   int a[NMAX], b[NMAX], n, w, c[NMAX][3];   long long s;   char st[NMAX];   void out() {     puts(st);     exit(0);   }   void add(int id) {     int cur = st[id] -  0 ;     s += c[id][cur];     for (int i = 0; i < (int)(3); i++) {       if (i == cur) continue;       q[cur][i].insert(make_pair(c[id][i] - c[id][cur], id));     }   }   void erase(int id) {     int cur = st[id] -  0 ;     s -= c[id][cur];     for (int i = 0; i < (int)(3); i++) {       if (i == cur) continue;       q[cur][i].erase(make_pair(c[id][i] - c[id][cur], id));     }   }   void perf(int st1, int st2) {     int id = q[st1][st2].begin()->second;     erase(id);     st[id] = st2 +  0 ;     add(id);   }   bool can2(int f1, int t1, int f2, int t2) {     if (q[f1][t1].empty()) return false;     int id1 = q[f1][t1].begin()->second;     int v1 = q[f1][t1].begin()->first;     erase(id1);     if (q[f2][t2].empty()) {       add(id1);       return false;     }     int id2 = q[f2][t2].begin()->second;     int v2 = q[f2][t2].begin()->first;     erase(id2);     if (v1 + v2 >= 0) {       add(id1);       add(id2);       return false;     }     st[id1] = t1 +  0 ;     add(id1);     st[id2] = t2 +  0 ;     add(id2);     return true;   }   bool can3(int f1, int t1, int f2, int t2, int f3, int t3) {     if (q[f1][t1].empty()) return false;     int id1 = q[f1][t1].begin()->second;     long long v1 = q[f1][t1].begin()->first;     erase(id1);     if (q[f2][t2].empty()) {       add(id1);       return false;     }     int id2 = q[f2][t2].begin()->second;     long long v2 = q[f2][t2].begin()->first;     erase(id2);     if (q[f3][t3].empty()) {       add(id1);       add(id2);       return false;     }     int id3 = q[f3][t3].begin()->second;     long long v3 = q[f3][t3].begin()->first;     erase(id3);     if (v1 + v2 + v3 >= 0) {       add(id1);       add(id2);       add(id3);       return false;     }     st[id1] = t1 +  0 ;     add(id1);     st[id2] = t2 +  0 ;     add(id2);     st[id3] = t3 +  0 ;     add(id3);     return true;   }   long long solve(long long ans = -1) {     for (int i = 0; i < (int)(3); i++)       for (int j = 0; j < (int)(3); j++) q[i][j].clear();     for (int i = 0; i < (int)(n); i++) st[i] =  0 ;     for (int i = 0; i < (int)(n); i++) add(i);     s = 0;     int left = w;     while (left) {       if (left >= 2 && q[0][2].size()) {         perf(0, 2);         left -= 2;       } else if (left >= 1 && q[0][1].size()) {         perf(0, 1);         left--;       }     }     if (left) throw;     long long res = s;     if (s == ans) out();     bool change = true;     while (change) {       change = false;       change |= can2(0, 1, 1, 0);       change |= can2(0, 1, 2, 1);       change |= can2(1, 2, 2, 1);       change |= can2(1, 2, 1, 0);       change |= can2(0, 2, 2, 0);       change |= can3(0, 2, 2, 1, 2, 1);       change |= can3(0, 2, 1, 0, 2, 1);       change |= can3(0, 2, 1, 0, 1, 0);       change |= can3(2, 0, 1, 2, 1, 2);       change |= can3(2, 0, 0, 1, 1, 2);       change |= can3(2, 0, 0, 1, 0, 1);       if (res == ans) out();       res = min(res, s);     }     return res;   }   int main() {     cin >> n >> w;     for (int i = 0; i < (int)(n); i++) {       scanf( %d%d , &a[i], &b[i]);       c[i][0] = 0;       c[i][1] = a[i];       c[i][2] = b[i];     }     long long ans = solve();     cout << ans << endl;     solve(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int sqr(long long int a) { return a * a; }   int main() {     ios::sync_with_stdio(false);     long long int a, n, m;     string str;     cin >> n;     long long int arr[n + 1], brr[n + 1], crr[n + 1];     long long int sum = 0, maxx = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n);     for (int i = 0; i < n / 2; i++) {       sum += sqr(arr[i] + arr[n - i - 1]);     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, m, d, ans;   struct node;   struct edge {     node *ed;     edge *next;   } E[N << 1], *newE = E;   struct node {     edge *son;     node *pa;     bool flag;     int dist[2], dis;     void dfs() {       dist[0] = dist[1] = dis = -1e8;       if (flag) dist[0] = 0;       for (edge *e = son; e; e = e->next)         if (e->ed != pa) {           e->ed->pa = this;           e->ed->dfs();           if (e->ed->dist[0] + 1 > dist[0]) {             dist[1] = dist[0];             dist[0] = e->ed->dist[0] + 1;           } else if (e->ed->dist[0] + 1 > dist[1]) {             dist[1] = e->ed->dist[0] + 1;           }         }     }     void dfs2() {       if (flag)         if (dis < 0) dis = 0;       if (max(dis, dist[0]) <= d) ans++;       for (edge *e = son; e; e = e->next)         if (e->ed != pa) {           e->ed->dis =               max(dis, e->ed->dist[0] == dist[0] - 1 ? dist[1] : dist[0]) + 1;           e->ed->dfs2();         }     }   } V[N];   int main() {     scanf( %d%d%d , &n, &m, &d);     for (int i = 0; i < m; i++) {       int p;       scanf( %d , &p);       V[p].flag = 1;     }     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       *newE = (edge){V + y, V[x].son}, V[x].son = newE++;       *newE = (edge){V + x, V[y].son}, V[y].son = newE++;     }     V[1].dfs();     V[1].dfs2();     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int n, a[20];   vector<long long> v;   int main() {     cin >> n;     int s = 1;     for (long long i = 1; i < 1e5; ++i) v.push_back(i);     while (v.size() > 8e4) v.erase(v.begin());     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     sort(a, a + n);     for (int i = 0; i < n; ++i) printf( %d  , a[i]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     string s;     cin >> s;     s =  0  + s;     vector<int> v(int(s.size()), 0);     for (int i = int(s.size()) - 1; i >= 0; i--) {       if (s[i] ==  1 ) {         v[i] = -1;         while (s[i] !=  0 ) i--;         v[i] = 1;       }     }     for (int i = 1; i < int(v.size()); i++) {       if (v[i] == -1 and v[i - 1] == 1) {         v[i - 1] = 0;         v[i] = 1;       } else if (v[i] == 1 and v[i - 1] == -1) {         v[i - 1] = 0;         v[i] = -1;       }     }     int count = 0;     for (int i = 0; i < int(v.size()); i++)       if (v[i] != 0) count++;     cout << count << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int n, m, k;   int t, x;   int c[200010];   int f1[200010];   int f2[200010];   vector<int> w, a, b;   vector<int> d;   vector<ll> ww, aa, bb, dd;   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> k;     for (int i = 0; i < n; i++) cin >> c[i];     cin >> t;     for (int i = 0; i < t; i++) {       cin >> x;       f1[x - 1] = 1;     }     cin >> t;     for (int i = 0; i < t; i++) {       cin >> x;       f2[x - 1] = 1;     }     for (int i = 0; i < n; i++) {       if (f1[i] && f2[i])         w.push_back(c[i]);       else if (f1[i])         a.push_back(c[i]);       else if (f2[i])         b.push_back(c[i]);       else         d.push_back(c[i]);     }     sort(w.begin(), w.end());     sort(a.begin(), a.end());     sort(b.begin(), b.end());     sort(d.begin(), d.end());     ww.push_back(0);     aa.push_back(0);     bb.push_back(0);     dd.push_back(0);     for (int i = 0; i < w.size(); i++) ww.push_back(ww.back() + w[i]);     for (int i = 0; i < a.size(); i++) aa.push_back(aa.back() + a[i]);     for (int i = 0; i < b.size(); i++) bb.push_back(bb.back() + b[i]);     for (int i = 0; i < d.size(); i++) dd.push_back(dd.back() + d[i]);     ll ans = 1e18 + 1;     for (int i = 0; i <= w.size(); i++) {       ll cost = ww[i];       int need = max(0, k - i);       if (need > a.size() || need > b.size() || i + need * 2 > m) continue;       cost += aa[need];       cost += bb[need];       int re = m - i - 2 * need;       if (a.size() - need + b.size() - need + d.size() < re) continue;       if (re > 0) {         int l = 0;         int r = 1e9 + 1;         while (l < r) {           int mid = (l + r) / 2;           int cnt = 0;           int h = upper_bound(a.begin(), a.end(), mid) - a.begin();           cnt += max(0, h - need);           h = upper_bound(b.begin(), b.end(), mid) - b.begin();           cnt += max(0, h - need);           h = upper_bound(d.begin(), d.end(), mid) - d.begin();           cnt += max(0, h);           if (cnt >= re)             r = mid;           else             l = mid + 1;         }         {           int mid = l;           int cnt = 0;           int h = upper_bound(a.begin(), a.end(), mid) - a.begin();           cnt += max(0, h - need);           if (h > need) cost += aa[h] - aa[need];           h = upper_bound(b.begin(), b.end(), mid) - b.begin();           cnt += max(0, h - need);           if (h > need) cost += bb[h] - bb[need];           h = upper_bound(d.begin(), d.end(), mid) - d.begin();           cnt += max(0, h);           cost += dd[h];           if (cnt > re) cost -= mid * (cnt - re);         }       }       ans = min(ans, cost);     }     if (ans > 1e17) ans = -1;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline char nc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline void read(int &x) {     char c = nc(), b = 1;     for (; !(c >=  0  && c <=  9 ); c = nc()) {       if (c ==  - ) b = -b;     }     for (x = 0; c >=  0  && c <=  9 ; x = x * 10 + c -  0 , c = nc())       ;     x *= b;   }   const int N = 500001;   const int sqN = 708;   int ans[N];   int fre[N];   int v[N];   int block[sqN];   int flag[sqN];   int answer = 0;   vector<int> bl;   struct query {     int l;     int r;     int idx;   } Q[N];   bool comp(query q1, query q2) {     if (q1.l / sqN != q2.l / sqN) {       return q1.l < q2.l;     }     if ((q1.l / sqN) & 1) {       return q1.r < q2.r;     }     return q1.r > q2.r;   }   inline void add(int idx) {     int val = v[idx];     fre[val]++;     if (fre[val] == 1) {       answer++;       block[val / sqN]++;       if (!flag[val / sqN]) {         flag[val / sqN] = 1;         bl.push_back(val / sqN);       }     }     if (fre[val] == 2) {       answer--;       block[val / sqN]--;     }   }   inline void rem(int idx) {     int val = v[idx];     fre[val]--;     if (fre[val] == 1) {       answer++;       block[val / sqN]++;       if (!flag[val / sqN]) {         flag[val / sqN] = 1;         bl.push_back(val / sqN);       }     }     if (fre[val] == 0) {       answer--;       block[val / sqN]--;     }   }   inline int solve() {     if (answer == 0) {       return 0;     }     while (!bl.empty() && block[bl.back()] < 1)       flag[bl.back()] = 0, bl.pop_back();     int i = bl.back();     for (int j = i * sqN; j < i * sqN + sqN; j++) {       if (fre[j] == 1) {         return j;       }     }   }   int main() {     int n;     read(n);     for (int i = 0; i < n; i++) {       read(v[i]);     }     int q, l, r;     read(q);     for (int i = 0; i < q; i++) {       read(l);       read(r);       l--;       r--;       Q[i].l = l;       Q[i].r = r;       Q[i].idx = i;     }     sort(Q, Q + q, comp);     l = 0, r = -1;     for (int i = 0; i < q; i++) {       int L = Q[i].l;       int R = Q[i].r;       while (l < L) {         rem(l);         l++;       }       while (l > L) {         l--;         add(l);       }       while (r < R) {         r++;         add(r);       }       while (r > R) {         rem(r);         r--;       }       ans[Q[i].idx] = solve();     }     for (int i = 0; i < q; i++) {       printf( %d n , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     multiset<char> ms;     for (char c : s) ms.insert(c);     string t, u;     for (int i = 0; i < (s.size()); i++) {       ms.erase(ms.find(s[i]));       t += s[i];       while (!t.empty() && ms.lower_bound(t.back()) == ms.begin()) {         u += t.back();         t.pop_back();       }     }     cout << u << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 25e4 + 1;   const long long inf = 1e18;   int n, m, k, h[maxn], par[maxn], tests, ted;   bool vis[maxn];   vector<int> e[maxn];   vector<int> ans[maxn];   void path_ans(int v) {     cout <<  PATH  <<   n ;     cout << tests <<   n ;     for (int test = 1; test <= tests; test++) {       cout << v <<    ;       v = par[v];     }     cout << endl;     return;   }   void dfs(int v) {     vis[v] = 1;     int ch = 0;     for (auto u : e[v]) {       if (vis[u] == 0) {         ch++;         par[u] = v;         h[u] = h[v] + 1;         if (h[u] >= tests) {           path_ans(u);           exit(0);         }         dfs(u);       }     }     if (ch == 0 && ted < k) {       int t1 = 0, t2 = 0;       for (auto u : e[v]) {         if (u != par[v]) {           if (h[u] > h[t1]) {             t2 = t1;             t1 = u;           } else if (h[u] > h[t2]) {             t2 = u;           }         }       }       if ((h[v] - h[t1] + 1) % 3 != 0) {         int x = v;         while (x != par[t1]) {           ans[ted].push_back(x);           x = par[x];         }       } else if ((h[v] - h[t2] + 1) % 3 != 0) {         int x = v;         while (x != par[t2]) {           ans[ted].push_back(x);           x = par[x];         }       } else {         ans[ted].push_back(v);         int x = t1;         while (x != par[t2]) {           ans[ted].push_back(x);           x = par[x];         }       }       ted++;     }     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     tests = (n + k - 1) / k;     for (int i = 1; i <= m; i++) {       int t1, t2;       cin >> t1 >> t2;       e[t1].push_back(t2);       e[t2].push_back(t1);     }     h[1] = 1;     dfs(1);     cout <<  CYCLES  <<   n ;     for (int i = 0; i < k; i++) {       cout << ans[i].size() <<   n ;       for (auto u : ans[i]) {         cout << u <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     vector<vector<int> > v(n, vector<int>(7, 0));     for (int i = 0; i < n; i++) {       cin >> s;       for (int j = 0; j < 7; j++) v[i][j] = s[j] -  0 ;     }     vector<int> cnt(7, 0);     for (int i = 0; i < 7; i++) {       for (int j = 0; j < n; j++) cnt[i] += v[j][i];     }     int m = 0;     for (int i = 0; i < 7; i++) {       if (cnt[i] > m) m = cnt[i];     }     cout << m;     return 0;   }


#include <bits/stdc++.h>   int n, C, orig[600010], top, stk[300010], all, Add[300010], One[300010],       cost[600010], ctop;   struct info {     int mx, ord, skdmx;   } c[3000010];   info merge(info a, info b) {     info c;     if (a.mx > b.mx)       c = a, c.skdmx = std::max(c.skdmx, b.mx);     else       c = b, c.skdmx = std::max(c.skdmx, a.mx);     return c;   }   void build(int root, int l, int r) {     c[root] = (info){-0x7f7f7f7f, 0, -0x7f7f7f7f};     if (l == r) return;     build(root << 1, l, (l + r) >> 1);     build(root << 1 | 1, ((l + r) >> 1) + 1, r);   }   void update(int root, int l, int r, int e, info x) {     if (l == r) {       c[root] = x;       return;     }     if ((l + r) >> 1 >= e)       update(root << 1, l, (l + r) >> 1, e, x);     else       update(root << 1 | 1, ((l + r) >> 1) + 1, r, e, x);     c[root] = merge(c[root << 1], c[root << 1 | 1]);   }   info query(int root, int l, int r, int el, int er) {     if (el > r || er < l) return (info){-0x7f7f7f7f, 0, -0x7f7f7f7f};     if (el <= l && er >= r) return c[root];     return merge(query(root << 1, l, (l + r) >> 1, el, er),                  query(root << 1 | 1, ((l + r) >> 1) + 1, r, el, er));   }   bool Del[300010];   long long f[600010], g[600010];   struct line {     int l, r, c;   } num[300001];   std::vector<int> add[600010], del[600010];   bool cmp(line a, line b) { return (a.r < b.r) || (a.r == b.r && a.l < b.l); }   int main() {     scanf( %d%d , &n, &C);     for (int i = 1; i <= n; i++)       scanf( %d%d%d , &num[i].l, &num[i].r, &num[i].c),           orig[++top] = num[i].l, orig[++top] = num[i].r, cost[++ctop] = num[i].c;     cost[++ctop] = 0;     std::sort(cost + 1, cost + ctop + 1);     ctop = std::unique(cost + 1, cost + ctop + 1) - cost - 1;     build(1, 1, ctop);     orig[++top] = 0;     orig[++top] = 0x7f7f7f7f;     std::sort(orig + 1, orig + top + 1);     top = std::unique(orig + 1, orig + top + 1) - orig - 1;     for (int i = 1; i <= n; i++)       num[i].l = std::lower_bound(orig + 1, orig + top + 1, num[i].l) - orig,       num[i].r = std::lower_bound(orig + 1, orig + top + 1, num[i].r) - orig - 1;     for (int i = 1; i <= n; i++)       add[num[i].l].push_back(i), del[num[i].r].push_back(i);     g[0] = -1e18;     for (int i = 1, cnt = 0, last1 = -1, last2 = -1, Sum = 0, empty = 0; i <= top;          i++) {       f[i] = std::max(f[i - 1], g[i - 1] + orig[i] - 1);       g[i] = -1e18;       for (int j = 0; j < add[i].size(); j++) stk[++all] = add[i][j], ++cnt;       if (!cnt)         g[i] = std::max(g[i], f[i] - orig[i] + 1), empty += orig[i + 1] - orig[i];       else if (cnt == 1) {         while (Del[stk[all]]) --all;         if (num[stk[all]].c <= C) {           Add[stk[all]] += orig[i + 1] - orig[i];           g[i] = std::max(g[i], 1ll * empty + 1ll * Add[stk[all]] +                                     1ll * One[stk[all]] - 1ll * orig[i + 1] + 1);           auto now = query(               1, 1, ctop, 1,               std::upper_bound(cost + 1, cost + ctop + 1, C - num[stk[all]].c) -                   cost - 1);           g[i] = std::max(g[i],                           1ll * empty + 1ll * Add[stk[all]] +                               1ll * (now.ord == stk[all] ? now.skdmx : now.mx) -                               1ll * orig[i + 1] + 1);           update(               1, 1, ctop,               std::lower_bound(cost + 1, cost + ctop + 1, num[stk[all]].c) - cost,               (info){Add[stk[all]], stk[all], -0x7f7f7f7f});         }       } else if (cnt == 2) {         while (Del[stk[all]]) --all;         int p1 = stk[all];         --all;         while (Del[stk[all]]) --all;         int p2 = stk[all];         stk[++all] = p1;         if (num[p1].c + num[p2].c <= C) {           if (last1 != p1 || last2 != p2) Sum = 0, last1 = p1, last2 = p2;           Sum += orig[i + 1] - orig[i];           g[i] = std::max(               g[i], 1ll * empty + Sum + Add[p1] + Add[p2] - orig[i + 1] + 1);           One[p2] = std::max(One[p2], Sum + Add[p1]);           One[p1] = std::max(One[p1], Sum + Add[p2]);         }       }       for (int j = 0; j < del[i].size(); j++) Del[del[i][j]] = 1, --cnt;     }     int m;     scanf( %d , &m);     for (int i = 1, k; i <= m; i++) {       scanf( %d , &k);       int l = 1, r = top - 1, mid, ans = -1;       while (l <= r) {         mid = (l + r) >> 1;         if (std::max(f[mid], g[mid] + 1ll * orig[mid + 1] - 1) >= 1ll * k)           ans = mid, r = mid - 1;         else           l = mid + 1;       }       printf( %lld n , std::max(1ll * orig[ans], 1ll * k - 1ll * g[ans]) + 1ll);     }   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return x * f;   }   inline long long readll() {     long long x = 0, f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return x * f;   }   const int N = 200005;   int tag[N << 2], f[N << 2][2][32], a[N];   int S, now;   inline void pushup(int rt) {     int ls = rt << 1, rs = rt << 1 | 1;     for (int i = 0; i < S; ++i)       f[rt][0][i] = f[ls][0][f[rs][0][i]], f[rt][1][i] = f[ls][1][f[rs][1][i]];   }   inline void Cover(int rt) { swap(f[rt][0], f[rt][1]), tag[rt] ^= 1; }   inline void pushdown(int rt) {     Cover(rt << 1);     Cover(rt << 1 | 1);     tag[rt] ^= 1;   }   void build(int l, int r, int rt) {     if (l == r) {       for (int i = 0; i < S; ++i)         f[rt][a[l]][i] = (i << 1) % S + 1,         f[rt][a[l] ^ 1][i] = (i << 1) % S + (i != S - 1);       return;     }     int mid = (l + r) >> 1;     build(l, mid, rt << 1);     build(mid + 1, r, rt << 1 | 1);     pushup(rt);   }   void update(int l, int r, int rt, int L, int R) {     if (L <= l && r <= R) {       Cover(rt);       return;     }     if (tag[rt]) pushdown(rt);     int mid = (l + r) >> 1;     if (L <= mid) update(l, mid, rt << 1, L, R);     if (R > mid) update(mid + 1, r, rt << 1 | 1, L, R);     pushup(rt);   }   void query(int l, int r, int rt, int L, int R) {     if (L <= l && r <= R) {       now = f[rt][0][now];       return;     }     if (tag[rt]) pushdown(rt);     int mid = (l + r) >> 1;     if (R > mid) query(mid + 1, r, rt << 1 | 1, L, R);     if (L <= mid) query(l, mid, rt << 1, L, R);   }   int main() {     int n = read(), m = read(), q = read();     S = (1 << m);     for (int i = 1; i <= n; ++i) a[i] = readll() % 2;     build(1, n, 1);     while (q--) {       int opt = read(), l = read(), r = read();       if (opt == 1) {         if (readll() % 2) update(1, n, 1, l, r);       } else {         now = S - 1;         query(1, n, 1, l, r);         putchar(now % 2 ?  1  :  2 );         putchar(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string luck[7] = { 1869 ,  1968 ,  1689 ,  6198 ,  1698 ,  1986 ,  1896 };     string str;     cin >> str;     int ans = 0;     bool vis[10];     int zero = 0;     memset(vis, 0, sizeof(vis));     for (int i = 0; i < str.length(); i++) {       if (str[i] ==  0 )         zero++;       else if (!vis[1] && str[i] ==  1 )         vis[1] = true;       else if (!vis[6] && str[i] ==  6 )         vis[6] = true;       else if (!vis[8] && str[i] ==  8 )         vis[8] = true;       else if (!vis[9] && str[i] ==  9 )         vis[9] = true;       else {         printf( %c , str[i]);         ans = ans * 10 + str[i] -  0 ;         ans %= 7;       }     }     ans = ans * 10000;     ans %= 7;     cout << luck[(7 - ans) % 7];     while (zero--) printf( 0 );     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using D = double;   using uint = unsigned int;   template <typename T>   using pair2 = pair<T, T>;   using pii = pair<int, int>;   using pli = pair<ll, int>;   using pll = pair<ll, ll>;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int maxn = 100005;   vector<int> pos[maxn];   int n, bulls, cows;   priority_queue<pair2<int>> freq;   int a[maxn], b[maxn];   vector<pair2<int>> all;   void solve() {     scanf( %d%d%d , &n, &bulls, &cows);     cows -= bulls;     for (int i = 0; i < n + 1; i++) pos[i].clear();     for (int i = 0; i < n; i++) {       scanf( %d , &b[i]);       b[i]--;       pos[b[i]].push_back(i);     }     for (int i = 0; i < n; i++) a[i] = -1;     int missing_color = -1;     while (!freq.empty()) freq.pop();     for (int i = 0; i < n + 1; i++) {       if (pos[i].empty()) missing_color = i;       freq.push({(int)pos[i].size(), i});     }     assert(missing_color != -1);     for (int i = 0; i < bulls; i++) {       int color = freq.top().second;       freq.pop();       a[pos[color].back()] = color;       pos[color].pop_back();       freq.push({(int)pos[color].size(), color});     }     all.clear();     int max_occ = freq.top().first;     while (!freq.empty()) {       int color = freq.top().second;       freq.pop();       for (auto t : pos[color]) all.push_back({color, t});     }     int max_cows = (int)all.size();     if (2 * max_occ > (int)all.size()) max_cows -= 2 * max_occ - (int)all.size();     if (cows > max_cows) {       printf( NO n );       return;     }     int shift = (int)all.size() / 2;     for (int i = 0; i < (int)all.size(); i++) {       int j = (i + shift) % (int)all.size();       int color = all[j].first;       if (all[i].first == all[j].first || cows == 0) color = missing_color;       if (color != missing_color) cows--;       a[all[i].second] = color;     }     printf( Yes n );     for (int i = 0; i < n; i++) printf( %d  , a[i] + 1);     printf(  n );   }   int main() {     int NT;     scanf( %d , &NT);     for (int T = 0; T < NT; T++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long binpow(long long a, long long b, long long m) {     a %= m;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   long long n, p;   const long long N = 1e6 + 2;   long long a[N];   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t, i, v1, ans, x, y;     cin >> t;     while (t--) {       cin >> n >> p;       for (i = 1; i <= n; ++i) cin >> a[i];       if (p == 1) {         if (n % 2)           cout << 1 <<   n ;         else           cout << 0 <<   n ;         continue;       }       sort(a + 1, a + 1 + n, greater<long long>());       stack<long long> s1, s2;       for (i = 1; i <= n; ++i) {         if (s1.empty()) {           s1.push(a[i]);           s2.push(1);           continue;         } else {           if (s1.size() == 1 && a[i] == s1.top()) {             s1.pop();             s2.pop();           } else if (s1.top() != a[i]) {             s1.push(a[i]);             s2.push(1);           } else {             x = s1.top();             y = s2.top() + 1;             if (y == p) {               y = 1;               ++x;             }             s1.pop();             s2.pop();             while (!s1.empty() && s1.top() == x) {               y = y + s2.top();               s1.pop();               s2.pop();               if (y == p) {                 y = 1;                 ++x;               }             }             s1.push(x);             s2.push(y);           }         }         if (s1.size() == 1) {           s1.pop();           s2.pop();         }       }       ans = 0;       while (s1.size() > 1) {         ans =             (ans + ((s2.top() * binpow(p, s1.top(), 1000000007)) % 1000000007)) %             1000000007;         s1.pop();         s2.pop();       }       if (s1.size() == 1)         ans = ((binpow(p, s1.top(), 1000000007)) - ans) % 1000000007;       ans = (ans + 1000000007) % 1000000007;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = (1LL << 60) - 1;   void solve() {     set<int> st;     int n, k, arr[1001];     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> arr[i];       st.insert(arr[i]);     }     if ((int)st.size() >= k) {       puts( YES );       int lst = -1;       for (int i = 0; i < n && k; i++) {         if (arr[i] != lst && st.find(arr[i]) != st.end()) {           cout << i + 1 <<    ;           lst = arr[i];           st.erase(arr[i]);           k--;         }       }     } else       puts( NO );   }   int main() { solve(); }


#include <bits/stdc++.h>   #include <stack>   using namespace std;   #define ll long long   #define rep(i,a,b) for(ll i=a; i<b; i++)   #define repi(i,a,b) for(ll i=b-1; i>=a; i--)   #define pb push_back   #define mod 1000000007   void fastscan(ll &num){       bool n=false;       register ll c;       num=0;       c=getchar();       if(c== - ){           n=true;           c=getchar();       }       for(;(c>47 && c<58); c=getchar()){           num=num*10+c-48;       }       if(n){           num*=-1;       }          }   ll max(ll a, ll b) {if(a>b){return a;}else {return b;}}   ll min(ll a, ll b) {if(a>b){return b;}else {return a;}}      ll gcd(ll a, ll b){       if(a>b){           if(b==0){               return a;           }else {               return gcd(a%b,b);           }       }else {           if(a==0){               return b;           }else {               return gcd(b%a,a);           }       }   }      bool isprime(ll n){       if(n<=1){           return false;       }else if(n<=3){           return true;       }       if(n%2==0 || n%3==0){           return false;       }       for(int i=5; i*i<=n; i=i+6){           if(n%i==0 || n%(i+2)==0){               return false;           }       }       return true;   }   int main() {       ios_base::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);       ll t,n;       cin>>t;       rep(i,0,t){           cin>>n;           ll x=2050,y=0;           while(n>=x){               x*=10;           }           x/=10;           while(n>=2050){               if(x<=n){                   n-=x;                   y++;               }else {                   x/=10;               }           }           if(n==0){               cout<<y<<endl;           }else {               cout<<-1<<endl;           }       }    // your code goes here    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n;     cin >> n;     long sum = 2;     int k = 1;     int b = 0;     for (int i = 1;; i = i + k) {       if (i == n) {         break;       }       b++;       if (b == 2) {         b = b % 2;         k++;       }       if (i > n) {         break;       }       sum++;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, z, a, b, c;     cin >> x >> y >> z;     cin >> a >> b >> c;     if (a < x) {       printf( No );       return 0;     }     if (a + b < x + y) {       printf( No );       return 0;     }     if (a + b + c < x + y + z) {       printf( No );       return 0;     }     printf( Yes );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int d, k, a, b, t, x = 0, ans = 0, y;     cin >> d >> k >> a >> b >> t;     ans = a * min(d, k);     x = min(d, k);     if (x < d) {       y = (d - x) / k;       if (t * y + a * y * k < b * y * k)         ans += (t * y + a * y * k);       else         ans += (b * y * k);       long long int left = d - x - y * k;       if (t + left * a < left * b)         ans += (t + left * a);       else         ans += (left * b);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   long long BIT[6][N];   int n, arr[N];   inline long long getPrefix(int z, int i) {     i = n - i - 1;     ++i;     long long ret = 0;     while (i) ret += BIT[z][i], i -= i & -i;     return ret;   }   inline void add(int z, int i, long long v) {     i = n - i - 1;     ++i;     while (i < N) BIT[z][i] += v, i += i & -i;   }   long long f(long long x) { return x * (x + 1) / 2; }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &arr[i]), arr[i]--;     double out = 0;     double fn = f(n);     for (int j = 0; j < n; j++) {       double i = getPrefix(0, arr[j]);       double i1 = getPrefix(1, arr[j]);       double fi = getPrefix(2, arr[j]);       double fni = getPrefix(3, arr[j]);       double ci = getPrefix(4, arr[j]);       double temp = ci * f(n - j - 1) / fn;       temp += (fni - ci * f(n - j - 1)) / fn;       temp += (i1 * j - fi * 2) / fn;       temp += fi / fn;       out += temp;       add(0, arr[j], j);       add(1, arr[j], j + 1);       add(2, arr[j], f(j));       add(3, arr[j], f(n - j - 1));       add(4, arr[j], 1);     }     for (long long len = 1; len <= n; len++)       out += len * (len - 1) / 4.0 * (n - len + 1) / fn;     printf( %.9lf n , out);   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     register long long x = 0;     char zf = 1;     char ch;     while (ch !=  -  && !isdigit(ch)) ch = getchar();     if (ch ==  - ) zf = -1, ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return x * zf;   }   void write(long long y) {     if (y < 0) putchar( - ), y = -y;     if (y > 9) write(y / 10);     putchar(y % 10 +  0 );   }   inline void writeln(const long long y) {     write(y);     putchar(  n );   }   inline int min(const int x, const int y) { return x < y ? x : y; }   inline int max(const int x, const int y) { return x > y ? x : y; }   int i, j, k, m, n, x, y, z, cnt, la[1000010], fa[1000010], size[1000010], top,       g = 0;   int ask(int x) {     while (fa[x] != x) x = fa[x];     return x;   }   void merge(int x, int y) {     if (x == y) return;     if (size[x] > size[y]) swap(x, y);     la[++top] = x;     fa[x] = y;     size[y] += size[x];   }   void undo() {     int La = la[top];     size[fa[La]] -= size[La];     fa[La] = La;     top--;   }   struct ed {     int x, y, z;     inline bool operator<(const ed s) const { return z < s.z; }   } q[1000010];   struct query {     int id, x, y, val;     inline bool operator<(const query s) const {       if (val == s.val) return id < s.id;       return val < s.val;     }   } A[1000010];   int ans[1000010];   int main() {     n = read();     m = read();     for (register int i = 1; i <= n; i++) size[i] = 1, fa[i] = i;     for (register int i = 1; i <= m; i++) {       x = read();       y = read();       z = read();       q[i] = {x, y, z};     }     k = read();     for (register int e = 1; e <= k; e++) {       z = read();       ans[e] = 1;       for (register int i = 1; i <= z; i++) {         x = read();         A[++cnt] = {e, q[x].x, q[x].y, q[x].z};       }     }     sort(q + 1, q + m + 1);     sort(A + 1, A + cnt + 1);     int qd = 1;     for (register int i = 1; i <= cnt;) {       while (q[qd].z < A[i].val) merge(ask(q[qd].x), ask(q[qd].y)), qd++;       top = 0;       do {         if (ask(A[i].x) == ask(A[i].y)) ans[A[i].id] = 0;         merge(ask(A[i].x), ask(A[i].y));         i++;       } while (A[i].val == A[i - 1].val && A[i].id == A[i - 1].id);       while (top) undo();     }     for (register int i = 1; i <= k; i++) puts(ans[i] ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500055;   int n, m, r, k;   set<pair<int, int> > rec;   const int dir[2][4] = {{0, 0, 1, -1}, {1, -1, 0, 0}};   struct node {     int x, y, val;     node() {}     node(int _x, int _y, int _val) : x(_x), y(_y), val(_val){};     bool operator<(const node &b) const { return val < b.val; }   };   int calc(int x, int y) {     int x_lb = max(0, x - r + 1), x_ub = min(n - 1, x + r - 1);     int y_lb = max(0, y - r + 1), y_ub = min(m - 1, y + r - 1);     int res = (x_ub - x_lb + 2 - r) * (y_ub - y_lb + 2 - r);     if (res <= 0) {       cout <<  x  <<  =  << x <<   ,  , cout <<  y  <<  =  << y <<   ,  ,           cout <<  y_lb  <<  =  << y_lb <<   ,  ,           cout <<  r  <<  =  << r <<   ,  , cout <<  y_ub  <<  =  << y_ub << endl;     }     return res;   }   void solve() {     priority_queue<node> q;     int tmp = calc(n / 2, m / 2);     q.push(node(n / 2, m / 2, tmp));     rec.insert(make_pair(n / 2, m / 2));     double res = 0;     while (!q.empty() && k--) {       node cur = q.top();       q.pop();       res += cur.val;       for (int i = 0; i < (4); ++i) {         int tx = dir[0][i] + cur.x, ty = dir[1][i] + cur.y;         if (tx > -1 && ty > -1 && tx < n && ty < m &&             !rec.count(pair<int, int>(tx, ty))) {           rec.insert(pair<int, int>(tx, ty));           q.push(node(tx, ty, calc(tx, ty)));         }       }     }     double ans = res / (n - r + 1) / (m - r + 1);     printf( %.10lf n , ans);   }   int main() {     cin >> n >> m >> r >> k;     solve();   }


#include<bits/stdc++.h>   #define int long long int   #define pb push_back   #define all(x)  (x).begin(), (x).end()   using namespace std;       int solve(int a,int b)   {     if(a<=0)       return 0;     return min(1+solve(a/b,b), 2+solve(a/(b+1),b+1));   }    signed main()   {     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);     int t;     cin>>t;     while(t--)     {       int a,b;       cin>>a>>b;       int ans=1e9;       for(int i=0;i<100;i++)       {         int x=b+i;         int temp= i;         int xa=a;         int xb=x;         for(int j=0;j<100;j++)         {           if(xa<=0)             break;           xa/=xb;           temp++;         }          ans=min(ans,temp);       }       cout<<ans<<endl;     }   }


#include <bits/stdc++.h>   using namespace std;   inline int nxt() {     int x;     scanf( %d , &x);     return x;   }   using ld = long double;   int main() {     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     int n = nxt();     long long k;     scanf( %lld , &k);     vector<int> a(n);     for (int i = 0; i < n; ++i) {       a[i] = nxt();     }     ld r = 0;     ld l = 0;     for (int i = 0; i < n; ++i) {       r = max<ld>(r, a[i]);       l = min<ld>(l, a[i] - 3ll * a[i] * a[i]);     }     for (int it = 0; it < 300; ++it) {       ld m = (l + r) / 2;       ld sum = 0;       for (int i = 0; i < n; ++i) {         if (m > a[i]) {           continue;         }         if (m < a[i] - 3ll * a[i] * a[i]) {           sum += a[i];           continue;         }         sum += sqrtl((a[i] - m) / 3);       }       if (sum >= k) {         l = m;       } else {         r = m;       }     }     vector<int> b(n);     vector<pair<long long, int>> can;     ld m = (l + r) / 2;     long long ans = 0;     for (int i = 0; i < n; ++i) {       if (m > a[i]) {         continue;       }       if (m < a[i] - 3ll * a[i] * a[i]) {         k -= a[i];         b[i] = a[i];         ans += 1ll * b[i] * (a[i] - 1ll * b[i] * b[i]);         continue;       }       b[i] = sqrtl((a[i] - m) / 3);       k -= b[i];       ans += 1ll * b[i] * (a[i] - 1ll * b[i] * b[i]);       if (b[i] < a[i]) {         can.push_back({1ll * (b[i] + 1) * (a[i] - 1ll * (b[i] + 1) * (b[i] + 1)) -                            1ll * b[i] * (a[i] - 1ll * b[i] * b[i]),                        i});       }     }     sort((can).begin(), (can).end());     while (k) {       ans += can.back().first;       b[can.back().second] += 1;       can.pop_back();       --k;     }     cerr << ans <<   n ;     for (int x : b) {       cout << x <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     int n;     cin >> n;     vector<string> a(2 * n - 2);     map<string, vector<int>> m;     for (int i = 0; i < 2 * n - 2; ++i) {       cin >> a[i];       m[a[i]].emplace_back(i);     }     int x = -1, y = -1;     for (int i = 0; i < 2 * n - 2; ++i) {       auto const& s = a[i];       if ((int)s.size() == n - 1) {         if (x == -1)           x = i;         else           y = i;       }     }     string ans(2 * n - 2,  S );     string u = a[x];     string v = a[y];     map<string, int> cc1, cc2;     for (int i = 0; i + 1 < n; ++i) {       ++cc1[u.substr(0, i + 1)];       ++cc1[v.substr(i, n - 1 - i)];       ++cc2[v.substr(0, i + 1)];       ++cc2[u.substr(i, n - 1 - i)];     }     bool can1 = true;     bool can2 = true;     for (auto const& [x, f] : m) {       can1 &= (cc1[x] == int(f.size()));       can2 &= (cc2[x] == int(f.size()));     }     if (not can1) {       swap(cc1, cc2);       swap(u, v);     }     for (int i = 0; i + 1 < n; ++i) {       auto p1 = u.substr(0, i + 1);       auto s1 = v.substr(i, n - 1 - i);       int idx1 = m[p1].back();       m[p1].pop_back();       int idx2 = m[s1].back();       m[s1].pop_back();       ans[idx1] =  P ;       ans[idx2] =  S ;     }     cout << ans;   }


#include <bits/stdc++.h>   using std::make_pair;   using std::pair;   const int N = 3e5 + 1e3;   int n, k;   int tot, rt;   struct Pair {     int l, r, pos, v1;     bool operator<(const Pair m) const { return v1 > m.v1; }   } p1[N], p2[N];   int sum[N << 4], ls[N << 4], rs[N << 4], mn[N << 4];   int r[N], a[N], mx[N], ans[N];   int ask(int cur, int l, int r, int L, int R) {     if (!cur) return 0;     if (L <= l && r <= R) {       return sum[cur];     }     int mid = l + r >> 1;     int ans = 0;     if (L <= mid) ans += ask(ls[cur], l, mid, L, R);     if (R > mid) ans += ask(rs[cur], mid + 1, r, L, R);     return ans;   }   int get(int cur, int l, int r, int L, int R) {     if (!cur) return 0;     if (L <= l && r <= R) {       return mn[cur];     }     int mid = l + r >> 1;     int ans = 0;     if (L <= mid) ans = std::max(ans, get(ls[cur], l, mid, L, R));     if (R > mid) ans = std::max(ans, get(rs[cur], mid + 1, r, L, R));     return ans;   }   void add(int &cur, int l, int r, int x, int v) {     if (!cur) cur = ++tot;     if (l == r) {       sum[cur] += v;       mn[cur] = std::max(mn[cur], v);       return;     }     int mid = l + r >> 1;     if (x <= mid)       add(ls[cur], l, mid, x, v);     else       add(rs[cur], mid + 1, r, x, v);     sum[cur] = sum[ls[cur]] + sum[rs[cur]];     mn[cur] = std::max(mn[ls[cur]], mn[rs[cur]]);   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; ++i) scanf( %d , &r[i]);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= n; ++i) {       p1[i].v1 = r[i], p1[i].l = a[i], p1[i].pos = i;     }     std::sort(p1 + 1, p1 + 1 + n);     std::reverse(p1 + 1, p1 + 1 + n);     for (int i = 1; i <= n; ++i) {       add(rt, 1, 1e9 + 2, p1[i].l, 1);       mx[p1[i].pos] = ask(rt, 1, 1e9 + 2, std::max(1, p1[i].l - k),                           std::min(p1[i].l + k, (int(1e9)) + 2));     }     int q;     scanf( %d , &q);     memset(ls, 0, sizeof(ls));     memset(rs, 0, sizeof(rs));     memset(sum, 0, sizeof(sum));     rt = tot = 0;     memset(mn, 0, sizeof(mn));     for (int i = 1; i <= q; ++i) {       int l, r;       scanf( %d %d , &l, &r);       p2[i].l = l, p2[i].r = r, p2[i].pos = i,       p2[i].v1 = std::max(::r[l], ::r[r]);     }     std::sort(p2 + 1, p2 + 1 + q);     std::sort(p1 + 1, p1 + 1 + n);     int now = 1;     for (int i = 1; i <= q; ++i) {       while (p2[i].v1 <= p1[now].v1 && now <= n) {         add(rt, 1, 1e9 + 1, a[p1[now].pos], mx[p1[now].pos]);         now++;       }       if (abs(a[p2[i].l] - a[p2[i].r]) > 2 * k) {         ans[p2[i].pos] = 0;         continue;       }       ans[p2[i].pos] = get(           rt, 1, 1e9 + 1, std::max(1, std::max(a[p2[i].l] - k, a[p2[i].r] - k)),           std::min((int(1e9)), std::min(a[p2[i].l] + k, a[p2[i].r] + k)));     }     for (int i = 1; i <= q; ++i) printf( %d  , ans[i] <= 0 ? -1 : ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long i, j, t, n, m, l, r, k, z, y, x;   long long a, b, ans;   int main() {     scanf( %I64d%I64d%I64d , &t, &a, &b);     if (t == 1) {       if (a == 1) {         if (a == b)           printf( inf n );         else           printf( 0 n );         return 0;       } else if (b >= a) {         while (b % a == 0) b /= a;         if (b == 1) {           printf( 1 n );           return 0;         }       }     }     ans = (a == b) ? 1 : 0;     x = z = 0;     y = 1;     if (t <= a) {       while (b) {         x = b % a;         b /= a;         z += y * x;         y *= t;       }     }     if (z == a) ans++;     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long k, b, n, t, z = 1, cnt = 0;     cin >> k >> b >> n >> t;     while (z <= t) {       cnt++;       z = k * z + b;     }     cout << n - min(n, cnt - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int n, m, k, t;   long long cnm[N];   long long h[N], w[N], e[N], ne[N], idx;   vector<long long> g[N];   int vis[N];   long long ans;   vector<int> res;   void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }   void dfs(int u, int s) {     if (s == 1) {       if (cnm[u] >= 0) {         ans += cnm[u];         res.push_back(u);         vis[u] = true;         for (int i = h[u]; i != -1; i = ne[i]) {           int j = e[i];           cnm[j] += cnm[u];           dfs(j, 2);         }       } else {         vis[u] = true;         for (int i = h[u]; i != -1; i = ne[i]) {           int j = e[i];           dfs(j, 2);         }         ans += cnm[u];         res.push_back(u);       }     } else {       bool ok = true;       for (auto it : g[u]) {         if (!vis[it]) {           ok = false;           dfs(it, 2);         }       }       if (ok) {         dfs(u, 1);       }     }   }   void solve() {     memset(h, -1, sizeof(h));     cin >> n;     for (int i = 1; i <= n; i++) cin >> cnm[i];     for (int i = 1; i <= n; i++) {       int a;       cin >> a;       if (a == -1) continue;       add(i, a);       g[a].push_back(i);     }     for (int i = 1; i <= n; i++) {       if (!vis[i] && g[i].size() == 0) {         dfs(i, 2);       }     }     cout << ans << endl;     for (auto it : res) cout << it <<    ;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, q, l[N], r[N], level[N], p[N][20], res[N];   int import[N], numCity, numVirus;   vector<int> adj[N];   vector<pair<int, int> > newAdj[N];   struct T {     int city, speed;   };   T virus[N];   pair<pair<int, int>, int> top;   struct Less {     bool operator()(const pair<pair<int, int>, int>& x,                     const pair<pair<int, int>, int>& y) {       int a = x.first.first / virus[x.first.second].speed,           b = y.first.first / virus[y.first.second].speed;       if (a != b) return a > b;       return x.first.second > y.first.second;     }   };   priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int> >,                  Less>       pq;   int T;   void dfs(int u) {     for (int i = 1; i <= 18; i++) p[u][i] = p[p[u][i - 1]][i - 1];     l[u] = ++T;     for (int v : adj[u]) {       if (v == p[u][0]) continue;       level[v] = level[u] + 1;       p[v][0] = u;       dfs(v);     }     r[u] = T;   }   int lca(int u, int v) {     if (level[u] < level[v]) swap(u, v);     for (int i = 18; i >= 0; --i)       if (level[u] - (1 << i) >= level[v]) u = p[u][i];     if (u == v) return u;     for (int i = 18; i >= 0; --i)       if (p[u][i] != p[v][i]) u = p[u][i], v = p[v][i];     return p[u][0];   }   int dist(int x, int y) { return level[x] + level[y] - 2 * level[lca(x, y)]; }   vector<pair<int, int> > all;   void compress_tree() {     all.clear();     for (int i = 1; i <= numVirus; i++)       all.push_back(make_pair(l[virus[i].city], virus[i].city));     for (int i = 1; i <= numCity; i++)       all.push_back(make_pair(l[import[i]], import[i]));     sort(all.begin(), all.end());     all.erase(unique(all.begin(), all.end()), all.end());     int sz = all.size();     for (int i = 1; i < sz; i++) {       int p = lca(all[i].second, all[i - 1].second);       all.push_back(make_pair(l[p], p));     }     sort(all.begin(), all.end());     all.erase(unique(all.begin(), all.end()), all.end());     vector<int> st;     for (auto& u : all) {       newAdj[u.second].clear();       while (st.size() && r[st.back()] < u.first) st.pop_back();       if (st.size()) {         int dist = level[u.second] - level[st.back()];         newAdj[st.back()].push_back(make_pair(u.second, dist));         newAdj[u.second].push_back(make_pair(st.back(), dist));       }       st.push_back(u.second);     }   }   void solve() {     for (auto& x : all) res[x.second] = -1;     for (int i = 1; i <= numVirus; i++)       pq.push({{virus[i].speed - 1, i}, virus[i].city});     while (pq.size()) {       top = pq.top();       pq.pop();       if (res[top.second] != -1) continue;       res[top.second] = top.first.second;       for (auto u : newAdj[top.second]) {         if (res[u.first] != -1) continue;         pq.push({{top.first.first + u.second, top.first.second}, u.first});       }     }     for (int i = 1; i <= numCity; i++) cout << res[import[i]] <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1);     cin >> q;     while (q--) {       cin >> numVirus >> numCity;       for (int i = 1; i <= numVirus; i++) cin >> virus[i].city >> virus[i].speed;       for (int i = 1; i <= numCity; i++) cin >> import[i];       compress_tree();       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, c;     cin >> a >> b >> c;     long long int temp1, temp2, temp3;     temp1 = a / c;     temp2 = b / c;     if (a % c != 0) temp1++;     if (b % c != 0) temp2++;     cout << temp1 * temp2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 45;   int n, m;   char G[maxn][maxn];   int sg[maxn][maxn][maxn][maxn][2];   int SG(int x0, int x1, int y0, int y1, int d) {     int &g = sg[x0][x1][y0][y1][d];     if (g != -1) return g;     char s[maxn * 2 + 1];     memset(s, 0, sizeof(s));     for (int y = 0; y < n; ++y) {       for (int x = 0; x < m; ++x) {         if (((x + y) & 1) == d) {           int x_ = y + x, y_ = y - x + m;           if (x0 <= x_ && x_ < x1 && y0 <= y_ && y_ < y1) {             int tmp;             if (G[y][x] ==  L )               tmp = SG(x0, x_, y0, y1, d) ^ SG(x_ + 1, x1, y0, y1, d);             if (G[y][x] ==  R )               tmp = SG(x0, x1, y0, y_, d) ^ SG(x0, x1, y_ + 1, y1, d);             if (G[y][x] ==  X ) {               tmp = SG(x0, x_, y0, y_, d) ^ SG(x0, x_, y_ + 1, y1, d) ^                     SG(x_ + 1, x1, y0, y_, d) ^ SG(x_ + 1, x1, y_ + 1, y1, d);             }             s[tmp] = 1;           }         }       }     }     while (s[++g])       ;     return g;   }   int main() {     while (cin >> n >> m) {       for (int i = 0; i < n; ++i) cin >> G[i];       memset(sg, -1, sizeof sg);       if ((SG(0, n + m, 0, n + m, 0) ^ SG(0, n + m, 0, n + m, 1)) > 0)         printf( WIN n );       else         printf( LOSE n );     }     return 0;   }


#include<bits/stdc++.h>      typedef   long long  int ll;   typedef  long double ld;   typedef std::vector<ll> vi;   typedef std::vector<std::vector<ll> > vv;   typedef std::vector<std::pair<ll,ll> > pii;      #define mod 1000000007   #define IO ios_base::sync_with_stdio(false);cin.tie(NULL);   #define fo(i,a,b) for(i=a;i<b;i++)   #define forr(i,a,b) for(i=a;i>=b;i--)   #define mp make_pair   #define pb(x) push_back(x)   #define fi first   #define se second   #define print(vec,a,b) for(ll i=a;i<b;i++) cout<<vec[i]<<   ;cout<<endl;   #define all(a) a.begin(),a.end()   #define input(vec,a,b) for(ll i = a;i<b;i++) cin>>vec[i];   #define ms(a,val) memset(a,val,sizeof(a))   using namespace std;      const int N = 2e5+ 5;            ll expo_pow(ll x, ll y) {    if (y == 0)     return 1;    y = y % (mod - 1);    x %= mod;    if (y == 0)     y = mod - 1;    ll res = 1;    while (y) {     if (y & 1)      res = (res * x) % mod;     x = (x * x) % mod;     y >>= 1;    }    return res;   }       ll modInverse(ll a, ll m = mod) {    return expo_pow(a, m - 2);   }             void solve(){               ll i,j,n,m;                              ll a,b,d;               cin>>a>>b>>d;                              if(a > b)               {       if((1 + d)*b >= a)        cout<< YES <<endl;       else        cout<< NO <<endl;       }       else if(b > a)                 {       if((1 + d)*a >= b)        cout<< YES <<endl;       else        cout<< NO <<endl;       }       else        cout<< YES <<endl;                                                                                }            int main()   {        IO;         ll t=1,i;         cin>>t;                 while(t--)         {                solve();         }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, l, q, num, ll;     cin >> n >> m >> l;     vector<long long> len(n);     vector<bool> is_long(n, false);     long long prev_long = 0;     long long count = 0;     bool was_long = false;     for (long long i = 0; i < n; ++i) {       cin >> len[i];       if (len[i] > l) {         if (!was_long) {           ++count;         }         was_long = true;         is_long[i] = true;       } else {         was_long = false;       }     }     int c_merged;     for (long long i = 0; i < m; ++i) {       cin >> q;       if (q == 1) {         cin >> num >> ll;         len[num - 1] += ll;         if (len[num - 1] > l) {           c_merged = 0;           if (is_long[num - 1] == false) {             if (num - 2 >= 0 && is_long[num - 2] == true) {               c_merged++;             }             if (num < n && is_long[num] == true) {               c_merged++;             }             if (c_merged == 2) {               --count;             }             if (c_merged == 0) {               ++count;             }           }           is_long[num - 1] = true;         }       } else {         cout << count << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 16;   const int inf = 1e9 + 7;   int f[N][N][N][2][2][2];   struct node {     int x;     int y;     int z;     int i1;     int j1;     int k1;     int p1;     int fi1, fi2;   } pre[N][N][N][2][2][2];   int a[N], b[N], c[N];   char s[N * 5];   inline void Upd(int &x, int y, node &v, int t1, int t2, int t3, int ii, int jj,                   int kk, int pp, int p1, int p2) {     if (x == -1) x = inf;     if (x <= y) return;     x = y;     v.x = t1;     v.y = t2;     v.z = t3;     v.i1 = ii;     v.j1 = jj;     v.k1 = kk;     v.p1 = pp;     v.fi1 = p1;     v.fi2 = p2;   }   int main() {     scanf( %s , s + 1);     int na, nb, nc;     na = nb = nc = 0;     memset(a, -1, sizeof(a));     memset(b, -1, sizeof(b));     memset(c, -1, sizeof(c));     int len = strlen(s + 1);     int ii = 1;     while (s[ii] !=  + ) {       a[++na] = s[ii] -  0 ;       ii++;     }     ii++;     while (s[ii] !=  = ) {       b[++nb] = s[ii] -  0 ;       ii++;     }     ii++;     while (ii <= len) {       c[++nc] = s[ii] -  0 ;       ii++;     }     reverse(a + 1, a + 1 + na);     reverse(b + 1, b + 1 + nb);     reverse(c + 1, c + 1 + nc);     memset(f, -1, sizeof(f));     f[0][0][0][0][0][0] = 0;     for (int i = (0); i <= (na); i++)       for (int j = (0); j <= (nb); j++)         for (int k = (0); k <= (nc); k++)           for (int up = (1); up >= (0); up--)             for (int p1 = (0); p1 <= (1); p1++)               for (int p2 = (0); p2 <= (1); p2++)                 if (f[i][j][k][up][p1][p2] != -1) {                   for (int t1 = (0); t1 <= (9); t1++)                     for (int t2 = (0); t2 <= (9); t2++) {                       int t3 = t1 + t2 + up;                       for (int q1 = (p1); q1 <= (1); q1++)                         for (int q2 = (p2); q2 <= (1); q2++) {                           int nxt = f[i][j][k][up][p1][p2] + 3;                           if (p1 && (i < na || t1)) continue;                           if (p2 && (i < na || t2)) continue;                           if ((i == na && !t1) && q1) nxt--;                           if ((j == nb && !t2) && q2) nxt--;                           Upd(f[i + (t1 == a[i + 1])][j + (t2 == b[j + 1])]                                [k + ((t3 % 10) == c[k + 1])][t3 / 10][q1][q2],                               nxt,                               pre[i + (t1 == a[i + 1])][j + (t2 == b[j + 1])]                                  [k + ((t3 % 10) == c[k + 1])][t3 / 10][q1][q2],                               t1, t2, t3 % 10, i, j, k, up, p1, p2);                         }                     }                 }     int i = na, j = nb, k = nc, p = 0, t1 = 1, t2 = 1;     long long ra = 0, rb = 0, rc = 0;     while (i || j || k) {       ra = 10ll * ra + pre[i][j][k][p][t1][t2].x;       rb = 10ll * rb + pre[i][j][k][p][t1][t2].y;       rc = 10ll * rc + pre[i][j][k][p][t1][t2].z;       int ti = i, tj = j, tk = k, tp = p, n1 = t1, n2 = t2;       i = pre[ti][tj][tk][tp][n1][n2].i1;       j = pre[ti][tj][tk][tp][n1][n2].j1;       k = pre[ti][tj][tk][tp][n1][n2].k1;       p = pre[ti][tj][tk][tp][n1][n2].p1;       t1 = pre[ti][tj][tk][tp][n1][n2].fi1;       t2 = pre[ti][tj][tk][tp][n1][n2].fi2;     }     printf( %lld+%lld=%lld n , ra, rb, rc);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long int s = 0;     s = n * (n);     s = s + (n - 1) * (n - 1);     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     string s;     cin >> s;     for (int i = 0; i < (int)s.size(); i++) {       if (s[i] ==  . )         cout <<  0 ;       else {         if (s[i + 1] ==  . )           cout <<  1 ;         else           cout <<  2 ;         i++;       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1009;   int a, b, sum = 0;   int arr[N][N], ans[N];   void llop_over(int r, int c) {     for (int i = 0; i < r; ++i) {       for (int g = 0; g < c; ++g) scanf( %d , &arr[i][g]);       sum ^= arr[i][0];     }   }   int main() {     scanf( %d %d , &a, &b);     llop_over(a, b);     if (sum == 0) {       bool flag = 0;       for (int i = 0; i < a && !flag; ++i) {         for (int g = 0; g < b; ++g) {           if (arr[i][g] != arr[i][0]) {             ans[i] = g;             flag = true;             break;           }         }       }       if (!flag) {         puts( NIE );         return 0;       }     }     cout <<  TAK n ;     for (int i = 0; i < a; ++i) cout << ans[i] + 1 <<    ;   }