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 <stdlib.h>

int n,k,card[10],count;
int check[10001];

// used[i]==1ÈçÎ iÍgÁÄ¢é
// used[i]==1ÈçÎ card[i]ÍgÁÄ¢é

void func(int a[],int now)
{
	int i,j,temp,keta=0,flg;
	
	if(now == k){
		char str[9];
		for(i=0;i<k;i++){
			temp=sprintf(str+keta,"%d",a[i]);
			keta+=temp;
		}
		temp=atoi(str);
		check[count]=temp;
		count++;
	}
	
	else {
		int used[10] = { 0 };
		
		for(i=0; i<now; i++){
			for(j=0;j<n;j++){
				if(a[i]==card[j] && used[j]==0){
					used[j]=1;
					break;
				}
			}
		}
		
		for(i=0;i<n;i++){
			if(used[i] == 0){
				a[now] = card[i];
				func(a,now+1);
			}
		}
	}
}

int main(void)
{
	int i,j,array[5];
	while(scanf("%d",&n),n){
		scanf("%d",&k);
		for(i=0;i<n;i++){
			scanf("%d", &card[i]);
		}
		
		func(array,0);
		for(i=0;i<count;i++){
			for(j=0;j<count;j++){
				if(check[i]==check[j] && i!=j && check[i]!=0){
					check[j]=0;
				}
			}
		}
		
		count=0;
		for(i=0;i<10000;i++){
			if(check[i]!=0){
				count++;
			}
		}
		printf("%d\n",count);
		
		for(i=0;i<10001;i++){
			check[i]=0;
		}
		count=0;
		for(i=0;i<10;i++){
			card[i]=0;
		}
		
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(int)(n);i++)
#define FORR(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define pb(a) push_back(a)
#define ZERO(a) memset(a,0,sizeof(a))
#define len(a) sizeof(a)
#define ll long long
#define INF 1<<29
#define MAX 11
using namespace std;

int a[MAX],s[MAX];

void solve(){
 int n,k;
 for(;;){
  cin>>n;
  cin>>k;
  if(!n) break;
  set<string> S;
  FOR(i,n) cin>>a[i];
  FOR(i,1<<n){
   if(__builtin_popcount(i)!=k) continue;
   int p=0;
   FOR(j,n) if((1<<j)&i) s[p++]=j;
   vector<int> ord(k);
   FOR(j,k) ord.pb(j);
   string s="";
   do{
    FOR(j,k) s+=to_string(s[ord[j]]);
    S.insert(s);
   }while(next_permutation(ord.begin(),ord.end()));
  }
  cout<<S.size()<<endl;
 }
}

int main(){
 solve();
 return 0;
}

C++: #include<stdio.h>
#include<algorithm>
#include<sstream>
#include<vector>
#include<set>
using namespace std;

int n, k;
char card[10];
set<int>ans;
void solve(int a, vector<char>vec, vector<bool>b) {
	vec.push_back(card[a]);
	b[a] = true;
	if (vec.size() == k) {
		ostringstream oss;
		for (char i : vec)
			oss << (int)i;
		ans.insert(stoi(oss.str()));
		return;
	}
	for (int i = 0; i < n; i++) {
		if (!b[i])
			solve(i, vec, b);
	}
}
int main(){
	int cnt = ans.size();
	scanf("%d%d", &n, &k);
	if (!(n | k))return 0;
	for (int i = 0; i < n; i++)
		scanf("%d", &card[i]);
	vector<char>vec;
	vector<bool>b(10);
	for (int i = 0; i < n; i++)
		solve(i, vec, b);
	printf("%d\n", ans.size() - cnt);
	main();
	return 0;
}

C++: #include<stdio.h>
#include<set>
using namespace std;
int n,k;
int card[10];
bool used[10];
bool kt[10];
set<int> s;
void dfs(int i,int x){
	if(i==k){
		s.insert(x);
		return;
	}
	int j;
	for(j=0;j<n;j++){
		if(!used[j]){
			used[j]=true;
			if(kt[j])dfs(i+1,x*100+card[j]);
			else dfs(i+1,x*10+card[j]);
			used[j]=false;
		}
	}
}
int main(){
	while(1){
	scanf("%d %d",&n,&k);
	if(n==0)return 0;
	int i;
	s.clear();
	for(i=0;i<n;i++){
		scanf("%d",&card[i]);
		used[i]=false;
		if(card[i]<10)kt[i]=false;
		else kt[i]=true;
	}
	dfs(0,0);
	printf("%d\n",s.size());
	}
}

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

int main() {
  int n, k;
  while (true) {
    cin >> n >> k;
    if (n == 0 && k == 0) return 0;
    vector<string> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());

    set<string> s;
    do {
      string ans;
      rep(i, k) ans += a[i];
      s.insert(ans);
    } while (next_permutation(a.begin(), a.end()));

    cout << s.size() << endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<queue>
#include<string>
#include<cstring>
#include<cstdlib>
#include<sstream>
using namespace std;
bool memo[100000000];
class P{
    public:
    int num;
    int cnt;
    bool used[10];
    P(){}
    P(int num,int cnt,bool a[10]):num(num),cnt(cnt){
        for(int i = 0; i < 10; i++){
            used[i] = a[i];
        }
    }
};
int bond(int x,int y){
    stringstream ss1;
    ss1 << x;
    stringstream ss2;
    ss2 << y;
    string ans = ss1.str() + ss2.str();
    stringstream Ans;
    Ans << ans;
    int res;
    Ans >> res;
    return res;
}
int main(){
    int n;
    int m;
    while(scanf("%d%d",&n,&m),(n|m)){
        int card[10];
        queue<P> Q;
        memset(memo,0,sizeof(memo));
        for(int i = 0; i < n; i++){
            bool x[10]={0};
            x[i] = 1;
            scanf("%d",&card[i]);
            Q.push(P(card[i],1,x));
        }
        int ans = 0;
        while( Q.size() ){
            P p = Q.front();Q.pop();
            if(p.cnt == m){
                if( memo[p.num] )continue;
                ans++;
                memo[p.num] = true;
            }
            else{
                for(int i = 0; i < n; i++){
                    if(p.used[i] == 0){
                        p.used[i] = 1;
                        Q.push(P(bond(p.num,card[i]),p.cnt+1,p.used));
                        p.used[i] = 0;
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define rep(i,n) for(int i=0;i<(n);++i)

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100000000;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main(){
  int n,k;
  while(1){
    cin >> n >> k;
    if(n+k==0)break;
    vector<int> numbers;
    vector<int> answers;
    rep(i,n){
      int x;
      cin >> x;
      numbers.push_back(x);
    }
    for(int bit=0;bit<(1<<n);bit++){
      vector<int> use;
      for(int i=0;i<n;i++){
        if(bit&(1<<i)){
          use.push_back(numbers[i]);
        }
      }
      if(use.size()!=k)continue;
      sort(use.begin(),use.end());
      do{
        string ans="";
        rep(i,use.size()){
          ans += to_string(use[i]);
        }
        //cout << ans << endl;
        if(ans!=""){
          answers.push_back(stoi(ans));
        }
      }while(next_permutation(use.begin(),use.end()));
    }
    sort(answers.begin(),answers.end());
    int a = answers[0];
    int res=1;
    rep(i,answers.size()){
      //cout << answers[i] << endl;
      if(a != answers[i]){
        a = answers[i];
        res++;
      }
    }
    cout << res << endl;
    //cout << "LOOPEND" << endl;
  }

      

  return 0;
}