#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <map>
#include <bitset>
using namespace std;
#define ll long long

struct _comp {
    bool operator() (int i[3],int j[3]) { return (i[0]>j[0]);}
} comp;

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

vector<vector<int>> Ptriangle;
void fill_Ptriangle(int step){
    vector<int> tmp(1,1);
    Ptriangle.push_back(tmp);
    for(int i=1;i<=step;i++)
    {
        tmp.clear();
        tmp.push_back(1);
        for(int k=0;k<Ptriangle[i-1].size()-1;k++){
            tmp.push_back(Ptriangle[i-1][k]+Ptriangle[i-1][k+1]);
        }
        tmp.push_back(1);
        Ptriangle.push_back(tmp);
    }
}
string i2s(int a)
{
    string s="";
    if(a<0)
    {s+='-';a=abs(a);}
    while(a)
    {
        s+=a%10 + '0';
        a/=10;
    }
    return s;
}
//struct _set
//{
//  int parent_set;
//  int size;
//  vector<int> set_elems;
//  vector<int> set_indexes;
//  void make_set(int elem, int index)
//  {
//      parent_set = index;
//      set_elems.push_back(elem);
//      set_indexes.push_back(index);
//      size = 1;
//  }
//};
//_set my_set[300];
//int find_set(int index){
//  if(my_set[index].parent_set == index)
//      return index;
//  if(my_set[index].parent_set == -1)
//      return index;
//  return my_set[index].parent_set = find_set(my_set[index].parent_set);
//}
//void union_sets(int a, int b)
//{
//  a = find_set(a);
//  b = find_set(b);
//  if(a!=b)
//  {
//      if(my_set[a].size < my_set[b].size)
//          swap(a, b);
//      my_set[a].parent_set = b;
//      my_set[b].set_elems.insert(my_set[b].set_elems.end(), my_set[a].set_elems.begin(), my_set[a].set_elems.end());
//      my_set[b].set_indexes.insert(my_set[b].set_indexes.end(), my_set[a].set_indexes.begin(), my_set[a].set_indexes.end());
//      my_set[b].size += my_set[a].size;
//  }
//}
int zx[1000];
map<int,int> m;
int main()
{
    zx[1]=1;
    #ifndef ONLINE_JUDGE
        freopen("Input.txt", "r", stdin);
    #endif
    int n,t;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        scanf("%d", &t);
        m[t]++;
    }

    int res=0;
    for(int i=0;i<1000;i++)
    {
        for(int j=0;j<1000;j++)
        {
            zx[(i+j)%100]+=zx[i%100];
        }
    }
    t=0;
    for(map<int,int>::iterator it=m.begin();it!=m.end();it++)
    {
        while(it->second){
            res++;
            int z=0;
            for(map<int,int>::iterator it2=it;it2!=m.end();it2++){
                if(!it2->second || it2->first-z<0)
                    continue;
                if(z>it2->first)
                    break;
                if(it2->second<=it2->first+1-z){
                    z+=it2->second;
                    m[it2->first] = 0;
                }
                else {
                    m[it2->first] -= it2->first+1-z;
                    z=it2->first+1;
                }
            }
        }
    }
    cout << res << endl;
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    char c;
    int n,lastN=1,lln=1,counter=0;
    bool f = true;
    while((c=getchar())!=-1&&c>=48&&c<=58)
    {
        n = c - 48;
        if(n==1||n==4)
        {
            if(n==4)
            {
                if(counter==0)
                {
                    f = false;
                }
                if(lastN==4)
                {
                    if(lln!=1)
                    {
                        f = false;
                    }
                }
            }
        }
        else
        {
            f = false;
        }
        counter++;
        lln=lastN;
        lastN=n;
    }
    if(f)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
}


/*
######################################################
#    I don't know what I'm doing with my life O.O    #
######################################################
*/

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

//Optimizations
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//save time
#define endl '\n'
#define db(x) cout << "> " << #x << ": " << x << endl;
typedef long long ll;

//for sorting
#define all(a) a.begin(),a.end()

//Constants
#define PI   3.141592653593
#define MOD  1000000007LL
#define EPS  0.000000001
#define INF  0X3f3f3f3f

//loops
#define REP(i,n) 	    for(int i=0;i<(n);++i)
#define FOR(i,a,b)      for(int i=(a);i<(b);++i)
#define DFOR(i,a,b)     for(int i=(a);i>=(b);--i)

//vectors
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<int,int>>
#define vlll vector<pair<ll,ll>>
#define pb 	push_back

//pairs
#define pi pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define F first
#define S second

//fast I/O
#ifndef _WIN32
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
#define gc getchar
#define pc putchar

//If using cin and cout
#define IOS ios::sync_with_stdio(false)
#define TIE cin.tie(NULL);cout.tie(NULL)

//queue
#define di deque<int>
#define dll deque<ll>
#define qi queue<int>
#define PQ priority_queue

//general
#define E empty()

//Declare all variables and methods needed between this comment and the next one(OCD lol)
const int MAXN=1e5+10;
vii sale;
int k[MAXN],n,m,tot;
int bSearch(int low,int high){
    int mid=(low+high)>>1;
    if(low<=high){
        int last[n+1]={};
        for(auto s : sale)
            if(s.F<=mid)
                last[s.S]=max(s.F,last[s.S]);

        vii v;
        FOR(i,1,n+1)
            v.pb(mp(last[i],i));
        sort(all(v));

        int cnt=0,sum=0,tmp;
        auto it=v.begin();
        FOR(i,1,mid+1){
            ++cnt;
            while(it!=v.end() && it->F<i)
                ++it;

            while(it!=v.end() && it->F==i){
                tmp=min(cnt,k[it->S]);
                cnt-=tmp;
                sum+=tmp;
                ++it;
            }
        }

        sum=(tot-sum)*2;
        if(sum<=cnt)
            return bSearch(low,mid-1);
        else
            return bSearch(mid+1,high);
    }
    else
        return mid+1;
}
//Main function
int main(){
    IOS;
    TIE;

    cin>>n>>m;

    FOR(i,1,n+1){
        cin>>k[i];
        tot+=k[i];
    }

    int d,t;
    REP(i,m){
        cin>>d>>t;
        sale.pb(mp(d,t));
    }

    cout<<bSearch(1,int(2e5+10))<<endl;

    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <string>
#include <queue>

using namespace std;

const int MAXN = 300;
const int MAXM = 300000;
const int INF = 0x3f3f3f3f;

struct Edge
{
    int to,next,cap,flow,cost;
}edge[MAXM];

int head[MAXN],tol;
int pre[MAXN],dis[MAXN];
bool vis[MAXN];
int N;//½Úµã×Ü¸öÊý£¬½Úµã±àºÅ´Ó0~N-1

void init(int n)
{
    N = n;
    tol = 0;
    memset(head,-1,sizeof(head));
}

void addedge(int u,int v,int cap,int cost)
{
    edge[tol].to = v;
    edge[tol].cap = cap;
    edge[tol].cost = cost;
    edge[tol].flow = 0;
    edge[tol].next = head[u];
    head[u] = tol++;
    edge[tol].to = u;
    edge[tol].cap = 0;
    edge[tol].cost = -cost;
    edge[tol].flow = 0;
    edge[tol].next = head[v];
    head[v] = tol++;
}

bool spfa(int s,int t)
{
    queue<int>q;
    for(int i = 0;i < N;i++)
    {
        dis[i] = INF;
        vis[i] = false;
        pre[i] = -1;
    }
    dis[s] = 0;
    vis[s] = true;
    q.push(s);
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        vis[u] = false;
        for(int i = head[u]; i != -1;i = edge[i].next)
        {
            int v = edge[i].to;
            if(edge[i].cap > edge[i].flow &&
               dis[v] > dis[u] + edge[i].cost )
            {
                dis[v] = dis[u] + edge[i].cost;
                pre[v] = i;
                if(!vis[v])
                {
                    vis[v] = true;
                    q.push(v);
                }
            }
        }
    }
    if(pre[t] == -1)return false;
    else return true;
}

int minCostMaxflow(int s,int t,int &cost)
{
    int flow = 0;
    cost = 0;
    while(spfa(s,t))
    {
        int Min = INF;
        for(int i = pre[t];i != -1;i = pre[edge[i^1].to])
        {
            if(Min > edge[i].cap - edge[i].flow)
                Min = edge[i].cap - edge[i].flow;
        }
        for(int i = pre[t];i != -1;i = pre[edge[i^1].to])
        {
            edge[i].flow += Min;
            edge[i^1].flow -= Min;
            cost += edge[i].cost * Min;
        }
        flow += Min;
    }
    return flow;
}

int n,val[MAXN],fix[MAXN],sum;
char str[MAXN];
int ans;

int main()
{
	int i,j,s,t,tmp;
	scanf("%d",&n);
	init(2*n+2);
	s=0; t=2*n+1;
	scanf("%s",str+1);
	sum=0;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&val[i]);
		sum+=val[i];
	}
	memset(fix,0,sizeof(fix));
	for(i=1;i<=n/2;i++)
		if(val[i]>val[n+1-i])
			fix[i]=1,addedge(i,n+i,1,0);
		else
			fix[n+1-i]=1,addedge((n+1-i),n+(n+1-i),1,0);
	for(i=1;i<=n;i++)
		addedge(s,i,1,0),addedge(n+i,t,1,0);
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
		{
			if(fix[i] || fix[j])
				continue;
			if(str[i]==str[n+1-j])
				continue;
			if(i==j) tmp=0;
			else tmp=val[j];
			addedge(i,n+j,1,tmp);
		}
	int flow=minCostMaxflow(s,t,ans);
	ans=sum-ans;
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int i=0, j=0, row, column;
    bool success = false;
    char square [4][4];
    for (row = 0; row < 4; row++)
        for (column = 0; column < 4; column++)
            cin >> square[row][column];
    for (row = 1; row < 4; row++)
    {
        for (column = 1; column < 4; column++)
        {
            if (square[row][column] == '#') i++; else j++;
            if (square[row-1][column-1] == '#') i++; else j++;
            if (square[row-1][column] == '#') i++; else j++;
            if (square[row][column-1] == '#') i++; else j++;
            if ((i>=3) || (j>=3))
            {
                success=true;
                break;
            }
            else
            {
                i=0;
                j=0;
            }
        }
        if (success) break;
    }
    if (success == true) cout << "YES";
    else cout << "NO";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int T;
