#include <bits/stdc++.h>   using namespace std;   typedef long double LD;    typedef long long ll;    #define int ll    #define ff(i,a,b) for (int i = a; i < b; i++)    #define bf(i,a,b) for (int i = a; i >= b; i--)    #define all(v) v.begin(),v.end()    #define show(a) for(auto xyz:a)cout<<xyz<<   ;cout<<endl;   #define F first    #define S second   #define pb push_back   #define mp make_pair   #define lb lower_bound      #define ub upper_bound   #define yes cout<< YES <<endl   #define no cout<< NO <<endl   #define one cout<< -1 <<endl   #define pi 3.141592653589793238   #define err() cout<< ================================== <<endl;   #define errA(A) for(auto i:A)   cout<<i<<   ;cout<<endl;   #define err1(a) cout<<#a<<   <<a<<endl   #define err2(a,b) cout<<#a<<   <<a<<   <<#b<<   <<b<<endl   #define err3(a,b,c) cout<<#a<<   <<a<<   <<#b<<   <<b<<   <<#c<<   <<c<<endl   #define err4(a,b,c,d) cout<<#a<<   <<a<<   <<#b<<   <<b<<   <<#c<<   <<c<<   <<#d<<   <<d<<endl   #define intmx INT_MAX    #define intmi INT_MIN   const int MOD=1e9+7;      void solve(){      int n,l,r;      cin>>n>>l>>r;      map<int,int> left,right;      ff(i,0,n){          int x;          cin>>x;          if(i<=l-1)          left[x]++;          else          right[x]++;      }      for(auto &i:left){          int x=min(i.S,right[i.F]);          i.S-=x;          right[i.F]-=x;          //cout<<i.F<<   <<i.S<<endl;      }      int cntl=0,cntr=0;      for(auto i:left)      cntl+=i.S;      for(auto i:right)      cntr+=i.S;      int ans=0;      if(cntl<=cntr){          ans+=cntl;          int d=(cntr-cntl)/2;          int cnt=0;          for(auto i:right){              cnt+=i.S/2;          }          if(cnt<d){              ans+=cnt;              ans+=2*(d-cnt);          }          else          ans+=d;      }      else{          ans+=cntr;          int d=(cntl-cntr)/2;          int cnt=0;          for(auto i:left){              cnt+=i.S/2;          }          if(cnt<d){              ans+=cnt;              ans+=2*(d-cnt);          }          else          ans+=d;      }      cout<<ans<<endl;   }   signed main() {       int t=1;       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cin>>t;       while(t--){           solve();       }   }


#include <bits/stdc++.h>   using namespace std;   int entries[1010000][2];   long long has[1010000];   long long power[1010000];   int main() {     int i, j;     long long ans = 0;     int n, m, u, v, p = 31;     scanf( %d%d , &n, &m);     power[0] = 1;     for (i = 1; i <= n; i++) power[i] = power[i - 1] * p;     for (i = 0; i < m; i++) {       scanf( %d%d , &u, &v);       u--;       v--;       has[u] += power[v];       has[v] += power[u];       entries[i][0] = u;       entries[i][1] = v;     }     for (i = 0; i < m; i++) {       u = entries[i][0];       v = entries[i][1];       if (has[u] + power[u] == has[v] + power[v]) ans++;     }     sort(has, has + n);     for (i = 0; i < n; i = j) {       for (j = i; j < n && has[j] == has[i]; j++)         ;       long long temp = j - i;       ans += temp * (temp - 1) / 2;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using ii = pair<int, int>;   using vi = vector<int>;   using vl = vector<ll>;   using vii = vector<ii>;   using graph = vector<vi>;   using matrix = graph;   const int MAXN = 1e6 + 5;   const int INF = 0x3f3f3f3f;   const ll INFL = 1e18 + 4;   const ll mod = 1e9 + 7;   graph g;   int h[MAXN];   vi leafs;   bool seen[MAXN];   void dfs(int u) {     seen[u] = 1;     bool yes = 1;     for (auto v : g[u])       if (!seen[v]) {         yes = 0;         h[v] = h[u] + 1;         dfs(v);       }     if (yes) leafs.push_back(h[u]);   }   int main() {     int n;     scanf( %d , &n);     g.assign(n + 1, vi());     int u, v;     for (int i = 1; i < n; ++i) {       scanf( %d %d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     int ans = 0;     seen[1] = 1;     for (auto v : g[1]) {       leafs.clear();       dfs(v);       sort(leafs.begin(), leafs.end());       for (int i = 1; i < (int)leafs.size(); ++i) {         leafs[i] = max(leafs[i], leafs[i - 1] + 1);       }       ans = max(ans, leafs.back());     }     printf( %d n , ans + 1);   }


#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long base, long long power, long long mod) {     if (power == 0)       return 1;     else if (power % 2 == 1) {       long long p1 = base % mod;       long long p2 = (bigmod(base, power - 1, mod)) % mod;       return (p1 * p2) % mod;     } else if (power % 2 == 0) {       long long p1 = (bigmod(base, power / 2, mod)) % mod;       return (p1 * p1) % mod;     }   }   long long ncr(long long n, long long k) {     long long C[n + 1][k + 1];     long long i, j;     for (i = 0; i <= n; i++) {       for (j = 0; j <= min(i, k); j++) {         if (j == 0 || j == i)           C[i][j] = 1;         else           C[i][j] = C[i - 1][j - 1] + C[i - 1][j];       }     }     return C[n][k];   }   long long prime[500008];   long long sp[500008];   void seive() {     for (int i = 2; i <= 500008; i += 2) sp[i] = 2;     for (int i = 3; i <= 500008; i += 2) sp[i] = i;     long long x = sqrt(500008);     for (int i = 3; i <= x; i += 2) {       if (sp[i] == i) {         for (int j = i * i; j <= 500008; j += i) {           sp[j] = i;         }       }     }   }   map<long long, long long> m;   void pf(long long n) {     while (1) {       if (n <= 1) break;       long long x = sp[n];       while (n % x == 0) {         n /= x;         m[x]++;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     long long t = 1;     seive();     while (t--) {       long long k, a, b;       cin >> k >> a >> b;       string s;       cin >> s;       long long n = s.size();       long long x = n / k;       long long y = ceil(n / (1.0 * k));       if (x >= a && y <= b) {         int j = 0;         long long rem = n % k;         for (int i = 1; i <= rem; i++) {           for (int z = 0; z <= x; z++) {             cout << s[j++];           }           cout << endl;         }         for (int i = 1; i <= k - rem; i++) {           for (int z = 0; z < x; z++) {             cout << s[j++];           }           cout << endl;         }       } else         cout <<  No solution  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str1, str2;     cin >> str1 >> str2;     int siz = str1.size();     siz--;     while (siz > -1) {       if (str1[siz] ==  z ) {         str1[siz] =  a ;         siz--;       } else {         str1[siz]++;         break;       }     }     if (siz == -1 || str1 == str2)       cout <<  No such string  << endl;     else       cout << str1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int size = 1000007;   const long long modulo = 1000000007;   const long long INF = 1e9;   const double EPS = 1e-10;   int main() {     cin.sync_with_stdio(0);     int n, m, k;     cin >> n >> m >> k;     int ans = 0;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       if (a == 1) {         if (m > 0)           --m;         else           ++ans;       } else {         if (k > 0)           --k;         else if (m > 0)           --m;         else           ++ans;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> G[505000], S[505000];   unordered_map<int, int> f[505000];   int n, m, dep[505000], fa[505000], bel[505000], used[505000];   void dfs(int x, int fff) {     fa[x] = fff;     dep[x] = dep[fff] + 1;     for (auto y : G[x])       if (y != fff) {         if (!dep[y])           dfs(y, x);         else if (dep[y] > dep[x]) {           for (;; y = fa[y]) {             bel[y] = x;             S[x].push_back(y);             if (y == x) break;           }         }       }   }   deque<int> q;   void add(int x) {     for (; !q.empty() && q.back() < x;) q.pop_back();     q.push_back(x);   }   void del(int x) {     if (q.front() == x) q.pop_front();   }   int gaof(int fff, int x) {     if (f[x].count(fff)) return f[x][fff];     if (!bel[x]) {       if (!used[x]) {         used[x] = 1;         int res = 0;         for (auto y : G[x])           if (y != fff) res = max(res, gaof(x, y) + 1);         return f[x][fff] = res;       }       int now = 0;       for (auto y : G[x]) now = max(now, gaof(x, y) + 1);       f[x][0] = now;       now = 0;       for (auto y : G[x]) {         f[x][y] = max(f[x][y], now);         now = max(now, gaof(x, y) + 1);       }       now = 0;       for (auto it = G[x].rbegin(); it != G[x].rend(); ++it) {         int y = *it;         f[x][y] = max(f[x][y], now);         now = max(now, gaof(x, y) + 1);       }       return f[x][fff];     }     int b = bel[x];     vector<int>& T = S[b];     int sz = T.size();     if (!used[b]) {       used[b] = 1;       int id = find(T.begin(), T.end(), x) - T.begin();       int res = 0;       for (int i = 0; i < sz; ++i) {         int d = abs(i - id);         d = min(d, sz - d);         int u = T[i];         res = max(res, d);         for (auto v : G[u])           if (!(u == x && v == fff) && bel[v] != b)             res = max(res, gaof(u, v) + d + 1);       }       return f[x][fff] = res;     }     vector<int> mx, nex, pre;     mx.resize(sz);     nex.resize(sz);     pre.resize(sz);     for (int i = 0; i < sz; ++i) {       int u = T[i];       for (auto v : G[u])         if (bel[v] != b) mx[i] = max(mx[i], gaof(u, v) + 1);     }     q.clear();     int l = sz / 2;     for (int i = 0; i < sz * 2; ++i) {       add(mx[i % sz] + i);       if (i >= l) {         del(mx[(i - l) % sz] + (i - l));         nex[(i - l) % sz] = q.front() - (i - l);       }     }     q.clear();     for (int i = sz * 2; i > 0; --i) {       add(mx[i % sz] - i);       if (i + l <= sz * 2) {         del(mx[(i + l) % sz] - (i + l));         pre[(i + l) % sz] = q.front() + (i + l);       }     }     for (int i = 0; i < sz; ++i) {       int u = T[i];       for (auto v : G[u])         if (bel[v] != b) f[u][v] = max(pre[i], nex[i]);       f[u][0] = max(max(pre[i], nex[i]), mx[i]);       int now = 0;       for (auto v : G[u]) {         if (bel[v] == b) continue;         f[u][v] = max(f[u][v], now);         now = max(now, gaof(u, v) + 1);       }       now = 0;       for (auto it = G[u].rbegin(); it != G[u].rend(); ++it) {         int v = *it;         if (bel[v] == b) continue;         f[u][v] = max(f[u][v], now);         now = max(now, gaof(u, v) + 1);       }     }     return f[x][fff];   }   int main() {     cin >> n >> m;     int u, v;     for (int i = 1; i <= m; ++i) {       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     dfs(1, 0);     for (int i = 1; i <= n; ++i) {       printf( %d  , gaof(0, i));     }     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, cnt = INT_MAX, c = 0;     cin >> n >> k;     string s, temp =   ;     cin >> s;     int freq[26];     memset(freq, 0, sizeof(freq));     for (int i = 0; i < n; i++) freq[s[i] -  A ]++;     for (int i = 0; i < k; i++) {       if (!freq[i]) return cout << 0 << endl, 0;       cnt = min(cnt, freq[i]);     }     cout << cnt * k << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int a[222], sum[222];   struct node {     int a, id;   } b[222];   bool cmp(node s, node d) { return s.a < d.a; }   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i], b[i].a = a[i], b[i].id = i;     ;     sum[0] = a[0];     for (int i = 1; i < n; i++) sum[i] = sum[i - 1] + a[i];     sort(b, b + n, cmp);     int ans = -22222;     for (int l = 0; l < n; l++)       for (int r = l; r < n; r++) {         int p = min(k, r - l + 1);         int res = sum[r];         if (l) res -= sum[l - 1];         int i = 0, j = n - 1;         while (p--) {           while (i < n && b[i].id < l || b[i].id > r) i++;           while (j >= 0 && b[j].id >= l && b[j].id <= r) j--;           if (i == n || j == -1) break;           if (b[i].a > b[j].a) break;           res += (b[j].a - b[i].a);           i++;           j--;         }         ans = max(ans, res);       }     cout << ans << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const long long mod = 1e9 + 7;   const long long N = 1e5 + 10;   int main() {     ios::sync_with_stdio(false);     long long n;     cin >> n;     vector<pair<long long, long long> > v(n);     for (long long i = 0; i < n; i++) cin >> v[i].first >> v[i].second;     map<long long, long long> m;     for (long long i = 0; i < n; i++) m[v[i].first]++;     long long ans = 0;     for (auto it : m) ans += it.second * (it.second - 1) / 2;     m.clear();     for (long long i = 0; i < n; i++) m[v[i].second]++;     for (auto it : m) ans += it.second * (it.second - 1) / 2;     map<pair<long long, long long>, long long> freq;     for (long long i = 0; i < n; i++) freq[make_pair(v[i].first, v[i].second)]++;     for (auto it : freq) ans -= it.second * (it.second - 1) / 2;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const int N = 4e5 + 7, M = 2760000;   int a[N], prime[N], m, flg[M], f[M], x[N], y[N], nn, mm, tot[M];   template <typename Tp>   inline void read(Tp &x) {     x = 0;     bool f = true;     char ch = getchar();     for (; ch <  0  || ch >  9 ; ch = getchar()) f ^= ch ==  - ;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + (ch ^ 48);     x = f ? x : -x;   }   inline void primes() {     m = 0;     std::fill(flg + 1, flg + 2750132, true);     for (int i = 2; i <= 2750131; i++) {       if (flg[i]) {         prime[++m] = i;         f[i] = i;       }       for (int j = 1; j <= m && i * prime[j] <= 2750131; j++) {         flg[i * prime[j]] = false;         f[i * prime[j]] = std::min(f[i], prime[j]);         if (!(i % prime[j])) break;       }     }   }   int main() {     int n;     read(n);     n <<= 1;     for (int i = 1; i <= n; i++) read(a[i]);     std::sort(a + 1, a + n + 1);     primes();     for (int i = 1; i <= n; i++)       if (flg[a[i]])         x[++nn] = a[i];       else         y[++mm] = a[i];     for (int i = mm; i; i--) {       if (tot[y[i]]) {         tot[y[i]]--;         continue;       }       printf( %d  , y[i]);       tot[y[i] / f[y[i]]]++;     }     for (int i = 1; i <= nn; i++) {       if (tot[x[i]]) {         tot[x[i]]--;         continue;       }       printf( %d  , x[i]);       tot[prime[x[i]]]++;     }     return 0;   }


