#include <iostream>   #include <vector>   #include <set>   #include <algorithm>   using namespace std;   typedef long long ll;   typedef pair<ll, ll> P;   const int maxn = 105;   int n, m, k;   vector<set<int>> mp(maxn);   vector<int> g, ans;   int vis[maxn], pre[maxn], pres[maxn][maxn*maxn];   ll dp[maxn][maxn*maxn];   P query[maxn];   int c = 0;   bool found(int u, int t){       vis[u] = t;       for(set<int>::iterator i = mp[u].begin(); i != mp[u].end(); i++){           int v = *i;           if(vis[v] == t)    continue;           vis[v] = t;           if(pre[v] == 0 || found(pre[v], t)){               pre[v] = u;               return true;           }       }       return false;   }   int main(){    scanf( %d%d%d , &n, &m, &k);    for(int i = 1; i <= m; i++){     int u, v;     scanf( %d%d , &u, &v);     mp[u].insert(v+n);    }    for(int i = 1; i <= k; i++){     scanf( %lld%lld , &query[i].first, &query[i].second);    }    for(int i = 1; i <= n; i++){     if(found(i, i)) c++;     }    for(int i = c; i >= 1; i--){     if(i == 1)       int a = 1;     int now;     static vector<set<int>> _mp;     _mp = mp;          for(int j = 1; j <= n; j++){      int cnt = 0;      mp = _mp;      mp[j].clear();      if(i == 1 && j == 1){       int a = 1;      }      for(int i = 1; i <= 2*n; i++) vis[i] = pre[i] = 0;      for(int k = 1; k <= n; k++){       if(found(k, k)) cnt++;       }      if(cnt < i) now = j;      mp = _mp, cnt = 0;      for(int k = 1; k <= n; k++){       mp[k].erase(j+n);      }      for(int i = 1; i <= 2*n; i++) vis[i] = pre[n+i] = 0;      for(int k = 1; k <= n; k++){       if(found(k, k)) cnt++;       }      if(cnt < i) now = -j;     }     mp = _mp;     if(now < 0){      for(int k = 1; k <= n; k++){       mp[k].erase(-now+n);      }     }else{      mp[now].clear();     }     g.push_back(now);    }    reverse(g.begin(), g.end());    for(int i = 0; i <= c; i++) dp[0][i] = -1e9-7;    dp[0][c] = 0;    for(int i = 0; i < k; i++){     for(int j = 0; j <= c; j++) dp[i+1][j] = -1e9-7;     for(int j = 0; j <= c; j++){      if(dp[i][j] == -1e18-7) continue;      for(int h = 0; h <= j; h++){       if(i + 1 + h >= n) break;       int t = j - h;       ll add = max(0ll, query[i+1].first - t * query[i+1].second);       if(dp[i+1][h] < dp[i][j] + add){        dp[i+1][h] = dp[i][j] + add;        pres[i+1][h] = j;       }      }     }    }    int index = max_element(dp[k], dp[k]+c+1) - dp[k];    for(int i = k; i >= 1; i--){     int cnt = pres[i][index];     ans.push_back(0);     for(int j = index; j < cnt; j++){      ans.push_back(g.back());       g.pop_back();      }     index = cnt;    }    printf( %d n , ans.size());    for(int i = ans.size() - 1; i >= 0; i--){     printf( %d  , ans[i]);    }    return 0;   }


#include <bits/stdc++.h>   int CH, NEG;   template <typename TP>   inline void read(TP& ret) {     ret = NEG = 0;     while (CH = getchar(), CH <  ! )       ;     if (CH ==  - ) NEG = true, CH = getchar();     while (ret = ret * 10 + CH -  0 , CH = getchar(), CH >  ! )       ;     if (NEG) ret = -ret;   }   int n, data[200010LL], id[200010LL], rank[200010LL], val[200010LL];   inline bool cmp(const int& a, const int& b) { return data[a] < data[b]; }   int main() {     int m, i, p, q, l, d, r;     bool unord;     read(n), read(m);     unord = false, data[0] = -2000000001LL;     for (i = (1); i <= (n); i++)       if (read(data[i]), id[i] = i, data[i - 1] > data[i]) unord = true;     if (unord) std::sort(id + 1, id + n + 1, cmp);     for (i = (1); i <= (n); i++) rank[id[i]] = i, val[i] = data[id[i]];     val[n + 1] = 2000000001LL;     while (m-- > 0) {       read(p), read(l), p = rank[p];       q = std::upper_bound(val, val + n + 2, val[p] + l) - val - 1;       l -= val[q] - val[p], p = q, d = -1;       while (true) {         if (d == 1)           q = std::upper_bound(val + 1, val + n + 2, val[p] + l * d) - val - 1;         else           q = std::lower_bound(val + 1, val + n + 2, val[p] + l * d) - val;         if (p == q) break;         if (r = std::abs(val[p] - val[q]), (l / r) & 1) p = q, d = -d;         l %= r;       }       printf( %d n , id[p]);     }     getchar(), getchar();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k, tlen = 0, dir, i;     string temp;     cin >> n >> m >> k;     cin >> temp >> temp;     if (temp ==  head )       dir = -1;     else       dir = 1;     cin >> temp;     if (m < k)       m = 1;     else       m = n;     for (i = 0; i < temp.size(); ++i) {       if (k == 1)         dir = 1;       else if (k == n)         dir = -1;       k += dir;       if (temp[i] !=  1 ) {         if (k == m) {           cout <<  Controller   << i + 1;           return 0;         }       } else {         if (dir == -1)           m = n;         else           m = 1;       }     }     cout <<  Stowaway ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> factors(long long n) {     vector<long long> first;     long long tem = 1;     for (long long x = 2; x * x <= n; x++) {       while (n % x == 0) {         first.push_back(x);         n /= x;       }     }     if (n > 1) first.push_back(n);     return first;   }   long long stringToint(string str) {     int num = stoi(str);     return num;   }   int hamming(int a, int b) { return __builtin_popcount(a ^ b); }   bool cmp(int a, int b) { return a > b; }   void reset() {     for (int i = 0; i < 200000 + 100; i++) {     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, d;     while (cin >> n >> d) {       int m;       cin >> m;       for (int i = 0, x, y; i < m; i++) {         cin >> x >> y;         if (abs(x - y) >= 0 && abs(x - y) <= d && x + y <= n + n - d &&             x + y >= d && (x + y != 0 || x - y != 0))           cout <<  YES n ;         else           cout <<  NO n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     return b ? gcd(b, a % b) : a;   }   long long int lcm(long long int a, long long int b) {     return a * b / gcd(a, b);   }   int n, cnt[100010];   int main() {     scanf( %d , &n);     set<int> s;     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       s.insert(x);       auto itr = s.find(x);       itr++;       if (itr == s.end())         cnt[x]--;       else {         x = *itr;         itr++;         if (itr == s.end()) cnt[x]++;       }     }     int ans = 1;     for (int i = 1; i <= n; i++)       if (cnt[i] > cnt[ans]) ans = i;     printf( %d n , ans);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 10;   const int M = 1000000007;   const double PI = atan(1) * 4;   const int oo = 1000000000;   long long A, B, n, x;   long long pw(long long x, long long p) {     if (!p) return 1;     long long d = pw(x, p / 2);     d = (d * d) % M;     if (p % 2) d = (d * x) % M;     assert(x <= M);     assert(d <= M);     return d;   }   int main() {     cin >> A >> B >> n >> x;     if (A == 1) return cout << (n % M * B % M + x) % M, 0;     long long one = x * pw(A, n) % M;     long long dom = pw(A, n) - 1;     long long den = pw(A - 1, M - 2);     cout << (one + B * ((dom * den) % M) % M) % M << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = M_PI;   const int INF = -1 * 1e9;   const long long limit = 1 * 1e12;   const int MOD1 = 1e9 + 711;   const int MOD2 = 1e9 + 933;   const int MOD3 = 1e9 + 993;   const int maxn = 1e6 + 100;   int main() {     cout.tie(0);     cin.tie(0);     ios_base::sync_with_stdio(0);     int n;     cin >> n;     vector<int> a(n), b(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];       b[i] = a[i];     }     sort(b.begin(), b.end());     int cnt = 0;     for (int i = 0; i < n; ++i) {       if (a[i] != b[i]) {         ++cnt;       }     }     if (cnt <= 2) {       cout <<  YES ;     } else {       cout <<  NO ;     }     cerr <<   n nTime elapsed:   << 1.0 * clock() / CLOCKS_PER_SEC <<   s. n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ax, ay, bx, by, cx, cy;   int solve(long long x2, long long y2) {     if (cx == 0 && cy == 0) {       if (x2 == 0 && y2 == 0) return 1;       return 0;     } else if (cx == 0) {       long long g, h;       g = x2 / cy;       h = y2 / cy;       if (g * cy == x2 && h * cy == y2) return 1;       return 0;     } else if (cy == 0) {       long long g, h;       g = x2 / cx;       h = y2 / cx;       if (g * cx == x2 && h * cx == y2) return 1;       return 0;     } else {       long long a, b;       if ((cx * cy + cx * cx) == 0) return 0;       b = (x2 * cy - y2 * cx) / (cy * cy + cx * cx);       a = (x2 - b * cy) / cx;       if (b * (cy * cy + cx * cx) == (x2 * cy - y2 * cx) &&           (a * cx == x2 - b * cy)) {         return 1;       }       return 0;     }     return 0;   }   int main() {     scanf( %lld%lld , &ax, &ay);     scanf( %lld%lld , &bx, &by);     scanf( %lld%lld , &cx, &cy);     if (solve(bx - ax, by - ay)) {       puts( YES );       return 0;     }     if (solve(bx + ax, by + ay)) {       puts( YES );       return 0;     }     if (solve(bx - ay, by + ax)) {       puts( YES );       return 0;     }     if (solve(bx + ay, by - ax)) {       puts( YES );       return 0;     }     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int g[100100];   int suff[100100];   char S[1024];   set<int> crim;   char T[100100];   int R[100100], neg[100100];   int main() {     int n, m, tot = 0;     scanf( %d , &n);     scanf( %d , &m);     for (int i = 0; i < n; i++) {       scanf( %s , S);       int l = strlen(S);       char sign = S[0];       int pos = 1, num = 0;       while (pos < l) {         num = num * 10 + S[pos] -  0 ;         pos++;       }       num--;       if (S[0] ==  + )         g[num]++;       else {         tot++;         neg[num]++;       }       T[i] = S[0];       R[i] = num;     }     for (int i = 0; i < n; i++) {       g[i] += tot;       g[i] -= neg[i];     }     for (int i = 0; i < n; i++) {       if (g[i] == m) crim.insert(i);     }     int prob = crim.size();     for (int i = 0; i < n; i++) {       if (T[i] ==  + ) {         if (crim.find(R[i]) == crim.end()) {           puts( Lie );         } else {           if (prob == 1)             puts( Truth );           else             puts( Not defined );         }       } else {         if (crim.find(R[i]) == crim.end()) {           puts( Truth );         } else {           if (prob == 1)             puts( Lie );           else             puts( Not defined );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int su[3000000];   vector<int> vec;   int vv[3000010];   int main() {     memset(su, 0, sizeof(su));     memset(vv, 0, sizeof(vv));     vec.push_back(2);     for (int i = 3; i <= 2750131; i++) {       for (int j = 0; j < vec.size(); j++) {         if (vec[j] * vec[j] > i) break;         if (i % vec[j] == 0) {           su[i] = i / vec[j];           break;         }       }       if (su[i] == 0) vec.push_back(i);     }     int n;     scanf( %d , &n);     int h_sum = 2 * n;     for (int i = 1; i <= 2 * n; i++) {       int x;       scanf( %d , &x);       vv[x]++;     }     for (int i = 2750131; i >= 2; i--) {       while (su[i] && vv[i]) {         printf( %d  , i);         vv[i]--;         vv[su[i]]--;         h_sum -= 2;       }     }     for (int i = 2750131; i >= 2; i--) {       if (h_sum == 0) break;       while (vv[i]) {         int k = lower_bound(vec.begin(), vec.end(), i) - vec.begin() + 1;         printf( %d  , k);         vv[i]--;         vv[k]--;         h_sum -= 2;         if (h_sum == 0) break;       }     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n;     cin >> n;     vector<pair<int, int>> d(n);     for (auto &i : d) cin >> i.first, i.second = &i - &d[0] + 1;     sort(d.begin(), d.end());     vector<pair<int, int>> e;     vector<int> a;     a.push_back(2 * d.back().second - 1);     for (int i = 1; i < d.back().first; ++i) a.push_back(-1);     a.push_back(2 * d.back().second);     int l = 0, r = a.size() - 1;     d.pop_back();     while (!d.empty()) {       auto p = d.back();       d.pop_back();       if (a[l + 1] == -1) {         ++l;         a[l] = 2 * p.second - 1;         if (p.first == r - l + 1) {           ++r;           a.push_back(2 * p.second);         } else {           e.push_back({l + p.first - 1, 2 * p.second});         }       } else {         ++r;         a.push_back(2 * p.second);         e.push_back({r - p.first + 1, 2 * p.second - 1});       }     }     for (size_t i = 1; i < a.size(); ++i) cout << a[i - 1] <<     << a[i] <<   n ;     for (auto &i : e) cout << a[i.first] <<     << i.second <<   n ;     return 0;   }


