#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   struct Node {     long long l, r;   } dict[maxn];   long long N, s;   inline bool check(long long mid) {     long long cnt = 0, cost = 0;     priority_queue<long long, vector<long long>, greater<long long>> q;     for (int i = 1; i <= N; ++i) {       cost += dict[i].l;       if (dict[i].l < mid && dict[i].r >= mid) {         q.push(mid - dict[i].l);       } else if (dict[i].l >= mid) {         ++cnt;       }     }     while (!q.empty() && cnt < (N + 1) / 2) {       cost += q.top();       q.pop();       cnt++;     }     return cost <= s && cnt >= (N + 1) / 2;   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %lld%lld , &N, &s);       for (int i = 1; i <= N; ++i) {         scanf( %lld%lld , &dict[i].l, &dict[i].r);       }       long long l = 1, r = 1e14, ans;       while (l <= r) {         long long mid = (l + r) >> 1;         if (check(mid))           ans = mid, l = mid + 1;         else           r = mid - 1;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t = 1, n, k = 0, flag = -1, b = 0;     while (t--) {       scanf( %lld , &n);       k = 0;       while (n != flag) {         if (n / 10 == 0 && b == 0) {           flag = n;           b = 1;         }         k++;         n++;         while (n % 10 == 0) {           n = n / 10;         }       }       printf( %lld n , k);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t[40008];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m, k, l, p;     cin >> n;     string s;     map<string, string> ex;     map<string, int> kol;     map<string, int> wh;     for (int u = 1; u <= n; u++) {       cin >> s;       for (int i = 0; i < s.length(); i++) {         string q;         for (int j = i; j < s.length(); j++) {           q += s[j];           if (wh[q] == u) continue;           if (kol[q] == 0) {             ex[q] = s;           }           wh[q] = u;           kol[q]++;         }       }     }     int kk;     cin >> kk;     for (int i = 0; i < kk; i++) {       string s;       cin >> s;       int kko = kol[s];       cout << kko <<    ;       if (kko == 0) {         cout <<  - n ;       } else {         cout << ex[s] <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int mid = (m + 1) / 2;     int cnt = 0;     int ans[m + 1];     if (m % 2) {       int i = 1;       int cnt = 1;       int k = 1;       ans[k++] = mid;       while (true) {         if (cnt > m) break;         ans[k++] = mid - i;         cnt++;         if (cnt > m) break;         ans[k++] = mid + i;         cnt++;         i++;       }     } else {       int i = 1;       int cnt = 0;       int k = 1;       while (true) {         if (cnt > m) break;         ans[k++] = mid - i + 1;         cnt++;         if (cnt > m) break;         ans[k++] = mid + i;         cnt++;         i++;       }     }     int k = 1;     for (int i = (1); i <= (n); i++) {       cout << ans[k++] << endl;       if (k > m) k = 1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, d[105];   char x[205];   int main() {     scanf( %d%d%s , &n, &m, x);     d[0] = 1;     for (int i = 0; i < n; i++)       if (x[i] ==  1  && d[i])         for (int j = 1; j <= m; j++)           if (x[i + j] ==  1  && (!d[i + j] || d[i + j] > d[i] + 1))             d[i + j] = d[i] + 1;     printf( %d n , d[n - 1] - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;      int main(){    int t,n,d;    int a[110],b[110];            scanf( %d ,&t);    while(t--){     scanf( %d%d ,&n,&d);     int fir=200,sec=200;     int fid,sid;     int x[110];     int xid[110];     int c=0;          for(int i=1;i<=n;i++){      scanf( %d ,&a[i]);      if(a[i]<fir){       sec=fir;fir=a[i];       sid=fid;fid=i;      }      else if(a[i]<sec){sec=a[i];sid=i;}      if(a[i]>d){       x[++c]=a[i];       xid[c]=i;      }     }     if(fir>d||sec>d||(c>=1&&fir+sec>d))printf( NO n );     else printf( YES n );    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline void chkmin(T1 &first, T2 second) {     if (first > second) first = second;   }   template <typename T1, typename T2>   inline void chkmax(T1 &first, T2 second) {     if (first < second) first = second;   }   const string FileName =  input ;   const int MAXN = 3e5 + 100;   int n, k, b, c;   vector<int> arr;   vector<int> event[5];   long long sum, mod, ans = 1e18;   multiset<long long> que;   long long f(long long s, long long t) {     return ((t - s) / 5) * b + ((t - s) % 5) * c;   }   int main(int argc, char const *argv[]) {     srand(time(0));     ios::sync_with_stdio(0);     cin >> n >> k >> b >> c;     arr.resize(n);     b = min(b, c * 5);     for (int i = 0; i < n; ++i) {       cin >> arr[i];     }     sort(arr.begin(), arr.end());     for (int i = 0; i < n; ++i) {       for (int j = 0; j < 5; ++j) {         event[(((arr[i] + j) % 5) + 5) % 5].push_back(arr[i] + j);       }     }     for (int j = 0; j < 5; ++j) {       int L = 0;       sum = 0, mod = 0;       que.clear();       for (int i = 0; i < n; ++i) {         while (L < n && arr[L] <= event[j][i]) {           que.insert(-f(arr[L], event[j][i]) - mod);           sum += f(arr[L], event[j][i]);           ++L;         }         while (que.size() > k) {           sum += *que.begin() + mod;           que.erase(que.begin());         }         if (que.size() == k) {           ans = min(ans, sum);         }         if (i != n - 1) {           assert(event[j][i] <= event[j][i + 1]);           mod -= f(event[j][i], event[j][i + 1]);           sum += f(event[j][i], event[j][i + 1]) * que.size();         }       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, a[400010];   map<int, int> m;   set<pair<int, int> > s;   long long ans = 0;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; ++i) cin >> a[i];     a[0] = 0;     for (int l = 1, r = 0; l <= n; ++l) {       s.erase(make_pair(-m[a[l - 1]], a[l - 1]));       m[a[l - 1]]--;       s.insert(make_pair(-m[a[l - 1]], a[l - 1]));       while (-s.begin()->first < k) {         ++r;         if (r >= n + 1) break;         s.erase(make_pair(-m[a[r]], a[r]));         m[a[r]]++;         s.insert(make_pair(-m[a[r]], a[r]));       }       ans += max(n + 1 - r, 0);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long a[n];       vector<long long> v;       for (long long i = 0; i < n; i++) {         cin >> a[i];         v.push_back(a[i]);       }       bool ans = true;       sort(v.begin(), v.end());       for (long long i = 0; i < n; i++) {         if (a[i] != v[i] && a[i] % v[0] > 0) {           ans = false;           break;         }       }       if (ans)         cout <<  YES ;       else         cout <<  NO ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int fa[maxn], cnt[maxn], vis[maxn], arr[maxn];   int fi(int x) { return x == fa[x] ? x : fa[x] = fi(fa[x]); }   int main(int argc, char const *argv[]) {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; ++i) fa[i] = i, cnt[i] = 0, vis[i] = 0, arr[i] = 0;     for (int i = 1, a, b; i <= m; ++i) {       scanf( %d %d , &a, &b);       cnt[a]++;       cnt[b]++;       vis[a] = 1;       vis[b] = 1;       int fx = fi(a), fy = fi(b);       if (fx != fy) fa[fx] = fy;     }     int ans = 0, tot = 0;     for (int i = 1; i <= n; ++i) {       if (cnt[i] % 2 == 1) {         arr[fi(i)]++;       }     }     int ff = 0;     int cnt2 = 0, cnt1 = 0;     for (int i = 2; i <= n; ++i)       if (vis[i] == 1) ff = 1;     int cnt = 0;     for (int i = 1; i <= n; ++i) {       if (vis[i] && fa[i] == i && arr[i] >= 2) {         tot = tot + (arr[i] - 2) / 2;         ++cnt2;       }       if (vis[i] && fa[i] == i) tot += 1, cnt++;     }     cnt1 = cnt - cnt2;     if (cnt == 1) {       if (cnt1 == 1) {         if (vis[1] == 0)           printf( 2 n );         else           printf( 0 n );       } else if (cnt2 == 1) {         if (vis[1] == 0) tot++;         printf( %d n , tot);       }     } else if (cnt == 0) {       printf( 0 n );     } else if (cnt >= 2) {       if (vis[1] == 0) ++tot;       printf( %d n , tot);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   void input() { cin >> n; }   void solve() {     int cnt = 0;     for (int i = 1; i <= n; ++i) {       if (cnt == n) {         break;       }       printf( %d 1 n , i);       ++cnt;       if (cnt == n) {         break;       }       if ((i % 2) == 0) {         printf( %d 4 n , i);         ++cnt;       }     }   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     int t;     t = 1;     while (t--) {       input();       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int l = s.length();     cout << 4 << endl;     cout <<  R   << l - 1 << endl;     cout <<  L   << 2 << endl;     cout <<  L   << l + 1 << endl;     cout <<  L   << 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int dx[] = {0, 1, 0, -1};   const int dy[] = {1, 0, -1, 0};   int n, k;   string s;   int main() {     cin >> n >> k;     cin >> s;     int sum = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  # ) sum++;       if (sum >= k) {         puts( NO );         return 0;       }       if (s[i] ==  . ) sum = 0;     }     puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int b[65], p = 1e9 + 7;   long long pow_(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % p;       b >>= 1, a = a * a % p;     }     return res % p;   }   void solve(int n, int x) {     int t = 0;     long long ans = 0;     while (x) {       if (x & 1) ans = (ans + pow_(n, t)) % p;       x >>= 1, t++;     }     cout << ans % p << endl;   }   int main() {     ios::sync_with_stdio(!true);     int t, n, k;     cin >> t;     while (t--) cin >> n >> k, solve(n, k);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5000 + 10;   const int BASE = 1e9 + 7;   int n;   int memo[N][N], _memo[N][N];   string s;   int _solve(int pos_1, int pos_2) {     if (pos_1 > n || pos_2 > n) return 0;     if (_memo[pos_1][pos_2] != -1) return _memo[pos_1][pos_2];     int cur = 0;     if (s[pos_1] == s[pos_2]) cur += _solve(pos_1 + 1, pos_2 + 1) + 1;     return _memo[pos_1][pos_2] = cur;   }   int solve(int pos, int len) {     if (s[pos] ==  0 ) return 0;     if (pos + len - 1 > n) return 0;     if (pos + len - 1 == n) return 1;     if (memo[pos][len] != -1) return memo[pos][len];     int cur = 0;     cur = (cur + solve(pos, len + 1)) % BASE;     if (pos + 2 * len - 1 <= n) {       int tmp = _solve(pos, pos + len);       if (tmp < len && s[pos + tmp] < s[pos + len + tmp]) {         cur = (cur + solve(pos + len, len)) % BASE;       } else         cur = (cur + solve(pos + len, len + 1)) % BASE;     }     return memo[pos][len] = cur;   }   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     cin >> n >> s;     s =  @  + s;     memset(memo, -1, sizeof(memo));     memset(_memo, -1, sizeof(_memo));     cout << solve(1, 1);   }