#include <bits/stdc++.h>   #define ll long long   #define db long double   #define x first   #define y second   #define mp make_pair   #define pb push_back   #define all(a) a.begin(), a.end()      using namespace std;      struct Pair {     int x;     int y;     int def_stack;   };      bool cmp(Pair &a, Pair &b) {     return (a.x < b.x);   }      const int INF = 1e9;      pair<int, int> check(set<pair<int, int> > &st, Pair &p, Pair &prev, int cost, int t) {     if (!st.size()) return mp(-1, -1);     auto it = st.lower_bound(mp(p.y, -1));     if (it == st.end()) return mp(-1, -1);        int C = ((*it).y) + cost + t;     return mp(prev.y, C);      }      void Ins(set<pair<int, int> > &st, pair<int, int> &p, int t) {     p.y -= t;        if (st.size()) {          auto it = st.lower_bound(p);       if (it != st.end()) {         if ((*it).y <= p.y) return;       }        }        while (st.size()) {       auto it = st.lower_bound(p);       if (it == st.begin()) break;       it--;          if ((*it).y <= p.y) break;       st.erase(it);     }        st.insert(p);      }      int main(){   #ifdef LOCAL    freopen( D_input.txt ,  r , stdin);    //freopen( D_output.txt ,  w , stdout);   #endif    ios_base::sync_with_stdio(0);    cin.tie(0);        int n;     cin >> n;        vector<Pair> v(n);     for (auto &x : v) {       cin >> x.x >> x.y;       x.def_stack = 0;       if (x.x > x.y) {         swap(x.x, x.y);         x.def_stack = 1;         if (x.x > n) {           cout << -1;           exit(0);         }       }       else if (x.x > n) {         cout << -1;         exit(0);       }     }        sort(all(v), cmp);        int fadd = 0, sadd = 0;        set<pair<int, int> > first_stack, second_stack;     int D = v[0].def_stack;        first_stack.insert(mp(INF, 1-D));     second_stack.insert(mp(INF, D));        for (int i = 1; i < n; ++i) {       D = v[i].def_stack;              auto A = check(first_stack, v[i], v[i-1], D, fadd);       auto B = check(second_stack, v[i], v[i-1], 1-D, sadd);          if (v[i].y < v[i-1].y) {         if (D==0) fadd++;         else sadd++;       }       else {         fadd = 0;         sadd = 0;         first_stack.clear();         second_stack.clear();       }         // cout << A.x <<     << B.x << endl;          if (A.x != -1) {         Ins(second_stack, A, sadd);       }       if (B.x != -1) {         Ins(first_stack, B, fadd);       }     }        int ans = INF;     if (first_stack.size()) {       ans = min(ans, (*first_stack.begin()).y + fadd);     }     if (second_stack.size()) {       ans = min(ans, (*second_stack.begin()).y + sadd);     }        if (ans == INF) cout << -1;     else cout << ans;            }


