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 <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int clz(int x) { return 31 - __builtin_clz(x); }
int clz(ll x) { return 63 - __builtin_clzll(x); }
int ctz(int x) { return __builtin_ctz(x); }
int ctz(ll x) { return __builtin_ctzll(x); }

class compare {
public:
	bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) {
		return (get<1>(a) > get<1>(b));
	}
};

ll n,k;
vi v,c;
set<ll> s;

void rec(int l,int p){
	if(l==k){
		do{
			string str;
			rep(i,k){
				str+=to_string(c[v[i]]);
			}
			s.insert(stoll(str));
		}while(next_permutation(all(v)));
		sort(all(v));
	}
	else{
		range(i,p+1,n){
			v[l]=i;
			rec(l+1,i);
		}
	}
}

void solve(){
	c.resize(n);
	v.resize(k);
	rep(i,n){
		cin>>c[i];
	}
	rec(0,-1);
	cout<<s.size()<<endl;
	s.clear();
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	while(cin>>n>>k,n){
		solve();
	}
}

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>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int cards[10];
set<int> nums;
int n;

void f(int m,int k,int used){
	if(k==0){
		nums.insert(m);
		return;
	}
	int i;
	for(i=0;i<n;i++){
		if(used&1<<i)continue;
		f(m*(cards[i]<10?10:100)+cards[i],k-1,used|1<<i);
	}
}

int main() {
	int k;
	while(n=in(),k=in()){
		nums.clear();
		int i;
		for(i=0;i<n;i++){
			cards[i]=in();
		}
		f(0,k,0);
		cout<<nums.size()<<endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n, k;
  while (cin >> n >> k) {
    if (n == 0 && k == 0) break;
    vector<int> card;
    REP(i, n) {
      int c;
      cin >> c;
      card.push_back(c);
    }
    sort(ALL(card));
    map<int, int> mp;
    do {
      int num = 0;
      REP(i, k) {
        if (i == 0) {
          num += card[i];
        } else {
          int d = 0;
          int tmp = card[i];
          while (0 < tmp) {
            tmp /= 10;
            d++;
          }
          REP(j, d) num *= 10;
          num += card[i];
        }
      }
      mp[num]++;
    } while (next_permutation(ALL(card)));
    cout << mp.size() << endl;
  }
  return 0;
}

C++: #include<stdio.h>
#define INF 100000
int min(int a,int b){return a<b?a:b;}
int getk(int a){
	int res=0;
	while(a>0){
		res++;
		a/=10;
	}
	return res;
}
int pow(int a,int b){
	int l;
	int rt=1;
	for(l=0;l<b;l++)rt*=10;
	return rt;
}
int card[10];
bool pos[100000000];
int main(){
	int i,j;
	int n,k;
	while(1){
	scanf("%d",&n);
	scanf("%d",&k);
		if(n==0)return 0;
	for(i=0;i<n;i++)scanf("%d",&card[i]);
	for(i=0;i<30000000;i++)pos[i]=false;
	int max=1;
	int ket;
	int next;
	int ni;
	int num;
	int ans=0;
	bool used[10];
	for(i=0;i<k;i++)max*=n;
	for(i=0;i<max;i++){
cont:		
		for(j=0;j<n;j++)used[j]=false;
		ket=1;
		ni=i;
		num=0;
		for(j=0;j<k;j++){
			next=ni%n;
			ni/=n;
			if(used[next]){
				i++;
				if(i==max)goto end;
				goto cont;
			}
			else used[next]=true;
			num+=card[next]*ket;
			ket*=pow(10,getk(card[next]));
		}
		if(!pos[num]){
			ans++;
			pos[num]=true;
		}
	}
end:
	printf("%d\n",ans);
	}
}

C++: #include<iostream>
#include<math.h>
using namespace std ;

int n , k ;
int m[20] ;
int num[100000000] = {} ;

int calc( int y , int x ){
	int j ;
	for( j=1 ; pow(10,j) < y ; j++ ){}
	
	return y + x * pow(10,j) ;
}

int f( int p , int sum , int bit_sum ){
	if( p == k ){
		if( num[sum] == 0 ){
			num[sum] = 1 ;
			return 1 ;
		}
	}
	
	int ans=0 ;
	for( int i=0 ; i<n ; i++ ){
		int c = pow(2,i) ;
		if( c & bit_sum ){}
		else {
			ans += f( p+1 , calc(sum,m[i]) , c+bit_sum ) ;
		}
	}
	
	return ans ;
}

int main(){
	
	cin >> n >> k ;
	for( int i=0 ; i<n ; i++ ) cin >> m[i] ;
	
	int ans2 = 0 ;
	for( int i=0 ; i<n ; i++ ){
		ans2 += f(1,m[i],pow(2,i)) ;
	}
	
	cout << ans2 << endl ;
	
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(){
	ans.clear();
	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());
	main();
	return 0;
}