func_code_string: #include <bits/stdc++.h>   using namespace std;   static const int MOD = 51123987;   static const int MAXN = 150 + 10;   char s[MAXN];   int p[MAXN][3];   int dp[MAXN][55][55][55];   int n, res;   int main() {     scanf( %d%s , &n, s + 1);     p[n + 1][0] = p[n + 1][1] = p[n + 1][2] = n + 1;     for (int i = n; i >= 1; i--) {       p[i][0] = p[i + 1][0];       p[i][1] = p[i + 1][1];       p[i][2] = p[i + 1][2];       if (s[i] ==  a ) p[i][0] = i;       if (s[i] ==  b ) p[i][1] = i;       if (s[i] ==  c ) p[i][2] = i;     }     int k = (n + 2) / 3;     dp[1][0][0][0] = 1;     for (int i = 1; i <= n; i++)       for (int a = 0; a <= k; a++)         for (int b = 0; b <= k; b++)           for (int c = 0; c <= k; c++) {             if (a + b + c == n && abs(a - b) < 2 && abs(a - c) < 2 &&                 abs(b - c) < 2) {               res = (res + dp[i][a][b][c]) % MOD;               continue;             }             dp[p[i][0]][a + 1][b][c] =                 (dp[p[i][0]][a + 1][b][c] + dp[i][a][b][c]) % MOD;             dp[p[i][1]][a][b + 1][c] =                 (dp[p[i][1]][a][b + 1][c] + dp[i][a][b][c]) % MOD;             dp[p[i][2]][a][b][c + 1] =                 (dp[p[i][2]][a][b][c + 1] + dp[i][a][b][c]) % MOD;           }     printf( %d n , res);     return 0;   }   