#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   struct edge {     int from;     int to;     int w;   };   int comp(const edge& f, const edge& l) {     if (f.from < l.from)       return 1;     else if (f.from > l.from)       return 0;     else {       if (f.w > l.w) return 1;     }     return 0;   }   map<int, vector<edge> > d;   int check_cnt(int sum) {     sort(d[sum].begin(), d[sum].end(), comp);     set<pair<int, int> > wait;     int cnt = 0;     for (edge it : d[sum]) {       if (it.w == 1)         wait.insert({it.from, it.to});       else {         if (wait.count({it.to, it.from})) {           cnt++;           wait.clear();         }       }     }     return cnt;   }   void make(int sum) {     sort(d[sum].begin(), d[sum].end(), comp);     set<pair<int, int> > wait;     for (edge& it : d[sum]) {       if (it.w == 1)         wait.insert({it.from, it.to});       else {         if (wait.count({it.to, it.from})) {           cout << it.to + 1 <<     << it.from + 1 <<   n ;           wait.clear();         }       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int n;     cin >> n;     vector<int> a(n);     vector<int> p(n + 1, 0);     for (int i = 0; i < n; i++) {       cin >> a[i];       p[i + 1] = p[i] + a[i];     }     int sum = 0;     for (int i = 0; i < n; i++) {       for (int j = i; j < n; j++) {         sum = p[j + 1] - p[i];         d[sum].push_back((edge){i, j, 1});         d[sum].push_back((edge){j, i, -1});       }     }     int max_val = 0, max_cnt = 0, cnt = 0;     for (auto& it : d) {       cnt = check_cnt(it.first);       if (max_cnt < cnt) {         max_cnt = cnt;         max_val = it.first;       }     }     cout << max_cnt <<   n ;     make(max_val);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long fastexp(long long b, long long exp) {     if (exp == 0) return 1;     long long temp = fastexp(b, exp / 2);     temp = (temp * temp) % 998244353;     if (exp % 2 == 1) temp *= b;     return temp % 998244353;   }   long long fact[100001], inv[100001];   void precompute() {     fact[0] = 1;     inv[0] = 1;     for (int i = 1; i <= 100000; i++) {       fact[i] = (fact[i - 1] * i) % 998244353;       inv[i] = fastexp(fact[i], 998244353 - 2);     }   }   long long choose(int n, int k) {     if (n < 0 || k < 0 || k > n) return 0;     long long ans = (fact[n] * inv[k]) % 998244353;     ans = (ans * inv[n - k]) % 998244353;     return ans;   }   bool row[3605], col[3605];   int H, W, N;   long long dp1[3605][3605], dp2[3605][3605];   int emptyH, emptyW;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     precompute();     cin >> H >> W >> N;     for (int i = 0; i < N; i++) {       int r1, c1, r2, c2;       cin >> r1 >> c1 >> r2 >> c2;       row[r1] = true;       row[r2] = true;       col[c1] = true;       col[c2] = true;     }     for (int i = 1; i <= H; i++)       if (!row[i]) emptyH++;     for (int i = 1; i <= W; i++)       if (!col[i]) emptyW++;     dp1[0][0] = true;     for (int i = 1; i <= H; i++) {       for (int j = 0; j <= i; j++) {         if (row[i] || row[i - 1])           dp1[i][j] = dp1[i - 1][j];         else {           dp1[i][j] = dp1[i - 1][j];           if (i - 2 >= 0 && j - 1 >= 0) dp1[i][j] += dp1[i - 2][j - 1];           dp1[i][j] %= 998244353;         }       }     }     dp2[0][0] = true;     for (int i = 1; i <= W; i++) {       for (int j = 0; j <= i; j++) {         if (col[i] || col[i - 1])           dp2[i][j] = dp2[i - 1][j];         else {           dp2[i][j] = dp2[i - 1][j];           if (i - 2 >= 0 && j - 1 >= 0) dp2[i][j] += dp2[i - 2][j - 1];           dp2[i][j] %= 998244353;         }       }     }     long long ans = 0;     for (int i = 0; i <= H; i++) {       for (int j = 0; j <= W; j++) {         long long R = dp1[H][j] * choose(emptyH - 2 * j, i);         R %= 998244353;         long long C = dp2[W][i] * choose(emptyW - 2 * i, j);         C %= 998244353;         long long F = (fact[i] * fact[j]) % 998244353;         ans += ((R * C) % 998244353 * F) % 998244353;         ans %= 998244353;       }     }     cout << ans << endl;     return 0;   }


#include<bits/stdc++.h> /*   #include <ext/pb_ds/assoc_container.hpp> // Common file   #include <ext/pb_ds/tree_policy.hpp> // Including */   using namespace std;   //using namespace __gnu_pbds;      //typedefs      typedef long long ll;   typedef vector<int> vi;   typedef vector<ll> vl;   typedef vector<vi> vvi;   typedef vector<vl> vvl;   typedef pair<int,int> pii;   typedef pair<double, double> pdd;   typedef pair<ll, ll> pll;   typedef vector<pii> vii;   typedef vector<pll> vll;   typedef vector<int>::iterator vit;   typedef set<int>::iterator sit;      /*   template<typename T>   using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;   template<typename F, typename S>   using ordered_map = tree<F, S, less<F>, rb_tree_tag, tree_order_statistics_node_update>;   */      //#Defines   #define rep(i,a,b) for(i=a;i<=b;i++)   #define repR(i,a,b) for(i=a;i>=b;i--)   //#define pb push_back   #define pb emplace_back   #define F first   #define S second   #define mp make_pair   #define all(c)  c.begin(),c.end()   #define endl   n    #define pf printf   #define sf scanf   //#define left __left   //#define right __right   //#define tree __tree   #define MOD 1000000007   //#define harmonic(n) 0.57721566490153286l+log(n)      #define RESET(a,b) memset(a,b,sizeof(a))   #define gcd(a,b) __gcd(a,b)   #define lcm(a,b) (a*(b/gcd(a,b)))   #define sqr(a) ((a) * (a))      #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);   #define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);      const double PI = acos(-1);   const double eps = 1e-9;   const int inf = 2000000000;   const ll infLL = 9000000000000000000;         //Bit Operations   inline bool checkBit(ll n, int i) { return n&(1LL<<i); }   inline ll setBit(ll n, int i) { return n|(1LL<<i);; }   inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }      int fx[] = {0, 0, +1, -1};   int fy[] = {+1, -1, 0, 0};   //int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};   //int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};         //Inline functions      inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }   inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }   inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }   inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }   inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }   inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }   inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }   inline ll modInverse(ll a) { return modPow(a, MOD-2); }   inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }   inline bool isInside(pii p,ll n,ll m) { return (p.first>=0&&p.first<n&&p.second>=0&&p.second<m); }   inline bool isInside(pii p,ll n)  { return (p.first>=0&&p.first<n&&p.second>=0&&p.second<n); }   inline bool isSquare(ll x)     { ll s = sqrt(x); return (s*s==x); }   inline bool isFib(ll x)     { return isSquare(5*x*x+4)|| isSquare(5*x*x-4); }   inline bool isPowerOfTwo(ll x)   { return ((1LL<<(ll)log2(x))==x); }         struct func   {    //this is a sample overloading function for sorting stl    bool operator()(pii const &a, pii const &b)     {     if(a.F==b.F)      return (a.S<b.S);     return (a.F<b.F);    }   };      //Prime Number Generator      /*   #define M 100000000   int marked[M/64 + 2];      #define on(x) (marked[x/64] & (1<<((x%64)/2)))   #define mark(x)  marked[x/64] |= (1<<((x%64)/2))      vl prime;      bool isPrime(int num) {     return num > 1 && (num == 2 || ((num & 1) && !on(num)));    }      void sieve(ll n) {    for (ll i = 3; i * i < n; i += 2) {     if (!on(i)) {      for (ll j = i * i; j <= n; j += i + i) {       mark(j);      }     }    }    prime.pb(2);    for(ll i = 3; i <= n; i += 2) {     if(!on(i)) prime.pb(i);     }   }      */      //   //debug   #ifdef tajir   template < typename F, typename S >   ostream& operator << ( ostream& os, const pair< F, S > & p ) {    return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }      template < typename T >   ostream &operator << ( ostream & os, const vector< T > &v ) {    os <<  { ;    for(auto it = v.begin(); it != v.end(); ++it) {     if( it != v.begin() ) os <<  ,  ;      os << *it;    }    return os <<  } ;   }      template < typename T >   ostream &operator << ( ostream & os, const set< T > &v ) {    os <<  [ ;    for(auto it = v.begin(); it != v.end(); ++it) {     if( it != v.begin() ) os <<  ,  ;      os << *it;    }    return os <<  ] ;   }      template < typename T >   ostream &operator << ( ostream & os, const multiset< T > &v ) {    os <<  [ ;    for(auto it = v.begin(); it != v.end(); ++it) {     if( it != v.begin() ) os <<  ,  ;     os << *it;    }    return os <<  ] ;   }      template < typename F, typename S >   ostream &operator << ( ostream & os, const map< F, S > &v ) {    os <<  [ ;    for(auto it = v.begin(); it != v.end(); ++it) {     if( it != v.begin() ) os <<  ,  ;     os << it -> first <<   =   << it -> second ;     }    return os <<  ] ;   }      #define dbg(args...) do {cerr << #args <<   :  ; faltu(args); } while(0)      clock_t tStart = clock();   #define timeStamp dbg( Execution Time:  , (double)(clock() - tStart)/CLOCKS_PER_SEC)      void faltu () {    cerr << endl;   }      template <typename T>   void faltu( T a[], int n ) {    for(int i = 0; i < n; ++i) cerr << a[i] <<    ;    cerr << endl;   }      template <typename T, typename ... hello>   void faltu( T arg, const hello &... rest) {    cerr << arg <<    ;    faltu(rest...);   }   #else   #define dbg(args...)   #endif // tajir      int main()   {    #ifdef tajir     freopen( input.txt ,  r , stdin);    #else     // online submission    #endif    optimize();        int n;    int a[10001];    int x[10001];       cin >> n;       a[0] = 0;       for(int i = 1; i <= n; ++i)     cin >> a[i];       for(int i = n; i > 0; --i) {     x[i-1] = a[i] - a[i-1];    }    dbg(x,n);       vi res;       for(int i = 1; i <= n; ++i) {     vi v(i,-inf);     dbg(i);     bool flag = true;     for(int j = 0; j < n; ++j) {      if(v[j%i] == -inf)       v[j%i] = x[j];      else {       if(v[j%i] == x[j]) continue;       else {        dbg(j%i,v[j%i],x[j]);        flag = false;        break;       }      }      dbg(v);     }     dbg(flag);     if(flag)      res.pb(i);    }       cout << res.size() << endl;       for(auto x : res)      cout << x <<    ;    cout << endl;        return 0;   }                     //?


