#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; string s; cin >> n >> s; set st; if (n < 8) { vector p(n); iota(p.begin(), p.end(), 0); do { int x = 0; rep(i, n) x = x * 10 + (s[p[i]] - '0'); st.insert(x % 120); } while (next_permutation(p.begin(), p.end())); } else { vector cnt(10, 0); rep(i, n) cnt[s[i] - '0']++; rep(i, 10) rep(j, 10) rep(k, 10) { cnt[i]--, cnt[j]--, cnt[k]--; if (cnt[i] >= 0 && cnt[j] >= 0 && cnt[k] >= 0) { int x = i * 100 + j * 10 + k; st.insert(x); } cnt[i]++, cnt[j]++, cnt[k]++; } } cout << st.size() << '\n'; return 0; }