#include <bits/stdc++.h>   using std::abs;   using std::bitset;   using std::cerr;   using std::cin;   using std::cout;   using std::deque;   using std::map;   using std::max;   using std::min;   using std::pair;   using std::queue;   using std::set;   using std::sort;   using std::string;   using std::swap;   using std::unordered_map;   using std::unordered_set;   using std::vector;   void init() {     std::iostream::sync_with_stdio(0);     cout << std::fixed;     cout.precision(10);     cerr << std::fixed;     cerr.precision(10);     srand(time(0));   }   const int MAXN = 1e6 + 1;   long long arr[MAXN];   long long dp[MAXN][3];   int n;   long long a, b;   const long long INF = 1e18;   vector<int> fact(int x) {     vector<int> res;     int k = x;     for (int i = 2; i * i <= k; ++i)       if (!(x % i)) {         x /= i;         res.push_back(i);       }     if (x > 1) res.push_back(x);     return res;   }   long long solve(int p) {     for (int i = 0; i <= n; ++i)       for (int j = 0; j < 3; ++j) dp[i][j] = INF;     for (int i = 0; i < 3; ++i) dp[0][i] = 0;     for (int i = 1; i <= n; ++i) {       dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + a;       if (arr[i] % p == 0) {         dp[i][0] = dp[i - 1][0];         dp[i][2] = min(dp[i - 1][2], dp[i - 1][1]);       } else if ((arr[i] + 1) % p == 0 || (arr[i] - 1) % p == 0) {         dp[i][0] = dp[i - 1][0] + b;         dp[i][2] = min(dp[i - 1][2], dp[i - 1][1]) + b;       }     }     long long ans = INF;     for (int i = 0; i < 3; ++i) ans = min(ans, dp[n][i]);     return ans;   }   int main() {     init();     cin >> n >> a >> b;     for (int i = 1; i <= n; ++i) cin >> arr[i];     set<int> ma;     for (int i = -1; i <= 1; ++i) {       vector<int> tmp;       tmp = fact(arr[1] + i);       for (auto j : tmp) ma.insert(j);       tmp = fact(arr[n] + i);       for (auto j : tmp) ma.insert(j);     }     long long ans = INF;     for (auto i : ma) ans = min(ans, solve(i));     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void imprimirVector(vector<long long> v) {     if (!v.empty()) {       int p = v.size();       cout <<  [ ;       for (int i = 0; i < (int)(p - 1); i++) cout << v[i] <<  , ;       cout << v[p - 1] <<  ]  << endl;     } else       cout <<  []  << endl;   }   long long toNumber(string s) {     long long Number;     if (!(istringstream(s) >> Number)) Number = 0;     return Number;   }   string toString(long long number) {     ostringstream ostr;     ostr << number;     return ostr.str();   }   int main() {     ios_base::sync_with_stdio(0);     unsigned long long n;     cin >> n;     cout << (n * (n - 1) * (n - 2) * (n - 3) * (n - 4) / 120) * n * (n - 1) *                 (n - 2) * (n - 3) * (n - 4)          << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, long long> mp;   int main() {     int n;     cin >> n;     mp.clear();     for (int i = 1; i <= n; ++i) {       string tmp;       cin >> tmp;       mp[tmp]++;     }     cout << (mp[ UL ] + mp[ DR ] + mp[ ULDR ] + 1) *                 (mp[ UR ] + mp[ DL ] + mp[ ULDR ] + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isprime(int n) {     if (n == 1) return false;     if (n == 2) return true;     for (int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   void answer(int f) {     if (f) {       cout <<  YES ;     } else {       cout <<  NO ;     }     cout << endl;   }   long long int countSetBits(long long int n) {     long long int count = 0;     while (n) {       count += 1;       n = n / 10;     }     return count;   }   long long int factorial(long long int n) {     n = n % 1000000007;     return (n == 1 || n == 0 || n < 0) ? 1 : n * factorial(n - 1);   }   long long int ncp(long long int n, long long int p) {     long long int a = factorial(n);     long long int b = factorial(p);     long long int c = factorial(n - p);     return (a / (b * c));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int t = 1;     while (t--) {       long long int n, m;       cin >> n;       long long int i, c[n];       vector<long long int> a, b;       long long int sum1 = 0, sum2 = 0;       for (i = 0; i < n; i++) {         cin >> c[i];         if (c[i] > 0) {           sum1 += c[i];           a.push_back(c[i]);         } else {           long long int df = abs(c[i]);           sum2 += df;           b.push_back(df);         }       }       if (sum1 > sum2) {         cout <<  first ;         return 0;       } else if (sum1 < sum2) {         cout <<  second ;         return 0;       }       i = 0;       int x = min(a.size(), b.size());       while (i < x) {         if (a[i] < b[i]) {           cout <<  second ;           return 0;         } else if (a[i] > b[i]) {           cout <<  first ;           return 0;         }         i++;       }       if (c[n - 1] < 0)         cout <<  second ;       else         cout <<  first ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, ans[1010], foo[1010];   int t, l, r;   pair<pair<int, int>, int> ranges[1010];   int main() {     memset(foo, -1, sizeof(foo));     scanf( %d%d , &n, &m);     for (int i = 0; i < m; ++i) {       scanf( %d%d%d , &t, &l, &r);       ranges[i] = make_pair(pair<int, int>(l, r), t);       if (t == 1) {         for (int j = l; j < r; ++j) foo[j] = 0;       }     }     bool can = true;     ans[1] = 10000000;     for (int i = 0; i < m && can; ++i) {       if (ranges[i].second == 1) {         for (int j = ranges[i].first.first; j < ranges[i].first.second && can;              ++j) {           if (foo[j] != 0) can = false;         }       } else {         int cnt = 0;         for (int j = ranges[i].first.first; j < ranges[i].first.second && can;              ++j) {           if (foo[j] < 0) {             cnt++;             break;           }         }         if (cnt == 0) can = false;       }     }     if (!can) {       puts( NO );     } else {       puts( YES );       printf( %d , ans[1]);       for (int i = 2; i <= n; ++i) {         ans[i] = ans[i - 1] + foo[i - 1];         printf(  %d , ans[i]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[110000];   char res[110000];   int main() {     scanf( %s , s);     int resLen = 0;     int last = 0;     int index = 0;     for (int i = 0; i < 110000; i++) res[i] = 0;     for (char c =  z ; c >=  a ; c--)       for (int i = index; s[i]; i++)         if (s[i] == c) {           res[resLen] = c;           resLen++;           index = i + 1;         }     printf( %s n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k;     cin >> n >> k;     vector<pair<long double, long double>> v;     for (long long int i = 0; i < n; i++) {       long double x, y;       cin >> x >> y;       v.push_back(make_pair(x, y));     }     long double sum = 0;     for (long long int i = 1; i < v.size(); i++) {       long double x1 = v[i - 1].first, y1 = v[i - 1].second, x2 = v[i].first,                   y2 = v[i].second;       long double dis = sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));       sum = sum + dis;     }     long double ans = ((1.0 / 50.0) * sum) * k;     printf( %0.9Lf n , ans);   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx )   using namespace std;   const int MAXN = 1e3 + 3;   int n;   bool dp[MAXN][10];   string s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> s;     n = (int)s.length();     string kek =  heidi ;     memset(dp, 0, sizeof(dp));     for (auto i = 0; i != n; i++) {       for (auto j = 0; j != 5; j++) {         if (s[i] != kek[j]) continue;         if (j > 0) {           bool good = false;           for (auto k = 0; k != i; k++)             if (dp[k][j - 1]) {               good = true;               break;             }           if (!good) continue;         }         dp[i][j] = true;       }     }     for (auto i = 0; i != n; i++)       if (dp[i][4]) {         cout <<  YES ;         return 0;       }     cout <<  NO ;     return 0;   }


