Problem:
J - WISWIS
Time Limit: 2 sec
問題文
tupc君は非減少数列のファンです。
数列が非減少であれば嬉しく、さらにその数列が長ければ長いほど嬉しさが大きいです。
具体的に数列の嬉しさは以下のように定まります。
数列が非減少数列でないとき、嬉しさは0
数列が非減少数列であるとき、嬉しさはその数列の長さ
今、長さ $NK$ の数列 $A_0,A_1,\dots,A_{NK-1}$ があります。
この数列は最初の $N$ 項 $A_0,\dots,A_{N-1}$ が入力として与えられ、残りの項については $A_j=A_{j \bmod N}$ によって定められます。
$A$ の空でない部分列は $2^{NK}-1$ 通り考えられますが、それらの嬉しさの総和を求めてください。
但し部分列が数列として等しくても、異なる箇所から抜き出した部分列は区別するものとします。
答えは非常に大きくなることがあるので、$10^9+7$ で割った余りを求めてください。
非減少数列とは
数列 $X_1,X_2,\ldots,X_M$ が非減少数列であるとは、任意の $1\le i\le M-1$ に対して $X_i\le X_{i+1}$ が成り立つことを言います。
制約
$1\le N \le 8000$
$1\le K \le 10^9$
$1\le A_i \le 50$
入力は全て整数
入力
$N\quad K$
$A_0\quad A_1\quad \dots\quad A_{N-1}$
出力
答えを $10^9+7$ で割った余りを1行で出力せよ。
入力例1
2
2
2
1
出力例1
10
数列 $2,1,2,1$ の部分列で非減少数列であるものは、
$2$(2通り)
$1$(2通り)
$1\ 2$
$1\ 1$
$2\ 2$
の7通りが考えられます。このうち4つは長さが1で3つは長さが2ですので $4\times1+3\times2=10$ を出力してください。
入力例2
3
3
2
1
4
出力例2
168
入力例3
10
1000
1
2
3
4
5
6
7
8
9
50
出力例3
392795107

Submitted solutions:

code_snippet: #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define rep(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)
#define drep(i, m, n) for (ll i = m - 1; i >= n; i--)
#define Endl endl
#define all(a) a.begin(), a.end()
#define pr(i, j) make_pair(i, j)
#define isin(x, l, r) (l <= x && x < r)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define srt(ar) sort(ar.begin(), ar.end())
#define rev(ar) reverse(ar.begin(), ar.end())
#define jge(f, s, t) cout << (f ? s : t) << endl
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define printar(ar)             \
    do                          \
    {                           \
        for (auto dbg : ar)     \
        {                       \
            cout << dbg << " "; \
        }                       \
        cout << endl;           \
    } while (0)
const ll inf = 1e18;
const ld pi = 3.14159265358979;
const ld eps = 1e-9;
template <class T, ll n, ll idx = 0>
auto make_vec(const ll (&d)[n], const T &init) noexcept
{
    if constexpr (idx < n)
        return std::vector(d[idx], make_vec<T, n, idx + 1>(d, init));
    else
        return init;
}

template <class T, ll n>
auto make_vec(const ll (&d)[n]) noexcept
{
    return make_vec(d, T{});
}
//////////////// 以下を貼る ////////////////
template <class T>
size_t HashCombine(const size_t seed, const T &v)
{
    return seed ^ (std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
}
/* pair用 */
template <class T, class S>
struct std::hash<std::pair<T, S>>
{
    size_t operator()(const std::pair<T, S> &keyval) const noexcept
    {
        return HashCombine(std::hash<T>()(keyval.first), keyval.second);
    }
};
////////////////////////////////////////////
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, K;
    cin >> n >> K;
    vector<ll> a(n);
    rep(i, 0, n)
    {
        cin >> a[i];
        a[i]--;
    }
    ll p = 1000000007;
    auto c = make_vec<ll>({50, 50}, 0);
    auto s = make_vec<ll>({50, 50}, 0);
    rep(i, 0, a.size())
    {
        rep(j, 0, a[i] + 1)
        {
            drep(k, a[i] + 1, j)
            {
                ll x = c[j][k] + s[j][k];
                x %= p;
                s[j][a[i]] += x;
                s[j][a[i]] %= p;
                c[j][a[i]] += c[j][k];
                c[j][a[i]] %= p;
            }
        }
        c[a[i]][a[i]]++;
        s[a[i]][a[i]]++;
    }
    auto C = make_vec<ll>({30, 50, 50}, 0);
    auto S = make_vec<ll>({30, 50, 50}, 0);
    rep(i, 0, 50)
    {
        rep(j, i, 50)
        {
            C[0][i][j] = c[i][j] % p;
            S[0][i][j] = s[i][j] % p;
        }
    }
    rep(i, 1, 30)
    {
        rep(j, 0, 50)
        {
            rep(k, j, 50)
            {
                rep(l, k, 50)
                {
                    rep(m, l, 50)
                    {
                        ll x = C[i - 1][j][k] * C[i - 1][l][m];
                        x %= p;
                        C[i][j][m] += x;
                        C[i][j][m] %= p;
                        ll y = C[i - 1][l][m] * S[i - 1][j][k] + C[i - 1][j][k] * S[i - 1][l][m];
                        y %= p;
                        S[i][j][m] += y;
                        S[i][j][m] %= p;
                    }
                }
            }
        }
        rep(j, 0, 50)
        {
            rep(k, j, 50)
            {
                C[i][j][k] += C[i - 1][j][k] * 2;
                C[i][j][k] %= p;
                S[i][j][k] += S[i - 1][j][k] * 2;
                S[i][j][k] %= p;
            }
        }
    }
    auto c_K = make_vec<ll>({50, 50}, 0);
    auto s_K = make_vec<ll>({50, 50}, 0);
    rep(i, 0, 30)
    {
        if ((K >> i) & 1)
        {
            auto c_K_cp = make_vec<ll>({50, 50}, 0);
            auto s_K_cp = make_vec<ll>({50, 50}, 0);
            rep(j, 0, 50)
            {
                rep(k, j, 50)
                {
                    rep(l, k, 50)
                    {
                        rep(m, l, 50)
                        {
                            ll x = c_K[j][k] * C[i][l][m];
                            x %= p;
                            c_K_cp[j][m] += x;
                            c_K_cp[j][m] %= p;
                            ll y = c_K[l][m] * S[i][j][k] + C[i][j][k] * s_K[l][m];
                            y %= p;
                            s_K_cp[j][m] += y;
                            s_K_cp[j][m] %= p;
                        }
                    }
                }
            }
            rep(j, 0, 50)
            {
                rep(k, j, 50)
                {
                    ll x = C[i][j][k] + c_K[j][k];
                    ll y = S[i][j][k] + s_K[j][k];
                    x %= p;
                    y %= p;
                    c_K_cp[j][k] += x;
                    c_K_cp[j][k] %= p;
                    s_K_cp[j][k] += y;
                    s_K_cp[j][k] %= p;
                }
            }
            c_K = c_K_cp;
            s_K = s_K_cp;
        }
    }
    ll ans = 0;
    rep(i, 0, 50)
    {
        rep(j, i, 50)
        {
            ans += s_K[i][j];
            ans %= p;
        }
    }
    cout << ans << Endl;
}
accuracy: 1
time_ms: 90
memory_kb: 5120
final_rank: 8

code_snippet: // AOJ #3263 WISWIS
// 2025.2.21

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

struct Pair { ll a, b; };

typedef vector<vector<ll>> Matrix;
Matrix matMul(const Matrix &A, const Matrix &B) {
    int dim = A.size();
    Matrix C(dim, vector<ll>(dim, 0));
    for (int i = 0; i < dim; i++){
        for (int k = 0; k < dim; k++){
            if(A[i][k] != 0){
                for (int j = 0; j < dim; j++)
                    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
            }
        }
    }
    return C;
}

Matrix matPow(Matrix M, ll exp) {
    int dim = M.size();
    Matrix ans(dim, vector<ll>(dim, 0));
    for (int i = 0; i < dim; i++) ans[i][i] = 1;
    while(exp > 0){
        if(exp & 1) ans = matMul(ans, M);
        M = matMul(M, M);
        exp >>= 1;
    }
    return ans;
}

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

    int N;
    ll K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    const int MAXV = 50;
    vector<vector<ll>> f(MAXV+1, vector<ll>(MAXV+1, 0));
    vector<vector<ll>> g(MAXV+1, vector<ll>(MAXV+1, 0));

    for (int L = 1; L <= MAXV; L++){
        vector<ll> dp(MAXV+1, 0), dp2(MAXV+1, 0);
        for (int i = 0; i < N; i++){
            int val = A[i];
            if(val < L) continue;
            ll cnt = 1;
            ll sumLen = 1;
            for (int j = L; j <= val; j++){
                cnt = (cnt + dp[j]) % MOD;
                sumLen = (sumLen + dp2[j] + dp[j]) % MOD;
            }
            dp[val] = (dp[val] + cnt) % MOD;
            dp2[val] = (dp2[val] + sumLen) % MOD;
        }
        for (int v = L; v <= MAXV; v++){
            f[L][v] = dp[v] % MOD;
            g[L][v] = dp2[v] % MOD;
        }
    }

    int maxV = MAXV + 1;
    vector<vector<Pair>> M(maxV, vector<Pair>(maxV, {0, 0}));
    for (int v = 0; v < maxV; v++){
        int LB = (v == 0 ? 1 : v);
        for (int u = LB; u <= MAXV; u++){
            M[v][u].a = (M[v][u].a + f[LB][u]) % MOD;
            M[v][u].b = (M[v][u].b + g[LB][u]) % MOD;
        }
        M[v][v].a = (M[v][v].a + 1) % MOD;
    }

    int dim = 2 * maxV;
    Matrix T(dim, vector<ll>(dim, 0));
    for (int u = 0; u < maxV; u++){
        for (int v = 0; v < maxV; v++) T[u][v] = M[v][u].a % MOD;
    }
    for (int u = 0; u < maxV; u++){
        for (int v = 0; v < maxV; v++){
            T[maxV + u][v] = (T[maxV + u][v] + M[v][u].b) % MOD;
            T[maxV + u][maxV + v] = (T[maxV + u][maxV + v] + M[v][u].a) % MOD;
        }
    }

    vector<ll> X(dim, 0);
    X[0] = 1;

    Matrix Texp = matPow(T, K);
    vector<ll> final(dim, 0);
    for (int i = 0; i < dim; i++){
        for (int j = 0; j < dim; j++)
            final[i] = (final[i] + Texp[i][j] * X[j]) % MOD;
    }

    ll ans = 0;
    for (int i = 1; i < maxV; i++) ans = (ans + final[maxV + i]) % MOD;
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3900
final_rank: 3

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7,V=50,S=2*V+1;
typedef vector<vector<ll>>matrix;
matrix mul(const matrix&a,const matrix&b){
    matrix r(S,vector<ll>(S));
    for(int i=0;i<S;++i)for(int k=0;k<S;++k)if(a[i][k])for(int j=0;j<S;++j)r[i][j]=(r[i][j]+a[i][k]*b[k][j])%MOD;
    return r;
}
matrix power(matrix a,ll p){
    matrix r(S,vector<ll>(S));
    for(int i=0;i<S;++i)r[i][i]=1;
    while(p){if(p&1)r=mul(r,a);a=mul(a,a);p>>=1;}
    return r;
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int N;ll K;cin>>N>>K;vector<int>A(N);for(int&i:A)cin>>i;
    matrix T(S,vector<ll>(S));for(int i=0;i<S;++i)T[i][i]=1;
    for(int a:A){
        matrix T_a(S,vector<ll>(S));for(int i=0;i<S;++i)T_a[i][i]=1;
        int f=a-1,g=V+a-1;
        for(int v=1;v<=a;++v){
            T_a[f][v-1]=(T_a[f][v-1]+1)%MOD;
            T_a[g][v-1]=(T_a[g][v-1]+1)%MOD;
            T_a[g][V+v-1]=(T_a[g][V+v-1]+1)%MOD;
        }
        T_a[f][2*V]=(T_a[f][2*V]+1)%MOD;
        T_a[g][2*V]=(T_a[g][2*V]+1)%MOD;
        T=mul(T_a,T);
    }
    T=power(T,K);
    vector<ll>S0(S);S0[2*V]=1;vector<ll>Sn(S);
    for(int i=0;i<S;++i)for(int j=0;j<S;++j)Sn[i]=(Sn[i]+T[i][j]*S0[j])%MOD;
    ll res=0;for(int i=V;i<2*V;++i)res=(res+Sn[i])%MOD;
    cout<<res<<"\n";
}
accuracy: 1
time_ms: 340
memory_kb: 3816
final_rank: 11

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

typedef long long ll;
const int MOD = 1000000007;
const int V = 50;
const int STATE_SIZE = 2 * V + 1;

typedef vector<vector<ll>> matrix;

matrix multiply(const matrix &a, const matrix &b) {
    matrix res(STATE_SIZE, vector<ll>(STATE_SIZE, 0));
    for(int i = 0; i < STATE_SIZE; i++) {
        for(int k = 0; k < STATE_SIZE; k++) {
            if(a[i][k] == 0) continue;
            for(int j = 0; j < STATE_SIZE; j++) {
                res[i][j] = (res[i][j] + a[i][k] * b[k][j]) % MOD;
            }
        }
    }
    return res;
}

