/* Aditya0412 */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define all(a)      (a).begin(),(a).end()
#define si(x)       (int)((x).size())
#define debug(x)    cout<<#x<<" is "<<(x)<<endl;cout.flush();  
#define se second 
#define endl        '\n'
#define f(i,a,b)    for(int i=a;i<b;i++)
#define mem(a,x)          memset(a,x,sizeof(a))

// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
    os<<"[";
    for(auto& x:v){os<<x<<", ";}
    return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
    return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===


// const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=1000000+6;
#define M_PI           3.14159265358979323846
void inp(ll *arr,ll n)
{
  for(int i=0;i<n;i++)
    cin>>arr[i];
}
void inp_mat(ll *arr,ll n,ll m)
{
    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
        {
          ll x;cin>>x;
          *((arr+i*m) + j)=x;
        }
}
// syntax for inp_mat inp_mat((ll *)arr,n,m);
// int x2[]={+1,-1,+0,+0};
// int y2[]={+0,+0,+1,-1};
ll fact[N];
ll M=mod;
ll inv[3000000+5],fac_inv[3000000+5],fac[3000000+5];
void initialize()
{
	ll i;
	inv[1]=1;
	for(i=2;i<=3000000;i++)
		inv[i]=(M-M/i)*inv[M%i]%M; 
	fac[0]=fac[1]=1;
	for(i=2;i<=3000000;i++)
		fac[i]=i*fac[i-1]%M;
	fac_inv[0]=fac_inv[1]=1;
	for(i=2;i<=3000000;i++)
		fac_inv[i]=inv[i]*fac_inv[i-1]%M;
}

ll ncr(ll n,ll r)
{
	if(n<r) return 0;
	return (fac[n]*fac_inv[r]%M)*fac_inv[n-r]%M;
}
int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //  #ifndef ONLINE_JUDGEc
    //   freopen ("INPUT.txt" , "r" , stdin);
    //   freopen ("OUTPUT.txt", "w" , stdout);
    // #endif 
    int t=1;
    // cin>>t;
    while(t--)
    {
      ll n,m;cin>>n>>m;
      initialize();
      fact[0]=1;fact[1]=1;
      f(i,2,N)
      {
        fact[i]=(fact[i-1]*i)%mod;

      }
      ll ans=0;
      for(ll j=0;j<=n;j++)
      {
        if(j%2==0)
        {
          //+
          ll temp=1;
          temp*=(ncr(n,j));
          temp%=mod;
          temp*=(ncr(m-j,n-j));
          temp%=mod;
          temp*=(fact[n-j]);
          temp%=mod;
        ans+=(temp);
        ans%=mod;
        }
        else
        {
          //-
          
          ll temp=1;
          temp*=(ncr(n,j));
          temp%=mod;
          temp*=(ncr(m-j,n-j));
          temp%=mod;
          temp*=(fact[n-j]);
          temp%=mod;
        ans-=(temp);
        ans+=mod;
        ans%=mod;
        }
        
      }
      dbg(ans);
      ans*=ncr(m,n);
      ans%=mod;
      ans*=fact[n];
      ans%=mod;
      cout<<ans;
    }    
} 

Measured memory_bytes: 81748