Problem: Nick likes strings very much, he likes to rotate them, sort them, rearrange characters within a string... Once he wrote a random string of characters a, b, c on a piece of paper and began to perform the following operations: 

  * to take two adjacent characters and replace the second character with the first one, 
  * to take two adjacent characters and replace the first character with the second one 



To understand these actions better, let's take a look at a string «abc». All of the following strings can be obtained by performing one of the described operations on «abc»: «bbc», «abb», «acc». Let's denote the frequency of a character for each of the characters a, b and c as the number of occurrences of this character in the string. For example, for string «abc»: |a| = 1, |b| = 1, |c| = 1, and for string «bbc»: |a| = 0, |b| = 2, |c| = 1. 

While performing the described operations, Nick sometimes got balanced strings. Let's say that a string is balanced, if the frequencies of each character differ by at most 1. That is  - 1 ≤ |a| - |b| ≤ 1,  - 1 ≤ |a| - |c| ≤ 1 и  - 1 ≤ |b| - |c| ≤ 1. 

Would you help Nick find the number of different balanced strings that can be obtained by performing the operations described above, perhaps multiple times, on the given string s. This number should be calculated modulo 51123987.

Input

The first line contains integer n (1 ≤ n ≤ 150) — the length of the given string s. Next line contains the given string s. The initial string can be balanced as well, in this case it should be counted too. The given string s consists only of characters a, b and c.

Output

Output the only number — the number of different balanced strings that can be obtained by performing the described operations, perhaps multiple times, on the given string s, modulo 51123987.

Examples

Input

4
abca


Output

7


Input

4
abbc


Output

3


Input

2
ab


Output

1

Note

In the first sample it is possible to get 51 different strings through the described operations, but only 7 of them are balanced: «abca», «bbca», «bcca», «bcaa», «abcc», «abbc», «aabc». In the second sample: «abbc», «aabc», «abcc». In the third sample there is only one balanced string — «ab» itself.

Solution (in JAVA):

Solution:
import java.util.*;

public class Balance {
  
  public static final int MOD = 51123987;
  public static int[][] combos = null;
  
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    in.nextInt();
    String s = in.next();
    int len = s.length();
    int half = (len+1)/2;
    int[][][][] groupCounts = new int[half+2][half+2][half+2][3];
    int[][][][][] prevAdd = new int[half+2][half+2][half+2][3][3];
    // [i][j][k][-] = # of subsequences such that there are 'i' groups of a, 'j' groups of b, 'k' groups of c
    // [-][-][-][0] = # of such groups where the rightmost group is type 'a', [1] type 'b', [2] type 'c'
    //
    