//begin #include <Core>   /*    * Package: StandardCodeLibrary.Core    * */   #include <iostream>   #include <fstream>   #include <sstream>   #include <iomanip>   #include <utility>   #include <vector>   #include <list>   #include <string>   #include <stack>   #include <queue>   #include <deque>   #include <set>   #include <map>   #include <algorithm>   #include <functional>   #include <numeric>   #include <bitset>   #include <complex>   #include <cstdio>   #include <cstring>   #include <cmath>   #include <cstdlib>   #include <ctime>   #include <climits>   #if __GNUC__>=4 and __GNUC_MINOR__>=6   #include <ext/pb_ds/assoc_container.hpp>   #include <ext/pb_ds/tree_policy.hpp>   #include <ext/pb_ds/tag_and_trait.hpp>   #endif   using namespace std;      #define lp for(;;)   #define repf(i,a,b) for (int i=(a);i<(b);++i)   #define rep(i,n) repf(i,0,n)   #define ft(i,a,b) for (int i=(a);i<=(b);++i)   #define fdt(i,a,b) for (int i=(a);i>=b;--i)   #define feach(e,s) for (typeof((s).begin()) e=(s).begin();e!=(s).end();++e)   #define fsubset(subset,set) for (int subset=(set)&((set)-1);subset;subset=(subset-1)&(set))   #define forin(i,charset) for (cstr i=(charset);*i;i++)   #define whl while   #define rtn return   #define fl(x,y) memset((x),char(y),sizeof(x))   #define clr(x) fl(x,char(0))   #define cpy(x,y) memcpy(x,y,sizeof(x))   #define pb push_back   #define mp make_pair   #define ins insert   #define ers erase   #define lb lower_bound   #define ub upper_bound   #define rnk order_of_key   #define sel find_by_order   #define x first   #define y second   #define sz(x) (int((x).size()))   #define all(x) (x).begin(),(x).end()   #define srt(x) sort(all(x))   #define uniq(x) srt(x),(x).erase(unique(all(x)),(x).end())   #define vec vector   #define pr pair   #define que queue   #define prq priority_queue   #define itr iterator   #define sf scanf   #define pf printf   #define pdb(prcs,x) (cout<<setprecision(prcs)<<fixed<<(sgn(x)?(x):0))   #ifdef DEBUG   #define prt(x) cerr<<#x = <<(x)<<endl   #define asrtWA(s) do if(!(s))do{cerr<< assert( #s ) <<endl;}whl(0);whl(0)   #define asrtTLE(s) do if(!(s))do{cerr<< assert( #s ) <<endl;}whl(0);whl(0)   #define asrtMLE(s) do if(!(s))do{cerr<< assert( #s ) <<endl;}whl(0);whl(0)   #define asrtOLE(s) do if(!(s))do{cerr<< assert( #s ) <<endl;}whl(0);whl(0)   #define asrtRE(s) do if(!(s))do{cerr<< assert( #s ) <<endl;}whl(0);whl(0)   #define runtime() cerr<< Used:  <<db(clock())/CLOCKS_PER_SEC<< s <<endl   #define input(in) do{}whl(0)   #define output(out) do{}whl(0)   #else   #define endl (char(  n ))   #define prt(x) (cerr)   #define asrtWA(s) do if(!(s))exit(0);whl(0)   #define asrtTLE(s) do if(!(s))whl(1);whl(0)   #define asrtMLE(s) do if(!(s))whl(new int);whl(0)   #define asrtOLE(s) do if(!(s))whl(1)puts( OLE );whl(0)   #define asrtRE(s) do if(!(s))*(int*)0=0;whl(0)   #define runtime() (cerr)   #define input(in) freopen(in, r ,stdin)   #define output(out) freopen(out, w ,stdout)   #endif      typedef long long int lli;   typedef double db;   typedef const char* cstr;   typedef string str;   typedef vec<int> vi;   typedef vec<vi> vvi;   typedef vec<bool> vb;   typedef vec<vb> vvb;   typedef vec<str> vs;   typedef pr<int,int> pii;   typedef pr<lli,lli> pll;   typedef pr<db,db> pdd;   typedef pr<str,int> psi;   typedef map<int,int> mii;   typedef map<str,int> msi;   typedef map<char,int> mci;   typedef set<int> si;   typedef set<str> ss;   typedef que<int> qi;   typedef prq<int> pqi;   #if __GNUC__>=4 and __GNUC_MINOR__>=7   template<typename key,typename value>class ext_map:public __gnu_pbds::tree<key,value,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{};   template<typename key>class ext_set:public __gnu_pbds::tree<key,__gnu_pbds::null_type,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{};   #elif __GNUC__>=4 and __GNUC_MINOR__>=6   template<typename key,typename value>class ext_map:public __gnu_pbds::tree<key,value,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{};   template<typename key>class ext_set:public __gnu_pbds::tree<key,__gnu_pbds::null_mapped_type,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{};   #endif      const int oo=(~0u)>>1;   const lli ooll=(~0ull)>>1;   const db inf=1e+10;   const db eps=1e-10;   const db pi=acos(-1.0);   const int MOD=1000000007;      template<typename type>inline bool cmax(type& a,const type& b){rtn a<b?a=b,true:false;}   template<typename type>inline bool cmin(type& a,const type& b){rtn b<a?a=b,true:false;}   template<typename type>inline type sqr(const type& x){rtn x*x;}   inline int dbcmp(const db& a,const db& b){rtn (a>b+eps)-(a<b-eps);}   inline int sgn(const db& x){rtn dbcmp(x,0);}   template<typename ostream,typename type>ostream& operator<<(ostream& cout,const pr<type,type>& x){rtn cout<< ( <<x.x<< , <<x.y<< ) ;}   template<typename type>pr<type,type> operator-(const pr<type,type>& x){rtn mp(-x.x,-x.y);}   template<typename type>pr<type,type> operator+(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x+b.x,a.y+b.y);}   template<typename type>pr<type,type> operator-(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x-b.x,a.y-b.y);}   template<typename type>inline type cross(const pr<type,type>& a,const pr<type,type>& b,const pr<type,type>& c){rtn (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);}   template<typename type>inline type dot(const pr<type,type>& a,const pr<type,type>& b,const pr<type,type>& c){rtn (b.x-a.x)*(c.x-a.x)+(b.y-a.y)*(c.y-a.y);}   template<typename type>inline type gcd(type a,type b){if(b)whl((a%=b)&&(b%=a));rtn a+b;}   template<typename type>inline type lcm(type a,type b){rtn a*b/gcd(a,b);}   template<typename type>inline void bit_inc(vec<type>& st,int x,type inc){whl(x<sz(st))st[x]+=inc,x|=x+1;}   template<typename type>inline type bit_sum(const vec<type>& st,int x){type s=0;whl(x>=0)s+=st[x],x=(x&(x+1))-1;rtn s;}   template<typename type>inline type bit_kth(const vec<type>& st,int k){int x=0,y=0,z=0;whl((1<<(++y))<=sz(st));fdt(i,y-1,0){if((x+=1<<i)>sz(st)||z+st[x-1]>k)x-=1<<i;else z+=st[x-1];}rtn x;}   inline void make_set(vi& st){rep(i,sz(st))st[i]=i;}   inline int find_set(vi& st,int x){int y=x,z;whl(y!=st[y])y=st[y];whl(x!=st[x])z=st[x],st[x]=y,x=z;rtn y;}   inline bool union_set(vi& st,int a,int b){a=find_set(st,a),b=find_set(st,b);rtn a!=b?st[a]=b,true:false;}   template<typename type>inline void merge(type& a,type& b){if(sz(a)<sz(b))swap(a,b);whl(sz(b))a.insert(*b.begin()),b.erase(b.begin());}   template<typename type>inline void merge(prq<type>& a,prq<type>& b){if(sz(a)<sz(b))swap(a,b);whl(sz(b))a.push(b.top()),b.pop();}      struct Initializer{Initializer(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}~Initializer(){runtime();}}initializer;   //end #include <Core>      int main()   {    int n,m;    cin>>n>>m;    vi u(m),v(m);    vec<db> c(m);    rep(i,m) cin>>u[i]>>v[i]>>c[i],--u[i],--v[i];    vec<vec<db > > matrix(n,vec<db >(n+1));    vi st(n);    make_set(st);    rep(i,m)    {     if (u[i]!=0&&u[i]!=n-1) matrix[u[i]][u[i]]+=1,matrix[u[i]][v[i]]-=1;     if (v[i]!=0&&v[i]!=n-1) matrix[v[i]][v[i]]+=1,matrix[v[i]][u[i]]-=1;     union_set(st,u[i],v[i]);    }    matrix[0][0]=1;    rep(i,n)    {     repf(j,i,n) if (abs(matrix[j][i])>abs(matrix[i][i])) swap(matrix[i],matrix[j]);     if (sgn(matrix[i][i]))      repf(j,i+1,n)      {       db times=matrix[j][i]/matrix[i][i];       ft(k,i,n) matrix[j][k]-=matrix[i][k]*times;      }    }    vec<db > x(n);    fdt(i,n-1,0)    {     if (sgn(matrix[i][i]))     {      x[i]=matrix[i][n];      repf(j,i+1,n) x[i]-=matrix[i][j]*x[j];      x[i]/=matrix[i][i];     }     else if (find_set(st,i)==find_set(st,0)) x[i]=inf;    }    db times=-inf;    rep(i,m) cmax(times,abs(x[u[i]]-x[v[i]])/c[i]);    rep(i,n) x[i]/=times;    db ans=0;    rep(i,m)    {     if (u[i]==0) ans+=x[v[i]];     if (v[i]==0) ans+=x[u[i]];    }    pdb(10,ans)<<endl;    rep(i,m) pdb(10,x[v[i]]-x[u[i]])<<endl;   }


#include <bits/stdc++.h>   using namespace std;   long long get() {     long long x = 0;     char s = getchar();     while (s <  0  || s >  9 ) s = getchar();     while (s >=  0  && s <=  9 )       x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();     return x;   }   long long Max(const long long x, const long long y) {     if (x > y) return x;     return y;   }   long long pow2(const long long x) { return x * x; }   const long long M = 3e5 + 5, INF = 2e18;   long long n, a, d[M], c[M], f[M];   struct node {     long long d, mxf, mxans;     node() {}     node(const long long D, const long long MXF, const long long MXANS) {       d = D, mxf = MXF, mxans = MXANS;     }   };   stack<node> s;   signed main() {     n = get(), a = get();     for (long long i = 1; i <= n; ++i)       d[i] = get(), c[i] = c[i - 1] + get(), f[i] = a * i - c[i];     long long ans = Max(0, a - (c[n] - c[n - 1]));     s.push(node(0, f[n], f[n]));     long long mxf_pre;     for (long long l = n - 1; l; --l) {       mxf_pre = -INF;       while (!s.empty() && s.top().d <= d[l + 1] - d[l]) {         mxf_pre = Max(mxf_pre, s.top().mxf);         s.pop();       }       if (mxf_pre != -INF && !s.empty())         s.push(node(d[l + 1] - d[l], mxf_pre,                     Max(mxf_pre - pow2(d[l + 1] - d[l]), s.top().mxans)));       else         s.push(node(d[l + 1] - d[l], mxf_pre,                     Max(mxf_pre - pow2(d[l + 1] - d[l]), -INF)));       if (!s.empty())         s.push(node(0, f[l], Max(f[l], s.top().mxans)));       else         s.push(node(0, f[l], Max(f[l], -INF)));       if (!s.empty())         ans = Max(ans, s.top().mxans - f[l - 1]);       else         ans = Max(ans, -INF);     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 100;   long long n, x, y;   int a[maxn];   vector<long long> v[maxn];   int vis[maxn];   int flag;   void dfs(int u) {     int i, j;     vis[u] = 1;     if (u == y) {       flag = 1;       return;     }     for (i = 0; i < v[u].size(); i++) {       int k = v[u][i];       if (vis[k]) continue;       vis[k] = 1;       if (k == y) {         flag = 1;         return;       }       dfs(k);       if (!flag)         vis[k] = 0;       else         return;     }   }   long long cnt = 0;   void dfs2(int u) {     int i, j;     for (i = 0; i < v[u].size(); i++) {       int k = v[u][i];       if (vis[k]) {         continue;       }       vis[k] = 1;       cnt++;       dfs2(k);     }   }   int main() {     int i, j;     cin >> n >> x >> y;     for (i = 1; i <= n - 1; i++) {       int l, r;       cin >> l >> r;       v[l].push_back(r);       v[r].push_back(l);     }     if (n == 1) {       cout << 0 << endl;       return 0;     }     if (n == 2) {       cout << 1 << endl;       return 0;     }     dfs(x);     long long ans = n * (n - 1);     cnt = 0;     dfs2(x);     cnt++;     long long x1 = cnt;     cnt = 0;     dfs2(y);     cnt++;     long long y1 = cnt;     cout << ans - x1 * y1 << endl;     return 0;   }


#include <bits/stdc++.h>   const int N = 100002;   int n, k, l[N], r[N];   char s[N];   bool check1() {     if (n == k || l[n] == 1 || r[1] == n || l[n - k] == 1 || r[k + 1] == n)       return 1;     for (int i = 2; i <= n - k; i++)       if (s[i - 1] == s[i + k] && l[i - 1] == 1 && r[i + k] == n) return 1;     return 0;   }   bool check2() {     if ((k << 1) < n) return 0;     for (int i = 2; i <= n - k; i++)       if (l[i - 1] != 1 || r[i + k] != n) return 0;     return 1;   }   int main() {     scanf( %d %d %s , &n, &k, s + 1);     l[1] = 1;     r[n] = n;     for (int i = 2; i <= n; i++) l[i] = s[i] == s[i - 1] ? l[i - 1] : i;     for (int i = n - 1; i >= 1; i--) r[i] = s[i] == s[i + 1] ? r[i + 1] : i;     if (check1()) return !printf( tokitsukaze n );     if (check2()) return !printf( quailty n );     printf( once again n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 35050;   const int inf = 1e9;   int t[2 * N], lz[N], n, h, k;   int dp[55][N], val[N];   pair<int, int> up[N];   int pv[N];   inline void carrot() {     for (int i = int(0); i < int(n + 1); ++i) pv[i] = n;     for (int i = int(n - 1); i >= int(0); i--) {       up[i].first = i + 1;       up[i].second = pv[val[i]];       pv[val[i]] = i + 1;     }   }   inline void clear_trees() {     memset(t, 0, sizeof(t));     memset(lz, 0, sizeof(lz));   }   inline void build_trees(int row) {     for (int i = int(0); i < int(n); ++i) t[i + n] = dp[row][i];     for (int i = int(n - 1); i >= int(1); i--)       t[i] = max(t[i << 1], t[i << 1 | 1]);   }   inline void apply(int p, int val) {     t[p] += val;     if (p < n) lz[p] += val;   }   inline void build(int p) {     while (p > 1) p >>= 1, t[p] = max(t[p << 1], t[p << 1 | 1]) + lz[p];   }   inline void modify(int lo, int ro) {     lo += n, ro += n;     for (int l = lo, r = ro; l < r; l >>= 1, r >>= 1) {       if (l & 1) apply(l++, 1);       if (r & 1) apply(--r, 1);     }     build(lo);     build(ro);   }   inline void push(int p) {     for (int s = int(h); s >= int(1); s--) {       int i = p >> s;       if (lz[i] != 0) {         apply(i << 1, lz[i]);         apply(i << 1 | 1, lz[i]);         lz[i] = 0;       }     }   }   inline int query(int l, int r) {     push(l + n);     push(r + n - 1);     int res = -inf;     for (l += n, r += n; l < r; l >>= 1, r >>= 1) {       if (l & 1) res = max(res, t[l++]);       if (r & 1) res = max(res, t[--r]);     }     return res;   }   inline int solve() {     memset(dp, 0, sizeof(dp));     carrot();     set<int> s;     for (int i = int(n - 1); i >= int(0); i--) {       s.insert(val[i]);       dp[1][i] = int(s.size());     }     for (int num = int(2); num < int(k + 1); ++num) {       clear_trees();       build_trees(num - 1);       for (int i = int(n - num); i >= int(0); i--) {         modify(up[i].first, up[i].second);         dp[num][i] = query(i + 1, n);       }     }     return dp[k][0];   }   inline void input_random() {     n = (rand() % 10) + 1;     k = (rand() % n) + 1;     for (int i = int(0); i < int(n); ++i) val[i] = (rand() % n) + 1;   }   int dp2[15][15];   inline int brute() {     memset(dp2, 0, sizeof(dp2));     for (int i = int(0); i < int(n); ++i) dp2[1][i] = dp[1][i];     for (int num = int(2); num < int(k + 1); ++num) {       for (int i = int(n - num); i >= int(0); i--) {         set<int> s;         s.insert(val[i]);         for (int j = int(i + 1); j < int(n); ++j) {           if (dp[num - 1][j] == 0) continue;           dp2[num][i] = max(dp2[num][i], dp2[num - 1][j] + int(s.size()));           s.insert(val[j]);         }       }     }     for (int num = int(1); num < int(k + 1); ++num) {       for (int i = int(0); i < int(n); ++i) cout << dp[num][i] <<    ;       cout << endl;     }     return dp2[k][0];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (int i = int(0); i < int(n); ++i) cin >> val[i];     h = sizeof(int) * 8 - __builtin_clz(n);     int ans = solve();     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   int n;   int ans = 300005, pos = 1;   long long tnow, wnow;   struct node {     long long t, w;   } a[N];   priority_queue<long long, vector<long long>, greater<long long> > q;   bool cmp(node a, node b) { return a.t > b.t; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld%lld , &a[i].t, &a[i].w);     tnow = a[1].t;     wnow = a[1].w;     a[1].t = 0;     sort(a + 1, a + 1 + n, cmp);     while (1) {       while (pos <= n && a[pos].t > tnow) {         q.push(a[pos].w - a[pos].t + 1);         pos++;       }       ans = min(ans, (int)q.size() + 1);       if (!q.size() || tnow < q.top()) break;       tnow -= q.top();       q.pop();     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const int inf = 2e9;   int ans[208][208];   int n, m;   namespace MaxFlow {   struct Edge {     int to, capacity, revid;     Edge() : to(-1), capacity(0), revid(-1){};     Edge(int t, int c, int r) : to(t), capacity(c), revid(r) {}   };   int depth[34010];   size_t curr[34010];   vector<Edge> g[34010];   void buildEdge(int src, int dst, int cap) {     g[src].push_back(Edge(dst, cap, int(g[dst].size())));     g[dst].push_back(Edge(src, 0, int(g[src].size()) - 1));   }   void bfs(int src) {     for (int i = 0; i <= 24000; i++) depth[i] = inf;     queue<int> q;     q.push(src);     depth[src] = 0;     while (!q.empty()) {       int p = q.front();       q.pop();       for (size_t i = 0; i < g[p].size(); i++) {         if (g[p][i].capacity == 0 || depth[g[p][i].to] <= depth[p] + 1) continue;         q.push(g[p][i].to);         depth[g[p][i].to] = depth[p] + 1;       }     }   }   int dfs(int x, int dst, int cmin) {     if (x == dst) return cmin;     for (size_t& i = curr[x]; i < g[x].size(); i++) {       Edge& e = g[x][i];       if (e.capacity == 0 || depth[e.to] <= depth[x]) continue;       int d = dfs(e.to, dst, min(cmin, e.capacity));       if (d > 0) {         e.capacity -= d;         int ac = x, ak = e.to;         if (ac > n) ans[ak][ac - n] -= d;         if (ak > n) ans[ac][ak - n] += d;         g[e.to][e.revid].capacity += d;         return d;       }     }     return 0;   }   int solve(int src, int dst) {     int res = 0;     while (true) {       bfs(src);       if (depth[dst] == inf) return res;       memset(curr, 0, sizeof curr);       int d = dfs(src, dst, inf);       while (d > 0) {         res += d;         d = dfs(src, dst, inf);       }     }   }   }  // namespace MaxFlow   int pep[108];   int pur[108];   int tot;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> pep[i];       MaxFlow::buildEdge(i, n + i, inf);       MaxFlow::buildEdge(0, i, pep[i]);       tot += pep[i];     }     int sum = 0;     for (int i = 1; i <= n; i++) {       cin >> pur[i];       sum += pur[i];       MaxFlow::buildEdge(i + n, 205, pur[i]);     }     while (m--) {       int a, b;       cin >> a >> b;       MaxFlow::buildEdge(a, b + n, inf);       MaxFlow::buildEdge(b, a + n, inf);     }     if (MaxFlow::solve(0, 205) != tot or tot != sum) {       cout <<  NO ;       return 0;     }     puts( YES );     cout <<   ;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         printf( %d  , ans[i][j]);       }       puts(  );     }   }


