Problem:
E: And Partial Sum
問題
1
以上
S
以下の整数からなる長さ
N
の数列
C_0,C_1,...,C_{N-1}
が与えられます。
以下の条件を満たす
0
以上
2^N
未満の
相異なる
整数から成る要素数
K
の集合
X=\{x_1,x_2,...,x_K\}
を考えます。
x_1
AND
x_2
AND ... AND
x_K=Y
とする。(ここでANDはビットごとの論理積を表す)
2
進数で表した
Y
の最下位ビットを
0
ビット目として、
i
ビット目
(0\leq i\lt N)
が
1
のときに
C_i
を足す操作を行ったとき、その総和がちょうど
S
となる。(ビットが全て
0
の場合、総和は
0
とする)
上記の条件を満たすような集合
X
の総数を
10^9+7
で割った余りを求めてください。
入力形式
N
K
S
C_0
C_1
...
C_{N-1}
制約
1\leq N\leq 60
1\leq K\leq 3\times 10^5
K\leq 2^N
1\leq C_i\leq S\leq 5000 (0\leq i\lt N)
入力は全て整数
出力形式
条件を満たす集合
X
の個数を
10^9+7
で割った余りを出力してください。
入力例1
2 1 3
3 3
出力例1
2
集合
X
が
\{1\},\{2\}
のとき条件を満たします。
入力例2
4 3 10
4 5 6 7
出力例2
4
集合
X
が
\{5,7,13\},\{5,7,15\},\{5,13,15\},\{7,13,15\}
のとき条件を満たします。
入力例3
5 20 2
1 1 1 1 1
出力例3
0
条件を満たす集合
X
が存在しない場合もあります。
入力例4
8 3 1
1 1 1 1 1 1 1 1
出力例4
1089312

Submitted solutions:

code_snippet: // AOJ #3197 AND Partial Sum
// 2025.3.19

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll MOD = 1000000007;

ll modexp(ll a, ll b, ll m) {
    ll r = 1; a %= m;
    while(b) {
        if(b & 1) r = (r * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return r;
}

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

    int n, k, s;
    cin >> n >> k >> s;
    vector<int> c(n);
    for (int i = 0; i < n; i++) cin >> c[i];

    vector<vector<ll>> dp(n+1, vector<ll>(s+1, 0));
    dp[0][0] = 1;
    for (int i = 0; i < n; i++){
        for (int m = i; m >= 0; m--){
            for (int x = 0; x <= s - c[i]; x++){
                if(dp[m][x]) dp[m+1][x+c[i]] = (dp[m+1][x+c[i]] + dp[m][x]) % MOD;
            }
        }
    }

    vector<vector<ll>> cmb(n+1, vector<ll>(n+1, 0));
    for (int i = 0; i <= n; i++){
        cmb[i][0] = 1;
        for (int j = 1; j <= i; j++) cmb[i][j] = (cmb[i-1][j-1] + cmb[i-1][j]) % MOD;
    }

    vector<ll> f(k+1), invf(k+1);
    f[0] = 1;
    for (int i = 1; i <= k; i++) f[i] = (f[i-1] * i) % MOD;
    invf[k] = modexp(f[k], MOD-2, MOD);
    for (int i = k-1; i >= 0; i--) invf[i] = (invf[i+1] * (i+1)) % MOD;

    vector<ll> Fv(n+1, 0);
    for (int d = 0; d <= n; d++){
        ull Nval = 1ULL << d;
        if(Nval < (ull) k){
            Fv[d] = 0;
            continue;
        }
        ll prod = 1;
        for (int i = 0; i < k; i++) prod = (prod * (( (Nval - i) % MOD + MOD) % MOD)) % MOD;
        Fv[d] = (prod * invf[k]) % MOD;
    }

    vector<ll> Fcalc(n+1, 0);
    for (int L = 0; L <= n; L++){
        ll tot = 0;
        for (int j = 0; j <= L; j++){
            int d = L - j;
            ll t = cmb[L][j] * Fv[d] % MOD;
            if(j & 1) t = (MOD - t) % MOD;
            tot = (tot + t) % MOD;
        }
        Fcalc[L] = tot;
    }

    ll ans = 0;
    for (int m = 0; m <= n; m++) ans = (ans + dp[m][s] * Fcalc[n-m]) % MOD;
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 10168
final_rank: 2

code_snippet: #include<iostream>
using namespace std;
const long mod=1e9+7;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long fac[100],inv[100];
long C(int a,int b){return a<0||b<0||a<b?0L:fac[a]*inv[b]%mod*inv[a-b]%mod;}
long Ck[70];
long ok[70];
int c[60];
int N,K,S;
long dp[66][5050];
int main()
{
	fac[0]=1;
	for(int i=1;i<100;i++)fac[i]=fac[i-1]*i%mod;
	inv[99]=power(fac[99],mod-2);
	for(int i=99;i--;)inv[i]=inv[i+1]*(i+1)%mod;
	cin>>N>>K>>S;
	for(int i=0;i<N;i++)cin>>c[i];
	for(int i=0;i<70;i++)
	{
		long a=power(2,i);
		long x=1,y=1;
		for(int j=0;j<K;j++)
		{
			x=x*(a+mod-j)%mod;
			y=y*(j+1)%mod;
		}
		Ck[i]=x*power(y,mod-2)%mod;
	}
	for(int i=0;i<=60;i++)
	{
		long now=0;
		for(int l=0;l<=i;l++)
		{
			long tmp=C(i,l)*Ck[i-l]%mod;
			if(l%2==0)now+=tmp;
			else now+=mod-tmp;
			now%=mod;
		}
		ok[i]=now;
	}
	dp[N][S]=1;
	for(int i=0;i<N;i++)
	{
		for(int j=1;j<=N;j++)for(int k=c[i];k<=S;k++)
		{
			(dp[j-1][k-c[i]]+=dp[j][k])%=mod;
		}
	}
	long ans=0;
	for(int i=0;i<=N;i++)ans+=ok[i]*dp[i][0]%mod;
	cout<<ans%mod<<endl;
}
accuracy: 1
time_ms: 70
memory_kb: 5600
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> Graph;
const long long INF = 1LL<<60;
const long long MOD = 1000000007;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
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;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n,int k){
      return fact[n]*ifact[n-k];
  }
} comb(2000005);

mint dp[65][65][5005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,K,s;
    cin>>n>>K>>s;
    vec c(n);
    rep(i,n)cin>>c[i];
    dp[0][0][0]=1;
    rep(i,n){
        rep(j,n){
            rep(k,5005){
                dp[i+1][j][k]+=dp[i][j][k];
                if(k+c[i]<=5000)dp[i+1][j+1][k+c[i]]+=dp[i][j][k];
            }
        }
    }
    vector<mint> g(61);
    mint inv=1;
    repd(i,1,K+1)inv*=i;
    inv=mint(1)/inv;
    rep(i,61){
        ll x=(1LL<<i);
        //cout<<x<<endl;
        if(x<K)continue;
        mint now=1;
        rep(j,K){
            now*=(x-j);
        }
        now*=inv;
        g[i]=now;
    }
    mint ans=0;
    repd(i,1,n+1){
        mint now=dp[n][i][s];
        mint x=0;
        rep(j,n-i+1){
            mint memo=g[n-i-j];
            memo*=comb(n-i,j);
            if(j%2==0)x+=memo;
            else x-=memo;
        }
        now*=x;
        ans+=now;
    }
    cout<<ans<<endl;
    return 0;
}
accuracy: 1
time_ms: 140
memory_kb: 199080
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> Graph;
const long long INF = 1LL<<60;
const long long MOD = 1000000007;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
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;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n,int k){
      return fact[n]*ifact[n-k];
  }
} comb(2000005);

