#include <bits/stdc++.h>
using namespace std;
const int mod = 51123987;
int n;
int nex[3][160];
int dp[160][55][55][55];
string s;
inline int solve(int pointer, int Ka, int Kb, int Kc) {
  if ((n + 2) / 3 < max(max(Ka, Kb), Kc) || pointer == n) return 0;
  if (Ka + Kb + Kc == n)
    return (max(max(Ka, Kb), Kc) - min(min(Ka, Kb), Kc) < 2);
  int &ret = dp[pointer][Ka][Kb][Kc];
  if (ret != -1) return ret;
  ret = 0;
  ret += solve(nex[0][pointer], Ka + 1, Kb, Kc);
  ret += solve(nex[1][pointer], Ka, Kb + 1, Kc);
  ret += solve(nex[2][pointer], Ka, Kb, Kc + 1);
  return (ret %= mod);
}
int main() {
  cin >> n >> s;
  nex[0][n] = nex[1][n] = nex[2][n] = n;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < 3; j++) nex[j][i] = nex[j][i + 1];
    nex[(int)(s[i] - 'a')][i] = i;
  }
  memset(dp, -1, sizeof dp);
  cout << solve(0, 0, 0, 0) << endl;
  return 0;
}