#include <bits/stdc++.h>   int main() {     int count, i, a, x, max, tc;     scanf( %d , &tc);     for (int j = 0; j < tc; j++) {       count = 0, max = 0;       scanf( %d , &x);       char s[x];       scanf( %s , s);       for (i = x - 1; i >= 0; i--) {         if (s[i] ==  P ) {           count += 1;         } else {           if (count > max) {             max = count;           }           count = 0;         }       }       printf( %d n , max);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 23e4 + 5;   int sum[M], n, fen[M];   int Get(int p) {     int u = p;     int ans = 0;     for (; p > 0; p -= p & -p) ans += fen[p];     for (u++; u < M; u += u & -u) fen[u]++;     return ans;   }   int get(int p) {     int cur = 0;     for (int i = 17; ~i; i--) {       int d = cur + (1 << i);       if (fen[d] <= p) p -= fen[d], cur = d;     }     int u = cur;     for (u++; u < M; u += u & -u) fen[u]--;     return cur;   }   int32_t main() {     scanf( %d , &n);     int t = 2;     while (t--) {       memset(fen, 0, sizeof fen);       for (int i = 0; i < n; i++) {         int x;         scanf( %d , &x);         sum[i] += x - Get(x);       }     }     int sb = 0;     for (int i = n - 1; ~i; i--) {       sum[i] += sb;       int k = sum[i] % (n - i);       sb = (sum[i] - k) / (n - i);       sum[i] = k;     }     for (int i = 1; i < M; i++) fen[i] = i & -i;     for (int i = 0; i < n; i++) printf( %d  , get(sum[i]));     return printf(  n ), 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   long long pos = -1;   const long long N = 5005;   long long gundy[N];   long long mex[N];   void game() {     long long len = s.length();     long long totXo = 0;     gundy[0] = 0;     for (long long i = 1; i < N; i++) {       for (long long j = 0; j < N; j++) mex[j] = 0;       for (long long j = 0; j < i; j++) {         long long l = max(0LL, j - 1);         long long r = max(0LL, i - j - 2);         long long xo = gundy[l] ^ gundy[r];         if (xo < N) mex[xo] = 1;       }       long long gv = 0;       while (gv < N && mex[gv] == 1) gv++;       gundy[i] = gv;     }     for (long long i = 1; i < len - 1; i++) {       if (s[i - 1] == s[i + 1]) {         long long j = i;         while (j + 2 < len && s[j] == s[j + 2]) j++;         totXo ^= gundy[j - i + 1];         i = j + 1;       }     }     if (totXo == 0)       cout <<  Second             <<   n ;     else {       cout <<  First             <<   n ;       for (long long i = 1; i < len - 1; i++) {         if (s[i - 1] == s[i + 1]) {           long long j = i;           while (j + 2 < len && s[j] == s[j + 2]) j++;           long long span = j - i + 1;           long long remXo = totXo ^ gundy[span];           for (long long k = 0; k < span; k++) {             long long l = max(0LL, k - 1LL);             long long r = max(0LL, span - k - 2LL);             long long xo = gundy[l] ^ gundy[r] ^ remXo;             if (xo == 0) {               pos = i + k + 1;               cout << pos <<   n ;               return;             }           }           i = j + 1;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> s;     game();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long a = 0;     long long ret = 0;     long long x = n;     while (x >= 10) {       a = a * 10 + 9;       ret += 9;       x /= 10;     }     long long y = n - a;     while (y) {       ret += y % 10;       y /= 10;     }     cout << ret << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       long long int n, z = 0, o = 0;       cin >> n;       string s;       cin >> s;       if (n == 1) {         cout << s << endl;         continue;       }       for (long long int i = 0; i < n; i++) {         if (s[i] ==  0 )           z++;         else           break;       }       z++;       for (long long int i = n - 1; i >= 0; i--) {         if (s[i] ==  1 )           o++;         else           break;       }       if (o + z == n + 1) {         cout << s << endl;         continue;       }       while (z) {         cout <<  0 ;         z--;       }       while (o) {         cout <<  1 ;         o--;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int S = 100003;   const int MOD = 1e9 + 7;   const double pi = 2 * acos(0.0);   inline int _Int() {     int x;     scanf( %d , &x);     return x;   }   inline long long _LLi() {     long long x;     scanf( %lld , &x);     return x;   }   void pruts() {     puts( NO );     exit(EXIT_SUCCESS);   }   int dirX[] = {1, 0, -1, 0, 1, -1, 1, -1};   int dirY[] = {0, 1, 0, -1, 1, -1, -1, 1};   int rX[] = {1, 1, 2, 2, -1, -1, -2, -2};   int rY[] = {2, -2, 1, -1, 2, -2, 1, -1};   template <class T>   T tri_Area(T x1, T y1, T x2, T y2, T x3, T y3) {     return abs(x1 * (y2 - y3) - y1 * (x2 - x3) + (x2 * y3 - x3 * y2));   };   template <class T>   T Distance(T x1, T y1, T x2, T y2) {     return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));   };   template <class T>   T bigMod(T n, T p, T m) {     if (p == 0) return 1;     if (p & 1) return (n * bigMod(n, p - 1, m)) % m;     T x = bigMod(n, p / 2, m);     return (x * x) % m;   };   int sset(int N, int pos) { return N = N | (1 << pos); }   bool check(int N, int pos) { return (bool)(N & (1 << pos)); }   int reset(int N, int pos) { return N = N & ~(1 << pos); }   void Hunger() {     int a = _Int();     int b = _Int();     if (!a && !b) pruts();     puts((abs(a - b) <= 1) ?  YES  :  NO );   }   int main() {     Hunger();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, A, B, ans = 0;   long long fmin() {     long long pros = (n - (n / k)) * A;     if (B < pros) {       n = n / k;       return B;     } else {       n = n / k;       return pros;     }   }   int main() {     cin >> n;     cin >> k;     cin >> A;     cin >> B;     if (k == 1) {       cout << (n - 1) * A;       return 0;     }     while (n != 1) {       if (n >= k) {         if (n % k == 0) {           ans += fmin();         } else {           long long t = (n % k);           n = n - t;           ans += (A * t);         }       } else {         ans = ans + (n - 1) * A;         n = 1;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long s = 0, t = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) t = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();     return s * t;   }   const int N = 1e5 + 5;   const long long inf = 0x3f3f3f3f3f3f3f3f;   int n, top, Len = 1, s[N], nxt[N];   long long K, w[N], g[N], pre[N], suf[N];   vector<int> G[N];   long long a[N << 2], b[N << 2], d[N << 2], res[N << 2];   void Init(int x, long long t) { b[x] += t, res[x] -= t, d[x] += t; }   void Pushdown(int x) {     if (!d[x]) return;     Init(x << 1, d[x]), Init(x << 1 | 1, d[x]), d[x] = 0;   }   long long Calc(int x, int l, int r, long long t) {     if (l == r) return a[x] - t;     int mid = (l + r) >> 1;     Pushdown(x);     if (b[x << 1] < t) return min(Calc(x << 1, l, mid, t), res[x]);     return min(a[x << 1] - t, Calc(x << 1 | 1, mid + 1, r, t));   }   void Build(int x, int l, int r) {     if (l == r) {       a[x] = b[x] = suf[l];       return;     }     int mid = (l + r) >> 1;     Build(x << 1, l, mid), Build(x << 1 | 1, mid + 1, r);     a[x] = min(a[x << 1], a[x << 1 | 1]), b[x] = min(b[x << 1], b[x << 1 | 1]);     res[x] = Calc(x << 1 | 1, mid + 1, r, b[x << 1]);   }   void Upd(int x, int l, int r, int ql, int qr, long long t) {     if (ql <= l && r <= qr) {       Init(x, t);       return;     }     int mid = (l + r) >> 1;     Pushdown(x);     if (ql <= mid) Upd(x << 1, l, mid, ql, qr, t);     if (qr > mid) Upd(x << 1 | 1, mid + 1, r, ql, qr, t);     b[x] = min(b[x << 1], b[x << 1 | 1]),     res[x] = Calc(x << 1 | 1, mid + 1, r, b[x << 1]);   }   int Find(int x, int l, int r, long long t) {     if (l == r) return l;     int mid = (l + r) >> 1;     Pushdown(x);     return a[x << 1 | 1] <= t ? Find(x << 1 | 1, mid + 1, r, t)                               : Find(x << 1, l, mid, t);   }   int Solve(int x, int l, int r, long long &t) {     if (l == r) {       int tp = a[x] - t <= K ? l : 0;       return t = min(t, b[x]), tp;     }     int mid = (l + r) >> 1;     Pushdown(x);     if (b[x << 1] < t) {       if (res[x] <= K) return Solve(x << 1 | 1, mid + 1, r, t = b[x << 1]);       int tp = Solve(x << 1, l, mid, t);       return t = min(t, b[x]), tp;     } else {       int tp = a[x << 1] <= K + t ? Find(x << 1, l, mid, K + t) : 0;       return max(tp, Solve(x << 1 | 1, mid + 1, r, t));     }   }   void DFS(int x) {     s[++top] = x;     if (nxt[x] <= n) Upd(1, 1, n, nxt[x] - 1, n, pre[x] - pre[nxt[x]]);     if (x <= n) {       int l = 2, r = top - 1, res = 1;       while (l <= r) {         int mid = (l + r) >> 1;         if (pre[s[mid]] - pre[x] > K)           res = mid, l = mid + 1;         else           r = mid - 1;       }       int lim = s[res] - 1;       if (x > 1) Upd(1, 1, n, 1, x - 1, inf);       Upd(1, 1, n, lim, n, -inf);       long long tp = inf;       int pos = Solve(1, 1, n, tp);       if (x > 1) Upd(1, 1, n, 1, x - 1, -inf);       Upd(1, 1, n, lim, n, inf);       Len = max(Len, pos - x + 1);     }     for (auto y : G[x]) DFS(y);     if (nxt[x] <= n) Upd(1, 1, n, nxt[x] - 1, n, pre[nxt[x]] - pre[x]);     top--;   }   int main() {     n = read(), K = read();     for (int i = 1; i < n; i++) w[i] = read();     for (int i = 1; i <= n; i++) g[i] = read();     for (int i = 2; i <= n; i++) {       pre[i] = pre[i - 1] + w[i - 1] - g[i - 1];       suf[i] = suf[i - 1] + w[i - 1] - g[i];     }     for (int i = n; i >= 1; i--) {       while (top && pre[s[top]] <= pre[i]) top--;       nxt[i] = top ? s[top] : n + 1, s[++top] = i;       G[nxt[i]].push_back(i);     }     nxt[n + 1] = n + 1, top = 0;     Build(1, 1, n), DFS(n + 1), printf( %d , Len);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const double EPS = 1e-9;   const int INF = 1 << 29;   int main() {     int x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     int x, y;     cin >> x >> y;     int dx = abs(x1 - x2), dy = abs(y1 - y2);     if (dx % x || dy % y) {       puts( NO );       return 0;     }     int t = dx / x - dy / y;     if (t & 1) {       puts( NO );     } else {       puts( YES );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, s, d[100002], f, g, h, j, k, l, i, n, m;   string x;   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> d[i];     }     for (i = 0; i < n; i++) {       scanf(  n );       getline(cin, x);       for (a = 0; a < x.size(); a++) {         if (x[a] ==  a ) d[i]--;         if (x[a] ==  e ) d[i]--;         if (x[a] ==  i ) d[i]--;         if (x[a] ==  o ) d[i]--;         if (x[a] ==  u ) d[i]--;         if (x[a] ==  y ) d[i]--;       }       if (d[i] != 0) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   bool v[1005][1005][4][3];   char grid[1005][1005];   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   int n, m;   int xx, yy;   bool dfs(int x, int y, int dir, int turns) {     if (x < 0 || x == n || y < 0 || y == m || turns > 2 || grid[x][y] ==  * )       return false;     if (v[x][y][dir][turns]) return false;     v[x][y][dir][turns] = true;     if (x == xx && y == yy) return true;     bool can = false;     for (int i = 0; i < 4; i++)       can |= dfs(x + dx[i], y + dy[i], i, turns + (i != dir));     return can;   }   int main() {     cin >> n >> m;     pair<int, int> second, t;     for (int i = 0; i < n; i++) {       scanf( %s , grid[i]);       for (int j = 0; j < m; j++) {         if (grid[i][j] ==  S )           second = make_pair(i, j);         else if (grid[i][j] ==  T )           t = make_pair(i, j);       }     }     xx = t.first, yy = t.second;     if (dfs(second.first, second.second, 0, 0) ||         dfs(second.first, second.second, 1, 0) ||         dfs(second.first, second.second, 2, 0) ||         dfs(second.first, second.second, 3, 0))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300000;   vector<long long> st;   void add(vector<long long>& st, int x, long long inc) {     while (x < st.size()) {       st[x] += inc;       x |= x + 1;     }   }   long long sum(const vector<long long>& st, int x) {     long long s = 0;     while (x >= 0) {       s += st[x];       x = (x & (x + 1)) - 1;     }     return s;   }   void insert(int l, int r, long long p) {     add(st, r + 1, -p);     add(st, l, p);   }   int n, m, k;   int l[maxn], r[maxn];   long long d[maxn];   pair<int, int> a[maxn];   long long p[maxn];   int main() {     cin >> n >> m >> k;     st.resize(n + 3);     for (int i = 1; i <= n; i++) scanf( %I64d , &p[i]);     for (int i = 1; i <= m; i++) {       scanf( %d%d%I64d , &l[i], &r[i], &d[i]);     }     for (int i = 1; i <= k; i++) {       int x, y;       scanf( %d%d , &x, &y);       a[i] = make_pair(x, -1);       a[i + k] = make_pair(y + 1, 1);     }     sort(a + 1, a + 1 + 2 * k);     int sta = 1, tot = 0;     for (int i = 1; i <= m; i++) {       while (sta <= 2 * k && a[sta].first == i) tot -= a[sta++].second;       insert(l[i], r[i], d[i] * tot);     }     for (int i = 1; i <= n; i++) printf( %I64d  , sum(st, i) + p[i]);   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   void dfs(long long int par, long long int node,            vector<pair<long long int, string>> adj[],            vector<long long int> &nodes, vector<bool> &visited) {     visited[node] = true;     nodes.push_back(node);     for (auto child : adj[node]) {       if (!visited[abs(child.first)]) {         dfs(node, abs(child.first), adj, nodes, visited);       }     }   }   void dfs2(long long int par, long long int node, string role,             vector<pair<long long int, string>> adj[], bool &ok,             vector<bool> &visited2, long long int &cnt, vector<string> &cr) {     for (auto child : adj[node]) {       if (child.first > 0) {         if (visited2[node] && (!visited2[child.first])) {           visited2[child.first] = true;           if (cr[node] ==  imposter ) {             string childRole =                 child.second ==  imposter  ?  crewmate  :  imposter ;             cr[child.first] = childRole;             dfs2(node, child.first, childRole, adj, ok, visited2, cnt, cr);           } else {             string childRole =                 child.second ==  imposter  ?  imposter  :  crewmate ;             cr[child.first] = childRole;             dfs2(node, child.first, childRole, adj, ok, visited2, cnt, cr);           }         } else if ((!visited2[node]) && visited2[child.first]) {           visited2[node] = true;           if (cr[child.first] ==  imposter ) {             string childRole =                 child.second ==  imposter  ?  crewmate  :  imposter ;             cr[node] = childRole;           } else {             string childRole =                 child.second ==  imposter  ?  imposter  :  crewmate ;             cr[node] = childRole;           }         } else if (visited2[child.first] && visited2[node]) {           if (cr[child.first] ==  imposter ) {             if (cr[node] ==  imposter  && child.second ==  imposter ) {               ok = false;               return;             } else if (cr[node] ==  crewmate  && child.second ==  crewmate ) {               ok = false;               return;             }           } else {             if (cr[node] ==  imposter  && child.second ==  crewmate ) {               ok = false;               return;             } else if (cr[node] ==  crewmate  && child.second ==  imposter ) {               ok = false;               return;             }           }         }         if (!ok) {           return;         }       }     }     for (auto child : adj[node]) {       if (child.first < 0) {         if ((!visited2[abs(child.first)]) && visited2[node] == true) {           dfs2(node, abs(child.first),  imposter , adj, ok, visited2, cnt, cr);         }       }       if (!ok) {         return;       }     }     for (auto child : adj[node]) {       if (child.first > 0) {         if (visited2[node] && (!visited2[child.first])) {           visited2[child.first] = true;           if (cr[node] ==  imposter ) {             string childRole =                 child.second ==  imposter  ?  crewmate  :  imposter ;             cr[child.first] = childRole;             dfs2(node, child.first, childRole, adj, ok, visited2, cnt, cr);           } else {             string childRole =                 child.second ==  imposter  ?  imposter  :  crewmate ;             cr[child.first] = childRole;             dfs2(node, child.first, childRole, adj, ok, visited2, cnt, cr);           }         } else if (visited2[child.first] && visited2[node]) {           if (cr[child.first] ==  imposter ) {             if (cr[node] ==  imposter  && child.second ==  imposter ) {               ok = false;               return;             } else if (cr[node] ==  crewmate  && child.second ==  crewmate ) {               ok = false;               return;             }           } else {             if (cr[node] ==  imposter  && child.second ==  crewmate ) {               ok = false;               return;             } else if (cr[node] ==  crewmate  && child.second ==  imposter ) {               ok = false;               return;             }           }         }       }       if (!ok) {         return;       }     }   }   void answerNikalBc(long long int t1) {     long long int n, m;     cin >> n >> m;     map<pair<long long int, long long int>, string> mp;     vector<pair<long long int, string>> adj[n + 1];     bool ok = true;     for (long long int i = 1; i <= m; i++) {       long long int u, v;       string s;       cin >> u >> v >> s;       if (mp.find({u, v}) == mp.end()) {         adj[u].push_back({v, s});         adj[v].push_back({-1 * u, s});         mp[{u, v}] = s;       } else {         if (mp[{u, v}] == s) {           continue;         } else {           ok = false;         }       }     }     if (!ok) {       cout << -1 <<   n ;       return;     }     long long int ans = 0;     vector<bool> visited(n + 1, false);     vector<bool> visited2(n + 1, false);     vector<string> childRole(n + 1,  imposter );     for (long long int i = 1; i <= n; i++) {       if (!visited[i]) {         vector<long long int> nodes;         dfs(-1, i, adj, nodes, visited);         bool init = false;         long long int cnt1 = 0, cnt2 = 0;         for (long long int j = 0; j < nodes.size(); j++) {           if (!visited2[nodes[j]]) {             if (!init) {               visited2[nodes[j]] = true;               childRole[nodes[j]] =  imposter ;               dfs2(-1, nodes[j],  imposter , adj, ok, visited2, cnt1, childRole);               init = true;             } else {               dfs2(-1, nodes[j],  imposter , adj, ok, visited2, cnt1, childRole);             }           }         }         for (auto a : nodes) {           visited2[a] = false;         }         for (auto a : nodes) {           if (childRole[a] ==  imposter ) {             cnt1++;           }         }         init = false;         for (long long int j = 0; j < nodes.size(); j++) {           if (!visited2[nodes[j]]) {             if (!init) {               visited2[nodes[j]] = true;               childRole[nodes[j]] =  crewmate ;               dfs2(-1, nodes[j],  crewmate , adj, ok, visited2, cnt2, childRole);               init = true;             } else {               dfs2(-1, nodes[j],  crewmate , adj, ok, visited2, cnt2, childRole);             }           }         }         for (auto a : nodes) {           if (childRole[a] ==  imposter ) {             cnt2++;           }         }         if (!ok) {           cout << -1 <<   n ;           return;         }         ans += (max(cnt1, cnt2));       }     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     t = 1;     cin >> t;     for (long long int i = 1; i <= t; i++) {       answerNikalBc(t);     }     cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 * 100 + 10;   int a[MAXN], b[MAXN];   int dp[MAXN][310];   vector<int> vec1[MAXN], vec[MAXN];   long long n, m, second, E;   bool ok(int k) {     long long need = second;     for (int i = k - 1; i < n; i++)       if (dp[i][k] < m) need = min(need, (long long)(i + 1 + dp[i][k] + 1));     need += k * E;     if (need <= second) return true;     return false;   }   int bs(int s, int e) {     if (e - s <= 1) return s;     int m = (s + e) / 2;     return ok(m) ? bs(m, e) : bs(s, m);   }   int main() {     cin >> n >> m >> second >> E;     for (int i = 0; i < n; i++) cin >> a[i], vec1[a[i]].push_back(i);     for (int i = 0; i < m; i++) cin >> b[i], vec[b[i]].push_back(i);     for (int i = 0; i < MAXN; i++) vec[i].push_back(m);     for (int i = 0; i < n; i++)       for (int j = 0; j < 301; j++) dp[i][j] = m;     for (int i = 0; i < n; i++)       for (int j = 0; j < min(min((int)m, i + 1), 300) + 1; j++) {         if (j == 0)           dp[i][j] = -1;         else if (i == 0)           dp[i][j] =               vec[a[i]][lower_bound(vec[a[i]].begin(), vec[a[i]].end(), 0) -                         vec[a[i]].begin()];         else           dp[i][j] =               min(dp[i - 1][j],                   (dp[i - 1][j - 1] >= m)                       ? (int)m                       : vec[a[i]]                            [(int)(lower_bound(vec[a[i]].begin(), vec[a[i]].end(),                                               dp[i - 1][j - 1] + 1) -                                   vec[a[i]].begin())]);       }     cout << bs(0, min({(int)m, (int)n, 300}) + 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int readInt() {     char c;     int tmp = 0, x = 1;     c = getchar();     while (c >  9  || c <  0 ) {       if (c ==  - ) x = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       tmp = tmp * 10 + c -  0 ;       c = getchar();     }     return tmp * x;   }   const int maxN = 2000 + 10;   const int maxM = 100000 + 10;   int Head[maxN], eg[maxM << 1], nxt[maxM << 1], tot = 1;   void addEdge(int u, int v) {     eg[++tot] = v;     nxt[tot] = Head[u];     Head[u] = tot;     eg[++tot] = u;     nxt[tot] = Head[v];     Head[v] = tot;   }   bool isbri[maxM << 2];   int dfn[maxN], low[maxN], dfsclock = 0;   void tarjan(int v, int InEdge) {     dfn[v] = low[v] = ++dfsclock;     for (int i = Head[v]; i; i = nxt[i]) {       int u = eg[i];       if (!dfn[u]) {         tarjan(u, i);         low[v] = min(low[v], low[u]);         if (low[u] > dfn[v]) isbri[i] = isbri[i ^ 1] = true;       } else if (i != (InEdge ^ 1))         low[v] = min(low[v], dfn[u]);     }   }   int bccno[maxN], num = 0, bccsiz[maxN];   void dfs(int v) {     bccno[v] = num;     bccsiz[num]++;     for (int i = Head[v]; i; i = nxt[i]) {       int u = eg[i];       if (!bccno[u] && !isbri[i]) dfs(u);     }   }   vector<int> g[maxN];   void new_addEdge(int u, int v) {     g[u].push_back(v);     g[v].push_back(u);   }   bool vis[maxN], isLeaf[maxN];   int tmp = 0, tmpmax = -1, tmpleaf = 0, Leaf[maxN], siz[maxN], rot[maxN],       cnt = 0, Fa[maxN], Belong[maxN];   void predfs(int v, int fa) {     siz[v] = 1;     Fa[v] = fa;     Belong[v] = cnt;     if ((int)g[v].size() == 0 || (int)g[v].size() == 1)       Leaf[cnt]++, isLeaf[v] = true;     for (int i = 0; i < (int)g[v].size(); i++) {       int u = g[v][i];       if (u != fa) predfs(u, v), siz[v] += siz[u];     }   }   void FindLongest(int v, int fa, int D, int lev) {     if (tmp < D) tmp = D, tmpmax = v, tmpleaf = lev;     for (int i = 0; i < (int)g[v].size(); i++) {       int u = g[v][i];       if (u != fa) FindLongest(u, v, D + (!isLeaf[u]), lev + isLeaf[u]);     }   }   int FindDiameter(int v) {     tmp = 0, tmpmax = -1;     for (int i = 0; i < (int)g[v].size(); i++) {       int u = g[v][i];       FindLongest(u, v, 1, 0);     }     if (!(~tmpmax)) return 0;     int vv = tmpmax;     tmp = 0, tmpmax = -1, tmpleaf = 0;     FindLongest(vv, -1, 1, isLeaf[vv]);     return tmp - tmpleaf;   }   int n, m;   int main() {     n = readInt(), m = readInt();     int u, v;     for (int i = 1; i <= m; i++) {       u = readInt(), v = readInt();       addEdge(u, v);     }     for (int i = 1; i <= n; i++) {       if (!dfn[i]) tarjan(i, 0);     }     for (int i = 1; i <= n; i++) {       if (!bccno[i]) {         num++;         dfs(i);       }     }     for (int i = 2; i <= tot; i += 2) {       if (bccno[eg[i]] != bccno[eg[i ^ 1]]) {         new_addEdge(bccno[eg[i]], bccno[eg[i ^ 1]]);       }     }     int ans = 0;     for (int i = 1; i <= num; i++) ans += bccsiz[i] - 1;     cnt = 0;     for (int i = 1; i <= num; i++) {       if (!Belong[i]) cnt++, rot[cnt] = i, predfs(i, -1);     }     ans += cnt - 1;     for (int i = 1; i <= cnt; i++) {       int d = FindDiameter(rot[i]);       ans += siz[rot[i]] - d - Leaf[i];     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   int pre[N], rak[N];   int find(int first) {     if (pre[first] == -1) return first;     return pre[first] = find(pre[first]);   }   void unions(int first, int second) {     first = find(first);     second = find(second);     if (first == second) return;     if (rak[first] < rak[second]) swap(first, second);     rak[first] += rak[second];     pre[second] = first;   }   vector<pair<int, int> > rows[N], col[N];   void scc(int n, int m) {     memset(pre, -1, sizeof(pre));     fill(rak, rak + N, 1);     for (int i = 1; i <= n; i++) {       sort(rows[i].begin(), rows[i].end());       for (int j = 1; j < m; j++) {         if (rows[i][j - 1].first == rows[i][j].first)           unions((i - 1) * m + rows[i][j - 1].second,                  (i - 1) * m + rows[i][j].second);       }     }     for (int j = 1; j <= m; j++) {       sort(col[j].begin(), col[j].end());       for (int i = 1; i < n; i++) {         if (col[j][i - 1].first == col[j][i].first)           unions((col[j][i - 1].second - 1) * m + j,                  (col[j][i].second - 1) * m + j);       }     }   }   vector<int> edges[N];   int deg[N], ans[N];   stack<int> stk;   void topo(int n, int m) {     for (int i = 1; i <= n; i++) {       for (int j = 1; j < m; j++) {         if (rows[i][j - 1].first < rows[i][j].first) {           int first = find((i - 1) * m + rows[i][j - 1].second);           int second = find((i - 1) * m + rows[i][j].second);           edges[first].push_back(second);           deg[second]++;         }       }     }     for (int j = 1; j <= m; j++) {       for (int i = 1; i < n; i++) {         if (col[j][i - 1].first < col[j][i].first) {           int first = find((col[j][i - 1].second - 1) * m + j);           int second = find((col[j][i].second - 1) * m + j);           edges[first].push_back(second);           deg[second]++;         }       }     }     n = n * m;     for (int i = 1; i <= n; i++)       if (!deg[i] && pre[i] == -1) stk.push(i), ans[i] = 1;     while (!stk.empty()) {       int u = stk.top();       stk.pop();       for (int i = 0; i < edges[u].size(); i++) {         int first = edges[u][i];         ans[first] = max(ans[first], ans[u] + 1);         deg[first]--;         if (!deg[first]) stk.push(first);       }     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1, first; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &first);         rows[i].push_back(make_pair(first, j));         col[j].push_back(make_pair(first, i));       }     }     scc(n, m);     topo(n, m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         printf( %d%c , ans[find((i - 1) * m + j)], (j == m) ?   n  :    );       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   int t;   void solve();   struct Node {     long long q, w, e, r, t;   };   int n;   vector<Node> a;   vector<bool> ans;   int res = 0;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     t = 1;     for (int i = 0; i < t; ++i) {       solve();     }   }   void solve() {     cin >> n;     a.resize(n);     ans.resize(n);     for (int i = 0; i < int(n); ++i) {       cin >> a[i].q >> a[i].w >> a[i].e >> a[i].r >> a[i].t;     }     if (n > 66) {       cout << 0;       return;     }     for (int i = 0; i < int(n); ++i) {       for (int j = (0); j <= int(n - 1); ++j) {         for (int k = (j + 1); k <= int(n - 1); ++k) {           if (j == i || k == i) {             continue;           }           if ((a[j].q - a[i].q) * (a[k].q - a[i].q) +                   (a[j].w - a[i].w) * (a[k].w - a[i].w) +                   (a[j].e - a[i].e) * (a[k].e - a[i].e) +                   (a[j].r - a[i].r) * (a[k].r - a[i].r) +                   (a[j].t - a[i].t) * (a[k].t - a[i].t) >               0) {             ans[i] = true;             break;           }         }         if (ans[i]) break;       }       if (!ans[i]) res++;     }     cout << res << endl;     for (int i = 0; i < int(n); ++i) {       if (!ans[i]) {         cout << i + 1 << endl;       }     }   }


