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


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

long long ans[50000000];

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


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

void solve();

template <typename T>

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

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

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

    solve();

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

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

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

    }
    cout<<m<<endl;
}


#include<iostream>

using namespace std;

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

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


/*#include<cstdio>
#include<cstring>
#define maxn 200
#define minn 0x3f3f3f3f
using namespace std;
int vis[maxn],d[maxn],map[maxn][maxn];
void start(int m)
{
  for(int i=0;i<m;i++)
  {
  vis[i]=0;
  d[i]=minn;
  }
}
int prime(int m)
{
  int sum=0;
  for(int i=0;i<m;i++)
  d[i]=map[0][i];
  vis[0]=1;
  d[0]=0;
  int v,temp;
  for(int i=1;i<m;i++)
  {
  	 temp=minn;
    for(int j=0;j<m;j++)
    {
	   if(temp>d[j]&&!vis[j])
	   {
	     v=j;
	     temp=d[j];
	   }
	}
	sum+=temp;
	vis[v]=1;
	for(int j=0;j<m;j++)
	{
	  if(!vis[j]&&d[j]>map[v][j])
	  d[j]=map[v][j];
	}
  }
  return sum;
}
int main()
{
	int m,n;
	while(~scanf("%d",&m))
	{
	for(int i=0;i<m;i++)
	{
	  for(int j=0;j<m;j++)
	  {
	  scanf("%d",&map[i][j]);
	  }
	}
	start(m);
	int s=prime(m);
	printf("%d\n",s);
	}
return 0;
}*/
/*#include<cstdio>
#include<cstring>
#include<vector>
#define maxn 1005
using namespace std;
int main()
{
	int m,n;
	int f[maxn];
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	 scanf("%d",&f[i]);
	 int end=0,start=0,l=0,max=f[0],sum=0;
	 for(int i=0;i<n;i++)
	 {
	   sum=sum+f[i];
	   if(max<sum)
	   {max=sum;
	   end=i;
	   start=l;
	   }
	   else if(sum<0)
	   {
	     sum=0;
	     l=i+1;
	   }
	 }
	 printf("%d %d %d\n",max,f[start],f[end]);

return 0;
}*/
/*hash:
#include<cstdio>
#include<cmath>
#include<cstring>
#define maxn 200005
#define minn 10000007
using namespace std;
unsigned long long int next[maxn];
void hash(char *str,int n)
{
	unsigned long long int sum=0;
	int b=31,i;
	unsigned long long int num=pow(double(b),double(n));
  for(i=0;i<n;i++)
  {
    sum=sum*b+str[i];
  }
  next[i-1]=sum%minn;
  int s=0;
  while(str[i])
  {
  next[i]=next[i-1]*b-str[s]*num+str[i];
  s++;
  i++;
  }
}

int main()
{
	char str[maxn],th[maxn];
	while(~scanf("%s",str))
	{
		scanf("%s",th);
	  int l=strlen(th);
	  hash(str,l);
	  unsigned long long int shu=0;
	  for(int i=0;i<l;i++)
	  {
	    shu=shu*31+th[i];
	  }
	  int i=l-1;
	  int flag=0;
	  while(str[i])
	  {
	    if(next[i]==shu)
	     flag++;
	    i++;
	  }
	  printf("%d\n",flag);
	}
return 0;
}*/

/*#include<cstdio>
#include<cstring>
#define maxn 200010
int num[maxn];
using namespace std;
struct node
{
  int l;
  int r;
  int v;
}tree[4*maxn+5];
int max(int x,int y)
{
if(x>y)
return x;
else
return y;
}
void build(int next,int x,int y)
{
int node_left=(next<<1)+1;
int node_right=(next<<1)+2;
int mid=(x+y)/2;
tree[next].l=x;
tree[next].r=y;
if(x==y)
tree[next].v=num[x-1];
else
{
  build(node_left,x,mid);
  build(node_right,mid+1,y);
  tree[next].v=max(tree[node_left].v,tree[node_right].v);
}
}

int find(int next,int x,int y)
{
  int node_left=(next<<1)+1;
  int node_right=(next<<1)+2;
  int s,t;
  if(tree[next].l>y||tree[next].r<x)
  return 0;
  else if(tree[next].l>=x&&tree[next].r<=y)
  return tree[next].v;
  else
  {
 s= find(node_left,x,y);
 t= find(node_right,x,y);
 return max(s,t);
  }
}
void insert(int next,int s,int x)
{
  if(tree[next].l==tree[next].r)
  {
    if(tree[next].l==s)
    {
    tree[next].v=x;
   }
    else
    return ;
  }
  else if((s>=tree[next].l&&s<tree[next].r)||(s>tree[next].l&&s<=tree[next].r))
  {
    int node_left=(next<<1)+1;
    int node_right=(next<<1)+2;
    insert(node_left,s,x);
    insert(node_right,s,x);
    tree[next].v=max(tree[node_left].v,tree[node_right].v);
  }
}

int main()
{
	int t,x,y,n,m,i,j,s=1;
	char name;
	while(~scanf("%d%d",&n,&m))
	{
	for(i=0;i<n;i++)
	scanf("%d",&num[i]);
	getchar();
	build(0,1,n);
	while(m--)
	{
	scanf("%c%d%d",&name,&x,&y);
	getchar();
    if(name=='U')
    {
	insert(0,x,y);
	}
	else if(name=='Q')
	{
	  printf("%d\n",find(0,x,y));
	}
	}
  }
return 0;
}*/
/*#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int maxn = 300;
int vis[maxn][maxn];
struct node
{
int x;
int y;
int step;
}s;
int Move[4][2]={0,1,0,-1,1,0,-1,0};
int m,n;
char map[maxn][maxn];
int bfs(int x,int y,int a,int b)
{
	queue<node > que;
  struct node th;
  s.step=0;
  s.x=x;
  s.y=y;
  que.push(s);
  vis[s.x][s.y]=1;
  while(!que.empty())
  {
    th=que.front();
    que.pop();
    if(th.x==a&&th.y==b)
    {
	return th.step;
	}
	for(int i=0;i<4;i++)
	{
	  s.x=th.x+Move[i][0];
	  s.y=th.y+Move[i][1];
	  s.step=th.step+1;
	  if(s.x==a&&s.y==b)
	  {
	  return s.step;
	  }
	  if(s.x>=0&&s.x<m&&s.y>=0&&s.y<n&&map[s.x][s.y]!='#'&&map[s.x][s.y]!='Y'&&map[s.x][s.y]!='M'&&vis[s.x][s.y]==0)
	  {
	    vis[s.x][s.y]=1;
	    que.push(s);
	  }
	}
  }
  return -1;
}
int main()
{
	int x1,x2,y1,y2;
	struct node ma[900];
	while(~scanf("%d%d",&m,&n))
	{
		int u=0;
	  for(int i=0;i<m;i++)
	  {
	    getchar();
	    for(int j=0;j<n;j++)
	    {
		scanf("%c",&map[i][j]);
		if(map[i][j]=='Y')
		{
		  x1=i;
		  y1=j;
		}
		else if(map[i][j]=='M')
		{
		x2=i;
		y2=j;
		}
		else if(map[i][j]=='@')
		{
		ma[u].x=i;
		ma[u].y=j;
		u++;
		}
		}
	  }
	  int max=0x3f3f3f3f;
	  for(int i=0;i<u;i++)
	  {
		  if(map[ma[i].x][ma[i].y]=='@')
		  {
		  int l,r;
		  memset(vis,0,sizeof(vis));
		  l=bfs(x1,y1,ma[i].x,ma[i].y);
		  memset(vis,0,sizeof(vis));
		  r=bfs(x2,y2,ma[i].x,ma[i].y);
		  if(max>(l+r)&&(l>=0&&r>=0))
		  {
		  max=l+r;
		  }
		}
	  }
	  printf("%d\n",max*11);
	}
return 0;
}*/
/*#include<cstdio>
#include<cstring>
#include<string>
#define p 13
#include<cmath>
using namespace std;
const int maxn = 1000005;
const long long int mod = 1e9+9;
int hash(char str[],int l)
{
	int max=-1;
  unsigned long long int x,y;
  for(int i=0;i<l&&(l-i-1)>=max;i++)
  {
    for(int j=0;j<i&&(i+i-j)<l;j++)
    {
	  int l=i-j;
	  x=0;
	  y=0;
	  for(int s=j;s<i;s++)
	  {
	  x=(x*p+str[s])%mod;
	  y=(y*p+str[2*i-s])%mod;
	  }
	  if(x==y)
	  {
	    if(max<l)
	    max=l;
	  }
	}
  }
  int m=2*max+1;
  for(int i=0;i<l-1&&(l-i-1)>=max;i++)
  {
    for(int j=0;j<=i;j++)
    {
	  int l=i-j+1;
	  x=0;
	  y=0;
	  for(int s=0;s<=i;s++)
	  {
	  x=(x*p+str[s])%mod;
	  y=(y*p+str[2*i+1-s])%mod;
	  }
	  if(x==y)
	  {
	    if(max<l)
	    max=l;
	  }
	}
  }
  int n=2*max;
  return m>n?m:n;
}
int main()
{
	char str[maxn];
	while(~scanf("%s",str))
	{
	  if(strcmp(str,"END")==0)
	  break;
	  int l=strlen(str);
	  printf("%d\n",hash(str,l));
	}
return 0;
}*/
/*manacher:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 40005;
int p[maxn]={0};
char str[maxn];
int Manacher(char *s)
{
	char c[maxn];
    int len=strlen(s+1);
    for (int i=1; i<=len; i++) c[2*i-1]='~',c[2*i]=s[i]; c[len=2*len+1]='~';
    int Pos=0,R=0,MAX=0;  //Pos���е㣬R�����ұ��Ǹ���;
    for(int i=1;i<=len;i++)
    p[i]=0;
    for (int i=1; i<=len; i++)
    {
        if (i<R) p[i]=min(p[2*Pos-i],R-i); else p[i]=1;
        while (1<=i-p[i]&&i+p[i]<=len&&c[i-p[i]]==c[i+p[i]]) p[i]++;//����������
        if (i+p[i]>R) {R=i+p[i]; Pos=i;}
        MAX=max(MAX,p[i]-1);
    }
    return MAX;
}
int main()
{
	int n;
	int g=1;
	while(~scanf("%s",str+1))
	{
	  if(strcmp(str+1,"END")==0)
	  break;
	  int s=Manacher(str);
	  printf("Case %d: %d\n",g++,s);
	}
return 0;
}*/
/*#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=200005;
int n;
char str[maxn],th[maxn];
char s[maxn];
char s1[maxn];
int main(){
    scanf("%d",&n);
    scanf("%s%s",str,th);
    int cnt=0;
    for(int i=n-1;i>=0;i--){
        str[i]-='a';
        th[i]-='a';
        s[i]=(str[i]+th[i]+cnt)%26;
        cnt=(str[i]+th[i]+cnt)/26;
    }
    for(int i=0;i<n;i++){
        s1[i]=(s[i]+cnt*26)/2+'a';
        cnt=s[i]%2;
}
printf("%s\n",s1);
    return 0;
}*/
/*#include<cstdio>
#include<iostream>
#include<cstring>
#define ull unsigned long long
using namespace std;
const int maxn =1e4+5;
char num[maxn];
ull change(char str[],int p)
{
	ull sum=0;
	int i=0;
	int g;
  while(str[i])
  {
  	if(str[i]>='0'&&str[i]<='9')
  	g=str[i]-'0';
  	else if(str[i]>='A'&&str[i]<='Z')
  	g=10+str[i]-'A';
  	else
  	{
	  g=36+str[i]-'a';
	}
  sum=sum*p+g;
  }
}
char th[maxn];
int find(ull s,int p)
{
  int i=0;
  if(s==0)
  th[i++]='0';
  while(s)
  {
    th[i++]=s%p+'0';
    s=s/p;
  }
  return i;
}
int main()
{
	int n,l,r;
	scanf("%d",&n);
	while(n--)
	{
	scanf("%d%d",&l,&r);
	scanf("%s",num);

	}
return 0;
}*/
/*#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn = 1e5+5;
int find(char *str)
{
char th[maxn];
int cnt=2,l;
int i=0;
th[0]='$';
th[1]='#';
while(str[i])
{
th[cnt++]=str[i];
th[cnt++]='#';
i++;
}
th[cnt]='\0';
cnt=cnt-1;
int p[maxn];
for(i=0;i<=cnt;i++)
{
p[i]=0;
}
int minn=-100;
int mx=0,pos=0;
for(i=1;i<=cnt;i++)
{
  if(mx<=i)
  p[i]=1;
  else
  p[i]=max(p[2*pos-i],mx-i);
  while(i-p[i]>=1&&i+p[i]<=cnt&&th[p[i]+i]==th[i-p[i]])
  p[i]++;
  if(i+p[i]>mx)
  {
  mx=i+p[i];
  pos=i;
  }
  minn=max(minn,p[i]-1);
}
return minn;
}

int main()
{
	int l,n;
    char str[maxn];
    cin>>str;
    int g=find(str);
    printf("%d\n",g);
return 0;
}*/
/*#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 1e5+5;
vector<int > str1,ans;
int main()
{
	int a,b;
	string l,r;
	int t;
	cin>>t;
	while(t--)
	{
    cin>>a>>b>>l;
	for(int i=0;i<l.size();i++)
	{
	if(l[i]>='0'&&l[i]<='9') str1.push_back(l[i]-'0');
	if(l[i]>='A'&&l[i]<='Z') str1.push_back(l[i]-'A'+10);
	if(l[i]>='a'&&l[i]<='z') str1.push_back(l[i]-'a'+36);
	}
	}

return 0;
}*/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1e4+5;
unsigned long long sum[maxn][maxn]={0};
unsigned long long change(int x,int y)
{
	unsigned long long l=0,r=0;
  for(int i=0;i<=x;i++)
  {
  l+=i;
  }
  for(int j=0;j<=y;j++)
  {
  r+=j;
  }
  return (x+1)*r+(y+1)*l;
}
int main()
{
	int n,m;
	cin>>n>>m;
	int r=m*n,l=m;
	unsigned long long Max=0;
	for(int i=0;i<=r;i++)
	{
	  if(i%n==0)
	  {
	  Max=max(Max,change(i,m-i/n));
	  }
	}
	printf("%llu\n",Max);
return 0;
}


