#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename F, typename S>
using ordered_map = tree<F, S, less<F>, rb_tree_tag, tree_order_statistics_node_update>;

//#define PB push_back
#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define pf printf
#define sf scanf
#define left __left
#define right __right
#define tree __tree

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

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

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

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

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

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

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

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

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

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

void faltu () {
            cerr << endl;
}

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

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif // yamin

int ans = 0;

void solve(int lim) {
	queue<int> bfs;
	if (4 <= lim)
		bfs.push(4);
	if (7 <= lim)
		bfs.push(7);
	while (!bfs.empty()) {
		int u = bfs.front();
		bfs.pop();
		++ans;
		int v = u * 10 + 4;
		if (v <= lim)
			bfs.push(v);
		v = u * 10 + 7;
		if (v <= lim)
			bfs.push(v);
	}
}

bool lucky(int num) {
	while (num > 0) {
		int lol = num % 10;
		if (lol != 4 && lol != 7)
			return false;
		num /= 10;
	}
	return true;
}

int main() {
	int n, k;
	cin >> n >> k;

	--k;

	vi store;

	for (int i = 1; k > 0; ++i) {
		store.PB(k % i);
		k /= i;
		dbg(i, k);
	}

	if (store.size() > n) {
		cout << -1 << endl;
		return 0;
	}

	dbg(store, n - store.size());

	solve(n - store.size());

	set<int> yo;

	for (int i = n; i > n - store.size(); --i) {
		yo.insert(i);
	}

	dbg(yo);
	dbg(ans);

	for (int i = n - store.size() + 1, j = store.size() - 1; i <= n; ++i, --j) {
		auto it = yo.begin();
		for (int l = 0; l < store[j]; ++l)
			++it;
		int it2 = *it;
		yo.erase(it2);
		dbg(i, it2);
		if (lucky(i) && lucky(it2))
			++ans;
	}

	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,counter=0;
    cin>>n;
    string s;
    for (int i=0;i<n;i++) {
        cin>>s[i];
    }
    for (int i=0;i<n;i++) {
        if (s[i]=='x' && s[i+1]=='x' && s[i+2]=='x')
            counter++;
    }
    cout<<counter<<endl;
}


#include<cstdio>
#define ll long long
using namespace std;
int n,k;
ll dp[510][510],temp[510][510],mod=1e9+7,rez;
ll step(ll base,int pw){
   if(pw==0)return 1;
   ll pom=step(base,pw/2);
   pom=(pom*pom)%mod;
   if(pw&1)return (pom*base)%mod;
   return pom;
}
void go(){

   for(int i=1;i<=n;i++){/// last pos
      dp[0][0]=1;

      for(int j=0;j<=i;j++)/// count
      for(int p=0;p<=i;p++){/// last int
          temp[j+1][i]=(temp[j+1][i]+(dp[j][p]*(step(2,i-p)-1))%mod*step(2,p))%mod;
          temp[j][p]=(temp[j][p]+dp[j][p]*step(2,p))%mod;
      }

      for(int j=0;j<=i;j++)
        for(int p=0;p<=i;p++)
            dp[j][p]=temp[j][p];
      memset(temp,0,sizeof(temp));
   }

}
int main(){

    scanf("%d %d",&n,&k);
    go();

    for(int i=0;i<=n;i++)rez=(rez+dp[k][i])%mod;
    printf("%lld\n",rez);

return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
#define infl 0x3f3f3f3f3f3f3f3f
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define MOD 1000000007
#define maxn 500010
#define re(i,l,r) for(int i=l;i<=r;++i)
#define rep(i,l,r) for(int i=l;i<r;++i)
vector<ll> v1;
vector<ll> v2;
vector<ll> v3;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);//能被这样表示的是坏年，求好年的最长区间
	//求出来全部l-r，sort一下，相减就是区间长度
	ll x, y, l, r;
	cin >> x >> y >> l >> r;
	ll t = x;
	v1.emplace_back(1);
	v2.emplace_back(1);
	if (x != 0)
	{
		while (t <= r)
		{
			v1.emplace_back(t);
			if (t >= l && t <= r)
				v3.emplace_back(t);
			t *= x;
		}
	}
	else
	{
		v1.emplace_back(0);
	}
	t = y;
	if (y != 0)
	{
		while (t <= r)
		{
			v2.emplace_back(t);
			if (t >= l && t <= r)
				v3.emplace_back(t);
			t *= y;
		}
	}
	else
		v2.emplace_back(0);
	for (int i = 0; i < v1.size(); i++)
	{
		for (int j = 0; j < v2.size(); j++)
		{
			ll temp = v1[i] + v2[j];
				if (temp >= l && temp <= r)
				{
					v3.emplace_back(temp);
					//cout << "  sda "<<temp << endl;
				}
		}
	}
	sort(v3.begin(), v3.end());
	ll ans = 0;
	for (int i = 1; i < v3.size(); i++)
	{
		ll tem = v3[i] - v3[i - 1]-1;
		ans = max(ans, tem);
	}
	if (v3.size() > 0)
	{
		ans = max(ans, v3[0] - l);
		ans = max(ans, r - v3[v3.size() - 1]);
	}
	else
	{
		ans = max(ans,r - l + 1);
	}
	cout << ans << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int n;
int a[110];
int f[110];
int m,r,l,s,sum;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		f[i]=f[i-1]+a[i];
	}
//	for(int i=1;i<=n;i++)
//	cout<<f[i]<<" ";
	for(int i=2;i<=n;i++){
		for(int j=1;j<=i;j++){
			sum=i-j-(f[i]-f[j]);
			if(sum>m){
				r=i;
				l=j+1;
			}
		}
	}
	for(int i=l;i<=r;i++){
		a[i]=1-a[i];
	}
	for(int i=1;i<=n;i++){
		if(a[i]==1)s++;
	}
	cout<<s;
	return 0;
}


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

#define MAX 501
#define MOD 1000000007
#define ll long long

ll dp[MAX][MAX][MAX];

ll mhp , mat, mde;
ll h , a , b;
ll get(ll hp , ll at  , ll de){
    ll dx1 = max(0ll ,at-mde); // m lost
    ll dx2 = max(0ll ,mat-de); // y lost

    if(!dx1) return hp>0 && mhp <=0 ;

    ll dy = mhp / dx1  + (mhp % dx1!=0) ;
    hp -= dy * dx2;

    return hp > 0;
}

ll solve(ll hp , ll at , ll de){
    if(hp>=300  || at>=300 || de>=300 )
        return 1e9;

    if(get(hp,at,de))
        return 0;

    if(dp[hp][at][de]+1)
        return dp[hp][at][de];

    ll res1 = h+solve(hp+1,at,de);
    ll res2 = a+solve(hp,at+1,de);
    ll res3 = b+solve(hp,at,de+1);

    return dp[hp][at][de] = min(min(res1,res2),res3);
}