#include <bits/stdc++.h>   using namespace std;   bool const TO_FILE = false;   string const FILENAME =   ;   void prepare() {     if (TO_FILE) {       freopen((FILENAME +  .in ).c_str(),  r , stdin);       freopen((FILENAME +  .out ).c_str(),  w , stdout);     }   }   void solve() {     int n, m, k;     cin >> n >> m >> k;     map<int, pair<int, int>> apps;     map<pair<int, int>, int> apps2;     int curScr = 0;     int curPos = 0;     for (int i = 0; i < n; i++) {       int app;       cin >> app;       apps[app] = make_pair(curScr, curPos);       apps2[make_pair(curScr, curPos)] = app;       if (++curPos == k) {         curPos = 0;         curScr++;       }     }     long long res = m;     for (int i = 0; i < m; i++) {       int curApp, prevApp;       cin >> curApp;       int curScr = apps[curApp].first;       int curPos = apps[curApp].second;       int prevScr, prevPos;       if (curScr == 0 && curPos == 0)         continue;       else if (curPos == 0) {         prevScr = curScr - 1;         prevPos = k - 1;         prevApp = apps2[make_pair(prevScr, prevPos)];       } else {         prevScr = curScr;         prevPos = curPos - 1;         prevApp = apps2[make_pair(prevScr, prevPos)];       }       apps[curApp] = make_pair(prevScr, prevPos);       apps2[make_pair(prevScr, prevPos)] = curApp;       apps[prevApp] = make_pair(curScr, curPos);       apps2[make_pair(curScr, curPos)] = prevApp;       res += curScr;     }     cout << res;   }   int main() {     prepare();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using P = pair<int, int>;   constexpr int INF = 1 << 30;   template <typename Monoid>   struct SegmentTree {    private:     using F = function<Monoid(Monoid, Monoid)>;     int N;     vector<Monoid> node;     F f;     Monoid e;       public:     SegmentTree() {}     SegmentTree(F f, Monoid e) : f(f), e(e) {}     void init(int sz) {       N = 1;       while (N < sz) N <<= 1;       node.assign(2 * N - 1, e);     }     void build(vector<Monoid>& v) {       int sz = int(v.size());       init(sz);       for (int i = 0; i < sz; i++) {         node[i + N - 1] = v[i];       }       for (int i = N - 2; i >= 0; i--) {         node[i] = f(node[i * 2 + 1], node[i * 2 + 2]);       }     }     void update(int k, Monoid x) {       k += N - 1;       node[k] = x;       while (k > 0) {         k = (k - 1) / 2;         node[k] = f(node[2 * k + 1], node[2 * k + 2]);       }     }     Monoid query(int a, int b) { return query(a, b, 0, 0, N); }     Monoid query(int a, int b, int k, int l, int r) {       if (b <= l || r <= a) return e;       if (a <= l && r <= b) return node[k];       Monoid vl, vr;       vl = query(a, b, 2 * k + 1, l, (l + r) / 2);       vr = query(a, b, 2 * k + 2, (l + r) / 2, r);       return f(vl, vr);     }   };   SegmentTree<int> seg([](int a, int b) { return max(a, b); }, -INF);   vector<vector<int> > g;   vector<int> a;   int main() {     int n;     scanf( %d , &n);     g.resize(n);     a.resize(n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d %d , &u, &v);       u--;       v--;       g[u].push_back(v);       g[v].push_back(u);     }     seg.build(a);     int ans = INF;     for (int i = 0; i < n; i++) {       int maxi = a[i];       g[i].push_back(i);       sort(g[i].begin(), g[i].end());       int pre = 0;       for (auto j : g[i]) {         if (j != i) maxi = max(maxi, a[j] + 1);         maxi = max(maxi, seg.query(pre, j) + 2);         pre = j + 1;       }       maxi = max(maxi, seg.query(pre, n) + 2);       ans = min(ans, maxi);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int dx[] = {0, 1, -1, 0, 1, -1, -1, 1};   const long long int dy[] = {-1, 0, 0, 1, 1, 1, -1, -1};   long long int gcd(long long int x, long long int y) {     return (y != 0 ? gcd(y, x % y) : x);   }   long long int lcm(long long int x, long long int y) {     return (x / gcd(x, y) * y);   }   struct edge {     int viz;     int cap;     int cost;     int dual;     edge() {}     edge(int viz, int cap, int cost, int dual)         : viz(viz), cap(cap), cost(cost), dual(dual) {}   };   int pro[3054];   int spo[3054];   vector<edge> g[3054];   int d[3054];   int p[3054];   int p_edge[3054];   int color[3054];   int flow;   int fcost;   void add_edge(int x, int y, int cap, int cost) {     g[x].push_back(edge(y, cap, cost, (int)g[y].size()));     g[y].push_back(edge(x, 0, -cost, (int)g[x].size() - 1));   }   int SPFA(int s, int t) {     queue<int> fila;     for (int i = 0; i <= t; i++) {       d[i] = 1000000000;       color[i] = 0;     }     d[s] = 0;     fila.push(s);     while (!fila.empty()) {       int next = fila.front();       color[next] = 0;       fila.pop();       for (int i = 0; i < (int)g[next].size(); i++) {         int viz = g[next][i].viz;         int cap = g[next][i].cap;         int cost = d[next] + g[next][i].cost;         if (cap > 0 && d[viz] > cost) {           d[viz] = cost;           p_edge[viz] = i;           p[viz] = next;           if (color[viz] == 0) {             fila.push(viz);             color[viz] = 1;           }         }       }     }     return d[t] != 1000000000;   }   void mcmf(int s, int t) {     while (SPFA(s, t)) {       int augment = 1000000000;       for (int v = t; v != s; v = p[v]) {         int idx = p_edge[v];         augment = min(augment, g[p[v]][idx].cap);       }       for (int v = t; v != s; v = p[v]) {         int idx = p_edge[v];         int dual = g[p[v]][idx].dual;         g[p[v]][idx].cap -= augment;         g[v][dual].cap += augment;       }       flow += augment;       fcost += d[t] * augment;     }     return;   }   int main(void) {     int src = 3054 - 1;     int sink = 3054 - 2;     int sports = 3054 - 3;     int programming = 3054 - 4;     int n, pp, ss;     cin >> n >> pp >> ss;     for (int i = 0; i < n; i++) {       add_edge(src, i, 1, 0);       cin >> pro[i];       add_edge(i, programming, 1, -pro[i]);     }     for (int i = 0; i < n; i++) {       cin >> spo[i];       add_edge(i, sports, 1, -spo[i]);     }     add_edge(programming, sink, pp, 0);     add_edge(sports, sink, ss, 0);     mcmf(src, sink);     cout << -fcost << endl;     vector<int> saida1, saida2;     for (int i = 0; i < n; i++) {       if (g[i][1].cap == 0) {         saida1.push_back(i + 1);       }       if (g[i][2].cap == 0) {         saida2.push_back(i + 1);       }     }     for (int i = 0; i < saida1.size(); i++) {       cout << saida1[i] <<    ;     }     cout << endl;     for (int i = 0; i < saida2.size(); i++) {       cout << saida2[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     while (b) b ^= a ^= b ^= a %= b;     return a;   }   template <class T>   inline T lcm(T a, T b) {     a = abs(a);     b = abs(b);     return (a / gcd(a, b)) * b;   }   template <class T>   inline T my_strrev(T array) {     int N = strlen(array);     for (int i = 0; i < N / 2; ++i) swap(array[i], array[N - i - 1]);   }   template <class T>   inline T my_revara(T array, int N) {     for (int i = 0; i < N / 2; ++i) swap(array[i], array[N - i - 1]);   }   int fx[8] = {0, -1, 1, 1, 1, 0, -1, -1};   int fy[8] = {1, 0, 1, -1, 0, -1, -1, 1};   int main() {     string str1, str2;     cin >> str1;     cin >> str2;     int len = str1.length();     int flag = 0;     for (int i = 0; i < len; i++) {       if (flag == 1) {         if (str2[i] !=  a ) {           str2[i] = str2[i] - 1;           cout << str2 << endl;           return 0;         }         if (str1[i] !=  z ) {           str1[i] = str1[i] + 1;           cout << str1 << endl;           return 0;         }       }       if (str2[i] > str1[i]) {         if (str2[i] - str1[i] > 1) {           str1[i] = str1[i] + 1;           cout << str1 << endl;           return 0;         }         flag = 1;       }     }     printf( No such string n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T& a) {     static char c;     static bool b;     for (c = getchar(), b = false; !isdigit(c); c = getchar())       if (c ==  - ) b = true;     for (a = 0; isdigit(c); c = getchar()) a = a * 10 + (c -  0 );     if (b) a = -a;   }   template <>   void read<char>(char& c) {     do {       c = getchar();     } while (isspace(c));   }   template <typename T, typename... Args>   void read(T& a, Args&... args) {     read(a);     read(args...);   }   const int MAXN = 2e5 + 10;   const int MAXM = MAXN;   const int INF = 0x3f3f3f3f;   template <typename T>   struct Segment {     struct Node {       int l, r, lc, rc;       T v;     } t[MAXN << 2];     int cnt;     void maintain(int x) { t[x].v = min(t[t[x].lc].v, t[t[x].rc].v); }     int create() { return ++cnt; }     int build(int l, int r, T* origin) {       int x = create();       t[x].l = l, t[x].r = r;       if (l != r) {         int mid = l + r;         mid >>= 1;         t[x].lc = build(l, mid, origin);         t[x].rc = build(mid + 1, r, origin);         maintain(x);       } else         t[x].v = origin[l];       return x;     }     T query(int x, int l, int r) {       if (l <= t[x].l && t[x].r <= r) return t[x].v;       int mid = t[x].l + t[x].r;       mid >>= 1;       if (r <= mid)         return query(t[x].lc, l, r);       else if (l > mid)         return query(t[x].rc, l, r);       return min(query(t[x].lc, l, r), query(t[x].rc, l, r));     }     void modify(int x, int l, int v) {       if (t[x].l == t[x].r) {         t[x].v = v;         return;       }       int mid = t[x].l + t[x].r;       mid >>= 1;       if (l <= mid)         modify(t[x].lc, l, v);       else         modify(t[x].rc, l, v);       maintain(x);     }   };   struct BaseGraph {     struct Lfs {       int to, nxt;     } t[MAXM << 1];     int head[MAXN], cnt;     void add(int x, int y) {       ++cnt;       t[cnt].to = y;       t[cnt].nxt = head[x];       head[x] = cnt;     }     void add2(int x, int y) { add(x, y), add(y, x); }   };   struct Graph : BaseGraph {     int dfn[MAXN], low[MAXN], tm, n;     stack<int> st;     BaseGraph* gh;     void tarjan(int x) {       dfn[x] = low[x] = ++tm;       st.push(x);       for (int i = head[x]; i; i = t[i].nxt) {         int v = t[i].to;         if (dfn[v]) {           low[x] = min(low[x], dfn[v]);         } else {           tarjan(v);           low[x] = min(low[x], low[v]);           if (low[v] >= dfn[x]) {             ++n;             int y;             gh->add2(x, n);             do {               y = st.top();               st.pop();               gh->add2(y, n);             } while (y != v);           }         }       }     }     void tarjan(int n, BaseGraph* p) {       this->n = n;       this->gh = p;       tarjan(1);     }   } G;   struct NewGraph : BaseGraph {     multiset<int> R[MAXN];     int sz[MAXN], son[MAXN], top[MAXN];     int dfn[MAXN], dep[MAXN], fa[MAXN], id;     int w[MAXN], v[MAXN], rt;     int bn, n;     Segment<int> S;     void prepare(int bn, int n) {       fa[1] = id = 0;       dep[1] = 1;       dfs(1);       deal(1, 1);       this->bn = bn;       this->n = n;       for (int x = bn + 1; x <= n; ++x) {         for (int i = head[x]; i; i = t[i].nxt) {           int v = t[i].to;           if (v == fa[x]) continue;           R[x].insert(this->v[v]);         }         if (R[x].empty()) {           v[x] = INF;         } else           v[x] = *R[x].begin();       }       for (int i = 1; i <= n; ++i) w[dfn[i]] = v[i];       rt = S.build(1, n, w);     }     void dfs(int x) {       sz[x] = 1;       son[x] = 0;       for (int i = head[x]; i; i = t[i].nxt) {         int v = t[i].to;         if (v == fa[x]) continue;         dep[v] = dep[x] + 1;         fa[v] = x;         dfs(v);         sz[x] += sz[v];         if (sz[son[x]] < sz[v]) son[x] = v;       }     }     void deal(int x, int topf) {       if (!x) return;       dfn[x] = ++id;       top[x] = topf;       deal(son[x], topf);       for (int i = head[x]; i; i = t[i].nxt) {         int v = t[i].to;         if (v == fa[x]) continue;         if (v == son[x]) continue;         deal(v, v);       }     }     void modify(int x, int val) {       int f = fa[x];       if (f) {         R[f].erase(R[f].find(v[x]));         R[f].insert(val);         v[f] = *R[f].begin();         S.modify(rt, dfn[f], v[f]);       }       v[x] = val;       S.modify(rt, dfn[x], val);     }     int query(int x, int y) {       int ans = INF;       while (top[x] != top[y]) {         if (dep[top[x]] < dep[top[y]]) swap(x, y);         ans = min(ans, S.query(rt, dfn[top[x]], dfn[x]));         x = fa[top[x]];       }       if (dep[x] > dep[y]) swap(x, y);       ans = min(ans, S.query(rt, dfn[x], dfn[y]));       if (x > bn) ans = min(ans, v[fa[x]]);       return ans;     }   } G2;   int main() {     int n, m, T;     read(n, m, T);     for (int i = 1; i <= n; ++i) read(G2.v[i]);     for (int i = 1; i <= m; ++i) {       int x, y;       read(x, y);       G.add2(x, y);     }     G.tarjan(n, &G2);     G2.prepare(n, G.n);     while (T--) {       char c;       int x, y;       read(c, x, y);       switch (c) {         case  A :           printf( %d n , G2.query(x, y));           break;         case  C :           G2.modify(x, y);           break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int n = 1e7;   int main() {     long long a, b, c, ans = 0;     cin >> a >> b >> c;     long long mx = max(a, max(b, c));     long long sum = (a + b + c) - mx;     if (sum * 2 <= mx)       cout << sum << endl;     else       cout << (a + b + c) / 3 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, cnt[10], sta[10], g[10][10], f[10][10], pru[10], deg[10], tag[10];   char s[10];   int cal(int x) {     int res = 0;     while (x) {       res++;       x /= 10;     }     return res;   }   int read() {     scanf( %s , s);     int res = 0;     for (int i = 0; s[i]; i++) res++;     return res;   }   bool hall() {     for (int i = 1; i <= m; i++)       for (int j = i; j <= m; j++) f[i][j] = g[i][j];     for (int i = 1; i <= m; i++) deg[i] = 1;     for (int i = 1; i <= m - 2; i++) deg[pru[i]]++;     for (int i = 1; i <= m - 2; i++) {       bool ok = 0;       for (int j = 1; j <= m; j++) {         if (deg[j] == 1) {           ok = 1;           deg[pru[i]]--;           deg[j]--;           if (f[min(pru[i], j)][max(pru[i], j)] == 0) return 0;           f[min(pru[i], j)][max(pru[i], j)]--;           break;         }       }       if (!ok) return 0;     }     int x, y;     for (int i = 1; i <= m; i++) {       if (deg[i] == 1) {         x = i;         break;       }     }     for (int i = 1; i <= m; i++) {       if (deg[i] == 1) y = i;     }     if (f[x][y] == 0) return 0;     f[x][y]--;     int tmp;     for (int i = 1; i < 1 << m; i++) {       tmp = 0;       for (int j = 0; j < m; j++)         if (i & (1 << j)) tmp += cnt[j + 1] - 1;       for (int j = 0; j < m; j++)         for (int k = j; k < m; k++)           if (((1 << j) & i) || (i & (1 << k))) tmp -= f[j + 1][k + 1];       if (tmp > 0) return 0;     }     return 1;   }   bool hall_() {     int tmp;     for (int i = 1; i < 1 << m; i++) {       tmp = 0;       for (int j = 0; j < m; j++)         if (i & (1 << j)) tmp += cnt[j + 1];       for (int j = 0; j < m; j++)         for (int k = j; k < m; k++)           if (((1 << j) & i) || (i & (1 << k))) tmp -= g[j + 1][k + 1];       if (tmp > 0) return 0;     }     return 1;   }   void print() {     for (int i = 1; i <= m; i++) deg[i] = 1;     for (int i = 1; i <= m - 2; i++) deg[pru[i]]++;     for (int i = 1; i <= m - 2; i++) {       for (int j = 1; j <= m; j++) {         if (deg[j] == 1) {           deg[pru[i]]--;           deg[j]--;           g[min(pru[i], j)][max(pru[i], j)]--;           printf( %d %d n , sta[pru[i]], sta[j]);           break;         }       }     }     int x, y;     for (int i = 1; i <= m; i++) {       if (deg[i] == 1) {         x = i;         break;       }     }     for (int i = 1; i <= m; i++) {       if (deg[i] == 1) y = i;     }     g[x][y]--;     printf( %d %d n , sta[x], sta[y]);     n -= m;     for (int i = 1; i <= m; i++) tag[i] = sta[i], sta[i]--, cnt[i]--;     for (int i = 1; i <= m; i++) {       while (cnt[i] != 0) {         for (int j = 1; j <= m; j++) {           if (g[min(i, j)][max(i, j)]) {             g[min(i, j)][max(i, j)]--;             cnt[i]--;             if (hall_()) {               printf( %d %d n , sta[i], tag[j]);               sta[i]--;               break;             }             cnt[i]++;             g[min(i, j)][max(i, j)]++;           }         }       }     }   }   void dfs(int x) {     if (x == m - 2 + 1) {       if (hall()) {         print();         exit(0);       }       return;     }     for (int i = 1; i <= m; i++) {       pru[x] = i;       dfs(x + 1);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x = read(), y = read();       if (x > y) swap(x, y);       g[x][y]++;     }     for (int i = 1; i <= n; i++) {       m = cal(i);       cnt[m]++;       sta[m] = i;     }     if (m == 1) {       for (int i = 1; i < n; i++) printf( %d %d n , i, n);       return 0;     }     dfs(1);     puts( -1 );   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 2000005;   int n, t;   long long sum[MaxN];   int nums[MaxN];   int main() {     scanf( %d , &n);     t = 0;     for (int i = 1; i <= n; ++i) {       long long ns;       scanf( %lld , &ns);       int nn = 1;       while (t && ns * nums[t] <= sum[t] * nn) {         ns += sum[t];         nn += nums[t];         --t;       }       nums[++t] = nn;       sum[t] = ns;     }     for (int i = 1; i <= t; ++i) {       double val = (double)sum[i] / nums[i];       for (int j = 1; j <= nums[i]; ++j) printf( %.10lf n , val);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   using namespace std;   int q, a, b, c;   vector<array<int, 3>> v;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     for (int a = 1; a <= 10e4; ++a) {       for (int b = a; b <= 10e4; b += a) {         for (int c = b; c <= 10e4; c += b) v.push_back({a, b, c});       }     }     cin >> q;     while (q--) {       cin >> a >> b >> c;       array<int, 4> ans = {30000, 0, 0, 0};       for (auto x : v) {         int ma = abs(a - x[0]) + abs(b - x[1]) + abs(c - x[2]);         if (ma < ans[0]) ans = {ma, x[0], x[1], x[2]};       }       cout << ans[0] <<   n  << ans[1] <<     << ans[2] <<     << ans[3] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 3e3 + 3;   int p[MAX], cycle[MAX], nocycles, n, m;   void dfs(int v) {     cycle[v] = nocycles;     if (cycle[p[v]] == 0) dfs(p[v]);   }   void gen() {     nocycles = 1;     memset(cycle, 0, sizeof cycle);     for (int i = 1; i < n + 1; i++)       if (not cycle[i]) dfs(i), nocycles++;   }   vector<pair<int, int> > ans;   int main() {     scanf( %d , &n);     for (int i = 1; i < n + 1; i++) {       scanf( %d , p + i);     }     cin >> m;     gen();     int cur = n - nocycles + 1;     if (cur < m) {       int idx = 2;       while (cur != m) {         int comp = cycle[p[idx]];         if (comp == cycle[p[1]]) {           idx++;           continue;         }         ans.push_back(pair<int, int>(1, idx));         for (int i = idx; i < n + 1; i++)           if (cycle[i] == comp) cycle[i] = cycle[p[1]];         cur++, idx++;       }     } else if (cur > m) {       int idx = 1, loop = 1;       while (cur != m) {         if (p[idx] == idx) {           idx++;           continue;         }         for (int i = idx + 1; i < n + 1; i++)           if (cycle[p[i]] == cycle[p[idx]]) {             ans.push_back(pair<int, int>(idx, i));             swap(p[idx], p[i]);             break;           }         cur--;         gen();         loop++;         assert(loop <= n + 10);       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       printf( %d %d  , ans[i].first, ans[i].second);     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long fuck = 4e17;   long long n, arr[100010];   vector<long long> ans;   bool chk(long long x) {     vector<int> diffs;     for (int i = 0; i + 1 < n; i++) {       long long next = arr[i + 1];       if (arr[i] <= x) next = min(arr[i + 1], x);       long long d = next - arr[i];       if (diffs.size() == 0)         diffs.push_back(d);       else if (diffs[0] != d)         return false;     }     return true;   }   int main() {     scanf( %lld , &n);     for (int i = 0; i < n; i++) scanf( %lld , &arr[i]);     sort(arr, arr + n);     if (n == 1) {       printf( -1 );       return 0;     }     if (n == 2) {       long long d = arr[1] - arr[0];       ans.push_back(arr[0] - d);       ans.push_back(arr[1] + d);       if (!(d & 1)) ans.push_back(arr[1] - d / 2);     } else {       long long prev = arr[1] - arr[0], another = fuck, pos;       for (int i = 2; i < n; i++) {         long long d = arr[i] - arr[i - 1];         if (d != prev && d != another && another != fuck) {           printf( 0 );           return 0;         }         if (d != prev) {           pos = i;           another = arr[i] - arr[i - 1];         }       }       if (another == fuck) {         ans.push_back(arr[0] - prev);         ans.push_back(arr[n - 1] + prev);       } else {         if (prev == 2ll * another)           ans.push_back(arr[1] - another);         else if (another == prev * 2ll)           ans.push_back(arr[pos] - prev);       }     }     set<long long> res;     for (int i = 0; i < ans.size(); i++)       if (chk(ans[i])) res.insert(ans[i]);     printf( %d n , res.size());     for (set<long long>::iterator it = res.begin(); it != res.end(); it++)       printf( %lld  , *it);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int SEED = chrono::steady_clock::now().time_since_epoch().count();   mt19937 rng(SEED);   const int B = 3000;   struct Query {     int l, r, t, idx, bl, br;     Query(int l, int r, int t, int idx)         : l(l), r(r), t(t), idx(idx), bl(l / B), br(r / B) {}     bool operator<(const Query &q) const {       return tuple<int, int, int>(bl, br, t) <              tuple<int, int, int>(q.bl, q.br, q.t);     }   };   const int MAX = 100005;   int cnt[MAX], v[MAX], ocur[2 * MAX];   vector<pair<int, int> > updateForward, updateBackward;   void add(int pos) {     int x = v[pos];     cnt[ocur[x]]--;     cnt[++ocur[x]]++;   }   void remove(int pos) {     int x = v[pos];     cnt[ocur[x]]--;     cnt[--ocur[x]]++;   }   void applyUpdate(pair<int, int> upd, int l, int r) {     auto [pos, val] = upd;     if (l <= pos && pos <= r) remove(pos);     v[pos] = val;     if (l <= pos && pos <= r) add(pos);   }   int getAns() {     int res = 0;     while (cnt[res]) res++;     return res;   }   vector<int> MO(vector<Query> queries) {     cnt[0] = 0x3f3f3f3f;     int l = 0, r = -1, t = 0;     vector<int> ans(queries.size());     sort(queries.begin(), queries.end());     for (auto q : queries) {       while (t < q.t) applyUpdate(updateForward[t++], l, r);       while (q.t < t) applyUpdate(updateBackward[--t], l, r);       while (q.l < l) add(--l);       while (r < q.r) add(++r);       while (l < q.l) remove(l++);       while (q.r < r) remove(r--);       ans[q.idx] = getAns();     }     return ans;   }   void create_queries(vector<pair<int, int> > updates) {     int n = updates.size();     for (int i = 0; i < n; i++) {       auto [pos, val] = updates[i];       updateForward.emplace_back(pos, val);       updateBackward.emplace_back(pos, v[pos]);       v[pos] = val;     }     for (int i = n - 1; i >= 0; i--) {       auto [pos, val] = updateBackward[i];       v[pos] = val;     }   }   map<int, int> mp;   int compress(int x) {     if (!mp.count(x)) mp[x] = mp.size();     return mp[x];   }   void test_case() {     int n, q, type, l, r, x;     cin >> n >> q;     for (int i = 0; i < n; i++) {       cin >> x;       v[i] = compress(x);     }     vector<pair<int, int> > updates;     vector<Query> queries;     for (int i = 0; i < q; i++) {       cin >> type >> l >> r;       if (type == 1)         queries.emplace_back(l - 1, r - 1, updates.size(), queries.size());       if (type == 2) updates.emplace_back(l - 1, compress(r));     }     create_queries(updates);     vector<int> res = MO(queries);     for (auto x : res) cout << x << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t = 1;     for (int i = 1; i <= t; i++) {       test_case();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int INF = 1000000001;   const long long LINF = 1000000000000000001LL;   struct ITree {     vector<vector<long long>> T;     int p = 1;     int par(int x) { return (x - 1) / 2; }     ITree(vector<long long> &E) {       int n = (int)(E).size();       while (p < n) p *= 2;       T.resize(2 * p - 1);       for (int i = (0); i <= (n - 1); ++i) {         int v = i + p - 1;         T[v].push_back(E[i]);         while (v) {           v = par(v);           T[v].push_back(E[i]);         }       }       for (int i = (0); i <= ((int)(T).size() - 1); ++i)         sort(T[i].begin(), T[i].end());     }     int Count(int v, long long valL, long long valR) {       return upper_bound(T[v].begin(), T[v].end(), valR) -              lower_bound(T[v].begin(), T[v].end(), valL);     }     int Query(int l, int r, long long valL, long long valR) {       if (l > r) return 0;       l += p - 1;       r += p - 1;       int ans = Count(l, valL, valR);       if (l < r) ans += Count(r, valL, valR);       while (par(l) != par(r)) {         if (l % 2 == 1) ans += Count(l + 1, valL, valR);         if (r % 2 == 0) ans += Count(r - 1, valL, valR);         l = par(l);         r = par(r);       }       return ans;     }   };   void dfs(int v, vector<vector<pair<int, int>>> &g, vector<long long> &depth,            vector<int> &in, vector<int> &out, int &t) {     in[v] = ++t;     for (auto &e : g[v]) {       int u = e.first, len = e.second;       depth[u] = depth[v] + len;       dfs(u, g, depth, in, out, t);     }     out[v] = t;   }   vector<int> solve(int n, vector<int> &a, vector<vector<pair<int, int>>> &g) {     vector<long long> depth(n, 0);     vector<int> in(n), out(n);     int t = -1;     dfs(0, g, depth, in, out, t);     vector<long long> value(n);     for (int i = (0); i <= (n - 1); ++i) {       value[in[i]] = depth[i] - a[i];     }     ITree tree(value);     vector<int> ans(n);     for (int i = (0); i <= (n - 1); ++i) {       ans[i] = tree.Query(in[i] + 1, out[i], -LINF, depth[i]);     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     vector<int> a(n);     for (int i = (0); i <= (n - 1); ++i) {       cin >> a[i];     }     vector<vector<pair<int, int>>> g(n);     for (int i = (1); i <= (n - 1); ++i) {       int p, len;       cin >> p >> len;       p--;       g[p].push_back({i, len});     }     vector<int> ans = solve(n, a, g);     for (int i = (0); i <= (n - 1); ++i) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename S, typename T>   ostream& operator<<(ostream& out, pair<S, T> const& p) {     out <<  (  << p.first <<  ,   << p.second <<  ) ;     return out;   }   template <typename T>   ostream& operator<<(ostream& out, vector<T> const& v) {     long long l = v.size();     for (long long i = 0; i < l - 1; i++) out << v[i] <<    ;     if (l > 0) out << v[l - 1];     return out;   }   template <typename T>   void trace(const char* name, T&& arg1) {     cout << name <<   :   << arg1 <<   n ;   }   template <typename T, typename... Args>   void trace(const char* names, T&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     trace(comma + 1, args...);   }   int n, m;   int a[200], b[200];   vector<int> ans;   bool check(int no) {     for (int i = 0; i < n; i++) {       if (a[i] <= no and b[i] >= no) {         return true;       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i] >> b[i];     }     int c = 0;     for (int i = 1; i <= m; i++) {       if (check(i) == false) {         c++;         ans.push_back(i);       }     }     cout << c <<   n ;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   class trip {    public:     long long first;     long long second;     long long third;     trip() {}   };   bool comp1(trip a, trip b) {     if (a.first == b.first) {       if (a.second == b.second) {         return a.third < b.third;       }       return a.second < b.second;     }     return a.first < b.first;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     while (t--) {       long long n;       cin >> n;       vector<trip> v;       for (int i = 0; i < n; i++) {         trip p;         cin >> p.first >> p.second;         p.third = i + 1;         v.push_back(p);       }       long long k;       cin >> k;       vector<pair<long long, long long> > r;       for (int i = 0; i < k; i++) {         pair<long long, long long> p;         cin >> p.first;         p.second = i + 1;         r.push_back(p);       }       sort((v).begin(), (v).end(), comp1);       sort((r).begin(), (r).end());       vector<pair<long long, long long> > ans;       long long sum = 0;       for (int i = 0; i < k; i++) {         long long mx = 0;         long long in = -1;         for (int j = 0; j < n; j++) {           if (v[j].first > r[i].first) {             break;           } else {             if (v[j].second > mx) {               mx = v[j].second;               in = j;             }           }         }         if (in != -1) {           sum += v[in].second;           pair<long long, long long> p;           p.first = v[in].third;           p.second = r[i].second;           ans.push_back(p);           v[in].second = -1;         }       }       cout << ans.size() <<     << sum <<   n ;       for (int i = 0; i < ans.size(); i++) {         cout << ans[i].first <<     << ans[i].second <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<int> vis;   vector<int> ans;   map<int, int> d;   int main() {     int n, m;     cin >> n >> m;     queue<int> q;     int count = 0;     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       q.push(x);       vis.insert(x);       d[x] = 0;     }     long long int res = 0;     while (count < m) {       int now = q.front();       q.pop();       if (d[now] != 0) {         res += d[now];         ans.push_back(now);         count++;       }       if (vis.find(now - 1) == vis.end()) {         q.push(now - 1);         vis.insert(now - 1);         d[now - 1] = d[now] + 1;       }       if (vis.find(now + 1) == vis.end()) {         q.push(now + 1);         vis.insert(now + 1);         d[now + 1] = d[now] + 1;       }     }     printf( %lld n , res);     for (int i = 0; i < ans.size(); i++) {       printf( %d  , ans[i]);     }     int zz = 0;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long T = 0, n, t, a;   long long mu10(int b) {     long long c = 1;     for (int i = 1; i <= b; i++) c = c * 10;     return c;   }   long long solve(long long c) {     int m = 1;     long long T = 0;     while (T < c) {       T += ((mu10(m)) - (mu10(m - 1))) * m;       a = mu10(m) - 1;       m++;     }     m -= 1;     long long b = (T - c);     long long d = a - (b / m);     if (b % m == 0)       return d % 10;     else {       d /= mu10(b % m);       return d % 10;     }   }   int main() {     cin >> n;     cout << solve(n);     return 0;   }


