Language: C++

/*input
3 3
abc


*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=405;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;

ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    int c1 = 0, c2 = 0, c3 = 0;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (x == 1) {
            c1++;
        } else if (x == 2) {
            c2++;
        } else {
            c3++;
        }
    }
 
    for (int k = 0; k < MX; k++) {
        for (int j = 0; j + k < MX; j++) {
            for (int i = 0; i + j + k < MX; i++) {
                if (i == 0 && j == 0 && k == 0) {
                    continue;
                }
                if (i + j + k > MX) {
                    continue;
                }
                ld wait = 1.0 * n / (i + j + k);
                ld pi = 1.0 * i / (i + j + k);
                ld pj = 1.0 * j / (i + j + k);
                ld pk = 1.0 * k / (i + j + k);
 
                if (i) {
                    f[i][j][k] += pi * f[i - 1][j][k];
                }
                if (j) {
                    f[i][j][k] += pj * f[i + 1][j - 1][k];
                }
                if (k) {
                    f[i][j][k] += pk * f[i][j + 1][k - 1];
                }
                f[i][j][k] += wait;
            }
        }
    }
 
    cout.precision(10);
    cout << fixed << f[c1][c2][c3] << "\n";
    return 0;
}
 


Compiler output:
a.cc: In function 'int main()':
a.cc:63:25: error: 'MX' was not declared in this scope
   63 |     for (int k = 0; k < MX; k++) {
      |                         ^~
a.cc:21:11: error: 'first' was not declared in this scope
   21 | #define f first
      |           ^~~~~
a.cc:78:21: note: in expansion of macro 'f'
   78 |                     f[i][j][k] += pi * f[i - 1][j][k];
      |                     ^
a.cc:21:11: error: 'first' was not declared in this scope
   21 | #define f first
      |           ^~~~~
a.cc:81:21: note: in expansion of macro 'f'
   81 |                     f[i][j][k] += pj * f[i + 1][j - 1][k];
      |                     ^
a.cc:21:11: error: 'first' was not declared in this scope
   21 | #define f first
      |           ^~~~~
a.cc:84:21: note: in expansion of macro 'f'
   84 |                     f[i][j][k] += pk * f[i][j + 1][k - 1];
      |                     ^
a.cc:21:11: error: 'first' was not declared in this scope
   21 | #define f first
      |           ^~~~~
a.cc:86:17: note: in expansion of macro 'f'
   86 |                 f[i][j][k] += wait;
      |                 ^
a.cc:21:11: error: 'first' was not declared in this scope
   21 | #define f first
      |           ^~~~~
a.cc:92:22: note: in expansion of macro 'f'
   92 |     cout << fixed << f[c1][c2][c3] << "\n";
      |                      ^