#include <bits/stdc++.h>   using namespace std;   int a[100000], b[100000], c[100000][2];   int n, m;   long long k, sum;   int main() {     cin >> n >> k;     sum = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       b[i] = a[i];       long long aa = a[i];       sum += aa;     }     if (sum <= k) {       if (sum < k) {         printf( -1 n );       }       return 0;     }     sort(b, b + n);     m = 0;     c[0][0] = b[0];     c[0][1] = 0;     for (int i = 1; i < n; i++)       if (b[i] != b[i - 1]) {         m++;         c[m][0] = b[i];         c[m][1] = i;       }     int pre = 0;     for (int i = 0; i <= m; i++) {       long long u, v, duc;       v = c[i][0] - pre;       u = n - c[i][1];       duc = u * v;       if (duc <= k) {         k -= duc;       } else {         int h = -1;         for (int j = 0; j < n; j++)           if (a[j] >= c[i][0]) {             h++;             a[h] = a[j];             b[h] = j;           }         long long s, t;         s = k / u;         t = k % u;         int tt, ss;         tt = t;         ss = s;         for (int j = tt; j <= h; j++) {           if (j != tt) {             printf(   );           }           printf( %d , b[j] + 1);         }         for (int j = 0; j < tt; j++)           if ((ss + 1 != v) || (a[j] != c[i][0])) {             printf(  %d , b[j] + 1);           }         printf(  n );         break;       }       pre = c[i][0];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, turn;     cin >> n >> k;     turn = n / k;     if (turn % 2)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> t, a, b;   vector<pair<int, int>> p;   void push(int v) {     if (t[v] != -1) {       t[v * 2] = t[v * 2 + 1] = t[v];       t[v] = -1;     }   }   void update(int v, int l, int r, int vl, int vr, int color) {     if (vl > vr) return;     if (l == vl && r == vr)       t[v] = color;     else {       push(v);       int m = (l + r) / 2;       update(v * 2, l, m, vl, min(vr, m), color);       update(v * 2 + 1, m + 1, r, max(vl, m + 1), vr, color);     }   }   int get(int v, int l, int r, int pos) {     if (l == r) return t[v];     push(v);     int m = (l + r) / 2;     if (m >= pos)       return get(v * 2, l, m, pos);     else       return get(v * 2 + 1, m + 1, r, pos);   }   int main() {     cin >> n >> m;     a.resize(n);     b.resize(n);     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) cin >> b[i];     int bin = 1;     while (bin < n) bin *= 2;     n = bin;     t.assign(n * 2, -1);     for (int i = 0; i < m; ++i) {       int type;       cin >> type;       if (type == 1) {         int l, q, k;         cin >> l >> q >> k;         update(1, 0, n - 1, q - 1, q + k - 2, p.size());         p.push_back({l, q});       } else {         int x, y = -1;         cin >> x;         y = get(1, 0, n - 1, x - 1);         if (y == -1)           cout << b[x - 1] <<   n ;         else           cout << a[p[y].first + x - p[y].second - 1] <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int f[11][11][4][100010];   int n;   char s[100010];   char c[100010];   int ch(char s) {     if (s ==  A )       return 0;     else if (s ==  C )       return 1;     else if (s ==  T )       return 2;     else if (s ==  G )       return 3;     return -1;   }   void Add(int *tr, int x, int d) {     for (; x <= n; x += x & (-x)) {       tr[x] += d;     }   }   int Sum(int *tr, int x) {     if (x == 0) return 0;     int s = 0;     while (x) {       s += tr[x];       x -= x & (-x);     }     return s;   }   int main() {     scanf( %s , s);     n = strlen(s);     for (int i = n - 1; i >= 0; i--) s[i + 1] = s[i];     s[0] = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= 10; j++) Add(f[j][i % j][ch(s[i])], i, 1);     int q, x, d, l, r;     scanf( %d , &q);     while (q--) {       scanf( %d , &x);       if (x == 1) {         scanf( %d%s , &d, c);         for (int i = 1; i <= 10; i++) Add(f[i][d % i][ch(s[d])], d, -1);         s[d] = c[0];         for (int i = 1; i <= 10; i++) Add(f[i][d % i][ch(s[d])], d, 1);       } else {         scanf( %d%d%s , &l, &r, c);         int len = strlen(c);         int ans = 0;         for (int i = 0; i < len; i++)           ans += Sum(f[len][(l + i) % len][ch(c[i])], r) -                  Sum(f[len][(l + i) % len][ch(c[i])], l - 1);         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void EnableFileIO(const string& fileName, bool local = 0) {     if (fileName.empty()) return;     if (local) {       freopen((fileName +  .in ).c_str(),  r , stdin);       freopen((fileName +  .out ).c_str(),  w , stdout);       return;     }     freopen((fileName +  .in ).c_str(),  r , stdin);     freopen((fileName +  .out ).c_str(),  w , stdout);   }   const int INF = (1 << 30) - 1;   const long long LINF = (1LL << 61) - 1;   const double EPS = 1e-10, PI = acos(-1);   const int N = 5e4 + 100, L = 31, P = 1e9 + 7;   int tot = 1;   int trans[N * L][2];   short cnt[N * 30];   short sum[N * 30][L][2];   __attribute__((__optimize__( -O3 ))) void ins(int k) {     int u = 1;     for (int i = L - 1; i >= 0; i--) {       int c = k >> i & 1;       if (!trans[u][c]) trans[u][c] = ++tot;       ++sum[u][i][c];       u = trans[u][c];     }     ++cnt[u];   }   __attribute__((__optimize__( -O3 ))) void dfs(int u, int d) {     if (!u) return;     dfs(trans[u][0], d - 1);     dfs(trans[u][1], d - 1);     cnt[u] = cnt[u] + cnt[trans[u][0]] + cnt[trans[u][1]];     for (int i = 0; i <= d; i++) {       sum[u][i][0] += sum[trans[u][0]][i][0] + sum[trans[u][1]][i][0];       sum[u][i][1] += sum[trans[u][0]][i][1] + sum[trans[u][1]][i][1];     }   }   int n, m, a[N];   long long mid, num;   __attribute__((__optimize__( -O3 ))) int dfs(int u, int d, int eq) {     if (!u) return 0;     if (d < 0 || !eq) return cnt[u];     int cb = mid >> d & 1, cn = num >> d & 1, res = 0;     if (cb) {       if (cn) {         res += dfs(trans[u][0], d - 1, 1);       } else {         res += dfs(trans[u][1], d - 1, 1);       }     } else {       if (cn) {         res += dfs(trans[u][1], d - 1, 1);         res += dfs(trans[u][0], d - 1, 0);       } else {         res += dfs(trans[u][0], d - 1, 1);         res += dfs(trans[u][1], d - 1, 0);       }     }     return res;   }   __attribute__((__optimize__( -O3 ))) inline int check() {     long long res = 0;     for (int i = 0; i < n; i++) {       num = a[i];       res += dfs(1, L - 1, 1);     }     return int(res / 2);   }   __attribute__((__optimize__( -O3 ))) pair<long long, long long> dfsans(int u,                                                                          int d,                                                                          int eq) {     if (!u) return make_pair(0, 0);     long long res = 0, nodes = 0;     if (d < 0 || !eq) {       for (int i = 0; i <= d; ++i) {         int c = num >> i & 1;         if (c) {           res += sum[u][i][0] * (1LL << i);         } else {           res += sum[u][i][1] * (1LL << i);         }       }       return make_pair(cnt[u], res);     }     int cb = mid >> d & 1, cn = num >> d & 1;     pair<long long, long long> p;     if (cb) {       if (cn) {         p = dfsans(trans[u][0], d - 1, 1);         res += p.first * (1LL << d) + p.second;         nodes += p.first;       } else {         p = dfsans(trans[u][1], d - 1, 1);         res += p.first * (1LL << d) + p.second;         nodes += p.first;       }     } else {       if (cn) {         p = dfsans(trans[u][1], d - 1, 1);         res += p.second;         nodes += p.first;         p = dfsans(trans[u][0], d - 1, 0);         res += p.first * (1LL << d) + p.second;         nodes += p.first;       } else {         p = dfsans(trans[u][0], d - 1, 1);         res += p.second;         nodes += p.first;         p = dfsans(trans[u][1], d - 1, 0);         res += p.first * (1LL << d) + p.second;         nodes += p.first;       }     }     return make_pair(nodes, res);   }   __attribute__((__optimize__( -O3 ))) long long calcans() {     long long res = 0;     for (int i = 0; i < n; i++) {       num = a[i];       res += dfsans(1, L - 1, 1).second;     }     return res / 2;   }   __attribute__((__optimize__( -O3 ))) int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);     }     for (int i = 0; i < n; i++) {       ins(a[i]);     }     dfs(1, L - 1);     long long lb = 0, rb = 2147483647LL;     while (rb - lb > 1) {       mid = (lb + rb) >> 1;       if (check() >= m) {         lb = mid;       } else {         rb = mid;       }     }     mid = lb + 1;     long long ans = (m - check()) * 1LL * lb;     mid = lb + 1;     ans += calcans();     printf( %lld n , ans % P);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, ds[3001], sz[3001], ot[3001], a, b, c, no, ans, sum;   vector<pair<int, pair<int, int> > > v;   int get(int x) {     if (ds[x] == x)       return x;     else       return ds[x] = get(ds[x]);   }   void merge(int x, int y) {     sz[x] += sz[y];     ds[y] = x;     ot[x] += ot[y];     if (sz[x] > sum - ot[x]) no = 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n - 1; ++i) {       cin >> a >> b >> c;       v.push_back(make_pair(c, make_pair(a, b)));     }     sort(v.begin(), v.end());     for (int i = 1; i <= n; ++i) {       cin >> ot[i];       sz[i] = 1;       ds[i] = i;       sum += ot[i];     }     for (int i = 1; i <= n; ++i)       if (sz[i] > sum - ot[i]) no = 1;     if (!no && n > 1) ans = v[0].first;     for (int i = 0; i < v.size();) {       int j = i;       while (j < v.size() && v[i].first == v[j].first) {         merge(get(v[j].second.first), get(v[j].second.second));         ++j;       }       i = j;       if (!no && i < v.size()) ans = v[i].first;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1}, n, m;   const int N = 1505;   char c[N][N];   pair<int, int> seen[N][N];   int mod(int a, int m) {     while (a < 0) a += m;     return a % m;   }   bool dfs2(int x, int y) {     if (c[mod(x, n)][mod(y, m)] ==  # ) return false;     if (seen[mod(x, n)][mod(y, m)] != make_pair(1 << 27, 1 << 27)) {       if (seen[mod(x, n)][mod(y, m)] != make_pair(x, y))         return true;       else         return false;     }     seen[mod(x, n)][mod(y, m)] = make_pair(x, y);     for (int k = 0; k < 4; k++)       if (dfs2(x + dx[k], y + dy[k])) return true;     return false;   }   int k, comp[N][N], start_comp, start_x, start_y;   bool seen_edge;   vector<pair<int, int> > edges;   vector<int> edge_style;   void dfs(int x, int y) {     if (x < 0 || x >= n || y < 0 || y >= m) {       seen_edge = true;       return;     }     if (comp[x][y] || c[x][y] ==  # ) return;     if (c[x][y] ==  S ) {       start_x = x;       start_y = y;       start_comp = k;     }     comp[x][y] = k;     for (int k = 0; k < 4; k++) dfs(x + dx[k], y + dy[k]);   }   int dist[10000];   const int inf = 1 << 27;   bool relax(int a, int b, int w) {     if (dist[b] < inf && dist[a] > dist[b] + w) {       dist[a] = dist[b] + w;       return true;     }     return false;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> c[i];     k = 1;     start_comp = -1;     memset(comp, 0, sizeof(comp));     start_x = -1;     start_y = -1;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (!comp[i][j] && c[i][j] !=  # ) {           seen_edge = false;           dfs(i, j);           if (seen_edge)             k++;           else if (start_x >= 0 && start_y >= 0 && comp[start_x][start_y] == k) {             cout <<  No  << endl;             return 0;           }         }     edges.clear();     edge_style.clear();     for (int i = 0; i < n; i++) {       if (c[i][0] !=  #  && c[i][m - 1] !=  # ) {         edge_style.push_back(1);         edges.push_back(make_pair(comp[i][m - 1], comp[i][0]));       }     }     for (int j = 0; j < m; j++) {       if (c[0][j] !=  #  && c[n - 1][j] !=  # ) {         edge_style.push_back(2);         edges.push_back(make_pair(comp[n - 1][j], comp[0][j]));       }     }     bool flag = false;     for (int z = 0; z < 4; z++) {       for (int i = 1; i < k; i++) dist[i] = inf;       dist[start_comp] = 0;       for (int i = 0; i < k; i++)         for (int j = 0; j < edges.size(); j++) {           int a = edges[j].first, b = edges[j].second;           int dw = (edge_style[j] == 1) ? (z % 2 ? 1 : -1) : (z / 2 ? 1 : -1);           bool u = relax(a, b, dw), v = relax(b, a, -dw);           if (i == k - 1 && (u || v)) flag = true;         }     }     cout << (flag ?  Yes  :  No ) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int vis[200010];   int addnum, vel[400010], head[400010], ne[400010];   int fath[200010][21];   int fa[200010], dep[200010];   pair<int, int> s[200010];   int tot, n, m;   vector<int> o, o1, o2;   int id[11];   int d[200010], f[200010][2];   int num;   int p[200010];   inline int read() {     int ans = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 )       ans = (ans << 1) + (ans << 3) + ch -  0 , ch = getchar();     return ans;   }   inline int find(int x) {     if (fa[x] == x) return x;     return fa[x] = find(fa[x]);   }   void dfs(int u, int fa) {     vis[u] = 1;     for (int e = head[u]; e; e = ne[e]) {       int v = vel[e];       if (v == fa) continue;       fath[v][0] = u;       dep[v] = dep[u] + 1;       dfs(v, u);     }   }   int lca(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     int dt = dep[x] - dep[y];     for (int i = 19; i >= 0; i--)       if (dt >> i & 1) x = fath[x][i];     for (int i = 19; i >= 0; i--)       if (fath[x][i] != fath[y][i]) x = fath[x][i], y = fath[y][i];     if (x == y) return x;     return fath[x][0];   }   void calc(int num) {     int x = s[num].first, y = s[num].second;     int dt = lca(x, y);     o1.clear(), o2.clear();     while (x != dt) o1.push_back(x), x = fath[x][0];     o1.push_back(dt);     while (y != dt) o2.push_back(y), y = fath[y][0];     while (o1.size()) o2.push_back(o1.back()), o1.pop_back();     o.clear();     int pos = 0, cnt = o2.size();     for (int i = 0; i < cnt; i++)       if (p[o2[i]] == 1 && !p[o2[(i + 1) % cnt]]) {         pos = i;         break;       }     o.push_back(id[0] == o2[pos] ? id[0] : id[1]);     for (int i = pos + 1; i < cnt + pos; i++)       if (p[o2[i % cnt]])         break;       else         o.push_back(o2[i % cnt]);     o.push_back(id[0] == o2[pos] ? id[1] : id[0]);     printf( %d  , (int)o.size());     if (o.back() != id[0]) reverse(o.begin(), o.end());     while (o.size()) {       int u = o.back();       o.pop_back();       printf( %d%c , u, !o.size() ?   n  :    );     }   }   void add(int u, int v) {     addnum++, vel[addnum] = v, ne[addnum] = head[u], head[u] = addnum;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= m; i++) {       int x = read(), y = read();       if (find(x) != find(y))         fa[find(x)] = find(y), add(x, y), add(y, x);       else         s[++tot] = make_pair(x, y);     }     for (int i = 1; i <= n; i++)       if (!vis[i]) dfs(i, -1);     for (int i = 1; i < 20; i++)       for (int j = 1; j <= n; j++) fath[j][i] = fath[fath[j][i - 1]][i - 1];     for (int i = 1; i <= tot; i++) {       int x = s[i].first, y = s[i].second;       while (x != y) {         if (dep[x] < dep[y]) swap(x, y);         if (!d[x])           d[x] = i;         else {           num = d[x];           break;         }         x = fath[x][0];       }       if (num) {         printf( YES n );         x = s[i].first, y = s[i].second;         while (x != y) {           if (dep[x] < dep[y]) swap(x, y);           f[x][0] = 1;           x = fath[x][0];         }         x = s[num].first, y = s[num].second;         while (x != y) {           if (dep[x] < dep[y]) swap(x, y);           f[x][1] = 1;           x = fath[x][0];         }         for (int i = 1; i <= n; i++)           if (f[i][0] && f[i][1]) p[fath[i][0]]++, p[i]++;         int cnt = 0;         for (int i = 1; i <= n; i++)           if (p[i] == 1) id[cnt++] = i;         x = id[0];         y = id[1];         while (p[x]) o1.push_back(x), x = fath[x][0];         while (p[y]) o2.push_back(y), y = fath[y][0];         printf( %d  , (int)(o1.size() + o2.size() - 1));         for (int i = 0; i < (int)o1.size() - 1; i++) printf( %d  , o1[i]);         while (o2.size()) {           int u = o2.back();           o2.pop_back();           printf( %d%c , u, !o2.size() ?   n  :    );         }         calc(i), calc(num);         return 0;       }     }     printf( NO n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long a[1000];     cin >> n;     cin >> a[0];     long max = a[0], min = a[0];     for (int i = 1; i < n; i++) {       cin >> a[i];       if (a[i] > max) {         max = a[i];       } else if (a[i] < min) {         min = a[i];       }     }     cout << max - min - (n - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   vector<int> graph[100010];   int deg[100010];   int sum[100010];   long long dpa[100010], dpb[100010];   long long power(long long x, long long n) {     if (n == 0) return 1;     long long y = power(x, n / 2);     y = y * y % 1000000007ll;     if (n % 2 == 1) y = y * x % 1000000007ll;     return y;   }   void dfs(int p, int x) {     int i;     if (deg[x] == 1) {       dpa[x] = dpb[x] = 0;       return;     }     long long A = 0, B = 0;     int K = 0;     for ((i) = 0; (i) < (int)(graph[x].size()); (i)++) {       int y = graph[x][i];       if (y == p) continue;       K++;       dfs(x, y);       A = (A + dpa[y]) % 1000000007ll;       B = (B + dpb[y]) % 1000000007ll;     }     int K2 = K + 1;     if (x == 0) K2--;     dpa[x] = power((K2 - A + 1000000007ll) % 1000000007ll, 1000000007ll - 2);     dpb[x] = (B + sum[x]) * dpa[x] % 1000000007ll;   }   int main(void) {     int i;     cin >> N;     for ((i) = 0; (i) < (int)(N - 1); (i)++) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       graph[a].push_back(b);       graph[b].push_back(a);       deg[a]++;       deg[b]++;       sum[a] += c;       sum[b] += c;     }     dfs(-1, 0);     cout << dpb[0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T sqr(T x) {     return x * x;   }   const int maxn = 1000;   int n, m, val;   char s[maxn][maxn];   int f[maxn][maxn];   int sum[maxn][maxn];   long long res;   int main() {     for (int i = 0; i < int(maxn); i++)       for (int j = 0; j < int(maxn); j++) {         s[i][j] = 0;         f[i][j] = 0;         sum[i][j] = 0;       }     cin >> n >> m >> val;     for (int i = int(1); i < int(n + 1); i++)       for (int j = int(1); j < int(m + 1); j++) cin >> s[i][j];     for (int i = int(1); i < int(n + 1); i++)       for (int j = int(1); j < int(m + 1); j++) {         if (s[i][j] ==  1  && s[i - 1][j] ==  1  && s[i + 1][j] ==  1  &&             s[i][j - 1] ==  1  && s[i][j + 1] ==  1 )           f[i + 1][j + 1] = 1;       }     for (int i = int(1); i < int(n + 1); i++)       for (int j = int(1); j < int(m + 1); j++) {         sum[i][j] = (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1]) + f[i][j];       }     for (int i = int(1); i < int(n); i++)       for (int j = int(1); j < int(m); j++) {         for (int k = int(1); k < int(m - j + 2); k++) {           int l = i + 1, r = n + 1, cur;           while (l < r - 1) {             cur = (l + r) >> 1;             if (sum[cur][j + k - 1] - sum[cur][j + 1] - sum[i + 1][j + k - 1] +                     sum[i + 1][j + 1] <                 val)               l = cur;             else               r = cur;           }           res += n - l;         }       }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long expo(long long n) {     if (n == 0) return 1;     if (n % 2) {       long long x = expo(n / 2);       return x * x * 2;     } else {       long long x = expo(n / 2);       return x * x;     }   }   int main() {     ios_base::sync_with_stdio(false);     long long x, y, z, i, j, k, f = 0, n, m;     cin >> n >> m;     x = m;     while (x > 0) {       f++;       x /= 2;     }     if (f < n) {       cout << m;     } else {       cout << m % expo(n);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 2e9;   const long long INF = 8e18;   const int maxn = 1e5 + 5;   int n;   int cnt[maxn], val[maxn];   long long S, SUM;   vector<pair<int, int> > e[maxn];   inline void dfs(int u, int pre) {     if (u != 1 && e[u].size() == 1) {       cnt[u] = 1;     }     for (auto &x : e[u]) {       int v = x.first, w = x.second;       if (v == pre) {         continue;       }       val[v] = w;       dfs(v, u);       cnt[u] += cnt[v];     }   }   inline void init() {     for (int i = 0; i < n + 5; ++i) {       e[i].clear();       cnt[i] = 0;     }     SUM = 0;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int T;     cin >> T;     while (T--) {       cin >> n >> S;       for (int i = 1; i <= n - 1; ++i) {         int u, v, w;         cin >> u >> v >> w;         e[u].push_back({v, w});         e[v].push_back({u, w});       }       dfs(1, 1);       priority_queue<pair<long long, int> > pq;       for (int i = 2; i <= n; ++i) {         SUM += 1ll * val[i] * cnt[i];         pq.push({1ll * (val[i] - (val[i] >> 1)) * cnt[i], i});         val[i] >>= 1;       }       int ans = 0;       while (SUM > S) {         ++ans;         auto now = pq.top();         pq.pop();         long long w = now.first, id = now.second;         SUM -= w;         pq.push({1ll * (val[id] - (val[id] >> 1)) * cnt[id], id});         val[id] >>= 1;       }       cout << ans <<   n ;       init();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline long long read() {     long long x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(long long a) {     if (a < 0) {       a = -a;       putchar( - );     }     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   inline void writeln(long long a) {     write(a);     puts(  );   }   inline void wri(long long a) {     write(a);     putchar(   );   }   inline unsigned long long rnd() {     return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;   }   const int N = 100005, ZT = 500, K = 5, mod = 1e9 + 7;   struct data {     int a[K];     bool ins(int x) {       for (int i = (int)(K - 1); i >= (int)(0); i--)         if (x >> i & 1) {           if (a[i]) {             x ^= a[i];           } else {             for (int j = (int)(0); j <= (int)(i - 1); j++)               if (x >> j & 1) x ^= a[j];             a[i] = x;             for (int j = (int)(i + 1); j <= (int)(K - 1); j++)               if (a[j] >> i & 1) a[j] ^= x;             return 1;           }         }       return 0;     }     int& operator[](int x) { return a[x]; }   } A[ZT], ffff, qj;   bool operator<(data a, data b) {     for (int i = (int)(0); i <= (int)(K - 1); i++)       if (a[i] != b[i]) return a[i] < b[i];     return 0;   }   map<data, int> M;   vector<pair<int, int> > v[N];   bool vis[N], bj[N];   int dis[N], alb[N], fa[N], Q, QJ, QQ;   void dfs(int p) {     vis[p] = 1;     for (auto i : v[p])       if (i.first != 1) {         if (!vis[i.first]) {           dis[i.first] = dis[p] ^ i.second;           fa[i.first] = p;           dfs(i.first);         } else {           if (bj[p] && bj[i.first]) {             Q = 1;             QQ = alb[p] ^ alb[i.first] ^ i.second;           } else if (i.first != fa[p] && i.first < p) {             QJ *= qj.ins(i.second ^ dis[p] ^ dis[i.first]);           }         }       }   }   int dq, gg[ZT][ZT], zy[ZT][ZT];   long long ans, f[ZT], g[ZT];   inline void add(long long& a, long long b) { a = (a + b) % mod; }   void dfs(data a) {     if (!M.count(a)) {       M[a] = ++dq;       A[dq] = a;     } else       return;     for (int j = (int)(0); j <= (int)((1 << K) - 1); j++) {       data b = a;       b.ins(j);       dfs(b);     }   }   int main() {     dfs(ffff);     for (int i = (int)(1); i <= (int)(dq); i++)       for (int j = (int)(1); j <= (int)(dq); j++) {         data a = A[i];         gg[i][j] = 1;         for (int o = (int)(0); o <= (int)(K - 1); o++)           if (A[j][o]) gg[i][j] &= a.ins(A[j][o]);         zy[i][j] = M[a];       }     int n = read(), m = read();     for (int i = (int)(1); i <= (int)(m); i++) {       int a = read(), b = read(), w = read();       v[a].push_back(make_pair(b, w));       v[b].push_back(make_pair(a, w));     }     for (auto i : v[1]) {       bj[i.first] = 1;       alb[i.first] = i.second;     }     vis[1] = 1;     f[1] = 1;     for (auto i : v[1])       if (!vis[i.first]) {         Q = 0;         QJ = 1;         memset((qj.a), 0, sizeof(qj.a));         dfs(i.first);         if (!QJ) continue;         memcpy(g, f, sizeof(f));         if (Q) {           int x = M[qj];           QJ *= qj.ins(QQ);           int y = M[qj];           for (int j = (int)(1); j <= (int)(dq); j++) {             if (gg[j][x]) add(g[zy[j][x]], f[j] * 2);             if (gg[j][y]) add(g[zy[j][y]], f[j] * QJ);           }         } else {           int x = M[qj];           for (int j = (int)(1); j <= (int)(dq); j++)             if (gg[j][x]) add(g[zy[j][x]], f[j]);         }         swap(f, g);       }     for (int i = (int)(1); i <= (int)(dq); i++) add(ans, f[i]);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using ld = long double;   template <typename T1, typename T2>   inline void chkmin(T1 &x, const T2 &y) {     if (x > y) x = y;   }   template <typename T1, typename T2>   inline void chkmax(T1 &x, const T2 &y) {     if (x < y) x = y;   }   int n, m, k;   vector<pair<int, int>> a[4];   set<pair<int, int>> L, R;   int sumSet;   void read() {     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       int t, f1, f2;       cin >> t >> f1 >> f2;       a[f1 * 2 + f2].push_back({t, i});     }     for (int i = 0; i <= 3; i++) sort(a[i].begin(), a[i].end());   }   void relax(int sz) {     sz = max(sz, 0);     while (L.size() > sz) {       auto x = *(--L.end());       L.erase(--L.end());       sumSet -= x.first;       R.insert(x);     }     while (L.size() < sz) {       if (R.empty()) break;       auto x = *(R.begin());       R.erase(R.begin());       L.insert(x);       sumSet += x.first;     }   }   void add(pair<int, int> a) {     if (R.empty()) {       L.insert(a);       sumSet += a.first;     } else if (L.empty()) {       R.insert(a);     } else if (*(R.begin()) < a) {       R.insert(a);     } else {       L.insert(a);       sumSet += a.first;     }   }   int ans;   vector<int> fans;   void run() {     ans = 2e9 + 228 + 1337;     for (int it = 0; it < 2; it++) {       L.clear();       R.clear();       sumSet = 0;       int sum = 0;       int top1 = (int)a[1].size() - 1;       int top2 = (int)a[2].size() - 1;       for (auto i : a[0]) add(i);       for (auto i : a[1]) sum += i.first;       for (auto i : a[2]) sum += i.first;       for (int i = 0; i <= min(m, (int)a[3].size()); i++) {         if (i > 0) sum += a[3][i - 1].first;         while (top1 >= 0 && top1 + 1 + i > k) {           sum -= a[1][top1].first;           add(a[1][top1--]);         }         while (top2 >= 0 && top2 + 1 + i > k) {           sum -= a[2][top2].first;           add(a[2][top2--]);         }         if (min(top1, top2) + 1 + i < k) continue;         int sz = m - i - (top1 + 1) - (top2 + 1);         if (sz < 0) continue;         if (L.size() + R.size() < sz) continue;         relax(sz);         chkmin(ans, sum + sumSet);         if (!it || sum + sumSet != ans) continue;         for (auto j : L) {           fans.push_back(j.second);         }         for (int j = 0; j <= top1; j++) {           fans.push_back(a[1][j].second);         }         for (int j = 0; j <= top2; j++) {           fans.push_back(a[2][j].second);         }         for (int j = 0; j < i; j++) {           fans.push_back(a[3][j].second);         }         return;       }     }     cout << -1 << endl;     exit(0);   }   void write() {     cout << ans << endl;     sort(fans.begin(), fans.end());     for (auto i : fans) {       cout << i + 1 <<    ;     }     cout << endl;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     read();     run();     write();     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, i;     scanf( %d , &n);     int array[n];     for (i = 0; i < n; i++) {       scanf( %d , &array[i]);     }     int min = 9999999, max = 0, count;     for (i = 0; i < n; i++) {       if (array[i] < min) {         min = array[i];       }       if (array[i] > max) {         max = array[i];       }     }     int maxIndex, minIndex;     for (i = 0; i < n; i++) {       if (array[i] == max) {         maxIndex = i;         break;       }     }     for (i = n - 1; i >= 0; i--) {       if (array[i] == min) {         minIndex = i;         break;       }     }     int maxDistance, minDistance;     int swapCount = 0;     for (i = maxIndex; i > 0; i--) {       swapCount++;       int temp = array[i];       array[i] = array[i - 1];       array[i - 1] = temp;     }     for (i = 0; i < n; i++) {       if (array[i] == max) {         maxIndex = i;         break;       }     }     for (i = n - 1; i >= 0; i--) {       if (array[i] == min) {         minIndex = i;         break;       }     }     for (i = minIndex; i < n - 1; i++) {       swapCount++;       int temp = array[i];       array[i] = array[i + 1];       array[i + 1] = temp;     }     printf( %d , swapCount);   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void pv(T a, T b) {     for (T i = a; i != b; ++i) cout << *i <<    ;     cout << endl;   }   template <class T>   void chmin(T &t, T f) {     if (t > f) t = f;   }   template <class T>   void chmax(T &t, T f) {     if (t < f) t = f;   }   int in() {     int x;     scanf( %d , &x);     return x;   }   int uf[110];   int root(int x) { return (uf[x] < 0) ? x : (uf[x] = root(uf[x])); }   bool conn(int x, int y) {     x = root(x);     y = root(y);     if (x == y) return 0;     if (uf[x] > uf[y]) swap(x, y);     uf[x] += uf[y];     uf[y] = x;     return 1;   }   int N, M;   int A[10010], B[10010];   int len;   int usLens[110];   int us[110][110];   int main() {     int i;     int u, v;     int j, k;     for (; ~scanf( %d%d , &N, &M);) {       for (i = 0; i < M; ++i) {         A[i] = in() - 1;         B[i] = in() - 1;       }       memset(uf, ~0, N << 2);       for (i = 0; i < M; ++i) {         conn(A[i], B[i]);       }       len = 0;       memset(usLens, 0, sizeof(usLens));       for (u = 0; u < N; ++u)         if (uf[u] < 0) {           if (-uf[u] > 3) {             goto failed;           }           if (-uf[u] < 2) {             continue;           }           for (v = 0; v < N; ++v)             if (root(v) == u) {               us[len][usLens[len]++] = v;             }           ++len;         }       if (len > N / 3) {         goto failed;       }       for (u = 0; u < N; ++u)         if (uf[u] < 0) {           if (-uf[u] < 2) {             for (j = 0; j < N / 3; ++j) {               if (usLens[j] < 3) {                 us[j][usLens[j]++] = u;                 break;               }             }           }         }       for (j = 0; j < N / 3; ++j) {         for (k = 0; k < 3; ++k) {           if (k) printf(   );           printf( %d , us[j][k] + 1);         }         puts(  );       }       continue;     failed:;       puts( -1 );     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t > 0) {       long long int n, s;       cin >> n >> s;       long long int a[n];       long long int sum = 0;       for (long long int i = (0); i < (n); i++) {         cin >> a[i];         sum = sum + a[i];       }       if (s >= sum) {         cout << 0 << endl;         t--;         continue;       }       long long int flag = 0;       long long int index;       long long int count = 0;       for (long long int i = (0); i < (n); i++) {         count = count + a[i];         if (count > s) {           index = i;           flag = 1;           break;         }       }       long long int m = INT_MIN;       long long int ans = 0;       for (long long int i = (0); i < (index + 1); i++) {         if (a[i] > m) {           m = a[i];           ans = i;         }       }       if (ans == index) {         if (count - a[index] + a[index + 1] <= s) {           cout << index + 1 << endl;         } else {           cout << 0 << endl;         }         t--;         continue;       } else {         cout << ans + 1 << endl;         t--;         continue;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int T = 1;     while (T--) {       int n, u;       cin >> n >> u;       vector<int> v;       for (int i = 0; i < n; i++) {         int t;         cin >> t;         v.push_back(t);       }       int I, K, J;       double ans = 0.0;       for (int i = 0; i < n - 2; i++) {         I = v[i];         J = v[i + 1];         K = lower_bound((v).begin(), (v).end(), u + I) - v.begin();         if (K == n) {           K = n - 1;         } else if (v[K] != u + I) {           K--;         }         K = v[K];         double a = double(K - J) / (K - I);         ans = max(a, ans);       }       if (ans == 0) {         cout << -1;         exit(0);       }       printf( %.20f , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b, c;     cin >> a >> b;     sort(a.begin(), a.end());     if (a.length() < b.length()) {       reverse(a.begin(), a.end());       cout << a << endl;     } else {       for (int i = 0; i < a.length(); i++) {         for (int j = a.length() - 1; j > i; j--) {           c = a;           swap(a[i], a[j]);           sort(a.begin() + i + 1, a.end());           if (a > b) {             a = c;           } else             break;         }       }       cout << a << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N, M;     cin >> N >> M;     long long ans = 0;     int step = 1;     for (int i = 1; i <= M; ++i) {       int T;       cin >> T;       if (T >= step) {         ans += T - step;       } else {         ans += N - step + T;       }       step = T;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using i64 = long long;   using f64 = double;   using f80 = long double;   using pii = pair<int, int>;   using pll = pair<i64, i64>;   using ptx = pair<f64, f64>;   const int N = 3e5 + 5, LG = 20;   int f[N], conv[N], tmp[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int n;     cin >> n;     for (int t, i = 1; i <= n; ++i) {       cin >> t;       f[t] = conv[t] = 1;       if (t == 1) {         cout <<  1 n ;         return 0;       }     }     for (int tid = 2; tid <= 7; ++tid) {       i64 drop, st, dr;       for (int i = N - 1; i >= 1; --i) {         drop = st = dr = 0;         for (int j = i; j < N; j += i) {           drop += tmp[j];           st += conv[j];           dr += f[j];         }         tmp[i] = st * dr - drop;       }       if (tmp[1]) {         cout << tid << endl;         return 0;       }       for (int i = 0; i < N; ++i) {         conv[i] = int(tmp[i] > 0);         tmp[i] = 0;       }     }     cout <<  -1 n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long suf(long long a) { return (a * (a + 1)) / 2; }   const long long OO = 1e6 + 10, MOD = 1e9 + 7;   vector<vector<int> > adj, can;   int dx[]{1, -1, 0, 0, 1, -1, 1, -1};   int dy[]{0, 0, 1, -1, 1, -1, -1, 1};   int main() {     std::ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long n, m, k, a, b, c, d;     string s, s1;     char ch;     while (cin >> n) {       vector<vector<int> > v(1e5 + 5);       vector<pair<int, int> > ans;       for (int i = 0; i < n; i++) {         cin >> a;         v[a].push_back(i + 1);       }       for (int i = 0; i < v.size(); i++) {         if (v[i].size() == 1)           ans.push_back({i, 0});         else if (v[i].size() > 1) {           int now = v[i][1] - v[i][0];           bool ok = true;           for (int j = 2; j < v[i].size(); j++) {             if (v[i][j] - v[i][j - 1] != now) {               ok = false;               break;             }           }           if (ok) ans.push_back({i, now});         }       }       cout << ans.size() << endl;       for (int i = 0; i < ans.size(); i++)         cout << ans[i].first <<     << ans[i].second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2 * 1e5;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   int a[N];   int n;   int dfs(int h, int w, int s) {     if (s > n) return h;     int sum = 0;     for (int i = s; i <= n; i++) {       if (a[i] > a[i + 1]) sum++;       if (sum == w) return dfs(h + 1, i - s + 1, i + 1);     }     return h + 1;   }   int main() {     int T;     T = read();     while (T--) {       n = read();       for (int i = 1; i <= n; i++) a[i] = read();       printf( %d n , dfs(1, 1, 2) - 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXN = 200000;   int n;   int a[MAXN];   void run() {     scanf( %d , &n);     for (int i = (0); i < (n); ++i) scanf( %d , &a[i]);     sort(a, a + n);     int ndiff = unique(a, a + n) - a;     int ret = n + 1 - ndiff;     printf( %d n , ret);   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int l, r;   } e[200010];   bool operator<(node t1, node t2) { return t1.r < t2.r; }   int n, ans;   int main() {     scanf( %d , &n);     int w, x;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &x, &w);       e[i].l = x - w;       e[i].r = x + w;     }     sort(e + 1, e + n + 1);     int L = -0x7fffffff;     for (int i = 1; i <= n; i++) {       if (e[i].l >= L) {         ans++;         L = e[i].r;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using cd = complex<double>;   const double pi = acos(-1);   const double EPS = 1e-5;   void iter(vector<cd> &a, bool invert) {     int n = a.size();     for (int i = 1, j = 0; i < n; i++) {       int bit = n >> 1;       for (; j & bit; bit >>= 1) j ^= bit;       j ^= bit;       if (i < j) swap(a[i], a[j]);     }     for (int len = 2; len <= n; len <<= 1) {       double ang = 2 * pi / len * (invert ? -1 : 1);       cd wlen(cos(ang), sin(ang));       for (int i = 0; i < n; i += len) {         cd w(1);         for (int j = 0; j < len / 2; j++) {           cd u = a[i + j], v = a[i + j + len / 2] * w;           a[i + j] = u + v;           a[i + j + len / 2] = u - v;           w *= wlen;         }       }     }     if (invert)       for (cd &x : a) x /= n;   }   void iter2d(vector<vector<cd>> &a, bool invert) {     for (auto &it : a) iter(it, invert);     for (int j = 0; j < a[0].size(); j++) {       vector<cd> col(a.size());       for (int i = 0; i < a.size(); i++) col[i] = a[i][j];       iter(col, invert);       for (int i = 0; i < a.size(); i++) a[i][j] = col[i];     }   }   vector<vector<int>> mult(vector<vector<cd>> &a, vector<vector<cd>> &b) {     int nr = 1;     while (nr < a.size() + b.size()) nr <<= 1;     a.resize(nr);     b.resize(nr);     int nc = 1;     while (nc < a[0].size() + b[0].size()) nc <<= 1;     for (auto &it : a) it.resize(nc, 0);     for (auto &it : b) it.resize(nc, 0);     iter2d(a, 0);     iter2d(b, 0);     for (int i = 0; i < nr; i++)       for (int j = 0; j < nc; j++) a[i][j] *= b[i][j];     iter2d(a, 1);     vector<vector<int>> ret(nr, vector<int>(nc));     for (int i = 0; i < nr; i++)       for (int j = 0; j < nc; j++) ret[i][j] = (int)(a[i][j].real() + EPS);     return ret;   }   const int N = 401;   int n, m, r, c;   string str[N];   string pat[N];   int main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> str[i];     cin >> r >> c;     for (int i = 0; i < r; i++) cin >> pat[i];     vector<vector<cd>> a(n + r, vector<cd>(m + c)), b(r, vector<cd>(c, 0));     for (int i = 0; i < n + r; i++)       for (int j = 0; j < m + c; j++) {         int cur = str[i % n][j % m] -  a ;         double ang = 2 * pi * cur / 26;         a[i][j] = cd(cos(ang), sin(ang));       }     int cnt = 0;     for (int i = 0; i < r; i++)       for (int j = 0; j < c; j++) {         if (pat[i][j] ==  ? ) continue;         cnt++;         int cur = pat[i][j] -  a ;         double ang = 2 * pi * cur / 26;         b[r - 1 - i][c - 1 - j] = cd(cos(ang), -sin(ang));       }     vector<vector<int>> ret;     ret = mult(a, b);     for (int i = r - 1; i < n + r - 1; i++) {       for (int j = c - 1; j < m + c - 1; j++) cout << (ret[i][j] == cnt);       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 + 5;   int boy[maxn], girl[maxn];   int n, m;   int main() {     int b, g;     while (scanf( %d%d , &n, &m) != EOF) {       memset(boy, 0, sizeof(boy));       memset(girl, 0, sizeof(girl));       int in;       scanf( %d , &b);       for (int i = 0; i < b; i++) {         scanf( %d , &in);         boy[in] = 1;       }       scanf( %d , &g);       for (int i = 0; i < g; i++) {         scanf( %d , &in);         girl[in] = 1;       }       bool flag;       int stb = 0, stg = 0;       int cnt = maxn * maxn;       while (cnt) {         flag = true;         stb %= n;         stg %= m;         if (boy[stb] || girl[stg]) {           boy[stb] = 1;           girl[stg] = 1;         }         for (int i = 0; i < n; i++) {           if (!boy[i]) {             flag = false;             break;           }         }         for (int i = 0; i < m; i++) {           if (!girl[i]) {             flag = false;             break;           }         }         if (flag) break;         stb++;         stg++;         cnt--;       }       printf( %s n , flag ?  Yes  :  No );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9;   long double sqr(long double a) { return a * a; }   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     long long k;     cin >> k;     map<long long, pair<long long, long long> > sm;     for (auto i = 0; i < k; ++i) {       long long n, sum = 0;       cin >> n;       vector<long long> a(n);       for (auto &it : a) {         cin >> it;         sum += it;       }       for (auto j = 0; j < n; ++j) {         if (sm.find(sum - a[j]) != sm.end()) {           cout <<  YES n                 << sm[sum - a[j]].first <<     << sm[sum - a[j]].second <<   n                 << i + 1 <<     << j + 1;           return 0;         }       }       for (auto j = 0; j < n; ++j) {         sm[sum - a[j]] = {i + 1, j + 1};       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Imx = 2147483647;   const long long Lbig = 2e18;   const int mod = 1e9 + 7;   struct fastio {     char s[100000];     int it, len;     fastio() { it = len = 0; }     inline char get() {       if (it < len) return s[it++];       it = 0;       len = fread(s, 1, 100000, stdin);       if (len == 0)         return EOF;       else         return s[it++];     }     bool notend() {       char c = get();       while (c ==     || c ==   n ) c = get();       if (it > 0) it--;       return c != EOF;     }   } _buff;   inline long long getnum() {     long long r = 0;     bool ng = 0;     char c;     c = _buff.get();     while (c !=  -  && (c <  0  || c >  9 )) c = _buff.get();     if (c ==  - ) ng = 1, c = _buff.get();     while (c >=  0  && c <=  9 ) r = r * 10 + c -  0 , c = _buff.get();     return ng ? -r : r;   }   template <class T>   inline void putnum(T x) {     if (x < 0) putchar( - ), x = -x;     register short a[20] = {}, sz = 0;     while (x) a[sz++] = x % 10, x /= 10;     if (sz == 0) putchar( 0 );     for (int i = sz - 1; i >= 0; i--) putchar( 0  + a[i]);   }   inline char getreal() {     char c = _buff.get();     while (c ==     || c ==   n ) c = _buff.get();     return c;   }   int n;   int head[500111], nxt[1000111], to[1000111], tot = 1;   int head2[500111], nxt2[1000111], to2[1000111], tot2 = 1;   int f[500111];   bool oc[500111], oc2[500111];   void adde(int x, int y) {     nxt[++tot] = head[x];     head[x] = tot;     to[tot] = y;   }   void adde2(int x, int y) {     nxt2[++tot2] = head2[x];     head2[x] = tot2;     to2[tot2] = y;   }   int gf(int x) { return f[x] == x ? x : f[x] = gf(f[x]); }   map<pair<int, int>, int> mpid;   int nid[500111];   void dfs(int x, int p = -1) {     for (int i = head[x]; i; i = nxt[i]) {       int u = to[i];       if (u == p) continue;       dfs(u, x);       if (oc[i >> 1]) continue;       int tmp = nid[gf(u)];       if (!tmp) continue;       putnum(u), putchar(   ), putnum(x), putchar(   );       putnum(to2[tmp]), putchar(   ), putnum(to2[tmp ^ 1]), putchar(  n );     }   }   void dfs2(int x, int p = -1) {     for (int i = head2[x]; i; i = nxt2[i]) {       int u = to2[i];       if (u == p) continue;       if (!oc2[i >> 1]) nid[gf(u)] = i;       dfs2(u, x);     }   }   int main() {     n = getnum();     for (int i = 1; i <= n; i++) f[i] = i;     for (int i = 1; i < n; i++) {       int x, y;       x = getnum(), y = getnum();       if (x > y) swap(x, y);       mpid[make_pair(x, y)] = i;       adde(x, y);       adde(y, x);     }     int cnt = n - 1;     for (int i = 1; i < n; i++) {       int x, y;       x = getnum(), y = getnum();       if (x > y) swap(x, y);       if (mpid.find(make_pair(x, y)) != mpid.end()) {         oc[mpid[make_pair(x, y)]] = 1;         oc2[i] = 1;         cnt--;         f[gf(x)] = gf(y);       }       adde2(x, y);       adde2(y, x);     }     dfs2(1);     putnum(cnt), putchar(  n );     dfs(1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q, w, e, r;     cin >> q >> w >> e >> r;     string s;     cin >> s;     unsigned long long int c = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  1 ) {         c += q;       }       if (s[i] ==  2 ) {         c += w;       }       if (s[i] ==  3 ) {         c += e;       }       if (s[i] ==  4 ) {         c += r;       }     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m;     cin >> n >> m;     string s;     cin >> s;     char arr[26];     map<int, int> mmap;     for (int i = 0; i < 26; i++) {       mmap[i] = i;       arr[i] = i;     }     for (int i = 0; i < m; i++) {       char pr, nx;       cin >> pr >> nx;       arr[mmap[pr -  a ]] = nx -  a ;       arr[mmap[nx -  a ]] = pr -  a ;       int temp = mmap[nx -  a ];       mmap[nx -  a ] = mmap[pr -  a ];       mmap[pr -  a ] = temp;       for (int i = 0; i < 26; i++) {         if (false)           cout << (char)( a  + i) <<   ->   << (char)(arr[i] +  a ) << endl;       }     }     string ans =   ;     for (int i = 0; i < s.length(); i++) {       ans += (char)(arr[s[i] -  a ] +  a );     }     cout << ans << endl;   }   int main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   int a[222];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     int ans = m;     for (int i = 0; i < n - 1; i++)       if (a[i] - a[i + 1] > ans) ans = a[i] - a[i + 1];     cout << ans - m << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e5 + 10;   char s[M];   map<char, int> mp;   int main() {     int n;     scanf( %d , &n);     scanf( %s , s);     for (int i = 0; i < n; i++) {       mp[s[i]]++;     }     int minn1 = M;     if (mp[ o ] && mp[ n ] && mp[ e ]) {       minn1 = min(minn1, mp[ o ]);       minn1 = min(minn1, mp[ n ]);       minn1 = min(minn1, mp[ e ]);       mp[ o ] -= minn1;       mp[ e ] -= minn1;     }     int minn2 = M;     if (mp[ z ] && mp[ e ] && mp[ r ] && mp[ o ]) {       minn2 = min(minn2, mp[ z ]);       minn2 = min(minn2, mp[ e ]);       minn2 = min(minn2, mp[ r ]);       minn2 = min(minn2, mp[ o ]);     }     if (minn1 == M) minn1 = 0;     if (minn2 == M) minn2 = 0;     for (int i = 1; i <= minn1; i++) printf( 1  );     for (int i = 1; i <= minn2; i++) printf( 0  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve();   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       solve();       cout <<   n ;     }     cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl;     return 0;   }   long long num(long long x, long long n, long long m) {     long long res = 0;     --x;     for (long long i = 1; i <= n; i++) res += min(x / i, m);     return res;   }   void solve() {     long long n, m;     cin >> n >> m;     long long k;     cin >> k;     long long l = 1;     long long r = n * m + 1;     while (l < r) {       long long x = (l + r) >> 1;       if (num(x, n, m) < k)         l = x + 1;       else         r = x;     }     cout << l - 1;     return;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, f, k, ans, now;   int main() {     scanf( %d%d%d%d , &a, &b, &f, &k);     if (b < f) {       printf( -1 );       return 0;     }     now = b - f;     for (int i = 1; i <= k; i++) {       if (i % 2) {         if (b < (a - f) + (a - f) * (i != k)) return printf( -1 ), 0;         if (now < (a - f) + (a - f) * (i != k)) now = b, ans++;         now -= 2 * (a - f);       } else {         if (b < f + f * (i != k)) return printf( -1 ), 0;         if (now < f + f * (i != k)) now = b, ans++;         now -= 2 * f;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3)   #pragma GCC optimize(2)   using namespace std;   set<int> st;   set<pair<long long, int>> bus[200011];   map<long long, set<pair<int, int>>> q;   int n, k, m;   int main() {     int i;     scanf( %d%d%d , &n, &k, &m);     for (i = 1; i <= k; ++i) {       int xi;       scanf( %d , &xi);       st.insert(xi);       bus[xi].insert(make_pair(0, i));     }     while (m-- > 0) {       long long ti;       int a, b;       scanf( %I64d%d%d , &ti, &a, &b);       while (!q.empty()) {         auto iter = q.begin();         if (iter->first > ti) break;         for (auto p : iter->second) {           st.insert(p.first);           bus[p.first].insert(make_pair(iter->first, p.second));         }         q.erase(iter->first);       }       if (!st.empty()) {         auto iter = st.upper_bound(a);         pair<int, pair<long long, int>> car =             make_pair(1e6, make_pair(1e14, 1e6));         bool ok = false;         if (iter != st.end()) {           car.first = *iter;           car.second = *bus[car.first].begin();           ok = true;         }         if (iter != st.begin()) {           iter = prev(iter);           if (ok) {             int pos = *iter;             if ((abs(pos - a) < abs(car.first - a)) ||                 (abs(pos - a) == abs(car.first - a) &&                  car.second > *bus[pos].begin())) {               car.first = pos;               car.second = *bus[pos].begin();             }           } else {             car.first = *iter;             car.second = *bus[car.first].begin();           }         }         printf( %d %d n , car.second.second, abs(car.first - a));         bus[car.first].erase(car.second);         if (bus[car.first].empty()) st.erase(car.first);         long long finish = ti + abs(car.first - a) + abs(b - a);         q[finish].insert(make_pair(b, car.second.second));       } else {         long long t = q.begin()->first;         auto iter = q[t].upper_bound(make_pair(a, 0));         pair<int, int> car = make_pair(0, 0);         if (iter != q[t].end()) {           car = *iter;         }         if (iter != q[t].begin()) {           iter = prev(iter);           iter = q[t].upper_bound(make_pair(iter->first, 0));           if (car.first != 0) {             if ((abs(car.first - a) > abs(iter->first - a)) ||                 ((abs(car.first - a) == abs(iter->first - a)) &&                  car.second > iter->second)) {               car = *iter;             }           } else {             car = *iter;           }         }         printf( %d %I64d n , car.second, abs(t - ti) + abs(car.first - a));         q[t].erase(car);         if (q[t].empty()) q.erase(t);         q[t + abs(car.first - a) + abs(b - a)].insert(make_pair(b, car.second));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2e5 + 10;   const long long mod = 1e9 + 7;   long long ans;   long long n, k;   long long a[maxn];   long long z;   long long inv[maxn];   long long fact[maxn];   long long pashm[maxn];   void in();   void solve();   long long pwr(long long, long long);   long long oof(long long, long long);   long long C(long long, long long);   void out();   int main() {     ios::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     in();     solve();     out();   }   void in() {     cin >> n >> k;     for (long long i = 0; i < n; i++) cin >> a[i];   }   void solve() {     fact[0] = 1;     for (long long i = 1; i < maxn; i++) fact[i] = fact[i - 1] * i % mod;     inv[maxn - 1] = pwr(fact[maxn - 1], -1);     for (long long i = maxn - 2; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;     long long sum = 0;     for (long long i = 0; i < n; i++) sum = (sum + a[i]) % mod;     z = (oof(n, k) + oof(n - 1, k) * (n - 1) % mod) % mod;     ans = (ans + sum * z % mod) % mod;   }   long long oof(long long a, long long b) {     long long z = 0;     for (long long i = b; i >= 0; i--) {       long long Z = 1;       if ((b - i) % 2) Z *= -1;       z = (z + Z * pwr(i, a) % mod * C(b, i) % mod + mod) % mod;     }     z *= inv[b];     return z % mod;   }   long long pwr(long long a, long long b) {     if (b < 0) return pwr(a, b + mod - 1);     if (b == 0) return 1;     long long c = pwr(a, b / 2);     if (b % 2) return c * c % mod * a % mod;     return c * c % mod;   }   long long C(long long n, long long k) {     if (n == k) return 1;     if (k > n) return 0;     return fact[n] * inv[k] % mod * inv[n - k] % mod;   }   void out() { cout << ans; }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int N = 1005;   int main() {     long long n;     while (~scanf( %I64d , &n)) printf( 25 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr int maxn = 3e5 + 10, inf = 0x3f3f3f3f;   int a[maxn], qtd[2 * maxn];   long long ans;   void solve(int l, int r) {     if (l == r) return (void)(++ans);     int m = (l + r) >> 1;     solve(l, m);     solve(m + 1, r);     int Mn = inf, Mx = 0;     for (int i = m, ptr = m + 1; i >= l; i--) {       bool trocou = 0;       if (a[i] > Mx || a[i] < Mn) trocou = 1;       Mx = max(Mx, a[i]);       Mn = min(Mn, a[i]);       for (; ptr <= r && a[ptr] < Mx && a[ptr] > Mn; ptr++)         ;       if (trocou && ptr > m + 1)         ans += ptr - i >= Mx - Mn + 1;       else if (ptr > m + 1)         ans += ptr - i == Mx - Mn + 1;     }     Mn = inf, Mx = 0;     for (int i = m + 1, ptr = m; i <= r; i++) {       bool trocou = 0;       if (a[i] > Mx || a[i] < Mn) trocou = 1;       Mx = max(Mx, a[i]);       Mn = min(Mn, a[i]);       for (; ptr >= l && a[ptr] < Mx && a[ptr] > Mn; ptr--)         ;       if (trocou && ptr < m)         ans += i - ptr >= Mx - Mn + 1;       else if (ptr < m)         ans += i - ptr == Mx - Mn + 1;     }     Mn = inf, Mx = 0;     int MnR1 = inf, MnR2 = inf, ptr_mx = m + 1, ptr_mn = m + 1;     for (int i = m; i >= l; i--) {       Mx = max(Mx, a[i]);       Mn = min(Mn, a[i]);       for (; ptr_mn <= r && a[ptr_mn] > Mn; ptr_mn++)         MnR1 = min(MnR1, a[ptr_mn]), qtd[MnR1 + ptr_mn]--;       for (; ptr_mx <= r && a[ptr_mx] < Mx; ptr_mx++)         MnR2 = min(MnR2, a[ptr_mx]), qtd[MnR2 + ptr_mx]++;       ans += max(0, qtd[Mx + i]);     }     for (; ptr_mn < ptr_mx; ptr_mn++)       MnR1 = min(MnR1, a[ptr_mn]), qtd[MnR1 + ptr_mn]--;     for (; ptr_mx < ptr_mn; ptr_mx++)       MnR2 = min(MnR2, a[ptr_mx]), qtd[MnR2 + ptr_mx]++;     Mn = inf, Mx = 0, ptr_mx = m + 1, ptr_mn = m + 1;     int MxR1 = 0, MxR2 = 0;     for (int i = m; i >= l; i--) {       Mx = max(Mx, a[i]);       Mn = min(Mn, a[i]);       for (; ptr_mn <= r && a[ptr_mn] > Mn; ptr_mn++)         MxR1 = max(MxR1, a[ptr_mn]), qtd[ptr_mn - MxR1 + maxn]++;       for (; ptr_mx <= r && a[ptr_mx] < Mx; ptr_mx++)         MxR2 = max(MxR2, a[ptr_mx]), qtd[ptr_mx - MxR2 + maxn]--;       ans += max(0, qtd[i - Mn + maxn]);     }     for (; ptr_mn < ptr_mx; ptr_mn++)       MxR1 = max(MxR1, a[ptr_mn]), qtd[ptr_mn - MxR1 + maxn]++;     for (; ptr_mx < ptr_mn; ptr_mx++)       MxR2 = max(MxR2, a[ptr_mx]), qtd[ptr_mx - MxR2 + maxn]--;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0, x, y; i < n; i++) scanf( %d %d , &x, &y), a[x] = y;     solve(1, n);     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int a[300005];   int b[300005];   int flag;   int main() {     int n, m;     cin >> n >> m;     int i = 0, j = 0;     for (i = 0; i < m; i++) {       cin >> a[i];       cin >> b[i];       j++;     }     int hh = a[0], ff = b[0];     int cc, fff;     int temp = 0;     for (int i = 0; i < m; i++) {       if (a[i] == hh || b[i] == ff || a[i] == ff || b[i] == hh)         continue;       else {         temp = 1;         cc = a[i];         fff = b[i];         break;       }     }     if (temp == 0) {       printf( YES );       return 0;     }     int sum = 0;     for (int i = 0; i < m; i++) {       if ((a[i] != hh && b[i] != hh) && (a[i] != cc && b[i] != cc)) sum++;     }     if (sum == 0) {       printf( YES );       return 0;     }     sum = 0;     for (int i = 0; i < m; i++) {       if ((a[i] != hh && b[i] != hh) && (a[i] != fff && b[i] != fff)) sum++;     }     if (sum == 0) {       printf( YES );       return 0;     }     sum = 0;     for (int i = 0; i < m; i++) {       if ((a[i] != ff && b[i] != ff) && (a[i] != cc && b[i] != cc)) sum++;     }     if (sum == 0) {       printf( YES );       return 0;     }     sum = 0;     for (int i = 0; i < m; i++) {       if ((a[i] != ff && b[i] != ff) && (a[i] != fff && b[i] != fff)) sum++;     }     if (sum == 0) {       printf( YES );       return 0;     }     if (sum != 0) printf( NO );   }


