Go: ///
// File:  0546.go
// Author: ymiyamoto
//
// Created on Tue Mar  6 23:19:41 2018
//
package main

import (
	"fmt"
)

var n, k int

func perm(arr []int) [][]int {
	if len(arr) == 1 {
		return [][]int{arr}
	}

	p := perm(arr[1:])
	var ret [][]int
	for _, val := range p {
		for i := 0; i <= len(val); i++ {
			tmp := make([]int, len(val))
			copy(tmp, val)
			tmp = append(tmp, 0)
			copy(tmp[i+1:], tmp[i:])
			tmp[i] = arr[0]
			ret = append(ret, tmp)
		}
	}

	return ret
}

func permutation(n, k int) [][]int {
	ret := [][]int{}

	for i := 0; i < 1<<uint(n); i++ {
		var selects []int
		for j := 0; j < n; j++ {
			if (i>>uint(j))&1 == 1 {
				selects = append(selects, j)
			}
		}
		if len(selects) == k {
			ret = append(ret, perm(selects)...)
		}
	}

	return ret
}

func main() {
	for {
		fmt.Scan(&n, &k)
		if n == 0 && k == 0 {
			break
		}

		cards := make([]string, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&cards[i])
		}

		ret := permutation(len(cards), k)
		nums := map[string]bool{}
		for _, val := range ret {
			var num string
			for i := 0; i < len(val); i++ {
				num += cards[val[i]]
			}
			nums[num] = true
		}

		fmt.Println(len(nums))
	}
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

struct Info{
	int number;
};

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

//base??¨comp??????????????????????????¢??°
bool strCmp(char* base, char* comp){
	int length1 = 0,length2 = 0;
	for(int i=0;base[i] != '\0'; i++)length1++;
	for(int i=0;comp[i] != '\0'; i++)length2++;
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void func(int n,int k){

	Info info[5041];
	int index = 0,cards[10],tmp;

	for(int i = 0; i < n; i++)scanf("%d",&cards[i]);

	//k????????????????????¶?????°
	if(k == 2){

		for(int i = 0; i < n; i++){
			for(int k = 0; k < n; k++){
				if(i != k){
					//???????????°??????????????????
					if(cards[k] >= 10){
						tmp = 100*cards[i] + cards[k];
					}else{
						tmp = 10*cards[i] + cards[k];
					}

					if(index == 0){
						info[0].number = tmp;
						index++;
					}else{ //??¢??????????????????????????°??¨?????????????????????
						bool Found = false;
						for(int p = 0; p < index; p++){
							if(info[p].number == tmp){
								Found = true;
								break;
							}
						}
						if(!Found){ //?????¨???????????´???????????????
							info[index].number = tmp;
							index++;
						}
					}
				}
			}
		}

		printf("%d\n",index);
	}else if(k == 3){
		for(int i = 0; i < n; i++){
			for(int k = 0; k < n; k++){
				for(int a = 0; a < n; a++){
					if(i != k && i != a && k != a){
						//???????????°??????????????????
						if(cards[a] >= 10){
							tmp = 100*cards[k] + cards[a];
						}else{
							tmp = 10*cards[k] + cards[a];
						}

						if(tmp <= 99){ //2???
							tmp += 100*cards[i];
						}else if(tmp <= 999){ //3???
							tmp += 1000*cards[i];
						}else{ //4???
							tmp += 10000*cards[i];
						}

						if(index == 0){
							info[0].number = tmp;
							index++;
						}else{ //??¢??????????????????????????°??¨?????????????????????
							bool Found = false;
							for(int p = 0; p < index; p++){
								if(info[p].number == tmp){
									Found = true;
									break;
								}
							}
							if(!Found){ //?????¨???????????´???????????????
								info[index].number = tmp;
								index++;
							}
						}
					}
				}
			}
		}
		printf("%d\n",index);
	}else{ //k == 4
		for(int i = 0; i < n; i++){
			for(int k = 0; k < n; k++){
				for(int a = 0; a < n; a++){
					for(int b = 0; b < n; b++){
						if(i != k && i != a && i != b && k != a && k != b && a != b){
							//???????????°??????????????????
							if(cards[b] >= 10){
								tmp = 100*cards[a] + cards[b];
							}else{
								tmp = 10*cards[a] + cards[b];
							}

							if(tmp <= 99){ //2???
								tmp += 100*cards[k];
							}else if(tmp <= 999){ //3???
								tmp += 1000*cards[k];
							}else{ //4???
								tmp += 10000*cards[k];
							}

							if(tmp <= 999){ //3???
								tmp += 1000*cards[i];
							}else if(tmp <= 9999){ //4???
								tmp += 10000*cards[i];
							}else if(tmp <= 99999){ //5???
								tmp += 100000*cards[i];
							}else{ //6???
								tmp += 1000000*cards[i];
							}
							if(index == 0){
								info[0].number = tmp;
								index++;
							}else{ //??¢??????????????????????????°??¨?????????????????????
								bool Found = false;
								for(int p = 0; p < index; p++){
									if(info[p].number == tmp){
										Found = true;
										break;
									}
								}
								if(!Found){ //?????¨???????????´???????????????
									info[index].number = tmp;
									index++;
								}
							}
						}
					}
				}
			}
		}
		printf("%d\n",index);
	}
}


int main(){

	int n,k;

	while(true){
		scanf("%d %d",&n,&k);

		if(n == 0 && k == 0)break;

		func(n,k);
	}

    return 0;
}

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

int n, k;
vector<string> v;
set<string> s;

void dfs(string str, int flag, int count) {
    if (count == k) {
        s.insert(str);
        return ;
    }
    for (int i = 0; i < n; i++) {
        if (flag & (1 << i)) continue;
        dfs(str + v[i], flag | (1 << i), count + 1);
    }
}

int main() {
    while (cin >> n >> k, n || k) {
        v.resize(0);
        for (int i = 0; i < n; i++) {
            string str;
            cin  >> str;
            v.push_back(str);
        }

        s.clear();
        dfs("", 0, 0);
        cout << s.size() << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;



void dfs(int i, int cnt, string *C){
}

int main(){
    int n, k;
    while(cin>>n>>k, n|k){
        vector<string> C(n);
        REP(j, n) cin >> C[j] ;
        set<string> strs;
        for(int mask=0; mask< (1 << n); mask++){
            int total_1=0;
            for(int i=0; i<n; i++)
                if(mask >> i & 1) total_1++;
            if(total_1 != k) continue;
            vector<string> cards;
            for(int i=0; i<n; i++)
                if(mask >> i & 1) cards.push_back(C[i]);
            sort(ALL(cards));
            do{
                string tmp;
                for( auto num : cards)
                    tmp+=num;
                if(strs.find(tmp)==strs.end())
                    strs.insert(tmp);
            }while(next_permutation(ALL(cards)));
        }
        cout << strs.size() << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

int main(void){
	while(1){
		int n, k;
		scanf("%d %d", &n, &k);
		if(n == 0 && k == 0) return 0;
		vector<string> data(n);
		set<string> num;
		rep(i, n) cin >> data[i];
		
		sort(data.begin(), data.end());

		do{
			string tmp;
			rep(i, k){
				tmp += data[i];
			}
			num.insert(tmp);
		}while(next_permutation(data.begin(), data.end()));
		printf("%lu\n", num.size());
	}
}