#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define ms(x,y) memset(x,y,sizeof(x))
using namespace std;

typedef long long ll;

const double pi = acos(-1.0);
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;

bool flag = 0;

void step1(int &a,int &b);
void step2(int &a,int &b);
void step3(int &a,int &b);

void step1(int &a,int &b)
{
	if(flag) return;
	if(a==0||b==0)
	{
		flag =1;
		return;
	}
	step2(a,b);
}

void step2(int &a,int &b)
{
	if(flag) return;
	if(a>=2*b)
	{
		a-=2*b;
		step1(a,b);
	}
	else
		step3(a,b);
}

void step3(int &a,int &b)
{
	if(flag) return;
	if(b>=2*a)
	{
		b-=2*a;
		step1(a,b);
	}
	else
		flag=1;
}

int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int a,b;
	cin>>a>>b;
	step1(a,b);
	cout<<a<<" "<<b;
	return 0;
}


//dij
#include <iostream>
#include <fstream>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#define  N   301
#define  inf 0XFFFFFFF
#define  mod 1000000007
#define  ll long long
using namespace std;

//ofstream fo("out.txt");
//ifstream fi("in.txt");
//#define cout cout
//#define cin fi

int n,a[10],s[10];
ll c[N][N];
ll dfs(int n,int now)
{
    ll ans=0;
    if(now>=1&&s[9]-s[now-1]>n)return 0;
    if(now==0&&s[9]>n) return 0;
    if(now==9)
    {
        return 1;
    }
    else if(now!=0)
    {
        for(int i=a[now];i<=n-s[9]+s[now];i++)
        {
            ans+=c[i+n-i+1-1][n-i+1-1]*dfs(n-i,now+1);
            if(ans>=mod)ans%=mod;
        }
        return ans;
    }
    else
    {
        for(int i=a[now];i<=n-s[9]+s[now];i++)
        {
            ans+=c[i+n-i-1][n-i-1]*dfs(n-i,now+1);
            if(ans>=mod) ans%=mod;
        }
    }
    return ans;
}
int main()
{
    int i,j;
    cin>>n;
    for(i=0;i<10;i++)
        cin>>a[i];
    for(i=0;i<N;i++)
    for(j=0;j<=i;j++)
    c[i][j]=1;
    for(i=0;i<N;i++)
    {
        for(j=1;j<i;j++)
        {
            c[i][j]=c[i-1][j-1]+c[i-1][j];
            if(c[i][j]>=mod)c[i][j]%=mod;
        }
    }
    s[0]=a[0];
    for(i=1;i<10;i++)
        s[i]=s[i-1]+a[i];
    long long ans=0;
    for(i=s[9];i<=n;i++)
    {
        ans+=dfs(i,0);
        if(ans>=mod) ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


#include <vector>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int bitct(long long r) {return r == 0 ? 0 : (bitct(r>>1) + (r&1));}
long long gcd(long long x, long long y) {return x ? gcd(y%x,x) : y;}
template<typename T> ostream& operator << (ostream &o,vector<T> v) {o<<"{";
	int i=0,s=v.size();for(;i+1<s;i++)o<<v[i]<<", ";if(s)o<<v[i];o<<"}";return o;}
  /*jj
template<typename K, typename V> ostream& operator << (ostream &o,
  unordered_map<K, V> m) {o<<"{";for(auto i=m.begin();i!=m.end();++i)
  o<<i->first<<" -> "<< i->second << ", "; o<<"}";return o;}
  */
long long choose(long long n, long long q)
{ if(n==0 || q==0) return 1;
	if (q==1) return n; else return ( choose(n, q-1) * (n-q+1 ) /q); }
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

main() {
  long long h;
  cin >> h;
  :wq

	int N;
	cin >> N;
  int ct=0;
  for(int i=1;i<=N;i++)
    for(int j=i;j<=N;j++)
      {
      int c2 = i*i+j*j;
      double c2d = sqrt(c2);
      int test=(int) (c2d + 0.0001);
      if(test*test==c2 && test <= N)
        {
        ct++;
        }
      }
			cout << ct << endl;

}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstddef>
#include <complex>
#include <ctime>
#include <climits>

#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <functional>
#include <iterator>
#include <typeinfo>
#include <utility>
#include <memory>

#include <cassert>

#if __cplusplus >= 201103L
#include <tuple>
#include <ratio>
#include <array>
#include <forward_list>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long int64;
const int inf = 2000000000;
static inline int Rint()
{
	struct X{ int dig[256]; X(){
	for(int i = '0'; i <= '9'; ++i) dig[i] = 1; dig['-'] = 1;
	}};
	static 	X fuck;int s = 1, v = 0, c;
	for (;!fuck.dig[c = getchar()];);
	if (c == '-') s = 0; else if (fuck.dig[c]) v = c ^ 48;
	for (;fuck.dig[c = getchar()]; v = v * 10 + (c ^ 48));
	return s ? v : -v;
}
typedef vector<int> vi;
typedef map<int, int> mii;
typedef set<int> si;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define rep(i, s, e) for (int i = (s); i < (e); ++i)

#if __cplusplus >= 201103L
#define foreach(iter, c) for(auto& iter : c)
#else
#define foreach(itr, c) for(__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); ++itr)
#endif

template<typename T> static inline void cmax(T& a, const T& b){if(b>a)a=b;}
template<typename T> static inline void cmin(T& a, const T& b){if(b<a)a=b;}
#define SL static inline

#define dbg(x) cerr << (#x) << " = " << (x) << endl

const int maxn = 100005;
int64 h;
int n, m, k;

int64 pos[maxn];
int treasure[maxn];
int flag[maxn];

int64 D[10005];

int64 allk[32];
int top;

struct Pt
{
	int64 t, p, id;
	int operator < (const Pt& o) const
	{
		if (t != o.t) return t < o.t;
		if (p != o.p) return p > o.p;
		return id < o.id;
	}
};

void fix(priority_queue<Pt>& pq)
{
	set<pair<int64, int> > st;

	for (int i = 0; i < k; ++i)
	if (D[i] != -1)
	st.insert({D[i], i});

	while (!st.empty())
	{
		auto where = st.begin();
		auto curr = *where;
		st.erase(where);
		if (D[curr.second] != curr.first) continue;
		for (int i = 0; i < top; ++i)
		{
			int64 val = curr.first
			for (int coe = 0; coe < 3; ++coe)
			{
				val += allk[i];
				if (val > h) continue;

				int next = val % k;

				if (next == curr.second)
				{
					continue;
				}

				if (D[next] == -1)
				{
					D[next] = val;
					st.insert({D[next], next});
				}
				else if (D[next] > val)
				{
					D[next] = val;
					st.insert({D[next], next});
				}
			}
		}
	}

	for (int i = 1; i <= n; ++i) if (flag[i] == 0)
	{
		const int bucket = pos[i] % k;
		if (D[bucket] != -1)
		{
			if (pos[i] >= D[bucket])
			{
				pq.push({treasure[i], pos[i], i});
				flag[i] = 1;
			}
		}
	}
}

int main()
{
	scanf("%I64d", &h);
	n = Rint(), m = Rint(), k = Rint();

	for (int i = 1; i <= n; ++i)
	scanf("%I64d %d", pos+i, treasure+i);

	memset(D, -1, sizeof D);
	D[1%k] = 1;

	priority_queue<Pt> pq;

	for (int i = 1; i <= n; ++i)
	{
		const int bucket = pos[i] % k;
		if (D[bucket] != -1)
		{
			if (pos[i] >= D[bucket])
			{
				pq.push({treasure[i], pos[i], i});
				flag[i] = 1;
			}
		}
	}

	for (int id = 0; id < m; ++id)
	{
		const int cmd = Rint();
		if (cmd == 3)
		{
			while (!pq.empty())
			{
				auto curr = pq.top();
				if (treasure[curr.id] != curr.t)
				{
					pq.pop();
				}
				else
				{
					break;
				}
			}
			int64 ans = 0;
			if (!pq.empty())
			{
				ans = pq.top().t;
				treasure[pq.top().id] = -1;
				flag[pq.top().id] = 2;
				//dbg(pq.top().id);
				//dbg(pq.top().p);
				pq.pop();
			}
			printf("%I64d\n", ans);
		}
		else if (cmd == 2)
		{
			const int x = Rint();
			const int c = Rint();
			treasure[x] -= c;
			if (c != 0 && flag[x])
			{
				//assert(flag[x] == 1);
				if (flag[x] == 1)
				{
					pq.push({treasure[x], pos[x], x});
				}
			}
		}
		else
		{
			int64 x; scanf("%I64d", &x);
			int ok = 1;
			//for (int i = 0; i < top; ++i)
			//if (x % allk[i] == 0) ok = 0;
			//if (x % k == 0) ok = 0;
			if (ok)
			{
				allk[top++] = x;
				fix(pq);
				#if 0
				for (int i = 1; i <= n; ++i)
				if (flag[i])
				cerr << pos[i] << " " << treasure[i] << endl;
				cerr << endl;

				for (int i = 0; i < k; ++i)
				cerr << i << " " << D[i] << endl;
				cerr << endl;
				#endif
			}
		}
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <stack>
#include <cstring>
#include <iomanip>
#include <ctime>
using namespace std;
#define pb push_back
#define INF 1001001001
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define vi vector<int>
#define SZ(x) ((int)((x).size()))
#define fi first
#define se second
#define wez(n) int (n); scanf("%d",&(n));
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
inline void pisz(int n) { printf("%d\n",n); }
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR(i,SZ(t))s<<t[i]<<" ";return s; }
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define TESTS wez(testow)while(testow--)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define IOS ios_base::sync_with_stdio(0);

const ll P=1000000007;
ll dp[1042][1042];

int main()
{
    wez2(n,k);
    for(int i=1;i<=n;i++)
            dp[1][i]=n/i;
    for(int i=2;i<=n;i++)
    {
            for(int j=1;j<=n;j++)
            {
                      dp[i][j]=0;
                      for(int k=j;k<=n;k+=j)
                              dp[i][j]+=dp[i-1][k];
                      dp[i][j]=dp[i][j]%P;
            }
    }
    /*for(int i=1;i<=10;i++)
    {
            for(int j=0;j<=10;j++)cout<<dp[i][j]<<" ";
            cout<<endl;
    }*/
    cout<<dp[k][1]<<endl;
    //system("pause");
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
char str[100010],h[100010],m[100010];
ll int mh,mm,lh,lm;
ll int priority(char c)
{
	if(c>='0' && c<='9')
	return c-'0';
	return ((c-'A') +10);
}
void find_time(ll int r)
{
	ll int i,p=1;
	for(i=(lh-1);i>=0;i--)
	{
		mh+=p*priority(h[i]);
		p*=r;
		//~ cout<<mh<<endl;
	}
	p=1;
	for(i=(lm-1);i>=0;i--)
	{
		mm+=p*priority(m[i]);
		p*=r;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	scanf("%s",str);
	ll int i,j,mymax;
	//~ int x,y;
	//~ sscanf(str,"%d:%d",&x,&y);
	//~ cout<<x<<endl<<y<<" "<<endl;
	for(i=0;str[i]!='\0';i++)
	{
		if(str[i]==':')
		{
			h[i]='\0';
			break;
		}
		h[i]=str[i];
	}
	j=0;i++;
	for(;;i++)
	{
		if(str[i]=='\0')
		{
			m[j]='\0';
			break;
		}
		else
		m[j++]=str[i];
	}

	lh=strlen(h);lm=strlen(m);
	bool um,uh,all=1;
	for(i=(lh-1);i>=0;i--)
	{
		if(i<(lh-1) && h[i]!='0')
		uh=1;
		if(h[i]!='0')
		all=0;
	}
	for(i=(lm-1);i>=0;i--)
	{
		if(i<(lm-1) && m[i]!='0')
		um=1;
		if(m[i]!='0')
		all=0;
	}
	if(all)
	{
		cout<<-1<<endl;
	}
	else if(uh==0 && um==0)
	{
		cout<<"here "<<endl;
		mh=0;mm=0;
		find_time(1);
		if(mh<=23 & mm<=60)
		{
			cout<<-1<<endl;
		}
		else if(mh==24 && mm==0)
		{
			cout<<-1<<endl;
		}
		else
		{
			cout<<0<<endl;
		}
	}
	else
	{
		mymax=0;//as we know all are not zero
		vector<ll int> r;
		for(i=0;i<lh;i++)
		{
			mymax=max(mymax,priority(h[i]));
		}
		for(i=0;i<lm;i++)
		{
			mymax=max(mymax,priority(m[i]));
		}
		//~ cout<<mymax<<endl;
		for(i=mymax+1;;i++)
		{
			mh=0;mm=0;
			find_time(i);
			//~ cout<<mh<<" "<<" "<<mm<<endl;
			if(mh<=23 && mm<=60)
			r.push_back(i);
			else if(mh==24 && mm==0)
			r.push_back(i);
			else
			break;
		}
		if(r.size()!=0)
		{
			for(i=0;i<r.size();i++)
			cout<<r[i]<<" ";
			cout<<endl;
		}
		else
		cout<<0<<endl;
	}
	return 0;
}


/*
***************************************************************
Author           : Ishan Dutta
Email            : ishandutta2007@gmail.com
Facebook         : http://www.facebook.com/ishan.dutta
Blog             : tessellationsoftechnology.wordpress.com
Topcoder Handle  : Ishandutta2007
Codeforces Handle: ishandutta2007
Codechef Username: ishandutta2007
Spoj Username    : ishandutta2007
UVA Username     : ishandutta2007
***************************************************************
*/
/* ***************************************************************** */
// \_/\_/\_/\_/\_/\_/\_/\_/---Headers---\_/\_/\_/\_/\_/\_/\_/\_/
/* ***************************************************************** */

//C headers
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<ctime>
#include<cctype>
#include<cassert>
#include<climits>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<clocale>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>

//containers
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<complex>
#include<string>
#include<stack>
#include<bitset>
#include<istream>
#include<valarray>

//IOs
#include<iostream>
#include<sstream>
#include<iomanip>
#include<fstream>
#include<exception>
#include<ios>
#include<iosfwd>
#include<ostream>
#include<iterator>
#include<stdexcept>
#include<streambuf>

//algorithm & miscellaneous
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<limits>
#include<locale>
#include<memory>
#include<new>

/* ****************************************************************** */
// \_/\_/\_/\_/\_/\_/\_/---Frequently used macros---\_/\_/\_/\_/\_/\_/\_/
/* ****************************************************************** */

#define MOD 1000000007
#define INF 1000000000

/* ****************************************************************** */
// \_/\_/\_/\_/\_/\_/\_/\_/\_/---Shorthands---\_/\_/\_/\_/\_/\_/\_/\_/\_/
/* ****************************************************************** */

#define ll long long
#define F first
#define S second
#define pb push_back

#define SZ(c) (c).size()
#define reset(x) memset((x),0,sizeof(x));
#define negset(x) memset((x),-1,sizeof(x));
#define set(x) memset((x),1,sizeof(x));

#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define REVERSE(c) reverse(ALL(c))

#define FOR(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define REP(i,n) FOR(i,0,(n-1))

#define FORD(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define REPD(i,n) FOR(i,(n-1),0)

#define tst int t;scanf("%d",&t);while(t--)
#define s(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)

#define p(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define ps(x) printf("%s",x)

#define pn(x) printf("%d\n",x)
#define pln(x) printf("%lld\n",x)
#define psn(x) printf("%s\n",x)

#define sp system("PAUSE")

/* ****************************************************************** */
// \_/\_/\_/\_/\_/---Fast IO using getchar_unlocked---\_/\_/\_/\_/\_/
/* ****************************************************************** */
/*
int gi(){
   int c = 'a';
   while (!(c >= '0' && c <= '9') && c != '-') c = getchar_unlocked();//();//
   int c2;
   if (c != '-')
     c2 = c;
   else
     c2 = '0';
   int res = 0;
   while((c2 >= '0' && c2 <= '9')){
     res = (res << 3) + (res << 1) + (c2 - '0');
     c2 = getchar_unlocked();//();//
   }
   return res * (c == '-' ? -1 : 1);
}
*/
using namespace std;
/* ****************************************************************** */
// \_/\_/\_/\_/\_/\_/---Actual Code Starts Here---\_/\_/\_/\_/\_/\_/
/* ****************************************************************** */
int n,m,k;
bool fact(){
  if(k==1 && m>1)return true;
  int s=int(sqrt(m));
  if(s<=k){
    for(int i=2;i<=m/k;i++)
      if(m%i==0)return true;
  }
  else{
    for(int i=2;i<=k;i++)
      if(m%i==0)return true;
  }
  return false;
}
int main(){
  s(n);s(m);s(k);
  if(n&1 && fact())cout<<"Timur";
  else cout<<"Marsel";
//sp;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define maxn 2500
#define int long long
int n, P, L, R, ans, C[maxn][maxn];

int read()
{
	int x = 0, k = 1;
	char c; c = getchar();
	while(c < '0' || c > '9') { if(c == '-') k = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * k;
}

void Up(int &x, int y) { x = (x + y) % P; if(x < 0) x += P; }
void Pre()
{
	for(int i = 0; i < maxn; i ++) C[i][0] = 1;
	for(int i = 1; i < maxn; i ++)
		for(int j = 1; j < maxn; j ++)
			C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % P;
}

signed main()
{
	n = read(), P = read(), L = read(), R = read();
	Pre();
	for(int i = 0; i <= n; i ++)
	{
		if(L > i || R < 0) continue;
		int l = max(L, 0), r = min(i, R);
		for(int k = l; k <= r; k ++)
			Up(ans, C[n][i] * C[n - i][i - k] % P),
			Up(ans, P - C[n][i] * C[n - i][i - k - 2] % P);
	}
	printf("%I64d\n", ans);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <climits>
#include <stack>
#include <map>
#include <set>

using namespace std;
string palabra;
double arreglo[3];
int menor()
{
	for(int i=0;i<4;i++)
	{
		for(int j=1;j<4;j++)
		{
			int k = (i+j)%4;
			if(arreglo[i]*2>arreglo[k])
			{
				break;
			}
			if(j==3)
			{
				return i;
			}
		}
	}
	return -1;
}
int mayor()
{
	for(int i=0;i<4;i++)
	{
		for(int j=1;j<4;j++)
		{
			int k = (i+j)%4;
			if(arreglo[i]<arreglo[k]*2)
			{
				break;
			}
			if(j==3)
			{
				return i;
			}
		}
	}
	return -1;
}
char conv(int x)
{
	if(x == 0)
		 return 'A';
	if(x==1)
			return 'B';
	if(x==2)
			return 'C';
	if(x==3)
			return 'D';
	return 'E';
}
int main()
{
	while(true)
	{
		cin>>palabra;
		arreglo[0] = palabra.size()-2;
		cin>>palabra;
		arreglo[1] = palabra.size()-2;
		cin>>palabra;
		arreglo[2] = palabra.size()-2;
		cin>>palabra;
		arreglo[3] = palabra.size()-2;
		char a = conv(mayor());
		char b = conv(menor());
		if(a!='E' and b=='E')
		{
			cout<<a<<endl;
		}
		else if(a=='E' and b!='E')
		{
			cout<<b<<endl;
		}
		else
		{
			cout<<'C'<<endl;
		}
	}
	return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int a , b ,c ,p,h=0,arra[20]={ 0 },arrb[20]={ 0 };
cin>>a>>b;
p=0;
int i=a;
int sizea=0,sizeb=0;
while(i){
if(i%10 > p) p=i%10;
arra[sizea++]=i%10;
i/=10;
}
i=b;
while(i){
if(i%10 > p) p=i%10;
arrb[sizeb++]=i%10;
i/=10;
}
int carry=0;
p++;
for(i=0; i< max(sizea,sizeb); ++i){
carry=(arra[i]+arrb[i]+carry)%p;
h++;
}
if(carry>0) h++;
cout<<h<<"\n";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
template <typename T> inline void read(T &s)
{
	s = 0;char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) s = ((s+(s<<2))<<1)+ch-'0',ch = getchar();
}
int m,a,b,ans[310000];
bool vis[310000];
long long Sum,now;
queue <int> Q;
inline void BFS(int now)
{
	Q.push(now);
	while(!Q.empty())
	{
		int k = Q.front();Q.pop(),ans[now]++;
		if(k-b >= 0 && !vis[k-b]) vis[k-b] = 1,Q.push(k-b);
		if(k+a<=now && !vis[k+a]) vis[k+a] = 1,Q.push(k+a);
	}
}
int main()
{
	read(m),read(a),read(b),ans[0] = vis[0] = 1;
	for(int i = 0,t;i<a;++i)
	{
		t = 1ll*b*i%a;
		if(vis[t]) break;
		vis[t] = 1;
	}
	for(int i = 1;i<=2*a+b;++i)
		if(i-a >= 0 && vis[i-a]) vis[i] = 1,ans[i] = ans[i-1],BFS(i);
		else ans[i] = ans[i-1];
	for(int i = 0;i<=min(2*a+b,m);++i) Sum += ans[i];
	if(2*a + b >= m) {printf("%lld\n",Sum);return 0;}
	for(int i = 2*a+b+1,N,L,R;i<=a*3+b;++i) if(vis[i%a]) L = (i-i%a)/a,R = (m-i%a)/a,Sum += 1ll * a * (1+(R-L+1)) * (R-L+1) / 2;
	Sum += 1ll*ans[2*a+b] * (m - (2*a+b));
	printf("%lld\n",Sum);
	return 0;
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define N 20
using namespace std;
string s,ss;
int main(){
    cin>>s; ss=s;
    FOR(i,0,ss.size()) ss+=ss[i];
    FOR(i,1,5){
        string st;
        cin>>st;
        if (st[0]==s[0]||st[1]==s[1]) {cout<<"YES"; exit(0);}
    }
    cout<<"NO";
}


    #include<iostream>
    #include<math.h>
    #include<vector>
    using namespace std;
    typedef long long ll;

    ll xo, yo, ax, ay, bx, by;
    ll xs, ys, t, x, y, lx, ly,tt;

    vector<pair<ll, ll>> q;

    int main(){
        cin >> xo >> yo >> ax >> ay >> bx >> by;
        cin >> xs >> ys >> t;
        x = xo, y = yo;
        while(1){
            try{
                q.push_back(make_pair(x, y));
                xo = x, yo = y;
                x = ax * xo + bx;
                y = ay * yo + by;
            }
            catch (ll){break;}
            catch (ll){ break;}
        }
        int ans = 0;
        for (int i = 0; i < q.size();i++){
          //  cout << "x=" << q[i].first << " y=" << q[i].second << endl;
            ll now = abs(q[i].first - xs) + abs(q[i].second - ys);
            //cout << "now=" << now << endl;
            for (int j = 0; j < q.size();j++){
                ll to = abs(q[i].first - q[j].first) + abs(q[i].second - q[j].second);
                if(to+now<=t){
                  //  cout << i << " " << j <<" "<<to<< endl;
                    ans = max(ans, abs(j - i)+1);
                }

            }
        }
        printf("%d\n", ans );
    }


//Tanuj Khattar
#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

//#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
const int N = int(3e5)+10;
const int M = int(3e5)+10;
const int LOGN = 20;
VI tree[N],g[2][N];//edge list representation of graph
int U[2][M],V[2][M],vis[N],arr[2][N],T,cmpno,C[2][N],dep[N],DP[LOGN][N],level[N],A[N],comp[N];
bool isbridge[M]; // if i'th edge is a bridge edge or not
queue<int> Q[N];
int t;
int adj(int u,int e){
	return U[t][e]==u?V[t][e]:U[t][e];
}
int dfs0(int u,int edge){ //mark bridges
	vis[u]=1;arr[t][u]=T++;
	int dbe = arr[t][u];
	for(int i=0;i<SZ(g[t][u]);i++){
		int e = g[t][u][i];int w = adj(u,e);
		if(!vis[w])dbe = min(dbe,dfs0(w,e));
		else if(e!=edge)dbe = min(dbe,arr[t][w]);
	}
	if(dbe == arr[t][u] && edge!=-1)isbridge[edge]=true;
	return dbe;
}
void dfs1(int v){//Build the bridge tree
	int currcmp = cmpno;
	Q[currcmp].push(v);vis[v]=1;
	while(!Q[currcmp].empty()){
		int u = Q[currcmp].front();Q[currcmp].pop();C[t][u]=currcmp;
		for(int i=0;i<SZ(g[t][u]);i++){
			int e = g[t][u][i];int w = adj(u,e);
			if(vis[w])continue;
			if(isbridge[e]){cmpno++;
				if(!t){
					tree[currcmp].push_back(cmpno);
					tree[cmpno].push_back(currcmp);
				}
				dfs1(w);
			}
			else Q[currcmp].push(w),vis[w]=1;
		}
	}
}
void buildBridgeTree(int n)
{
	t=0;
	for(int i=1;i<=n;i++)
		if(!vis[i])
			dfs0(i,-1);
	SET(vis,0);
	for(int i=1;i<=n;i++)
		if(!vis[i])
			dfs1(i),cmpno++;
}
//Bridge Tree done
//Pre-Process the forest
int c;
void dfs2(int u,int p)
{
	arr[0][u]=T++;vis[u]=1;DP[0][u]=p;
	level[u]=level[p]+1;comp[u]=c;
	for(auto w:tree[u])
		if(!vis[w])
			dfs2(w,u);
	dep[u]=T++;
}
void preProcess(int n)
{
	T=0;c = 0;
	SET(vis,0);
	for(int i=0;i<n;i++)
		if(!vis[i])
			dfs2(i,i),c++;
	for(int i=1;i<LOGN;i++)
		for(int j=0;j<n;j++)
			DP[i][j]=DP[i-1][DP[i-1][j]];
}
int lca(int a,int b)
{
	if(comp[a]!=comp[b])return -1;
	if(level[a]>level[b])swap(a,b);
	int d = level[b]-level[a];
	for(int i=0;i<LOGN;i++)
		if((1<<i)&d)
			b = DP[i][b];
	if(a==b)return a;
	for(int i=LOGN-1;i>=0;i--)
		if(DP[i][a]!=DP[i][b])
			a=DP[i][a],b=DP[i][b];
	return DP[0][a];
}
//Q[]: array containing k nodes of auxillary tree
//arr[] : arrival time of nodes
//anc(p,u) : returns true if p is ancestor of u
//VI tree[N] : final auxillary tree with O(k) nodes
#define Q QQ
int Q[2*N],k;
int anc(int p,int u)
{
	return arr[0][u]>=arr[0][p] && dep[u]<=dep[p];
}
bool cmp(int u,int v){
	return arr[0][u]<arr[0][v];
}
void create_tree(int &m){//return root of tree
	set<int> S;//get distinct nodes
	for(int i=0;i<k;i++)S.insert(Q[i]);k=0;
	for(auto it=S.begin();it!=S.end();it++)Q[k++]=*it;
	sort(Q,Q+k,cmp);int kk = k;//distinct initial nodes
	//add lca of adjacent pairs
	for(int i=0;i<kk-1;i++){
		int x = lca(Q[i],Q[i+1]);
		if(x==-1)continue;
		if(S.count(x))continue;
		Q[k++]=x;S.insert(x);
	}
	sort(Q,Q+k,cmp);
	stack<int> s;
	for(int i=0;i<k;i++){
		while(!s.empty() && !anc(s.top(),Q[i]))s.pop();
		if(s.empty())
			s.push(Q[i]);
		else
		{
			U[t][m]=s.top();V[t][m]=Q[i];
			g[t][s.top()].PB(m);
			g[t][Q[i]].PB(m);
			m++;
			s.push(Q[i]);
		}
	}
}
//check biconnectivity in final tree
bool go(int n,int m)
{
	for(int i=0;i<k;i++)vis[Q[i]]=0;
	for(int i=0;i<m;i++)isbridge[i]=false;
	T=0;
	for(int i=0;i<k;i++)
		if(!vis[Q[i]])
			dfs0(Q[i],-1);
	for(int i=0;i<k;i++)vis[Q[i]]=0;
	cmpno=0;
	for(int i=0;i<k;i++)
		if(!vis[Q[i]])
			dfs1(Q[i]),cmpno++;
	bool ok=true;
	for(int i=0;i<n;i++)
		if(C[t][A[i]]!=C[t][A[0]])
			ok=false;
	for(int i=0;i<k;i++)g[t][Q[i]].clear();
	return ok;
}

//For input
int R;
int n,m,q;
int rotate(int element)
{
	element=(element+R)%n;
	if (element==0) {
		element=n;
	}
	return element;
}
int main()
{
	si(n);si(m);si(q);
	for(int i=0;i<m;i++)
	{
		scanf("%d %d",U[t]+i,V[t]+i);
		g[t][U[t][i]].PB(i);
		g[t][V[t][i]].PB(i);
	}
	buildBridgeTree(n);
	preProcess(cmpno);
	t=1;
	for(int qq=1;qq<=q;qq++)
	{
		int nn,mm;k=0;
		si(nn);si(mm);
		for(int i=0;i<nn;i++)
		{
			si(A[i]);A[i]=rotate(A[i]);
			Q[k++]=A[i];A[i]=C[0][A[i]];
		}
		for(int i=0;i<mm;i++)
		{
			scanf("%d %d",U[t]+i,V[t]+i);
			U[t][i]=rotate(U[t][i]);
			V[t][i]=rotate(V[t][i]);
			Q[k++]=U[t][i];Q[k++]=V[t][i];
			U[t][i]=C[0][U[t][i]];V[t][i]=C[0][V[t][i]];
		}
		for(int i=0;i<k;i++)Q[i]=C[0][Q[i]];
		for(int i=0;i<mm;i++)
		{
			g[t][U[t][i]].PB(i);
			g[t][V[t][i]].PB(i);
		}
		create_tree(mm);
		bool ok = go(nn,mm);
		puts(ok?"YES":"NO");
		if(ok)R+=qq;
	}
	return 0;
}


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

bool isLeap(int y){
	if( y % 4 == 0 && y % 100 != 0)
		return true;
	else if(y % 4 == 0 && y % 100 == 0 && y % 400 == 0)
		return true;
	else
		return false;
	// if(y % 4 == 0 && (y % 100 != 0 || y % 400 == 0) )

	// return (y % 4 == 0 && ( y % 100 != 0 || y % 400 == 0 ) ? true : false);
}

int calMonth(int m1, int m2, int y){

	int days = 0;

	for(int i=m1; i<=m2; i++){
				if(i == 2){
					if(isLeap(y))
						days += 29;
					else
						days += 28;
				}
				else if(i % 2 != 0 && i <= 7)
					days += 31;
				else if(i % 2 == 0 && i >= 8)
					days += 31;
				else
					days += 30;
			}

	return days;
}

int main() {
	// your code goes here
	string date1, date2;

	int y1, y2, m1, m2, d1, d2;

	cin>>date1>>date2;

	y1 = stoi(date1.substr(0, 4));
	y2 = stoi(date2.substr(0, 4));
	m1 = stoi(date1.substr(5, 2));
	m2 = stoi(date2.substr(5, 2));
	d1 = stoi(date1.substr(8, 2));
	d2 = stoi(date2.substr(8, 2));

	int days = 0;
	if(y1 == y2){
		if(m1 == m2)
			days += abs(d2-d1);
		else{
			if(m1 > m2){
				swap(m1, m2);
				swap(d1, d2);
			}

			if(m1 == 2){
				if(isLeap(y1))
					days += 29 - d1;
				else
					days += 28 - d1;
			}
			else if((m1 < 8 && m1 % 2 != 0) && (m1 >=8 && m1 % 2 == 0) )
				days = 31 - d1;
			else
				days = 30 - d1;

			days += calMonth(m1+1, m2-1, y1);
			days += d2;
		}

		cout<<days;
	}
	else{

		if(y1 > y2){
			swap(y1, y2);
			swap(m1, m2);
			swap(d1, d2);
		}

		if(m1 == 2){
				if(isLeap(y1))
					days += 29 - d1;
				else
					days += 28 - d1;
		}
		else if( (m1 < 8 && m1 % 2 != 0) || (m1>=8 && m1 % 2 == 0) )
			days = 31 - d1;
		else
			days = 30 - d1;

		days += calMonth(m1+1, 12, y1);

		for(int j=y1+1; j<= y2-1; j++){
			if(isLeap(j))
				days += 366;
			else
				days += 365;
		}

		days += calMonth(1, m2-1, y2);
		days += d2;

		cout<<days;
	}

	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define For(i,n) for(int i=0;i<n;i++)
#define mem(a,b) memset(a,b,sizeof(a))
#define int long long int
#define ld long double
#define fio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define vpi vector<pair<int,int> >
#define vv vector<int>
#define MAXN 1001
int A[MAXN];
int C[1001][1001];
void binomialCoeff()
{
    int i, j;
    int n = 1000, k = 1000;
    for (i = 0; i <= n; i++)
    {
        for (j = 0; j <= min(i, k); j++)
        {
            // Base Cases
            if (j == 0 || j == i)
                C[i][j] = 1;
            else
                C[i][j] = C[i - 1][j - 1] +
                          C[i - 1][j];
        }
    }

    return C[n][k];
}

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fio;
	int t=1;
	//cin >> t;
	binomialCoeff()
	while (t--)
	{
		int n;
		cin >> n;
    int kk = [n][n/2];
    cout<<kk*(n+1)*2<<endl;
	}

}


#include <iostream>
#include <algorithm>

using namespace std;

void solve() {
	long int m, n, k;
	cin >> n >> m >> k;
	if (n > m)
		swap(n, m);
	if (m + n - 2 < k) {
		cout << -1 << '\n';
		return;
	}
	else if (m + n - 2 == k) {
		cout << 1 << '\n';
		return;
	}

	long int a1, b1, a2, b2;

	if (k > m - 1) {
		a1 = 1;
		b1 = n / (k - m);
	}
	else {
		a1 = m / (k + 1);
		b1 = n;
	}

	if (k > n - 1) {
		a2 = 1;
		b2 = m / (k - n);
	}
	else {
		a2 = n / (k + 1);
		b2 = m;
	}

	cout << max(a1*b1, a2*b2) << '\n';
}

int main() {

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	solve();

	return 0;
}

/* Sat Feb 22 2020 12:14:22 GMT+0300 (MSK) */


#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long t , n;
	string s;
	cin >> s;
	n = 0;
	for (int i = 0; i < s.length()-2; i++){
		if (s[i] != 'Q') continue;
		for (int j = i+1; j < s.length()-1; j++){
			if (s[j] != 'A') continue;
			for (int k = j+1; k < s.length(); k++)
		 		if (s[i] == 'Q' && s[j] == 'A' &&  s[k] == 'Q') n++;
		}
	}
	cout << n;
}
//by karangreat


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

#define ll long long
#define ull unsigned long long
#define st size_t
#define quick ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define mp make_pair

string append_zero(ll n) {
  string str = "";
  while (n > 1)
    str += '0';
  return str;
}

int main() {
  quick;
  int n;
  string str;
  cin >> n >> str;
  char prev = '\0';
  ll ans = 0;
  string res = "";
  for (char c : str) {
    if (prev == '\0') {
      prev = c;
      ans = 1;
    }
    else if (prev == c) {
      ans++;
    } else {
      if (prev == '1')
	res += to_string(ans);
      else
	res += append_zero(ans);
      ans = 1;
      prev = c;
    }
  }
  if (prev == '1')
    res += to_string(ans);
  else
    res += append_zero(ans);
  cout << res << endl;
  return 0;
}


#include<stdio.h>
int main()
{
	int v1,v2,t1,t2,t3,t4,n;
	scanf("%d%d%d%d%d",&n,&v1,v2,t1,t2);
	t3=n*v1+(2*t1);
	t4=n*v2+(2*t2);
	if(t3>t4)printf("First\n");
	else if(t4>t3)printf("Second\n");
	else printf("Friendship\n");
	return 0;
}


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

struct tab
{
    int valor;
    int distancia;
};

int visitados[200005];
int calcula(int x,int p){
    int flag2 = 0;
    int a = (x/50)%475;
    for(int i=0;i<25;i++){
        a = ((a*96)+42)%475;
        if((a+26) == p){
            flag2 = 1;
            break;
        }
    }
    return flag2;
}

int main(){
    int p,x,y;
    scanf("%d %d %d",&p,&x,&y);
    queue<tab> FILA;
    tab aux1,aux2,aux3;

    aux1.valor = x;
    aux1.distancia = 0;
    FILA.push(aux1);

    while(!FILA.empty()){
        aux1 = FILA.front();

        FILA.pop();
        int flag = calcula(aux1.valor,p);

        if(flag && aux1.valor >= y){
            printf("%d\n",aux1.distancia);
            break;
        }
        else{
            if(visitados[aux1.valor] == 1){
                continue;
            }
            visitados[aux1.valor] = 1;

            aux2.valor = aux1.valor + 100;
            aux2.distancia = aux1.distancia + 1;
            FILA.push(aux2);

            aux2.valor = aux1.valor - 50;
            aux2.distancia = aux1.distancia;
            FILA.push(aux2);

            while((x - 50) >= y){
                aux2.valor = x - 50;
                aux2.distancia = aux1.distancia;
                FILA.push(aux2);
                x -= 50;
            }
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <fstream>

using namespace std;

int main(){
long long  a,b;
cin>>a>>b;
vector <int> prime(100000000+5,0);
long long minidex=0;
long long min1=1000000000000000000-1;
long long c=a;
long long d=b;
    while(c>0&&d>0){
        if(c>d){
            c=c%d;
        }
        else{
            d=d%c;
            }
    }
for(long long i=0;i<=max(c+d,abs(a-b));i++){
    long long y=a+i;
     long long x=b+i;
    while(x>0&&y>0){
        if(x>y){
            x=x%y;
        }
        else{
            y=y%x;
            }
    }
    if((((b+i)*(a+i))/(x+y))<min1){
        minidex=i;
        min1=(((b+i)*1ll*(a+i))/(x+y));
    }
}
cout<<minidex;
return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())
#define MAGIC0
mt19937 rnd(time(0)); //rnd()

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

const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = 1LL * INF*INF;
const int MAX = 1e5 + 7;
const double PI = acos(-1.);
const double EPS = 1e-8;
const int MOD = 1000 * 1000 * 1000 + 7;

vector<LL> vec;

int kol;

LL gcd(LL a, LL b)
{
//	cout << a << ' ' << b << endl;
	if (!kol)
	{
		vec.PB(abs(a-b));
		vec.PB(a+b);
	}
	if (!b) return a;
	return gcd(b, a % b);
}

LL nsk(LL a, LL b)
{
	return a / gcd(a, b) * b;
}

VI fac(int a)
{
	VI res;
	for(LL j = 1;j * j <= a;++j)
	{
		if (a % j == 0)
		{
			res.PB(a / j);
			if (a / j != j)
			{
				res.PB(j);
			}
		}
	}
	return res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	LL a, b;
	cin >> a >> b;

	vec.reserve(1000000);
	LL cur = nsk(a, b), k = 0;
	FOR(el, 0, min((LL)1e7, (LL)abs(a-b)+1))
	{

		if (nsk(a + el, b + el) < cur)
		{
			cur = nsk(a + el, b + el);
			k = el;
		}
		else
		if (nsk(a + el, b + el) == cur)
		{
			k = min(k, (LL)el);
		}
	}

	cout << k;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,d,n,m;
    cin>>a>>b>>c>>d;
    n=a-(a/250)*c;
    n=max(a*3/10,a);
    m=b-(b/250)*d;
    if(n>m)cout<<"Misha"<<endl;
    m=max(b*3/10,b);
    else if(m>n)cout<<"Vasya"<<endl;
    else cout<<"Tie"<<endl;
    cout<<m<<endl<<n<<endl;
}


#include<cmath>
#include<iostream>
using namespace std;
typedef long long ll;
int dig[12],tot,ans;
int main(){
	ll n,m; cin>>n; m=n;
	while(n){dig[++tot]=n%10; n/=10;}
	int iter=tot+1;
	for(int i=1;i<=tot;i++){
		if(dig[i]!=9){iter=i; break;}
		else ans+=9;
	}
	if(iter==tot) return 0;
	else{
		for(int i=iter;i<tot;i++){
			if(dig[i]==9){ans+=9; dig[i+1]--;}
			else{ans+=dig[i]+10; dig[i+1]--;}
		}
		ans+=dig[tot];
	}
	cout<<ans;
return 0;
}


# include <bits/stdc++.h>
using namespace std;
long long us[100000];
int main()
{366 365
    long long n , i , j  , s , k = 0 , p;
    cin>> n;
    for(i = 1 ; i <= n ; i ++){
        for(j = i ; j <= n ; j ++){
            s = i * i + j * j;
            p = sqrt(s);
            if(p * p == s && p >= j && p <= n)
            k++;

        }
    }
    cout<<k;
}


#include<iostream>
using namespace std;
//#include<stdio.h>
int main()
{
    int r1,r2,l1,l2;
    while(scanf("%d%d",&r1,&l1))
    {
        //scanf("%d%d",&l1,&r1);
        scanf("%d%d",&l2,&r2);
        if(((2*l1+3>r2)&&(r2+1>l1-1))||((2*r1+3>l2)&&(l2+1>r1-1)))
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


// Paste me into the FileEdit configuration dialog
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<sstream>
#include<set>
using namespace std;
#define PI (2.*acos(0.))
#define EPS 1e-9

#define GETBIT(x,i) (x&(1<<i))
#define SETBIT(x,i) (x|(1<<i))
#define FORab(i,a,b) for(typeof(b) i=(a);i<=(b);i++)
#define FOR(i,n) FORab(i,0,(n)-1)
#define FOR1(i,n) FORab(i,1,n)
#define FORit(it,a) for( typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define all(a) (a).begin(),(a).end()
#define ms(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define sz(a) (int)a.size()
#define in(a,b,c) ((a) <= (b) && (b) <= (c))
#define px first
#define py second

typedef long long  LL;
typedef vector<int>   vi;
typedef pair<int,int>  pii;
int n,k,d[1100],s[1100];
#define MOD 1000000009
int main()
{
    LL n,m;
    cin>>n>>m;
    LL a=1;
    FOR(i,m)a=(a*2)%MOD;
    LL ans=1;
    FOR(i,n)
    {
        a=(a-1+MOD)%MOD;
        ans*=a;
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}

// Paste me into the FileEdit configuration dialog
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<sstream>
#include<set>
using namespace std;
#define PI (2.*acos(0.))
#define EPS 1e-9

#define GETBIT(x,i) (x&(1<<i))
#define SETBIT(x,i) (x|(1<<i))
#define FORab(i,a,b) for(typeof(b) i=(a);i<=(b);i++)
#define FOR(i,n) FORab(i,0,(n)-1)
#define FOR1(i,n) FORab(i,1,n)
#define FORit(it,a) for( typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define all(a) (a).begin(),(a).end()
#define ms(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define sz(a) (int)a.size()
#define in(a,b,c) ((a) <= (b) && (b) <= (c))
#define px first
#define py second

typedef long long  LL;
typedef vector<int>   vi;
typedef pair<int,int>  pii;
int n,k,d[1100],s[1100];
#define MOD 1000000009
int main()
{
    LL n,m;
    cin>>n>>m;
    LL a=1;
    FOR(i,m)a=(a*2)%MOD;
    LL ans=1;
    FOR(i,n)
    {
        a=(a-1+MOD)%MOD;
        ans*=a;
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define int long long
using namespace std;

#define rep(i,n) for (int i=0;i<(int)(n);++i)
#define rep1(i,n) for (int i=1;i<=(int)(n);++i)
#define range(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define F first
#define S second

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
/*
计算u^v % mod
*/
ll power(ll u,ll v,ll mod){
    ll ret=1,t=u%mod;
    while (v){
        if (v&1) ret=t*ret%mod;
        t=t*t%mod, v>>=1;
    }
    return ret%mod;
}

/*
计算gcd(a,b)并找寻ax+by=gcd(a,b)的一组解
ret=exgcd(a,b,x,y);
*/
ll exgcd(ll a,ll b,ll &x,ll &y){
    if (b){
        ll d=exgcd(b,a%b,y,x);
        return y-=a/b*x, d;
    }
    return x=1,y=0,a;
}

/*
计算x=a(mod m), x=b(mod n)的一组解，若无解返回-1
ret=crt(a,m,b,n);
*/
ll crt(ll a,ll m,ll b,ll n){
    if (n>m) swap(a,b), swap(n,m);
    ll x,y,g=exgcd(m,n,x,y);
    if ((b-a)%g) return -1;
    x=(b-a)%n*x%n/g*m+a;
    return x<0?x+m*n/g:x;
}

/*
生成<=n的质数
gen_prime<5000>(ret);
*/

void gen_prime(int n,vi &ret){
    vector<bool> p;
    p.resize(n+1,1);
    p[0]=p[1]=0;
    for (int i=4;i<=n;i+=2) p[i]=0;
    for (int i=3;i*i<=n;i+=2){
        if (p[i]){
            for (int j=i*i;j<=n;j+=2*i){
                p[j]=0;
            }
        }
    }
    for (int i=2;i<=n;++i){
        if (p[i]) ret.pb(i);
    }
}

/*
生成<=n的phi
gen_phi<5000>(ret);
*/
void gen_phi(int n,vi &phi){
    phi.resize(n+1);
    for (int i=0;i<=n;++i) phi[i]=i&1?i:i/2;
    for (int i=3;i<=n;i+=2){
        if (phi[i]==i){
            for (int j=i;j<=n;j+=i) phi[j]-=phi[j]/i;
        }
    }
}

/*
支持更高的快速幂操作
expower.mod_pow(a,b,mod);
*/

struct expower{
    ull mod_mul(ull a,ull b,ull M) {
        ll ret=a*b-M*ull(ld(a)* ld(b)/ld(M));
        return ret+M*(ret<0)-M*(ret>=(ll)M);
    }
    ull mod_pow(ull b,ull e,ull mod) {
        ull ans=1;
        for (; e; b=mod_mul(b,b,mod), e/=2)
            if (e&1) ans=mod_mul(ans,b,mod);
        return ans%mod;
    }
}expower;

/*
Miller-Rubin素数判别
is_prime(n);
*/
bool is_prime(ull n){
    if (n<2||n%6%4!=1) return n-2<2;
    ull A[]={2,325,9375,28178,450775,9780504,1795265022},
    s=__builtin_ctzll(n-1), d = n >> s;
    for (auto a:A){
        ull p=expower.mod_pow(a,d,n),i=s;
        while (p!=1&&p!=n-1&&a%n&&i--)
            p=expower.mod_mul(p,p,n);
        if (p!=n-1&&i!=s) return 0;
    }
    return 1;
}

/*
素因数分解
ret=factorization(n);
*/
ull pollard(ull n){
    auto f=[n](ull x){return (expower.mod_mul(x,x,n)+1)%n;};
    if (!(n&1)) return 2;
    for (ull i=2;;i++){
        ull x=i,y=f(x),p;
        while ((p=__gcd(n+y-x,n))==1)
            x=f(x),y=f(f(y));
        if (p!=n) return p;
    }
}

vector<ull> factorization(ull n){
    if (n==1) return {};
    if (is_prime(n)) return {n};
    ull x=pollard(n);
    auto l=factorization(x),r=factorization(n/x);
    l.insert(l.end(),range(r));
    return l;
}

struct DSU{
    //insert info.
    vector<int> p;
    DSU(int n){
        p.resize(n+1);
        for (int i=1;i<=n;++i) p[i]=i;
    }
    int find(int u){
        if (p[u]==u) return u;
        return p[u]=find(find(p[u]));
    }
    bool unite(int u,int v){
        int pu=find(u), pv=find(v);
        if (pu!=pv){
            p[pu]=pv;
        }
        return pu!=pv;
    }
};

/* (u,v,w) */
template<class T> vector<tuple<int,int,T> > MST(int n,vector<tuple<int,int,T> >g){
    vector<tuple<int,int,T> > ret;
    ret.clear();
    DSU dsu(n);
    auto cmp=[&](tuple<int,int,T> x,tuple<int,int,T> y){
        int ux,uy,vx,vy;
        T wx,wy;
        tie(ux,vx,wx)=x, tie(uy,vy,wy)=y;
        return wx<wy;
    };
    sort(range(g),cmp);
    for (auto c:g){
        int u,v;
        T w;
        tie(u,v,w)=c;
        if(dsu.unite(u,v)) ret.push_back(c);
    }
    return ret;
}

template<int n,class T>
struct SegmentTree{
    typedef struct{
        T lz,mx,mn,sum;
    }Node;
    vector<Node> tree;
    SegmentTree(){
        tree.resize((n+7)<<2);
    }
    void pushup(int num){
        tree[num].mx=max(tree[num<<1].mx,tree[num<<1|1].mx);
        tree[num].mn=min(tree[num<<1].mn,tree[num<<1|1].mn);
        tree[num].sum=tree[num<<1].sum+tree[num<<1|1].sum;
    }
    void pushdown(int num,int l,int r,int md){
        if (tree[num].lz){
            tree[num<<1].mx+=tree[num].lz;
            tree[num<<1|1].mx+=tree[num].lz;
            tree[num<<1].mn+=tree[num].lz;
            tree[num<<1|1].mn+=tree[num].lz;
            tree[num<<1].sum+=tree[num].lz*(md-l+1);
            tree[num<<1|1].sum+=tree[num].lz*(r-md);
            tree[num<<1].lz+=tree[num].lz;
            tree[num<<1|1].lz+=tree[num].lz;
            tree[num].lz=0;
        }
    }
    void update1(int num,int l,int r,int L,int R,T val){
        if (L<=l&&r<=R){
            tree[num].mx+=val;
            tree[num].mn+=val;
            tree[num].sum+=val*(r-l+1);
            tree[num].lz+=val;
            return;
        }
        int md=(l+r)>>1;
        pushdown(num,l,r,md);
        if (md>=L) update1(num<<1,l,md,L,R,val);
        if (md<R) update1(num<<1|1,md+1,r,L,R,val);
        pushup(num);
    }
    tuple<T,T,T> query1(int num,int l,int r,int L,int R){
        if (L<=l&&r<=R){
            return {tree[num].mn,tree[num].mx,tree[num].sum};
        }
        int md=(l+r)>>1;
        pushdown(num,l,r,md);
        if (md>=R){
            return query1(num<<1,l,md,L,R);
        }
        else{
            if (md<L){
                return query1(num<<1|1,md+1,r,L,R);
            }
            else{
                tuple<T,T,T> ret1=query1(num<<1,l,md,L,R), ret2=query1(num<<1|1,md+1,r,L,R);
                T a,b,c,d,e,f;
                tie(a,b,c)=ret1, tie(d,e,f)=ret2;
                return {min(a,d),max(b,e),c+f};
            }
        }
    }
    void update(int L,int R,int w){
        update1(1,1,n,L,R,w);
    }
    tuple<T,T,T> query(int L,int R){
        return query1(1,1,n,L,R);
    }
    void debug1(int num,int l,int r){
        if (l==r){
            cout<<tree[num].mn<<" "; return;
        }
        int md=(l+r)>>1;
        pushdown(num,l,r,md);
        debug1(num<<1,l,md);
         debug1(num<<1|1,md+1,r);
    }
    void debug(){
        debug1(1,1,n);
        cout<<endl;
    }
};

struct XORBasis{
    int n;
    vector<ull> p;
    vector<ull> ans;
    XORBasis(int k):n(k){
        p.resize(k+1);
    }
    void rebuilt(){
        ans.clear();
        for (int i=0;i<=n;++i){
            if (p[i]) ans.push_back(p[i]);
        }
    }
    void insert(ull u){
        for (int i=n;i>=0;--i){
            if (u&(1ull<<i)){
                if (p[i]) u^=p[i];
                else{
                    p[i]=u;
                    for (int j=i-1;j>=0;--j){
                        if (p[i]&(1ull<<j)) p[i]^=p[j];
                    }
                    for (int j=i+1;j<=n;++j){
                        if (p[j]&(1ull<<i)) p[j]^=p[i];
                    }
                    break;
                }
            }
        }
        rebuilt();
    }
    bool check(ull u){
        for (int i=n;i>-1;--i){
            if (u&(1ull<<i)) u^=p[i];
        }
        return (u==0);
    }
    ull kth(ull t){ // the k-th smallest, excluding 0.
        if (t>=(1ull<<sz(ans))) return -1;
        ull ret=0;
        for (int i=0;i<sz(ans);++i){
            if (t&(1ull<<i)) ret^=ans[i];
        }
        return ret;
    }
    ull total(){
        return (1ull<<sz(ans));
    }
};

vi pi(const string& s) {
	vi p(sz(s));
	for (int i=1;i<=sz(s);++i) {
		int g = p[i-1];
		while (g && s[i] != s[g]) g = p[g-1];
		p[i] = g + (s[i] == s[g]);
	}
	return p;
}

vi match(const string& s, const string& pat) {
	vi p = pi(pat + '\0' + s), res;
	for(int i=sz(p)-sz(s);i<=sz(p);++i)
		if (p[i] == sz(pat)) res.push_back(i - 2 * sz(pat));
	return res;
}

struct AhoCorasick {
	enum {alpha = 26, first = 'a'};
	struct Node {
		// (nmatches is optional)
		int back, next[alpha], start = -1, end = -1;
        ll nmatches = 0;
		Node(int v) { memset(next, v, sizeof(next)); }
	};
	vector<Node> N;
	vector<int> backp;
	void insert(string& s, int j,ll val) {
		assert(!s.empty());
		int n = 0;
		for(auto c:s) {
			int& m = N[n].next[c - first];
			if (m == -1) { n = m = sz(N); N.emplace_back(-1); }
			else n = m;
		}
		if (N[n].end == -1) N[n].start = j;
		backp.push_back(N[n].end);
		N[n].end = j;
		N[n].nmatches+=val;
	}
	AhoCorasick(vector<string>& pat,vi val) {
		N.emplace_back(-1);
		for (int i=0;i<sz(pat);++i) insert(pat[i], i, val[i]);
		N[0].back = sz(N);
		N.emplace_back(0);

		queue<int> q;
		for (q.push(0); !q.empty(); q.pop()) {
			int n = q.front(), prev = N[n].back;
			for (int i=0;i<alpha;++i) {
				int &ed = N[n].next[i], y = N[prev].next[i];
				if (ed == -1) ed = y;
				else {
					N[ed].back = y;
					(N[ed].end == -1 ? N[ed].end : backp[N[ed].start])
						= N[y].end;
					N[ed].nmatches += N[y].nmatches;
					q.push(ed);
				}
			}
		}
	}
	vi find(string& word,ll& ans) {
		int n = 0;
		vi res;
		for(auto c:word) {
			n = N[n].next[c - first];
			res.push_back(N[n].end);
			ans += N[n].nmatches;
		}
		return res;
	}
	vector<vi> findAll(vector<string>& pat, string word) {
		ll ans=0;
        vi r = find(word,ans);
		vector<vi> res(sz(word));
		for (int i=0;i<sz(word);++i) {
			int ind = r[i];
			while (ind != -1) {
				res[i - sz(pat[ind]) + 1].push_back(ind);
				ind = backp[ind];
			}
		}
		return res;
	}
};

struct HLD{
    int n,cnt=0;
    vector<vi> G;
    vi par,dep,siz,son,top,dfn,rk;
    //父亲节点，深度，子树大小，重子节点，重链头部，dfs序，dfs序对应的节点编号
    HLD(vector<vi> g,int root=1):n(sz(g)),G(g),par(n+7),dep(n+7),siz(n+7,1),son(n+7,-1),top(n+7),dfn(n+7),rk(n+7){
        dep[0]=-1, dfs1(root,0), dfs2(root,0,root);
    }
    void dfs1(int u,int p){
        for (auto c:G[u]){
            if (c==p) continue;
            dep[c]=dep[u]+1, par[c]=u;
            dfs1(c,u);
            siz[u]+=siz[c];
            if (son[u]==-1||siz[son[u]]<siz[c]) son[u]=c;
        }
    }
    void dfs2(int u,int p,int tp){
        top[u]=tp;
        dfn[u]=++cnt;
        rk[cnt]=u;
        if (son[u]==-1) return;
        dfs2(son[u],u,tp);
        for (auto c:G[u]){
            if (c==p||c==son[u]) continue;
            dfs2(c,u,c);
        }
    }
    int lca(int u,int v){
        while (top[u]!=top[v]){
            if (dep[top[u]]>dep[top[v]]){
                u=par[top[u]];
            }
            else{
                v=par[top[v]];
            }
        }
        return dep[u]>dep[v]?v:u;
    }
    vector<pii> find_seg(int u,int v){
        vector<pii> ft,bk,res;
        ft.clear(), bk.clear(), res.clear();
//        cout<<top[u]<<" "<<top[v]<<endl;
        while (top[u]!=top[v]){
            if (dep[top[u]]>dep[top[v]]){
                ft.pb({u,top[u]});
                u=par[top[u]];
            }
            else{
                bk.pb({top[v],v});
                v=par[top[v]];
            }
        }
        ft.pb({u,v});
        for (int i=0;i<sz(ft);++i) res.pb(ft[i]);
        for (int i=sz(bk);i>0;--i) res.pb(bk[i-1]);
        return res;
    }
};

struct BIT{
    vi C; int n;
    BIT(int n):n(n){C.resize(n+7,0);}
    void update(int u,int w){
        for (;u<=n;u+=u&(-u)) C[u]+=w;
    }
    int query(int u){
        int res=0;
        for (;u>0;u-=u&(-u)) res+=C[u];
        return res;
    }
};

vi topoSort(const vector<vi>& gr) {
	vi indeg(sz(gr)), ret;
	for (auto& li : gr) for (int x : li) indeg[x]++;
	queue<int> q; // use priority queue for lexic. smallest ans.
	rep(i,sz(gr)) if (indeg[i] == 0) q.push(-i);
	while (!q.empty()) {
		int i = -q.front(); // top() for priority queue
		ret.push_back(i);
		q.pop();
		for (int x : gr[i])
			if (--indeg[x] == 0) q.push(-x);
	}
	return ret;
}

vi path;
namespace Eulerian {
    const int N = 3, M = 3;
    int t, n, m, tot, cc, hd[N], nxt[M], to[M], bh[M], vis[M], in[N], out[N], ans[M];
    void add(int x, int y, int id) {
        nxt[++tot] = hd[x];
        hd[x] = tot;
        to[tot] = y;
        bh[tot] = id;
        in[y]++;
        out[x]++;
    }
    void dfs(int x) {
        for (int i = hd[x]; i; i = hd[x]) {
            while (i && vis[abs(bh[i])]) i = nxt[i];
            hd[x] = i;
            if (!i) break;
            vis[abs(bh[i])] = 1;
            dfs(to[i]), ans[++cc] = bh[i];
        }
    }

    void init() {
        memset(hd, 0, sizeof(hd));
        memset(nxt, 0, sizeof(nxt));
        memset(to, 0, sizeof(to));
        memset(bh, 0, sizeof(bh));
        memset(vis, 0, sizeof(vis));
        memset(in, 0, sizeof(in));
        memset(out, 0, sizeof(out));
        memset(ans, 0, sizeof(ans));
        t = 1;
        n = 0;
        m = 0;
        tot = 0;
        cc = 0;
    }
    bool solve() {
        for (int i = 1; i <= n; i++)
            if ((t == 1 && in[i] & 1)) {
                return false;
            }
        dfs(to[1]);
        if (cc < m) return false;
        else {
            path.clear();
            for (int i = cc; i >= 1; i--) path.push_back(ans[i]);
            return true;
        }
    }
} // namespace Eulerian

namespace FWT{
    //mod=-1 (no mod)
    const int mod=-1;

    inline int modadd(int a,int b){
        a+=b;
        if (mod==-1) return a;
        a%=mod, a+=mod, a%=mod;
        return a;
    }

    vi OR(vi &a,int mode=1){
        vi b(a);
        for (int i=0;(1<<i)<sz(a);++i){
            for (int j=0;j<sz(a);++j){
                if (j>>i&1) b[j]=modadd(b[j],b[j^(1<<i)]*mode);
            }
        }
        return b;
    }
    vi AND(vi &a,int mode=1){
        vi b(a);
        for (int i=0;(1<<i)<sz(a);++i){
            for (int j=0;j<sz(a);++j){
                if (j>>i&1) b[j^(1<<i)]=modadd(b[j^(1<<i)],b[j]*mode);
            }
        }
        return b;
    }
    vi XOR(vi &a,int mode=1){
        vi b(a);
        for (int i=0;(1<<i)<sz(a);++i){
            for (int j=0;j<sz(a);++j){
                if (j>>i&1){
                    b[j^(1<<i)]=modadd(b[j^(1<<i)],b[j]);
                    b[j]=modadd(b[j^(1<<i)],-2*b[j]);
                    if (mode<0) {
                        if (mod>0) b[j]=b[j]*power(2,mod-2,mod)%mod, b[j^(1<<i)]=b[j^(1<<i)]*power(2,mod-2,mod)%mod;
                        else b[j]/=2, b[j^(1<<i)]/=2;
                    }
                }
            }
        }
        return b;
    }
}

const int maxn=4000007;
const int mod=998244353;
int n,m;
int f[maxn];
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n>>m;
    f[0]=1;
    rep1(i,maxn-1) f[i]=i*f[i-1]%mod;
    int res=0,res2=0;
    auto mt=[&](int u,int v){
        return u*v%mod;
    };
    auto C=[&](int u,int v){
        return mt(f[u],mt(power(f[v],mod-2,mod),power(f[u-v],mod-2,mod)));
    };
    rep1(i,n){
        int tmp=mt(mt(f[n],mt(power(f[i],mod-2,mod),power(f[n-i],mod-2,mod))),mt(m+i,power(i,mod-2,mod)));
        if (i&1) res+=tmp; else res-=tmp;
        res+=mod, res%=mod;
    }
    rep(i,n+1){
        res2=(res2+mt(mt(i+1,mt(C(n,i),power(C(n+m,i),mod-2,mod))),mt(m,power(n+m-i,mod-2,mod))))%mod;
    }
    cout<<mt(res,res2);
    return 0;

}


#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<iterator>
#include<map>
#define N 100000
#include<set>
using namespace std;
int main(){
	int l,r;
	cin>>l>>r;
	set<long long int> S;
	S.insert(1);
	set<long long int>::iterator it;
	for(it=S.begin();it!=S.end();it++){
		if(*it * 2<=r)
			S.insert(*it*2);
		if(*it * 3<=r)
			S.insert(*it*3);
		cout<<*it<<endl;
	}
	int sum=0;
	for(it=S.begin();it!=S.end();it++){
		if(*it>=l&&*it<=r)
			sum++;
	}
	cout<<sum;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>

using namespace std;

int nmem=0;
int *memdir[10000000];
int memval[10000000];

void asigna(int &a,int b)
{
  memdir[nmem]=&a;
  memval[nmem]=a;
  a=b;
  nmem++;
  if (nmem>=10000000) {
    cout<<"pifia"<<endl;
    exit(0);
  }
}

void recupera()
{
  while (nmem>0) {
    nmem--;
    *(memdir[nmem])=memval[nmem];
  }
}

const int limite=1000000;

void inserta(vector<int> &alcanza,int pos,int val,int primero)
{
  pos+=primero;
  asigna(alcanza[pos],val);
  while (pos>1) {
    pos/=2;
    asigna(alcanza[pos],max(alcanza[2*pos],alcanza[2*pos+1]));
  }
}

int alcanzaanterior(vector<int> &alcanza,int pos,int primero)
{
  pos+=primero;
  if (alcanza[pos]) return pos-primero;
  for (;;) {
    if (pos==1) return -1;
    if (pos%2==1 and alcanza[pos-1]) {
      pos--;
      while (pos<primero)
	if (alcanza[2*pos+1]) pos=2*pos+1;
	else pos=2*pos;
      return pos-primero;
    }
    pos/=2;
  }
  return -1;
}

int identificador[limite];

int computaidentificador(int u)
{
  int &idu=identificador[u];
  if (idu==0) return u;
  asigna(idu,computaidentificador(idu));
  return idu;
}

void fusiona(int u,int v)
{
  //cout<<"fusiona "<<u<<" "<<v<<endl;
  u=computaidentificador(u);
  v=computaidentificador(v);
  if (u==v) return;
  asigna(identificador[u],v);
}

pair<int,int> minimo[1<<21];

void inserta(int pos,int val,int u)
{
  pos+=1<<20;
  minimo[pos]=pair<int,int> (val,u);
  while (pos>1) {
    pos/=2;
    minimo[pos]=min(minimo[2*pos],minimo[2*pos+1]);
  }
}

int minimoentre(int pos0,int pos1)
{
  if (pos0>pos1) swap(pos0,pos1);
  pos0+=1<<20;
  pos1+=1<<20;
  if (pos0==pos1) return minimo[pos0].second;
  pair<int,int> mini0=minimo[pos0];
  pair<int,int> mini1=minimo[pos1];
  while (pos0+1<pos1) {
    if (pos0%2==0) mini0=min(mini0,minimo[pos0+1]);
    pos0/=2;
    if (pos1%2==1) mini1=min(mini1,minimo[pos1-1]);
    pos1/=2;
  }
  return min(mini0,mini1).second;
}

int n,m,casos;
vector<int> g[limite];
vector<pair<int,int> > gg[limite];
vector<int> alcanza[limite];
vector<int> elemento[limite];
int au[limite],av[limite],apendiente[limite];
int superidentificador[limite];
int superpadre[limite];
int superraiz[limite];
int superposicion[limite];
int primero[limite];
int tope[limite];
int visto[limite];
int numnodos[limite];
int profundidad[limite];

int s[limite];

int posle[limite];
int nrecorrido=0;

int ancestro(int u,int v)
{
  return minimoentre(posle[u],posle[v]);
}

void eliminapadre(int u,int p,int prof)
{
  visto[u]=1;
  profundidad[u]=prof;
  posle[u]=nrecorrido;
  inserta(nrecorrido++,profundidad[u],u);
  vector<int> &ar=g[u];
  vector<int> nextar;
  numnodos[u]=1;
  for (int i=0;i<int(ar.size());i++) {
    int v=ar[i];
    if (v!=p) {
      eliminapadre(v,u,prof+1);
      numnodos[u]+=numnodos[v];
      nextar.push_back(v);
      inserta(nrecorrido++,profundidad[u],u);
    }
  }
  ar=nextar;
}

void genera(int u,int sr,int sp)
{
  vector<int> lista;
  lista.push_back(u);
  for (;;) {
    vector<int> &ar=g[u];
    int nextu=0;
    for (int i=0;i<int(ar.size());i++) {
      int v=ar[i];
      if (2*numnodos[v]>=numnodos[u]) nextu=v;
      else genera(v,sr,u);
    }
    if (nextu==0) break;
    u=nextu;
    lista.push_back(u);
  }
  u=lista[0];
  {
    int nn=int(lista.size())+3;
    primero[u]=1;
    while (nn>0) {
      nn/=2;
      primero[u]*=2;
    }
    tope[u]=2*primero[u];
  }
  alcanza[u]=vector<int> (tope[u],0);
  elemento[u]=vector<int> (tope[u],0);
  for (int i=0;i<int(lista.size());i++) {
    int v=lista[i];
    superposicion[v]=i+1;
    superidentificador[v]=u;
    superpadre[v]=sp;
    superraiz[v]=sr;
    elemento[u][superposicion[v]]=v;
  }
}

void eliminaanteriores(int u)
{
  //cout<<"eliminaanteriores "<<u<<endl;
  int idu=superidentificador[u];
  vector<int> &alcanzaidu=alcanza[idu];
  int primeroidu=primero[idu];
  int posant=alcanzaanterior(alcanzaidu,superposicion[u],primeroidu);
  //cout<<"posant "<<posant<<" "<<alcanzaidu[primeroidu+posant]<<endl;
  if (posant==-1 or posant==0) return;
  inserta(alcanzaidu,posant,0,primeroidu);
  eliminaanteriores(u);
}

int cas=0;

void juntarancestro(int u,int w)
{
  //if (cas==11) cout<<"juntarancestro "<<u<<" "<<w<<endl;
  if (u==w) return;
  int idu=superidentificador[u];
  vector<int> &alcanzaidu=alcanza[idu];
  int primeroidu=primero[idu];
  if (superpadre[u]!=superpadre[w]) {
    if (alcanzaidu[primeroidu]<superposicion[u]) {
      int posant=alcanzaanterior(alcanzaidu,superposicion[u],primeroidu);
      if (posant==-1)
	inserta(alcanzaidu,0,superposicion[u],primeroidu);
      else {
	int nextpos=max(superposicion[u],alcanzaidu[primeroidu+posant]);
	eliminaanteriores(u);
	inserta(alcanzaidu,0,nextpos,primeroidu);
      }
    }
    juntarancestro(superpadre[u],w);
  } else {
    int posant=alcanzaanterior(alcanzaidu,superposicion[u],primeroidu);
    if (posant==-1) {
      inserta(alcanzaidu,superposicion[w],superposicion[u],primeroidu);
    } else if (posant<=superposicion[w]) {
      if (alcanzaidu[primeroidu+posant]<superposicion[w])
	inserta(alcanzaidu,superposicion[w],superposicion[u],primeroidu);
      else if (alcanzaidu[primeroidu+posant]<superposicion[u])
	inserta(alcanzaidu,posant,superposicion[u],primeroidu);
    } else if (alcanzaidu[primeroidu+posant]<=superposicion[u]) {
      inserta(alcanzaidu,posant,0,primeroidu);
      juntarancestro(u,w);
    } else {
      int nextpos=alcanzaidu[primeroidu+posant];
      inserta(alcanzaidu,posant,0,primeroidu);
      juntarancestro(elemento[idu][nextpos],w);
    }
  }
}

void juntar(int u,int v)
{
  //cout<<"juntar "<<u<<" "<<v<<endl;
  int w=ancestro(u,v);
  juntarancestro(u,w);
  juntarancestro(v,w);
}

int obtenerancestro(int u)
{
  int idu=superidentificador[u];
  vector<int> &alcanzaidu=alcanza[idu];
  int primeroidu=primero[idu];
  if (superposicion[u]<=alcanzaidu[primeroidu])
    return obtenerancestro(superpadre[u]);
  int posant=alcanzaanterior(alcanzaidu,superposicion[u],primeroidu);
  if (posant==-1 or alcanzaidu[primeroidu+posant]<superposicion[u])
    return u;
  return elemento[idu][posant];
}

int obteneridentificadorexterno(int u)
{
  int idu=obtenerancestro(u);
  //cout<<"obtenerancestro "<<u<<" "<<idu<<endl;
  idu=computaidentificador(idu);
  //cout<<"obteneridentificadorexterno "<<u<<" "<<idu<<endl;
  return idu;
}

void fusionaexterno(int u,int v)
{
  //cout<<"fusionaexterno "<<u<<" "<<v<<endl;
  u=obteneridentificadorexterno(u);
  v=obteneridentificadorexterno(v);
  fusiona(u,v);
}

int R=0;
int rotate(int element)
{
  element=(element+R)%n;
  if (element==0)
    element=n;
  return element;
}

int numids=0;
vector<pair<int,int> > paresidnodo[limite];
int veo[limite];
int numraices;
int raices[limite];

void eliminarepes()
{
  if (numraices==0) return;
  sort(raices,raices+numraices);
  int last=0;
  for (int i=1;i<numraices;i++)
    if (raices[i]!=raices[last])
      raices[++last]=raices[i];
  numraices=last+1;
}

void recogearistas(int u,int prof)
{
  //cout<<"recogearistas "<<u<<" "<<prof<<" "<<numids<<endl;
  vector<pair<int,int> > &ar=gg[u];
  for (int i=0;i<int(ar.size());i++) {
    int v=ar[i].first;
    int ida=ar[i].second;
    if (profundidad[u]+1==profundidad[v] and veo[v]<profundidad[u])
      recogearistas(v,prof);
    else if (profundidad[v]<profundidad[u] and prof<=profundidad[v]) {
      int uu=au[ida];
      int vv=av[ida];
      int ru=superraiz[uu];
      int rv=superraiz[vv];
      paresidnodo[ru].push_back(pair<int,int> (numids,uu));
      paresidnodo[rv].push_back(pair<int,int> (numids,vv));
      apendiente[ida]=1;
    }
  }
}

void calcula(int u,int p,int prof)
{
  //cout<<"calcula "<<u<<" "<<p<<" "<<prof<<endl;
  bool vistop=false;
  profundidad[u]=prof;
  veo[u]=prof;
  vector<pair<int,int> > &ar=gg[u];
  for (int i=0;i<int(ar.size());i++) {
    int v=ar[i].first;
    if (v==p and not vistop) {
      vistop=true;
    } else if (profundidad[v]) {
      veo[u]=min(veo[u],profundidad[v]);
    } else {
      calcula(v,u,prof+1);
      veo[u]=min(veo[u],veo[v]);
      if (profundidad[u]<veo[v]) {
	recogearistas(v,prof+1);
	numids++;
      } else if (profundidad[u]==veo[v]) {
	recogearistas(v,prof);
	numids++;
      }
    }
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin>>n>>m>>casos;
  for (int i=0;i<m;i++) {
    cin>>au[i]>>av[i];
    if (au[i]!=av[i]) {
      int idu=computaidentificador(au[i]);
      int idv=computaidentificador(av[i]);
      if (idu==idv) apendiente[i]=1;
      else {
	g[au[i]].push_back(av[i]);
	g[av[i]].push_back(au[i]);
	fusiona(au[i],av[i]);
      }
    }
  }
  for (int u=1;u<=n;u++) {
    if (not visto[u]) {
      //cout<<"tratando "<<u<<endl;
      eliminapadre(u,0,1);
      genera(u,u,0);
    }
  }
  /*
  for (int u=1;u<=n;u++)
    cout<<u<<" "<<superidentificador[u]<<" "<<superposicion[u]<<endl;
  */
  for (int i=0;i<m;i++)
    if (apendiente[i])
      juntar(au[i],av[i]);
  // Eliminamos la memoria que no nos interesa recuperar:
  nmem=0;
  // Reutilizaremos el calculo de identificadores.
  for (int i=0;i<limite;i++) {
    identificador[i]=0;
    apendiente[i]=0;
    profundidad[i]=0;
  }
  for (cas=1;cas<=casos;cas++) {
    //cout<<"caso "<<cas<<endl;
    int numnodos;
    cin>>numnodos>>m;
    numraices=0;
    for (int i=0;i<numnodos;i++) {
      cin>>s[i];
      //if (cas==11) cout<<"nodo "<<s[i]<<endl;
      s[i]=rotate(s[i]);
    }
    /*
    cout<<"numnodos: ";
    for (int i=0;i<numnodos;i++)
      cout<<s[i]<<",";
    cout<<endl;
    */
    for (int i=0;i<m;i++) {
      cin>>au[i]>>av[i];
      //if (cas==11) cout<<"arista "<<au[i]<<" "<<av[i]<<endl;
      au[i]=rotate(au[i]);
      av[i]=rotate(av[i]);
      if (au[i]!=av[i]) {
	if (superraiz[au[i]]==superraiz[av[i]]) {
	  //if (cas==11) cout<<"juntar "<<au[i]<<" "<<av[i]<<endl;
	  juntar(au[i],av[i]);
	  //if (cas==11) cout<<"volvemos juntar "<<au[i]<<" "<<av[i]<<endl;
	} else {
	  int ru=superraiz[au[i]];
	  int rv=superraiz[av[i]];
	  raices[numraices++]=ru;
	  raices[numraices++]=rv;
	  gg[ru].push_back(pair<int,int> (rv,i));
	  gg[rv].push_back(pair<int,int> (ru,i));
	}
      }
    }
    /*
    cout<<"aristas: ";
    for (int i=0;i<m;i++)
      cout<<"("<<au[i]<<","<<av[i]<<")";
    cout<<endl;
    */
    eliminarepes();
    /*
    cout<<"raices"<<endl;
    for (int i=0;i<int(raices.size());i++)
      cout<<raices[i]<<",";
    cout<<endl;
    */
    for (int i=0;i<numraices;i++) {
      int u=raices[i];
      if (not profundidad[u])
	calcula(u,0,1);
    }
    for (int i=0;i<numraices;i++) {
      int r=raices[i];
      vector<pair<int,int> > &lista=paresidnodo[r];
      sort(lista.begin(),lista.end());
      for (int j=0;j<int(lista.size());j++) {
	if (j==0 or lista[j].first!=lista[j-1].first) {
	  for (int k=j+1;k<int(lista.size()) and lista[k].first==lista[j].first;k++) {
	    int u=lista[j].second;
	    int v=lista[k].second;
	    juntar(u,v);
	  }
	}
      }
    }
    for (int i=0;i<m;i++) {
      if (apendiente[i]) {
	fusionaexterno(au[i],av[i]);
	apendiente[i]=0;
      }
    }
    int as0=obteneridentificadorexterno(s[0]);
    //cout<<"as0 "<<as0<<endl;
    bool error=false;
    for (int i=1;i<numnodos and not error;i++)
      error=as0!=obteneridentificadorexterno(s[i]);
    if (error) cout<<"NO"<<endl;
    else {
      cout<<"YES"<<endl;
      R+=cas;
    }
    for (int i=0;i<numraices;i++) {
      int r=raices[i];
      gg[r]=vector<pair<int,int> > ();
      paresidnodo[r]=vector<pair<int,int> > ();
      profundidad[r]=0;
    }
    numids=0;
    recupera();
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = (int) 1e6 + 7;
const ll M = (ll) 1e9 + 9;

int main() {
	ios_base::sync_with_stdio(0);
	ll n, m, k;
	cin >> n >> m >> k;
	ll wrong = n - m;
	ll each = n / k;
	if (wrong >= each) {
		cout << m;
	} else {
		ll cnt = wrong * each;
		assert(cnt <= n);
		ll ans = cnt - wrong;
		ll left = n - cnt;
		ll total = 0;
		ll good = left / k;
		while(good) {
			total += k;
			total *= 2ll;
			total %= M;
			--good;
		}
		ll t = left / k;
		total += left - t * k;
		total %= M;
		cout << (ans + total) % M;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<long long> tablelist;
  for(int i = 1; i <= n; i++) {
    for(int j = 1; j<=m; j++) {
      tablelist.push_back(i*j);
    }
  }
  sort(tablelist.begin(), tablelist.end());
  cout << tablelist[k-1];
}


#include <iostream>
#include <vector>

using namespace std;
vector<int> vec;

int main() {

    unsigned int n;
    cin >> n;
    int cnt = 0;
    if (n % 2 == 1)
        cout << cnt << endl;
    else {

        int a = n / 2;
        for (int i = 1; i <= a / 2; i++) {

            if (i != a - i)
                vec.push_back(i);
        }

        cout << vec.size() << endl;
    }

    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    long long int a,b,k;
    cin>>a>>b>>k;
    cout<<k*(2*(a+b-2))-(k-1)*(16);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define beshoo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
long long sum;
int main()
{
    int x,y,s;
    while(true)
    cin>>x>>y>>s;
    sum=abs(x)+abs(y);
    if(x==y&&x==0&&s%2==0){cout<<"YES";return 0;}
    if(sum==s){cout<<"YES";return 0;}
    if(s%sum==0){cout<<"YES";return 0;}
    cout<<"NO";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pair<int,int> >
#define bs binary_search
#define gcd __gcd
#define fs first
#define sc second
#define MOD 1000000007
int ABS(int a){return max(a,-a);}
ll ABS(ll a){return max(a,-a);}
double ABS(double a){return max(a,-a);}

const int N = 2005;
const int M = 1000000007;
int dp[N][N];

void add(int &x, int y) {
	x+=y;
	if(x>=M) x-=M;
}

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

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	for(int i=1;i<=N;i++)
		for(int j=1;j<=N;j++)
			dp[i][j]=0;

	for(int i=1;i<=N;i++)
		dp[1][i]=1;

	int n,k;
	cin>>n>>k;

	for(int len=1;len<=k-1;len++)
	{
		for(int end=1;end<=n;end++)
		{
			if(dp[len][end]!=0)
			{
				for(int j=end;j<=n;j+=end)
					add(dp[len+1][j],dp[len][end]);
			}
		}
	}

	int ans=0;
	for(int i=1;i<=n;i++)
		add(ans,dp[k][i]);

	cout<<ans%M;

}


#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin>>n;
int p=2*n-1;
while(n!=0){
    n=n--;
    p+=n*2-1;
}
cout<<p;
return 0;
}


/* .................................................................................................................................. */

/** Header **/

#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <list>
#include <set>
#include <map>

using namespace std;

/** Repeat **/

#define REP(I, N) for (int I=0;I<int(N);++I)
#define FOR(I, A, B) for (int I=int(A);I<int(B);++I)
#define DWN(I, B, A) for (int I=int(B-1);I>=int(A);--I)
#define REP_1(I, N) for (int I=1;I<=int(N);++I)
#define FOR_1(I, A, B) for (int I=int(A);I<=int(B);++I)
#define DWN_1(I, B, A) for (int I=int(B);I>=int(A);--I)
#define REP_C(I, N) for (int N____=int(N),I=0;I<N____;++I)
#define FOR_C(I, A, B) for (int B____=int(B),I=A;I<B____;++I)
#define DWN_C(I, B, A) for (int A____=int(A),I=B-1;I>=A____;--I)
#define REP_1_C(I, N) for (int N____=int(N),I=1;I<=N____;++I)
#define FOR_1_C(I, A, B) for (int B____=int(B),I=A;I<=B____;++I)
#define DWN_1_C(I, B, A) for (int A____=int(A),I=B;I>=A____;--I)
#define DO(N) while(N--)
#define DO_C(N) int N____ = N; while(N____--)
#define TO(i, a, b) int s_=a<b?1:-1,b_=b+s_;for(int i=a;i!=b_;i+=s_)
#define TO_1(i, a, b) int s_=a<b?1:-1,b_=b;for(int i=a;i!=b_;i+=s_)
#define SQZ(I, J, A, B) for (int I=int(A),J=int(B)-1;I<J;++I,--J)
#define SQZ_1(I, J, A, B) for (int I=int(A),J=int(B);I<=J;++I,--J)

/** Micro Mezzo Macro Flation -- Overheated Economy **/

#define ALL(A) A.begin(), A.end()
#define CPY(A, B) memcpy(A, B, sizeof(A))
#define INS(A, P, B) A.insert(A.begin() + P, B)
#define ERS(A, P) A.erase(A.begin() + P)
#define SRT(A) sort(ALL(A))
#define BSC(A, X) find(ALL(A), X) // != A.end()
#define SZ(A) int(A.size())
#define PB push_back
#define MP(A, B) make_pair(A, B)

#define Rush int T____; RD(T____); DO(T____)
#pragma comment(linker, "/STACK:36777216")
#define Ruby system("ruby main.rb")
#define Haskell system("runghc main.hs")
#define Pascal system("fpc main.pas")

/** Typedef **/

typedef long long LL;
typedef double DB;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<LL> VL;
typedef vector<DB> VD;
typedef set<int> SI;
typedef set<string> SS;
typedef set<LL> SL;
typedef set<DB> SD;
typedef map<int, int> MI;
typedef map<string, int> MS;
typedef map<LL, int> ML;
typedef map<DB, int> MD;
typedef pair<int, int> PII;
typedef pair<int, bool> PIB;
typedef vector<PII> VII;
typedef set<PII> SII;
typedef map<PII, int> MII;
typedef vector<VI> VVI;
typedef vector<VII> VVII;

/** I/O Accelerator **/

/* ... :" We are I/O Accelerator ... Use us at your own risk ;) ... " .. */

template<class T> inline void RD(T &x){
    //cin >> x;
    //scanf("%d", &x);
    char c; for (c = getchar(); c < '0'; c = getchar()); x = c - '0'; for (c = getchar(); c >= '0'; c = getchar()) x = x * 10 + c - '0';
    //char c; c = getchar(); x = c - '0'; for (c = getchar(); c >= '0'; c = getchar()) x = x * 10 + c - '0';

}

template<class T> inline void OT(const T &x){
    cout << x << endl;
    //printf("%d", x);
    //printf("%.2lf", x);
    //printf("Case %d: %d", ____T, ans)
}

template<class T> inline T& _RD(T &x){ RD(x); return x;}
inline int RD(){ int x; RD(x); return x;}
inline LL RD_LL(){ int x; RD(x); return x;}
inline DB RD_DB(){ DB x; RD(x); return x;}

template<class T0, class T1> inline void RD(T0 &x0, T1 &x1){RD(x0), RD(x1);}
template<class T0, class T1, class T2> inline void RD(T0 &x0, T1 &x1, T2 &x2){RD(x0), RD(x1), RD(x2);}
template<class T0, class T1, class T2, class T3> inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3){RD(x0), RD(x1), RD(x2), RD(x3);}
template<class T0, class T1, class T2, class T3, class T4> inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6);}

template<class T0, class T1> inline void OT(T0 &x0, T1 &x1){OT(x0), OT(x1);}
template<class T0, class T1, class T2> inline void OT(T0 &x0, T1 &x1, T2 &x2){OT(x0), OT(x1), OT(x2);}
template<class T0, class T1, class T2, class T3> inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3){OT(x0), OT(x1), OT(x2), OT(x3);}
template<class T0, class T1, class T2, class T3, class T4> inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);}

template<class T> inline void RST(T &A){memset(A, 0, sizeof(A));}
template<class T0, class T1> inline void RST(T0 &A0, T1 &A1){RST(A0), RST(A1);}
template<class T0, class T1, class T2> inline void RST(T0 &A0, T1 &A1, T2 &A2){RST(A0), RST(A1), RST(A2);}
template<class T0, class T1, class T2, class T3> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3){RST(A0), RST(A1), RST(A2), RST(A3);}
template<class T0, class T1, class T2, class T3, class T4> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);}

template<class T> inline void CLR(T &A){A.clear();}
template<class T0, class T1> inline void CLR(T0 &A0, T1 &A1){CLR(A0), CLR(A1);}
template<class T0, class T1, class T2> inline void CLR(T0 &A0, T1 &A1, T2 &A2){CLR(A0), CLR(A1), CLR(A2);}
template<class T0, class T1, class T2, class T3> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3){CLR(A0), CLR(A1), CLR(A2), CLR(A3);}
template<class T0, class T1, class T2, class T3, class T4> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);}
template<class T> inline void CLR(T &A, int n){REP(i, n) CLR(A[i]);}
//template<class T> inline void CLR_(T &A){REP}

template<class T> inline void FLC(T &A, int x){memset(A, x, sizeof(A));}
template<class T0, class T1> inline void FLC(T0 &A0, T1 &A1, int x){FLC(A0, x), FLC(A1, x);}
template<class T0, class T1, class T2> inline void FLC(T0 &A0, T1 &A1, T2 &A2){FLC(A0), FLC(A1), FLC(A2);}
template<class T0, class T1, class T2, class T3> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3){FLC(A0), FLC(A1), FLC(A2), FLC(A3);}
template<class T0, class T1, class T2, class T3, class T4> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5), FLC(A6);}

/** Add - On **/

template<class T> inline void checkMin(T &a, T b){if (b<a) a=b;}
template<class T> inline void checkMax(T &a, T b){if (b>a) a=b;}
template<class T> inline T sqr(T x){return x * x;}
template<class T> inline T min(T a, T b, T c){return min(min(a, b), c);}
template<class T> inline T max(T a, T b, T c){return max(max(a, b), c);}

/* .................................................................................................................................. */

const int MOD = 1000000007;
const int INF = 0x7fffffff;
const DB EPS = 1e-6;
const DB OO = 1e15;

const int N = 20000 + 5;

bool A[3], B[3], _B[3], B_[3];
int x[3], m[3], l[3], u[3];
int res;

void dfs(){

    int _i, i_;

/*
    if (x[0] == 10 && x[1] == 9){
        cout << _B[0] << " " << _B[1] << endl;
    }*/

    REP(i, 3) if (!_B[i]){

        if (i == 0) _i = 1, i_ = 2; else if (i == 1) _i = 0, i_ = 2; else _i = 0, i_ = 1;

        if (B[i] && !B_[i]){ // ����

            if (u[i] == i_) swap(_i, i_);

            B_[i] = true, _B[_i] = false;

            if (B[_i] && !B_[_i]){

                checkMax(res, x[i] + l[i] + l[_i] +  (A[i_] ? 0 : m[i_]));

            }

            else {

                int x_i = x[_i];

                FOR_1(j, -l[i], l[i]) if (j != 0){

                    int xx = x[i] + j;

                    if (x[i_] != xx && (abs(x[i_] - xx) == 1 || j == 1 || j == l[i])) {

                        checkMax(res, xx);

                        x[_i] = xx,

                        dfs();

                        x[_i] = x_i;

                    }

                }
            }

            _B[_i] = true, B_[i] = false;

        }
        else { // ���� ...

            if (!B[i]){

#define Grab(i_, d) if (!_B[i_] && x[i_] == x[i] + d) {x[i_] = x[i], B[i] = _B[i_] = true, u[i] = i_, dfs(), x[i_] = x[i] + d; B[i] = _B[i_] = false;}

                Grab(_i, -1); Grab(_i, 1); Grab(i_, -1); Grab(i_, 1);
            }

            if (!A[i]){ // ��· ..
                A[i] = true; int xi = x[i];
                FOR_1(j, -m[i], m[i]) if (j != 0){
                    int xx = xi + j;
                    if (x[_i] != xx && x[i_] != xx)
                        //(abs(x[_i] - xx) == 1 || abs(x[i_] - xx) == 1 || j == m[i] || j == -m[i])){
                        checkMax(res, xx); x[i] = xx, dfs(), x[i] = xi;
                    }
                }
                A[i] = false;
            }
        }
    }
}

int main(){

   // freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //ios::sync_with_stdio(false);

    REP(i, 3) RD(x[i], m[i], l[i]); res = max(x[0], x[1], x[2]);

    //x[0] = 10, x[1] = 9; x[2] = -18;
    //x[0] = 8, x[1] = 9, x[2] = -18;A[0] = true;

    dfs(); OT(res);
}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int main () {
	long long n,x,i=1;
	int counter=0;
	cin>>n;
	vector<long long>vec;
	while (i<=n) {
		vec.push_back(i);
		i++;
	}
	for (int i=0; i<vec.size(); i++) {
		if ( vec[i]%6==0 && vec[i]%7==0 &&
			vec[i]%8==0 && vec[i]%9==0 && vec[i]%10==0)
			counter++;
	}
	cout<<counter<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+100;
typedef long long ll;
const ll mod=998244353;
ll fact[maxn],inv[maxn];

ll qpow(ll a, ll b)
{
    ll ans=1;
    while(b)
    {
        if(b&1) ans = ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
ll n;
int main()
{
    scanf("%I64d",&n);
    fact[0]=1;
    for(int i=1;i<=n;++i) fact[i]=i*fact[i-1]%mod;
    inv[n]=qpow(fact[n],mod-2);
    for(int i=n-1;i>=1;--i) inv[i]=inv[i+1]*(i+1)%mod;

    ll ans=( qpow(3,n*n)-qpow( (qpow(3,n)-3+mod)%mod , n) + mod )%mod;

    ll xishu=-1;
    for(int i=1;i<=n;++i)
    {
        ll tmp=fact[i]*(3*qpow(  (qpow(3,n-1)-1+mod)%mod),n )%mod + (qpow(3,i)-3+mod)%mod*qpow(3,(n-i)*n)%mod;
        ans= (ans+ tmp*xishu%mod +mod) %mod;
    }
    printf("%I64d\n",ans);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 100010;
struct node{
    int y,z;
};
int f(int x) {
    if(x<0) return -x; else return x;
}
int a[maxn],vis[maxn];
vector<node>g[maxn];
int ans;

void dfs(int x,int d) {
    int z = g[x].size();
    for(int i=0; i<z; i++) {
       node s = g[x][i];
       if(!vis[s.y] && s.z+d <= a[s.y]) {
            vis[s.y] = 1;
            ans++;
            dfs(s.y,max(d+s.z,0));
       }
    }
}
int main(){
    ans=0;
    int n; scanf("%d",&n);
    for(int i=1;i<=n; i++) {
        scanf("%d",&a[i]);
    }
    for(int i=1;i<n; i++) {
        int y,z; scanf("%d%d",&y,&z);
        node tmp;
        tmp.y=y; tmp.z=z;
        g[i+1].push_back(tmp);
        tmp.y=i+1;
        g[y].push_back(tmp);
    }
    vis[1]=1;
    ans++;
    dfs(1,0);
    cout<<n-ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<pair<long long,long long>>v;
map<long long,long long>mp;
pair<long long,long long>p[10000];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long n,m,i,j,k,x=0,y=10000000000,z,d,a,b;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            if(i*j>=n)
            {
                x=2*(i+j);
                y=min(y,x);

            }
        }
    }
    cout<<y<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int c,v,v1,a,l,d=1,e,f;
    cin>>c>>v>>v1>>a>>l;
    e=v;
    f=v;
    while(e<c)
    {
        f=min(v1,f+a);
        e+=f-1;
        d++;
    }
    cout<<d;
}


#include <bits/stdc++.h>

using namespace std;

string mabna(int n,int k){
	int x=n;
	string ans="";
	while (x){
		ans+=char(x%n+'0');
		x/=n;
	}
	reverse(ans.begin(),ans.end());
	return ans;
}

int main(){
	int n;
	cin >> n;
	for (int i=1;i<n;++i){
		for (int j=1;j<n;++j)
			cout << mabna(i*j,n) << " ";
		cout << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
int n, q;
char  ma[40][2][4];
char a[10];
int ans;
char s[50000][8];
int cnt;

bool cmp(char x[], char y[]){
	int tmp = strcmp(x, y);
	if (tmp >= 0)return 1;
	return 0;
}

void dfs(int x, char t[]){
	if (x == n){
		int i, j;
		j = strlen(t);
		for (i = 0; i <= j; i++)
			s[cnt][i] = t[i];
		cnt++;

		return;
	}
	int l = strlen(t);
	int i, j, u;
	for (i = 0; i<l; i++){
		for (j = 1; j <= q; j++){
			if (ma[j][1][0] == t[i]){
				char b[10];
				for (u = 0; u<i; u++)
					b[u] = a[u];
				b[u + 1] = ma[j][0][0];
				b[u + 2] = ma[j][0][1];
				for (u = i + 1; u<l; u++)
					b[u + 1] = a[u];
				b[l + 1] = '\0';
				dfs(x + 1, b);
			}
		}
	}
}

int main()
{
	int i, j;
	while (~scanf("%d%d", &n, &q)){
		for (i = 1; i <= q; i++)
			scanf("%s%s", ma[i][0], ma[i][1]);
		ans = cnt = 0;
		a[0] = 'a'; a[1] = '\0';
		dfs(1, a);
		sort(s, s + cnt, cmp);
		int ans = cnt;
		for (i = 0; i<cnt - 1; i++){
			if (strcmp(s[i], s[i + 1]) == 0)
				ans--;
		}
		printf("%d\n", ans);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ld EPS = 1e-10;
const ll MOD = 1e9 + 7;
const ll OO = 1e18 + 9;

const int N = 1e6 + 1;

ll a[14];

int main() {
	//freopen("input.in", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	for(int i=0;i<14;++i) cin >> a[i];
	ll ans = 0;
	for(int i=0;i<14;++i) {
		ll tmp = 0,md = a[i]%14,dv = a[i]/14;
		int j = i+1;
		while(md) {
			ll x = dv + a[j] + 1;
			if(x%2==0) tmp += x;
			j = (j+1)%14;
			md--;
		}
		while(j <= i) {
			if((a[j] + dv)%2 == 0) tmp += (a[j] + dv);
			j++;
		}
		ans = max(ans,tmp);
	}
	cout << ans;

}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ld EPS = 1e-10;
const ll MOD = 1e9 + 7;
const ll OO = 1e18 + 9;

const int N = 1e6 + 1;

ll a[14];

int main() {
	//freopen("input.in", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	for(int i=0;i<14;++i) cin >> a[i];
	ll ans = 0;
	for(int i=0;i<14;++i) {
		ll tmp = 0,md = a[i]%14,dv = a[i]/14;
		int j = i+1;
		while(md) {
			ll x = dv + a[j] + 1;
			if(x%2==0) tmp += x;
			j = (j+1)%14;
			md--;
		}
		while(j <= i) {
			if((a[j] + dv)%2 == 0) tmp += (a[j] + dv);
			j++;
		}
		ans = max(ans,tmp);
	}
	cout << ans;

}


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

#define t(t) int t; cin>>t; while(t--)

int main()
{

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

	int n;

	cin >> n;
	string s;

	cin >> s;

	vector<string> a;

	int i = 0,  max = INT_MIN;
	string z;

	while (s[i + 1] != '\0')
	{
		string q = s.substr(i, 2);

		if (a.size() == 0)
		{
			a.push_back(q);
			max = a[0].size();
			z = a[0];
		}

		else

		{
			for (int j = 0; j < a.size(); j++)
			{
				if (q == a[j])
				{
					a[j] += q;
					if (max < a[j].size())
					{
						max = a[j].size();
						z = a[j].substr(0, 2);
					}
				}
				else
				{
					a.push_back(q);
					if (max < a.back().size())
					{
						max = a[j].size();
						z = a[j].substr(0, 2);
					}
				}
			}
			i++;
		}

	}

	cout << z << endl;

	return 0;

}


#include<iostream>
using namespace std;
int main(){
	int n,a[10001],s,d=1,i=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	while(i<n){
		if(a[i]==1){
			if(i==n-1){
				cout<<d;
				return 0;
			}
			s=0;
			i++;
			while(a[i]==0){
				s++;
				i++;
			}
			if(i==n)d=d;
			else d=d*(s+1);
		}
	}
	cout<<d;
}


///IUK_TEAM_RAPTURE///
///AL-HELAL//////////
///ISLAMIC UNIVERSITY
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define fr(i,n) for(__typeof(n) i=0; i<(n); i++)
#define fre(i,n) for(__typeof(n) i=1; i<=(n); i++)
#define frt(i,a,b) for(__typeof(b) i=(a); i<=(b); i++)
#define inf 1061109567000LL
#define PI 3.14159265358979323846264338327950
#define PB(x) push_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ size()
#define eps 1e-9
#define VI vector<int>
#define VS vector<string>
#define LL long long
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define CLEAR(x) memset(x,0,sizeof(x));
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define mem(x,y) memset(x,y,sizeof(x));
using namespace std;
bool is_palindrome(const string &s, int start, int end) {
 int sz = end - start + 1;
if (sz % 2 == 0) {
  int middle = start + sz/2;
    int i;
  for (i = 0; middle - 1 - i >= 0 && middle+i <= end && s[middle-1-i] == s[middle+i]; i++);
   if (middle - i - 1 < 0 || middle+i > end)
    return true;
 } else {
   int middle = start + sz/2;
int i;
 for (i = 1; middle - i >= 0 && middle+i <= end && s[middle-i]==s[middle+i]; i++);
   if (middle - i < 0 || middle+i > end)
return true;
 }
return false;
}
//Polya-Burnside theory : (n^6+3n^4+12n^3+8n^2)/24;
int euclidd,euclidx,euclidy;
void extendedeuclid(int a,int b)
{
    if(b==0)
    {
        euclidd=a;
        euclidx=1;
        euclidy=0;
        return ;
    }
    extendedeuclid(b,a%b);
    int d1,x1,y1;
    d1=euclidd;
    x1=euclidx;
    y1=euclidy;
    euclidx=y1;
    euclidy=x1-((a/b)*y1);
}
double area_triangle(double x1,double y1,double x2,double y2,double x3,double y3)
{
    double a;
    a=x1*(y2-y3)+y1*(x3-x2)+((x2*y3)-(y2*x3))+eps;
    a=a/2+eps;
return a;
}
double dist_2point(double x1,double y1,double x2,double y2)
{
    double d;
    d=sqrt(pow((x1-x2),2)+pow((y1-y2),2));
    return d;
}
int binary_search(int a[],int n,int l,int u)
{
    int mid;
  if(l>u)
      return 0;
  mid=floor(l+u)/2;
  if(a[mid]==n)
      return mid;
  else if(a[mid]>n)
      binary_search(a,n,l,mid-1);
      else
      binary_search(a,n,mid+1,u);
}
long gcd(long a,long b)
{
while(b>0)
{
a=a%b;
a=a^b;
b=b^a;
a=a^b;
}
return a;
}
long lcm(long a,long b)
{
    long x=(a*b)/gcd(a,b);
    return x;
}
long is_prime(long n)
{
    long ii;
if (n == 1)
 return 0;
if (n == 2)
 return 1;
if (n%2 == 0)
 return 0;
for (ii=3;ii*ii<=n;ii=ii+2)
     if (n%ii == 0)
           return 0;
return 1;
}
long long bigmod(long long b,long long p,long long m)
{
    if(b==0) return 0;
    long long x,power;
    x=1;
    power=b%m;
    while(p)
    {
       if(p%2==1)
            x=(x*power)%m;
        power=(power*power)%m;
        p=p/2;
    }
    return x;
}
typedef pair<double,double> pr;
double a,b,c;
void abc(pr m, pr n)
{
    a=m.second-n.second;
    b=-(m.first-n.first);
    c=(-b)*m.second-a*m.first;
}
int intersec(pr p1,pr p2,pr p3, pr p4)
{
    double x,y,a1,a2,b1,b2,c1,c2;
    abc(p1,p2);
    a1=a;b1=b;c1=c;
    abc(p3,p4);
    a2=a;b2=b;c2=c;
    if(a1*b2==a2*b1) return 0;
    x=(b1*c2-b2*c1)/(a1*b2-b1*a2);
    y=((c1*a2)-(a1*c2))/(a1*b2-b1*a2);
    if((x>=p1.first&&x<=p2.first)||(x<=p1.first&&x>=p2.first))
    if((x>=p3.first&&x<=p4.first)||(x<=p3.first&&x>=p4.first))
    if((y>=p3.second&&y<=p4.second)||(y<=p3.second&&y>=p4.second))
    if((y>=p1.second&&y<=p2.second)||(y<=p1.second&&y>=p2.second))
    return 1;
    return 0;
}
int main()
{
    while(1)
    {
ios_base::sync_with_stdio(false);
//freopen("input.txt","r",stdin);
//long i,n;
 int a[10]={0},i,j,k;
 int m=0;
 int n=0;
 int p=0;
for(i=0;i<4;i++)
cin>>a[i];

for(i=0;i<4;i++)

    for(j=i+1;j<4;j++)

        for(k=j+1;k<4;k++)
        {

            if(a[i]<a[j]+a[k] && a[j]<a[i]+a[k] && a[k]<a[i]+a[j])
            m=1;
             if(a[i]<=a[j]+a[k] && a[j]<=a[i]+a[k] && a[k]<=a[i]+a[j])
            n=1;
              if(a[i]==a[j]+a[k] || a[j]==a[i]+a[k] || a[k]==a[i]+a[j])
             p=1;
        }
        if(m)
    cout<<"TRIANGLE"<<endl;
       else  if( p && n)
    cout<<"SEGMENT"<<endl;
    else
    cout<<"IMPOSSIBLE"<<endl;
}
return 0;
}


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

ll n,s,i,j,s1=0,sum;
int main(){
	cin>>n;
	vector <ll> a(n);
	while(n>0){
		s=n%10;
		a[j]=s;
		j++;
		n=n/10;
	}
	for(i=j-1;i>=0;i--){
			if(a[i]==0){
				s1=2*s1;
			}
			else{
				if(a[i]==1){
						s1=(2*s1+1);
				}

			}
		}
		if(s1==20){
			cout<<"3"<<endl;
			return 0;
		}
		for(i=0;;i++){
			sum+=pow(4,i);
			if(sum>s1){
				cout<<i<<endl;
				break;
			}
		}
	return 0;
}


#include<iostream>
using namespace std;
int sum_digits(int a)
{
    int sum=0;
    while(a!=0)
    {
        sum+=a%10;
        a/=10;
    }
    return sum;
}
int main()
{
    int a,temp,sum=0
    cin>>a;
    sum=sum_digits(a);
    if(!sum%4)
        cout<<a;
    else
    {
        temp=a%10;
        if(temp+4-sum%4<10)
            cout<<a+4-sum%4;
        else
        {
            a+=(10-temp);
            temp=a;sum=sum_digits(a);
            if(sum%4==0)
                cout<<a;
            else
                cout<<a+4-sum%4;
        }
    }
}


#include <iostream>

using namespace std;
int maxvote(int n,int a[])
{
int pos=0;
for(int i=0;i<n;i++)
{
 if(a[i]>=a[pos])
  pos=i;
}
return pos;
}
void minbribe(int n,int a[],int &bribe)
{
int m=maxvote(n,a);
if(m==0)
return;
a[m]--;
a[0]++;
bribe++;
minbribe(n,a,bribe);
}
int main()
{
int n,a[50];
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
int bribe=0;
minbribe(n,a,bribe);
cout<<bribe<<endl;
}


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

#define ll long long
#define pb push_back
#define FastIO cin.sync_with_stdio(false),cin.tie(NULL)
#define val first

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

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

const int MOD = 998244353, N = 2e5 + 5 , INF = INT_MAX;
ll a[N];
int x, y;

bool ch(int n){
	for(int i = n+1; i <= n+y; i++)if(a[i] <= a[n])return false;
	for(int i = n-1; i >= 0 && i >= n-x; i--)if(a[i] <= a[n])return false;
	return true;
}

int main(){
	FastIO;
	int t = 1;

	//cin >> t;

	while(t--){
		int k;
		cin >> k;
		string s;
		ll tp = 1;
		while(s.size() <= k){
			s += to_string(tp);
			tp++;
		}
		cout << s[k] << "\n";
	}

    return 0;
}

/*
for(int i = 2;  i< N; i++){
		if(!b[i]){
			prm.pb(i);
			for(int j = 2; j *i < N; j++)b[i*j] = true;
		}
	}
    */

/*void dfs(int u, int par){
	ch[u] = true;
	h[u] = h[par]+1;
	he[ h[u] ].pb(u);
	for(int i = 0; i < v[u].size(); i++){
		if(!ch[ v[u][i] ]){
			dfs(v[u][i], u);
		}
	}
}*/


#include <bits/stdc++.h>
#define bit skwkdfkw
using namespace std;
long long bit[70],f[70][130][2],ans=0;
int end=0;
long long dp(long long sum,int tot,int l1,int l2){
	int lg=log2(sum);
	memset(f,0,sizeof(f));
	f[0][0][0]=1;
	for(int i=1;i<=lg;i++){
		long long d=(sum>>i)&1;
		int ed=i*2-2;
		for(int j=0;j<=ed;j++) for(int k=0;k<=1;k++) for(int p1=0;p1<=1;p1++) for(int p2=0;p2<=1;p2++){
			if((i<l1||p1==0)&&(i<l2||p2==0)&&(((p1+p2+k)&1)==d)){
				f[i][j+p1+p2][(k+p1+p2)/2]+=f[i-1][j][k];
			}
		}
	}
	return f[lg][tot][0];
}
int main(){
	long long n,s,res;
	scanf("%lld",&n);
	bit[0]=1;
	while(bit[end]<=n) end++,bit[end]=bit[end-1]<<1;
	for(int i=1;i<=end;i++){
		if(bit[i]-1>n) break;
		s=n%(bit[i]-1);
		for(int j=i;j>=1;j--) if(s>=bit[j]-1) s-=bit[j]-1;
		if(!s) ans++;
	}
	for(int l1=1;l1<end;l1++){
		for(int l2=1;bit[l2]-1<=n&&l2<end;l2++){
			s=(n-bit[l2]+1)/(bit[l1+1]+bit[l2+1]-3);
			if(s){
				res=(n-bit[l2]+1)%(bit[l1+1]+bit[l2+1]-3);
				if(!res){
					ans++;
					continue;
				}
				if(l1==1&&l2==1){
					ans+=(n==s*5+1);
					continue;
				}
				for(int i=1,k_end=l1+l2;i<=k_end;i++) if(!((res+i)&1)) ans+=dp(res+i,i,l1,l2);
			}
		}
	}
	printf("%lld\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,dp[55][105][2];
int calc(int cnt,int l,int r,int res)
{
    memset(dp,0,sizeof(dp));
    dp[0][0][0]=1;
    int maxn=0;
    for (int i=1;(1ll<<i)<=res;i++)
    {
        maxn=i;
        for (int j=0;j<=min(cnt,2*i);j++)
        {
            for (int p1=0;p1<=(i<l);p1++)
            {
                for (int p2=0;p2<=(i<r);p2++)
                {
                    if (j+p1+p2>cnt) continue;
                    int k=(res>>i)&1;
                    k^=p1;
                    k^=p2;
                    dp[i][j+p1+p2][(k+p1+p2)/2]+=dp[i-1][j][k];
                }
            }
        }
    }
    return dp[maxn][cnt][0];
}
signed main()
{
    cin>>n;
    int ans=0;
    for (int i=0;(1ll<<i)<=n;i++)
    {
        for (int j=0;(1ll<<j)<=n;j++)
        {
            int tmp1=(1ll<<i)-1,tmp2=(1ll<<j)-1;
            int tmp=2*tmp1+2*tmp2+1;
            int tot=n-(1ll<<j)+1;
            int x=tot/tmp;
            if (x<=0) continue;
            int res=tot-tmp*x;
            if (res<0) continue;
            if (!res)
            {
                ans++;
                continue;
            }
            int anss=ans;
            for (int k=0;k<=i+j-(!l)-(!r);k++)
                if ((res+k)%2==0) ans+=calc(k,i,j,res+k);
        }
    }
    cout<<ans;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>

	using namespace std;
	int main()
	{

		int n;
		cin >> n;
		int cnt=1;
		int gcnt=1;
		bool h = 1;
		for (int i = 0; i < n; i++)
		{ bool x = 0;
		if (h)
		{
			while (true) {
				cin >> x;
				i++;
				if (x)
				{
					h = false;
					break;
				}
			}
		}
			cin >> x;

			if (x)
			{
				gcnt *= cnt;
				cnt = 1;
			}
			else
				cnt++;

		}
		cout << gcnt;

	}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long ll;
#define endl "\n"
#define debug cout<<" here "
#define For(i,n) for(int i=0;i<n;i++)
#define pb(i) push_back(i)
#define mp(i,j) make_pair(i,j)
ll m=1e9+7;

ll powerfn(ll n){

  if(n==1){return 2;}

  ll t=powerfn(n/2);

  if(n%2!=0){
    return (((t*t)%m)*2)%m;
  }
  else{
    return (t*t)%m;
     }
}

void solve(){

ll n;cin>>n;
ll f=1;
For(i,n){
f*=i+1;f%=m;
 }
ll p=powerfn(n-1);
cout<<f-p<<endl;
}

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

     }
}


// BEGIN CUT HERE
// END CUT HERE
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
using namespace std;

int main(  )
{

    string s;
    cin>>s;
    char prev;
    int c;
    c=1;

    if(s.size()==1)
                   return 1;
    prev=s[0];
    for(int i =1; i<s.size();i++)
    {
            int count =1;
            if(prev != s[i])
                    { c++; prev =s[i];}
            else
            {while(count<=5 && i<s.size())
            {
             if(prev == s[i])
                          {i++;count++;continue;}
             else
                          {prev=s[i];c++;i++;break;}
            }
            if(count>5)
                       c++;i--;}
    }
     cout<<c<<endl;
     return 0;

}


#include <cstdio>
#include <cstdlib>
using namespace std;
int n, a, b, c, p = 1000000009;
int main()
{
	a = 1, b = 2, c = 4;
	scanf("%d", &n);
	while (n -= 2)
	{
		c = (long long)c * a % p;
		b += c, if (b >= p) b -= p;
		a = (a << 1) + 3, if (a >= p) a -= p;
	}
	b = (long long)(b * b + 1) * 2 % p;
	printf("%d\n", b);
	return 0;
}


// gskhirtladze

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

using namespace std;

main()
{
      cin>>n;
      if ((n & (n-1)) == 0) cout<<"YES"<<endl; else
       cout<<"NO"<<endl;
}