int main(){

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // !ONLINE_JUDGE

    ll hp,at,de;
    cin>>hp>>at>>de;
    cin>>mhp>>mat>>mde;
    cin>>h>>a>>b;

    memset(dp,-1,sizeof dp);

    cout<<solve(hp,at,de);

}
// NOTE :  .Check MAX and limits before submit ;


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char  a[1000005];
int main()
{
	int i=1,j=1,cun,jishu=1,ge=0;
	while((a[i++]=getchar())!=' ');
	for(;j<=(i-1);)
	{
		for(int c=j+1;c<=(i-1);c++)
		{
			if(a[c]!=a[j])
			{
                j=c;
                jishu=1;
                break;
            }
			if(a[c]==a[j])
			{
				jishu+=1;
			}
		}
		if(jishu%2==0)
		{
			ge+=1;
		}
	}
	cout<<ge<<endl;
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <queue>
using namespace std;
long long int n,k,syc,bas[20],a;
long long int dizi[20],di[20];
priority_queue <int,vector<int>,greater<int> > qu;
int fk (int x)
{
    int crp=1;
    for(int i=1;i<=x;i++)
        crp*=i;
    return crp;
}
int muk (int x)
{
    int b=0;
   // printf("%d\n",x);
    while(x)
    {
        b=x%10;
        x=x/10;
        if(b!=4 && b!=7)
            return 0;
    }
  //  printf("YES\n\n\n");
    return 1;
}
void kont ()
{
    for(int i=0;i<=a-1;i++)
        if(muk(dizi[i]) && muk(n-i))
            syc++;
    printf("%lli\n",syc);
}
void kont2 ()
{
    for(int i=0,j=n;i<=a-1;i++,j-- )
        if(muk(dizi[i]) && muk(j))
            syc++;
    printf("%lli\n",syc);
}
int main ()
{
    scanf("%lli %lli",&n,&k);
    if(n>=15)
    {
        for(int  i=1;i<=n;i++)
            qu.push(i);
        a=15;
        for(int i=a-1;i>=0;i--)
        {
            int bay=0,end=0;
            if(k>fk(i))
            {
                if(k%fk(i))
                {
                    end=k/fk(i);
                    k=k%fk(i);
                }
                else
                {
                    end=k/fk(i)-1;
                    k=fk(i);
                }
            }
            while (bay<end)
            {
                di[bay]=qu.top();
                qu.pop();
                bay++;
            }
            dizi[i]=qu.top();
            qu.pop();
            for(int j=0;j<bay;j++)
                qu.push(di[j]);
        }
        /*for(int i=1;i<=n-15;i++)
            printf("%d ",i);*/
        for(int i=a-1;i>=0;i--)
        {
        //    printf("%lli ",n-15+dizi[i]);
            dizi[i]=n-15+dizi[i];
        }
        for(int i=1;i<=n-15;i++)
            if(muk(i))
                syc++;
        kont2();
        getchar();getchar();
    }
    else
    {
        if(k>fk(n))
        {
            printf("-1\n");
            exit(0);
        }
        for(int  i=1;i<=n;i++)
            qu.push(i);
        a=n;
        for(int i=a-1;i>=0;i--)
        {
            int bay=0,end=0;
            if(k>fk(i))
            {
                if(k%fk(i))
                {
                    end=k/fk(i);
                    k=k%fk(i);
                }
                else
                {
                    end=k/fk(i)-1;
                    k=fk(i);
                }
            }
            while (bay<end)
            {
                di[bay]=qu.top();
                qu.pop();
                bay++;
            }
            dizi[i]=qu.top();
            qu.pop();
            for(int j=0;j<bay;j++)
                qu.push(di[j]);
        }
        kont();
      /*  for(int i=a-1;i>=0;i--)
            printf("%lli ",dizi[i]);*/
        getchar();getchar();
    }
}


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

int n, otv;
bool u[300][300];

int main()
{
    cin >> n;
    for(int i = 0; i < n; ++i)
    {
        char c;
        cin >> c;
        if(c == 'U')
            y++;
        if(c == 'D')
            y--;
        if(c == 'R')
            x++;
        if(c == 'L')
            x--;
        if(u[x][y] == true)
            otv++;
        u[x][y] = true;
    }
    cout << otv;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <stdio.h>
#include <functional>

using namespace std;

typedef long long ll;
typedef long double ld;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	map <char, int> mp;
	map <int, char> mp2;
	for (int i = 1; i <= 50; i++)
	{
		if (i < 10)
		{
			mp[char(i + '0')] = i;
			mp2[i] = char(i + '0');
		}
		else if (i < 36)
		{
			mp[char((i - 10) + 'a')] = i;
			mp2[i] = char((i - 10) + 'a');
		}
		else
		{
			mp[char((i - 36) + 'A')] = i;
			mp2[i] = char((i - 36) + 'A');
		}
	}

	int n, k;
	cin >> n >> k;
	vector <string> s;
	s.push_back("1");
	for (int j = 2; j <= n; j++)
	{
		int l = s.size();
		for (int i = 0; i < l; i++)
		{
			if (mp[s[i][s[i].length() - 1]] == j - 1)
			{
				string t = s[i].substr(0, s[i].length() - 1) + mp2[j] + s[i][s[i].length() - 1];
				s.push_back(t);
			}
			s[i] += mp2[j];
		}
	}
	sort(s.begin(), s.end());
	for (int i = 0; i < s[k - 1].length(); i++)
	{
		if (s[k - 1][i] >= '1' && s[k - 1][i] <= '9')
		{
			cout << int(s[k - 1][i] - '0') << " ";
		}
		else
			if (s[k - 1][i] >= 'a' && s[k - 1][i] <= 'z')
			{
				cout << int(s[k - 1][i] - 'a') + 10 << " ";
			}
			else
			{
				cout << int(s[k - 1][i] - 'A') + 36 << " ";
			}
	}
	//system("pause");
	return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;
long long n;
int main()
{
 //freopen("input.txt","r",stdin);
 //freopen("output.txt","w",stdout);
 //ios_base::sync_with_stdio(0);
 long long n,m,r,l;
 //scanf("%I64d%I64d%I64d%I64d",&n,&m,&l,&r);//cout<<1;
 cin>>n>>m>>l>>r;
 vector <long long> v1;
 v1.push_back(1);
 long long nn=1;
 while(nn*n<=r)
 {
  nn*=n;
  v1.push_back(nn);

 }
 vector <long long> v2;
 v2.push_back(1);
 long long mm=1;
 while(mm*m<=r)
 {
  mm*=m;
  v2.push_back(mm);
  //cout<<mm<<endl;
 }
 vector <long long> v3;
 for (int i=0;i<(int)v1.size();i++)
    for (int j=0;j<(int)v2.size();j++)
     if (v1[i]+v2[j]<=r && v1[i]+v2[j]>=l) {v3.push_back(v1[i]+v2[j]);}
 sort(v3.begin(),v3.end());
 long long ans=0;
 if (v3.size()>0)ans=max(ans,v3[0]-l);
 for (int i=1;i<(int)v3.size();i++)
  {
   if (v3[i-1]>=l && v3[i]<=r) {ans=max(ans,v3[i]-v3[i-1]-1);}//cout<<v3[i]<<' '<<v3[i-1]<<endl;
  // cout<<v3[i]<<endl;
  }// cout<<1;
// cout<<v3[v3.size()-1];
 if (v3.size()>0)ans=max(ans,r-v3.back());
 if (v3.size()==0) {cout<<r-l+1;}
 else cout<<ans;
}


#include<bits/stdc++.h>
#define maxn 1001
#define INF 1000000007
typedef long long ll;
using namespace std;

ll x,n;
bool prime[1000000000]={false};
vector<int> G;
ll cond=1;

ll quick_pow(ll x,ll n,ll m){
	ll res = 1;
	while(n > 0){
		if(n & 1)	res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

void prime_num(ll x){//������
	for(ll i=2;i<=sqrt(x);i++){
		if(prime[i]==false){
			for(ll j=2;j*i<=x;j++){
				prime[i*j]=true;
			}
		}
	}
}

void g(ll x,ll y){
	ll t=x;
	ll tot=0;
	while(t<=y){
		tot+=y/t;
		if(t>y/x)break;
		t=t*x;
	}
	cond=(cond*quick_pow(x,tot,INF))%INF;
}

int main(){
	scanf("%lld%lld",&x,&n);
	prime_num(x);
	for(ll i=2;i<=min(x,n);i++){
		if(prime[i]==false&&x%i==0){
			G.push_back(i);
		}
	}
	for(ll j=0;j<G.size();j++){
		g(G[j],n);
	}
	printf("%lld",cond);
	return 0;
}


#include <cstdio>
main() { int n; scanf("%d", n); puts((n & 1)? "black": "white\n1 2");}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll find(ll m,ll x)
{
   ll y=(m-1-x-(x*x));//cout<<y<<"o\n";
   if((y%(2*x))==0)
   {
       y=y/(2*x);
      return y;
   }
    else
        return -1;

}
int main()
{
 ll x;cin>>x;
 ll i=0,y=-1;
 while((i<x)&&(y==-1))
 {
    y=find(x,i);//cout<<y<<"p\n";
    i++;

 }

 if(y==-1)
 {
     cout<<"NO\n";
 }
    else
    {
       cout<<i-1<<" "<<y;

    }
    }


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef priority_queue<int> P_QI;
typedef priority_queue<string> P_QS;
typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector< int > :: iterator $$;

#define SET(arr) memset(arr, -1, sizeof(arr))
#define CLR(arr) memset(arr, 0, sizeof(arr))

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

#define $ vector< int > :: iterator
#define m_p make_pair
#define p_b push_back
#define rep(i, n) for(int i=0; i<(n); i++)
#define forn(i, n) for (int i = 1; i <=(int)(n); ++i)
#define forab(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define forba(i, b, a) for (int i = (int)(b); i >= (int)(a); --i)

#define forv(i,v) rep(i,SZ(v))
#define forit(i,s) for(auto i=(s).begin();i!=(s).end();++i)

#define Boost ios_base::sync_with_stdio(0); cin.tie(0)
#define all(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define _ <<" "<<
#define CS(i) cout<<"Case "<<(int)(i)<<": "

const int MOD = 1e9+7;
const int inf = 1e9+9;
const long long INF = 1e18+3;
const ld eps = 1e-9;
const ld PI=acos(-1.0);

int main() {
Boost;
//READ("in.txt");
//WRITE("out.txt");
ll n;
cin>>n;
n++;
int p=2,i=1;
while(p<=n) {
    p*=2;
    i++;
}
if(p/2==n) cout<<i-1<<endl;
else cout<<n<<endl;
return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <climits>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

using namespace std;
#define gc getchar_unlocked

typedef long long        LL;
typedef pair<int, int>   pii;
typedef pair<int, pii>   piii;
typedef vector<int>      vi;
typedef vector<pii>      vii;
typedef vector<piii>     viii;

inline int sqr(int x) { return x * x; }
inline int cube(int x) { return x * x * x; }
inline LL sqrLL(LL x) { return x * x; }
inline LL cubeLL(LL x) { return x * x * x; }

const LL LLINF = 9223372036854775807LL;
const LL LLINF17 = 100000000000000000LL;
const int INF = 2147483647;
const int INF9 = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-7;
const double PI = acos(-1.0);

#define FOR(a,b,c)   for (int (a)=(b); (a)<(c); (a)++)
#define FORN(a,b,c)  for (int (a)=(b); (a)<=(c); (a)++)
#define FORD(a,b,c)  for (int (a)=(b); (a)>=(c); (a)--)
#define REP(i,n)     FOR(i,0,n)
#define REPN(i,n)    FORN(i,1,n)
#define REPD(i,n)    FORD(i,n,1)
#define rea(a,b)     read(a),read(b)
#define rean(a,b,c)  rea((a,b),c)

#define RESET(a,b)   memset(a,b,sizeof(a))
#define SYNC         ios_base::sync_with_stdio(0);
#define SIZE(a)      (int)(a.size())
#define MIN(a,b)     (a) = min((a),(b))
#define MAX(a,b)     (a) = max((a),(b))
#define ALL(a)       a.begin(),a.end()
#define RALL(a)      a.rbegin(),a.rend()
#define SIZE(a)      (int)(a.size())
#define LEN(a)       (int)(a.length())
#define pl(n)       printf("%lld", n );

#define fi           first
#define se           second
#define pb           push_back
#define mp           make_pair
#define ll           long long

#ifdef _WIN32
#define getchar_unlocked getchar
#define scanf            scanf_s
#endif

template<typename T>
void read(T &x)
{
    register T c = gc();
    x = 0;
    for (; (c < 48 || c>57); c = gc());
    for (; c > 47 && c < 58; c = gc()) { x = (x << 1) + (x << 3) + c - 48; }
}
ll num_of_zero(ll num)
{
    ll left_part_zeros;

    if (num == 0)
        return 0;

    left_part_zeros = num_of_zero(num >> 1);
    if ((num & 1) == 0)
        return left_part_zeros + 1;
    else
        return left_part_zeros;
}
int main() {
    ll a, b;
    rea(a, b);
    ll count1 = 0;

    for (ll i = a; i <= b; i++) {
        ll n = i;
        if (num_of_zero(n) == 1) {
            count1++;
        }
    }
    pl(count1);
    return 0;
}


#pragma GCC optimize(2)
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ST sort
#define MAXN 100005
#define DB double
#define LL long long
#define INF 0x3f3f3f3f3f3f3f3f
#define Int register int
#define XM XiangMeiHaoGuai
#define Pa pair<LL,LL>
#define Lson Son[x][0]
#define Rson Son[x][1]
using namespace std;
inline void read(LL &x)
{
	x = 0;
	LL f = 1;
	char s = getchar();
	while (s < '0' ||s > '9')
	{
		if (s == '-')
			f = -1;
		s = getchar();
	}
	while (s >= '0' && s <= '9')
	{
		x = (x << 3) + (x << 1) + (s ^ 48);
		s = getchar();
	}
	x *= f;
}
inline LL Max(LL x,LL y)
{
	return x > y ? x : y;
}
inline LL Min(LL x,LL y)
{
	return x < y ? x : y;
}
LL Gcd(LL a,LL b)
{
	if (! b)
		return a;
	return Gcd(b, a % b);
}
inline LL Abs(LL x)
{
	if (x < 0)
		return -x;
	return x;
}
inline DB Fabs(DB x)
{
	if (x > 0)
		return x;
	return -x;
}
LL a, b, p, x;
inline LL QuickPow(LL x,LL y,LL Mod)
{
	LL Res = 1, temp = x;
	while ( y )
	{
		if (y & 1)
			Res = Res * temp % Mod;
		temp = temp * temp % Mod;
		y /= 2;
	}
	return Res;
}
inline LL Inv(LL x)
{
	return QuickPow(x, p - 2, p);
}
inline LL Mo(LL x,LL Mod)
{
	return ((x % Mod) + Mod) % Mod;
}
inline Jie(LL n,LL Mi)
{
	LL Get = b * Inv( Mi ) % p;
	LL Dai = (p - 1) * Mo(n - Get, p) + n;
	if (Dai > x)
		return 0;
	return (x - Dai) / (p * (p - 1)) + 1;
}
int main()
{
	read( a ); read( b ); read( p ); read( x );
	LL Power = 1, Ans = 0;
	for (Int i = 1; i < p; ++ i)
	{
		Power = Power * a % p;
		LL Da = Jie(i, Power);
		Ans += Da;
	}
	printf("%lld", Ans);
	return 0;
}
/*
n * a ^ n ≡b (mod p)

*/ <stack>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ST sort
#define MAXN 100005
#define DB double
#define LL long long
#define INF 0x3f3f3f3f3f3f3f3f
#define Int register int
#define XM XiangMeiHaoGuai
#define Pa pair<LL,LL>
#define Lson Son[x][0]
#define Rson Son[x][1]
using namespace std;
inline void read(LL &x)
{
	x = 0;
	LL f = 1;
	char s = getchar();
	while (s < '0' ||s > '9')
	{
		if (s == '-')
			f = -1;
		s = getchar();
	}
	while (s >= '0' && s <= '9')
	{
		x = (x << 3) + (x << 1) + (s ^ 48);
		s = getchar();
	}
	x *= f;
}
inline LL Max(LL x,LL y)
{
	return x > y ? x : y;
}
inline LL Min(LL x,LL y)
{
	return x < y ? x : y;
}
LL Gcd(LL a,LL b)
{
	if (! b)
		return a;
	return Gcd(b, a % b);
}
inline LL Abs(LL x)
{
	if (x < 0)
		return -x;
	return x;
}
inline DB Fabs(DB x)
{
	if (x > 0)
		return x;
	return -x;
}
LL a, b, p, x;
inline LL QuickPow(LL x,LL y,LL Mod)
{
	x %= Mod;
	LL Res = 1, temp = x;
	while ( y )
	{
		if (y & 1)
			Res = Res * temp % Mod;
		temp = temp * temp % Mod;
		y /= 2;
	}
	return Res;
}
inline LL Inv(LL x)
{
	return QuickPow(x, p - 2, p);
}
inline LL Mo(LL x,LL Mod)
{
	return ((x % Mod) + Mod) % Mod;
}
inline Jie(LL n,LL Mi)
{
	LL Get = b * Inv( Mi ) % p;
	LL Dai = (p - 1) * Mo(n - Get, p) + n;
	if (Dai > x)
		return 0;
	return (x - Dai) / (p * (p - 1)) + 1;
}
int main()
{
	read( a ); read( b ); read( p ); read( x );
	LL Power = 1, Ans = 0;
	for (Int i = 1; i < p; ++ i)
	{
		Power = Power * a % p;
		LL Da = Jie(i, Power);
		Ans += Da;
	}
	printf("%lld", Ans);
	return 0;
}
/*
n * a ^ n ≡b (mod p)

*/
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ST sort
#define MAXN 100005
#define DB double
#define LL long long
#define INF 0x3f3f3f3f3f3f3f3f
#define Int register int
#define XM XiangMeiHaoGuai
#define Pa pair<LL,LL>
#define Lson Son[x][0]
#define Rson Son[x][1]
using namespace std;
inline void read(LL &x)
{
	x = 0;
	LL f = 1;
	char s = getchar();
	while (s < '0' ||s > '9')
	{
		if (s == '-')
			f = -1;
		s = getchar();
	}
	while (s >= '0' && s <= '9')
	{
		x = (x << 3) + (x << 1) + (s ^ 48);
		s = getchar();
	}
	x *= f;
}
inline LL Max(LL x,LL y)
{
	return x > y ? x : y;
}
inline LL Min(LL x,LL y)
{
	return x < y ? x : y;
}
LL Gcd(LL a,LL b)
{
	if (! b)
		return a;
	return Gcd(b, a % b);
}
inline LL Abs(LL x)
{
	if (x < 0)
		return -x;
	return x;
}
inline DB Fabs(DB x)
{
	if (x > 0)
		return x;
	return -x;
}
LL a, b, p, x;
inline LL QuickPow(LL x,LL y,LL Mod)
{
	LL Res = 1, temp = x;
	while ( y )
	{
		if (y & 1)
			Res = Res * temp % Mod;
		temp = temp * temp % Mod;
		y /= 2;
	}
	return Res;
}
inline LL Inv(LL x)
{
	return QuickPow(x, p - 2, p);
}
inline LL Mo(LL x,LL Mod)
{
	return ((x % Mod) + Mod) % Mod;
}
inline Jie(LL n,LL Mi)
{
	LL Get = b * Inv( Mi ) % p;
	LL Dai = (p - 1) * Mo(n - Get, p) + n;
	if (Dai > x)
		return 0;
	return (x - Dai) / (p * (p - 1)) + 1;
}
int main()
{
	read( a ); read( b ); read( p ); read( x );
	LL Power = 1, Ans = 0;
	for (Int i = 1; i < p; ++ i)
	{
		Power = Power * a % p;
		LL Da = Jie(i, Power);
		Ans += Da;
	}
	printf("%lld", Ans);
	return 0;
}
/*
n * a ^ n ≡b (mod p)

*/


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

// returns (d, x, y) such that d = gcd(a, b) = ax + by
ll extended_euclid(ll a, ll b, ll &x, ll &y)
{
    if (b == 0) { x = 1, y = 0; return a; }
    ll r = extended_euclid(b, a % b, y, x);
    y -= a / b * x;
    return r;
}

ll chinese_remainder_theorem(ll a, ll m)
{
    ll s = m, t, ans = 0, p, q;
    t = s / m;
    extended_euclid(t, m, p, q);
    ans = (ans + t * p * a) % s;
    if (ans < 0) ans += s;
    return ans;
}

ll pow(ll a, ll b, ll M)
{
	ll x = 1;
	for (; b > 0; b >>= 1)
	{
		if (b & 1) x = x * a % M;
		a = a * a % M;
	}
	return x;
}

typedef long double ld;
#define y1 Y1
#define double ld
ll minE_max(double x)
{
	ll e = x;
	if (e - 1 >= x) return e - 1;
	if (e >= x) return e;
	return e + 1;
}

ll maxE_min(double x)
{
	ll e = x;
	if (e + 1 <= x) return e + 1;
	if (e <= x) return e;
	return e - 1;
}

ll x1, x2, y1, y2;
// returns (x, y) such that c = ax + by
ll diophantine_equation(ll a, ll b, ll c)
{
	ll g, x, y;
	ll g = extended_euclid(a, b, x, y);
	if (c % g != 0) return 0;

	if(g * b < 0) swap(x1, x2);
	if(g * a > 0) swap(y1, y2);

	return max((min(maxE_min(double(x2 * g - x * c) / b), maxE_min(double(y2 * g - y * c) / -a))
			- max(minE_max(double(x1 * g - x * c) / b), minE_max(double(y1 * g - y * c) / -a)) + 1), 0LL);
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0);

    ll a, b, p, l;
    cin >> a >> b >> p >> l;

    if (a%p == 0)
    {
    	cout << (b%p==0) * l;
    	return 0;
    }

    vector<ll> r;
    set<ll> s;
    ll x = a % p;
    do
    {
        r.push_back(x);
        s.insert(x);
        x = (x * a) % p;
    } while ((ll)r.size() < l && s.find(x) == s.end());

    ll k = r.size();
    ll ans = 0;
    for (int i = 1; i <= k; ++i)
    {
        a = r[i-1];
        ll x = chinese_remainder_theorem((b * pow(a, p-2, p)) % p, p);
        if (k == p)
        {
        	ll z = (i - x) / p;
        	if (z * p == (i - x))
        	{
        		ll mn_t1 = max((1-x+p-1)/p, 0LL);
        		ll mx_t1 = (l-x)/p;
        		if (mx_t1 - mn_t1 >= 0)
        		{
            		ll mn_t2 = max((1-i+p-1)/p, 0LL);
            		ll mx_t2 = (l-i)/p;
            		if (mx_t2 - mn_t2 >= 0)
            		{
            			mn_t2 = max(mn_t2, mn_t1 - z);
            			mx_t2 = min(mx_t2, mx_t1 - z);
            			if (mx_t2 - mn_t2 >= 0)
            				ans += mx_t2 - mn_t2 + 1;
            		}
        		}
        	}
        }
        else
        {
        	x1 = x==0;
        	x2 = (l-x)/p;
        	y1 = 0;
        	y2 = (l-i)/k;
        	if (x1 <= x2 && y1 <= y2)
        		ans += diophantine_equation(p, -k, i-x);
        }
    }

    cout << ans;

    return 0;
}


//Utkarsh.25dec
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
const int N=500023;
vector <int> adj[N];
void solve()
{
    ll s,x;
    cin>>s>>x;
    vl bits;
    ll index=0;
    ll ans=1;
    if(x==0)
    {
        cout<<1;
        return;
    }
    while(true)
    {
        ll temp=1<<index;
        if(temp>x)
            break;
        if((x&temp)!=0)
        {
            bits.pb(1);
            // cout<<temp<<'\n';
            ans*=2;
        }
        else
            bits.pb(0);
        index++;
    }
    ll temp=s-x;
    if(temp%2==1)
    {
        cout<<0;
        return;
    }
    if(temp<0)
    {
        cout<<0;
        return;
    }
    temp/=2;
    vl bits2;
    index=0;
    while(true)
    {
        ll temp1=1<<index;
        if(temp1>temp)
            break;
        if(x&temp1!=0)
        {
            bits2.pb(0);
        }
        else
            bits2.pb(1);
        index++;
    }
    for(int i=0;i<min(bits.size(),bits2.size());i++)
    {
        if(bits[i]==1&&bits2[i]==1)
        {
            cout<<0;
            return;
        }
    }
    ll flag=0;
    for(int i=0;i<bits.size();i++)
    {
        if(bits[i]==0)
            flag=1;
    }
    if(flag==0)
        ans-=2;
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(0);
#define rep(i,n,m) for(int i=n;i<m;i++)
#define pre(i,n,m) for(int i=n-1;i>=m;i--)
#define vii vector<int>
#define vi vector<vii>
#define pi pair<int,int>
#define mi unordered_map<int,int>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define sz(xx) (int)xx.size()
#define all(yy) yy.begin(),yy.end()
#define rall(yyy) yyy.rbegin(),yyy.rend()
#define f first
#define s second
#define ll long long
#define ld long double
#define hell 100000000000LL
#define callable 998244353
const int mod=1e9+7;
template<typename T1,typename T2> inline void chkmin(T1 &x, T2 y) { if(y<x) x=y; };
template<typename T1,typename T2> inline void chkmax(T1 &x,T2 y) { if(y>x) x=y; };
int gcd(int x,int y)
{
	return(y==0?x:gcd(y,x%y));
}
inline int mul(int a,int b)
{
	return(1ll*a*b)%callable;
}
inline int sub(int a,int b)
{
	a-=b;
	if(a<0)
	a+=mod;
	if(a>=mod)
	a-=mod;
	return a;
}
inline int add(int a,int b)
{
	a+=b;
	if(a>=mod)
	a-=mod;
	if(a<0)
	a+=mod;
	return a;
}
inline int expo(int a,int b)
{
	int values=1;
	while(b)
	{
		if(b&1)
		values=mul(values,a);
		a=mul(a,a);
		b>>=1;
	}
	return values%mod;
}
const int MAXN=1e5+100;
ll n,c1,c2,
inline ll call(ll sss,ll cnt)
{
	return cnt*(c1+c2*(sss-1)*(sss-1));
}
ll can(ll g)
{
	ll k,r;
	k=n/g;
	r=n%g;
	ll ss=g-r;
	ll bb=r;
	return call(k,ss)+call(k+1,bb);
}
void solve()
{
	ll val=0;
	cin>>n>>c1>>c2;
	rep(i,0,n)
	{
		char c;
		cin>>c;
		if(c=='1')
		++val;
	}
	ll res=1e18;
	pre(i,val+1,1)
	{
		ll cur=can(i);
		if(cur<res)
		res=cur;
	}
	cout<<res<<endl;
}
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
    }
	return 0;
}


#include <iostream>
using namespace std;

unsigned long long n;
unsigned long long c1, c2;

unsigned long long mature;

void getMature()
{
	mature = 0;
	char c;
	for (int i = 0; i < n; i++)
	{
		cin >> c;
		if (c == '1')
			mature++;
	}
}

unsigned long long getCost(unsigned long long size, unsigned long long count)
{
	return count * (c1 + c2 * (size - 1) * (size - 1));
}

unsigned long long check(unsigned long long group)
{
	unsigned long long k = n / group;
	unsigned long long r = n % group;
	unsigned long long smallGroup = group - r;
	unsigned long long bigGroup = r;
	return getCost(k, smallGroup) + getCost(k + 1, bigGroup);
}

unsigned long long all()
{
	unsigned long long min = pow(2, 64) - 1;
	unsigned long long current;
	for (int i = mature; i > 0; i--)
	{
		current = check(i);
		if (current < min)
			min = current;
	}
	return min;
}

int main()
{
	cin >> n >> c1 >> c2;
	getMature();
	cout << all();
	return 0;
}


 #include<iostream>
#include<fstream>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<string>
#include<stack>
#include<vector>
#include<set>
#include<iomanip>

using namespace std;
using namespace std;

void main() {
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(15);
	long long n,c1,c2;
	cin >> n>>c1>>c2;
	long long d = 0, v = 0;
	for (int i = 0; i  < n; i++)
	{
		char f;
		cin >> f;
		if (f =='1')
	     v++;
		else
		 d++;
	}
	long long min =100000000000000000000;
	for (int i = v; i >0 ;i--)
	{
		long long s = n / i;
		long long m = n % i;
		if (c1*i + c2*(s - 1)*(s - 1) * (i - m) + c2*(s*s)*m < min)
			min = c1*i + c2*(s - 1)*(s - 1) * (i - m) + c2*(s*s)*m;
	}
	cout << min;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
	long long n, c1, c2;
	cin >> n >> c1 >> c2;

	string s;
	cin >> s;

	long long sc = 0, b = 0;
	for(int i = 0; i < s.size(); i ++)
		if(s[i] == '0')
			sc ++;
		else
			b ++;
	long long ans = 1000000000000;

	for(int i = 1; i <= b; i ++)
		  ans = min(ans, c1 + c2 * (n / i + n % i - 1) *  (n / i + n % i - 1) + (i - 1) *
			  (c1 + c2 * (n / i - 1) * (n / i - 1)));
	cout << ans << endl;

}


#include <iostream>
#include <string>
#include <fstream>
#include <algorithm>

using namespace std;

int main()
{
    long long a[4][6] = {4, 5, 6, 3, 2, 1,
                        11, 12, 13, 10, 9, 8,
                        4, 5, 6, 3, 2, 1,
                        11, 12, 13, 10, 9, 8};
    char str[101];
    while (cin >> str)
    {
        long long n = 0;
        int i = 0;
        for (i = 0; str[i] >= '0' && str[i] <= '9'; ++ i)
        {
            n = n * 10 + (str[i] - '0');
        }
        n = n - 1;
        int row = n % 4;
        int col = str[i] - 'a';

        cout << a[row][col] + (n / 4) * 4 + (n / 4) * 12 << endl;
    }
    return 0;
}
close


#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7,N=100005;
typedef long long ll;
int x,n,pos;
int cnt1,cnt2;
int fac[N],inv[N];
int qpow(int a,int b)
{
    int res=1,tp=a;
    while(b)
    {
        if(b&1)
            res=1ll*res*tp%mod;
        tp=1ll*tp*tp%mod;
        b>>=1;
    }
    return res;
}
ll P(int n,int m)
{
    return 1ll*fac[n]*inv[n-m]%mod;
}
int main()
{
    scanf("%d%d%d",&n,&x,&pos);
    fac[0]=1,inv[0]=1;
    for(int i=1;i<=N;i++) fac[i]=fac[i-1]*1ll*i%mod;
    for(int i=1;i<=N;i++) inv[i]=qpow(fac[i],mod-2);
    int l=0,r=n;
    while(l<r)
    {
        int mid=(l+r)/2;
        if(mid<=pos)
            l=mid+1,cnt1+=(mid<pos);
        else
            r=mid,cnt2++;
    }
    ll ans=1ll*P(x-1,cnt1)*
           P(n-x,cnt2)%mod*
           fac[n-cnt1-cnt2-1]%mod;
    printf("%lld\n",ans);
    return 0;
}


# include<iostream>
using namespace std;
int main () {
int n;
cin>>n;
if(n%2==0)
cout<<n/2;
else
cout<<n/2<<n.2+1;
return 0;


#include <iostream>

using namespace std;

int main()
{
  n = int(raw_input())
print " ".join(str(i+1) for i in range(20,-1,-1) if (n&(1<<i)) > 0)
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n,k,l,c,d,p,np,nl;
    cin>>n>>k>>l>>c>>d>>p>>nl>>np;//n, k, l, c, d, p, nl, np
    long long s=(k*l)/nl;
    long long q,m;
    q=c*d;
    m=p/np;
    cout<<s<<" "<<q<<" "<<m<<endl;
    q=min(q,min(m,s));
    q=q/n;
    cout<<q;
    return main();
}


#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:16777216")
#include <iostream>
#include <fstream>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <stdlib.h>
#include <string>
#include <list>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <sstream>
#include <assert.h>
#include <functional>
#include <climits>
#include <cstring>

typedef long long ll;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

using namespace std;

std::vector<__int64> F;

int main()
{
#if defined(_DEBUG) || defined(_RELEASE)
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
    //freopen(File".in", "r", stdin); freopen(File".out", "w", stdout);
#endif

//  return 0;
    //cout << "SDSD";
    F.push_back(1);
    F.push_back(1);
    ll c = 1;
//  cout << "SaaaaaD";
    while (F[c] < 10000000000000000000)
    {
        F.push_back(F[c - 1] + F[c]);
        c++;
    }
//  cout << "SDSD";
    __int64 n;
    cin >> n;
    __int64 k;
    cin >> k;
    ll printed=0;

    while (printed < n)
    {
        if (n - printed > c)
        {
            cout << 1 + printed << " ";
            printed++;
        }
        else
            if (k <= F[n-printed - 1])
            {
                cout << 1 + printed << " ";
                printed++;
            }
            else
            {
                cout << 2 + printed << " " << 1 + printed<<" ";
                k = k - F[n - 1 - printed];
                printed++;
                printed++;
            }

    }

    return 0;

}


#include<bits/stdc++.h>

using namespace std;

typedef long long int ll ;

 int   n , dp[55] = {0} ;

 ll k ;

 char s[55] ={'\0'};

 ll fibo ( int  p ) {

    if( p < 2 ){
        return ( dp[p] = 1 ) ;
    }

    return ( dp[p] = fibo(p-2) + fibo(p-1) ) ;

 }

void find_kth_per(  int index , int kth ) {

    //cout<<index<< "  " << kth <<endl;
    int i ;
    if ( index <= 0 ){return ;}
    //cout<<index<< "  " << dp[index-1]<<endl;
    if( kth <= dp[index-1] ){
           // cout<<"H"<<endl;

        s[n-index] = '1' ;
        int l = strlen(s) ;
        find_kth_per( index-1 , kth ) ;

        for ( i = l ; i <  strlen(s) ; i++ ){

            s[i] = s[i] + 1 ;
            //cout<<s[i]<< " ";

        }//cout<<endl;
       // s[i] = '\0' ;
    }
    else{
       // cout<<"e"<<endl;
        s[n-index] = '2' ;
        s[n-index+1] = '1' ;

        int l = strlen(s);

        find_kth_per( index-2 , kth-dp[index-1] ) ;

        for ( int i = l ; i <  strlen(s) ; i++ ){

            s[i] = s[i] + 2 ;

        }
        // s[i] = '\0' ;
    }

}

int main (  ) {

    cin>>n>>k;

    //ll num = fib( n ) ;
    dp[0] = 1 ;

    fibo( n ) ;

    /*cout<< fibo( n ) ;

    for ( int i = 1 ; i <= n ; i++ ){
        cout<<dp[i]<<" ";
    }cout<<endl;*/

    find_kth_per(  n , k ) ;

    for ( int i = 0 ; i < strlen(s) ; i++ ){

        cout<<s[i]-'0'<<" ";
    }cout<<endl;

    return 0;

}


#include<stdio.h>
#include<stdlib.h>
#include<algorithm>

using namespace std;
main(){
int m,n,k,g,j,h,d[2],s,q,w,e,r,a,t,i,f;
scanf("%d%d%d%d%d%d%d%d",&n,&m,&k,&a,&w,&t,&f,&g);
r=m*k/n/f;
e=t/n/g;
d[0]=r;
d[1]=e;
d[2]=w/n;
sort(d,d+3);
printf("%d\n",d[0]);
system("pause");}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
const LL p=1e9+7;
LL fac[1000010],inv[1000010];
void pre()
{
    fac[0]=fac[1]=inv[0]=inv[1]=1;
    for(LL i=2;i<=1000000;i++) fac[i]=fac[i-1]*i%p,inv[i]=(p-p/i)*inv[p%i]%p;
    for(LL i=2;i<=1000000;i++) inv[i]=inv[i-1]*inv[i]%p;
}
LL C(LL m,LL n) {return fac[m]*inv[m-n]%p*inv[n]%p;}
LL n,k,f[1000010];
int main()
{
	pre();
	scanf("%lld %lld",&n,&k);
	f[0]=1;
	for(LL i=1;i<=n;i++)
	{
		//printf("%lld:\n",i);
		for(LL j=0;j<=min(k-1,i-1);j++)
		{
			(f[i]+=f[i-j-1]*C(i-1,j)%p*fac[j]%p)%=p;
			//printf("%lld:%lld\n",j,f[i]);
		}
		//printf("\n");
	}
	LL ans=0;
	//for(int i=0;i<=n;i++) printf("%lld ",f[i]);printf("\n");
	for(LL i=1;i<=n;i++)
	{
		(ans+=f[i-1]*C(n-1,i-1)%p*fac[n-i]%p)%=p;
		//printf("%lld %lld\n",i,ans);
	}
	//for(int i=n-k+1;i<=n;i++) (ans+=C(n-1,i-1)*fac[n-i]%p*fac[i-1]%p)%=p;
	printf("%lld",(fac[n]-ans+p)%p);
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

void len(long long int p,vector<int> &num)
{
	while(p/10!=0)
	{
		num.push_back(p%10);
		p = p/10 ;
	}
	num.push_back(p);

}

int main()
{
	long long int p,d ;
	cin>>p>>d ;

	vector<long long int> tens(19);
	vector<long long int> nines(19);

	tens[1]= 10 ;
	nines[1]=9 ;

	for(int i=2;i<19;i++)
	{
		tens[i] = tens[i-1]*10 ;
		nines[i]= tens[i]-1 ;

	}
	vector<int> num;
	len(p,num);
	//num.push_back(0);
	int k = num.size() ;
	/*for(int i=0;i<k;i++)
	{
		cout<<num[i]<<endl;
	}*/
	long long int temp,temp2 = p  ;
	//cout<<k<<endl;
	for(int i=k-1;i>=0;i--)
	{
		temp =  ( num[i] - 1 )*tens[i] + nines[i] ;
		//cout<<temp<<endl;
		if(temp2 - temp<=d)
		{
			cout<< p - (temp2 - temp) <<endl;
			break;
		}
		temp2 = temp2 % tens[i] ;
		//cout<<"\t"<<temp2<<endl;

	}

	return 0;

}


#include<iostream>
 #include <math.h>

using namespace std;
const int N = 1000;

int max(int a, int b)
{
	if (a > b)
		return a;
	else
		return b;
}

int min(int a, int b)
{
	if (a<b)
		return a;
	return b;
}

int main()
{
	int n, m, a[N], b[N], c[N], d[N], cc, dd;

		cin >> n >> m >> cc >> dd;

		int **f = new int *[n+1];
		for (int i = 0; i < n+1; ++i)
			f[i] = new int[m+1];

		for (int i = 1; i <= m; i++)
			cin >> a[i] >> b[i] >> c[i] >> d[i];

		for (int i = 0; i <= n; i++) {
		    if (cc == 0) f[i][0]=0;
		    else
			f[i][0] = (int)(i / сc)*dd;

		}
		for (int j = 1; j <= m; j++)
			for (int i = 1; i <= n; i++)
			{
				int k = min((i / c[j]), (a[j] / b[j]));
				f[i][j] = f[i][j - 1];
				for (int y = 0; y <= k; y++)
					f[i][j] = max(f[i][j], f[i - y * c[j]][j - 1] + y * d[j]);
			}
		cout << f[n][m] << endl;

	}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int k;
  cin>>k;
  while (k)

  {
		char S[4][5];
		int count[10] = { 0 };
		bool b = true;
		for (int i = 0; i < 4; i++)
    {
			cin>>  S[i];
			for (int j = 0; j < 4; j++)
      {
				if (S[i][j] != '.')
					count[S[i][j] - '0']++;
			}
		}
		for (int i = 1; i <= 9; i++)
    {
			if (count[i]>k * 2)
				b = false;

  }
		if (b)
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}


// Example program
#include <iostream>
#include <string>
using namespace std;

int main()
{
  string x,s1;
  cin>>x;
  int i,j,f=0;
  int l=x.length();
      for(i=0;i<l;i++) if(x.at(i)!='0') s1+=x.at(i);
      for(i=0,j=l-1;i<(l/2),j>=(l/2);i++,j--) if(s1.at(i)!=s1.at(j)){
            f=1;
            break;
      }
      if(f==1) cout<<"NO\n";
      else cout<<"YES\n";
      return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define ph push_back
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   ll a[3];
   cin>>a[0]>>a[1]>>a[2];
   sort(a,a+3);
   cout<<(ll) a[0]*((2*a[1])+(2*a[2])-a[0]-3);
}


#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

#define inc(i,a,b)              for(int i=a;i<b;++i)
#define dec(i,a,b)              for(int i=a;i>b;--i)

#define ll                      long long

ll n, sx, sy, dx, dy, t;

const ll b[6][6] = {
    { 2, 1, 1, 0, 1, 2 },
    { 1, 2, 0, 1, 1, 2 },
    { 1, 1, 1, 0, 1, 2 },
    { 1, 1, 0, 1, 1, 2 },
    { 0, 0, 0, 0, 1, 1 },
    { 0, 0, 0, 0, 0, 1 },
};
const ll i2[6][6] = {
    { 1, 0, 0, 0, 0, 0 },
    { 0, 1, 0, 0, 0, 0 },
    { 0, 0, 1, 0, 0, 0 },
    { 0, 0, 0, 1, 0, 0 },
    { 0, 0, 0, 0, 1, 0 },
    { 0, 0, 0, 0, 0, 1 },
};

struct matrix {
    ll m[6][6];
}base, ident;

matrix operator* (const matrix &a, const matrix &b) {
    matrix c;

    inc(i,0,6) inc(j,0,6) {
        c.m[i][j] = 0;

        inc(k,0,6) {
            c.m[i][j] += a.m[i][k]*b.m[k][j]+n;
            c.m[i][j] %= n;
        }
    }

    return c;
}

matrix power(ll p) {
    if(p==0) return ident;
    if(p==1) return base;

    return (power(p/2)*power(p/2)*power(p&1));
}

void printMatrix(const matrix &a) {
    inc(i,0,6) {
        inc(j,0,6) {
            cerr << a.m[i][j] << " ";
        }
        cerr << "\n";
    }
}

int main() {
    cin >> n >> sx >> sy >> dx >> dy >> t;
    sx--, sy--;

    memcpy(ident.m,i2,sizeof(i2));
    memcpy(base.m,b,sizeof(b));

    matrix res = power(t);

    matrix start;
    inc(i,0,6) inc(j,0,6) start.m[i][j] = 0;
    start.m[0][0] = sx, start.m[1][0] = sy, start.m[2][0] = dx, start.m[3][0] = dy, start.m[4][0] = 0, start.m[5][0] = 1;

    matrix finale = res*start;
//     printMatrix(finale);
    cout << finale.m[0][0]+1 << " " << finale.m[1][0]+1 << "\n";
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#define PI 3.1415926535898
#define INF 10000009
#define N 22
using namespace std;
int n,sx,sy,dx,dy;
long long t,T;
int main()
{
    cin>>n>>sx>>sy>>dx>>dy>>T;
    while(t<T){
        long long k=sx+sy+t;
        dx=(dx+k)%n;
        dy=(dy+k)%n;
        sx=sx+dx;
        sy=sy+dy;
        t++;
    }
    sx=(sx-1)%n+1;
    sy=(sy-1)%n+1;
    cout<<sx<<" "<<sy<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
  int n,i,len,flag;
  string s,ans="";
  cin>>s;
  len=s.length();
  i=0;
  if(s[0]=='d' || s[0]=='a') {
    i++;
    ans+=s[0];
  }
  flag=1;
  for( ;i<len; ) {
    if(s[i]=='d' && i+1<len && s[i+1]=='o' && i+2<len && s[i+2]=='t') {
      ans+='.';
      i=+3;
    }
    else if(flag && s[i]=='a' && i+1<len && s[i+1]=='t') {
      ans+='@';
      i+=2;
      flag=0;
    }
    else {
      ans+=s[i];
      i++;
    }
  }
  len=ans.length();
  if(ans[len-1]=='.') {
    ans[len-1]='d';
    ans+="ot";
  }
  cout<<ans<<endl;

  return 0;
}


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

int main()
{
    long long a,b;
    scanf("%lld %lld",&a,&b);
    vector<long long> p2;
    long long temp=1;
    while(temp<=10000000000000000000)
    {
        p2.push_back(temp);
        temp*=2;
    }
    p2.push_back(temp-1);
    long long ans=0;
    for(int i=2;i<p2.size();i++)
    {
        for(int j=0;j<(i-1);j++)
        {
            long long bk=(p2[i]-1-p2[j]);
            if(bk>=a&&bk<=b)
            {
                ans++;
            }

        }
    }
    printf("%lld",ans);
}


#include <iostream>
#include <stdio.h>
#include <map>
#include<unordered_map>
using namespace std;

unordered_map < ll,ll > dp;
bool p[1000005];
bool is( long long N ){
    if( N < 2 )return false;
    for( long long i = 2 ; i*i <= N ; ++i ){
        if( N%i == 0 ){
            return false;
        }
    }
    return true;
}
long long DP( long long N , long long lastp ){
   if( N == 1 )return 1;
    long long H = N*100000000000007 + lastp;
    if( dp.count(H) )return dp[H];
    long long  sol=0;
    if( is(N-1) && (N-1)> astp )++sol;
    for( long long i = lastp+1 ; i*i <= N ; ++i ){
        if( p[i] == 0 ){
            long long aux = i;
            while( (aux + 1) <= N ){
                if( N%(aux+1) == 0 )
                    sol += DP( N/(aux+1) , i );
                aux *= i;
            }
        }
    }
    dp[N]=sol;
    return sol;
}
ll A,B;
int main(){
    cin.sync_with_stdio(false);
    cin.tie(0);
    p[1]=p[0]=1;
    for( int i = 2 ; i <= 1000001 ; ++i )
        if( p[i] == 0 )
            for( int j = i+i ; j <= 1000001 ; j+=i )p[j]=1;
    cin >> A;
    cout << DP(A,1) << endl;
}


#include <iostream>
#include <stdio.h>
#include <map>
#include<unordered_map>
using namespace std;

unordered_map < long long,long long > dp;
bool p[1111111];
bool is( long long N ){
    if( N < 2 )return false;
    for( long long i = 2 ; i*i <= N ; ++i ){
        if( N%i == 0 ){
            return false;
        }
    }
    return true;
}
long long DP( long long N , long long lastp=1 ){
   if( N == 1 )return 1;
    long long H = N*100000000000007 + lastp;
    if( dp.count(H) )return dp[H];
    long long  sol=0;
    sol = (N - 1 > lastp) && is(A - 1);
    for( long long i = lastp+1 ; i*i <= N ; ++i ){
        if( !p[i] ){
            long long aux = i;
            while( (aux + 1) <= N ){
                if( N%(aux+1) == 0 )
                    sol += DP( N/(aux+1) , i );
                aux *= i;
            }
        }
    }
    return dp[N]=sol;
}
long long A,B;
int main(int argc, char *argv[]){
    //cin.sync_with_stdio(false);
    //cin.tie(0);
   // p[1]=p[0]=1;
    for( int i = 2 ; i < 1111111 ; ++i )
        if( !p[i] )
           for (long long j = 2; i * j < 1111111; ++j) p[i * j] = true;
    cin >> A;
    cout << DP(A) << endl;
    return 0;
}


#include <iostream>
#include<stdio.h>
using namespace std;

int main()
{
	int i,a1,a2,b1=1,b2=1,n;
	b1=1;b2=1;
	scanf("%d %d",&a1,&a2);
	for(i=1;i<=a1;i++)
		b1*=i;
	for(i=1;i<=a2;i++)
		b2*=i;
	if(a1==0||a2==0)
		printf("%d",0);
	else
		if(b1>b2)
			printf("%d",b2);
		else
			printf("%d",b1);
    return 0;
}


#include <cstdio>
#include <iostream>
int main() {
	long long int n;
	cin>>n;
	n = (n % 360 + 360) % 360;
	n = (n + 45) % 360;
	cout<<(n - 1) / 90;
	return 0;
}


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

int main(){
int k,a[4][4],b[9];
cin>>k;
memset(b,0,sizeof b);
for(int i=0;i<4;i++)
    for(int j=0;j<4;j++)
      {
        cin>>a[i][j];
        b[a[i][j]]++;
      }
for(int i=1;i<=9;i++)
      if(b[i]>2*k){
            cout<<"NO";
            return 0;
      }
cout<<"YES";
return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define inll(n) scanf("%I64d",&n)
#define inll2(n,m) scanf("%I64d%I64d",&n,&m)
#define outll(n) printf("%I64d\n",n)
#define outll(n) printf("%I64d\n",n)
#define outll2(n,m) printf("%I64d %I64d\n",n,m)

int main()
{
    queue< pair< pair<int,int>,int > > arr;
    //while(1)
    {
        int r,x,y,x1,y1,val;
    scanf("%d%d%d%d%d",&r,&x,&y,&x1,&y1);
    arr.push(make_pair(make_pair(x,y),0));
      while(1)
        {
            int lol1,lol2,lol3;
            x=arr.front().first.first;
            y=arr.front().first.second;
            val=arr.front().second;
            arr.pop();
            if(x==x1 && y==y1)
            {
                cout<<val<<endl;
                return 0;
            }
        else
        {
            int p1,p2,z1x,z1y,z2x,z2y,z3x,z3y,ok1x,ok1y,ok2x,ok2y,ok3x,ok3y;
            int ok4x,ok4y;
            //case 1

            p1=r+x;
            p2=y;
            z1x=p1;
            z1y=p2+r;
            z2x=p1;
            z2y=p2-r;
            z3x=p1+r;
            z3y=p2;
            int lol1,l1,bakar;
            lol1=abs(z1x-x1)+abs(z1y-y1);

                arr.push(make_pair(make_pair(z1x,z1y),val+1));

            l1=abs(z2x-x1)+abs(z2y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z2x,z2y),val+1));
            }
            l1=abs(z3x-x1)+abs(z3y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z3x,z3y),val+1));
            }
            //cout<<"1 "<<ok1x<<" "<<ok1y<<endl;
            //case2
            p1=x;
            p2=r+y;
            z1x=p1+r;
            z1y=p2;
            z2x=p1;
            z2y=p2+r;
            z3x=p1-r;
            z3y=p2;
 lol1=abs(z1x-x1)+abs(z1y-y1);

                arr.push(make_pair(make_pair(z1x,z1y),val+1));

            l1=abs(z2x-x1)+abs(z2y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z2x,z2y),val+1));
            }
            l1=abs(z3x-x1)+abs(z3y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z3x,z3y),val+1));
            }
            //cout<<"2 "<<ok2x<<" "<<ok2y<<endl;
            //case3
            p1=x-r;
            p2=y;
            z1x=p1;
            z1y=p2+r;
            z2x=p1;
            z2y=p2-r;
            z3x=p1-r;
            z3y=p2;
 lol1=abs(z1x-x1)+abs(z1y-y1);

                arr.push(make_pair(make_pair(z1x,z1y),val+1));

            l1=abs(z2x-x1)+abs(z2y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z2x,z2y),val+1));
            }
            l1=abs(z3x-x1)+abs(z3y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z3x,z3y),val+1));
            }
            //case4
            p1=x;
            p2=y-r;
            z1x=p1+r;
            z1y=p2;
            z2x=p1;
            z2y=p2-r;
            z3x=p1-r;
            z3y=p2;
 if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z1x,z1y),val+1));
            }
            l1=abs(z2x-x1)+abs(z2y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z2x,z2y),val+1));
            }
            l1=abs(z3x-x1)+abs(z3y-y1);
            if(l1<=lol1)
            {
                arr.push(make_pair(make_pair(z3x,z3y),val+1));
            }
    }
