#include <bits/stdc++.h>
using namespace std;

struct node{
	long long val = 0;
	node *lc = nullptr, *rc = nullptr;
	node() {}
	node(long long val): val(val) {}
	node(node *lc, node *rc): lc(lc), rc(rc) {
		val += lc->val;
		val += rc->val;
	}
};

typedef node * pnode;

const int maxn = 3e5+4;
int n, a[2*maxn];
pnode roots[2*maxn];
long long ans[maxn];
long long cur_inv = 0;

pnode build(int l, int r){
	if (l == r) return new node();
	int mid = (l+r)/2;
	return new node(build(l,mid),build(mid+1,r));
}

pnode update(pnode p, int l, int r, int pos, int val){
	if (l == r) return new node(p->val + val);
	int mid = (l+r)/2;
	if (pos <= mid) return new node(update(p->lc,l,mid,pos,val),p->rc);
	else return new node(p->lc,update(p->rc,mid+1,r,pos,val));
}

long long query(pnode p, int l, int r, int lb, int rb){
	if (r < lb || l > rb) return 0;
	if (l >= lb && r <= rb) return p->val;
	int mid = (l+r)/2;
	return query(p->lc,l,mid,lb,rb) + query(p->rc,mid+1,r,lb,rb);
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n;
	for (int i=0; i<n; i++){
		cin >> a[i];
		a[i+n] = a[i];
	}
	roots[0] = build(0,n-1);
	for (int i=0; i<2*n; i++){
		cur_inv += query(roots[i],0,n-1,a[i]+1,n-1);
		if (i >= n) cur_inv -= query(roots[i],0,n-1,0,a[i-n]-1);
		if (i >= n-1) ans[i-n+1] = cur_inv;
		roots[i+1] = update(roots[i],0,n-1,a[i],1);
		if (i >= n-1) roots[i+1] = update(roots[i+1],0,n-1,a[i-n+1],-1);
	}
	for (int i=0; i<n; i++) cout << ans[i] << "\n";
}

// 0 1 2 3 0 1 2 3

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll read() {
	ll x=0, f=1; char ch=' ';
	while(!isdigit(ch)) {ch=getchar(); if(ch=='-') f=-1;}
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48), ch=getchar();
	return x*f;
}
int n, a[300005];
ll c[500005], ans;
void jia(int i,ll x){
	while(i<=n){
		c[i]+=x;
		i+=(i&-i);
	}
}
ll he(int i){
	ll s=0;
	while(i){
		s+=c[i];
		i-=(i&-i);
	}
	return s;
}
int main() {
	cin>>n;
	for(int i=1;i<=n;i++) a[i]=read()+1;
	for(int i=1;i<=n;i++){
		jia(a[i],1);
		ans+=he(n)-he(a[i]);
	}
	cout<<ans<<endl;
	for(int i=1;i<n;i++) {
		ans=ans-(a[i]-1)+(n-a[i]);
		cout<<ans<<endl;
	}
}


