/* -*- coding: utf-8 -*- * * 2593.cc: No.2593 Reorder and Mod 120 - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 200000; const int M = 40; /* typedef */ /* global variables */ char s[MAX_N + 4]; int cs[10], ds[10], es[M]; /* subroutines */ /* main */ int main() { int n; scanf("%d%s", &n, s); for (int i = 0; i < n; i++) cs[s[i] - '0']++; int k, l; if (n <= 1) k = 10, l = 1; else if (n == 2) k = 100, l = 2; else k = 1000, l = 3; for (int i = 0; i < k; i++) { fill(ds, ds + 10, 0); for (int j = 0, p = i; j < l; j++, p /= 10) ds[p % 10]++; bool ok = true; for (int j = 0; ok && j < 10; j++) ok = (ds[j] <= cs[j]); if (ok) es[i % M] = 1; } int cnt = 0; for (int i = 0; i < M; i++) cnt += es[i]; printf("%d\n", cnt); return 0; }