/*            He was Humble but not fool.
           slow_processor for maskman_lucifer.     */

#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define pll pair<ll,ll>
#define pb push_back
#define M 1000000007
#define lc '\n'
using namespace std;
ll n,m;
ll a[40];
ll dp[1000000][40];
ll solve(ll ind,ll s)
{
    if(ind==n)
    {
        return s%m;
    }
    else
    {
        if(s>=1000000)
        {
              return max(solve(ind+1,s),solve(ind+1,s+a[ind]));
        }
        else
        {
            ll &ans=dp[s][ind];
            if(ans==-1)
            {
                ans=max(solve(ind+1,s),solve(ind+1,s+a[ind]));
            }
            return ans;
        }
    }
}
int main()
{
    IO
    cin>>n>>m;
    memset(dp,-1,sizeof(dp));
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]%=m;
    }
    sort(a,a+n);
    cout<<solve(0,0);
    return 0;
}


#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9+5
#define OO 1e18
#define EPS 1e-6
#define Endl '\n'
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=4005;
int Min(oo);
int a[5],b[5],c[5];
void check(int x,int y,int z){
    int A=x+a[0];
    int B=y+a[1];
    int C=z+a[2];
    int fr2_awl=max(0,B-b[2]);
    int fr2_tani=max(0,b[1]-C);
    if(fr2_awl&&!fr2_tani){
        Min=min(Min,c[1]*y+c[2]*z);
        re ;
    }
    if(!fr2_awl||!fr2_tani)re ;
    int hna=(A+fr2_tani-1)/fr2_tani;
    int m3lsh=(b[0]+fr2_awl-1)/fr2_awl;
    if(hna>m3lsh)Min=min(Min,c[0]*x+c[1]*y+c[2]*z);
    re ;
}
int main()
{
    IO;
    for(int i=0;i<3;++i)cin >> a[i];
    for(int i=0;i<3;++i)cin >> b[i];
    for(int i=0;i<3;++i)cin >> c[i];
    for(int i=0;i<=200;++i)
        for(int j=0;j<=1000;++j)
            for(int k=0;k<=1000;++k)
                check(i,j,k);
    cout<<Min<<endl;
    re 0;
}


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

long int fact(long int n)
{
    if (n==1) return 1;
    else return n*fact(n-1);
}
int main() {
	long int a,b; cin>>a>>b;
	long int fact(long int);
	a=fact(a); b=fact(b);
	cout<<__gcd(a,b);
	return 0;
}


#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include<algorithm>
#include<unordered_map>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pob         pop_back
#define ins         insert
#define fi          first
#define se          second
#define inf         200001
#define rep(a,b,c)  for(ll i=a;i<b;i=i+c)
#define repd(a,b,c) for(ll i=a;i>b;i=i-c)
#define Arena       ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pii         pair<ll,ll>
#define mod         1000000007
#define N           100001
#define si(n)       scanf("%s",&n)
int main(){
    Arena
    ll n;cin>>n;
    ll a=n,b,c,temp;
    ll ndig=0;
    unordered_map<ll,int>hash;
    for(ll i=0;i<=n;i++){
        hash[i]=0;
    }
    while(a){
        a=a/10;
        ndig++;
    }
    ll ans=0;
    // for(ll i=1;i<=9;i++){
    //     if(i<=n){
    //         ans++;
    //     }
    // }
    //cout<<ndig<<endl;
    for(ll i=2;i<=ndig;i++){
        for(ll x=1;x<=9;x++){
            for(ll y=x+1;y<=9;y++){
                for(ll j=0;j<(1<<i);j++){
                    a=i;
                    b=j;
                    c=1;
                    temp=0;
                    while(a){
                        if(b&1){
                            temp=c*x + temp;
                        }
                        else{
                            temp=c*y + temp;
                        }
                        a--;
                        b=b/2;
                        c=c*10;
                    }
                    //cout<<temp<<endl;
                    if(temp<=n && hash[temp]==0){
                        //cout<<temp<<endl;
                        hash[temp]=1;
                        ans++;
                    }
                }
            }
        }
    }
    //cout<<ans<<endl;
    for(ll i=0;i<(1<<ndig);i++){
        for(ll j=1;j<=9;j++){
            a=i;
            temp=0;
            c=1;
            while(a){
                if(a&1){
                    temp=c*j+temp;
                }
                c=c*10;
                a=a/2;
            }
            if(temp<=n && hash[temp]==0){
                //cout<<temp<<endl;
                ans++;
                hash[temp]=1;
            }
        }
    }
    cout<<ans-1;
    return 0;
}


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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#ifdef MPS
#define D(x...) printf(x)
#else
#define D(x...)
#endif
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;

const int P = 1e9+7;

unordered_map<pair<ll,int>,ll> f;

void exgcd(ll a,ll b,ll& d,ll& x,ll& y)
{
    if(!b) { d = a; x = 1; y = 0; }
    else{ exgcd(b, a%b, d, y, x); y -= x*(a/b); }
}

ll inv(ll a, ll p)
{
    ll d, x, y;
    exgcd(a, p, d, x, y);
    return d == 1 ? (x+p)%p : -1;
}

ll dp(ll n, int k)
{
	if(!k) return n;
	if(f[mp(n,k)]) return f[mp(n,k)];
	ll tmp = 0; int overall = 0;
	for(ll i = 1; i * i <= n; ++ i)
		if(n%i == 0)
		{
			tmp = (tmp + dp(i, k-1)) % P;
			if(i * i == n) overall ++;
			else {overall += 2; tmp = (tmp + dp(n/i,k-1)) % P;}
		}
	return f[mp(n,k)] = (tmp * inv(overall, P))%P;
}

int main()
{
	#ifdef MPS
		fp("1.in","r",stdin);
		fp("1.out","w",stdout);
		double mps = clock();
	#endif
	ll n; int k;
	cin >> n >> k;
	cout << dp(n, k) << endl;
	D("total excution time %.5f\n",clock()-mps);
	return 0;
}


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

ll x, y, z, dp[10005][55], ans = 1, var;

ll fs(ll s, ll ss, ll n){
	ll res = 1;
	while (ss > 0){
		if (ss & 1){
			res = (res * s) % n;
		}
		ss >>= 1;
		s = (s * s) % n;
	}
	return res;
}

ll rec(ll ss, ll n){
	if (ss <= 0){
		return fs(var, n, mod);
	}
	ll &re = dp[ss][n];
	if (re != -1){
		return re;
	}
	re = 0;
	ll rep = fs(n + 1, mod - 2, mod);
	for (int i = 0; i <= n; i++){
		re = (re + (rec(ss - 1, n - i) * rep % mod)) % mod;
	}
	return re;
}

int main(){
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	scanf("%lld%lld", &x, &y);
	for (int i = 2; i * i <= x; i++){
		z = 0;
		while (x % i == 0){
			x /= i;
			z++;
		}
		if (z){
			var = i;
			memset(dp, -1, sizeof(dp));
			ans = (ans * rec(y, z)) % mod;
		}
	}
	if (x > 1){
		var = x;
		memset(dp, -1, sizeof(dp));
		ans = (ans * rec(y, 1)) % mod;
	}
	printf("%lld\n", ans);
	return 0;
}


/*
 * temp.cpp
 *
 *  Created on: 2012-7-18
 *      Author: BSBandme
 */
#include <iostream>
#include <fstream>
#include <string.h>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
#include <iomanip>
#include <math.h>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <climits>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <sstream>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <double, double> pdd;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <double> vd;
typedef vector <string> vs;
typedef map <string, int> mpsi;
typedef map <double, int> mpdi;
typedef map <int, int> mpii;