#include<cstdio>//JZM YYDS!!!
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define ll long long
#define MAXN 200005
#define uns unsigned
#define MOD 998244353ll
#define INF 0x7f7f7f7f
using namespace std;
inline ll read(){
	ll x=0;bool f=1;char s=getchar();
	while((s<'0'||s>'9')&&s>0){if(s=='-')f^=1;s=getchar();}
	while(s>='0'&&s<='9')x=(x<<1)+(x<<3)+s-'0',s=getchar();
	return f?x:-x;
}
ll x,y,p,q;
inline ll exgcd(ll a,ll b,ll&x,ll&y){
	if(b==0){x=1,y=0;return a;}
	ll res=exgcd(b,a%b,y,x);
	y-=a/b*x;return res;
}
signed main()
{
	for(int T=read();T--;){
		x=read(),y=read(),p=read(),q=read();
		ll md=(x+y)<<1,lim=md*(p+q)+1,ans=lim;
		ll b=p,a=p+q,K,f,g=exgcd(p+q,md,K,f);
		for(ll i=x;i<x+y;i++){
			ll c=((i-b)%md+md)%md,k=K;
			if(c%g!=0)continue;
			c/=g,k=(k*c%md+md)%(md/g);
			if((k*a+b)%md>=x&&(k*a+b)%md<x+y)ans=min(ans,k*a+b);
		}
		md=p+q,b=x,a=(x+y)<<1,g=exgcd((x+y)<<1,md,K,f);
		for(ll i=p;i<p+q;i++){
			ll c=((i-b)%md+md)%md,k=K;
			if(c%g!=0)continue;
			c/=g,k=(k*c%md+md)%(md/g);
			if((k*a+b)%md>=p&&(k*a+b)%md<p+q)ans=min(ans,k*a+b);
		}
		if(ans>=lim)printf("infinity\n");
		else printf("%lld\n",ans);
	}
	return 0;
}

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF (long long)1 << 61
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<int> IV;
typedef vector<llong> LV;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main() {
	long long n; cin >> n;
    vector<long long> ans = divisor(n);
    for(auto &x:ans){
        cout << x << endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define MP make_pair
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(int &a, int b) { if (a > b) a = b; }
void chmax(int &a, int b) { if (a < b) a = b; }

int main(){
	int N, M;
	cin >> N >> M;
	vector<int> value(N);
	FOR(i,0,N){
		cin >> value.at(i);
	}
	vector<vector<int>> data(N);
	FOR(i,0,M){
		int x, y;
		cin >> x >> y;
		--x;
		--y;
		data.at(y).push_back(x);
	}

	int ans = -2e9;

	FOR(i,0,N){
		if(data.at(i).size()==0){
			continue;
		}
		int nowvalue = value.at(i);
		FOR(j,0,data.at(i).size()){
			int now = data.at(i).at(j);
			chmin(value.at(i), value.at(now));
			ans = max(ans, nowvalue - value.at(now));
		}
	}

	cout << ans << endl;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int n, m;
vector<long long> a;

int solve();

int main() {
  cin >> n >> m;
  a.resize(m);
  for (int i = 0; i < m; ++i) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

int solve() {
  long long res = 0, len = 3e9;
  a.push_back(0);
  a.push_back(n + 1);
  sort(a.begin(), a.end());
  n = a.size();
  for (int i = 1; i < n; ++i)
    if (a[i] - a[i - 1] - 1) len = min(len, a[i] - a[i - 1] - 1);
  if (len == 3e9) return 0;
  for (int i = 1; i < n; ++i) res += (a[i] - a[i - 1] - 1 + len - 1) / len;
  return res;
}


#include <bits/stdc++.h>
using namespace std;

/***********************************MACROS***********************************/

#define ll long long

#define pll pair<ll,ll>
#define vll vector<ll>
#define vii vector<int>
#define mll map<ll, ll>

#define all(v) v.begin(), v.end()

#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'

#define CASE(t) ll t; cin>>t; while(t--)

#define forr(i, b) for(ll i=0;i<b;i++)

/***********************************FUNCTIONS***********************************/

void FAST() {	//FAST Input Output, DONT use both scnaf,printf / cin,cout , Use any ONE system
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

/***********************************CODE***********************************/

int f(int n){
	vector<int> d;
	while(n!=0){
		d.push_back(n%10);
		n=n/10;
	}
	sort(d.begin(),d.end());

	int x=0,y=0;
	int k=d.size();
	for(int i=0;i<k;++i){
		x=x*10;
		x+=d[i];
		y=y*10;
		y+=d[k-1-i];
	}

	return y-x;
}

int main() {
	FAST();
    // CASE(t)
	{
		int n,k;
		cin>>n>>k;

		for(int i=0;i<k;i++){
			if(f(n)==n){
				break;
			}
			else{
				n=f(n);
			}
		}

		cout<<n;

	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

int n,k,tot;
priority_queue<int, vector<int>, greater<int> > g2;
priority_queue<int ,vector<int>,less<int> >g1;

int G1(int x)
{
	int num=0,NUM=1;
	int X;
	while(x/10!=0)
	{
		X=x%10;
		g1.push(X);
		x=x/10;
		if(x<10&&x>0) g1.push(x);
	}
	while(!g1.empty())
	{
		num+=g1.top()*NUM;
		NUM=NUM*10;
		g1.pop();
	}
	return num;
}
int G2(int x)
{
	int num=0,NUM=1;
	int X;
	while(x/10!=0)
	{
		X=x%10;
		g2.push(X);
		x=x/10;
		if(x<10&&x>0) g2.push(x);
	}
	while(!g2.empty())
	{
		num+=g2.top()*NUM;
		g2.pop();
		NUM=NUM*10;
	}
	return num;
}
int f(int x)
{
	int X,Y;
	X=G2(x),Y=G1(x);
	int num;
	num=X-Y;
	return num;
}
int main()
{
	cin>>n>>k;
	while(k!=0)
	{
		n=f(n);
		k--;
	}
	cout<<n;
	return 0;
}


#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;

#define fo(i,z,n) for(int i = z;i<n;i++)
#define rfo(i,z,n) for(int i = z;i >= n;i--)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vc vector<char>
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define vpi vector<pair<int,int> >
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvpi vector<vector<pair<int,int> > >
#define vvc vector<vector<char> >
#define vvl vector<vector<ll> >
#define pb push_back
#define f first
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

void __print(int x) {cerr << x;}
// void __print(long x) {cerr << x;}
// void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
// void __print(float x) {cerr << x;}
// void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

ll power(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}

int ceil(int a,int b){
    if(a%b == 0)return a/b;
    else return a/b+1;
}

int madd(int a,int b){
    int res = (((a + mod)%mod + (b+mod)%mod)%mod + mod)%mod;
    return res;
}

int pow(int a,int b){
    if(b == 0)return 1;
    int res = pow(a,b/2);
    res = res*res;
    if(b&1)res *= a;
    return res;
}

vi par(200005,-1);
vi siz(200005,1);

int find(int u){
    if(par[u] == u)return u;
    return par[u] = find(par[u]);
}

void solve(){

    int n;
    cin >> n;
    vi v(n);
    fo(i,0,n)cin >> v[i];

    fo(i,0,n)par[v[i]] = v[i];

    fo(i,0,n/2){
        // if(v[i] == v[n-i-1])continue;
        int fp1 = find(v[i]);
        int fp2 = find(v[n-i-1]);
        // debug(fp1,fp2,i);
        if(fp1 != fp2){
            par[fp2] = fp1;
            siz[fp1] += siz[fp2];
        }
    }

    int connectedcom = 0;
    int ans = 0;
    fo(i,0,200005)
        if(par[i] == i){
            // debug(par[i],i,siz[i]);
            connectedcom++;
            if(siz[i] == 1)ans += siz[i];
            else
            ans += siz[i];
        }
    // cout << connectedcom << endl;
    ans -= connectedcom;

    cout << ans << endl;

}

int32_t main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);

    // memset(vis,-1,sizeof(vis));
    int t = 1;
    // cin >> t;
     while(t--){
        solve();
     }

return 0;

    }

#include <bits/stdc++.h>
using namespace std;
const int N = 10000;
int n;
bool mem[N][N];
class ad {
   public:
    int a, b, c, d, r, id;
    ad() {}
    void read() {
        scanf("%d%d%d", &a, &b, &r);
        mem[a][b] = true;
        c = a + 1, d = b + 1;
    }
    void print() { printf("%d %d %d %d\n", a, b, c, d); }
    int size;
    void cal_size() { size = (c - a) * (d - b); }
    double grad0, grad1;
    void cal_grad() {
        double p1 = 1.0 * size, p2 = size + d - b, p3 = size + c - a;
        p1 = min(p1 / r, r / p1), p2 = min(p2 / r, r / p2),
        p3 = min(p3 / r, r / p3);
        p1 = p1 * (2 - p1), p2 = p2 * (2 - p2), p3 = p3 * (2 - p3);
        grad0 = p2 - p1, grad1 = p3 - p1;
    }
    void init() {
        cal_size();
        cal_grad();
    }
    bool extend0() {
        if (a) {
            bool f = true;
            for (int j = b; j < d; ++j) {
                if (mem[a - 1][j]) {
                    f = false;
                    break;
                }
            }
            if (f) {
                for (int j = b; j < d; ++j) mem[a - 1][j] = true;
                --a;
                init();
                return true;
            }
        }
        if (c < 9999) {
            bool f = true;
            for (int j = b; j < d; ++j) {
                if (mem[c][j]) {
                    f = false;
                    break;
                }
            }
            if (f) {
                for (int j = b; j < d; ++j) mem[c][j] = true;
                ++c;
                init();
                return true;
            }
        }
        return false;
    }
    bool extend1() {
        if (b) {
            bool f = true;
            for (int i = a; i < c; ++i) {
                if (mem[i][b - 1]) {
                    f = false;
                    break;
                }
            }
            if (f) {
                for (int i = a; i < c; ++i) mem[i][b - 1] = true;
                --b;
                init();
                return true;
            }
        }
        if (d < 9999) {
            bool f = true;
            for (int i = a; i < c; ++i) {
                if (mem[i][d]) {
                    f = false;
                    break;
                }
            }
            if (f) {
                for (int i = a; i < c; ++i) mem[i][d] = true;
                ++d;
                init();
                return true;
            }
        }
        return false;
    }
    bool operator<(const ad &rhs) const {
        return grad0 + grad1 < rhs.grad0 + rhs.grad1;
    }
};
priority_queue<ad> q;
ad ans[200];
int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        ad t;
        t.read();
        t.id = i;
        t.init();
        q.push(t);
    }
    while (!q.empty()) {
        ad now = q.top();
        q.pop();
        bool f = false;
        if (now.grad0 >= now.grad1 && now.grad0 > 0) {
            f = true;
            if (!now.extend0()) now.grad0 = 0;
        }
        if (now.grad1 > now.grad0 && now.grad1 > 0) {
            f = true;
            if (!now.extend1()) now.grad1 = 0;
        }
        if (f)
            q.push(now);
        else
            ans[now.id] = now;
    }
    for (int i = 0; i < n; ++i) ans[i].print();
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<(a)<<endl
#define dumparr(a,n) cerr<<#a<<"["<<(n)<<"]="<<(a[n])<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

int main(){
  cout<<setprecision(1000);
  ll N,M;
  cin>>N>>M;
  vector<ll> dp(1LL<<N);
  vector<vector<pll>> cond(N);
  REP(M){
    ll x,y,z;
    cin>>x>>y>>z;
    --x;--y;
    cond[x].push_back(pll(y,z));
  }
  auto f=[](ll num,ll y,ll z){
    ll mask=(1LL<<(y+1))-1;
    num&=mask;
    return __builtin_popcountll(num)<=z;
  };
  dp[0]=1;
  For(j,(1LL<<N)){
    ll n=__builtin_popcountll(j);
    if(n==N)continue;
    ll cur=1;
    REP(N){
      if((cur&j)==0){
        ll jj=(j|cur);
        ([&]() {
          FOR(cidx, n, N)
          {
            for (auto &&[y, z] : cond[cidx])
            {
              if (!f(jj, y, z))
              {
                return;
              }
            }
          }
          dp[jj]+=dp[j];
        })();
      }
      cur<<=1;
    }
  }
  dump(dp);
  cout<<dp[(1LL<<N)-1]<<endl;
  return 0;
}

#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <complex>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <queue>

#define	INF   1010101010LL
#define INFLL 1010101010101010101LL

using namespace std;

int mod = 1000000007;

class Segtree {
public:
	Segtree(int n) //サイズ
	{
		int t = 1;
		while (t < n) {
			t *= 2;
		}
		a = vector<long long>(2 * t - 1);
		this->n = t;
	}

	int sum(int l, int r)
	{
		return query(l, r, 0, n - 1, 0);
	}

	void update(int p, long long num)
	{
		p += this->n - 1;
		a[p] ^= num;
		while (p > 0) {
			p = (p - 1) / 2;
			a[p] = a[2 * p + 1] ^ a[2 * p + 2];
		}
	}

private:
	int query(int l, int r, int p, int q, int k)
	{
		if (l <= p && q <= r) return a[k];
		else if (q < l || r < p) return 0;

		return query(l, r, p, (p + q) / 2, 2 * k + 1) ^ query(l, r, (p + q) / 2 + 1, q, 2 * k + 2);
	}

private:
	vector<long long> a;
	int n;
};

int main()
{
	int n, q;
	cin >> n >> q;
	Segtree seg(n);
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		seg.update(i, t);
	}
	for (int i = 0; i < q; i++) {
		int t, x, y;
		cin >> t >> x >> y;
		if (t == 1) {
			seg.update(x - 1, y);
		} else {
			cout << seg.sum(x - 1, y - 1) << endl;
		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T f=0,x=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
namespace run{
	int n,m;
	int main(){
		n=read<int>(),m=read<int>();
		if(n==1){
			if(m!=0) puts("-1"),exit(0);
			puts("1 2"),exit(0);
		}
		if(m<0 || m>=n-1) puts("-1"),exit(0);

		int lim=1e6;
		printf("%d %d\n",1,lim);
		for(int i=1,k=2;i<=m+1;i++)
			printf("%d %d\n",k,k+1),k+=2;
		lim++;
		for(int i=m+2;i<n;i++) printf("%d %d\n",lim,lim+1),lim+=2;
		return 0;
	}
}
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

/*
 * Author       : YangDavid
 * Created Time : 2020.10.24 20:11:31
 */

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int B = 10000000;
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	if(n == 1) {
		if(m == 0) {
			printf("1 2\n");
			return 0;
		} else {
			puts("-1");
			return 0;
		}
	}
	if(abs(m) >= n-1) { puts("-1"); return 0; }
	if(m >= 0) {
		printf("%d %d\n", 1, 2*m+3);
		rep(i, m+1)
			printf("%d %d\n", 2*i, 2*i+1+(i==m+1));
	} else {
        puts("-1");
        return 0;
		/*m = -m;
		printf("%d %d\n",2,2*m+4);
		rep(i, m+1)
			printf("%d %d\n", 2*i-(i==1), 2*i+1);
	*/}
	rep(i, n-m-2)
		printf("%d %d\n", B+4*i, B+4*i+1);

    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back
#define ll long long
#define fr first
#define sc second
#define rep(i,n) for (i = 0; i < n; ++i)
#define REP(i,k,n) for (i = k; i <= n; ++i)
#define REPR(i,k,n) for (i = k; i >= n; --i)
using namespace std;
// taskkill /im new.exe /t /f
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
   //freopen("error.txt", "w", stderr);
  freopen("output.txt", "w", stdout);
#endif

 ll T = 1 ;
 //cin>>T;
for(ll t=0;t<T;t++)
{
  ll ans = 0;
  ll n , m;
  cin>>n>>m;
  string s[n];
  for(ll i = 0;i<n;i++)
  {
    cin>>s[i];
  }
  // for rows
  for(ll i = 0;i<n;i++)
  {
    ll c = 0;
    for(ll j = 0;j<m;j++)
    {
     // cout<<c<<" ";
      if(s[i][j]=='.')
      {
        c++;
      } else {
        if(c) ans = ans + c - 1;
        c = 0;
      }
    }
    if(c) ans = ans + c  - 1;
  }
  //cout<<endl;
  // columns
  for(ll i = 0;i<m;i++)
  {
    ll c = 0;
    for(ll j = 0;j<n;j++)
    {
      //cout<<c<<" ";
      if(s[j][i]=='.')
      {
        c++;
      } else {
        if(c) ans = ans + c - 1;
        c = 0;
      }
    }
    if(c) ans = ans + c  - 1;
  }
  cout<<ans<<endl;
}

  return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define forin(in ,n) for(ll i=0; i<n; i++) cin>>in[i]
#define forout(out) for(ll i=0; i<(ll)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, n) for (ll i = a; i < n; ++i)
#define rep_down(i, a, n) for (ll i = a; i >= n; --i)
#define P pair<ll, ll>

#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

constexpr ll INF = (1ll << 60);
//constexpr ll mod = 1000000007;
//constexpr ll mod = 998244353;

constexpr ll mod = 3;

constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
void pt(T val) {
    cout << val << "\n";
}
template <typename T>
void pt_vll(vector<T> &v) {
    ll vs = v.size();
    rep(i, vs) {
        cout << v[i];

        if (i == vs - 1)
            cout << "\n";
        else
            cout << " ";
    }
}
ll mypow(ll a, ll n) {
    ll ret = 1;
    if(n==0) return 1;
    if(a==0) return 0;
    rep(i, n) {
        if (ret > (ll)(1e18 + 10) / a) return -1;
        ret *= a;
    }
    return ret;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

const int MAX = 510000;
long long th[MAX], tw[MAX];
// テーブルを作る前処理
void COMinit() {
    th[1]=0; tw[1]=0;
    for (ll i = 2; i < MAX; i++){
        if(i%3==2) tw[i]=1;
        if(i%3==0){
            ll x=i;
            while(x%3==0){
                th[i]++;
                x/=3;
            }
            if(x%3==2) tw[i]=1;
        }
        tw[i]+=tw[i-1];
        th[i]+=th[i-1];
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if(th[n]>th[k]+th[n-k]) return 0;
    if((tw[n]-tw[k]-tw[n-k])%2==0) return 1;
    return 2;
}

int main() {
    ll n,m,k,sum=0,ans=0;
    string s;
    cin>>n>>s;
    COMinit();
    vll a(n);
    rep(i,n){
        if(s[i]=='W') a[i]=0;
        if(s[i]=='B') a[i]=1;
        if(s[i]=='R') a[i]=2;
        a[i]*=COM(n-1,i);
    }
    rep(i,n){
        sum+=a[i];
        sum%=mod;
    }
    if(n%2==0) sum=(3-sum)%3;
    if(sum%3==0) cout<<"W"<<endl;
    if(sum%3==1) cout<<"B"<<endl;
    if(sum%3==2) cout<<"R"<<endl;
}


#include<iostream>
#include<vector>
#include<math.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    cin>>b[i];
  }
  int result=100000000;
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<n;j++)
    {
      result=min(result, i==j ?(a[i]+b[j]):max(a[i],b[j]));
    }
  }
  cout<<result;
   return 0;
 }


#include<bits/stdc++.h>
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define pii pair<int,int>
#define fi first
#define se second
#define PB push_back
#define ll long long
#define ull unsigned long long
#define y1 orzkcz
using namespace std;

const int mo=1000000007;
int power(int x,int y){
	int s=1;
	for (;y;y/=2,x=1ll*x*x%mo)
		if (y&1) s=1ll*s*x%mo;
	return s;
}
int main(){
	int S=0,n,m,x;
	scanf("%d%d",&n,&m);
	For(i,1,n) scanf("%d",&x),m++,S+=x+1;
	int s1=1,s2=1;
	For(i,1,S){
		s1=1ll*s1*i%mo;
		s2=1ll*s2*(m+1-i)%mo;
	}
	cout<<1ll*s2*power(s1,mo-2)%mo<<endl;
}

//#include <atcoder/all>
#include <bits/stdc++.h>

using namespace std;

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9+7; //998244353;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}
//using mint = atcoder::modint1000000007;

struct Segtree{
	typedef ll sgT;
	vector<sgT> seg;
	int nbn; sgT INF;
	void init(int n){
		for(nbn=1; nbn<n+2; nbn<<=1); INF=1LL<<61; // min:+inf,max:-inf,0
		seg.assign(nbn*2, INF);
	}
	sgT comp(sgT l, sgT r){return min(l, r);}  //min<->max
	void update(int k,sgT x){
		k+=nbn-1; seg[k]=x;
		while(k>0){ k=(k-1)/2; seg[k]=comp(seg[k*2+1],seg[k*2+2]); }
	}
	sgT query2(int a,int b,int l,int r,int k){
		if(b<=l||r<=a) return INF;
		if(a<=l&&r<=b) return seg[k];
		return comp(query2(a,b,l,(l+r)/2,k*2+1), query2(a,b,(l+r)/2,r,k*2+2));
	}
	sgT query(int a,int b){ return query2(a,b,0,nbn,0); }
	sgT get(int a){return seg[nbn+a-1];}  // =query(a,a+1)

	int posLeft(sgT v, int l, int r ){//v以上の右端rで最左位置を求める
		int lo=l-1, hi=r;
		while(hi - lo >1){
			int md = (hi + lo) >> 1;
			if( query(md, r+1) == v ) hi = md; else lo = md;
		}
		return hi;
	}
	int posRight(sgT v, int l, int r ){ //v以上の左端lで最右位置を求める
		int lo=l-1, hi=r;
		while(hi - lo >1){
			int md = (hi + lo) >> 1;
			if( query(l, md+1) == v ) lo = md; else hi = md;
		}
		return lo;
	}
};

int main(){
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n);
	rep(i, n) cin >>a[i];
	map<int, int> mp;
	rep(i, n) mp[a[i]] = i;
	Segtree sg; sg.init(n);
	rep(i, n) sg.update(i, a[i]);
	ll ans =0;

	rep(i, n){
		ll cr = a[i];
		int ps1 = sg.posLeft(cr, 0, i);
		int ps2 = sg.posRight(cr, i, n);

		ans = max(ans, cr * (ps2+1-ps1));
	}
	cout <<ans <<"\n";
	return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define F(i,n) for (int i = 0; i < n; ++i)
#define F1(i,n) for (int i = 1; i <= n; ++i)
#define dbg(x) cerr << #x << " = " << x << endl
#define dbgg(x) cerr << #x << " = " << x << ' '
#define T(x) x[pool]
#define mineq(x,y) { if ((x) > (y)) (x) = (y); }
#define maxeq(x,y) { if ((x) < (y)) (x) = (y); }
#define MEOW cout << "meowwwww" << '\n'; system("pause");
#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;

template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c)
{
	s << "[ "; for (auto it : c) s << it << " "; s << "\b]\n";
	return s;
}

template<typename T>
ostream& operator <<(ostream &s, const pair<int, T> &c)
{
	s << "[ "; cout << c.fi << " , " << c.se << " ] ";
	return s;
}

const int maxn = 123456, mod = 1000000007;
int n;
int a[maxn], fib[maxn];

void input()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	F1 (i, n) cin >> a[i];
}

void solve()
{
	int fu = 1;
	int ans = 0;
	fib[0] = fib[1] = 1;
	for (int i = 2; i <= n; ++i)
		fib[i] = (fib[i - 1] + fib[i - 2]) % mod;
	ans = a[1] * fib[n] % mod;
	for (int i = 2; i <= n; ++i)
	{
		int neg = fib[i - 2] * fib[n - i] % mod;
		int coef = (fib[n] - neg - neg + mod + mod) % mod;
		ans = (ans + a[i] * coef % mod) % mod;
	}
	cout << ans << '\n';
}
main()
{
	input();
	solve();
}


#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int MOD2 = 998'244'353;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}

template<class T, class S> inline bool exist(std::set<T> &s, const S &e){
    return (s.find(e) != s.end());
}

template<unsigned long long m> class comb_perm{
private:
    int n;
    std::vector<long long> fact, fact_inv;
public:
    comb_perm(): n(0), fact(1), fact_inv(1){
        fact[0] = fact_inv[0] = 1;
    }
    comb_perm(int N): n(N), fact(N+1), fact_inv(N+1){
        fact[0] = fact[1] = fact_inv[0] = fact_inv[1] = 1;
        for(int i{2}; i <= n; ++i) fact[i] = fact[i - 1] * i % m;
        for(int i{2}; i <= n; ++i) fact_inv[i] = inv(fact[i]);
    }

    bool resize(int N){
        if(N <= n) return false;
        fact.resize(N+1);
        fact_inv.resize(N+1);
        if(!n && N){
            fact[1] = fact_inv[1] = 1;
        }
        for(int i{std::max(2, n+1)}; i <= N; ++i) fact[i] = fact[i - 1] * i % m;
        for(int i{std::max(2, n+1)}; i <= N; ++i) fact_inv[i] = inv(fact[i]);
        n = N;
        return true;
    }

    long long power(long long a, unsigned long long b){
        long long ret{1};
        while(b){
            if(b & 1) ret = (ret * a) % m;
            a = (a * a) % m;
            b /= 2;
            if(ret < 0) ret += m;
            if(a < 0) a += m;
        }
        return ret;
    }

    long long inv(long long a){ // GCD(a, m) = 1
        return power(a, m - 2);
    }

    long long permutation(int n, int r){
        if(n < r) return 0;
        if(n < 0 || r < 0) return 0;
        if(this->n < n) resize(n);
        long long ret(fact[n]);
        ret = ret * fact_inv[n - r] % m;
        return ret;
    }

    long long combination(int n, int r){
        if(n < r) return 0;
        if(n < 0 || r < 0) return 0;
        long long ret{permutation(n, r)};
        return ret * fact_inv[r] % m;
    }

    long long multi_combination(int n, int r){
        return combination(n + r - 1, r);
    }

    long long factorial(int a){
        return fact[a];
    }

    long long inv_factorial(int a){
        return fact_inv[a];
    }

};

int main(){
    int N, M, K; std::cin >> N >> M >> K;
    long long ans{};
    if(N <= M + K){
        comb_perm<MOD> cp;
        ans += cp.combination(N+M, N);
        (ans -= cp.combination(N+M, M+K+1)) %= MOD;
        if(ans < 0) ans += MOD;
    }
    std::cout << ans << std::endl;
    return 0;
}

#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")

using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define CHOOSE3(a) CHOOSE4 a
#define CHOOSE4(a0, a1, a2, x, ...) x
#define mes_1(a) cout << (a) << endl
#define mes_2(a, b) cout << (a) << " " << (b) << endl
#define mes_3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define mes(...)                                   \
    CHOOSE3((__VA_ARGS__, mes_3, mes_2, mes_1, ~)) \
    (__VA_ARGS__)
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)

#define ynmes(a) (a) ? mes("Yes") : mes("No")
#define YNmes(a) (a) ? mes("YES") : mes("NO")
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

ll gcd(ll a, ll b)
{
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

ll nlcm(vector<ll> numbers)
{
    ll res;
    res = numbers[0];
    for (ll i = 1; i < (ll)numbers.size(); i++)
    {
        res = lcm(res, numbers[i]);
    }
    return res;
}

uintmax_t ncr(unsigned int n, unsigned int r)
{
    if (r * 2 > n)
        r = n - r;
    uintmax_t dividend = 1;
    uintmax_t divisor = 1;
    for (unsigned int i = 1; i <= r; ++i)
    {
        dividend *= (n - i + 1);
        divisor *= i;
    }
    return dividend / divisor;
}

signed main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    ynmes(a * a + b * b < c * c);
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
#define neinf 0xc0c0c0c0c0c0c0c0ll
#define inf 0x3f3f3f3f3f3f3f3fll
#define uint unsigned int
#define ull unsigned ll
#define ll long long
#define reg register
#define db double
#define il inline
#define gc getchar
#define pc putchar
#define HgS 1000000007
#define to(i) ((ed+(i))->_to)
#define nxt(i) ((ed+(i))->_nxt)
#define pr pair<ll,ll>
#define prpr make_pair
il ll rd()
{
	reg ll res=0,lab=1;
	reg char ch=gc();
	while((ch<'0'||ch>'9')&&ch!=EOF)
	{if(ch=='-')lab=-lab;ch=gc();}
	while(ch>='0'&&ch<='9')
		res=(res<<3)+(res<<1)+(ch&15),ch=gc();
	return res*lab;
}
il void prt(ll x,char t='\n')
{
	reg char ch[70];reg int tp=0;
	if(x<0)pc('-'),x=-x;
	while(x)ch[++tp]=(x%10)^48,x/=10;
	if(!tp)ch[++tp]=48;
	while(tp)pc(ch[tp--]);
	if(t)pc(t);
}
il ll uabs(ll x){return x>0?x:-x;}
il ll umax(ll x,ll y){return x>y?x:y;}
il ll umin(ll x,ll y){return x<y?x:y;}
ll n,k,ru,rv,h[200005],d[200005],fa[200005],en,res,ans;
bool vis[200005];
struct edge{ll _to,_nxt;}ed[400005];
il ll add_edge(ll u,ll v){nxt(++en)=h[u];to(en)=v;return h[u]=en;}
pr dfs(int cur,ll x)
{
	vis[cur]=1;
	ll mxf=neinf,mnf=inf;pr tmp;
	for(int i=h[cur];i;i=nxt(i))
	{
		if(!vis[to(i)])
			tmp=dfs(to(i),x),
			mxf=umax(mxf,tmp.first+1),mnf=umin(mnf,tmp.second+1);
	}
	if(mnf>x)mxf=umax(mxf,0);
	if(mxf+mnf<=x)mxf=neinf;
	if(mxf==x){mxf=neinf;mnf=0;++res;}
	return prpr(mxf,mnf);
}
il bool chk(ll r)
{
	res=0;memset(vis,0,sizeof(vis));
	return res+(dfs(1,r).first>=0)<=k;
}
int main()
{
	ans=n=rd();k=rd();
	for(int i=1;i<n;++i)ru=rd(),rv=rd(),add_edge(ru,rv),add_edge(rv,ru);
	reg ll l=0,r=n,mid;
	while(l<=r)
	{
		mid=(l+r)>>1;
		if(chk(mid))ans=mid,r=mid-1;
		else l=mid+1;
	}
	prt(ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
#define println(x) cout << x << endl
#define print(x) cout << x << " "
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const int MOD = 1e9+7;
int main(){
    int a, b;
    cin >> a >> b;
    REPR(i, b + 1){
        if(b / i > ceil(a / (double)i)){
            println(i);
            return 0;
        }
    }
    return 0;
}


#include <algorithm>
#include <bits/stdc++.h>
#include <stdio.h>
#include <string.h>
using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define re_rep(i, n) for (int i = (n); i >= 1;)
#define wrep(a) while ((int)a > 0)
#define re_wrep(a, N) while ((int)a < N)
#define scanfd(N) scanf("%d", &N);
#define scanfc(a) scanf("%s", a);
#define scanfca(a) scanf("%s", a);
#define scanfd2(a, b) scanf("%d %d", &a, &b);
#define scanfca2(a, b) scanf("%s%s", a, b);
#define scanfcad(a, b) scanf("%s%d", a, &b);
#define scanfc3(a, b, c) scanf("%s%s%s", &a, &b, &c);
#define scanfc3a(a, b, c) scanf("%s%s%s", a, b, c);
#define scanfdcd(a, b, c) scanf("%d %c %d", &a, &b, &c);
#define scanfsd_if(c, d) scanf("%s %d", &c, &d);
#define scanfcd_switch(c, d) scanf(" %c %d", &c, &d);
#define printfd(a) printf("%d", a);
#define printfca(a) printf("%s", a);
#define printfc3(a, b, c) printf("%c%c%c", a, b, c);

struct MyPair {
    string S;
    int T;
};

bool t_cmp(const struct MyPair &p, const struct MyPair &q) { return p.T < q.T; }

int main() {
    int N, T;
    string S, a;

    cin >> N;
    vector<MyPair> p(N);

    rep(i, N) {
        cin >> S >> T;
        p.at(i).S = S;
        p.at(i).T = T;
    }
    sort(p.begin(), p.end(), t_cmp);

    // rep(i, N) { cout << p.at(i).S << endl; }
    cout << p.at(N - 2).S << endl;
    return 0;
}

#ifdef LOGX
#define _GLIBCXX_DEBUG
#endif
#include <bits/extc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;

/*---------macro---------*/
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define mybit(i,j) (((i)>>(j))&1)

/*---------type/const---------*/
typedef long long ll;
typedef unsigned long long ull;
typedef std::string::const_iterator state; //構文解析
const int big=1000000007;
//const int big=998244353;
const double EPS=1e-8; //適宜変える
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char newl='\n';
struct{
    constexpr operator int(){return -int(1e9)-10;}
    constexpr operator ll(){return -ll(1e18)-10;}
}neginf;
struct{
    constexpr operator int(){return int(1e9)+10;}
    constexpr operator ll(){return ll(1e18)+10;}
    constexpr auto operator -(){return neginf;}
}inf;

/*---------debug---------*/
#ifdef LOGX
#include <template/debug.hpp>
#else
#define dbg(...) ;
#define dbgnewl ;
#define prt(x) ;
#define _prt(x) ;
#endif

/*---------function---------*/
template<typename T> T max(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;}
template<typename T> T min(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;}
template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;}
template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;}
bool valid(int i,int j,int h,int w){return (i>=0 && j>=0 && i<h && j<w);}
template<class T,class U>T expm(T x,U y,const ll mod=big){T res=1;while(y){if(y&1)(res*=x)%=mod;(x*=x)%=mod;y>>=1;}return res;}
template<class T,class U>T exp(T x,U y){T res=1;while(y){if(y&1)res*=x;x*=x;y>>=1;}return res;}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.precision(10);
/*------------------------------------*/

    int n;cin >> n;
    vector<pair<ll,ll>> xc(n);
    vector<ll> x(n),c(n);
    rep(i,n){
        cin >> xc[i].first >> xc[i].second;
    }
    sort(ALL(xc));
    rep(i,n){
        x[i]=xc[i].first;
        c[i]=xc[i].second, c[i]--;
    }
    vector<vector<int>> col(n);
    rep(i,n){
        col[c[i]].emplace_back(i);
    }
    dbg(x);
    dbg(c);
    ll x_l=0;
    ll x_r=0;
    ll val_l=0;
    ll val_r=0;
    rep(i,n){
        if(col[i].size()){
            ll ne_l=x[col[i].front()];
            ll ne_r=x[col[i].back()];
            ll nval_l=inf;
            ll nval_r=inf;
            chmin(nval_l, val_l+abs(x_l-ne_r)+abs(ne_r-ne_l));
            chmin(nval_l, val_r+abs(x_r-ne_r)+abs(ne_r-ne_l));

            chmin(nval_r, val_l+abs(x_l-ne_l)+abs(ne_r-ne_l));
            chmin(nval_r, val_r+abs(x_r-ne_l)+abs(ne_r-ne_l));

            x_l=ne_l;
            x_r=ne_r;
            val_l=nval_l;
            val_r=nval_r;
            dbg(x_l, val_l);
            dbg(x_r,val_r);
            dbgnewl;
        }
    }
    cout << min(val_l+abs(x_l), val_r+abs(x_r)) << newl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int

ll maxx(ll a, ll b){
    if(a>b){
        return a;
    }
    else{
        return b;
    }
}
ll minn(ll a, ll b){
    if(a<b){
        return a;
    }
    else{
        return b;
    }
}

int main()
{
    ll n;
    cin>>n;

    ll N = pow(2, n);
    vector<pair<ll,ll>>v(N);
    ll i;

    for(i=0; i<N; i++){
        ll x;
        cin>>x;

        v[i].first = x;
        v[i].second = i+1;

        // cout<<v[i].first<<" "<<v[i].second<<endl;
    }

    ll cnt =0;
    ll res;

    while(1){

        if(v.size() == 2){
            if(v[0].first > v[1].first){
                res = v[1].second;
            }
            else{
                res = v[0].second;
            }
            break;
        }

        vector<pair<ll,ll>>vec;
        for(i=1; i<v.size(); i=i+2){

            if(v[i].first > v[i-1].first){
                vec.push_back(v[i]);
            }
            else{
                vec.push_back(v[i-1]);
            }
        }

        // for(i=0; i<vec.size(); i++){
        //     cout<<vec[i].first<<" "<<vec[i].second<<endl;
        // }
        // cout<<endl;

        v.clear();
        v = vec;

    }

    cout<<res;

    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(numeros) (ll) __builtin_popcountll(numeros)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " es " << (x) <<"\n"
#define test ll deftestcases;cin>>deftestcases;while(deftestcases--)
#define PI acos(-1)
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;
typedef vector<ll>  vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
template<class T> using ordered_set =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
const ll inf = 2e18;
const ll mod = 1e9+7;
const ll MAX = 6e2+15;

int main(){
    fastio;
    map<string,ll> mp;ll n;
    cin>>n;
    f(i,0,n){
        ll x;string s;
        cin>>s>>x;
        mp[s]=x;
    }
    ll maxi = 0;
    for(auto it : mp){
        if(maxi<it.sc){
            maxi = it.sc;
        }
    }
    string ans;ll aux  =0;
    for(auto it : mp){
        if(it.sc == maxi) continue;
        if(aux<it.sc){
            aux = it.sc;
            ans = it.fs;
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
// auto mod int
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod; return *this;}
  mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod; return *this;}
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct E{
  vector<mint> v;
  E(int n):v(n){}
};
const mint i2 = mint(1)/2;
int main() {
  int n,m,k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  vector<vector<E>> x(1,vector<E>(n,E(n)));
  auto& x0 = x[0];
  rep(i,n) x0[i].v[i] = m;
  rep(i,m){
    int u,v;
    cin >> u >> v;
    --u,--v;
    x0[u].v[u] -= i2;
    x0[u].v[v] += i2;
    x0[v].v[u] += i2;
    x0[v].v[v] -= i2;
  }
  for(int p=1;k>>p;++p){
    x.emplace_back(n,E(n));
    auto &u = x[p-1], &v = x[p];
    rep(k,n){
      auto& e = u[k].v;
      rep(i,n)rep(j,n){
        v[k].v[j] += e[i]*u[i].v[j];
      }
    }
  }
  mint im = mint(1)/m;
  im = im.pow(k);
  rep(u,n){
    vector<mint> s(n);
    s[u] = 1;
    for(int p=0;k>>p;++p)if(k>>p&1){
      auto& xi = x[p];
      vector<mint> t(n);
      rep(i,n)rep(j,n){
        t[j] += s[i]*xi[i].v[j];
      }
      swap(s,t);
    }
    mint ans;
    rep(i,n) ans += s[i]*a[i];
    ans *= im;
    printf("%lld\n",ans.x);
  }
}

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const long double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

typedef int SegT;
const SegT defvalue=0;
class SegTree{
	private:
		vector<SegT>val;
		int n;
		SegT combine(SegT a,SegT b){return a^b;}
	public:
		SegTree(int size){
			n=1;
			while(n<size)n<<=1;
			val=vector<SegT>(2*n,defvalue);
		}
		SegTree(const vector<SegT> &in){
			n=1;
			while(n<in.size())n<<=1;
			val=vector<SegT>(2*n,defvalue);
			for(int i=n-1+in.size()-1;i>=0;i--){
				if(n-1<=i)val[i]=in[i-(n-1)];
				else val[i]=combine(val[i*2+1],val[i*2+2]);
			}
		}
		void update(int i,SegT a){
			i+=n-1;
			val[i]^=a;
			while(i>0){
				i=(i-1)/2;
				val[i]=combine(val[i*2+1],val[i*2+2]);
			}
		}
		SegT query(int a,int b,int k=0,int l=0,int r=-1){//[a,b)
			if(r==-1)r=n;
			if(r<=a||b<=l)return defvalue;
			if(a<=l&&r<=b)return val[k];
			else return combine(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
		}
		void tmp(){
			rep(i,val.size())cout<<" "<<val[i];cout<<endl;
		}
};

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n,q;
	cin>>n>>q;
	SegTree st(n);
	rep(i,n){
		int a;cin>>a;
		st.update(i,a);
	}
	while(q--){
		int t,x,y;
		cin>>t>>x>>y;
		if(t==1){
			st.update(x-1,y);
		}else{
			cout<<st.query(x-1,y)<<endl;
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int a[200010],b[200010],c[200010] = {};
	int n,q;
	cin >> n;
	for(int i = 0;i < n;i++){
		int x,t;
		cin >> x >> t;
		a[i] = -INF;
		b[i] = INF;
		if(t == 1) c[i] = x;
		else if(t == 2) a[i] = x;
		else b[i] = x;

		if(i){
			if(b[i - 1] < a[i] - c[i - 1]) a[i] = b[i] = a[i] - c[i - 1];
			else if(b[i] - c[i - 1] < a[i - 1]) a[i] = b[i] = b[i] - c[i - 1];
			else{
				a[i] = max(a[i] - c[i - 1],a[i - 1]);
				b[i] = min(b[i] - c[i - 1],b[i - 1]);
			}
			c[i] += c[i - 1];
		}
	}
	cin >> q;
	for(int i = 0;i < q;i++){
		int x;
		cin >> x;
		if(x <= a[n - 1]) x = a[n - 1];
		if(x >= b[n - 1]) x = b[n - 1];
		cout << x + c[n - 1] << endl;
	}
}

#include <bits/stdc++.h>

using namespace std;

typedef long long lli;

const int N = 200000 + 10;
const int Q = 200000 + 10;

struct Item{
	lli val;
	int id;
};

lli ans[Q];
int a[N], t[N];
Item x[Q];

bool cmp(const Item& u, const Item& v){
	return u.val < v.val;
}

int main(){
	lli add, v;
	int n, q, left, right;
	cin>>n;
	for (int i=1; i<=n; i++) cin>>a[i]>>t[i];
	cin>>q;
	for (int i=1; i<=q; i++){
		cin>>x[i].val;
		x[i].id = i;
	}
	sort(x + 1, x + q + 1, cmp);
	left = 1, right = q;
	add = 0;
	for (int i=1; i<=n; i++)
		if (t[i] == 1) add += a[i];
		else if (t[i] == 2){
			v = a[i] - add;
			if (x[left].val > v) continue;
			while (left <= right && x[left].val <= v) left ++;
			left --;
			x[left].val = v;
		}
		else{
			v = a[i] - add;
			if (x[right].val < v) continue;
			while (right >= left && x[right].val >= v) right --;
			right ++;
			x[right].val = v;
		}
	for (int i=left; i>=1; i--) x[i].val = x[left].val;
	for (int i=right; i<=q; i++) x[i].val = x[right].val;
	for (int i=1; i<=q; i++) ans[x[i].id] = x[i].val + add;
	for (int i=1; i<=q; i++) cout<<ans[i]<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define all(v) v.begin(), v.end()

int main(void){
    int n; string s1, s2 = "";
    cin >> n >> s1;
    if (n < 3){cout << n << endl; return 0;}

    s2 = s1.substr(n - 2, 2);
    s1 = s1.substr(0, n - 2);
    reverse(all(s2));

    auto size = [&]()->int{return s1.length() + s2.length();};

    auto dfs = [&](auto dfs, int i1, int i2)->void{
        int n1 = s1.length(), n2 = s2.length();
        if (n1 < i1 || n2 < i2) return;
        string ss1 = s1.substr(n1 - i1, i1), ss2 = s2.substr(n2 - i2, i2);
        reverse(all(ss2));
        if (ss1 + ss2 == "fox"){
            for (int i = 0; i < i1; ++i) s1.pop_back();
            for (int i = 0; i < i2; ++i) s2.pop_back();
            dfs(dfs, 1, 2);
            dfs(dfs, 2, 1);
        }
    };

    while (!s1.empty()){
        dfs(dfs, 1, 2);
        dfs(dfs, 2, 1);
        if (!s1.empty()) s2.push_back(s1.back()), s1.pop_back();
    }

    cout << size() << endl;
    return 0;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define fill(arr,c) memset(arr,c,sizeof(arr))
#define perm(r) next_permutation(all(r))
//it gives bool value ans permute the string lexoggraphically
#define sortdesc greater<int>()
#define ll long long int
//std::setfill('0') << std::setw(5) << 25; it adds leaing zeroes;
#define f(i,a) for(int i=0;i<a;i++)
#define fo(i,a) for(int i=1;i<=a;i++)
#define foo(i,x,n,c) for(ll i=x;i<n;i+=c)
#define foi(i,x,n,c) for(ll i=x;i>=n;i+=c)
#define fauto(i,m) for(auto i:m)
#define forall(a) for( auto itr=a.begin();itr!=a.end();itr++)
#define ld long double
#define in push_back
#define mll map<ll,ll>
#define mcl map<char,ll>
#define msl map<string,ll>
#define vi vector<int >
#define vl vector<ll >
#define vp vector< pair<int,int> >
#define vs vector <string>
#define vc vector <char>
#define o(a) cout<<a
#define os(a) cout<<a<<" "
#define en cout<<"\n";
#define testcase ll t ;cin>>t; while(t--)
#define ff first
#define ss second
#define pl pair<ll,ll>
#define pi pair<int,int>
#define all(a) (a).begin(), (a).end()

#define sz(a)  (a).size()
#define prec(n) fixed<<setprecision(n)
#define mp make_pair
#define bitcount  __builtin_popcountll
#define imin o("imin");en;
using namespace std;
bool comp(const pair<int,int> &a , const pair<int,int> &b){
    if(a.first == b.first)  return a.second < b.second;
     return a.first < b.first;
}
bool comps(const pair<int,int> &a , const pair<int,int> &b){
    if(a.second == b.second)  return a.first< b.first;
     return a.second < b.second;
}
//ll pi=acos(0.0)*2;
void fastio()
{
    	ios::sync_with_stdio(0);
cin.tie(0);

}
void inout()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);

     freopen("output.txt", "w", stdout);
     #endif
}
ll ans=0;
ll chk(ll i,ll gap,ll n,string s)
{
	string f;
	if(gap==0)
	{
	if(s[i]=='f' && s[i+1]=='o' && s[i+2]=='x')
	{
		ans+=3;
	//	os(i);os(0);en;
			ll x=chk(i,gap+3,n,s);

	}
//	os(f);
}
	else
	{
		if(i-1>=0 && i+2<n)
		{

	if(s[i-1]=='f' && s[i+gap]=='o' && s[i+1+gap]=='x')
	{
			ans+=3;
		//		os(i);os(1);en;
		ll x=chk(i-1,gap+3,n,s);
	}

//	os(f);

}
else 	if(i-2>=0 && i+1<n)
		{

	if(s[i-2]=='f' && s[i-1]=='o' && s[i+gap]=='x')
{
//	os(i);os(2);en;
			ans+=3;
		ll x=chk(i-2,gap+3,n,s);
	}

//os(f);

}
	return 0;
	}

//	os(f);en;
	return 0;
}

int main()
{
fastio();
ll n;
cin>>n;
string s;
cin>>s;
stack<char> bag;
ll ans=0;
char a,b,c;
f(i,n)
{
	bag.push(s[i]);
	if(sz(bag)>=3)
	{
		a=bag.top();
		bag.pop();
		b=bag.top();
		bag.pop();
		c=bag.top();
		bag.pop();
		if(a=='x' && b=='o' && c=='f')
		ans++;
		else
		{
			bag.push(c);bag.push(b);bag.push(a);
		}
	}

}
o(n-3*ans);
en;

return 0;
}


#include <bits/stdc++.h>
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define REPS(i, ss, nn ) for(int i = ss ; i < (int) nn; i++)
#define REV(i, ss, nn ) for(int i = ss ; i >= nn; i--)
#define deb(x) std::cout << #x << " " << x << endl;
#define debl(x) std::cout << #x << " " << x << " ";
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
namespace std{
    template<class Fun>
    class y_combinator_result{
        Fun fun_;
        public:
            template<class T>
            explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)){}
            template<class ...Args>
            decltype(auto) operator()(Args&&...args){
                return fun_(std::ref(*this), std::forward<Args>(args)...);
            }
    };
    template<class Fun>
    decltype(auto) y_combinator(Fun && fun){
        return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
    }
};
template<typename T>
bool u_max(T& a, T b){
    if( a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
bool u_min(T& a, T b){
    if( a > b){
        a = b;
        return true;
    }
    return false;
}
// struct edge{
//     int to, from;
//     ll cost;
//     edge(){ edge(0,0);}
//     edge(int to_, ll cost_){ edge(0, -1, 0);}
//     edge(int to_, int from_, ll cost_) : to(to_), from(from_), cost(cost_){}
// };

template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}

void solve(){
    ll x, y;
    read(x, y);
    ll ans = abs(y - x);
    ll base = 2 * x;
    int n_pow = 1;

    auto count_bit = [&](ll d, int bit_num){
        ll ret = 0;
        int count = 0;
        for(int i = 0 ; i < bit_num; i++){
            // deb(d) deb(last)
            if( d % 2 == 1){
                count++;
            }else{
                if(count >= 2){
                    ret++;
                    d += 1;
                    count = 1;
                }else{
                    ret += count;
                    count = 0;
                }
            }
            d /= 2;
        }
        // debl(ret) debl(count) deb(d)
        if(count <= 2){
            return ret + count + d;
        }else{
            //count -> 2
            // d -> d -1
            return ret + d + 2;
        }
    };
    // 11100010 ==> 1000010 - 10000

    while(abs(base - y) < 4 * abs(x - y) ){
        ll diff = abs(y - base);
        // debl(base) deb(diff)
        ll op_num = count_bit(diff, n_pow);
        // deb(op_num)
        u_min(ans, n_pow + op_num);
        base *= 2;
        n_pow++;
    }
    cout << ans << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  //f
  long long x, y;
  cin >> x >> y;
  map<long long, long long> memo;
  auto rec = [&] (auto&& self, long long cur) -> long long {
    if (memo.count(cur)) return memo[cur];
    if (cur <= x) return x - cur;
    if (cur % 2 == 0) {
      return memo[cur] = min(cur - x, self(self, cur / 2) + 1);
    } else {
      return memo[cur] = min({cur - x, self(self, (cur + 1) / 2) + 2, self(self, (cur - 1) / 2) + 2});
    }
  };
  cout << rec(rec, y) << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 1000005
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

///**
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
  return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if ( it != v.begin() ) os << ", ";
    os << *it;
  }
  return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if ( it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if ( it != v.begin() ) os << ", ";
    os << it -> first << " = " << it -> second ;
  }
  return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () { cerr << endl; }

template <typename T>
void faltu( T a[], int n ) {
  for (int i = 0; i < n; ++i) cerr << a[i] << ' ';
  cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) { cerr << arg << ' '; faltu(rest...); }
// Program showing a policy-based data structure.
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
// GNU link : https://goo.gl/WVDL6g
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;

// find_by_order(k) – ফাংশনটি kth ordered element এর একটা পয়েন্টার রিটার্ন করে। অর্থাৎ তুমি চাইলেই kth ইন্ডেক্সে কি আছে, সেটা জেনে ফেলতে পারছো!
// order_of_key(x) – ফাংশনটি x এলিমেন্টটা কোন পজিশনে আছে সেটা বলে দেয়।

//*//**___________________________________________________**/

int main()
{
  FASTIO
  /*
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
//*/
  int T;
  //scanf("%d", &T);
  T = 1;
  for (int cs = 1; cs <= T; cs++) {
    int n, k, m;
    cin >> n >> k >> m;
    int sm = 0;
    for (int i = 1; i < n; i++) {
      int x;
      cin >> x;
      sm += x;
    }
    for (int i = 0; i <= k; i++) {
      int x = sm + i;
      if (x / n >= m) {
        cout << i << endl;
        return 0;
      }
    }
    cout << -1 << endl;
    return 0;
  }
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
#define lowbit(x) (x & -x)
const ll INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const double EPS=1e-7;
ll mod=1e9+7;
const ll MOD=998244353;
ll qpow(ll base,ll q){
    ll res=1;
    while(q){
        if(q&1)res=res*base;
        base=base*base;
        q>>=1;
    }
    return res;
}
inline ll read()
{  ll f=1,x=0;char ch=getchar();
   for(;ch>'9'||ch<'0';ch=getchar())if(ch=='-') f=-1;
   for(;ch<='9'&&ch>='0';ch=getchar())x=x*10+ch-'0';
   return x*f;
}
const int N = 500010;
struct node {
    ll to, t, k, ne;
    bool operator < (const node &a) const{
        return t > a.t;
    }
}e[N];
ll d[N], st[N];
ll n, m, s, y;
ll h[N], idx;
void add(ll x, ll y, ll t, ll k){
    e[++idx] = {y, t, k, h[x]};
    h[x] = idx;
}
ll dijkstra(){
    memset(d, 0x3f, sizeof d);
    priority_queue<node> q;
    d[s] = 0;
    q.push({s, 0});
    while (!q.empty()){
        node t = q.top();
        q.pop();
        ll x = t.to;
        if (st[x]) continue;
        st[x] = 1;
        for (int i = h[x]; i != 0; i = e[i].ne){
            ll to = e[i].to, t = e[i].t, k = e[i].k;
            ll temp = (d[x] + k - 1) / k * k;
            if (d[to] > t + temp){
                d[to] = t + temp;
                q.push({to, d[to]});
            }
        }
    }
    return d[y] == LL_INF ? -1 : d[y];
}
void solve(){
    cin >> n >> m >> s >> y;
    for (int i = 1; i <= m; i++){
        ll a, b, k, t;
        scanf("%lld%lld%lld%lld", &a, &b, &t, &k);
        add(a, b, t, k);
        add(b, a, t, k);
    }
    cout << dijkstra();
}
int main(){
    int t = 1;
    while (t--) solve();
    return 0;
}


    /* Great things never come from comfort zones,
    "whatever the mind of a man can conceive and believe,it can achieve." */

    #include <bits/stdc++.h>
    using namespace std;

    void my_dbg() { cout << endl; }
    template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B)
    { cout << ' ' << A; my_dbg(B...); }
    #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

    #define ll long long
    #define dd double
    #define scf(n) scanf("%d",&n)
    #define lscf(n) scanf("%lld",&n)
    #define lpri(n) printf("%lld ",n)
    #define pri(n) printf("%d ",(int)n)
    #define prin(n) printf("%d\n",(int)n)
    #define lprin(n) printf("%lld\n",n)
    #define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
    #define show(a) for(auto xy: a) pri(xy); printf("\n");

    #define pb push_back
    #define mp make_pair
    #define F first
    #define S second
    #define all(x)     x.begin(),x.end()
    #define SET(a,b) memset(a,b,sizeof(a))
    #define tc   int tt; scf(tt); while(tt--)

    #define inf INT_MAX
    #define ninf INT_MIN
    #define gcd __gcd
    #define bitcount(n) __builtin_popcount(n)

    const int mod=1e9+7;
    const int N = 1e6+7;

    int pos[N];

    int main()
    {
        int n; scf(n);

        vector<ll>a(n),b(n);

        vector<int>ind(n);

        iota(all(ind),0);// iterates and fill with increaing values
                        //0 1 2 3 4.......

        ll A=0,B=0,tmp;

        rep(i,0,n)
        lscf(a[i]),lscf(b[i]);

        sort(all(ind),[&](const int &i , const int &j)
        {
            return (2*a[i]+b[i]>2*a[j]+b[j]);
        }); // net effect 2*a[k] + b[k] in town of speech

        A=accumulate(all(a),0ll);

        int c=0,d=0;

        rep(i,0,n)
        {
            if(B>A)
            break;

            c++;

            int j=ind[i];

            B+=b[j]+a[j];

            A-=a[j];
        }

        prin(c);

    }

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define veci vector<int>
#define vecll vector<ll>
#define ii pair<ll, ll>
#define iii pair<ii, ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define up upper_bound

#define rep(x, start, end) for (auto x = (start) - ((start) > (end)); x != (end) - ((end) < (start)); ((start) < (end) ? x++ : x--))
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin.exceptions(ios::badbit | ios::failbit);

    int a, b;
    cin >> a >> b;
    int c = a + b;

    if (c >= 15 && b >= 8)
        cout << 1 << endl;
    else if (c >= 10 && b >= 3)
        cout << 2 << endl;
    else if (c >= 3)
        cout << 3 << endl;
    else
        cout << 4 << endl;

    return 0;
    return 0;
}


#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define replr(i, l, r) for (int i = (l); i < (r); ++i)
const int mod = 1e9 + 7;
int main() {
    int a, b;
    cin >> a >> b;
    if (a == b) {
        cout << a << endl;
    }

    int k = 7;
    a = 1 << a;
    b = 1 << b;

    if ((k ^ a ^ b) == 1) {
        cout << 0 << endl;
    }
    if ((k ^ a ^ b) == 2) {
        cout << 1 << endl;
    }
    if ((k ^ a ^ b) == 4) {
        cout << 2 << endl;
    }

    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <sstream>
#include <stack>
#include <set>
#include <bitset>
#include <deque>
#include <vector>
using namespace std;
int main()
{
	char w[55],s[55];
	scanf("%s",w);
	int j=0;
	while(w[j]=='0') j++;
	for(int i=j;i<strlen(w);i++)
	s[i-j]=w[i];
	//printf("%d %d \n",strlen(w),strlen(s));
	int len=strlen(w)-j;
	if(len==1)
	{
		printf("0");
		return 0;
	}
	if(len&1)
	{
		for(int i=0;i<len/2;i++)
		printf("9");
	}
	else
	{
		int a=0,b=0;
		for(int i=0;i<len/2;i++)
		a=a*10+(int)(s[i]-'0');
		for(int i=len/2;i<len;i++)
		b=b*10+(int)(s[i]-'0');
		if(a<=b) printf("%d",a);
		else printf("%d",a-1);
	}
    //system("pause");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

int main() {
	int n;
	string s;
	cin >> n >> s;

	vector<int> a(n);
	int k = 1e9;
	for(int i = 0; i <= n; i++) {
		cin >> a[i];
		if(i - 1 >= 0)
			k = min(k, abs(a[i] - a[i - 1]));
	}

	cout << k << '\n';
	for(int i = 0; i < k; i++) {
		for(int j = 0; j <= n; j++) {
			cout << (a[j] + i) / k << ' ';
		}
		cout << '\n';
	}

}

#include <bits/stdc++.h>

#define ll long long
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define pii pair<int, int>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;
template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    vi a(n + 1);
    rep(i, 0, n + 1) cin >> a[i];
    int ans = INT_MAX;
    rep(i, 0, n) ans = min(ans, abs(a[i] - a[i + 1]));
    vector<vi> b(n + 1, vi(ans, 0));
    int k = 0;
    rep(i, 0, n + 1) {
        rep(j, 0, ans) b[i][j] = a[i] / ans;
        int dif = a[i] - (a[i] / ans) * ans;
        if(i % 2 == 0) {
            rep(j, 0, dif) {
                b[i][k]++;
                k = (k + 1) % ans;
            }
        }else {
            rep(j, 0, dif) {
                k = (k + ans - 1) % ans;
                b[i][k]++;
            }
        }
    }

    cout << ans << '\n';
    rep(j, 0, ans) {
        rep(i, 0, n + 1) {
            cout << b[i][j] << ' ';
        }
        cout << '\n';
    }
}


#include <bits/stdc++.h>
using namespace std;

int main() {

  int N;
  int W;
  cin >> N >> W;
  int count = 0;
  int weight = 0;
  while (weight <= N-W){
    count++;
    weight += W;
  }

  cout << count << endl;

}

#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (int)(a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
using VD = vector<double>;
using VII = vector<VI>;
using VLL = vector<VL>;
using VDD = vector<VD>;
using P = pair<int, int>;
using PL = pair<ll, ll>;

void solve(long long N, long long W) {
  cout << N / W << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long W;
  scanf("%lld", &W);
  solve(N, W);
  return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1010000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s;
    cin >> s;
    reverse(all(s));
    int N = si(s);

    char a = '#';
    vi A(30,0);
    ll ans = 0;

    rep(i,N){
        if(s[i] == a){
            rep(j,30){
                if(j != int(s[i]-'a')) ans += (ll)A[j];
            }

            A.assign(30,0);
            A[int(s[i]-'a')] = i+1;

        }else{
            A[int(s[i]-'a')]++;
            a = s[i];
        }
    }

    cout << ans << endl;

    return 0;
}

//yukicoder@cpp14
//writer:luckYrat(twitter:@luckYrat_)
//競技プログラミングから逃げるな
//https://www.youtube.com/watch?v=z_B9iJ8r4ic

//せんげん！
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

#include <cctype>
#include <utility>
#include <climits>

//なまえくーかん！
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

//てーすう！
const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);

//でふぁいん！
#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)

//みじかく！
#define pb push_back
#define fir first
#define scn second
#define ednl endl

//いぇすのー！
#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")

//きんぼーnほーこー！！
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
//B
template <int mod>
struct ModInt{
  int n;
  ModInt():n(0){}
  ModInt(int n_):n(n_ >= 0 ? n_%mod : mod - ((-n_)%mod) ){}

  ModInt &operator+=(const ModInt &p){
    if((n+=p.n) >= mod)n-=mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p){
    n+=mod-p.n;
    if(n >= mod)n-=mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p){
    n = (int) ((1LL*n*p.n)%mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p){
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const {return ModInt(-n);}
  ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}
  ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}
  ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}
  ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}

  bool operator==(const ModInt &p) const {return n==p.n;}
	bool operator<(const ModInt &p) const {return n<p.n;}
	bool operator>(const ModInt &p) const {return n>p.n;}
	bool operator>=(const ModInt &p) const {return n>=p.n;}
	bool operator<=(const ModInt &p) const {return n<=p.n;}
  bool operator!=(const ModInt &p) const {return n!=p.n;}

  ModInt inverse() const {
    int a = n,b = mod,u = 1,v = 0;
    while(b){
      int t = a/b;
      a -= t*b; swap(a,b);
      u -= t*v; swap(u,v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t z) const {
    ModInt ret(1),mul(n);
    while(z > 0){
      if(z & 1) ret *= mul;
      mul *= mul;
      z >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p){
    return os << p.n;
  }
  friend istream &operator>>(istream &is, ModInt &a){
    int64_t t;
    is >> t;
    a = ModInt<mod> (t);
    return (is);

  }
};
using mint = ModInt<mod>;
//E
ll alp[26];
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
  string s;cin>>s;
  ll ans = 0;
  alp[s[s.size()-1]-'a']++;
  alp[s[s.size()-2]-'a']++;
  for(ll i = s.size()-3; 0 <= i; i--){
    if(s[i]==s[i+1] && s[i] != s[i+2]){
      ans += (s.size()-(i+2)-(alp[s[i]-'a']-1));
      for(ll j = 0; 26 > j; j++){
        if(s[i]=='a'+j){
          alp[j] = s.size()-i;
        }else{
          alp[j] = 0;
        }
      }
    }else{
       alp[s[i]-'a']++;
    }
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, i, last, cc;
    cin >> n;
    vector<int> p(n);
    vector<int> sw(200001);
    last = 0;
    cc = 0;

    for (i = 0; i < 200001; ++i)
    {
        sw[i] = 0;
    }

    for (i = 0; i < n; ++i)
    {
        cin >> p[i];
        sw[p[i]]=1;
        while (cc == 0)
        {
            if (sw[last] == 0)
                cc++;
            else
                last++;
        }
        cc = 0;
        cout << last << endl;
    }

    return 0;
}

#include <iostream>

#include <algorithm>
#include <list>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>

#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>

#define manx maxn
#define whlie while
#define itn int
#define fro for
#define asn ans
#define scnaf scanf
#define sacnf scanf
#define pritnf printf
#define haed head
#define tmep temp
#define udpate update
#define cosnt const

#define Fastin freopen("/home/rqdmap/Desktop/codes/in", "r", stdin)
#define Fastout freopen("/home/rqdmap/Desktop/codes/main.out", "w", stdout)
#define lowbit(x) ((x) & (-x))
#define clr(a, x) memset((a), x, sizeof (a))
#define TTT int __; scanf("%d", &__); for(int _ = 1; _ <= __; _++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

/*------------------------------------------------------------------------------------*/
template<typename T>
void prt(T *a, int n, bool withid = 0){
    if(!withid) for(int i = 0; i < n; i++) cout << a[i] << ((i == n - 1)? '\n':' ');
    else for(int i = 0; i < n; i++) cout << i << ": " << a[i] << '\n';
}

template<typename T>
T ceil(T a, T b){return (a + b - 1) / b;}
template<typename T>
T gcd(T x, T y){return !x? y: gcd(y % x, x);}
template<typename T>
void exgcd(T a, T b, T &x, T &y){
    if(!b){x = 1; y = 0;return;}
    exgcd(b, a % b, y, x); y -= a / b * x;
}
ll qp(ll a, ll p){
    if(p < 0) return 0;
    ll ans = 1; while(p){if(p & 1) ans = ans * a ; a = a * a; p >>= 1;}
    return ans;
}
ll qp(ll a, ll p, ll M){
    ll ans = 1; while(p){ if(p & 1) ans = ans * a % M; a = a * a % M; p >>= 1;}
    return (ans % M + M) % M;
}
int euler(int *prime, int *vis, int n){
    int top = 0;
    for(int i = 0; i <= n; i++) vis[i] = 0;
    for(int i = 2; i <= n; i++){
        if(!vis[i]) prime[top++] = i;
        for(int j = 0; j < top && i * prime[j] <= n; j++){
            vis[i * prime[j]] = 1;
            if(i % prime[j] == 0) break;
        }
    }
    return top;
}
struct star{int to, next, w;};
/*------------------------------------------------------------------------------------*/

int main(){
    // Fastin;
    TTT{
        ll n; scnaf("%lld", &n);
        if(n & 1) puts("Odd");
        else{
            n /= 2;
            if(n % 2 == 0) puts("Even");
            else puts("Same");
        }
    }
    return 0;
}


/* Author: rrrr_wys
 **/

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
typedef double db;
typedef long long ll;
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;

const int N = 810;
const int P = 1e9 + 7;

int bn, bm, bit[N][N];
void init(int n, int m) {
  memset(bit, 0, sizeof bit);
  bn = n, bm = m;
}
void add(int x, int y) {
  for (int i = x; i <= bn; i += i & -i)
    for (int j = y; j <= bm; j += j & -j)
      ++bit[i][j];
}
int ask(int x, int y) {
  int ans = 0;
  for (int i = x; i > 0; i -= i & -i)
    for (int j = y; j > 0; j -= j & -j)
      ans += bit[i][j];
  return ans;
}
int n, k, a[N][N], b[N][N];
int dx[4] = {0, -1, -1, 0};
int dy[4] = {0, -1, 0, -1};
int inb(int x, int y, int k) {
  if (x < 1 || x > n || y < 1 || y > n)
    return 0;
  x += k;
  y += k;
  if (x < 1 || x > n || y < 1 || y > n)
    return 0;
  return 1;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  int rnk = k * k - ((k * k) / 2 + 1) + 1;
  // cout << rnk << "\n";
  vector<pair<ll, pii>> v;
  rep(i, 1, n) rep(j, 1, n) cin >> a[i][j], v.pb({a[i][j], {i, j}});
  sort(v.begin(), v.end());
  auto ck = [&](int m) {
    init(n, n);
    rep(i, 0, v.size() - 1) if (v[i].fi <= m) add(v[i].se.fi, v[i].se.se);
    rep(i, 1, n) rep(j, 1, n) if (i + k - 1 <= n && j + k - 1 <= n) {
      int tt = ask(i + k - 1, j + k - 1) - ask(i + k - 1, j - 1) -
               ask(i - 1, j + k - 1) + ask(i - 1, j - 1);
      if (tt >= rnk)
        return 1;
    }
    return 0;
  };
  int l = v[0].fi, r = v.back().fi, ans = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (ck(mid))
      r = mid - 1, ans = mid;
    else
      l = mid + 1;
  }
  cout << ans << "\n";
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b); i-- > (a); )
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())
#define lb(x...) lower_bound(x)
#define ub(x...) upper_bound(x)

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll B = 10000;
const ll inf = B * (2e5 + 30);

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	ld p, q, s; cin >> p >> q >> s;
	ll a = round(B * p);
	ll b = round(B * q);
	ll r = round(B * s);

	ll ans = 0;
	for (ll x = -inf; x <= inf; x += B) {
		ll d = r * r - (x - a) * (x - a);
		if (d < 0) continue;
		ll l = 0, r = sqrt(d) + 30;
		while (r - l > 1) {
			ll m = l + (r - l) / 2;
			(m * m <= d ? l : r)  = m;
		}

		ans += (b + l + inf) / B - (b - r + inf) / B;
	}

	cout << ans;
}


#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pi  3.141592653589793238462643383279
#define int long long
#define ff first
#define ss second
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define high_functioning_sociopath  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const unsigned int M = 998244353;
//__________THE GAME IS ON__________/
void solve()
{
      int n;
      cin >> n;
      vector<pair<int,int>>v(n),res(n);
      for(int i=0;i<n;i++)
      {
             cin >> v[i].ff >> v[i].ss;
             res[i].ff = (2*v[i].ff)+v[i].ss;
             res[i].ss = v[i].ff;
      }
      sort(all(res));
      reverse(all(res));
      int pre[n+2],suf[n+2];
      pre[0] = 0; pre[n+1]=0;suf[0]=0;suf[n+1]=0;
      for(int i=0;i<n;i++) pre[i+1] = pre[i] + (res[i].ff-res[i].ss);
      for(int i=n;i>0;i--) suf[i]=suf[i+1] + res[i-1].ss;
      // for(int i=0;i<=n+1;i++)cout << pre[i] << " ";
      // cout << endl;
      // for(int i=0;i<=n+1;i++)cout << suf[i] << " ";
      // cout << endl;
      int lo = 0 ,hi = n-1,mid,ans;
      while(lo<=hi)
      {
             mid = (lo+hi)/2;
             int res = pre[mid+1]- suf[mid+2];
             // cout<<pre[mid]<<" "<<suf[mid+1]<<endl;
             if(res>0)
             {
                    ans = mid+1;
                    hi  = mid-1;
             }
             else
             {
                    lo = mid+1;
             }
      }
      cout << ans << endl;

}
int32_t main()
{
   high_functioning_sociopath
   //pre();
   ll t=1;
  // cin>>t;
   while(t--)
   {
      solve();
   }
}

#pragma region Macros
#include <bits/stdc++.h>
#if defined(LOCAL) || defined(ONLINE_JUDGE) || defined(_DEBUG)
#include <atcoder/all>
#endif
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>using vec = vector<T>;
template<class T, class U>using umap = unordered_map<T, U>;
using ll = long long;
using P = pair<ll, ll>;
using vl = vec<ll>;
#define fi first
#define se second
#define el endl
constexpr ll INF = numeric_limits<ll>::max()/2-1;
#pragma endregion

#pragma region IOMacros
template<class T>
istream &operator>>(istream &stream, vec<T>& o){REP(i, o.size())stream >> o[i];return stream;}
template<class T>
ostream &operator<<(ostream &stream, vec<T>& objs){REP(i, objs.size())stream << objs[i] << " ";stream << el;return stream;}

#define I(T, ...) ;T __VA_ARGS__;__i(__VA_ARGS__);
void __i() {}
template<class T, class... Ts> void __i(T&& o, Ts&&... args){cin >> o;__i(forward<Ts>(args)...);}

void O() {cout << el;}
template<class T, class... Ts> void O(T&& o, Ts&&... args){cout << o << " ";O(forward<Ts>(args)...);}
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    I(ll, N);
    ll cnt = 0;
    umap<ll, bool> mp;
    FOR(i, sqrt(N)+1, 2){
        ll cnt = 0;
        for(ll j=(ll)i*i; j<=N;){
            mp[j] = true;
            if(j < 0){
                O(i, j, cnt);
            }
            if(j>N/i){
                break;
            }
            j*=i;cnt++;
        }
    }
    cout << N-mp.size() << el;
}