#include <bits/stdc++.h>   int main(void) {     int w = 1;     int h = 1;     int n = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       char op[10] = {0};       scanf( %s , op);       if (strcmp(op,  UL ) == 0 || strcmp(op,  DR ) == 0)         w++;       else if (strcmp(op,  UR ) == 0 || strcmp(op,  DL ) == 0)         h++;       else {         w++;         h++;       }     }     printf( %I64d n , (long long)w * h);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, l, r;   int Niz1[100001], Niz2[100001], hes[100001], time1[100001], time2[100001];   int main() {     scanf( %d %d %d , &n, &l, &r);     for (int i = 1; i <= n; i++) {       scanf( %d , &Niz1[i]);       hes[i] = Niz1[i];     }     for (int i = 1; i <= n; i++) {       scanf( %d , &Niz2[i]);     }     for (int i = 1; i <= n; i++) {       if (i < l) {         if (hes[i] != Niz2[i]) {           printf( LIE );           return 0;         }       } else {         if (i > r) {           if (hes[i] != Niz2[i]) {             printf( LIE );             return 0;           }         } else {           time2[Niz2[i]]++;         }       }     }     for (int i = l; i <= r; i++) {       time1[Niz1[i]]++;     }     for (int i = l; i <= r; i++) {       if (time1[Niz1[i]] != time2[Niz1[i]]) {         printf( LIE );         return 0;       }     }     printf( TRUTH );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long cur = 1;     long long ans = 0;     long long now = n;     while (cur <= now) {       now -= cur;       cur *= 2;       ans++;     }     if (now != 0) ans++;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     int a[100009];     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     int t = 0;     long long sum1 = 0;     sort(a, a + n);     int m = 0, l = 0, token = 0;     for (int i = n - 1; i >= 0; i--) {       if (a[i] > k) {         int temp = a[i] / k;         token = temp;         temp /= 2;         if (a[i] % k != 0) {           if (token % 2 == 1) temp++;           token++;         }         if (token % 2 == 1) {           if (l == 0)             l = 1;           else {             t++;             l = 0;           }         }         t += temp;       } else {         if (m == 0) {           m = 1;         } else {           t++;           m = 0;         }       }       if (l == 1 && m == 1 && i == 0)         t++;       else if (m == 1 && i == 0)         t++;       else if (l == 1 && i == 0)         t++;     }     cout << t <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long k = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       k = k * 10 + ch -  0 ;       ch = getchar();     }     return k * f;   }   inline void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   inline void writeln(long long x) {     write(x);     puts(  );   }   const long long N = 2e5 + 10;   const long long MOD = 1e9 + 7;   long long nedge = 0, p[2 * N], nex[2 * N], head[2 * N], c[2 * N];   long long n, deep[N], Deep[N][2], dep[N], Dep[N][2];   long long s[N], f[N], vis[N], sum, rt, ans = 0, d[N], K;   long long maxx = 0, Maxx = 0, a[N];   inline void upd(long long &x, long long v) { x = (x + v) % MOD; }   inline void addedge(long long x, long long y, long long z) {     p[++nedge] = y;     c[nedge] = z;     nex[nedge] = head[x];     head[x] = nedge;   }   inline void dfs(long long x, long long fa) {     s[x] = 1;     f[x] = 0;     for (long long k = head[x]; k; k = nex[k])       if (p[k] != fa && !vis[p[k]]) {         dfs(p[k], x);         s[x] += s[p[k]];         f[x] = max(f[x], s[p[k]]);       }     f[x] = max(f[x], sum - s[x]);     if (f[x] < f[rt]) rt = x;   }   inline void dfss(long long x, long long fa, long long ps, long long v) {     if (d[x] > K) return;     maxx = max(maxx, d[x]);     upd(v, a[x]);     upd(deep[d[x]], v);     upd(dep[d[x]], 1);     for (long long k = head[x]; k; k = nex[k])       if (p[k] != fa && !vis[p[k]]) {         if (ps == c[k])           d[p[k]] = d[x];         else           d[p[k]] = d[x] + 1;         dfss(p[k], x, c[k], v);       }   }   inline void cal(long long x) {     upd(ans, a[x]);     for (long long i = 0; i <= Maxx; i++) {       Deep[i][0] = Deep[i][1] = 0;       Dep[i][0] = Dep[i][1] = 0;       deep[i] = dep[i] = 0;     }     d[x] = Maxx = 0;     for (long long k = head[x]; k; k = nex[k])       if (!vis[p[k]]) {         for (long long i = 0; i <= Maxx; i++) deep[i] = dep[i] = 0;         maxx = 0;         d[p[k]] = 0;         dfss(p[k], x, c[k], 0);         for (long long i = 0; i <= maxx; i++) {           upd(ans, ((deep[i] * Dep[min(Maxx, K - i)][c[k]]) % MOD +                     (Deep[min(Maxx, K - i)][c[k]] * dep[i]) % MOD) %                        MOD);           upd(ans, dep[i] * Dep[min(Maxx, K - i)][c[k]] % MOD * a[x] % MOD);           if (K - i - 1 >= 0) {             upd(ans, ((deep[i] * Dep[min(Maxx, K - i - 1)][c[k] ^ 1]) % MOD +                       (Deep[min(Maxx, K - i - 1)][c[k] ^ 1] * dep[i]) % MOD) %                          MOD);             upd(ans,                 dep[i] * Dep[min(Maxx, K - i - 1)][c[k] ^ 1] % MOD * a[x] % MOD);           }         }         while (Maxx < maxx) {           Maxx++;           Deep[Maxx][0] = Deep[Maxx - 1][0];           Deep[Maxx][1] = Deep[Maxx - 1][1];           Dep[Maxx][0] = Dep[Maxx - 1][0];           Dep[Maxx][1] = Dep[Maxx - 1][1];         }         for (long long i = 0; i <= Maxx; i++) {           if (i) {             upd(deep[i], deep[i - 1]);             upd(dep[i], dep[i - 1]);           }           if (i == Maxx) upd(ans, (deep[i] + a[x] * dep[i] % MOD) % MOD);           upd(Deep[i][c[k]], deep[i]);           upd(Dep[i][c[k]], dep[i]);         }       }   }   inline void work(long long x) {     vis[x] = 1;     cal(x);     for (long long k = head[x]; k; k = nex[k])       if (!vis[p[k]]) {         sum = s[p[k]];         rt = 0;         dfs(p[k], 0);         work(rt);       }   }   signed main() {     n = read();     K = read();     for (long long i = 1; i <= n; i++) a[i] = read();     for (long long i = 1; i < n; i++) {       long long x = read(), y = read(), v = read();       addedge(x, y, v);       addedge(y, x, v);     }     f[0] = 1e9;     sum = n;     dfs(1, 0);     work(rt);     writeln(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500;   const int maxm = 500000 + 10;   struct Edge {     int next, v;     Edge() {}     Edge(int next, int v) : next(next), v(v) {}   } e[maxm << 1];   int n, m, timer, num, len;   int head[maxm], cnt;   int dfn[maxn], low[maxn], belo[maxn];   bool inst[maxn], used[maxn];   int st[maxm], top, q[maxm], front, tail;   char org[27], s[maxn], ans[maxn], res[maxn];   int val[128];   inline int read() {     int x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x;   }   inline void AddEdge(int u, int v) {     e[++cnt] = Edge(head[u], v);     head[u] = cnt;   }   void tarjan(int u) {     dfn[u] = low[u] = ++timer;     st[++top] = u;     inst[u] = 1;     for (int i = head[u]; i; i = e[i].next) {       int v = e[i].v;       if (!dfn[v]) {         tarjan(v);         low[u] = min(low[u], low[v]);       } else if (inst[v])         low[u] = min(low[u], dfn[v]);     }     if (dfn[u] == low[u]) {       num++;       int v;       do {         v = st[top--];         belo[v] = num;         inst[v] = 0;       } while (u != v);     }   }   inline bool judge(int tot) {     for (int i = 2; i <= tot; i++)       if (!dfn[i]) tarjan(i);     for (int i = 2; i < tot; i += 2)       if (belo[i] == belo[i + 1]) return 0;     return 1;   }   inline char find(int pos, char ch) {     for (int i = pos + 1; i < len; i++)       if (org[i] == ch) return  a  + i;     return -1;   }   int main() {     scanf( %s , org);     len = strlen(org);     for (int i = 0; i < len; i++)       if (org[i] ==  C ) val[ a  + i] = 1;     n = read(), m = read();     char op1[10], op2[10];     int x, y;     while (m--) {       x = read(), scanf( %s , op1);       y = read(), scanf( %s , op2);       x = x << 1 | (op1[0] ==  C );       y = y << 1 | (op2[0] ==  C );       AddEdge(x, y);       AddEdge(y ^ 1, x ^ 1);     }     scanf( %s , s + 1);     if (!judge(n << 1 | 1)) {       puts( -1 );       return 0;     }     bool exis = 0;     res[1] = -1;     for (int pos = n + 1; pos >= 1; pos--) {       for (int a = pos << 1; a <= (pos << 1 | 1); a++) {         strcpy(ans + 1, s + 1);         if (pos <= n) {           char tp = find(s[pos] -  a , a & 1 ?  V  :  C );           if (tp == -1) continue;           ans[pos] = tp;         }         for (int i = pos + 1; i <= n; i++) ans[i] =  a ;         bool flag = 1;         memset(used, 0, sizeof(used));         for (int i = 1; i <= n && flag; i++) {           x = i << 1 | val[ans[i]];           if (used[x]) continue;           used[x] = 1;           front = tail = 0;           q[++tail] = x;           while (front != tail) {             x = q[++front];             used[x] = 1;             if (used[x ^ 1]) {               flag = 0;               break;             }             if ((x >> 1) <= pos && val[ans[x >> 1]] != (x & 1)) {               flag = 0;               break;             }             if ((x >> 1) > pos) {               char tp = find(-1, x & 1 ?  C  :  V );               if (tp == -1) {                 flag = 0;                 break;               }               ans[x >> 1] = tp;             }             for (int j = head[x]; j; j = e[j].next) {               int v = e[j].v;               if (!used[v]) {                 used[v] = 1;                 q[++tail] = v;               }             }           }         }         if (!flag) continue;         exis = 1;         if (res[1] == -1)           strcpy(res + 1, ans + 1);         else if (strcmp(res + 1, ans + 1) > 0)           strcpy(res + 1, ans + 1);       }       if (exis) break;     }     if (exis)       puts(res + 1);     else       puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e4 + 10;   int n, A[maxn];   int main() {     cin.sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; ++i) cin >> A[i];     int cnt = 0;     for (int i = 2; i <= n - 1; ++i)       if ((A[i] > A[i - 1] && A[i] > A[i + 1]) ||           (A[i] < A[i - 1] && A[i] < A[i + 1]))         ++cnt;     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     double h, w;     cin >> h >> w;     int ans1, ans2, mx = 0;     long long int i = 1;     while (i * 2 <= h && i * 2 <= w) {       i *= 2;     }     ans1 = min((long long int)h, (long long int)(1.25 * i));     ans2 = min((long long int)w, (long long int)(1.25 * i));     if (ans1 >= ans2)       cout << ans1 <<     << i;     else       cout << i <<     << ans2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char str[100005];     scanf( %s , str);     int l = strlen(str);     int pr = -1, i, j;     for (i =  z ; i >=  a ; i--)       for (j = 0; j < l; j++) {         if (str[j] == i && j > pr) {           cout << str[j];           pr = j;         }       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k;     cin >> n >> k;     long long int a[n + 1];     for (long long int i = 1; i < n; i++) cin >> a[i];     long long int i = 1;     long long int sum = 1;     while (i < n) {       if (sum >= k) break;       sum = i + a[i];       i = sum;     }     if (sum == k)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long A, long long b) {     if (b == 0)       return A;     else       return gcd(b, A % b);   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.first != b.first) return a.first < b.first;     return a.second > b.second;   }   long long dist(pair<int, int> a, pair<int, int> b) {     return abs(a.first - b.first) + abs(a.second - b.second);   }   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     map<int, vector<pair<int, int> > > m;     for (long long i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       int lvl = max(a, b);       if (m.find(lvl) == m.end()) {         vector<pair<int, int> > vec;         vec.push_back({a, b});         m[lvl] = vec;       } else {         m[lvl].push_back({a, b});       }     }     map<int, vector<pair<int, int> > >::iterator it = m.begin();     while (it != m.end()) {       sort(it->second.begin(), it->second.end(), cmp);       it++;     }     vector<vector<long long> > dp(n + 2, vector<long long>(2, 1e18));     dp[0][0] = 0;     dp[0][1] = 0;     it = m.begin();     int lvl = 1;     int pre = 0;     m[0] = {{0, 0}};     while (it != m.end()) {       pair<int, int> curl = it->second[0];       pair<int, int> curr = it->second.back();       pair<int, int> prel = m[pre][0];       pair<int, int> prer = m[pre].back();       pre = it->first;       dp[lvl][0] =           min(dp[lvl][0], dp[lvl - 1][0] + dist(prel, curr) + dist(curl, curr));       dp[lvl][0] =           min(dp[lvl][0], dp[lvl - 1][1] + dist(prer, curr) + dist(curl, curr));       dp[lvl][1] =           min(dp[lvl][1], dp[lvl - 1][0] + dist(prel, curl) + dist(curl, curr));       dp[lvl][1] =           min(dp[lvl][1], dp[lvl - 1][1] + dist(prer, curl) + dist(curl, curr));       it++;       lvl++;     }     cout << min(dp[lvl - 1][0], dp[lvl - 1][1]) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, na, nb, nc;   vector<int> a, b;   vector<int> start;   int solve(vector<pair<int, int> > &c, vector<pair<int, int> > &b) {     int nb = b.size();     int nc = c.size();     int ans = 0;     sort(c.begin(), c.end());     sort(b.begin(), b.end());     int i = 0, j = 0;     for (; i < nb && b[i].second; i++)       ;     for (; j < nc && c[j].second; j++)       ;     for (; i < nb && j < nc;) {       int ii = i++, jj = j++;       for (; i < nb && b[i].second; i++)         ;       for (; j < nc && c[j].second; j++)         ;       if (i < nb && j < nc) {         if (ii - i != jj - j) ans++;       }     }     return ans;   }   int main() {     scanf( %d , &n);     b.push_back(0);     for (int i = 0, zz = 0; i < n; i++) {       scanf( %d , &zz);       b.push_back(zz);       for (int j = 0, _x; j < zz; j++) {         scanf( %d , &_x);         a.push_back(_x);       }     }     for (int i = 0; i < n; i++) b[i + 1] += b[i];     int ans = 0;     vector<pair<int, int> > ta, tb;     for (int k = 0; k < n; k++) {       ta.clear();       tb.clear();       for (int i = b[k]; i < b[k + 1]; i++) {         ta.push_back(pair<int, int>(a[i], 0));         tb.push_back(pair<int, int>(a[i], 0));       }       if (k == 0) {         for (int i = b[n - 1]; i < b[n]; i++) {           ta.push_back(pair<int, int>(a[i], 1));         }       } else {         for (int i = b[k - 1]; i < b[k]; i++) {           ta.push_back(pair<int, int>(a[i], 1));         }       }       if (k == n - 2) {         for (int i = b[n - 1]; i < b[n]; i++) {           tb.push_back(pair<int, int>(a[i], 1));         }       } else {         for (int i = b[(k + 1) % n]; i < b[(k + 2) % n]; i++) {           tb.push_back(pair<int, int>(a[i], 1));         }       }       ans += solve(ta, tb);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long n, l, r, x;     cin >> n >> l >> r >> x;     long long c[n];     for (long long i = 0; i < n; i++) cin >> c[i];     long long ans = 0;     for (long long i = 0; i < (1 << n); i++) {       long long mn = INT_MAX;       long long mx = 0;       bool ok = true;       long long dif = 0;       for (long long j = 0; j < n; j++) {         if (i & (1 << j)) {           mx = max(mx, c[j]);           mn = min(mn, c[j]);           dif += c[j];         }       }       ans += (dif >= l && dif <= r && mx - mn >= x);     }     cout << ans <<   n ;   }


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