#include <bits/stdc++.h>   int prime[20000000 + 1] = {0};   int palin[20000000 + 1] = {0};   bool check[20000000 + 1] = {1, 1, 0};   void primecheck() {     for (int i = 2; i <= 20000000; i++) {       if (check[i]) {         prime[i] = prime[i - 1];         continue;       }       prime[i] = prime[i - 1] + 1;       for (int j = 2; j * i <= 20000000; j++) check[j * i] = true;     }   }   void palincheck() {     for (int i = 1; i <= 20000000; i++) {       int j = i;       int counter = 0;       while (j > 0) {         counter = counter * 10 + j % 10;         j = j / 10;       }       if (i == counter)         palin[i] = palin[i - 1] + 1;       else         palin[i] = palin[i - 1];     }   }   int main() {     primecheck();     palincheck();     int p, q;     int left, right, mid;     left = 1, right = 20000000;     mid = (left + right) / 2;     scanf( %d %d , &p, &q);     for (int i = 20000000; i >= 1; i--)       if ((long long int)q * prime[i] <= (long long int)p * palin[i]) {         printf( %d n , i);         return 0;       }     return 0;   }


#include <bits/stdc++.h>   using db = double;   int read() {     int x;     scanf( %d , &x);     return x;   }   const int N = 50007;   const db eps = 1e-10;   db x, y, k[N], b[N], ans;   int n, c, t[N * 2], las[N], L[N * 2], R[N * 2];   struct node {     db ang;     int id;   } a[N * 2];   db sqr(db a) { return a * a; }   void add(int p, int v) {     for (; p <= c; p += p & -p) t[p] += v;   }   int ask(int p) {     int s = 0;     for (; p; p ^= p & -p) s += t[p];     return s;   }   int check(db r) {     db A, B, C, D, X, Y;     int s = 0;     c = 0;     for (int i = 1; i <= n; ++i) {       A = sqr(k[i]) + 1, B = -2 * x + 2 * k[i] * (b[i] - y),       C = sqr(x) + sqr(b[i] - y) - sqr(r);       if (B * B + eps <= 4 * A * C) continue;       D = sqrt(sqr(B) - 4 * A * C), A *= 2;       X = (D - B) / A, Y = k[i] * X + b[i], a[++c] = {atan2(Y - y, X - x), i};       X = (-D - B) / A, Y = k[i] * X + b[i], a[++c] = {atan2(Y - y, X - x), i};     }     std::sort(a + 1, a + c + 1,               [](const node& a, const node& b) { return a.ang < b.ang; });     for (int i = 1, id; i <= c; ++i)       las[id = a[i].id] ? s += ask(i) - ask(las[id]), add(las[id], -1),           las[id] = 0   : (add(i, 1), las[id] = i);     return s;   }   int pre[100010], nxt[100010], lst;   db cal(int i, int j) {     db X = (b[j] - b[i]) / (k[i] - k[j]), Y = X * k[i] + b[i];     return sqrt(sqr(X - x) + sqr(Y - y));   }   int main() {     db l = 0;     int m, s = 0;     n = read(), x = read() / 1000.0, y = read() / 1000.0, m = read();     for (int i = 1; i <= n; ++i) k[i] = read() / 1000.0, b[i] = read() / 1000.0;     for (db r = 1e13, mid, i = 100; i > 0; --i)       check(mid = (l + r) / 2) < m ? l = mid : r = mid;     check(l);     for (int i = 1, j = 0, p; i <= c; ++i)       if (las[a[i].id]) {         for (p = j; p > las[a[i].id]; p = L[p]) ++s, ans += cal(a[i].id, a[p].id);         R[L[p]] = R[p], L[R[p]] = L[p];         if (p == j) j = L[j];       } else         R[j] = i, L[i] = j, j = i, las[a[i].id] = i;     printf( %.10lf , ans + l * (m - s));   }


