Problem:
Score: 400 points

Problem Statement

AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code.

The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code.

How many different PIN codes can he set this way?

Both the lucky number and the PIN code may begin with a 0.

Constraints

4 \leq N \leq 30000

S is a string of length N consisting of digits.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of different PIN codes Takahashi can set.

Sample Input 1

4
0224

Sample Output 1

3

Takahashi has the following options:

Erase the first digit of S and set 224.

Erase the second digit of S and set 024.

Erase the third digit of S and set 024.

Erase the fourth digit of S and set 022.

Thus, he can set three different PIN codes: 022, 024, and 224.

Sample Input 2

6
123123

Sample Output 2

17

Sample Input 3

19
3141592653589793238

Sample Output 3

329

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

#define D
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
#if A
        FastIO.Int();
        var D = FastIO.Int();
        FastIO.Int();
        var K = FastIO.Int();
        WriteLine(D < K ? 1 : 0);
#endif

#if B
        var N = int.Parse(ReadLine());
        for (int i = 1; i <= N; i++)
        {
            if ((i * 108) / 100 == N)
            {
                WriteLine(i);
                return;
            }
        }
        WriteLine(":(");
#endif

#if C
        var X = int.Parse(ReadLine());
        var q = X / 100;
        var r = X % 100;
        WriteLine(5 * q < r ? 0 : 1);
#endif

#if D
        var N = int.Parse(ReadLine());
        var S = ReadLine();

        var b = new int[10];
        for (int i = 0; i < b.Length; i++)
        {
            b[i] = -1;
            for (int j = 0; j < S.Length; j++)
            {
                if (S[j] == '0' + i)
                {
                    b[i] = j;
                    break;
                }
            }
        }

        var c = new int[10, 10];
        for (int i = 0; i < 10; i++)
        {
            if (b[i] == -1) continue;
            for (int j = 0; j < 10; j++)
            {
                c[i, j] = -1;
                for (int k = b[i] + 1; k < S.Length; k++)
                {
                    if (S[k] == '0' + j)
                    {
                        c[i, j] = k;
                        break;
                    }
                }
            }
        }

        var d = new int[10, 10, 10];
        for (int i = 0; i < 10; i++)
        {
            if (b[i] == -1) continue;
            for (int j = 0; j < 10; j++)
            {
                if (c[i, j] == -1) continue;
                for (int k = 0; k < 10; k++)
                {
                    d[i, j, k] = -1;
                    for (int l = c[i, j] + 1; l < S.Length; l++)
                    {
                        if (S[l] == '0' + k)
                        {
                            d[i, j, k] = l;
                            break;
                        }
                    }
                }
            }
        }

        var ans = 0;
        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                for (int k = 0; k < 10; k++)
                {
                    if (d[i, j, k] > 0)
                    {
                        ans++;
                    }
                }
            }
        }

        WriteLine(ans);
#endif
    }
}


public static class FastIO
{
    static System.IO.Stream str = System.Console.OpenStandardInput();
    const int size = 1024;
    static byte[] buffer = new byte[size];
    static int ptr;
    static int len;

    static byte Read()
    {
        if (ptr == len)
        {
            len = str.Read(buffer, 0, size);
            if (len == 0) return 0;
            ptr = 0;
        }
        return buffer[ptr++];
    }

    public static int Int()
    {
        var c = Read();
        while (c < 0x21)
        {
            c = Read();
        }
        var n = false;
        if (c == '-')
        {
            n = true;
            c = Read();
        }
        var ret = 0;
        while (c > 0x20)
        {
            ret = ret * 10 + c - '0';
            c = Read();
        }
        return n ? -ret : ret;
    }

    public static long Long()
    {
        var c = Read();
        while (c < 0x21)
        {
            c = Read();
        }
        var n = false;
        if (c == '-')
        {
            n = true;
            c = Read();
        }
        var ret = 0L;
        while (c > 0x20)
        {
            ret = ret * 10 + c - '0';
            c = Read();
        }
        return n ? -ret : ret;
    }
}