#include <bits/stdc++.h>
using namespace std;
const int mod = 51123987;
int dp[152][52][52][52], n, nxt[152][3];
string s;
void add(int &a, int b) {
  a = a + b;
  if (a >= mod) a %= mod;
}
int main() {
  scanf("%d", &n);
  cin >> s;
  for (int j = 0; j < 3; j++) nxt[n][j] = n;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < 3; j++) nxt[i][j] = nxt[i + 1][j];
    nxt[i][s[i] - 'a'] = i;
  }
  dp[0][0][0][0] = 1;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int a = 0; a * 3 <= n + 2; a++) {
      for (int b = 0; b * 3 <= n + 2; b++) {
        for (int c = 0; c * 3 <= n + 2 && a + b + c <= n; c++) {
          if (dp[i][a][b][c]) {
            if (a + b + c == n && abs(b - c) <= 1 && abs(a - c) <= 1 &&
                abs(b - c) <= 1)
              add(ans, dp[i][a][b][c]);
            add(dp[nxt[i][0]][a + 1][b][c], dp[i][a][b][c]);
            add(dp[nxt[i][1]][a][b + 1][c], dp[i][a][b][c]);
            add(dp[nxt[i][2]][a][b][c + 1], dp[i][a][b][c]);
          }
        }
      }
    }
  }
  printf("%d\n", ans);
}