#include <bits/stdc++.h>   using namespace std;   int parent[100005];   int coun[100005];   bool isLucky(int a) {     while (a) {       int x = a % 10;       if (x == 4 || x == 7) {       } else         return false;       a = a / 10;     }     return true;   }   int findp(int a) {     if (parent[a] == a) {       return a;     }     parent[a] = findp(parent[a]);     return parent[a];   }   void uni(int x, int y) {     int parx = findp(x);     int pary = findp(y);     if (parx != pary) {       parent[parx] = pary;       coun[pary] += coun[parx];     }   }   vector<int> vec[100005];   int main() {     ios::sync_with_stdio(false);     cin.tie();     cout.tie();     long long int n, i, j, k, x, y, c = 0, ans = 0, z, z1;     cin >> n;     for (int i = 1; i < n + 1; i++) {       coun[i] = 1;       parent[i] = i;     }     for (int i = 0; i < n - 1; i++) {       cin >> x >> y >> z;       if (!isLucky(z)) {         vec[x].push_back(y);         vec[y].push_back(x);         uni(x, y);       }     }     for (i = 1; i <= n; i++) {       int x = findp(i);       int y = coun[x];       ans += (n - y) * (n - y - 1);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fscpp() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     fscpp();     long long n;     cin >> n;     long long ct = 0;     long long xm, ym;     long long x, y;     cin >> xm >> ym;     vector<long long> vx(n), vy(n);     vx[0] = xm;     vy[0] = ym;     for (long long int i = 1; i < n; i++) {       cin >> x >> y;       vx[i] = x;       vy[i] = y;     }     vector<long long> mvx(vx), mvy(vy);     sort(mvx.begin(), mvx.end());     sort(mvy.begin(), mvy.end());     long long max1 = mvx[n - 1], max2 = mvx[n - 2];     long long min1 = mvy[0], min2 = mvy[1];     long long len = min1 - max1;     if (len < 0) len = 0;     long long rx, ry;     for (long long int i = 0; i < n; i++) {       if (max1 == vx[i])         rx = max2;       else         rx = max1;       if (min1 == vy[i])         ry = min2;       else         ry = min1;       if (ry - rx > len) len = ry - rx;     }     len--;     cout << len + 1;     int p = 23;     string s = std::bitset<63>(p).to_string();     string h;     string g;     g = s;     for (long long int i = s.size() - 2; i < s.size(); i++) h += s[i];     y = h.size();     s.clear();     for (long long int i = 0; i < 31 - y; i++) {       s +=  1 ;     }     sort(s.begin(), s.end());     s.erase(unique(s.begin(), s.end()), s.end());     for (long long int i = 0; i < y; i++) {       s += h[i];     }     y = std::bitset<63>(g).to_ulong();     g.clear();     if (g.size() != 0) cout <<  yedhukku n t n ;     reverse(s.begin(), s.end());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxint = -1u >> 1;   const double pi = 3.14159265358979323;   const double eps = 1e-8;   int n, k, a[100100];   set<long long> vis;   int main() {     scanf( %d%d , &n, &k);     for (int i = (0); i < (n); i++) scanf( %d , &a[i]);     sort(a, a + n);     int ans = 0;     for (int i = (0); i < (n); i++) {       if (vis.find(a[i]) == vis.end()) {         ans++;         vis.insert(1LL * a[i] * k);       } else         continue;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     cin >> str;     int t = 0;     while (str[t]) {       if (str[t] ==  . ) {         cout << 0;         t++;       } else if (str[t] ==  -  && str[t + 1] ==  . ) {         cout << 1;         t += 2;       } else if (str[t] ==  -  && str[t + 1] ==  - ) {         cout << 2;         t += 2;       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100 + 10;   const int MAX_V = 200 + 10;   const int MAX_S = 1 << 7;   const int INF = 1000000;   const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, 1, 0, -1};   int N, M, K, S;   int w[MAX_N][MAX_N];   int f[MAX_N][MAX_N][MAX_S];   int pre[MAX_N][MAX_N][MAX_S];   int qx[MAX_V];   int qy[MAX_V];   int in[MAX_N][MAX_N];   int cov[MAX_N][MAX_N];   void Init() {     int x, y;     scanf( %d%d%d , &N, &M, &K);     S = 1 << K;     for (int i = 1; i <= N; ++i)       for (int j = 1; j <= M; ++j) scanf( %d , &w[i][j]);     for (int i = 1; i <= N; ++i)       for (int j = 1; j <= M; ++j)         for (int k = 1; k < S; ++k) {           f[i][j][k] = INF;           pre[i][j][k] = INF;         }     for (int i = 0; i < K; ++i) {       scanf( %d%d , &x, &y);       f[x][y][1 << i] = w[x][y];     }   }   void SPFA(int s) {     int qh = 0, qt = 0;     for (int i = 1; i <= N; ++i)       for (int j = 1; j <= M; ++j) {         qx[qt] = i;         qy[qt++] = j;         in[i][j] = true;       }     int nx, ny, px, py;     for (; qh < qt;) {       px = qx[qh];       py = qy[qh++];       for (int i = 0; i < 4; ++i) {         nx = px + dx[i];         ny = py + dy[i];         if (nx > 0 && nx <= N && ny > 0 && ny <= M &&             f[nx][ny][s] > f[px][py][s] + w[nx][ny]) {           f[nx][ny][s] = f[px][py][s] + w[nx][ny];           pre[nx][ny][s] = -i;           if (!in[nx][ny]) {             in[nx][ny] = true;             qx[qt] = nx;             qy[qt++] = ny;           }         }       }       in[px][py] = false;     }   }   void DFS(int x, int y, int s) {     cov[x][y] = true;     int tmp = pre[x][y][s];     if (tmp == INF) return;     if (tmp <= 0)       DFS(x - dx[-tmp], y - dy[-tmp], s);     else       DFS(x, y, tmp), DFS(x, y, s - tmp);   }   void Solve() {     for (int s = 1; s < S; ++s) {       for (int i = 1; i <= N; ++i)         for (int j = 1; j <= M; ++j)           for (int ns = (s - 1) & s; ns; ns = (ns - 1) & s)             if (f[i][j][s] > f[i][j][ns] + f[i][j][s - ns] - w[i][j]) {               f[i][j][s] = f[i][j][ns] + f[i][j][s - ns] - w[i][j];               pre[i][j][s] = ns;             }       SPFA(s);       if (0) {         printf( Now is state %d n , s);         for (int i = 1; i <= N; ++i) {           for (int j = 1; j <= M; ++j) printf( %d  , f[i][j][s]);           printf(  n );         }       }     }     int ax, ay, ans = INF;     for (int i = 1; i <= N; ++i)       for (int j = 1; j <= M; ++j)         if (f[i][j][S - 1] < ans) {           ans = f[i][j][S - 1];           ax = i, ay = j;         }     printf( %d n , ans);     DFS(ax, ay, S - 1);     for (int i = 1; i <= N; ++i) {       for (int j = 1; j <= M; ++j) putchar(cov[i][j] ?  X  :  . );       putchar(  n );     }   }   int main() {     Init();     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isprime(long long n) {     if (n < 2) return false;     if (n == 2) return true;     if (n % 2 == 0) return false;     for (int i = 3; i * i <= n; i = i + 2) {       if (n % i == 0) return false;     }     return true;   }   int main() {     int w, h, k;     cin >> w >> h >> k;     int sum = 0;     while (k--) {       sum += (2 * w + (2 * (h - 2)));       w -= 4;       h -= 4;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   const double eps = 1e-11;   int dx[] = {-1, 0, 1, 0};   int dy[] = {0, 1, 0, -1};   using namespace std;   const int maxn = 1005;   int n;   typedef struct node_ {     int x, y;   } N;   N node[maxn];   pair<int, pair<int, int> > ans[100005];   int cnt;   void deal(int t, int a, int b) {     ans[cnt].first = t, ans[cnt].second.first = a, ans[cnt++].second.second = b;   }   int main() {     while (scanf( %d , &n) == 1) {       cnt = 0;       for (int i = (1); i < (n); i++) {         scanf( %d%d , &node[i].x, &node[i].y);       }       for (int i = 1; i < n; i++) {         int tmp;         if (node[i].x != i + 1) {           tmp = node[i].x;           for (int j = (1); j < (n); j++) {             if (node[j].x == tmp) {               node[j].x = i + 1;             } else if (node[j].x == i + 1) {               node[j].x = tmp;             }           }           deal(1, tmp, i + 1);         }         if (node[i].y > i) {           tmp = node[i].y;           for (int j = (1); j < (n); j++) {             if (node[j].y == tmp) {               node[j].y = i;             } else if (node[j].y == i) {               node[j].y = tmp;             }           }           deal(2, tmp, i);         }       }       printf( %d n , cnt);       for (int i = 0; i < cnt; i++) {         printf( %d %d %d n , ans[i].first, ans[i].second.first,                ans[i].second.second);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a >> b >> c;     cout << min(a + a + b + b, min(a + b + c, min(a + a + c + c, b + b + c + c)))          << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 6;   namespace AC {   int tot, tr[N][26];   int fail[N];   int cnt[N];   int sid[N];   int next[N];   bool vis[N];   int isend[N];   int in[N];   int val[N];   int victim[N];   queue<int> q;   void init() {     memset(fail, 0, sizeof(fail));     memset(tr, 0, sizeof(tr));     memset(cnt, 0, sizeof(cnt));     memset(vis, false, sizeof vis);     memset(sid, 0, sizeof sid);     memset(val, 0, sizeof val);     memset(isend, 0, sizeof isend);     memset(victim, 0, sizeof victim);     memset(next, 0, sizeof next);     tot = 0;   }   void insert(char *s, int id) {     int u = 0;     for (int i = 1; s[i]; i++) {       if (!tr[u][s[i] -  a ]) tr[u][s[i] -  a ] = ++tot;       u = tr[u][s[i] -  a ];     }     sid[id] = u;     isend[u] = true;   }   void build() {     next[0] = 0;     for (int i = 0; i < 26; i++)       if (tr[0][i]) q.push(tr[0][i]);     while (q.size()) {       int u = q.front();       q.pop();       for (int i = 0; i < 26; i++) {         if (tr[u][i]) {           fail[tr[u][i]] = tr[fail[u]][i], q.push(tr[u][i]);           in[fail[tr[u][i]]] += 1;         } else           tr[u][i] = tr[fail[u]][i];         next[tr[u][i]] =             isend[fail[tr[u][i]]] ? fail[tr[u][i]] : next[fail[tr[u][i]]];       }     }   }   int query(char *t) {     int u = 0, res = -1;     for (int i = 1; t[i]; i++) {       u = tr[u][t[i] -  a ];       for (int x = u; x; x = next[x]) {         if (isend[x]) {           res = max(res, victim[x]);         }       }     }     return res;   }   void query(char *t, int) {     int u = 0;     for (int i = 1; t[i]; i++) {       u = tr[u][t[i] -  a ];       val[u] += 1;     }   }   void topoSort() {     for (int i = 0; i < N; ++i)       if (in[i] == 0) q.push(i);     while (!q.empty()) {       int u = q.front();       q.pop();       int v = fail[u];       in[v]--;       val[v] += val[u];       if (in[v] == 0) q.push(v);     }   }   }  // namespace AC   char s[N];   int val[N];   map<int, int> mp[N];   int main() {     int ans = 0;     int n, m;     cin >> n >> m;     AC::init();     for (int i = 0; i < n; i++) {       scanf( %s , s + 1);       AC::insert(s, i);       mp[AC::sid[i]][0] += 1;     }     AC::build();     while (m--) {       int x, c, v;       scanf( %d , &x);       if (x == 1) {         scanf( %d %d , &c, &v);         mp[AC::sid[c - 1]][val[c - 1]] -= 1;         if (mp[AC::sid[c - 1]][val[c - 1]] == 0) {           mp[AC::sid[c - 1]].erase(val[c - 1]);         }         val[c - 1] = v;         mp[AC::sid[c - 1]][v] += 1;         AC::victim[AC::sid[c - 1]] = (*--mp[AC::sid[c - 1]].end()).first;         continue;       }       scanf( %s , s + 1);       cout << AC::query(s) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a;   vector<pair<int, int> > s;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       a.push_back(x);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n - 1; j++) {         if (a[j] > a[j + 1]) {           swap(a[j], a[j + 1]);           s.push_back({j + 1, j + 2});         }       }     }     for (auto a : s) {       cout << a.first <<     << a.second <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     short n, before, after;     cin >> n;     string a;     bool flag = false;     for (short i = 0; i < n; i++) {       cin >> a;       cin >> before;       cin >> after;       if (after >= 2400 && before >= 2400 && after - before > 0) flag = true;     }     if (flag == true)       cout <<  YES ;     else       cout <<  NO ;   }