#include<bits/stdc++.h>      using namespace std;      #define FOR(i, j, k) for(int i = j; i <= k; i++)   #define ROF(i, j, k) for(int i = j; i >= k; i--)   #define PB push_back   #define MEM(n, val) memset((n), val, sizeof(n))   #define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);   #define F first   #define S second   #define MP make_pair   #define LL long long   #define MOD 1000000007   #define MX 200010   #define INFL 1000000000000000000LL   #define INF 1000000000      typedef pair<int, int> PII;   typedef pair<LL, LL> PLL;      int fx[] = {0, 0, 1, -1};   int fy[] = {1, -1, 0, 0};      int n, x;   vector<int> adjl[100010];   int mxlev;   int mxfreq;   int lev_freq[100010];   int freq[100010];   vector<PII> frv;   bool is_lev_a[100010];   int lev[100010];   vector<int> ultalv[100010];         void func(int u, int lv) {       mxlev = max(lv, mxlev);       lev_freq[lv]++;       lev[u] = lv;       ultalv[ lv ].PB(u);       for(int v: adjl[u]) {           func(v, lv + 1);       }   }      int dp[450][100001];   //PII bt[320][100001];      map<int, int> mp_cnt;      int main() {   //    freopen( in.txt ,  r , stdin);   //    freopen( out.txt ,  w , stdout);       FastIO;       mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());          cin >> n >> x;       FOR(v, 2, n) {           int u;           cin >> u;           adjl[u].PB(v);   //        cout << u <<   :   << v <<   n ;       }          func(1, 1);             FOR(i, 1, mxlev) {           freq[ lev_freq[i] ]++;           mxfreq = max(mxfreq, lev_freq[i]);       }       FOR(i, 1, mxfreq) {           if(freq[i]) {               frv.PB({i, freq[i]});           }       }      //    FOR(i, 1, mxlev) {   //        cout << i <<   :   << lev_freq[i] <<   n ;   //    }   //    cout <<   n ;   //    FOR(i, 1, mxfreq) {   //        cout << i <<   :   << freq[i] <<   n ;   //    }   //    cout <<   n ;   //    for(PII val: frv) {   //        cout << val.F <<   :   << val.S <<   n ;   //    }   //    if(x == 237) {   //        cout <<  sz :   << frv.size() << endl;   //    }       MEM(dp, -1);   //    MEM(bt, -1);       int turn = 0;       for(int i = 0; i < frv.size(); i++) {           int val = frv[i].F;           int fr = frv[i].S;           dp[i][0] = 0;           for(int j = 1; j <= x; j++) {               if(i != 0 && dp[i - 1][j] >= 0) {                   dp[i][ j ] = 0;   //                bt[i][j] = {i - 1, j};                   continue;               }               if((j - val >= 0) && (dp[i][j - val] >= 0) && (dp[i][j - val] < fr)) {                   dp[i][j] = dp[i][j - val] + 1;   //                bt[i][j] = {i, j - val};               }           }       }      //    cout <<  dp :  n ;   //    for(int i = 0; i < frv.size(); i++) {   //        for(int j = 0; j <= x; j++) {   //            cout << dp[i][j] <<    ;   //        }   //        cout <<   n ;   //    }   //    cout <<   n ;   //   //    cout << dp[ (int)frv.size() - 1 ][x] <<   n n ;          if(dp[ (int)frv.size() - 1 ][x] >= 0) {           int a = frv.size() - 1, b = x;           while(a != -1 && b != -1) {               if(dp[a][b]) {   //                cout << frv[a].F <<   :   << dp[a][b] <<   n ;                   mp_cnt[ frv[a].F ] = max(mp_cnt[ frv[a].F ], dp[a][b]);               }       //        cout << a <<     << b <<   :   << frv[a].F <<   :   << dp[a][b] <<   n ;               PII nn = {-1, -1};               if(a != 0 && dp[a][b] == 0 && dp[a - 1][b] >= 0) {                   nn = {a - 1, b};               }               int val = frv[a].F;               int fr = frv[a].S;               if((b - val >= 0) && (dp[a][b - val] >= 0) && (dp[a][b - val] < fr) && (dp[a][b] == dp[a][b - val] + 1)) {   //                dp[i][j] = dp[i][j - val] + 1;                   nn = {a, b - val};   //                bt[i][j] = {i, j - val};               }                  a = nn.F;               b = nn.S;           }              FOR(i, 1, mxlev) {               if(mp_cnt[ lev_freq[i] ]) {                   mp_cnt[ lev_freq[i] ]--;                   is_lev_a[i] = 1;               }           }              cout << mxlev <<   n ;           FOR(i, 1, n) {               if(is_lev_a[ lev[i] ]) {                   cout <<  a ;               }               else {                   cout <<  b ;               }           }           return 0;       }          map<int, int> exp;       int sum = n;       FOR(i, 1, mxlev) {           if(lev_freq[i] <= x) {               is_lev_a[i] = 1;               x -= lev_freq[i];               sum -= lev_freq[i];           }           else if(lev_freq[i] <= sum - x) {               sum -= lev_freq[i];           }           else {               vector<int> leaf, nonleaf;               for(int u: ultalv[i]) {                   if(adjl[u].size() > 0) {                       nonleaf.PB(u);                   }                   else {                       leaf.PB(u);                   }               }               if(x >= nonleaf.size()) {                   /// use all x                   sum -= x;                   for(int u: nonleaf) {                       exp[u] = 1;                   }                   x -= nonleaf.size();                   for(int j = 0; j < x; j++) {                       int u = leaf[j];                       exp[u] = 1;                   }                   sum -= leaf.size() - x;                   x = 0;               }               else {                   /// use all sum - x   //                sum = x;   //                x = lev_freq[i] - (sum - x);                   sum -= nonleaf.size();                   int leafbaki = (int)leaf.size() - (sum - x);                      for(int j = 0; j < leafbaki; j++) {                       int u = leaf[j];                       exp[u] = 1;                   }                   x -= leafbaki;                   sum = x;               }           }       }          cout << mxlev + 1 <<   n ;       FOR(i, 1, n) {           if(exp[i]) {               cout <<  a ;               continue;           }           if(is_lev_a[ lev[i] ]) {               cout <<  a ;           }           else {               cout <<  b ;           }       }       return 0;   }   /**   2000000000000   */