#include <bits/stdc++.h>   using namespace std;   struct s {     long long x;     long long y;   };   vector<s> v;   bool cmp(s a, s b) {     if (a.x == b.x) return a.y < b.y;     return a.x > b.x;   }   int main() {     long long a, b, c, d, e, i, j, k, xx, yy;     s aa, bb;     scanf( %lld %lld , &a, &b);     for (i = 0; i < a; i++) {       scanf( %lld %lld , &aa.x, &aa.y);       v.push_back(aa);     }     sort(v.begin(), v.end(), cmp);     xx = v[b - 1].x;     yy = v[b - 1].y;     long long count = 0;     for (i = 0; i < a; i++) {       if (xx == v[i].x && yy == v[i].y) {         count++;       }     }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int c1, c2, c3, c4, n, m;   const int maxn = 1050;   int a[maxn], b[maxn];   int p, q, r, s;   int x, y;   int main() {     cin >> c1 >> c2 >> c3 >> c4;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];       x += min(c1 * a[i], c2);     }     for (int i = 0; i < m; i++) {       cin >> b[i];       y += min(c1 * b[i], c2);     }     cout << min(min(x, c3) + min(y, c3), c4) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<pair<int, int> > s;   int t[200000];   int n, k, q;   int main() {     cin >> n >> k >> q;     for (int i = 1; i <= n; ++i) scanf( %d , t + i);     for (int i = 0; i < q; ++i) {       int type, id;       pair<int, int> p;       scanf( %d %d , &type, &id);       p = make_pair(t[id], id);       if (type == 1) {         s.insert(p);         if (s.size() > k) s.erase(s.begin());       } else if (type == 2) {         if (s.count(p))           printf( YES n );         else           printf( NO n );       } else {         assert(0);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int dd = (int)1e5 + 7;   int A[dd], k[dd], j[dd], G[dd];   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; ++i) {       int l, r;       scanf( %d %d , &l, &r);       G[l - 1]++, G[r]--;     }     int F = 0;     for (int i = 0; i < m; ++i) A[i] = (F += G[i]);     vector<int> Y;     for (int i = 0; i < m; ++i) {       auto I = upper_bound(Y.begin(), Y.end(), A[i]);       k[i] = I - Y.begin() + 1;       if (I == Y.end())         Y.push_back(A[i]);       else         *I = A[i];     }     Y = vector<int>(0);     for (int i = m - 1; i >= 0; --i) {       auto I = upper_bound(Y.begin(), Y.end(), A[i]);       j[i] = I - Y.begin() + 1;       if (I == Y.end())         Y.push_back(A[i]);       else         *I = A[i];     }     int ans = 0;     for (int i = 0; i < m; ++i) ans = max(ans, k[i] + j[i] - 1);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5, M = 1e9 + 7;   int n, a[N];   long long bigmod(long long b, long long p) {     long long t = 1;     for (; p; b = (b * b) % M, p >>= 1)       if (p & 1) t = (t * b) % M;     return t;   }   long long go(int now) {     vector<int> div;     for (int i = 1; i * i <= now; i++) {       if (now % i == 0) {         div.push_back(i);         if (i * i != now) div.push_back(now / i);       }     }     div.push_back(N);     sort(div.begin(), div.end());     long long last = 1, cur = 1;     for (int i = 0; i < div.size() - 1; i++) {       int x = lower_bound(a, a + n, div[i]) - a;       int y = lower_bound(a, a + n, div[i + 1]) - a;       long long tmp = bigmod(i + 1, y - x);       cur *= tmp;       cur %= M;     }     int sz = div.size() - 2;     div[sz] = N;     for (int i = 0; i < div.size() - 2; i++) {       int x = lower_bound(a, a + n, div[i]) - a;       int y = lower_bound(a, a + n, div[i + 1]) - a;       long long tmp = bigmod(i + 1, y - x);       last *= tmp;       last %= M;     }     return (cur - last + M) % M;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     long long ans = 1;     for (int i = 1; i < N; i++) {       ans += go(i);       ans %= M;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const int MX = 1e5 + 23;   const long long MOD = 998244353;   int read() {     char k = getchar();     int x = 0;     while (k <  0  || k >  9 ) k = getchar();     while (k >=  0  && k <=  9 ) x = x * 10 + k -  0 , k = getchar();     return x;   }   struct node {     int l, r;     int sum, mx;     node *lch, *rch;   } * root;   void pushup(node *x) {     x->sum = x->lch->sum + x->rch->sum;     x->mx = std::max(x->lch->mx + x->rch->sum, x->rch->mx);   }   node *build(int l, int r) {     node *x = new node;     x->l = l, x->r = r;     if (l == r) {       x->sum = x->mx = 0;       x->lch = x->rch = nullptr;     } else {       int mid = (l + r) >> 1;       x->lch = build(l, mid);       x->rch = build(mid + 1, r);       pushup(x);     }     return x;   }   void add(node *x, int p, int v) {     if (x->l == x->r) {       x->sum += v;       x->mx += v;       return;     }     if (p <= x->lch->r)       add(x->lch, p, v);     else       add(x->rch, p, v);     pushup(x);   }   int query(node *x, int ex) {     if (x->l == x->r) return x->l;     if (x->rch->mx + ex >= 1) return query(x->rch, ex);     return query(x->lch, ex + x->rch->sum);   }   int m, w[MX];   int main() {     root = build(1, 100000 + 233);     m = read();     for (int i = 1, type, x, v; i <= m; ++i) {       x = read(), type = read();       if (type == 0) {         add(root, x, -1);       } else {         v = read();         w[x] = v;         add(root, x, 1);       }       if (root->mx <= 0) {         puts( -1 );       } else {         printf( %d n , w[query(root, 0)]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long x, y;   vector<pair<pair<long long, long long>, int> > p;   long long dx, dy;   bool dot(long long x, long long y) {     long long x1 = x - p[0].first.first;     long long x2 = x - p[1].first.first;     long long y1 = y - p[0].first.second;     long long y2 = y - p[1].first.second;     return x1 * y2 - y1 * x2;     return true;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %I64d%I64d , &x, &y);       p.push_back(make_pair(make_pair(x, y), i + 1));     }     sort(p.begin(), p.end());     dx = p[0].first.first - p[1].first.first;     dy = p[0].first.second - p[1].first.second;     for (int i = 2; i < n; i++) {       if (dot(p[i].first.first, p[i].first.second)) {         printf( %d %d %d n , p[0].second, p[1].second, p[i].second);         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string a[55];   long long f[(1LL << (21))];   double fac[55];   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     int l = a[0].size();     fac[0] = 1;     for (int i = 1; i <= l; i++) fac[i] = fac[i - 1] * i;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         int s = 0;         for (int k = 0; k < l; k++)           if (a[i][k] == a[j][k]) s |= (1LL << (k));         f[s] |= (1LL << (i)) | (1LL << (j));       }     }     double res = 0;     for (int s = (1LL << (l)) - 1; s >= 0; s--) {       for (int k = 0; k < l; k++)         if (s >> k & 1) f[s ^ (1LL << (k))] |= f[s];     }     for (int s = 0; s < (1LL << (l)); s++) {       int nturn = __builtin_popcount(s);       for (int k = 0; k < l; k++)         if (s >> k & 1) {           int nreveal = 0;           long long x = f[s] ^ f[s ^ (1LL << (k))];           while (x) {             x -= x & (-x);             nreveal++;           }           res += (fac[nturn - 1] / fac[l] * fac[l - nturn]) * nturn * nreveal / n;         }     }     printf( %.15lf , res);   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 2 * 1e5 + 10;   ll res;   ll a[N];   void solve() {     ll t, x, y, ex, ey, neast = 0, nnorth = 0, nsouth = 0, nwest = 0;     map<char, int> mp;     cin >> t >> x >> y >> ex >> ey;     ll k = ex - x;     ll l = ey - y;     string s;     cin >> s;     if (k > 0) {       neast = k;     } else {       nwest = abs(k);     }     if (l > 0) {       nnorth = l;     } else {       nsouth = abs(l);     }     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  N  and nnorth > 0) {         nnorth--;       }       if (s[i] ==  E  and neast > 0) {         neast--;       }       if (s[i] ==  S  and nsouth > 0) {         nsouth--;       }       if (s[i] ==  W  and nwest > 0) {         nwest--;       }       if (nnorth == 0 and nsouth == 0 and neast == 0 and nwest == 0) {         cout << i + 1;         return;       }     }     cout << -1;   }   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     ll t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int MN = 1000 * 100 + 100;   int arr[MN], n, s_l, s_r;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];       s_r += arr[i];     }     s_r -= arr[0];     s_l = arr[0];     int cnt = 0;     for (int i = 1; i < n; i++) {       if (s_l == s_r) cnt++;       s_r -= arr[i];       s_l += arr[i];     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   const int MAX_N = 500000;   const int MAX_M = 500000;   const int MOD = 998244353;   int l[MAX_M], r[MAX_M], val[MAX_M];   int smen[1 + MAX_N + 1], left[1 + MAX_N], dp[1 + MAX_N], _sp[1 + 1 + MAX_N],       *sp = _sp + 1;   int solve(int n, int m, int bit) {     int last = 0, p = 0;     for (int i = 1; i <= n; ++i) {       smen[i] = 0;       left[i] = 0;     }     smen[n + 1] = left[n + 1] = 0;     for (int i = 0; i < m; ++i)       if ((1 << bit) & val[i]) {         smen[l[i]]++;         smen[r[i] + 1]--;       } else         left[r[i] + 1] = std::max(left[r[i] + 1], l[i]);     sp[0] = 1;     dp[0] = 1;     for (int i = 1; i <= n + 1; ++i) {       p += smen[i];       last = std::max(last, left[i]);       if (p == 0) {         dp[i] = (sp[i - 1] + MOD - sp[last - 1]) % MOD;       } else         dp[i] = 0;       sp[i] = (sp[i - 1] + dp[i]) % MOD;     }     return dp[n + 1];   }   int main() {     int n, k, m;     scanf( %d%d%d , &n, &k, &m);     for (int i = 0; i < m; ++i) scanf( %d%d%d , &l[i], &r[i], &val[i]);     int res = 1;     for (int i = 0; i < k; ++i) res = (long long)res * solve(n, m, i) % MOD;     printf( %d , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> ans;     int x[n], y[n];     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];       x[i] += 1e8;       y[i] += 1e8;     }     while (1) {       for (int i = 0; i < n; i++) {         if ((x[i] + y[i]) & 1) ans.push_back(i + 1);       }       if (ans.size() == 0 || ans.size() == n) {         ans.clear();         for (int j = 0; j < n; j++) {           int op = (x[j] + y[j]) / 2;           x[j] = (x[j] - y[j] + (int)1e9) / 2 - 5e8;           y[j] = op;         }       } else         break;     }     cout << ans.size() << endl;     for (auto x : ans) {       cout << x <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 2.0 * acos(0.0);   const double eps = 1e-9;   template <class T>   T Abs(T x) {     return x > 0 ? x : -x;   }   template <class T>   string toString(T n) {     ostringstream ost;     ost << n;     ost.flush();     return ost.str();   }   template <class T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <class T>   inline T lcm(T a, T b) {     if (a < 0) return lcm(-a, b);     if (b < 0) return lcm(a, -b);     return a * (b / gcd(a, b));   }   long long bit_set(long long k, int p) { return k = (k | (1 << p)); }   long long re_set(long long k, int p) { return k = (k & ~(1 << p)); }   template <class T>   inline T sqr(T n) {     return n * n;   }   template <class T>   T power(T n, int p) {     if (!p)       return 1;     else {       T sum = sqr(power(n, p >> 1));       if (p & 1) sum = n;       return sum;     }   }   int main() {     long long num;     cin >> num;     num = (num + 1) / 3LL;     cout << (num / 12LL) <<     << num % 12LL << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s[105];   int main() {     int n, m, cnt = 0, t, tt, temp, dis = 0, ans = 0, len;     int row = 0, rowup = 2e9, rowdn = -1, col = 0, collft = 2e9, colrt = -1;     int rowupcol, rowdncol, collftrow, colrtrow;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (s[i][j] ==  B ) {           cnt++;           if (i < rowup) {             rowup = i;             rowupcol = j;           }           if (rowdn < i) {             rowdn = i;             rowdncol = j;           }           if (j < collft) {             collft = j;             collftrow = i;           }           if (colrt < j) {             colrt = j;             colrtrow = i;           }         }       }     }     if (!cnt)       printf( 1 n );     else if (cnt == 1)       printf( 0 n );     else {       len = max(rowdn - rowup + 1, colrt - collft + 1);       if (len > n || len > m)         printf( -1 n );       else         printf( %d n , (len * len) - cnt);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long i, j, k, n, m, ans = 0, sum = 0, a[100005] = {0}, mn = 2e9, mx = 0,                              cnt = 1, index = 0, x, y, z, xptr, yptr, id1, id2,                              zptr;     string s;     set<int> all;     set<int>::iterator it2;     set<pair<int, int> > seg, tem;     set<pair<int, int> >::iterator it1, it, it3, it4;     cin >> s;     n = s.size();     for (i = 0; i < n; i++) {       all.insert(i);       if (i + 1 == n || s[i] != s[i + 1]) {         seg.insert(make_pair(index, cnt));         tem.insert(make_pair(index, index + cnt - 1));         cnt = 1;         index = i + 1;       } else {         cnt++;       }     }     while (seg.size() > 1) {       ans++;       vector<pair<int, int> > v;       for (it = seg.begin(); it != seg.end(); it++) {         x = it->first;         y = it->second;         it1 = it;         it1++;         if (it == seg.begin()) {           if (y > 1) {             v.push_back(make_pair(x, y - 1));           }           it3 = tem.lower_bound(make_pair(x, -1));           it2 = all.upper_bound(it3->second);           it2--;           all.erase(it2);           if (y == 1) {             tem.erase(it3);           }         } else if (it1 == seg.end()) {           if (y > 1) {             v.push_back(make_pair(x, y - 1));           }           it2 = all.lower_bound(x);           all.erase(it2);           if (y == 1) {             it3 = tem.lower_bound(make_pair(x, -1));             tem.erase(it3);           }         } else {           it2 = all.lower_bound(x);           all.erase(it2);           if (y > 1) {             it3 = tem.lower_bound(make_pair(x, -1));             it2 = all.upper_bound(it3->second);             it2--;             all.erase(it2);             if (y > 2) {               v.push_back(make_pair(x, y - 2));             }           }           if (y == 1 || y == 2) {             it3 = tem.lower_bound(make_pair(x, -1));             tem.erase(it3);           }         }       }       seg.clear();       if (v.size() != 0) {         xptr = v[0].first;         yptr = v[0].second;         it3 = tem.lower_bound(make_pair(xptr, -1));         zptr = it3->second;         tem.erase(it3);       }       for (i = 0; i < v.size(); i++) {         z = xptr;         it2 = all.lower_bound(z);         id1 = *it2;         z = v[i].first;         it2 = all.lower_bound(z);         id2 = *it2;         if (s[id1] == s[id2]) {           if (i != 0) {             yptr = yptr + v[i].second;             it3 = tem.lower_bound(make_pair(v[i].first, -1));             zptr = it3->second;             tem.erase(it3);           }         } else {           seg.insert(make_pair(xptr, yptr));           tem.insert(make_pair(xptr, zptr));           xptr = v[i].first;           yptr = v[i].second;           it3 = tem.lower_bound(make_pair(v[i].first, -1));           zptr = it3->second;           tem.erase(it3);         }         if (i + 1 == v.size()) {           seg.insert(make_pair(xptr, yptr));           tem.insert(make_pair(xptr, zptr));         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   using vec = vector<T>;   template <typename Iter>   ostream &_IterOutput_(ostream &o, Iter b, Iter e, const string ss =   ,                         const string se =   ) {     o << ss;     for (auto it = b; it != e; it++) o << (it == b ?    :  ,  ) << *it;     return o << se;   }   template <typename T1, typename T2>   ostream &operator<<(ostream &o, const pair<T1, T2> &pair) {     return o <<  (  << pair.first <<  ,   << pair.second <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &o, const vector<T> &vec) {     return _IterOutput_(o, begin(vec), end(vec),  [ ,  ] );   }   template <typename T>   ostream &operator<<(ostream &o, const set<T> &st) {     return _IterOutput_(o, begin(st), end(st),  { ,  } );   }   template <typename T, size_t N>   ostream &operator<<(ostream &o, const array<T, N> &arr) {     return _IterOutput_(o, begin(arr), end(arr),  | ,  | );   }   template <typename T1, typename T2>   ostream &operator<<(ostream &o, const map<T1, T2> &mp) {     o <<  { ;     for (auto it = mp.begin(); it != mp.end(); it++) {       o << (it == mp.begin() ?    :  ,  ) << it->first <<  :  << it->second;     }     o <<  } ;     return o;   }   void lucky_test() {     std::random_device rd;     std::mt19937 gen_(rd());     std::normal_distribution<double> dist_(0.0, 1.0);     if (dist_(gen_) >= 4.44444444) {       cout <<  Not lucky  << endl;       exit(0);     }   }   int N;   const int MX = 131072 * 4;   const int INF = 1e9;   int ZZ = 0;   struct Seg {     int val[MX];     int nl[MX], nr[MX];     int lz[MX];     void init(int id, int ql, int qr) {       nl[id] = ql;       nr[id] = qr;       val[id] = -INF;       if (ql == qr - 1) {         return;       }       int md = (ql + qr) / 2;       init(id * 2, ql, md);       init(id * 2 + 1, md, qr);     }     void push(int id) {       ZZ++;       int l = nl[id], r = nr[id];       int v = lz[id];       lz[id] = 0;       if (l == r - 1) {         return;       }       adj(id * 2, v);       adj(id * 2 + 1, v);       return;     }     void pull(int id) {       ZZ++;       int l = nl[id], r = nr[id];       if (l == r - 1) return;       val[id] = max(val[id * 2], val[id * 2 + 1]);     }     void adj(int id, int v) {       lz[id] += v;       val[id] += v;     }     void add(int id, int ql, int qr, int v) {       push(id);       int l = nl[id], r = nr[id];       if (l == ql and r == qr) {         adj(id, v);         return;       }       int md = (l + r) / 2;       if (qr <= md)         add(id * 2, ql, qr, v);       else if (ql >= md)         add(id * 2 + 1, ql, qr, v);       else {         add(id * 2, ql, md, v);         add(id * 2 + 1, md, qr, v);       }       pull(id);     }     int walk(int id) {       push(id);       if (val[id] < 0) return -1;       int l = nl[id], r = nr[id];       if (l == r - 1) {         return val[id] >= 0 ? l : -1;       }       if (val[id * 2 + 1] >= 0)         return walk(id * 2 + 1);       else         return walk(id * 2);     }   } tree;   struct Hao {     int val[MX];     int n;     void init(int id, int l, int r) {       n = r;       for (int i = l; i < r; i++) val[i] = -INF;     }     void add(int id, int l, int r, int v) {       for (int i = l; i < r; i++) val[i] += v;     }     int walk(int id) {       for (int i = n - 1; i >= 0; i--)         if (val[i] >= 0) return i;       return -1;     }     void dmp() {       for (int i = 0; i < n; i++) cout << val[i] <<    ;       cout << endl;     }   };   int V[MX];   int32_t main() {     do {       ios_base::sync_with_stdio(0);       cin.tie(0);     } while (0);     cin >> N;     tree.init(1, 0, N + 5);     for (int i = 0; i < N; i++) {       int p, t;       cin >> p >> t;       if (t == 0) {         tree.add(1, 0, p, -1);       } else {         cin >> V[p];         tree.add(1, p, p + 1, INF);         tree.add(1, 0, p, 1);       }       int pos = tree.walk(1);       if (pos == -1)         cout << -1 <<   n ;       else         cout << V[pos] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int n;     cin >> n;     vector<int> a(n + 1), b(n + 1), p(n + 1);     for (int i = 1; i <= n; ++i) {       cin >> a[i];       p[a[i]] = 0;     }     for (int i = 1; i <= n; ++i) {       cin >> b[i];       p[b[i]] = i;     }     if (p[1]) {       int k = 1, i;       for (i = 2; p[i] == p[1] + i - 1; ++i) {         k++;       }       if (p[i - 1] == n) {         set<int> s;         for (auto x : a) {           if (x) {             s.insert(x);           }         }         int f = 1;         int ind = 1;         for (; i <= n; ++i) {           auto it = s.find(i);           if (it == s.end()) {             f = 0;             break;           }           s.erase(it);           s.insert(b[ind]);           ind++;         }         if (f == 1) {           cout << n - k;           return 0;         }       }     }     int ans = 0;     for (int i = 1; i <= n; ++i) {       ans = max(ans, p[i] - i + 1 + n);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, t;     cin >> n >> t;     if (n == 1 && t == 10) {       cout <<  -1 ;       return 0;     }     if (t != 10)       cout << t;     else       cout <<  1 ;     for (int i = 1; i < n; i++) cout <<  0 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char board[8][8];   int main() {     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) scanf(  %c , &board[i][j]);     }     int minA = 100, minB = 100;     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) {         if (board[i][j] ==  W ) {           int k;           for (k = i; k >= 0; k--) {             if (k == i) continue;             if (board[k][j] !=  . ) break;           }           if (k < 0 and i < minA) minA = i;         }         if (board[i][j] ==  B ) {           int k;           for (k = i; k < 8; k++) {             if (k == i) continue;             if (board[k][j] !=  . ) break;           }           if (k >= 8 and 7 - i < minB) minB = 7 - i;         }       }     }     if (minA <= minB)       cout <<  A  << endl;     else       cout <<  B  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, y;     cin >> x >> y;     long long d = x * x + y * y;     if (x == 0 || y == 0) {       cout <<  black  << endl;       return 0;     }     for (long long i = 1; i <= 10000; i++) {       if (d < i * i) {         bool white = (i % 2 == 0 && x * y > 0) || (i % 2 == 1 && x * y < 0);         cout << (white ?  white  :  black ) << endl;         return 0;       }       if (d == i * i) {         cout <<  black  << endl;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int f, int s) {     if (s == 0)       return f;     else       return gcd(s, f % s);   }   int const N = 1002006;   long long const M = 998244353;   long double const ep = .000000000000000001;   vector<int> G[N];   long long pw[N];   int od = 0, ev = 0;   int vis[N];   bool wtf = 1;   void dfs(int node, int col) {     if (col % 2 == 0)       ev++;     else       od++;     vis[node] = col;     for (int i = 0; i < G[node].size(); i++) {       int el = G[node][i];       if (vis[el] == -1)         dfs(el, col ^ 1);       else if (col == vis[el])         wtf = 0;     }   }   int main() {     pw[0] = 1;     for (int i = 1; i < N; i++) pw[i] = (pw[i - 1] * 2) % M;     int t;     cin >> t;     while (t--) {       int n, e;       scanf( %d%d , &n, &e);       for (int i = 1; i <= n; i++) {         G[i].clear();         vis[i] = -1;       }       for (int i = 0; i < e; i++) {         int temp, temp1;         scanf( %d%d , &temp, &temp1);         G[temp].push_back(temp1);         G[temp1].push_back(temp);       }       wtf = 1;       long long ans = 1;       for (int i = 1; i <= n; i++) {         if (vis[i] == -1) {           od = 0, ev = 0;           dfs(i, 0);           long long tot = pw[od] + pw[ev];           tot %= M;           ans = (ans * tot) % M;         }       }       ans *= wtf;       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int mx = 705;   long long int dp[mx][mx][3][3];   char s[mx];   int p[mx];   stack<int> st;   long long int dfs(int l, int r, int lc, int rc) {     if (l >= r) return 1;     if (dp[l][r][lc][rc] != -1) return dp[l][r][lc][rc];     int x = p[l];     int y = p[r];     dp[l][r][lc][rc] = 0;     if (x == r) {       for (int i = 1; i <= 2; i++)         if (i != rc)           dp[l][r][lc][rc] = (dp[l][r][lc][rc] + dfs(l + 1, r - 1, 0, i)) % mod;       for (int i = 1; i <= 2; i++)         if (i != lc)           dp[l][r][lc][rc] = (dp[l][r][lc][rc] + dfs(l + 1, r - 1, i, 0)) % mod;     } else if (x + 1 == y) {       for (int i = 1; i <= 2; i++)         for (int j = 1; j <= 2; j++)           if (i != lc && j != rc)             dp[l][r][lc][rc] = (dp[l][r][lc][rc] + dfs(l + 1, x - 1, i, 0) *                                                        dfs(y + 1, r - 1, 0, j)) %                                mod;       for (int i = 1; i <= 2; i++)         for (int j = 1; j <= 2; j++)           if (i != j)             dp[l][r][lc][rc] = (dp[l][r][lc][rc] + dfs(l + 1, x - 1, 0, i) *                                                        dfs(y + 1, r - 1, j, 0)) %                                mod;       for (int i = 1; i <= 2; i++)         for (int j = 1; j <= 2; j++)           if (i != lc)             dp[l][r][lc][rc] = (dp[l][r][lc][rc] + dfs(l + 1, x - 1, i, 0) *                                                        dfs(y + 1, r - 1, j, 0)) %                                mod;       for (int i = 1; i <= 2; i++)         for (int j = 1; j <= 2; j++)           if (j != rc)             dp[l][r][lc][rc] = (dp[l][r][lc][rc] + dfs(l + 1, x - 1, 0, i) *                                                        dfs(y + 1, r - 1, 0, j)) %                                mod;     } else {       for (int i = 1; i <= 2; i++)         for (int j = 1; j <= 2; j++)           if (i != lc && j != rc)             dp[l][r][lc][rc] =                 (dp[l][r][lc][rc] + dfs(l + 1, x - 1, i, 0) *                                         dfs(x + 1, y - 1, 0, 0) % mod *                                         dfs(y + 1, r - 1, 0, j)) %                 mod;       for (int i = 1; i <= 2; i++)         for (int j = 1; j <= 2; j++)           dp[l][r][lc][rc] = (dp[l][r][lc][rc] +                               dfs(l + 1, x - 1, 0, i) * dfs(x + 1, y - 1, i, j) %                                   mod * dfs(y + 1, r - 1, j, 0)) %                              mod;       for (int i = 1; i <= 2; i++)         for (int j = 1; j <= 2; j++)           if (i != lc)             dp[l][r][lc][rc] =                 (dp[l][r][lc][rc] + dfs(l + 1, x - 1, i, 0) *                                         dfs(x + 1, y - 1, 0, j) % mod *                                         dfs(y + 1, r - 1, j, 0)) %                 mod;       for (int i = 1; i <= 2; i++)         for (int j = 1; j <= 2; j++)           if (j != rc)             dp[l][r][lc][rc] =                 (dp[l][r][lc][rc] + dfs(l + 1, x - 1, 0, i) *                                         dfs(x + 1, y - 1, i, 0) % mod *                                         dfs(y + 1, r - 1, 0, j)) %                 mod;     }     return dp[l][r][lc][rc];   }   int main() {     memset(dp, -1, sizeof(dp));     int n;     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = 1; i <= n; i++)       if (s[i] ==  ( )         st.push(i);       else {         p[st.top()] = i;         p[i] = st.top();         st.pop();       }     long long int ans = dfs(1, n, 0, 0);     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   int a[maxn], cnt[maxn], n, q;   long long ans = 0;   map<pair<long long, long long>, int> mp;   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       ans += a[i];     }     cin >> q;     long long s, t, u;     while (q--) {       cin >> s >> t >> u;       if (mp.find(pair<long long, long long>(s, t)) != mp.end()) {         int c = mp[pair<long long, long long>(s, t)];         if (cnt[c] <= a[c]) ans++;         cnt[c]--;         mp.erase(pair<long long, long long>(s, t));       }       if (u != 0) {         mp[pair<long long, long long>(s, t)] = u;         if (cnt[u] < a[u]) ans--;         cnt[u]++;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long n, i, j, pw = 1, ans1, ans2, diff = 1;   char a[100000], b[100000];   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) cin >> b[i];     ans1 = ans2 = 1;     for (i = 0; i < n; i++) {       if (a[i] ==  ? ) pw = (pw * 10) % mod;       if (b[i] ==  ? ) pw = (pw * 10) % mod;       if (a[i] ==  ?  && b[i] ==  ? )         ans1 = (ans1 * 55) % mod, ans2 = (ans2 * 55) % mod, diff *= 10;       else {         if (a[i] ==  ?  || b[i] ==  ? ) {           if (a[i] ==  ? )             ans1 = (ans1 * ( 9  - b[i] + 1)) % mod,             ans2 = (ans2 * (b[i] -  0  + 1)) % mod;           else             ans2 = (ans2 * ( 9  - a[i] + 1)) % mod,             ans1 = (ans1 * (a[i] -  0  + 1)) % mod;         } else {           if (a[i] < b[i]) ans1 = 0, diff = 0;           if (a[i] > b[i]) ans2 = 0, diff = 0;         }       }     }     cout << (pw - ans1 - ans2 + 3 * mod + diff) % mod;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = acos(-1.0);   vector<long long> v1, v2;   long long ans = 0, x, y;   long long fact[1008], dp[1008][1008];   void pow1(long long a[], long long i, long long end, long long sum) {     if (i == end) {       v1.push_back(sum);       return;     }     pow1(a, i + 1, end, sum + a[i]);     pow1(a, i + 1, end, sum);   }   void subsetSums1(long long arr[], long long l, long long r, long long sum = 0) {     if (l > r) {       v1.push_back(sum);       return;     }     subsetSums1(arr, l + 1, r, sum + arr[l]);     subsetSums1(arr, l + 1, r, sum);   }   void subsetSums2(long long arr[], long long l, long long r, long long sum = 0) {     if (l > r) {       v2.push_back(sum);       return;     }     subsetSums2(arr, l + 1, r, sum + arr[l]);     subsetSums2(arr, l + 1, r, sum);   }   void pow2(long long a[], long long i, long long end, long long sum) {     if (i == end) {       v2.push_back(sum);       return;     }     pow1(a, i + 1, end, sum + a[i]);     pow1(a, i + 1, end, sum);   }   string bn(long long length) {     string s;     s.resize(length);     char a[length];     for (int i = 0; i < length; ++i) a[i] =  0 ;     for (int i = 0; i < length; ++i) s[i] = a[i];     cout << s;     return s;     int count = length - 1;     while (length) {       s[count--] = (length % 2);       length /= 2;     }     return s;   }   long long powm(long long a, long long b, long long m) {     if (b == 0) return 1;     long long t = powm(a, b / 2, m);     if (b % 2) return a * t % m * t % m;     return t * t % m;   }   long long modinv1(long long b, long long m) { return powm(b, m - 2, m); }   long long nck(long long n, long long k) {     return fact[n] * modinv1(fact[n - k], 1000000007) % 1000000007 *            modinv1(fact[k], 1000000007) % 1000000007;   }   int suffix(int l, vector<int> v) {     int ans = 0;     long long p = 1;     for (int i = 0; i < max((int)v.size(), l); ++i) {       if (i < v.size()) {         ans = (ans + p * v[i] % 998244353) % 998244353;         p = (p * 10) % 998244353;       }       if (i < l) {         p = (p * 10) % 998244353;       }     }     return ans;   }   int prefix(vector<int> v, int l) {     int ans = 0;     long long p = 1;     for (int i = 0; i < max((int)v.size(), l); ++i) {       if (i < l) {         p = (p * 10) % 998244353;       }       if (i < v.size()) {         ans = (ans + p * v[i] % 998244353) % 998244353;         p = (p * 10) % 998244353;       }     }     return ans;   }   int ct = 0;   void sum(long long n) {     if (n / 10 == 0) return;     long long ans = 0;     while (n) {       ans += n % 10;       n /= 10;     }     ct++;     sum(ans);   }   vector<long long> v;   long long string_num(string);   void perm(long long l, long long cur, long long n) {     if (cur == l) {       v.push_back(n);       return;     }     perm(l, cur + 1, n * 10 + 4);     perm(l, cur + 1, n * 10 + 7);   }   long long string_num(string s) {     int x = s.size();     long long ans = 0, i = 0;     while (x--) {       ans += (pow(10, x) * (s[i++] -  0 ));     }     return ans;   }   void DJ() {     long long l, r;     cin >> l >> r;     long long ans = 0;     for (int i = 1; i < 11; ++i) {       perm(i, 0, 0);     }     long long it = lower_bound(v.begin(), v.end(), l) - v.begin();     long long sum = r - l + 1;     if (v[it] - l >= sum) {       ans += sum * v[it];       sum = 0;     } else {       ans += v[it] * (v[it] - l + 1);       sum -= v[it] - l + 1;       it++;     }     while (sum) {       if (v[it] - v[it - 1] >= sum) {         ans += sum * (v[it]);         sum = 0;       } else {         ans += v[it] * (v[it] - v[it - 1]);         sum -= v[it] - v[it - 1];         it++;       }     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) DJ();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 + 10;   int n, m;   int a[maxn];   int res0, res1;   void output(int l, int r) {     printf( ?  );     for (int i = 1; i < l; i++) printf( 0 );     for (int i = l; i <= r; i++) printf( 1 );     for (int i = r + 1; i <= n; i++) printf( 0 );     printf(  n );     fflush(stdout);   }   void dfs(int l, int r) {     if (res0 && res1) return;     if (l == r) {       output(l, l);       scanf( %d , &a[++m]);       if (a[m] - a[1] == 1)         res0 = l;       else         res1 = l;       return;     }     if (r - l == 1) {       output(l, l);       scanf( %d , &a[++m]);       if (a[m] - a[1] == 1) res0 = l;       if (a[1] - a[m] == 1) res1 = l;       if (res0 && res1) return;       dfs(r, r);       return;     }     int mid = (l + r) >> 1;     output(l, mid);     scanf( %d , &a[++m]);     if (a[m] - a[1] == mid - l + 1) {       res0 = l;       if (res0 && res1) return;       dfs(mid + 1, r);     } else if (a[1] - a[m] == mid - l + 1) {       res1 = l;       if (res0 && res1) return;       dfs(mid + 1, r);     } else {       if (res0 && res1) return;       dfs(l, mid);       if (res0 && res1) return;       dfs(mid + 1, r);     }   }   int main() {     scanf( %d , &n);     output(1, 0);     scanf( %d , &a[++m]);     dfs(1, n);     printf( ! %d %d n , res0, res1);     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mmax = 1e6 + 10;   const int eps = 1e-9;   struct node {     string name;   } s[105];   long long cmp(node a, node b) {     if (a.name == b.name) return a.name < b.name;     return a.name < b.name;   }   int main() {     long long n;     while (cin >> n) {       for (int i = 0; i < n; i++) {         cin >> s[i].name;       }       sort(s, s + n, cmp);       long long ans = 0, sum = 0;       for (int i = 0; i < n; i++) {         if (s[i].name[0] == s[i + 1].name[0])           ans++;         else {           long long num0 = (ans + 1) / 2;           long long num1 = ans + 1 - num0;           long long sum0 = 0, sum1 = 0;           for (int i = 1; i < num0; i++) sum0 += i;           for (int i = 1; i < num1; i++) sum1 += i;           sum += (sum0 + sum1);           ans = 0;         }       }       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, kk;   vector<int> g[10], e[10];   int cnt = 0;   bool used[10] = {}, vis[10] = {};   int usedCnt, visCnt;   long long cur;   int st;   int pc[1024];   void go(int v) {     vis[v] = true, ++visCnt;     vector<int> &f = e[v];     int sz = 0;     for (int x : g[v])       if (!used[x]) {         f[sz++] = x;       }     for (int mask = 0; mask < (int)(1 << sz); ++mask) {       int pcm = pc[mask];       for (int i = 0; i < (int)(sz); ++i)         if (mask & (1 << i)) {           used[f[i]] = true;         }       usedCnt += pcm;       int pos = 0;       while (pos < n && (!used[pos] || vis[pos])) ++pos;       if (pos != n) {         go(pos);       } else {         if (usedCnt == n) ++cur;       }       for (int i = 0; i < (int)(sz); ++i)         if (mask & (1 << i)) {           used[f[i]] = false;         }       usedCnt -= pcm;     }     vis[v] = false, --visCnt;   }   long long ans[15], c[15][15];   int main() {     for (int i = 0; i < (int)(1024); ++i) pc[i] = __builtin_popcount(i);     scanf( %d%d%d , &n, &m, &kk);     for (int i = 0; i < (int)(m); ++i) {       int from, to;       scanf( %d%d , &from, &to), --from, --to;       g[from].push_back(to);       g[to].push_back(from);     }     for (int i = 0; i < (int)(n); ++i) e[i].resize(g[i].size());     for (int i = 0; i < (int)(15); ++i) c[0][i] = 0;     c[0][0] = 1;     for (int i = 1; i < 15; ++i) {       c[i][0] = 1;       for (int j = 1; j < 15; ++j) {         c[i][j] = c[i - 1][j] + c[i - 1][j - 1];       }     }     for (int k = n - 1; k >= kk; --k) {       for (int mask = 0; mask < (int)(1 << n); ++mask)         if (pc[mask] == k) {           for (int i = 0; i < (int)(n); ++i)             vis[i] = used[i] = (mask & (1 << i)) > 0;           st = 0;           while (used[st]) ++st;           if (st == n) break;           usedCnt = k + 1;           visCnt = k;           used[st] = true;           cur = 0;           go(st);           for (int i = 0; i < (int)(n); ++i)             if (mask & (1 << i)) {               int mul = 0;               for (int to : g[i])                 if (!(mask & (1 << to))) {                   ++mul;                 }               cur *= mul;             }           ans[k] += cur;         }       for (int x = n - 1; x > k; --x) {         ans[k] -= ans[x] * c[x][k];       }     }     printf( %d n , (int)ans[kk]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long s;   int main() {     int n, a, b, c, d;     cin >> n >> a >> b >> c >> d;     for (int x = 1; x <= n; x++) {       int y = x + b - c;       int z = x + a - d;       int w = y + a - d;       if (y <= n && z <= n && w <= n && y > 0 && z > 0 && w > 0) s++;     }     s *= n;     cout << s;     return 0;   }


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


