#include <bits/stdc++.h>
#define endl '\n'
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);
int n;
bool can[10];
void read()
{
cin >> n;
string t;
cin >> t;
for(char c: t)
can[c - '0'] = 1;
}
int64_t d[10][30][20][10][10];
int64_t rec(int i, int c2, int c3, int c5, int c7)
{
if(c2 < 0) return 0;
if(c3 < 0) return 0;
if(c5 < 0) return 0;
if(c7 < 0) return 0;
if(i == n)
return c2 + c3 + c5 + c7 == 0;
int64_t &memo = d[i][c2][c3][c5][c7];
if(memo != -1)
return memo;
memo = 0;
for(int d = 1; d < 10; d++)
if(can[d])
{
int n2 = c2, n3 = c3, n5 = c5, n7 = c7;
int x = d;
while(x % 2 == 0) n2--, x /= 2;
while(x % 3 == 0) n3--, x /= 3;
while(x % 5 == 0) n5--, x /= 5;
while(x % 7 == 0) n7--, x /= 7;
memo += rec(i + 1, n2, n3, n5, n7);
}
return memo;
}
int64_t sq(int64_t x) { return x * x; }
void solve()
{
int64_t answer = 0;
if(can[0])
{
int64_t numb1 = 1, rem = 1;
int cnt_av = 0;
for(int i = 1; i < 10; i++)
if(can[i]) cnt_av++;
for(int i = 0; i < n; i++)
{
numb1 *= (cnt_av + 1);
rem *= cnt_av;
}
answer += (numb1 - rem) * (numb1 - rem);
}
memset(d, -1, sizeof(d));
for(int c2 = 0; c2 < 30; c2++)
for(int c3 = 0; c3 < 20; c3++)
for(int c5 = 0; c5 < 10; c5++)
for(int c7 = 0; c7 < 10; c7++)
answer += sq(rec(0, c2, c3, c5, c7));
cout << answer << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
read();
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZW5kbCAnXG4nCgovLyNw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