#include <bits/stdc++.h>
using namespace std;
const int MOD = 51123987;
const int N = 54;
int n;
char s[154];
int f[154][N][N][N];
void update(int &x, int y) { x = (x + y) % MOD; }
int main() {
  cin >> n;
  scanf("%s", s + 1);
  f[0][0][0][0] = 1;
  int ans = 0;
  for (int i = (0); i <= (n); i++)
    for (int j = (0); j <= (min(52, n)); j++)
      for (int k = (0); k <= (min(52, n - j)); k++)
        for (int l = (0); l <= (min(52, n - j - k)); l++)
          if (f[i][j][k][l]) {
            if (j + k + l == n)
              if (abs(j - k) <= 1 && abs(j - l) <= 1 && abs(k - l) <= 1)
                update(ans, f[i][j][k][l]);
            int num[3] = {0, 0, 0};
            if (i != 0) num[s[i] - 'a']++;
            for (int x = (i + 1); x <= (n); x++) {
              if (num[s[x] - 'a']++) continue;
              if (s[x] == 'a') update(f[x][j + 1][k][l], f[i][j][k][l]);
              if (s[x] == 'b') update(f[x][j][k + 1][l], f[i][j][k][l]);
              if (s[x] == 'c') update(f[x][j][k][l + 1], f[i][j][k][l]);
            }
            if (!i) continue;
            if (s[i] == 'a') update(f[i][j + 1][k][l], f[i][j][k][l]);
            if (s[i] == 'b') update(f[i][j][k + 1][l], f[i][j][k][l]);
            if (s[i] == 'c') update(f[i][j][k][l + 1], f[i][j][k][l]);
          }
  cout << ans << endl;
  return 0;
}