long long a,b;
/*long long cf(long long x,long long n,long long p)
{
    if(!n) return 1;
    long long ans=cf(x,n/2,p);
    ans=(ans%p)*(ans%p);
    if(n%2) ans=((ans%p)*(x%p))%p;
    return ans%p;
}
bool miller_rabin(long long n)
{
    long long i,j,aa,x,y,t,u,s=10;
    if(n==2) return true;
    if(n<2||!(n&1)) return false;
    for(t=0,u=n-1;!(u&1);t++,u>>=1);
    for(i=0;i<s;i++)
    {
        aa=rand()%(n-1)+1;
        x=cf(aa,u,n);
        for(j=0;j<t;j++)
        {
            y=x*x%n;
            if(y==1&&x!=1&&x!=n-1) return false;
            x=y;
        }
        if(x!=1) return false;
    }
    return true;
}*/
inline bool is_prime(long long x){
    long long s=(long long)sqrt((double)x+1.0);
    for(register long long i=2;i<=s;i++) if(!(x%i)) return false;
    return true;
}
int main(){
    cin>>T;
    while(T--){
        cin>>a>>b;
        if(a<=(b+1)){
            if(is_prime(a+b)) printf("YES\n");
            else printf("NO\n");
        }
        else printf("NO\n");
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const int inf = 1e9+123;

ll a, b, c ,d, cnt=0;
ll ret(ll x, ll n)
{
	if(x<=0 || n<=0)
		return 0;
	if(n>=x)
		return n*x-((x-1)*(x))/2;
	else
		return (n*(n+1))/2;
}
void solve()
{
	ll a, b, c ,d, cnt=0;
	cin >> a >> b >> c >> d;
	for(int z = c; z<=d; z++)
	{
		ll lb = b, rb = c;
		ll llb = a, rrb = b;
		while(lb<rb)
		{
			ll mb = (lb+rb)/2;
			llb = a, rrb = b;
			while(llb<rrb)
			{
				ll mmb = (llb+rrb)/2;
				if(mmb+mb<z+1)
					llb = mmb+1;
				else
					rrb = mmb;
			}
			if(llb+mb<z+1)
				lb = mb+1;
			else
				rb = mb;
		}
		llb = a, rrb = b;
		while(llb<rrb)
			{
				ll mmb = (llb+rrb)/2;
				if(mmb+lb<z+1)
					llb = mmb+1;
				else
					rrb = mmb;
			}
		if(llb+lb>z)
		{
			cnt += (b-llb+1)*(c-lb+1);
			cnt += ret(llb-a, c-lb);
		}
	}
	cout << cnt << '\n';
}

int main()
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
//	ll t;
//	cin >> t;
//	while(t--)
	solve();
}


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

int main() {
	int n, a, b, c;

	scanf("%d %d %d %d", &n, &a, &b, &c);

	if (n == 1) {
		printf("0");
	}
	else if (n == 2) {
		printf("%d", min(a, b));
	}
	else {
		int s;
		if (a <= b && a <= c) s = a;
		else if (b <= a && b <= c) s = b;
		else if (c <= a && c <= b) s = c;
		if (s == c) s = min(a, b) + (n - 2) * s;
		else s = (n - 1) * s;
		printf("%d", s);
	}

	return 0;
}


/*
  ------------------------- Hachiikung ---------------------------------
  ---------------------- Worrachate Bosri ------------------------------
  ------ Faculty of Computer Engineering Chulalongkorn University ------
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<map>
#include<string>
#include<utility>
using namespace std;
#define REP(i,FN) for(int i=0;i<FN;i++)
#define FOR(i,ST,FN) for(int i=ST;i<=FN;i++)
#define FORD(i,FN,ST) for(int i=FN;i>=ST;i--)
#define FORX(i,c) for(typeof(c.begin())i=c.begin();i!=c.end();i++)
#define pause system("pause")
#define S scanf
#define P printf
#define X first
#define Y second
#define pb push_back
#define PII pair<int,int>
#define mp make_pair
#define sz size()
#define eps 1e-8

const int MOD(1000000007);
const int INF((1<<30)-1);
const int MAXN(5005);

int n;

long long dp[2][MAXN];

int main(){

    int a,k,b;
    S("%d%d%d%d",&n,&a,&b,&k);

    int now = 1, prev = 0;

    dp[prev][a] = 1;

    while(k--)
    {
        FOR(i,1,n)
        {
            dp[now][i] = 0;
            dp[prev][i] += dp[prev][i-1];
            dp[prev][i] %= MOD;
        }

        FOR(i,1,n)
        {
            if(i == b) dp[now][i] = 0;

            else if(i < b)
            {
                dp[now][i] += dp[prev][i-1];

                int m = (i+b)/2;

                if((b-i)%2 == 1)
                {
                    dp[now][i] += dp[prev][m] - dp[prev][i];
                }
                else
                {
                    dp[now][i] += dp[prev][m-1] - dp[prev][i];
                }
            }

            else
            {
                dp[now][i] += dp[prev][n] - dp[prev][i];

                int m = (b+i)/2;

                dp[now][i] += dp[prev][i-1] - dp[prev][m];
            }

            dp[now][i] %= MOD;
        }

        now ^= 1;
        prev ^= 1;
    }

    long long ans = 0;

    FOR(i,1,n)
    {
        ans += dp[prev][i];
        ans %= MOD;
    }

    P("%I64d",(ans+MOD)%MOD);
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<string>

using namespace std;

int main()
{
	string str;
	int n,k,len,num[30],m,mi;
	while(cin>>n>>k)
	{
		m=mi=0;
		cin>>str;
		memset(num,0,sizeof(num));
		for(int i=0;i<n;i++)
			num[str[i]-'a']++;
		sort(num,num+26);
		if(num[25]<=k)
			cout<<"YES\n";
		else
			cout<<"NO\n";

	}

	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long int n;
	cin >> n;
	int i,flag=0;
	long int dif;
	int arr[10000];
	for(i=0;i<n;i++)
	{
		cin >> arr[i];
	}
		dif=arr[1]-arr[0];
	for(i=1;i<n-1;i++)
	{
		if(arr[i+1]-arr[i]!=dif)
		{
			flag=1;
			break;
		}
	}
	if(flag==1)
	{
		cout << arr[n-1];
	}
     else
	{
		cout << arr[n-1] + dif;
	}
	return 0;
}


//### In The Name Of GOD ###

//%% Remember; (((He))) is The (((Accepter))) %%

// GOD IS GREATER ...

#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;
typedef long double ld ;

//#define int ll
#define pb push_back
#define bp pop_back
#define pf push_front
#define fp pop_front
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);
#define sz(a) (int)(a.size())
#define sg(a, b) (a + b - 1) / b

const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 2 * 1000 * 1000 + 200;
const int MAXN = 2 * 100 * 100 + 20;
const int MLOG = 18;
const int NMAX = 1 * 1000;

int main() {
	IO;
	ll n, m;
	cin >> n >> m;
	m--;
	deque <int> dq;
	dq.pb(n);
	for(int i = 0; i < n - 1; i++)
		if((m >> i) & 1) dq.pb(n - i - 1);
		else dq.pf(n - i - 1);
	for(int i = 0; i < n; i++) cout << dq[i] << ' ';
}


/*
Nahid Hossain
Jahangirnagar University
Roll:54
*/
#include<bits/stdc++.h>
#define ll          long long int
#define db          double
#define pf          printf
#define sf          scanf
#define ff          first
#define ss          second
#define clr         clear()
#define sz          size()
#define pb          push_back
#define mk          make_pair
#define pi          acos(-1)
#define inf         1000000000000
#define mod         1000000007
#define ull         unsigned long long int
#define f(i,k,n)    for(ll i=k;i<n;i++)
#define fr(i,n,k)   for(i=n;i>=k;i--)
#define ent(a)      scanf("%lld",&a)
#define ent2(a,b)   scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a)      memset(a,0,sizeof(a))
#define vec(v,s)    vector<ll>v[s]
#define arr(a,s)    ll a[s];
//#define check(n,pos) (n&(1<<pos))
//#define set(n,pos)  (n|(1<<pos))
//knight and king//
int dr[]={2, 2, -2, -2, 1, -1, 1, -1};
int dc[]={1,-1,  1, -1, 2,  2,-2, -2};
int dr1[]={0, 0, 0, 1, 1, 1, -1, -1, -1};
int dc1[]={-1,0, 1,-1, 0, 1, -1, 0,   1};
int dr2[]={0, 0, 1, -1};
int dc2[]={1,-1, 0,  0};
////////////////////////////
using namespace std;
#define ma 100006

ll dp[12][2][12];
ll a[20];
string t;
ll cal(ll x,ll f,ll y)
{
    if(y<0)return 0;
    if(x==t.sz)
    {
        if(y==0)return 1;
        return 0;
    }

    ll &r=dp[x][f][y];
    if(r!=-1)return r;
    r=0;
    ll u=9;
    if(f==0)u=t[x]-'0';
    for(ll i=0;i<=u;i++)
    {
        r+=cal(x+1,i<u||f==1,y-(i==4||i==7));
    }
    return r;
}

ll cal1(ll x,ll s)
{
    if(s>9)return 0;
    if(x==0)
    {
        ll s1=0;

        for(ll i=s+1;i<=10;i++)s1+=a[i];
        s1%=mod;
        return s1;
    }
    ll r=0;

    for(ll i=0;i<=10;i++)
    {
        ll p=a[i];
        a[i]--;
        r=r+p*cal1(x-1,s+i);
        r%=mod;
        a[i]++;
    }
    return r;

}

int main()
{
    ll i;
    while(cin>>t)
    {
       for(i=0;i<=10;i++)
       {
           memset(dp,-1,sizeof(dp));
           a[i]=cal(0,0,i);
           ll cn=0;
           if(i==0)a[i]--;
       }

       ll ans=cal1(6,0);
       cout<<ans<<endl;
    }
    return 0;
}


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

int main(){
	ll n,k,t;
	cin>>n>>k>>t;
	if(t < k) cout<<t;
	else if(t >= k && t<=n) cout<<k;
	else if(t>n && t <n+k) cout<<(k-(t-n));
	else cout<<0;
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
    long long int n,m;
    cin>>n>>m;
    if((long double)((long double)log(m)/(long double)log(2))>=(n-0.1))
    {
        cout<<m%(1<<n);
    }
    else
    {
        cout<<(m);
    }
	return 0;
}


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

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

   	string s;
   	s="";
   	for(int i=1;i<=n;i++)
   	{
   		if(i<=9)
   		s.push_back(i+'0');
   		else
   		{
   			string s1="";
   			int p=i;
   			while(p!=0)
   			{
   				int r=p%10;
   				s1.push_back(r+'0');
   				p=p/10;
			}
			reverse(s1.begin(),s1.end());
			s+=s1;
		}
	}
	cout<<s[n-1];
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
       int n,a[102],i,j,sum,min=1e9;
       cin >> n;
       for(int i=1; i<=n; i++) cin >> a[i];
       for(int i=1; i<=n; i++)
       {
              sum=0;
              for(int j=1; j<=n; j++)
              {
                     sum+=a[j]*2*(abs(i-j)+(i-1)+(j-1));
              }
              if(sum<min) min=sum;
       }
       cout << min;
}


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

int l, r, p, pri[105], tot, n, c[3000010], f[3000010];
bool v[3000010];

void getpri(int n)
{
	for (int i = 2; i <= n; ++i)
	{
		if (!v[i]) pri[++tot] = i;
		for (int j = 1; i * pri[j] <= n; ++j)
		{
			v[i * pri[j]] = true;
			if (i % pri[j] == 0) break;
		}
	}
}

void add(int x, int now)
{
	c[++n] = x;
	for (int i = now; i <= tot; ++i)
		if (1ll * x * pri[i] <= r)
			add(x * pri[i], i);
}