mint dp[65][65][5005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,K,s;
    cin>>n>>K>>s;
    vec c(n);
    rep(i,n)cin>>c[i];
    dp[0][0][0]=1;
    rep(i,n){
        rep(j,n){
            rep(k,5005){
                dp[i+1][j][k]+=dp[i][j][k];
                if(k+c[i]<=5000)dp[i+1][j+1][k+c[i]]+=dp[i][j][k];
            }
        }
    }
    vector<mint> g(61);
    mint inv=1;
    repd(i,1,K+1)inv*=i;
    inv=mint(1)/inv;
    rep(i,61){
        ll x=(1LL<<i);
        //cout<<x<<endl;
        if(x<K)continue;
        mint now=1;
        rep(j,K){
            now*=(x-j);
        }
        now*=inv;
        g[i]=now;
    }
    mint ans=0;
    repd(i,1,n+1){
        mint now=dp[n][i][s];
        mint x=0;
        rep(j,n-i+1){
            mint memo=g[n-1-j];
            memo*=comb(n-i,j);
            if(j%2==0)x+=memo;
            else x-=memo;
        }
        now*=x;
        ans+=now;
    }
    cout<<ans<<endl;
    return 0;
}
accuracy: 0.03225806451612903
time_ms: 30
memory_kb: 199216
final_rank: 20

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



#include <utility>

namespace atcoder {

namespace internal {

// @param m `1 <= m`
// @return x mod m
constexpr long long safe_mod(long long x, long long m) {
    x %= m;
    if (x < 0) x += m;
    return x;
}

// Fast moduler by barrett reduction
// Reference: https://en.wikipedia.org/wiki/Barrett_reduction
// NOTE: reconsider after Ice Lake
struct barrett {
    unsigned int _m;
    unsigned long long im;

    // @param m `1 <= m`
    barrett(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {}

    // @return m
    unsigned int umod() const { return _m; }

    // @param a `0 <= a < m`
    // @param b `0 <= b < m`
    // @return `a * b % m`
    unsigned int mul(unsigned int a, unsigned int b) const {
        // [1] m = 1
        // a = b = im = 0, so okay

        // [2] m >= 2
        // im = ceil(2^64 / m)
        // -> im * m = 2^64 + r (0 <= r < m)
        // let z = a*b = c*m + d (0 <= c, d < m)
        // a*b * im = (c*m + d) * im = c*(im*m) + d*im = c*2^64 + c*r + d*im
        // c*r + d*im < m * m + m * im < m * m + 2^64 + m <= 2^64 + m * (m + 1) < 2^64 * 2
        // ((ab * im) >> 64) == c or c + 1
        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;
    }
};

// @param n `0 <= n`
// @param m `1 <= m`
// @return `(x ** n) % m`
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;
}

// Reference:
// M. Forisek and J. Jancina,
// Fast Primality Testing for Integers That Fit into a Machine Word
// @param n `0 <= n`
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;
    for (long long a : {2, 7, 61}) {
        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);

// @param b `1 <= b`
// @return pair(g, x) s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g
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};

    // Contracts:
    // [1] s - m0 * a = 0 (mod b)
    // [2] t - m1 * a = 0 (mod b)
    // [3] s * |m1| + t * |m0| <= b
    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

        // [3]:
        // (s - t * u) * |m1| + t * |m0 - m1 * u|
        // <= s * |m1| - t * u * |m1| + t * (|m0| + |m1| * u)
        // = s * |m1| + t * |m0| <= b

        auto tmp = s;
        s = t;
        t = tmp;
        tmp = m0;
        m0 = m1;
        m1 = tmp;
    }
    // by [3]: |m0| <= b/g
    // by g != b: |m0| < b/g
    if (m0 < 0) m0 += b / s;
    return {s, m0};
}

// Compile time primitive root
// @param m must be prime
// @return primitive root (and minimum in now)
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);

}  // 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

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

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

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());
    }
    static_modint(bool 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());
    }
    dynamic_modint(bool 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


#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second

using namespace std;

typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

template <typename T>
struct coord_comp {
    vector<T> v;
    bool sorted = false;

    coord_comp() {}

    int size() { return v.size(); }

    void add(T x) { v.push_back(x); }

    void build() {
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        sorted = true;
    }

    int get_idx(T x) {
        assert(sorted);
        return lower_bound(v.begin(), v.end(), x) - v.begin();
    }
};

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

using namespace atcoder;
using mint = modint1000000007;

vector<mint> fact;
vector<mint> revfact;

void setfact(int n) {
    fact.resize(n + 1);
    revfact.resize(n + 1);
    fact[0] = 1;
    rep(i, n) fact[i + 1] = fact[i] * mint(i + 1);

    revfact[n] = fact[n].inv();
    for (int i = n - 1; i >= 0; i--) revfact[i] = revfact[i + 1] * mint(i + 1);
}

mint getC(int n, int r) {
    if (n < r || r < 0) return 0;
    return fact[n] * revfact[r] * revfact[n - r];
}

int main() {
    int n, K, S;
    scanf("%d%d%d", &n, &K, &S);
    int c[n];
    rep(i, n) scanf("%d", &c[i]);

    vector<vector<mint>> dp(n + 1, vector<mint>(S + 1, 0));
    dp[0][0] = 1;
    rep(i, n) {
        vector<vector<mint>> nxt(n + 1, vector<mint>(S + 1, 0));
        rep(j, n + 1) rep(s, S + 1) if (dp[j][s] != 0) {
            if (j < n && s + c[i] <= S) nxt[j + 1][s + c[i]] += dp[j][s];
            nxt[j][s] += dp[j][s];
        }
        swap(dp, nxt);
    }

    setfact(max(n, K));
    mint comb[n + 1];
    rep(i, n + 1) {
        lint m = 1LL << i;
        if (m < K) {
            comb[i] = 0;
            continue;
        }
        comb[i] = revfact[K];
        for (lint j = m; j > m - K; --j) comb[i] *= mint(j);
    }

    mint ans = 0;
    For(j, 1, n + 1) if (dp[j][S] != 0) {
        mint sum = 0;
        rep(l, n - j + 1) {
            mint tmp = getC(n - j, l) * comb[n - j - l];
            if (l % 2 == 0)
                sum += tmp;
            else
                sum -= tmp;
        }
        ans += dp[j][S] * sum;
    }
    printf("%u\n", ans.val());
}
accuracy: 1
time_ms: 60
memory_kb: 6700
final_rank: 4

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

const long long MOD = 1e9 + 7;
const int N = 3e5 + 111;

long long r[N];

long long cnk(long long n, long long k)
{
    if (k > n || k < 0) return 0;
    if (k == 0) return 1;
    long long c = cnk(n, k - 1);
    c = c * ((n - k + 1) % MOD) % MOD;
    c = c * r[k] % MOD;
    return c;
}

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

    long long n, k;
    cin >> n >> k;

    r[1] = 1;
    for (int i = 2; i < N; i++) r[i] = MOD - r[MOD % i] * (MOD / i) % MOD;

    vector<long long> ways(n + 1);
    for (int i = n; i >= 0; i--)
    {
        ways[i] = cnk((1ll << (n - i)), k);
        if (i + 1 <= n)
        {
            for (int j = i + 1; j <= n; j++)
            {
                ways[i] = (ways[i] - cnk(n - i, j - i) * ways[j]) % MOD;
            }
            ways[i] = (ways[i] + MOD) % MOD;
        }
    }

    long long ans = 0;
    long long s;
    cin >> s;
    vector<long long> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];

    vector<vector<long long> > dp(s + 1, vector<long long>(n + 1));
    dp[0][0] = 1;
    for (int i = 0; i < n; i++)
    {
        for (int u = i; u >= 0; u--)
        {
            for (int s1 = 0; s1 + a[i] <= s; s1++)
            {
                dp[s1 + a[i]][u + 1] = (dp[s1 + a[i]][u + 1] + dp[s1][u]) % MOD;
            }
        }
    }
    for (int sel = 0; sel <= n; sel++)
    {
        ans = (ans + dp[s][sel] * ways[sel]) % MOD;
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 150
memory_kb: 17140
final_rank: 7

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 9223372036854775807
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 1000005


ll N,K,S;
ll POW[65],value[65];
ll dp[65][5005],dp2[65];
ll fact[SIZE],inv_fact[SIZE];



ll mod_pow(ll x,ll count, ll mod){

	if(count == 0)return 1;
	ll ret = mod_pow((x*x)%mod,count/2,mod);
	if(count%2 == 1){

		ret = (ret*x)%mod;
	}
	return ret;
}

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

ll mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

ll nCk(ll n,ll k){

	if(k > n)return 0;

	ll ret = fact[n]*inv_fact[k];
	ret %= MOD;
	ret *= inv_fact[n-k];

	return ret%MOD;
}



int main(){

	fact[0] = 1;
	for(ll i = 1; i < SIZE; i++){
		fact[i] = i*fact[i-1];
		fact[i] %= MOD;
	}
	inv_fact[SIZE-1] = mod_inverse(fact[SIZE-1],MOD);
	for(ll i = SIZE-1; i >= 1; i--){

		inv_fact[i-1] = inv_fact[i]*i;
		inv_fact[i-1] %= MOD;
	}

	POW[0] = 1;
	for(int i = 1; i < 65; i++){

		POW[i] = POW[i-1]*2;
		POW[i] %= MOD;
	}

	scanf("%lld %lld %lld",&N,&K,&S);

	for(ll i = 0; i < N; i++){

		scanf("%lld",&value[i]);
	}



	for(ll i = 0; i <= N; i++){
		for(ll k = 0; k <= S; k++){
			dp[i][k] = 0;
		}
	}

	dp[0][0] = 1; //dp[個数][和] := 場合の数

	for(ll i = 0; i < N; i++){
		for(ll k = i; k >= 0; k--){//加算済の個数
			for(ll p = S-value[i]; p >= 0; p--){ //和
				if(dp[k][p] == 0)continue;

				dp[k+1][p+value[i]] += dp[k][p];
				dp[k+1][p+value[i]] %= MOD;
			}
		}
	}


	for(ll num = 0; num < 61; num++){
		ll work = 0;
		for(ll a = 0;  a <= num; a++){ //a個の桁が全て1

			if(POW[num-a] < K)continue;
			ll tmp = nCk(num,a);

			for(ll b = 0; b < K; b++){

				tmp *= (POW[num-a]-b+MOD)%MOD;
				tmp %= MOD;
			}
			tmp *= inv_fact[K];
			tmp %= MOD;

			if(a%2 == 0){

				work += tmp;
				work %= MOD;
			}else{

				work -= tmp;
				if(work < 0){
					work += MOD;
				}
			}
		}
		dp2[num] = work;
	}

	ll ans = 0;

	for(ll num = 1; num <= N; num++){
		if(dp[num][S] == 0)continue;

		ll num_free = N-num;
		ll tmp = dp2[num_free];

		tmp *= dp[num][S];
		tmp %= MOD;

		ans += tmp;
		ans %= MOD;
	}

	printf("%lld\n",ans);

	return 0;
}
accuracy: 1
time_ms: 940
memory_kb: 21236
final_rank: 10

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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}


