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 <set>

std::set<int> ans;
int hand[12];
bool used[12] = { false, false, false, false, false, false, false, false, false, false, false, false };

void pattern(int now, int n, int k){
	// テァツオツづ、ツコツ?・ツ?ヲテァツ青?
	if (k <= 0){
		//printf("Pattern -> %d\n", now);

		//printf("use : ");
		//for (int i = 0; i < n; i++){
		//	if (used[i]){ printf("|%d|", hand[i]); }
		//}
		//printf("\n");

		ans.insert(now);
		return;
	}

	// ティツィツ暗ァツョツ?
	for (int i = 0; i < n; i++){
		if (used[i] == true){ continue; }

		int rank = (hand[i] >= 10) ? 100 : 10;
		now *= rank;
		now += hand[i];
		used[i] = true;
		pattern(now, n, k - 1);
		used[i] = false;
		now -= hand[i];
		now /= rank;
	}
}

int main(void){
	int n, k;

	while (true){
		scanf("%d%d", &n, &k);
		if (n == 0 && k == 0){ break; }

		// テ・ツ?・テ・ツ環?
		for (int i = 0; i < n; i++){ scanf("%d", &hand[i]); }
		
		// GO
		pattern(0, n, k);
		
		// テ・ツ?コテ・ツ環?
		printf("%d\n", ans.size());
		ans.clear();
	}


	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

set<int> ans;
int n, k;
vs32 a;
vector< bool > used;
vs32 choosed;
int pos = 0;

void dfs()
{
    if (pos == k)
    {
        int t = 0;
        rep (i, choosed.size())
        {
            int x = choosed[i];
            if (x >= 10)
            {
                t = t * 100 + x;
            }
            else
            {
                t = t * 10 + x;
            }
        }
        ans.insert(t);
        return;
    }

    rep (i, n)
    {
        if (!used[i])
        {
            used[i] = true;
            choosed[pos++] = a[i];
            dfs();
            used[i] = false;
            --pos;
        }
    }
}

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

    while (true)
    {
        cin >> n >> k;
        if (n == 0 && k == 0) break;
        a.resize(n);
        rep (i, n) cin >> a[i];
        used.resize(n, false);
        choosed.resize(k);
        ans.clear();

        dfs();

        cout << ans.size() << "\n";
    }
    return 0;
}

C++: #include <iostream>
#include <string>

using namespace std;

int main()
{
    while (1)
    {
        int n, k, c=0;
        string a[10], val[10000], t;
        bool no;
        cin>>n>>k;
        if (n==0 && k==0) break;
        for (int i=0; i<n; i++) cin>>a[i];
        if (k==2)
        {
            for (int i=0; i<n; i++)
            {
                for (int j=0; j<n; j++)
                {
                    if (i==j) continue;
                    no=true;
                    t=a[i]+a[j];
                    for (int k=0; k<c; k++) if (val[k]==t) { no=false; k=c; }
                    if (no) { val[c]=t; c++; }
                }
            }
        }
        if (k==3)
        {
            for (int i=0; i<n; i++)
            {
                for (int j=0; j<n; j++)
                {
                    for (int k=0; k<n; k++)
                    {
                        if (i==j || j==k || i==k) continue;
                        no=true;
                        t=a[i]+a[j]+a[k];
                        for (int l=0; l<c; l++) if (val[l]==t) { no=false; l=c; }
                        if (no) { val[c]=t; c++; }
                    }
                }
            }
        }
        if (k==4)
        {
            for (int i=0; i<n; i++)
            {
                for (int j=0; j<n; j++)
                {
                    for (int k=0; k<n; k++)
                    {
                        for (int l=0; l<n; l++)
                        {
                            if (i==j || j==k || k==l || i==k || i==l || j==l) continue;
                            no=true;
                            t=a[i]+a[j]+a[k]+a[l];
                            for (int m=0; m<c; m++) if (val[m]==t) { no=false; m=c; }
                            if (no) { val[c]=t; c++; }
                        }
                    }
                }
            }
        }
        cout<<c<<'\n';
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
using namespace std;
int main(){
    int n,k;
    map<string,bool> ret;
    while(cin >> n >> k){
        vector<int>data(n);
        for(int i=0;i<n;i++)
            cin >> data[i];
        sort(data.begin(),data.end());
        do{
            stringstream ss;
            for(int i=0;i<k;i++)
                ss << data[i];
            ret[ss.str()];
        }while(next_permutation(data.begin(), data.end()));
        cout << ret.size() << endl;
    }
}

C++: 
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define rep(i,n) for(int i = 0; i < n; i++)
#define MSG(a) cout << #a << " " << a << endl;
template<class T, class C> pair<T,C> mp(T a, C b){ return make_pair(a, b);}

int main()
{
	int n, k;
	while(cin >> n >> k && n)
	{
		vint card(n), pool;
		rep(i,n) cin >> card[i];
		sort(card.begin(), card.end());
		
		do
		{
			int x = 0;
			rep(i,k) x = x * (static_cast<int>(card[i] / 10) > 0 ? 100 : 10) + card[i];
			pool.push_back(x);
		}
		while(next_permutation(card.begin(), card.end()));
		sort(pool.begin(), pool.end());

		pool.erase(unique(pool.begin(), pool.end()), pool.end());

		cout << pool.size() << endl;
	}
}