#include<bits/stdc++.h>
using namespace std;
bool dp[1000005];
int main(){
	int n,sum=0,x;
	cin>>n;
	dp[0]=1;
	while(n--){
		scanf("%d",&x);
		for(int i=sum+x;i>=x;i--){
			dp[i]|=dp[i-x];
		}
		sum+=x;
	}
	int ans=sum;
	for(int i=0;i<=sum;i++)
		if(dp[i])ans=min(ans,max(i,sum-i));
	printf("%d\n",ans);
	return 0;
}

#include <iostream>
#include <vector>

int main()
{
  int N;
  std::cin>>N;

  std::vector<int64_t>T;
  for(int i=0;i<N;i++)
  {
    int64_t t;
    std::cin>>t;
    T.push_back(t);
  }

  int sum=0;
  for(auto e:T)sum+=e;

  bool g[101][100001]{0};
  g[0][0]=true;
  for(int i=0;i<=N-1;i++)
  {
    for(int64_t j=0;j<=sum;j++)
    {
      if(j-T[i]>=0)
      {
        g[i+1][j]=g[i][j]|g[i][j-T[i]];
      }
      else
      {
        g[i+1][j]=g[i][j];
      }
    }
  }

  int64_t res=0;
  for(int64_t i=sum/2+(sum%2);i<=sum;i++)
  {
    if(g[N][i])
    {
      res=i;
      break;
    }
  }

  std::cout<<res<<std::endl;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// #pragma GCC optimize("O2")
typedef long long int ll;
typedef long double ld;
typedef map <ll,ll> mm;
typedef vector <ll> mv;
typedef pair <ll,ll> mp;
typedef set <ll> ms;
typedef multiset <ll> mms;
typedef queue <ll> mq;
typedef deque <ll> mdq;
typedef stack <ll> mst;
typedef priority_queue <ll> mpq;
typedef priority_queue <ll, vector<ll>, greater<ll> > mmh;
typedef complex<double> cd;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define flush cout.flush();
#define all(v) v.begin(),v.end()
#define deb(x) cout << #x << " " << x << endl;
#define ff first
#define ss second
#define pb(v) push_back(v)
#define lb(v) lower_bound(v)
#define ub(v) upper_bound(v)
#define cn continue
#define forl(i,n) for(ll i=0;i<n;i++)
#define forlr(i,n) for(ll i=n-1;i>=0;i--)
#define rev(s) reverse(s.begin(),s.end())
void swap(ll &a,ll &b) {
	ll tmp=a;
	a=b;
	b=tmp;
}
ll atoistring(string s) {
	stringstream lol(s);
	ll x;
	lol>>x;
	return x;
}
void pv(mv v) {
	forl(i,v.size()) cout<<v[i]<<" ";
	cout<<"\n";
}
void pa(ll *v, ll size) {
	forl(i,size) cout<<v[i]<<" ";
	cout<<"\n";
}
void removeDups(mv &v) {
	sort(all(v));
	mv::iterator it = unique(v.begin(), v.end());
	v.resize(distance(v.begin(), it));
}
inline ld kthRoot(ld n, ll k) {
	return pow(k, (1.0 / k) * (log(n) / log(k)));
}
ll power(ll x, ll y, ll p) {
	ll res=1;
	x=x%p;
	while(y>0) {
		if(y&1) res = (res*x)%p;
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
void checkmod(ll &x, ll mod) {
	if(x>=mod) x%=mod;
}

ll mod = 1e9 + 7;

mv adj[200005], queries[200005];
vector < mp > queriess;
bool vis[200005];
ll vals[200005];
map < mp , ll > ans;
mm mapArr[200005];
ll mapIndex;

void DFSHt(ll curHt, ll x) {
	if(vis[x]) return ;
	vals[x] = curHt;
	vis[x] = 1;
	curHt ++ ;
	forl(i,adj[x].size()) DFSHt(curHt, adj[x][i]);
}

ll findAns(ll x) {
	if(vis[x]) return -1;
	vis[x] = 1;
	if(x != 0 && adj[x].size() == 1) {
		// cout<<x<<"-\n";
		mapArr[mapIndex][vals[x]] ++ ;
		// for(auto v : mapArr[mapIndex]) cout<<v.ff<<" "<<v.ss<<"\n";
		forl(i,queries[x].size()) ans[{x, queries[x][i]}] = mapArr[mapIndex][queries[x][i]];
		mapIndex ++ ;
		return mapIndex - 1;
	}
	mv mapps;
	forl(i,adj[x].size()) {
		ll y = findAns(adj[x][i]);
		if(y != -1) mapps.pb(y);
	}
	// cout<<x<<"-\n";
	// pv(mapps);
	ll pos = 0, maxSize = -1;
	forl(i,mapps.size()) {
		if(maxSize < (ll)mapArr[mapps[i]].size()) {
			maxSize = mapArr[mapps[i]].size();
			pos = i;
		}
	}
	forl(i,mapps.size()) {
		if(i != pos) {
			for(auto v : mapArr[mapps[i]]) {
				// cout<<v.ff<<" "<<v.ss<<"\n";
				mapArr[mapps[pos]][v.ff] += v.ss;
			}
		}
	}
	// exit(0);
	// cout<<x<<"-\n";
	// for(auto v : mapArr[mapps[pos]]) cout<<v.ff<<" "<<v.ss<<"\n";
	mapArr[mapps[pos]][vals[x]] ++ ;
	forl(i,queries[x].size()) ans[{x, queries[x][i]}] = mapArr[mapps[pos]][queries[x][i]];
	return mapps[pos];
}

void thisIsMain() {
	ll n;
	cin>>n;
	forl(i,n) {
		adj[i].clear();
		mapArr[i].clear();
	}
	queriess.clear();
	ans.clear();
	forl(i,n-1) {
		ll x;
		cin>>x;
		x -- ;
		adj[x].pb(i + 1);
		adj[i + 1].pb(x);
	}
	forl(i,n) vis[i] = 0;
	DFSHt(1, 0);
	// pa(vals, n);
	ll q;
	cin>>q;
	while(q--) {
		ll x, y;
		cin>>x>>y;
		x -- ;
		queriess.push_back({x, y + 1});
		queries[x].pb(y + 1);
	}
	mapIndex = 0;
	forl(i,n) vis[i] = 0;
	findAns(0);
	forl(i,queriess.size()) cout<<ans[queriess[i]]<<"\n";
}

int main(void)
{
	fastio
	ll t = 1;
	// cin>>t;
	while(t--) thisIsMain();
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll LINF = 1001001001001001001;
#ifdef _DEBUG
#define show(x)          \
	cerr << #x << " : "; \
	showVal(x)
template <typename T>
void showVal(const T &a) { cerr << a << endl; }
template <typename T>
void showVal(const vector<T> &a) {
	for (const T &v : a) cerr << v << " ";
	cerr << endl;
}
template <typename T>
void showVal(const vector<vector<T>> &a) {
	cerr << endl;
	for (const vector<T> &v : a) showVal(v);
}
#else
#define show(x)
#endif
struct graph {
	int n;
	vector<vector<int>> g;
	vector<ll> dist;
	vector<bool> vis;
	vector<int> a, b;
	graph(int n) : n(n), g(n), dist(n, LINF), vis(n, false), a(n), b(n) {}
	void addEdge(int from, int to) {
		g[from].push_back(to);
	}
	void addEdgeBoth(int n1, int n2) {
		addEdge(n1, n2);
		addEdge(n2, n1);
	}
};
int t = 0;
void dfs(graph &G, int no) {
	G.vis[no] = true;
	G.a[no] = t;
	t++;
	for (auto v : G.g[no]) {
		if (G.vis[v]) continue;
		G.dist[v] = G.dist[no] + 1;
		dfs(G, v);
	}
	G.b[no] = t;
	t++;
	return;
}
int main() {
	int n;
	cin >> n;
	graph g(n);
	for (int i = 0; i < n - 1; i++) {
		int p;
		cin >> p;
		p--;
		g.addEdgeBoth(i + 1, p);
	}

	g.dist[0] = 0;
	dfs(g, 0);
	show(g.a);
	show(g.b);
	vector<vector<int>> v(n);
	for (int i = 0; i < n; i++) {
		v[g.dist[i]].push_back(g.a[i]);
	}
	for (int i = 0; i < n; i++) {
		sort(v[i].begin(), v[i].end());
	}

	int q;
	cin >> q;
	for (int qi = 0; qi < q; qi++) {
		int u, d;
		cin >> u >> d;
		u--;
		int l = -1, r = v[d].size(), m;
		while (abs(l - r) > 1) {
			m = (l + r) / 2;
			if (v[d][m] < g.a[u]) {
				l = m;
			} else {
				r = m;
			}
		}
		int low = r;
		l = -1, r = v[d].size();
		while (abs(l - r) > 1) {
			m = (l + r) / 2;
			if (v[d][m] <= g.b[u]) {
				l = m;
			} else {
				r = m;
			}
		}
		int hi = l;
		cout << hi - low + 1 << endl;
	}
	return 0;
}