template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}


template<typename M_>
class Enumeration{
  using M = M_;
protected:
  static vector<M> fact,finv,invs;
public:
  static void init(int n){
    n=min<decltype(M::mod)>(n,M::mod-1);

    int m=fact.size();
    if(n<m) return;

    fact.resize(n+1,1);
    finv.resize(n+1,1);
    invs.resize(n+1,1);

    if(m==0) m=1;
    for(int i=m;i<=n;i++) fact[i]=fact[i-1]*M(i);
    finv[n]=M(1)/fact[n];
    for(int i=n;i>=m;i--) finv[i-1]=finv[i]*M(i);
    for(int i=m;i<=n;i++) invs[i]=finv[i]*fact[i-1];
  }

  static M Fact(int n){
    init(n);
    return fact[n];
  }
  static M Finv(int n){
    init(n);
    return finv[n];
  }
  static M Invs(int n){
    init(n);
    return invs[n];
  }

  static M C(int n,int k){
    if(n<k||k<0) return M(0);
    init(n);
    return fact[n]*finv[n-k]*finv[k];
  }

  static M P(int n,int k){
    if(n<k||k<0) return M(0);
    init(n);
    return fact[n]*finv[n-k];
  }

  // put n identical balls into k distinct boxes
  static M H(int n,int k){
    if(n<0||k<0) return M(0);
    if(!n&&!k) return M(1);
    init(n+k);
    return C(n+k-1,n);
  }
};
template<typename M>
vector<M> Enumeration<M>::fact=vector<M>();
template<typename M>
vector<M> Enumeration<M>::finv=vector<M>();
template<typename M>
vector<M> Enumeration<M>::invs=vector<M>();

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

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

  auto cs=read(n);

  using M = Mint<int>;

  auto dp=make_v<M>(n+1,s+1);
  fill_v<M>(dp,0);
  dp[0][0]=M(1);

  for(int c:cs){
    auto nx=make_v<M>(n+1,s+1);
    fill_v<M>(nx,0);

    for(int j=0;j<=n;j++){
      for(int x=0;x<=s;x++){
        // not use
        if(j+1<=n)
          nx[j+1][x]+=dp[j][x];

        // use
        if(x+c<=s)
          nx[j][x+c]+=dp[j][x];
      }
    }
    swap(dp,nx);
  }

  vector<M> pre(n+1,0);
  for(int i=0;i<=n;i++)
    pre[i]=M::comb(1LL<<i,k);

  using E = Enumeration<M>;
  vector<M> way(n+1,0);
  for(int x=0;x<=n;x++){
    for(int y=0;y<=x;y++){
      M res=E::C(x,y)*pre[x-y];
      if(y&1) way[x]-=res;
      else way[x]+=res;
    }
  }

  M ans{0};
  for(int j=0;j<=n;j++)
    ans+=dp[j][s]*way[j];
  cout<<ans<<newl;
  return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 5600
