fact_dict = [1, 1]
for i in range(2, 21):
fact_dict.append(fact_dict[-1]*i)
def find_tuples(d):
start = [[]]
for i in range(10):
next_s = []
if d[i]==0:
for x in start:
x2 = [y for y in x]
next_s.append(x2+[0])
else:
for x in start:
for j in range(1, d[i]+1):
x2 = [y for y in x]
next_s.append(x2+[j])
start = next_s
return start
def counter1(d):
S1 = fact_dict[sum(d)]
for i in range(10):
S1 = S1//fact_dict[d[i]]
return S1
def counter(d):
S1 = counter1(d)
if d[0] > 0:
d2 = [x for x in d]
d2[0]-=1
S1-=counter1(d2)
return S1
def process(n):
d = [0 for i in range(10)]
for x in str(n):
d[int(x)]+=1
answer = 0
for d1 in find_tuples(d):
answer+=counter(d1)
print(answer)
return
n = int(input())
process(n)
706B - Interesting drink | 1265A - Beautiful String |
214A - System of Equations | 287A - IQ Test |
1108A - Two distinct points | 1064A - Make a triangle |
1245C - Constanze's Machine | 1005A - Tanya and Stairways |
1663F - In Every Generation | 1108B - Divisors of Two Integers |
1175A - From Hero to Zero | 1141A - Game 23 |
1401B - Ternary Sequence | 598A - Tricky Sum |
519A - A and B and Chess | 725B - Food on the Plane |
154B - Colliders | 127B - Canvas Frames |
107B - Basketball Team | 245A - System Administrator |
698A - Vacations | 1216B - Shooting |
368B - Sereja and Suffixes | 1665C - Tree Infection |
1665D - GCD Guess | 29A - Spit Problem |
1097B - Petr and a Combination Lock | 92A - Chips |
1665B - Array Cloning Technique | 1665A - GCD vs LCM |