    for (int i = 0; i < len; ++i) {
      char val = s.charAt(i);
      for (int a = 0; a <= i && a <= half; ++a) {
        for (int b = 0; a+b <= i && b <= half; ++b) {
          for (int c = 0; a+b+c <= i && c <= half; ++c) {
            if (a+b+c == 0) {
              groupCounts[val=='a'?1:0][val=='b'?1:0][val=='c'?1:0][val-'a'] = 1;
              continue;
            }
            int newAdd;
            if (val == 'a') {
              newAdd = groupCounts[a][b][c][1] - prevAdd[a][b][c][1][0];
              groupCounts[a+1][b][c][0] = mod(groupCounts[a+1][b][c][0] + newAdd, MOD);
              prevAdd[a][b][c][1][0] += newAdd;
              
              newAdd = groupCounts[a][b][c][2] - prevAdd[a][b][c][2][0];
              groupCounts[a+1][b][c][0] = mod(groupCounts[a+1][b][c][0] + newAdd, MOD);
              prevAdd[a][b][c][2][0] += newAdd;
            } else if (val == 'b') {
              newAdd = groupCounts[a][b][c][0] - prevAdd[a][b][c][0][1];
              groupCounts[a][b+1][c][1] = mod(groupCounts[a][b+1][c][1] + newAdd, MOD);
              prevAdd[a][b][c][0][1] += newAdd;
              
              newAdd = groupCounts[a][b][c][2] - prevAdd[a][b][c][2][1];
              groupCounts[a][b+1][c][1] = mod(groupCounts[a][b+1][c][1] + newAdd, MOD);
              prevAdd[a][b][c][2][1] += newAdd;
            } else { // val == 'c'
              newAdd = groupCounts[a][b][c][0] - prevAdd[a][b][c][0][2];
              groupCounts[a][b][c+1][2] = mod(groupCounts[a][b][c+1][2] + newAdd, MOD);
              prevAdd[a][b][c][0][2] += newAdd;
              
              newAdd = groupCounts[a][b][c][1] - prevAdd[a][b][c][1][2];
              groupCounts[a][b][c+1][2] = mod(groupCounts[a][b][c+1][2] + newAdd, MOD);
              prevAdd[a][b][c][1][2] += newAdd;
            }
          }
        }
      }
    }
    long total = 0;
    for (int a = 0; a <= half; ++a) {
      for (int b = 0; b <= half; ++b) {
        for (int c = 0; a+b+c <= len && c <= half; ++c) {
          long calc = calculate(a, b, c, len) % MOD;
          total += groupCounts[a][b][c][0] * calc;
          total += groupCounts[a][b][c][1] * calc;
          total += groupCounts[a][b][c][2] * calc;
          total %= MOD;
        }
      }
    }
    System.out.println(total);
  }
  
  public static int[][] getCombinations(int n, int m) {
    if (combos != null)
      return combos;
    combos = new int[n+1][n+1];
    combos[0][0] = 1;
    for (int row = 1; row <= n; ++row) {
      combos[row][0] = 1;
      for (int col = 1; col <= row; ++col) {
        combos[row][col] = combos[row-1][col-1] + combos[row-1][col];
        if (combos[row][col] >= m)
          combos[row][col] -= m;
      }
    }
    return combos;
  }
  
  public static long calculate(int a, int b, int c, int total) {
    getCombinations(total, MOD);
    long ret = 1;
    int goal = total/3;
    //SPECIAL CASE: at least one is zero
    if (a == 0 || b == 0 || c == 0) {
      // the only way this is possible is if total <= 2
      // total == 2: 0,1,1 , 1,0,1, 1,1,0
      // total == 1: 0,0,1 , 0,1,0  1,0,0
      if (total > 2)
        return 0;
      int sum = a + b + c;
      if (sum == total)
        return 1;
      return 0;
    }
    if (total % 3 == 0) {
      // each group must have the same total;
      if (a > goal || b > goal || c > goal)
        return 0;
      ret *= combos[goal-1][goal-a];
      ret *= combos[goal-1][goal-b];
      ret %= MOD;
      ret *= combos[goal-1][goal-c];
      ret %= MOD;
    } else if (total % 3 == 1) {
      long retPartial = 0;
      // try goal,goal,goal+1
      if (a <= goal && b <= goal && c <= goal+1) {
        ret *= combos[goal-1][goal-a];
        ret *= combos[goal-1][goal-b];
        ret %= MOD;
        ret *= combos[goal][goal-c+1];
        retPartial += ret;
        ret = 1;
      }
      // try goal,goal+1,goal
      if (a <= goal && b <= goal+1 && c <= goal) {
        ret *= combos[goal-1][goal-a];
        ret *= combos[goal][goal-b+1];
        ret %= MOD;
        ret *= combos[goal-1][goal-c];
        retPartial += ret;
        ret = 1;
      }
      // try goal+1,goal,goal
      if (a <= goal+1 && b <= goal && c <= goal) {
        ret *= combos[goal][goal-a+1];
        ret *= combos[goal-1][goal-b];
        ret %= MOD;
        ret *= combos[goal-1][goal-c];
        retPartial += ret;
        ret = 1;
      }
      ret = retPartial % MOD;
    } else { // total % 3 == 2
      long retPartial = 0;
      // try goal,goal+1,goal+1
      if (a <= goal && b <= goal+1 && c <= goal+1) {
        ret *= combos[goal-1][goal-a];
        ret *= combos[goal][goal-b+1];
        ret %= MOD;
        ret *= combos[goal][goal-c+1];
        retPartial += ret;
        ret = 1;
      }
      // try goal+1,goal,goal+1
      if (a <= goal+1 && b <= goal && c <= goal+1) {
        ret *= combos[goal][goal-a+1];
        ret *= combos[goal-1][goal-b];
        ret %= MOD;
        ret *= combos[goal][goal-c+1];
        retPartial += ret;
        ret = 1;
      }
      // try goal+1,goal+1,goal
      if (a <= goal+1 && b <= goal+1 && c <= goal) {
        ret *= combos[goal][goal-a+1];
        ret *= combos[goal][goal-b+1];
        ret %= MOD;
        ret *= combos[goal-1][goal-c];
        retPartial += ret;
        ret = 1;
      }
      ret = retPartial % MOD;
    }
    return ret;
  }
  
  public static int mod(int a, int m) {
    if (a < 0)
      a += m;
    if (a >= m)
      a -= m;
    return a;
  }
}