Language: C++

using namespace std;
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <bitset>
#include <iterator>
#include <set> 
#include <unordered_set>
#include <string>
#include <functional>
#include <limits.h>
//#include <bits/stdc++.h> 
//#include <list>
#include <stack>
#include <stdio.h>
typedef signed long long ll; //watch out ll= int*int will not become ll, rather (ll)ini*int casting will work
#include <queue>
#include <math.h>
#include <deque>
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
//typedef long float lf;
#include <cmath>
#include <iomanip>
#include <numeric>
#include <stdio.h>
const long double PI = 3.141592653589793238L;
/*struct CustomCompare
{
	bool operator()(pii& p1, pii& p2)
	{
		if (p1.second - p1.first == p2.second - p2.first)
			return p1.first > p2.first;

		return p1.second - p1.first < p2.second - p2.first;
	}
};*/
int tt, n, k, inp, a, b, x,m;
void pv(vector<int> a) {
	for (auto i : a)
		cout << i +1<< ' ';
	cout << '\n';
}
void pp (vector<pair<int, int>> a) {
	for (auto i : a)
		cout << i.first << ' ' << i.second<<'\n';
}
long float solve(tuple<int, int, int> s,
	map <tuple <int, int, int>, long float> &memo) {
	//cout << get<0>(s) << ' '<< get<1>(s) << ' '<< get<2>(s);
	//cout << endl;
	if (memo.find(s) == memo.end()) {
		int i = get<0>(s);
		int j = get<1>(s);
		int k = get<2>(s);
		
		//cout << "FIRST";
		long float ans = 0;
		if (k>0)
		ans +=(long float) k / n * (1 + solve({ i,j + 1,k-1 }, memo));
		
		
		//cout << "SECOND";
		if (j>0)
		ans += (long float)  j / n * (1 + solve({ i + 1,j-1,k }, memo));
		
		
		//cout << "THIRD";
		if (i>0)
		ans += (long float)     i / n * (1 + solve({ i-1,j,k }, memo));
		
		//cout << "FOURTH";
		ans = (long float) n / (i + j + k) * (ans + (long float)(n - i - j - k) / n);
		
		//cout << "ANS " << ans << '\n';
		memo.insert({ s, ans });
		return ans;
	}
	else
		return memo.find(s)->second;

}
int main() {
	//vector<int> x = { 2,1,0 };
	//cout << mex(x);
	cin >> n;
	vector<int> a(n);
	tuple <int, int, int> s = {0,0,0};
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] == 1)
			get<0>(s)++;
		else if (a[i]==2)
			get<1>(s)++;
		else if (a[i] == 3)
			get<2>(s)++;

	}
	map <tuple <int, int, int>, long float> memo;
	memo.insert({ {0,0,0},0.0 });
	cout << std::setprecision(11)<<solve(s, memo);
}


/*
int main() {
	int t; int n, k,initk;
	t = 0;
	cin >> t;
	for (int tt = 0; tt < t; tt++) {
		cin >> n >> m;
		vector<vector<int>> a(n);
		bool fail = false;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				int inp;
				cin >> inp;
				a[i].push_back(inp);
				if (i != 0 && i != n - 1 && j != 0 && j != m - 1 &&
					a[i][j] > 4)
					fail = true;
			}
		}
		if (a[0][0] > 2 || a[n - 1][0] > 2 || a[n - 1][m - 1] > 2 ||
			a[0][m - 1] > 2) {
			fail = true;
		}
		else {
			a[0][0] = 2;
			a[n - 1][0] = 2;
			a[n - 1][m - 1] = 2;
			a[0][m - 1] = 2;
		}
		for (int j = 1; j < m-1; j++) {
			if (a[0][j] > 3)
				fail = true;
			else 
				a[0][j] = 3;
		}
		for (int j = 1; j < m-1; j++) {
			if (a[n - 1][j] > 3)
				fail = true;
			else
				a[n - 1][j] = 3;
		}
		for (int i = 1; i < n-1; i++) {
			if (a[i][0] > 3)
				fail = true;
			else
				a[i][0] = 3;
		}
		for (int i = 1; i < n-1; i++) {
			if (a[i][0] > 3)
				fail = true;
			else
				a[i][m - 1] = 3;
		}

		if (fail) {
			cout << "NO\n"; continue;
		}
		else {
			cout << "YES\n";
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					if (i != 0 && i != n - 1 && j != 0 && j != m - 1)
						cout << 4 << ' ';
					else
						cout << a[i][j] << ' ';
				}cout << '\n';
			}
		}
	}
	
	
}*/

Compiler output:
a.cc:54:37: error: 'long' specified with 'float'
   54 |         map <tuple <int, int, int>, long float> &memo) {
      |                                     ^~~~
a.cc:53:1: error: 'long' specified with 'float'
   53 | long float solve(tuple<int, int, int> s,
      | ^~~~
a.cc: In function 'float solve(std::tuple<int, int, int>, std::map<std::tuple<int, int, int>, float>&)':
a.cc:63:17: error: 'long' specified with 'float'
   63 |                 long float ans = 0;
      |                 ^~~~
a.cc:65:24: error: 'long' specified with 'float'
   65 |                 ans +=(long float) k / n * (1 + solve({ i,j + 1,k-1 }, memo));
      |                        ^~~~
a.cc:70:25: error: 'long' specified with 'float'
   70 |                 ans += (long float)  j / n * (1 + solve({ i + 1,j-1,k }, memo));
      |                         ^~~~
a.cc:75:25: error: 'long' specified with 'float'
   75 |                 ans += (long float)     i / n * (1 + solve({ i-1,j,k }, memo));
      |                         ^~~~
a.cc:78:24: error: 'long' specified with 'float'
   78 |                 ans = (long float) n / (i + j + k) * (ans + (long float)(n - i - j - k) / n);
      |                        ^~~~
a.cc:78:62: error: 'long' specified with 'float'
   78 |                 ans = (long float) n / (i + j + k) * (ans + (long float)(n - i - j - k) / n);
      |                                                              ^~~~
a.cc: In function 'int main()':
a.cc:104:37: error: 'long' specified with 'float'
  104 |         map <tuple <int, int, int>, long float> memo;
      |                                     ^~~~