#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

int main()
{
    int64_t n;
    string s;
    cin >> n >> s;

    if (n < 3)
    {
        set<int64_t> st;

        sort(s.begin(), s.end());
        do
        {
            int64_t x = 0;
            for (auto &&c : s)
            {
                x *= 10;
                x += c - '0';
            }

            st.insert(x % 120);
        } while (next_permutation(s.begin(), s.end()));

        cout << st.size() << endl;
        return 0;
    }

    vector<int64_t> cnt(10, 0);
    for (auto &&c : s)
    {
        cnt[c - '0']++;
    }

    set<int64_t> st;

    for (int64_t a = 0; a < 10; a++)
    {
        for (int64_t b = 0; b < 10; b++)
        {
            for (int64_t c = 0; c < 10; c++)
            {
                cnt[a]--;
                cnt[b]--;
                cnt[c]--;

                if (cnt[a] < 0 || cnt[b] < 0 || cnt[c] < 0)
                {
                    cnt[a]++;
                    cnt[b]++;
                    cnt[c]++;

                    continue;
                }

                st.insert((100 * a + 10 * b + c) % 40);

                cnt[a]++;
                cnt[b]++;
                cnt[c]++;
            }
        }
    }

    cout << st.size() << endl;

    return 0;
}