from itertools import permutations n=int(input()) a=list(range(1,n+1)) b=list(permutations(a)) c=tuple(map(int,list(input()))) print(b.index(c)+1)
前九个AC显示13ms,不到4MB,最后一个RE了……