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<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<algorithm>
using namespace std;
int card[11],n,k,bit=1,ans=0;
string str;
vector<string> V;
vector<int> num;
string IntToString(int n){
	stringstream ss;
	ss<<n;
	return ss.str();
}

int main(){
	while(1){
		cin>>n;
		cin>>k;
		ans=0;
		if(n==0 && k==0)
		break;
		for(int i=0;i<n;i++)
		cin>>card[i];
		V.erase(V.begin(),V.end());
		for(int i=0;i<(1<<n);i++){
			str="";
			num.erase(num.begin(),num.end());
			int count=0;
			int flag=0;
			for(int j=0;j<n;j++){
				if(i&(1<<j)){
					num.push_back(card[j]);
					count++;
				}
			}
			if(count==k){
				sort(num.begin(),num.end());
				while(1){
					flag=0;
					for(int j=0;j<k;j++){
						str+=IntToString(num[j]);
					}
					for(int j=0;j<V.size();j++){
						if(V[j]==str)
						flag=1;
					}
					if(flag==0){
						V.push_back(str);
						ans++;
					}
					if(next_permutation(num.begin(),num.end())==0)
					break;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int n={},k={};
string integer[11]={};
vector<string>num={};
int chousen[10]={};
string complete_integer[1000]={};
string answer={};
int integer_count=1;
bool check[100000000]={};
int counter=0;

void operation(){
    for(int i=1;i<=n;i++){
        if (chousen[i]==0){
            
            chousen[i]=1;
            num.push_back(integer[i]);
        
            if(num.size()==k){
                for(int i=1;i<=k;i++){
                    answer+=num[i-1];
                }
                complete_integer[integer_count]=answer;
                integer_count+=1;
                answer={};
            }else{
                operation();
            }
            num.pop_back();
            chousen[i]=0;
        }
        
    }

}



void compare(){
    for(int i=1;i<=integer_count-1;i++){
        //cout << complete_integer[i] << endl;
        if(check[stoi(complete_integer[i])]){
        }else{
            check[stoi(complete_integer[i])]=1;
            counter+=1;
        }
    }
}



int main(){
    
    while(true){

    n={};
    k={};
    integer[11]={};
    vector<string>num={};
    chousen[11]={};
    complete_integer[1000]={};
    answer={};
    integer_count=1;
    check[100000000]={};
    counter=0;
        
    
        
    cin >> n >> k;
    if (n==0&&k==0){
        break;
    }
    for(int i=1;i<=n;i++){
        cin >> integer[i];
    }
        
    operation();
    compare();
    cout<< counter << endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
    while (1)
    {
        int n, k, c=0;
        string a[10], val[10000];
        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;
                    for (int k=0; k<c; k++) if (val[k]==a[i]+a[j]) no=false;
                    if (no) { val[c]=a[i]+a[j]; 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;
                        for (int l=0; l<c; l++) if (val[l]==a[i]+a[j]+a[k]) no=false;
                        if (no) { val[c]=a[i]+a[j]+a[k]; 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;
                            for (int m=0; m<c; m++) if (val[m]==a[i]+a[j]+a[k]+a[l]) no=false;
                            if (no) { val[c]=a[i]+a[j]+a[k]+a[l]; c++; }
                        }
                    }
                }
            }
        }
        cout<<c<<'\n';
    }
    return 0;
}

C++: #include <iostream>
#include <cmath>
#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
using namespace std;
typedef long long ll;

int main(){
    int n, k, C[100];
    int checked_num[1000000]={};
    while(1){
        cin >> n >> k;
        if(n==0 && k==0) break;
        for(int i=0; i<n; i++)
            cin >> C[i];
        sort(begin(C), begin(C)+n);

        // 全ての組み合わせを考える
        do{
            string num="";
            for(int i=0; i<k; i++)
                num+=to_string(C[i]);
            checked_num[stoi(num)]=1;
        }while(next_permutation(C, C+n));

        int ans=0;
        for(int i=0; i<1000000; i++)
            ans+=checked_num[i];
        cout << ans << endl;

        memset(C, 0, 100*sizeof(int));
        memset(checked_num, 0, 1000000*sizeof(int));
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

string card[15];

int main(void){
	int n,k;
	cin >> n >> k;
	for(int i=0;i<n;++i) cin >> card[i];
	set<int> ans;
	sort(card,card+n);
	do{
		string cur="";
		for(int i=0;i<k;++i) cur+=card[i];
		ans.insert(stoi(cur));
	}while(next_permutation(card,card+n));
	cout << ans.size() << endl;
	return 0;
}