#include <bits/stdc++.h>   using namespace std;   const int N = 234567;   int n;   vector<int> e[N];   int f[N];   void dfs(int u, int p) {     int go_before_parent = 0;     int go_after_parent = 0;     for (int i = 0; i < e[u].size(); ++i) {       int v = e[u][i];       if (v == p) {         continue;       }       dfs(v, u);       if (f[v] == 0) {         ++go_before_parent;       } else {         ++go_after_parent;       }     }     int son_degree = go_after_parent;     if (son_degree & 1) {       f[u] = 0;     } else {       f[u] = 1;     }   }   void print_solution(int u, int p) {     for (int i = 0; i < e[u].size(); ++i) {       int v = e[u][i];       if (v == p) {         continue;       }       if (f[v] == 0) {         print_solution(v, u);       }     }     cout << u << endl;     for (int i = 0; i < e[u].size(); ++i) {       int v = e[u][i];       if (v == p) {         continue;       }       if (f[v] == 1) {         print_solution(v, u);       }     }   }   int main() {     cin >> n;     for (int i = 1, j; i <= n; ++i) {       cin >> j;       if (j != 0) {         e[i].push_back(j);         e[j].push_back(i);       }     }     dfs(1, 0);     if (f[1] == 0) {       cout <<  NO  << endl;       return 0;     }     cout <<  YES  << endl;     print_solution(1, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 100;   int x[N], z[2 * N], n, m, k;   struct node {     int v, i;   } y[N];   bool com(node k1, node k2) { return k1.v < k2.v; }   bool f(int w) {     int o = 0, i = 1, j = w, l;     while (i <= n && j <= m) {       if (x[i] <= y[j].v)         z[++o] = x[i], i++;       else         z[++o] = y[j].v, j++;     }     while (i <= n) z[++o] = x[i], i++;     while (j <= m) z[++o] = y[j].v, j++;     for (i = 1, l = 0; i <= o; i += k, l++)       for (j = i; j <= min(o, i + k - 1); j++)         if (z[j] < l) return false;     return true;   }   int main() {     int i, l, r, mid;     scanf( %d%d%d , &n, &m, &k);     for (i = 1; i <= n; i++) scanf( %d , &x[i]);     for (i = 1; i <= m; i++) scanf( %d , &y[i].v), y[i].i = i;     sort(x + 1, x + n + 1);     sort(y + 1, y + m + 1, com);     if (!f(m + 1)) {       puts( -1 );       return 0;     }     l = 0;     r = m + 1;     while (l + 1 < r) {       mid = (l + r) / 2;       if (f(mid))         r = mid;       else         l = mid;     }     printf( %d n , m - r + 1);     for (i = r; i <= m; i++) printf( %d  , y[i].i);   }