#include <bits/stdc++.h>   using namespace std;   static const double PI = acos(-1.0);   static const double EPS = 1e-9;   long long n;   long long a[200010];   long long dp[200010][2];   inline bool border(long long x) { return 0 <= x && x < n; }   long long dfs(long long x, long long step) {     if (dp[x][step] != -1) return dp[x][step];     dp[x][step] = -2;     if (step == 0) {       if (!border(x + a[x])) {         return dp[x][step] = a[x];       } else {         long long y = dfs(x + a[x], 1);         if (y == -2)           return dp[x][step] = -2;         else           return dp[x][step] = y + a[x];       }     } else if (step == 1) {       if (!border(x - a[x])) {         return dp[x][step] = a[x];       } else {         long long y = dfs(x - a[x], 0);         if (y == -2)           return dp[x][step] = -2;         else           return dp[x][step] = y + a[x];       }     }   }   int main() {     int i, j;     cin >> n;     for (i = 1; i < n; ++i) cin >> a[i];     for (i = 0; i < n; ++i)       for (j = 0; j < 2; ++j) dp[i][j] = -1;     for (i = 1; i < n; ++i)       for (j = 0; j < 2; ++j) dfs(i, j);     for (i = 1; i < n; ++i) {       if (dp[i][1] == -2)         puts( -1 );       else         printf( %I64d n , dp[i][1] + i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     cin >> n >> t;     n--;     t--;     int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int i = 0; i <= n; i) {       if (i == t) {         cout <<  YES n ;         return 0;       } else {         if (i < n)           i += arr[i];         else           break;       }     }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n;     vector<int> pl;     vector<int> sum;     int a;     int otv = 0;     cin >> n;     int m = pow(2, n + 1) - 2;     pl.push_back(0);     for (int i = 1; i <= m; ++i) {       cin >> a;       pl.push_back(a);     }     for (int j = n; j > 0; j--)       for (int i = pow(2, j); i < pow(2, j + 1) - 1; i += 2) {         pl[i / 2 - 1] += max(pl[i - 1], pl[i]);         otv += abs(pl[i - 1] - pl[i]);       }     cout << otv;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int CONST =  z  -  a  + 1;   struct Node {     Node() {       chars.resize(CONST);       for (int i = 0; i < CONST; i++) chars[i].reset(nullptr);     }     vector<unique_ptr<Node> > chars;   };   int prefix(Node* node, const string& word, int index) {     while (true) {       if (index == word.size()) return word.size();       char c = word[index];       if (node->chars[c -  a ].get() == nullptr) return index + 1;       node = node->chars[c -  a ].get();       ++index;     }   }   void add(Node* node, const string& word, int index) {     while (true) {       if (index == word.size()) return;       char c = word[index];       if (node->chars[c -  a ].get() == nullptr)         node->chars[c -  a ].reset(new Node());       node = node->chars[c -  a ].get();       index++;     }   }   int main() {     int k;     cin >> k;     string T;     cin >> T;     for (int i = 0; i < T.size(); ++i) {       for (int j = 1; j < T.size(); j++) {         for (int l = i; l <= i + j * 4; l += j) {           if (l < T.size() && T[l] ==  * ) {             if (l == i + j * 4) {               cout <<  yes  << endl;               return 0;             }           } else {             break;           }         }       }     }     cout <<  no  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class A>   void pr(A a) {     cout << a;     cout <<   n ;   }   template <class A, class B>   void pr(A a, B b) {     cout << a <<    ;     pr(b);   }   template <class A, class B, class C>   void pr(A a, B b, C c) {     cout << a <<    ;     pr(b, c);   }   template <class A, class B, class C, class D>   void pr(A a, B b, C c, D d) {     cout << a <<    ;     pr(b, c, d);   }   template <class A>   void PR(A a, long long n) {     for (long long i = (long long)(0); i < (long long)(n); i++) {       if (i) cout <<    ;       cout << a[i];     }     cout <<   n ;   }   long long check(long long n, long long m, long long x, long long y) {     return x >= 0 && x < n && y >= 0 && y < m;   }   const long long MAX = 1e9 + 7, MAXL = 1LL << 61, dx[4] = {-1, 0, 1, 0},                   dy[4] = {0, 1, 0, -1};   void Main() {     int T;     cin >> T;     while (T--) {       long long n;       string s;       cin >> n >> s;       long long ans = n;       for (long long i = (long long)(0); i < (long long)(n); i++) {         if (s[i] ==  1 ) {           ans = max(ans, (i + 1) * 2);           ans = max(ans, (n - i) * 2);         }       }       pr(ans);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     Main();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m, i;     cin >> n >> m;     map<int, int> mp;     for (i = 0; i < 3; i++) {       int t;       cin >> t;       if (i == 0) mp[t] = 1;       if (i == 1) mp[t] = 2;       if (i == 2) mp[t] = 3;     }     for (i = 1; i < m; i++) {       int a, b, c;       cin >> a >> b >> c;       if (mp[a] == 0 && mp[b] == 0 && mp[c] == 0) {         mp[a] = 1;         mp[b] = 2;         mp[c] = 3;       } else {         if (mp[a] != 0) {           int cur = b;           for (int j = 1; j <= 3; j++) {             if (mp[a] != j) {               mp[cur] = j;               cur = c;             }           }         } else if (mp[b] != 0) {           int cur = a;           for (int j = 1; j <= 3; j++) {             if (mp[b] != j) {               mp[cur] = j;               cur = c;             }           }         } else {           int cur = a;           for (int j = 1; j <= 3; j++) {             if (mp[c] != j) {               mp[cur] = j;               cur = b;             }           }         }       }     }     for (i = 1; i <= n; i++) {       cout << mp[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, x, res, p[(1 << 20)];   int main() {     for (cin >> n; n--;) scanf( %d , &x), p[x]++;     for (int i = 0; i < (1 << 20); i++) res += p[i] & 1, p[i + 1] += p[i] / 2;     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void trace(T a) {     cout << a <<   n ;   }   template <typename T, typename... Args>   void trace(T a, Args... args) {     cout << a <<    ;     trace(args...);   }   int recNum = 0;   void prTabs() {     for (int i = 0; i < recNum; i++) cout <<       ;   }   template <typename... Args>   void recInit(Args... args) {     prTabs();     trace( rec( , args...,  ) );     recNum++;   }   template <typename T>   void recEnd(T a) {     prTabs();     trace( -> , a);     recNum--;   }   int n, m, a, b, c;   map<int, int> s;   map<int, int> sa;   int li[500001];   int freq[2][2000002];   int k;   int main() {     memset(freq, 0, sizeof freq);     scanf( %d %d %d %d , &m, &k, &n, &b);     for (int i = 1; i <= m; i++) {       scanf( %d , li + i);     }     for (int i = 0; i < b; i++) {       scanf( %d , &a);       if (s.count(a)) {         s[a]++;       } else {         s[a] = 1;       }     }     int il = 0, ir = 0;     for (int i = 0; i < n; i++) {       int dacerto = true;       while (ir < m - ((n - 1 - i) * k)) {         freq[1][li[++ir]]++;       }       while (il < k * i) {         freq[0][li[++il]]++;       }       for (map<int, int>::iterator it = s.begin(); it != s.end(); it++) {         if (freq[1][it->first] - freq[0][it->first] < it->second) {           dacerto = false;           break;         }       }       if (!dacerto) continue;       printf( %d n , m - (n * k));       int falta = k - b;       for (int j = k * i + 1; j <= m - ((n - 1 - i) * k); j++) {         if (sa[li[j]] < s[li[j]]) {           sa[li[j]]++;         } else if (falta) {           sa[li[j]]++;           falta--;         } else {           printf( %d  , j);         }       }       printf(  n );       return 0;     }     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int infinity = 9e18;   bool possible(long long int x1, long long int x2, long long int y1,                 long long int y2, long long int n, long long int m, string s,                 long long int dx, long long int dy) {     long long int a = m / n;     long long int b = m % n;     x1 += a * dx;     y1 += a * dy;     for (int i = 0; i < b; i++) {       if (s[i] ==  U ) y1++;       if (s[i] ==  D ) y1--;       if (s[i] ==  R ) x1++;       if (s[i] ==  L ) x1--;     }     if ((abs(y1 - y2) + abs(x1 - x2)) <= m) return 1;     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int x1, x2, y1, y2, n;     cin >> x1 >> y1 >> x2 >> y2 >> n;     string s;     cin >> s;     long long int dx = 0, dy = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  U ) dy++;       if (s[i] ==  D ) dy--;       if (s[i] ==  R ) dx++;       if (s[i] ==  L ) dx--;     }     long long int st = 0, end = 1e18;     while (st < end) {       long long int mid = (end + st) / 2;       if (possible(x1, x2, y1, y2, n, mid, s, dx, dy)) {         end = mid;       } else {         st = mid + 1;       }     }     if (st == 1e18)       cout << -1;     else       cout << st;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   vector<int> g[N], gr[N];   bool used[N];   vector<int> order, component;   pair<int, int> edge[N];   int par[N];   vector<int> v[N];   int f(int i) {     if (par[i] != i) par[i] = f(par[i]);     return par[i];   }   void merge(int a, int b) {     a = f(a), b = f(b);     if (a == b) return;     par[a] = b;   }   void dfs1(int v) {     used[v] = true;     for (size_t i = 0; i < g[v].size(); ++i)       if (!used[g[v][i]]) dfs1(g[v][i]);     order.push_back(v);   }   void dfs2(int v) {     used[v] = true;     component.push_back(v);     for (size_t i = 0; i < gr[v].size(); ++i)       if (!used[gr[v][i]]) dfs2(gr[v][i]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       for (int i = 1; i <= n; i++)         g[i].clear(), gr[i].clear(), par[i] = i, v[i].clear();       order.clear();       component.clear();       for (int i = 1; i <= n; i++) used[i] = false;       for (int i = 0; i <= m - 1; i++) {         int a, b;         cin >> a >> b;         edge[i] = make_pair(a, b);         g[a].push_back(b);         gr[b].push_back(a);       }       for (int i = 1; i <= n; ++i)         if (!used[i]) dfs1(i);       for (int i = 1; i <= n; i++) used[i] = false;       for (int i = 0; i < n; ++i) {         int v = order[n - 1 - i];         if (!used[v]) {           dfs2(v);           int sz = component.size();           for (int i = 0; i <= sz - 1; i++) merge(component[0], component[i]);           component.clear();         }       }       for (int i = 1; i <= n; i++) v[i].clear();       set<int> s;       for (int i = 1; i <= n; i++) {         s.insert(f(i));       }       if (s.size() == 1) {         cout <<  No n ;       } else {         for (int i = 0; i <= m - 1; i++) {           if (f(edge[i].first) == f(edge[i].second)) continue;           v[f(edge[i].first)].push_back(f(edge[i].second));         }         set<int> s1;         for (int i = 1; i <= n; i++) {           if (v[f(i)].size() == 0) {             for (int j = 1; j <= n; j++) {               if (f(i) == f(j)) s1.insert(j);             }             break;           }         }         cout <<  Yes n ;         cout << s1.size() <<     << n - s1.size();         cout <<   n ;         for (__typeof(s1.begin()) it = s1.begin(); it != s1.end(); it++) {           cout << *it;           cout <<    ;         }         cout <<   n ;         for (int i = 1; i <= n; i++) {           if (!(s1.find(i) != s1.end())) {             cout << i;             cout <<    ;           }         }         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   double first[10005], second[10005], w, u, v;   double eps = 1e-9;   signed main() {     ios::sync_with_stdio(0);     cin.tie(NULL), cout.tie(NULL);     cin >> n >> w >> u >> v;     for (int i = 0; i < n; i++) cin >> first[i] >> second[i];     double ans = w / v;     int fl = 0;     for (int i = 0; i < n; i++) {       if (first[i] > eps) fl = 1;     }     if (!fl) {       cout << fixed << setprecision(15) << ans;       return 0;     }     fl = 0;     for (int i = 0; i < n; i++) {       if (first[i] < eps) {         fl = 1;         break;       }       if (w - second[i] < eps) continue;       double ti = first[i] / u;       double hi = second[i] / v;       if (hi - ti < eps) continue;       fl = 1;       break;     }     if (!fl) {       cout << fixed << setprecision(15) << ans;       return 0;     }     for (int i = 0; i < n; i++) {       if (first[i] < eps) continue;       if (w - second[i] < eps) continue;       double j = first[i] / u;       if (second[i] - w > eps) continue;       double f = second[i] / v;       if (f - j > eps) j = f;       j += (w - second[i]) / v;       ans = max(ans, j);     }     cout << fixed << setprecision(15) << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[110];   bool a[10];   int main() {     int x, y, pow = 1, t, k, b = 0;     gets(s);     k = strlen(s);     for (int i = 0; i < k; i++) {       for (int j = 0; j < 8; j++) a[j] = 0;       x = (int)s[i];       for (int j = 0; j < 8; j++) {         if (x % 2 == 1)           a[j] = 1;         else           a[j] = 0;         x /= 2;       }       t = 0;       pow = 1;       for (int j = 7; j >= 0; j--) {         t += pow * a[j];         pow *= 2;       }       y = (256 - t + b) % 256;       b = t;       cout << y << endl;     }     scanf(   );   }