final_rank: 6

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1e18;
const ll mod = 1000000007;
ll N, K, S;
ll C[70];
ll dp1[70][70][5005];
ll dp2[70];
ll ans;
vector<ll> inv, FactorialInv, Factorial;
ll beki(ll a, ll b){
    ll ret = 1 % mod;
    a %= mod;
    while(b) {
        if(b & 1LL) ret = ret * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ret;
}
void init_combination(ll MAX){
    Factorial.resize(MAX + 1);
    FactorialInv.resize(MAX + 1);
    inv.resize(MAX + 1);
    Factorial[0] = 1;
    inv[0] = 1;
    for(int i = 1; i <= MAX; i++){
        Factorial[i] = Factorial[i - 1] * i % mod;
    }
    FactorialInv[MAX] = beki(Factorial[MAX], mod - 2);
    for(ll i = MAX - 1; i >= 0; i--) {
        FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
    }
    for(int i = 1; i <= MAX; i++) {
        inv[i] = FactorialInv[i] * Factorial[i-1] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    if(b < 0) return 0;
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}

ll combination2(ll N, ll K) {
    ll ret = 1;
    for(ll i = 0; i < K; i++) {
        ret *= ((N - i) % mod);
        ret %= mod;
        ret *= inv[i+1];
        ret %= mod;
    }
    return ret;
}

int main() {
    cin >> N >> K >> S;
    init_combination(1000000);
    for(int i = 0; i < N; i++) cin >> C[i];
    dp1[0][0][0] = 1;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= N; j++) {
            for(int k = 0; k <= S; k++) {
                dp1[i+1][j][k] += dp1[i][j][k];
                dp1[i+1][j][k] %= mod;
                if(k + C[i] <= S) {
                    dp1[i+1][j+1][k+C[i]] += dp1[i][j][k];
                    dp1[i+1][j+1][k+C[i]] %= mod;
                }
            }
        }
    }
    for(ll i = N; i >= 0; i--) {
        ll num = (1LL << (N - i));
        if(num < K) continue;
        dp2[i] = combination2(num, K);
        for(int j = i + 1; j <= N; j++) {
            dp2[i] -= dp2[j] * combination(N - i, N - j);
            dp2[i] %= mod;
            dp2[i] += mod;
            dp2[i] %= mod;
        }
    }
    for(int i = 0; i <= N; i++) {
        //cerr << i << " " << dp1[N][i][S] << " " << dp2[i] << endl;
        ans += dp1[N][i][S] * dp2[i];
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 192496
final_rank: 11

code_snippet: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

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

	int S;
	cin >> N >> K >> S;
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	vector<vector<long long int>>dp(N + 1, vector<long long int>(S + 1));
	dp[0][0] = 1;
	for (auto i : v) {
		for (int j = N; j > 0; j--) {
			for (int k = S; k >= i; k--) {
				dp[j][k] += dp[j - 1][k - i];
				dp[j][k] %= MOD;
			}
		}
	}
	vector<long long int>ncr(N + 1);
	bool flag = false;
	long long int rev = 1;
	for (int i = 1; i <= K; i++) {
		rev *= i;
		rev %= MOD;
	}
	rev = power(rev, MOD - 2, MOD);
	for (int i = 0; i <= N; i++) {
		if (!flag&&power(2, i, MOD) >= K)flag = true;
		if (!flag)continue;
		ncr[i] = 1;
		long long int by = power(2, i, MOD);
		for (int j = 1; j <= K; j++) {
			ncr[i] *= by;
			ncr[i] %= MOD;
			by += MOD - 1;
			by %= MOD;
		}
		ncr[i] *= rev;
		ncr[i] %= MOD;
	}
	vector<vector<long long int>>nCr(N + 1, vector<long long int>(N + 1));
	for (int i = 0; i <= N; i++) {
		nCr[i][0] = 1;
		for (int j = 1; j <= i; j++) {
			nCr[i][j] = nCr[i - 1][j - 1] + nCr[i - 1][j];
			nCr[i][j] %= MOD;
		}
	}
	long long int ans = 0;
	for (int num = 0; num <= N; num++) {
		long long int add = dp[num].back();
		long long int by = 0;
		for (int i = 0; i <= N - num; i++) {
			int b = N - num - i;
			if (i & 1)by += MOD - nCr[N - num][i] * ncr[b] % MOD;
			else by += nCr[N - num][i] * ncr[b] % MOD;
			by %= MOD;
		}
		ans += add * by;
		ans %= MOD;
	}
	cout << ans << endl;
}
accuracy: 1
time_ms: 50
memory_kb: 5280
final_rank: 1

code_snippet: #include "bits/stdc++.h"
using namespace std;
//#include "atcoder/all"
//using namespace atcoder;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

template<int MOD> struct Fp {
	long long val;
	constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
		if (val < 0) val += MOD;
	}
	constexpr int getmod() { return MOD; }
	constexpr Fp operator - () const noexcept {
		return val ? MOD - val : 0;
	}
	constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
	constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
	constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
	constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
	constexpr Fp& operator += (const Fp& r) noexcept {
		val += r.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}
	constexpr Fp& operator -= (const Fp& r) noexcept {
		val -= r.val;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr Fp& operator *= (const Fp& r) noexcept {
		val = val * r.val % MOD;
		return *this;
	}
	constexpr Fp& operator /= (const Fp& r) noexcept {
		long long a = r.val, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % MOD;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr bool operator == (const Fp& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Fp& r) const noexcept {
		return this->val != r.val;
	}
	friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
		return os << x.val;
	}
	friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
		if (n == 0) return 1;
		auto t = modpow(a, n / 2);
		t = t * t;
		if (n & 1) t = t * a;
		return t;
	}
};
 

template<class T> struct BiCoef {
	vector<T> fact_, inv_, finv_;
	constexpr BiCoef() {}
	constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
		init(n);
	}
	constexpr void init(int n) noexcept {
		fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
		int MOD = fact_[0].getmod();
		for(int i = 2; i < n; i++){
			fact_[i] = fact_[i-1] * i;
			inv_[i] = -inv_[MOD%i] * (MOD/i);
			finv_[i] = finv_[i-1] * inv_[i];
		}
	}
	constexpr T com(int n, int k) const noexcept {
		if (n < k || n < 0 || k < 0) return 0;
		return fact_[n] * finv_[k] * finv_[n-k];
	}
	constexpr T P(int n, int k) const noexcept {
		if (n < k || n < 0 || k < 0) return 0;
		return fact_[n] * finv_[n-k];
	}
	constexpr T fact(int n) const noexcept {
		if (n < 0) return 0;
		return fact_[n];
	}
	constexpr T inv(int n) const noexcept {
		if (n < 0) return 0;
		return inv_[n];
	}
	constexpr T finv(int n) const noexcept {
		if (n < 0) return 0;
		return finv_[n];
	}
};
 
const int MOD = 1000000007;
// const int MOD = 998244353;
using mint = Fp<MOD>;
BiCoef<mint> bc;
// bc.init(500050);

int dp[66][66][5005] = {};

signed main(){
	bc.init(500050);
	int N, K, S;
	cin >> N >> K >> S;
	vector<int>c(N);
	cin >> c;
	
	dp[0][0][0] = 1;
	REP(i, N) {
		REP(j, N + 1) {
			REP(k, S + 1) {
				dp[i + 1][j][k] += dp[i][j][k];
				if(k + c[i] <= S) {
					dp[i + 1][j + 1][k + c[i]] += dp[i][j][k];
				}
			}
		}
	}
	vector<mint>cnt(100010);

	mint div = 1;
	REP(i, K) div /= i + 1;
	mint ans = 0;
	REP(j, N + 1) {
		mint t = 0;
		REP(i, N - j + 1) {
			mint mul = 1;
			if(N - j - i < 0) while(1);
			mint beki = modpow(mint(2), N - j - i);
			if(cnt[N - j - i] != 0) mul *= cnt[N - j - i];
			else {
				REP(k, K) {
					mul *= beki - k;
				}
				cnt[N - j - i] = mul;
			}
			mul *= bc.com(N - j, i) * div;
			if(i % 2 == 0) {
				t += mul;
			} else {
				t -= mul;
			}
		}
		ans += t * dp[N][j][S];
	}
	out(ans);
}
accuracy: 1
time_ms: 980
memory_kb: 171276
final_rank: 13

code_snippet: #include "bits/stdc++.h"
using namespace std;
//#include "atcoder/all"
//using namespace atcoder;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

template<int MOD> struct Fp {
	long long val;
	constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
		if (val < 0) val += MOD;
	}
	constexpr int getmod() { return MOD; }
	constexpr Fp operator - () const noexcept {
		return val ? MOD - val : 0;
	}
	constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
	constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
	constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
	constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
	constexpr Fp& operator += (const Fp& r) noexcept {
		val += r.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}
	constexpr Fp& operator -= (const Fp& r) noexcept {
		val -= r.val;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr Fp& operator *= (const Fp& r) noexcept {
		val = val * r.val % MOD;
		return *this;
	}
	constexpr Fp& operator /= (const Fp& r) noexcept {
		long long a = r.val, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % MOD;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr bool operator == (const Fp& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Fp& r) const noexcept {
		return this->val != r.val;
	}
	friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
		return os << x.val;
	}
	friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
		if (n == 0) return 1;
		auto t = modpow(a, n / 2);
		t = t * t;
		if (n & 1) t = t * a;
		return t;
	}
};
 