#include<bits/stdc++.h>   #define pb push_back   #define int long long   using namespace std;   int p=998244353,tt,n,m,fac[25];   void prepare(){    fac[0]=1;    for(int i=1;i<25;i++){     fac[i]=(fac[i-1]*i)%p;    }   }   int inv(int z){    int s=p-2,t=z,ans=1;       while(s>0){        if(s%2)ans=(ans*t)%p;        t=(t*t)%p;        s/=2;       }       return ans;   }   void solve(){    prepare();    cin>>n>>m;    int a[n+1][m+1],x=0;    for(int i=1;i<=n;i++){     for(int j=1;j<=m;j++){      cin>>a[i][j];     }    }    for(int i=1;i<=m;i++){     vector<int> v;     for(int j=1;j<=n;j++)v.pb(a[j][i]);        sort(v.begin(),v.end());        int c=1;        for(int i=0;i<n;i++){         c=(c*(v[i]-i-1))%p;        }        x=(x+fac[n]-c+p)%p;    }       cout<<((x*inv(fac[n]))%p)<<  n ;    }      signed main(){       #ifndef ONLINE_JUDGE       freopen( input.txt , r ,stdin);       freopen( output.txt , w ,stdout);       #endif       ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);       //cin>>tt;       //while(tt--)       solve();   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e4 + 10, mod = 1e9 + 9, maxa = 1e6 + 100;   long long sta = 0;   const long long inf = 2e18 + 13;   long long max(long long x, long long y) { return (x > y ? x : y); }   long long min(long long x, long long y) { return (x < y ? x : y); }   long long pw(long long x, long long y) {     if (!y) {       return 1;     }     long long res = pw(x, y / 2);     res *= res;     res %= mod;     if (y & 1) {       res *= x;     }     return res % mod;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     long long ans = 1;     for (int i = 1; i <= n; i++) {       ans = ans * (pw(2, m) - i);       ans += mod;       ans %= mod;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, tx, ty;   vector<pair<int, int> > ar;   int vis[100010];   bool check(int first, int second, int x1, int y1, int x2, int y2) {     if ((1LL * x2 - 1LL * x1) * 1LL * (1LL * second - 1LL * y1) ==         (1LL * y2 - 1LL * y1) * 1LL * (1LL * first - 1LL * x1))       return true;     return false;   }   int main(int argc, char const *argv[]) {     scanf( %d , &n);     ar.clear();     for (int i = 0; i < n; i++) {       scanf( %d%d , &tx, &ty);       ar.push_back({tx, ty});     }     if (n == 1) {       cout <<  YES n ;     } else if (n == 2) {       cout <<  YES n ;     } else {       memset(vis, 0, sizeof(vis));       for (int i = 0; i < n; i++) {         if (check(ar[i].first, ar[i].second, ar[0].first, ar[0].second,                   ar[1].first, ar[1].second)) {           vis[i] = 1;         }       }       int x1, y1, x2, y2, flag = 0, hold1, hold2;       for (int j = 0; j < n; j++) {         if (!vis[j]) {           flag++;           x1 = ar[j].first;           y1 = ar[j].second;           vis[j] = 1;           hold1 = j;           break;         }       }       for (int j = 0; j < n; j++) {         if (!vis[j]) {           flag++;           x2 = ar[j].first;           y2 = ar[j].second;           int fgh = 1;           if (check(ar[0].first, ar[0].second, x1, y1, x2, y2) ||               check(ar[1].first, ar[1].second, x1, y1, x2, y2)) {             fgh = 0;             hold2 = j;             continue;           }           if (fgh) {             vis[j] = 1;             hold2 = j;           }           break;         }       }       vis[hold2] = 1;       if (flag == 0 || flag == 1) {         cout <<  YES n ;       } else {         for (int i = 0; i < n; i++) {           if (check(ar[i].first, ar[i].second, x1, y1, x2, y2)) {             vis[i] = 1;           }         }         flag = 0;         for (int i = 0; i < n; i++) {           if (!vis[i]) {             flag = 1;           }         }         if (!flag)           cout <<  YES n ;         else {           memset(vis, 0, sizeof(vis));           for (int i = 0; i < n; i++) {             if (check(ar[i].first, ar[i].second, ar[0].first, ar[0].second, x1,                       y1))               vis[i] = 1;             else if (check(ar[i].first, ar[i].second, ar[1].first, ar[1].second,                            x2, y2))               vis[i] = 1;           }           flag = 0;           for (int i = 0; i < n; i++) {             if (!vis[i]) {               flag = 1;             }           }           if (!flag) {             cout <<  YES n ;           } else {             memset(vis, 0, sizeof(vis));             for (int i = 0; i < n; i++) {               if (check(ar[i].first, ar[i].second, ar[0].first, ar[0].second, x2,                         y2))                 vis[i] = 1;               else if (check(ar[i].first, ar[i].second, ar[1].first, ar[1].second,                              x1, y1))                 vis[i] = 1;             }             flag = 0;             for (int i = 0; i < n; i++) {               if (!vis[i]) {                 flag = 1;               }             }             if (flag)               cout <<  NO n ;             else               cout <<  YES n ;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long K, B, N, T;   int main() {     cin >> K >> B >> N >> T;     if (K == 1 && 1 + N * B >= T) {       cout << (int)ceil((1 + N * B - T) / (1.0 * B)) << endl;       return 0;     }     if (K == 1) {       cout << 0 << endl;       return 0;     }     long long C = 1, counter = N + 1;     double thres = 1.0 * (T * (K - 1) + B) / (K - 1 + B);     for (int i = 1; i <= N; i++) {       C *= K;       if (C > thres) {         counter = i;         break;       }     }     counter--;     cout << N - counter << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char buff[100000], *pb;   int readInt() {     int num = 0;     while (*pb && isdigit(*pb)) {       num = num * 10 + (*pb -  0 );       ++pb;     }     return num;   }   int nextChar() {     int c =   0 ;     if (*pb) {       c = *pb;       pb++;     }     return c;   }   int hasNext() { return *pb ? 1 : 0; }   int main(void) {     int n;     scanf( %i n , &n);     int nextId = 1;     map<vector<int>, int> SId;     vector<int> deg(n + 1);     vector<vector<vector<int>>> S(n + 1);     vector<vector<int>> H(n + 1);     for (int i = 1; i <= n; i++) {       scanf( %s , buff);       pb = buff;       while (hasNext()) {         int k = readInt();         assert(nextChar() ==  : );         vector<int> s;         while (hasNext()) {           s.push_back(readInt());           if (nextChar() ==  - ) {             break;           }         }         assert(s.size() == k);         sort(begin(s), end(s));         S[i].push_back(s);         deg[i]++;         if (!SId.count(s)) {           SId[s] = nextId++;         }         H[i].push_back(SId[s]);       }     }     vector<vector<int>> sh = H;     for (vector<int> &s : sh) {       sort(s.begin(), s.end());     }     vector<int> from, to;     vector<int> proc(n + 1);     queue<int> Q;     for (int i = 1; i <= n; i++) {       if (deg[i] == 1) {         proc[i] = 1;         Q.push(i);       }     }     vector<int> tree_deg(n + 1);     map<int, int> root;     set<int> seen;     while (!Q.empty()) {       int u = Q.front();       Q.pop();       vector<int> sub = {u};       for (int j = 0; j < H[u].size(); j++) {         int id = H[u][j];         if (seen.count(id)) {           from.push_back(u);           to.push_back(root[id]);           tree_deg[root[id]]++;           for (auto e : S[u][j]) {             sub.push_back(e);           }         }       }       sort(begin(sub), end(sub));       int id = SId[sub];       seen.insert(id);       root[id] = u;       for (int i = 1; i <= n; i++)         if (!proc[i]) {           if (binary_search(begin(sh[i]), end(sh[i]), id)) {             deg[i]--;             if (deg[i] <= 1) {               proc[i] = 1;               Q.push(i);             }           }         }     }     bool ok = true;     for (int d : tree_deg) {       if (d > 1) {         ok = false;       }     }     if (ok && int(from.size()) == n - 1) {       printf( %i n , n - 1);       for (int i = 0; i < n - 1; i++) {         printf( %i %i n , from[i], to[i]);       }     } else {       puts( -1 );     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     ;     long long int t;     cin >> t;     while (t--) {       string s;       cin >> s;       long long int a[26] = {0};       long long int cnt = 0;       char c;       int i = 0;       while (i < s.length()) {         cnt = 0;         c = s[i];         while (s[i] == c && i < s.length()) {           cnt++;           i++;         }         if (cnt % 2 != 0) {           a[c -  a ] = 1;         }       }       string ans =   ;       for (i = 0; i < 26; i++) {         if (a[i] == 1) {           ans += (i +  a );         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int check(string st) {     int s1 = 0, s2 = 0;     for (int i = 1; i < st.length(); i++) {       if (st[i] ==  1  && i % 2 == 1) s1++;       if (st[i] ==  1  && i % 2 == 0) s2++;       if (s1 - s2 > 5 - i / 2 || (i % 2 == 1 && s2 - s1 >= 5 - i / 2) ||           (i % 2 == 0 && s2 - s1 > 5 - i / 2))         return i;     }     return 10;   };   int main() {     int t;     cin >> t;     while (t--) {       string st;       cin >> st;       st =     + st;       string sts = st;       for (int i = 1; i < st.length(); i++)         if (st[i] ==  ? )           if (i % 2 == 1)             st[i] =  1 ;           else             st[i] =  0 ;       for (int i = 1; i < sts.length(); i++)         if (sts[i] ==  ? )           if (i % 2 == 0)             sts[i] =  1 ;           else             sts[i] =  0 ;       cout << min(check(st), check(sts)) << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   using ld = long double;   template <class T>   using Table = vector<vector<T>>;   const ld eps = 1e-9;   template <class S, class T>   ostream &operator<<(ostream &os, const pair<S, T> v) {     os <<  (   << v.first <<  ,   << v.second <<  ) ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (int i = 0; i < v.size(); i++) {       if (i > 0) {         os <<    ;       }       os << v[i];     }     return os;   }   template <class T>   ostream &operator<<(ostream &os, const vector<vector<T>> &v) {     for (int i = 0; i < v.size(); i++) {       if (i > 0) {         os << endl;       }       os << v[i];     }     return os;   }   template <class T>   ostream &operator<<(ostream &os, const vector<set<T>> &v) {     for (int i = 0; i < v.size(); i++) {       if (i > 0) {         os << endl;       }       os << v[i];     }     return os;   }   template <class T>   ostream &operator<<(ostream &os, const set<T> &v) {     int i = 0;     for (auto it : v) {       if (i > 0) {         os <<    ;       }       os << it;       i++;     }     return os;   }   const int INF = 2147483647;   const long long int L_INF = 9223372036854775807;   struct Edge {     int src, dst;     int weight;     Edge(int src, int dst, int weight) : src(src), dst(dst), weight(weight) {}   };   bool operator<(const Edge &e, const Edge &f) {     return e.weight != f.weight ? e.weight > f.weight            : e.src != f.src     ? e.src < f.src                                 : e.dst < f.dst;   }   int maximumFlow(const vector<vector<Edge>> &ag, int s, int t) {     vector<vector<Edge>> g(ag);     for (int i = 0; i < ag.size(); ++i) {       for (int j = 0; j < ag[i].size(); ++j) {         int d = ag[i][j].dst;         int s = ag[i][j].src;         bool ok = false;         for (int k = 0; k < ag[d].size(); ++k) {           if (ag[d][k].src == s) {             ok = true;             break;           }         }         if (!ok) {           g[d].push_back(Edge(d, s, 0));         }       }     }     int n = g.size();     vector<vector<int>> flow(n, vector<int>(n)), capacity(n, vector<int>(n));     for (int u = 0; u < (int)n; ++u)       for (auto e = (g[u]).begin(); e != (g[u]).end(); ++e)         capacity[e->src][e->dst] += e->weight;     int total = 0;     while (1) {       queue<int> Q;       Q.push(s);       vector<int> prev(n, -1);       prev[s] = s;       while (!Q.empty() && prev[t] < 0) {         int u = Q.front();         Q.pop();         for (auto e = (g[u]).begin(); e != (g[u]).end(); ++e)           if (prev[e->dst] < 0 && (capacity[u][e->dst] - flow[u][e->dst]) > 0) {             prev[e->dst] = u;             Q.push(e->dst);           }       }       if (prev[t] < 0) break;       int inc = INF;       for (int j = t; prev[j] != j; j = prev[j])         inc = min(inc, (capacity[prev[j]][j] - flow[prev[j]][j]));       for (int j = t; prev[j] != j; j = prev[j])         flow[prev[j]][j] += inc, flow[j][prev[j]] -= inc;       total += inc;     }     return total;   }   using ll = long long int;   int dx[] = {-1, 0, 1, 0};   int dy[] = {0, 1, 0, -1};   int N, T;   vector<vector<int>> get_time(const vector<vector<int>> &canmove, int sy, int sx,                                vector<vector<int>> c_times) {     vector<vector<int>> times(N, vector<int>(N, 100000));     if (c_times.empty()) {       c_times = times;     }     times[sy][sx] = 0;     queue<pair<int, int>> que;     que.emplace(sx, sy);     while (!que.empty()) {       auto p(que.front());       que.pop();       int x = p.first;       int y = p.second;       if (c_times[y][x] == times[y][x]) continue;       for (int way = 0; way < 4; ++way) {         int nx = x + dx[way];         int ny = y + dy[way];         if (nx >= 0 && nx < N && ny >= 0 && ny < N) {           if (canmove[ny][nx] != false) {             if (times[ny][nx] > times[y][x] + 1 &&                 c_times[ny][nx] >= times[y][x] + 1) {               times[ny][nx] = times[y][x] + 1;               que.emplace(nx, ny);             }           }         }       }     }     return times;   }   int main() {     ios::sync_with_stdio(false);     cin.tie();     cin >> N >> T;     vector<vector<int>> canmove(N, vector<int>(N, true));     vector<vector<int>> ins(N, vector<int>(N)), outs(N, vector<int>(N));     vector<string> in_sts(N), out_sts(N);     int collapt_x, collapt_y;     for (int i = 0; i < N; ++i) {       cin >> in_sts[i];       for (int j = 0; j < N; ++j) {         if (in_sts[i][j] ==  Y ) {           canmove[i][j] = false;         } else if (in_sts[i][j] ==  Z ) {           canmove[i][j] = false;         } else {           ins[i][j] = in_sts[i][j] -  0 ;         }       }     }     for (int i = 0; i < N; ++i) {       cin >> out_sts[i];       for (int j = 0; j < N; ++j) {         if (out_sts[i][j] ==  Y ) {         } else if (out_sts[i][j] ==  Z ) {           collapt_x = j;           collapt_y = i;         } else {           outs[i][j] = out_sts[i][j] -  0 ;         }       }     }     vector<vector<int>> collapt_times =         get_time(canmove, collapt_y, collapt_x, vector<vector<int>>(0));     vector<vector<vector<vector<int>>>> oks(         N,         vector<vector<vector<int>>>(N, vector<vector<int>>(N, vector<int>(N))));     const int start = 0;     const int in_id = 1;     const int out_id = in_id + N * N;     const int goal = out_id + N * N;     vector<vector<Edge>> g(goal + 1);     for (int y = 0; y < N; ++y) {       for (int x = 0; x < N; ++x) {         g[start].push_back(Edge{start, in_id + y * N + x, ins[y][x]});         g[out_id + y * N + x].push_back(             Edge{out_id + y * N + x, goal, outs[y][x]});       }     }     for (int y = 0; y < N; ++y) {       for (int x = 0; x < N; ++x) {         auto atimes = get_time(canmove, y, x, collapt_times);         for (int ty = 0; ty < N; ++ty) {           for (int tx = 0; tx < N; ++tx) {             if (atimes[ty][tx] <= collapt_times[ty][tx] && atimes[ty][tx] <= T) {               oks[y][x][ty][tx] = true;               int aid = in_id + y * N + x;               int bid = out_id + ty * N + tx;               g[aid].push_back(Edge{aid, bid, 1000});             }           }         }       }     }     int answer = maximumFlow(g, start, goal);     cout << answer << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m, k, t;     cin >> n >> m >> k >> t;     vector<pii> waste(k);     for (int i = 0; i < k; ++i) {       cin >> waste[i].first >> waste[i].second;       --waste[i].first;       --waste[i].second;     }     sort(begin(waste), end(waste));     vector<pair<pii, int>> queries(t);     for (int i = 0; i < t; ++i) {       cin >> queries[i].first.first >> queries[i].first.second;       --queries[i].first.first;       --queries[i].first.second;       queries[i].second = i;     }     sort(begin(queries), end(queries));     vector<int> ans(t);     int ptr = 0;     for (auto& p : queries) {       pii pos = p.first;       int idx = p.second;       while (ptr < k and waste[ptr] < pos) {         ++ptr;       }       if (ptr < k and waste[ptr] == pos) {         ans[idx] = 3;       } else {         int tot = m * pos.first + pos.second;         tot -= ptr;         ans[idx] = tot % 3;       }     }     vector<string> res = { Carrots ,  Kiwis ,  Grapes ,  Waste };     for (int x : ans) cout << res[x] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> ad[100009];   vector<int> idx;   deque<int> vec;   int cnt[100009];   int ans[100009];   vector<pair<int, int> > arr, arr2;   int val[100009];   set<int> s;   int main() {     int a, b, c, d, e, i, j, k, l, n, m, x, y, t, p, X;     scanf( %d , &t);     for (p = 1; p <= t; p++) {       scanf( %d%d%d , &n, &x, &y);       c = y - x;       m = n + 1;       arr.clear();       arr2.clear();       for (i = 0; i <= m; i++) {         cnt[i] = 0;         ad[i].clear();         ans[i] = -1;       }       s.clear();       for (i = 1; i <= n; i++) {         scanf( %d , &a);         val[i] = a;         cnt[a]++;         ad[a].push_back(i);         s.insert(i);       }       for (i = 1; i <= m; i++) {         if (cnt[i] == 0) {           X = i;           break;         }       }       if (c == 0) {         for (i = 1; i <= n; i++) {           if (x) {             ans[i] = val[i];             x--;           } else {             ans[i] = X;           }         }         printf( YES n );         for (i = 1; i <= n; i++) {           printf( %d  , ans[i]);         }         printf(  n );         continue;       }       for (i = 1; i <= m; i++) {         if (cnt[i] > 0) {           arr.push_back({cnt[i], i});         }       }       sort(arr.begin(), arr.end());       m = arr.size();       c = y - x;       for (i = 0; i < m; i++) {         if (c == 0) {           break;         }         b = c / (m - i);         if (c % (m - i) != 0) {           b++;         }         b = min(b, arr[i].first);         c -= b;         arr2.push_back({b, arr[i].second});       }       sort(arr2.begin(), arr2.end());       c = y - x;       m = arr2.size();       if (m == 1) {         a = arr2[0].second;         l = arr2[0].first;         if (l > (n - cnt[a])) {           printf( NO n );           continue;         }         b = l;         for (i = 1; i <= n; i++) {           if (val[i] != a && b > 0) {             ans[i] = a;             b--;           }         }         for (i = 0; i < l; i++) {           b = ad[a][i];           ans[b] = X;         }       } else {         l = 0;         if (arr2[m - 1].first > (c - arr2[m - 1].first)) {           l = arr2[m - 1].first - (c - arr2[m - 1].first);           for (i = 0; i < m; i++) {             a = arr2[i].second;             b = arr2[i].first;             for (j = 0; j < b; j++) {               s.erase(ad[a][j]);             }           }           a = arr2[m - 1].second;           b = ad[a].size();           for (j = 0; j < b; j++) {             s.erase(ad[a][j]);           }           b = s.size();           if (l > b) {             printf( NO n );             continue;           }           arr2[m - 1].first -= l;           a = arr2[m - 1].second;           for (i = 0; i < l; i++) {             d = *s.begin();             s.erase(d);             ans[d] = a;           }           b = arr2[m - 1].first;           d = b + l;           for (i = b; i < d; i++) {             k = ad[a][i];             ans[k] = X;           }         }         vec.clear();         idx.clear();         for (i = 0; i < m; i++) {           a = arr2[i].second;           b = arr2[i].first;           if (i == m - 1) {             for (j = 0; j < b; j++) {               vec.push_front(a);             }           } else {             for (j = 0; j < b; j++) {               vec.push_back(a);             }           }           for (j = 0; j < b; j++) {             idx.push_back(ad[a][j]);           }         }         d = idx.size();         for (i = 0; i < d; i++) {           a = idx[i];           ans[a] = vec[i];         }       }       for (i = 1; i <= n; i++) {         if (ans[i] == -1) {           if (x) {             ans[i] = val[i];             x--;           } else {             ans[i] = X;           }         }       }       if (x > 0) {         printf( NO n );         continue;       }       printf( YES n );       for (i = 1; i <= n; i++) {         printf( %d  , ans[i]);       }       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int nums[n];     for (int i = 0; i < n; i++) {       cin >> nums[i];     }     for (int i = 0; i < n - 1; i++) {       if (nums[i] < 0) {         cout <<  NO ;         return 0;       }       if (nums[i] % 2 == 1) {         nums[i + 1] -= 1;       }     }     if (nums[n - 1] >= 0 && nums[n - 1] % 2 == 0) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   void rd(int &x) {     x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   void lrd(long long &x) {     x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   const int INF = 1e9;   const long long LINF = 1e18;   const int mod = 998244353;   const int N = 3e5 + 10;   using namespace std;   int n;   int fi[N], nxt[N << 1], to[N << 1], tot;   void link(int x, int y) {     nxt[++tot] = fi[x];     fi[x] = tot;     to[tot] = y;   }   int f[N][3];   void dfs(int x) {     f[x][0] = f[x][1] = f[x][2] = 1;     int cnt = 1;     int ghb = 1;     for (int i = fi[x]; i; i = nxt[i]) {       if (f[to[i]][0]) continue;       dfs(to[i]);       cnt = cnt * 2 % mod;       int tmp;       tmp = (1ll * f[to[i]][0] * 2 + f[to[i]][1] + f[to[i]][2]) % mod;       f[x][0] = 1ll * f[x][0] * tmp % mod;       f[x][1] = 1ll * f[x][1] * (1ll * 2 * f[to[i]][0] + f[to[i]][1]) % mod;       ghb = 1ll * ghb * (f[to[i]][0] + f[to[i]][1]) % mod;       f[x][2] = 1ll * f[x][2] * (1ll * f[to[i]][0] * 2 + f[to[i]][1]) % mod;     }     f[x][1] = (f[x][1] - ghb + mod) % mod;   }   int main() {     rd(n);     for (int i = 1; i < n; i++) {       int x, y;       rd(x);       rd(y);       link(x, y);       link(y, x);     }     dfs(1);     printf( %d n , (f[1][0] + f[1][1] - 1) % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int dr8[] = {0, 0, 1, -1, 1, 1, -1, -1};   int dc8[] = {1, -1, 0, 0, -1, 1, -1, 1};   int dr4[] = {0, 1, -1, 0};   int dc4[] = {1, 0, 0, -1};   int n;   int a[N];   set<pair<int, int> > s;   set<int> end_idx;   int sz[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i + 1];     }     int c = 1;     for (int i = 2; i <= n; i++) {       if (a[i] != a[i - 1]) {         s.insert({-c, i - 1});         end_idx.insert(i - 1);         sz[i - 1] = c;         c = 1;       } else         c++;     }     s.insert({-c, n});     end_idx.insert(n);     sz[n] = c;     int ans = 0;     while (!s.empty()) {       auto it = *s.begin();       s.erase(s.begin());       end_idx.erase(it.second);       ans++;       auto idx = end_idx.lower_bound(it.second);       if (idx != end_idx.begin() && idx != end_idx.end()) {         int rgt = *idx;         idx--;         int lft = *idx;         if (a[lft] == a[rgt]) {           s.erase(s.find({-sz[lft], lft}));           s.erase(s.find({-sz[rgt], rgt}));           end_idx.erase(lft);           sz[rgt] += sz[lft];           s.insert({-sz[rgt], rgt});         }       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (107);   const int inf = (int)1e9 + 42;   struct aho_corasick {     int is_end[MAXN], link[MAXN], psz;     map<char, int> to[MAXN];     void clear() {       for (int i = 0; i < psz; i++) is_end[i] = 0, link[i] = 0, to[i].clear();       psz = 1;       is_end[0] = 1;     }     aho_corasick() {       psz = MAXN - 2;       clear();     }     void add_word(string s) {       int u = 0;       for (char c : s) {         if (!to[u].count(c)) to[u][c] = psz++;         u = to[u][c];       }       is_end[u] = 1;     }     void push_links() {       queue<int> Q;       int u, v, j;       char c;       Q.push(0);       link[0] = -1;       while (!Q.empty()) {         u = Q.front();         Q.pop();         for (auto it : to[u]) {           v = it.second;           c = it.first;           j = link[u];           while (j != -1 && !to[j].count(c)) j = link[j];           if (j != -1)             link[v] = to[j][c];           else             link[v] = 0;           Q.push(v);         }       }     }   };   int n, m;   string s1, s2, virus;   void read() {     cin >> s1;     cin >> s2;     cin >> virus;     n = s1.size();     m = s2.size();   }   aho_corasick aho;   bool is_bad[MAXN];   int dp[MAXN][MAXN][MAXN];   int nxt_i[MAXN][MAXN][MAXN];   int nxt_j[MAXN][MAXN][MAXN];   int nxt_state[MAXN][MAXN][MAXN];   int rec(int i, int j, int state) {     if (i >= n + 1) return -inf;     if (j >= m + 1) return -inf;     if (is_bad[state]) return -inf;     if (i == n && j == m) return 0;     int &memo = dp[i][j][state];     if (memo != -1) return memo;     memo = -inf;     if (i < n && j < m && s1[i] == s2[j]) {       int u = state;       while (u != -1 && !aho.to[u].count(s1[i])) u = aho.link[u];       if (u == -1)         u = 0;       else         u = aho.to[u][s1[i]];       memo = max(memo, 1 + rec(i + 1, j + 1, u));       nxt_state[i][j][state] = u;       nxt_i[i][j][state] = i + 1;       nxt_j[i][j][state] = j + 1;     }     if (memo < rec(i + 1, j, state)) {       memo = max(memo, rec(i + 1, j, state));       nxt_state[i][j][state] = state;       nxt_i[i][j][state] = i + 1;       nxt_j[i][j][state] = j;     }     if (memo < rec(i, j + 1, state)) {       memo = max(memo, rec(i, j + 1, state));       nxt_state[i][j][state] = state;       nxt_i[i][j][state] = i;       nxt_j[i][j][state] = j + 1;     }     return memo;   }   void solve() {     aho.clear();     aho.add_word(virus);     aho.push_links();     int u = 0;     for (char c : virus) u = aho.to[u][c];     is_bad[u] = true;     for (int i = 0; i < aho.psz; i++) {       int u = i;       while (u != -1) {         is_bad[i] |= is_bad[u];         u = aho.link[u];       }     }     memset(dp, -1, sizeof(dp));     int ret = rec(0, 0, 0);     if (!ret)       cout << 0 <<   n ;     else {       string ans =   ;       int c_i = 0, c_j = 0, c_state = 0, last_i, last_j, last_state;       while (!(c_i == n && c_j == m)) {         last_i = c_i;         last_j = c_j;         last_state = c_state;         c_i = nxt_i[last_i][last_j][last_state];         c_j = nxt_j[last_i][last_j][last_state];         c_state = nxt_state[last_i][last_j][last_state];         if (c_i - last_i && c_j - last_j) ans.push_back(s1[last_i]);       }       cout << ans <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     read();     solve();     return 0;   }