#include <bits/stdc++.h>   using namespace std;   const int M = 50 * 1000 * 1000, LG = 40;   int get(long long x, int y) { return (x >> y) & 1; }   int main() {     int n, p;     cin >> n >> p;     for (int i = 0; i < M; i++) {       long long x = (long long)n - 1ll * p * i;       if (x >= i && __builtin_popcount(x) <= i) {         cout << i << endl;         return 0;       }     }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string a;     cin >> a;     int count1 = 0, count2 = 0, count3 = 0, count4 = 0;     for (int i = 0; i < a.length(); i++) {       if (a[i] ==  r  && i % 2 == 0) count1++;       if (a[i] ==  b  && i % 2 == 0) count3++;       if (a[i] ==  b  && i % 2 != 0) count2++;       if (a[i] ==  r  && i % 2 != 0) count4++;     }     cout << min(max(count1, count2), max(count3, count4)) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 2000 * 100 + 100;   vector<pair<int, int> > c[maxN];   bool mark[maxN];   bool used[maxN];   int arr[maxN], ind;   int st[maxN];   struct Ans {     int x, y, z;   };   void dfs(int s) {     mark[s] = true;     st[s] = ind;     arr[ind++] = s;     for (auto x : c[s])       if (!mark[x.first]) dfs(x.first);   }   vector<Ans> ans;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       c[u].push_back({v, i});       c[v].push_back({u, i});     }     for (int i = 0; i < n; i++)       if (!mark[i]) dfs(i);     reverse(arr, arr + n);     for (int t = 0; t < n; t++) {       int s = arr[t];       sort(c[s].begin(), c[s].end(), [](pair<int, int> a, pair<int, int> b) {         return st[a.first] > st[b.first];       });       pair<int, int> last(-1, -1);       for (auto x : c[s])         if (!used[x.second]) {           if (last.first == -1)             last = x;           else {             ans.push_back({last.first + 1, s + 1, x.first + 1});             used[last.second] = true;             used[x.second] = true;             last = pair<int, int>(-1, -1);           }         }     }     cout << ans.size() <<   n ;     for (auto x : ans) cout << x.x <<     << x.y <<     << x.z <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> dijkstra(vector<vector<int>> &edges, int s) {     vector<int> dist(edges.size(), 1e9);     queue<int> pq;     dist[s] = 0;     pq.push(s);     while (!pq.empty()) {       auto u = pq.front();       pq.pop();       auto d = dist[u];       if (d == dist[u])         for (auto &e : edges[u])           if (dist[e] > d + 1) {             dist[e] = d + 1;             pq.push(e);           }     }     return dist;   }   void print_bees(array<int, 3> &bees) {     for (auto x : bees) cout << 1 + x <<    ;     cout << endl;   }   int read_pos() {     int n;     cin >> n;     return n - 1;   }   bool done(array<int, 3> &bees, int N) {     for (auto x : bees)       if (x == N) return true;     return false;   }   const array<array<int, 3>, 6> perms{{{{0, 1, 2}},                                        {{0, 2, 1}},                                        {{1, 0, 2}},                                        {{1, 2, 0}},                                        {{2, 0, 1}},                                        {{2, 1, 0}}}};   void solve() {     int n, m;     cin >> n >> m;     vector<vector<int>> g(n);     while (m--) {       int u, v;       cin >> u >> v;       --u, --v;       g[u].push_back(v);       g[v].push_back(u);     }     vector<vector<int>> dist(n);     for (int i = 0; i < n; ++i) dist[i] = dijkstra(g, i);     array<int, 3> bees;     for (auto &x : bees) x = rand() % n;     print_bees(bees);     int N;     while (true) {       N = read_pos();       if (done(bees, N)) return;       for (int i = 0; i < 3; ++i) {         if (dist[bees[i]][N] == 1) {           bees[i] = N;           print_bees(bees);           cerr <<  at dist 1 n ;           return;         }       }       vector<int> nbs = g[N];       assert(nbs.size() <= 3);       while (nbs.size() < 3) nbs.push_back(nbs.back());       int best_dist = -1;       array<int, 3> best_bees;       for (auto perm : perms) {         array<int, 3> ps;         for (int i = 0; i < 3; ++i) ps[i] = nbs[perm[i]];         array<int, 3> newbees = bees;         for (int i = 0; i < 3; ++i) {           if (bees[i] == ps[i]) continue;           for (auto d : g[bees[i]])             if (dist[ps[i]][d] < dist[ps[i]][bees[i]]) {               newbees[i] = d;               break;             }         }         int maxdist = 0;         for (int i = 0; i < 3; ++i) maxdist = (maxdist + dist[ps[i]][newbees[i]]);         if (best_dist == -1 or maxdist < best_dist) {           best_dist = maxdist;           best_bees = newbees;         }       }       for (int i = 0; i < 3; ++i) assert(dist[bees[i]][best_bees[i]] <= 1);       bees = best_bees;       print_bees(bees);       if (done(bees, N)) {         cerr <<  this shouldn t happen n ;         return;       }     }   }   int main() {     srand(123245);     solve();   }