template<class T> struct BiCoef {
	vector<T> fact_, inv_, finv_;
	constexpr BiCoef() {}
	constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
		init(n);
	}
	constexpr void init(int n) noexcept {
		fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
		int MOD = fact_[0].getmod();
		for(int i = 2; i < n; i++){
			fact_[i] = fact_[i-1] * i;
			inv_[i] = -inv_[MOD%i] * (MOD/i);
			finv_[i] = finv_[i-1] * inv_[i];
		}
	}
	constexpr T com(int n, int k) const noexcept {
		if (n < k || n < 0 || k < 0) return 0;
		return fact_[n] * finv_[k] * finv_[n-k];
	}
	constexpr T P(int n, int k) const noexcept {
		if (n < k || n < 0 || k < 0) return 0;
		return fact_[n] * finv_[n-k];
	}
	constexpr T fact(int n) const noexcept {
		if (n < 0) return 0;
		return fact_[n];
	}
	constexpr T inv(int n) const noexcept {
		if (n < 0) return 0;
		return inv_[n];
	}
	constexpr T finv(int n) const noexcept {
		if (n < 0) return 0;
		return finv_[n];
	}
};
 
const int MOD = 1000000007;
// const int MOD = 998244353;
using mint = Fp<MOD>;
BiCoef<mint> bc;
// bc.init(500050);

signed main(){
	bc.init(500050);
	int N, K, S;
	cin >> N >> K >> S;
	vector<int>c(N);
	cin >> c;
	int dp[N + 10][N + 10][S + 1] = {};
	
	dp[0][0][0] = 1;
	REP(i, N) {
		REP(j, N + 1) {
			REP(k, S + 1) {
				dp[i + 1][j][k] += dp[i][j][k];
				if(k + c[i] <= S) {
					dp[i + 1][j + 1][k + c[i]] += dp[i][j][k];
				}
			}
		}
	}
	vector<mint>cnt(N * 2);

	mint div = 1;
	REP(i, K) div /= i + 1;
	mint ans = 0;
	REP(j, N + 1) {
		mint t = 0;
		REP(i, N - j + 1) {
			mint mul = 1;
			if(N - j - i < 0) while(1);
			mint beki = modpow(mint(2), N - j - i);
			if(cnt[N - j - i] != 0) mul *= cnt[N - j - i];
			else {
				REP(k, K) {
					mul *= beki - k;
				}
				cnt[N - j - i] = mul;
			}
			mul *= bc.com(N - j, i) * div;
			if(i % 2 == 0) {
				t += mul;
			} else {
				t -= mul;
			}
		}
		ans += t * dp[N][j][S];
	}
	out(ans);
}
accuracy: 0.45161290322580644
time_ms: 10
memory_kb: 14704
final_rank: 17

code_snippet: #include "bits/stdc++.h"
using namespace std;
//#include "atcoder/all"
//using namespace atcoder;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

template<int MOD> struct Fp {
	long long val;
	constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
		if (val < 0) val += MOD;
	}
	constexpr int getmod() { return MOD; }
	constexpr Fp operator - () const noexcept {
		return val ? MOD - val : 0;
	}
	constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
	constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
	constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
	constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
	constexpr Fp& operator += (const Fp& r) noexcept {
		val += r.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}
	constexpr Fp& operator -= (const Fp& r) noexcept {
		val -= r.val;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr Fp& operator *= (const Fp& r) noexcept {
		val = val * r.val % MOD;
		return *this;
	}
	constexpr Fp& operator /= (const Fp& r) noexcept {
		long long a = r.val, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % MOD;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr bool operator == (const Fp& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Fp& r) const noexcept {
		return this->val != r.val;
	}
	friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
		return os << x.val;
	}
	friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
		if (n == 0) return 1;
		auto t = modpow(a, n / 2);
		t = t * t;
		if (n & 1) t = t * a;
		return t;
	}
};
 

template<class T> struct BiCoef {
	vector<T> fact_, inv_, finv_;
	constexpr BiCoef() {}
	constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
		init(n);
	}
	constexpr void init(int n) noexcept {
		fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
		int MOD = fact_[0].getmod();
		for(int i = 2; i < n; i++){
			fact_[i] = fact_[i-1] * i;
			inv_[i] = -inv_[MOD%i] * (MOD/i);
			finv_[i] = finv_[i-1] * inv_[i];
		}
	}
	constexpr T com(int n, int k) const noexcept {
		if (n < k || n < 0 || k < 0) return 0;
		return fact_[n] * finv_[k] * finv_[n-k];
	}
	constexpr T P(int n, int k) const noexcept {
		if (n < k || n < 0 || k < 0) return 0;
		return fact_[n] * finv_[n-k];
	}
	constexpr T fact(int n) const noexcept {
		if (n < 0) return 0;
		return fact_[n];
	}
	constexpr T inv(int n) const noexcept {
		if (n < 0) return 0;
		return inv_[n];
	}
	constexpr T finv(int n) const noexcept {
		if (n < 0) return 0;
		return finv_[n];
	}
};
 
const int MOD = 1000000007;
// const int MOD = 998244353;
using mint = Fp<MOD>;
BiCoef<mint> bc;
// bc.init(500050);

signed main(){
	bc.init(500050);
	int N, K, S;
	cin >> N >> K >> S;
	vector<int>c(N);
	cin >> c;
	int dp[N + 10][N + 10][S + 1] = {};
	
	dp[0][0][0] = 1;
	REP(i, N) {
		REP(j, N + 1) {
			REP(k, S + 1) {
				dp[i + 1][j][k] += dp[i][j][k];
				if(k + c[i] <= S) {
					dp[i + 1][j + 1][k + c[i]] += dp[i][j][k];
				}
			}
		}
	}
	vector<mint>cnt(N * 2);

	mint div = 1;
	REP(i, K) div /= i + 1;
	mint ans = 0;
	REP(j, N + 1) {
		mint t = 0;
		REP(i, N - j + 1) {
			mint mul = 1;
			mint beki = modpow(mint(2), N - j - i);
			if(cnt[N - j - i] != 0) mul *= cnt[N - j - i];
			else {
				REP(k, K) {
					mul *= beki - k;
				}
				cnt[N - j - i] = mul;
			}
			mul *= bc.com(N - j, i) * div;
			if(i % 2 == 0) {
				t += mul;
			} else {
				t -= mul;
			}
		}
		ans += t * dp[N][j][S];
	}
	out(ans);
}
accuracy: 0.45161290322580644
time_ms: 10
memory_kb: 14664
final_rank: 16

code_snippet: #include "bits/stdc++.h"
using namespace std;
//#include "atcoder/all"
//using namespace atcoder;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

template<int MOD> struct Fp {
	long long val;
	constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
		if (val < 0) val += MOD;
	}
	constexpr int getmod() { return MOD; }
	constexpr Fp operator - () const noexcept {
		return val ? MOD - val : 0;
	}
	constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
	constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
	constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
	constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
	constexpr Fp& operator += (const Fp& r) noexcept {
		val += r.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}
	constexpr Fp& operator -= (const Fp& r) noexcept {
		val -= r.val;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr Fp& operator *= (const Fp& r) noexcept {
		val = val * r.val % MOD;
		return *this;
	}
	constexpr Fp& operator /= (const Fp& r) noexcept {
		long long a = r.val, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % MOD;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr bool operator == (const Fp& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Fp& r) const noexcept {
		return this->val != r.val;
	}
	friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
		return os << x.val;
	}
	friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
		if (n == 0) return 1;
		auto t = modpow(a, n / 2);
		t = t * t;
		if (n & 1) t = t * a;
		return t;
	}
};
 

