#include <bits/stdc++.h>
using namespace std;
const int maxn = 155;
const int mod = 51123987;
const long long inf = 1e18 + 10;
string s;
int dp[maxn][55][55][55], n;
int nxt[maxn][3];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> s;
  s.resize(unique(s.begin(), s.end()) - s.begin());
  int m = s.size();
  s = "*" + s;
  for (int j = 0; j < 3; j++) nxt[m + 1][j] = m + 1;
  for (int i = m; i >= 0; i--) {
    for (int j = 0; j < 3; j++) nxt[i][j] = nxt[i + 1][j];
    if (i > 0) nxt[i][s[i] - 'a'] = i;
  }
  int k = 50;
  long long ans = 0;
  for (int i = 0; i <= m; 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 && (int)abs(a - c) <= 1 && (int)abs(b - c) <= 1 &&
              (int)abs(a - b) <= 1)
            (ans += dp[i][a][b][c]) %= mod;
          if (i == 0 && a == 0 && b == 0 && c == 0) dp[i][a][b][c] = 1;
          (dp[nxt[i][0]][a + 1][b][c] += dp[i][a][b][c]) %= mod;
          (dp[nxt[i][1]][a][b + 1][c] += dp[i][a][b][c]) %= mod;
          (dp[nxt[i][2]][a][b][c + 1] += dp[i][a][b][c]) %= mod;
        }
  cout << ans;
}