#include <bits/stdc++.h>   using namespace std;   int n;   int pow2[50];   int l[50];   int level(long long p) {     long long comp = 1;     int ans = 0;     while (comp <= p) {       comp <<= 1;       ans++;     }     return ans - 1;   }   bool ispow2(long long p) {     long long comp = 1;     while (comp < p) {       comp <<= 1;     }     return comp == p;   }   bool viable(int cnt) {     int le[50];     for (int i = 0; i < 50; i++) le[i] = l[i];     int slot[50];     for (int i = 0; i < 50; i++) slot[i] = 0;     for (int i = 0; i < 50; i++) {       if (i == 0) {         if (pow2[i] > cnt) {           slot[i] = cnt;           le[i] += pow2[i] - cnt;         } else {           slot[i] = pow2[i];         }       } else {         if (pow2[i] > slot[i - 1]) {           slot[i] = slot[i - 1];           le[i] += pow2[i] - slot[i];         } else {           slot[i] = pow2[i];         }       }     }     int sum = 0;     for (int i = 49; i >= 0; i--) {       sum += le[i];       if (sum > slot[i]) return false;     }     return true;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       long long a;       cin >> a;       if (ispow2(a))         pow2[level(a)]++;       else         l[level(a)]++;     }     if (!viable(pow2[0])) {       cout << -1 << endl;       return 0;     }     int ansl = pow2[0];     while (ansl > 1 && viable(ansl - 1)) ansl--;     for (int i = ansl; i <= pow2[0]; i++) {       if (viable(i)) cout << i <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   long long n, l[MAXN], r[MAXN], vall[MAXN], valr[MAXN], pos[MAXN], d[MAXN],       tree[4 * MAXN], ind[MAXN];   bool validl[MAXN], validr[MAXN], dead;   pair<long long, long long> sortr[MAXN];   void computeleft() {     l[0] = -1, r[0] = 1, r[n + 1] = -1, l[n + 1] = n;     for (int i = 1; i <= n; ++i) l[i] = i - 1, r[i] = i + 1;     validl[0] = 1, vall[0] = 2 * d[0];     for (int i = 1; i <= n + 1; ++i) {       queue<int> drop;       if ((i > 1) && (pos[r[i - 1]] - pos[l[i - 1]] > 2 * d[i - 1]))         drop.push(i - 1);       while (!drop.empty()) {         int t = drop.front();         drop.pop();         int lt = l[t], rt = r[t];         r[lt] = r[t];         l[rt] = l[t];         if (lt != 0) {           if (pos[r[lt]] - pos[l[lt]] > 2 * d[lt]) drop.push(lt);         }         if (rt != i) {           if (pos[r[rt]] - pos[l[rt]] > 2 * d[rt]) drop.push(rt);         }       }       if (2 * d[i] - (pos[i] - pos[l[i]]) > 0) validl[i] = 1;       vall[i] = 2 * d[i] + pos[l[i]];     }     if (r[0] != n + 1) {       cout <<  0.0 n ;       exit(0);     }   }   void computeright() {     l[0] = -1, r[0] = 1, r[n + 1] = -1, l[n + 1] = n;     for (int i = 1; i <= n; ++i) l[i] = i - 1, r[i] = i + 1;     validr[n + 1] = 1, valr[n + 1] = pos[n + 1] - 2 * d[n + 1];     for (int i = n; i >= 1; --i) {       queue<int> drop;       if ((i < n) && (pos[r[i + 1]] - pos[l[i + 1]] > 2 * d[i + 1]))         drop.push(i + 1);       while (!drop.empty()) {         int t = drop.front();         drop.pop();         int lt = l[t], rt = r[t];         r[lt] = r[t];         l[rt] = l[t];         if (lt != i) {           if (pos[r[lt]] - pos[l[lt]] > 2 * d[lt]) drop.push(lt);         }         if (rt != n + 1) {           if (pos[r[rt]] - pos[l[rt]] > 2 * d[rt]) drop.push(rt);         }       }       if (2 * d[i] - (pos[r[i]] - pos[i]) > 0) validr[i] = 1;       valr[i] = pos[r[i]] - 2 * d[i];     }   }   void init(int l = 0, int r = n, int node = 1) {     if (l == r) {       tree[node] = 1e9 + 5;       return;     }     int mid = (l + r) / 2;     init(l, mid, 2 * node);     init(mid + 1, r, 2 * node + 1);     tree[node] = min(tree[2 * node], tree[2 * node + 1]);   }   int findmin(int a, int b, int l = 0, int r = n, int node = 1) {     if (a == l && b == r) return tree[node];     int mid = (l + r) / 2;     if (b <= mid) return findmin(a, b, l, mid, 2 * node);     if (a >= mid + 1) return findmin(a, b, mid + 1, r, 2 * node + 1);     return min(findmin(a, mid, l, mid, 2 * node),                findmin(mid + 1, b, mid + 1, r, 2 * node + 1));   }   void upd(int v, int x, int l = 0, int r = n, int node = 1) {     if (l == r) {       tree[node] = x;       return;     }     int mid = (l + r) / 2;     if (v <= mid)       upd(v, x, l, mid, 2 * node);     else       upd(v, x, mid + 1, r, 2 * node + 1);     tree[node] = min(tree[2 * node], tree[2 * node + 1]);   }   void findans() {     for (int i = 0; i <= n; ++i)       sortr[i] = pair<long long, long long>(valr[i + 1], i + 1);     sort(sortr, sortr + n + 1);     for (int i = 0; i <= n; ++i) ind[sortr[i].second] = i;     init();     long long best = 1e9 + 5;     for (int i = n; i >= 0; --i) {       if (validr[i + 1]) upd(ind[i + 1], pos[i + 1]);       if (!validl[i]) continue;       int lo = -1, hi = n;       while (lo != hi) {         int mid = (lo + hi + 1) / 2;         if (sortr[mid].first > vall[i])           hi = mid - 1;         else           lo = mid;       }       if (lo != -1) best = min(best, findmin(0, lo) - pos[i]);     }     cout << fixed << setprecision(1) << 0.5 * best << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n + 2; ++i) cin >> pos[i];     d[0] = d[n + 1] = 1LL * 1000000 * 1000000 + 5;     for (int i = 1; i <= n; ++i) cin >> d[i];     computeleft();     computeright();     findans();   }