template<class T> struct BiCoef {
	vector<T> fact_, inv_, finv_;
	constexpr BiCoef() {}
	constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
		init(n);
	}
	constexpr void init(int n) noexcept {
		fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
		int MOD = fact_[0].getmod();
		for(int i = 2; i < n; i++){
			fact_[i] = fact_[i-1] * i;
			inv_[i] = -inv_[MOD%i] * (MOD/i);
			finv_[i] = finv_[i-1] * inv_[i];
		}
	}
	constexpr T com(int n, int k) const noexcept {
		if (n < k || n < 0 || k < 0) return 0;
		return fact_[n] * finv_[k] * finv_[n-k];
	}
	constexpr T P(int n, int k) const noexcept {
		if (n < k || n < 0 || k < 0) return 0;
		return fact_[n] * finv_[n-k];
	}
	constexpr T fact(int n) const noexcept {
		if (n < 0) return 0;
		return fact_[n];
	}
	constexpr T inv(int n) const noexcept {
		if (n < 0) return 0;
		return inv_[n];
	}
	constexpr T finv(int n) const noexcept {
		if (n < 0) return 0;
		return finv_[n];
	}
};
 
const int MOD = 1000000007;
// const int MOD = 998244353;
using mint = Fp<MOD>;
BiCoef<mint> bc;
// bc.init(500050);

signed main(){
	bc.init(500050);
	int N, K, S;
	cin >> N >> K >> S;
	vector<int>c(N);
	cin >> c;
	int dp[N + 1][N + 1][S + 1] = {};
	
	dp[0][0][0] = 1;
	REP(i, N) {
		REP(j, N) {
			REP(k, S + 1) {
				dp[i + 1][j][k] += dp[i][j][k];
				if(k + c[i] <= S) {
					dp[i + 1][j + 1][k + c[i]] += dp[i][j][k];
				}
			}
		}
	}
	vector<mint>cnt(N * 2);

	mint div = 1;
	REP(i, K) div /= i + 1;
	mint ans = 0;
	REP(j, N + 1) {
		mint t = 0;
		REP(i, N - j + 1) {
			mint mul = 1;
			mint beki = modpow(mint(2), N - j - i);
			if(cnt[N - j - i] != 0) mul *= cnt[N - j - i];
			else {
				REP(k, K) {
					mul *= beki - k;
				}
				cnt[N - j - i] = mul;
			}
			mul *= bc.com(N - j, i) * div;
			if(i % 2 == 0) {
				t += mul;
			} else {
				t -= mul;
			}
		}
		ans += t * dp[N][j][S];
	}
	out(ans);
}
accuracy: 0.5483870967741935
time_ms: 670
memory_kb: 62192
final_rank: 15

code_snippet: #include "bits/stdc++.h"
using namespace std;
//#include "atcoder/all"
//using namespace atcoder;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

template<int MOD> struct Fp {
	long long val;
	constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
		if (val < 0) val += MOD;
	}
	constexpr int getmod() { return MOD; }
	constexpr Fp operator - () const noexcept {
		return val ? MOD - val : 0;
	}
	constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
	constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
	constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
	constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
	constexpr Fp& operator += (const Fp& r) noexcept {
		val += r.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}
	constexpr Fp& operator -= (const Fp& r) noexcept {
		val -= r.val;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr Fp& operator *= (const Fp& r) noexcept {
		val = val * r.val % MOD;
		return *this;
	}
	constexpr Fp& operator /= (const Fp& r) noexcept {
		long long a = r.val, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % MOD;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr bool operator == (const Fp& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Fp& r) const noexcept {
		return this->val != r.val;
	}
	friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
		return os << x.val;
	}
	friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
		if (n == 0) return 1;
		auto t = modpow(a, n / 2);
		t = t * t;
		if (n & 1) t = t * a;
		return t;
	}
};
 

template<class T> struct BiCoef {
	vector<T> fact_, inv_, finv_;
	constexpr BiCoef() {}
	constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
		init(n);
	}
	constexpr void init(int n) noexcept {
		fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
		int MOD = fact_[0].getmod();
		for(int i = 2; i < n; i++){
			fact_[i] = fact_[i-1] * i;
			inv_[i] = -inv_[MOD%i] * (MOD/i);
			finv_[i] = finv_[i-1] * inv_[i];
		}
	}
	constexpr T com(int n, int k) const noexcept {
		if (n < k || n < 0 || k < 0) return 0;
		return fact_[n] * finv_[k] * finv_[n-k];
	}
	constexpr T P(int n, int k) const noexcept {
		if (n < k || n < 0 || k < 0) return 0;
		return fact_[n] * finv_[n-k];
	}
	constexpr T fact(int n) const noexcept {
		if (n < 0) return 0;
		return fact_[n];
	}
	constexpr T inv(int n) const noexcept {
		if (n < 0) return 0;
		return inv_[n];
	}
	constexpr T finv(int n) const noexcept {
		if (n < 0) return 0;
		return finv_[n];
	}
};
 
const int MOD = 1000000007;
// const int MOD = 998244353;
using mint = Fp<MOD>;
BiCoef<mint> bc;
// bc.init(500050);

signed main(){
	bc.init(500050);
	int N, K, S;
	cin >> N >> K >> S;
	vector<int>c(N);
	cin >> c;
	int dp[N + 1][N + 1][S + 1] = {};
	
	dp[0][0][0] = 1;
	REP(i, N) {
		REP(j, N) {
			REP(k, S + 1) {
				dp[i + 1][j][k] += dp[i][j][k];
				if(k + c[i] <= S) {
					dp[i + 1][j + 1][k + c[i]] += dp[i][j][k];
				}
			}
		}
	}
	unordered_map<int, mint>mp;

	mint div = 1;
	REP(i, K) div /= i + 1;
	mint ans = 0;
	REP(j, N + 1) {
		mint t = 0;
		REP(i, N - j + 1) {
			mint mul = 1;
			mint beki = modpow(mint(2), N - j - i);
			if(mp.count(beki.val)) mul *= mp[beki.val];
			else {
				REP(k, K) {
					mul *= beki - k;
				}
				mp[beki.val] = mul;
			}
			mul *= bc.com(N - j, i) * div;
			if(i % 2 == 0) {
				t += mul;
			} else {
				t -= mul;
			}
		}
		ans += t * dp[N][j][S];
	}
	out(ans);
}
accuracy: 0.5483870967741935
time_ms: 80
memory_kb: 62392
final_rank: 14

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

const ll mod = 1e9 + 7;

template <int mod>
struct Modint {
    int x;

    Modint() : x(0) {}
    Modint(long long y) : x(y >= 0 ? y % mod : y % mod + mod) {}

    Modint& operator+=(const Modint& p) { if ((x += p.x) >= mod) x -= mod; return *this; }
    Modint& operator-=(const Modint& p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; }
    Modint& operator*=(const Modint& p) { x = (int) (1LL * x * p.x % mod); return *this; }
    Modint& operator/=(const Modint& p) { *this *= p.inv(); return *this; }

    Modint operator-() const { return Modint(-x); }

    Modint operator+(const Modint& p) const { return Modint(*this) += p; }
    Modint operator-(const Modint& p) const { return Modint(*this) -= p; }
    Modint operator*(const Modint& p) const { return Modint(*this) *= p; }
    Modint operator/(const Modint& p) const { return Modint(*this) /= p; }

    bool operator==(const Modint& p) const { return x == p.x; }
    bool operator!=(const Modint& p) const { return x != p.x; }

    Modint inv() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return Modint(u);
    }

    Modint pow(long long n) const {
        Modint ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream& os, const Modint& p) {
        return os << p.x;
    }

    friend istream &operator>>(istream& is, Modint& a) {
        long long t;
        is >> t;
        a = Modint<mod>(t);
        return is;
    }
};

