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

typedef long long ll;
typedef vector<ll>vl1;
typedef vector<vl1> vl2;

int main()
{ ll i, j, k, kn, m, n, p, t, r, x, y, z, a, b, c;
  ll val, pos, tmp, suma, maxa, mina, naso, num, nk;
  ll moda=1000000007;

  cin>>n>>kn;
  vl1 veka(n+1);
  vl2 mata(n+1, vl1(n+1));
  for(i=1;i<=n;i++)
    { cin>>val;
      veka[i]=val;
      mata[1][i]=val;
    }
   for(i=2;i<=n;i++)
    { nk=n-i+1;
      for(k=1;k<=nk;k++)
        { val=mata[i-1][k]+mata[1][k+i-1];
          if(val>=moda) val-=moda;
          mata[i][k]=val;
        }
    }

   /*cout<<endl;
   for(i=1;i<=n;i++)
    { nk=n-i+1;
      for(k=1;k<=nk;k++) cout<<mata[i][k]<<' ';
      cout<<endl;
    }*/

   for(j=1;j<=kn;j++)
     { for(i=2;i<=n;i++)
       { nk=n-i+1;
         for(k=1;k<=nk;k++)
          { val=i*mata[i][k]+mata[i-2][k+1];
            if(val>=moda) val%=moda;
            mata[i][k]=val;
          }
       }
     }

   //cout<<endl;
   cout<<mata[n][1]<<endl;


  return 0;
}
/*
5 0
1 6 3 4 7

5 1
1 6 3 4 7
*/