//    printf("%d\n",ans);

    }
    }
}
//     \ ||


#include <stdio.h>

int main() {
	int n, k, l, c, d, p, nl, np;

	scanf("%d%d%d%d%d%d%d%d", &n, &k, &l, &c, &d, &nl, &np);

	k*=l;
	k/=nl;

	c*=d;

	p/=np;

	if (k > c && k > p) {
		printf("%d\n", k/n);

	} else if (c > p && c > k) {
		printf("%d\n", c/n);
	} else if (p > k && p > c) {
		printf("%d\n", p/n);
	}

	return 0;
}


/*
ID:   cs_diab1
TASK:
LANG: C++
*/

#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<sstream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<queue>
#include<set>

#define stop exit(0)
#define nc -1
#define eps 1e-10
#define inf 1000000000
#define mp make_pair

#define fill(array,value) memset(array,value,sizeof(array))
#define f(i,beg,end) for(int i=beg; i<=end; i++)
#define F(i,beg,end) for(int i=beg; i>=end; i--)
#define Max(a,b) ( (a>b)?a:b )
#define Min(a,b) ( (a<b)?a:b )
#define pi 3.1415926535897932384626433832
#define iread(var) scanf("%d",&var)
#define dread(var) scanf("%f",&var)
#define lread(var) scanf("%lld",&var)
#define input(name) freopen(name,"r",stdin)
#define output(name) freopen(name,"w",stdout)
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef long long ll;

