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))
	}
}

Python: from itertools import permutations as P
for e in iter(input,'0'):
 n,k=int(e),int(input())
 C=[input()for _ in[0]*n]
 print(len(set(''.join(s)for s in P(C,k))))

Python: while True:
    n=int(input())
    k=int(input())
    if n==0:
        break
    c=[input() for _ in [0]*n]
    
    s=set()
    
    from itertools import permutations
    
    cnt=0
    for i in permutations(range(n),k):
        s.add(int("".join([c[j] for j in i])))
    print(len(s))

Python: def s():
 from itertools import permutations as P
 for e in iter(input,'0'):
  n,k=int(e),int(input())
  C=[input()for _ in[0]*n]
  print(len(set(''.join(s)for s in P(C,k))))
if'__main__'==__name__:s()

Python: from itertools import permutations as P
import sys
r=sys.stdin.readline
for e in iter(r,'0\n'):
 n,k=int(e),int(r())
 C=[r()for _ in[0]*n]
 print(len(set(''.join(s)for s in P(C,k))))

Python: import sys
from itertools import permutations

def main():
	while True:
		n = input()
		k = input()
		if n == k == 0:
			return 0
		nums = [raw_input().strip() for i in xrange(n)]
		result = set(["".join(p) for p in permutations(nums, k)])
		print (len(result))

if __name__ == '__main__':
	sys.exit(main())

Python: def s():
 from itertools import permutations as P
 for e in iter(input,'0'):
  n,k=int(e),int(input())
  C=[input()for _ in[0]*n]
  print(len(set(''.join(s)for s in P(C,k))))
if'__main__'==__name__:s()

Python: from itertools import permutations as P
for e in iter(input,'0'):
 n,k=int(e),int(input())
 C=[input()for _ in[0]*n]
 print(len(set(''.join(s)for s in P(C,k))))

Python: import sys
from itertools import permutations

def main():
	while True:
		n, k = map(int, raw_input().split())
		if n == k == 0:
			sys.exit(0)
		nums = [raw_input().strip() for i in xrange(n)]
		result = set(["".join(p) for p in permutations(nums, k)])
		print (len(result))

if __name__ == '__main__':
	sys.exit(main())

Python: import itertools

while 1:
    n = int(input())
    k = int(input())
    if n == k == 0:
        break
    a = []
    for i in range(n):
        a.append(input())
    
    b = []
    p = list(itertools.permutations(a, k))
    for i in p:
        b.append(''.join(i))
    c = list(set(b))
    print(len(c))

Python: import itertools

while(1):
 n = int(input())
 k = int(input())
 if((n == 0)and(k == 0)): break

 num = []
 for i in range(n): num.append(input())
 #print('num :::',num)
 
 A = []
 for i in range(n): A.append(i)
 #print('A :::',A)

 num_list = []
 Comb = list(itertools.permutations(A,k))
 #print('Comb :::',len(Comb))
 
 for i in range(len(Comb)):
  tmp = list(Comb[i])
  tmp_num = ''
  for j in range(len(tmp)):
   tmp_num += num[tmp[j]]
  tmp_num = int(tmp_num)
  num_list.append(tmp_num)

 ans = len(list(set(num_list))) 
 print(ans)
 #print('aaaa')

Python: from itertools import permutations
while True:
    n, k = int(input()), int(input())
    if not n:
        break
    a = [input() for _ in [0]*n]
    s = set(int("".join(a)) for a in permutations(a, k))
    print(len(s))

Python: from itertools import permutations as P
import sys
r=sys.stdin.readline
for e in iter(r,'0\n'):
 n,k=int(e),int(r())
 C=[r()[:-1]for _ in[0]*n]
 print(len(set(''.join(s)for s in P(C,k))))

Python: import itertools

while 1:
    n = int(input())
    k = int(input())
    if n == 0:
        break

    card = []
    for _ in range(n):
        num = int(input())
        card.append(num)

    ans = []
    for permu in itertools.permutations(card, k):
        num = ''.join(str(p) for p in permu)
        ans.append(num)

    ans = list(set(ans))
    print(len(ans))

Python: from itertools import permutations

def solve(n,k):
    c=[]
    s=set()
    for _ in range(n):
        c+=[int(input())]

    for e in permutations(c,k):
        tmp=''
        for f in e:
            tmp+=str(f)
        s.add(tmp)
    print(len(s))


for i in range(5):
    n=int(input())
    k=int(input())
    if n==k==0:exit()
    solve(n,k)

Python: from itertools import permutations

while 1:
    N = int(input())
    S = int(input())
    if N == 0:
        break
    l = [int(input()) for _ in range(N)]
    dic = {}
    for i in permutations(l,S):
        i = map(str,i)
        dic[("".join(i))] = 1
    print(len(dic))

Python: import itertools

while(True):
  n = int(input())
  k = int(input())
  if (n,k) == (0,0):
    break
  num_lis = []
  for _ in range(n):
    num_lis.append(input())
  word_list = []
  
  for item in list(itertools.permutations(num_lis,k)):
    word_list.append("".join(item))
  
  print(len(set(word_list)))

Python: # -*- coding: utf-8 -*-
"""
Lining up the cards
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0546

"""
import sys


from itertools import permutations

def solve(cards, k):
    return len(set([''.join(c) for c in permutations(cards, k)]))


def main(args):
    while True:
        n = int(input())
        k = int(input())
        if n == 0 and k == 0:
            break
        cards = [input()  for _ in range(n)]
        ans = solve(cards, k)
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Python: from itertools import permutations as P
for e in iter(input,'0'):
 n,k=int(e),int(input())
 C=[input()for _ in[0]*n]
 print(len(set(''.join(s)for s in P(C,k))))

Python: def solve():
    from itertools import permutations
    from sys import stdin
    f_i = stdin
    
    while True:
        n = int(f_i.readline())
        k = int(f_i.readline())
        if n == 0:
            break
        
        cards = []
        for i in range(n):
            cards.append(f_i.readline().rstrip())
        
        nums = set(''.join(t) for t in permutations(cards, k))
        
        print(len(nums))

solve()

Python: import sys
from itertools import permutations
 
def main():
	while True:
		line = raw_input()
		if line == "0 0": break
		n = int(line)
		k = input()
		nums = [raw_input().strip() for i in xrange(n)]
		result = set(["".join(p) for p in permutations(nums, k)])
		print (len(result))

if __name__ == '__main__':
	sys.exit(main())

Python: n = k = 0
cards = []
mini_ans = {}


def dfs(s: list) -> None:
    global n, k, cards, mini_ans
    if len(s) == k:
        string = ""
        for i in s:
            string += cards[i]
        mini_ans.add(string)
        return

    for i in range(n):
        if i not in s:
            dfs(s + [i])


def main() -> None:
    ans = []

    global n, k, cards, mini_ans
    while True:
        n, k = [int(input()) for _ in range(2)]
        if n + k == 0:
            break
        cards = [input() for _ in range(n)]
        mini_ans = set()

        dfs([])
        ans += [len(mini_ans)]
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()