#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

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

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}


int ng[500];
int dp[500];

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n,m;
    cin >> n >> m;
    vector<ll> a(n);
    vector<ll> s(n + 1);
    map<ll, ll> mp;
    rep(i, n) {
        cin >> a[i];
        s[i + 1] = s[i] + a[i];
    }
    rep(i, n + 1) mp[s[i] % m]++;
    ll ans = 0;
    for(auto num : mp){
        ans += num.sc * (num.sc - 1) / 2;
    }
    print(ans);


    

}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int f(int x,int y){
	if(y<10)return x*10+y;
	return x*100+y;
}

int main(){
while(1){
	int n,k,c[100],ans=1;
	vector<int> sum;
	scanf("%d%d",&n,&k);
	if(n==0&&k==0)break;
	for(int i=0;i<n;i++)scanf("%d",&c[i]);
	int a=0;
	for(int i=0;i<n;i++){
		int a0=c[i];
		for(int j=0;j<n;j++){
			if(j!=i){
				int a1=f(a0,c[j]);
				if(k==2)sum.push_back(a1);
				else {
					for(int l=0;l<n;l++){
						if(l!=j&&l!=i){
							int a2=f(a1,c[l]);
							if(k==3)sum.push_back(a2);
							else{
								for(int m=0;m<n;m++){
									if(m!=l&&m!=j&&m!=i){
										int a3=f(a2,c[m]);
										sum.push_back(a3);
									}
								}
							}
						}
					}
				}
			}
		}
	}
	sort(sum.begin(),sum.end());
	int s=sum.size();
	for(int i=1;i<s;i++){
		if(sum[i]!=sum[i-1])ans++;
	}
	printf("%d\n",ans);
}
}