#include <bits/stdc++.h>   using namespace std;   const int K = 103, N = 30005;   double f[K], sum[K];   double pr[N][K];   double mem[N][K];   int main() {     string s;     cin >> s;     int n, H;     cin >> n >> H;     H++;     if (s ==  Bob ) {       cout << n << endl;       return 0;     }     for (int i = 1; i <= H; i++) {       if (i == H)         f[i] = pow(2, -(i - 1));       else         f[i] = pow(2, -i);       sum[i] = sum[i - 1] + f[i];     }     for (int i = 1; i <= n; i++)       for (int t = 1; t <= H; t++)         mem[i][t] = pow(sum[t], i - 1) - pow(sum[t - 1], i - 1);     memset(pr, 0, sizeof pr);     pr[1][0] = 1;     for (int i = 2; i <= n; i++) {       for (int h = 1; h <= H; h++) {         double leftbigger = 1 - pow(sum[h], i - 1);         double rightbigger = 1 - pow(sum[h], n - i);         double skipped = leftbigger * rightbigger;         double dd = skipped * f[h];         pr[i][0] += dd;         double sm = dd;         for (int t = 1; t < h; t++) {           double left = mem[i][t];           pr[i][t] += left * f[h];           sm += left * f[h];         }         pr[i][h] += f[h] - sm;       }     }     double ans = 1;     for (int i = 1; i <= n; i++)       for (int h = 1; h <= H; h++) ans += pr[i][h] * pow(2, h - 1);     cout << setprecision(15) << ans << endl;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000 )   #pragma GCC ostarimize( O500 )   using namespace std;   const bool db = false;   set<pair<int, int>> s;   int a[200100];   int main() {     int n, k, q;     scanf( %d %d %d n , &n, &k, &q);     for (int i = 1; i <= n; i++) scanf( %d  , &a[i]);     scanf(  n );     int type, num;     set<pair<int, int>>::iterator it;     while (q--) {       scanf( %d %d n , &type, &num);       if (type == 1) {         s.insert({-a[num], num});         if (s.size() > k) {           it = s.end();           it--;           s.erase(it);         }       } else {         if (s.count({-a[num], num}))           puts( YES );         else           puts( NO );       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   struct Point {     long long x, y;     int id;     Point() {}     Point(long long a, long long b, int c) : x(a), y(b), id(c) {}     Point operator-(Point b) { return Point(x - b.x, y - b.y, 0); }     bool operator<(const Point &b) const {       return (x != b.x) ? x < b.x : y < b.y;     }   };   long long cross(Point x, Point y) { return x.x * y.y - x.y * y.x; }   bool in[2005];   int gethull(Point *p, int n, int s, bool v) {     static Point st[2005], hull[2005];     int top = 0, cnt = 0;     for (int i = 1; i <= n; i++) {       while (top > 1 && cross(p[i] - st[top], st[top] - st[top - 1]) >= 0) top--;       st[++top] = p[i];     }     for (int i = 1; i < top; i++) hull[++cnt] = st[i];     top = 0;     for (int i = 1; i <= n; i++) {       while (top > 1 && cross(p[i] - st[top], st[top] - st[top - 1]) <= 0) top--;       st[++top] = p[i];     }     for (int i = top; i > 1; i--) hull[++cnt] = st[i];     for (int i = 1; i <= cnt; i++)       if (hull[i].id == s) {         in[hull[i].id] = 1;         return (v) ? hull[(i - 1 + cnt - 1) % cnt + 1].id : hull[i % cnt + 1].id;       }   }   Point p[2005], q[2005];   char str[2005];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x, y;       scanf( %d%d , &x, &y);       p[i] = Point(x, y, i);     }     scanf( %s , str + 1);     str[n - 1] =  L ;     sort(p + 1, p + n + 1);     int cur = p[1].id;     for (int i = 1; i < n; i++) {       int cnt = 0;       for (int j = 1; j <= n; j++)         if (!in[p[j].id]) q[++cnt] = p[j];       printf( %d  , cur);       cur = gethull(q, cnt, cur, (str[i] ==  R ));     }     printf( %d n , cur);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int N = 1e6 + 5;   int n, m, k;   bool vis[N];   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> k;     int h;     for (int i = 1; i <= m; i++) {       cin >> h;       vis[h] = 1;     }     bool fg = 0;     int bone = 1;     if (vis[bone]) fg = 1;     for (int i = 1; i <= k; i++) {       int u, v;       cin >> u >> v;       if ((u == bone || v == bone) && !fg) {         bone = (bone == u) ? v : u;         if (vis[bone]) fg = 1;       }     }     cout << bone << endl;     return 0;   }


#include <bits/stdc++.h>   int min(int a, int b) { return a < b ? a : b; }   int max(int a, int b) { return a > b ? a : b; }   unsigned int X;   void srand_() {     struct timeval tv;     gettimeofday(&tv, NULL);     X = tv.tv_sec ^ tv.tv_usec | 1;   }   int rand_() { return (X *= 3) >> 1; }   int *ej[1000], eo[1000];   void append(int i, int j) {     int o = eo[i]++;     if (o >= 2 && (o & o - 1) == 0)       ej[i] = (int *)realloc(ej[i], o * 2 * sizeof *ej[i]);     ej[i][o] = j;   }   int aa[1000], bb[1000], ii[1000], n;   int compare(int i, int j) { return aa[i] != aa[j] ? aa[i] - aa[j] : i - j; }   void sort(int *ii, int l, int r) {     while (l < r) {       int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;       while (j < k) {         int c = compare(ii[j], i_);         if (c == 0)           j++;         else if (c < 0) {           tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;           i++, j++;         } else {           k--;           tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;         }       }       sort(ii, l, i);       l = k;     }   }   char visited[1000];   int qu[1000], cnt;   int i_;   void dfs1(int i) {     int o;     if (visited[i] || compare(i, i_) > 0) return;     visited[i] = 1;     qu[cnt++] = i;     for (o = eo[i]; o--;) {       int j = ej[i][o];       dfs1(j);     }   }   char add[1000];   int cc[1000][1000];   void dfs2(int p, int i, int c) {     int o;     for (o = eo[i]; o--;) {       int j = ej[i][o];       if (j != p) {         if (compare(j, i_) > 0)           cc[i_][j] = max(cc[i_][j], c);         else           dfs2(i, j, min(c + bb[j], 0x3f3f3f3f));       }     }   }   int dp[1000];   int solve(int s) {     int g;     memset(dp, 0, n * sizeof *dp), dp[0] = s;     for (g = 0; g < n; g++) {       int i_ = ii[g], x = dp[i_], j;       if (x == 0) continue;       for (j = 0; j < n; j++)         if (compare(i_, j) < 0 && cc[i_][j] != -1) {           int c = add[i_] ? min(x + cc[i_][j], 0x3f3f3f3f)                           : min(s + cc[i_][j], 0x3f3f3f3f);           if (c >= aa[j]) dp[j] = max(dp[j], min(c + bb[j], 0x3f3f3f3f));         }     }     return dp[ii[n - 1]] > 0;   }   int main() {     int t;     srand_();     scanf( %d , &t);     while (t--) {       static int qu_[1000], dd[1000], pp[1000];       int m, g, h, i, j, o, cnt_, lower, upper;       scanf( %d%d , &n, &m);       aa[0] = 0;       for (i = 1; i < n; i++) scanf( %d , &aa[i]), aa[i]++;       for (i = 1; i < n; i++) scanf( %d , &bb[i]);       for (i = 0; i < n; i++) ej[i] = (int *)malloc(2 * sizeof *ej[i]), eo[i] = 0;       for (h = 0; h < m; h++) {         scanf( %d%d , &i, &j), i--, j--;         append(i, j), append(j, i);       }       for (i = 0; i < n; i++) ii[i] = i;       sort(ii, 0, n);       for (g = 0; g < n; g++) {         i_ = ii[g];         memset(visited, 0, n * sizeof *visited), cnt = 0;         memset(cc[i_], -1, n * sizeof *cc[i_]);         dfs1(0);         if (visited[i_]) {           int tree, p;           memset(dd, 0, n * sizeof *dd);           memset(pp, -1, n * sizeof *pp);           for (h = 0; h < cnt; h++) {             i = qu[h];             for (o = eo[i]; o--;) {               j = ej[i][o];               if (visited[j]) dd[i]++;             }           }           cnt_ = 0;           for (h = 0; h < cnt; h++) {             i = qu[h];             if (dd[i] == 1) qu_[cnt_++] = i;           }           while (cnt_) {             i = qu_[--cnt_];             dd[i] = -1;             for (o = eo[i]; o--;) {               j = ej[i][o];               if (dd[j] > 0) {                 pp[i] = j;                 if (--dd[j] == 1) qu_[cnt_++] = j;               }             }           }           tree = 1;           for (h = 0; h < cnt; h++) {             i = qu[h];             if (dd[i] > 0) {               tree = 0;               break;             }           }           p = -1, i = 0;           while (i != -1 && dd[i] <= 0 && i != i_) p = i, i = pp[i];           add[i_] = 1;           if (dd[i_] <= 0 && i != i_)             dfs2(pp[i_], i_, 0);           else if (tree)             dfs2(p, i_, 0);           else {             int c;             add[i_] = 0;             c = 0;             for (i = 0; i != -1 && dd[i] <= 0; i = pp[i])               c = min(c + bb[i], 0x3f3f3f3f);             for (h = 0; h < cnt; h++) {               i = qu[h];               if (dd[i] > 0) c = min(c + bb[i], 0x3f3f3f3f);             }             for (p = -1, i = 0; i != -1 && dd[i] <= 0; p = i, i = pp[i])               for (o = eo[i]; o--;) {                 j = ej[i][o];                 if (compare(j, i_) > 0)                   cc[i_][j] = max(cc[i_][j], c);                 else if (j != pp[i] && j != p)                   dfs2(i, j, min(c + bb[j], 0x3f3f3f3f));               }             for (h = 0; h < cnt; h++) {               i = qu[h];               if (dd[i] > 0)                 for (o = eo[i]; o--;) {                   j = ej[i][o];                   if (compare(j, i_) > 0)                     cc[i_][j] = max(cc[i_][j], c);                   else if (pp[j] == i && j != p)                     dfs2(i, j, min(c + bb[j], 0x3f3f3f3f));                 }             }           }         }       }       lower = 0, upper = 0x3f3f3f3f;       while (upper - lower > 1) {         int s = (lower + upper) / 2;         if (solve(s))           upper = s;         else           lower = s;       }       printf( %d n , upper);       for (i = 0; i < n; i++) free(ej[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MIN = numeric_limits<long long>::min();   class WindowHeap {    public:     WindowHeap() {}     long long top() {       if (_i >= _h.size()) return MIN;       return _h[_i].first;     }     void erase(int idx) {       if (!_h.empty() && _h[_i].second == idx) ++_i;     }     void insert(long long val, int idx) {       if (val == MIN) return;       while (!_h.empty() && val > _h.rbegin()->first) _h.pop_back();       if (_h.empty() || val < _h.rbegin()->first)         _h.emplace_back(val, idx);       else         _h.rbegin()->second = idx;       if (_i >= _h.size()) _i = _h.size() - 1;     }       private:     vector<pair<long long, int>> _h;     size_t _i;   };   int main() {     int n, k, x;     cin >> n >> k >> x;     vector<int> a(n);     for (int& ai : a) cin >> ai;     vector<long long> dp(n + 1, MIN);     dp[0] = 0;     for (int xi = 0; xi < x; ++xi) {       WindowHeap wh;       for (int i = n - 1; i > max(n - k, -1); --i) {         wh.insert(dp[i], i);       }       for (int i = n; i > xi; --i) {         if (i - k >= 0) wh.insert(dp[i - k], i - k);         long long p = wh.top();         if (p > MIN) dp[i] = p + a[i - 1];         wh.erase(i - 1);       }       dp[xi] = MIN;     }     long long best = -1;     for (int i = n; i > n - k; --i) best = max(best, dp[i]);     cout << best << endl;     return 0;   }


