#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while ((c = getchar()) == ' ')
    ;
  x = c;
}
inline void writes(string s) { puts(s.c_str()); }
inline void writeln() { writes(""); }
inline void writei(int x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
inline void writell(long long x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
int n, m, i, a, b, c, mod = 51123987, dp[155][55][55][55], nxt[155][3], ans;
string st;
void inc(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
int main() {
  cin >> n >> st;
  m = n / 3 + 1;
  st = " " + st;
  for (i = n; i >= 1; i--) {
    memcpy(nxt[i], nxt[i + 1], sizeof(nxt[i]));
    nxt[i][st[i] - 'a'] = i;
  }
  0 [0 [0 [1 [dp]]]] = 1;
  for ((i) = (0); (i) <= (n); (i)++)
    for ((a) = (0); (a) <= (m); (a)++)
      for ((b) = (0); (b) <= (m); (b)++)
        for ((c) = (0); (c) <= (m); (c)++)
          if (c[b[a[i[dp]]]]) {
            if (a + b + c == n && abs(a - b) <= 1 && abs(a - c) <= 1 &&
                abs(b - c) <= 1)
              inc(ans, c[b[a[i[dp]]]]);
            if (nxt[i][0]) inc(dp[nxt[i][0]][a + 1][b][c], c[b[a[i[dp]]]]);
            if (nxt[i][1]) inc(dp[nxt[i][1]][a][b + 1][c], c[b[a[i[dp]]]]);
            if (nxt[i][2]) inc(dp[nxt[i][2]][a][b][c + 1], c[b[a[i[dp]]]]);
          }
  cout << ans << endl;
  return 0;
}