using mint = Modint<mod>;

mint comb(mint n, mint r) {
    mint num = 1, den = 1;
    for (int i = 1; i <= r.x; i++) {
        num *= n - i + 1;
        den *= i;
    }
    return num / den;
}


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

    int N, K, S;
    cin >> N >> K >> S;
    vector<int> C(N);
    for (int i = 0; i < N; i++) cin >> C[i];
    vector<vector<mint>> dp(S + 1, vector<mint>(N + 1));
    dp[0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = S; j >= C[i]; j--) {
            for (int k = N; k > 0; k--) {
                dp[j][k] += dp[j - C[i]][k - 1];
            }
        }
    }
    vector<mint> comb2iK(61);
    for (int i = 0; i <= 60; i++) comb2iK[i] = comb(1LL << i, K);
    mint ans = 0;
    for (int i = 1; i <= N; i++) {
        int x = N - i;
        mint tmp = 0;
        for (int j = 0; j <= x; j++) {
            mint tmp2 = comb(x, j) * comb2iK[x - j];
            if (j % 2) tmp2 = -tmp2;
            tmp += tmp2;
        }
        ans += tmp * dp[S][i];
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 70
memory_kb: 4580
final_rank: 3

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
 
struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}


template<ll Mod>
struct ModInt{
    long long x;
    ModInt():x(0){}
    ModInt(long long y):x(y>=0?y%Mod:(Mod-(-y)%Mod)%Mod){}
    ModInt &operator+=(const ModInt &p){
        if((x+=p.x)>=Mod) x-=Mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p){
        if((x+=Mod-p.x)>=Mod)x-=Mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p){
        x=(int)(1ll*x*p.x%Mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p){
        (*this)*=p.inverse();
        return *this;
    }
    ModInt operator-()const{return ModInt(x);}
    ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
    ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
    ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
    ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
    ModInt operator==(const ModInt &p)const{return x==p.x;}
    ModInt operator!=(const ModInt &p)const{return x!=p.x;}
    ModInt inverse()const{
        int a=x,b=Mod,u=1,v=0,t;
        while(b>0){
            t=a/b;
            swap(a-=t*b,b);swap(u-=t*v,v);
        }
        return ModInt(u);
    }
    ModInt pow(long long n)const{
        ModInt ret(1),mul(x);
        while(n>0){
            if(n&1) ret*=mul;
            mul*=mul;n>>=1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os,const ModInt &p){return os<<p.x;}
    friend istream &operator>>(istream &is,ModInt &a){long long t;is>>t;a=ModInt<Mod>(t);return (is);}
    static int get_mod(){return Mod;}
};
using mint=ModInt<mod>;
 
template<int MAX>
struct comcalc{
    vector<mint> fact,finv,inv;
    comcalc():fact(MAX),finv(MAX),inv(MAX){
        fact[0]=mint(1),fact[1]=mint(1),finv[0]=mint(1),finv[1]=mint(1),inv[1]=mint(1);
        for(int i=2;i<MAX;i++){
            fact[i]=fact[i-1]*mint(i);
            inv[i]=mint(0)-inv[mod%i]*(mint(mod/i));
            finv[i]=finv[i-1]*inv[i];
        }
    }
    mint com(int n,int k){
        if(n<k) return mint(0);
        if(n<0 or k<0) return mint(0);
        return fact[n]*(finv[k]*finv[n-k]);
    }
    mint fac(int n){
        return fact[n];
    }
    // 重複組み合わせ:n種類の物から重複を許し，k個選ぶ
    mint nHk(int n,int k){
        return com(n+k-1,k);
    }
    // 玉n区別，箱k区別，各箱1個以上O(k)
    mint F12_dis_dis_one(int n,int k){
        if(n<k)return mint(0);
        mint ret=0;
        for(int i=0;i<=k;i++){
            mint add=com(k,i)*(mint(i).pow(n));
            if((k-i)%2) ret-=add;
            else        ret+=add;
        }
        return ret;
    }
};
mint pow_mod(mint x,ll n){
    return x.pow(n);
}
mint inv_mod(mint x){
    return x.inverse();
}
// O(n)
mint fact_mod(ll n){
    mint ret=1;
    for(int i=2;i<=n;i++) ret*=mint(i);
    return ret;
}
// O(r)
mint comb_mod(ll n,ll r){
    if(r>n) return mint(0);
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    mint a=1,b=mint(fact_mod(r)).inverse();
    for(int i=0;i<r;i++)a*=mint(n-i);
    return a*b;
}
 
const int MAX=210000;
using cominit=comcalc<MAX>;


mint dp[65][5010][65];

signed main(){
    cominit F;

    int n,s,k;cin>>n>>k>>s;
    vector<int> c(n);
    vector<ll> b2(1,1);
    rep(i,n+10) b2.push_back(b2.back()*2);
    vector<mint> b2ck(b2.size());
    rep(i,n+10) b2ck[i]=comb_mod(b2[i],k);

    cin>>c;

    dp[0][0][0]=1;
    
    rep(i,n)for(int j=0;j<=s;j++)rep(l,n){
        mint src=dp[i][j][l];
        if(j+c[i]<=s) dp[i+1][j+c[i]][l]+=src;
        dp[i+1][j][l+1]+=src;
    }


    auto f=[&](int x){
        mint ret=0;
        int x2=1;
        rep(i,x+1){
            mint tmp=b2ck[x-i]*F.com(x,i);
            if(i%2) ret-=tmp;
            else    ret+=tmp;
        };
        return ret;
    };

    mint res=0;
    rep(i,n+1) res+=f(i)*dp[n][s][i];
    cout<<res<<endl;
    return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 173496
final_rank: 9

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

const ll mod = 1e9 + 7;

template <int mod>
struct Modint {
    int x;

    Modint() : x(0) {}
    Modint(long long y) : x(y >= 0 ? y % mod : y % mod + mod) {}

    Modint& operator+=(const Modint& p) { if ((x += p.x) >= mod) x -= mod; return *this; }
    Modint& operator-=(const Modint& p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; }
    Modint& operator*=(const Modint& p) { x = (int) (1LL * x * p.x % mod); return *this; }
    Modint& operator/=(const Modint& p) { *this *= p.inv(); return *this; }

    Modint operator-() const { return Modint(-x); }

    Modint operator+(const Modint& p) const { return Modint(*this) += p; }
    Modint operator-(const Modint& p) const { return Modint(*this) -= p; }
    Modint operator*(const Modint& p) const { return Modint(*this) *= p; }
    Modint operator/(const Modint& p) const { return Modint(*this) /= p; }

    bool operator==(const Modint& p) const { return x == p.x; }
    bool operator!=(const Modint& p) const { return x != p.x; }

    Modint inv() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return Modint(u);
    }

    Modint pow(long long n) const {
        Modint ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream& os, const Modint& p) {
        return os << p.x;
    }

    friend istream &operator>>(istream& is, Modint& a) {
        long long t;
        is >> t;
        a = Modint<mod>(t);
        return is;
    }
};

using mint = Modint<mod>;

mint comb(mint n, mint r) {
    mint num = 1, den = 1;
    for (int i = 1; i <= r.x; i++) {
        num *= n - i + 1;
        den *= i;
    }
    return num / den;
}


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

    int N, K, S;
    cin >> N >> K >> S;
    vector<int> C(N);
    for (int i = 0; i < N; i++) cin >> C[i];
    vector<vector<mint>> dp(S + 1, vector<mint>(N + 1));
    dp[0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = S; j >= C[i]; j--) {
            for (int k = N; k > 0; k--) {
                dp[j][k] += dp[j - C[i]][k - 1];
            }
        }
    }
    mint ans = 0;
    for (int i = 1; i <= N; i++) {
        int x = N - i;
        mint tmp = 0;
        for (int j = 0; j <= x; j++) {
            mint tmp2 = comb(x, j) * comb(1 << (x - j), K);
            if (j % 2) tmp2 = -tmp2;
            tmp += tmp2;
        }
        ans += tmp * dp[S][i];
    }
    cout << ans << endl;
}
accuracy: 0.45161290322580644
time_ms: 300
memory_kb: 3592
final_rank: 18

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