const double pi = acos(0.0) * 2.0;
const double eps = 1e-12;
const int step[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

template <class T> inline T abs1(T a) {return a < 0 ? -a : a;}
template <class T> inline T max1(T a, T b) {return a > b ? a : b;}
template <class T> inline T min1(T a, T b) {return a < b ? a : b;}
template <class T> inline T gcd1(T a, T b) {
	if(a < b) swap(a, b);
	if(a % b == 0) return b;
	return gcd1(b, a % b);
}
template <class T> inline T lb(T num) {return num & (-num); }
inline int bitnum(ull nValue){
    nValue = ((0xaaaaaaaaaaaaaaaaull & nValue)>>1) + (0x5555555555555555ull & nValue);
    nValue = ((0xccccccccccccccccull & nValue)>>2) + (0x3333333333333333ull & nValue);
    nValue = ((0xf0f0f0f0f0f0f0f0ull & nValue)>>4) + (0x0f0f0f0f0f0f0f0full & nValue);
    nValue = ((0xff00ff00ff00ff00ull & nValue)>>8) + (0x00ff00ff00ff00ffull & nValue);
    nValue = ((0xffff0000ffff0000ull & nValue)>>16) + (0x0000ffff0000ffffull & nValue);
    nValue = ((0xffffffff00000000ull & nValue)>>32) + (0x00000000ffffffffull & nValue);
	return nValue;
}
inline int jud(double a, double b){
	if(abs1(a - b) < eps) return 0;
	if(a < b) return -1;
	return 1;
}
long long pow(long long n, long long m, long long mod = 0){
	long long ans = 1;
	long long k = n;
	while(m){
		if(m & 1) {
			ans *= k;
			if(mod) ans %= mod;
		}
		k *= k;
		if(mod) k %= mod;
		m >>= 1;
	}
	return ans;
}

int n, k;

/*const ll mod = 777777777;
ll dp[2][300][300];
ll c[300][300];

int main(){
	freopen("input.txt","w", stdout);
	c[0][0] = 1; c[1][0] = c[1][1] = 1;
	for(int i = 2; i < 300; i++){
		c[i][0] = 1;
		for(int j = 1; j <= i; j++){
			c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
			c[i][j] %= mod;
		}
	}
	for(int n = 1; n <= 260; n <<= 1){
		memset(dp, 0, sizeof(dp));
		dp[0][0][0] = 1;
		for(int i = 1; i <= n; i++){
			int now = i & 1, last = 1 - now;
			memset(dp[now], 0, sizeof(dp[now]));
			for(int j = 0; j <= n; j++) for(int k = 0; k <= n - j; k++) for(int w = 0; w <= k; w++){
				if(j != i){
					dp[now][k + j][w] += dp[last][k][w] * c[n - k][j];
					dp[now][k + j][w] %= mod;
				} else{
					dp[now][k + j][w + j] += dp[last][k][w] * c[n - k][j];
					dp[now][k + j][w + j] %= mod;
				}
			}
		}
		printf("{");
		for(int i = 0; i < 300; i++) printf("%I64d, ", dp[n & 1][n][i]);
		printf("}\n");
	}

	return 0;
}*/
int dp[8][300] =
{{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
,{1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
,{109, 80, 30, 32, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
,{7593125, 4898872, 1897056, 1757896, 415870, 147224, 59808, 6824, 541, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
,{391464593, 569389279, 312106242, 578944191, 515619293, 117354594, 161873957, 472062098, 428982705, 565460332, 735127505, 33900006, 293783147, 746623577, 290516100, 776830421, 166257661, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
,{212568440, 186175544, 519860281, 612549793, 737154512, 651912135, 44684703, 387329805, 195188679, 444199674, 20119449, 142138221, 132906648, 628771752, 513156108, 486011304, 225200475, 391579767, 342079395, 647490480, 264125799, 629394768, 360252438, 398169441, 157617135, 229471758, 736955478, 211593382, 468868529, 683961846, 584837659, 261086313, 464207287, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
,{550671827, 520987612, 63744786, 421203111, 279421821, 202356819, 370826673, 67309914, 291740751, 496385218, 199307003, 433540170, 643714911, 239654268, 554473341, 156006018, 469781928, 522840969, 320813094, 628905585, 575661807, 611444862, 352474101, 676760679, 232198470, 732674124, 446575689, 184587732, 390739055, 190181628, 578972226, 61292868, 135769095, 226078251, 129676638, 582889860, 448939463, 551553401, 56407680, 275899176, 87664059, 206607807, 374020479, 391428765, 104256117, 298053147, 51326142, 506108358, 383350905, 398730015, 74806569, 703150560, 165216555, 554790222, 509737025, 459185405, 366667722, 672407328, 509425833, 156126222, 6511239, 581127897, 239509872, 240805271, 382725349, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
,{149150650, 232966794, 487159055, 30540300, 458170419, 480722613, 605295159, 37220268, 292922628, 530767740, 138718678, 257373347, 44594256, 340129188, 610216692, 416259390, 657133515, 479433192, 317959019, 500636381, 12787348, 669954708, 68131467, 526429710, 423048528, 254706039, 42951006, 282387700, 303717460, 341834527, 333633477, 65589678, 376367145, 4802637, 415705878, 352406796, 72018835, 52410890, 241289776, 343900011, 624827616, 353784942, 615036450, 508213986, 138765186, 668528077, 437011960, 710035809, 735862995, 676063665, 294926121, 565603164, 111746817, 335375775, 27702486, 299270097, 434962491, 501639192, 286484229, 578826927, 685038942, 700348950, 654339672, 143420103, 104733162, 590145264, 371892402, 506813013, 596108961, 533997135, 244690731, 261388683, 663532359, 429824745, 435828036, 705296781, 474743430, 427694175, 346831137, 54648783, 310453920, 465470131, 33785059, 738490312, 39521181, 671903001, 487033953, 685013007, 478908360, 93337440, 208947235, 407997044, 591219559, 594676173, 777331779, 387099846, 265613565, 739707108, 95984586, 500815609, 703097347, 561797418, 495032139, 705610017, 137170026, 676047609, 498253248, 750976272, 124604900, 756201264, 517628076, 773939082, 652682670, 55761813, 671961765, 168908523, 243630450, 175889805, 231881111, 478771358, 621882744, 678182556, 341766705, 36099042, 154906374, 462063756, 768209115, 482164403, 642497124, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
,{51933421, 410403148, 334527774, 772784623, 616557739, 119956662, 238586775, 63611061, 336008070, 669986155, 113924623, 290147622, 396846646, 112511021, 506832921, 18685233, 505761984, 225925875, 457760646, 658656684, 195193908, 757727334, 640171035, 277206615, 551718468, 545555745, 681825249, 115612245, 685740951, 231158277, 622498779, 374707494, 691786683, 666008595, 585462906, 146037150, 466218648, 547014447, 290039148, 190245195, 363920382, 156455586, 278403867, 327398400, 586278000, 393846327, 543672234, 561963717, 580966092, 753823584, 130668327, 353120823, 249229170, 166684527, 751104774, 309569589, 415359657, 723936555, 583194366, 494437752, 518796945, 39580443, 776201013, 42414435, 612152037, 608226003, 99972432, 558262341, 106017282, 690040638, 28879011, 512108856, 337388940, 551043738, 450089262, 360676008, 402578568, 120337812, 519804558, 324290610, 23385663, 225772848, 745389414, 233672418, 19259856, 276174402, 744786693, 375112647, 758102058, 444609585, 510907446, 172560633, 142626330, 429471231, 211245489, 577291428, 91991781, 9088632, 259025598, 596818971, 43978329, 157324491, 3103092, 462674016, 627500097, 512182818, 338032656, 603489402, 54829908, 501181650, 736006257, 286368453, 389728458, 40215357, 534475872, 64943298, 112310856, 682966116, 69045921, 439587099, 469819224, 695798271, 38780154, 396695565, 631539342, 88089750, 632887668, 56238084, 569195676, 708023862, 80301375, 1768977, 434685258, 475528473, 421403409, 775975599, 511142751, 131177718, 748118511, 296645895, 110110707, 639416484, 194905872, 211085469, 309238398, 11740617, 693768537, 652625388, 324264456, 640051812, 584206074, 361094166, 224922159, 89967528, 349541550, 591638112, 410970006, 291661029, 15985323, 613778508, 65323503, 341231688, 468358191, 521572968, 361541124, 429215724, 127304142, 228266073, 11703825, 304947090, 589390074, 128418948, 3862068, 377654949, 714128667, 456248898, 147611205, 5728464, 21997836, 396817281, 734158215, 341780733, 747135963, 339589404, 417125457, 44524053, 339589656, 681789969, 494463186, 220301928, 453528621, 517248963, 675326610, 507964023, 351220905, 574648641, 689828796, 695091546, 465336054, 429224274, 405628839, 696994956, 611296308, 357242229, 176520078, 721298331, 127701891, 117572859, 511306362, 452641455, 771641703, 283264821, 443032569, 441456687, 139696515, 627111387, 665791056, 388047555, 332840025, 259736526, 473910948, 191720088, 102052314, 654363234, 399056049, 496688157, 691964847, 654378921, 766395126, 111085128, 722623041, 492109128, 523195911, 645447222, 614109258, 706116537, 242583957, 533025234, 553627998, 488329191, 743539734, 315527373, 490300965, 715317967, 493725043, 228877044, 317300809, 663739304, 80515854, 396414708, 317067177, 102404925, 289303402, 139952108, 386543325, 412133651, 507720408, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};

int main(){
	scanf("%d%d", &n, &k);
	int n1 = 0;
	k = n - k;
	while(n > 1) n1++, n >>= 1;
	printf("%d\n", dp[n1][k]);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll a,b;
cin>>a>>b;
ll count=0;
for(ll i=a;i<=b;i++)
{
   ll p=floor(log2(i));
   ll x=pow((ll)2,p+1);
   x--;
   for(ll j=p-1;j>=0;j--)
   {
      ll y=pow((ll)2,j);
      ll z=x-y;
      if(z==i)
      {
      count++;
      break;
      }

   }

}

cout<<count;
}


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

struct aho {
    int go[2], link, back;
};

aho suf[1600], pr[40];
string sufs[1600], prs[40];

void add_string(aho m[], string ms[], int &top, string s) {
    int u = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (m[u].go[s[i]] == 0) {
            ++top;
            m[u].go[s[i]] = top;
            ms[top] = ms[u] + s[i];
        }
        u = m[u].go[s[i]];
    }
}

void build_aho(aho m[]) {
    m[0].link = 0;
    vector <int> v = {0};
    for (int i = 0; i < v.size(); ++i) {
        for (int j = 0; j < 2; ++j)
        if (m[v[i]].go[j] != 0) {
            if (i == 0)
                m[m[v[i]].go[j]].link = 0;
            else
                m[m[v[i]].go[j]].link = m[m[v[i]].link].go[j];
            v.push_back(m[v[i]].go[j]);
        } else
            m[v[i]].go[j] = m[m[v[i]].link].go[j];
    }
}
int find_string(aho m[], string s) {
    int u = 0;
    for (int i = 0; i < s.size(); ++i)
        u = m[u].go[s[i]];
    return u;
}

string cnt(string s) {
    for (int i = 0; i < s.size(); ++i)
        s[i] += '0';
    return s;
}

long long dp[41][41][1600][2];

int main() {
    int i, j, k, n, top, l;
    string s;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    cin >> s;
    for (i = 0; i < s.size(); ++i)
        s[i] -= '0';
    if (s.size() > n) {
        for (i = 0; i < s.size() - n; ++i)
        if (s[i] != s[i + n]) {
            cout << 0;
            return 0;
        }
        cout << 1;
        return 0;
    }
    add_string(pr, prs, j = 0, s);
    build_aho(pr);
    k = 0;
    for (int i = 0; i < s.size(); ++i) {
        string s1 = "";
        for (int j = i; j < s.size(); ++j)
            s1 += s[j];
        add_string(suf, sufs, k, s1);
    }
    build_aho(suf);
    dp[0][0][0][0] = 1;
    for (i = 0; i < n; ++i)
    for (j = 0; j < s.size(); ++j)
    for (l = 0; l <= k; ++l)
    if (l != s.size()) {
        for (int i1 = 0; i1 < 2; ++i1)
            dp[i + 1][pr[j].go[i1]][l][1] += dp[i][j][l][1];
        for (int i1 = 0; i1 < 2; ++i1)
        if (sufs[suf[l].go[i1]].size() <= sufs[l].size())
            dp[i + 1][pr[j].go[i1]][l][1] += dp[i][j][l][0];
        else {
            dp[i + 1][pr[j].go[i1]][suf[l].go[i1]][0] += dp[i][j][l][0];
        }
    }
    long long ans = 1;
    for (i = 0; i < n; ++i)
        ans *= 2;
    for (i = 0; i <= s.size(); ++i)
    for (j = 0; j <= k; ++j) {
        string s1 = prs[i] + sufs[j];
        int u = 0;
        bool flag = true;
        for (l = 0; l < s1.size(); ++l) {
            u = suf[u].go[s1[l]];
            if (u == s.size())
                flag = false;
        }
        if (flag)
            ans -= dp[n][i][j][0] + dp[n][i][j][1];
    }
    cout << ans;
}


#pragma GCC diagnostic ignored "-Wunused-result"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = (int)41;
//const ll INF = (ll)1e18 + 41;
const int INF = (int)1e9 + 41;
const ll MD = (ll)1e9 + 7;
bool D = false, E = false;

ll dp[N][N * N + 1][N][2];

pair<int, int> decode(int x) {
	return {x / N, x % N};
}

int code(int L, int R) {
	return L * N + R;
}

int nxt[N][N][2];
int nxtSuf[N][2];
bool isOk[N * N][N];

void solve() {
	int n;
	string s;
	cin >> n >> s;
	int m = s.length();

	for (int l = 0; l < m; l++) {
		for (int r = l; r <= m; r++) {
			for (int z = 0; z < 2; z++) {
				string kek = (r == l ? "" : s.substr(l, r - l)) + char('0' + z);
				int cod = 0;
				for (int l2 = 0; l2 < m; l2++) {
					int r2 = l2 + kek.length();
					if (r2 <= n && s.substr(l2, r2 - l2) == kek && cod == 0) {
						cod = code(l2, r2);
					}
				}
				nxt[l][r][z] = cod;
			}
		}
	}

	for (int len = 0; len <= m; len++) {
		for (int z = 0; z < 2; z++) {
			string kek = s.substr(0, len) + char('0' + z);
			int ans = 0;
			int klen = kek.length();
			for (int len2 = 1; len2 <= klen; len2++) {
				if (kek.substr(klen - len2, len2) == s.substr(0, len2)) ans = len2;
			}
			nxtSuf[len][z] = ans;
			//printf("nxtSuf[%d][%d] = %d\n", len, z, nxtSuf[len][z]);
		}
	}

	dp[0][0][0][0] = 1;
	ll ans = 0;

	for (int code = 0; code < N * N; code++) {
		for (int suf = 0; suf <= m; suf++) {
			isOk[code][suf] = false;
			int l = code / N;
			int r = code % N;
			if (r <= l || r > m) continue;

			string kek = s.substr(0, suf) + s.substr(l, r - l);

			isOk[code][suf] = (kek.find(s) != string::npos);
			//cerr << l << " " << r << " " << suf << " " << kek << " " << (int)isOk[code][suf] << "\n";
		}
	}
	isOk[0][m] = true;

	for (int len = 0; len <= n; len++) {
		for (int code = 0; code < N * N; code++) {
			int l = code / N;
			int r = code % N;
			if (r <= l && l + r > 0) continue;

			for (int suf = 0; suf <= min(len, m); suf++) {
				for (int isIn = 0; isIn < 2; isIn++) {
					int curDp = dp[len][code][suf][isIn];
					if (curDp == 0) continue;

					//if (D) printf("len = %d, l = %d, r = %d, suf = %d, in = %d, val = %d\n", len, l, r, suf, (int)isIn, curDp);

					if ((isIn || isOk[code][suf]) && len == n) {
						ans += curDp;
						continue;
					}

					for (int z = 0; z < 2; z++) {
						int newSuf = nxtSuf[suf][z];
						int newIn = min(1, isIn + (int)(newSuf == m));

						int newCode = 0;
						if (r - l == len && len < m && nxt[l][r][z] > 0) newCode = nxt[l][r][z];
						else newCode = code;

						dp[len + 1][newCode][newSuf][newIn] += curDp;
					}
				}
			}
		}
	}

	cout << ans << "\n";
}

int main() {
	int tst = 1;
	//scanf("%d", &tst);
	//cin >> tst;
#ifdef MADE_BY_SERT
	D = true;
	tst = 1;
	while (tst--) solve();
#else
	while (tst--) solve();
#endif
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>

#if LOCAL
	#define DO_NOT_SEND
#endif

typedef long long LL;

int IntMaxVal = (int) 1e20;
int IntMinVal = (int) -1e20;
LL LongMaxVal = (LL) 1e20;
LL LongMinVal = (LL) -1e20;

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

#define minimize(a, b) { a = min(a, b); }
#define maximize(a, b) { a = max(a, b); }

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

using namespace std;

#define next(type, i) type i; cin >> i;
template<typename T> struct argument_type;
template<typename T, typename U> struct argument_type<T(U)> { typedef U type; };
#define nextVector(t, v, size) vector< argument_type<void(t)>::type > v(size); { for (int i = 0 ; i < size ; i++) cin >> v[i]; }

#define range(name, start, count) vector<int> name(count); { for (int i = 0 ; i < count ; i++) name[i] = i + start; }

template <typename T1, typename T2> istream& operator >>(istream& is, pair<T1, T2>& s) { is >> s.first >> s.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T> &v) { for (int i = 0 ; i < v.size() ; i++) os << v[i] << ' '; os << endl; return os; }
template <typename T1, typename T2> ostream& operator <<(ostream& s, pair<T1, T2>& t) { s << t.first << ' ' << t.second; return s; }

const int mod = 777777777;

LL add(LL a, LL b) {
	return (a + b) % mod;
}

LL mult(LL a, LL b) {
	return a * b % mod;
}

LL waysToMerge[257][257];
LL ans[257][257];

int main() {
	srand (time(NULL));
    ios_base::sync_with_stdio(false); cin.tie(NULL);

	FOR (i, 0, 257) waysToMerge[i][0] = 1;
	FOR (i, 0, 257) FOR (j, 1, 257) {
		waysToMerge[i][j] = 0;
		FOR (k, 0, i + 1) waysToMerge[i][j] = add(waysToMerge[i][j], waysToMerge[i - k][j - 1]);
	}

	next(int, n);
	next(int, k);

	FOR (i, 0, 257) ans[0][i] = 0;
	ans[0][0] = 1;

	bool debug = 0;
	FOR (upTo, 1, n + 1) FOR (ppl, 0, n + 1) {
		ans[upTo][ppl] = 0;
		FOR (x, 0, ppl + 1) {
			if (debug) cout << upTo << ' ' << ppl << ' ' << x << endl; DO_NOT_SEND
			if (x == upTo && x > n - k) { if (debug) cout << "skip1" << endl; continue; }
			if (upTo == n - k && x != upTo) { if (debug) cout << "skip2" << endl; continue; }

			ans[upTo][ppl] = add(ans[upTo][ppl], mult(waysToMerge[x][ppl - x], ans[upTo - 1][ppl - x]));
		}
		if (debug) cout << "== " << upTo << ' ' << ppl << ' ' << ans[upTo][ppl] << endl;
	}

	cout << ans[n][n];
}


#include <bits/stdc++.h>

using namespace std;

long long a[100];

int main()
{
    int n, i, j;
    long long suma = 0;
    long long control = 0;
    cin >> n;
    for (i = 1; i <= n; i++)
        cin >> a[i];
    sort (a + 1, a + n + 1);
    for (i = n; i >= 2; i--)
        if (a[i] == a[i-1]){
            a[i-1] = a[i-1] - 1;
            control = a[i];
            for (j = i - 1; j <= 1; j--)
                if (a[j] == control)
                    a[j] = a[j] - 1;

        }
    for (i = 1; i <= n; i++)
        suma = suma + a[i];
    cout << suma;
    return 0;
}


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

const int mod = 998244353;

int p,r,s;

const int maxN = 1e5 + 10;

ll fac[maxN],ifac[maxN];

inline ll qpow(ll a,ll x){ll ans=1;for(;x;x>>=1,a=a*a%mod) if(x&1) ans=ans*a%mod;return ans;}
inline ll C(int n,int r){if(r<0 || r>n) return 0;return fac[n]*ifac[r]%mod*ifac[n-r]%mod;}

void pre()
{
	int i;

	fac[0]=1;
	for(i=1;i<maxN;i++) fac[i]=fac[i-1]*i%mod;
	ifac[maxN-1]=qpow(fac[maxN-1],mod-2);
	for(i=maxN-2;~i;i--) ifac[i]=ifac[i+1]*(i+1)%mod;
}

ll calc(int p,int l,int s)//<l
{
	if(p<0 || s<0) return 0;
	if(!p && s>0) return 0;
	if(!p && !s) return 1;
	int i;ll ans=0;

	//cout<<p<<' '<<l<<' '<<s<<endl;

	for(i=0;i<=p;i++) ans+=(i&1?-1:1)*C(p,i)*C(p+s-l*i-1,s-l*i)%mod;
	//cout<<Mod(ans%mod)<<endl;
	return Mod(ans%mod);
}

void solve()
{
	int i,j;ll ans=0,down=C(p+s-1,s);

	for(i=r;i<=s;i++)
	{
		for(j=0;j<=p-1;j++)
		{
			ans+=C(p-1,j)*calc(p-1-j,i,s-i*(j+1))%mod*qpow(j+1,mod-2)%mod;
		}
	}

	for(i=r-1;~i;i--)
	{
		down-=C(p-1+s-i-1,s-i);
	}

	printf("%lld\n",Mod(ans%mod*qpow(down,mod-2)%mod));
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("e.in","r",stdin);
	freopen("e.out","w",stdout);
	#endif

	scanf("%d%d%d",&p,&s,&r);
	pre();
	solve();

	return 0;
}


#include<cstdio>
using namespace std;
int main()
{
    int n,i,ans=0;
    scanf("%d",&n);
    for(i=2;i<=n-1;i++) ans+=i*(i+1);
    printf("%d",ans);
        return 0
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int n0 = 4003, mod = 1e9 + 7;
int w, h, cur[4], cnt[2][4];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	cin >> w >> h;
	cnt[0][0] = cnt[0][1] = w / 2 + 1;
	cnt[1][0] = cnt[1][1] = (w + 1) - (w / 2 + 1);

	cnt[0][2] = cnt[0][3] = h / 2 + 1;
	cnt[1][2] = cnt[1][3] = (h + 1) - (h / 2 + 1);
	int all = 0;
	for (int x = 0; x < 2; x++) {
		for (int y = 0; y < 2; y++) {
			int ways = 0;
			for (int k = 0; k < 16; k++) {
				int res = 1;
				for (int l = 0; l < 4; l++) {
					cur[l] = (k >> l & 1);
					res = (ll)res * cnt[cur[l]][l] % mod;
				}
				int val = ((cur[0] ^ x) & (cur[3] ^ y)) ^ ((cur[1] ^ x) & (cur[2] ^ y));
				if (val & 1) continue;
				ways += res;
				ways -= (all >= mod) ? mod : 0;
			}
			all += ((ll)cnt[x][0] * cnt[y][2] % mod) * ways % mod;
			all -= (all >= mod) ? mod : 0;
		}
	}
	for (int i = 0; i <= w; i++) {
		for (int j = 0; j <= h; j++) {
			int cnt = (w - i + 1) * (h - j + 1), num = 0;
			if (i == 0) num = j + 1;
			else if (j == 0) num = i + 1;
			else {
				int g = __gcd(i, j);
				num = g + 1;
			}
			int num2 = num;
			if (i > 0 || j > 0)
				num2 = 6 * (num - 2) + 2 * 3;
			if (i > 0 && j > 0)
				cnt *= 2;
			all -= (ll)cnt * num2 % mod;
			all += (all >= 0) ? 0 : mod;
		}
	}
	cout << all;
}


// .... .... .... !

#include <iostream>
#include <iomanip>
#include <fstream>

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

#include <cstdio>
#include <cstring>

using namespace std;

#define rep(i, n) for (int i = 0, _n = (int)(n); i < _n; i++)
#define fer(i, x, n) for (int i = (int)(x), _n = (int)(n); i < _n; i++)
#define rof(i, n, x) for (int i = (int)(n), _x = (int)(x); i-- > _x; )
#define fch(i, x) for (__typeof(x.begin()) i = x.begin(); i != x.end(); i++)
#define sz(x) (int((x).size()))
#define X first
#define Y second

typedef long long ll;
typedef pair <int, int> pii;

////////////////////////////////////////////////////////////////////////////////

const int mod = 1000000007;
const int maxw = 4000 + 100;

int w, h;
int cache[maxw];

int cnt (int a, int b) // gcd (a, b) = 1
{
	if (cache[a+b] != -1) return cache[a+b];
	int ret = 0;

	rep (m, maxw)
	{
		int len = (a+b) * m;
		if (h+1-len <= 0) break;
		ret += (m ? 2 : 1) * (h+1-len);
	}

	return cache[a+b] = ret;
}

pii hmw (int k)
{
	int tot = k*(ll)k*k % mod;
	int x = k/2, y = k-x;
	int sam = (x*(ll)x*x + y*(ll)y*y) % mod;
	return pii (sam, (tot - sam + mod) % mod);
}

int pm (int x, int p)
{
	int ret = 1;
	for (int i = 0; (1<<i) <= p; i++)
	{
		if (p >> i & 1) ret = (ret * (ll)x) % mod;
		x = x*(ll)x % mod;
	}
	return ret;
}

int main()
{
	ios::sync_with_stdio (false);

	memset (cache, -1, sizeof cache);

	cin >> w >> h;

	int bad = 0;

	fer (a, 1, w) fer (b, 1, w-a+1)
	{
		int gab =__gcd (a, b);
		int va = a/gab, vb = b/gab;
		int tmp = cnt (va, vb);
		tmp = tmp * (ll)(w+1-a-b) * 6LL % mod;
		bad += tmp; if (bad >= mod) bad -= mod;
	}

	bad = (bad + (h+1) * (ll)h % mod * (ll)(h-1) * (ll)(w+1)) % mod;

	int tot = (w+1) * (h+1);

	bad = (bad + tot * 3LL * (tot-1)) % mod;
	bad = (bad + 1LL * tot) % mod;

	pii wc = hmw (w+1);
	pii hc = hmw (h+1);

	int ans = (wc.X * (ll)(hc.X + hc.Y) + wc.Y * (ll)hc.X) % mod;
	ans = (ans + wc.Y * 1LL * hc.Y * pm (3, mod-2)) % mod;

	cout << (ans-bad+mod)%mod << endl;

	{ int _; cin >> _; }
	return 0;
}


#include <iostream>

#define endl "\n"
#define ll long long

using namespace std;

string s;

long long n, i, a[10001], x, k;

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

    cin >> n >> k;

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

    for (i = 0; i < 101; i++)
    {
        if(a[i] > k)
        {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;
}


#include<iostream>
#include<string>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#define FOR(i, a, b) for( int i = (a); i < (b); i++ )
#define Fore(it, x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define Set(a, s) memset(a, s, sizeof (a))
using namespace std;
string text;
int n,h;
int oo =1<<25;
int mini=-oo;
int tar;
//true down
//false up
#define DOWN 1
#define UP 0

int dp[5][25][11][11][2];

long long solve(int num,int index , int h  , int d, bool dir , bool first)
{
    if(d<0 || h<0)return 0;
    if(index==n &&h==0 && d==0)
        return 1;
    if(index==n)return 0;
    if(dp[num][index][h][d][dir]!=-1)
        return dp[num][index][h][d][dir];
    long long sum=0;
    for(int i = num+1 ; i<4 ; i++)
            if(dir==DOWN)
                sum+=solve(i,index+1,h,d-1,UP,0);
            else
                sum+=solve(i,index+1,h,d,UP,0);
    if(!first)
    for(int i = num-1 ; i>=0 ; i--)
            if(dir==DOWN)
                sum+=solve(i,index+1,h,d,DOWN,0);
            else
                sum+=solve(i,index+1,h-1,d,DOWN,0);
    return sum;
}

int main()
{
   // freopen("input.in","r",stdin);

    while(cin>>n>>h)
    {
        Set(dp,-1);
        tar=(1<<4)-1;
        int sum=0;
        for(int i = 0 ; i<4 ; i++)
            dp[0][0][h][h-1][UP]=sum+=solve(i,1,h,h-1,UP,1);
        cout<<sum<<endl;
    }

    return 0;
}


#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <stdio.h>

using namespace std;

#define fo(i,n) for(int i=0; i<(int)n; i++)
#define rep(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#define mp(a,b) make_pair(a,b)
#define pb(x) push_back(x)
#define pii pair<int,int>

int dp[21][11][11][6][6];
int n,t;
int solve(int i, int l1, int l2, int v, int pre) {
    if (l1<0 || l2<0) return 0;
    if (i==n && l1==0 && l2==0 && v<pre) return 1;
    if (i==n) return 0;
    if (dp[i][l1][l2][v][pre]>0) return dp[i][l1][l2][v][pre];

    int tmp = 0;
    for (int j=v+1; j<=4; j++) {
        if (v>pre || i==1) tmp += solve(i+1,l1,l2,j,v);
        else tmp += solve(i+1,l1,l2-1,j,v);
    }
    for (int j=1; j<v; j++) {
        if (v<pre || i==1) tmp += solve(i+1,l1,l2,j,v);
        else tmp += solve(i+1,l1-1,l2,j,v);
    }

    //cout<<i<<" "<<l1<<" "<<l2<<" "<<v<<" "<<pre<<" "<<tmp<<endl;
    dp[i][l1][l2][v][pre] = tmp;
    return tmp;

}

int main() {

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

    cin>>n>>t;
    int res = 0;
    for (int i=0; i<=n; i++) for (int j=0; j<=t; j++) for (int p=0; p<=t; p++) for (int k=0; k<5; k++) for (int r=0; r<=6; r++) dp[i][j][p][k][r] = -1;
    for (int i=1; i<4; i++) res += solve(1,t,t-1,i,0);
    cout<<res<<endl;

    return 0;

}


#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <complex>
using namespace std;

// begin insert defines
#define ALL(a) (a).begin(),(a).end()
#define CR clear
typedef vector<int> VRI;
template <class T> void PV(T x) {for(__typeof__((x).begin()) i = (x).begin(); i != (x).end(); i++) cout << *i << " "; cout << endl;}
#define Rep(i,n) for(int n_ = (n), i = 0; i< n_; ++i)
#define PB push_back
#define VR vector
typedef long long ll;
// end insert defines

//const ll INF = 1000000000LL * 100LL;

VR<ll> fac;
ll n;
VRI id;
VR<bool> vis;

void dfs(int dep, ll k)
{
  if (dep >= n) return ;
  for (int i = 0; i < n; i++) {
    if (vis[i]) continue;
    if (fac[n - dep - 1] < k) {
      k -= fac[n - dep - 1];
    }
    else {
      id[dep] = i;
      vis[i] = true;
      dfs(dep + 1, k);
      break;
    }
  }
}

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

int main(int argc, char *argv[])
{
  ll N, m;
  fac.PB(1LL);
  Rep(i, 15) fac.PB(fac.back() * (i + 1));
  cin >> N >> m;
  n = min(N, (ll)fac.size() - 1);
  id.resize(n);
  vis.assign(n, false);
  if (m > fac[n]) {
    cout << -1 << endl;
    return 0;
  }
  dfs(0, m);
  VRI oid = id;
  //  PV(oid);
  id.CR();
  if (n == N) id = oid;
  else {
    Rep(i, N - n) id.PB(i);
    Rep(i, n) id.PB(oid[i] + N - n);
  }
  //  PV(id);

  // VRI tv;
  // Rep(i, N) tv.PB(i);
  // int tn = m - 1;
  // while (tn--) {
  //   next_permutation(ALL(tv));
  // }
  // PV(tv);

  int ret = 0;
  Rep(i, id.size()) {
    if (check(i + 1) && check(id[i] + 1)) ret++;
  }
  cout << ret << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int MODULE = (int)1e9+7;

int cnt[3];

int ql[2222222];
int qr[2222222];
int qans[2222222];
// will fill array "cnt"
int Nanase(int p)
{
	int low = 0;
	int high = 0;
	int end = 0;

	ql[end] = 0; qr[end] = 2; qans[end++] = 0;
	cnt[0] = (cnt[0] + 2LL*p-3)%MODULE;

	// delta
	for(int i = 3;i < p;)
	{
		while(low < end && qr[low] < i/3) low++;
		while(high < end && qr[high] < i-i/3) high++;
		int sved = 0;
		int q = qr[high];
		for(int j = 0;j < 3;j++)
		{
			if((3*q-j) % 2) continue;
			if((3*q-j) / 2 % 3 != j) continue;
			sved = max(sved,(3*q-j)/2);
		}
		//printf("sved = %d\n",sved);
		int till = min(qr[low]*3+2,sved);
		till = min(till,p-1);

		int mexa[3] = {0};
		mexa[qans[low]]++; mexa[qans[high]]++;
		for(int j = 0;j < 3;j++)
		{
			if(!mexa[j])
			{
				if(end && j == qans[end-1]) qr[end-1] = till;
				else { ql[end] = i; qr[end] = till; qans[end++] = j; }

				int len = till-i+1;
				cnt[j] += ( (ll)p*len%MODULE-(ll)(i+till)*len/2%MODULE+MODULE ) % MODULE;
				cnt[j] %= MODULE;
				break;
			}
		}

		i = till+1;
	}
	return end;
}

int F[1111][4];

int main(void)
{
	int n = 0;
	int p = 0;
	scanf("%d %d",&n,&p);

	Nanase(p);

	F[0][0] = 1;
	for(int i = 0;i < n;i++)
	{
		for(int j = 0;j < 4;j++)
		{
			for(int k = 0;k < 3;k++)
			{
				F[i+1][j^k] = (F[i+1][j^k]+(ll)F[i][j]*cnt[k])%MODULE;
			}
		}
	}

	int ans = 0;
	for(int i = 1;i < 4;i++) ans = (ans+F[n][i])%MODULE;
	printf("%d\n",ans);
	while(getchar() != EOF);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define maxn 1005
#define maxk 155
#define mo 1000000007
#define ll long long
#define min(a,b) (((a) < (b)) ? a : b)
using namespace std;

int sg[maxk];

int wz[maxk];

int n,p;

int f[maxn][4];

int tot;

ll num[4];

int mex(int x,int y){
	if (x*y>0) return 0;
	if (x==1 || y==1) return 2;
	return 1;
}

int main(){
	scanf("%d%d",&n,&p);
	wz[1]=1;
	sg[1]=0;
	tot=1;
	int las1=1,las2=1,noww=3;
	while (noww<p){
		tot++;
		wz[tot]=noww;
		sg[tot]=mex(sg[las1],sg[las2]);
		if (sg[tot]==sg[tot-1]) tot--;
		noww=min(1ll*wz[las2+1] * 3,(1ll*(wz[las1+1]-1)*3/2+1));
		noww=min(noww,p);
		if (sg[las1+1]==noww-noww/3) las1++;
		if (sg[las2+1]==noww / 3) las2++;
	}
	fo(i,1,tot) {
		int l=wz[i];
		int r=wz[i+1];
		if (i==tot) r=p;
		num[sg[i]]=(num[sg[i]]+1ll*p*(r-l)-1ll*r*(r-1)/2+1ll*l*(l-1)/2) % mo;
		num[sg[i]]=(num[sg[i]] % mo+mo) % mo;
	}
	f[0][0]=1;
	fo(i,1,n)
		fo(j,0,3)
			fo(k,0,2) f[i][j ^ k]=(f[i][j ^ k]+f[i-1][j]*1ll*num[k])	% mo;
	ll ans=f[n][1]+f[n][2]+f[n][3];
	printf("%I64d",ans % mo);
	return 0;
}


/**
 *  winners never quit
**/

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
typedef long long Long;

const int N = 1e5;

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  int tc, ca = 0;
  int n, el;
  cin >> n;
  vector <int> v;
  for (int i = 0;i < n;i++){
    cin >> el;
    if (el%2)v.pb(i);
  }
  string ans = "No";
  int len = v.size();
  if (len%2 && v[len-1]%2 && v[0]%2)ans = "Yes";
  cout << ans << '\n';
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair <int,int> pii;

const int N = 200200;
const int M = 300300;

struct Edge
{
    int x, y;
    Edge(int x = 0, int y = 0) : x(x), y(y) {}
};

struct Query
{
    int T, x;
    Query(int T = 0, int x = 0) : T(T), x(x) {}
};

int a[N];
int n, m, q;
vector <Edge> edges;
vector <Query> queries;

int P[N];
bool InTree[M];
set <pii> Nodes[N];
stack <pii> PChanges;
stack <stack <pii>> NodesInChanges;
stack <stack <pii>> NodesOutChanges;

void Init()
{
    for(int x = 1; x <= n; x++) P[x] = x, Nodes[x].emplace(a[x], x);
}

int F(int x)
{
    while(x != P[x])
        x = P[x];
    return x;
}

void Un(int e, bool storeChanges)
{
    int x = edges[e].x;
    int y = edges[e].y;

    if((x = F(x)) == (y = F(y)))
        return ;

    InTree[e] = true;

    if(Nodes[x].size() < Nodes[y].size())
        swap(x, y);

    if(storeChanges)
    {
        NodesInChanges.push(stack <pii> ());
        NodesOutChanges.push(stack <pii> ());
    }

    for(pii p : Nodes[y])
    {
        if(storeChanges)
        {
            NodesInChanges.top().emplace(x, p.second);
            NodesOutChanges.top().emplace(y, p.second);
        }
    }

    for(pii p : Nodes[y])
        Nodes[x].insert(p);
    Nodes[y].clear();

    if(storeChanges)
        PChanges.emplace(y, P[y]);

    P[y] = x;
}

void DeUn(int e)
{
    if(!InTree[e])
        return ;

    P[PChanges.top().first] = PChanges.top().second;

    while(!NodesInChanges.top().empty())
    {
        pii p = NodesInChanges.top().top();
        NodesInChanges.top().pop();
        Nodes[p.first].erase(pii(a[p.second], p.second));
    }

    while(!NodesOutChanges.top().empty())
    {
        pii p = NodesOutChanges.top().top();
        NodesOutChanges.top().pop();
        Nodes[p.first].insert(pii(a[p.second], p.second));
    }

    PChanges.pop();
    NodesInChanges.pop();
    NodesOutChanges.pop();
}

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

    for(int x = 1; x <= n; x++) scanf("%d", a + x);

    for(int i = 0; i < m; i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        edges.emplace_back(x, y);
    }

    for(int i = 0; i < q; i++)
    {
        int T, x;
        scanf("%d%d", &T, &x);
        if(T == 2)  x--;
        queries.emplace_back(T, x);
    }

    vector <bool> LazyUn(m);
    for(const Query& Q : queries)
        if(Q.T == 2)
            LazyUn[Q.x] = true;

    Init();
    for(int i = 0; i < m; i++)
        if(!LazyUn[i])
            Un(i, false);

    reverse(queries.begin(), queries.end());
    for(const Query& Q : queries)
        if(Q.T == 2)
            Un(Q.x, true);

    reverse(queries.begin(), queries.end());
    for(const Query& Q : queries)
    {
        if(Q.T == 1)
        {
            int x = F(Q.x);
            int y = (*Nodes[x].rbegin()).second;
            printf("%d\n", a[y]);

            Nodes[x].erase(pii(a[y], y));
            a[y] = 0;
            Nodes[x].insert(pii(a[y], y));
        }

        else
        {
            DeUn(Q.x);
        }
    }
}


#include<bits/stdc++.h>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

using namespace std;

typedef long long ll;
const int maxn=100100;
const ll MOD=1e9+7;

int len;
int num[20];
ll dp[20][20];
ll res[20];

void getNum(ll x){
    len=0;
    while(x){
        num[++len]=x%10;
        x/=10;
    }
}

ll F(int idx,int cnt,bool e){
//    cout<<idx<<" "<<cnt<<endl;
    if(!idx) return cnt==0;
    if(!e&&dp[idx][cnt]) return dp[idx][cnt];

    int limit=e?num[idx]:9;
    ll ret=0;
    for(int i=0;i<=limit;++i){
        if(i==4||i==7)
            ret=(ret+F(idx-1,cnt-1,e&&i==limit))%MOD;
        else ret=(ret+F(idx-1,cnt,e&&i==limit))%MOD;
    }
    return e?ret:dp[idx][cnt]=ret;
}

ll dfs(int idx,int cnt){
    if(idx==6) return 1;
    ll ret=0;
    for(int i=0;i<=cnt;++i){
        res[i]--;
        ret=(ret+(res[i]+1)*dfs(idx+1,cnt-i))%MOD;
        res[i]++;
    }
    return ret;
}

int main()
{
//    freopen("in.txt","r",stdin);
    ll x;scanf("%I64d",&x);
    if(x<=7){
        cout<<0<<endl;return 0;
    }
    getNum(x);
    for(int i=0;i<=len;++i){
        memset(dp,0,sizeof(dp));
        res[i]=F(len,i,true);
    }
    res[0]--;
//    cout<<res[0]<<" "<<res[1]<<" "<<res[2]<<endl;
    ll ans=0;
    for(int i=1;i<=len;++i)
        ans=(ans+res[i]*dfs(0,i-1))%MOD;
    cout<<ans<<endl;
    return 0;
}


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

long long n, x, y, x2, y2, l;

int main() {
    freopen("tmp.inp", "r", stdin);
    freopen("tmp.out", "w", stdout);

    cin >> n >> x >> y >> x2 >> y2;
    l = ceil(sqrt(abs(x-x2)*abs(x-x2) + abs(y-y2)*abs(y-y2)));

    if (l%(2*n) == 0) cout << l/(2*n);
    else cout << l/(2*n)+1;

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>

#define ONLINE_JUDGE
#define pii pair<int, int>

using namespace std;
const int MAXN = 100500;

void dfs(int v, vector<vector<int>> g, vector<bool>& used)
{
    used[v] = true;
    for (int i = 0; i < g[v].size(); i++)
    {
        int u = g[v][i];
        if (!used[u])
            dfs(u, g, used);
    }
}

vector<int> f(MAXN, 0);
vector<vector<int>> g(MAXN, vector<int>());
vector<vector<int>> gT(MAXN, vector<int>());
vector<bool> used(MAXN, false);
vector<bool> usedT(MAXN, false);

int main()
{
#ifndef ONLINE_JUDGE
    ifstream cin("input.txt");
    ofstream cout("output.txt");
#endif

    int n, m;

    cin >> n >> m;

    for (int i = 0; i < n; i++)
        cin >> f[i];

    for (int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].push_back(v);
        gT[v].push_back(u);
    }

    for (int i = 0; i < n; i++)
    {
        if (!used[i] && f[i] == 1)
            dfs(i, g, used);
    }

    for (int i = 0; i < n; i++)
    {
        if (!usedT[i] && f[i] == 2)
            dfs(i, gT, usedT);
    }

    for (int i = 0; i < n; i++)
    {
        if (used[i] && usedT[i])
            cout << 1 << endl;
        else
            cout << 0 << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	short int stick[2];
	cin>>stick[0]>>stick[1]>>stick[2];
	sort(stick,stick+3);
	cout<<max(stick[2]-stick[1]-stick[0]+1,0)<<endl;
	return 0;
}


#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int i;
	int ans[n],limit=1;
	ans[0] = n;
	for(i=n/2;i>0;i--){
		if(n%i == 0){
			n=i;
			ans[limit]=i;
			limit++;
		}
	}
	for(i=0;i<limit;i++){
		cout<<ans[i]<<" ";
	}
	return 9;
}


#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define F first
#define S second
const int N=2e5+7;
typedef long long int ll;
string l,r;
int T,n,a,b,m,k;
int d[N];
int cnt=0;
vector<pair<int,int> >g[N];

int main()
{
     ios::sync_with_stdio(false);
     cin.tie(0);
     cin>>n;
     rep(i,2,n)
     ans+=ll(i)*(i+1);
     cout<<ans;
     return 0;

}


 #include <bits/stdc++.h>
 #define nint new int
 #define ll long long
 #define pb push_back
 #define sony ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 using namespace std;
 int main()
 {
 sony;
 ll a,b;
 cin>>a>>b;
 a=max(a,b);
 for (b=a;--a;)	b*=a;
 cout<<b;
 return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define pb push_back
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds;

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

vector<int> g[200001];

vector<int> gpr[200001];

vector<int> path;

vector<pair<int,int> > used;

vector<int> db;

queue<pair<int,int> > q;

void dfs(int v1,int l1){
    q.push({l1,v1});
    while(!q.empty()){
    int v=q.front().S;
    int l=q.front().F;
    q.pop();
    if(used[v].F<l && used[v].F!=0){
        continue;
    }
    for(int i=0;i<gpr[v].size();i++){
        int to=gpr[v][i];
        if(used[to].F==0 || used[to].F==l+1){
            used[to].F=l+1;
            used[to].S+=used[v].S;
            q.push({l+1,to});
        }
        else
        if(used[to].F>(l+1)){
            used[to].F=l+1;
            used[to].S=used[v].S;
                    q.push({l+1,to});
        }
    }
    }
}

int main(){
    cin.tie(0);cout.tie(0);
    ios_base::sync_with_stdio(0);
    #ifdef LOL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #else
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    #endif

    int n,m;

    cin>>n>>m;

    used.resize(n);
    db.resize(n);

    for(int i=0;i<m;i++){
        int x,y;

        cin>>x>>y;
        x--;y--;

        g[x].pb(y);
        gpr[y].pb(x);
    }

    int len;

    cin>>len;

    path.resize(len);

    for(int i=0;i<len;i++){
        cin>>path[i];
        path[i]--;
    }
    used[path[len-1]].F=1;
    used[path[len-1]].S=1;
    dfs(path[len-1],1);

    vector<set<int> > kol;

    for(int i=0;i<n;i++){

    }

    int ansmi=0,ansma=0;

    for(int i=0;i<len-1;i++){
        if((used[path[i+1]].F+1)!=used[path[i]].F){
            ansmi++;
            ansma++;
        }
        else{
            int f=0;
            for(int j=0;j<g[path[i]].size();j++){
                int to=g[path[i]][j];
                if(to!=path[i+1] && used[to].F==used[path[i+1]].F){
                    f=1;
                }

            }
    if(f==1){
        ansma++;
    }
        }
    }
    cout<<ansmi<<' '<<ansma<<endl;

}


//CLOCKS_PER_SEC
using namespace std;
#include<bits/stdc++.h>
#define sqr(x) 1ll*(x)*(x)
//#define sort stable_sort
#define ll long long
#define mk make_pair
#define pb push_back
#define in insert
#define mtr(x,y,z) mk(mk(x,y),z)
#define fi first
#define se second
#define lch(x) ((x)<<1)
#define rch(x) (((x)<<1)|1)
#define all(x) (x).begin(),(x).end()
#define titose CLOCKS_PER_SEC
#define fpi(x) freopen(x,"r",stdin);
#define fpo(x) freopen(x,"w",stdout);
#define fprio fpi("in.txt");fpo("out.txt");
#define fast ios_base::sync_with_stdio(false);
inline void read(int &x){int v=0,f=1;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=(c&15);while (isdigit(c=getchar())) v=(v<<1)+(v<<3)+(c&15);x=v*f;}
inline void read(ll &x){ll v=0ll,f=1ll;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=(c&15);while (isdigit(c=getchar())) v=(v<<1)+(v<<3)+(c&15);x=v*f;}
inline void readc(char &x){char c;while (((c=getchar())==' ')||c=='\n');x=c;}
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define si set<int>
#define sl set<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define msi map<string,int>
#define msl map<string,ll>
#define piii pair<int,pii >
#define piipi pair<pii,int>
#define plll pair<ll,pll >
#define pllpl pair<pll,ll>
#define pqi priority_queue<int>
#define pql priority_queue<ll>
#define npqi priority_queue<int,vector<int>,greater<int> >
#define npql priority_queue<ll,vector<ll>,greater<ll> >
#define forup(i,a,b) for ((i)=(a);(i)<=(b);(i)++)
#define fordo(i,a,b) for ((i)=(a);(i)>=(b);(i)--)
#define rep(i,x) forup ((i),1,(x))
#define repd(i,x) fordo ((i),(x),1)
#define rep0(i,x) forup ((i),0,(x)-1)
#define rep0d(i,x) fordo ((i),((int)(x))-1,0)
#define itr iterator
#define fe(itcalc,c) for(__typeof((c).begin()) itcalc=(c).begin();itcalc!=(c).end();itcalc++)
#define NO {cout<<"NO";return 0;}
#define YES {cout<<"YES";return 0;}
#define y0 y000000000000000000000000000
#define y1 y111111111111111111111111111
#define j0 j000000000000000000000000000
#define j1 j111111111111111111111111111
#define cl0(a) memset((a),(0),(sizeof((a))))
#define clz(a) memset((a),(0x16),(sizeof((a))))
#define clf(a) memset((a),(-(0x16)),(sizeof((a))))
#define inf 0x3bbbbbbb
#define lnf 0x2bbbbbbbbbbbbbbbll
//#define sqrt divi
#define p2(i) (1ll<<(i))
#define readi read
#define readll read
/*************************************************/
const int mod=998244353,maxn=131072;
int n,m,i,j,g[50005],g0[50005],g1[50005],g2[50005],f0[50005],f1[50005],f2[50005],w[maxn+5],tmp[maxn+5],ans;
void solve(int l,int r)
{
	if(l==r){
		f0[l]=(f0[l]+g0[l])%mod;
		f1[l]=(f1[l]+g1[l])%mod;
		f2[l]=(f2[l]+g2[l])%mod;
		return;
	}
	int mid=(l+r)/2,i;
	solve(l,mid);
	poly_mul(f0+l,mid-l+1,g0,r-l+1,tmp+l,r-l+1);
	forup(i,mid+1,r) f0[i]=(f0[i]+tmp[i])%mod;
	poly_mul(f0+l,mid-l+1,g1,r-l+1,tmp+l,r-l+1);
	forup(i,mid+1,r) f1[i]=(f1[i]+tmp[i])%mod;
	poly_mul(f1+l,mid-l+1,g1,r-l+1,tmp+l,r-l+1);
	forup(i,mid+1,r) f0[i]=(f0[i]+tmp[i])%mod;
	forup(i,mid+1,r) f2[i]=(f2[i]+tmp[i])%mod;
	poly_mul(f1+l,mid-l+1,g2,r-l+1,tmp+l,r-l+1);
	forup(i,mid+1,r) f1[i]=(f1[i]+tmp[i])%mod;
	poly_mul(f2+l,mid-l+1,g2,r-l+1,tmp+l,r-l+1);
	forup(i,mid+1,r) f2[i]=(f2[i]+tmp[i])%mod;
	solve(mid+1,r);
}
int main()
{
	init();
	read(n);
	g[0]=g[2]=1;
	for(i=4;i<=n;i+=2){
		g[i]=(g[i-2]+g[i-4])%mod;
	}
	forup(i,1,n){
		g0[i]=1ll*(i-1)*(i-1)%mod*g[i-1]%mod;
	}
	forup(i,2,n){
		g1[i]=1ll*(i-1)*(i-1)%mod*g[i-1]%mod;
	}
	forup(i,3,n){
		g2[i]=1ll*(i-1)*(i-1)%mod*g[i-1]%mod;
	}
	solve(1,n);
	ans=1ll*n*(g0[n]+g2[n])%mod;
	for(i=2;i<=n-2;i+=2){
		ans=(ans+1ll*
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inp ll t; cin>>t; for(ll tt=1;tt<=t;tt++)
#define pb push_back
#define sz 100000

int main()
{
     ll n,b,i;
     cin>>n>>b;
     ll a[27];
     memset(a,0,sizeof(a));

     string s;
     cin>>s;
     for(i=0;i<s.size();i++)
          a[s[i]-97]++;
     sort(a,a+n);
     bool mik=true;
     for(i=0;i<26;i++)
     if(a[i]>b) mik=false;
     if(mik) cout<<"YES"<<endl;
     else cout<<"NO"<<endl;
}


#include <bits/stdc++.h>
#define cou pair<int,int>
#define trip pair<cou,int>
#define mp make_pair
#define fi first
#define se second
using namespace std;

map<cou,int> dp;
int n;
char c[101];

void bfs(int x,int y,int pos)
{
	queue<trip> q;
	q.push(mp(mp(x,y),pos));
	while(q.size())
	{
		int now_x=q.front().fi.fi,now_y=q.front().fi.se,now_pos=q.front().se;
		q.pop();
		for(int i=now_pos+1;i<=n;i++)
		{
			int cur_x=now_x,cur_y=now_y;
			if(c[i]=='U') cur_y=now_y+1;
			if(c[i]=='D') cur_y=now_y-1;
			if(c[i]=='L') cur_x=now_x-1;
			if(c[i]=='R') cur_x=now_x+1;
			int cost=dp[mp(now_x,now_y)]+1;
			if(dp[mp(cur_x,cur_y)]<=cost)
			{
				dp[mp(cur_x,cur_y)]=cost;
				q.push(mp(mp(cur_x,cur_y),i));
			}
		}
	}
}

int main()
{
	//freopen("i.inp","r",stdin);
	scanf("%d ",&n);
	for(int i=1;i<=n;i++) scanf("%c ",&c[i]);
	bfs(0,0,0);
	printf("%d ",dp[mp(0,0)]);
}


#include<iostream>//少剪枝
#include<cstdio>//循环太多，每次都要初始化一次
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
const int INF=1e9;
int a[41][41],n,m,ans;
int search(int x,int y)
{     bool f=false;int k=INF;
      for(int i=1;i<=n;i++){
         for(int j=1;j<=m;j++)
            if(a[i][j]==1){f=true;break;}
         if(f)break;}
      if(!f)return ans;
      ans++;
      a[x][y]=a[x-1][y]=a[x][y-1]=a[x+1][y]=a[x][y+1]=0;
      for(int i=1;i<=n;i++)
         for(int j=1;j<=m;j++){
         	k=min(search(i,j),k);}}
int main()
{     int i,j,k,minx=INF;
      cin>>n>>m;
      if(n==1&&m==1)cout<<0<<endl;
      else{
      for(i=1;i<=n;i++)
         for(j=1;j<=m;j++){
         	for(int w=1;w<=n;w++)
               for(int k=1;k<=m;k++)a[w][k]=1;
            ans=0;
         	int x=search(i,j);
            if(x<minx)minx=x;}
      cout<<m*n-minx<<endl;}
	  return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long int
#define sort(a) sort((a).begin(),(a).end());
#define rev(a) reverse((a).begin(),(a).end());
#define vec vector
#define str string
#define pb(a) .push_back((a));
using namespace std;
ull n,a,sum=0;
bool b[100000000];
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		while(1){
			if(b[a]==0){
				b[a]=1;
				sum+=a;
				break;
			}
			else a--;
		}
	}
	cout<<sum;
}


//#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define lng long long
using namespace std;

const int maxn = 3000;
lng dp[19][550][2550];
lng a, b;
int s[550], num[20], tot;

int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }

void init()
{
    for(int i = 1; i < 512; ++i)
    {
        s[i] = 1;
        for(int j = 2; j < 10; ++j)
        {
            if(i & (1 << (j - 1)))
            {
                s[i] = (s[i] * j) / gcd(s[i], j);
            }
        }
    }
}

lng dfs(int pos, int sta, int pre, int ok, int msta)
{
    if(pos == -1) return sta == msta && pre == 0;
    if((msta | sta) != msta) return 0;
    if(!ok && dp[pos][sta][pre] != -1) return dp[pos][sta][pre];
    lng ans = dfs(pos - 1, sta, (pre * 10) % s[msta], ok && num[pos] == 0, msta);
    int end = ok ? num[pos] : 9;
    for(int i = 1; i <= end; ++i)
    {
        int tpre = ((pre * 10) + i) % s[msta];
        ans += dfs(pos - 1, sta | (1 << (i - 1)), tpre, ok && i == end, msta);
    }
    if(!ok) dp[pos][sta][pre] = ans;
    return ans;
}

int count_bit(int n) { return n == 0 ? 0 : n % 2 + count_bit(n / 2); }

lng calc(lng n)
{
    tot = 0;
    while(n) { num[tot++] = n % 10; n /= 10; }
    lng ans = 0;
    for(int i = 1; i < 512; ++i)
    {
        if(count_bit(i) > tot) continue;
        for(int j = 0; j < tot; ++j)
        {
            for(int k = i; k; k = (k - 1) & i)
                for(int q = 0; q < s[i]; ++q) dp[j][k][q] = -1;
            for(int q = 0; q < s[i]; ++q) dp[j][0][q] = -1;
        }
        ans += dfs(tot - 1, 0, 0, 1, i);
    }
    return ans;
}

void prework()
{
    cin >> a >> b;
}

void solve()
{
    cout << calc(b) - calc(a - 1) << "\n";
}

int main()
{
    init();
    freopen("in.txt", "r", stdin);
    int t; cin >> t;
    while(t--)
    {
        prework();
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define mem(a, b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define DBG printf("this is a input\n")
const int MOD = 2520;
int indx[10000];
int num[50];
int dp[50][3000][3000];
ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

void Init()
{
    int cnt = 0;
    for(int i = 1 ; i <= MOD ; i ++)
    {
        if(MOD % i == 0)
            indx[i] = cnt ++;
    }
}
int dfs(int pos , int presum , int prelcm , int limit)
{
    if(pos == -1) return presum % prelcm == 0;
    if(limit && dp[pos][presum][indx[prelcm]]) return dp[pos][presum][indx[prelcm]];
    int maxn = limit ? num[pos] : 9;
    int ans = 0;
    for(int i = 0 ; i <= maxn ; i ++)
    {
        int nowlcm = prelcm;
        int nowsum = (presum*10 + i)%MOD;
        if(i)
            nowlcm = lcm(prelcm,i);
        ans += dfs(pos-1,nowsum,nowlcm,limit && i == num[pos]);

    }
    if(!limit) dp[pos][presum][indx[prelcm]] = ans;
    return ans;
}
int solve(int x)
{
    int len = 0;
    while(x)
    {
        num[len ++] = x % 10;
        x /= 10;
    }
    return dfs(len-1,0,1,true);
}
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin>>T;
    while(T --)
    {
        int n , m ;
        cin>>n>>m;
        cout<<solve(m)-solve(n-1)<<endl;
    }
}


#include <iostream>

#include <cstring>

#include <cstdio>

using namespace std;

long long a[22];

int hash[2522];

long long dp[22][2522][50];

int gcd(int a,int b)

{

    if(a<b)swap(a,b);

    while(b)

    {

        int w=a;

        a=b;

        b=w%b;

    }

    return a;

}

long long dpp(int pos,int sum,int b,int limit)

{

    if(pos==-1)return sum%b==0;

    if(!limit&&dp[pos][sum][hash[b]]!=-1)return dp[pos][sum][hash[b]];

    long long sun=0;

    int end=limit?a[pos]:9;

    for(int i=0;i<=end;i++)

    {   int q=b;

    if(i>=2)q=q*i/gcd(q,i);

        sun+=dpp(pos-1,(sum*10+i)%2520,q,limit&&i==a[pos]);

    }

    if(!limit)dp[pos][sum][hash[b]]=sun;

    return sun;

}

long  long go(long long x)

{

    int pos=0;

    while(x)

    {

        a[pos++]=x%10;

        x/=10;

    }

    return dpp(pos-1,0,1,1);

}

int main()

{

    long long n,m,t;

    int j;

    memset(dp,-1,sizeof(dp));

    for(int i=1,j=0;i<=2520;i++)

    {

        if(2520%i==0)hash[i]=j++;

    }

    scanf("%I64d",&t);

    while(t--)

    {   scanf("%I64d%I64d",&n,&m);

        printf("%I64d\n",go(m)-go(n-1));

    }

    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main (){
    int n, k, x, cnt, max=0;
    vector <int> c;
    cin >> n >> k >> x;
    for (int i=0 ; i<n ; i++){
        cin >> cnt;
        c.push_back(cnt);
    }
    for (unsigned int i=1 ; i<c.size()-1 ; i++)
        if (c[i]==c[i+1] && c[i]==x){
            vector <int> d;
            for (int j=0 ; j<n ; j++)
                d.push_back(c[j]);
            cnt=2;
            d.erase(d.begin()+i,d.begin()+(i+2));
            i++;
            for (unsigned int j=0 ; j<d.size()-2 && d.size()!=0; j++)
                if (d[j]==d[j+1] && d[j+1]==d[j+2]){
                    while (d[j+1]==d[j] && j<d.size()-1){
                        d.erase(d.begin()+j);
                        cnt++;
                    }
                    d.erase(d.begin()+j);
                    cnt++;
                    j=-1;
                }
            if (cnt>max)max=cnt;
        }
    cout << max;
    return 0;
}


#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <queue>
#include <string>
#include <map>
#include <fstream>
#include <hash_map>

#define input fstream fin( "input.txt" , ios :: in ) ;
#define output fstream fout( "output.txt" , ios :: out ) ;
#define FOR(s,x) for ( int i = s ; i < x ; i ++ )
#define FOR2(s,x) for ( long long j = s ; j < x ; j ++ )
#define FOR3(s,x) for ( long long r = s ; r < x ; r ++ )
#define FOI(s,x) for ( long long d = x ; d >= s ; d -- )
#define SZ  size()

#define S    begin()
#define E    end()
using namespace std;

long long n , m , res = 0  , sum = 0 , c = 0 , nm1 , nm2 , nm3;
long long mx = 0 , mn = INT_MAX ;

string s , s1 = "", s3;
long long x[1000000] , y[1000000];
int find(   vector<int> dist , int num ){

    FOR(0, dist.size())
        if ( num == dist[i])
            return i ;

    return -1 ;

}
int main(){

    cin >> n >> m >> nm2 ;
    vector <int> pos , nums , nums2;
    FOR ( 0 , n ){
        cin >> nm3 ;
        nums2.push_back(nm3);
        if ( nm2 == nm3 && pos.SZ == 0 )
            pos.push_back(i);

        else if ( nm2 == nm3 && nums2[i-1] != nm2  )
            pos.push_back(i);
    }
    FOR ( 0 , pos.SZ ){

        res = 0 ;
        nums = nums2 ;
        int b = pos[i] ;
        nm1 = 0 ;
        while ( nums[b] == nm2  ){
            nums.erase(nums.begin() + b , nums.begin() + b + 1);
            res ++ ;
            nm1 ++ ;
            if ( nums.SZ == 0 )
                break ;
        }

        if ( nm1 < 2 )
            continue ;
        if ( res > mx )
            mx = res ;

        while ( nums.SZ > 1 ){
            if ( b - 2 >= 0 ){

                if ( nums[b] == nums[b-2] && nums[b-1] == nums[b] )
                    b -= 2 ;

                else if ( nums[b] == nums[b-1] )
                    b -- ;

            }

            else if ( b - 1 >= 0 ){

                if ( nums[b] == nums[b-1] )
                    b -- ;

            }
            nm1 = 0 ;
            if ( b + 1 < nums.SZ  )
            while ( nums[b] == nums[b+1]  ){
            if ( b + 2 >= nums.SZ  && nums[b] == nums[b+1] )
                {

                   nm1 += 2 ;
                   res += 2 ;
                   nums.clear();
                   break ;
                }
            nums.erase(nums.begin() + b , nums.begin() + b + 1);
                res ++ ;
                nm1 ++ ;

                if ( nums[b+1] != nums[b] ){
                  nums.erase(nums.begin() + b , nums.begin() + b + 1);
                   res ++ ;
                   nm1 ++ ;
                   break;
                }
                if ( b + 1 >= nums.SZ  )
                    break;

            }

          if ( nm1 < 3 )
                break;
      }
        if ( nm1 < 3 )
            res -= nm1 ;
        if ( res > mx )
            mx = res ;

    }
    cout << mx ;
}


#include <iostream>

using namespace std;

int main()
{
    long long x;
   cin >>x;
   x+=1;
   if (x==1)
    cout << '0';
  else  if(x%2==0)
    cout <<x/2;
   else
    for (long long i=1;i<=x;i++)
    if ((2*i)%x==0)
   {
       cout<< i;
       return 0;
   }
}


#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string.h>
using namespace std;
int rook(int r1,int c1,int r2,int c2){
    if((r1==r2)||(c1==c2)){
        return 1;
    }
    else{
        return 2;
    }
}
int bishop(int r1,int c1,int r2,int c2){
    if(rook(r1,c1,r2,c2)==1){
        if(r1==r2){
            if(abs(c1-c2)%2==0){
                return 2;
            }
            else{
                return 0;
            }
        }
        else{
            if(abs(r1-r2)%2==0){
                return 2;
            }
            else{
                return 0;
            }
        }
    }
    float slope=((float)(c2-c1)/(r2-r1));
    int t1,t2,dir=0;
    t1=r1;
    t2=c1;
    if((slope==1)||(slope==-1)){
        return 1;
    }
    else{
        while(1<t1&&1<t2){
            t1--;
            t2--;
            if((r2-t1)!=0){
                slope=(float)(c2-t2)/(r2-t1);
                if((slope==1)||(slope==-1)){
                    return 2;
                }
            }
            if(rook(t1,t2,r2,c2)==1){
                if(t1==r2){
                    if(abs(t2-c2)%2==0){
                        return 2;
                    }
                    else{
                        return 0;
                    }
                }
                else{
                    if(abs(t1-r2)%2==0){
                        return 2;
                    }
                    else{
                        return 0;
                    }
                }
            }
        }
        t1=r1;
        t2=c1;
        while(t1<8&&t2<8){
            t1++;
            t2++;
            if((r2-t1)!=0){
                slope=(float)(c2-t2)/(r2-t1);
                if((slope==1)||(slope==-1)){
                    return 2;
                }
            }
            if(rook(t1,t2,r2,c2)==1){
                if(t1==r2){
                    if(abs(t2-c2)%2==0){
                        return 2;
                    }
                    else{
                        return 0;
                    }
                }
                else{
                    if(abs(t1-r2)%2==0){
                        return 2;
                    }
                    else{
                        return 0;
                    }
                }
            }
        }
        t1=r1;
        t2=c1;
        while(t1<8&&1<t2){
            t1++;
            t2--;
            if((r2-t1)!=0){
                slope=(float)(c2-t2)/(r2-t1);
                if((slope==1)||(slope==-1)){

                    return 2;
                }
            }
            if(rook(t1,t2,r2,c2)==1){
                if(t1==r2){
                    if(abs(t2-c2)%2==0){
                        return 2;
                    }
                    else{
                        return 0;
                    }
                }
                else{
                    if(abs(t1-r2)%2==0){
                        return 2;
                    }
                    else{
                        return 0;
                    }
                }
            }
        }
        t1=r1;
        t2=c1;
        while(1<t1&&t2<8){
            t1--;
            t2++;
            if((r2-t1)!=0){
                slope=(float)(c2-t2)/(r2-t1);
                if((slope==1)||(slope==-1)){
                    return 2;
                }
            }
            if(rook(t1,t2,r2,c2)==1){
                if(r1==r2){
                    if(abs(c1-c2)%2==0){
                        return 2;
                    }
                    else{
                        return 0;
                    }
                }
                else{
                    if(abs(r1-r2)%2==0){
                        return 2;
                    }
                    else{
                        return 0;
                    }
                }
            }
        }
    }
    return 0;
}

int king(int r1,int c1,int r2,int c2){
    int c=0;
    if(rook(r1,c1,r2,c2)==1){
        if(r1==r2){
            if(c1>c2){
                return (c1-c2);
            }
            else{
                return (c2-c1);
            }
        }
        else if(c1==c2){
            if(r1>r2){
                return (r1-r2);
            }
            else{
                return (r2-r1);
            }
        }
    }
    else if(bishop(r1,c1,r2,c2)==1){
        if((r2>r1)&&(c2>c1)){
            while((r1!=r2)&&(c1!=c2)){
                r1++;
                c1++;
                c++;
            }
        }
        else if((r2>r1)&&(c1>c2)){
            while((r1!=r2)&&(c1!=c2)){
                r1++;
                c1--;
                c++;
            }
        }
        else if((r1>r2)&&(c2>c1)){
            while((r1!=r2)&&(c1!=c2)){
                r1--;
                c1++;
                c++;
            }
        }
        else if((r1>r2)&&(c1>c2)){
            while((r1!=r2)&&(c1!=c2)){
                r1--;
                c1--;
                c++;
            }
        }
        return c;
    }
    else{
        if((r2>r1)&&(c2>c1)){
            while((r1!=r2)&&(c1!=c2)){
                r1++;
                c1++;
                c++;
            }
            if(r1==r2){
                c = c + abs(c1-c2);
            }
            else{
                c = c + abs(r1-r2);
            }
        }
        else if((r2>r1)&&(c1>c2)){
            while((r1!=r2)&&(c1!=c2)){
                r1++;
                c1--;
                c++;
            }
            if(r1==r2){
                c = c + abs(c1-c2);
            }
            else{
                c = c + abs(r1-r2);
            }
        }
        else if((r1>r2)&&(c2>c1)){
            while((r1!=r2)||(c1!=c2)){
                r1--;
                c1++;
                c++;
            }
            if(r1==r2){
                c = c + abs(c1-c2);
            }
            else{
                c = c + abs(r1-r2);
            }
        }
        else if((r1>r2)&&(c1>c2)){
            while((r1!=r2)||(c1!=c2)){
                r1--;
                c1--;
                c++;
            }
            if(r1==r2){
                c = c + abs(c1-c2);
            }
            else{
                c = c + abs(r1-r2);
            }
        }
        return c;
    }
}

int main(){
int r1,c1,r2,c2;
cin>>r1>>c1>>r2>>c2;
cout<<rook(r1,c1,r2,c2)<<" ";
cout<<bishop(r1,c1,r2,c2)<<" ";
cout<<king(r1,c1,r2,c2)<<" ";
return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <algorithm>
#include <queue>
#include <unordered_map>
using namespace std;

#define mod 1000000007

typedef long long int lli;

int getMax(int a,int b){
    return (a>b)?a:b;
}

int getMin(int a,int b){
    return (a<b)?a:b;
}

lli getRes(int n){
    queue<string> q;
    q.push("7");
    //q.push("8");
    lli res = 1;
    while(!q.empty()){
        string t = q.front();
        q.pop();
        if(t.size()+1 <= n){
            q.push(t+"7");
            q.push(t+"8");
            res += 2;
        }
    }
    return 2*res;
}

int main(){
    int n;
    cin>>n;
    cout<<getRes(n);
    //lli a = dfs("7",n);
    //lli b =
    return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main ()
{
	int p1,g1;
	int p2,g2;
	int hour,minute;
	int sum1,sum2,sum3=300;
	int num=0;
	char ch;
	cin>>p1>>g1;
	cin>>p2>>g2;
	cin>>hour>>ch>>minute;
	sum1=hour*60+minute;
	sum2=sum1+g1;
	while(sum3<sum2)
	{
		if(sum3+g2>=sum1)
		{
			num++;
			sum3+=p1;
		}
	}
	cout<<num<<endl;
	return 0;

}


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

int a, b, c, d, x, y, z;

int yy() {
	bool w1, w2;
	if(a % 2 && b % 2) w1 = 1;
	else if(a % 2 == 0 && b % 2 == 0) w1 = 1;
	else w1 = 0;
	if(c % 2 && d % 2) w2 = 1;
	else if(c % 2 == 0 && d % 2 == 0) w2 = 1;
	else w2 = 0;
	if(w1 != w2) return 0;
	for(int i = a, j = b; i > 0 && j > 0; i--, j--)
		if(i == c && j == d) return 1;
	for(int i = a, j = b; i <= 8 && j <= 8; i++, j++)
		if(i == c && j == d) return 1;
	for(int i = a, j = b; i <= 8 && j > 0; i++, j--)
		if(i == c && j == d) return 1;
	for(int i = a, j = b; i > 0 && j <= 8; i--, j++)
		if(i == c && j == d) return 1;
	return 2;
}

int g(int aa, int bb, int v) {
	int ret;
	if(aa == c && bb == d) return v;
	if(aa < c && bb < d) ret = g(aa+1, bb+1, v+1);
	if(aa > c && bb > d) ret = g(aa-1, bb-1, v+1);
	if(aa < c && bb > d) ret = g(aa+1, bb-1, v+1);
	if(aa > c && bb < d) ret = g(aa-1, bb+1, v+1);
	if(aa == c && bb > d) ret = g(a, bb-1, v+1);
	if(aa == c && bb < d) ret = g(a, bb+1, v+1);
	if(aa > c && bb == d) ret = g(a-1, bb, v+1);
	if(aa < c && bb == d) ret = g(a+1, bb, v+1);
	return ret;
}

int main() {
	cin >> a >> b >> c >> d;
	x = !(a == c) + !(b == d);
	y = yy();
	z = g(a, b, 0);
	cout << x << " " << y << " " << z << endl;
}


#include <iostream>
#include <vector>

#define M 100100
#define pb push_back

using namespace std;

long n,m;
vector<long> g[M],d[M],f(M);
vector<bool> u(M,0),c(M,0),t(M,0);

void read(void){
    long a,b;
    cin>>n>>m;
    for(long i=1; i<=n; ++i)
    cin>>f[i];
    for (long i=0; i<m; ++i){
        cin>>a>>b;
        g[a].pb(b);
        d[b].pb(a);
    }
}

void dfs(long v){
    c[v]=1;
    u[v]=1;
    for (long i=0; i<g[v].size(); ++i)
    if (!u[g[v][i]])
    dfs(g[v][i]);
}

void dfs1(long v){
    t[v]=1;
    u[v]=1;
    if (f[v]!=1)
    for (long i=0; i<d[v].size(); ++i)
    if (!u[d[v][i]])
    dfs1(d[v][i]);
}

int main()
{
    read();
    for (long i=1; i<=n; ++i)
    if (f[i]==1 && !c[i])
    dfs(i);
    fill(u.begin(), u.end(), 0);
    for (long i=1; i<=n; ++i)
    if (f[i]==2 && !t[i]){
    dfs1(i);
    for (long i=1; i<=n; ++i)
    if (c[i] && t[i])
    cout<<1<<"\n";
    else
    cout<<0<<"\n";
    return 0;
}