Problem:
Balls and Boxes 3
Balls
Boxes
Any way
At most one ball
At least one ball
Distinguishable
Distinguishable
1
2
3
Indistinguishable
Distinguishable
4
5
6
Distinguishable
Indistinguishable
7
8
9
Indistinguishable
Indistinguishable
10
11
12
Problem
You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.
Find the number of ways to put the balls under the following conditions:
Each ball is distinguished from the other.
Each box is distinguished from the other.
Each ball can go into only one box and no one remains outside of the boxes.
Each box must contain at least one ball.
Note that you must print this count modulo $10^9+7$.
Input
$n$ $k$
The first line will contain two integers $n$ and $k$.
Output
Print the number of ways modulo $10^9+7$ in a line.
Constraints
$1 \le n \le 1000$
$1 \le k \le 1000$
Sample Input 1
4 3
Sample Output 1
36
Sample Input 2
10 3
Sample Output 2
55980
Sample Input 3
100 100
Sample Output 3
437918130

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
#line 2 "modint/montgomery-modint.hpp"

template <uint32_t mod>
struct LazyMontgomeryModInt {
  using mint = LazyMontgomeryModInt;
  using i32 = int32_t;
  using u32 = uint32_t;
  using u64 = uint64_t;

  static constexpr u32 get_r() {
    u32 ret = mod;
    for (i32 i = 0; i < 4; ++i) ret *= 2 - mod * ret;
    return ret;
  }

  static constexpr u32 r = get_r();
  static constexpr u32 n2 = -u64(mod) % mod;
  static_assert(mod < (1 << 30), "invalid, mod >= 2 ^ 30");
  static_assert((mod & 1) == 1, "invalid, mod % 2 == 0");
  static_assert(r * mod == 1, "this code has bugs.");

  u32 a;

  constexpr LazyMontgomeryModInt() : a(0) {}
  constexpr LazyMontgomeryModInt(const int64_t &b)
      : a(reduce(u64(b % mod + mod) * n2)){};

  static constexpr u32 reduce(const u64 &b) {
    return (b + u64(u32(b) * u32(-r)) * mod) >> 32;
  }

  constexpr mint &operator+=(const mint &b) {
    if (i32(a += b.a - 2 * mod) < 0) a += 2 * mod;
    return *this;
  }

  constexpr mint &operator-=(const mint &b) {
    if (i32(a -= b.a) < 0) a += 2 * mod;
    return *this;
  }

  constexpr mint &operator*=(const mint &b) {
    a = reduce(u64(a) * b.a);
    return *this;
  }

  constexpr mint &operator/=(const mint &b) {
    *this *= b.inverse();
    return *this;
  }

  constexpr mint operator+(const mint &b) const { return mint(*this) += b; }
  constexpr mint operator-(const mint &b) const { return mint(*this) -= b; }
  constexpr mint operator*(const mint &b) const { return mint(*this) *= b; }
  constexpr mint operator/(const mint &b) const { return mint(*this) /= b; }
  constexpr bool operator==(const mint &b) const {
    return (a >= mod ? a - mod : a) == (b.a >= mod ? b.a - mod : b.a);
  }
  constexpr bool operator!=(const mint &b) const {
    return (a >= mod ? a - mod : a) != (b.a >= mod ? b.a - mod : b.a);
  }
  constexpr mint operator-() const { return mint() - mint(*this); }
  constexpr mint operator+() const { return mint(*this); }