const ll mod = 1e9 + 7;

template <int mod>
struct Modint {
    int x;

    Modint() : x(0) {}
    Modint(long long y) : x(y >= 0 ? y % mod : y % mod + mod) {}

    Modint& operator+=(const Modint& p) { if ((x += p.x) >= mod) x -= mod; return *this; }
    Modint& operator-=(const Modint& p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; }
    Modint& operator*=(const Modint& p) { x = (int) (1LL * x * p.x % mod); return *this; }
    Modint& operator/=(const Modint& p) { *this *= p.inv(); return *this; }

    Modint operator-() const { return Modint(-x); }

    Modint operator+(const Modint& p) const { return Modint(*this) += p; }
    Modint operator-(const Modint& p) const { return Modint(*this) -= p; }
    Modint operator*(const Modint& p) const { return Modint(*this) *= p; }
    Modint operator/(const Modint& p) const { return Modint(*this) /= p; }

    bool operator==(const Modint& p) const { return x == p.x; }
    bool operator!=(const Modint& p) const { return x != p.x; }

    Modint inv() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return Modint(u);
    }

    Modint pow(long long n) const {
        Modint ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream& os, const Modint& p) {
        return os << p.x;
    }

    friend istream &operator>>(istream& is, Modint& a) {
        long long t;
        is >> t;
        a = Modint<mod>(t);
        return is;
    }
};

using mint = Modint<mod>;

mint comb(mint n, mint r) {
    mint num = 1, den = 1;
    for (int i = 1; i <= r.x; i++) {
        num *= n - i + 1;
        den *= i;
    }
    return num / den;
}


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

    int N, K, S;
    cin >> N >> K >> S;
    vector<int> C(N);
    for (int i = 0; i < N; i++) cin >> C[i];
    vector<vector<int>> dp(S + 1, vector<int>(N + 1));
    dp[0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = S; j >= C[i]; j--) {
            for (int k = N; k > 0; k--) {
                dp[j][k] += dp[j - C[i]][k - 1];
            }
        }
    }
    mint ans(0);
    for (int i = 1; i <= N; i++) {
        int x = N - i;
        mint tmp = 0;
        for (int j = 0; j <= x; j++) {
            mint tmp2 = comb(x, j) * comb(1 << (x - j), K);
            if (j % 2) tmp2 = -tmp2;
            tmp += tmp2;
        }
        ans += tmp * dp[S][i];
    }
    cout << ans << endl;
}
accuracy: 0.45161290322580644
time_ms: 300
memory_kb: 3716
final_rank: 19

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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int sign(int x) { return (x > 0) - (x < 0); }
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int cdiv(int a, int b) { return (a - 1 + b) / b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T> T sq(T x) { return x * x; }
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const deque<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const set<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

template<int MOD = 1000000007>
struct mod_int {
    int val;
    mod_int(long long val_ = 0) : val(val_ % MOD) { if (val < 0) { val += MOD; }}
    bool operator==(const mod_int &rhs) const { return val == rhs.val; }
    bool operator!=(const mod_int &rhs) const { return std::rel_ops::operator!=(*this, rhs); }
    mod_int &operator+=(const mod_int &rhs) {
        if ((val += rhs.val) >= MOD) { val -= MOD; }
        return *this;
    }
    mod_int &operator-=(const mod_int &rhs) {
        if ((val += MOD - rhs.val) >= MOD) { val -= MOD; }
        return *this;
    }
    mod_int &operator*=(const mod_int &rhs) {
        val = (int) ((long long) val * rhs.val % MOD);
        return *this;
    }
    mod_int &operator/=(const mod_int &rhs) { return *this *= rhs.inv(); }
    mod_int operator+() const { return *this; }
    mod_int operator-() const { return -val; }
    mod_int operator++() { return *this += 1; }
    mod_int operator--() { return *this -= 1; }
    mod_int operator++(signed) {
        const mod_int ret(*this);
        ++*this;
        return ret;
    }
    mod_int operator--(signed) {
        const mod_int ret(*this);
        --*this;
        return ret;
    }
    mod_int operator+(const mod_int &rhs) const { return mod_int(*this) += rhs; }
    mod_int operator-(const mod_int &rhs) const { return mod_int(*this) -= rhs; }
    mod_int operator*(const mod_int &rhs) const { return mod_int(*this) *= rhs; }
    mod_int operator/(const mod_int &rhs) const { return mod_int(*this) /= rhs; }
    mod_int inv() const {
        assert(val != 0);
        int a = val, b = MOD, x = 1, u = 0;
        while (b) {
            int t = a / b;
            std::swap(a -= t * b, b);
            std::swap(x -= t * u, u);
        }
        return x;
    }
    mod_int pow(long long n) const {
        if (n < 0) { return pow(-n).inv(); }
        mod_int ret = 1, mul = *this;
        while (n) {
            if (n & 1) { ret *= mul; }
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend std::istream &operator>>(std::istream &is, mod_int &rhs) {
        long long v;
        is >> v;
        rhs = v;
        return is;
    }
    friend std::ostream &operator<<(std::ostream &os, const mod_int &rhs) { return os << rhs.val; }
    struct combination {
        std::vector<mod_int> fact{1, 1}, f_inv{1, 1}, inv{0, 1};
        void calc(int n) {
            while (fact.size() <= n) {
                int i = fact.size();
                fact.push_back(fact[i - 1] * i);
                inv.push_back(-inv[MOD % i] * (MOD / i));
                f_inv.push_back(f_inv[i - 1] * inv[i]);
            }
        }
        mod_int P(int n, int r) { return r < 0 || n < r ? 0 : (calc(n), fact[n] * f_inv[n - r]); }
        mod_int C(int n, int r) { return r < 0 || n < r ? 0 : (calc(n), fact[n] * f_inv[r] * f_inv[n - r]); }
        mod_int H(int n, int r) { return C(n + r - 1, r); }
    };
};
using mint = mod_int<>;

signed main() {
    int N, K, S;
    cin >> N >> K >> S;
    vint C(N);
    rep(i, N) { cin >> C[i]; }
    vector<mint> pre(N + 1), bekichoose(N + 1);
    mint::combination comb;
    comb.calc(K);
    auto choose = [&](int n, int r) -> mint {
        if (n < r) { return 0; }
        mint ret = 1;
        reps(i, r) { ret = ret * (n - i + 1) * comb.inv[i]; }
        return ret;
    };
    rep(i, N + 1) { bekichoose[i] = choose(bit(i), K); }
    rep(i, N + 1) {
        rep(j, i + 1) {
            mint cur = bekichoose[j] * comb.C(i, j);
            pre[i] += (i + j) & 1 ? -cur : cur;
        }
    }
    vector dp(N + 1, vector(N + 1, vector<mint>(S + 1)));
    dp[0][0][0] = 1;
    rep(i, N) {
        rep(j, N) {
            rep(k, S + 1) {
                dp[i + 1][j + 1][k] += dp[i][j][k];
                if (k + C[i] <= S) { dp[i + 1][j][k + C[i]] += dp[i][j][k]; }
            }
        }
    }
    mint ans = 0;
    rep(i, N + 1) { ans += dp[N][i][S] * pre[i]; }
    cout << ans << endl;
}
accuracy: 1
time_ms: 150
memory_kb: 160584
final_rank: 8