#include <bits/stdc++.h>   char s[100][100];   int main() {     int n, m, ans = 0;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1);     for (int i = 1; i < n; i++) {       for (int j = i + 1; j <= n; j++) {         int f = 0, g = 0;         for (int k = 1; k <= m; k++)           if (s[i][k] !=  .  || s[j][k] !=  . ) {             if (s[i][k] == s[j][k])               f = 1;             else               g = 1;           }         if (f == g && f) {           printf( No );           return 0;         }       }     }     printf( Yes );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long n, d;       cin >> n >> d;       if (n >= d)         cout <<  YES  << endl;       else {         double i = 1, cnt = 0;         while (i <= n) {           int y = ceil(d / (i + 1)) + i;           if (y <= n) {             cout <<  YES  << endl;             ++cnt;             break;           }           ++i;         }         if (cnt == 0) cout <<  NO  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) cin >> arr[i];       sort(arr, arr + n);       bool flag = 1;       for (int i = 1; i < n; i++) {         if (arr[i] - arr[i - 1] > 1) {           flag = 0;         }       }       if (flag)         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 100, PI = 3.14159265359, M = 1e9 + 7;   long long a[N], ans = 1;   int main() {     long long n;     cin >> n;     long long x = 0, y = 0;     for (int i = 0; i < n; i++) {       long long a, b;       cin >> a >> b;       long long t1 = a - x, t2 = b - x;       if (x == y) {         ans += min(a, b) - x;       } else if (x < y) {         if (y <= a) {           x = y;           ans += min(a, b) - x + 1;         }       } else if (x > y) {         if (x <= b) {           y = x;           ans += min(a, b) - x + 1;         }       }       x = a, y = b;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 40;   int a[maxN][maxN];   int b[maxN][maxN];   int flips[maxN][maxN];   int n, x;   int check(int mask) {     memset(flips, 0, sizeof(flips));     for (int i = 0; i < x; ++i) {       if (mask & (1 << i)) {         flips[x - 1][i] = 1;       }     }     for (int i = 0; i + 1 < x; ++i) {       for (int j = 0; j < x; ++j) {         flips[i + x][j] = flips[i][j] ^ flips[x - 1][j];       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j + 1 < x; ++j) {         flips[i][j + x] = flips[i][j] ^ flips[i][x - 1];       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         b[i][j] = a[i][j];         if (flips[i][j]) {           b[i][j] = -b[i][j];         }       }     }     int res = 0;     for (int i = 0; i < n; ++i) {       res += b[x - 1][i];     }     for (int i = 0; i + 1 < x; ++i) {       for (int j = 0; j < n; ++j) {         b[i][j] += b[i + x][j];       }     }     for (int i = 0; i + 1 < x; ++i) {       int cres1 = 0, cres2 = 0;       for (int j = 0; j + 1 < x; ++j) {         cres1 += abs(b[i][j] + b[i][j + x]);         cres2 += abs(b[i][j] - b[i][j + x]);       }       res += max(cres1 + b[i][x - 1], cres2 - b[i][x - 1]);     }     return res;   }   int solve(vector<vector<int> > a) {     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         ::a[i][j] = a[i][j];       }     }     x = (n + 1) / 2;     int res = -1000000000LL;     for (int i = 0; i < (1 << x); ++i) {       res = max(res, check(i));     }     return res;   }   int main() {     scanf( %d , &n);     vector<vector<int> > a(n, vector<int>(n));     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         scanf( %d , &a[i][j]);       }     }     cout << solve(a) << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long n, k;   long long S[1000000] = {};   int main() {     cin >> n >> k;     for (long long i = 0; i < n; i++) {       string s;       cin >> s;       S[s.size()]++;     }     string s;     cin >> s;     long long pass = s.size();     long long sum1 = 1, sum2 = 0;     for (long long i = 0; i < pass; i++) {       sum1 += S[i];       sum2 += S[i];     }     sum2 += S[pass];     cout << sum1 + ((sum1 - 1) / k) * 5 <<     << sum2 + ((sum2 - 1) / k) * 5          << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long exp(long long x, long long y, long long p) {     long long res = 1;     while (y) {       if (y % 2) res = (res * x % p) % p;       x = (x * x) % p;       y /= 2;     }     return res;   }   long long exp(long long x, long long y) {     long long res = 1;     while (y) {       if (y % 2) res = (res * x);       x = (x * x);       y /= 2;     }     return res;   }   long long a[100];   int main() {     long long n, m;     cin >> n >> m;     long long a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     if (n > m)       cout << 0 << endl;     else {       long long sum = 1;       for (long long i = 0; i < n; i++) {         for (long long j = i + 1; j < n; j++) {           sum = sum * abs(a[i] - a[j]);           sum = sum % m;         }       }       cout << sum % m;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 500010;   int A[N];   const int S = 250;   int sum[S][S];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int Q;     cin >> Q;     while (Q--) {       int t, x, y;       cin >> t >> x >> y;       if (t == 1) {         A[x] += y;         for (int m = 1; m < S; m++) {           sum[m][x % m] += y;         }       } else {         int ans = 0;         if (x < S) {           ans = sum[x][y];         } else {           for (int i = y; i < N; i += x) {             ans += A[i];           }         }         cout << ans <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {    public:     int x, y;     bool operator<(const Point &a) const {       if (x != a.x) return x < a.x;       return y < a.y;     }   } tem;   set<Point> p;   set<int> xSet;   set<int> ySet;   bool f() {     if (xSet.size() != 3 || ySet.size() != 3 || p.size() != 8) return false;     set<int>::iterator p1;     set<int>::iterator p2;     int cn = 0;     for (p1 = xSet.begin(); p1 != xSet.end(); p1++) {       for (p2 = ySet.begin(); p2 != ySet.end(); p2++) {         cn++;         if (cn == 5) continue;         tem.x = *p1;         tem.y = *p2;         if (p.find(tem) == p.end()) return false;       }     }     return true;   }   int main(int argc, char **argv) {     int i, a, b;     for (i = 0; i < 8; i++) {       scanf( %d%d , &a, &b);       tem.x = a;       tem.y = b;       xSet.insert(a);       ySet.insert(b);       p.insert(tem);     }     printf( %s n , (f() ?  respectable  :  ugly ));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     vector<int> b(n);     string aans = string(n / 2,  1 ) + string((n + 1) / 2,  0 );     string bans = string(n / 2,  1 ) + string((n + 1) / 2,  0 );     for (int i = 0; i < n; i++) {       cin >> a[i];       cin >> b[i];     }     if (n % 2) {       if (a[n / 2] < b[n / 2])         aans[n / 2] =  1 ;       else         bans[n / 2] =  1 ;     }     int bpoint = 0;     int apoint = 0;     for (int i = 0; i < n; i++) {       if (a[apoint] < b[bpoint]) {         aans[apoint] =  1 ;         apoint++;       } else {         bans[bpoint] =  1 ;         bpoint++;       }     }     cout << aans <<   n  << bans;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int dx[8] = {0, -1, 0, 1, -1, -1, 1, 1},             dy[8] = {1, 0, -1, 0, -1, 1, -1, 1};   int a[100005];   int cnt = 0;   int n, m, k;   vector<int> vt[100005], vt2[2];   stack<int> st;   int dfn[100005], color[100005];   void dfs(int x, int fa) {     st.push(x);     dfn[x] = st.size();     for (int i = 0; i < vt[x].size(); i++) {       int v = vt[x][i];       if (v == fa) continue;       if (!dfn[v]) {         dfs(v, x);       } else if (dfn[x] - dfn[v] + 1 <= k && dfn[x] > dfn[v]) {         cout << 2 << endl;         cout << dfn[x] - dfn[v] + 1 << endl;         while (1) {           cout << st.top() <<    ;           if (st.top() == v) {             exit(0);           }           st.pop();         }       }     }     st.pop();   }   void dfs2(int x, int fa, int co) {     vt2[co].push_back(x);     color[x] = co;     if (vt2[co].size() == k) {       for (int i = 0; i < vt2[co].size(); i++) {         cout << vt2[co][i] <<    ;       }       exit(0);     }     for (int i = 0; i < vt[x].size(); i++) {       int v = vt[x][i];       if (v == fa || color[v] != -1) continue;       dfs2(v, x, co ^ 1);     }   }   void solve() {     memset(color, -1, sizeof color);     cin >> n >> m >> k;     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       vt[x].push_back(y);       vt[y].push_back(x);     }     dfs(1, 0);     k = (k + 1) / 2;     cout << 1 << endl;     dfs2(1, 0, 0);   }   int main() {     ios::sync_with_stdio(0);     ;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   struct Edge {     int to, cap, flow;   };   struct Graph {     int n;     vector<vector<int> > e;     vector<Edge> edges;     vector<int> d, c;     Graph() {}     Graph(int _n) {       n = _n;       e.resize(n);     }     void addEdge(int from, int to, int cap) {       e[from].push_back(edges.size());       edges.push_back(Edge({to, cap, 0}));       e[to].push_back(edges.size());       edges.push_back(Edge({from, 0, 0}));     }     bool bfs() {       d.assign(n, INF);       c.assign(n, 0);       vector<int> q(n);       int qL = 0, qR = 0;       d[0] = 0;       q[qR++] = 0;       while (qL < qR) {         int v = q[qL++];         for (int i = 0; i < (int)e[v].size(); i++) {           Edge cur = edges[e[v][i]];           if (d[cur.to] > d[v] + 1 && cur.flow < cur.cap) {             d[cur.to] = d[v] + 1;             q[qR++] = cur.to;           }         }       }       return d[n - 1] != INF;     }     int dfs(int v, int flow) {       if (v == n - 1) return flow;       if (flow == 0) return 0;       for (int &i = c[v]; i < (int)e[v].size(); i++) {         Edge cur = edges[e[v][i]];         if (d[cur.to] != d[v] + 1) continue;         int pushed = dfs(cur.to, min(flow, cur.cap - cur.flow));         if (pushed > 0) {           edges[e[v][i]].flow += pushed;           edges[e[v][i] ^ 1].flow -= pushed;           return pushed;         }       }       return 0;     }     long long flow() {       long long flow = 0;       while (bfs()) {         while (int pushed = dfs(0, INF)) {           flow += pushed;         }       }       return flow;     }   };   int main() {     int n, m, h;     while (cin >> n >> h >> m) {       vector<int> l(m), r(m), x(m), c(m);       for (int i = 0; i < m; i++) {         cin >> l[i] >> r[i] >> x[i] >> c[i];         x[i]++;         l[i]--;         r[i]--;       }       Graph gr(1 + n * (h + 1) + m + 1);       int sz = gr.n;       long long sum = 0;       for (int i = 0; i < n; i++) {         for (int j = 1; j <= h; j++) {           gr.addEdge(1 + i * (h + 1) + (j - 1), 1 + i * (h + 1) + j, INF);           gr.addEdge(1 + i * (h + 1) + j, sz - 1, 2 * j - 1);           sum += 2 * j - 1;         }       }       for (int i = 0; i < m; i++) {         if (x[i] > h) continue;         for (int t = l[i]; t <= r[i]; t++) {           gr.addEdge(1 + n * (h + 1) + i, 1 + t * (h + 1) + x[i], INF);         }         gr.addEdge(0, 1 + n * (h + 1) + i, c[i]);       }       cout << sum - gr.flow() << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int cnt = 0;     while (n--) {       int p, q;       cin >> p >> q;       if ((q - p) >= 2) cnt++;     }     cout << cnt <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   char s[4005], t[4005], ax[4005];   int main() {     scanf( %s%s , s, t);     int n = strlen(s), m = strlen(t), ret = m;     for (int i = n - 1; i >= 0; i--) s[i + m] = s[i], s[i] = 0;     n += m;     for (int i = 0; i < n; i++) {       int ct = 0;       for (int j = 0; j < m; j++) {         if (i + j >= n || s[i + j] != t[j]) ct++;       }       ret = min(ret, ct);       ct = 0;       for (int j = 0; j < m; j++) {         if (i - j < 0 || s[i - j] != t[m - 1 - j]) ct++;       }       ret = min(ret, ct);     }     printf( %d n , ret);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1000000007;   const int MM = 998244353;   const long double PI = acos(-1);   const long long INF = 2e18;   template <typename T, typename T1>   void amax(T &a, T1 b) {     if (b > a) a = b;   }   template <typename T, typename T1>   void amin(T &a, T1 b) {     if (b < a) a = b;   }   long long power(long long b, long long e) {     if (e == 0) return 1;     if (e & 1) return b * power(b * b, e / 2);     return power(b * b, e / 2);   }   long long power(long long b, long long e, long long m) {     if (e == 0) return 1;     if (e & 1) return b * power(b * b % m, e / 2, m) % m;     return power(b * b % m, e / 2, m);   }   long long modinv(long long a, long long m) { return power(a, m - 2, m); }   int TLE_TERROR() {     long long n, p, f = 0, zz = -1;     cin >> n >> p;     string s;     cin >> s;     if (p == 1) {       cout <<  NO ;       return 0;     }     if (p == 2) {       if (n > 2)         cout <<  NO ;       else if (n == 1) {         if (s[0] ==  a )           cout <<  b ;         else           cout <<  NO ;       } else {         if (s ==  ab )           cout <<  ba ;         else           cout <<  NO ;       }       return 0;     }     for (long long i = n - 1; i >= 0; i--) {       char z = s[i];       while ((z -  a  + 1) < p) {         z++;         if (i > 0 && z == s[i - 1]) continue;         if (i > 1 && z == s[i - 2]) continue;         long long q = n - i;         s[i] = z;         f = 1;         zz = i;         break;       }       if (f == 1) break;     }     if (f == 0)       cout <<  NO ;     else {       for (long long i = zz + 1; i < n; i++) {         if (i > 1) {           if (s[i - 1] !=  a  && s[i - 2] !=  a )             s[i] =  a ;           else if (s[i - 1] !=  b  && s[i - 2] !=  b )             s[i] =  b ;           else             s[i] =  c ;         } else {           if (s[i - 1] !=  a )             s[i] =  a ;           else if (s[i - 1] !=  b )             s[i] =  b ;           else             s[i] =  c ;         }       }       cout << s;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int TESTS = 1;     while (TESTS--) TLE_TERROR();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;     point() : x(0), y(0) {}     point(int x, int y) : x(x), y(y) {}     point operator-(const point& p) const { return point(x - p.x, y - p.y); }     int dot(const point& p) const { return x * p.x + y * p.y; }     int cross(const point& p) const { return x * p.y - y * p.x; }   };   istream& operator>>(istream& is, point& p) { return is >> p.x >> p.y; }   bool pointInSegment(const point& a, const point& b, const point& p) {     return (p - a).cross(b - a) == 0 && (a - p).dot(b - p) <= 0;   }   bool pointInPerimeter(const vector<point>& P, const point& p) {     int n = P.size();     for (int i = 0; i < n; i++) {       if (pointInSegment(P[i], P[(i + 1) % n], p)) {         return true;       }     }     return false;   }   bool crossesRay(const point& a, const point& b, const point& p) {     return ((b.y >= p.y) - (a.y >= p.y)) * (a - p).cross(b - p) >= 0;   }   bool pointInPolygon(const vector<point>& P, const point& p) {     if (pointInPerimeter(P, p)) {       return true;     }     int n = P.size();     int rays = 0;     for (int i = 0; i < n; i++) {       rays += crossesRay(P[i], P[(i + 1) % n], p);     }     return rays & 1;   }   int sgn(int x) {     if (x > 0) return 1;     if (x < 0) return -1;     return 0;   }   int intersectSegmentsInfo(const point& a, const point& b, const point& c,                             const point& d) {     point v1 = b - a, v2 = d - c;     int t = sgn(v1.cross(c - a)), u = sgn(v1.cross(d - a));     if (t == u) {       if (t == 0) {         if (pointInSegment(a, b, c) || pointInSegment(a, b, d) ||             pointInSegment(c, d, a) || pointInSegment(c, d, b)) {           return -1;         } else {           return 0;         }       } else {         return 0;       }     } else {       return sgn(v2.cross(a - c)) != sgn(v2.cross(b - c));     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     vector<point> a(4), b(4);     for (point& p : a) cin >> p;     for (point& p : b) cin >> p;     bool ans = false;     for (const point& p : a) {       ans = ans | pointInPolygon(b, p);     }     for (const point& p : b) {       ans = ans | pointInPolygon(a, p);     }     for (int i = 0; i < 4; ++i) {       for (int j = 0; j < 4; ++j) {         ans = ans | (intersectSegmentsInfo(a[i], a[(i + 1) % 4], b[j],                                            b[(j + 1) % 4]) != 0);       }     }     cout << (ans ?  YES  :  NO ) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s1, s2;     int flag = 0, f = 0;     cin >> s1 >> s2;     int l = s1.length();     for (int i = 0; i < l; i++) {       if (s1[i] <  a ) {         s1[i] += 32;       }       if (s2[i] <  a ) s2[i] += 32;       if (s1[i] != s2[i]) {         f = i;         flag = 1;         break;       }     }     if (flag == 0)       cout <<  0 ;     else {       if (s1[f] > s2[f])         cout <<  1 ;       else         cout <<  -1 ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, f[33];   double ans = 0;   vector<int> v[33];   string s;   template <class T>   ostream& operator<<(ostream& out, vector<T> v) {     out << v.size() <<   n ;     for (auto e : v) out << e <<    ;     return out;   }   double check(int k) {     double ans = 0, local;     for (int i = 0; i < n; i++) {       memset(f, 0, sizeof f);       for (auto j : v[k]) {         f[s[(j + i) % n] -  a ]++;       }       local = 0;       for (int i = 0; i <=  z  -  a ; i++)         if (f[i] == 1) local += (double)1. / v[k].size();       ans = max(ans, local);     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> s;     n = s.size();     for (int i = 0; i < s.size(); i++) v[s[i] -  a ].push_back(i);     for (int i = 0; i <=  z  -  a ; i++) {       ans += ((double)v[i].size() / n) * check(i);     }     cout << fixed << setprecision(13) << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);   string to_string(const string& s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (int i = 0; i < static_cast<int>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   long long sqr(long long n) { return n * n; }   long long binpow(long long a, long long n) {     if (n == 0) return 1;     if (n % 2 != 0)       return binpow(a, n - 1) * a;     else {       long long b = binpow(a, n / 2);       return b * b;     }   }   long long gcd(long long a, long long b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   int n;   vector<string> v;   string ans;   bool check(string s1, string s2) {     string s = s1 + s2.substr(n - 2);     multiset<string> v1, pref, suff;     for (int i = 0; i < n - 1; i++) {       pref.insert(s.substr(0, n - i - 1));       v1.insert(s.substr(0, n - i - 1));       suff.insert(s.substr(i + 1));       v1.insert(s.substr(i + 1));     }     if (v1 == multiset<string>(v.begin(), v.end())) {       for (int i = 0; i < 2 * n - 2; i++) {         if (pref.count(v[i])) {           ans +=  P ;           pref.erase(v[i]);         } else if (suff.count(v[i])) {           ans +=  S ;           suff.erase(v[i]);         } else {           ans =   ;           return false;         }       }       return true;     }     return false;   }   void solve() {     cin >> n;     v = vector<string>(2 * n - 2);     string mx1 =   , mx2 =   ;     for (int i = 0; i < 2 * n - 2; i++) {       cin >> v[i];       if (v[i].size() == n - 1 && mx1.size() == 0)         mx1 = v[i];       else if (v[i].size() == n - 1 && mx2.size() == 0)         mx2 = v[i];     }     if (check(mx1, mx2))       cout << ans << endl;     else {       check(mx2, mx1);       cout << ans << endl;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c, d, i, e, f, g, n, m, k, l, A[500005], B[500005], fix[500005],       root, ans, C[500005];   vector<long long> v[500005];   void dfs(long long x, long long y) {     for (long long i = 0; i < v[x].size(); i++) {       if (v[x][i] == y) continue;       dfs(v[x][i], x);       if (fix[v[x][i]] == 0) C[x]++;     }     if (C[x] == 0) return;     root = x;     fix[x] = 1;     for (long long i = 0; i < v[x].size(); i++) {       if (v[x][i] == y) continue;       if (fix[v[x][i]] == 1) continue;       fix[v[x][i]] = 1;       swap(A[B[root]], A[B[v[x][i]]]);       ans += 2;       a = B[root];       B[root] = B[v[x][i]];       B[v[x][i]] = a;       root = v[x][i];     }   }   int main() {     cin >> n;     for (long long i = 1; i <= n; i++) {       A[i] = i;       B[i] = i;     }     for (long long i = 1; i < n; i++) {       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     dfs(1, 0);     if (fix[1] == 0) {       a = v[1][0];       swap(A[1], A[B[v[1][0]]]);       ans += 2;     }     cout << ans << endl;     for (long long i = 1; i <= n; i++) cout << A[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 101;   int n, m;   struct price {     int p;     int au;     bool operator<(const price &rhs) const {       if (au == rhs.au) return p > rhs.p;       return au < rhs.au;     }   } price[MAX_N];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %d , &price[i].p);     }     for (int i = 0; i < m; ++i) {       int x;       scanf( %d , &x);       price[x].au = 1;     }     sort(price + 1, price + n + 1);     long long ans = 0;     for (int i = 1; i <= n; ++i) {       if (price[i].au == 0) {         ans += price[i].p;       } else {         if (ans > price[i].p)           ans *= 2;         else           ans += price[i].p;       }     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int N = 2e5 + 6;   int cnt[666], dp[777][777];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int _, n;     cin >> _;     while (_--) {       cin >> n;       for (int i = 0; i <= n - 1; i++) cin >> cnt[i];       for (int i = 0; i <= n; i++)         for (int j = 0; j <= n * 2; j++) dp[i][j] = 1e9;       sort(cnt, cnt + n);       int ans = 1e9;       dp[0][0] = 0;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n * 2; j++) {           for (int k = 0; k <= j - 1; k++) {             dp[i][j] = min(dp[i - 1][k] + abs(cnt[i - 1] - j), dp[i][j]);             if (n - i == 0) ans = min(ans, dp[i][j]);           }         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool calculate_digits(int a) {     int sum = 0;     while (a > 0) {       sum += (a % 10);       a = a / 10;     }     if (sum % 4 == 0) {       return true;     } else {       return false;     }   }   int main() {     int a;     cin >> a;     for (int i = a; i <= a + 10; i++) {       if (calculate_digits(i)) {         cout << i << endl;         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, res = 0;     cin >> n >> k;     vector<int> arrAB;     vector<int> arrA;     vector<int> arrB;     for (int i = 0; i < n; i++) {       int time, a, b;       cin >> time >> a >> b;       if (a == 1 && b == 1) {         arrAB.push_back(time);       } else if (a == 1) {         arrA.push_back(time);       } else if (b == 1) {         arrB.push_back(time);       }     }     sort(arrA.begin(), arrA.end());     sort(arrB.begin(), arrB.end());     for (int i = 0; i < arrA.size() && i < arrB.size(); i++) {       arrAB.push_back(arrA[i] + arrB[i]);     }     sort(arrAB.begin(), arrAB.end());     if (arrAB.size() < k)       cout <<  -1  << endl;     else {       for (int i = 0; i < k; i++) res += arrAB[i];       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int max_n = 100000;   int n, k;   char s[max_n + 5];   void solve(void);   int main(void) {     int t;     scanf( %d , &t);     while (t--) solve();     return 0;   }   void solve(void) {     scanf( %d%d , &n, &k);     scanf( %s , s);     int i, j, t, ans = 0;     int lcnt = 0;     for (i = 0; i < n; i++) {       if (s[i] ==  W ) {         if (i > 0 && s[i - 1] ==  W )           ans += 2;         else           ans++;       } else         lcnt++;     }     if (lcnt == n) {       if (!k)         printf( 0 n );       else         printf( %d n , 2 * k - 1);       return;     }     i = 0;     vector<int> gap;     while (i < n) {       if (s[i] ==  L ) {         i++;         continue;       }       j = i;       while (j < n && s[j] ==  W ) j++;       t = j;       while (t < n && s[t] ==  L ) t++;       if (t >= n) break;       gap.push_back(t - j);       i = t;     }     sort(gap.begin(), gap.end());     for (i = 0; k && i < (int)gap.size(); i++) {       if (gap[i] <= k) {         k -= gap[i];         lcnt -= gap[i];         ans += 2 * gap[i] + 1;       } else {         lcnt -= k;         ans += 2 * k;         k = 0;       }     }     if (k) {       ans += min(k, lcnt) * 2;     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     cin >> a;     string s;     cin >> s;     int x = 0;     for (int i = 0; i < a - 1; i++) {       if (s[i] > s[i + 1]) {         cout <<  YES  << endl;         cout << i + 1 <<     << i + 2;         return 0;       }     }     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, p, q, r;     cin >> n >> p >> q >> r;     long long int a[n], ans = LLONG_MIN;     for (long long int i = 0; i < n; i++) cin >> a[i];     long long int prefixMax[n], suffixMax[n];     prefixMax[0] = p * a[0];     suffixMax[n - 1] = r * a[n - 1];     for (long long int i = 1; i < n; i++)       prefixMax[i] = max(prefixMax[i - 1], p * a[i]);     for (long long int i = n - 2; i >= 0; i--)       suffixMax[i] = max(suffixMax[i + 1], r * a[i]);     for (long long int i = 0; i < n; i++) {       ans = max(ans, prefixMax[i] + suffixMax[i] + (q * a[i]));     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const double PI = 3.141592653589793;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   struct Pt {     double x, y;     Pt(double a = 0, double b = 0) : x(a), y(b) {}     bool operator==(const Pt& p) const { return p.x == x && p.y == y; }     bool operator<(const Pt& p) const { return x == p.x ? y > p.y : x < p.x; }     Pt operator-(const Pt& p) const { return {x - p.x, y - p.y}; }     Pt operator+(const Pt& p) const { return {x + p.x, y + p.y}; }     Pt operator/(const double c) const { return {x / c, y / c}; }     Pt operator*(const double c) const { return {x * c, y * c}; }     Pt vetor(const Pt& o) const { return o - (*this); }     double dot(const Pt& b) const { return (x * b.x) + (y * b.y); }     double sq() const { return (x * x) + (y * y); }     double dist(const Pt& b) { return sqrt((b - *this).sq()); }     double cross(const Pt& b) const { return (x * b.y) - (y * b.x); }     double cross(const Pt& a, const Pt& b) const {       return (a - *this).cross(b - *this);     }     double angle(Pt& a, Pt& b) const {       a = vetor(a), b = vetor(b);       return acos(1.0 * a.dot(b) / sqrt(1.0 * a.dot(a) * b.dot(b)));     }   } pts[101000];   Pt obj;   Pt perp(Pt p) { return {-p.y, p.x}; }   ostream& operator<<(ostream& os, Pt p) {     return os <<  (  << p.x <<  ,  << p.y <<  ) ;   }   template <typename F>   int sgn(F x) {     return (F(0) < x) - (x < F(0));   }   struct Line {     double A, B, C;     Line() {}     Line(const Pt& de, const Pt& pa) {       A = de.y - pa.y;       B = pa.x - de.x;       C = -A * de.x - B * de.y;     }   };   bool mORe(double a, double b) { return a <= b || fabs(a - b) <= EPS; }   struct Seg {     Pt A, B;     Seg() {}     Seg(Pt a, Pt b) : A(a), B(b) {       if (B < A) swap(A, B);     }     bool inDouble(const Pt& Pt) {       return mORe(min(A.x, B.x), Pt.x) && mORe(Pt.x, max(A.x, B.x)) &&              mORe(min(A.y, B.y), Pt.y) && mORe(Pt.y, max(A.y, B.y));     }     bool inter(Seg& o, Pt& res) {       Line l1 = Line(A, B), l2 = Line(o.A, o.B);       double dx = Pt(l1.C, l1.B).cross(Pt(l2.C, l2.B));       double dy = Pt(l1.A, l1.C).cross(Pt(l2.A, l2.C));       double d = Pt(l1.A, l1.B).cross(Pt(l2.A, l2.B));       if (d == 0) return false;       res = Pt(-dx / d, -dy / d);       if (!inDouble(res) || !o.inDouble(res)) return false;       return true;     }   };   int n, p, q;   void solve() {     vector<Pt> chain;     int sz = 0;     for (int i = 0; i < n; i++) {       while (sz >= 2 && chain[sz - 2].cross(chain[sz - 1], pts[i]) >= 0)         chain.pop_back(), sz--;       chain.emplace_back(pts[i]);       sz++;     }     vector<Seg> linhas;     for (int i = 1; i < chain.size(); i++) {       linhas.emplace_back(chain[i - 1], chain[i]);     }     Seg teste = {Pt(0, 0), obj * 1000002.0};     for (Seg linha : linhas) {       Pt res;       if (linha.inter(teste, res)) {         printf( %.12f n , max(obj.x / res.x, obj.y / res.y));         return;       }     }   }   int main() {     scanf( %d%d%d , &n, &p, &q);     obj = {(double)p, (double)q};     int x, y;     int maxx = 0, maxy = 0;     for (int i = 0; i < n; i++) {       scanf( %d%d , &x, &y);       pts[i] = {(double)x, (double)y};       maxx = max(maxx, x);       maxy = max(maxy, y);     }     pts[n] = {0.0, (double)maxy};     pts[n + 1] = {(double)maxx, 0.0};     n += 2;     sort(pts, pts + n);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     while (cin >> a >> b >> c >> d) {       cout << (((a ^ b) & (c | d)) ^ ((b & c) | (a ^ d))) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void exgcd(int a, int b, int *x, int *y) {     if (b) {       exgcd(b, a % b, y, x);       (*y) = (*y) - (a / b) * (*x);     } else       *x = 1, *y = 0;   }   int main() {     std::ios::sync_with_stdio(false);     double r1, r2, c1, c2, d1, d2;     cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;     double a, b, c, d;     b = (r1 + c2 - d1) / 2.0;     a = r1 - b;     d = c2 - b;     c = d2 - b;     if ((int)a == a && (int)b == b && (int)c == c && (int)d == d && a + b == r1 &&         c + d == r2 && a + d == d1 && c + b == d2 && a + c == c1 && b + d == c2) {       set<int> temp;       temp.insert(a);       temp.insert(b);       temp.insert(c);       temp.insert(d);       if (temp.size() == 4 && *(temp.begin()) > 0 && *(temp.rbegin()) < 10) {         cout << (int)a <<     << (int)b << endl;         cout << (int)c <<     << (int)d << endl;       } else         cout << -1;     } else       cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int x, y, id;   };   bool operator<(const Node &s, const Node &t) {     if (s.x != t.x)       return s.x < t.x;     else       return s.y < t.y;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     vector<Node> vn;     vector<int> ans;     set<int> se;     for (int i = 0; i < m; i++) {       Node no;       scanf( %d%d , &(no.x), &(no.y));       no.id = i + 1;       vn.push_back(no);     }     sort(vn.begin(), vn.end());     for (int i = 0; i < n; i++) se.insert(i);     for (int i = 0; i < m; i++) {       set<int>::iterator it = se.lower_bound(n - vn[i].y);       if (it == se.end()) continue;       if (*it < vn[i].x) {         se.erase(it);         ans.push_back(vn[i].id);       }     }     sort(ans.begin(), ans.end());     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }   long long power(long long a, long long n) {     long long p = 1;     while (n > 0) {       if (n % 2) {         p = p * a;       }       n >>= 1;       a *= a;     }     return p;   }   long long power(long long a, long long n, long long mod) {     long long p = 1;     while (n > 0) {       if (n % 2) {         p = p * a;         p %= mod;       }       n >>= 1;       a *= a;       a %= mod;     }     return p % mod;   }   using namespace std;   int a[100004], b[100004], c[100004];   vector<int> p;   void sieve() {     int i, j;     for (i = 2; i * i <= 100000; i++)       if (!b[i])         for (j = i * i; j <= 100000; j += i) b[j] = 1;     for (i = 2; i <= 100000; i++)       if (!b[i]) p.push_back(i);   }   int main() {     int i, j;     int n;     sieve();     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     int x, y;     for (i = 0; i < n; i++) {       x = a[i];       for (j = 0; p[j] * p[j] <= a[i]; j++) {         if (x % p[j] == 0) c[p[j]]++;         while (x % p[j] == 0) x = x / p[j];       }       if (x > 1) c[x]++;     }     x = 1;     for (i = 0; i < p.size(); i++) x = max(x, c[p[i]]);     printf( %d n , x);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string str1, str2;   int main() {     cin >> str1 >> str2;     if (str1 == str2)       cout << str1;     else       puts( 1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = unsigned long long;   ll a[5], b[5], c[5], d[5], fl, k, cnt, vis[10];   set<pair<ll, ll> > st;   map<pair<ll, ll>, ll> mp;   vector<ll> G[10];   set<ll> stt;   void dfs(ll u = 1, ll par = -1) {     vis[u] = 1;     cnt++;     for (ll v : G[u]) {       if (par == v) continue;       if (vis[v]) return;       dfs(v, u);     }   }   int main() {     while (cin >> a[0] >> b[0] >> c[0] >> d[0]) {       st.clear();       stt.clear();       for (int i = 1; i < 4; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];       fl = 1;       for (int i = 0; i < 4; i++) {         if (a[i] != c[i] && b[i] != d[i]) fl = 0;       }       k = 0;       for (int i = 0; i < 10; i++) G[i].clear();       for (int i = 0; i < 10; i++) vis[i] = 0;       for (int i = 0; i < 4; i++) {         if (mp.find({a[i], b[i]}) == mp.end()) {           mp[{a[i], b[i]}] = ++k;         }         if (mp.find({c[i], d[i]}) == mp.end()) {           mp[{c[i], d[i]}] = ++k;         }         st.insert({a[i], b[i]});         st.insert({c[i], d[i]});         G[mp[{a[i], b[i]}]].push_back(mp[{c[i], d[i]}]);         G[mp[{c[i], d[i]}]].push_back(mp[{a[i], b[i]}]);       }       if (st.size() != 4) fl = 0;       for (int i = 0; i < 4; i++) {         stt.insert((a[i] - c[i]) * (a[i] - c[i]) + (b[i] - d[i]) * (b[i] - d[i]));       }       if (stt.size() > 2) fl = 0;       cnt = 0;       dfs();       if (cnt != 4) fl = 0;       puts(fl ?  YES  :  NO );     }   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int d, n, c, ans, m;     string arr[105];     cin >> n >> d;     ans = 0;     m = 0;     for (int i = 0; i < d; i++) {       cin >> arr[i];       c = 0;       for (int j = 0; j < n; j++) {         if (arr[i][j] ==  1 ) c++;       }       if (c < n)         m++;       else         m = 0;       if (m > ans) ans = m;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   int get_inv(int x) {     return (x == 1) ? 1 : (mod - (long long)(mod / x) * get_inv(mod % x) % mod);   }   const int MaxN = 200010, MaxT = 1 << 19;   struct tree_node {     int k, sum;     int lazy;     tree_node() { k = lazy = 1; }   } T[MaxT];   int v[MaxN], deg[MaxN];   class Graph {    public:     int en[MaxN], next[MaxN], point[MaxN], tot;     void add_edge(int x, int y) {       next[++tot] = en[x];       en[x] = tot;       point[tot] = y;     }   } G;   int in[MaxN], out[MaxN];   int n, q;   int dfn;   void dfs(int now) {     in[now] = ++dfn;     for (int i = G.en[now]; i; i = G.next[i]) dfs(G.point[i]);     out[now] = dfn;   }   inline int mul(int &x, int v) { return (x = (long long)x * v % mod); }   inline int inc(int x, int v) {     x += v;     return x >= mod ? x - mod : x;   }   void add_lazy(int now, int lazy) {     mul(T[now].lazy, lazy);     mul(T[now].k, lazy);     mul(T[now].sum, lazy);   }   void push_down(int now) {     if (T[now].lazy != 1) {       add_lazy(now << 1, T[now].lazy);       add_lazy(now << 1 | 1, T[now].lazy);       T[now].lazy = 1;     }   }   void update(int now) { T[now].sum = inc(T[now << 1].sum, T[now << 1 | 1].sum); }   void modify_v(int l, int r, int x, int v, int now) {     if (l == r) {       T[now].sum = 1ll * T[now].k * v % mod;       return;     }     int mid = (l + r) >> 1;     push_down(now);     if (x <= mid)       modify_v(l, mid, x, v, now << 1);     else       modify_v(mid + 1, r, x, v, now << 1 | 1);     update(now);   }   void modify_k(int l, int r, int x, int y, int k, int now) {     if ((r < x) || (y < l)) return;     if ((x <= l) && (r <= y)) return add_lazy(now, k);     int mid = (l + r) >> 1;     push_down(now);     modify_k(l, mid, x, y, k, now << 1);     modify_k(mid + 1, r, x, y, k, now << 1 | 1);     update(now);   }   int query_k(int l, int r, int x, int now) {     if (l == r) return T[now].k;     int mid = (l + r) >> 1;     push_down(now);     if (x <= mid)       return query_k(l, mid, x, now << 1);     else       return query_k(mid + 1, r, x, now << 1 | 1);   }   int query_sum(int l, int r, int x, int y, int now) {     if ((r < x) || (y < l)) return 0;     if ((x <= l) && (r <= y)) return T[now].sum;     int mid = (l + r) >> 1;     push_down(now);     return inc(query_sum(l, mid, x, y, now << 1),                query_sum(mid + 1, r, x, y, now << 1 | 1));   }   void debug() {     for (int i = 1; i <= 17; ++i)       printf( %d: %d %d %d n , i, T[i].sum, T[i].k, T[i].lazy);   }   int main() {     static int type[MaxN], f[MaxN], u[MaxN];     scanf( %d%d , v + 1, &q);     n = 1;     for (int i = 1; i <= q; ++i) {       scanf( %d , type + i);       if (type[i] == 1) {         u[i] = ++n;         scanf( %d%d , &f[n], &v[n]);         G.add_edge(f[n], n);       } else         scanf( %d , u + i);     }     dfs(1);     modify_v(1, n, in[1], v[1], 1);     deg[1] = 1;     for (int i = 1; i <= q; ++i)       if (type[i] == 2) {         int ans = query_sum(1, n, in[u[i]], out[u[i]], 1), k;         if (u[i] == 1)           k = 1;         else           k = query_k(1, n, in[f[u[i]]], 1);         ans = (long long)ans * get_inv(k) % mod;         printf( %d n , ans);       } else {         int k = (long long)(deg[f[u[i]]] + 1) * get_inv(deg[f[u[i]]]) % mod;         ++deg[f[u[i]]];         modify_k(1, n, in[f[u[i]]], out[f[u[i]]], k, 1);         deg[u[i]] = 1;         modify_v(1, n, in[u[i]], v[u[i]], 1);       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[500005], cmd[500005];   int baam[500005], daan[500005], jora[500005];   int n, m, pos;   long long bit[500005];   void update(int l, int r) {     bit[l] += 1;     bit[r + 1] -= 1;   }   void moveLeft() {     if (baam[pos] > 0 && baam[pos] <= n) pos = baam[pos];     return;   }   void moveRight() {     if (daan[pos] > 0 && daan[pos] <= n) pos = daan[pos];     return;   }   void deleteNode() {     int nextPos, L, R;     L = min(pos, jora[pos]);     R = max(pos, jora[pos]);     if (daan[R] <= n)       pos = daan[R];     else       pos = baam[L];     daan[baam[L]] = daan[R];     baam[daan[R]] = baam[L];     update(L, R);     return;   }   int main() {     scanf( %d %d %d , &n, &m, &pos);     getchar();     for (int i = 1; i <= n; i++) scanf( %c , &str[i]);     getchar();     stack<int> st;     for (int i = 1; i <= n; i++) {       if (str[i] ==  ( )         st.push(i);       else {         jora[i] = st.top();         jora[st.top()] = i;         st.pop();       }     }     for (int i = 1; i <= n; i++) {       baam[i] = i - 1;       daan[i] = i + 1;     }     scanf( %s , cmd);     for (int i = 0; cmd[i]; i++) {       if (cmd[i] ==  L )         moveLeft();       else if (cmd[i] ==  R )         moveRight();       else         deleteNode();     }     for (int i = 1; i <= n; i++) bit[i] += bit[i - 1];     for (int i = 1; i <= n; i++) {       if (!bit[i]) printf( %c , str[i]);     }     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int maxn = 2e5 + 10;   int n;   int d[maxn];   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       d[u]++;       d[v]++;     }     for (int i = 1; i <= n; i++) {       if (d[i] == 2) {         puts( NO );         return 0;       }     }     puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     vector<long long int> v;     unordered_map<long long int, long long int> mapy;     v.push_back(0);     v.push_back(2);     mapy[2] = 1;     for (long long int i = 2; i <= 100000; i++) {       v.push_back(((3 * (i * (i + 1))) / 2) - i);       mapy[(((3 * (i * (i + 1))) / 2) - i)] = 1;     }     while (t--) {       long long int n;       cin >> n;       ;       long long int c = 0;       while (n > 1) {         auto f = lower_bound(v.begin(), v.end(), n);         if (mapy[n] == 1) {           c++;           break;         }         long long int hj = f - v.begin();         hj--;         n -= v[hj];         c++;       }       cout << c << endl;     }   }