#include <bits/stdc++.h>   const int N = 1e5 + 10;   int ri() {     char c = getchar();     int x = 0, f = 1;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) x = (x << 1) + (x << 3) -  0  + c;     return x * f;   }   struct Pt {     long long x, y;     Pt(long long _x = 0, long long _y = 0) : x(_x), y(_y) {}     Pt operator+(Pt a) { return Pt(x + a.x, y + a.y); }     Pt operator-(Pt a) { return Pt(x - a.x, y - a.y); }     double operator*(Pt a) { return (double)x * a.y - (double)y * a.x; }   } A[N * 60], B[N], p[N], Ans[N * 60];   int tpa, tpb, all, cnt, tot, n, m, sums, G, mn, lst[N], sz[N << 1];   bool del[N << 1];   bool cmp(Pt a, Pt b) { return a.x == b.x ? a.y > b.y : a.x < b.x; }   struct Edge {     int pr[N << 1], to[N << 2], nx[N << 2], tp;     Pt w[N << 2];     Edge() { tp = 1; }     void add(int u, int v, Pt _w) {       to[++tp] = v;       nx[tp] = pr[u];       pr[u] = tp;       w[tp] = _w;     }     void adds(int u, int v, Pt w = Pt()) {       add(u, v, w);       add(v, u, w);     }   } R, T;   void Ins(int u, int v, Pt w) {     ++tot;     T.adds(tot, v, w);     T.adds(tot, lst[u]);     lst[u] = tot;   }   void Build(int u, int fa) {     for (int i = R.pr[u], v; i; i = R.nx[i])       if ((v = R.to[i]) != fa) Ins(u, v, R.w[i]), Build(v, u);   }   void Dfs(int u, int fa, Pt D) {     if (u <= n) p[++cnt] = D;     for (int i = T.pr[u], v; i; i = T.nx[i])       if (!del[i >> 1] && (v = T.to[i]) != fa) Dfs(v, u, D + T.w[i]);   }   void Get(Pt *p, int &cnt, Pt *A, int &tp) {     if (!cnt) return void(tp = 0);     std::sort(p + 1, p + cnt + 1, cmp);     A[tp = 1] = p[1];     for (int i = 2; i <= cnt; ++i)       if (p[i].x != p[i - 1].x) {         for (; tp > 1 && (p[i] - A[tp]) * (A[tp - 1] - A[tp]) >= 0;) --tp;         A[++tp] = p[i];       }   }   void Push() {     if (!tpa) {       for (int i = 1; i <= tpb; ++i) Ans[++all] = B[i];       return;     }     if (!tpb) {       for (int i = 1; i <= tpa; ++i) Ans[++all] = A[i];       return;     }     Ans[++all] = A[1] + B[1];     for (int i = 1, j = 1; i < tpa || j < tpb;) {       ++all;       if (i >= tpa)         Ans[all] = A[i] + B[++j];       else if (j >= tpb)         Ans[all] = A[++i] + B[j];       else {         Pt v1 = A[i + 1] - A[i];         Pt v2 = B[j + 1] - B[j];         Ans[all] = Ans[all - 1] + (v1 * v2 < 0 ? ++i, v1 : (++j, v2));       }     }   }   void Rt(int u, int fa) {     sz[u] = 1;     for (int i = T.pr[u], v; i; i = T.nx[i])       if (!del[i >> 1] && (v = T.to[i]) != fa) {         Rt(v, u);         sz[u] += sz[v];         int tmp = std::max(sz[v], sums - sz[v]);         if (mn > tmp) mn = tmp, G = i;       }   }   void Div(int u, int pres) {     if (pres == 1) return;     sums = pres;     mn = tot + 1;     Rt(u, 0);     del[G >> 1] = true;     int x = T.to[G], y = T.to[G ^ 1], sy = pres - sz[x];     cnt = 0;     Dfs(x, 0, Pt());     Get(p, cnt, A, tpa);     cnt = 0;     Dfs(y, 0, T.w[G]);     Get(p, cnt, B, tpb);     Push();     Div(x, sz[x]);     Div(y, sy);   }   long long F(int p, long long i) { return A[p].x * i + A[p].y; }   int main() {     tot = n = ri();     m = ri();     for (int i = 1; i < n; ++i) {       int u = ri(), v = ri(), a = ri(), b = ri();       R.adds(u, v, Pt(a, b));     }     for (int i = 1; i <= n; ++i) lst[i] = i;     Build(1, 0);     Div(1, tot);     Get(Ans, all, A, tpa);     int r = 1;     long long mmx = 0;     int ps = 0;     for (int i = 1; i <= tpa; ++i)       if (A[i].y > mmx) mmx = A[i].y, ps = i;     for (int i = 0; i < m; ++i) {       for (; r < tpa && F(r + 1, i) >= F(r, i); ++r)         ;       if (!i && mmx != F(r, i)) {         for (int i = 20; i <= 44; ++i) printf( %lld %lld n , A[i].x, A[i].y);         printf( %d %d %d n , r, ps, tot);       }       printf( %lld  , F(r, i));     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> vc[200007];   int main() {     int n;     scanf( %d , &n);     int res = 0;     for (auto i = (1); i <= (n); ++i) {       int m;       scanf( %d , &m);       vc[i].resize(m);       for (auto j = (0); j <= (m - 1); ++j) scanf( %d , &vc[i][j]);       sort(vc[i].rbegin(), vc[i].rend());       res = max(res, vc[i][0]);     }     long long ans = 0LL;     for (auto i = (1); i <= (n); ++i)       ans += (long long)(res - vc[i][0]) * (int)vc[i].size();     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a, i, j, ct = 0;   int main() {     cin >> a;     for (i = 0; i < a; i++) {       ct++;       if (ct == 1 || ct == 2) {         cout <<  a ;       }       if (ct == 3 || ct == 4) {         cout <<  b ;         if (ct == 4) {           ct = 0;         }       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   int n, k;   char str[100005];   long long jie[100005];   long long ni[100005];   long long sum[100005];   long long extend_gcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1, y = 0;       return a;     }     long long gcd = extend_gcd(b, a % b, x, y);     long long t = x;     x = y;     y = t - a / b * x;     return gcd;   }   long long Get_Inverse(long long num) {     long long x, y;     extend_gcd(num, 1000000007, x, y);     return (x % 1000000007 + 1000000007) % 1000000007;   }   void init() {     jie[0] = jie[1] = 1;     ni[0] = ni[1] = 1;     for (int i = 2; i <= 100000; i++) {       jie[i] = (jie[i - 1] * i) % 1000000007;       ni[i] = Get_Inverse(jie[i]);     }   }   long long cal(int n, int m) {     if (n < m) return 0;     return jie[n] * ni[n - m] % 1000000007 * ni[m] % 1000000007;   }   int main(void) {     init();     scanf( %d%d , &n, &k);     scanf( %s , str + 1);     long long ans = 0;     long long ten = 1;     for (int i = 1; i <= n; i++) {       sum[i] =           (sum[i - 1] + ten * cal(n - i - 1, k - 1) % 1000000007) % 1000000007;       ten = ten * 10 % 1000000007;     }     ten = 1;     for (int i = n; i >= 1; i--) {       int c = str[i] -  0 ;       ans += c * ten % 1000000007 * cal(i - 1, k) % 1000000007;       ans += c * sum[n - i] % 1000000007;       ans %= 1000000007;       ten = ten * 10 % 1000000007;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void hashLine(int n) {     for (int i = 0; i < n; i++) cout <<  # ;     cout << endl;   }   void right(int n) {     cout <<  . ;     for (int i = 1; i < n - 1; i++) cout <<  . ;     cout <<  # n ;   }   void left(int n) {     cout <<  # ;     for (int i = 1; i < n - 1; i++) cout <<  . ;     cout <<  . n ;   }   int main() {     int n, m, i, j, dir = 0;     cin >> n >> m;     for (i = 0; i < n; i++) {       if (i % 2 == 0)         hashLine(m);       else {         if (dir == 0) {           right(m);           dir = 1;         } else {           left(m);           dir = 0;         }       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 222222;   unsigned long long p4423[maxn];   struct State {     unsigned long long hashValue;     int count;     void assign(int value) {       if (value == 0) {         hashValue = 0;         count = 0;       } else {         hashValue = value;         count = 1;       }     }     void assign(const State &l, const State &r) {       hashValue = p4423[r.count] * l.hashValue + r.hashValue;       count = l.count + r.count;     }   };   State states[maxn * 2];   int n, m;   int a[maxn], b[maxn];   int pos[maxn];   void update(int l, int r, int p, int v) {     if (l == r) {       if (p == l) {         states[(((l) + (r)) | ((l) != (r)))].assign(v);       }       return;     }     int m = l + r >> 1;     if (p <= m) {       update(l, m, p, v);     }     if (p > m) {       update(m + 1, r, p, v);     }     states[(((l) + (r)) | ((l) != (r)))].assign(         states[(((l) + (m)) | ((l) != (m)))],         states[(((m + 1) + (r)) | ((m + 1) != (r)))]);   }   int main() {     p4423[0] = 1;     for (int i = 1; i < maxn; i++) {       p4423[i] = p4423[i - 1] * 4423;     }     scanf( %d%d , &n, &m);     unsigned long long targetHash = 0, ones = 0;     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       targetHash = targetHash * 4423 + a[i];       ones = ones * 4423 + 1;     }     for (int i = 0; i < m; i++) {       scanf( %d , b + i);       pos[b[i]] = i;     }     for (int i = 1; i < n; i++) {       update(0, m - 1, pos[i], i);     }     int ret = 0;     for (int i = n; i <= m; i++) {       update(0, m - 1, pos[i], i);       assert(states[(((0) + (m - 1)) | ((0) != (m - 1)))].count == n);       if (states[(((0) + (m - 1)) | ((0) != (m - 1)))].hashValue == targetHash) {         ret++;       }       targetHash += ones;       update(0, m - 1, pos[i - n + 1], 0);     }     printf( %d n , ret);   }


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


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<long long, int> > vertices;   bool cmp(pair<long long, int> x, pair<long long, int> y) {     return x.first < y.first;   }   bool cmp2(pair<long long, pair<int, int> > x,             pair<long long, pair<int, int> > y) {     return x.first < y.first;   }   int lab[200010];   vector<pair<long long, pair<int, int> > > ed;   void uni(int r1, int r2) {     int x = lab[r1] + lab[r2];     if (lab[r1] < lab[r2]) {       lab[r1] = x;       lab[r2] = r1;     } else {       lab[r2] = x;       lab[r1] = r2;     }   }   int get(int x) {     if (lab[x] < 0) return x;     lab[x] = get(lab[x]);     return lab[x];   }   static int desyncIO = []() {     std::ios::sync_with_stdio(false);     std::cout.tie(nullptr);     std::cin.tie(nullptr);     return 0;   }();   int main() {     ios::sync_with_stdio(false);     memset(lab, -1, sizeof(lab));     cin >> n >> m;     for (int i = 1; i <= n; i++) {       long long x;       cin >> x;       vertices.push_back(make_pair(x, i));     }     sort(vertices.begin(), vertices.end(), cmp);     for (int i = 1; i < n; i++) {       int u = vertices[0].second;       int v = vertices[i].second;       long long w = vertices[0].first + vertices[i].first;       ed.push_back(make_pair(w, make_pair(u, v)));     }     for (int i = 1; i <= m; i++) {       int u, v;       long long w;       cin >> u >> v >> w;       ed.push_back(make_pair(w, make_pair(u, v)));     }     sort(ed.begin(), ed.end(), cmp2);     long long ret = 0;     for (int i = 0; i < ed.size(); i++) {       int u = ed[i].second.first;       int v = ed[i].second.second;       long long w = ed[i].first;       int r1 = get(u);       int r2 = get(v);       if (r1 != r2) {         ret += w;         uni(r1, r2);       }     }     cout << ret;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> com;   vector<int> num;   vector<string> adj[1000010];   struct node {     string s;     int i;     node() {}     node(string x, int idx) {       s = x;       i = idx;     }   };   int toNum(string s) {     int i, j, k;     int l = s.length();     k = 1;     j = 0;     for (i = l - 1; i >= 0; i--) {       j += (s[i] - 48) * k;       k *= 10;     }     return j;   }   int jdx, sz;   void solve(node x, int lvl) {     if (lvl >= 0) adj[lvl].push_back(x.s);     if (lvl >= 0 && num[x.i] == 0) return;     while (jdx < sz) {       if (lvl == -1) {         node temp = node(com[jdx], jdx);         jdx++;         solve(temp, lvl + 1);       } else {         while (num[x.i] > 0) {           num[x.i]--;           node temp = node(com[jdx], jdx);           jdx++;           solve(temp, lvl + 1);         }         if (!num[x.i]) return;       }     }   }   int main() {     int i, j, k;     int n, m;     string s, t;     cin >> s;     t =   ;     n = s.length();     for (i = 0; i < n; i++) {       if (s[i] ==  , ) {         if (isdigit(t[0]))           num.push_back(toNum(t));         else           com.push_back(t);         t =   ;       } else {         t += s[i];       }     }     num.push_back(toNum(t));     jdx = 0;     sz = com.size();     node r = node( root , -1);     solve(r, -1);     k = 0;     for (i = 0; i < 1000010; i++) {       if (adj[i].size() > 0)         k++;       else         break;     }     printf( %d n , k);     for (i = 0; i < k; i++) {       m = adj[i].size();       for (j = 0; j < m; j++) cout << adj[i][j] <<    ;       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     cin >> n;     cin >> m;     cin >> k;     bool done = false;     int num = 0;     int lanes = 0;     int desks = 0;     int d = 0;     while (num < k) {       desks = 0;       done = false;       num += 2 * m;       lanes++;       while (done == false) {         if (d >= num || d >= k) {           done = true;           break;         }         d += 2;         desks++;       }     }     cout << lanes <<     << desks <<    ;     if (k % 2 == 0) {       cout <<  R  << endl;     } else       cout <<  L  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 0x3f3f3f3f;   const long long MAXN = 3e5 + 5;   long long n, MOD, k, ans;   map<long long, long long> mp;   signed main() {     scanf( %lld%lld%lld , &n, &MOD, &k);     for (long long i = 1; i <= n; i++) {       long long x;       scanf( %lld , &x);       x = (x * x % MOD * x % MOD * x % MOD + MOD - x * k % MOD) % MOD;       mp[x]++;     }     for (map<long long, long long>::iterator it = mp.begin(); it != mp.end();          it++) {       long long x = it->second;       ans += (x - 1) * x / 2;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long binpow(long long a, long long b) {     a = a % 1000000007;     long long res = 1;     while (b > 0) {       if (b & 1) res *= a % 1000000007;       a = a * a % 1000000007;       b = b >> 1;     }     return res;   }   void speedup() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   int dx[] = {1, -1, 2, 2, -2, -2, 1, -1};   int dy[] = {2, 2, 1, -1, 1, -1, -2, -2};   int bfs(int sx, int sy, int desx, int desy) {     int vis[9][9];     int d[9][9];     for (int i = 1; i <= 8; i++) {       for (int j = 1; j <= 8; j++) {         vis[i][j] = 0;         d[i][j] = 0;       }     }     vis[sx][sy] = 1;     queue<pair<int, int> > q;     q.push(pair<int, int>(sx, sy));     while (!q.empty()) {       pair<int, int> top = q.front();       q.pop();       for (int i = 0; i < 8; i++) {         int tx = top.first + dx[i];         int ty = top.second + dy[i];         if (tx >= 1 && tx <= 8 && ty >= 1 && ty <= 8 && vis[tx][ty] == 0) {           vis[tx][ty] = 1;           d[tx][ty] = d[top.first][top.second] + 1;           q.push(pair<int, int>(tx, ty));         }       }     }     return d[desx][desy];   }   int main() {     speedup();     int n;     cin >> n;     int a[n], l[n], r[n];     for (int i = 0; i < n; i++) cin >> l[i];     for (int i = 0; i < n; i++) cin >> r[i];     for (int i = 0; i < n; i++) a[i] = n - l[i] - r[i];     for (int i = 0; i < n; i++) {       for (int j = 0; j < i; j++) {         l[i] -= (a[j] > a[i]);       }     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         r[i] -= (a[j] > a[i]);       }     }     for (int i = 0; i < n; i++) {       if (l[i] != 0 || r[i] != 0) {         cout <<  NO n ;         return 0;       }     }     cout <<  YES n ;     for (int i = 0; i < n; i++) cout << a[i] <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int a, b, c, r, x, y, z, i, j, k, count = 0, result;       cin >> a >> b >> c >> r;       x = c - r;       y = c + r;       r = (a >= b) ? a : b;       z = (a <= b) ? a : b;       a = z;       b = r;       if (x < a && y <= b && y >= a)         count = y - a;       else if (x >= a && y <= b)         count = y - x;       else if (x < b && x >= a && y > b)         count = b - x;       else if (x < a && y > b)         count = b - a;       else         count = 0;       result = b - a - count;       cout << result <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   using namespace std;   const string tp[4] = { aaaa ,  aabb ,  abab ,  abba };   int n, k;   int m;   string w[10000];   int prime(int x) {     if (x == 1) return 0;     for (int i = 2; i * i <= x; i++)       if (x % i == 0) return 0;     return 1;   }   int check(int x, int y) {     if (x > n || x < 1 || y >= m || y < 0) return 0;     return 1;   }   long long gcd(long long a, long long b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   int vowel(char t) {     if (t ==  a  || t ==  e  || t ==  i  || t ==  o  || t ==  u ) return 1;     return 0;   }   int main() {     cin >> n >> k;     int bad = 0;     for (int i = 0; i < n * 4; i++) {       string s;       cin >> s;       w[i] =   ;       int l = 0;       while (l < k and s.size()) {         char c = s[s.size() - 1];         w[i] += c;         s.erase(s.size() - 1);         l += vowel(c);       }       if (l < k) {         bad = 1;       }     }     if (!bad) {       for (int t = 0; t < 4; t++) {         int ok2 = 1;         for (int i = 0; i < n * 4; i += 4) {           int ok = 1;           for (int p = 0; p < 4 and ok; p++) {             for (int q = p + 1; q < 4 and ok; q++) {               if (tp[t][p] == tp[t][q] and w[i + p] != w[i + q]) {                 ok = 0;               }             }           }           if (!ok) {             ok2 = 0;             break;           }         }         if (ok2) {           cout << tp[t];           return 0;         }       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 5;   int n, k, l, sm[MAXN];   char s[MAXN];   pair<long long, long long> dp[MAXN];   long long solve(char a) {     for (int i = 1; i <= n; i++) sm[i] = sm[i - 1] + (s[i] == a);     int lo = 0, hi = l;     long long ans = 0;     while (lo <= hi) {       int mi = (lo + hi) / 2;       for (int i = 1; i <= l; i++) dp[i] = max(dp[i - 1], {sm[i] - mi, -1});       for (int i = l + 1; i <= n; i++)         dp[i] = max(dp[i - 1], {dp[i - l].first + sm[i] - sm[i - l] - mi,                                 dp[i - l].second - 1});       if (-dp[n].second <= k)         hi = mi - 1, ans = dp[n].first;       else         lo = mi + 1;     }     return sm[n] - k * lo - ans;   }   int main() {     scanf( %d %d %d , &n, &k, &l);     scanf( %s , s + 1);     if ((long long)k * (long long)l >= n) return !printf( 0 n );     for (int i = 1; i <= n; i++) s[i] =  a  <= s[i] ?  a  :  b ;     printf( %I64d n , min(solve( a ), solve( b )));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 9;   int main() {     long long n, m;     cin >> n >> m;     vector<int> row(n), col(n);     int r = 0, c = 0;     int x, y;     long long ans = n * n;     for (int i = 0; i < m; i++) {       scanf( %d %d , &x, &y);       long long v = 0;       if (row[x - 1] == 0 && col[y - 1] == 0)         v = n + n - (1 + r + c);       else if (row[x - 1] && col[y - 1])         v = 0;       else if (row[x - 1])         v = n - r;       else if (col[y - 1])         v = n - c;       ans -= v;       if (row[x - 1] == 0) row[x - 1] = 1, r++;       if (col[y - 1] == 0) col[y - 1] = 1, c++;       printf( %lld  , ans);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long tecpoint = 0;     vector<long long> mas(n);     for (int i = 0; i < n; i++) {       long long a;       cin >> mas[i];     }     vector<long long> questions(m);     vector<bool> visited(n);     for (int i = 0; i < m; i++) {       int a;       cin >> a;       a--;       questions[i] = mas[a];       visited[a] = 1;     }     for (int i = 0; i < n; i++) {       if (!visited[i]) tecpoint += mas[i];     }     vector<bool> take(m);     for (int i = 0; i < m; i++) {       long long tecma = 0;       long long tecmai = 0;       for (int j = 0; j < m; j++) {         if (take[j]) continue;         if (max(questions[j], tecpoint) > tecma) {           tecma = max(questions[j], tecpoint);           tecmai = j;         }       }       tecpoint += tecma;       take[tecmai] = 1;     }     cout << tecpoint <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     int n, m, i;     scanf( %d , &n);     m = 1;     for (i = 1; i < n; i++) {       m = (m + i);       if (m > n) m -= n;       printf( %d , m);       if (i < n)         printf(   );       else         printf(  n );     }     return EXIT_SUCCESS;   }


#include <bits/stdc++.h>   using namespace std;   long long x, y, c;   int n;   const int maxn = 300009;   char str[maxn];   long long cnt = 0;   int main() {     cin >> n >> x >> y;     cin >> str;     int now = 0;     for (int i = 0; i < n; ++i) {       if (str[i] ==  1 ) {         if (now != 0) cnt++;         now = 0;       } else {         now++;       }     }     if (now) cnt++;     if (!cnt) return 0 * puts( 0 );     if (y <= x)       cout << cnt * y << endl;     else {       cout << (cnt - 1) * x + y << endl;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, bags[100000], i;     scanf( %d , &n);     for (i = 0; i < (n * n); i++) bags[i] = (i + 1);     for (i = 0; i < ((n * n) / 2); i += 2) {       printf( %d  , bags[i]);       printf( %d  , bags[(n * n) - i - 1]);     }     printf(  n );     for (i = 1; i <= (((n * n) / 2)); i += 2) {       printf( %d  , bags[i]);       printf( %d  , bags[(n * n) - i - 1]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int n;   vector<int> g[MAXN];   int d[MAXN];   int bio[MAXN];   void dfs(int x, int dep) {     d[x] = dep;     bio[x] = 1;     for (int i : g[x])       if (!bio[i]) dfs(i, dep + 1);   }   int main() {     scanf( %d , &n);     int a, b;     for (int i = 0; i < n - 1; i++) {       scanf( %d%d , &a, &b);       a--;       b--;       g[a].push_back(b);       g[b].push_back(a);     }     dfs(0, 1);     double rj = 0;     for (int i = 0; i < n; i++) {       rj += 1.0 / d[i];     }     printf( %lf n , rj);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char c = getchar();     long long x = 0;     bool f = 0;     for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     if (f) x = -x;     return x;   }   const long long maxn = 2007, maxm = 4007, inf = 0x3f3f3f3f3f3f3f3f;   long long n, m, s, t, maxflow;   long long dep[maxn], cur[maxn], de[maxn];   long long tot = 1, head[maxn];   struct edge {     long long to, nxt, w;   } e[maxm << 1];   inline void adde(long long u, long long v, long long w) {     e[++tot] = (edge){v, head[u], w};     head[u] = tot;   }   inline void add(long long u, long long v, long long w) {     adde(u, v, w);     adde(v, u, 0);   }   inline void ins(long long u, long long v, long long l, long long r) {     add(u, v, r - l), de[u] -= l, de[v] += l;   }   bool bfs(long long s, long long t) {     queue<long long> q;     memcpy(cur, head, sizeof cur);     memset(dep, 63, sizeof dep);     dep[s] = 0;     q.push(s);     while (!q.empty()) {       long long u = q.front();       q.pop();       for (long long i = head[u]; i; i = e[i].nxt) {         long long v = e[i].to;         if (dep[v] == inf && e[i].w) {           dep[v] = dep[u] + 1;           q.push(v);         }       }     }     return dep[t] < inf;   }   long long dfs(long long u, long long t, long long minn) {     if (!minn || u == t) return minn;     long long res = 0;     for (long long i = cur[u]; i; i = e[i].nxt) {       long long v = e[i].to;       cur[u] = i;       if (dep[v] != dep[u] + 1) continue;       long long flow = dfs(v, t, min(minn, e[i].w));       if (!flow) continue;       res += flow, minn -= flow;       e[i].w -= flow, e[i ^ 1].w += flow;       if (!minn) break;     }     if (!res) dep[u] = 0;     return res;   }   inline long long dinic(long long s, long long t) {     long long maxflow = 0;     while (bfs(s, t)) maxflow += dfs(s, t, inf);     return maxflow;   }   long long a[maxn], b[maxn], c[maxn], d[maxn], uu[maxn], vv[maxn],       lim = 100000000;   map<long long, long long> mp;   long long func(long long v) {     if (mp.count(v)) return mp[v];     for (register long long i = (1); i <= (n + 2); ++i) head[i] = de[i] = 0;     s = n + 1, t = n + 2;     tot = 1;     for (register long long i = (1); i <= (m); ++i) {       long long l = a[i] * v + b[i] * lim, r = c[i] * v + d[i] * lim;       ins(uu[i], vv[i], l, r);     }     long long res = 0;     for (register long long i = (1); i <= (n); ++i)       if (de[i] > 0)         add(s, i, de[i]), res += de[i];       else         add(i, t, -de[i]);     return mp[v] = res - dinic(s, t);   }   signed main() {     n = read(), m = read();     for (register long long i = (1); i <= (m); ++i) {       uu[i] = read(), vv[i] = read();       a[i] = read(), b[i] = read(), c[i] = read(), d[i] = read();     }     func(75000004);     long long l = 0, r = lim;     while (r - l >= 5) {       long long m1 = l + (r - l) / 3, m2 = r - (r - l) / 3;       if (func(m1) < func(m2))         r = m2;       else         l = m1;     }     pair<long long, long long> mg = make_pair(inf, inf);     for (register long long i = (l); i <= (r); ++i)       mg = min(mg, make_pair(func(i), i));     if (mg.first) {       puts( 0 );       return 0;     }     l = mg.second + 1, r = lim;     long long resl = mg.second, resr = mg.second;     while (l <= r) {       long long mid = l + r >> 1;       if (!func(mid))         resr = mid, l = mid + 1;       else         r = mid - 1;     }     l = 0, r = mg.second - 1;     while (l <= r) {       long long mid = l + r >> 1;       if (!func(mid))         resl = mid, r = mid - 1;       else         l = mid + 1;     }     printf( %.8lf , 1.0 * (resr - resl) / lim);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200009;   const int MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);     int n, k, tot;     cin >> n >> k;     tot = n;     vector<int> sta, vis(n + 2);     vis[n + 1] = 1;     int cur = 1;     vector<int> ans;     for (int i = 0; i < k; ++i) {       int t;       cin >> t;       ans.push_back(t);       sta.push_back(t);       vis[t] = 1;       tot--;       while (((int)(sta).size()) && sta.back() == cur) {         cur++;         sta.pop_back();       }     }     for (int i = 1; i < ((int)(sta).size()); ++i) {       if (sta[i] > sta[i - 1]) {         cout <<  -1 n ;         return 0;       }     }     while (tot) {       while (((int)(sta).size()) && sta.back() == cur) {         cur++;         sta.pop_back();       }       int top;       if (((int)(sta).size()) == 0)         top = n + 1;       else         top = sta.back();       for (int i = top; i >= cur; --i) {         if (!vis[i]) sta.push_back(i), tot--, ans.push_back(i);         vis[i] = 1;       }     }     for (int i : ans) cout << i <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long arr[200005], lazy[4 * 200005], seg[4 * 200005];   void build(int node, int start, int end) {     int mid = (start + end) / 2;     if (start == end) {       lazy[node] = 0;       seg[node] = arr[start];       return;     }     build(2 * node, start, mid);     build(2 * node + 1, mid + 1, end);     seg[node] = min(seg[2 * node], seg[2 * node + 1]);   }   void update(int node, int start, int end, int left, int right, long long val) {     int mid = (start + end) / 2;     if ((start > right) || (end < left)) return;     if ((left <= start) && (end <= right)) {       lazy[node] += val;       seg[node] += val;       return;     } else {       update(2 * node, start, mid, left, right, val);       update(2 * node + 1, mid + 1, end, left, right, val);       seg[node] = min(seg[2 * node], seg[2 * node + 1]) + lazy[node];     }   }   long long query(int node, int start, int end, int left, int right) {     int mid = (start + end) / 2;     if ((start > right) || (end < left)) return LLONG_MAX;     if ((left <= start) && (end <= right))       return seg[node];     else       return lazy[node] + min(query(2 * node, start, mid, left, right),                               query(2 * node + 1, mid + 1, end, left, right));   }   int main() {     int n, m, lf, rg;     long long v;     char c;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lld , &arr[i]);     build(1, 0, n - 1);     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d%d , &lf, &rg);       c = getchar();       if (c !=   n ) {         scanf( %lld , &v);         if (lf <= rg)           update(1, 0, n - 1, lf, rg, v);         else {           update(1, 0, n - 1, lf, n - 1, v);           update(1, 0, n - 1, 0, rg, v);         }       } else {         if (lf <= rg)           printf( %lld n , query(1, 0, n - 1, lf, rg));         else           printf( %lld n ,                  min(query(1, 0, n - 1, lf, n - 1), query(1, 0, n - 1, 0, rg)));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int a, b, c, x, y, z;     cin >> a >> b >> c >> x >> y >> z;     int cnt = 0;     if (a > x) cnt += (a - x) / 2;     if (b > y) cnt += (b - y) / 2;     if (c > z) cnt += (c - z) / 2;     if (a < x)       if (x - a <= cnt) {         cnt -= x - a;         a += x - a;       }     if (b < y)       if (y - b <= cnt) {         cnt -= y - b;         b += y - b;       }     if (c < z)       if (z - c <= cnt) {         cnt -= z - c;         c += z - c;       }     if (a >= x && b >= y && c >= z)       cout <<  Yes  << endl;     else       cout <<  No  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int n, to[N << 1], nxt[N << 1], head[N], cnt;   int len[N], son[N], tmp[N], *f[N], *id = tmp, ans[N];   void link(int u, int v) {     to[++cnt] = v;     nxt[cnt] = head[u];     head[u] = cnt;     to[++cnt] = u;     nxt[cnt] = head[v];     head[v] = cnt;   }   void dfs(int u, int ff) {     for (int e = head[u]; e; e = nxt[e])       if (to[e] != ff) {         dfs(to[e], u);         if (len[to[e]] > len[son[u]]) son[u] = to[e];       }     len[u] = len[son[u]] + 1;   }   void dp(int u, int ff) {     f[u][0] = 1;     if (son[u]) f[son[u]] = f[u] + 1, dp(son[u], u), ans[u] = ans[son[u]] + 1;     for (int e = head[u]; e; e = nxt[e]) {       int v = to[e];       if (v == ff || v == son[u]) continue;       f[v] = id;       id += len[v];       dp(v, u);       for (int j = 1; j <= len[v]; ++j) {         f[u][j] += f[v][j - 1];         if ((j < ans[u] && f[u][j] >= f[u][ans[u]]) ||             (j > ans[u] && f[u][j] > f[u][ans[u]]))           ans[u] = j;       }     }     if (f[u][ans[u]] == 1) ans[u] = 0;   }   int main() {     cin >> n;     for (int i = 1; i < n; ++i) {       int u, v;       scanf( %d%d , &u, &v);       link(u, v);     }     dfs(1, 0);     f[1] = id;     id += len[1];     dp(1, 0);     for (int i = 1; i <= n; ++i) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int n, long long int k) {     long long int ans = 1;     long long int mod = 1000000007;     while (k) {       if (k & 1) ans = (ans * n) % mod, k--;       n = (n * n) % mod, k >>= 2;     }     return ans;   }   long long int mod(long long int n, long long int k) {     long long int ans = n % k;     if (n < 0) ans += k;     return ans;   }   string cins() {     char ss[1000000];     fgets(ss, 1000000, stdin);     string s;     for (int i = 0; i < strlen(ss); i++) s += ss[i];     return s;   }   void solve();   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int tt;     cin >> tt;     for (int T = 1; T < tt + 1; T++) solve();     return 0;   }   void solve() {     int n;     cin >> n;     int ans = 0;     for (int i = 1; i < n + 1; i++) {       int x;       cin >> x;       if (x > i + ans) ans += x - (i + ans);     }     {       cout << ans <<   n ;       return;     };     ;   }