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.io.BufferedReader;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author AlexFetisov
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {

    final static int MOD = 51123987;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        String s = in.nextString();
        StringBuilder sb = new StringBuilder(s);
        for (int i = 0; i < sb.length(); ++i) {
            if (i + 1 < sb.length()) {
                if (sb.charAt(i) == sb.charAt(i + 1)) {
                    sb.deleteCharAt(i + 1);
                }
            }
        }
        String comp = sb.toString();

        int lim = (n + 2) / 3 + 2;
        int[][][] dp = new int[comp.length()+1][lim][lim];
        dp[0][0][0] = 1;

        int[][] firstAfter = new int[comp.length()][3];
        for (int i = 0; i < comp.length(); ++i) {
            Arrays.fill(firstAfter[i], -1);
            for (int j = i; j < comp.length(); ++j) {
                int c = comp.charAt(j) - 'a';
                if (firstAfter[i][c] == -1) {
                    firstAfter[i][c] = j;
                }
            }
        }

        for (int i = 0; i < n; ++i) {
            int[][][] next = new int[comp.length()+1][lim][lim];
            for (int j = 0; j < comp.length(); ++j) {
                for (int ca = 0; ca < lim; ++ca) {
                    for (int cb = 0; cb < lim; ++cb) {
                        if (dp[j][ca][cb] > 0) {
                            if (firstAfter[j][0] != -1 && ca + 1 < lim) {
                                next[firstAfter[j][0]][ca + 1][cb] += dp[j][ca][cb];
                                if (next[firstAfter[j][0]][ca + 1][cb] >= MOD) {
                                    next[firstAfter[j][0]][ca + 1][cb] -= MOD;
                                }
                            }
                            if (firstAfter[j][1] != -1 && cb + 1 < lim) {
                                next[firstAfter[j][1]][ca][cb + 1] += dp[j][ca][cb];
                                if (next[firstAfter[j][1]][ca][cb + 1] >= MOD) {
                                    next[firstAfter[j][1]][ca][cb + 1] -= MOD;
                                }
                            }
                            if (firstAfter[j][2] != -1) {
                                next[firstAfter[j][2]][ca][cb] += dp[j][ca][cb];
                                if (next[firstAfter[j][2]][ca][cb] >= MOD) {
                                    next[firstAfter[j][2]][ca][cb] -= MOD;
                                }
                            }
                        }
                    }
                }
            }
            int[][][] temp = dp;
            dp = next;
            next = temp;
            ArrayUtils.fill(next, 0);
        }

        int res = 0;
        for (int i = 0; i < comp.length(); ++i) {
            for (int ca = 0; ca < lim; ++ca) {
                for (int cb = 0; cb < lim; ++cb) {
                    int cc = n - ca - cb;
                    if (ca >= 0 && cb >= 0 && cc >= 0) {
                        if (dp[i][ca][cb] > 0) {
                            if (Math.abs(ca - cb) <= 1 && Math.abs(ca - cc) <= 1 && Math.abs(cb - cc) <= 1) {
                                res += dp[i][ca][cb];
                                if (res >= MOD) {
                                    res -= MOD;
                                }
                            }
                        }
                    }
                }
            }
        }
        out.println(res);
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer stt;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
    }

    public String nextLine() {
        try {
            return reader.readLine().trim();
        } catch (IOException e) {
            return null;
        }
    }

    public String nextString() {
        while (stt == null || !stt.hasMoreTokens()) {
            stt = new StringTokenizer(nextLine());
        }
        return stt.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

}

class ArrayUtils {

    public static void fill(int[][] f, int value) {
        for (int i = 0; i < f.length; ++i) {
            Arrays.fill(f[i], value);
        }
    }

    public static void fill(int[][][] a, int value) {
        for (int i = 0; i < a.length; ++i) {
            fill(a[i], value);
        }
    }

}