matrix power_matrix(matrix a, ll power) {
    matrix res(STATE_SIZE, vector<ll>(STATE_SIZE, 0));
    for(int i = 0; i < STATE_SIZE; i++) res[i][i] = 1;
    while(power > 0) {
        if(power & 1LL) {
            res = multiply(a, res);
        }
        a = multiply(a, a);
        power >>=1LL;
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    ll K;
    cin >> N >> K;
    vector<int> A(N);
    for(auto &x:A) cin >> x;    
    
    matrix T_total(STATE_SIZE, vector<ll>(STATE_SIZE, 0));
    for(int i = 0; i < STATE_SIZE; i++) T_total[i][i] = 1;
    
    for(int idx = 0; idx < N; idx++) {
        int a = A[idx];
        matrix T_a(STATE_SIZE, vector<ll>(STATE_SIZE, 0));
        for(int i = 0; i < STATE_SIZE; i++) T_a[i][i] = 1;

    int f_a = a -1;
    int g_a = V + a -1;
        
   for(int v = 1; v <= a; v++) {
    int f_v = v - 1;
    T_a[f_a][f_v] = (T_a[f_a][f_v] + 1) % MOD;
    }
    T_a[f_a][2*V] = (T_a[f_a][2*V] + 1) % MOD;
  
    for(int v = 1; v <= a; v++) {
        int f_v = v -1;
        int g_v = V + v -1;
        T_a[g_a][g_v] = (T_a[g_a][g_v] + 1) % MOD;
        T_a[g_a][f_v] = (T_a[g_a][f_v] + 1) % MOD;
    }
    T_a[g_a][2*V] = (T_a[g_a][2*V] + 1) % MOD;
    T_total = multiply(T_a, T_total);
}         
    matrix T_final = power_matrix(T_total, K);

    vector<ll> S_initial(STATE_SIZE, 0);
    S_initial[2*V] = 1;

    vector<ll> S_final(STATE_SIZE, 0);
    for(int i = 0; i < STATE_SIZE; i++) {
        for(int j = 0; j < STATE_SIZE; j++) {
            S_final[i] = (S_final[i] + T_final[i][j] * S_initial[j]) % MOD;
        }
    }
        
    ll total = 0;
    for(int i = V; i < 2*V; i++) {
        total = (total + S_final[i]) % MOD;
    }
    cout << total << '\n';
}
accuracy: 1
time_ms: 340
memory_kb: 3840
final_rank: 13

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

typedef long long ll;
const int MOD = 1000000007;
const int V = 50;
const int STATE_SIZE = 2 * V + 1;

typedef vector<vector<ll>> matrix;

matrix multiply(const matrix &a, const matrix &b) {
    matrix res(STATE_SIZE, vector<ll>(STATE_SIZE, 0));
    for(int i = 0; i < STATE_SIZE; i++) {
        for(int k = 0; k < STATE_SIZE; k++) {
            if(a[i][k] == 0) continue;
            for(int j = 0; j < STATE_SIZE; j++) {
                res[i][j] = (res[i][j] + a[i][k] * b[k][j]) % MOD;
            }
        }
    }
    return res;
}

matrix power_matrix(matrix a, ll power) {
    matrix res(STATE_SIZE, vector<ll>(STATE_SIZE, 0));
    for(int i = 0; i < STATE_SIZE; i++) res[i][i] = 1;
    while(power > 0) {
        if(power & 1LL) {
            res = multiply(a, res);
        }
        a = multiply(a, a);
        power >>=1LL;
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    ll K;
    cin >> N >> K;
    vector<int> A(N);
    for(auto &x:A) cin >> x;
    
    matrix T_total(STATE_SIZE, vector<ll>(STATE_SIZE, 0));
    for(int i = 0; i < STATE_SIZE; i++) T_total[i][i] = 1;
    
    for(int idx = 0; idx < N; idx++) {
        int a = A[idx];
        matrix T_a(STATE_SIZE, vector<ll>(STATE_SIZE, 0));
        for(int i = 0; i < STATE_SIZE; i++) T_a[i][i] = 1;
        
        int f_a = a -1;
        int g_a = V + a -1;
        
        for(int v = 1; v <= a; v++) {
            int f_v = v - 1;
            T_a[f_a][f_v] = (T_a[f_a][f_v] + 1) % MOD;
        }
        T_a[f_a][2*V] = (T_a[f_a][2*V] + 1) % MOD;
        
        for(int v = 1; v <= a; v++) {
            int f_v = v -1;
            int g_v = V + v -1;
            T_a[g_a][g_v] = (T_a[g_a][g_v] + 1) % MOD;
            T_a[g_a][f_v] = (T_a[g_a][f_v] + 1) % MOD;
        }
        T_a[g_a][2*V] = (T_a[g_a][2*V] + 1) % MOD;
        
        T_total = multiply(T_a, T_total);
    }
    
    matrix T_final = power_matrix(T_total, K);
    
    vector<ll> S_initial(STATE_SIZE, 0);
    S_initial[2*V] = 1;
    
    vector<ll> S_final(STATE_SIZE, 0);
    for(int i = 0; i < STATE_SIZE; i++) {
        for(int j = 0; j < STATE_SIZE; j++) {
            S_final[i] = (S_final[i] + T_final[i][j] * S_initial[j]) % MOD;
        }
    }
    
    ll total = 0;
    for(int i = V; i < 2*V; i++) {
        total = (total + S_final[i]) % MOD;
    }
    cout << total << '\n';
}
accuracy: 1
time_ms: 340
memory_kb: 3832
final_rank: 12

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

typedef long long ll;
const int MOD = 1000000007;
const int V = 50;
const int STATE_SIZE = 2 * V + 1;

typedef vector<vector<ll>> matrix;

matrix multiply(const matrix &a, const matrix &b) {
    matrix res(STATE_SIZE, vector<ll>(STATE_SIZE, 0));
    for(int i = 0; i < STATE_SIZE; i++) {
        for(int k = 0; k < STATE_SIZE; k++) {
            if(a[i][k] == 0) continue;
            for(int j = 0; j < STATE_SIZE; j++) {
                res[i][j] = (res[i][j] + a[i][k] * b[k][j]) % MOD;
            }
        }
    }
    return res;
}

matrix power_matrix(matrix a, ll power) {
    matrix res(STATE_SIZE, vector<ll>(STATE_SIZE, 0));
    for(int i = 0; i < STATE_SIZE; i++) res[i][i] = 1;
    while(power > 0) {
        if(power & 1LL) {
            res = multiply(a, res);
        }
        a = multiply(a, a);
        power >>=1LL;
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    ll K;
    cin >> N >> K;
    vector<int> A(N);
    for(auto &x:A) cin >> x;
    
    matrix T_total(STATE_SIZE, vector<ll>(STATE_SIZE, 0));
    for(int i = 0; i < STATE_SIZE; i++) T_total[i][i] = 1;
    
    for(int idx = 0; idx < N; idx++) {
        int a = A[idx];
        matrix T_a(STATE_SIZE, vector<ll>(STATE_SIZE, 0));
        for(int i = 0; i < STATE_SIZE; i++) T_a[i][i] = 1;
        
        int f_a = a -1;
        int g_a = V + a -1;
        
        for(int v = 1; v <= a; v++) {
            int f_v = v - 1;
            T_a[f_a][f_v] = (T_a[f_a][f_v] + 1) % MOD;
        }
        T_a[f_a][2*V] = (T_a[f_a][2*V] + 1) % MOD;
        
        for(int v = 1; v <= a; v++) {
            int f_v = v -1;
            int g_v = V + v -1;
            T_a[g_a][g_v] = (T_a[g_a][g_v] + 1) % MOD;
            T_a[g_a][f_v] = (T_a[g_a][f_v] + 1) % MOD;
        }
        T_a[g_a][2*V] = (T_a[g_a][2*V] + 1) % MOD;
        
        T_total = multiply(T_a, T_total);
    }
    
    matrix T_final = power_matrix(T_total, K);
    
    vector<ll> S_initial(STATE_SIZE, 0);
    S_initial[2*V] = 1;
    
    vector<ll> S_final(STATE_SIZE, 0);
    for(int i = 0; i < STATE_SIZE; i++) {
        for(int j = 0; j < STATE_SIZE; j++) {
            S_final[i] = (S_final[i] + T_final[i][j] * S_initial[j]) % MOD;
        }
    }
    
    ll total = 0;
    for(int i = V; i < 2*V; i++) {
        total = (total + S_final[i]) % MOD;
    }
    cout << total << '\n';
}
accuracy: 1
time_ms: 340
memory_kb: 3800
final_rank: 10

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

typedef long long ll;
const int MOD = 1000000007;

// Размер состояния: f[1..50], g[1..50], константа
const int V = 50;
const int STATE_SIZE = 2 * V + 1;

// Представление матрицы как вектора векторов
typedef vector<vector<ll>> matrix;

// Функция умножения двух матриц
matrix multiply(const matrix &a, const matrix &b) {
    matrix res(STATE_SIZE, vector<ll>(STATE_SIZE, 0));
    for(int i = 0; i < STATE_SIZE; i++) {
        for(int k = 0; k < STATE_SIZE; k++) {
            if(a[i][k] == 0) continue;
            for(int j = 0; j < STATE_SIZE; j++) {
                res[i][j] = (res[i][j] + a[i][k] * b[k][j]) % MOD;
            }
        }
    }
    return res;
}

// Функция возведения матрицы в степень
matrix power_matrix(matrix a, ll power) {
    matrix res(STATE_SIZE, vector<ll>(STATE_SIZE, 0));
    // Инициализируем как единичную матрицу
    for(int i = 0; i < STATE_SIZE; i++) res[i][i] = 1;
    while(power > 0) {
        if(power & 1LL) {
            res = multiply(a, res);
        }
        a = multiply(a, a);
        power >>=1LL;
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    ll K;
    cin >> N >> K;
    vector<int> A(N);
    for(auto &x:A) cin >> x;
    
    // Инициализируем трансформационную матрицу как единичную
    matrix T_total(STATE_SIZE, vector<ll>(STATE_SIZE, 0));
    for(int i = 0; i < STATE_SIZE; i++) T_total[i][i] = 1;
    
    // Построение трансформационной матрицы для одного блока (последовательности A)
    for(int idx = 0; idx < N; idx++) {
        int a = A[idx];
        // Создаем трансформационную матрицу для текущего элемента a
        matrix T_a(STATE_SIZE, vector<ll>(STATE_SIZE, 0));
        // Инициализируем как единичную
        for(int i = 0; i < STATE_SIZE; i++) T_a[i][i] = 1;
        
        // Обновляем f[a]
        // f[a] += sum(f[v] for v <=a) + 1 * c
        // Это означает, что в строке f[a] нужно добавить 1 к каждому f[v] для v <=a и добавить константу
        int f_a = a -1;
        int g_a = V + a -1; // Перенос объявления g_a сюда
        
        for(int v = 1; v <= a; v++) {
            int f_v = v - 1;
            T_a[f_a][f_v] = (T_a[f_a][f_v] + 1) % MOD;
        }
        // Добавляем вклад константы
        T_a[f_a][2*V] = (T_a[f_a][2*V] + 1) % MOD;
        
        // Обновляем g[a]
        // g[a] += sum(g[v] for v <=a) + sum(f[v] for v <=a) + 1 * c
        for(int v = 1; v <= a; v++) {
            int f_v = v -1;
            int g_v = V + v -1;
            T_a[g_a][g_v] = (T_a[g_a][g_v] + 1) % MOD;
            T_a[g_a][f_v] = (T_a[g_a][f_v] + 1) % MOD;
        }
        // Добавляем вклад константы
        T_a[g_a][2*V] = (T_a[g_a][2*V] + 1) % MOD;
        
        // Объединяем текущую трансформацию с общей
        T_total = multiply(T_a, T_total);
    }
    
    // Возводим трансформационную матрицу в степень K
    matrix T_final = power_matrix(T_total, K);
    
    // Начальное состояние: все f и g равны 0, константа равна 1
    vector<ll> S_initial(STATE_SIZE, 0);
    S_initial[2*V] = 1;
    
    // Применяем матрицу к начальному состоянию
    vector<ll> S_final(STATE_SIZE, 0);
    for(int i = 0; i < STATE_SIZE; i++) {
        for(int j = 0; j < STATE_SIZE; j++) {
            S_final[i] = (S_final[i] + T_final[i][j] * S_initial[j]) % MOD;
        }
    }
    
    // Суммируем все g[v] для получения общей счастья
    ll total = 0;
    for(int i = V; i < 2*V; i++) {
        total = (total + S_final[i]) % MOD;
    }
    cout << total << '\n'; // Добавляем символ новой строки
}
accuracy: 1
time_ms: 340
memory_kb: 3796
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int MOD=1e9+7;
constexpr int MAX_A=50;

ll modpow(ll a,ll n){
  ll ret=1,t=a;
  while(n>0){
    if(n%2)ret=ret*t%MOD;
    t=t*t%MOD;
    n/=2;
  }
  return ret;
}

void ch(ll &a,ll b){
  a=(a+b)%MOD;
}

vector<vector<ll>> matmul(vector<vector<ll>> A,vector<vector<ll>> B){
  vector ret(MAX_A*2,vector(MAX_A*2,0ll));
  for(int i=0;i<MAX_A*2;i++){
    for(int j=0;j<MAX_A*2;j++){
      for(int k=0;k<MAX_A*2;k++){
        ch(ret[i][j],A[i][k]*B[k][j]);
      }
    }
  }
  return ret;
}

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll N,K;
  cin>>N>>K;
  vector A(N,0);
  for(auto &i:A)cin>>i,--i;
  vector m(MAX_A*2,vector(MAX_A*2,0ll));
  for(int c=0;c<MAX_A*2;c++){
    m[c][c]=1;
    for(int i=0;i<N;i++){
      for(int j=MAX_A-1;j>=0;j-=1){
        if(j<=A[i]){
          ch(m[c][A[i]*2+1],m[c][j*2+1]);
          ch(m[c][A[i]*2+1],m[c][j*2]);
          ch(m[c][A[i]*2],m[c][j*2]);
        }
      }
    }
  }
  // for(int i=0;i<MAX_A*2;i++){
  //   for(int j=0;j<MAX_A*2;j++)cout<<m[i][j]<<' ';
  //   cout<<'\n';
  // }
  vector ans(MAX_A*2,vector(MAX_A*2,0ll));
  for(int i=0;i<MAX_A*2;i++)ans[i][i]=1;
  while(K>0){
    if(K%2){
      ans=matmul(ans,m);
    }
    m=matmul(m,m);
    K/=2;
  }
  ll ret=0;
  for(int i=0;i<MAX_A;i++)ch(ret,ans[0][i*2+1]);
  // for(int i=0;i<MAX_A*2;i++){
  //   for(int j=0;j<MAX_A*2;j++)cout<<ans[i][j]<<' ';
  //   cout<<'\n';
  // }
  cout<<ret<<'\n';
}
accuracy: 1
time_ms: 340
memory_kb: 3860
final_rank: 14

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

const int MOD = 1000000007;

class modint {
private:
	int x;
public:
	modint() : x(0) {}
	modint(long long n) : x(n >= 0 ? n % MOD : (MOD - (-n) % MOD) % MOD) {}
	int get() const { return x; }
	modint& operator+=(const modint& m) { x = (x + m.x) % MOD; return *this; }
	modint& operator-=(const modint& m) { x = (x - m.x + MOD) % MOD; return *this; }
	modint& operator*=(const modint& m) { x = 1LL * x * m.x % MOD; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint pow(long long b) const {
		modint res(1), a(*this);
		while (b >= 1) {
			if (b % 2 == 1) {
				res *= a;
			}
			a *= a;
			b /= 2;
		}
		return res;
	}
	modint inv() const {
		return pow(MOD - 2);
	}
};

vector<vector<modint> > merge(int N, const vector<vector<modint> >& A, const vector<vector<modint> >& B) {
	vector<vector<modint> > res(N, vector<modint>(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (B[i][j].get() != 0) { // <-- this reduces time complexity
				for (int k = 0; k < N; k++) {
					res[k][j] += A[k][i] * B[i][j];
				}
			}
		}
	}
	return res;
}

modint solve(int N, int K, int L, const vector<int>& A) {
	vector<vector<modint> > f(2 * L, vector<modint>(2 * L));
	for (int i = 0; i < 2 * L; i++) {
		f[i][i] = 1;
	}
	for (int i = 0; i < N; i++) {
		vector<vector<modint> > g(2 * L, vector<modint>(2 * L));
		for (int j = 0; j < 2 * L; j++) {
			g[j][j] = 1;
		}
		for (int j = 0; j <= A[i]; j++) {
			g[j][A[i]] += 1;
			g[j][A[i] + L] += 1;
			g[j + L][A[i] + L] += 1;
		}
		f = merge(2 * L, f, g);
	}
	vector<vector<modint> > h(2 * L, vector<modint>(2 * L));
	for (int i = 0; i < 2 * L; i++) {
		h[i][i] = 1;
	}
	while (K >= 1) {
		if (K % 2 == 1) {
			h = merge(2 * L, h, f);
		}
		f = merge(2 * L, f, f);
		K /= 2;
	}
	modint ans = 0;
	for (int i = 0; i < L; i++) {
		ans += h[0][L + i];
	}
	return ans;
}

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	vector<int> comp = A;
	sort(comp.begin(), comp.end());
	comp.erase(unique(comp.begin(), comp.end()), comp.end());
	for (int i = 0; i < N; i++) {
		A[i] = lower_bound(comp.begin(), comp.end(), A[i]) - comp.begin();
	}
	modint ans = solve(N, K, comp.size(), A);
	cout << ans.get() << endl;
	return 0;
}
accuracy: 1
time_ms: 470
memory_kb: 3560
final_rank: 15

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
#define MOD 1000000007

struct monoid {
	int cnt;
	int sum;
	monoid () : cnt(0), sum(0) {}
	monoid (int cnt, int sum) : cnt(cnt), sum(sum) {}
	monoid operator + (const monoid &rhs) {
		return {(cnt + rhs.cnt) % MOD, (sum + rhs.sum) % MOD};
	}
	monoid operator * (const monoid &rhs) {
		return {(int) (((int64_t) cnt * rhs.cnt) % MOD), (int) (((int64_t) cnt * rhs.sum + (int64_t) sum * rhs.cnt) % MOD)};
	}
};

int main() {
	int n = ri();
	int m = ri();
	std::vector<int> a(n);
	for (auto &i : a) i = ri() - 1;
	
	std::vector<std::vector<monoid> > mat(50, std::vector<monoid>(50));
	for (int i = 0; i < 50; i++) {
		std::vector<monoid> dp(50);
		dp[i] = monoid{1, 0};
		for (auto j : a) {
			std::vector<monoid> next_dp = dp;
			for (int k = j; k >= 0; k--) {
				next_dp[j] = next_dp[j] + monoid{dp[k].cnt, (dp[k].sum + dp[k].cnt) % MOD};
			}
			dp = next_dp;
		}
		mat[i] = dp;
	}
	std::vector<monoid> vec(50);
	vec[0].cnt = 1;
	for (; m; m >>= 1) {
		if (m & 1) {
			std::vector<monoid> new_vec(50);
			for (int i = 0; i < 50; i++) for (int j = 0; j < 50; j++)
				new_vec[j] = new_vec[j] + vec[i] * mat[i][j];
			vec = new_vec;
		}
		std::vector<std::vector<monoid> > new_mat(50, std::vector<monoid>(50));
		for (int i = 0; i < 50; i++) for (int j = 0; j < 50; j++) for (int k = 0; k < 50; k++)
			new_mat[i][k] = new_mat[i][k] + mat[i][j] * mat[j][k];
		mat = new_mat;
	}
	
	int64_t res = 0;
	for (auto i : vec) res += i.sum;
	printf("%d\n", (int) (res % MOD));
	return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 3592
final_rank: 4

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
#define MOD 1000000007

struct monoid {
	int cnt;
	int sum;
	monoid () : cnt(0), sum(0) {}
	monoid (int cnt, int sum) : cnt(cnt), sum(sum) {}
	monoid operator + (const monoid &rhs) {
		return {(cnt + rhs.cnt) % MOD, (sum + rhs.sum) % MOD};
	}
	monoid operator * (const monoid &rhs) {
		return {(int) (((int64_t) cnt * rhs.cnt) % MOD), (int) (((int64_t) cnt * rhs.sum + (int64_t) sum * rhs.cnt) % MOD)};
	}
};

int main() {
	int n = ri();
	int m = ri();
	std::vector<int> a(n);
	for (auto &i : a) i = ri() - 1;
	
	std::vector<std::vector<monoid> > mat(50, std::vector<monoid>(50));
	for (int i = 0; i < 50; i++) {
		std::vector<monoid> dp(50);
		dp[i] = monoid{1, 0};
		for (auto j : a) {
			std::vector<monoid> next_dp = dp;
			for (int k = j; k >= 0; k--) {
				next_dp[j] = next_dp[j] + monoid{dp[k].cnt, dp[k].sum + dp[k].cnt};
			}
			dp = next_dp;
		}
		mat[i] = dp;
	}
	std::vector<monoid> vec(50);
	vec[0].cnt = 1;
	for (; m; m >>= 1) {
		if (m & 1) {
			std::vector<monoid> new_vec(50);
			for (int i = 0; i < 50; i++) for (int j = 0; j < 50; j++)
				new_vec[j] = new_vec[j] + vec[i] * mat[i][j];
			vec = new_vec;
		}
		std::vector<std::vector<monoid> > new_mat(50, std::vector<monoid>(50));
		for (int i = 0; i < 50; i++) for (int j = 0; j < 50; j++) for (int k = 0; k < 50; k++)
			new_mat[i][k] = new_mat[i][k] + mat[i][j] * mat[j][k];
		mat = new_mat;
	}
	
	int64_t res = 0;
	for (auto i : vec) res += i.sum;
	printf("%d\n", (int) (res % MOD));
	return 0;
}
accuracy: 0.4583333333333333
time_ms: 10
memory_kb: 3576
final_rank: 20

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
#define debug(a) cerr<<#a<<":"<<a<<endl;
#define debug2(a,b) cerr<<"("<<#a<<","<<#b<<"):("<<a<<","<<b<<")"<<endl;
#define debug3(a,b,c) cerr<<"("<<#a<<","<<#b<<","<<#c<<"):("<<a<<","<<b<<","<<c<<")"<<endl;
#define debug4(a,b,c,d) cerr<<"("<<#a<<","<<#b<<","<<#c<<","<<d<<"):("<<a<<","<<b<<","<<c<<","<<d<<")"<<endl;

template<typename T>
istream& operator>>(istream&is,vector<T>&v){
  for(T&p:v)is>>p;
  return is;
}
template<typename T>
ostream& operator<<(ostream&os,const vector<T>&v){
  if(&os==&cerr)os<<"[";
  for(int i=0;i<v.size();i++){
    os<<v[i];
    if(i+1<v.size())os<<(&os==&cerr?",":" ");
  }
  if(&os==&cerr)os<<"]";
  return os;
}
//BEGIN CUT HERE
template<typename T, T MOD = 1000000007>
struct Mint{
  inline 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 *this;}
  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;}

  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>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}
//END CUT HERE
using mint=Mint<long long>;

template<typename T,typename ...Args>
auto make_vector(T x,int arg,Args ...args){
  if constexpr(sizeof...(args)==0)return vector<T>(arg,x);
  else return vector(arg,make_vector<T>(x,args...));
}

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

  int n,k;cin>>n>>k;
  vector<int> v(n);
  cin>>v;
  REP(i,n)v[i]=50-v[i];

  auto num=make_vector<mint>(0,50,50);
  auto sum=make_vector<mint>(0,50,50);

  REP(i,n){
    auto csum=sum;
    csum[v[i]][v[i]]+=1;
    for(int l=v[i];l<50;l++)for(int r=v[i];r<=l;r++)csum[l][v[i]]+=sum[l][r]+num[l][r];
    sum=csum;
    
    auto cnum=num;
    cnum[v[i]][v[i]]+=1;
    for(int l=v[i];l<50;l++)for(int r=v[i];r<=l;r++)cnum[l][v[i]]+=num[l][r];
    num=cnum;

    

    //cerr<<"S"<<i<<endl;
    //REP(i,10)REP(j,10)cerr<<sum[i][j]<<"\n "[j+1<10];
  }

  /*cerr<<"NUM"<<endl;
  REP(i,10)REP(j,10)cerr<<num[i][j]<<"\n "[j+1<10];
  cerr<<"SUM"<<endl;
  REP(i,10)REP(j,10)cerr<<sum[i][j]<<"\n "[j+1<10];*/
  

  auto anum=num;
  auto asum=sum;
  k--;

  auto fnum=[](const vector<vector<mint>>&L,const vector<vector<mint>>&R){
    auto res=L; REP(i,50)REP(j,50)res[i][j]+=R[i][j];
    REP(l,50)REP(r,l+1)
      for(int ll=r;ll<=l;ll++)for(int rr=ll;rr<=l;rr++)
        res[l][r]+=L[l][rr]*R[ll][r];
    return res;
  };
  auto fsum=[](const vector<vector<mint>>&Lsum,const vector<vector<mint>>&Rsum,const vector<vector<mint>>&Lnum,const vector<vector<mint>>&Rnum){
    auto res=Lsum; REP(i,50)REP(j,50)res[i][j]+=Rsum[i][j];
    REP(l,50)REP(r,l+1)
      for(int ll=r;ll<=l;ll++)for(int rr=ll;rr<=l;rr++)
        res[l][r]+=Lnum[l][rr]*Rsum[ll][r]+Lsum[l][rr]*Rnum[ll][r];
    return res;
  };

  while(k){
    if(k&1){
      asum=fsum(asum,sum,anum,num);
      anum=fnum(anum,num);
    }
    sum=fsum(sum,sum,num,num);
    num=fnum(num,num);
    k>>=1;
  }

  /*cerr<<"aNUM"<<endl;
  REP(i,3)REP(j,3)cerr<<anum[i][j]<<"\n "[j+1<3];
  cerr<<"aSUM"<<endl;
  REP(i,3)REP(j,3)cerr<<asum[i][j]<<"\n "[j+1<3];
  */

  mint ans=0;
  REP(l,50)REP(r,l+1)ans+=asum[l][r];
  cout<<ans<<endl;
}
accuracy: 1
time_ms: 300
memory_kb: 3596
final_rank: 7

code_snippet: #line 1 "Contests/Dummy/TUPC2021/j/main.cpp"
#include <bits/stdc++.h>
using namespace std;
#line 1 "ac-library/atcoder/modint.hpp"



#line 6 "ac-library/atcoder/modint.hpp"
#include <type_traits>

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

#line 1 "ac-library/atcoder/internal_math.hpp"



#line 5 "ac-library/atcoder/internal_math.hpp"

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

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 modular multiplication 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 < 2^31`
    explicit 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;
    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);

// @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);

// @param n `n < 2^32`
// @param m `1 <= m < 2^32`
// @return sum_{i=0}^{n-1} floor((ai + b) / m) (mod 2^64)
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;
        // y_max < m * (n + 1)
        // floor(y_max / m) <= n
        n = (unsigned long long)(y_max / m);
        b = (unsigned long long)(y_max % m);
        std::swap(m, a);
    }
    return ans;
}

}  // namespace internal

}  // namespace atcoder


#line 1 "ac-library/atcoder/internal_type_traits.hpp"



#line 7 "ac-library/atcoder/internal_type_traits.hpp"

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


#line 14 "ac-library/atcoder/modint.hpp"

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


#line 1 "ac-library/atcoder/fenwicktree.hpp"



#line 6 "ac-library/atcoder/fenwicktree.hpp"

#line 8 "ac-library/atcoder/fenwicktree.hpp"

namespace atcoder {

// Reference: https://en.wikipedia.org/wiki/Fenwick_tree
template <class T> struct fenwick_tree {
    using U = internal::to_unsigned_t<T>;

  public:
    fenwick_tree() : _n(0) {}
    explicit fenwick_tree(int n) : _n(n), data(n) {}

    void add(int p, T x) {
        assert(0 <= p && p < _n);
        p++;
        while (p <= _n) {
            data[p - 1] += U(x);
            p += p & -p;
        }
    }

    T sum(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        return sum(r) - sum(l);
    }

  private:
    int _n;
    std::vector<U> data;

    U sum(int r) {
        U s = 0;
        while (r > 0) {
            s += data[r - 1];
            r -= r & -r;
        }
        return s;
    }
};

}  // namespace atcoder


#line 5 "Contests/Dummy/TUPC2021/j/main.cpp"
using namespace atcoder;

#line 1 "library/KowerKoint/expansion/ac-library/modint.hpp"
using MI7 = modint1000000007;
using V7 = vector<MI7>;
using VV7 = vector<V7>;
using VVV7 = vector<VV7>;
using MI3 = modint998244353;
using V3 = vector<MI3>;
using VV3 = vector<V3>;
using VVV3 = vector<VV3>;

ostream &operator<<(ostream &os, const modint &x) {
    os << x.val();
    return os;
}

ostream &operator<<(ostream &os, const MI3 &x) {
    os << x.val();
    return os;
}

ostream &operator<<(ostream &os, const MI7 &x) {
    os << x.val();
    return os;
}

istream &operator>>(istream &is, modint &x) {
    int y; is >> y;
    x = y;
    return is;
}

istream &operator>>(istream &is, MI3 &x) {
    int y; is >> y;
    x = y;
    return is;
}

istream &operator>>(istream &is, MI7 &x) {
    int y; is >> y;
    x = y;
    return is;
}
#line 2 "library/KowerKoint/base.hpp"

#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif

#line 8 "library/KowerKoint/base.hpp"
using namespace std;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define END(...) { print(__VA_ARGS__); return; }

#ifdef ONLINE_JUDGE
#define DBG(...) {}
#else
#define DBG(a) { cerr << #a << ": "; dbg(a); }
#endif

using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using ll = long long;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
using VS = vector<string>;
using VVS = vector<VS>;
using VVVS = vector<VVS>;
using VC = vector<char>;
using VVC = vector<VC>;
using VVVC = vector<VVC>;
using P = pair<int, int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VVVP = vector<VVP>;
using LP = pair<ll, ll>;
using VLP = vector<LP>;
using VVLP = vector<VLP>;
using VVVLP = vector<VVLP>;

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001ll;
constexpr int DX[] = {1, 0, -1, 0};
constexpr int DY[] = {0, 1, 0, -1};

void print() { cout << '\n'; }
template<typename T>
void print(const T &t) { cout << t << '\n'; }
template<typename Head, typename... Tail>
void print(const Head &head, const Tail &... tail) {
    cout << head << ' ';
    print(tail...);
}

#ifdef ONLINE_JUDGE
template<typename... Args>
void dbg(const Args &... args) {}
#else
void dbg() { cerr << '\n'; }
template<typename T>
void dbg(const T &t) { cerr << t << '\n'; }
template<typename Head, typename... Tail>
void dbg(const Head &head, const Tail &... tail) {
    cerr << head << ' ';
    dbg(tail...);
}
#endif

template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
    os << p.first << " " << p.second;
    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 >
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 T >
istream &operator>>(istream &is, vector< T > &v) {
    for(T &in : v) is >> in;
    return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template <typename T>
pair<VI, vector<T>> compress(const vector<T> &a) {
    int n = a.size();
    vector<T> x;
    REP(i, n) x.push_back(a[i]);
    sort(ALL(x)); x.erase(unique(ALL(x)), x.end());
    VI res(n);
    REP(i, n) res[i] = lower_bound(ALL(x), a[i]) - x.begin();
    return make_pair(res, x);
}

template <typename T>
pair<vector<T>, vector<T>> factorial(int n) {
    vector<T> res(n+1), rev(n+1);
    res[0] = 1;
    REP(i, n) res[i+1] = res[i] * (i+1);
    rev[n] = 1 / res[n];
    for(int i = n; i > 0; i--) {
        rev[i-1] = rev[i] * i;
    }
    return make_pair(res, rev);
}
#line 1 "library/KowerKoint/internal_operator.hpp"
namespace internal_operator {
    template <typename T>
    T default_add(T a, T b) { return a + b; }
    template <typename T>
    T default_sub(T a, T b) { return a - b; }
    template <typename T>
    T zero() { return T(0); }
    template <typename T>
    T default_div(T a, T b) { return a / b; }
    template <typename T>
    T default_mult(T a, T b) { return a * b; }
    template <typename T>
    T one() { return T(1); }
    template <typename T>
    T default_xor(T a, T b) { return a ^ b; }
    template <typename T>
    T default_and(T a, T b) { return a & b; }
    template <typename T>
    T default_or(T a, T b) { return a | b; }
}

#line 4 "library/KowerKoint/math/matrix.hpp"

template <
    typename T,
    T (*add)(const T, const T)=internal_operator::default_add,
    T (*zero)()=internal_operator::zero,
    T (*mult)(const T, const T)=internal_operator::default_mult,
    T (*one)()=internal_operator::one,
    T (*sub)(const T, const T)=internal_operator::default_sub,
    T (*div)(const T, const T)=internal_operator::default_div
>
struct Matrix {
    vector<vector<T>> A;

    Matrix(size_t n, size_t m) : A(n, vector<T>(m, zero())) {}

    size_t height() const { return A.size(); }
    size_t width() const { return A[0].size(); }

    vector<T> &operator[](int i) { return A.at(i); }
    const vector<T> &operator[](int i) const { return A.at(i); }

    static Matrix I(size_t n) {
        Matrix ret(n, n);
        REP(i, n) ret[i][i] = one();
        return ret;
    }

    Matrix &operator+=(const Matrix &B) {
        size_t n = height(), m = width();
        assert(n == B.height() && m == B.width());
        REP(i, n) REP(j, m) A[i][j] = add(A[i][j], B[i][j]);
        return *this;
    }
    Matrix operator+(const Matrix &B) const {
        return (Matrix(*this) += B);
    }

    Matrix &operator-=(const Matrix &B) {
        size_t n = height(), m = width();
        assert(n == B.height() && m == B.width());
        REP(i, n) REP(j, m) A[i][j] = sub(A[i][j], B[i][j]);
        return *this;
    }
    Matrix operator-(const Matrix &B) const {
        return (Matrix(*this) -= B);
    }

    Matrix &operator*=(const Matrix &B) {
        size_t n = height(), m = width(), l = B.width();
        assert(m == B.height());
        vector<vector<T>> res(n, vector<T>(l, zero()));
        REP(i, n) REP(j, m) REP(k, l) res[i][k] = add(res[i][k], mult(A[i][j], B[j][k]));
        A.swap(res);
        return (*this);
    }
    Matrix operator*(const Matrix &B) const {
        return (Matrix(*this) *= B);
    }

    friend istream &operator>>(istream &is, Matrix &mat) {
        size_t n = mat.height(), m = mat.width();
        REP(i, n) REP(j, m) is >> mat[i][j];
        return is;
    }

    friend ostream &operator<<(ostream &os, Matrix &mat) {
        size_t n = mat.height(), m = mat.width();
        REP(i, n) {
            REP(j, m) os << mat[i][j] << (j==m-1? '\n' : ' ');
        }
        return os;
    }

    pair<Matrix, T> gaussian_elimination() const {
        int n = height(), m = width();
        Matrix mat(*this);
        T det = one();
        VI columns;
        int i = 0;
        int j = 0;
        while(i < n && j < m) {
            int idx = -1;
            FOR(k, i, n) if(mat[k][j] != zero()) idx = k;
            if(idx == -1) {
                det = zero();
                j++;
                continue;
            }
            if(i != idx) {
                det *= sub(zero(), one());
                swap(mat[i], mat[idx]);
            }
            det *= mat[i][j];
            T scale = mat[i][j];
            REP(l, m) mat[i][l] = div(mat[i][l], scale);
            FOR(k, i+1, n) {
                T scale = mat[k][j];
                REP(l, m) mat[k][l] = sub(mat[k][l], mult(mat[i][l], scale));
            }
            columns.push_back(j);
            i++;
            j++;
        }
        REP(i, columns.size()) {
            int j = columns[i];
            REP(k, i) {
                T scale = mat[k][j];
                FOR(l, j, m) {
                    mat[k][l] = sub(mat[k][l], mult(mat[i][l], scale));
                }
            }
        }
        return make_pair(mat, det);
    }

    Matrix inv() const {
        int n = height();
        Matrix and_i(n, n*2);
        REP(i, n) REP(j, n) and_i[i][j] = A[i][j];
        REP(i, n) and_i[i][n+i] = one();
        auto [i_and, det] = and_i.gaussian_elimination();
        assert(det != zero());
        Matrix res(n, n);
        REP(i, n) REP(j, n) res[i][j] = i_and[i][n+i];
        return res;
    }

    Matrix operator^=(ll n) {
        if(n < 0) {
            *this = this->inv();
            n = -n;
        }
        Matrix res = Matrix::I(height());
        while(n) {
            if(n & 1) res *= *this;
            *this *= *this;
            n >>= 1LL;
        }
        A.swap(res.A);
        return (*this);
    }
    Matrix operator^(const ll n) const {
        return (Matrix(*this) ^= n);
    }
};
#line 9 "Contests/Dummy/TUPC2021/j/main.cpp"

void solve(){
    int n; ll k; cin >> n >> k;
    VI a(n); cin >> a;
    Matrix<MI7> mat(102, 102);
    REP(i, 51) {
        fenwick_tree<MI7> num(51);
        fenwick_tree<MI7> sum(51);
        num.add(i, 1);
        REP(j, n) {
            sum.add(a[j], sum.sum(0, a[j]+1) + num.sum(0, a[j]+1));
            num.add(a[j], num.sum(0, a[j]+1));
        }
        REP(j, 51) {
            mat[i*2][j*2] = mat[i*2+1][j*2+1] = num.sum(j, j+1);
            mat[i*2][j*2+1] = sum.sum(j, j+1);
        }
    }
    Matrix<MI7> init_vec(1, 102);
    init_vec[0][0] = 1;
    init_vec *= mat ^= k;
    MI7 ans = 0;
    REP(i, 51) ans += init_vec[0][i*2+1];
    print(ans);
}

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
    // Fasterize input/output script
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(100);
    // scanf/printf user should delete this fasterize input/output script

    int t = 1;
    //cin >> t; // comment out if solving multi testcase
    for(int testCase = 1;testCase <= t;++testCase){
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3592
final_rank: 2

code_snippet: /*	author:  Kite_kuma
	created: 2022.03.13 15:00:13 */

// #ifdef LOCAL
// #define _GLIBCXX_DEBUG
// #endif
#include <bits/stdc++.h>
using namespace std;

#pragma region macros

#define foa(s, v) for(auto &s : v)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcnt(n) __builtin_popcountll((long long)n)

#define REPname(a, b, c, d, e, ...) e
#define rep(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define REP0(x) for(int Counter_in_rep_macro = 0; Counter_in_rep_macro < (x); ++Counter_in_rep_macro)
#define REP1(i, x) for(int i = 0; i < (x); ++i)
#define REP2(i, l, r) for(int i = (l); i < (r); ++i)
#define REP3(i, l, r, c) for(int i = (l); i < (r); i += (c))

#define DREPname(a, b, c, d, e, ...) e
#define drep(...) DREPname(__VA_ARGS__, DREP3, DREP2, DREP1)(__VA_ARGS__)
#define DREP1(i, x) for(int i = (x)-1; i >= 0; --i)
#define DREP2(i, l, r) for(int i = (r)-1; i >= (l); --i)
#define DREP3(i, l, r, c) for(int i = (r)-1; i >= (l); i -= (c))

#pragma endregion

#pragma region aliases

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vvvi = std::vector<std::vector<std::vector<int>>>;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
template <class T = ll>
using V = std::vector<T>;
template <class T = ll>
using VV = V<V<T>>;
template <class T = ll>
using VVV = V<V<V<T>>>;
template <class T = ll>
using pqup = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T = ll>
using pqdn = std::priority_queue<T>;

#pragma endregion

#pragma region constants

const int inf = 1e9;
const long long INF = 1e18;
const long double pi = acos(-1);
const char dl = '\n';
const char sp = ' ';
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

const int mod_1000000007 = 1000000007;
const int mod_998244353 = 998244353;

#pragma endregion

#pragma region basic_operation

template <class T0, class T1, class T2>
inline bool in_range(T0 x, T1 lef, T2 rig) {
	return ((lef <= x) && (x < rig));
}

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

void Yes(bool f = 1) { std::cout << (f ? "Yes" : "No") << '\n'; }
void No() { std::cout << "No\n"; }
void YES(bool f = 1) { std::cout << (f ? "YES" : "NO") << '\n'; }
void NO() { std::cout << "NO\n"; }

template <class T>
void drop(T answer) {
	std::cout << answer << '\n';
	exit(0);
}

void err(bool flag = true) {
	if(!flag) return;
	std::cout << -1 << '\n';
	exit(0);
}

template <class T>
void vout(std::vector<T> const &v, bool vertically = 0) {
	if(vertically) {
		for(auto const &a : v) {
			std::cout << a << '\n';
		}
		return;
	}
	for(auto it = v.begin(); it != v.end(); it++) {
		std::cout << (*it);
		if(it != v.end() - 1) {
			std::cout << ' ';
		}
	}
	std::cout << '\n';
	return;
}

inline void print() { std::cout << '\n'; }
template <class T>
inline void print(T x) {
	std::cout << x << '\n';
	return;
}
template <typename Head, typename... Tail>
void print(Head H, Tail... T) {
	std::cout << H << " ";
	print(T...);
}

template <class T>
void add(std::vector<T> &v, T val) {
	for(auto &a : v) a += val;
	return;
}

template <class T>
T dup(T a, T b) {
	assert(b != 0);
	return (a + b - 1) / b;
}

template <class T>
T greatest_lower_multiple(T x, T d) {
	if(d == 0) return 0;
	if(d < 0) d *= -1;
	T y = x % d;
	if(y < 0) y += d;
	return x - y;
}

template <class T>
T least_upper_multiple(T x, T d) {
	return -greatest_lower_multiple(-x, d);
}

long long POW(long long a, long long n) {
	long long res = 1;
	while(n > 0) {
		if(n & 1) res = res * a;
		a = a * a;
		n >>= 1;
	}
	return res;
}

long long modpow(long long a, long long n, long long mod) {	 // a^n mod
	assert(n >= 0 && mod);
	if(mod == 1) return 0LL;
	long long res = 1;
	a %= mod;
	while(n > 0) {
		if(n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res < 0 ? res + mod : res;
}

// return x which satisfies a * x % mod == gcd(a, mod)
// not (mod | a)
long long modinv(long long a, long long mod) {
	long long b = mod, u = 1, v = 0;
	while(b) {
		long long t = a / b;
		a -= t * b;
		std::swap(a, b);
		u -= t * v;
		std::swap(u, v);
	}
	u %= mod;
	if(u < 0) u += mod;
	return u;
}

template <class T>
int lb(const std::vector<T> &a, const T x) {
	return std::distance(a.begin(), std::lower_bound(a.begin(), a.end(), x));
}
template <class T>
int ub(const std::vector<T> &a, const T x) {
	return std::distance(a.begin(), std::upper_bound(a.begin(), a.end(), x));
}
template <class T>
void unq_sort(std::vector<T> &a) {
	std::sort(a.begin(), a.end());
	a.erase(std::unique(a.begin(), a.end()), a.end());
}
template <class T>
std::vector<int> press(std::vector<T> &a) {
	auto vec = a;
	unq_sort(vec);
	std::vector<int> ret;
	for(auto &v : a) ret.push_back(lb(vec, v));
	return ret;
}

#pragma endregion

#pragma region input
#define VEC(type, name, size) \
	vector<type> name(size);  \
	scanner::INPUT(name)
#define VVEC(type, name, h, w)                     \
	vector<vector<type>> name(h, vector<type>(w)); \
	scanner::INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LL(...)            \
	long long __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define STR(...)        \
	string __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define CHR(...)      \
	char __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define DBL(...)        \
	double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LD(...)              \
	long double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define TPL3(type0, type1, type2, name)   \
	std::tuple<type0, type1, type2> name; \
	scanner::INPUT(name);
#define TPL4(type0, type1, type2, type3, name)   \
	std::tuple<type0, type1, type2, type3> name; \
	scanner::INPUT(name);

namespace scanner {
template <class T>
void scan(T &a) {
	std::cin >> a;
}

template <class T, class L>
void scan(std::pair<T, L> &p) {
	scan(p.first);
	scan(p.second);
}

template <class T0, class T1, class T2>
void scan(std::tuple<T0, T1, T2> &p) {
	T0 t0;
	T1 t1;
	T2 t2;
	scan(t0);
	scan(t1);
	scan(t2);
	p = std::make_tuple(t0, t1, t2);
}

template <class T0, class T1, class T2, class T3>
void scan(std::tuple<T0, T1, T2, T3> &p) {
	T0 t0;
	T1 t1;
	T2 t2;
	T3 t3;
	scan(t0);
	scan(t1);
	scan(t2);
	scan(t3);
	p = std::make_tuple(t0, t1, t2, t3);
}

template <class T>
void scan(std::vector<T> &a) {
	for(auto &i : a) scan(i);
}

void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &... tail) {
	scan(head);
	INPUT(tail...);
}
}  // namespace scanner

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

#pragma region debug

#pragma region output
template <typename T1, typename T2>
std::ostream &std::operator<<(std::ostream &os, const std::pair<T1, T2> &p) {
	os << p.first << " " << p.second;
	return os;
}
template <class T>
std::ostream &std::operator<<(std::ostream &os, const std::vector<T> &v) {
	for(int i = 0; i < (int)v.size(); i++) {
		if(i) os << " ";
		os << v[i];
	}
	return os;
}
#pragma endregion

#pragma region view

namespace viewer {
void view(const long long e) {
	if(e == INF)
		std::cerr << "INF";
	else if(e == -INF)
		std::cerr << "-INF";
	else
		std::cerr << e;
}

void view(const int e) {
	if(e == inf)
		std::cerr << "inf";
	else if(e == -inf)
		std::cerr << "-inf";
	else
		std::cerr << e;
}

template <typename T>
void view(const T e) {
	std::cerr << e;
}

template <typename T, typename U>
void view(const std::pair<T, U> &p) {
	std::cerr << "(";
	view(p.first);
	std::cerr << ", ";
	view(p.second);
	std::cerr << ")";
}

template <class T0, class T1, class T2>
void view(const std::tuple<T0, T1, T2> &p) {
	std::cerr << "(";
	view(std::get<0>(p));
	std::cerr << ", ";
	view(std::get<1>(p));
	std::cerr << ", ";
	view(std::get<2>(p));
	std::cerr << ")";
}

template <class T0, class T1, class T2, class T3>
void view(const std::tuple<T0, T1, T2, T3> &p) {
	std::cerr << "(";
	view(std::get<0>(p));
	std::cerr << ", ";
	view(std::get<1>(p));
	std::cerr << ", ";
	view(std::get<2>(p));
	std::cerr << ", ";
	view(std::get<3>(p));
	std::cerr << ")";
}

template <typename T>
void view(const std::set<T> &s) {
	if(s.empty()) {
		std::cerr << "{ }";
		return;
	}
	std::cerr << "{ ";
	for(auto &t : s) {
		view(t);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}

template <typename T>
void view(const std::unordered_set<T> &s) {
	if(s.empty()) {
		std::cerr << "{ }";
		return;
	}
	std::cerr << "{ ";
	for(auto &t : s) {
		view(t);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}

template <typename T>
void view(const std::vector<T> &v) {
	if(v.empty()) {
		std::cerr << "{ }";
		return;
	}
	std::cerr << "{ ";
	for(const auto &e : v) {
		view(e);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}

template <typename T>
void view(const std::vector<std::vector<T>> &vv) {
	std::cerr << "{\n";
	for(const auto &v : vv) {
		std::cerr << "\t";
		view(v);
		std::cerr << '\n';
	}
	std::cerr << "}";
}

template <typename T, typename U>
void view(const std::vector<std::pair<T, U>> &v) {
	std::cerr << "{\n";
	for(const auto &c : v) {
		std::cerr << "\t(";
		view(c.first);
		std::cerr << ", ";
		view(c.second);
		std::cerr << ")\n";
	}
	std::cerr << "}";
}

template <class T0, class T1, class T2>
void view(const std::vector<std::tuple<T0, T1, T2>> &v) {
	if(v.empty()) {
		std::cerr << "{ }";
		return;
	}
	std::cerr << '{';
	for(const auto &t : v) {
		std::cerr << "\n\t";
		view(t);
		std::cerr << ",";
	}
	std::cerr << "\n}";
}

template <class T0, class T1, class T2, class T3>
void view(const std::vector<std::tuple<T0, T1, T2, T3>> &v) {
	if(v.empty()) {
		std::cerr << "{ }";
		return;
	}
	std::cerr << '{';
	for(const auto &t : v) {
		std::cerr << "\n\t";
		view(t);
		std::cerr << ",";
	}
	std::cerr << "\n}";
}

template <typename T, typename U>
void view(const std::map<T, U> &m) {
	std::cerr << "{\n";
	for(const auto &t : m) {
		std::cerr << "\t[";
		view(t.first);
		std::cerr << "] : ";
		view(t.second);
		std::cerr << '\n';
	}
	std::cerr << "}";
}

template <typename T, typename U>
void view(const std::unordered_map<T, U> &m) {
	std::cerr << "{\n";
	for(const auto &t : m) {
		std::cerr << "\t[";
		view(t.first);
		std::cerr << "] : ";
		view(t.second);
		std::cerr << '\n';
	}
	std::cerr << "}";
}
}  // namespace viewer

#pragma endregion

// when debugging : g++ foo.cpp -DLOCAL
#ifdef LOCAL
void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	viewer::view(H);
	std::cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                                \
	do {                                                          \
		std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                                   \
		std::cerr << "\b\b]\n";                                   \
	} while(0)
#define dump(x)                                      \
	do {                                             \
		std::cerr << __LINE__ << " " << #x << " : "; \
		viewer::view(x);                             \
		std::cerr << '\n';                           \
	} while(0)

#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

#pragma endregion

#pragma region modint

const int mod = mod_1000000007;

template <int mod>
struct ModInt {
	int 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; }
	bool operator==(const ModInt &p) const { return x == p.x; }
	bool 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>;

#pragma endregion

mint solve(int n) {
	ll conjunction;
	cin >> conjunction;
	vector<int> a(n);
	foa(t, a) cin >> t;
	add(a, -1);
	const int value_max = 50;

	VV<mint> ways_from_to(value_max, V<mint>(value_max, 0));
	auto ptsums = ways_from_to;

	rep(startvalue, value_max) {
		auto &ways = ways_from_to[startvalue];
		auto &ptsum = ptsums[startvalue];
		ways[startvalue] = 1;
		foa(val, a) {
			V<mint> ways_nxt = ways;
			V<mint> ptsum_nxt = ptsum;
			rep(prevalue, val + 1) {
				ways_nxt[val] += ways[prevalue];
				ptsum_nxt[val] += ptsum[prevalue] + ways[prevalue];
			}
			swap(ways, ways_nxt);
			swap(ptsum_nxt, ptsum);
		}
	}

	debug(ptsums);

	auto merge_results = [&](const VV<mint> &ways_left, const VV<mint> &pts_left, const VV<mint> &ways_right,
							const VV<mint> &pts_right) -> pair<VV<mint>, VV<mint>> {
		VV<mint> ways_ret(value_max, V<mint>(value_max, mint(0)));
		auto ptsum_ret = ways_ret;
		rep(from_left, value_max) rep(to_left, from_left, value_max) {
			const mint &wl = ways_left[from_left][to_left];
			const mint &sl = pts_left[from_left][to_left];
			// rep(from_right, to_left, value_max) {
			const int from_right = to_left;
			rep(to_right, from_right, value_max) {
				const mint &wr = ways_right[from_right][to_right];
				const mint &sr = pts_right[from_right][to_right];
				ways_ret[from_left][to_right] += wl * wr;
				ptsum_ret[from_left][to_right] += wl * sr + wr * sl;
			}
			// }
		}
		return make_pair(ways_ret, ptsum_ret);
	};

	using result = VV<mint>;

	auto calc = [&](auto self, ll k, const VV<mint> &ways, const VV<mint> &ptsum) -> pair<VV<mint>, VV<mint>> {
		if(k == 1) return make_pair(ways, ptsum);
		pair<result, result> dbl = merge_results(ways, ptsum, ways, ptsum);
		pair<result, result> upper = self(self, k >> 1, dbl.first, dbl.second);
		if(k & 1) return merge_results(upper.first, upper.second, ways, ptsum);
		return upper;
	};

	mint ans = 0;
	auto ptsum = calc(calc, conjunction, ways_from_to, ptsums).second;
	foa(val, ptsum.front()) ans += val;
	return (ans);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout << std::fixed << std::setprecision(15);
	srand((unsigned)time(NULL));

	int n;
	while(cin >> n && n) cout << solve(n) << dl;
	return 0;
}
accuracy: 0.9166666666666666
time_ms: 80
memory_kb: 3924
final_rank: 17

code_snippet: /*	author:  Kite_kuma
	created: 2022.03.13 15:00:13 */

// #ifdef LOCAL
// #define _GLIBCXX_DEBUG
// #endif
#include <bits/stdc++.h>
using namespace std;

#pragma region macros

#define foa(s, v) for(auto &s : v)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcnt(n) __builtin_popcountll((long long)n)

#define REPname(a, b, c, d, e, ...) e
#define rep(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define REP0(x) for(int Counter_in_rep_macro = 0; Counter_in_rep_macro < (x); ++Counter_in_rep_macro)
#define REP1(i, x) for(int i = 0; i < (x); ++i)
#define REP2(i, l, r) for(int i = (l); i < (r); ++i)
#define REP3(i, l, r, c) for(int i = (l); i < (r); i += (c))

#define DREPname(a, b, c, d, e, ...) e
#define drep(...) DREPname(__VA_ARGS__, DREP3, DREP2, DREP1)(__VA_ARGS__)
#define DREP1(i, x) for(int i = (x)-1; i >= 0; --i)
#define DREP2(i, l, r) for(int i = (r)-1; i >= (l); --i)
#define DREP3(i, l, r, c) for(int i = (r)-1; i >= (l); i -= (c))

#pragma endregion

#pragma region aliases

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vvvi = std::vector<std::vector<std::vector<int>>>;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
template <class T = ll>
using V = std::vector<T>;
template <class T = ll>
using VV = V<V<T>>;
template <class T = ll>
using VVV = V<V<V<T>>>;
template <class T = ll>
using pqup = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T = ll>
using pqdn = std::priority_queue<T>;

#pragma endregion

#pragma region constants

const int inf = 1e9;
const long long INF = 1e18;
const long double pi = acos(-1);
const char dl = '\n';
const char sp = ' ';
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

const int mod_1000000007 = 1000000007;
const int mod_998244353 = 998244353;

#pragma endregion

#pragma region basic_operation

template <class T0, class T1, class T2>
inline bool in_range(T0 x, T1 lef, T2 rig) {
	return ((lef <= x) && (x < rig));
}

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

void Yes(bool f = 1) { std::cout << (f ? "Yes" : "No") << '\n'; }
void No() { std::cout << "No\n"; }
void YES(bool f = 1) { std::cout << (f ? "YES" : "NO") << '\n'; }
void NO() { std::cout << "NO\n"; }

template <class T>
void drop(T answer) {
	std::cout << answer << '\n';
	exit(0);
}

void err(bool flag = true) {
	if(!flag) return;
	std::cout << -1 << '\n';
	exit(0);
}

template <class T>
void vout(std::vector<T> const &v, bool vertically = 0) {
	if(vertically) {
		for(auto const &a : v) {
			std::cout << a << '\n';
		}
		return;
	}
	for(auto it = v.begin(); it != v.end(); it++) {
		std::cout << (*it);
		if(it != v.end() - 1) {
			std::cout << ' ';
		}
	}
	std::cout << '\n';
	return;
}

inline void print() { std::cout << '\n'; }
template <class T>
inline void print(T x) {
	std::cout << x << '\n';
	return;
}
template <typename Head, typename... Tail>
void print(Head H, Tail... T) {
	std::cout << H << " ";
	print(T...);
}

template <class T>
void add(std::vector<T> &v, T val) {
	for(auto &a : v) a += val;
	return;
}

template <class T>
T dup(T a, T b) {
	assert(b != 0);
	return (a + b - 1) / b;
}

template <class T>
T greatest_lower_multiple(T x, T d) {
	if(d == 0) return 0;
	if(d < 0) d *= -1;
	T y = x % d;
	if(y < 0) y += d;
	return x - y;
}

template <class T>
T least_upper_multiple(T x, T d) {
	return -greatest_lower_multiple(-x, d);
}

long long POW(long long a, long long n) {
	long long res = 1;
	while(n > 0) {
		if(n & 1) res = res * a;
		a = a * a;
		n >>= 1;
	}
	return res;
}

long long modpow(long long a, long long n, long long mod) {	 // a^n mod
	assert(n >= 0 && mod);
	if(mod == 1) return 0LL;
	long long res = 1;
	a %= mod;
	while(n > 0) {
		if(n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res < 0 ? res + mod : res;
}

// return x which satisfies a * x % mod == gcd(a, mod)
// not (mod | a)
long long modinv(long long a, long long mod) {
	long long b = mod, u = 1, v = 0;
	while(b) {
		long long t = a / b;
		a -= t * b;
		std::swap(a, b);
		u -= t * v;
		std::swap(u, v);
	}
	u %= mod;
	if(u < 0) u += mod;
	return u;
}

template <class T>
int lb(const std::vector<T> &a, const T x) {
	return std::distance(a.begin(), std::lower_bound(a.begin(), a.end(), x));
}
template <class T>
int ub(const std::vector<T> &a, const T x) {
	return std::distance(a.begin(), std::upper_bound(a.begin(), a.end(), x));
}
template <class T>
void unq_sort(std::vector<T> &a) {
	std::sort(a.begin(), a.end());
	a.erase(std::unique(a.begin(), a.end()), a.end());
}
template <class T>
std::vector<int> press(std::vector<T> &a) {
	auto vec = a;
	unq_sort(vec);
	std::vector<int> ret;
	for(auto &v : a) ret.push_back(lb(vec, v));
	return ret;
}

#pragma endregion

#pragma region input
#define VEC(type, name, size) \
	vector<type> name(size);  \
	scanner::INPUT(name)
#define VVEC(type, name, h, w)                     \
	vector<vector<type>> name(h, vector<type>(w)); \
	scanner::INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LL(...)            \
	long long __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define STR(...)        \
	string __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define CHR(...)      \
	char __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define DBL(...)        \
	double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LD(...)              \
	long double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define TPL3(type0, type1, type2, name)   \
	std::tuple<type0, type1, type2> name; \
	scanner::INPUT(name);
#define TPL4(type0, type1, type2, type3, name)   \
	std::tuple<type0, type1, type2, type3> name; \
	scanner::INPUT(name);

namespace scanner {
template <class T>
void scan(T &a) {
	std::cin >> a;
}

template <class T, class L>
void scan(std::pair<T, L> &p) {
	scan(p.first);
	scan(p.second);
}

template <class T0, class T1, class T2>
void scan(std::tuple<T0, T1, T2> &p) {
	T0 t0;
	T1 t1;
	T2 t2;
	scan(t0);
	scan(t1);
	scan(t2);
	p = std::make_tuple(t0, t1, t2);
}

template <class T0, class T1, class T2, class T3>
void scan(std::tuple<T0, T1, T2, T3> &p) {
	T0 t0;
	T1 t1;
	T2 t2;
	T3 t3;
	scan(t0);
	scan(t1);
	scan(t2);
	scan(t3);
	p = std::make_tuple(t0, t1, t2, t3);
}

template <class T>
void scan(std::vector<T> &a) {
	for(auto &i : a) scan(i);
}

void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &... tail) {
	scan(head);
	INPUT(tail...);
}
}  // namespace scanner

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

#pragma region debug

#pragma region output
template <typename T1, typename T2>
std::ostream &std::operator<<(std::ostream &os, const std::pair<T1, T2> &p) {
	os << p.first << " " << p.second;
	return os;
}
template <class T>
std::ostream &std::operator<<(std::ostream &os, const std::vector<T> &v) {
	for(int i = 0; i < (int)v.size(); i++) {
		if(i) os << " ";
		os << v[i];
	}
	return os;
}
#pragma endregion

#pragma region view

namespace viewer {
void view(const long long e) {
	if(e == INF)
		std::cerr << "INF";
	else if(e == -INF)
		std::cerr << "-INF";
	else
		std::cerr << e;
}

void view(const int e) {
	if(e == inf)
		std::cerr << "inf";
	else if(e == -inf)
		std::cerr << "-inf";
	else
		std::cerr << e;
}

template <typename T>
void view(const T e) {
	std::cerr << e;
}

template <typename T, typename U>
void view(const std::pair<T, U> &p) {
	std::cerr << "(";
	view(p.first);
	std::cerr << ", ";
	view(p.second);
	std::cerr << ")";
}

template <class T0, class T1, class T2>
void view(const std::tuple<T0, T1, T2> &p) {
	std::cerr << "(";
	view(std::get<0>(p));
	std::cerr << ", ";
	view(std::get<1>(p));
	std::cerr << ", ";
	view(std::get<2>(p));
	std::cerr << ")";
}

template <class T0, class T1, class T2, class T3>
void view(const std::tuple<T0, T1, T2, T3> &p) {
	std::cerr << "(";
	view(std::get<0>(p));
	std::cerr << ", ";
	view(std::get<1>(p));
	std::cerr << ", ";
	view(std::get<2>(p));
	std::cerr << ", ";
	view(std::get<3>(p));
	std::cerr << ")";
}

template <typename T>
void view(const std::set<T> &s) {
	if(s.empty()) {
		std::cerr << "{ }";
		return;
	}
	std::cerr << "{ ";
	for(auto &t : s) {
		view(t);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}

template <typename T>
void view(const std::unordered_set<T> &s) {
	if(s.empty()) {
		std::cerr << "{ }";
		return;
	}
	std::cerr << "{ ";
	for(auto &t : s) {
		view(t);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}

template <typename T>
void view(const std::vector<T> &v) {
	if(v.empty()) {
		std::cerr << "{ }";
		return;
	}
	std::cerr << "{ ";
	for(const auto &e : v) {
		view(e);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}

template <typename T>
void view(const std::vector<std::vector<T>> &vv) {
	std::cerr << "{\n";
	for(const auto &v : vv) {
		std::cerr << "\t";
		view(v);
		std::cerr << '\n';
	}
	std::cerr << "}";
}

template <typename T, typename U>
void view(const std::vector<std::pair<T, U>> &v) {
	std::cerr << "{\n";
	for(const auto &c : v) {
		std::cerr << "\t(";
		view(c.first);
		std::cerr << ", ";
		view(c.second);
		std::cerr << ")\n";
	}
	std::cerr << "}";
}

template <class T0, class T1, class T2>
void view(const std::vector<std::tuple<T0, T1, T2>> &v) {
	if(v.empty()) {
		std::cerr << "{ }";
		return;
	}
	std::cerr << '{';
	for(const auto &t : v) {
		std::cerr << "\n\t";
		view(t);
		std::cerr << ",";
	}
	std::cerr << "\n}";
}

template <class T0, class T1, class T2, class T3>
void view(const std::vector<std::tuple<T0, T1, T2, T3>> &v) {
	if(v.empty()) {
		std::cerr << "{ }";
		return;
	}
	std::cerr << '{';
	for(const auto &t : v) {
		std::cerr << "\n\t";
		view(t);
		std::cerr << ",";
	}
	std::cerr << "\n}";
}

template <typename T, typename U>
void view(const std::map<T, U> &m) {
	std::cerr << "{\n";
	for(const auto &t : m) {
		std::cerr << "\t[";
		view(t.first);
		std::cerr << "] : ";
		view(t.second);
		std::cerr << '\n';
	}
	std::cerr << "}";
}

template <typename T, typename U>
void view(const std::unordered_map<T, U> &m) {
	std::cerr << "{\n";
	for(const auto &t : m) {
		std::cerr << "\t[";
		view(t.first);
		std::cerr << "] : ";
		view(t.second);
		std::cerr << '\n';
	}
	std::cerr << "}";
}
}  // namespace viewer

#pragma endregion

// when debugging : g++ foo.cpp -DLOCAL
#ifdef LOCAL
void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	viewer::view(H);
	std::cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                                \
	do {                                                          \
		std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                                   \
		std::cerr << "\b\b]\n";                                   \
	} while(0)
#define dump(x)                                      \
	do {                                             \
		std::cerr << __LINE__ << " " << #x << " : "; \
		viewer::view(x);                             \
		std::cerr << '\n';                           \
	} while(0)

#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

#pragma endregion

#pragma region modint

const int mod = mod_1000000007;

template <int mod>
struct ModInt {
	int 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; }
	bool operator==(const ModInt &p) const { return x == p.x; }
	bool 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>;

#pragma endregion

mint solve(int n) {
	ll k;
	cin >> k;
	vector<int> a(n);
	foa(t, a) cin >> t;
	add(a, -1);
	const int value_max = 50;

	VV<mint> ways_from_to(value_max, V<mint>(value_max, 0));
	auto ptsums = ways_from_to;

	rep(startvalue, value_max) {
		vector<mint> ways(value_max, 0), ptsum(value_max, 0);
		ways[startvalue] = 1;
		foa(val, a) {
			// vector<mint> nxt(value_max, 0);
			V<mint> ways_nxt = ways;
			V<mint> ptsum_nxt = ptsum;
			rep(prevalue, val + 1) {
				// if(!ways[prevalue].x) continue;
				ways_nxt[val] += ways[prevalue];
				ptsum_nxt[val] += ptsum[prevalue] + ways[prevalue];
			}
			swap(ways, ways_nxt);
			swap(ptsum_nxt, ptsum);
		}

		ways_from_to[startvalue] = ways;
		ptsums[startvalue] = ptsum;
	}

	debug(ptsums);

	auto merge_result = [&](const VV<mint> &ways_left, const VV<mint> &pts_left, const VV<mint> &ways_right,
							const VV<mint> &pts_right) -> pair<VV<mint>, VV<mint>> {
		VV<mint> ways_ret(value_max, V<mint>(value_max, mint(0)));
		auto ptsum_ret = ways_ret;
		rep(from_left, value_max) rep(to_left, from_left, value_max) {
			const mint &wl = ways_left[from_left][to_left];
			const mint &sl = pts_left[from_left][to_left];
			// rep(from_right, to_left, value_max) {
			const int from_right = to_left;
			rep(to_right, from_right, value_max) {
				const mint &wr = ways_right[from_right][to_right];
				const mint &sr = pts_right[from_right][to_right];
				ways_ret[from_left][to_right] += wl * wr;
				ptsum_ret[from_left][to_right] += wl * sr + wr * sl;
			}
			// }
		}
		return make_pair(ways_ret, ptsum_ret);
	};

	using result = VV<mint>;

	auto calc = [&](auto self, ll k, const VV<mint> &ways, const VV<mint> &ptsum) -> pair<VV<mint>, VV<mint>> {
		if(k == 1) return make_pair(ways, ptsum);
		pair<result, result> dbl = merge_result(ways, ptsum, ways, ptsum);
		pair<result, result> upper = self(self, k >> 1, dbl.first, dbl.second);
		if(k & 1) return merge_result(upper.first, upper.second, ways, ptsum);
		return upper;
	};

	mint ans = 0;
	auto ptsum = calc(calc, k, ways_from_to, ptsums).second;
	foa(val, ptsum.front()) ans += val;
	return (ans);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout << std::fixed << std::setprecision(15);
	srand((unsigned)time(NULL));

	int n;
	while(cin >> n && n) cout << solve(n) << dl;
	return 0;
}
accuracy: 0.9166666666666666
time_ms: 90
memory_kb: 4036
final_rank: 19

code_snippet: /*	author:  Kite_kuma
	created: 2022.03.13 15:00:13 */

// #ifdef LOCAL
// #define _GLIBCXX_DEBUG
// #endif
#include <bits/stdc++.h>
using namespace std;

#pragma region macros

#define foa(s, v) for(auto &s : v)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcnt(n) __builtin_popcountll((long long)n)

#define REPname(a, b, c, d, e, ...) e
#define rep(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define REP0(x) for(int Counter_in_rep_macro = 0; Counter_in_rep_macro < (x); ++Counter_in_rep_macro)
#define REP1(i, x) for(int i = 0; i < (x); ++i)
#define REP2(i, l, r) for(int i = (l); i < (r); ++i)
#define REP3(i, l, r, c) for(int i = (l); i < (r); i += (c))

#define DREPname(a, b, c, d, e, ...) e
#define drep(...) DREPname(__VA_ARGS__, DREP3, DREP2, DREP1)(__VA_ARGS__)
#define DREP1(i, x) for(int i = (x)-1; i >= 0; --i)
#define DREP2(i, l, r) for(int i = (r)-1; i >= (l); --i)
#define DREP3(i, l, r, c) for(int i = (r)-1; i >= (l); i -= (c))

#pragma endregion

#pragma region aliases

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vvvi = std::vector<std::vector<std::vector<int>>>;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
template <class T = ll>
using V = std::vector<T>;
template <class T = ll>
using VV = V<V<T>>;
template <class T = ll>
using VVV = V<V<V<T>>>;
template <class T = ll>
using pqup = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T = ll>
using pqdn = std::priority_queue<T>;

#pragma endregion

#pragma region constants

const int inf = 1e9;
const long long INF = 1e18;
const long double pi = acos(-1);
const char dl = '\n';
const char sp = ' ';
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

const int mod_1000000007 = 1000000007;
const int mod_998244353 = 998244353;

#pragma endregion

#pragma region basic_operation

template <class T0, class T1, class T2>
inline bool in_range(T0 x, T1 lef, T2 rig) {
	return ((lef <= x) && (x < rig));
}

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

void Yes(bool f = 1) { std::cout << (f ? "Yes" : "No") << '\n'; }
void No() { std::cout << "No\n"; }
void YES(bool f = 1) { std::cout << (f ? "YES" : "NO") << '\n'; }
void NO() { std::cout << "NO\n"; }

template <class T>
void drop(T answer) {
	std::cout << answer << '\n';
	exit(0);
}

void err(bool flag = true) {
	if(!flag) return;
	std::cout << -1 << '\n';
	exit(0);
}

template <class T>
void vout(std::vector<T> const &v, bool vertically = 0) {
	if(vertically) {
		for(auto const &a : v) {
			std::cout << a << '\n';
		}
		return;
	}
	for(auto it = v.begin(); it != v.end(); it++) {
		std::cout << (*it);
		if(it != v.end() - 1) {
			std::cout << ' ';
		}
	}
	std::cout << '\n';
	return;
}

inline void print() { std::cout << '\n'; }
template <class T>
inline void print(T x) {
	std::cout << x << '\n';
	return;
}
template <typename Head, typename... Tail>
void print(Head H, Tail... T) {
	std::cout << H << " ";
	print(T...);
}

template <class T>
void add(std::vector<T> &v, T val) {
	for(auto &a : v) a += val;
	return;
}

template <class T>
T dup(T a, T b) {
	assert(b != 0);
	return (a + b - 1) / b;
}

template <class T>
T greatest_lower_multiple(T x, T d) {
	if(d == 0) return 0;
	if(d < 0) d *= -1;
	T y = x % d;
	if(y < 0) y += d;
	return x - y;
}

template <class T>
T least_upper_multiple(T x, T d) {
	return -greatest_lower_multiple(-x, d);
}

long long POW(long long a, long long n) {
	long long res = 1;
	while(n > 0) {
		if(n & 1) res = res * a;
		a = a * a;
		n >>= 1;
	}
	return res;
}

long long modpow(long long a, long long n, long long mod) {	 // a^n mod
	assert(n >= 0 && mod);
	if(mod == 1) return 0LL;
	long long res = 1;
	a %= mod;
	while(n > 0) {
		if(n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res < 0 ? res + mod : res;
}

// return x which satisfies a * x % mod == gcd(a, mod)
// not (mod | a)
long long modinv(long long a, long long mod) {
	long long b = mod, u = 1, v = 0;
	while(b) {
		long long t = a / b;
		a -= t * b;
		std::swap(a, b);
		u -= t * v;
		std::swap(u, v);
	}
	u %= mod;
	if(u < 0) u += mod;
	return u;
}

template <class T>
int lb(const std::vector<T> &a, const T x) {
	return std::distance(a.begin(), std::lower_bound(a.begin(), a.end(), x));
}
template <class T>
int ub(const std::vector<T> &a, const T x) {
	return std::distance(a.begin(), std::upper_bound(a.begin(), a.end(), x));
}
template <class T>
void unq_sort(std::vector<T> &a) {
	std::sort(a.begin(), a.end());
	a.erase(std::unique(a.begin(), a.end()), a.end());
}
template <class T>
std::vector<int> press(std::vector<T> &a) {
	auto vec = a;
	unq_sort(vec);
	std::vector<int> ret;
	for(auto &v : a) ret.push_back(lb(vec, v));
	return ret;
}

#pragma endregion

#pragma region input
#define VEC(type, name, size) \
	vector<type> name(size);  \
	scanner::INPUT(name)
#define VVEC(type, name, h, w)                     \
	vector<vector<type>> name(h, vector<type>(w)); \
	scanner::INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LL(...)            \
	long long __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define STR(...)        \
	string __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define CHR(...)      \
	char __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define DBL(...)        \
	double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LD(...)              \
	long double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define TPL3(type0, type1, type2, name)   \
	std::tuple<type0, type1, type2> name; \
	scanner::INPUT(name);
#define TPL4(type0, type1, type2, type3, name)   \
	std::tuple<type0, type1, type2, type3> name; \
	scanner::INPUT(name);

namespace scanner {
template <class T>
void scan(T &a) {
	std::cin >> a;
}

template <class T, class L>
void scan(std::pair<T, L> &p) {
	scan(p.first);
	scan(p.second);
}

template <class T0, class T1, class T2>
void scan(std::tuple<T0, T1, T2> &p) {
	T0 t0;
	T1 t1;
	T2 t2;
	scan(t0);
	scan(t1);
	scan(t2);
	p = std::make_tuple(t0, t1, t2);
}

template <class T0, class T1, class T2, class T3>
void scan(std::tuple<T0, T1, T2, T3> &p) {
	T0 t0;
	T1 t1;
	T2 t2;
	T3 t3;
	scan(t0);
	scan(t1);
	scan(t2);
	scan(t3);
	p = std::make_tuple(t0, t1, t2, t3);
}

template <class T>
void scan(std::vector<T> &a) {
	for(auto &i : a) scan(i);
}

void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &... tail) {
	scan(head);
	INPUT(tail...);
}
}  // namespace scanner

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

#pragma region debug

#pragma region output
template <typename T1, typename T2>
std::ostream &std::operator<<(std::ostream &os, const std::pair<T1, T2> &p) {
	os << p.first << " " << p.second;
	return os;
}
template <class T>
std::ostream &std::operator<<(std::ostream &os, const std::vector<T> &v) {
	for(int i = 0; i < (int)v.size(); i++) {
		if(i) os << " ";
		os << v[i];
	}
	return os;
}
#pragma endregion

#pragma region view

namespace viewer {
void view(const long long e) {
	if(e == INF)
		std::cerr << "INF";
	else if(e == -INF)
		std::cerr << "-INF";
	else
		std::cerr << e;
}

void view(const int e) {
	if(e == inf)
		std::cerr << "inf";
	else if(e == -inf)
		std::cerr << "-inf";
	else
		std::cerr << e;
}

template <typename T>
void view(const T e) {
	std::cerr << e;
}

template <typename T, typename U>
void view(const std::pair<T, U> &p) {
	std::cerr << "(";
	view(p.first);
	std::cerr << ", ";
	view(p.second);
	std::cerr << ")";
}

template <class T0, class T1, class T2>
void view(const std::tuple<T0, T1, T2> &p) {
	std::cerr << "(";
	view(std::get<0>(p));
	std::cerr << ", ";
	view(std::get<1>(p));
	std::cerr << ", ";
	view(std::get<2>(p));
	std::cerr << ")";
}

template <class T0, class T1, class T2, class T3>
void view(const std::tuple<T0, T1, T2, T3> &p) {
	std::cerr << "(";
	view(std::get<0>(p));
	std::cerr << ", ";
	view(std::get<1>(p));
	std::cerr << ", ";
	view(std::get<2>(p));
	std::cerr << ", ";
	view(std::get<3>(p));
	std::cerr << ")";
}

template <typename T>
void view(const std::set<T> &s) {
	if(s.empty()) {
		std::cerr << "{ }";
		return;
	}
	std::cerr << "{ ";
	for(auto &t : s) {
		view(t);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}

template <typename T>
void view(const std::unordered_set<T> &s) {
	if(s.empty()) {
		std::cerr << "{ }";
		return;
	}
	std::cerr << "{ ";
	for(auto &t : s) {
		view(t);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}

template <typename T>
void view(const std::vector<T> &v) {
	if(v.empty()) {
		std::cerr << "{ }";
		return;
	}
	std::cerr << "{ ";
	for(const auto &e : v) {
		view(e);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}

template <typename T>
void view(const std::vector<std::vector<T>> &vv) {
	std::cerr << "{\n";
	for(const auto &v : vv) {
		std::cerr << "\t";
		view(v);
		std::cerr << '\n';
	}
	std::cerr << "}";
}

template <typename T, typename U>
void view(const std::vector<std::pair<T, U>> &v) {
	std::cerr << "{\n";
	for(const auto &c : v) {
		std::cerr << "\t(";
		view(c.first);
		std::cerr << ", ";
		view(c.second);
		std::cerr << ")\n";
	}
	std::cerr << "}";
}

template <class T0, class T1, class T2>
void view(const std::vector<std::tuple<T0, T1, T2>> &v) {
	if(v.empty()) {
		std::cerr << "{ }";
		return;
	}
	std::cerr << '{';
	for(const auto &t : v) {
		std::cerr << "\n\t";
		view(t);
		std::cerr << ",";
	}
	std::cerr << "\n}";
}

template <class T0, class T1, class T2, class T3>
void view(const std::vector<std::tuple<T0, T1, T2, T3>> &v) {
	if(v.empty()) {
		std::cerr << "{ }";
		return;
	}
	std::cerr << '{';
	for(const auto &t : v) {
		std::cerr << "\n\t";
		view(t);
		std::cerr << ",";
	}
	std::cerr << "\n}";
}

template <typename T, typename U>
void view(const std::map<T, U> &m) {
	std::cerr << "{\n";
	for(const auto &t : m) {
		std::cerr << "\t[";
		view(t.first);
		std::cerr << "] : ";
		view(t.second);
		std::cerr << '\n';
	}
	std::cerr << "}";
}

template <typename T, typename U>
void view(const std::unordered_map<T, U> &m) {
	std::cerr << "{\n";
	for(const auto &t : m) {
		std::cerr << "\t[";
		view(t.first);
		std::cerr << "] : ";
		view(t.second);
		std::cerr << '\n';
	}
	std::cerr << "}";
}
}  // namespace viewer

#pragma endregion

// when debugging : g++ foo.cpp -DLOCAL
#ifdef LOCAL
void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	viewer::view(H);
	std::cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                                \
	do {                                                          \
		std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                                   \
		std::cerr << "\b\b]\n";                                   \
	} while(0)
#define dump(x)                                      \
	do {                                             \
		std::cerr << __LINE__ << " " << #x << " : "; \
		viewer::view(x);                             \
		std::cerr << '\n';                           \
	} while(0)

#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

#pragma endregion

#pragma region modint

const int mod = mod_1000000007;

template <int mod>
struct ModInt {
	int 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; }
	bool operator==(const ModInt &p) const { return x == p.x; }
	bool 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>;

#pragma endregion

mint solve(int n) {
	ll k;
	cin >> k;
	vector<int> a(n);
	foa(t, a) cin >> t;
	add(a, -1);
	const int value_max = 50;

	VV<mint> ways_from_to(value_max, V<mint>(value_max, 0));
	auto ptsums = ways_from_to;

	rep(startvalue, value_max) {
		vector<mint> ways(value_max, 0), ptsum(value_max, 0);
		ways[startvalue] = 1;
		foa(val, a) {
			// vector<mint> nxt(value_max, 0);
			V<mint> ways_nxt = ways;
			V<mint> ptsum_nxt = ptsum;
			rep(prevalue, val + 1) {
				if(!ways[prevalue].x) continue;
				ways_nxt[val] += ways[prevalue];
				ptsum_nxt[val] += ptsum[prevalue] + ways[prevalue];
			}
			swap(ways, ways_nxt);
			swap(ptsum_nxt, ptsum);
		}

		ways_from_to[startvalue] = ways;
		ptsums[startvalue] = ptsum;
	}

	debug(ptsums);

	auto merge_result = [&](const VV<mint> &ways_left, const VV<mint> &pts_left, const VV<mint> &ways_right,
							const VV<mint> &pts_right) -> pair<VV<mint>, VV<mint>> {
		VV<mint> ways_ret(value_max, V<mint>(value_max, mint(0)));
		auto ptsum_ret = ways_ret;
		rep(from_left, value_max) rep(to_left, from_left, value_max) {
			const mint &wl = ways_left[from_left][to_left];
			const mint &sl = pts_left[from_left][to_left];
			// rep(from_right, to_left, value_max) {
			const int from_right = to_left;
			rep(to_right, from_right, value_max) {
				const mint &wr = ways_right[from_right][to_right];
				const mint &sr = pts_right[from_right][to_right];
				ways_ret[from_left][to_right] += wl * wr;
				ptsum_ret[from_left][to_right] += wl * sr + wr * sl;
			}
			// }
		}
		return make_pair(ways_ret, ptsum_ret);
	};

	using result = VV<mint>;

	auto calc = [&](auto self, ll k, const VV<mint> &ways, const VV<mint> &ptsum) -> pair<VV<mint>, VV<mint>> {
		if(k == 1) return make_pair(ways, ptsum);
		pair<result, result> dbl = merge_result(ways, ptsum, ways, ptsum);
		pair<result, result> upper = self(self, k >> 1, dbl.first, dbl.second);
		if(k & 1) return merge_result(upper.first, upper.second, ways, ptsum);
		return upper;
	};

	mint ans = 0;
	auto ptsum = calc(calc, k, ways_from_to, ptsums).second;
	foa(val, ptsum.front()) ans += val;
	return (ans);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout << std::fixed << std::setprecision(15);
	srand((unsigned)time(NULL));

	int n;
	while(cin >> n && n) cout << solve(n) << dl;
	return 0;
}
accuracy: 0.9166666666666666
time_ms: 70
memory_kb: 4032
final_rank: 18

code_snippet: #pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline ll time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

constexpr ll mod = 1e9+7;

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

int d_dp[31][50][50];
int d_sum[31][50][50];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i]; a[i]--;
    }
    int m = 50;
    vector<vector<int>> dp(m,vector<int>(m));
    vector<vector<int>> sum(m,vector<int>(m));
    dp[a[0]][a[0]] = 1;
    sum[a[0]][a[0]] = 1;
    for(int i=1;i<n;i++){
        auto ndp = dp;
        auto nsum = sum;
        for(int r=0;r<=a[i];r++){
            for(int l=0;l<=r;l++){
                add(ndp[l][a[i]], dp[l][r]);
                add(nsum[l][a[i]], sum[l][r]);
                add(nsum[l][a[i]], dp[l][r]);
            }
        }
        ndp[a[i]][a[i]]++;
        nsum[a[i]][a[i]]++;
        swap(dp,ndp);
        swap(sum,nsum);
    }
    for(int i=0;i<50;i++){
        for(int j=0;j<50;j++){
            d_dp[0][i][j] = dp[i][j];
            d_sum[0][i][j] = sum[i][j];
        }
    }
    for(int i=1;i<31;i++){
        for(int l=0;l<m;l++){
            for(int r=l;r<m;r++){
                add(d_dp[i][l][r], d_dp[i-1][l][r]);
                add(d_dp[i][l][r], d_dp[i-1][l][r]);

                add(d_sum[i][l][r], d_sum[i-1][l][r]);
                add(d_sum[i][l][r], d_sum[i-1][l][r]);
            }
        }
        for(int l1=0;l1<50;l1++){
            for(int r1=l1;r1<50;r1++){
                for(int l2=r1;l2<50;l2++){
                    for(int r2=l2;r2<50;r2++){
                        add(d_dp[i][l1][r2], (ll)d_dp[i-1][l1][r1]*(ll)d_dp[i-1][l2][r2]%mod);
                        // add(d_dp[i][l1][r2], d_dp[i-1][l1][r1]);
                        // add(d_dp[i][l1][r2], d_dp[i-1][l2][r2]);

                        add(d_sum[i][l1][r2], (ll)d_sum[i-1][l1][r1]*(ll)d_dp[i-1][l2][r2]%mod);
                        add(d_sum[i][l1][r2], (ll)d_sum[i-1][l2][r2]*(ll)d_dp[i-1][l1][r1]%mod);
                        // add(d_sum[i][l1][r2], d_sum[i-1][l1][r1]);
                        // add(d_sum[i][l1][r2], d_sum[i-1][l2][r2]);
                    }
                }
            }
        }
    }
    vector<vector<int>> s_dp(m,vector<int>(m));
    vector<vector<int>> s_sum(m,vector<int>(m));
    for(int i=0;i<30;i++){
        if((1<<i)&k){
        }
        else continue;

        auto ss_dp = s_dp;
        auto ss_sum = s_sum;

        for(int l=0;l<m;l++){
            for(int r=l;r<m;r++){
                add(ss_dp[l][r], d_dp[i][l][r]);
                add(ss_sum[l][r], d_sum[i][l][r]);
            }
        }

        for(int l1=0;l1<50;l1++){
            for(int r1=l1;r1<50;r1++){
                for(int l2=r1;l2<50;l2++){
                    for(int r2=l2;r2<50;r2++){
                        add(ss_dp[l1][r2], (ll)s_dp[l1][r1]*(ll)d_dp[i][l2][r2]%mod);
                        // add(ss_dp[l1][r2], s_dp[l1][r1]);
                        // add(ss_dp[l1][r2], d_dp[i][l2][r2]);

                        add(ss_sum[l1][r2], (ll)s_sum[l1][r1]*(ll)d_dp[i][l2][r2]%mod);
                        add(ss_sum[l1][r2], (ll)d_sum[i][l2][r2]*(ll)s_dp[l1][r1]%mod);
                        // add(ss_sum[l1][r2], s_sum[l1][r1]);
                        // add(ss_sum[l1][r2], d_sum[i][l2][r2]);
                    }
                }
            }
        }
        swap(s_dp, ss_dp);
        swap(s_sum, ss_sum);
    }
    int res = 0;
    for(int i=0;i<m;i++){
        for(int j=i;j<m;j++){
            add(res, s_sum[i][j]);
            // cout << i << " " << j << " " << s_dp[i][j] << " " << s_sum[i][j] << endl; 
        }
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 160
memory_kb: 4180
final_rank: 6

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

using namespace std;
typedef long long ll;
typedef vector<vector<ll>> vvl;
ll mod = 1000000007;
vvl mul(const vvl &a,const vvl &b){
    int i,j,k,n = a.size();
	vvl c(n,vector<ll>(n,0));
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			for(k=0;k<n;k++) (c[i][j] += a[i][k]*b[k][j]%mod) %= mod;
		}
	}
	return c;
}

vector<ll> mul2(vvl &a,vector<ll> b){
    int i,j,n = a.size();
    vector<ll> c(n);
    for(i=0;i<n;i++){
        for(j=0;j<a[i].size();j++) (c[i] += a[i][j]*b[j]%mod) %= mod;
    }
	return c;
}

vvl mat_pw(vvl &a, ll x){
    int i,n = a.size();
	vvl ret(n,vector<ll>(n,0));
	for(i=0;i<n;i++) ret[i][i] = 1;
	while(x){
        if(x&1) ret = mul(ret,a);
		a = mul(a,a); x /= 2;
	}
	return ret;
}

int a[8010];
ll dp_val[8010][51],dp_cnt[8010][51];
ll dp1[51][51],dp2[51][51];
int main(){
    int i,j,k,K,n; cin >> n >> K;
    for(i=0;i<n;i++) cin >> a[i];
    for(j=0;j<=50;j++){
        for(i=0;i<n;i++){
            for(k=0;k<=50;k++) dp_val[i][k] = dp_cnt[i][k] = 0;
        }
        for(i=0;i<n;i++){
            if(a[i]>=j){
                dp_val[i][a[i]]++; dp_cnt[i][a[i]]++;
            }
            if(i){
                for(k=1;k<=a[i];k++) (dp_val[i][a[i]] += dp_val[i - 1][k] + dp_cnt[i - 1][k]) %= mod;
                for(k=1;k<=a[i];k++) (dp_cnt[i][a[i]] += dp_cnt[i - 1][k]) %= mod;
                for(k=1;k<=50;k++){
                    (dp_val[i][k] += dp_val[i - 1][k]) %= mod; (dp_cnt[i][k] += dp_cnt[i - 1][k]) %= mod;
                }
            }
        }
        for(k=1;k<=50;k++) dp1[j][k] = dp_val[n - 1][k], dp2[j][k] = dp_cnt[n - 1][k];
    }
    for(j=0;j<=50;j++) (dp2[j][j] += 1) %= mod;
    vvl mat(102,vector<ll>(102));
    for(k=0;k<102;k++){
        for(j=0;j<102;j++){
            if(k<=50 && j<=50) mat[k][j] = dp2[j][k];
            if(k<=50 && j>50) mat[k][j] = dp1[j - 51][k];
            if(k>50 && j>50) mat[k][j] = dp2[j - 51][k - 51];
        }
    }
    mat = mat_pw(mat,K);
    vector<ll> dp(102);
    dp[51] = 1;
    dp = mul2(mat,dp);
    ll ans = 0;
    for(i=0;i<=50;i++) (ans += dp[i]) %= mod;
    cout << ans << endl;
    /*cout << "val\n";
    for(j=0;j<=50;j++){
        for(k=0;k<=50;k++){
            if(dp1[j][k]) cout << "(" << j << "," << k << "," <<dp1[j][k] << ")" << " "; 
        }
    }
    cout << endl;
    cout << "cnt\n";
    for(j=0;j<=50;j++){
        for(k=0;k<=50;k++){
            if(dp2[j][k] && j!=k) cout << "(" << j << "," << k << ","  << dp2[j][k] << ") ";
            if(dp2[j][k]>1 && j==k) cout << "(" << j << "," << k << "," << dp2[j][k] - 1 << ") "; 
        }
    }
    cout << endl;*/
}
accuracy: 1
time_ms: 1150
memory_kb: 10032
final_rank: 16

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

template <int mod>
class Modint {
    using mint = Modint;
    static_assert(mod > 0, "Modulus must be positive");

public:
    static constexpr int get_mod() noexcept { return mod; }

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

    constexpr int value() const noexcept { return x; }

    constexpr mint& operator+=(const mint& r) noexcept { if ((x += r.x) >= mod) x -= mod; return *this; }
    constexpr mint& operator-=(const mint& r) noexcept { if ((x += mod - r.x) >= mod) x -= mod; return *this; }
    constexpr mint& operator*=(const mint& r) noexcept { x = static_cast<int>(1LL * x * r.x % mod); return *this; }
    constexpr mint& operator/=(const mint& r) noexcept { *this *= r.inv(); return *this; }

    constexpr mint operator-() const noexcept { return mint(-x); }

    constexpr mint operator+(const mint& r) const noexcept { return mint(*this) += r; }
    constexpr mint operator-(const mint& r) const noexcept { return mint(*this) -= r; }
    constexpr mint operator*(const mint& r) const noexcept { return mint(*this) *= r; }
    constexpr mint operator/(const mint& r) const noexcept { return mint(*this) /= r; }

    constexpr bool operator==(const mint& r) const noexcept { return x == r.x; }
    constexpr bool operator!=(const mint& r) const noexcept { return x != r.x; }

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

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

    friend std::ostream& operator<<(std::ostream& os, const mint& r) {
        return os << r.x;
    }

    friend std::istream& operator>>(std::istream& is, mint& r) {
        long long t;
        is >> t;
        r = mint(t);
        return is;
    }

private:
    int x;
};

using mint = Modint<(int) 1e9 + 7>;

template <typename M>
class FenwickTree {
    using T = typename M::T;

public:
    FenwickTree() = default;
    explicit FenwickTree(int n) : n(n), data(n + 1, M::id) {}

    T prefix_fold(int i) const {
        T ret = M::id;
        for (; i > 0; i -= i & -i) ret = M::op(ret, data[i]);
        return ret;
    }

    void update(int i, const T& x) {
        for (++i; i <= n; i += i & -i) data[i] = M::op(data[i], x);
    }

    int lower_bound(const T& x) const {
        return lower_bound(x, std::less<>());
    }

    template <typename Compare>
    int lower_bound(const T& x, Compare cmp) const {
        int k = 1;
        while (k * 2 <= n) k <<= 1;
        int i = 0;
        T v = M::id;
        for (; k > 0; k >>= 1) {
            if (i + k <= n) continue;
            T nv = M::op(v, data[i + k]);
            if (cmp(nv, x)) {
                v = nv;
                i += k;
            }
        }
        return i + 1;
    }

private:
    int n;
    std::vector<T> data;
};

struct S {
    mint s, c;
    constexpr S(mint s = 0, mint c = 0) : s(s), c(c) {}
    S operator+(const S& b) { return {s + b.s, c + b.c}; }
    S operator*(const S& b) { return {s * b.c + b.s * c, c * b.c}; }
};

struct Monoid {
    using T = S;
    static constexpr T id = {0, 0};
    static T op(T a, T b) { return a + b; }
};

vector<vector<S>> calc(vector<vector<S>>& A, vector<vector<S>>& B) {
    int n = A.size();
    vector<vector<S>> ret(n, vector<S>(n));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            ret[i][j] = A[i][j] + B[i][j];
            for (int k = 0; k < n; ++k) {
                if (i <= k && k <= j) {
                    ret[i][j] = ret[i][j] + A[i][k] * B[k][j];
                }
            }
        }
    }
    return ret;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    const int M = 50;
    int N;
    ll K;
    cin >> N >> K;
    vector<int> A(N);
    for (auto& x : A) cin >> x, --x;
    vector<vector<S>> mat(M, vector<S>(M));
    for (int a = 0; a < M; ++a) {
        FenwickTree<Monoid> ft(M);
        for (int i = 0; i < N; ++i) {
            if (A[i] >= a) {
                S s = ft.prefix_fold(A[i]+1);
                S t = s * S(1, 1) + S(1, 1);
                mat[a][A[i]] = mat[a][A[i]] + t;
                ft.update(A[i], t);
            }
        }
    }
    vector<vector<S>> ans(M, vector<S>(M));
    while (K) {
        if (K & 1) ans = calc(ans, mat);
        mat = calc(mat, mat);
        K >>= 1;
    }

    S a;
    for (int i = 0; i < M; ++i) {
        a = a + ans[0][i];
    }
    cout << a.s << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3472
final_rank: 1

code_snippet: #define LOCAL
#include <bits/stdc++.h>
using namespace std;
#pragma region Macros
typedef long long ll;
typedef __int128_t i128;
typedef unsigned int uint;
typedef unsigned long long ull;
#define ALL(x) (x).begin(), (x).end()

template <typename T> istream& operator>>(istream& is, vector<T>& v) {
    for (T& x : v) is >> x;
    return is;
}
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    for (size_t i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "" : " ");
    }
    return os;
}
template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <typename T, typename U> ostream& operator<<(ostream& os, const map<T, U>& m) {
    os << '{';
    for (auto itr = m.begin(); itr != m.end();) {
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr != m.end()) os << ',';
    }
    os << '}';
    return os;
}
template <typename T, typename U> ostream& operator<<(ostream& os, const unordered_map<T, U>& m) {
    os << '{';
    for (auto itr = m.begin(); itr != m.end();) {
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr != m.end()) os << ',';
    }
    os << '}';
    return os;
}
template <typename T> ostream& operator<<(ostream& os, const set<T>& s) {
    os << '{';
    for (auto itr = s.begin(); itr != s.end();) {
        os << *itr;
        if (++itr != s.end()) os << ',';
    }
    os << '}';
    return os;
}
template <typename T> ostream& operator<<(ostream& os, const multiset<T>& s) {
    os << '{';
    for (auto itr = s.begin(); itr != s.end();) {
        os << *itr;
        if (++itr != s.end()) os << ',';
    }
    os << '}';
    return os;
}
template <typename T> ostream& operator<<(ostream& os, const unordered_set<T>& s) {
    os << '{';
    for (auto itr = s.begin(); itr != s.end();) {
        os << *itr;
        if (++itr != s.end()) os << ',';
    }
    os << '}';
    return os;
}
template <typename T> ostream& operator<<(ostream& os, const deque<T>& v) {
    for (size_t i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "" : " ");
    }
    return os;
}
template <typename T, size_t N> ostream& operator<<(ostream& os, const array<T, N>& v) {
    for (size_t i = 0; i < N; i++) {
        os << v[i] << (i + 1 == N ? "" : " ");
    }
    return os;
}

template <int i, typename T> void print_tuple(ostream&, const T&) {}
template <int i, typename T, typename H, class... Args> void print_tuple(ostream& os, const T& t) {
    if (i) os << ',';
    os << get<i>(t);
    print_tuple<i + 1, T, Args...>(os, t);
}
template <typename... Args> ostream& operator<<(ostream& os, const tuple<Args...>& t) {
    os << '{';
    print_tuple<0, tuple<Args...>, Args...>(os, t);
    return os << '}';
}

void debug_out() { cerr << '\n'; }
template <class Head, class... Tail> void debug_out(Head&& head, Tail&&... tail) {
    cerr << head;
    if (sizeof...(Tail) > 0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...)                                                                   \
    cerr << " ";                                                                     \
    cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n'; \
    cerr << " ";                                                                     \
    debug_out(__VA_ARGS__)
#else
#define debug(...) void(0)
#endif

template <typename T> T gcd(T x, T y) { return y != 0 ? gcd(y, x % y) : x; }
template <typename T> T lcm(T x, T y) { return x / gcd(x, y) * y; }

int topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }
int topbit(long long t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }
int botbit(signed a) { return a == 0 ? 32 : __builtin_ctz(a); }
int botbit(long long a) { return a == 0 ? 64 : __builtin_ctzll(a); }
int popcount(signed t) { return __builtin_popcount(t); }
int popcount(long long t) { return __builtin_popcountll(t); }
bool ispow2(int i) { return i && (i & -i) == i; }
long long MSK(int n) { return (1LL << n) - 1; }

template <class T> T ceil(T x, T y) {
    assert(y >= 1);
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <class T> T floor(T x, T y) {
    assert(y >= 1);
    return (x > 0 ? x / y : (x - y + 1) / y);
}

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

template <typename T> void mkuni(vector<T>& v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
}
template <typename T> int lwb(const vector<T>& v, const T& x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); }
#pragma endregion

#include <iostream>

#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


namespace atcoder {

template <int MOD> std::istream& operator>>(std::istream& is, static_modint<MOD>& x) {
    int64_t v;
    x = static_modint<MOD>{(is >> v, v)};
    return is;
}

template <int MOD> std::ostream& operator<<(std::ostream& os, const static_modint<MOD>& x) { return os << x.val(); }

template <int ID> std::ostream& operator<<(std::ostream& os, const dynamic_modint<ID>& x) { return os << x.val(); }

}  // namespace atcoder

#include <cassert>
#include <iostream>
#include <vector>

template <typename T> struct Matrix {
    std::vector<std::vector<T>> A;

    Matrix(size_t n, size_t m) : A(n, std::vector<T>(m, 0)) {}

    Matrix(size_t n) : A(n, std::vector<T>(n, 0)) {}

    size_t size() const { return A.size(); }

    size_t height() const { return A.size(); }

    size_t width() const { return A[0].size(); }

    inline const std::vector<T>& operator[](int k) const { return A[k]; }

    inline std::vector<T>& operator[](int k) { return A[k]; }

    static Matrix I(size_t n) {
        Matrix res(n);
        for (size_t i = 0; i < n; i++) res[i][i] = 1;
        return res;
    }

    Matrix& operator+=(const Matrix& B) {
        size_t n = height(), m = width();
        assert(n == B.height() && m == B.width());
        for (size_t i = 0; i < n; i++) {
            for (size_t j = 0; j < m; j++) {
                (*this)[i][j] += B[i][j];
            }
        }
        return *this;
    }

    Matrix& operator-=(const Matrix& B) {
        size_t n = height(), m = width();
        assert(n == B.height() && m == B.width());
        for (size_t i = 0; i < n; i++) {
            for (size_t j = 0; j < m; j++) {
                (*this)[i][j] -= B[i][j];
            }
        }
        return *this;
    }

    Matrix& operator*=(const Matrix& B) {
        size_t n = height(), m = B.width(), p = width();
        assert(p == B.height());
        std::vector<std::vector<T>> C(n, std::vector<T>(m, 0));
        for (size_t i = 0; i < n; i++) {
            for (size_t k = 0; k < p; k++) {
                for (size_t j = 0; j < m; j++) {
                    C[i][j] += (*this)[i][k] * B[k][j];
                }
            }
        }
        A.swap(C);
        return *this;
    }

    Matrix& operator*=(const T& v) {
        for (size_t i = 0; i < height(); i++) {
            for (size_t j = 0; j < width(); j++) {
                (*this)[i][j] *= v;
            }
        }
        return *this;
    }

    Matrix& operator/=(const T& v) {
        T inv = T(1) / v;
        for (size_t i = 0; i < height(); i++) {
            for (size_t j = 0; j < width(); j++) {
                (*this)[i][j] *= inv;
            }
        }
        return *this;
    }

    Matrix& operator^=(long long k) {
        assert(0 <= k);
        Matrix B = Matrix::I(size());
        while (k > 0) {
            if (k & 1) B *= *this;
            *this *= *this;
            k >>= 1;
        }
        A.swap(B.A);
        return *this;
    }

    Matrix operator-() const {
        Matrix res(height(), width());
        for (size_t i = 0; i < height(); i++) {
            for (size_t j = 0; j < width(); j++) {
                res[i][j] = -(*this)[i][j];
            }
        }
        return res;
    }

    Matrix operator+(const Matrix& B) const { return Matrix(*this) += B; }

    Matrix operator-(const Matrix& B) const { return Matrix(*this) -= B; }

    Matrix operator*(const Matrix& B) const { return Matrix(*this) *= B; }

    Matrix operator*(const T& v) const { return Matrix(*this) *= v; }

    Matrix operator/(const T& v) const { return Matrix(*this) /= v; }

    Matrix operator^(const long long k) const { return Matrix(*this) ^= k; }

    bool operator==(const Matrix& B) const {
        assert(height() == B.height() && width() == B.width());
        return A == B.A;
    }

    bool operator!=(const Matrix& B) const {
        assert(height() == B.height() && width() == B.width());
        return A != B.A;
    }

    Matrix transpose() const {
        Matrix res(width(), height());
        for (size_t i = 0; i < height(); i++) {
            for (size_t j = 0; j < width(); j++) {
                res[j][i] = (*this)[i][j];
            }
        }
        return res;
    }

    T determinant() const {
        assert(height() == width());
        Matrix B(*this);
        T res = 1;
        for (size_t i = 0; i < height(); i++) {
            int pivot = -1;
            for (size_t j = i; j < height(); j++) {
                if (B[j][i] != 0) {
                    pivot = j;
                    break;
                }
            }
            if (pivot == -1) return 0;
            if (pivot != (int)i) {
                res *= -1;
                std::swap(B[i], B[pivot]);
            }
            res *= B[i][i];
            T inv = T(1) / B[i][i];
            for (size_t j = 0; j < width(); j++) B[i][j] *= inv;
            for (size_t j = i + 1; j < height(); j++) {
                T a = B[j][i];
                for (size_t k = 0; k < width(); k++) {
                    B[j][k] -= B[i][k] * a;
                }
            }
        }
        return res;
    }

    friend std::ostream& operator<<(std::ostream& os, const Matrix& p) {
        size_t n = p.height(), m = p.width();
        os << "[(" << n << " * " << m << " Matrix)";
        os << "\n[columun sums: ";
        for (size_t j = 0; j < m; j++) {
            T sum = 0;
            for (size_t i = 0; i < n; i++) sum += p[i][j];
            ;
            os << sum << (j + 1 < m ? "," : "");
        }
        os << "]";
        for (size_t i = 0; i < n; i++) {
            os << "\n[";
            for (size_t j = 0; j < m; j++) os << p[i][j] << (j + 1 < m ? "," : "");
            os << "]";
        }
        os << "]\n";
        return os;
    }
};

const int INF = 1e9;
const long long IINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const char dir[4] = {'D', 'R', 'U', 'L'};
const long long MOD = 1000000007;
// const long long MOD = 998244353;

using mint = atcoder::modint1000000007;
const int MAX_A = 55;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    Matrix<mint> M(MAX_A * 2);
    for (int i = 0; i < MAX_A * 2; i++) M[i][i] = 1;

    for (; N--;) {
        int A;
        cin >> A;
        Matrix<mint> M2(MAX_A * 2);
        for (int i = 0; i < MAX_A * 2; i++) {
            for (int j = 0; j < MAX_A * 2; j++) {
                M2[i][j] = M[i][j];
            }
        }
        for (int i = 0; i <= A; i++) {
            for (int j = 0; j < MAX_A * 2; j++) M2[j][A] += M[j][i];
            for (int j = 0; j < MAX_A * 2; j++) M2[j][A + MAX_A] += M[j][i];
            for (int j = 0; j < MAX_A * 2; j++) M2[j][A + MAX_A] += M[j][i + MAX_A];
        }
        swap(M, M2);
    }

    M ^= K;
    mint ans = 0;
    for (int i = 0; i < MAX_A; i++) ans += M[0][i + MAX_A];
    cout << ans << '\n';
    return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 3620
final_rank: 5