using namespace std;

int n,k,l,c,d,p,nl,np;

void init()
{
    cin>>n>>k>>l>>c>>d>>p>>nl>>np;
    int x1, x2, x3;
    x1=k*l; x1/=n;
    x2=c*d;
    x3=p/np;
    int sol=Min(Min(x1,x2),x3);
    if (sol<n) sol=1;
    else sol/=n;

    cout<<sol<<endl;
}

int main()
{
    //redirect();
    input("test.txt");
    init();

    return 0;
}


/*
*  Author:      illuz <iilluzen[at]gmail.com>
*  File:        3555.cpp
*  Create Date: 2014-07-26 16:04:07
*  Descripton:  digit dp
*/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;
#define RI(x) scanf("%d",&x)
#define PIN(x) printf("%d\n",x)

typedef  long long ll

int t;
int bit[N];
ll DP[20][(1<<8)][2520];

//    pos    = 当前处理的位置(一般从高位到低位)
//    pre    = 上一个位的数字(更高的那一位)
//    status = 要达到的状态,如果为1则可以认为找到了答案,到时候用来返回,
//         　　 给计数器+1。
//    limit  = 是否受限,也即当前处理这位能否随便取值。如567,当前处理6这位,
//         　　 如果前面取的是4,则当前这位可以取0-9。如果前面取的5,那么当前
//         　　 这位就不能随便取，不然会超出这个数的范围,所以如果前面取5的
//         　　 话此时的limit=1,也就是说当前只可以取0-6。
//
//    用DP数组保存这三个状态是因为往后转移的时候会遇到很多重复的情况。
ll   dfs(int pos,int pre,int status,int limit)
{
    //已结搜到尽头,返回"是否找到了答案"这个状态。
    if(pos < 1)
    {
    	for(int i = 0;i < 8;i ++)
    	{
    		if((pre&(1<<i))&&(status%(i + 2)!=0))
    			return 0;
    	}
    	return 1;
    }

    //DP里保存的是完整的,也即不受限的答案,所以如果满足的话,可以直接返回。
    if(!limit && DP[pos][pre][status] != -1)
        return    DP[pos][pre][status];

    int    end = limit ? bit[pos] : 9;
    ll    ret = 0;

    //往下搜的状态表示的很巧妙,status用||是因为如果前面找到了答案那么后面
    //还有没有答案都无所谓了。而limti用&&是因为只有前面受限、当前受限才能
    //推出下一步也受限，比如567,如果是46X的情况,虽然6已经到尽头,但是后面的
    //个位仍然可以随便取,因为百位没受限,所以如果个位要受限,那么前面必须是56。
    //
    //这里用"不要49"一题来做例子。
    for(int i = 0;i <= end;i ++)
    {
    	if(i>=2)
        ret += dfs(pos - 1,(pre|(1<<(i-2))),(status*10+i)%2520,limit && (i == end));
        else
        ret += dfs(pos - 1,pre,(status*10+i)%2520,limit && (i == end));
    }

    //DP里保存完整的、取到尽头的数据
    if(!limit)
        DP[pos][pre][status] = ret;

    return ret;
}
ll solve(ll n) {
	int len = 0;
	while (n) {
		bit[++len] = n % 10;
		n /= 10;
	}
	bit[len + 1] = 0;
	return dfs(len,0,0,1);
}