#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long b, long long p, long long md) {     if (p == 0) return 1;     if (p % 2 == 1) {       return ((b % md) * bigmod(b, p - 1, md)) % md;     } else {       long long y = bigmod(b, p / 2, md);       return (y * y) % md;     }   }   int cnt[70];   char getchar(int a) {     if (a >= 0 && a <= 9)       return  0  + a;     else if (a >= 10 && a <= 35)       return  a  + a - 10;     else       return  A  + a - 36;   }   int main() {     int n;     cin >> n;     string str;     cin >> str;     for (int i = 0; i < n; i++) {       if (str[i] >=  0  && str[i] <=  9 )         cnt[str[i] -  0 ]++;       else if (str[i] >=  a  && str[i] <=  z )         cnt[str[i] -  a  + 10]++;       else         cnt[str[i] -  A  + 36]++;     }     vector<int> odd;     for (int i = 0; i <= 61; i++) {       if (cnt[i] % 2) {         odd.push_back(i);       }     }     if (odd.size() == 0) {       cout << 1 << endl;       deque<char> dq;       for (int i = 0; i <= 61; i++) {         while (cnt[i]) {           dq.push_back(getchar(i));           dq.push_front(getchar(i));           cnt[i] -= 2;         }       }       for (auto it = dq.begin(); it != dq.end(); it++) cout << *it;       cout << endl;       return 0;     }     int sz = 0;     for (int i = odd.size(); i <= str.size(); i += 2) {       if (str.size() % i) continue;       sz = str.size() / i;       if (sz % 2) break;     }     int total = str.size() / sz;     cout << total << endl;     int c = 0;     while (c != total) {       deque<char> dq;       if (c < odd.size())         dq.push_back(getchar(odd[c])), cnt[odd[c]]--;       else {         for (int i = 0; i <= 61; i++) {           if (cnt[i]) {             dq.push_back(getchar(i));             cnt[i]--;             break;           }         }       }       for (int i = 0; i <= 61; i++) {         while (cnt[i] >= 2 && dq.size() < sz) {           dq.push_back(getchar(i));           dq.push_front(getchar(i));           cnt[i] -= 2;         }       }       for (auto it = dq.begin(); it != dq.end(); it++) cout << *it;       cout <<    ;       c++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O3 )   int i, j, k, n, m, res, kilk, cnt;   vector<int> nums;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m;     if (n < 3) return cout <<  Yes  <<   n , 0;     while (m) {       if (m % n == 0 || m % n == 1)         m /= n;       else {         if (m % n == n - 1)           m = m / n + 1;         else           return cout <<  No  <<   n , 0;       }     }     cout <<  Yes  <<   n ;     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     char in[n];     int result = 0;     scanf( %s , in);     for (int i = 0; i < n; i++) {       if (in[i] ==  < ) {         result++;       } else {         break;       }     }     for (int i = n - 1; i >= 0; i--) {       if (in[i] ==  > ) {         result++;       } else {         break;       }     }     printf( %d n , result);   }


#include <bits/stdc++.h>   using namespace std;   const int len = 3050;   int d[len];   int ans(int n) {     int sum = 0;     while (true) {       int i;       if (!d[0]) break;       for (i = 0; i < n;) {         if (i == n - 1) {           sum++;           break;         }         if (i < n - 2 && d[i + 2])           i += 2;         else if (i < n - 1 && d[i + 1])           i++;         else           return sum;       }       for (i = 0; i < n; i++)         if (d[i] >= 1) d[i]--;     }     return sum;   }   int main() {     int n;     while (~scanf( %d , &n)) {       for (int i = 0; i < n; i++) {         scanf( %d , &d[i]);       }       printf( %d n , ans(n));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int count = 0;       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  B  && count > 0) {           count--;         } else {           count++;         }       }       cout << count << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout << (n / 2) + n;   }


#include <bits/stdc++.h>   using namespace std;   int dp[51][51], n;   int len[2];   bool ok[2][26][51][51];   char str[50][51], s[2][51];   void Init(int id) {     int st, ed, L, mid;     for (int i = 0; i < len[id]; i++) ok[id][s[id][i] -  a ][i + 1][i + 1] = true;     for (L = 2; L <= len[id]; L++)       for (st = 1, ed = st + L - 1; ed <= len[id]; st++, ed++)         for (mid = st; mid < ed; mid++)           for (int i = 0; i < n; i++)             if (ok[id][str[i][3] -  a ][st][mid] &&                 ok[id][str[i][4] -  a ][mid + 1][ed])               ok[id][str[i][0] -  a ][st][ed] = true;   }   int main() {     for (int i = 0; i < 2; i++) {       scanf( %s n , s[i]);       len[i] = strlen(s[i]);     }     scanf( %d n , &n);     for (int i = 0; i < n; i++) scanf( %s n , str[i]);     Init(0);     Init(1);     for (int i = 0; i < 51; i++)       for (int j = 0; j < 51; j++) dp[i][j] = 99999999;     dp[0][0] = 0;     for (int i = 1; i <= len[0]; i++)       for (int j = 1; j <= len[1]; j++)         for (int q = 0; q < i; q++)           for (int p = 0; p < j; p++)             if (dp[q][p] < dp[len[0]][len[1]])               for (int ch = 0; ch < 26; ch++)                 if (ok[0][ch][q + 1][i] && ok[1][ch][p + 1][j]) {                   dp[i][j] = min(dp[q][p] + 1, dp[i][j]);                   break;                 }     if (dp[len[0]][len[1]] < 999999)       printf( %d n , dp[len[0]][len[1]]);     else       puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<long long>> matrixMul(vector<vector<long long>> lft,                                       vector<vector<long long>> rit,                                       long long mod = 1e9 + 7) {     int n = lft.size(), s = rit.size(), m = rit.back().size();     vector<vector<long long>> res(n, vector<long long>(m, 0));     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         for (int k = 0; k < s; ++k)           res[i][j] = (res[i][j] + lft[i][k] * rit[k][j]) % mod;     return res;   }   vector<vector<long long>> matrixPow(vector<vector<long long>> base,                                       long long exp, long long mod = 1e9 + 7) {     int n = base.size();     vector<vector<long long>> res(n, vector<long long>(n, 0));     for (int i = 0; i < n; ++i) res[i][i] = 1;     for (; exp; exp >>= 1, base = matrixMul(base, base, mod))       if (exp & 1) res = matrixMul(res, base, mod);     return res;   }   int main() {     long long n, m;     cin >> n >> m;     vector<vector<long long>> mat;     mat.resize(m);     for (int i = 0; i < m; ++i) mat[i].resize(m);     for (int i = 0; i < m; ++i)       for (int j = 0; j < m; ++j) {         mat[i][j] = 0;       }     for (int i = 1; i < m; ++i) mat[i][i - 1] = 1;     mat[0][0] = 1;     mat[0][m - 1] = 1;     cout << matrixPow(mat, n)[0][0];   }


#include <bits/stdc++.h>   using namespace std;   const int base = 1000 * 1000 * 1000, inf = 1000 * 1000 * 1000;   int buf = 0;   long long gcd(long long a, long long b) {     while (b) b ^= a ^= b ^= a %= b;     return a;   }   int p[10], e[10][10];   string a[10];   int main() {     int n, k, ans = inf;     cin >> n >> k;     for (int(i) = (1); (i) <= (n); ++(i)) {       cin >> a[i];       for (int(j) = 0; (j) < (a[i].length()); ++(j)) e[i][j + 1] = a[i][j] -  0 ;     }     for (int(i) = (1); (i) <= (k); ++(i)) p[i] = i;     bool ok = true;     for (;;) {       if (!ok) break;       int MAX = -inf, MIN = inf;       for (int(i) = (1); (i) <= (n); ++(i)) {         int w[10];         long long buf = 0;         for (int(j) = (1); (j) <= (k); ++(j)) {           w[j] = e[i][p[j]];           long long y = 1;           for (int(qq) = 0; (qq) < (k - j); ++(qq)) y *= 10;           buf += w[j] * y;         }         if (buf > MAX) MAX = buf;         if (buf < MIN) MIN = buf;       }       if (ans > MAX - MIN) ans = MAX - MIN;       ok = false;       for (int i = k - 1; i >= 1; i--) {         if (p[i] < p[i + 1]) {           int mn = -1;           for (int(j) = (i + 1); (j) <= (k); ++(j))             if (mn == -1 || p[j] > p[i] && p[j] < p[mn]) mn = j;           swap(p[i], p[mn]);           reverse(p + i + 1, p + k + 1);           ok = true;           break;         }       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   char s[2000], t[2000];   int f[2000];   int main() {     int n, m, q;     scanf( %d%d%d , &n, &m, &q);     scanf( %s , s + 1);     scanf( %s , t + 1);     for (int i = 1; i <= n - m + 1; i++) {       int flag = 1;       for (int j = 1; j <= m; j++)         if (s[i + j - 1] != t[j]) {           flag = 0;           break;         }       f[i] = f[i - 1] + flag;     }     for (int i = 1; i <= q; i++) {       int l, r;       scanf( %d%d , &l, &r);       if (r - l + 1 < m)         printf( 0 n );       else         printf( %d n , f[r - m + 1] - f[l - 1]);     }   }


#include <bits/stdc++.h>   const int maxn = 3e5 + 1;   inline long long max(long long a, long long b) { return a > b ? a : b; }   inline long long min(long long a, long long b) { return a < b ? a : b; }   long long rev[19], n, m, opt, k, x, l, r;   struct Segment_Tree {     long long val[maxn << 2];     inline void pushup(long long rt) {       val[rt] = val[rt << 1] + val[rt << 1 | 1];     }     inline void build(long long rt, long long l, long long r) {       if (l == r) return (void)(scanf( %lld , &val[rt]));       build(rt << 1, l, ((l + r) >> 1));       build(rt << 1 | 1, ((l + r) >> 1) + 1, r);       pushup(rt);     }     inline void update(long long rt, long long l, long long r, long long k,                        long long ch, long long dep) {       if (l == r) return (void)(val[rt] = ch);       if (k > ((l + r) >> 1)) {         if (rev[dep])           update(rt << 1, ((l + r) >> 1) + 1, r, k, ch, dep - 1);         else           update(rt << 1 | 1, ((l + r) >> 1) + 1, r, k, ch, dep - 1);       } else {         if (rev[dep])           update(rt << 1 | 1, l, ((l + r) >> 1), k, ch, dep - 1);         else           update(rt << 1, l, ((l + r) >> 1), k, ch, dep - 1);       }       pushup(rt);     }     inline long long query(long long rt, long long l, long long r, long long L,                            long long R, long long dep) {       if (L <= l && r <= R) return val[rt];       long long ans = 0;       if (L <= ((l + r) >> 1)) {         if (rev[dep])           ans += query(rt << 1 | 1, l, ((l + r) >> 1), L, R, dep - 1);         else           ans += query(rt << 1, l, ((l + r) >> 1), L, R, dep - 1);       }       if (R > ((l + r) >> 1)) {         if (rev[dep])           ans += query(rt << 1, ((l + r) >> 1) + 1, r, L, R, dep - 1);         else           ans += query(rt << 1 | 1, ((l + r) >> 1) + 1, r, L, R, dep - 1);       }       return ans;     }   } t;   signed main() {     scanf( %lld %lld , &n, &m);     t.build(1, 1, (1ll << n));     for (long long i = 1; i <= m; i++) {       scanf( %lld , &opt);       if (opt == 1)         scanf( %lld %lld , &x, &k), t.update(1, 1, (1ll << n), x, k, n);       if (opt == 2) {         scanf( %lld , &k);         for (long long yny = 0; yny <= k; yny++) rev[yny] ^= 1;       }       if (opt == 3) scanf( %lld , &k), rev[k + 1] ^= 1;       if (opt == 4)         scanf( %lld %lld , &l, &r),             printf( %lld n , t.query(1, 1, (1ll << n), l, r, n));     }   }


