Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there. 

The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.

And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:

  if s_{i} = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);  if s_{i} is a digit (between 0 to 9, inclusively), then it means that there is digit s_{i} on position i in code;  if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.  The length of the safe code coincides with the length of the hint. 

For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".

After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.

At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...


-----Input-----

The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.

The input limits for scoring 30 points are (subproblem A1):   1 ≤ |s| ≤ 5. 

The input limits for scoring 100 points are (subproblems A1+A2):   1 ≤ |s| ≤ 10^5. 

Here |s| means the length of string s.


-----Output-----

Print the number of codes that match the given hint.


-----Examples-----
Input
AJ

Output
81

Input
1?AA

Output
100

Difficulty: interview

Starter code:

Solutions:
res = 1
started = False
seen = set()
codes = set(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'])
for ch in input():
	if ch == '?':
		if started:
			res *= 10
		else:
			res *= 9
	elif (ch in codes) and (ch not in seen):
		if not started:
			res *= len(codes) - len(seen) - 1
		else:
			res *= len(codes) - len(seen)
		seen.add(ch)
	started = True
print(res)



s = input()
ans = 1

used = list('ABCDEFGHIJ')

if s[0] == '?':
    ans *= 9
elif s[0] in used:
    ans *= 9
    used.remove(s[0])

for sym in s[1:]:
    if sym == '?':
        ans *= 10
    elif sym in used:
        ans *= len(used)
        used.remove(sym)

print(ans)


#!/usr/bin/env python3

s = input()
x = set()
f = False
r = 1
letter = set([c for c in 'ABCDEFGHIJ'])
if s[0] == '?':
    r *= 9
if s[0] in letter:
    x.add(s[0])
    f = True
for c in s[1:]:
    if c == '?':
        r *= 10
    if c in letter:
        x.add(c)
for t in range(len(x)):
    if t == 0 and f:
        r *= 9
    else:
        r *= 10 - t;

print(r)



from sys import *
from math import *

s = stdin.readline().strip()
ans = 1
now = 10
was = {}
was['A'] = False
was['B'] = False
was['C'] = False
was['D'] = False
was['E'] = False
was['F'] = False
was['G'] = False
was['H'] = False
was['I'] = False
was['J'] = False

if s[0] == '?':
  ans *= 9
if (ord(s[0]) >= ord('A')) and (ord(s[0]) <= ord('J')):
  ans *= 9
  was[s[0]] = True
  now = 9
for i in range(1, len(s)):
  if (ord(s[i]) >= ord('A')) and (ord(s[i]) <= ord('J')):
    if was[s[i]] == False:
      ans *= now
      now -= 1
    was[s[i]] = True 
  elif s[i] == '?':
    ans *= 10
print(ans) 


import math
import string

s = input()
pr = 0
for x in string.ascii_uppercase[:10]:
    if x in s:
        pr += 1
ans = 0
r = s.count('?')
if s[0] == '?':
    ans = 9 * pow(10, r - 1) * math.factorial(10) // math.factorial(10 - pr)
elif s[0] in string.ascii_uppercase:
    ans = 9 * pow(10, r) * math.factorial(9) // math.factorial(9 - pr + 1)
else:
    ans = pow(10, r) * math.factorial(10) // math.factorial(10 - pr)
print(ans)


s = input()
ans = 1
used = [False] * 10
fl = False
for i in range(len(s)):
	c = s[i]
	if c == '?':
		ans *= 10 if i else 9
		continue
	x = ord(c)
	if ord('0') <= x <= ord('9'):
		continue
	used[x - ord('A')] = True
	if i == 0:
		fl = True
cur = 10
for b in used:
	if b:
		ans *= cur
		cur -= 1
if fl:
	ans //= 10
	ans *= 9
print(ans)

s = input()
letters = set()
answer = 1
for ch in s:
    if ch == '?':
        answer *= 10
    elif ch >= 'A':
        letters.add(ord(ch))
temp = 10
for i in range(len(letters)):
    answer *= temp
    temp -= 1
if s[0] == '?' or s[0] >= 'A':
    answer = answer // 10 * 9
print(answer)

s=input()

ans=1
x=0
z="ABCDEFGHIJ"
L={}
for item in z:
    L[item]=False;
n=len(s)
for i in range(n):
    if(s[i] in "ABCDEFGHIJ" and i==0):
        ans*=9
        x+=1
        L[s[i]]=True
    elif(s[i] in "ABCDEFGHIJ" and not(L[s[i]])):
        ans*=(10-x)
        x+=1
        L[s[i]]=True
    elif(s[i]=="?" and i==0):
        ans*=9
    elif(s[i]=="?"):
        ans*=10

print(ans)
        



s = input()

z = set()
us = 0

ans = 1
if s[0] == '?' or (s[0] >= 'A' and s[0] <= 'J'):
    ans = 9
    z.add(s[0])
    if s[0] >= 'A' and s[0] <= 'J':
        us += 1

i = -1
for x in s:
    i += 1
    if i == 0:
        continue
    if x == '?':
        ans *= 10
    if x >= 'A' and x <= 'J':
        if x not in z:
            ans *= (10 - us)
            z.add(x)
            us += 1

print(ans)


s = input()


ans = 1
table = [0] * 26
for c in s:
    if c == '?':
        ans *= 10
    elif 'A' <= c <= 'J':
        table[ord(c) - ord('A')] += 1

total = 0
for c in range(26):
    if table[c]:
        total += 1

for i in range(total):
    ans *= 10 - i
if 'A' <= s[0] <= 'J':
    ans = ans // 10 * 9
if s[0] == '?':
    ans = ans // 10 * 9
print(ans)


ans = 1
n = 10
j = 9
d = set()
for i in input():
  if i == '?':
    ans *= min(10, j)
  elif i.isalpha() and i not in d:
    d.add(i)
    ans *= min(n, j)
    n -= 1
  j = 10
print(ans)

s = input()
l = []
n = '0123456789'
c = 1
z = True
tot = 1
for i in s:
    if i == '?':
        if z:
            c*=9
        else:
            c *= 10
    elif i in n:
        pass
    else:
        if i not in l:
            if z:
                c *= 9
                l.append(i)
            else:    
                c *= (10 - len(l))
                l.append(i)
    z = False
print(c)

s = input()
n = len (s)
was = [0, 0, 0, 0, 0]
ans = 1
cnt = 10
k = []
e = set (k)

for i in range (n) :
    if (s[i] >= 'A' and s[i] <= 'J' and s[i] not in e) :
        e.add (s[i])
        ans *= cnt
        cnt -= 1
    else :
        if (s[i] == '?') :
            ans *= 10

if (s[0] >= 'A' and s[0] <= 'J') :
    ans = ans // 10 * 9

if (s[0] == '?') :
    ans = ans // 10 * 9

print (ans)


#!/usr/bin/env python3
# -*- coding: utf-8 -*-


letters = set(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'])


def check(s, i):
    tested_s = str(i)
    used_letters, used_digits = dict(), dict()
    for ch, tested_ch in zip(s, tested_s):
        if ch == '?':
            continue
        if ch in letters:
            if ch in used_letters:
                if used_letters[ch] != tested_ch:
                    return False
            elif tested_ch in used_digits:
                if used_digits[tested_ch] != ch:
                    return False
            else:
                used_letters[ch] = tested_ch
                used_digits[tested_ch] = ch
            continue
        if ch != tested_ch:
            return False
    return True


def __starting_point():
    s = input()
    count = 0

    for i in range(10 ** (len(s) - 1), (10 ** (len(s)))):
        if check(s, i):
            count += 1

    print(count)

__starting_point()

hint = input()
seen = []

if 'A' <= hint[0] <= 'J':
    num = 9
    seen = [hint[0]]
elif '0' <= hint[0] <= '9':
    num = 1
elif hint[0] == '?':
    num = 9

for l in hint[1:]:
    if 'A' <= l <= 'J':
        if not l in seen:
            num *= 10 - len(seen)
            seen += [l]
    elif l == '?':
        num *= 10

print(num)


from sys import *
from math import *

s = stdin.readline().strip()
ans = 1
now = 10
was = {}
was['A'] = False
was['B'] = False
was['C'] = False
was['D'] = False
was['E'] = False
was['F'] = False
was['G'] = False
was['H'] = False
was['I'] = False
was['J'] = False

if s[0] == '?':
  ans *= 9
if (ord(s[0]) >= ord('A')) and (ord(s[0]) <= ord('J')):
  ans *= 9
  was[s[0]] = True
  now = 9
cnt = 0
for i in range(1, len(s)):
  if s[i] == '?':
    cnt += 1
  if (ord(s[i]) >= ord('A')) and (ord(s[i]) <= ord('J')):
    if was[s[i]] == False:
      ans *= now
      now -= 1
    was[s[i]] = True
print(ans, end = "") 
for i in range(cnt):
  print('0', end = "")
print()


a = str(input())
q = a.count('?')
l = 0
for i in 'ABCDEFGHIJ':
    if a.find(i) != -1:
        l += 1
if a[0] != '?':
    q = 10**q
else:
    q = 9 * (10**(q - 1))
l1 = 1
for i in range(0, l):
    l1 *= 10 - i
if a[0] in 'ABCDEFGHIJ':
    l1 //= 10
    l1 *= 9
print(l1 * q)
    


import sys
s = input()

use = [0] * 30
diff = 0
for i in s:
  c = ord(i) - ord('A')
  if (0 <= c and c <= 25): use[c] = True
for i in range(0, 30):
  if (use[i]): diff += 1
ans = 1
for i in range(10, 10 - diff, -1):
  if (i == 10 and (ord('A') <= ord(s[0]) and ord(s[0]) <= ord('Z'))): ans *= 9
  else: ans *= i
j = 0
for i in s:
  if (i == '?'):
    if (j == 0): ans *= 9
    else: ans *= 10
  j += 1
print(ans)

import math
import string
s = input()
p = 0
for x in string.ascii_uppercase[:10]:
    if x in s:
        p += 1
ans = 0
r = s.count('?')
if s[0] == '?':
    ans = 9 * pow(10, r - 1) * math.factorial(10) // math.factorial(10 - p)
elif s[0] in string.ascii_uppercase:
    ans = 9 * pow(10, r) * math.factorial(9) // math.factorial(9 - p + 1)
else:
    ans = pow(10, r) * math.factorial(10) // math.factorial(10 - p)
print(ans)

__author__ = 'Karolis'

s = input()
total = 1
was=[]
have = 10

for i in range(len(s)):
    if s[i] == '?':
        if i == 0:
            total *= 9
        else:
            total *= 10
    elif s[i] >= 'A' and s[i] <= 'J' and was.count(s[i]) == 0:
        was.append(s[i])

        if i == 0:
            total *= 9
        else:
            total *= have
        have-=1



print(total)


def main():
    s=input()
    l=[]
    i=1
    result=1
    
    for i in range(len(s)):
        if s[i:i+1]=='?':
            if i==0:
                result=result*9
            else:
                result=result*10
        if s[i:i+1]>='A' and s[i:i+1]<='J':
            if i==0:
                result=result*9
                l.append(s[i:i+1])
                
            else:
                if l.count(s[i:i+1])==0:
                    result=result*(10-len(l))
                    l.append(s[i:i+1])
                    
     
    print(result)
                
def __starting_point():
    main()

__starting_point()

input_str = input()
tmp = []
if input_str[0] == '?':
    result=9
    a = 11
    for c in input_str[1:]:
        if c == '?':
            result*=10
        elif 'A' <= c <= 'J' and tmp.count(c)==0:
            tmp.append(c)
            a-=1
            result*=a
elif 'A' <= input_str[0] <= 'J':
    tmp.append(input_str[0])
    result=9
    a=10
    for c in input_str[1:]:
        if c == '?':
            result*=10
        elif 'A' <= c <= 'J' and tmp.count(c)==0:
            tmp.append(c)
            a-=1
            result*=a
else:
    a=11
    result=1
    for c in input_str[1:]:
        if c == '?':
            result*=10
        elif 'A' <= c <= 'J' and tmp.count(c)==0:
            tmp.append(c)
            a-=1
            result*=a
print(result)

def readln(): return tuple(map(int, input().split()))

ans = 1
cnt = set()
for i, c in enumerate(list(input())):
    if c == '?':
        ans *= 10 - (i == 0)
    elif c.isalpha() and c not in cnt:
        ans *= 10 - len(cnt) - (i == 0)
        cnt.add(c)
print(ans)


def f(x, k):
    res = 1
    for i in range(k - x, k):
        res *= i
    return res
    
t = input()
s, k = set(), t.count('?')

for i in t:
    if i >= 'A': s.add(i)

if t[0] in '123456789': print(f(len(s), 11) * 10 ** k)
elif t[0] == '?': print(f(len(s), 11) * 9 * 10 ** (k - 1))
else: print(9 * f(len(s) - 1, 10) * 10 ** k)


s = input()
abc = [0] * 26
cnt1 = 0;
ans = 1;
for i in range(len(s)):
    if s[i] == '?':
        if i == 0:
            ans *= 9
        else:
            ans *= 10
    elif (s[i] >= 'A') and (s[i] <= 'Z'):
        if abc[(ord(s[i]) - ord('A'))] == 0:
            if i == 0:
                abc[(ord(s[i]) - ord('A'))] = 1
                ans *= 9
                cnt1 += 1 
            else:
                abc[(ord(s[i]) - ord('A'))] = 1
                ans *= (10 - cnt1)
                cnt1 += 1
print(ans)