int main()
{
//	freopen("schizophrenia.in", "r", stdin);
//	freopen("schizophrenia.out", "w", stdout);
	cin >> l >> r >> p;
	getpri(p); add(1, 1);
	sort(c + 1, c + n + 1);
	memset(f, 0x3f, sizeof f);
	f[1] = 0;
	for (int i = 2; i <= p; ++i)
	{
		int k = 1;
		for (int j = 1; j <= n; ++j)
		{
			if (1ll * c[j] * i > r) break;
			while (c[k] < c[j] * i) ++k;
			f[k] = min(f[k], f[j] + 1);
			if (f[k] + i <= p) v[k] = 1;
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		if (c[i] >= l) ans += v[i];
	cout << ans << endl;
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
	char p[20];
	char c[20];
	int n,i;
	int ans=0;
	scanf("%s%d",p,&n);
	int lambai=strlen(p);
	if(n>=lambai)
	{
		for(i=0;i<lambai;i++)
		{
			if(p[i]=='0')
			{
				ans=lambai-1;
				break;
			}
			else
			{
				continue;
			}
		}
		printf("%d\n",ans);
	}
	else
	{
		int z=0;
		for(i=lambai-1;i>=0;i--)
		{
			c[i]=p[i];
		}
		for(i=lambai-1;i>=0;i--)
		{
			if(p[i]!='0')
			{
				c[i]='0';
				ans++;
			}
			else
			{
				z++;
			}
			if(z==n)
			{
				break;
			}
		}
		if(atoi(c)!=0)
		{
			printf("%d\n",ans);
		}
		else
		{
			printf("%d\n",lambai-1);
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

#ifndef ONLINE_JUDGE
	#define ONLINE_JUDGE
#endif

#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MOD(x)   ((x)>0?(x):(-(x)))
#define pb push_back
#define mp make_pair
#define rep(i,n) for(i=0;i<n;i++)
#define repr(i,j,n) for(i=j;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define endl '\n'
using namespace std;
typedef long long ll;
const ll maxn = (ll) 1e5+9;
const ll mod = (ll) 1e9+7;

string nstr,kstr;
vector<string> vals;

int main()
{
	std::ios::sync_with_stdio(0);
	ll i,j,k,t,q,m,l,r,n,bs;
	cin>>nstr;
	cin>>kstr;

	k=kstr.size();
	while(k>0) {
		j = k-nstr.size(); if(j<0)j=0;

		if(k-j == nstr.size()) {
			for(t=0;t<nstr.size();t++) {
				if(nstr[t]!=kstr[j+t])break;
			}
			if(t<nstr.size()) {
				if(t==0 && kstr[j+t]=='0') {
					j=j+t;
					while(k-j>1 && kstr[j]=='0')j++;
				}
				else if(kstr[j+t]>nstr[t]) {
					j=j+1;
					while(k-j>1 && kstr[j]=='0')j++;
				}
			}
			else {
				j++;
				while(k-j>1 && kstr[j]=='0')j++;
			}
		}

		vals.pb(kstr.substr(j,k-j));
		k=j;
	}
	//rep(i,vals.size())cout<<vals[i]<<endl;

	bs=0;
	rep(i,nstr.size()) {
		bs=(bs*10+(nstr[i]-'0'));
	}

	m=0;n=1;
	rep(i,vals.size()) {
		k=0;
		rep(j,vals[i].size()) {
			k=(k*10+(vals[i][j]-'0'));
		}
		m+=k*n;
		n*=bs;
	}
	cout<<m<<endl;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int n, x, l, r;
  int a[16];
  while (~scanf("%d%d%d%d", &n, &l, &r, &x)) {
    int count = 0;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    for (int cout = 1; cout <= 1 << n; cout++) {
      int _max = 0;
      int _min = 100000000;
      int sum = 0;
      for (int i = 0; i < n; i++) {
        if (cout >> i & 1) {
          _min = min(_min, a[i]);
          _max = max(_max, a[i]);
          sum += a[i];
        }
      }

      if ((_max - _min >= x) && sum >= l && sum <= r)
        count++;
    }

    cout << count << endl;
  }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
long long	int a,b,c,d;
	cin>>a>>b>>c>>d;
if(a>b&&c<d){cout<<"Misha";}
else if(a<b&&c>d){cout<<"Vasya";}

else	if(max((a*3)/10,a-(a/250)*c)>max(b*3/10,b-(b/250)*d)){
		cout<<"Misha";
	}
	else if(max(a*3/10,a-(a/250)*c)<max(b*3/10,b-(b/250)*d)){
		cout<<"Vasya";
	}
	else cout<<"Tie";
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n , k , a,b,i,j,s=0;

//    scanf("%d %d %d %d",&n,&k,&a,&b);
    cin>>n>>k>>a>>b;

    while(n>1)
    {

        //cout<<n<<endl;
        int d = n%k;
        s+=d*a;

        n-=d;

        if((n-(n/k))*a>=b){n/=k;s+=b;}
        else {s +=(n-1)*a; break;}

    }

    //cout<<n<<endl;
    cout<<s<<endl;

    return 0;
}


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

const int MAXN = 40;

//[0, i) matched length |s| with T or F
//first |s|-i character, last i character matched length |s| with T or F
using State = pair<uint64_t, uint64_t>;
State OK = {-1, -1};

State trans(int N, const string& s, const State& st, int idx, char next)
{
    int M = (int)s.size();
    if(st == OK) return OK;
    State n = {0, st.second};
    n.first |= 1;
    for(int i=0; i<M; ++i)
    {
        uint64_t mask = ((uint64_t)1)<<i;
        if( (st.first&mask) && s[i] == next) n.first |= (((uint64_t)1)<<(i+1));
    }
    if(n.first & (((uint64_t)1)<<M)) return OK;

    for(int i=0; i<M; ++i)
    {
        uint64_t mask = ((uint64_t)1)<<i;
        if(idx < M-i && s[i+idx] != next) n.second &= ~mask;
        if(idx >= N-i && s[idx-(N-i)] != next) n.second &= ~mask;
    }
    if(idx == N-1 && n.second) return OK;
    return n;
}

long long solve(int N, string s)
{
    map<State, long long> M;
    M[{1, ((((uint64_t)1)<<s.size())-1)}] = 1;
    for(int i=0; i<N; ++i)
    {

        map<State, long long> M2;
        for(auto [a, b]: M)
        {
            cerr << a.first << " " << a.second << " " << b << endl;
            M2[trans(N, s, a, i, '0')] += b;
            M2[trans(N, s, a, i, '1')] += b;
        }
        cerr << endl;
        M = M2;
    }
    for(auto [a, b]: M) cerr << a.first << " " << a.second << " " << b << endl;
    cerr << endl;
    return M[OK];
}

int main()
{
    int N; string s;
    cin >> N >> s;
    cout << solve(N, s) << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,now,jaznow,ans=0;
 cin>>n;
 for(int i=1;i<=n;i++)
 {
     for(int j=1;j<=n;j++)
     {
         now=i*i+j*j;
         jaznow=sqrt(now);
         if(jaznow*jaznow==now and jaznow<=n)
         {
             if(i==j)
             ans+=2;
             else
             ans++;
         }
     }
 }
 cout<<ans/2;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

const ll inf = LLONG_MAX;

#define rel( i, a, b) for( ll i = a ; i <= b ; i++ )
#define rep( k, a, b) for( ll k = a ; k <= b ; k+=2*k )
#define rev( i, a, b) for( ll i = b ; i >= a ; i-- )
#define M 1000000007
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector<pll>
#define mll map<ll,ll>
#define mpll map<ll,pll>
#define sll set<ll>
#define spll set<pll>
#define msll multiset<ll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define FIO ios::sync_with_stdio(false);cin.tie(0);cerr.tie(0)
#define lb lower_bound
#define ub upper_bound
#define fprint(x) cout << fixed << setprecision(10) << (ld)x;
ll n, m;
ll mini, maxi;

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

	ll t1, t2;

	t1 = n/m;

	mini = m*((t1*(t1-1))/2);

	if( n % m != 0 ){
		ll t = n%m;

		mini += t1*t;
	}

	maxi = ((n-m+1)*(n-m))/2;

	cout << mini << " " << maxi;

	return 0;
}


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

bool dfs(vector<int> &v,int b)
{
    if(v.back()==b)
    return true;

    if(v.empty() or v.back()>b)
    return false;

    int x=v.back();//new term learnt
    v.push_back(2*x);
    if(dfs(v,b))
    return true;
    else
    v.pop_back();

    v.push_back(10*x+1);
    if(dfs(v,b))
    return true;
    else
    v.pop_back();

    return false;
}

int32_t main()
{
   cin>>a>>b;
  vector<int>v;
  v.push_back(a);

  bool flag=dfs(v,b);
  if(flag)
  {
      cout<<"YES"<<endl;
      cout<<v.size()<<endl;
      for(auto i:v)
      cout<<i<<" ";

      cout<<endl;
  }
  else
  cout<<"NO"<<endl;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{

int n;
cin >> n;
int lg10 = log10(n);

    long long dig = 0;
    long long keepUp = 0;
    unsigned long long  now;
    lg10 ++;
    for(int i = 1;i <= lg10;i ++){
        now = pow(10.0,i) + 0.5;
        if(i < lg10){
            dig += ( (now - 1 - keepUp)* i );
            keepUp = (now - 1);
            //cout<<dig<<" "<<keepUp<<endl;
        }
        else
            dig += ( (n - keepUp)* i);
    }
    cout<<dig;

    return 0;
}


#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

const long long MAXN = 2000;
const long long mod = 1000000007;
long long C[MAXN][MAXN], nn[MAXN], f[MAXN];
long long a[MAXN];
long long n, k;
long long res = 0, s = 0;

long long next(long long a[], long long l, long long r, long long up)
{
	a[r + 1] = 0;
	a[l]++;
	for(long long i = l; i <= r; i++)
		if (a[i] > up)
		{
			a[i] = 1;
			a[i + 1]++;
		}
	if (a[r + 1])
		return 0;
	return 1;
}

long long pow(long long a, long long b)
{
	long long res = 1;
	for(long long i = 1; i <= b; i++)
		res = res * a % mod;
	return res;
}

int main()
{
	cin >> n >> k;
	for(long long i = 0; i <= n; i++)
		C[i][0] = 1;
	for(long long i = 1; i <= n; i++)
		for(long long j = 1; j <= n; j++)
			C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
	nn[0] = 1;
	//for(long long i = 1; i <= n; i++, prlong longf("\n"))
	//	for(long long j = 1; j <= n; j++)
	//		prlong longf("%I64d ", C[i][j]);
	for(long long i = 1; i <= n; i++)
		nn[i] = nn[i - 1] * i % mod;
	res = pow(n - k, n - k);

	//prlong longf("%I64d\n", res);
	for(long long i = 1; i <= k; i++)
	{
		long long tmp = C[k - 1][i - 1] * nn[i - 1] % mod;
		long long left = k - i;
		for(long long j = i + 1; j <= k; j++)
			a[j] = 1;
		long long tmp2 = 0;
		while(1)
		{
			long long flag = 1;
			for(long long j = i + 1; j <= k; j++)
			{
				long long x = j, ok = 0;
				for(long long l = 1; l <= k; l++)
				{
					x = a[x];
					if (x <= i)
						ok = 1;
				}
				if (!ok)
				{
					flag = 0;
					break;
				}
			}
			tmp2 += flag;
			if (!next(a, i + 1, k, k))
				break;
		}
		s += tmp2 * tmp % mod;
		s %= mod;

	}
	cout << res * s % mod << endl;
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int a, b, c, mxn = -1;

	cin >> a >> b >> c;

	mxn = max(mxn, a * b * c);
	mxn = max(mxn, a + b + c);
	mxn = max(mxn, a * b + c);
	mxn = max(mxn, a + b * c);
	mxn = max(mxn, a * (b + c));
	mxn = max(mxn, (a + b) * c);

	cout << mxn << endl;

	return 0;
}


#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; i++)
#define _per(i, x, y) for(int i = x; i >= y; i--)
#define LL long long
using namespace std;
template <typename T>
inline void read(T &x) {
    x = 0;
    LL f = 1;
    char c = getchar();
    for (; !isdigit(c); c = getchar())
        if (c == '-')
            f = -1;
    for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
    x *= f;
}
template <typename T>
inline void write(T x) {
	if(x < 0) {putchar('-'); x = -x;}
	if(x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
int n, x, m;
int mul_mod(int a, int b, int m) {
	return 1ll * a * b % m;
}
int pow_mod(int a, int b, int m) {
	int res = 1;
	while(b) {
		res = (b & 1 ? mul_mod(res, a, m) : res);
		a = mul_mod(a, a, m);
		b >>= 1;
	}
	return res;
}
bool is_prime(int n) {
	if(n < 2) return false;
	_rep(i, 2, sqrt(n)) {
		if(n % i == 0) return false;
	}
	return true;
}
bool is_primitive_root(int g) { // pr
	if(!(g % m)) return false;
	_rep(i, 2, sqrt(n)) {
		if(!(n % i)) {
			if(pow_mod(g, i, m) == 1) return false;
			if(pow_mod(g, (m - 1) / i, m) == 1) return false;
		}
	}
	return true;
}
int main() {
	read(n); read(x); m = n + 1;
	if(!is_prime(m)) {write(-1); return 0;}
	_per(i, x - 1, 2) {
		if(is_primitive_root(i)) {
			write(i); return 0;
		}
	}
	write(-1);
	return 0;
}


/* Codeforces 382E. Ksenia and Combinatorics
 *   组合计数，树DP，DP套DP
 *   combinatorics, dp */
#include <iostream>
#include <algorithm>

typedef long long calc_t;
const int MaxN = 52, mod_v = 1000000007;
calc_t f[MaxN][MaxN >> 1][2], C[MaxN][MaxN];

void init_comb(int n)
{
	for(int i = 0; i <= n; ++i)
	{
		C[i][i] = C[i][0] = 1;
		for(int j = 1; j < i; ++j)
		{
			C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
			if(C[i][j] >= mod_v) C[i][j] -= mod_v;
		}
	}
}

int main()
{
	int n0, k0;
	std::cin >> n0 >> k0;
	if(k0 << 1 > n0)
	{
		std::cout << "0\n";
		return 0;
	}

	init_comb(n0);
	f[1][0][0] = 1; f[0][0][1] = 1;
	for(int n = 2; n <= n0; ++n)
	{
		for(int k = 1; k <= std::min(k0, n >> 1); ++k)
		{
			for(int g = 0; g <= 1; ++g)
			{
				calc_t& val = f[n][k][g];
				for(int n1 = 0, n2 = n - 1; n1 <= n2; ++n1, --n2)
				{
					calc_t ways;
					if(n1 != n2) ways = C[n - 1][n1];
					else ways = C[n - 2][n1 - 1];
					if(n1) ways = ways * n1 * n2 % mod_v;
					else ways = ways * n2 % mod_v;

					for(int k1 = 0; k1 + g <= k; ++k1)
					{
						int k2 = k - k1 - g;
						if(g == 0)
						{
							val += f[n1][k1][1] * f[n2][k2][1] % mod_v * ways % mod_v;
						} else {
							val += (f[n1][k1][1] * f[n2][k2][0]
								 + f[n1][k1][0] * f[n2][k2][1]
								 + f[n1][k1][0] * f[n2][k2][0]) % mod_v * ways % mod_v;
						}
					}

					val %= mod_v;
				}
			}
		}
	}

	std::cout << (f[n0][k0][0] + f[n0][k0][1]) % mod_v << std::endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string str;
	cin>>str;
	string ans;
	int start=0;
	while(str!="\0"){
		if(str.find("ogo")==string::npos){
			ans.append(str);
			break;
		}
		int pos=str.find("ogo");
		for(int i=0;i<pos;i++)
			ans+=str[i];
		int i=pos+3;
		while(str[i]=='g'&&str[i+1]=='o')
			i=i+2;
		ans.append("***");
		i--;
		str.erase(start,i-start+1);
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std ;
typedef long long ll;

ll a, b, ans;

int main () {
    cin >> a >> b;
    if(a == b) {
        cout << 1;
        return 0;
    }
    long long x = b - a;
    //cout << x << '\n';
    if (x >= 5){
        cout << 0;
        return 0;
    }
    if (x == 1){
        cout << b % 10;
        return 0;
    }
    ans = 1;
    for (long long i = a + 1; i <= b; ++i){
        ans *= i;
        ans %= 10;
    }
    cout << ans % 10;
    return 0;
}
/*
998244355 998244359
*/


#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,k,w,i,s=0;
	cin>>k>>n>>w;
	for (i=1;i<=w;i++)
	s+=i;
	cout<<max(s*k-n,0);
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (1e9+20)
typedef long long int LL;

#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
struct data
{
    int x,y;
} a[45],book[45];
void init ()
{
    int liu=1;
    for (int i=1; i<=3; i++)
    {
        for (int j=1; j<=3; j++)
        {
            book[liu].x=i;
            book[liu].y=j;
            liu++;
        }
    }
    book[0].x=4;
    book[0].y=2;
    return;
}
void work ()
{
    init ();
    int n;
    scanf ("%d",&n);
    char str[100];
    scanf ("%s",str+1);
    int lena=2;
    for (int i=2; i<=n; i++)
    {
        int x=book[str[i-1]-'0'].x;
        int y=book[str[i-1]-'0'].y;
        a[lena].x=book[str[i]-'0'].x-x;
        a[lena].y=book[str[i]-'0'].y-y;
        lena++;
    }
    for (int i=1; i<=3; i++)
    {
        for (int j=1; j<=3; j++)
        {
            int bx=i;
            int by=j;
            if (bx==book[str[1]-'0'].x&&by==book[str[1]-'0'].y) continue;
            int t=2;
            while (t<=n)
            {
                int nx=bx+a[t].x;
                int ny=by+a[t].y;
                //printf ("%d %d %d %d\n",bx,by,nx,ny);
                if (nx>=1&&nx<=3&&ny>=1&&ny<=3 || nx==4&&ny==2)
                {
                    bx=nx;
                    by=ny;
                }
                else break;
                t++;
            }
            if (t==n+1)
            {
                //printf ("%d %d\n",i,j);
                printf ("NO\n");
                return ;
            }
        }
    }
    int bx=4;
    int by=2;
    int t=2;
    if (bx==book[str[1]-'0'].x&&by==book[str[1]-'0'].y) t=inf;
    while (t<=n)
    {
        int nx=a[t].x+bx;
        int ny=a[t].y+by;
        if (nx>=1&&nx<=3&&ny>=1&&ny<=3 || nx==4&&ny==2)
        {
            bx=nx;
            by=ny;
        }
        else break;
        t++;
        if (t==n+1)
        {
            printf ("NO\n");
            return ;
        }
    }
    printf ("YES\n");
    return ;
}

int main ()
{
#ifdef local
    freopen("data.txt","r",stdin);
#endif
    work ();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define sz(x)             (int)((x).size())
// #define int               long long
#define M                 1000000007
#define MOD                 1000000007
#define MM                998244353
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T>pair<T,T> operator+=(pair<T,T> &a,pair<T,T> b){a.fr+=b.fr;a.sc+=b.sc;return a;}
template<typename T>pair<T,T> operator-=(pair<T,T> &a,pair<T,T> b){a.fr-=b.fr;a.sc-=b.sc;return a;}
template<typename T>pair<T,T> operator+(pair<T,T> a,pair<T,T> b){a.fr+=b.fr;a.sc+=b.sc;return a;}
template<typename T>pair<T,T> operator-(pair<T,T> a,pair<T,T> b){a.fr-=b.fr;a.sc-=b.sc;return a;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

const int INF=1e18;

const int N=1e6+5;

int pw(int a,int b=M-2,int p=M){
	if(b==0)return 1;
	int t=pw(a,b/2,p);
	if(b%2)return (((1LL*a*t)%p)*t)%p;
	else return ((1LL*t*t)%p);
}

struct mod_int {
    int val;

    mod_int(long long v = 0) {
        if (v < 0) v = v % MOD + MOD;
        if (v >= MOD) v %= MOD;
        val = v;
    }

    static int mod_inv(int a, int m = MOD) {
        // https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Example
        int g = m, r = a, x = 0, y = 1;

        while (r != 0) {
            int q = g / r;
            g %= r; swap(g, r);
            x -= q * y; swap(x, y);
        }

        return x < 0 ? x + m : x;
    }

    explicit operator int() const {
        return val;
    }

    mod_int& operator+=(const mod_int &other) {
        val += other.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }

    mod_int& operator-=(const mod_int &other) {
        val -= other.val;
        if (val < 0) val += MOD;
        return *this;
    }

    static unsigned fast_mod(uint64_t x, unsigned m = MOD) {
        return x%m;
    }

    mod_int& operator*=(const mod_int &other) {
        val = fast_mod((uint64_t) val * other.val);
        return *this;
    }

    mod_int& operator/=(const mod_int &other) {
        return *this *= other.inv();
    }

    friend mod_int operator+(const mod_int &a, const mod_int &b) { return mod_int(a) += b; }
    friend mod_int operator-(const mod_int &a, const mod_int &b) { return mod_int(a) -= b; }
    friend mod_int operator*(const mod_int &a, const mod_int &b) { return mod_int(a) *= b; }
    friend mod_int operator/(const mod_int &a, const mod_int &b) { return mod_int(a) /= b; }

    mod_int& operator++() {
        val = val == MOD - 1 ? 0 : val + 1;
        return *this;
    }

    mod_int& operator--() {
        val = val == 0 ? MOD - 1 : val - 1;
        return *this;
    }

    mod_int operator++(int32_t) { mod_int before = *this; ++*this; return before; }
    mod_int operator--(int32_t) { mod_int before = *this; --*this; return before; }

    mod_int operator-() const {
        return val == 0 ? 0 : MOD - val;
    }

    bool operator==(const mod_int &other) const { return val == other.val; }
    bool operator!=(const mod_int &other) const { return val != other.val; }

    mod_int inv() const {
        return mod_inv(val);
    }

    mod_int pow(long long p = MOD-2) const {
        assert(p >= 0);
        mod_int a = *this, result = 1;

        while (p > 0) {
            if (p & 1)
                result *= a;

            a *= a;
            p >>= 1;
        }

        return result;
    }

    friend ostream& operator<<(ostream &stream, const mod_int &m) {
        return stream << m.val;
    }
    friend istream& operator>>(istream &stream, mod_int &m) {
        return stream >> m.val;
    }
};

mod_int P[N];
// int d[N];
// int num[N];
mod_int ele[N];
void solve(){
	int n,k;
	cin>>n>>k;
	rep(i,1,k+4){
		mod_int j=i;
		P[i]=P[i-1]+j.pow(k);
		// P[i]%=M;
	}
	if(n<=k+2){
		cout<<P[n];
		return;
	}
	// d[1]=1;
	ele[1]=1;
	// num[1]=1;
	rep(i,1,k+2){
		// d[1]*=M-i;
		// d[1]%=M;
		// num[1]*=(M+n-i-1)%M;
		// num[1]%=M;
		ele[1]*=(M+n-i-1);
		// ele[1]%=M;
		// ele[1]*=mod_int(M-i).pow();
		ele[1]/=mod_int(M-i);
		// ele[1]%=M;
	}
	// cout<<num[1]<<"\n";
	mod_int ans=0;
	// ans+=num[1]*pw(d[1])%M * P[1]%M;
	ans+=ele[1]*P[1];
	rep(i,2,k+3){
		// d[i]=d[i-1]*pw(M-k+i-3)%M;
		// d[i]=d[i]*(i-1)%M;
		// num[i]=num[i-1]*pw(M+n-i)%M;
		// num[i]=num[i]*(M+n-i+1)%M;
		ele[i]=ele[i-1]*(M-k+i-3);
		// ele[i]*=mod_int(i-1).pow();
		ele[i]/=mod_int(i-1);
		// ele[i]*=mod_int(M+n-i).pow();
		ele[i]/=mod_int(M+n-i);
		ele[i]*=(M+n-i+1);
		ans+=ele[i] * P[i] ;
		// ans%=M;
	}
	cout<<ans;
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SEIVE
		seive();
	#endif
	#ifdef NCR
		init();
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 205
typedef long long ll;
int n,mod,ans;
int dp[N][N][N],fac[N],ifac[N];
int qpow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return ans;
}
void init(int n){
	fac[0]=1;
	for(int i=1;i<=n;++i){
		fac[i]=1LL*fac[i-1]*i%mod;
	}
	ifac[n]=qpow(fac[n],mod-2);
	for(int i=n-1;i>=0;--i){
		ifac[i]=1LL*ifac[i+1]*(i+1)%mod;
	}
}
int a1;
int dfs(int i,int j,int k){ // a_1+...+a_i=j,a_i=k
	if(!k)return !j?ifac[i]:0;
	if(n-i<n+1-a1-k)return 0;
	if(~dp[i][j][k])return dp[i][j][k];
	int &tmp=dp[i][j][k];
	tmp=0;
	for(int cnt=0;k*cnt<=j&&cnt<=i;++cnt){
		tmp=(tmp+1LL*ifac[cnt]*dfs(i-cnt,j-k*cnt,k-1))%mod;
	}
	return tmp;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>mod;
	init(n);
	for(a1=max(1,n-25);a1<=n+1;++a1){
		memset(dp,-1,sizeof(dp));
		for(int sum=1;sum<=a1;++sum){
			ans=(ans+dfs(n,sum,n+1-a1))%mod;
		}
	}
	cout<<(1LL*ans*fac[n]+1)%mod<<'\n';
	return 0;
}


// author: Ryuuk
#include<bits/stdc++.h>
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define LSOne(i) (i&(-i))
#define REP(i,a,b) for(int(i)=(a);(i)<(b);i++)
#define BUG(x) {cout<<#x<<" = "<<x<<endl;}
#define left(x) (x<<1)
#define right(x) ((x>>1) +1)
#define middle(s,e)(s+(e-s)/2)
#define size_tree(n) 2*(int)pow(2,ceil(log2(n)))
#define CL(A,I) (memset(A,I,sizeof(A)))

static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const long double epsilon = 1e-15;
static const long double pi = acos((long double) -1);
using namespace std;
inline void init_io(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
void read(int &number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef long long ll;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE
    init_io();
    int n , pos, l ,r ;
    cin>>n>>pos>>l>>r;
    int a = 1, b = n ;
    int res ;
    if(pos>=l && pos <=r && a<l && b>r)
    {
        int x = min(pos-l, r-pos);
        res=x+1 + r-l+1;
    }
    else if(pos>=l && pos <=r)
    {
        if(a==l && b==r)
            res = 0;
        else if(a==l)
        {
            res = r-pos +1;
        }
        else if(b==r)
        {
            res = pos-l +1;
        }
    }
    else if(pos<l)
    {
        if(b>r)
            res = (l-pos+1) + r-l +1;
        else
            res = (l-pos+1);
    }
    else if(pos>r)
    {
        if(a<l)
            res =(pos-r+1)+ r-l+1;
        else
            res =(pos-r+1);
    }

    cout <<res<<endl;
    return 0;
}


#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cstdlib>
using namespace std;
char s[1005],a;
int main(){
//	freopen("cp.in","r",stdin);
	int l=0;
	while(~scanf("%c",&a)) s[++l]=a;
	for(int i=l;i;i--)
		if(s[i]>='a'&&s[i]<='z'||s[i]>='A'&&s[i]<='Z'){
			if(s[i]=='Y'||s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U'||s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='y'){printf("YES");return 0;}
			break;
		}
	printf("NO");
	return 0;
}


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

#define double long double
#define int long long
#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first,l.second+r.second};
}
typedef void (*callback_function)(void); // type for conciseness
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
typedef long long ll;
#undef int
int main() {
#define int long long
	ios_base::sync_with_stdio(false);
	cin.tie();
  //auto beginProgram = chrono::steady_clock::now();

/* Tutorial by Bugman
448B - Suffix Structures

Solution:7139584

Consider each case separately. If we use only suffix automaton then s transform
to some of its subsequence. Checking that t is a subsequence of s can be
performed in different ways. Easiest and fastest — well-known two pointers
method. In case of using suffix array we can get every permutation of s. If it
is not obvious for you, try to think. Thus, s and t must be anagrams. If we
count number of each letter in each string, we can check this. If every letter
appears in s the same times as in t then words are anagrams. In case of using
both structures strategy is: remove some letters and shuffle the rest. It is
possible if every letter appears in s not less times than in t. Otherwise it is
impossible to make t from s. Total complexity O(|s| + |t| + 26).
*/

  {// Code goes here
    string s, t; cin >> s >> t;
    vec<int> cntS(256, 0), cntT(256, 0);
    for (char &ch : s) cntS[ch]++;
    for (char &ch : t) cntT[ch]++;
    FORE(i, 'a', 'z') if (cntS[i] < cntT[i]) {
      cout << "need tree" << endl; return 0;
    }
    int i = 0, j = 0;
    while (j < t.length()) {
      while (i < s.length() && s[i] != t[j]) i++;
      if (i == s.length()) {
        cout << (s.length() != t.length() ? "both" : "array") << endl;
        return 0;
      }
      i++, j++;
    }
    cout << "automaton" << endl;
  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>

typedef unsigned long long ll;

using namespace std;

struct Point {
	int x, y, k;
};

double pi = 3.14159265358979;

double RAD(double x1, double y1, double x2, double y2) {
	if (!(sqrt(x1*x1 + y1 * y1)*sqrt(x2*x2 + y2 * y2)))
	{
		return  pi / 2;
		return 0;
	}
	double r = acos((x1*x2 + y1 * y2) / (sqrt(x1*x1 + y1 * y1)*sqrt(x2*x2 + y2 * y2)));
	return double(abs(r) + (r < 0)*(pi / 2));
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, p;
	cin >> n >> p;
	int minn = -1;
	int k = 0;
	for (int i = 1; i <= 1000; i++)
	{
		if (n - p * i<i)
		{
			cout << minn;
			return 0;
		}
		int n1 = n - i * p;
		if (n1 == 1 && i!=1)
		{
			cout << minn;
			return 0;
		}
		while (n1)
		{
			//cout << n1 % 2;
			k += n1 % 2;
			n1 /= 2;
		}
		//cout << ' ' << k << '\n';
		if (k <= i && (minn == -1 || minn>i))
		{
			minn = i;
		}
		k = 0;
	}
	cout << minn;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>

/* A. Olympiad */

using namespace std;
typedef long long ll;

int n, a[105], res, vis[605];

int main(int argc, char * argv[])
{
	scanf("%d", &n);
    for (int i = 0; i < n; i ++)
        scanf("%d", &a[i]);
    sort(a, a + n);
    res = 0;
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < n; i ++)
    {
    	if (a[i] != 0 && !vis[a[i]])
    	{
    		res ++;
    		vis[a[i]] = 1;
    	}
    }
    cout << res << endl;
    return 0;
}


//194 A
#include<iostream>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;

    if(k>2*n)
    {
        k = k - 2*n;
        if(k>n)
            cout<<0;
        else
            cout<<n-k;
    }
    else
        cout<<n;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	int t;
	cin >> t;
	vector<vector<int>> a(2,vector<int>(2));
	while(t--){
		int cnt=0;
		for(int i=0; i<2; i++){
			for(int j=0; j<2; j++){
				cin >> a[i][j];
				if(a[i][j]==1) cnt++;
			}
		}
		if(cnt==0){
			cout << 0 << endl;
		}
		else if(cnt==4){
			cout << 2 << endl;
		}
		else{
			cout << 1 << endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int n,b[5051],sum;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=100;i++)
    {
    sum+=i;
    b[sum]=1;
    }
    if(b[n])
    cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>
#define db(x) cout<<x<<" "
#define db1(x) cout<<x<<'\n'
#define db2(x,y) cout<<x<<" "<<y<<'\n'
#define db3(x,y,z) cout<<x<<" "<<y<<" "<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pair(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pair<int,int>>
//#define um unordered_map<int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
// #define mod 1000000007
#define mod 1073741824
#define MAX_N 100000
using namespace std;
using ll = long long int;
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

string check(string &s, int k) {

	int n = s.length();

	set<char,greater<char>> st;

	rep(i,k)
	st.insert(i+'a');

	string ans = "IMPOSSIBLE";

	rep(i,s.length()) {
		if(st.find(s[i])!=st.end())
		st.erase(s[i]);
	}

	int i,j;

	if (n%2) {
		//odd;
		 i = n/2-1;
		 j = n/2+1;
		if(s[n/2]=='?'){
			if(st.size())
			{
				s[n/2] = *st.begin();
				st.erase(s[n/2]);
			}
			else {
				s[n/2] = 'a';
			}
		}
	}
	else {
		i=n/2-1;
		j=n/2;
	}

	while(i>=0 && j<s.length() && st.size()) {

		if (s[i] =='?' && s[j] =='?') {
			s[i] = *st.begin();
			s[j] = *st.begin();
			st.erase(s[i]);
		}
		i--;
		j++;
	}

	if(st.size())
		return ans;

	if(n%2) {
		i=n/2-1;
		j=n/2+1;
	}
	else {
		j=n/2;
		i=n/2-1;
	}

	while (i>=0 && j<s.length()) {

		if(s[i]=='?') {
			s[i] = s[j];
		}
		else if (s[j]=='?') {
			s[j] = s[i];
		}
		else {
			if(s[i]!=s[j])
				return ans;
			if (s[i]-'a'>=k)
				return ans;
		}

		i--;
		j++;
	}

	rep(i,s.length()) {
		if (s[i] == '?')
			s[i] = 'a';
	}

	return s;

}

void solve() {

	int k;
	cin>>k;

	string s;
	cin>>s;

	s = check(s,k);

	db1(s);

}

int main(){

 int t = 1;
 //cin>>t;

while(t--){
 solve();
  }
  return 0;
}


#include <iostream>
using namespace std;
int main(){
    int a,b; cin >> a >> b;
    int sum=0;
    if(abs(a-b)%2==0){
        for(int i=1;i<=abs(a-b)/2;i++){
            sum += i;
        }
        cout << 2*sum << "\n";
    }
    else {
        int diff = abs(a-b)/2;
        int d1=diff+1;
        int d2=diff;
        for(int i=1;i<=d1;i++) sum+=i;
        for(int i=1;i<=d2;i++) sum+=i;
        cout << sum << "\n";
    }
    return 0;
}


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

int main()
{
  ll n,a,b;
  cin>>n>>a>>b;
  if(min(a,b)>=n)
  cout<<"YES\n";
  else
  cout<<"NO\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace  std;
#define ll __int64
#define ull unsigned long long
const int N = 5e6+10;

int vis[110][110];
int f[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};

struct node {
	int x, y, step;
	friend bool operator < (const node n1, const node n2) {
		return n1.step > n2.step;
	}
}t, e;
priority_queue<node>q;

int bfs(int l, int u, int xi, int yi) {
	e.x=l, e.y=u, e.step=0;
	q.push(e);
	vis[e.x][e.y] = 1;
	while(!q.empty()) {
		e = q.top(); q.pop();
		if(e.x == xi && e.y == yi) return e.step;
		for(int i = 0; i < 4; i++) {
			t.x = e.x + f[i][0];
			t.y = e.y + f[i][1];
			t.step = e.step + 1;
			if(t.x<0 || t.y<0) continue;
			if(vis[t.x][t.y]) continue;
			vis[t.x][t.y] = 1;
			q.push(t);
		}
	}
}

int main() {
	string s;
	cin>>s;
	int len = (int)s.size();
	int x=0, y=0, xx=0, yy=0;
	for(int i = 0; i < len; i++) {
		if(s[i] == 'L') y--;
		if(s[i] == 'R') y++;
		if(s[i] == 'U') x--;
		if(s[i] == 'D') x++;
		xx = min(xx, x);
		yy = min(yy, y);
	}
	xx = -xx, yy = -yy;
	for(int i=0; i<110; i++) {
		for(int j=0; j<110; j++) vis[i][j] = 1;
	}
	x=xx, y=yy;
	for(int i=0; i<len; i++) {

		if(s[i] == 'L') y--;
		if(s[i] == 'R') y++;
		if(s[i] == 'U') x--;
		if(s[i] == 'D') x++;
		vis[x][y] = 0;

	}
	int ans = bfs(xx, yy, x, y);

	if(ans == len) printf("OK\n");
	else printf("BUG\n");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
   int m,n,z,lcm;
   cin>>m>>n>>z;
   if(m>n)
      lcm = m;
   else
      lcm = n;
   while(1) {
      if( lcm%m==0 && lcm%n==0 ) {
         cout<<z/lcm;
         break;
      }
      lcm++;
   }
   return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using pii = pair<int, int>;
using vi = vector <int>;
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define ook order_of_key
#define fbo find_by_order
#define sq(x) (x) * (x)
#define N 2005

ll n, dp[N][N], ans, mod = 1e9 + 7, sum[N];
int main (){
	cin >> n;
	n *= 2;
	dp[0][0] = 1;
	for (int i = 0;i < n;i++)
		for (int j = 0;j <= n - i;j++){
			sum[i] = (sum[i] + dp[i][j]) % mod;
			if (j) dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j]) % mod;
			dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % mod;
		}
	for (int i = n - 1;i >= 0;i -= 2)
		ans = (ans + sum[i]) % mod;
	cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

#define sz s.size()

string s;

int c;

int main () {
    cin >>s;
    for (int i=0;i<sz;i++){
        if ('A'<=s[i] && s[i]<='Z'){
            c++;
        }
    }
    if (c==sz){
        for (int i=0;i<sz;i++){
            s[i]=tolower (s[i]);
        }
    }
    if (('a'<=s[0] && s[0]<='z') && c+1==sz){
        s[0]=toupper (s[0]);
        for (int i=1;i<sz;++i){
            s[i]=tolower (s[i]);
        }
    }
    cout <<s;
    return 0;
}


#include<cstdio>
#include<cstring>
using namespace std;
const int maxN = 1<<7, maxL = 7, M = 1e9+7;
struct Matr {
  int size;
  int ele[maxN][maxN];
} m[maxL+1];
int ans, w[maxL+1], dp[maxL][2], sum[maxL+1][maxN];
int solve(int u, int v, int n) {
  memset(dp, 0, sizeof dp);
  dp[0][1] = 1;
  for (int i = 0; i < n; i++) {
    dp[i+1][0] = (dp[i][0]+dp[i][1])%M;
    dp[i+1][1] = dp[i][0];
    if (((u>>i)&1)==1 || ((v>>i)&1)==1) dp[i+1][1] = (dp[i+1][1]+dp[i][1])%M;
  }
  return dp[n][1];
}
void init(int x) {
  m[x].size = x;
  for (int i = 0; i < (1<<x); i++)
    for (int j = 0; j < (1<<x); j++)
      m[x].ele[i][j] = solve(i, j, x);
}
Matr muti(Matr &x, Matr &y) {
  int n;
  Matr t;
  t.size = n = x.size;
  for (int i = 0; i < (1<<n); i++)
    for (int j = 0; j < (1<<n); j++) {
      t.ele[i][j] = 0;
      for (int k = 0; k < (1<<n); k++)
        t.ele[i][j] = (1LL*x.ele[i][k]*y.ele[k][j]+t.ele[i][j])%M;
    }
  return t;
}
Matr pow(Matr x, int k) {
  if (k == 1) return x;
  Matr t = pow(x, k>>1);
  t = muti(t, t);
  if (k&1) t = muti(t, x);
  return t;
}
int main()
{
  for (int i = 1; i <= maxL; i++) init(i);
  for (int i = 1; i <= maxL; i++) scanf("%d", &w[i]);
  sum[0][0] = 1;
  for (int i = 1; i <= maxL; i++)
    if (w[i] > 0) {
      m[i] = pow(m[i], w[i]);
      for (int u = 0; u < (1<<i); u++)
        for (int v = 0; v < (1<<i); v++)
          sum[i][v] = (1LL*m[i].ele[v][u]*sum[i-1][u]+sum[i][v])%M;
      ans = sum[i][0];
    } else {
      for (int u = 0; u < (1<<i); u++) sum[i][u] = sum[i-1][u];
    }
  printf("%d\n", ans);
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n,m,a=1;
    cin>>n>>m;
    while (m>=a)
    {
        m-=a;
        a++;
        if (a==n+1)
        {
            a=1;
        }
    }
    cout<<m;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<stdlib.h>
using namespace std;

int main(){
    int x1, y1, x2, y2, a, b;
    while(cin >> x1 >> y1 >> x2 >> y2){
        cin >> a >> b;

        int x = abs(x2 - x1);
        int y = abs(y2 - y1);

        if(!a){
            if(!x && y % b == 0) cout << "YES" << endl;
            else cout << "NO" << endl;
        }
        else if(!b) if(!y && x % a == 0) cout << "YES" << endl;
            else cout << "NO" << endl;
        else{
            int a1 = x % a;
            int b1 = y % b;
            int a2 = x / a;
            int b2 = y / b;
//            cout << x << " " << y << " " << a1 << " " << b1 << " " << a2 << " " << b2 << " " << endl;
            if(a1 == 0 && b1 == 0){
                if(a2 % 2 == b2 % 2) cout << "YES" << endl;
                else cout << "NO" << endl;
            }
            else cout << "NO" << endl;
        }

    }
}


#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<assert.h>
#include<set>
#include<cmath>
#include<queue>
#include<cstdlib>
#include<iostream>
#include<bitset>
#include<stack>
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define rep(i,j,k) for(int i=(int)(j);i<=(int)(k);i++)
#define per(i,j,k) for(int i=(int)(j);i>=(int)(k);i--)
using namespace std;
typedef long long LL;
typedef double db;
int main()
{
    string s;
    cin>>s;
    int x,d,i;
    x=d=0;
    for(i=0;i<s.size();i++){
        if(s[i]>='a'&&s[i]<='z')
            x++;
        else
            d++;
    }
    if(x>=d){
        for(i=0;i<s.size();i++){
            if(s[i]>='a'&&s[i]<='z')
                cout<<s[i];
            else
                printf("%c",s[i]+32);
        }
    }
    else
    {
        for(i=0;i<s.size();i++){
            if(s[i]>='A' && s[i]<='Z')
                cout<<s[i];
            else
                printf("%c",s[i]-32);
        }
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;
    int a[8];
    for(int i=1;i<=7;i++)
    cin>>a[i];
    int k = n;
    while(n>0)
    for(int i =1 ;i<=7;i++)
    {
        if(a[i] >= n )
        {
            cout<<i;
             n = n- a[i];
            break;
        }

            n = n- a[i];
            }
}


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

int main()
{
    long int x,t,a,b,da,db;
    scanf("%ld %ld %ld %ld %ld %ld", &x, &t, &a, &b, &da, &db);
    if(x == 0)
    {printf("%s \n", "YES");
            goto exit;}
            else{

    for(int tz = 0; tz < t; ++tz)
    {
        for(int tu = 0; tu < t; ++tu)
        {
            if(a - da*tz == x)
            {printf("%s \n", "YES");
            goto exit;}
        }
    }

    for(int tz = 0; tz < t; ++tz)
    {
        for(int tu = 0; tu < t; ++tu)
        {
            if(b - db*tu == x)
            {printf("%s \n", "YES");
            goto exit;}
        }
    }

    for(int tz = 0; tz < t; ++tz)
    {
        for(int tu = 0; tu < t; ++tu)
        {
            if(a - da*tz + b - db*tu == x)
            {printf("%s \n", "YES");
            goto exit;}
        }
    }
    printf("%s \n", "NO");
            }
    exit:
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

unsigned long long solve(vector<unsigned long long>& arr, unsigned long long K) {
	int N = (int)arr.size();
	unsigned long long ret = 0, mul = 1;
	for (int i = N - 1; i >= 0; i--) {
		ret += mul*arr[i];
		mul *= K;
	}
	return ret;
}

int main() {
	unsigned long long N, K;
	cin >> N >> K;
	vector<unsigned long long> arr1;
	for (unsigned long long i = 0; i < N; i++) {
		unsigned long long buf; cin >> buf; arr1.push_back(buf);
	}
	unsigned long long N2, K2;
	cin >> N2 >> K2;
	vector<unsigned long long> arr2;
	for (unsigned long long i = 0; i < N2; i++) {
		unsigned long long buf; cin >> buf; arr2.push_back(buf);
	}

	unsigned long long val1 = solve(arr1, K);
	unsigned long long val2 = solve(arr2, K2);
	if (val1 == val2) { puts("="); }
	else if (val1 > val2) { puts(">"); }
	else { puts("<"); }
	return 0;
}


#include <iostream>
#include <queue>
#include <string>
#include <map>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <vector>
#include <stack>
#include <algorithm>
#include <string.h>
#include <set>
#include <cstdlib>
#include <iostream>
#include <bits/stdc++.h>
#define pii pair<int,int>
#define ll long long int
#define sl(n) scanf("%lld",&n)
#define s(n) scanf("%d",&n)
#define f(n) for(int i=0;i<n;++i)
#define fo(n) for(int i=1;i<=n;++i)
#define fnm(n,m) for(ll i=n;i<m+1;++i)
#define pb push_back
#define pf printf
#define F first
#define S second
#define srt(v) sort(v.begin(),v.end());
#define srta(v,n) sort(v,v+n);
const ll LL_INF=0x3f3f3f3f3f3f;

using namespace std;

int main(){
    // pf("\t\t\t***************************************************************************\n\n");
    // pf("\t\t\t***************************************************************************\n\n");
    string s,ans="",temp;
    map<char,int>mp;
    char imp;
    int impi;
    cin>>s;
    if(s[1]=='>'){
        ans=s[2];
        mp[s[2]]=1;
        ans+=s[0];
        mp[s[0]]=2;
    }
    else{
        ans=s[0];
        mp[s[0]]=1;
        ans+=s[2];
        mp[s[2]]=2;
    }

    // cout<<ans<<endl;
    cin>>s;
    if(s[1]=='>'){

        if(ans[1]==s[2]&&ans[0]==s[0]){
            pf("Impossible\n");
            return 0;
        }
        int i=0;
        temp="";
        if(mp[s[0]]){
            if(mp[s[2]]>mp[s[0]]){
                pf("IMPOSSIBLE\n");
                return 0;
            }
            imp=s[0];
            while(true){
                temp+=s[2];
                temp+=ans[i];
                // cout<<temp<<endl;
                if(ans[i++]==s[0])break;
            }
            for(int j=i;j<ans.size();++j)temp+=ans[j];
            ans=temp;
            if(ans.size()==3){
                f(3)mp[ans[i]]=i+1;
            }
            else{
                mp[ans[ans.size()-1]]=3;
            }
        }
        else if(s[2]==ans[1]) ans+=s[0];
        else{
            imp=ans[0];
            temp=ans[0];
            temp+=s[0];
            temp+=ans[1];
            temp+=s[0];
            ans=temp;
        }
    }
    else{
        if(ans[1]==s[0]&&ans[0]==s[2]){
            pf("Impossible\n");
            return 0;
        }
        int i=0;
        temp="";
        if(mp[s[2]]){
            if(mp[s[2]]<mp[s[0]]){
                pf("Impossible\n");
                return 0;
            }
            imp=s[2];
            while(true){
                temp+=s[0];
                temp+=ans[i];
                if(ans[i++]==s[2])break;
            }
            for(int j=i;j<ans.size();++j)temp+=ans[j];
            ans=temp;

        }
        // else ans+=s[2];
        else if(s[0]==ans[1]) ans+=s[2];
        else{
            imp=ans[0];
            temp=ans[0];
            temp+=s[2];
            temp+=ans[1];
            temp+=s[2];
            ans=temp;
        }
    }
    if(ans.size()==3){
        f(3)mp[ans[i]]=i+1;
    }

    // cout<<ans<<endl;
    // if(ans.size()==4)pf("%c\n",imp);
    // for(auto &it:mp){
    //     pf("%c: %d\n",it.F,it.S);
    // }
    cin>>s;
    if(ans.size()==3){
        if(s[1]=='>'){
            if(mp[s[0]]<mp[s[2]]){
                pf("Impossible\n");
                return 0;
            }
            else{
                cout<<ans<<endl;
            }
        }else{
            if(mp[s[0]]>mp[s[2]]){
                pf("Impossible\n");
                return 0;
            }
            else{
                cout<<ans<<endl;
            }
        }
    }else{
        if(s.find(imp)!=-1){
            pf("Impossible\n");
            return 0;
        }
        else{
            if(s[1]=='>'){
                if(count(ans.begin(),ans.end(),ans[3])==1)
                    cout<<s[2]<<s[0]<<ans[3]<<endl;
                else{
                    cout<<ans[0]<<s[2]<<s[0]<<endl;
                }
            }else{
                if(count(ans.begin(),ans.end(),ans[3])==1)
                    cout<<s[0]<<s[2]<<ans[3]<<endl;
                else{
                    cout<<ans[0]<<s[0]<<s[2]<<endl;
                }
                // cout<<s[0]<<s[2]<<ans[3]<<endl;
            }
        }
    }

    return 0;
}


#include <stdio.h>
#include <math.h>

int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	double tmp1 = b * log(a);
	double tmp2 = a * log(b);
	if (fabs(tmp1 - tmp2) <= 0.000001f) printf("=");
	else if (tmp1 < tmp2) printf("<");
	else printf(">");
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    long long a,b,c,d,e,f,cost1,cost2;
    cin >> a >> b >> c >> d >> e >> f;
    cost1=min(a,d)*e+min(b,min(c,d-min(a,d)))*f;
    cost2=min(b,min(c,d))*f + min(a,d-min(b,min(c,d)))*e;
    cout <<max(cost1,cost2);
}


#include <bits/stdc++.h>

int main() {
	int a, b, y{0};
	std::cin>>a>>b;
	while(a<=b){
		a *= 3;
	    b *= 2;
	    y++;
	}
	std::cout<<y<<'\n';
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    cin>>x; //输入
    int a;
	a=sqrt(x);//平方根计算，暴力
	int i=a;
	while(i!=0)//while循环
	{
		for(int j=a;j<=x;j++)
		{
            if(x==i*j)//层层判断，if是否符合题意
            {
                cout<<i<<" "<<j;//输出
                return 0;
            }
		}
		i--;//i每次减掉1
	}
}


#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define INF 1000000007
#define eps 1e-9
#define ll long long

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

	int a,x,y;
	cin >> a >> x >> y;
	if(x >= a)
	{
		cout << -1 << endl;
		return 0;
	}
	if(x <= (-a))
	{
		cout << -1 << endl;
		return 0;
	}
	if(y%a == 0)
	{
		cout << -1 << endl;
		return 0;
	}
	if(y < 2*a)
	{
		if(((double)x) >= ((double)a)/2)
		{
			cout << -1 << endl;
			return 0;
		}
		if(((double)x) <= (-(double)a)/2)
		{
			cout << -1 << endl;
			return 0;
		}
		if(y < a)
		{
			cout << 1 << endl;
			return 0;
		}
		else
		{
			cout << 2 << endl;
			return 0;
		}
	}
	int t = y/a;
	if(t%2 == 1)
	{
		if(2*x>=a)
		{
			cout << -1 << endl;
			return 0;
		}
		if(2*x+a<=0)
		{
			cout << -1 << endl;
			return 0;
		}
		cout << 5+3*((t-1)/2 - 1) << endl;
		return 0;
	}

	if(x == 0)
	{
		cout << -1 << endl;
		return 0;
	}

	if(x < 0)
	{
		cout << 5+3*((t-1-1)/2 - 1)+1 << endl;
	}
	else
	{
		cout << 5+3*((t-1-1)/2 - 1)+2 << endl;
	}

	return 0;
}


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define SIZEOF(a) (sizeof(a)/sizeof((a)[0]))

typedef long long ll;

const int MAX_N = 1e6+10;
ll a[MAX_N];
ll b[MAX_N];
ll c[MAX_N];

const int BUFSIZE = 1000000;
char buf[BUFSIZE + 1];
string nextString() {
	scanf("%s", buf); return buf;
}

int main()
{
	string s; cin >> s;
	size_t n = s.size();

	if(s=="0"){
		cout << "zero" << endl;
		return 0;
	}

	if(n == 2 && s[0]=='1'){
		int i = 1;
		if(s[i]=='0') cout << "ten";		// 10
		if(s[i]=='1') cout << "eleven";		// 11
		if(s[i]=='2') cout << "twelve";		// 12
		if(s[i]=='3') cout << "thirteen";
		if(s[i]=='4') cout << "fourteen";
		if(s[i]=='5') cout << "fifteen";
		if(s[i]=='6') cout << "sixteen";
		if(s[i]=='7') cout << "seventeen";
		if(s[i]=='8') cout << "eighteen";
		if(s[i]=='9') cout << "nineteen";
		cout << endl;
		return 0;
	}

	if(n == 2){
		int i = 0;
		if(s[i]=='2') cout << "twenty";
		if(s[i]=='3') cout << "thirty";
		if(s[i]=='4') cout << "forty";
		if(s[i]=='5') cout << "fifty";
		if(s[i]=='6') cout << "sixty";
		if(s[i]=='7') cout << "seventy";
		if(s[i]=='8') cout << "eighty";
		if(s[i]=='9') cout << "ninety";

		if(s[1]=='0'){
			cout << endl;
			return 0;
		}else{
			cout << '-';
		}
	}

	if(n >= 1){
		int i = n-1;
		if(s[i]=='1') cout << "one";
		if(s[i]=='2') cout << "two";
		if(s[i]=='3') cout << "three";
		if(s[i]=='4') cout << "four";
		if(s[i]=='5') cout << "five";
		if(s[i]=='6') cout << "six";
		if(s[i]=='7') cout << "seven";
		if(s[i]=='8') cout << "eight";
		if(s[i]=='9') cout << "nine";
	}
	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,arr[105]={},s=0,mx=-1,p=0,ans[105]={};
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        s+=arr[i];
        if(arr[i]>mx){mx=arr[i];}
    }
    //if(n==1){cout<<arr[0]+101;return 0;}
        for(int i=mx;i<10100;i++)
        {
            for(int j=0;j<n;j++)
            {
                ans[j]=i-arr[j];
                p+=ans[j];
            }
            if(p>s){cout<<i;return 0;}
            p=0;
        }
    return 0;
}


//Feet don't fail me now
//Take me to the finish line
//Oh, my heart, it breaks every step that I take
//But I'm hoping at the gates, they'll tell me
//that gold is mine
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define no_answer return cout << 0, 0;
#define FOR(i, start, finish, k) for(llong i = start; i <= finish; i += k)

const long long MXN = 1e7 + 200;
const long long MNN = 1e4 + 520;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long long OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int n;
llong x, y, dp[MXN];

void bfs(int first){
    queue<int> q;
    q.push(first);
    while(!q.empty()){
        int k = q.front();
        q.pop();
        if(k + 1 <= n && dp[k + 1] > dp[k] + x){
            dp[k + 1] = dp[k] + x;
            q.push(k + 1);
        }
        if(k + k <= n && dp[k + k] > dp[k] + y){
            dp[k + k] = dp[k] + y;
            q.push(k + k);
        }
        if(k + k - 1 >= 1 && k + k - 1 <= n && dp[k + k - 1] > dp[k] + y + x){
            dp[k + k - 1] = dp[k] + y + x;
            q.push(k + k - 1);
        }
    }
}

int main(){
    cin >> n >> x >> y;
    for(int i = 1; i <= n; i++) dp[i] = INF;
    for(int i = 0; i <= n; i++){
        if(i + 1 <= n) dp[i + 1] = min(dp[i + 1], dp[i] + x);
        if(i + i <= n) dp[i + i] = min(dp[i] + y, dp[i + i]);
        if(i + i - 1 <= n) dp[i + i - 1] = min(dp[i + i - 1], dp[i] + x + y);
    }
    bfs(0);
    cout << dp[n];
}


#include <stdio.h>
typedef long long LL;
struct pt{
    int x,y;
    pt(){}
    pt(int x,int y):x(x),y(y){}
    void get(){
        scanf("%d%d",&x,&y);
    }
};
bool judge(int x1,int y1,int x2,int y2){
    LL t1=1ll*(x1)*x2+1ll*(y1)*y2;
    LL t2=1ll*x2*x2+1ll*y2*y2;
    if(t2==0){
        return x1==0&&y1==0;
    }
    if(t1%t2==0){
        t1/=t2;
        if(x2==0)return x1%y2==0;
        return (y1-t1*y2)%x2==0;
    }
    return 0;
}
int main(){
    pt a,b,c;
    a.get();
    b.get();
    c.get();
    for(int i=0;i<4;i++){
        a=pt(-a.y,a.x);
        if(judge(b.x-a.x,b.y-a.y,c.x,c.y)){
            printf("YES");
            return 0;
        }
    }
    printf("NO");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,k[1001],max=0;
	cin>>n>>m;

	for(int i=0;i<n;i++)
	{
		cin>>k[i];
	}

	for(int i=1;i<n;i++)
	{
		if(k[i-1]-k[i]>max && k[i-1]>k[i])
			max=k[i-1]-k[i];
	}

	if(max==0 ||(max-m)<0)
		cout<<0<<endl;
	else
		cout<<max-m<<endl;

	return 0;
}


#include<iostream>
#include<set>
#include<map>
#include<functional>
#include<queue>
#include<string.h>
#include<stdio.h>
#include<iomanip>
#include<stdlib.h>
#include<math.h>
#include<cstdlib>
#include<vector>
#include<random>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<bitset>
#include<fstream>
typedef long long ll;
typedef unsigned long long ull;
#define PI acos(-1.0)
#define rep(i,a,b) for (int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define sz(a) (int)a.size()
#define sqr(x) ((x) * (x))
#define pi pair<ll, ll>
#define mk(a, b) make_pair(a, b)
#define nextI nextInt()
#define nextD nextDouble()
#define nextL nextLong()
#define nextC nextChar()
#define line newLine()
int nextInt(){ int x; scanf("%d", &x); return x; }
double nextDouble(){ double x; scanf("%lf", &x); return x; }
ll nextLong(){ ll x; scanf("%I64d", &x); return x; }
char nextChar(){ char x; scanf("%c", &x); return x; }
void newLine(){ printf("\n"); }
ll gcd(ll a, ll b){ return b == 0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b){ return (a*b) / gcd(a, b); }
ll powM(ll a, ll b, ll MOD){ ll x = 1, y = a; while (b > 0){ if (b % 2 == 1){ x = (x*y); if (x>MOD) x %= MOD; }y = (y*y); if (y>MOD) y %= MOD; b /= 2; }return x; }
int countBitSet(ll n){ int ans = 0;  while (n != 0){ n -= (n & -n); ++ans; } return ans; }
ll mod = ll(1e9 + 7);
ll mod2 = ll(1e9 + 9);
const int N = 100100;
const int M = 100;
const double eps = (double)1e-6;
using namespace std;
string str[55];
ll cnt[1 << 20];
double dp[1 << 20];
int main(){
#ifdef HOME
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//clock_t t1 = clock();
#endif

	int m = nextI;
	for (int i = 0; i < m; i++) cin >> str[i];
	int n = str[0].length();
	for (int i = 0; i < m; i++){
		for (int j = i + 1; j < m; j++){
			int mask = 0;
			for (int k = 0; k < n; k++){
				if (str[i][k] == str[j][k]) mask |= (1 << k);
			}
			cnt[mask] |= (1ll << i) | (1ll << j);
		}
	}
	for (int s = (1 << n) - 1; s > 0; s--){
		for (int i = 0; i < n; i++){
			if (s & (1 << i))
				cnt[s - (1 << i)] |= cnt[s];
		}
	}

	dp[0] = 1;
	for (int i = 1; i <= n; i++){
		dp[i] = dp[i - 1] * (1.0 / (n - i + 1)) * i;
	}
	for (int k = 0; k < (1 << n); k++) cnt[k] = m - countBitSet(cnt[k]);
	double ans = 0;
	for (int s = 1; s < (1 << n); s++){
		int num = countBitSet(s);
		for (int i = 0; i < n; i++){
			if (s & (1 << i)){
				//int f1 = m - countBitSet(cnt[s]);
				//int f2 = m - countBitSet(cnt[s - (s & (1 << i))]);
				ans += dp[num] * (cnt[s] - cnt[s - (s & (1 << i))]);
			}
		}
	}
	cout << fixed << setprecision(20) << ans/(1.0 * m) << endl;
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-10
using namespace std;

#define REP(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, j, k) for(int i = (j); i <= (k); ++i)
#define pii pair<int, int>
#define fr first
#define sc second

int ans[] {
1,
0,
18,
0,
1800,
0,
670320,
0,
734832000,
0,
890786230,
0,
695720788,
0,
150347555,
0
};

int main() {
	int n;
	cin >> n;
	cout << ans[n - 1];
	return 0;
}


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

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

const double PI = acos(-1);
#define MOD 1000000007  ///1e9+7

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '

#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 fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///******************************** C o d e ********************************///
ll x,y,c;

void _case()
{
    c=8;
    set<ll> mx,my;
    set<pll> m;
    while(c--){
        cin>>x>>y;
        mx.insert(x);
        my.insert(y);
        m.insert({x,y});
    }
    c=sz(m);
    if(sz(mx)!=3 or sz(my)!=3 or c!=8) cout<<"ugly" el;
    else{
        set<ll>::iterator i,j;
        i=mx.begin(); i++;
        j=my.begin(); j++;
        ///cout<<i->F sp<<j->F el;
        ///cout<<sz(m) el;
        if(m.count({*i, *j})) cout<<"ugly" el;
        else cout<<"respectable" el;
    }
}

main()
{
///    test
    fastio();
    _case();
}

///Thank you.

///Brainless_Loco Terminates Here!


#include <iostream>

constexpr int N = 1000005;
constexpr int p = 998244353;
constexpr int inv2 = 499122177;
constexpr int inv6 = 166374059;

int add(int x, int y) { return (x += y) >= p ? x - p : x; }
int sub(int x, int y) { return (x -= y) < 0 ? x + p : x; }
int mul(int x, int y) { return (long long)x * y % p; }

int n;
int f[N];

int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
    std::cin >> n;
    f[0] = 1;
    int sum = 0;
    for (int i = 1; i <= n; ++i) {
        f[i] = mul(f[i - 1], add(add(sum, 1), mul(f[i - 1] + 1, inv2)));
        sum = add(sum, f[i - 1]);
    }
    sum = sub(sum, f[n - 1]);
    int ans = add(add(f[n], mul(f[n - 1], mul(mul(sum, add(sum, 1)), inv2))), add(mul(mul(mul(f[n - 1], add(f[n - 1], 1)), inv2), sum), mul(mul(mul(f[n - 1], add(f[n - 1], 1)), add(f[n - 1], 2)), inv6)));
    ans = sub(mul(ans, 2), 1);
    for (int i = 0; i < n - 1; ++i) ans = add(ans, mul(sub(f[i], 1), sub(f[n - i - 1], f[n - i - 2])));
    std::cout << ans << '\n';
    return 0;
}


#include <cstdio>
#include <iostream>

using namespace std;

int main ()
{
    int n;
    int m;
    int a;

    scanf ("%d %d %d", &n, &m, &a);

    long long flagsByRow;

    if (n % a == 0) {
        flagsByRow = n / a;

    } else {
        flagsByRow = n / a;
        flagsByRow++;

    }

    long long flagsByColumn;

    if (m % a == 0) {
        flagsByColumn = m / a;

    } else {
        flagsByColumn = m / a;
        flagsByColumn++;

    }

    cout << flagsByRow * flagsByColumn << endl;

    return 0;
}


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


#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <unordered_map>

using namespace std;

void solve() {
	long long n;
	cin>>n;

	long long d = 1;
	if (n%2!=0){
		d= -1;
	}

	cout.precision(0);
	cout << fixed << ceil(n/2.0)*d;
}

/*
int main() {
	int t;
	cin >> t;

	while (t--) {
		solve();
	}

	return 0;
}
*/

int main() {
	solve();

	return 0;
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int>a(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
	int result=0;
	int start_i,end_i;
	start_i=0;
	end_i=n-1;
	while(1&&(end_i>=start_i))
	{
		if(a[start_i]<=k)
		{
			result++;
			start_i++;
		}
	    else if(a[end_i]<=k)
		{
			result++;
			end_i--;
		}
		else
		break;
	}
	cout<<result;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

struct node
{
    int sum;
    int id;
} b[5], t;

int a[30];

int main()
{
    int n;
    while (~scanf("%d", &n))
    {
        memset(b, 0, sizeof(b));
        for (int i = 1; i <= n; i++)
            scanf("%d", &a[i]);
        int sum1 = 0, sum2 = 0, sum3 = 0;
        for (int i = 1; i <= n; i++)
        {
            if (i % 3 == 1)
                sum1 += a[i];
            if (i % 3 == 2)
                sum2 += a[i];
            if (i % 3 == 0)
                sum3 += a[i];
        }
        b[0].sum = sum1, b[0].id = 1;
        b[1].sum = sum2, b[1].id = 2;
        b[2].sum = sum3, b[2].id = 3;
        for (int i = 0; i < 3 - 1; i++)
            for (int j = 0; j < 3 - i - 1; j++)
            {
                if (b[j].sum < b[j + 1].sum)
                {
                    t = b[j];
                    b[j] = b[j + 1];
                    b[j + 1] = t;
                }
                else if (b[j].sum == b[j + 1].sum && b[j + 1].id < b[j].id)
                {
                    t = b[j];
                    b[j] = b[j + 1];
                    b[j + 1] = t;
                }
            }
        if (b[0].id == 1)
            printf("chest\n");
        else if (b[0].id == 2)
            printf("biceps\n");
        else if (b[0].id == 3)
            printf("back\n");
    }
    return 0;
}


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

int main(){
	int n;
	cin>>n;
	int r[n+5],b[n+5];
	int x=0,y=0;
	for(int i=0;i<n;i++){
		cin>>r[i];
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
		if(b[i]==1&&r[i]==0) y++;
		if(r[i]==1&&b[i]==0) x++;
	}
	//cout<<x<<' '<<y<<endl;
	if(x==0){
		cout<<-1<<endl;
		return 0;
	}
	cout<<y/x+1;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int inf=2000+5;
int memo[inf][inf],m;
int pow_mod(int x,int y)
{
    if(y==0)
        return 1%m;

    if(y==1)
        return x%m;

    if(~memo[x][y])
        return memo[x][y];

    int ret=pow_mod(x,y/2) %m ;

    ret=( (ret%m) * (ret%m) )%m;

    return memo[x][y]=( pow_mod(x,y%2) *ret )%m;
}
int main()
{
    int x,y,temp,cnt=0;
    bool fg;
    cin>>m;
    memset(memo,-1,sizeof memo);
    for(x=1;x<m;x++)
    {
        fg=0;
        for(y=1;y<m;y++)
        {
            temp=(pow_mod(x,y)-1+m)%m;

            if(y==m-1){
                if(temp)
                    fg=1;
            }
            else if(!temp)
                fg=1;
        }
        if(!fg)
            cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>

#define MAX 100005
#define MOD 1000000007
#define eps 1e-7

using namespace std;

typedef long long ll;
typedef complex <double> point;

#define pii pair<int, int>
#define pip pair<int ,pii>
#define F first
#define S second
#define bits(x) __builtin_popcount(x)
#define X real()
#define Y imag()

int ar[] = {0 ,0 ,1 ,-1};
int ac[] = {1 ,-1 ,0 ,0};
ll fast_pow(int n , int m){
    ll res = 1;
    ll p = n;
    while(m){
        if(m % 2)
            res *= p;
        p *= p;
        m /= 2;
    }
    return res;
}
int n;
ll c(int m ,int r){
    ll res = 1;
    for(int i = 0 ;i < r ;i++)
        res = (res * (m - i))/(i + 1);
    return res;
}
ll p(int m ,int r){
    ll res = 1;
    for(int i = 0 ;i < r ;i++)
        res = (res * (m - i));
    return res;
}
int main(){
#ifdef Code_Breakers
      freopen("input.txt", "r", stdin);
 //     freopen("input.txt" ,"w" ,stdout);
#endif //Code Breakers
    ios_base::sync_with_stdio(false);cin.tie(0);
    cout << fixed << setprecision(6);
    cin >> n;
    cout << c(n ,5) * p(n ,5);
    return 0;
}


#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstring>
using namespace std;
int main()
{
	char s[1000];
	int a[1000]={0};
	cin>>s;
	for(int i=0;i<strlen(s);i++)
	{
		a[s[i]]=1;
	}
	int tot=0;
	for(int i=0;i<1000;i++)
	{
		if(a[i])tot++;
	}
	if(tot%2)
	{
		cout<<"IGNORE HIM!"<<endl;
	}else
	{
		cout<<"CHAT WITH HER!"<<endl;
	}
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <cstring>
#include <iomanip>
#include <set>
#include<ctime>
//CLOCKS_PER_SEC
#define se second
#define fi first
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define Pii pair<int,int>
#define Pli pair<ll,int>
#define ull unsigned long long
#define pb push_back
#define fio ios::sync_with_stdio(false);cin.tie(0)
const double Pi=3.14159265;
const int N=3e5+50;
const ull base=163;
const int INF=0x3f3f3f3f;
using namespace std;
int a[N];
int b[N];
int mp[N];
int main(){
    fio;
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        mp[a[i]]=1;
    }
    int MIN=INF;
    for(int i=1;i<=m;i++){
        cin>>b[i];
        if(mp[b[i]])MIN=min(MIN,b[i]);
    }
    sort(a+1,a+1+n);
    sort(b+1,b+1+m);
    int x=a[1]*10+b[1];
    int y=b[1]*10+a[1];
    cout<<min(x,min(y,MIN));
    return 0;
}


#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <string.h>
#include <algorithm>
#include <list>
#include <queue>
#include <map>
#include <ctime>

#define F first
#define S second
#define pb push_back
#define INF 1<<30
#define mp make_pair
#define pi pair<int, int>
#define readString(s) gets(rs);s = rs
#define y1 yyy1
#define y2 yyy2
#define SQR(a) ((a)*(a))

#define swag swap

using namespace std;

const int N = 111;

char buff[N];

int r1, c1, r2, c2;

int main()
{
    #define TASKNAME "disease"

    #ifdef DEBUG
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w",stdout);
    #else
        //freopen(TASKNAME".in", "r", stdin);
        //freopen(TASKNAME".out", "w", stdout);
    #endif

    scanf("%d%d%d%d", &r1, &c1, &r2, &c2);

    int a1 = 0, a2 =0, a3 = 0;

    if (r1 == r2 || c1 == c2)
        a1 = 1;
    else
        a1 = 2;

    if (abs(r1 - r2) == abs(c1 - c2))
        a2 = 1;
    else
        if ((r1 + c1)%2 != (r2+c2)%2)
            a2 = 0;
        else
            a2 = 2;

    a3 = max(abs(r1 - r2), abs(c1-c2));

    printf("%d %d %d", a1, a2, a3);

    return 0;
}


#include<bits/stdc++.h>
#define FAST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define endl '\n'
int main()
{
	int x;
	int y;
	int c = 1;
	cin >> x >>y;
	for (int i = 1; true; i++)
	{
		if (i % 2 != 0)
		{
			if (x > 1 && y > 1)
			{
				x -= 2;
				y -= 2;

			}
			else if (x == 1 && y > 11)
			{
				x--;
				y -= 12;

			}
			else if (x == 0 && y > 21)
			{
				y -= 22;

			}
			else
			{
				c = 1;
				break;
			}

		}
		else
		{

				if (y > 21)
				{
					y -= 22;

				}
				else if (x >= 1 && y > 11)
				{
					x--;
					y -= 12;

				}
				else if (x > 1 && y > 1)
				{
					x -= 2;
					y -= 2;

				}
				else
				{
					c = 2;
					break;
				}

		}

	}
	if (c == 1)
	{
		cout << "Hanako";

	}
	else
	{
		cout << "Ciel";

	}

#ifndef ONLINE_JUDGE
	system("pause");
#endif // !ONLINE_JUDGE

}


#include <bits/stdc++.h>
using namespace std;
vector<long long > v ;
void calc(long long x)
{

    if(x > 1e9)return ;
    v.push_back(x);
    calc(x*10+4);
    calc(x*10+7);
}

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

    long long n ;
    cin >> n ;
    calc(0);
    sort(v.begin() , v.end());
    for(int i = 0 ; i < v.size() ; i ++)
    {
        if(v[i] == n)
        {
            cout << i ;
            return 0;
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1<<16;
ll read()
{
	ll res=0,f=1;
	char c=getchar();
	while(!isdigit(c) && c!='-') c=getchar();
	if(c=='-') f=-1,c=getchar();
	while(isdigit(c)) res=(res<<1)+(res<<3)+c-48,c=getchar();
	return res*f;
}
int main()
{
//    freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	string s1,s2;
	cin>>s1>>s2;
	int n=s1.size();
	cout<<s1[0];
	for(int i=1;i<n;i++)
	{
		if(s1[i]<s2[0]) cout<<s1[i];
		else break;
	}
	cout<<s2[0]<<endl;
	return 0;
}


#include <iostream>
//#include<bits/stdc++.h>
#define M_PI 3.14159265358979323846
using namespace std;

int main() {
	int a,b,r;
	cin>>a>>b>>r;
	// float area = M_PI*r*r;
	// float area2 = a*b;
	// float q = area2/area;
	// int u = int(q);
	if(2*r > a || 2*r >b)
	{
		cout<<"Second";
	}
	else
	{
		cout<<"First";
	}

	// your code goes here
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2345678;

double real_p[123], p[123];
double f[N];
double ans[123];
int id[123];
int kb[N];

int main() {
  int real_n, k;
  scanf("%d %d", &real_n, &k);
  int n = 0;
  for (int i = 0; i < real_n; i++) {
    scanf("%lf", real_p + i);
    if (real_p[i] > 1e-4) {
      id[n] = i;
      p[n++] = real_p[i];
    }
  }
  k = min(k, n);
  kb[0] = 0;
  for (int t = 1; t < (1 << n); t++) {
    kb[t] = kb[t & (t - 1)] + 1;
  }
  for (int t = 0; t < (1 << n); t++) {
    f[t] = 0.0;
  }
  for (int i = 0; i < real_n; i++) {
    ans[i] = 0.0;
  }
  f[0] = 1.0;
  for (int t = 0; t < (1 << n); t++) {
    if (kb[t] == k) {
      for (int j = 0; j < n; j++) {
        if (t & (1 << j)) {
          ans[id[j]] += f[t];
        }
      }
      continue;
    }
    double total = 0;
    for (int j = 0; j < n; j++) {
      if (t & (1 << j)) {
        continue;
      }
      total += p[j];
    }
    double q = f[t] * 1.0 / total;
    for (int j = 0; j < n; j++) {
      if (t & (1 << j)) {
        continue;
      }
      f[t | (1 << j)] += p[j] * q;
    }
  }
  for (int i = 0; i < real_n; i++) {
    if (i > 0) {
      putchar(' ');
    }
    printf("%.17f", ans[i]);
  }
  printf("\n");
  return 0;
}


#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <utility>
#include <vector>
#include <fstream>
#include <iterator>
#include <functional>
#include <queue>

#define per(i,a,b) for (int i = a; i<b; i++)
#define LONG long long
#define pii pair<int,int>
#define mp make_pair
#define pq priority_queue
#define INF 1000000000000000
#define BIG(x) (x>='A' &&  x<='Z')
#define SMALL(x) (x>='a' && x<='z')
#define toBIG(x) (SMALL(x)?(x-'a'+'A'):x)
#define toSMALL(x) (BIG(x)?(x-'A'+'a'):x)
#define END(s) {cout << s; return 0;}
#define tmin(a,b,c) min(a,min(b,c))
#define tmax(a,b,c) max(a,max(b,c))

using namespace std;

int m[10];

int main()
{
#ifdef DEBUG
	std::freopen("input.txt", "rt", stdin); std::freopen("output.txt", "wt", stdout);
#endif
	string a, b;
	cin >> a >> b;
	per(i, 0, a.length()) {
		m[a[i] - '0']++;
	}
	int dec = -1; // Если слева надо уменьшить
m1:
	LONG st = 1; // length b
	per(i, 1, a.length()) {
		st *= 10;
	}
	LONG r = 0;
	int k = b.length()-a.length();
	bool ok = false; // Могут ли дальше быть любые символы
	if (b.length() > a.length())
		ok = true;
	while (st != 0) {
		int x = 0;
		bool f = false;
		for (int i = 9; i >= 0; i--) {
			if (k==dec) {
				if (m[i] > 0 && (i < b[k] - '0' || ok)) {
					x = i;
					m[i]--;
					if (i < b[k] - '0')
						ok = true;
					f = true;
					break;
				}
			}
			else if (m[i] > 0 && (i<=b[k]-'0'||ok)) {
				x = i;
				m[i]--;
				if (i < b[k] - '0')
					ok = true;
				f = true;
				break;
			}
		}
		if (f == false) {
			dec = k-1;
			per(i, 0, 10) {
				m[i]=0;
			}
			per(i, 0, a.length()) {
				m[a[i] - '0']++;
			}
			goto m1;
		}
		r += st*x;
		k++;
		st /= 10;
	}
	cout << r;
	return 0;
}


#include <iostream>
#include <set>
using namespace std;
multiset <long long> s;
void f(long long n,long long num,int i,int j)
{ if (n>=num)
{s.insert(n);
if (i>j+2)
return ;

}
    f(n*10+4,num,i+1,j);
    f(n*10+7,num,i+1,j);
    }

int main()
{long long num;
int o=0;

cin >>num;
long long k=num;
while (k!=0)
{o++;
k=k/10;

}
f(0,num,0,o);
s.insert(num) ;
set <long long>::iterator i;

/*i=s.find(num);
i++;
cout<<*i<<endl;*/
int y,l=0,m=0 ;
set <int> c;
long long x,z;
for (i=s.find(num);i!=s.end();i++)
{x=*i ;
z=x;
while (x!=0)
{ y=x%10;
c.insert(y) ;
if (y==7)
l++;
else if (y==4) m++ ;

x=x/10 ;
}
    if (l==m&&l!=0&&c.size()==2)
    {cout<<z<<endl ;
break;
    }l=0;m=0; c.clear();
}
    return 0;
}


#include <iostream>
#define ll long long int
using namespace std;

int digsum(ll n)
{
	int s = 0;
	while(n > 0)
	{
		s += n%10;
		n /= 10;
	}
	return s ;
}

int main() {
	// your code goes here
	ll n,c;
	cin >> n;
	c = n;
	int k = 0;
	while(n > 0)
	{
		n /= 10;
		k++;
	}
	int ans = (k-1)*9;
	ll b = 0;
	for(int i=0;i<k-1;i++)
	{
		b += 9;
		b *= 10;
	}
	b/=10;
	ans += digsum(c - b) ;
	cout << ans ;
	return 0;
}


#include<stdio.h>
typedef long long ll;
const ll mod=1e9+7;
ll prime[1000];
ll quick_pow(ll n,ll x)
{
	ll ans=1;
	while(x)
	{
		if(x&1)
		ans=ans*n%mod;
		n=n*n%mod;
		x>>=1;
	}
	return ans%mod;
}
int main()
{
	ll x,n,k=0;
	scanf("%lld%lld",&x,&n);
	for(int i=2;i*i<=x;i++)
	{
		if(x%i==0)
		{
			prime[k++]=(ll)i;
			while(x%i==0)
			x/=i;
		}
	}
	if(x>1)
	prime[k++]=x;
	ll ans=1;
	for(int i=0;i<k;i++)
	{
		ll t=n,cnt=0;
		while(t>0)
		{
			cnt+=t/prime[i];
			t/=prime[i];
		}
		ans=ans*(quick_pow(prime[i],cnt))%mod;
	}
	printf("%lld\n",ans);
}


#include <bits\stdc++.h>
#include <ext\rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

void dfs(int x, int y, int n, int m,
         vector<vector<char> > &used,
         const string &hor, const string &ver)
{
    used[x][y] = 1;
    if (hor[x] == '>')
    {
        for (int i = y + 1; i < m; i++)
            if (!used[x][i])
                dfs(x, i, n, m, used, hor, ver);
    }
    else
    {
        for (int i = 0; i < y; i++)
            if (!used[x][i])
                dfs(x, i, n, m, used, hor, ver);
    }

    if (ver[y] == '^')
    {
        for (int i = x + 1; i < n; i++)
            if (!used[i][y])
                dfs(i, y, n, m, used, hor, ver);
    }
    else
    {
        for (int i = 0; i < x; i++)
            if (!used[i][y])
                dfs(i, y, n, m, used, hor, ver);
    }
}

void solve(int n)
{
    int m;
    string hor, ver;
    cin >> m >> hor >> ver;
    reverse(ver.begin(), ver.end());

    vector<vector<char> > used(n, vector<char>(m, 0));
    bool ok = true;

    for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
    {
        used.assign(n, vector<char>(m, 0));
        dfs(i, j, n, m, used, hor, ver);
        for (int x = 0; x < n; x++)
        for (int y = 0; y < m; y++)
            ok &= (used[x][y] == 1);
    }

    if (ok)
        printf("YES\n");
    else
        printf("NO\n");
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE

    int n, m, k = 0;

    while (cin >> n)
        solve(n);
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,m,x,y,vx,vy,ty;
int xGCD(int a, int b, int &x, int &y) {
    if(b == 0) {
       x = 1;
       y = 0;
       return a;
    }
    int x1, y1, gcd = xGCD(b, a % b, x1, y1);
    x = y1;
    y = x1 - (a / b) * y1;
    y%=a;
    if(y<0) y+=a;
    x = (gcd-b*y)/a;
    return gcd;
}
void move(int dist, int &y)
{
    y += dist;
    y%=2*m;
}
int solve(int dist)
{
    int x1,y1;
    int m = ::m;
    int n = ::n;
    int wutt = __gcd(n,m);
    if(dist%(wutt))
    {
        return -1;
    }
    m/=wutt;
    n/=wutt;
    dist/=wutt;
    wutt=xGCD(m,n,x1,y1);
    y1*=dist;
    y1%=m;
    if(y1<0) y1+=m;
    x1 = (dist-y1*n)/m;
    return y1;
}
int32_t main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int x1,y1;
    cin>>n>>m>>x>>y>>vx>>vy;
    if(vy==0)
    {
        if(y!=0 && y!=m)
            cout<<-1;
        else if(vx==1)
            cout<<n<<" "<<y;
        else
            cout<<0<<" "<<y;
    }
    else if(vx==0)
    {
        if(x!=0 && x!=n)
        {
            cout<<-1;
        }
        else if(vy==1)
            cout<<x<<" "<<m;
        else
            cout<<x<<" "<<0;
    }
    else
    {
        if(vy==-1) y = 2*m-y;
        if(vx==-1)
        {
            move(x,y);
            x=0;vx=1;
            if(y==0 || y==m || y==2*m)
            {
                if(y>m) y=2*m-y;
                cout<<x<<" "<<y;
                return 0;
            }
            int dist = (m-(y%m))%m;
            int y1 = solve(dist);
            int y2 = solve(dist+m);
            if(y1==-1 && y2==-1)
            {
                cout<<-1;
            }
            else
            {
                if(y1==-1) y1 = y2;
                else if(y2!=-1)
                    y1 = min(y1,y2);
                y += y1*n;
                y%=2*m;
                if(y1%2) x=n;
                cout<<x<<" "<<y;
            }
        }
        else
        {
            move(n-x,y);
            x=n;vx=-1;
            int cnt = 0;
            int dist = (m-(y%m))%m;
            int y1 = solve(dist);
            int y2 = solve(dist+m);
            if(y==0 || y==m || y==2*m)
            {
                if(y>m) y=2*m-y;
                cout<<x<<" "<<y;
                return 0;
            }
            if(y1==-1 && y2==-1)
            {
                cout<<-1;
            }
            else
            {
                if(y1==-1) y1 = y2;
                else if(y2!=-1)
                    y1 = min(y1,y2);
                y += y1*n;
                y%=2*m;
                if(y1%2) x=0;
                cout<<x<<" "<<y;
            }
        }
    }
    return 0;
}
//a*m+k*n = dist


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

int main() {
    int long long n, k;

    while (cin >> k >> n) {

        if (ceil(k / 2.0) >= n){

            cout << (n * 2) - 1 << endl;

        }
        else{
            int long long j= (n - ceil(k / 2.0)) * 2;
            cout << j << endl;
        }
    }return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long int i,j=0,n,c,sum=0,x,a,b,f=0;
int base(int k,int l)
{
    sum=0;
    while(k!=0)
    {
        sum+=k%l;
        k/=l;

    }
    return sum;
}
int gcd(int a,int b)
{
    return(b==0?a:gcd(b,a%b));
}
int main()
{   f=0;
    cin>>n;
    for(i=2;i<n;i++)
        f+=base(n,i);
        j=gcd(f,n-2);
       cout<<(f/j)<<"/"<<(n-2)/j<<endl;
}