int main() {
//	freopen("in.txt","r",stdin);
//	freopen("luo.txt","w",stdout);
memset(DP, -1, sizeof(DP));
	__int64 n,m;
	int t;
	scanf("%d",&t);
	while (t --) {
		scanf("%I64d %I64d",&n,&m);
//		if(n == 0&&m == 0) break;

        printf("%I64d\n",(solve(m)-solve(n-1)));
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
char *decimal_to_binary(long long x)
{
    char *s = new char[100];
    if (x == 0)
    {
        s[0] = '0';
        s[1] = NULL;
        return s;
    }
    long long nr = 0, i, j;
    while (x != 0)
    {
        if (x % 2 == 0)
        {
            s[nr] = '0';
        }
        else
        {
            s[nr] = '1';
        }
        nr++;
        x = x / 2;
    }
    s[nr] = NULL;
    char *ans = new char[100];
    ans[nr] = NULL;
    for (i = 0; i < nr; i++)
    {
        ans[nr - i - 1] = s[i];
    }
    return ans;
}
int main()
{
    long long a, b, sum = 0;
    long long i, n1, n2, j, nr;
    cin >> a >> b;
    for (i = a; i <= b; i++)
    {
        char *s = decimal_to_binary(i);
        n1 = strlen(s);
        nr = 0;
        for (j = 0; j < n1; j++)
        {
            if (s[j] == '0')
            {
                nr++;
            }
            if (nr == 2)
            {
                break;
            }
        }
        if (nr == 1)
        {
            sum++;
        }
        delete s;
    }
    cout << sum << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main() {
    long long x;
    cin >> x;

    x = (x % 360 + 360) % 360;
    if(x >= 225 and x < 315) cout << 1 << '\n';
    else if(x >= 135 and x < 225) cout << 2 << '\n';
    else if(x >= 45 and x < 135) cout << 3 << '\n';
    else cout << cout << 0 << '\n';
}


#include <iostream>
#include <string>
using namespace std;

int main() {
    int n,a=0;
    string x;
    cin>>n;

int b=0;
for(int j=0;j<n;j++){
    cin>>x[j];
    if(x[j]=='x')
    a++;
    if(a==3&&x[j-1]=='x'&&x[j-2]=='x'){
        b++;
        a=2;
    }

}
 cout<<b;
return 0;
}


#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;

int main()
{
    long long ourNum = 1, n,
    first = 0,
    second = 1,
    result,
    resultIndex = 0;
    cin >> n;
        while (n > ourNum)
        {
            result = first + second;
            ourNum += result;
            first = second;
            second = result;
            resultIndex++;
        }
    //if (resultIndex == 46) cout << 45
    else
    cout << resultIndex;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    long long a,b;
    cin>>a>>b;
    ll mx=0;
    for(ll i=a;i<=b;i++){
        ll sum=0;
        ll ss=1;
        ll j=i;
        while(j){
            sum=sum+ss*(9-(j%10));
            j/=10;
            ss*=10;
        }
        mx=max(mx,sum*i);
    }
    cout<<mx<<endl;
}


#pragma comment(linker, "/stack:640000000")

#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<stdio.h>
using namespace std;
#define ll long long int
#define scanl(a) scanf("%lld",&a)
#define scanii(a,b) scanf("%d%d",&a,&b)
#define scaniii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scanll(a,b) scanf("%lld%lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scani(a) scanf("%d",&a)
#define clr(a) memset(a,0,sizeof(a))
#define clr_(a) memset(a,-1,sizeof(a))
#define pb(a) push_back(a)
#define pii pair<int,int>
#define sqr(a) a*a
#define eps 1e-9
#define inf INT_MAX
#define pi acos(-1.0)
#define ff first
#define ss second
#define INF (ll)1e18
#define m_p make_pair
#define vsort(v) sort(v.begin(),v.end())
#define all(v) v.begin(),v.end()
#define UNIQUE(X) sort(all(X)) X.resize( unique( all(X)) - X.begin() )
int fx[]={0,0,-1,1,-1,1,1,-1};
int fy[]={1,-1,0,0,1,1,-1,-1};
ll lcm(ll a,ll b){return (a/__gcd(a,b))*b;}
ll bigmod(ll a,ll p,ll mod){ll ans=1;while(p){if(p&1)ans=ans*a%mod;a=a*a%mod;p>>=1;}return ans;}
ll power(ll x,ll n){if(n==0)return 1;else if(n%2==0){ll y=power(x,n/2);return y*y;}else return x*power(x,n-1);}
struct point{double x,y;point(){}point(double xx,double yy){x=xx;y=yy;}};
inline double Distance(point  a,point b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
#ifdef shaft
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " is " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cerr.write(names, comma - names) << " is " << arg1 <<endl;
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif
string s;
int n;
int dp[100][101][101][101];
int call(int pos , int x , int y , int tot){
    if(pos >= n) {
            if(x == 0 && y == 0) return tot;
            return 0;
    }
    int ans;
    if(x >=0 && y >= 0){
    if(dp[pos][x][y][tot] != -1)return dp[pos][x][y][tot];
    }
    ans = call(pos + 1, x , y , tot);
    int xx = x, yy = y;
    if(s[pos] == 'U') yy = y + 1;
    if(s[pos] == 'D') yy = y - 1;
    if(s[pos] == 'L') xx = x - 1;
    if(s[pos] == 'R') xx = x + 1;
    int p2 = call(pos + 1 , xx , yy , tot + 1);
    ans = max(ans,p2);
    if(x >= 0 && y >=0){
        dp[pos][x][y][tot] = ans;
    }
    return ans;

}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    #ifdef shaft
       // freopen("in.txt","r",stdin);
        ///freopen("out.txt","w",stdout);
    #endif ///shaft
    cin>>n;
    clr_(dp);
    cin >> s;
    cout<<call(0 , 0 , 0 , 0)<<endl;
    return 0;
}


#include <bits/stdc++.h>

#define ft first
#define sc second
#define all(v) v.begin(), v.end()
#define PB push_back
#define MP make_pair
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl

typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const double PI = atan(1)*4;

ll add(ll x, ll y)
{
	x += y;
	while (x >= MOD) x -= MOD;
	while (x < 0) x += MOD;
	return x;
}

ll sub(ll x, ll y)
{
	return add(x, -y);
}

ll mul(ll x, ll y)
{
	return (x * y) % MOD;
}

ll binpow(ll x, ll y)
{
	ll z = 1;
	while (y > 0)
	{
		if (y % 2 == 1) z = mul(z, x);
		x = mul(x, x);
		y /= 2;
	}
	return z;
}

ll inv(ll x)
{
	return binpow(x, MOD - 2);
}

ll divide(ll x, ll y)
{
	return mul(x, inv(y));
}

vector<ll> factorial(1,1);

ll fact(ll n){
    while (factorial.size() < n+5){
    factorial.PB(mul(factorial.size(), factorial.back()));
    }

    return factorial[n];
}

ll nChoosek( ll n, ll k ){
    if ((k>n) || (k<0)) return 0;
    ll sz = factorial.size();
    while (sz < n + 1){
        factorial.PB(mul(factorial.size(), factorial.back()));
        sz++;
    }
    return divide(factorial[n], mul(factorial[k], factorial[n-k]));
}

void solve() {
    ll n, x, pos;
    cin >> n >> x >> pos;
    ll lh, rh = 0;
    ll l = 0;
    ll r = n;

    while (l < r){
        ll middle = (l + r)/2;
        if (middle == pos) l = r;
        else if (middle < pos) {
            l = middle + 1;
            rh++;
        }
        else{
            r = middle;
            lh++;
        }
    }
    ll cl = mul(fact(lh), nChoosek(n-x, lh));
    ll cr = mul(fact(rh), nChoosek(x-1, rh));
    cout << mul(mul(cl, cr), fact(n-1-lh-rh));

}

int main() {
    cin.tie(0), cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
      solve();
      cout << '\n';
    }
}


#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
#define pii pair <ll, ll>

using namespace std;

const int MAXN = 35000000;
const int MOD = 1e9 + 7;
bool prime[MAXN + 10];
vector <ll> primes;
vector <pair <ll, int> > fact;
vector <ll> divi;
pii dp[70000][10002];

ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

void sito() {
  FOR(i, 2, MAXN) {
    if (prime[i]) continue;

    primes.push_back((ll) i);
    for (int j = i + i; j < MAXN; j += i) prime[j] = true;
  }
  return;
}

void rek(int x, ll a) {
  if (x == fact.size()) {
    divi.push_back(a);
    return;
  }

  ll tr = 1;
  REP(i, fact[x].second + 1) {
    rek(x + 1, a * tr);
    tr *= fact[x].first;
  }
  return;
}

pii add(pii a, pii b) {
  ll A = (ll) a.first * b.second + (ll) b.first * a.second;
  ll B = (ll) a.second * b.second;
  //ll C = gcd(A, B);

  return {A % MOD, B % MOD};
}

pii mul(pii a, pii b) {
  ll A = (ll) a.first * b.first;
  ll B = (ll) a.second * b.second;
  //ll C = gcd(A, B);

  return {A % MOD, B % MOD};
}

ll pot(ll x, ll a) {
  ll out = 1, pot = x;
  while (a) {
    if (a & 1) out = (out * pot) % MOD;
    pot = (pot * pot) % MOD;
    a >>= 1;
  }
  return out;
}

int main() {
  ios_base::sync_with_stdio(false);
  sito();

  REP(i, 100000) {
    REP(j, 55) {
      dp[i][j] = {-1, -1};
    }
  }

  ll n, nn;
  int k;
  cin >> n >> k;
  nn = n;

  for (int x : primes) {
    int t = 0;
    while (n % x == 0) {
      n /= x;
      t++;
    }
    if (t > 0) fact.push_back({x, t});
  }
  if (n > 1) fact.push_back({n, 1});

  rek(0, 1);
  sort(divi.begin(), divi.end());

  REP(x, divi.size()) {
    REP(y, k + 1) {
      if (x == 0) {
        dp[x][y] = {1, 1};
        continue;
      }
      if (y == 0) {
        dp[x][y] = {divi[x], 1};
        continue;
      }

      pii tr = {0, 1};
      int tt = 0;
      REP(i, x + 1) {
        if (divi[x] % divi[i] == 0) {
          tr = add(tr, dp[i][y - 1]);
          tt++;
        }
      }
      tr = mul(tr, {1, tt});

      dp[x][y] = tr;
    }
  }

  pii out = dp[divi.size() - 1][k];
  ll sol = (out.first * pot(out.second, MOD - 2)) % MOD;
  cout << sol << "\n";

  return 0;
}


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

int main(){

    int a, b; cin >> a >> b;
    int cnt1=0, cnt2=0;
    while(a>0 && b>0)
    {
        a--;
        b--;
        cnt1++;
    }
    int maxi=max(a,b);
    while(maxi%2==0)
    {
        maxi/=2;
        cnt2++;
    }
    cout << cnt1 << " " << cnt2;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int m,n;
    cin>>m>>n;
    int dp = 0, sp = 0 ;
    while(m || n)
    {
        if (m && n)
        {
        --m,--n;
        dp += 1;
        }
        else if (m == 0 &&  n > 1)
        {
            sp += 1;
            n = n-2;
        }
        else if (n == 0 && m > 1)
        {
            sp += 1;
            m = m-2;
        }

    }cout<<dp<<" "<<sp<<" ";
    return 0;
}


#include<iostream>
#include<string>
#include<cstring>
using namespace std;

string a,b,c;
int dp[105][105][105],choice[105][105][105];
int pi[105];
int pos[105][26];

void computePi()
{
    int i,j,k=0;
    pi[0]=0;
    for(i=1;i<c.size();i++)
    {
        while(k && c[i]!=c[k]) k=pi[k];
        if(c[i]==c[k]) k++;
        pi[i]=k;
    }
}

void precalPos()
{
    int i,j,k;
    for(i=0;i<26;i++)
    {
        for(j=0;j<c.size();j++)
        {
            k=j;
            while(k && c[k]!='A'+i) k=pi[k];
            if(c[k]=='A'+i) k++;
            pos[j][i]=k;
        }
    }
}
int calc(int x,int y,int z)
{
    int &ret=dp[x][y][z];
    int &ch=choice[x][y][z];
    if(ret!=-1) return ret;
    if(x==a.size() || y==b.size()) return 0;
    ret=0;
    if(calc(x+1,y,z)>ret) ret=calc(x+1,y,z),ch=1;
    if(calc(x,y+1,z)>ret) ret=calc(x,y+1,z),ch=2;
    if(a[x]==b[y])
    {
        if(a[x]==c[z] && z+1<c.size() && 1+calc(x+1,y+1,z+1)>ret) ret=1+calc(x+1,y+1,z+1),ch=3;
        else if(a[x]!=c[z])
        {
            //while(z && c[z]!=a[x]) z=pi[z];
            //if(c[z]==a[x]) z++;
            z=pos[z][a[x]-'A'];
            if(1+calc(x+1,y+1,z)>ret) ret=1+calc(x+1,y+1,z),ch=3;
        }
    }
    return ret;
}
void print_ans(int x,int y,int z)
{
    //cout<<x<<" "<<y<<" "<<z<<endl;
    if(x==a.size() || y==b.size()) return;
    if(choice[x][y][z]==3)
    {
        cout<<b[y];
        if(a[x]==c[z]) print_ans(x+1,y+1,z+1);
        else
        {
            //while(z && c[z]!=a[x]) z=pi[z];
            //if(c[z]==a[x]) z++;
            z=pos[z][a[x]-'A'];
            print_ans(x+1,y+1,z);
        }
    }
    else if(choice[x][y][z]==1) print_ans(x+1,y,z);
    else print_ans(x,y+1,z);
}
int main()
{
    cin>>a>>b>>c;
    memset(dp,-1,sizeof(dp));
    computePi();
    precalPos();
    int x=calc(0,0,0);
    if(x) print_ans(0,0,0);
    else cout<<0;
    cout<<endl;
    return 0;
}


//! Bismillahi-Rahamanirahim.
/** ========================================**
 ** @Author: Md. Abu Farhad ( RUET, CSE'15)
 ** @Category:
/** ========================================**/

#include<bits/stdc++.h>
#include<stdio.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;

#define ll                  long long
#define scl(n)              scanf("%lld",&n)
#define scc(c)	            scanf("%c",&c)
#define fr(i,n)             for (ll i=0;i<n;i++)
#define fr1(i,n)            for(ll i=1;i<=n;i++)
#define pfl(x)              printf("%lld\n",x)
#define pb                  push_back
#define debug               cout<<"I am here"<<endl;
#define pno                 cout<<"NO"<<endl
#define pys                 cout<<"YES"<<endl

#define l(s)                s.size()
#define asort(a)            sort(a,a+n)
#define all(x) 	            (x).begin(), (x).end()
#define dsort(a)            sort(a,a+n,greater<int>())
#define vasort(v)           sort(v.begin(), v.end());
#define vdsort(v)           sort(v.begin(), v.end(),greater<int>());
#define uniquee(x)          x.erase(unique(x.begin(), x.end()),x.end())
#define pn                  printf("\n")
#define el                  cout<<endl
#define md                  1000000007
#define inf                 1e18
#define ps                  cout<<" ";
#define Pai                  acos(-1.0)
#define pr                  pair<ll, ll>
#define ff                  first
#define ss                  second
#define mem(a,i)            memset(a, i, sizeof(a))
#define tcas(i,t)           for(ll i=1;i<=t;i++)
#define pcas(i)             cout<<"Case "<<i<<": "<<endl;
#define fast 	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

ll bigmd(ll b, ll p)
{
    //debug;
    ll ans=1;
    while(p)
    {
        if(p&1)ans=(ans*b)%md;
        p>>=1;
        b=(b*b)%md;
    }
    return ans%md;
}

#define N 100000006
bool prime[N];
void sieve()
{
   // debug;

    ll i, j;
    mem(prime , 1);
    prime[1]=0;
    for(i=4; i<=N; i+=2)prime[i]=0;
    for(i=3; i*i<=N; i++)
    if(prime[i])
    {
        for(j=i*i; j<=N; j+=i)prime[j]=0;
    }
}
ll num[N];

int main()
{
    ll m,n,b,c,d,i,j,k,x,y,z,l,q,r;
    string s,s1, s2, s3, s4;

    sieve();
    //fr1(i, 20)if(prime[i])cout<<i<<" "; pn;

    ll cnt=0,ans=0,sum=0;
    cin>>x>>n;

    for(i=2; i<=sqrt(x); i++)
    {
        //debug;
        if(prime[i]  and x%i==0) num[cnt++]=i ;//, cout<<i<<" ";
        if(prime[x/i]  and x%i==0  and i!=(x/i) )num[cnt++]=x/i ;//, cout<<x/i<<" ";
    }
    if(cnt==0)num[cnt++]=x;

    ll res=1;
    fr(i, cnt)
    {
        ll tmp=n, ans=0;
        while(tmp>=num[i])
        {
            tmp/=num[i];
            ans+=tmp;
        }
        //cout<<num[i]<<" "<<ans<<endl;

        res*=bigmd(num[i] , ans)%md;
        //cout<<res<<endl;

        res%=md;
    }

    cout<<res<<endl;

return 0;
}

///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1


#include <iostream>
using namespace std;
int main(){
int n, k=0;
string s,q="xxx";
cin>>n>>s;
int i=0;
while(true){
	if(s.substr(i,3)==q) { k++; if(s.length()==3) {cout<<k; return 0;}
	s.erase(0,i+3);
	for(int j = 0;j < s.length();j++){
		if(s[j]=='x') {k++; if(j==s.length()-1){cout<<k; return 0;	} 	}
		else {s.erase(0,j+1); j=s.length(); i=-1;}
			}
		}
	i++;
	if(i==s.length()-1){cout<<k; return 0;	}
	}
cout<<k;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s ;
    cin >> s ;
    int k = 0 ;
    if ( s.find ("at") != 0 )
        s.replace ( s.find("at") , 2 , "@" ) ;

    for ( int i = 1 ; i < s.size() - 4  ; i++ )
    {
        if ( s.find ("dot") == 0 )
           k = 1 ;

        if ( s.find ("dot") != -1 )
            s.replace ( s.find ("dot") , 3 , "." ) ;
    }

    if ( k == 1 )
        s.replace (0 , 1 , "dot") ;

    cout << s ;

    return 0 ;
}


#include <cmath>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<cctype>

using namespace std;

long counter;

//map<pair<int, pair<int, int> >, int> m;

vector<vector<vector<int> > > v(300001, vector<vector<int> >(300001, vector<int>(300001, -1)));

void  isPossible(int a, int b, int c, int l){

    float s = (float)(a + b + c) / 2.0;

//  cout << "s: " << s << " a: " << a << " b: " << b << " c: " << c << endl;
    if (s > a && s > b && s >c  && (v[a][b][c]  == -1) ) {

        //m.find(make_pair(a, make_pair(b, c))) == m.end()
        //m[make_pair(a, make_pair(b, c))] = 1;
    //  cout << "In the loop" << endl;
        v[a][b][c] = 1;
        counter++;
    }

    for (int i = 1; i <= l; i++){

        isPossible(a + i, b, c, l - i);
        isPossible(a , b + i, c, l - i);
        isPossible(a, b, c + i, l - i);

        //cout << "HI " << endl;

    }

}

int main(){

    int a, b, c, l;
    cin >> a >> b >> c >> l;

    counter = 0;

    isPossible(a, b, c , l);

    cout << counter << endl;

    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <stack>
#include <set>
#include <map>

using namespace std;

#define name ""
#define inf	int(1e9)
#define eps 1e-9
#define FOR(i,a,b) for(int i = a; i <= b; ++ i)
#define REP(i,n) FOR(j,0,n-1)
#define all(x) x.begin(), x.end()
#define SZ(x) int(x.size())
#define fi first
#define se second
#define MP make_pair
#define PB push_back

int n, m, T;
int a[11][101],	b[11][101],	c[11][101];
int ans = 0, X = 0, Y = 0;

int main(){

	cin >> n >> m >> T;

	string s[11];

	for (int i = 0 ; i < n; ++ i) {
	 	cin >> s[i];
	 	for (int j = 0; j < m; ++ j) {
	 	 	cin >> a[i][j] >> b[i][j] >> c[i][j];
	 	}
	}

	for (int i = 0; i < n; ++ i) {
	 	for (int k = 0; k < n; ++ k) if(i != j) {
	 		int x1 = 0,
	 			y1 = 0,
	 			t1 = 0;
	 		vector<pair<int,int> > q;
	 	 	for (int j = 0; j < m; ++ j) {
	 	 	 	if (b[k][j] - a[i][j] > 0) {
	 	 	 		q.push_back(make_pair(b[k][j] - a[i][j], j));
//	 	 	 	 	x1 += a[i][j]*c[i][j];
//	 	 	 	 	y1 += b[k][j]*c[i][j];
	 	 	 	}
	 	 	}

	 	 	sort(q.rbegin(), q.rend());

	 	 	for (int j = 0; j < q.size(); ++ j) {
	 	 		int p = q[j].se;

	 	 		if (t1 + c[i][p] <= T) {
	 	 	 	 	x1 += a[i][p]*c[i][p];
	 	 	 	 	y1 += b[k][p]*c[i][p];
	 	 	 	 	t1 += c[i][p];
	 	 		} else {
	 	 	 	 	x1 += a[i][p]*(T-t1);
	 	 	 	 	y1 += b[k][p]*(T-t1);
	 	 	 	 	t1 += T-t1;
                }
	 	 	}

	 	 	if (y1-x1 > ans)
	 	 		ans = y1 - x1;
	 	}
	}

	cout << ans;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin >> s;

	int ans = 0;
	int cnt = 1;
	for (int i = 1; i < s.length(); i++)
	{
		if (s[i] == s[i-1])
		{
			cnt++;
		} else {
			if (cnt % 2 == 0) ans++;
			cnt = 1;
		}
	}

	cout << ans << endl;
	return 0;
}


//135E Hewr
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
using namespace std;
#define fo(i,a,b) for (int i = a; i <= b; ++i)
#define fd(i,a,b) for (int i = a; i >= b; --i)
#define fe(i,x) for (int i = g[x], y = E[i].y; i; i = E[i].l, y = E[i].y)
#define forall(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); ++i)
#define pb push_back
#define SIZE(x) ((int) (x).size())
#define MP make_pair
#define fi first
#define se second
#define UNIQUE(x) x.resize(unique(x.begin(), x.end()) - x.begin())
#define clr(a,x) memset(&a, x, sizeof(a))
#define move(a,b) memcpy(&b, &a, sizeof(a))
#define Plus(a,b) (((LL) (a) + (b)) % mo)
#define Minus(a,b) ((((LL) (a) - (b) ) % mo + mo) % mo)
#define Mul(a,b) ((LL) (a) * (b) % mo)
#define updmin(a,b) (a = min(a, b))
#define updmax(a,b) (a = max(a, b))
#define sqr(x) ((x) * (x))

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef vector<int> VI;

const double eps = 1e-10;
const int oo = ~0u >> 2, mo = (int) 1e9 + 7;
const int mn = (int) 1e6 * 2 + 2;

int fac[mn], rev[mn];
int k, w, Ans(0);

int pow(int e, int x){
	int ret = 1;
	while (x){
		if (x & 1) ret = Mul(ret, e);
		e = Mul(e, e), x >>= 1;
	}
	return ret;
}

int Get_Rev(int x){
	return pow(x, mo - 2);
}

int calc1(int t, int d){
	int mol = Mul(Mul(pow(k, w - t - d - 1), t), Mul(fac[k], fac[k]));
	int den = Mul(rev[k - t], rev[k - t - d]);
	int ret = Mul(mol, den);
	return ret;
}

int calc2(int t, int d){
	int mol = Mul(Mul(fac[k], w - d), fac[k - t - d + w - 1]);
	int den = Mul(rev[k - t], rev[k - t - d]);
	int ret = Mul(mol, den);
	return ret;
}

int main(){
	fac[0] = rev[0] = 1;
	fo (i, 1, mn - 1) fac[i] = Mul(fac[i - 1], i), rev[i] = Mul(rev[i - 1], Get_Rev(i));
	cin >> k >> w;
	fo (i, 1, k){
		int t;
		if (i <= w - 1) t = calc1(i, 0), Ans = Plus(Ans, t);
		if (i > w - 1) t = calc2(i, 0), Ans = Plus(Ans, t);
		if (i < k && i + 1 <= w - 1) t = calc1(i, 1), Ans = Plus(Ans, t);
		if (i < k && i + 1 > w - 1) t = calc2(i, 1), Ans = Plus(Ans, t);
	}
	cout << Ans << endl;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

const int N = 200005;
int n,m,lim,p = 1,a[N],nex[N*2],spot[N*2],head[N],fa[N],f[N],g[N];
int maxcolor[N][2],c[N];
bool color[N],v[N];

void add(int x,int y)
{
	nex[++p] = head[x], head[x] = p, spot[p] = y;
	nex[++p] = head[y], head[y] = p, spot[p] = x;
}

void dfs0(int x)
{
	int tp,y;
	v[x] = 1;
	for(tp = head[x]; y = spot[tp],tp; tp = nex[tp])
		if(a[y]>=lim && fa[x]!=y) {
			fa[y] = x;
			dfs0(y);
			if(c[y]) c[x]++;
		}
	c[x] += color[x];
}
/*
void dfs1(int x)
{
	int tp,y,cnt = 0,m1 = 0,m2 = 0;

	for(tp = head[x]; y = spot[tp],tp; tp = nex[tp])
		if(a[y]>=lim && y!=fa[x]) {
			dfs1(y);
			if(!color[y]) cnt += f[y];
			else {
				if(m1==0) m1 = f[y];
				else {
					if(f[y]>m2) m2 = f[y];
					if(m1<m2) swap(m1,m2);
				}
			}
		}
	maxcolor[x][0] = m1;
	maxcolor[x][1] = m2;
	f[x] = cnt+m1+1;
}

void dfs2(int x, int &ret)
{
	if(fa[x]) {//Èç¹ûx²»ÊÇµÚÒ»´ÎËÑË÷µÄ¸ù½Úµã
		if(color[fa[x]]) {
			//xÒªÔÚËüµ±³õÑ¡µÄcolor½áµãºÍËü¸¸Ç×³ýÈ¥ËüÄÇ²¿·ÖÖÐÑ¡Ôñ
			if(color[x]) {//xµ±³õ±»Ñ¡»ò²»Ñ¡
				if(f[x]<maxcolor[fa[x]][0])//µ±³õxÃ»ÓÐ±»Ëü¸¸Ç×Ñ¡ÖÐ
					g[x] = f[x]-maxcolor[x][0]+max(maxcolor[x][0], g[fa[x]]);
				else //µ±³õËü±»Ñ¡ÖÐÁË
					g[x] = f[x]-maxcolor[x][0]+max(maxcolor[x][0],
						g[fa[x]]-maxcolor[fa[x]][0]+maxcolor[fa[x]][1]);
						//³ýÈ¥ËüËü¸¸Ç×Ö»ÄÜÍË¶øÇóÆä´ÎÁË
			}
			else //µ±³õx±»Ö±½Ó¼ÓÉÏ
				g[x] = f[x]-maxcolor[x][0]+max(maxcolor[x][0], g[fa[x]]-f[x]);
		}
		else {
			//xÖ±½Ó¼ÓÉÏËü¸¸Ç×
			if(color[x]) {
				if(f[x]<maxcolor[fa[x]][0])
					g[x] = f[x]+g[fa[x]];
				else
					g[x] = f[x]+g[fa[x]]-maxcolor[fa[x]][0]+maxcolor[fa[x]][1];
			}
			else
				g[x] = g[fa[x]];//f[x]+g[fa[x]]-f[x]£¬ºÍËü¸¸Ç×Ò»Ñù
		}
	}
	else g[x] = f[x];
	ret = max(ret, g[x]);
	for(int tp = head[x]; tp; tp = nex[tp])
		if(a[spot[tp]]>=lim && spot[tp]!=fa[x])
			dfs2(spot[tp], ret);
}
*/
void dfs1(int x)
{
	int tp,y,cnt = 0,m1 = 0,m2 = 0;

	for(tp = head[x]; y = spot[tp],tp; tp = nex[tp])
		if(a[y]>=lim && y!=fa[x]) {
			dfs1(y);
			if(!c[y]) cnt += f[y];
			else {
				if(f[y]>m2) m2 = f[y];
				if(m1<m2) swap(m1,m2);
			}
		}
	maxcolor[x][0] = m1;
	maxcolor[x][1] = m2;
	f[x] = cnt+m1+1;
}

void dfs2(int x, int &ret)
{
	if(fa[x]) {//Èç¹ûx²»ÊÇµÚÒ»´ÎËÑË÷µÄ¸ù½Úµã
		if(c[fa[x]]-(c[x]!=0)>0) {
			//xÒªÔÚËüµ±³õÑ¡µÄcolor½áµãºÍËü¸¸Ç×³ýÈ¥ËüÄÇ²¿·ÖÖÐÑ¡Ôñ
			if(c[x]) {//xµ±³õ±»Ñ¡»ò²»Ñ¡
				if(f[x]<maxcolor[fa[x]][0])//µ±³õxÃ»ÓÐ±»Ëü¸¸Ç×Ñ¡ÖÐ
					g[x] = f[x]-maxcolor[x][0]+max(maxcolor[x][0], g[fa[x]]);
				else //µ±³õËü±»Ñ¡ÖÐÁË
					g[x] = f[x]-maxcolor[x][0]+max(maxcolor[x][0],
						g[fa[x]]-maxcolor[fa[x]][0]+maxcolor[fa[x]][1]);
						//³ýÈ¥ËüËü¸¸Ç×Ö»ÄÜÍË¶øÇóÆä´ÎÁË
			}
			else //µ±³õx±»Ö±½Ó¼ÓÉÏ
				g[x] = f[x]-maxcolor[x][0]+max(maxcolor[x][0], g[fa[x]]-f[x]);
		}
		else {
			//xÖ±½Ó¼ÓÉÏËü¸¸Ç×
			if(c[x]) {
				if(f[x]<maxcolor[fa[x]][0])
					g[x] = f[x]+g[fa[x]];
				else
					g[x] = f[x]+g[fa[x]]-maxcolor[fa[x]][0]+maxcolor[fa[x]][1];
			}
			else
				g[x] = g[fa[x]];//f[x]+g[fa[x]]-f[x]£¬ºÍËü¸¸Ç×Ò»Ñù
		}
		c[x] += ((c[fa[x]]-(c[x]!=0))!=0);
	}
	else g[x] = f[x];
//	printf("g[%d] = %d\t", x, g[x]);
	ret = max(ret, g[x]);
	for(int tp = head[x]; tp; tp = nex[tp])
		if(a[spot[tp]]>=lim && spot[tp]!=fa[x])
			dfs2(spot[tp], ret);
}
int solve()
{
	memset(v, 0, sizeof(v));
	memset(fa, 0, sizeof(fa));
	memset(maxcolor, 0, sizeof(maxcolor));
	memset(c, 0, sizeof(c));
	int maxn = 0;
//	cout <<"solve " <<lim<<endl;
	for(int i = 1; i<=n; i++)
		if(a[i]>=lim && v[i]==0) {
//			cout << "dfs from "<<i<<endl;
			dfs0(i), dfs1(i), dfs2(i,maxn);
//			cout << endl;
		}
//	cout << maxn << endl;
//	for(int i = 1; i<=n; i++) cout << color[i]<<' ';
///	cout << endl;
	return maxn>=m;
}

int main()
{
//	freopen("shuju.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int i,x,y,l,r,tp;
	cin >> n >> m;
	for(i = 1; i<=n; i++)
		scanf("%d", &a[i]);
	for(i = 1; i<n; i++) {
		scanf("%d%d", &x,&y);
		add(x,y);
	}
	for(l = 1,r = 1000000; l<r; )
	{
		lim = l+r+1>>1;
		memset(color, 0, sizeof(color));
		for(i = 1; i<=n; i++)
			if(a[i]<lim)
				for(tp = head[i]; tp; tp = nex[tp])
					color[spot[tp]] = 1;
		if(solve()) l = lim;
		else r = lim-1;
	}
	cout << l;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,k,arr[1<<18];
bool vis[1<<18],big[1<<18];int failed[1<<18],failed1[1<<18];
vector<int>adj[1<<18];
pair<int,int>mx[1<<18],mx1[1<<18];
int sum[1<<18];
void dfs(int x,int p)
{
    int sz=adj[x].size(),nxt;
    bool ok=1;
    pair<int,int>pii;
    sum[x]=1;
    vis[x]=1;
    for(int i=0;i<sz;++i)
    {
        nxt=adj[x][i];
        if(nxt==p)continue;
        if(vis[nxt]){failed1[x]=failed[x];failed[x]=nxt;continue;}
        dfs(nxt,x);
        if(failed[nxt]){
            pii=make_pair(sum[nxt]+mx[nxt].first,nxt);
            if(pii>mx[x])swap(pii,mx[x]);
            if(pii>mx1[x])swap(pii,mx1[x]);
        }
        else sum[x]+=sum[nxt];
        if(failed[nxt]){failed1[x]=failed[x];failed[x]=nxt;continue;}
    }
}
void dfs1(int x,int p)
{
    //cout<<x<<" "<<sum[x]<<" "<<mx[x].first<<" "<<mx1[x].first<<" h\n";
    if(p){
        pair<int,int>pii=mx[p];
        if(mx[p].second==x)pii=mx1[p];
        if(!failed[p]){
            sum[x]+=sum[p]-sum[x];
        }
        else if(failed[p]==x&&!failed1[p]){
            sum[x]+=sum[p];
        }
        else pii.first+=sum[p];
        //cout<<x<<" "<<p<<" "<<pii.first<<endl;
        if(pii>mx[x])swap(pii,mx[x]);
        if(pii>mx1[x])swap(pii,mx1[x]);
        //change failed
        if((failed[p]&&failed[p]!=x)||(failed1[p]&&failed1[p]!=x)){
            failed1[x]=failed[x];
            failed[x]=p;
        }
    }
       // cout<<x<<" "<<sum[x]<<" "<<mx[x].first<<" "<<mx1[x].first<<" f\n";

    int sz=adj[x].size(),nxt;
    for(int i=0;i<sz;++i){
        nxt=adj[x][i];
        if(nxt==p)continue;
        if(!big[nxt])continue;
        dfs1(nxt,x);
    }
}
bool check(int mid)
{
    //cout<<mid<<endl;
    for(int i=1;i<=n;++i){
        big[i]=(arr[i]>=mid);
        vis[i]=(arr[i]<mid);
        mx[i]=mx1[i]=make_pair(0,0);
        sum[i]=0;
        failed[i]=failed1[i]=0;
    }
    for(int i=1;i<=n;++i){
        if(!vis[i]){
            dfs(i,0);
            dfs1(i,0);
        }
    }
    //for(int i=1;i<=n;++i)cout<<i<<" "<<sum[i]<<" "<<mx[i].first<<" "<<mx1[i].first<<" "<<failed[i]<<endl;
    //cout<<"---------------------------\n";
    for(int i=1;i<=n;++i){
        if(big[i]){
            if(sum[i]+mx[i].first>=k)return 1;
        }
    }
    return 0;

}
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;++i)scanf("%d",arr+i);
    int u,v;
    for(int i=1;i<n;++i){
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int st=1,en=1000002,mid;
    //check(700000);return 0;
    while(st<en){
        mid=(st+en)/2;
        if(check(mid))st=mid+1;
        else en=mid;
    }
    cout<<en-1;

}


#include<bits/stdc++.h>
using namespace std;
int n,k,a[200005];
vector<int>adj[200005];
bool comp[200005];
int sum[200005];
pair<int,int>mx[2][200005];
pair<int,int>dfs(int x,int p,int z)
{

    comp[x]=1;
    pair<int,int> m;
    sum[x]=1;
    for(int i=0;i<adj[x].size();++i){
        if(adj[x][i]==p)continue;
        m=dfs(adj[x][i],x,z);
        if(m.second)sum[x]+=m.first;
        else {
            comp[x]=0;
            m.second=adj[x][i];
            if(m>mx[0][x])swap(m,mx[0][x]);
            if(m>mx[1][x])swap(m,mx[1][x]);
        }
    }
    if(a[x]<z){
        comp[x]=0;
        sum[x]=0;
        mx[0][x]=mx[1][x]=make_pair(-1,0);
        return make_pair(0,0);
    }
    if(comp[x])return make_pair(sum[x],1);
    return make_pair(sum[x]+mx[0][x].first,0);
}
void dfs1(int x,int p){
    if(p){
        if(!comp[p]&&(mx[1][p].first!=-1||mx[0][p].second!=x)){
            pair<int,int>m;
            m=mx[0][p];
            if(m.second==x)m=mx[1][p];
            m.first+=sum[p];
            if(comp[x])m.first-=sum[x];
            m.second=p;
            if(m>mx[0][x])swap(m,mx[0][x]);
            if(m>mx[1][x])swap(m,mx[1][x]);
            comp[x]=0;
        }
        else {
            if(!comp[x])sum[x]+=sum[p];
            else sum[x]=sum[p];
        }
    }
    for(int i=0;i<adj[x].size();++i)
        if(adj[x][i]!=p)dfs1(adj[x][i],x);
}

bool check(int mid){
    for(int i=1;i<=n;++i){
        comp[i]=0;
        sum[i]=0;
        mx[0][i]=mx[1][i]=make_pair(-1,0);
    }
    dfs(1,0,mid);
    //for(int i=1;i<=n;++i)cout<<i<<" "<<sum[i]<<" "<<mx[0][1].first<<" "<<comp[i]<<endl;
    dfs1(1,0);

    for(int i=1;i<=n;++i)if(sum[i]+max(0,mx[0][i].first)>=k)return 1;
    return 0;

}
int main()
{
    cin>>n>>k;
    int u,v;
    for(int i=1;i<=n;++i)scanf("%d",a+i);
    for(int i=1;i<n;++i){
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int st=0,en=1e6+4,mid;
    //cout<<check(3)<<endl;
    //return 0;
    while(st<en){
        mid=(st+en)/2;
        if(check(mid))st=mid+1;
        else en=mid;
    }
    cout<<st-1<<endl;
}

//http://codeforces.com/contest/635/problem/F


#include <iostream>
#include <stack>
#include <math.h>
#include <set>
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <map>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
#define endl "\n"
#define mp make_pair
#define int long long
#define pii pair<int , int>
inline int in(){int32_t x ; scanf("%d",&x) ; return x ;}
inline string getStr(){char ch[500001] ; scanf("%s",ch) ;return ch;}
const int MAX_N = 2e5 + 10;
inline int gcd( int a, int b ) { return b == 0 ? a : gcd( b, a%b ); }
vector<int> g[MAX_N];
bool del[MAX_N] , forb[MAX_N] , mark[MAX_N];
int a[MAX_N] , dp[MAX_N] ,  ln , vl[MAX_N] , deg[MAX_N];
queue<int> Bomb ; int  n , k;
inline void BombProcess()
{
    for (int i = 1 ; i <= n ; i ++) if (deg[i] == 1 && !forb[i]) Bomb.push(i);
    while (Bomb.size()){
        int first = Bomb.front(); Bomb.pop();
        deg[first] --;
        del[first] = true;
        int FIND = -1;
        for (auto u : g[first]){
            if (!del[u] && !forb[u]){
                FIND = u;
                break;
            }
        }
        if (FIND != -1){
            vl[FIND] += vl[first];
            deg[FIND] --;
            if (deg[FIND] == 1)
                Bomb.push(FIND);
        }
        ln = max(ln , vl[first]);
        vl[first] = 0;
    }
}
int cnt2 = 0 , cnt = 0;
inline void dfs(int v , int pr){

    mark[v] = true;
    dp[v] = vl[v];
    int f1 = 0 , f2 = 0 ;
    for (auto u : g[v]){
        if (!forb[u] && (u - pr)){
            dfs(u , v);
            if (dp[u] > f1){
                f2 = f1;
                f1 = dp[u];
            }
            else{
                f2 = max(f2 , dp[u]);
            }
        }
    }
    if (f2 && f1) cnt2 ++ ;
    if (!pr && f2 && f1) cnt ++;

    ln = max(ln , dp[v] + f2 + f1);
    dp[v] += f1;
}
inline bool can(int low){
    ln = 0;
    for (int i = 1 ; i <= n ; i ++){
        mark[i] = 0;
        deg[i] = g[i].size();
        dp[i] = 0;
        del[i] = 0  ;
        mark[i] = 0 ;
        vl[i] = 1;
        forb[i] = (a[i] < low);
    }
    BombProcess();
    for (int i = 1 ; i <= n ; i ++)if (!mark[i] && !forb[i]) dfs(i , -1) ;
    assert(cnt == cnt2);
    return ln >= k;
}
int32_t main()
{
    n = in() , k = in();
    for (int i = 0 ; i < n ;  i ++) a[i + 1] = in();
    for (int i = 0 ; i < n - 1 ; i ++){
        int v = in() , u = in();
        g[v].push_back(u);
        g[u].push_back(v);

    }
    int l = 0 , r = (1 << 20) , best = 0 , mid;
    while (l <= r){
        mid = (l + r) >> 1;
        if (can(mid)) {best = mid ; l = mid + 1 ; continue ; }
        r = mid - 1;
    }
    cout << best << "\n";
}


/* Author haleyk10198 */
/* �@��:  haleyk10198 */
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <string>
#include <set>
#include <stack>

#define MOD 1000000007
#define LINF (1LL<<60)
#define INF 2147483647
#define PI 3.1415926535897932384626433
#define ll long long
#define pii pair<int,int>
#define mp(x,y) make_pair((x),(y))

using namespace std;
int n,k;
vector<int> near[200010];
int sz[200010],a[200010];
bool f=false;

int setsz(int now,int prv){
	int &res=sz[now];
	for(int x:near[now])
		if(x-prv)
			res+=setsz(x,now);
	return ++res;
}

int check(int now,int prv,int x){
	int fix=1;
	int wild1=0,wild2=0;
	priority_queue<int> q;
	for(int y:near[now]){
		if(y-prv){
			int v=check(y,now,x);
			if(v==sz[y])
				fix+=v;
			else{
				if(v>wild1){
					swap(wild1,wild2);
					wild1=v;
				}
				else if(v>wild2)
					wild2=v;
			}
		}
	}
	if(a[now]>=x){
		f|=(fix+wild1+wild2>=k);
		return fix+wild1;
	}
	else
		return 0;
}

int bins(int l,int r){
	int mid=(l+r)/2;
	if(l>r)
		return r;
	f=false;
	check(1,1,mid);
	if(f)
		return bins(mid+1,r);
	else
		return bins(l,mid-1);
}

int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		near[u].push_back(v);
		near[v].push_back(u);
	}
	sz[1]=setsz(1,1);
	cout<<bins(0,1000000000)<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int n,sz[N],a[N],c,ret,dp[N];
pair<int,int> m[N][2];
vector<int> adj[N];
void dfs(int x,int p){
	int f=0,u,i,d;dp[x]=0;
	if(!sz[x])f=1,++sz[x];
	d= a[x]>=c ? 1 :0;
	for(i=0;i<adj[x].size();++i){
		u= adj[x][i];
		if(u!=p){
			dfs(u,x);
			if(f)sz[x]+=sz[u];
			if(dp[u]==sz[u])dp[x]+=dp[u];
			else{
				if(m[x][0].first<=dp[u])
					m[x][1]= m[x][0],m[x][0]=make_pair(dp[u],u);
				else if(m[x][1].first<dp[u])
					m[x][1]= make_pair(dp[u],u);
			}
		}
	}
	dp[x]+=d;
	if(d==0)dp[x]=0;
}
int ar[3];
void dfs2(int x,int p,int d){
	int t=d,u,i,v=0,nd,test,z;
	test= dp[x]+ m[x][0].first;
	if(a[x]>=c){
		if(d==n-sz[x])t=0,v=d,test= dp[x]+d;
		else
			test= dp[x]+ max(d,m[x][0].first);
		ar[0]= m[x][0].first,ar[1]= m[x][1].first,ar[2]= t;
		sort(ar,ar+3);
		ret= max(ret,dp[x]+ ar[2]+ar[1]+v);
	}
	for(i=0;i<adj[x].size();++i){
		u= adj[x][i];
		if(u!=p){
			nd=0;z=0;
			if(a[x]>=c){
				nd= dp[x]+v+ max(t,m[x][0].first);
				z= test;
				if(sz[u]==dp[u]){
					nd= dp[x]-sz[u]+ max(m[x][0].first,t)+ v;
					z= test-sz[u];
				}
				else if(u==m[x][0].second){
					nd= dp[x] + v + max(m[x][1].first,t);
					if(d==n-sz[x])z= test-m[x][0].first+m[x][1].first;
					else
						z= dp[x]+max(d,m[x][1].first);
				}
			}
			assert(z==nd);
			dfs2(u,x,nd);
		}
	}
}
int main(){
	int i,x,y,q,l,r,k,mid;
	cin>>n>>k;
	for(i=1;i<=n;++i)scanf("%d",&a[i]);
	for(i=0;i<n-1;++i)scanf("%d%d",&x,&y),adj[x].push_back(y),adj[y].push_back(x);
	dfs(1,0);
	l=1,r= 1e6;
	while(l<r){
		mid= (l+r+1)/2;
		c= mid;
		memset(m,0,sizeof(m));ret=0;
		dfs(1,0);
		dfs2(1,0,0);
		if(ret>=k)l= mid;
		else
			r= mid-1;
	}
	printf("%d\n",l);
}


# include <iostream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
using namespace std;

long long ans[50000000];

int main(void)
{
//	freopen("aaa.in","r",stdin);
	long long x,y,l,r;
	int cnt = 0;
	scanf("%I64d%I64d%I64d%I64d",&x,&y,&l,&r);
	ans[++cnt] = l-1;
	ans[++cnt] = r+1;
	for (long long i=1;i<r&&i>0;i*=x)
	{
		for (int j=1;j+i<=r&&j+i>0;j*=y)
		{
			if (i+j<l) continue;
			ans[++cnt] = i+j;
		}
	}
	sort(ans+1,ans+cnt+1);
//	cout<<cnt<<endl;
	long long anss = 0;
	for (int i=1;i<cnt;i++)
	anss = max(anss,ans[i+1]-ans[i]-1);
	cout<<anss<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define MOD 1000000007
#define forn(i, n) for (long i = 0; i < n; i++)
#define mp make_pair
#define pb push_back
#define watch(x) cerr << (#x) << " is " << (x)<<" "
#define debug() cerr << "running till line " << __LINE__ << " in function " << __func__ << endl
const double PI = 3.141592;
const int inf = (int)1.01e9;
const double eps = (1e-9);
typedef unsigned long long ull;
typedef long long ll;
typedef vector<long> vl;
typedef vector<int> vi;

void solve();

template <typename T>

void print(T arr[],size_t sizee)
{
    for (size_t it = 0 ;it<sizee;it++){
    	cout<<arr[it]<<" ";
    }

    cout << endl;
}
template <class T>
void print(T container1)
{
    for (auto it : container1)
    {
        cout << it << " ";
    }
    cout << endl;
}
int main(int argc, char const *argv[])
{

#ifdef _DEBUG
    int tt = clock();
#endif

    solve();

#ifdef _DEBUG
    cerr << "TIME = " << clock() - tt << endl;
    tt = clock();
#endif
}

void solve()
{
    int n;
    cin>>n;
    string s;
    cin >>s ;
    int x=0,y=0;
   vector <pair<int,pair <int,int >> > pp;

    int c1=0,c2=0;
    int m=0;
    for(int i =0;i<n;i++){
        c1=0,c2=0;
        if(s[i]=='L')
        {
           c1--;
        }
        if(s[i]=='R')
        {
            c1++;
        }
        if(s[i]=='U')
        {
            c2++;
        }
        if(s[i]=='D')
        {
            c2--;
        }
        int nn=pp.size();
       for(int j=0;j<nn;j++ ){
           int x=c1+pp[j].second.first;
           int y=c2+pp[j].second.second;
           pp.push_back({pp[j].first+1,{x,y}});
            if(x==0 && y==0){
                if(m<pp[j].first+1){
                    m=pp[j].first+1;
                }
            }
       }
       pp.push_back({1,{c1,c2}});

    }
    cout<<m<<endl;
}


#include<iostream>

using namespace std;

long long d[10000+5][10000+5];

main()
{
    long long m,b;
    cin>>m>>b;
    long long c=10001;
    d[0][0]=0;
    for (long long i=1; i<c; i++)
        d[0][i]=d[0][i-1]+i;
    for (long long i=1; i<c; i++)
        d[i][0]=d[i-1][0]+i;
    for (long long i=1; i<c; i++)
        for (long long j=1; j<c; j++)
            if (i==0&&j==0) continue;
        else d[i][j]=d[i-1][j]+d[i][j-1]-d[i-1][j-1]+i+j;
    long long max=0;
    for (long long i=0; i<c; i++)
    {
        long long u=-(i/m)+b;
        if (i%m!=0) u--;
        if (u<0) continue;
        if (max<d[i][u]) {max=d[i][u];}
    }
    cout<<max;
}