  constexpr mint pow(u64 n) const {
    mint ret(1), mul(*this);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  constexpr mint inverse() const {
    int x = get(), y = mod, u = 1, v = 0, t = 0, tmp = 0;
    while (y > 0) {
      t = x / y;
      x -= t * y, u -= t * v;
      tmp = x, x = y, y = tmp;
      tmp = u, u = v, v = tmp;
    }
    return mint{u};
  }

  friend ostream &operator<<(ostream &os, const mint &b) {
    return os << b.get();
  }

  friend istream &operator>>(istream &is, mint &b) {
    int64_t t;
    is >> t;
    b = LazyMontgomeryModInt<mod>(t);
    return (is);
  }

  constexpr u32 get() const {
    u32 ret = reduce(a);
    return ret >= mod ? ret - mod : ret;
  }

  static constexpr u32 get_mod() { return mod; }
};
using ll=long long;
using ull=unsigned long long;
constexpr int MOD=1'000'000'007;
using mint=LazyMontgomeryModInt<MOD>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define loop(n) for (int tjh = 0; tjh < (int)(n); ++tjh)
constexpr int maxn=1000;
constexpr array<mint,maxn+1>mkfac() {
  array<mint,maxn+1>res;
  res[0]=1;
  rep(i,maxn)res[i+1]=res[i]*(i+1);
  return res;
}
constexpr auto fac=mkfac();
constexpr array<mint,maxn+1>mkinv() {
  array<mint,maxn+1>res;
  res[maxn]=mint(1)/fac[maxn];
  for (int i=maxn;i--;) {
    res[i]=res[i+1]*(i+1);
  }
  return res;
}
constexpr auto invfac=mkinv();
array<array<mint,maxn+1>,maxn+1>dp;
signed main() {
  cin.tie(0)->sync_with_stdio(0);
  cout<<fixed<<setprecision(16);
  int n,k;cin>>n>>k;
  if (n<k){cout<<0<<'\n';return 0;}
  dp[0][0]=mint(1);
  for (int i=1;i<=n;++i)dp[i][1]=mint(1);
  for (int i=2;i<=n;++i)for (int j=2;j<=min(i,k);++j) {
    for (int l=1;l<=i-(j-1);++l) {
      dp[i][j]+=dp[i-l][j-1]*fac[i]*invfac[i-l]*invfac[l];
    }
  }
  cout<<dp[n][k]<<'\n';
}
accuracy: 1
time_ms: 360
memory_kb: 7552
final_rank: 15

code_snippet: #include "bits/stdc++.h"
using namespace std;
using ll = long long;
ll MOD = 1000000007;

ll binexp(ll a, ll b, ll m) {
    if (b == 0) return 1;
    if (b == 1) return a;
    ll r = binexp(a, b / 2, m);
    r = (r * r) % m;
    if (b % 2) r = (r * a) % m;
    return r;
}

ll inv(ll x, ll m) {
    return binexp(x, m - 2, m);
}

ll C(ll n, ll r, ll m) {
    if (r == 0) return 1;
    return (((n * C(n - 1, r - 1, m)) % m) * inv(r, m)) % m;
}

int main() {
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    for (ll i = 0; i <= k; i++) {
        ll x = (C(k, i, MOD) * binexp(k - i, n, MOD)) % MOD;
        if (i % 2 == 0) ans = (ans + x) % MOD;
        else ans = (ans - x + MOD) % MOD;
    }
    cout << ans << '\n';
}
accuracy: 1
time_ms: 220
memory_kb: 3468
final_rank: 12

code_snippet: /*
    Created by Pujx on 2024/8/4.
*/
#pragma GCC optimize(2, 3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
//#define int long long
//#define double long double
using i64 = long long;
using ui64 = unsigned long long;
//using i128 = __int128;
#define inf (int)0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define yn(x) cout << (x ? "yes" : "no") << endl
#define Yn(x) cout << (x ? "Yes" : "No") << endl
#define YN(x) cout << (x ? "YES" : "NO") << endl
#define mem(x, i) memset(x, i, sizeof(x))
#define cinarr(a, n) for (int _ = 1; _ <= n; _++) cin >> a[_]
#define cinstl(a) for (auto& _ : a) cin >> _
#define coutarr(a, n) for (int _ = 1; _ <= n; _++) cout << a[_] << " \n"[_ == n]
#define coutstl(a) for (const auto& _ : a) cout << _ << ' '; cout << endl
#define all(x) (x).begin(), (x).end()
#define ls (s << 1)
#define rs (s << 1 | 1)
#define ft first
#define se second
#define pii pair<int, int>
#ifdef DEBUG
    #include "debug.h"
#else
    #define dbg(...) void(0)
#endif

const int N = 2000 + 5;
//const int M = 1e5 + 5;
//const int mod = 998244353;
const int mod = 1e9 + 7;
//template <typename T> T ksm(T a, i64 b) { T ans = 1; for (; b; a = 1ll * a * a, b >>= 1) if (b & 1) ans = 1ll * ans * a; return ans; }
//template <typename T> T ksm(T a, i64 b, T m = mod) { T ans = 1; for (; b; a = 1ll * a * a % m, b >>= 1) if (b & 1) ans = 1ll * ans * a % m; return ans; }

int a[N];
int n, m, t, k, q;

template <int P> struct MInt {
    int x;
    MInt() : x(0) {}
    MInt(const signed& x) : x(norm(x % getMod())) {}
    MInt(const long long& x) : x(norm(x % getMod())) {}

    static int Mod;
    static int getMod() { return P > 0 ? P : Mod; }
    static void setMod(int _Mod) { Mod = _Mod; }
    int norm(const int& x) const { return x < 0 ? x + getMod() : (x >= getMod() ? x - getMod() : x); }
    int val() const { return x; }
    explicit operator int() const { return x; }
    MInt operator - () const { MInt res; res.x = norm(getMod() - x); return res; }
    MInt ksm(const long long& x) const {
        MInt a = *this, ans = 1;
        for (long long pw = x; pw; a *= a, pw >>= 1) if (pw & 1) ans *= a;
        return ans;
    }
    MInt inv() const { assert(x != 0); return ksm(getMod() - 2); }
    MInt& operator += (const MInt& b) & { x = norm(x + b.x); return *this; }
    MInt& operator -= (const MInt& b) & { x = norm(x - b.x); return *this; }
    MInt& operator *= (const MInt& b) & { x = norm(1ll * x * b.x % getMod()); return *this; }
    MInt& operator /= (const MInt& b) & { return *this *= b.inv(); }
    MInt& operator ++ () & { return *this += 1; }
    MInt& operator -- () & { return *this -= 1; }
    const MInt operator ++ (signed) { MInt old = *this; ++(*this); return old; }
    const MInt operator -- (signed) { MInt old = *this; --(*this); return old; }
    friend MInt operator + (const MInt& a, const MInt& b) { MInt res = a; res += b; return res; }
    friend MInt operator - (const MInt& a, const MInt& b) { MInt res = a; res -= b; return res; }
    friend MInt operator * (const MInt& a, const MInt& b) { MInt res = a; res *= b; return res; }
    friend MInt operator / (const MInt& a, const MInt& b) { MInt res = a; res /= b; return res; }
    friend istream& operator >> (istream& in, MInt& a) { long long v; in >> v; a = MInt(v); return in; }
    friend ostream& operator << (ostream& out, const MInt& a) { return out << a.val(); }
    friend bool operator == (const MInt& a, const MInt& b) { return a.val() == b.val(); }
    friend bool operator != (const MInt& a, const MInt& b) { return a.val() != b.val(); }
    friend bool operator < (const MInt& a, const MInt& b) { return a.val() < b.val(); }
    friend bool operator > (const MInt& a, const MInt& b) { return a.val() > b.val(); }
    friend bool operator <= (const MInt& a, const MInt& b) { return a.val() <= b.val(); }
    friend bool operator >= (const MInt& a, const MInt& b) { return a.val() >= b.val(); }
};
using Mint = MInt<mod>;
template<> int MInt<0>::Mod = 1;

Mint fac[N], c[N][N], s[N][N], p[N][N];

void init() {
    fac[0] = 1, c[0][0] = s[0][0] = p[0][0] = 1;
    for (int i = 1; i <= 2000; i++) {
        fac[i] = fac[i - 1] * i;
        c[i][0] = 1, s[i][0] = p[i][0] = 0;
        for (int j = 1; j <= i; j++) {
            c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
            s[i][j] = s[i - 1][j - 1] + j * s[i - 1][j];
            p[i][j] = p[i - 1][j - 1] + p[i - j][j];
        }
    }
}

void work() {
    cin >> n >> k;
    t = 3;
    if (t == 1) {
        cout << Mint(k).ksm(n) << endl;
    }
    else if (t == 2) {
        cout << fac[n] * c[k][n] << endl;
    }
    else if (t == 3) {
        cout << fac[k] * s[n][k] << endl;
    }
    else if (t == 4) {
        cout << c[n + k - 1][k - 1] << endl;
    }
    else if (t == 5) {
        cout << c[k][n] << endl;
    }
    else if (t == 6) {
        cout << c[n - 1][k - 1] << endl;
    }
    else if (t == 7) {
        Mint ans = 0;
        for (int i = 1; i <= k; i++)
            ans += s[n][i];
        cout << ans << endl;
    }
    else if (t == 8) {
        cout << (k >= n) << endl;
    }
    else if (t == 9) {
        cout << s[n][k] << endl;
    }
    else if (t == 10) {
        cout << p[n + k][k] << endl;
    }
    else if (t == 11) {
        cout << (k >= n) << endl;
    }
    else {
        cout << p[n][k] << endl;
    }
}

signed main() {
#ifdef LOCAL
    freopen("C:\\Users\\admin\\CLionProjects\\Practice\\data.in", "r", stdin);
    freopen("C:\\Users\\admin\\CLionProjects\\Practice\\data.out", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    init();
    int Case = 1;
    //cin >> Case;
    while (Case--) work();
    return 0;
}
/*
     _____   _   _       _  __    __
    |  _  \ | | | |     | | \ \  / /
    | |_| | | | | |     | |  \ \/ /
    |  ___/ | | | |  _  | |   }  {
    | |     | |_| | | |_| |  / /\ \
    |_|     \_____/ \_____/ /_/  \_\
*/
accuracy: 1
time_ms: 20
memory_kb: 50612
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef pair<ll,ll> pi;
typedef pair<ll,pi> ppi;
#define FOR(i,l,r) for(ll i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,l,r) for(ll i=r-1;i>=l;i--)
#define RREP(i,n) RFOR(i,0,n)
#define sz(A) (ll)(A.size())
#define ALL(A) A.begin(),A.end()
#define LB(A,x) (ll)(lower_bound(ALL(A),x)-A.begin())
#define UB(A,x) (ll)(upper_bound(ALL(A),x)-A.begin())
#define COU(A,x) (UB(A,x)-LB(A,x))
#define F first
#define S second
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.F<<" "<<p.S;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.F>>p.S;return is;}
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){REP(i,sz(v))os<<v[i]<<(i+1!=sz(v)?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<class T>bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,T b){if(b<a){a=b;return 1;}return 0;}
const ll mod=998244353;
template<const long long int mod=998244353>
struct modint{
  using mint=modint<mod>;
  long long int x;
  modint(long long int _x=0):x(_x%mod){if(x<0)x+=mod;}
  long long int val(){return x;}
  mint&operator=(const mint&a){x=a.x;return *this;}
  mint&operator+=(const mint&a){x+=a.x;if(x>=mod)x-=mod;return *this;}
  mint&operator-=(const mint&a){x-=a.x;if(x<0)x+=mod;return *this;}
  mint&operator*=(const mint&a){x*=a.x;x%=mod;return *this;}
  friend mint operator+(const mint&a,const mint&b){return mint(a)+=b;}
  friend mint operator-(const mint&a,const mint&b){return mint(a)-=b;}
  friend mint operator*(const mint&a,const mint&b){return mint(a)*=b;}
  mint operator-()const{return mint(0)-*this;}
  mint pow(long long int n){
    if(!n)return 1;
    mint a=1;
    mint _x=x;
    while(n){
      if(n&1)a*=_x;
      _x=_x*_x;n>>=1;
    }
    return a;
  }
  mint inv(){return pow(mod-2);}
  mint&operator/=(mint&a){return *this*=a.inv();}
  friend mint operator/(const mint&a,mint b){return mint(a)/=b;}
};
ll pow_mod(ll a,ll n,ll m){
  ll res=1%m;
  a%=m;
  while(n){
    if(n%2)res=res*a%m;
    a=a*a%m;n/=2;
  }
  if(res<0)res+=m;
  return res;
}
template<typename T>
struct fenwick_tree{
    private:
    vector<T>tree;
    T sum_from_zero(int i){
        i++;
        T s=0;
        while(i){
            s+=tree[i];
            i-=i&-i;
        }
        return s;
    }
    public:
    fenwick_tree(size_t N):tree(vector<T>(N+1)){}
    T sum(int l,int r){
        assert(0<=l&&l<=r&&r<=tree.size());
        return sum_from_zero(r-1)-sum_from_zero(l-1);
    }
    T get(int i){
        assert(0<=i&&i<tree.size());
        return sum(i,i+1);
    }
    void add(int i,T x){
        assert(0<=i&&i<tree.size());
        i++;
        while(i<tree.size()){
            tree[i]+=x;
            i+=i&-i;
        }
    }
    void print(){
        for(auto i:tree)cout<<i<<" ";cout<<endl;
    }
};
//using mint=modint<998244353>;
using mint=modint<1000000007>;
int main(){
    ll N,K;cin>>N>>K;
    mint ans=0;
    vector<mint>ex(2e6,1),r(2e6);
    FOR(i,1,2e6)ex[i]=i*ex[i-1];
    REP(i,2e6)r[i]=1/ex[i];
    FOR(i,1,K+1)ans+=((K-i)%2?-1:1)*pow_mod(i,N,1000000007)*ex[K]*r[i]*r[K-i];
    cout<<ans.val()<<endl;
    return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 34436
final_rank: 16

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

#define int long long
#define all(x) x.begin(), x.end()

using namespace __gnu_pbds; using namespace std;

template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update>; template<class T> using ordered_multiset = tree<T, null_type , less_equal<T> , rb_tree_tag , tree_order_statistics_node_update>; typedef long long ll;  typedef pair<int, int> ii;  typedef tuple<int, int, int> iii; typedef tuple<int, int, int, int> iiii; typedef vector<int> vi; 
const ll oo = 1987654321987654321;

template<class It> void db(It b, It e) { for (auto it = b; it != e; it++) cout << *it << ' '; cout<< endl; } template<typename A> istream& operator>>(istream& fin, vector<A>& v) { for (auto it = v.begin(); it != v.end(); ++it) fin >> *it; return fin; } template<typename A, typename B> istream& operator>>(istream& fin, pair<A, B>& p){ fin >> p.first >> p.second; return fin; } template<typename T> void chmin(T &a, T b){ a = min(a, b); } template<typename T> void chmax(T &a, T b){ a = max(a, b); }


int n, k;
const int P = 1e9 + 7;
const int MAX = 1002;
int memo[MAX][MAX];
int fat[MAX];
int invfat[MAX];

int expbin(ll a, ll b) {
  if (b == 0) return 1;
  if (b & 1) return (a%P * expbin(a, b - 1))%P;
  int tmp = expbin(a, b / 2);
  return (tmp * tmp)%P;
}


int nchoosek(int n, int k){
    return ((fat[n]  * invfat[k])%P * invfat[n - k])%P;
}

int dp(int i = 0, int j = 0){
    if (i == k){
        return j == 0;
    }
    int &ans = memo[i][j];
    if (ans != -1) return ans;
    ans = 0;
    for (int qt=1; qt <= j; qt++){
        ans += dp(i + 1, j - qt) * nchoosek(j, qt);
        ans %= P;
    }
    return ans;
}

signed main(){
    cin.tie(0)->sync_with_stdio(0);
    memset(memo, -1, sizeof(memo));
    cin >> n >> k;
 
    fat[0] = 1;
    for (int i = 1; i < MAX; i++) {
      fat[i] = (fat[i - 1] * i)%P;
    }

    invfat[MAX - 1] = expbin(fat[MAX - 1], P - 2);
    for (int i = MAX - 1; i >= 1; i--) {
      invfat[i - 1] = (invfat[i] * (i))%P;
    }


    cout << dp(0, n) << "\n";
}
accuracy: 1
time_ms: 630
memory_kb: 11432
final_rank: 19

code_snippet: #define _USE_MATH_DEFINES  // M_PI等のフラグ
#include <bits/stdc++.h>
#define MOD 1000000007
#define COUNTOF(array) (sizeof(array)/sizeof(array[0]))
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define intceil(a,b) ((a+(b-1))/(b))
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<long,long>;
const long long INF = LONG_LONG_MAX - 1001001001001001;
void chmax(ll& x, ll y) { x = max(x,y); }
void chmin(ll& x, ll y) { x = min(x,y); }
string vs = "URDL";  // 上右下左
vector<ll> vy = { -1, 0, 1, 0 };
vector<ll> vx = { 0, 1, 0, -1 };


/** 自動でMODをとるModInt型
 *
 * Usage
 *   // 基本的な使い方
 *   mint a, b;
 *   a = 100;
 *   b = a + MOD;
 *   // istreamとostreamをオーバロードしてるので、mint型も普通に入出力できる
 *   cout << b << endl;  // 100
 *   // 明示的にlong long型を出力するときは.xを参照する
 *   cout << b.x << endl;  // 100
 *
 * References
 *  https://youtu.be/L8grWxBlIZ4?t=9858
 *  https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
 *  https://youtu.be/8uowVvQ_-Mo?t=1329 : division
 */
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime MOD
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
    bool operator<=(const mint a) const { return mint(*this) <= a; }
    bool operator<(const mint a) const { return mint(*this) < a; }
    bool operator>=(const mint a) const { return mint(*this) >= a; }
    bool operator>(const mint a) const { return mint(*this) > a; }
    bool operator==(const mint a) const { return mint(*this) == a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

/**
 * @brief mintを使った高速なnCr計算
 *
 * @tparam T
 *
 * @details
 *  O(n)で前計算を構築し、nCrのクエリにO(1)で応答する
 *
 *  * 0!, 1!, ..., (n-1)!, n!
 *  * 1/n!, 1/(n-1)!, ..., 1/0!
 *  のテーブルをそれぞれO(n)で構築する。
 *
 *  それにより nCr = n!/(r!*(n-r)!) のクエリにO(1)で応答できる
 *
 * @usage
 *  combination_mint_builder<ll> c(1e6);
 *  mint ans = c(6,2);  // 6C2
 */
template <typename T>
struct combination_mint_builder {
    vector<mint> fact, ifact;
    combination_mint_builder(T n) {
        assert(n < MOD);
        fact.resize(n+1); ifact.resize(n+1);
        fact[0] = 1;
        for(T i=1; i<=n; i++) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for(T i=n; i>=1; i--) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(T n, T r) {
        if (r<0 || r>n) return 0;
        return fact[n]*ifact[r]*ifact[n-r];
    }
};
combination_mint_builder<ll> combo(1e6);

void solve() {
    ll N, K; cin >> N >> K;

    // i個の箱にボールを入れない場合の数を数える
    mint notAns = 0;
    for(ll i=1; i<=K-1; i++) {
        mint val = combo(K,i) * mint(K-i).pow(N);
        if (i%2 == 0) notAns -= val;
        else notAns += val;
    }

    // 全事象
    mint all = mint(K).pow(N);

    // 余事象を求める
    mint ans = all - notAns;
    cout << ans << endl;
}


int main() {
    solve();
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 18812
final_rank: 11

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numeric>
#include <optional>

using namespace std;

#define rep(i, x) for (ll i = 0; i < (x); i++)
#define rep1(i, x) for (ll i = 1; i <= (x); i++)
#define rep_i(i, j, x) for (ll i = j; i < (x); i++)
#define rep_inv(i, x) for (ll i = (x)-1; i >= 0; i--)
#define rep_inv1(i, x) for (ll i = (x); i >= 1; i--)
#define rep_inv_i(i, j, x) for (ll i = (x)-1; i >= j; i--)
#define all(a) a.begin(), a.end()
#define input(a)                                                                                   \
    a;                                                                                             \
    cin >> a;
#define input2(a, b)                                                                               \
    a, b;                                                                                          \
    cin >> a >> b;
#define input3(a, b, c)                                                                            \
    a, b, c;                                                                                       \
    cin >> a >> b >> c;

#define vec_in(a, N)                                                                               \
    a(N);                                                                                          \
    rep(i, N) {                                                                                    \
        cin >> a[i];                                                                               \
    }
#define rep2(i, j, x, y)                                                                           \
    for (ll i = 0; i < x; ++i)                                                                     \
        for (ll j = 0; j < y; ++j)
#define p_in(P) cin >> P.first >> P.second;
#define p_in_all(a, N)                                                                             \
    a(N);                                                                                          \
    rep(i, N) {                                                                                    \
        p_in(a[i]);                                                                                \
    }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;
typedef pair<char, ll> pcl;
typedef pair<double, double> pdd;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<char, ll>> vpcl;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<vector<vector<int>>> viii;
typedef vector<vector<vector<vector<int>>>> viiii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef vector<vector<vector<ll>>> vlll;
typedef vector<vector<vector<vector<ll>>>> vllll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vbb;
typedef vector<char> vc;
typedef vector<vector<char>> vcc;
typedef vector<double> vd;
typedef vector<vd> vdd;
typedef vector<string> vs;

const ll ll_INF = 9223372036854775807;
const ll ll_INF_2 = ll_INF / 10;

const int i_INF = 2147483647;
const int i_INF2 = i_INF / 10;
const double epsilon = 1e-15;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
template <class T>
void chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
    }
}

template <class T>
void chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
    }
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "[" << p.first << " " << p.second << "]";
    return os;
}
namespace modint {
/**
 * @brief ax + by = gcd(a, b)の解(x, y)を求める。
 * @param x 解x(副作用)
 * @param y 解y(副作用)
 * @return gcd(a, b)
 */
template <class T>
T ext_gcd(T a, T b, T &x, T &y) {
    T d = a;
    if (b != 0) {
        d = ext_gcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}
/**
 * @brief aの逆数x ((a * x) % mod == 1)を求める。
 */
template <class T>
T mod_inv(T a, T mod) {
    T x, y;
    ext_gcd(a, mod, x, y);
    return (mod + x % mod) % mod;
}
template <ll MOD>
struct mint {
    ll v;
    mint<MOD>() {
    }
    mint<MOD>(ll v) {
        this->v = ((MOD + v % MOD) % MOD);
    }
    void operator+=(const mint<MOD> &other) {
        v = (v + other.v) % MOD;
    }
    void operator+=(const ll &other) {
        v = (v + other % MOD) % MOD;
    }
    mint<MOD> operator+(const mint<MOD> &other) const {
        return mint<MOD>(v + other.v);
    }
    mint<MOD> operator+(const ll &other) const {
        return mint<MOD>(v + other % MOD);
    }
    void operator-=(const mint<MOD> &other) {
        v = (MOD + v - other.v) % MOD;
    }
    void operator-=(const ll &other) {
        v = (MOD + v - other % MOD) % MOD;
    }
    mint<MOD> operator-(const mint<MOD> &other) const {
        return mint<MOD>(v - other.v);
    }
    mint<MOD> operator-(const ll &other) const {
        return mint<MOD>(v - other % MOD);
    }
    void operator*=(const mint<MOD> &other) {
        v = (v * (other.v)) % MOD;
    }
    void operator*=(const ll &other) {
        v = (v * other) % MOD;
    }
    mint<MOD> operator*(const mint<MOD> &other) const {
        mint<MOD> res(*this);
        res *= other;
        return res;
    }
    mint<MOD> operator*(const ll &other) const {
        mint<MOD> res(*this);
        res *= other;
        return res;
    }
    mint<MOD> inv() const {
        ll a = 1, b = 1;
        ext_gcd<ll>(v, MOD, a, b);
        return mint<MOD>(a);
    }
    void operator/=(const mint<MOD> &other) {
        *this *= other.inv();
    }
    void operator/=(const ll &other) {
        *this *= mint<MOD>(other).inv();
    }
    mint<MOD> operator/(const mint<MOD> &other) const {
        mint<MOD> res(*this);
        res /= other;
        return res;
    }
    mint<MOD> operator/(const ll &other) const {
        mint<MOD> res(*this);
        res /= other;
        return res;
    }
};

template <ll MOD>
ostream &operator<<(ostream &os, const mint<MOD> &p) {
    os << p.v;
    return os;
}
}    // namespace modint
using namespace modint;
template <class T>
T get_pow(T a, int n) {
    T res = 1;
    while (0 < n) {
        if ((n & 1) == 1) {
            res *= a;
        }
        a *= a;
        n >>= 1;
    }
    return res;
}
typedef mint<MOD> mi;
typedef vector<mi> vm;
int main() {
    ll input2(n, k);
    if (n < k) {
        cout << 0 << "\n";
        return 0;
    }
    vm facto(k + 1);
    facto[0] = 1;
    rep1(i, k) {
        facto[i] = facto[i - 1] * i;
    }
    auto comb = [&facto](ll a, ll b) -> mi { return facto[a] / facto[b] / facto[a - b]; };

    vm dp(k + 1, 0);

    rep1(i, k) {
        dp[i] = get_pow<mi>(mi(i), n);
        rep1(j, i - 1) {
            dp[i] -= comb(i, j) * dp[j];
        }
    }
    cout << dp[k] << "\n";
}
accuracy: 1
time_ms: 200
memory_kb: 3432
final_rank: 10

code_snippet: #include <iostream>
#include <cmath>
#include <vector>

struct ModuloCombination{
    int size;
    int mod;
    std::vector<long long> fac;
    std::vector<long long> inv;
    std::vector<long long> finv;

    ModuloCombination(int const mod = 1000000007, int const size = 510000)
    : size(size),
    mod(mod),
    fac(size),
    inv(size),
    finv(size){
        init();
    }

    void init(){
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[0] = 0;
        inv[1] = 1;
        for(int i=2; i<size; ++i){
            fac[i] = fac[i-1] * i % mod;
            inv[i] = mod - inv[mod%i] * (mod / i) % mod;
            finv[i] = finv[i-1] * inv[i] % mod;
        }
    }

    long long combination(int const n, int const r){
        if(n < r) return 0;
        if(n < 0 || r < 0) return 0;
        return fac[n] * (finv[r] * finv[n - r] % mod) % mod;
    }
};

long long int pow(long long int x, int n, long long int mod){
    long long int res = 1;
    while(n > 0){
        if(n % 2 == 1) res = (res * x) % mod;
        x = (x * x) % mod;
        n /= 2;
    }
    return res;
}

/*
long long int combination(int const n, int const r, int const mod){
    if(r == 0){
        return 1;
    }

    return (combination(n, r-1, mod) * (n - r + 1) / r) % mod;
}
*/

int main(){
    int n, k;
    std::cin >> n >> k;
    int mod = 1000000007;

    ModuloCombination mc(mod);

    long long int ans = 0;
    for(int i=0; i<=k; ++i){
        long long a = ((k - i) % 2 == 1) ? 1 : mod - 1;
        long long b = pow(i, n, mod);
        long long c = mc.combination(k, i);
        ans = (ans + (((a * b) % mod) * c) % mod) % mod;
    }
    std::cout << (mod - ans) % mod << std::endl;

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 15120
final_rank: 9

code_snippet: #include <iostream>
#include <cmath>
#include <vector>

struct ModuloCombination{
    int size;
    int mod;
    std::vector<long long> fac;
    std::vector<long long> inv;
    std::vector<long long> finv;

    ModuloCombination(int const mod = 1000000007, int const size = 510000)
    : size(size),
    mod(mod),
    fac(size),
    inv(size),
    finv(size){
        init();
    }

    void init(){
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[0] = 0;
        inv[1] = 1;
        for(int i=2; i<size; ++i){
            fac[i] = fac[i-1] * i % mod;
            inv[i] = mod - inv[mod%i] * (mod / i) % mod;
            finv[i] = finv[i-1] * inv[i] % mod;
        }
    }

    long long combination(int const n, int const r){
        if(n < r) return 0;
        if(n < 0 || r < 0) return 0;
        return fac[n] * (finv[r] * finv[n - r] % mod) % mod;
    }
};

long long int pow(long long int x, int n, long long int mod){
    long long int res = 1;
    while(n > 0){
        if(n % 2 == 1) res = (res * x) % mod;
        x = (x * x) % mod;
        n /= 2;
    }
    return res;
}

/*
long long int combination(int const n, int const r, int const mod){
    if(r == 0){
        return 1;
    }

    return (combination(n, r-1, mod) * (n - r + 1) / r) % mod;
}
*/

int main(){
    int n, k;
    std::cin >> n >> k;
    int mod = 1000000007;

    ModuloCombination mc(mod);

    long long int ans = 0;
    for(int i=0; i<=k; ++i){
        long long a = ((k - i) % 2 == 1) ? 1 : mod - 1;
        long long b = pow(i, n, mod);
        long long c = mc.combination(k, i);
        ans = (ans + (((a * b) % mod) * c) % mod) % mod;
    }
    std::cout << mod - ans << std::endl;

    return 0;
}
accuracy: 0.13333333333333333
time_ms: 10
memory_kb: 15056
final_rank: 20

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<deque>
#include<list>
#include<bitset>

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ld EPS = 1e-10;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
const double PI = M_PI;

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

// MODを考慮した ll
struct mll{

  ll val;

  mll( ll _val = 0LL ){
    val = ( _val + MOD ) % MOD;
  }

  mll inv(){
    ll x, y;
    extgcd( val, MOD, x, y );
    x %= MOD;
    x += MOD;
    return x % MOD;
  }

  mll operator+( mll x ){
    mll res;
    res.val = ( val + x.val ) % MOD;
    return res;
  }

  mll operator+=( mll x ){
    return *this = *this + x;
  }

  mll operator-( mll x ){
    mll res;
    res.val = ( val + MOD - x.val ) % MOD;
    return res;
  }

  mll operator-=( mll x ){
    return *this = *this - x;
  }

  mll operator*( mll x ){
    mll res;
    res.val = ( val * x.val ) % MOD;
    return res;
  }

  mll operator*=( mll x ){
    return *this = *this * x;
  }

  mll operator/( mll x ){
    mll res;
    res.val = ( val * x.inv().val ) % MOD;
    return res;
  }

  mll operator/=( mll x ){
    return *this = *this / x;
  }

  mll operator++(){
    mll one( 1LL );
    return *this = *this + one;
  }

  mll operator++( int ){
    mll one( 1LL );
    mll res = *this;
    *this = *this + one;
    return res;
  }

  mll operator--(){
    mll one( 1LL );
    return *this = *this - one;
  }

  mll operator--( int ){
    mll one( 1LL );
    mll res = *this;
    *this = *this - one;
    return res;
  }

  bool operator<( mll x ){
    return val < x.val;
  }

  bool operator>( mll x ){
    return val > x.val;
  }

  bool operator<=( mll x ){
    return val <= x.val;
  }

  bool operator>=( mll x ){
    return val >= x.val;
  }

  bool operator==( mll x ){
    return val == x.val;
  }

  bool operator!=( mll x ){
    return val != x.val;
  }

};

// MODを考慮した x の y 乗
mll power( mll mx, mll my ){

  mll res( 1LL );
  ll y = my.val;
  while( y > 0LL ){
    if( y & 1LL )
      res *= mx;
    mx *= mx;
    y >>= 1;
  }
  return res;

}

// MODを考慮した xCy
mll permutation( mll mx, mll my ){

  mll res( 1LL );
  mll i( 1LL );
  while( i <= my ){
    res *= mx;
    mx--;
    i++;
  }
  return res;

}

// MODを考慮した xCy
mll combination( mll mx, mll my ){

  mll res( 1LL );
  mll i( 1LL );
  while( i <= my ){
    res *= mx;
    res /= i;
    mx--;
    i++;
  }
  return res;

}

// 包除原理を用いた解法
// 箱 i が空いている事象を Ai とする
// 全てのパターン = 求める値 + ( Ai の合計 ) - ( Ai ∩ Aj の合計 ) + ( Ai ∩ Aj ∩ Ak の合計 ) - ..
mll func1( mll mx, mll my ){

  bool minus = true;
  mll res = power( my, mx );
  for( mll i(1LL) ; i <= my ; i++ ){
    if( minus )
      res -= combination( my, i ) * power(  my - i, mx );
    else
      res += combination( my, i ) * power(  my - i, mx );
    minus = !minus;
  }
  return res;

}

////////////////////////////// n 個の ボールを k 個の 箱に入れる時 /////////////////////////////////////
// ボール : 区別できる,   箱 : 区別できる,   入れ方に制限なし => power( k, n )
// ボール : 区別できる,   箱 : 区別できる,   箱の中身は1つ以下 => k >= n ? permutation( k, n ) : 0
// ボール : 区別できる,   箱 : 区別できる,   箱の中身は1つ以上 => n >= k ? func1( n, k ) : 0
// ボール : 区別できない, 箱 : 区別できる,   入れ方に制限なし => combination( n + k - 1, k - 1 )
// ボール : 区別できない, 箱 : 区別できる,   箱の中身は1つ以下 => k >= n ? combination( k, n ) : 0
// ボール : 区別できない, 箱 : 区別できる,   箱の中身は1つ以上 => n >= k ? combination( n - 1, k - 1) : 0
// ボール : 区別できる,   箱 : 区別できない, 箱の中身は1つ以下 => k >= n ? 1 : 0
// ボール : 区別できない, 箱 : 区別できない,  箱の中身は1つ以下 => k >= n ? 1 : 0

int main(){

  ll n, k;
  cin >> n >> k;
  mll mx = mll( n );
  mll my = mll( k );
  cout << ( mx >= my ? func1( mx, my ).val : 0LL ) << endl;

}
accuracy: 1
time_ms: 30
memory_kb: 3440
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
using ll = long long;

const ll MOD = 1e+9 + 7;
const ll MAX = 2100000;

vector<ll> fact(MAX), inv(MAX), inv_fact(MAX);

void init() {
    fact.at(0) = fact.at(1) = 1;
    inv.at(0) = inv.at(1) = 1;
    inv_fact.at(0) = inv_fact.at(1) = 1;
    
    for (int i = 2; i < MAX; i++) {
        fact.at(i) = fact.at(i - 1) * i % MOD;
        inv.at(i) = MOD - inv.at(MOD % i) * (MOD / i) % MOD;
        inv_fact.at(i) = inv_fact.at(i - 1) * inv.at(i) % MOD;
    }
}

ll nCk(ll n, ll k) {
    if (n < k) {
        return 0;
    }
    if (n < 0 || k < 0) {
        return 0;
    }
	
	ll x = fact.at(n);
    ll y = inv_fact.at(n - k);
    ll z = inv_fact.at(k);

    return (x * ((y * z) % MOD)) % MOD;
}

ll mod_pow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}



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

	if (n < k) {
		cout << 0 << endl;
		return 0;
	}

	ll ans = 0;
	for (int i = 0; i <= k; i++) {
		ll tmp = nCk(k, i) * mod_pow(k - i, n, MOD) % MOD;
		if (i % 2 == 0) {
			ans = (ans + tmp) % MOD; 
		} else {
			ans = (ans - tmp + MOD) % MOD;
		}
	}
	cout << ans << endl;

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 52260
final_rank: 18

code_snippet: // 2022.10.21
#define _GLIBCXX_DEBUG //
// #define __USE_MATH_DEFINES // const double PI = acos(-1.0)
#include <bits/stdc++.h>
using namespace std;
// (*) snipet
// type name
using ll = long long;
using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vl = vector<ll>; using vvl = vector<vl>; using vvvl = vector<vvl>;
using vpii = vector<pii>; using vpil = vector<pil>; using vpli = vector<pli>; using vpll = vector<pll>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
template <typename T> using pq = priority_queue<T, vector<T>>;
template <typename T> using pql = priority_queue<T, vector<T>, greater<T>>;
// rep
#define rep0(goal) for (int cnt = 0; cnt < int(goal); ++cnt)
#define rep(cnt, goal) for (int cnt = 0; cnt < int(goal); ++cnt)
#define rep2(cnt, start, goal) for (int cnt = int(start); cnt < int(goal); ++cnt)
#define rep3(cnt, start, goal) for (int cnt = int(start); cnt > int(goal); --cnt)
// all
#define all(ctn) begin(ctn), end(ctn)
// chmax, chmin
template <typename T> bool chmax(T &x, const T y) { if (x < y) { x = y; return true; } else { return false; }}
template <typename T> bool chmin(T &x, const T y) { if (x > y) { x = y; return true; } else { return false; }}
// etc.
void Yn(const bool &exp) { if (exp) cout << "Yes" << endl; else cout << "No" << endl;}
void set_prec(const int &dig) { cout << fixed << setprecision(dig); cerr << fixed << setprecision(dig);}
// template <typename T> T INF() { return numeric_limits<T>::max();}
// template <typename T> T MIN_INF() { return numeric_limits<T>::min();}

// #include <atcoder/all>
// using namespace atcoder;
// // using mint = atcoder::modint1000000007;
// using mint = atcoder::modint998244353;
// // using mint = atcoder::modint;
// void pr(const mint &MINT) { cerr << MINT.val(); } // mint
// using pmm = pair<mint, mint>; using pim = pair<int, mint>; using pmi = pair<mint, int>; using plm = pair<ll, mint>; using pml = pair<mint, ll>;
// using vm = vector<mint>; using vvm = vector<vm>; using vvvm = vector<vvm>;

// debug
template <typename T> void pr(const T &obj) { cerr << obj; } // single
template <typename T, typename ...Ts> void pr(const T &first, const Ts &...rest) { pr(first); cerr << ", "; pr(rest...); } // multi(plural)
template <typename S, typename T> void pr(const pair<S, T> &PAIR) { cerr << "("; pr(PAIR.first); cerr << ", "; pr(PAIR.second); cerr << ")"; } // pair
template <typename S, typename T, typename U> void pr(const tuple<S, T, U> &trp) { cerr << "("; pr(get<0>(trp)); cerr << ", "; pr(get<1>(trp)); cerr << ", "; pr(get<2>(trp)); cerr << ")"; } // tuple(3)
template <typename T> void pr(const vector<T> &vec) { cerr << "{"; for (T obj : vec) { pr(obj); cerr << ", "; } cerr << "}"; } // vector
template <typename T> void pr(const vector<vector<T>> &vv) { rep(row, vv.size()) { cerr << endl; cerr << "[" << row << "]: "; pr(vv[row]); }} // vector(multi-D)
template <typename T> void pr(const set<T> &SET) { cerr << "{"; for (T obj : SET) { pr(obj); cerr << ", "; } cerr << "}"; } // set
template <typename T> void pr(const multiset<T> &MS) { cerr << "{"; for (T obj : MS) { pr(obj); cerr << ", "; } cerr << "}"; } // multiset
template <typename S, typename T> void pr(const map<S, T> &MAP) { cerr << "{"; for (pair<S, T> p : MAP) { pr(p.first); cerr << ": "; pr(p.second); cerr << ", "; } cerr << "}";} // map
template <typename T> void pr(const queue<T> &que) { queue<T> q = que; cerr << "{"; while (!q.empty()) { pr(q.front()); q.pop(); cerr << ", ";} cerr << "}";} // queue
template <typename T> void pr(const deque<T> &deq) { deque<T> d = deq; cerr << "{"; while (!d.empty()) { pr(d.front()); d.pop_front(); cerr << ", ";} cerr << "}";} // deque
template <typename T> void pr(const stack<T> &stc) { stack<T> s = stc; vector<T> v; while (!s.empty()) { v.push_back(s.top()); s.pop();} reverse(all(v)); cerr << "{"; for (T obj : v) cerr << obj << ", "; cerr << "}";} // stack
template <typename T> void pr(const priority_queue<T> &pq) { priority_queue<T> p = pq; cerr << "{"; while (!p.empty()) { pr(p.top()); p.pop(); cerr << ", "; } cerr << "}";} // priority_queue
template <typename T> void pr(const priority_queue<T, vector<T>, greater<T>> &pq) { priority_queue<T, vector<T>, greater<T>> p = pq; cerr << "{"; while (!p.empty()) { pr(p.top()); p.pop(); cerr << ", ";} cerr << "}";} // priority_queue(from less)

#define db(obj) cerr << #obj << ": "; pr(obj); cerr << " ";
#define dl(obj) db(obj); cerr << endl;
#define dm(...) cerr << "(" << #__VA_ARGS__ << "): ("; pr(__VA_ARGS__); cerr << ") ";
#define dml(...) dm(__VA_ARGS__); cerr << endl;

// 

// global
int n; // 玉の数
int k; // 箱の数

vvl dp; // dp[n][k]
vvl dp2; // dp2[n][k] //
ll m = 1e9 + 7; // 998244353; // MOD

void input() {
	cin >> n >> k;
}

void init() {
	dp = vvl(n + 1, vl(k + 1, -1));
	dp2 = dp; //
}

// 重複順列の数 kΠn = k^n
ll kPin(int n, int k) {
	assert(0 <= n); assert(0 <= k);
	if (dp2[n][k] != -1) return dp2[n][k];

	if (n == 0 && k == 0) return dp2[n][k] = 1;
	if (n == 0) return dp2[n][k] = 1; // 玉がない
	if (k == 0) return dp2[n][k] = 0; // 箱がない

	ll res = 0;
	res = k * kPin(n - 1, k) % m; // (n)は箱(k個)のどれかに入れる
	return dp2[n][k] = res;
}

// 組合せの数 kCn = k!/n!(k-n)!
ll kCn(int n, int k) {
	assert(0 <= n); assert(0 <= k);
	if (dp[n][k] != -1) return dp[n][k];

	if (n == 0 && k == 0) return dp[n][k] = 1;
	if (n == 0) return dp[n][k] = 1; // 玉がない
	if (k == 0) return dp[n][k] = 0; // 箱がない

	ll res = 0;
	res = (res + kCn(n - 1, k - 1)) % m; // [k]に玉を入れる
	res = (res + kCn(n, k - 1)) % m; // [k]に玉を入れない
	return dp[n][k] = res;
}

// 全射の数 Σ[i:0->k](-1)^(k-i)*kCi*iΠn
ll surjection(int n, int k) {
	assert(0 <= n); assert(0 <= k);

	if (n < k) return 0;
	
	ll res = 0;
	rep(i, k + 1) {
		ll temp = kCn(i, k) * kPin(n, i) % m;
		if ((k - i) % 2 == 0) res = (res + temp) % m;
		else res = (res - temp + m) % m;
	}
	return res;
}

void solve() {
	cout << surjection(n, k) << endl;
	// dl(dp);
	// dl(dp2); //
};

int main() {
	input();
	init();
	solve();
}
accuracy: 1
time_ms: 30
memory_kb: 19272
final_rank: 13

code_snippet: #include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
using ll = long long;

ll mod_pow(ll x, ll n, ll mod) {
    if (n == 0) {
        return 1;
    }
    ll
 res = mod_pow(x * x % mod, n / 2, mod);
    if (n & 1) res = res * x % mod;
    return res;
}

const ll MOD = 1e9 + 7;
const ll MAX = 1100000;

vector<ll> fact(MAX), inv(MAX), inv_fact(MAX);

void init() {
    fact.at(0) = fact.at(1) = 1;
    inv.at(0) = inv.at(1) = 1;
    inv_fact.at(0) = inv_fact.at(1) = 1;
    
    for (int i = 2; i < MAX; i++) {
        fact.at(i) = fact.at(i - 1) * i % MOD;
        inv.at(i) = MOD - inv.at(MOD % i) * (MOD / i) % MOD;
        inv_fact.at(i) = inv_fact.at(i - 1) * inv.at(i) % MOD;
    }
}

ll nCk(ll n, ll k) {
    ll x = fact.at(n);
    ll y = inv_fact.at(n - k);
    ll z = inv_fact.at(k);

    if (n < k) {
        return 0;
    }
    if (n < 0 || k < 0) {
        return 0;
    }

    return (x * ((y * z) % MOD)) % MOD;
}

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

	ll ans = 0;
	for (int i = 0; i <= k; i++) {
		ll ok = k - i;
		ll add = nCk(k, i) * mod_pow(ok, n, MOD) % MOD;
		if (i % 2 == 0) {
			ans = (ans + add) % MOD;
		} else {
			ans = (ans - add + MOD) % MOD;
		}
	}
	cout << ans << endl;

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 28688
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std ;
#define fast_input_output ios::sync_with_stdio(false); cin.tie(nullptr);
typedef long long ll ;
typedef long double ld ;
typedef pair<ll,ll> P ;
typedef tuple<ll,ll,ll> TP ;
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
#define bit_count(x) __builtin_popcountll(x)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / gcd(a,b) * b
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define rrep(i,a,b) for(int i = a ; i < b ; i++)
#define endl "\n"

const int mod = 1000000007 ;
const int MAX_N = 505050 ;

ll inv[MAX_N+1] ; // (n!)^(p-2) (mod p) を格納
ll fac[MAX_N+1] ; // (n!) (mod p) を格納

// 繰り返し二乗法
ll powmod(ll A , ll N){
    ll res = 1 ;
    while(N > 0){
        if(N & 1) res = (res * A) % mod ;
        A = (A * A) % mod ;
        N >>= 1 ;
    }
    return res % mod ;
}

// 階乗の逆元(n!)^(-1)のmodを配列に格納
void f(){
    inv[0] = 1 ; inv[1] = 1 ;
    for(ll i = 2 ; i <= MAX_N ; i++){
        inv[i] = powmod(i,mod-2) * inv[i-1] % mod ;
    }
}

// 階乗のmodを配列に格納
void g(){
    fac[0] = 1 ; fac[1] = 1 ;
    for(ll i = 2 ; i <= MAX_N ; i++){
        fac[i] = (fac[i-1] * i) % mod ;
    }
}

//nCrの計算
ll combination(ll n , ll r){
    return fac[n] * inv[n-r] % mod * inv[r] % mod ;
}

ll permutation(ll n , ll r){
    return fac[n] * inv[n-r] % mod ;
}

void init(){ f() ; g() ; }

ll n , k ;

int main(){
    fast_input_output
    init() ;
    cin >> n >> k ;
    ll sum = 0 ;
    rrep(i,1,k){
        if(i % 2 == 1) sum += combination(k,i) * powmod(k-i,n) % mod ;
        if(i % 2 == 0) sum -= combination(k,i) * powmod(k-i,n) % mod ;
        (sum += mod) %= mod ;
    }
    ll res = (powmod(k,n) - sum + mod) % mod ;
    cout << res << endl ;
}
accuracy: 1
time_ms: 40
memory_kb: 11352
final_rank: 6

code_snippet: #include <bits/stdc++.h>

#include <cassert>
#include <numeric>
#include <type_traits>

#ifdef _MSC_VER
#include <intrin.h>
#endif


#include <utility>

#ifdef _MSC_VER
#include <intrin.h>
#endif

namespace atcoder {

namespace internal {

constexpr long long safe_mod(long long x, long long m) {
    x %= m;
    if (x < 0) x += m;
    return x;
}

struct barrett {
    unsigned int _m;
    unsigned long long im;

    explicit barrett(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {}

    unsigned int umod() const { return _m; }

    unsigned int mul(unsigned int a, unsigned int b) const {

        unsigned long long z = a;
        z *= b;
#ifdef _MSC_VER
        unsigned long long x;
        _umul128(z, im, &x);
#else
        unsigned long long x =
            (unsigned long long)(((unsigned __int128)(z)*im) >> 64);
#endif
        unsigned int v = (unsigned int)(z - x * _m);
        if (_m <= v) v += _m;
        return v;
    }
};

constexpr long long pow_mod_constexpr(long long x, long long n, int m) {
    if (m == 1) return 0;
    unsigned int _m = (unsigned int)(m);
    unsigned long long r = 1;
    unsigned long long y = safe_mod(x, m);
    while (n) {
        if (n & 1) r = (r * y) % _m;
        y = (y * y) % _m;
        n >>= 1;
    }
    return r;
}

constexpr bool is_prime_constexpr(int n) {
    if (n <= 1) return false;
    if (n == 2 || n == 7 || n == 61) return true;
    if (n % 2 == 0) return false;
    long long d = n - 1;
    while (d % 2 == 0) d /= 2;
    constexpr long long bases[3] = {2, 7, 61};
    for (long long a : bases) {
        long long t = d;
        long long y = pow_mod_constexpr(a, t, n);
        while (t != n - 1 && y != 1 && y != n - 1) {
            y = y * y % n;
            t <<= 1;
        }
        if (y != n - 1 && t % 2 == 0) {
            return false;
        }
    }
    return true;
}
template <int n> constexpr bool is_prime = is_prime_constexpr(n);

constexpr std::pair<long long, long long> inv_gcd(long long a, long long b) {
    a = safe_mod(a, b);
    if (a == 0) return {b, 0};

    long long s = b, t = a;
    long long m0 = 0, m1 = 1;

    while (t) {
        long long u = s / t;
        s -= t * u;
        m0 -= m1 * u;  // |m1 * u| <= |m1| * s <= b


        auto tmp = s;
        s = t;
        t = tmp;
        tmp = m0;
        m0 = m1;
        m1 = tmp;
    }
    if (m0 < 0) m0 += b / s;
    return {s, m0};
}

constexpr int primitive_root_constexpr(int m) {
    if (m == 2) return 1;
    if (m == 167772161) return 3;
    if (m == 469762049) return 3;
    if (m == 754974721) return 11;
    if (m == 998244353) return 3;
    int divs[20] = {};
    divs[0] = 2;
    int cnt = 1;
    int x = (m - 1) / 2;
    while (x % 2 == 0) x /= 2;
    for (int i = 3; (long long)(i)*i <= x; i += 2) {
        if (x % i == 0) {
            divs[cnt++] = i;
            while (x % i == 0) {
                x /= i;
            }
        }
    }
    if (x > 1) {
        divs[cnt++] = x;
    }
    for (int g = 2;; g++) {
        bool ok = true;
        for (int i = 0; i < cnt; i++) {
            if (pow_mod_constexpr(g, (m - 1) / divs[i], m) == 1) {
                ok = false;
                break;
            }
        }
        if (ok) return g;
    }
}
template <int m> constexpr int primitive_root = primitive_root_constexpr(m);

unsigned long long floor_sum_unsigned(unsigned long long n,
                                      unsigned long long m,
                                      unsigned long long a,
                                      unsigned long long b) {
    unsigned long long ans = 0;
    while (true) {
        if (a >= m) {
            ans += n * (n - 1) / 2 * (a / m);
            a %= m;
        }
        if (b >= m) {
            ans += n * (b / m);
            b %= m;
        }

        unsigned long long y_max = a * n + b;
        if (y_max < m) break;
        n = (unsigned long long)(y_max / m);
        b = (unsigned long long)(y_max % m);
        std::swap(m, a);
    }
    return ans;
}

}  // namespace internal

}  // namespace atcoder


#include <cassert>
#include <numeric>
#include <type_traits>

namespace atcoder {

namespace internal {

#ifndef _MSC_VER
template <class T>
using is_signed_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value ||
                                  std::is_same<T, __int128>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using is_unsigned_int128 =
    typename std::conditional<std::is_same<T, __uint128_t>::value ||
                                  std::is_same<T, unsigned __int128>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using make_unsigned_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value,
                              __uint128_t,
                              unsigned __int128>;

template <class T>
using is_integral = typename std::conditional<std::is_integral<T>::value ||
                                                  is_signed_int128<T>::value ||
                                                  is_unsigned_int128<T>::value,
                                              std::true_type,
                                              std::false_type>::type;

template <class T>
using is_signed_int = typename std::conditional<(is_integral<T>::value &&
                                                 std::is_signed<T>::value) ||
                                                    is_signed_int128<T>::value,
                                                std::true_type,
                                                std::false_type>::type;

template <class T>
using is_unsigned_int =
    typename std::conditional<(is_integral<T>::value &&
                               std::is_unsigned<T>::value) ||
                                  is_unsigned_int128<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using to_unsigned = typename std::conditional<
    is_signed_int128<T>::value,
    make_unsigned_int128<T>,
    typename std::conditional<std::is_signed<T>::value,
                              std::make_unsigned<T>,
                              std::common_type<T>>::type>::type;

#else

template <class T> using is_integral = typename std::is_integral<T>;

template <class T>
using is_signed_int =
    typename std::conditional<is_integral<T>::value && std::is_signed<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using is_unsigned_int =
    typename std::conditional<is_integral<T>::value &&
                                  std::is_unsigned<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using to_unsigned = typename std::conditional<is_signed_int<T>::value,
                                              std::make_unsigned<T>,
                                              std::common_type<T>>::type;

#endif

template <class T>
using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;

template <class T>
using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;

template <class T> using to_unsigned_t = typename to_unsigned<T>::type;

}  // namespace internal

}  // namespace atcoder


namespace atcoder {

namespace internal {

struct modint_base {};
struct static_modint_base : modint_base {};

template <class T> using is_modint = std::is_base_of<modint_base, T>;
template <class T> using is_modint_t = std::enable_if_t<is_modint<T>::value>;

}  // namespace internal

template <int m, std::enable_if_t<(1 <= m)>* = nullptr>
struct static_modint : internal::static_modint_base {
    using mint = static_modint;

  public:
    static constexpr int mod() { return m; }
    static mint raw(int v) {
        mint x;
        x._v = v;
        return x;
    }

    static_modint() : _v(0) {}
    template <class T, internal::is_signed_int_t<T>* = nullptr>
    static_modint(T v) {
        long long x = (long long)(v % (long long)(umod()));
        if (x < 0) x += umod();
        _v = (unsigned int)(x);
    }
    template <class T, internal::is_unsigned_int_t<T>* = nullptr>
    static_modint(T v) {
        _v = (unsigned int)(v % umod());
    }

    unsigned int val() const { return _v; }

    mint& operator++() {
        _v++;
        if (_v == umod()) _v = 0;
        return *this;
    }
    mint& operator--() {
        if (_v == 0) _v = umod();
        _v--;
        return *this;
    }
    mint operator++(int) {
        mint result = *this;
        ++*this;
        return result;
    }
    mint operator--(int) {
        mint result = *this;
        --*this;
        return result;
    }

    mint& operator+=(const mint& rhs) {
        _v += rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    mint& operator-=(const mint& rhs) {
        _v -= rhs._v;
        if (_v >= umod()) _v += umod();
        return *this;
    }
    mint& operator*=(const mint& rhs) {
        unsigned long long z = _v;
        z *= rhs._v;
        _v = (unsigned int)(z % umod());
        return *this;
    }
    mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }

    mint operator+() const { return *this; }
    mint operator-() const { return mint() - *this; }

    mint pow(long long n) const {
        assert(0 <= n);
        mint x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const {
        if (prime) {
            assert(_v);
            return pow(umod() - 2);
        } else {
            auto eg = internal::inv_gcd(_v, m);
            assert(eg.first == 1);
            return eg.second;
        }
    }

    friend mint operator+(const mint& lhs, const mint& rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs) {
        return mint(lhs) /= rhs;
    }
    friend bool operator==(const mint& lhs, const mint& rhs) {
        return lhs._v == rhs._v;
    }
    friend bool operator!=(const mint& lhs, const mint& rhs) {
        return lhs._v != rhs._v;
    }

  private:
    unsigned int _v;
    static constexpr unsigned int umod() { return m; }
    static constexpr bool prime = internal::is_prime<m>;
};

template <int id> struct dynamic_modint : internal::modint_base {
    using mint = dynamic_modint;

  public:
    static int mod() { return (int)(bt.umod()); }
    static void set_mod(int m) {
        assert(1 <= m);
        bt = internal::barrett(m);
    }
    static mint raw(int v) {
        mint x;
        x._v = v;
        return x;
    }

    dynamic_modint() : _v(0) {}
    template <class T, internal::is_signed_int_t<T>* = nullptr>
    dynamic_modint(T v) {
        long long x = (long long)(v % (long long)(mod()));
        if (x < 0) x += mod();
        _v = (unsigned int)(x);
    }
    template <class T, internal::is_unsigned_int_t<T>* = nullptr>
    dynamic_modint(T v) {
        _v = (unsigned int)(v % mod());
    }

    unsigned int val() const { return _v; }

    mint& operator++() {
        _v++;
        if (_v == umod()) _v = 0;
        return *this;
    }
    mint& operator--() {
        if (_v == 0) _v = umod();
        _v--;
        return *this;
    }
    mint operator++(int) {
        mint result = *this;
        ++*this;
        return result;
    }
    mint operator--(int) {
        mint result = *this;
        --*this;
        return result;
    }

    mint& operator+=(const mint& rhs) {
        _v += rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    mint& operator-=(const mint& rhs) {
        _v += mod() - rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    mint& operator*=(const mint& rhs) {
        _v = bt.mul(_v, rhs._v);
        return *this;
    }
    mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }

    mint operator+() const { return *this; }
    mint operator-() const { return mint() - *this; }

    mint pow(long long n) const {
        assert(0 <= n);
        mint x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const {
        auto eg = internal::inv_gcd(_v, mod());
        assert(eg.first == 1);
        return eg.second;
    }

    friend mint operator+(const mint& lhs, const mint& rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs) {
        return mint(lhs) /= rhs;
    }
    friend bool operator==(const mint& lhs, const mint& rhs) {
        return lhs._v == rhs._v;
    }
    friend bool operator!=(const mint& lhs, const mint& rhs) {
        return lhs._v != rhs._v;
    }

  private:
    unsigned int _v;
    static internal::barrett bt;
    static unsigned int umod() { return bt.umod(); }
};
template <int id> internal::barrett dynamic_modint<id>::bt(998244353);

using modint998244353 = static_modint<998244353>;
using modint1000000007 = static_modint<1000000007>;
using modint = dynamic_modint<-1>;

namespace internal {

template <class T>
using is_static_modint = std::is_base_of<internal::static_modint_base, T>;

template <class T>
using is_static_modint_t = std::enable_if_t<is_static_modint<T>::value>;

template <class> struct is_dynamic_modint : public std::false_type {};
template <int id>
struct is_dynamic_modint<dynamic_modint<id>> : public std::true_type {};

template <class T>
using is_dynamic_modint_t = std::enable_if_t<is_dynamic_modint<T>::value>;

}  // namespace internal

}  // namespace atcoder

using namespace std;
using namespace atcoder;
using mint = modint1000000007;
#define ll long long

const int comb_N = 1e6;
vector<mint> fact, inverse;

mint comb(int n, int k) {
    if (n<0 || k<0 || n<k) return mint(0);
    return fact[n]*inverse[k]*inverse[(n-k)];
}

mint perm(int n, int k) {
    if (n<0 || k<0 || n<k) return mint(0);
    return fact[n]*inverse[(n-k)];
}

void calc_comb() {
    fact = vector<mint>(comb_N, mint(0));
    inverse = vector<mint>(comb_N, mint(0));
    fact[0] = mint(1);
    inverse[0] = mint(1);
    for (int i=1;i<comb_N;i++) {
        fact[i] = fact[i-1]*i;
        inverse[i] = fact[i].inv();
    }
}

int main() {
    calc_comb();
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    mint ans = 0;
    mint flag = -1;
    for (int i=0;i<=k;i++) {
        flag *= -1;
        ans += flag*comb(k, i)*(mint(k-i).pow(n));
    }

    cout << ans.val() << "\n";
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 10840
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define X cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
#define I inline
#define TTT   template<typename T>
#define TTTU  template<typename T,typename U>
#define TTTT  template<typename... T>
#define TTTTT template<typename T,typename... Ts>
#define overload2(a,b,c,...) c
#define overload3(a,b,c,d,...) d
#define overload4(a,b,c,d,e,...) e
#define overload5(a,b,c,d,e,f,...) f
#define overload6(a,b,c,d,e,f,g,...) g
//------------------------------------------------------------------------------
using ll = long long;
using db = long double;
using str = string;
using bl = bool;
//------------------------------------------------------------------------------
#define P pair
using pii = P<ll,ll>;
using pdd = P<db,db>;
//------------------------------------------------------------------------------
#define V vector
using vi = V<ll>;   using vvi = V<vi>; using vvvi = V<vvi>; using vvvvi = V<vvvi>;
using vd = V<db>;   using vvd = V<vd>;
using vc = V<char>; using vvc = V<vc>;
using vb = V<bl>;   using vvb = V<vb>;
using vs = V<str>;
using vp = V<pii>; using vpd = V<pdd>;
#define vvi1(v,h,w)   vvi v(h,vi(w))
#define vvi2(v,h,w,n) vvi v(h,vi(w,n))
#define vvi(...) overload4(__VA_ARGS__,vvi2,vvi1)(__VA_ARGS__)
#define vvd1(v,h,w)   vvd v(h,vd(w))
#define vvd2(v,h,w,n) vvd v(h,vd(w,n))
#define vvd(...) overload4(__VA_ARGS__,vvd2,vvd1)(__VA_ARGS__)
#define vvc1(v,h,w)   vvc v(h,vc(w))
#define vvc2(v,h,w,n) vvc v(h,vc(w,n))
#define vvc(...) overload4(__VA_ARGS__,vvc2,vvc1)(__VA_ARGS__)
#define vvb1(v,h,w)   vvb v(h,vb(w))
#define vvb2(v,h,w,n) vvb v(h,vb(w,n))
#define vvb(...) overload4(__VA_ARGS__,vvb2,vvb1)(__VA_ARGS__)
#define vvvi1(v,x,y,z)   vvvi v(x,V<vi>(y,vi(z)))
#define vvvi2(v,x,y,z,n) vvvi v(x,V<vi>(y,vi(z,n)))
#define vvvi(...) overload5(__VA_ARGS__,vvvi2,vvvi1)(__VA_ARGS__)
#define vvvvi1(v,w,x,y,z)   vvvvi v(w,V<vvi>(x,V<vi>(y,vi(z))))
#define vvvvi2(v,w,x,y,z,n) vvvvi v(w,V<vvi>(x,V<vi>(y,vi(z,n))))
#define vvvvi(...) overload6(__VA_ARGS__,vvvvi2,vvvvi1)(__VA_ARGS__)
#define vv1(T,v,h,w)   V<V<T>> v(h,V<T>(w))
#define vv2(T,v,h,w,n) V<V<T>> v(h,V<T>(w,n))
#define vv(...) overload5(__VA_ARGS__,vv2,vv1)(__VA_ARGS__)
using graph = V<vi>;
using wgraph = V<vp>;
using wgraphd = V<V<P<ll,db>>>;
TTTU using umap = unordered_map<T,U>;
TTT using que = queue<T>;
TTT using deq = deque<T>;
TTT using pq = priority_queue<T,V<T>,greater<T>>; //昇順
TTT using qp = priority_queue<T>; //降順
//------------------------------------------------------------------------------
#define fi first
#define sc second
#define mp make_pair
#define en cout<<endl
#define sq sqrt
#define exit return 0
#define si(v) ll(v.size())
#define pb(v,n) v.push_back(n)
#define pf(v,n) v.push_front(n)
#define pp(v) v.pop_back()
//------------------------------------------------------------------------------
#define lp1(n)        lp2(i,n)
#define lp2(i,n)      for(ll i=0;i<ll(n);i++)
#define lp3(i,n,m)    for(ll i=n;i<ll(m);i++)
#define lp4(i,n,m,c)  for(ll i=n;i<ll(m);i+=c)
#define lp(...)  overload4(__VA_ARGS__,lp4,lp3,lp2,lp1)(__VA_ARGS__)
#define lp1_(n)       lp(n+1)
#define lp2_(i,n)     lp(i,n+1)
#define lp3_(i,n,m)   lp(i,n,m+1)
#define lp4_(i,n,m,c) lp(i,n,m+1,c)
#define lp_(...) overload4(__VA_ARGS__,lp4_,lp3_,lp2_,lp1_)(__VA_ARGS__)
#define pl1(n)        pl2(i,n)
#define pl2(i,n)      for(ll i=n;i>=0;i--)
#define pl3(i,n,m)    for(ll i=n;i>=m;i--)
#define pl4(i,n,m,c)  for(ll i=n;i>=m:i-=c)
#define pl(...)  overload4(__VA_ARGS__,pl4,pl3,pl2,pl1)(__VA_ARGS__)
#define lpv1(v)       lp(si(v))
#define lpv2(i,v)     lp(i,si(v))
#define lpv3(i,n,v)   lp(i,n,si(v))
#define lpv(...) overload3(__VA_ARGS__,lpv3,lpv2,lpv1)(__VA_ARGS__)
#define comlp(i,j,n)  lp(i,n-1)lp(j,i+1,n)
#define lpa1(v)   lpa2(i,v)
#define lpa2(i,v) for(auto i:v)
#define lpa(...) overload2(__VA_ARGS__,lpa2,lpa1)(__VA_ARGS__)
#define lpm1(m)   lpm2(i,m)
#define lpm2(i,m) for(auto i=m.begin();i!=m.end();i++)
#define lpm(...) overload2(__VA_ARGS__,lpm2,lpm1)(__VA_ARGS__)
//------------------------------------------------------------------------------
TTTU I P<T,U> operator+(const P<T,U> &x,const P<T,U> &y) {return P<T,U>(x.fi+y.fi,x.sc+y.sc);}
TTTU I P<T,U> operator-(const P<T,U> &x,const P<T,U> &y) {return P<T,U>(x.fi-y.fi,x.sc-y.sc);}
TTTU I P<T,U> operator+=(P<T,U> &x,const P<T,U> &y){return x=x+y;}
TTTU I P<T,U> operator-=(P<T,U> &x,const P<T,U> &y){return x=x-y;}
TTTU I db operator%(const P<T,U> &x,const P<T,U> &y) {return sq((x.fi-y.fi)*(x.fi-y.fi)+(x.sc-y.sc)*(x.sc-y.sc));}
TTTU I istream&operator>>(istream &is,P<T,U> &x)       {return is>>x.fi>>x.sc;}
TTTU I ostream&operator<<(ostream &os,const P<T,U> &x) {return os<<x.fi<<" "<<x.sc;}
TTT  I istream&operator>>(istream &is,V<T> &v)         {lpm(v)is>>*i;return is;}
TTT  I ostream&operator<<(ostream &os,const V<T> &v)   {lpm(v){if(i!=v.begin())os<<" ";os<<*i;}return os;}
TTT  I ostream&operator<<(ostream &os,const V<V<T>> &v){lpv(v){if(i>0)en;lpm(j,v[i]){if(j!=v[i].begin())os<<" ";os<<*j;}}return os;}
TTT I void operator>>(V<T> &v,const T x){pb(v,x);}
TTT I void operator--(V<T> &v){pp(v);}
TTT I void operator>>(set<T> &s,const T x){s.insert(x);}
TTT I void operator<<(set<T> &s,const T x){s.erase(x);}
TTT I void operator>>(stack<T> &s,const T x){s.push(x);}
TTT I T operator--(stack<T> &s){T r=s.top();s.pop();return r;}
TTT I void operator>>(que<T> &q,const T x){q.push(x);}
TTT I T operator--(que<T> &q){T r=q.front();q.pop();return r;}
TTT I void operator>>(pq<T> &q,const T x){q.push(x);}
TTT I T operator--(pq<T> &q){T r=q.top();q.pop();return r;}
TTT I void operator>>(qp<T> &q,const T x){q.push(x);}
TTT I T operator--(qp<T> &q){T r=q.top();q.pop();return r;}
//------------------------------------------------------------------------------
TTTT  I void in(T&... a) {(cin>>...>>a);}
TTTTT I void print(const T& a,const Ts&... b) {cout<<a;(cout<<...<<(cout<<' ',b));en;}
TTTTT I void print_(const T& a,const Ts&... b) {cout<<a;(cout<<...<<(cout<<' ',b));}
TTTTT I void out(const T& a,const Ts&... b)   {cout<<a;(cout<<...<<(en,b));en;}
TTTU I void vini(V<T> &v,U n)       {lpv(v) v[i]=n;}
TTTU I void vini(V<V<T>> &v,U n)    {lpv(v)lpv(j,v[0]) v[i][j]=n;}
TTTU I void vini(V<V<V<T>>> &v,U n) {lpv(v)lpv(j,v[0])lpv(k,v[0][0]) v[i][j][k]=n;}
TTTU I void vini(V<T> &v,ll x,U n)                 {v.assign(x,n);}
TTTU I void vini(V<V<T>> &v,ll x,ll y,U n)         {v.assign(x,V<T>(y,n));}
TTTU I void vini(V<V<V<T>>> &v,ll x,ll y,ll z,U n) {v.assign(x,V<V<T>>(y,V<T>(z,n)));}
#define LL(...)   ll   __VA_ARGS__; in(__VA_ARGS__)
#define DB(...)   db   __VA_ARGS__; in(__VA_ARGS__)
#define STR(...)  str  __VA_ARGS__; in(__VA_ARGS__)
#define CHAR(...) char __VA_ARGS__; in(__VA_ARGS__)
#define PII(...)  pii  __VA_ARGS__; in(__VA_ARGS__)
#define PDD(...)  pdd  __VA_ARGS__; in(__VA_ARGS__)
#define VI(v,n) vi v(n); in(v)
#define VD(v,n) vd v(n); in(v)
#define VP(v,n) vp v(n); in(v)
#define VVI(v,h,w) vvi(v,h,w); in(v)
I void gin(graph &g,ll m)   {lp(m){LL(A,B);  A--;B--;g[A]>>B;g[B]>>A;}}
I void gin_(graph &g,ll m)  {lp(m){LL(A,B);  A--;B--;g[A]>>B;}}
I void gin(wgraph &g,ll m)  {lp(m){LL(A,B,C);A--;B--;g[A]>>mp(B,C);g[B]>>mp(A,C);}}
I void gin_(wgraph &g,ll m) {lp(m){LL(A,B,C);A--;B--;g[A]>>mp(B,C);}}
I void gin(wgraphd &g,ll m) {lp(m){LL(A,B);DB(C);A--;B--;g[A]>>mp(B,C);g[B]>>mp(A,C);}}
I void gin_(wgraphd &g,ll m){lp(m){LL(A,B);DB(C);A--;B--;g[A]>>mp(B,C);}}
#define cout(x) cout<<x<<endl
TTT I void vout(V<T> &v) {lpv(v)cout(v[i]);}
#ifdef ONLINE_JUDGE
#define debug(...)
#define debug_(q)
#else
#define debug(...) {print_(#__VA_ARGS__); cout<<" : "; print(__VA_ARGS__);}
#define debug_(q) {cout<<#q<<" : ";auto q_=q;while(!q_.empty())cout<<--q_<<" ";en;}
#endif
//------------------------------------------------------------------------------
#define all(v) (v).begin(),(v).end()
#define lla(v) (v).rbegin(),(v).rend()
#define SORT(v)    sort(all(v))
#define REVERSE(v) reverse(all(v))
#define RESORT(v)  sort(lla(v))
TTT I T sum(V<T> &v) {T r=v[0];lpv(i,1,v) r+=v[i];return r;}
TTT I T max(V<T> &v) {return *max_element(all(v));}
TTT I T min(V<T> &v) {return *min_element(all(v));}
TTTU I void ap(V<T> &v,U n) {lpv(v) v[i]+=n;}
TTTU I void ap(V<P<T,T>> &v,U n,bl x=1,bl y=1){lpv(v){if(x)v[i].fi+=n;if(y)v[i].sc+=n;}}
TTTU I void ap(V<V<T>> &v,U n) {lpv(v)lpv(j,v[0]) v[i][j]+=n;}
#define bs(v,x) binary_search(all(v),x)
#define lower lower_bound
#define upper upper_bound
TTTU I ll lb(T &v,U x) {return lower(all(v),x)-v.begin();} // a[i]<xとなるiの個数 / a[i]>=xとなる最初のi
TTTU I ll ub(T &v,U x) {return upper(all(v),x)-v.begin();} // a[i]<=xとなるiの個数 / a[i]>xとなる最初のi
TTTU I ll cou(T &v,U x){return count(all(v),x);}
TTT I void uni(T &v) {SORT(v);v.erase(unique(all(v)),v.end());}
TTT I vi compress(T &v){ll n=si(v);auto u=v;vi r(n);SORT(u);uni(u);lp(n)r[i]=lb(u,v[i]);return r;}
TTT I vi compress_(T &v){ll p=-1,n=si(v);vi r;lp(n-1)if(v[i]!=v[i+1]){pb(r,i-p);p=i;}pb(r,n-1-p);return r;}
TTT I V<T> acsum(V<T> &v){ll n=si(v);V<T> r(n+1);r[0]=0;lp(n)r[i+1]=r[i]+v[i];return r;}
#define np(v) while(next_permutation(all(v)))
//------------------------------------------------------------------------------
const ll MOD=1000000007;
//const ll MOD=998244353;
const ll INF=(1LL<<60),FNI=-INF,MOOD=MOD*10,M=100005,M2=200005;
const db E=1e-10,PI=acos(-1);
const ll DX[8]={0,0,1,-1,1,1,-1,-1},DY[8]={1,-1,0,0,1,-1,1,-1};
const ll TEN[19]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000,100000000000,1000000000000,10000000000000,100000000000000,1000000000000000,10000000000000000,100000000000000000,1000000000000000000};
const ll ONE[19]={1,11,111,1111,11111,111111,1111111,11111111,111111111,1111111111,11111111111,111111111111,1111111111111,11111111111111,111111111111111,1111111111111111,11111111111111111,111111111111111111,1111111111111111111};
const ll COMAX=510000; // 変更
ll fac[COMAX],finv[COMAX],inv[COMAX];
bl COMflag=0;
TTTTT I T min(T a,T b,T c,Ts... x) {return min(a,min(b,c,x...));}
TTTTT I T max(T a,T b,T c,Ts... x) {return max(a,max(b,c,x...));}
I ll gcd(ll x,ll y) {if(x<0)x=-x;if(y<0)y=-y;return __gcd(x,y);}
I ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}
TTTTT I T gcd(T a,T b,T c,Ts... x) {return gcd(a,gcd(b,c,x...));}
TTTTT I T lcm(T a,T b,T c,Ts... x) {return lcm(a,lcm(b,c,x...));}
I ll gcd(vi &v) {ll r=v[0];lpv(i,1,v)r=gcd(r,v[i]);return r;}
I ll lcm(vi &v) {ll r=1;lpv(v)r=lcm(r,v[i]);return r;}
I ll wa(ll x) {ll r=0;for(;x!=0;){r+=x%10;x/=10;}return r;}
I ll keta(ll x) {ll r=0;while(x!=0){x/=10;r++;}return r;}
I void comini(ll m) {COMflag=1;fac[0]=fac[1]=finv[0]=finv[1]=inv[1]=1;lp(i,2,COMAX){fac[i]=fac[i-1]*i%m;inv[i]=m-inv[m%i]*(m/i)%m;finv[i]=finv[i-1]*inv[i]%m;}}
I ll com(ll n,ll k,ll m=MOD) {if(!COMflag)comini(m);if(n<0||k<0||n<k)return 0;return fac[n]*(finv[k]*finv[n-k]%m)%m;}
I ll per(ll n,ll k,ll m=MOD) {if(!COMflag)comini(m);if(n<0||k<0||n<k)return 0;return fac[n]*finv[n-k]%m;}
I ll nc2(ll n) {return n*(n-1)/2;}
I ll rui(ll x,ll n,ll m=MOD) {x%=m;if(x==0)return 0;ll r=1;while(n>0){if(n&1)r=r*x%m;x=x*x%m;n>>=1;}return r;}
I vi n_sin(ll x,ll n,bl re=0) {vi r;while(x!=0){pb(r,x%n);(x-=(x%n))/=n;}if(re)REVERSE(r);return r;}
I ll kiri(ll a,ll b=2){return (a+b-1)/b;}
I ll ma(ll a,ll b,ll m=MOD) {return (a+b)%m;}
I ll ms(ll a,ll b,ll m=MOD) {return (a-b+m*10)%m;}
I ll mm(ll a,ll b,ll m=MOD) {return a*b%m;}
I ll md(ll a,ll b,ll m=MOD) {ll c=m,x=1,y=0;while(c){ll t=b/c;b-=t*c;swap(b,c);x-=t*y;swap(x,y);}x%=m;if(x<0)x+=m;return (a%m)*x%m;}
I ll kai(ll n,ll k=-1,ll m=MOD) {ll r=1;if(k<0)k=n;lp(k)(r*=(n-i))%=m;return r;}
I vi prime_b(ll x) {vi r;lp_(i,2,sq(x)){if(x%i!=0)continue;ll e=0;while(x%i==0){e++;x/=i;}pb(r,e);}if(x!=1)pb(r,1);return r;}
I vi prime_p(ll x) {vi r;lp_(i,2,sq(x)){if(x%i!=0)continue;while(x%i==0)x/=i;pb(r,i);}if(x!=1)pb(r,x);return r;}
I vp prime(ll x) {vp r;lp_(i,2,sq(x)){if(x%i!=0)continue;ll e=0;while(x%i==0){e++;x/=i;}pb(r,mp(i,e));}if(x!=1)pb(r,mp(x,1));return r;}
I vi div(ll x) {vi r;lp_(i,1,sq(x)){if(x%i==0){pb(r,i);if(i*i!=x)pb(r,x/i);}}SORT(r);return r;}
I ll DP(vi &v,ll s,ll m=MOD){ll n=si(v);vvi(dp,n+3,s+3,0);dp[0][0]=1;lp(i,n)lp_(j,s){(dp[i+1][j]+=dp[i][j])%=m;if(j>=v[i])(dp[i+1][j]+=dp[i][j-v[i]])%=m;}return dp[n][s];}
I ll LIS(vi &a) {vi dp(si(a),INF);lpv(a){auto p=lower(all(dp),a[i]);*p=a[i];}return lb(dp,INF);}
I vi Z(str s) {vi r(si(s));for(ll i=1,j=0;i<si(s);i++){if(i+r[i-j]<j+r[j])r[i]=r[i-j];else{ll k=max(0LL,j+r[j]-i);while(i+k<si(s)&&s[k]==s[i+k])k++;r[i]=k;j=i;}}r[0]=si(s);return r;}
TTT I bl chmin(T&a,T b) {if(a>b){a=b;return 1;}return 0;}
TTT I bl chmax(T&a,T b) {if(a<b){a=b;return 1;}return 0;}
TTTU I bl eq(T a,U b) {return abs(a-b)<E;}
TTT I T pos(T a) {return max(T(0),a);}
#define Y cout("Yes")
#define N cout("No")
#define yn1(x)     if(x){Y;}else N
#define yn2(x,y)   if(x){cout(y);exit;}
#define yn3(x,y,n) if(x){cout(y);}else cout(n)
#define yn(...) overload3(__VA_ARGS__,yn3,yn2,yn1)(__VA_ARGS__)

//==============================================================================



int main()
{ X;
  LL(n,k);
  ll r=0;
  lp_(k)
  {
    if((k-i)%2==0) r=ma(r,com(k,i)*rui(i,n)%MOD);
    else r=ms(r,com(k,i)*rui(i,n)%MOD);
  }
  cout(r);
}
accuracy: 1
time_ms: 10
memory_kb: 15400
final_rank: 7

code_snippet: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef pair<int, int> P;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define fi first
#define se second
// #include <atcoder/all>
// using namespace atcoder;
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T, class U>
inline bool chmax(T& a, U b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T, class U>
inline bool chmin(T& a, U b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T, class U>
ostream& operator<<(ostream& os, pair<T, U>& p) {
    cout << "(" << p.first << ", " << p.second << ")";
    return os;
}
template <class T>
inline void dump(T& v) {
    irep(i, v) { cout << (*i) << ((i == --v.end()) ? '\n' : ' '); }
}
template <class T, class U>
inline void dump(map<T, U>& v) {
    if (v.size() > 100) {
        cout << "ARRAY IS TOO LARGE!!!" << endl;
    } else {
        irep(i, v) { cout << i->first << " " << i->second << '\n'; }
    }
}
template <class T, class U>
inline void dump(pair<T, U>& p) {
    cout << p.first << " " << p.second << '\n';
}
inline void yn(const bool b) { b ? fin("yes") : fin("no"); }
inline void Yn(const bool b) { b ? fin("Yes") : fin("No"); }
inline void YN(const bool b) { b ? fin("YES") : fin("NO"); }
void Case(int i) { printf("Case #%d: ", i); }
const int INF = INT_MAX;
constexpr ll LLINF = 1LL << 61;
constexpr ld EPS = 1e-11;
#define MODTYPE 0
#if MODTYPE == 0
constexpr ll MOD = 1000000007;
#else
constexpr ll MOD = 998244353;
#endif
/* --------------------   ここまでテンプレ   -------------------- */

struct mint {
    ll x;
    mint(ll _x = 0) : x((_x % MOD + MOD) % MOD) {}

    /* 初期化子 */
    mint operator+() const { return mint(x); }
    mint operator-() const { return mint(-x); }

    /* 代入演算子 */
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint& operator/=(const mint a) {
        x *= modinv(a).x;
        x %= MOD;
        return (*this);
    }
    mint& operator%=(const mint a) {
        x %= a.x;
        return (*this);
    }
    mint& operator++() {
        ++x;
        if (x >= MOD) x -= MOD;
        return *this;
    }
    mint& operator--() {
        if (!x) x += MOD;
        --x;
        return *this;
    }
    mint& operator&=(const mint a) {
        x &= a.x;
        return (*this);
    }
    mint& operator|=(const mint a) {
        x |= a.x;
        return (*this);
    }
    mint& operator^=(const mint a) {
        x ^= a.x;
        return (*this);
    }
    mint& operator<<=(const mint a) {
        x *= pow(2, a).x;
        return (*this);
    }
    mint& operator>>=(const mint a) {
        x /= pow(2, a).x;
        return (*this);
    }

    /* 算術演算子 */
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
    mint operator%(const mint a) const {
        mint res(*this);
        return res %= a;
    }
    mint operator&(const mint a) const {
        mint res(*this);
        return res &= a;
    }
    mint operator|(const mint a) const {
        mint res(*this);
        return res |= a;
    }
    mint operator^(const mint a) const {
        mint res(*this);
        return res ^= a;
    }
    mint operator<<(const mint a) const {
        mint res(*this);
        return res <<= a;
    }
    mint operator>>(const mint a) const {
        mint res(*this);
        return res >>= a;
    }

    /* 条件演算子 */
    bool operator==(const mint a) const noexcept { return x == a.x; }
    bool operator!=(const mint a) const noexcept { return x != a.x; }
    bool operator<(const mint a) const noexcept { return x < a.x; }
    bool operator>(const mint a) const noexcept { return x > a.x; }
    bool operator<=(const mint a) const noexcept { return x <= a.x; }
    bool operator>=(const mint a) const noexcept { return x >= a.x; }

    /* ストリーム挿入演算子 */
    friend istream& operator>>(istream& is, mint& m) {
        is >> m.x;
        m.x = (m.x % MOD + MOD) % MOD;
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& m) {
        os << m.x;
        return os;
    }

    /* その他の関数 */
    mint modinv(mint a) { return pow(a, MOD - 2); }
    mint pow(mint x, mint n) {
        mint res = 1;
        while (n.x > 0) {
            if ((n % 2).x) res *= x;
            x *= x;
            n.x /= 2;
        }
        return res;
    }
    mint powll(mint x, ll n) {
        mint res = 1;
        while (n > 0) {
            if (n % 2) res *= x;
            x *= x;
            n /= 2;
        }
        return res;
    }
};

// modint呼ぶ！！！

class Counting {
    struct pre_calculation {
        bool factorial;
        bool partition;
        bool combination;
    };
    pre_calculation pre_calc;

    vector<mint> Factorial;
    void factorial_precalc(const int MAX = 301010) {
        Factorial = vector<mint>(MAX, 1);
        for (int i = 1; i < MAX; i++) {
            Factorial[i] = Factorial[i - 1] * i;
        }
    }

    vector<mint> FactorialInv;
    void nCk_precalc(const int MAX = 301010) {
        if (!pre_calc.factorial) {
            factorial_precalc();
        }
        FactorialInv = vector<mint>(MAX, 1);
        for (int i = 1; i < MAX; i++) {
            FactorialInv[i] = mint(1).pow(Factorial[i], MOD - 2);
        }
    }

    vector<vector<mint>> Partition;
    void partition_precalc(const int MAX = 2000) {
        Partition = vector<vector<mint>>(MAX, vector<mint>(MAX, 0));
        for (int k = 0; k < MAX; k++) {
            Partition[0][k] = 1;
        }
        for (int n = 1; n < MAX; n++) {
            for (int k = 1; k < MAX; k++) {
                Partition[n][k] = Partition[n][k - 1];
                if (n - k >= 0) {
                    Partition[n][k] += Partition[n - k][k];
                }
            }
        }
    }

   public:
    Counting(void) {
        pre_calc.factorial = false;
        pre_calc.partition = false;
        pre_calc.combination = false;
    };

    // 階乗 n! を計算
    mint factorial(const mint n) {
        if (!pre_calc.factorial) {
            factorial_precalc();
            pre_calc.factorial = true;
        }
        return Factorial[n.x];
    }

    // 二項係数 nCk を計算
    mint nCk(const mint n, const mint k) {
        if (n < k) {
            return 0;
        }
        if (!pre_calc.combination) {
            nCk_precalc();
            pre_calc.combination = true;
        }
        mint nl = Factorial[n.x];            // n!
        mint nkl = FactorialInv[n.x - k.x];  // (n-k)!
        mint kl = FactorialInv[k.x];         // k!
        mint nkk = (nkl.x * kl.x);
        return nl * nkk;
    }

    // 順列 nPk を計算
    mint nPk(mint n, mint k) {
        if (n < k) {
            return 0;
        }
        if (!pre_calc.factorial) {
            factorial_precalc();
            pre_calc.factorial = true;
        }
        return Factorial[n.x] / Factorial[n.x - k.x];
    }

    // 包除原理 \sum_{i=0}^k (-1)^{k-i} kCi i^n
    mint inclusion_exclusion(const mint n, const mint k) {
        if (!pre_calc.combination) {
            nCk_precalc();
            pre_calc.combination = true;
        }
        mint ans = 0;
        for (int i = 0; i <= k.x; i++) {
            ans += mint(1).pow(-1, k-i) * nCk(k, i) * mint(0).pow(i, n);
        }
        return ans;
    }

    // 分割数 P(n, k) を計算
    mint partition(const mint n, const mint k) {
        if (!pre_calc.partition) {
            partition_precalc();
            pre_calc.partition = true;
        }
        return Partition[n.x][k.x];
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    Counting cnt;
    cout << cnt.inclusion_exclusion(n, k) << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 7856
final_rank: 3

code_snippet: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef pair<int, int> P;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define fi first
#define se second
// #include <atcoder/all>
// using namespace atcoder;
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T, class U>
inline bool chmax(T& a, U b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T, class U>
inline bool chmin(T& a, U b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T, class U>
ostream& operator<<(ostream& os, pair<T, U>& p) {
    cout << "(" << p.first << ", " << p.second << ")";
    return os;
}
template <class T>
inline void dump(T& v) {
    irep(i, v) { cout << (*i) << ((i == --v.end()) ? '\n' : ' '); }
}
template <class T, class U>
inline void dump(map<T, U>& v) {
    if (v.size() > 100) {
        cout << "ARRAY IS TOO LARGE!!!" << endl;
    } else {
        irep(i, v) { cout << i->first << " " << i->second << '\n'; }
    }
}
template <class T, class U>
inline void dump(pair<T, U>& p) {
    cout << p.first << " " << p.second << '\n';
}
inline void yn(const bool b) { b ? fin("yes") : fin("no"); }
inline void Yn(const bool b) { b ? fin("Yes") : fin("No"); }
inline void YN(const bool b) { b ? fin("YES") : fin("NO"); }
void Case(int i) { printf("Case #%d: ", i); }
const int INF = INT_MAX;
constexpr ll LLINF = 1LL << 61;
constexpr ld EPS = 1e-11;
#define MODTYPE 0
#if MODTYPE == 0
constexpr ll MOD = 1000000007;
#else
constexpr ll MOD = 998244353;
#endif
/* --------------------   ここまでテンプレ   -------------------- */

struct mint {
    ll x;
    mint(ll _x = 0) : x((_x % MOD + MOD) % MOD) {}

    /* 初期化子 */
    mint operator+() const { return mint(x); }
    mint operator-() const { return mint(-x); }

    /* 代入演算子 */
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint& operator/=(const mint a) {
        x *= modinv(a).x;
        x %= MOD;
        return (*this);
    }
    mint& operator%=(const mint a) {
        x %= a.x;
        return (*this);
    }
    mint& operator++() {
        ++x;
        if (x >= MOD) x -= MOD;
        return *this;
    }
    mint& operator--() {
        if (!x) x += MOD;
        --x;
        return *this;
    }
    mint& operator&=(const mint a) {
        x &= a.x;
        return (*this);
    }
    mint& operator|=(const mint a) {
        x |= a.x;
        return (*this);
    }
    mint& operator^=(const mint a) {
        x ^= a.x;
        return (*this);
    }
    mint& operator<<=(const mint a) {
        x *= pow(2, a).x;
        return (*this);
    }
    mint& operator>>=(const mint a) {
        x /= pow(2, a).x;
        return (*this);
    }

    /* 算術演算子 */
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
    mint operator%(const mint a) const {
        mint res(*this);
        return res %= a;
    }
    mint operator&(const mint a) const {
        mint res(*this);
        return res &= a;
    }
    mint operator|(const mint a) const {
        mint res(*this);
        return res |= a;
    }
    mint operator^(const mint a) const {
        mint res(*this);
        return res ^= a;
    }
    mint operator<<(const mint a) const {
        mint res(*this);
        return res <<= a;
    }
    mint operator>>(const mint a) const {
        mint res(*this);
        return res >>= a;
    }

    /* 条件演算子 */
    bool operator==(const mint a) const noexcept { return x == a.x; }
    bool operator!=(const mint a) const noexcept { return x != a.x; }
    bool operator<(const mint a) const noexcept { return x < a.x; }
    bool operator>(const mint a) const noexcept { return x > a.x; }
    bool operator<=(const mint a) const noexcept { return x <= a.x; }
    bool operator>=(const mint a) const noexcept { return x >= a.x; }

    /* ストリーム挿入演算子 */
    friend istream& operator>>(istream& is, mint& m) {
        is >> m.x;
        m.x = (m.x % MOD + MOD) % MOD;
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& m) {
        os << m.x;
        return os;
    }

    /* その他の関数 */
    mint modinv(mint a) { return pow(a, MOD - 2); }
    mint pow(mint x, mint n) {
        mint res = 1;
        while (n.x > 0) {
            if ((n % 2).x) res *= x;
            x *= x;
            n.x /= 2;
        }
        return res;
    }
    mint powll(mint x, ll n) {
        mint res = 1;
        while (n > 0) {
            if (n % 2) res *= x;
            x *= x;
            n /= 2;
        }
        return res;
    }
};

// modint呼ぶ！！！

class Counting {
    struct pre_calculation {
        bool factorial;
        bool partition;
        bool combination;
    };
    pre_calculation pre_calc;

    vector<mint> Factorial;
    void factorial_precalc(const int MAX = 301010) {
        Factorial = vector<mint>(MAX, 1);
        for (int i = 1; i < MAX; i++) {
            Factorial[i] = Factorial[i - 1] * i;
        }
    }

    vector<mint> FactorialInv;
    void nCk_precalc(const int MAX = 301010) {
        if (!pre_calc.factorial) {
            factorial_precalc();
        }
        FactorialInv = vector<mint>(MAX, 1);
        for (int i = 1; i < MAX; i++) {
            FactorialInv[i] = mint(1).pow(Factorial[i], MOD - 2);
        }
    }

    vector<vector<mint>> Partition;
    void partition_precalc(const int MAX = 2000) {
        Partition = vector<vector<mint>>(MAX, vector<mint>(MAX, 0));
        for (int k = 0; k < MAX; k++) {
            Partition[0][k] = 1;
        }
        for (int n = 1; n < MAX; n++) {
            for (int k = 1; k < MAX; k++) {
                Partition[n][k] = Partition[n][k - 1];
                if (n - k >= 0) {
                    Partition[n][k] += Partition[n - k][k];
                }
            }
        }
    }

   public:
    Counting(void) {
        pre_calc.factorial = false;
        pre_calc.partition = false;
        pre_calc.combination = false;
    };

    // 階乗 n! を計算
    mint factorial(const mint n) {
        if (!pre_calc.factorial) {
            factorial_precalc();
            pre_calc.factorial = true;
        }
        return Factorial[n.x];
    }

    // 二項係数 nCk を計算
    mint nCk(const mint n, const mint k) {
        if (n < k) {
            return 0;
        }
        if (!pre_calc.combination) {
            nCk_precalc();
            pre_calc.combination = true;
        }
        mint nl = Factorial[n.x];            // n!
        mint nkl = FactorialInv[n.x - k.x];  // (n-k)!
        mint kl = FactorialInv[k.x];         // k!
        mint nkk = (nkl.x * kl.x);
        return nl * nkk;
    }

    // 順列 nPk を計算
    mint nPk(mint n, mint k) {
        if (n < k) {
            return 0;
        }
        if (!pre_calc.factorial) {
            factorial_precalc();
            pre_calc.factorial = true;
        }
        return Factorial[n.x] / Factorial[n.x - k.x];
    }

    // 包除原理
    mint inclusion_exclusion(const mint n, const mint k) {
        if (!pre_calc.combination) {
            nCk_precalc();
            pre_calc.combination = true;
        }
        mint ans = 0;
        for (int i = 0; i <= k.x; i++) {
            if ((k.x & 1) == (i & 1)) {
                ans += nCk(k, i) * mint(0).pow(i, n);
            } else {
                ans -= nCk(k, i) * mint(0).pow(i, n);
            }
        }
        // for (int i = 0; i <= k.x; i++) {
        //     ans += mint(1).pow(-1, i) * nCk(k, i) * mint(0).pow(k - i, n);
        // }
        return ans;
    }

    // 分割数 P(n, k) を計算
    mint partition(const mint n, const mint k) {
        if (!pre_calc.partition) {
            partition_precalc();
            pre_calc.partition = true;
        }
        return Partition[n.x][k.x];
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    Counting cnt;
    cout << cnt.inclusion_exclusion(n, k) << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 7860
final_rank: 5

code_snippet: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef pair<int, int> P;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define fi first
#define se second
// #include <atcoder/all>
// using namespace atcoder;
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T, class U>
inline bool chmax(T& a, U b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T, class U>
inline bool chmin(T& a, U b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T, class U>
ostream& operator<<(ostream& os, pair<T, U>& p) {
    cout << "(" << p.first << ", " << p.second << ")";
    return os;
}
template <class T>
inline void dump(T& v) {
    irep(i, v) { cout << (*i) << ((i == --v.end()) ? '\n' : ' '); }
}
template <class T, class U>
inline void dump(map<T, U>& v) {
    if (v.size() > 100) {
        cout << "ARRAY IS TOO LARGE!!!" << endl;
    } else {
        irep(i, v) { cout << i->first << " " << i->second << '\n'; }
    }
}
template <class T, class U>
inline void dump(pair<T, U>& p) {
    cout << p.first << " " << p.second << '\n';
}
inline void yn(const bool b) { b ? fin("yes") : fin("no"); }
inline void Yn(const bool b) { b ? fin("Yes") : fin("No"); }
inline void YN(const bool b) { b ? fin("YES") : fin("NO"); }
void Case(int i) { printf("Case #%d: ", i); }
const int INF = INT_MAX;
constexpr ll LLINF = 1LL << 61;
constexpr ld EPS = 1e-11;
#define MODTYPE 0
#if MODTYPE == 0
constexpr ll MOD = 1000000007;
#else
constexpr ll MOD = 998244353;
#endif
/* --------------------   ここまでテンプレ   -------------------- */

struct mint {
    ll x;
    mint(ll _x = 0) : x((_x % MOD + MOD) % MOD) {}

    /* 初期化子 */
    mint operator+() const { return mint(x); }
    mint operator-() const { return mint(-x); }

    /* 代入演算子 */
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint& operator/=(const mint a) {
        x *= modinv(a).x;
        x %= MOD;
        return (*this);
    }
    mint& operator%=(const mint a) {
        x %= a.x;
        return (*this);
    }
    mint& operator++() {
        ++x;
        if (x >= MOD) x -= MOD;
        return *this;
    }
    mint& operator--() {
        if (!x) x += MOD;
        --x;
        return *this;
    }
    mint& operator&=(const mint a) {
        x &= a.x;
        return (*this);
    }
    mint& operator|=(const mint a) {
        x |= a.x;
        return (*this);
    }
    mint& operator^=(const mint a) {
        x ^= a.x;
        return (*this);
    }
    mint& operator<<=(const mint a) {
        x *= pow(2, a).x;
        return (*this);
    }
    mint& operator>>=(const mint a) {
        x /= pow(2, a).x;
        return (*this);
    }

    /* 算術演算子 */
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
    mint operator%(const mint a) const {
        mint res(*this);
        return res %= a;
    }
    mint operator&(const mint a) const {
        mint res(*this);
        return res &= a;
    }
    mint operator|(const mint a) const {
        mint res(*this);
        return res |= a;
    }
    mint operator^(const mint a) const {
        mint res(*this);
        return res ^= a;
    }
    mint operator<<(const mint a) const {
        mint res(*this);
        return res <<= a;
    }
    mint operator>>(const mint a) const {
        mint res(*this);
        return res >>= a;
    }

    /* 条件演算子 */
    bool operator==(const mint a) const noexcept { return x == a.x; }
    bool operator!=(const mint a) const noexcept { return x != a.x; }
    bool operator<(const mint a) const noexcept { return x < a.x; }
    bool operator>(const mint a) const noexcept { return x > a.x; }
    bool operator<=(const mint a) const noexcept { return x <= a.x; }
    bool operator>=(const mint a) const noexcept { return x >= a.x; }

    /* ストリーム挿入演算子 */
    friend istream& operator>>(istream& is, mint& m) {
        is >> m.x;
        m.x = (m.x % MOD + MOD) % MOD;
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& m) {
        os << m.x;
        return os;
    }

    /* その他の関数 */
    mint modinv(mint a) { return pow(a, MOD - 2); }
    mint pow(mint x, mint n) {
        mint res = 1;
        while (n.x > 0) {
            if ((n % 2).x) res *= x;
            x *= x;
            n.x /= 2;
        }
        return res;
    }
    mint powll(mint x, ll n) {
        mint res = 1;
        while (n > 0) {
            if (n % 2) res *= x;
            x *= x;
            n /= 2;
        }
        return res;
    }
};

// modint呼ぶ！！！

class Counting {
    struct pre_calculation {
        bool factorial;
        bool partition;
        bool combination;
    };
    pre_calculation pre_calc;

    vector<mint> Factorial;
    void factorial_precalc(const int MAX = 301010) {
        Factorial = vector<mint>(MAX, 1);
        for (int i = 1; i < MAX; i++) {
            Factorial[i] = Factorial[i - 1] * i;
        }
    }

    vector<mint> FactorialInv;
    void nCk_precalc(const int MAX = 301010) {
        if (!pre_calc.factorial) {
            factorial_precalc();
        }
        FactorialInv = vector<mint>(MAX, 1);
        for (int i = 1; i < MAX; i++) {
            FactorialInv[i] = mint(1).pow(Factorial[i], MOD - 2);
        }
    }

    vector<vector<mint>> Partition;
    void partition_precalc(const int MAX = 2000) {
        Partition = vector<vector<mint>>(MAX, vector<mint>(MAX, 0));
        for (int k = 0; k < MAX; k++) {
            Partition[0][k] = 1;
        }
        for (int n = 1; n < MAX; n++) {
            for (int k = 1; k < MAX; k++) {
                Partition[n][k] = Partition[n][k - 1];
                if (n - k >= 0) {
                    Partition[n][k] += Partition[n - k][k];
                }
            }
        }
    }

   public:
    Counting(void) {
        pre_calc.factorial = false;
        pre_calc.partition = false;
        pre_calc.combination = false;
    };

    // 階乗 n! を計算
    mint factorial(const mint n) {
        if (!pre_calc.factorial) {
            factorial_precalc();
            pre_calc.factorial = true;
        }
        return Factorial[n.x];
    }

    // 二項係数 nCk を計算
    mint nCk(const mint n, const mint k) {
        if (n < k) {
            return 0;
        }
        if (!pre_calc.combination) {
            nCk_precalc();
            pre_calc.combination = true;
        }
        mint nl = Factorial[n.x];            // n!
        mint nkl = FactorialInv[n.x - k.x];  // (n-k)!
        mint kl = FactorialInv[k.x];         // k!
        mint nkk = (nkl.x * kl.x);
        return nl * nkk;
    }

    // 順列 nPk を計算
    mint nPk(mint n, mint k) {
        if (n < k) {
            return 0;
        }
        if (!pre_calc.factorial) {
            factorial_precalc();
            pre_calc.factorial = true;
        }
        return Factorial[n.x] / Factorial[n.x - k.x];
    }

    // 包除原理
    mint inclusion_exclusion(const mint n, const mint k) {
        if (!pre_calc.combination) {
            nCk_precalc();
            pre_calc.combination = true;
        }
        mint ans = 0;
        // for (int i = 0; i <= k.x; i++) {
        //     if ((k.x & 1) == (i & 1)) {
        //         ans += nCk(k, i) * mint(0).pow(i, n);
        //     } else {
        //         ans -= nCk(k, i) * mint(0).pow(i, n);
        //     }
        // }
        for (int i = 0; i <= k.x; i++) {
            ans += mint(1).pow(-1, i) * nCk(k, i) * mint(0).pow(k - i, n);
        }
        return ans;
    }

    // 分割数 P(n, k) を計算
    mint partition(const mint n, const mint k) {
        if (!pre_calc.partition) {
            partition_precalc();
            pre_calc.partition = true;
        }
        return Partition[n.x][k.x];
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    Counting cnt;
    cout << cnt.inclusion_exclusion(n, k) << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 7856
final_rank: 3

code_snippet: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef pair<int, int> P;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define fi first
#define se second
// #include <atcoder/all>
// using namespace atcoder;
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T, class U>
inline bool chmax(T& a, U b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T, class U>
inline bool chmin(T& a, U b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T, class U>
ostream& operator<<(ostream& os, pair<T, U>& p) {
    cout << "(" << p.first << ", " << p.second << ")";
    return os;
}
template <class T>
inline void dump(T& v) {
    irep(i, v) { cout << (*i) << ((i == --v.end()) ? '\n' : ' '); }
}
template <class T, class U>
inline void dump(map<T, U>& v) {
    if (v.size() > 100) {
        cout << "ARRAY IS TOO LARGE!!!" << endl;
    } else {
        irep(i, v) { cout << i->first << " " << i->second << '\n'; }
    }
}
template <class T, class U>
inline void dump(pair<T, U>& p) {
    cout << p.first << " " << p.second << '\n';
}
inline void yn(const bool b) { b ? fin("yes") : fin("no"); }
inline void Yn(const bool b) { b ? fin("Yes") : fin("No"); }
inline void YN(const bool b) { b ? fin("YES") : fin("NO"); }
void Case(int i) { printf("Case #%d: ", i); }
const int INF = INT_MAX;
constexpr ll LLINF = 1LL << 61;
constexpr ld EPS = 1e-11;
#define MODTYPE 0
#if MODTYPE == 0
constexpr ll MOD = 1000000007;
#else
constexpr ll MOD = 998244353;
#endif
/* --------------------   ここまでテンプレ   -------------------- */

struct mint {
    ll x;
    mint(ll _x = 0) : x((_x % MOD + MOD) % MOD) {}

    /* 初期化子 */
    mint operator+() const { return mint(x); }
    mint operator-() const { return mint(-x); }

    /* 代入演算子 */
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint& operator/=(const mint a) {
        x *= modinv(a).x;
        x %= MOD;
        return (*this);
    }
    mint& operator%=(const mint a) {
        x %= a.x;
        return (*this);
    }
    mint& operator++() {
        ++x;
        if (x >= MOD) x -= MOD;
        return *this;
    }
    mint& operator--() {
        if (!x) x += MOD;
        --x;
        return *this;
    }
    mint& operator&=(const mint a) {
        x &= a.x;
        return (*this);
    }
    mint& operator|=(const mint a) {
        x |= a.x;
        return (*this);
    }
    mint& operator^=(const mint a) {
        x ^= a.x;
        return (*this);
    }
    mint& operator<<=(const mint a) {
        x *= pow(2, a).x;
        return (*this);
    }
    mint& operator>>=(const mint a) {
        x /= pow(2, a).x;
        return (*this);
    }

    /* 算術演算子 */
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
    mint operator%(const mint a) const {
        mint res(*this);
        return res %= a;
    }
    mint operator&(const mint a) const {
        mint res(*this);
        return res &= a;
    }
    mint operator|(const mint a) const {
        mint res(*this);
        return res |= a;
    }
    mint operator^(const mint a) const {
        mint res(*this);
        return res ^= a;
    }
    mint operator<<(const mint a) const {
        mint res(*this);
        return res <<= a;
    }
    mint operator>>(const mint a) const {
        mint res(*this);
        return res >>= a;
    }

    /* 条件演算子 */
    bool operator==(const mint a) const noexcept { return x == a.x; }
    bool operator!=(const mint a) const noexcept { return x != a.x; }
    bool operator<(const mint a) const noexcept { return x < a.x; }
    bool operator>(const mint a) const noexcept { return x > a.x; }
    bool operator<=(const mint a) const noexcept { return x <= a.x; }
    bool operator>=(const mint a) const noexcept { return x >= a.x; }

    /* ストリーム挿入演算子 */
    friend istream& operator>>(istream& is, mint& m) {
        is >> m.x;
        m.x = (m.x % MOD + MOD) % MOD;
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& m) {
        os << m.x;
        return os;
    }

    /* その他の関数 */
    mint modinv(mint a) { return pow(a, MOD - 2); }
    mint pow(mint x, mint n) {
        mint res = 1;
        while (n.x > 0) {
            if ((n % 2).x) res *= x;
            x *= x;
            n.x /= 2;
        }
        return res;
    }
};

#define MAX_MINT_NCK 201010
mint f[MAX_MINT_NCK], rf[MAX_MINT_NCK];

bool isinit = false;

void init() {
    f[0] = 1;
    rf[0] = 1;
    for (int i = 1; i < MAX_MINT_NCK; i++) {
        f[i] = f[i - 1] * i;
        // rf[i] = modinv(f[i].x);
        rf[i] = f[i].pow(f[i], MOD - 2);
    }
}

mint nCk(mint n, mint k) {
    if (n < k) return 0;
    if (!isinit) {
        init();
        isinit = 1;
    }
    mint nl = f[n.x];          // n!
    mint nkl = rf[n.x - k.x];  // (n-k)!
    mint kl = rf[k.x];         // k!
    mint nkk = (nkl.x * kl.x);

    return nl * nkk;
}

map<ll, ll> prime;
void factorize(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            prime[i]++;
            n /= i;
        }
    }
    if (n != 1) {
        prime[n] = 1;
    }
}

int main() {
    int n, k;
    cin >> n >> k;
    mint ans = 0;
    for (int i = 0; i <= k; i++) {
        ans += mint(1).pow(-1, i) * nCk(k, i) * mint(1).pow(k - i, n);
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 6580
final_rank: 2