#include <bits/stdc++.h>   using namespace std;   inline void normal(long long int& a) { a = (a + 1000000007) % 1000000007; }   inline int modMul(long long int a, long long int b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     return (a * b) % 1000000007;   }   inline int modAdd(long long int a, long long int b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     return (a + b) % 1000000007;   }   inline int modSub(long long int a, long long int b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     a -= b;     normal(a);     return a;   }   inline int modPow(long long int b, long long int p) {     int r = 1;     while (p) {       if (p & 1) r = modMul(r, b);       b = modMul(b, b);       p >>= 1;     }     return r;   }   inline int modInv(int a) { return modPow(a, 1000000007 - 2); }   inline int modDiv(int a, int b) { return modMul(a, modInv(b)); }   inline int fact(int r) {     int ans = 1;     while (r) ans = modMul(ans, r), r--;     return ans;   }   inline int invfact(int r) {     int ans = 1;     while (r) ans = modMul(ans, modInv(r)), r--;     return ans;   }   inline double dgcd(double a, double b) {     if (a < b) return dgcd(b, a);     if (b < .0001) return a;     return dgcd(b, fmod(a, b));   }   const long long int N = 2e5 + 1;   const long long int INF = 2e18;   clock_t start;   mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& q) {     in >> q.first >> q.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2>& q) {     out << q.first <<     << q.second;     return out;   }   template <typename T1, typename T2>   pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2) {     return {p1.first + p2.first, p1.second + p2.second};   }   template <typename T1, typename T2>   pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2) {     return {p1.first - p2.first, p1.second - p2.second};   }   long long int power(long long int base, long long int exp) {     long long int res = 1;     while (exp > 0) {       if (exp % 2 == 1) res = (res * base) % 1000000007;       base = (base * base) % 1000000007;       exp /= 2;     }     return res % 1000000007;   }   bool isPrime(int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   void Timelimitexceeded() {     long long int n;     cin >> n;     vector<long long int> v;     long long int temp;     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       if (i == 0)         v.push_back(x), temp = x;       else {         temp += x;         v.push_back(temp);       }     }     long long int q;     cin >> q;     while (q--) {       long long int x;       cin >> x;       long long int l = 0, u = n;       while (l <= u) {         long long int mid = (l + u) / 2;         if (v[mid] < x)           l = mid + 1;         else           u = mid - 1;       }       cout << l + 1 <<   n ;     }     return;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     clock_t start, end;     start = clock();     cout << fixed << setprecision(11);     while (t--) {       Timelimitexceeded();     }     end = clock();     double time_taken = double(end - start) / double(CLOCKS_PER_SEC);   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f, oo = inf;   inline long long read() {     register long long x = 0;     char f = 0;     register char c = getchar();     for (; !isdigit(c); c = getchar()) f |= (c ==  - );     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     return f ? -x : x;   }   inline double readdb() {     register double x = 0, p = 0.1;     register char f = 0, c = getchar();     for (; !isdigit(c); c = getchar()) f |= (c ==  - );     for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);     if (c ==  . )       for (c = getchar(); isdigit(c); c = getchar(), p /= 10)         x = x + (c ^ 48) * p;     return f ? -x : x;   }   inline void write(long long x) {     if (x < 0) x = -x, putchar( - );     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   inline void writeln(long long x) {     write(x);     puts(  );   }   inline void writeln(long long x, char c, long long y) {     write(x);     putchar(c);     writeln(y);   }   inline void writeln(long long x, char c, long long y, char d, long long z) {     write(x);     putchar(c);     write(y);     putchar(d);     writeln(z);   }   const int maxn = 3e5 + 233;   const int maxm = 6e5 + 233;   struct Edge {     int to, nxt, dist;     Edge() {}     Edge(int to, int nxt, int dist) : to(to), nxt(nxt), dist(dist) {}   } edge1[maxm], edge2[maxm];   int first1[maxn], first2[maxn];   int nume1, nume2;   void Addedge1(int a, int b, int c) {     edge1[nume1] = Edge(b, first1[a], c);     first1[a] = nume1++;   }   int s[maxn], dfn[maxn], low[maxn], dfsclk = 0;   bool Ins[maxn];   int bel[maxn];   int val[maxn], dist[maxn];   void Tarjan(int u, int fa) {     dfn[u] = low[u] = ++dfsclk;     Ins[u] = true;     s[++*s] = u;     for (int e = first1[u]; ~e; e = edge1[e].nxt) {       int v = edge1[e].to;       if (v == fa) continue;       if (!dfn[v]) {         Tarjan(v, u);         low[u] = min(low[u], low[v]);       } else if (Ins[v]) {         low[u] = min(low[u], dfn[v]);       }     }     if (dfn[u] == low[u]) {       bel[0]++;       for (;;) {         int v = s[s[0]--];         Ins[v] = false;         bel[v] = *bel;         if (u == v) break;       }     }   }   void Addedge2(int a, int b, int c) {     edge2[nume2] = Edge(b, first2[a], c);     first2[a] = nume2++;   }   void rebuild() {     memset(val, false, sizeof(val));     for (int i = 0; i < nume1; i += 2) {       int u = bel[edge1[i ^ 1].to];       int v = bel[edge1[i].to];       int w = edge1[i].dist;       if (u != v) {         Addedge2(u, v, w);         Addedge2(v, u, w);       } else if (w) {         val[u] = true;       }     }   }   int front, rear, q[maxn];   void BFS(int S, int T) {     memset(dist, -1, sizeof(dist));     front = rear = 0;     q[rear++] = S;     dist[S] = val[S];     while (front < rear) {       int u = q[front++];       for (int e = first2[u]; ~e; e = edge2[e].nxt) {         int v = edge2[e].to;         if (dist[v] == -1) {           dist[v] = dist[u] | edge2[e].dist | val[v];           q[rear++] = v;         }       }     }     if (dist[T]) {       puts( YES );     } else {       puts( NO );     }   }   int n, m;   int main() {     n = read(), m = read();     memset(first1, -1, sizeof(first1));     nume1 = 0;     memset(first2, -1, sizeof(first2));     nume2 = 0;     for (register int i = (1); i <= (m); ++i) {       int a = read(), b = read(), c = read();       Addedge1(a, b, c);       Addedge1(b, a, c);     }     memset(dfn, 0, sizeof(dfn));     *bel = 0;     Tarjan(1, 0);     rebuild();     int s = read(), t = read();     BFS(bel[s], bel[t]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 50;   int n, p, first[N], second[N];   double tmin = 1e9;   pair<double, int> d[N];   bool ok(double x) {     double tp = x * p;     for (int i = 0; i < n; ++i) {       tp -= max(first[i] * x - second[i], 0.0);     }     return tp >= 0;   }   int main() {     cin.sync_with_stdio(0);     cin >> n >> p;     for (int i = 0; i < n; ++i) cin >> first[i] >> second[i];     double lo = 0, hi = 1e20, mid;     if (ok(hi)) {       printf( -1 );     } else {       for (int i = 0; i < 1000; ++i) {         mid = (lo + hi) / 2;         if (ok(mid))           lo = mid;         else           hi = mid;       }       printf( %.6f , mid);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int MOD2 = (int)1e8 + 7;   const int INF = (int)1e9;   const long long LINF = (long long)1e18;   const long double PI = acos((long double)-1);   const long double EPS = 1e-9;   inline long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   template <class T>   inline int chkmin(T& a, const T& val) {     return val < a ? a = val, 1 : 0;   }   template <class T>   inline int chkmax(T& a, const T& val) {     return a < val ? a = val, 1 : 0;   }   inline long long isqrt(long long k) {     long long r = sqrt(k) + 1;     while (r * r > k) r--;     return r;   }   inline long long icbrt(long long k) {     long long r = cbrt(k) + 1;     while (r * r * r > k) r--;     return r;   }   inline void addmod(int& a, int val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   inline void submod(int& a, int val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }   inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }   inline int sign(long double x, long double y) { return sign(x - y); }   template <class TF, class TC, TF Foo, TC Coo>   struct MinCostMaximumFlow {     static const int MAXV = 1e5 + 5;     static const int MAXE = 1e6 + 5;     int n, s, t, E;     int adj[MAXE], nxt[MAXE], lst[MAXV], frm[MAXV], vis[MAXV];     TF cap[MAXE], flw[MAXE], totalFlow;     TC cst[MAXE], dst[MAXV], totalCost;     void init(int n, int s, int t) {       this->n = n, this->s = s, this->t = t;       fill_n(lst, n, -1), E = 0;     }     void add(int u, int v, TF ca, TC co) {       adj[E] = v, cap[E] = ca, flw[E] = 0, cst[E] = +co, nxt[E] = lst[u],       lst[u] = E++;       adj[E] = u, cap[E] = 0, flw[E] = 0, cst[E] = -co, nxt[E] = lst[v],       lst[v] = E++;     }     int spfa() {       fill_n(dst, n, Coo), dst[s] = 0;       queue<int> que;       que.push(s);       while (que.size()) {         int u = que.front();         que.pop();         for (int e = lst[u]; e != -1; e = nxt[e])           if (flw[e] < cap[e]) {             int v = adj[e];             if (dst[v] > dst[u] + cst[e]) {               dst[v] = dst[u] + cst[e];               frm[v] = e;               if (!vis[v]) {                 vis[v] = 1;                 que.push(v);               }             }           }         vis[u] = 0;       }       return dst[t] < Coo;     }     TC mincost() {       totalCost = 0, totalFlow = 0;       while (1) {         if (!spfa()) break;         TF mn = Foo;         for (int v = t, e = frm[v]; v != s; v = adj[e ^ 1], e = frm[v])           mn = min(mn, cap[e] - flw[e]);         for (int v = t, e = frm[v]; v != s; v = adj[e ^ 1], e = frm[v]) {           flw[e] += mn;           flw[e ^ 1] -= mn;         }         totalFlow += mn;         totalCost += mn * dst[t];       }       return totalCost;     }   };   MinCostMaximumFlow<int, int, (int)1e9, (int)1e9> mcmf;   const int maxn = 5e3 + 5;   int n;   int a[maxn];   int num[100005];   void solve() {     cin >> n;     for (int i = (0); i < (n); i++) cin >> a[i];     int tot = n + n, s = tot++, t = tot++, ss = tot++;     mcmf.init(tot, ss, t);     mcmf.add(ss, s, 2, 0);     for (int i = (0); i < (n); i++) {       mcmf.add(s, i, 1, 0);       mcmf.add(i + n, t, 1, 0);       mcmf.add(i, i + n, 1, -1);       static int* his[maxn];       int nhis = 0;       for (int j = (i + 1); j < (n); j++)         if (abs(a[i] - a[j]) == 1) {           his[nhis++] = &num[a[j]];           if (num[a[j]]++ <= 4) {             mcmf.add(i + n, j, 1, 0);           }         }       for (int j = (0); j < (nhis); j++) (*his[j])--;     }     vector<int> lst[7];     for (int i = (n)-1; i >= (0); i--) {       int r = a[i] % 7;       for (int j = (0); j < (int((lst[r]).size())); j++) {         mcmf.add(i + n, lst[r][j], 1, 0);       }       while (int((lst[r]).size()) > 4) lst[r].erase(lst[r].begin());       lst[r].push_back(i);     }     cout << -mcmf.mincost() <<   n ;   }   int main() {     int JUDGE_ONLINE = 1;     if (fopen( in.txt ,  r )) {       JUDGE_ONLINE = 0;       assert(freopen( in.txt ,  r , stdin));     } else {       ios_base::sync_with_stdio(0), cin.tie(0);     }     solve();     if (!JUDGE_ONLINE) {     }     return 0;   }