N = int(eval(input()))

S = list(map(int,list(eval(input()))))

S_riv=S[::-1]

l_lis=[0]*N

r_lis=[0]*N

mat=([set([])for j in range(10)])

l_set=set([])

r_set=set([])

for i,s in enumerate(S):

  l_lis[i]=l_set.copy()

  l_set.add(s)

  

for i,s in enumerate(S_riv):

  r_lis[i]=r_set.copy()

  r_set.add(s)

  

r_lis.reverse()

ans=0

for i,s in enumerate(S):

  ans+=len(l_lis[i]-mat[s])*len(r_lis[i])

  mat[s]=l_lis[i]

  

print(ans)
N = int(eval(input()))

S = list(map(int,list(eval(input()))))

S_riv=S[::-1]

l_lis=[0]*N

r_lis=[0]*N

mat=([0 for j in range(10)])

l_set=set([])

r_set=set([])

for i,s in enumerate(S):

  l_lis[i]=l_set.copy()

  l_set.add(s)

  

for i,s in enumerate(S_riv):

  r_lis[i]=r_set.copy()

  r_set.add(s)

  

r_lis.reverse()

ans=0

for i,s in enumerate(S):

  length=len(l_lis[i])

  ans+=(length-mat[s])*len(r_lis[i])

  mat[s]=length

  

print(ans)
N = int(eval(input()))
S = list(map(int, list(eval(input()))))
S_riv = S[::-1]
l_lis = [0] * N
r_lis = [0] * N
mat = [set([]) for j in range(10)]
l_set = set([])
r_set = set([])
for i, s in enumerate(S):
    l_lis[i] = l_set.copy()
    l_set.add(s)
for i, s in enumerate(S_riv):
    r_lis[i] = r_set.copy()
    r_set.add(s)
r_lis.reverse()
ans = 0
for i, s in enumerate(S):
    ans += len(l_lis[i] - mat[s]) * len(r_lis[i])
    mat[s] = l_lis[i]
print(ans)

N = int(eval(input()))
S = list(map(int, list(eval(input()))))
S_riv = S[::-1]
l_lis = [0] * N
r_lis = [0] * N
mat = [0 for j in range(10)]
l_set = set([])
r_set = set([])
for i, s in enumerate(S):
    l_lis[i] = l_set.copy()
    l_set.add(s)
for i, s in enumerate(S_riv):
    r_lis[i] = r_set.copy()
    r_set.add(s)
r_lis.reverse()
ans = 0
for i, s in enumerate(S):
    length = len(l_lis[i])
    ans += (length - mat[s]) * len(r_lis[i])
    mat[s] = length
print(ans)

-mat = [set([]) for j in range(10)] +mat = [0 for j in range(10)] -    ans += len(l_lis[i] - mat[s]) * len(r_lis[i]) -    mat[s] = l_lis[i] +    length = len(l_lis[i]) +    ans += (length - mat[s]) * len(r_lis[i]) +    mat[s] = length