func_code_string: #include <bits/stdc++.h>   using namespace std;   const int mod = 51123987;   char str[152];   int a[152];   int dp[152][52][52][52];   int nxt[152][3];   signed main() {     int n;     scanf( %d , &n);     cin >> str + 1;     for (int i = 1; i <= n; i++) a[i] = str[i] -  a ;     nxt[n + 1][0] = nxt[n + 1][1] = nxt[n + 1][2] = n + 1;     for (int i = n; i >= 1; i--) {       nxt[i][0] = nxt[i + 1][0];       nxt[i][1] = nxt[i + 1][1];       nxt[i][2] = nxt[i + 1][2];       nxt[i][a[i]] = i;     }     int ans = 0;     dp[1][0][0][0] = 1;     for (int i = 1; i <= n; i++)       for (int j1 = 0; j1 <= (n + 2) / 3; j1++)         for (int j2 = 0; j2 <= (n + 2) / 3; j2++)           for (int j3 = 0; j3 <= (n + 2) / 3; j3++) {             (dp[nxt[i][0]][j1 + 1][j2][j3] += dp[i][j1][j2][j3]) %= mod;             (dp[nxt[i][1]][j1][j2 + 1][j3] += dp[i][j1][j2][j3]) %= mod;             (dp[nxt[i][2]][j1][j2][j3 + 1] += dp[i][j1][j2][j3]) %= mod;             if (j1 + j2 + j3 == n && abs(j1 - j2) <= 1 && abs(j1 - j3) <= 1 &&                 abs(j2 - j3) <= 1)               ans += dp[i][j1][j2][j3], ans %= mod;           }     printf( %d , ans);     return 0;   }   