#include<bits/stdc++.h>
#define fp(i,a,b) for(int i=a,i##_=(b)+1;i!=i##_;++i)
#define fd(i,a,b) for(int i=a,i##_=(b)-1;i!=i##_;--i)
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
namespace IO{
    //In
    char ss[1<<17],*_A=ss,*_B=ss;
    #define gc() (_A==_B&&(_B=(_A=ss)+fread(ss,1,1<<17,stdin),_A==_B)?-1:*_A++)
    template<class T>inline void In(T&x){
        char c;T y=1;while(c=gc(),!isdigit(c)&&c!=-1)if(c==45){y=-1;}x=c-48;
        while(c=gc(),isdigit(c)){x=x*10+c-48;}x*=y;
    }
    template<class T,class ..._T>inline void In(T &x,_T &...y){return In(x),In(y...);}
    template<class T>inline void In(T*a,int Len){fp(i,0,Len-1)In(*(a+i));}
    inline void In(char*a){char c=gc();for(;c<=32;c=gc());for(*a=c;c>32;*(++a)=c)c=gc();}
    //Out
    char sr[1<<21],_z[20],*_C=sr,*_D=sr+(1<<21)-1;int _Z;
    inline void flush(){fwrite(sr,1,_C-sr,stdout),_C=sr;}
    inline void Out(char c){*_C++=c;if(*_C==*_D)flush();}
    inline void Out(char*c){while(*c){*_C++=*c++;if(_C==_D)flush();}}
    template<class T>inline void Out(T x){
        if(x<0)Out(45),x=-x;
        while(_z[++_Z]=x%10+48,x/=10);
        while(Out(_z[_Z]),--_Z){};
    }
    template<class T,class ..._T>inline void Out(T x,_T ...y){return Out(x),Out(y...);}
    template<class T>inline void Out(T*a,int Len){fp(i,0,Len-1)Out(*(a+i)," \n"[i==Len-1]);}
    struct _Flush{~_Flush(){flush();}}flusher;
}
using namespace IO;
using namespace std;
const int N=4e6+5,P=1e9+7;
typedef int arr[N];
typedef long long ll;
/*-------------------------------------------------------------------------------------*/
int n,m;
arr a,inv;
inline int pow(int a,int b){
    int x=1;
    for(;b;b>>=1,a=(ll)a*a%P)if(b&1)x=(ll)x*a%P;
    return x;
}
inline void Solve(){
    In(a+1,n);
    ll A=accumulate(a+1,a+n+1,n),Ans=1;
    inv[1]=1,m-=A-n;
    fp(i,2,A)inv[i]=(ll)(P-P/i)*inv[P%i]%P;
    fp(i,1,A)Ans=Ans*(A+m+1-i)%P*inv[i]%P;
    printf("%lld\n",Ans);
}
int main(){
#ifndef ONLINE_JUDGE
    file("s");
#endif
    while(In(n,m),n!=-49)
        Solve();
    return 0;
}
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vvvvi vector<vvvi>
#define vl vector<ll>
#define vvl vector<vl>
#define vld vector<ld>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define rep(s, l, r) for (int s = l; s < r; s++)
#define per(s, r, l) for (int s = r - 1; s >= l; s--)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
using namespace std;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> void setmax(T& a, T b) { a = max(a, b); };
template<typename T> void setmin(T& a, T b) { a = min(a, b); };
template<typename T> bool in(T lo, T v, T hi) { return lo <= v && v <= hi; };

struct Fenwick {
	int n;
	vi f;
	Fenwick(int _n) {
		n = _n;
		f.assign(n, 0);
	}
	void add(int i, int delta) {
		for (int j = i; j < n; j |= (j + 1)) f[j] += delta;
	}
	int sum(int i) {
		int s = 0;
		for (int j = i; j >= 0; j = (j & (j + 1)) - 1) s += f[j];
		return s;
	}
};

struct Solution {
	ll n;
	vi a;
	void solve() {
		cin >> n;
		a.resize(n);
		rep(i, 0, n) cin >> a[i];
		a.resize(2 * n);
		rep(i, n, 2 * n) a[i] = a[i - n];

		Fenwick f(n);
		ll cnt = 0;

		for (int i = 0; i < n; i++) {
			cnt += f.sum(n - 1) - f.sum(a[i]);
			f.add(a[i], 1);
		}

		cout << cnt << endl;
		// get num inversions in a[0..n-1]
		rep(i, n, 2 * n - 1) {
			f.add(a[i - n], -1);
			cnt -= f.sum(a[i - n]);
			cnt += f.sum(n - 1) - f.sum(a[i]);
			f.add(a[i], 1);
			cout << cnt << endl;
		}
	}
};

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


	int t = 1;
	while (t--) {
		Solution s;
		s.solve();
	}

  return 0;
}