#include <bits/stdc++.h>   using namespace std;   bool SR(int &x) { return scanf( %d , &x) == 1; }   bool SR(long long &x) { return scanf( %lld , &x) == 1; }   bool SR(double &x) { return scanf( %lf , &x) == 1; }   bool SR(char *s) { return scanf( %s , s) == 1; }   bool RI() { return true; }   template <typename I, typename... T>   bool RI(I &x, T &...tail) {     return SR(x) && RI(tail...);   }   void SP(const int x) { printf( %d , x); }   void SP(const long long x) { printf( %lld , x); }   void SP(const double x) { printf( %.16lf , x); }   void SP(const char *s) { printf( %s , s); }   void PL() { puts(  ); }   template <typename I, typename... T>   void PL(const I x, const T... tail) {     SP(x);     if (sizeof...(tail)) putchar(   );     PL(tail...);   }   const int maxn = 3e5 + 5;   int n, m, k;   vector<int> edge[maxn];   vector<int> vol;   int src, tar;   void read() {     RI(n, m, k);     vol.resize(k);     for (int i = 0; i < int(k); i++) RI(vol[i]);     for (int i = (1); i <= int(m); i++) {       int a, b;       RI(a, b);       edge[a].push_back(n + i);       edge[n + i].push_back(a);       edge[b].push_back(n + i);       edge[n + i].push_back(b);     }     RI(src, tar);   }   struct Dsu {     int par[maxn];     void init() {       for (int i = (1); i <= int(n); i++) par[i] = i;     }     int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); }     void merge(int a, int b) { par[find(a)] = find(b); }   } dsu;   void build() {     n += m;     dsu.init();     if (find((vol).begin(), (vol).end(), tar) == vol.end())       vol.push_back(tar), k++;   }   bitset<maxn> vis;   void sol() {     vector<int> prv, cur;     cur = vol;     for (int ans = (1); ans <= int(maxn); ans++) {       prv.swap(cur);       cur.clear();       for (auto u : prv)         if (!vis[u]) {           vis[u] = 1;           for (auto v : edge[u]) dsu.merge(u, v);           cur.insert(cur.end(), (edge[u]).begin(), (edge[u]).end());         }       if (dsu.find(src) == dsu.find(tar)) {         PL(ans);         return;       }     }     PL(-1);   }   int main() {     read();     build();     sol();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     long long n, m;     long long result = 0;     cin >> n >> m;     if (n > m) {       swap(n, m);     }     for (long long i = 1; i <= n; i++) {       if (i + m < 5) continue;       int r = 5 - (i % 5);       result++;       result += (m - r) / 5;     }     cout << result << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 200005;   int visited[MAX];   int a[MAX], dis[MAX];   int n;   void bfs() {     queue<int> q;     int b;     visited[1] = 1;     dis[1] = 0;     q.push(1);     while (!q.empty()) {       b = q.front();       q.pop();       if (!visited[b + 1] && b + 1 <= n) {         visited[b + 1] = 1;         dis[b + 1] = dis[b] + 1;         q.push(b + 1);       }       if (!visited[b - 1] && b - 1 > 0) {         visited[b - 1] = 1;         dis[b - 1] = dis[b] + 1;         q.push(b - 1);       }       if (!visited[a[b]]) {         visited[a[b]] = 1;         dis[a[b]] = dis[b] + 1;         q.push(a[b]);       }     }   }   int main() {     while (cin >> n) {       for (int i = 1; i <= n; i++) {         cin >> a[i];       }       memset(visited, 0, sizeof(visited));       bfs();       for (int i = 1; i <= n; i++) {         if (i == 1)           cout << dis[i];         else           cout <<     << dis[i];       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long long int gcd(long long int A, long long int B) {     if (!B) return A;     return gcd(B, A % B);   }   int main() {     int n;     string s;     cin >> n >> s;     vector<int> pbal(n + 2), sbal(n + 2);     vector<bool> pref(n + 1, 1), suff(n + 1, 1);     for (int i = 1; i <= n; i++) {       if (s[i - 1] ==  ( )         pbal[i]++;       else         pbal[i]--;       pbal[i] += pbal[i - 1];       if (pref[i - 1] && pbal[i] >= 0)         pref[i] = 1;       else         pref[i] = 0;     }     for (int i = n; i > 0; i--) {       if (s[i - 1] ==  ) )         sbal[i]--;       else         sbal[i]++;       sbal[i] += sbal[i + 1];       if (suff[i + 1] && sbal[i] <= 0)         suff[i] = 1;       else         suff[i] = 0;     }     int ans = 0;     for (int i = 1; i <= n; i++) {       if (!pref[i - 1] || !suff[i + 1])         continue;       else {         if (s[i - 1] ==  ( ) {           if (pbal[i - 1] > 0 && pbal[i - 1] - 1 + sbal[i + 1] == 0) ans++;         } else {           if (sbal[i + 1] < 0 && pbal[i - 1] + 1 + sbal[i + 1] == 0) ans++;         }       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int level[10];   int loyal[10];   int n, A;   double calculate(int cur, int pass, int B, double rate) {     double sum;     if (cur == n) {       if (pass > n / 2) {         return rate;       } else         return rate * (double(A) / (double)(A + B));     }     sum = 0;     sum = sum + calculate(cur + 1, pass, B + level[cur],                           (rate * (double(100 - loyal[cur])) / 100.0));     sum = sum +           calculate(cur + 1, pass + 1, B, (rate * double(loyal[cur])) / 100.0);     return sum;   }   double dfs(int cur, int k) {     if (k == 0) {       return calculate(0, 0, 0, 1.0);     }     if (cur == n) return calculate(0, 0, 0, 1.0);     double a = 0.0;     double temp;     int ori = loyal[cur];     while (loyal[cur] <= 100 && k >= 0) {       temp = dfs(cur + 1, k);       if (temp > a) a = temp;       loyal[cur] = loyal[cur] + 10;       k--;     }     loyal[cur] = ori;     return a;   }   int main() {     int k, i;     scanf( %d%d%d , &n, &k, &A);     for (i = 0; i < n; i++) {       scanf( %d%d , &level[i], &loyal[i]);     }     printf( %.10lf n , dfs(0, k));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   struct edge {     int v, next;   } e[500100];   int head[100100], tot = 0;   void Add(int u, int v) {     e[tot].v = v;     e[tot].next = head[u];     head[u] = tot++;   }   int res[100100];   int deep[100100];   int vis[100100];   void DFS(int u) {     vis[u] = 1;     for (int i = head[u]; i != -1; i = e[i].next) {       int v = e[i].v;       if (deep[v] <= 2 && !vis[v]) DFS(v);     }   }   int main() {     memset((head), (-1), sizeof(head));     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       Add(u, v);       Add(v, u);       deep[u]++;       deep[v]++;     }     for (int i = 1; i <= n; i++) {       if (deep[i] == 1) DFS(i);     }     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         for (int j = head[i]; j != -1; j = e[j].next) {           int v = e[j].v;           if (vis[v]) {             res[i] = min(res[i] + 1, 2);           }         }       }     }     for (int u = 1; u <= n; u++) {       if (!vis[u]) {         int cnt = 0;         for (int i = head[u]; i != -1; i = e[i].next) {           int v = e[i].v;           if (!vis[v] && deep[v] - res[v] > 1) cnt++;         }         if (cnt > 2) {           cout <<  No  << endl;           return 0;         }       }     }     cout <<  Yes  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   long long x, y, z, a, b, c, sum, ans, total, t, cnt, n, m, k, p, kase;   string s1, s2;   map<long long, long long> mp;   set<long long> s;   map<long long, long long>::iterator itr1, ptr1;   set<long long>::iterator itr, ptr;   int main() {     a += 100;     cin >> t;     while (t--) {       cin >> a >> b >> c;       if (a < c) {         cout << 1 <<    ;         if ((b * a) > c)           cout << b << endl;         else           cout <<  -1  << endl;       } else if (a == c) {         if (b != 1) {           cout <<  -1                 <<     << b << endl;         } else           cout <<  -1                 <<                    <<  -1  << endl;       } else {         cout <<  -1               <<     << b << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int num = 0;     bool f = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       f = (ch ==  - );       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       num = (num << 1) + (num << 3) + ch -  0 ;       ch = getchar();     }     return f ? -num : num;   }   int n, m;   int deg[111];   vector<int> vec[111];   int topsort() {     int res = 0, fl = 1;     queue<int> Q;     while (fl) {       fl = 0;       for (int i = 1; i <= n; i++)         if (deg[i] == 1) Q.push(i), fl = 1;       while (!Q.empty()) {         int u = Q.front();         Q.pop();         deg[u]--;         for (int v : vec[u]) deg[v]--;       }       if (fl) res++;     }     return res;   }   int main() {     n = read(), m = read();     for (int i = 1; i <= m; i++) {       int x = read(), y = read();       deg[x]++, deg[y]++;       vec[x].push_back(y);       vec[y].push_back(x);     }     printf( %d n , topsort());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int AS = 26;   struct vertex {     int next[AS];     bool leaf = false;     multiset<int> st;     int mx = 0;     int p = -1;     int length = 0;     char pch;     int link = -1;     int elink = -1;     int go[AS];     vertex(int p = -1, char ch =  $ ) : p(p), pch(ch) {       fill(begin(next), end(next), -1);       fill(begin(go), end(go), -1);     }   };   vector<vertex> trie(1000000);   int cur_size = 1;   int addString(string const& s) {     int v = 0;     for (char ch : s) {       int c = ch -  a ;       if (trie[v].next[c] == -1) {         trie[v].next[c] = cur_size;         trie[cur_size].p = v;         trie[cur_size].pch = ch;         cur_size++;       }       v = trie[v].next[c];     }     trie[v].length = s.length();     trie[v].st.insert(0);     trie[v].leaf = true;     return v;   }   int go(int v, char ch);   int get_link(int v) {     if (trie[v].link == -1) {       if (v == 0 || trie[v].p == 0)         trie[v].link = 0;       else         trie[v].link = go(get_link(trie[v].p), trie[v].pch);     }     return trie[v].link;   }   int go(int v, char ch) {     int c = ch -  a ;     if (trie[v].go[c] == -1) {       if (trie[v].next[c] != -1)         trie[v].go[c] = trie[v].next[c];       else         trie[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);     }     return trie[v].go[c];   }   int tmp_ar[1000000];   void aho_dfs(int node) {     int v = node;     int i, j;     while (1) {       if (trie[v].elink == -1) {         i = 1;         tmp_ar[0] = v;         while (v = get_link(v)) {           if (trie[v].leaf) break;           if (trie[v].elink != -1) {             v = trie[v].elink;             break;           }           tmp_ar[i] = v;           i++;         }         for (j = 0; j < i; j++) trie[tmp_ar[j]].elink = v;       } else {         v = trie[v].elink;       }       if (v == 0) break;     }     for (i = 0; i < AS; i++) {       if (trie[node].next[i] != -1) {         aho_dfs(trie[node].next[i]);       }     }     return;   }   int data[1000000];   int susp[1000000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int n, m, i, id, vid, sus;     cin >> n >> m;     string s;     for (i = 0; i < n; i++) {       cin >> s;       data[i] = addString(s);     }     aho_dfs(0);     trie[0].mx = -1;     for (i = 0; i < m; i++) {       cin >> id;       if (id == 2) {         cin >> s;         int v = 0;         int tv;         int mx = -1;         for (char ch : s) {           v = go(v, ch);           if (trie[v].leaf)             tv = v;           else             tv = trie[v].elink;           do {             mx = max(mx, trie[tv].mx);             tv = trie[tv].elink;           } while (tv);         }         cout << mx <<   n ;       } else {         cin >> vid >> sus;         vid--;         trie[data[vid]].st.erase(trie[data[vid]].st.find(susp[vid]));         susp[vid] = sus;         trie[data[vid]].st.insert(sus);         trie[data[vid]].mx = *(--trie[data[vid]].st.end());       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, b, a[200000], x[200000];     cin >> n;     cin >> b;     x[0] = 0;     a[0] = b;     for (int i = 1; i < n; i++) {       cin >> b;       x[i] = max(x[i - 1], a[i - 1]);       a[i] = b + x[i];     }     for (int i = 0; i < n; i++) cout << a[i] <<    ;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   typedef long long int ll;   ll mod=1e9+7;   ll get(ll x,ll y)   {       ll z;       cout<< ?  <<x<<   <<y<<endl;       cin>>z;       return z;   }   int main()   {       #ifndef ONLINE_JUDGE           freopen( input.txt , r ,stdin);           freopen( output.txt , w ,stdout);       #endif         int i,j,k,n,m,t,l,r,h;         cin>>t;         while(t--)         {           ll x,y,w,b;           cin>>n>>x>>y;           ll flag1=0,flag2=0;            cin>>w>>b;            ll temp1=x+y;            ll temp2=2*n-x-y;             if(w<=(temp1/2)){flag1=1;}             if(b<=(temp2/2)){flag2=1;}             if(flag1+flag2==2){cout<< YES <<endl;}             else{cout<< NO <<endl;}         }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   template <typename T>   void uin(T &a, T b) {     if (b < a) a = b;   }   template <typename T>   void uax(T &a, T b) {     if (b > a) a = b;   }   const long long maxn = 1000 * 1000 + 228;   long long n, k;   long long dp[maxn], p[maxn];   long long dpret[maxn], hret[maxn];   vector<long long> g[maxn];   void dfs(long long v, long long deep = 0) {     hret[v] = deep;     if ((long long)g[v].size() == 1 && v != 1) {       dp[v] = 1;       dpret[v] = 1;       hret[v] = max(0LL, deep - k);     } else {       for (long long to : g[v]) {         if (to != p[v]) {           dfs(to, deep + 1);           if (hret[to] <= deep) {             dpret[v] += dpret[to];             uin(hret[v], hret[to]);           }         }       }       dp[v] = dpret[v];       for (long long to : g[v]) {         if (to != p[v]) {           if (hret[to] <= deep) {             uax(dp[v], dp[to] + dpret[v] - dpret[to]);           } else {             uax(dp[v], dp[to] + dpret[v]);           }         }       }     }   }   void solve() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k;     for (long long i = 2; i <= n; ++i) {       cin >> p[i];       g[i].push_back(p[i]);       g[p[i]].push_back(i);     }     dfs(1);     cout << dp[1] <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int K = 105;   const int N = (int)1e4 + 100;   int c[N];   long double dp[K][N];   long double C[K][K];   long double fact[K];   int main(int, char **) {     fact[0] = 1;     for (int i = 0; i < K; i++) {       if (i != 0) fact[i] = fact[i - 1] * i;       C[i][0] = C[i][i] = 1;       for (int j = 1; j < i; j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];     }     int n, x;     scanf( %d%d , &n, &x);     for (int i = 0; i < n; i++) scanf( %d , &c[i]);     dp[0][0] = 1;     for (int i = 0; i < n; i++)       for (int j = i; j >= 0; j--)         for (int s = 0; s + c[i] < N; s++) {           dp[j + 1][s + c[i]] += dp[j][s];         }     long double ans = 0;     for (int k = 1; k <= n; k++) {       long double xx = x;       xx += ((long double)n / (long double)k - 1.) * (long double)x / 2.;       long double value = 0;       for (int s = 0; s < N; s++) {         long double cur = dp[k][s];         if (cur < 0.5) continue;         long double A = xx;         long double B = (long double)s / (long double)k;         value += cur * min(A, B);       }       value /= C[n][k];       ans += value;     }     printf( %.14lf n , (double)ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt1[5001] = {0};   int cnt2[5001][5001] = {0};   vector<int> p[5001];   int cnt[5001] = {0};   int solve() {     int n, q;     cin >> n >> q;     vector<pair<int, int>> v;     for (int j = 0; j < q; j++) {       int l, r;       cin >> l >> r;       v.push_back({l, r});     }     sort(v.begin(), v.end());     for (int j = 0; j < q; j++) {       for (int i = v[j].first; i <= v[j].second; i++) {         cnt[i]++;         if (cnt[i] <= 2) {           p[i].push_back(j);         }       }     }     int s = 0;     for (int j = 1; j <= n; j++) {       int k = cnt[j];       if (k) {         s++;       }       if (k == 1) {         cnt1[p[j][0]]++;       } else if (k == 2) {         cnt2[p[j][0]][p[j][1]]++;         cnt2[p[j][1]][p[j][0]]++;       }     }     int ans = 0;     for (int j = 0; j < q; j++) {       for (int i = j + 1; i < q; i++) {         ans = max(ans, s - cnt1[j] - cnt1[i] - cnt2[i][j]);       }     }     cout << ans <<   n ;     return 0;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   long long M[maxn << 2], tag[maxn << 2];   void gather(int p) { M[p] = max(M[p << 1], M[p << 1 | 1]); }   void push(int p) {     if (tag[p]) {       tag[p << 1] += tag[p];       tag[p << 1 | 1] += tag[p];       M[p << 1] += tag[p];       M[p << 1 | 1] += tag[p];       tag[p] = 0;     }   }   void modify(int p, int tl, int tr, int l, int r, long long v) {     if (tr < l || r < tl) return;     if (l <= tl && tr <= r) {       tag[p] += v;       M[p] += v;       return;     }     push(p);     int mid = (tl + tr) >> 1;     modify(p << 1, tl, mid, l, r, v);     modify(p << 1 | 1, mid + 1, tr, l, r, v);     gather(p);   }   long long query(int p, int tl, int tr, int l, int r) {     if (tr < l || r < tl) return 0ll;     if (l <= tl && tr <= r) return M[p];     push(p);     int mid = (tl + tr) >> 1;     long long ret = query(p << 1, tl, mid, l, r);     ret = max(ret, query(p << 1 | 1, mid + 1, tr, l, r));     return ret;   }   long long c[maxn];   inline int lowbit(int s) { return s & (-s); }   inline void modify(int i, long long x) {     while (i < maxn) c[i] += x, i += lowbit(i);   }   inline long long query(int i) {     long long ret = 0;     while (i > 0) ret += c[i], i -= lowbit(i);     return ret;   }   long long x[maxn], y[maxn];   int main() {     int q;     scanf( %d , &q);     for (int t = 1; t <= q; ++t) {       char op[11];       scanf( %s %lld , op, x + t);       if (op[0] ==  + ) {         scanf( %lld , y + t);         modify(1, 1, 1000000, x[t], x[t], x[t]);         modify(1, 1, 1000000, 1, x[t], y[t]);         modify(x[t], y[t]);       } else if (op[0] ==  - ) {         modify(1, 1, 1000000, x[x[t]], x[x[t]], -x[x[t]]);         modify(1, 1, 1000000, 1, x[x[t]], -y[x[t]]);         modify(x[x[t]], -y[x[t]]);       } else {         long long tmp =             query(1, 1, 1000000, 1, x[t]) - (query(1000000) - query(x[t]));         printf( %lld n , max(x[t], tmp) - x[t]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   void draw(int k) {     for (int i = 0; i < n - k; i++) {       cout <<     ;     }     for (int i = 0; i < k; i++) {       cout << i <<    ;     }     for (int i = k; ~i; i--) {       cout << i << (i ?     :   n );     }   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       draw(i);     }     for (int i = n; ~i; i--) {       draw(i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MM = 2e4 + 5;   struct Node {     int l, r, lz, mx;   } seg[MM * 4];   int n, m, k, dp[55][MM], a[55][MM], b[55][MM];   void build(int u, int l, int r, int i) {     seg[u].l = l;     seg[u].r = r;     seg[u].lz = 0;     if (l == r) {       seg[u].mx = dp[i - 1][l];       return;     }     int mid = (l + r) / 2;     build(u * 2, l, mid, i);     build(u * 2 + 1, mid + 1, r, i);     seg[u].mx = max(seg[u * 2].mx, seg[u * 2 + 1].mx);   }   void upd(int u, int l, int r, int v);   void push(int u) {     if (seg[u].lz == 0) return;     for (int i = 0; i < 2; i++) {       upd(u * 2 + i, seg[u * 2 + i].l, seg[u * 2 + i].r, seg[u].lz);     }     seg[u].lz = 0;   }   void upd(int u, int l, int r, int v) {     if (seg[u].l == l && seg[u].r == r) {       seg[u].mx += v;       seg[u].lz += v;       return;     }     push(u);     int mid = (seg[u].l + seg[u].r) / 2;     if (r <= mid)       upd(u * 2, l, r, v);     else if (l > mid)       upd(u * 2 + 1, l, r, v);     else       upd(u * 2, l, mid, v), upd(u * 2 + 1, mid + 1, r, v);     seg[u].mx = max(seg[u * 2].mx, seg[u * 2 + 1].mx);   }   int main() {     cin.tie(0)->sync_with_stdio(0);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> a[i][j];         b[i][j] = a[i][j];         a[i][j] += a[i][j - 1];       }     }     for (int i = 1; i + k - 1 <= m; i++) {       dp[1][i] = a[1][i + k - 1] - a[1][i - 1] + a[2][i + k - 1] - a[2][i - 1];     }     for (int i = 2; i <= n; i++) {       build(1, 1, m, i);       auto get_sum = [&](int l, int r) {         int val = a[i][r] - a[i][l - 1];         if (i != n) val += a[i + 1][r] - a[i + 1][l - 1];         return val;       };       for (int j = 1; j <= k; j++) {         int l = max(j - k + 1, 1), r = j;         if (l <= r) upd(1, l, r, -b[i][j]);       }       dp[i][1] = seg[1].mx + get_sum(1, k);       for (int j = k + 1; j <= m; j++) {         int st = j - k + 1;         int pos = j - k;         int l = max(pos - k + 1, 1), r = pos;         if (l <= r) upd(1, l, r, b[i][pos]);         pos = j;         l = max(pos - k + 1, 1), r = pos;         if (l <= r) upd(1, l, r, -b[i][pos]);         dp[i][st] = seg[1].mx + get_sum(st, st + k - 1);       }     }     int ans = 0;     for (int i = 1; i + k - 1 <= m; i++) ans = max(ans, dp[n][i]);     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2e9, N = 101;   int n, m, q, tot, a[N], b[N];   int vis[N];   bool solve(int pos) {     memset(vis, 0, sizeof(vis));     for (int i = pos; i < pos + tot; i++) vis[a[i]]++;     for (int i = 1; i < m + 1; i++)       if (vis[i] != b[i]) return 0;     return 1;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 1; i < m + 1; i++) {       cin >> b[i];       tot += b[i];     }     for (int i = 0; i < n - tot + 1; i++)       if (solve(i)) return !(cout <<  YES  << endl);     cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxx = 2e5 + 10;   char s[maxx], t[maxx];   int l[maxx], r[maxx];   int main() {     cin >> s >> t;     int m = strlen(s);     int n = strlen(t);     int a = 0, b = 0;     for (int i = 0; i < m; i++) {       if (s[i] == t[a]) {         l[a] = i;         a++;       }       if (a == n) break;     }     for (int i = m - 1; i >= 0; i--) {       if (s[i] == t[n - b - 1]) {         r[b] = i;         b++;       }       if (b == n) break;     }     int ans = max(r[n - 1], m - l[n - 1] - 1);     for (int i = 0; i < n; i++) ans = max(ans, r[i] - l[n - i - 2] - 1);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   constexpr int MAXWHITE = 20;   constexpr int MINBLACK = 40;   int64_t dp[110][MAXWHITE + 5][MINBLACK + 5];   int vis[110];   int par[110];   vector<vector<int>> adj;   int N, K;   int64_t MOD = (int64_t)1e9 + 7LL;   int64_t Get(int u, int max_white, int min_black) {     return dp[u][max_white + 1][min_black + 1];   }   void Set(int u, int max_white, int min_black, int64_t val) {     dp[u][max_white + 1][min_black + 1] = val;   }   void ClearTemp() {     for (int i = 0; i <= MAXWHITE + 1; ++i) {       for (int j = 0; j <= MINBLACK + 1; ++j) {         dp[109][i][j] = 0;       }     }   }   void SetTemp(int max_white, int min_black, int64_t val) {     Set(109, max_white, min_black, val);   }   int64_t GetTemp(int max_white, int min_black) {     return Get(109, max_white, min_black);   }   void Flush(int u) {     for (int i = 0; i <= MAXWHITE + 1; ++i) {       for (int j = 0; j <= MINBLACK + 1; ++j) {         dp[u][i][j] = dp[109][i][j];       }     }     ClearTemp();   }   void Update(int u) {     int first_one = true;     for (int i = 0; i < adj[u].size(); ++i) {       int v = adj[u][i];       if (par[u] == v) continue;       if (first_one) {         first_one = false;         for (int a = -1; a <= MAXWHITE; ++a) {           for (int b = -1; b <= MINBLACK; ++b) {             if (a == b && b == -1) continue;             if (a == -1) {               Set(u, (b + 1 <= K ? a : a + 1), b + 1, Get(v, a, b));             } else if (b == -1) {               Set(u, a + 1, b, Get(v, a, b));             } else {               Set(u, a + 1, b + 1, Get(v, a, b));             }           }         }         int64_t black_way = 0;         for (int a = -1; a <= MAXWHITE; ++a) {           if (a + 1 > K) continue;           for (int b = -1; b <= MINBLACK; ++b) {             black_way += Get(v, a, b);             black_way %= MOD;           }         }         Set(u, -1, 0, black_way);         continue;       }       for (int a = -1; a <= MAXWHITE; ++a) {         for (int b = -1; b <= MINBLACK; ++b) {           if (a == b && b == -1) continue;           for (int c = -1; c <= MAXWHITE; ++c) {             for (int d = -1; d <= MINBLACK; ++d) {               if (c == d && d == -1) continue;               int max_white = (a == -1 ? c + 1 : (c == -1 ? a : max(a, c + 1)));               int min_black = (b == -1 ? d + 1 : (d == -1 ? b : min(b, d + 1)));               if (a == c && c == -1) {                 max_white = -1;               }               if (b == d && d == -1) {                 min_black = -1;               }               if (max_white != -1 && min_black != -1) {                 if (min_black + max_white <= K) {                   max_white = -1;                 }               }               if (max_white <= MAXWHITE && min_black <= MINBLACK) {                 int64_t x = Get(u, a, b);                 int64_t y = Get(v, c, d);                 x = (x * y) % MOD;                 x = (x + GetTemp(max_white, min_black)) % MOD;                 SetTemp(max_white, min_black, x);               }             }           }         }       }       Flush(u);     }   }   void Dfs(int u) {     vis[u] = 1;     bool leaf = true;     for (int i = 0; i < adj[u].size(); ++i) {       int v = adj[u][i];       if (!vis[v]) {         leaf = false;         par[v] = u;         Dfs(v);       }     }     if (leaf) {       Set(u, -1, 0, 1);       Set(u, 0, -1, 1);       return;     }     Update(u);   }   int main() {     scanf( %d%d , &N, &K);     int u, v;     adj.resize(N);     for (int i = 0; i < N - 1; ++i) {       scanf( %d%d , &u, &v);       --u;       --v;       adj[u].push_back(v);       adj[v].push_back(u);     }     Dfs(0);     int64_t ans = 0;     for (int max_white = -1; max_white <= MAXWHITE; ++max_white) {       for (int min_black = -1; min_black <= MINBLACK; ++min_black) {         if ((max_white == -1 && min_black <= K) ||             (min_black != -1 && min_black + max_white <= K)) {           ans += Get(0, max_white, min_black);           ans %= MOD;         }       }     }     cout << ans << endl;     return 0;   }