def main():

    N=int(eval(input()))

    s=eval(input())

    ind=[[0 for j in range(10)] for i in range(N)]

    first=[-1 for i in range(10)]

    last=[-1 for i in range(10)]



    k=int(s[0])

    first[k]=0

    last[k]=0

    ind[0][k]=1



    for i in range(1,len(s)):

        k=int(s[i])

        if first[k]==-1: first[k]=i

        last[k]=i

        ind[i]=[ind[i-1][j] for j in range(10)]

        ind[i][k]=ind[i-1][k]+1



    ans=0

    for i in range(10):

        for j in range(10):

            f=first[i]

            l=last[j]

            if f!=-1 and f+1<l:

                for k in range(0,10):

                    if ind[f][k]<ind[l-1][k]: ans+=1

                    



    print(ans)



if __name__ == '__main__':

    main()
def main():

    from itertools import accumulate as acc

    N=int(eval(input()))

    s=eval(input())

    ind=[[0 for j in range(N)] for i in range(10)]

    first=[-1 for i in range(10)]

    last=[-1 for i in range(10)]





    for i in range(len(s)):

        k=int(s[i])

        if first[k]==-1: first[k]=i

        last[k]=i

        ind[k][i]=1

        

    for i in range(10):

        ind[i]=list(acc(ind[i]))



    ans=0

    for i in range(10):

        for j in range(10):

            f=first[i]

            l=last[j]

            if f!=-1 and f+1<l:

                for k in range(0,10):

                    if ind[k][f]<ind[k][l-1]: ans+=1

                    



    print(ans)



if __name__ == '__main__':

    main()
def main():
    N = int(eval(input()))
    s = eval(input())
    ind = [[0 for j in range(10)] for i in range(N)]
    first = [-1 for i in range(10)]
    last = [-1 for i in range(10)]
    k = int(s[0])
    first[k] = 0
    last[k] = 0
    ind[0][k] = 1
    for i in range(1, len(s)):
        k = int(s[i])
        if first[k] == -1:
            first[k] = i
        last[k] = i
        ind[i] = [ind[i - 1][j] for j in range(10)]
        ind[i][k] = ind[i - 1][k] + 1
    ans = 0
    for i in range(10):
        for j in range(10):
            f = first[i]
            l = last[j]
            if f != -1 and f + 1 < l:
                for k in range(0, 10):
                    if ind[f][k] < ind[l - 1][k]:
                        ans += 1
    print(ans)


if __name__ == "__main__":
    main()

def main():
    from itertools import accumulate as acc

    N = int(eval(input()))
    s = eval(input())
    ind = [[0 for j in range(N)] for i in range(10)]
    first = [-1 for i in range(10)]
    last = [-1 for i in range(10)]
    for i in range(len(s)):
        k = int(s[i])
        if first[k] == -1:
            first[k] = i
        last[k] = i
        ind[k][i] = 1
    for i in range(10):
        ind[i] = list(acc(ind[i]))
    ans = 0
    for i in range(10):
        for j in range(10):
            f = first[i]
            l = last[j]
            if f != -1 and f + 1 < l:
                for k in range(0, 10):
                    if ind[k][f] < ind[k][l - 1]:
                        ans += 1
    print(ans)


if __name__ == "__main__":
    main()

+    from itertools import accumulate as acc + -    ind = [[0 for j in range(10)] for i in range(N)] +    ind = [[0 for j in range(N)] for i in range(10)] -    k = int(s[0]) -    first[k] = 0 -    last[k] = 0 -    ind[0][k] = 1 -    for i in range(1, len(s)): +    for i in range(len(s)): -        ind[i] = [ind[i - 1][j] for j in range(10)] -        ind[i][k] = ind[i - 1][k] + 1 +        ind[k][i] = 1 +    for i in range(10): +        ind[i] = list(acc(ind[i])) -                    if ind[f][k] < ind[l - 1][k]: +                    if ind[k][f] < ind[k][l - 1]: