#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll N;

//dp
vector<vector<vector<double>>> table;

double dp(ll i,ll j,ll k){
  //cout<<i<<" "<<j<<" "<<k<<endl;
  if(i==0&&j==0&&k==0) return 0;
  if(table.at(i).at(j).at(k)>-1) return table.at(i).at(j).at(k);
  
  table.at(i).at(j).at(k)=0;
  if(i>0) table.at(i).at(j).at(k)+=dp(i-1,j,k)*i/N;
  if(j>0) table.at(i).at(j).at(k)+=dp(i+1,j-1,k)*j/N;
  if(k>0) table.at(i).at(j).at(k)+=dp(i,j+1,k-1)*k/N;
  table.at(i).at(j).at(k)+=1;
  
  return table.at(i).at(j).at(k)/=(double)(i+j+k)/N;
}

int main()
{
  cin>>N;
  vector<ll> vec(4,0); rep(i,N) {ll a; cin>>a; vec.at(a)++;}
  
  //dp
  table=vector<vector<vector<double>>>(N+1,vector<vector<double>>(N+1,vector<double>(N+1,-1)));
  
  cout<<fixed<<setprecision(15)<<dp(vec.at(1),vec.at(2),vec.at(3))<<endl;
  /*
  rep(i,2) {
    if(i!=0) cout<<" ";
    cout<<table.at(0).at(0).at(i);
  }
  cout<<fixed<<setprecision(15)<<endl;
  */
  
  
  return 0;
}
#include <bits/stdc++.h>
using namespace std;

int D;
int d[22];
long long ans;

bool analyze(int ndig) {
	int tmp = D;
	for (int i = ndig; i >= 1; --i) {
		d[i] = tmp % 10; tmp /= 10;
	}
	return tmp == 0;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> D;
	for (int ndig = 2; ndig <= 20; ++ndig) {
		bool odd = ndig % 2;
		if (!analyze(ndig)) continue;
			
		long long cur = 1; // current answer
		// d[1], d[2], ..., d[ndig]
		bool lef = 0 /* -> */, rig = 0 /* <- */;
		for (int dig = 1; dig <= ndig / 2; ++dig) {
			bool nlef = 0, nrig = 0;
			bool LEF = 0, RIG = 0;
			// opposite: ndig + 1 - dig
			int npair = 0;
			for (int i = 0; i <= 9; ++i) {
				for (int j = 0; j <= 9; ++j) {
					// check for validity
					if (dig == 1) {
						if (j == 0) continue;
						if (i < j) continue;
					}

					// I - J ~ [d[dig] + 1, d[dig]]
					// J - I = d[n + 1 - dig] || 10 + J - I = d[n + 1 - dig]
					int I = i, J = j;
					if (lef) I += 10; if (rig) --J;
					
					if (I - j == d[dig]) nlef = 0;
					else if (I - j == d[dig] + 1) nlef = 1;
					else continue;
					
					if (J - i == d[ndig + 1 - dig]) nrig = 0;
					else if (10 + J - i == d[ndig + 1 - dig]) nrig = 1;
					else continue;

					// now valid
					++npair;
					LEF = nlef;
					RIG = nrig;
				}
			}
			cur *= npair;
			lef = LEF;
			rig = RIG;
		}
		if (!odd && lef != rig) continue;
		else if (odd) {
			int cnt = 0;
			for (int i = 0; i <= 9; ++i) {
				int I = i;
				if (lef) I += 10;
				if (rig) I--;
				if (I - i == d[(ndig + 1) / 2]) ++cnt;
			}
			cur *= cnt;
		}
		ans += cur;
	}

	cout << ans << endl;
}