#include <bits/stdc++.h>   long double read() {     int x;     scanf( %d , &x);     return x / 1000.0L;   }   const long double eps = 1e-9, Eps = 1e-7;   const int N = 1e5 + 5, V = 4e7 + 5;   int n, m, q, rb[N], vol, stc[V];   std::pair<int, int> p[N];   long double k, ox, oy, a[N], b[N], cx[N], cy[N];   long double ans, dis[N], s[N], t[N], tb[N];   struct FenwickTree {     int f[N];     void reset(int n) { memset(f, 0, (n + 1) * 4); }     void modify(int u, int x) {       for (int i = u; i <= m; i += i & -i) {         f[i] += x;       }     }     int query(int u) {       int res = 0;       for (int i = u; i >= 1; i ^= i & -i) {         res += f[i];       }       return res;     }     int query(int l, int r) {       if (l >= r) {         return 0;       }       return query(r) - query(l);     }   } tr;   long double get(int i, int j) {     long double x = (b[i] - b[j]) / (a[j] - a[i]), y = a[i] * x + b[i];     return std::sqrt((x - ox) * (x - ox) + (y - oy) * (y - oy));   }   bool check(long double k, bool typ) {     int res = 0;     m = 0;     for (int i = 0; i < n; i++) {       long double x = cx[i] - ox, y = cy[i] - oy;       if (dis[i] > k * k - eps) {         continue;       }       if (std::abs(dis[i]) < eps) {         s[i] = std::atan2(a[i], 1);         t[i] = std::atan2(-a[i], -1);       } else {         long double z = std::sqrt(k * k / dis[i] - 1);         s[i] = std::atan2(y - x * z, x + y * z);         t[i] = std::atan2(y + x * z, x - y * z);       }       if (s[i] > t[i]) {         std::swap(s[i], t[i]);       }       s[i] += eps;       t[i] -= eps;       tb[m++] = s[i];       tb[m++] = t[i];     }     std::sort(tb, tb + m);     for (int i = 0; i < n; i++) {       if (dis[i] > k * k - eps) {         p[i] = {m, i};         continue;       }       p[i] = {std::upper_bound(tb, tb + m, s[i]) - tb - 1, i};       rb[i] = std::upper_bound(tb, tb + m, t[i]) - tb;     }     std::sort(p, p + n);     if (!typ) {       tr.reset(m);       for (int i = 0; i < n; i++) {         if (p[i].first == m) {           break;         }         res += tr.query(p[i].first, rb[p[i].second]);         tr.modify(rb[p[i].second], 1);         if (res >= q) {           return false;         }       }     } else {       for (int i = 0; i < n; i++) {         if (p[i].first == m) {           break;         }         for (; vol > 0 && rb[stc[vol]] <= p[i].first; vol--)           ;         stc[++vol] = p[i].second;         for (int i = vol - 1; i > 0; i--) {           if (rb[stc[i]] > rb[stc[i + 1]]) {             break;           }           double tmp = get(stc[i], stc[i + 1]);           ans += tmp;           res++;           std::swap(stc[i], stc[i + 1]);         }       }       ans += (q - res) * k;     }     return true;   }   int main() {     scanf( %d , &n);     ox = read();     oy = read();     scanf( %d , &q);     int pass = 0;     for (int i = 0; i < n; i++) {       a[i] = read();       b[i] = read();       if (std::abs(a[i]) < eps) {         cx[i] = ox;         cy[i] = b[i];       } else {         long double _a = -1 / a[i], _b = oy - _a * ox;         cx[i] = (_b - b[i]) / (a[i] - _a);         cy[i] = a[i] * cx[i] + b[i];       }       dis[i] = (ox - cx[i]) * (ox - cx[i]) + (oy - cy[i]) * (oy - cy[i]);       if (dis[i] < eps) {         pass++;       }     }     if (pass * (pass - 1ll) / 2 >= q) {       printf( 0.000000 n );       return 0;     }     for (long double l = Eps, r = 21e8, mid; l <= r;) {       mid = (l + r) / 2;       if (check(mid, false)) {         l = mid + Eps;         k = mid;       } else {         r = mid - Eps;       }     }     check(k, true);     printf( %.6f n , (double)ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   vector<int> v[100000];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     map<int, int> m;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       for (int j = 2; j <= sqrt(a); j++) {         if (a % j == 0) {           m[j]++;           while (a % j == 0) a /= j;         }       }       if (a != 1) m[a]++;     }     int ans = 1;     for (auto i : m) ans = max(ans, i.second);     cout << ans;     return 0;   }


#include <iostream>   #include <queue>   #include <algorithm>   #include <cstring>   #include <cmath>   #include <vector>   using namespace std;   typedef long long LL;   const LL mod = 1e9 + 7;   const int N = 1e6 + 10;      LL l[N], r[N];   LL c[N], a[N], b[N];   int main()   {    int T;cin >> T;    while (T--)    {     int n;     cin >> n;     for (int i = 1; i <= n; i++)scanf( %lld ,&c[i]);     for (int i = 1; i <= n; i++)scanf( %lld , &a[i]);     for (int i = 1; i <= n; i++)scanf( %lld , &b[i]);        LL res = 0;     for (int i = 1; i < n;i++)     {      LL t = abs(a[i+1] - b[i+1]);      LL t2 = abs(a[i + 1] - b[i + 1]);            l[i] =t+1;      if (a[i+1] != b[i+1]&&i>1)       l[i] = max(l[i], l[i - 1] + c[i] - t + 1);      res = max(res, l[i] + c[i + 1]);           }        cout << res << endl;    }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 20;   const int V = (1 << 20) + 10;   const int P = 1000000007;   int Pow(int x, int y) {     int ret = 1;     while (y) {       if (y & 1) ret = (long long)ret * x % P;       x = (long long)x * x % P;       y /= 2;     }     return ret;   }   void utf(int *a, int l, int r) {     if (l + 1 != r) {       int mid = (l + r) / 2;       for (int i = 0; i < mid - l; i++) {         a[l + i] -= a[mid + i];         if (a[l + i] < 0) a[l + i] += P;       }       utf(a, l, mid);       utf(a, mid, r);     }   }   void tf(int *a, int l, int r) {     if (l + 1 != r) {       int mid = (l + r) / 2;       tf(a, l, mid);       tf(a, mid, r);       for (int i = 0; i < mid - l; i++) {         if (((l + i) & (mid + i)) != (l + i))           while (1)             ;         a[l + i] += a[mid + i];         if (a[l + i] >= P) a[i + l] -= P;       }     }   }   int cnt[V], q[V];   int n, x, pro[V];   int pt[V];   int main() {     pt[0] = 1;     for (int i = 1; i < (1 << N); i++) pt[i] = pt[i - 1] * 2 % P;     while (~scanf( %d , &n)) {       memset(cnt, 0, sizeof(cnt));       for (int i = 0; i < n; i++) {         scanf( %d , &x);         cnt[x]++;       }       tf(cnt, 0, (1 << N));       for (int i = 0; i < (1 << N); i++) pro[i] = pt[cnt[i]];       utf(pro, 0, (1 << N));       printf( %d n , pro[0]);     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, i, j, ans = 0;     char c[101];     scanf( %d , &n);     scanf( %s , c);     int l;     for (l = 1; l <= n; l++) {       for (i = 0; i < n - 4 * l; i++) {         if (c[i] ==  *  && c[i + l] ==  *  && c[i + 2 * l] ==  *  &&             c[i + 3 * l] ==  *  && c[i + 4 * l] ==  * ) {           ans = 1;           break;         }       }       if (ans == 1) break;     }     if (ans == 1)       printf( yes n );     else       printf( no n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T sq(T x) {     return x * x;   }   const long long inf = 2147383647;   const double pi = 2 * acos(0.0);   const double eps = 1e-9;   const long long maxint = 2147483647;   const long long minint = -2147483648;   long long gcd(long long a, long long b) {     while (b) {       a = a % b;       swap(a, b);     }     return a;   }   long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }   long long power(long long a, long long p) {     long long res = 1, x = a;     while (p) {       if (p & 1) res = res * x;       x = x * x;       p >>= 1;     }     return res;   }   long long bigmod(long long a, long long p, long long mod) {     long long res = 1, x = a;     while (p) {       if (p & 1) res = (res * x) % mod;       x = (x * x) % mod;       p >>= 1;     }     return res;   }   map<int, int> mp, mp2;   struct pop {     int first, second, id;   };   vector<pop> people;   int m;   int assign[100010];   long long memo[100010][2][2];   long long dp(int pos, int a, int b) {     if (pos == m) {       return 0;     }     if (memo[pos][a][b] != -1) return memo[pos][a][b];     int na, nb;     if (pos + 1 < m && people[pos].first == people[pos + 1].first) {       na = a;       nb = b;     } else if (pos + 1 < m && people[pos].first + 1 == people[pos + 1].first) {       na = b;       nb = 1;     } else {       na = 1;       nb = 1;     }     long long x = dp(pos + 1, na, nb);     long long y = x;     if (a && people[pos].second >= mp[people[pos].first]) {       int na, nb;       if (pos + 1 < m && people[pos].first == people[pos + 1].first) {         na = 0;         nb = b;       } else if (pos + 1 < m && people[pos].first + 1 == people[pos + 1].first) {         na = b;         nb = 1;       } else {         na = 1;         nb = 1;       }       y = mp[people[pos].first] + dp(pos + 1, na, nb);     }     long long z = x;     if (b && people[pos].second >= mp[people[pos].first + 1]) {       int na = a, nb = b;       if (pos + 1 < m && people[pos + 1].first == people[pos].first) {         na = a;         nb = 0;       } else if (pos + 1 < m && people[pos].first + 1 == people[pos + 1].first) {         na = 0;         nb = 1;       } else {         na = 1;         nb = 1;       }       z = mp[people[pos].first + 1] + dp(pos + 1, na, nb);     }     long long r = max(max(x, y), z);     return memo[pos][a][b] = r;   }   bool compare(const pop &a, const pop &b) {     if (a.first < b.first)       return true;     else if (a.first == b.first && a.second < b.second)       return true;     else       return false;   }   void init(int pos, int a, int b, long long res) {     if (pos == m) return;     int na, nb;     if (pos + 1 < m && people[pos].first == people[pos + 1].first) {       na = a;       nb = b;     } else if (pos + 1 < m && people[pos].first + 1 == people[pos + 1].first) {       na = b;       nb = 1;     } else {       na = 1;       nb = 1;     }     long long x = dp(pos + 1, na, nb);     if (x == res) {       assign[pos] = -1;       return init(pos + 1, na, nb, res);     }     long long y = x;     if (a && people[pos].second >= mp[people[pos].first]) {       int na, nb;       if (pos + 1 < m && people[pos].first == people[pos + 1].first) {         na = 0;         nb = b;       } else if (pos + 1 < m && people[pos].first + 1 == people[pos + 1].first) {         na = b;         nb = 1;       } else {         na = 1;         nb = 1;       }       y = mp[people[pos].first] + dp(pos + 1, na, nb);       if (y == res) {         assign[pos] = people[pos].first;         return init(pos + 1, na, nb, res - mp[people[pos].first]);       }     }     long long z = x;     if (b && people[pos].second >= mp[people[pos].first + 1]) {       int na = a, nb = b;       if (pos + 1 < m && people[pos + 1].first == people[pos].first) {         na = a;         nb = 0;       } else if (pos + 1 < m && people[pos].first + 1 == people[pos + 1].first) {         na = 0;         nb = 1;       } else {         na = 1;         nb = 1;       }       z = mp[people[pos].first + 1] + dp(pos + 1, na, nb);       if (z == res) {         assign[pos] = people[pos].first + 1;         return init(pos + 1, na, nb, res - mp[people[pos].first + 1]);       }     }   }   int main() {     memset(memo, -1, sizeof memo);     int n;     scanf( %d , &n);     int i;     for (i = 0; i < n; i++) {       int ci, si;       scanf( %d %d , &ci, &si);       mp[si] = ci;       mp2[si] = i + 1;     }     scanf( %d , &m);     for (i = 0; i < m; i++) {       pop temp;       scanf( %d %d , &temp.second, &temp.first);       temp.id = i + 1;       people.push_back(temp);     }     sort(people.begin(), people.end(), compare);     long long res = dp(0, 1, 1);     printf( %lld n , res);     init(0, 1, 1, res);     int r = 0;     for (i = 0; i < m; i++) {       int t = assign[i];       if (t == -1) continue;       if (mp2[t] > 0) r++;     }     printf( %d n , r);     for (i = 0; i < m; i++) {       int t = assign[i];       if (t == -1) continue;       if (mp2[t] > 0) {         printf( %d %d n , people[i].id, mp2[t]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, l, r, k, i, ans;   int main() {     scanf( %I64d%I64d%I64d%I64d , &n, &l, &r, &k);     r = (r + n - l + 1) % n;     if (k < r) {       printf( -1 );       return 0;     }     if (2 * r >= k) {       ans = min(k + n - r * 2 + 1, n);       if (ans >= k - r) {         printf( %I64d , ans);         return 0;       }     }     for (i = 1; i <= k; i++) {       l = max((k - n * i - r - 1) / (i + 1), (k - n * i - r * 2 - 1) / i) + 1;       ans = min(min((k - n * (i - 1) - r * 2 + 1) / (i + 1), (k - n * i - r) / i),                 n);       if (ans >= l) {         printf( %I64d , ans);         return 0;       }       if (i * i >= k) break;     }     i = min(i, n);     for (; i >= 0; i--) {       l = k % (n + i) - r;       if ((l <= min(i, r)) && (l >= max(i + r - n - 1, 0ll))) {         if (n + i >= k)           printf( %I64d , min(i + 1, n));         else           printf( %I64d , i);         return 0;       }     }     printf( -1 );   }