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.*;

import java.awt.geom.Point2D;
import java.text.*;
import java.math.*;
import java.util.*;

public class Main implements Runnable {

	final String filename = "";
	
	//abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc
	//36993465

	public void solve() throws Exception {
		
		long time = System.currentTimeMillis();
		final int mod = 51123987;
		int n = iread();
		String s = readword();
		StringBuilder sb = new StringBuilder();
		for (int i=0; i<n; i++)
		{
			if (i==0 || s.charAt(i)!=s.charAt(i-1))
				sb.append(s.charAt(i));
		}
		String t = sb.toString();
		int m = t.length();
		int[][] next = new int[3][m];
		for (int j=0; j<3; j++)
			Arrays.fill(next[j], -1);
		for (int i=0; i<m; i++)
		{
			for (int j=0; j<3; j++)
				for (int k=i; k<m; k++)
					if (t.charAt(k)=='a'+j)
					{
						next[j][i] = k;
						break;
					}
		}
		int n2 = (n+2)/3;
		int[][][][] dyn = new int[2][n2+2][n2+2][m];
		dyn[0][0][0][0] = 1;
		int step = 0;
		for (int len = 0; len<n; len++)
		{
			for (int i=0;i<=n2; i++)
				for (int j=0; j<=n2; j++)
				{
					Arrays.fill(dyn[1^step][i][j], 0);
				}
			for (int a=0; a<=len&&a<=n2; a++)
				for (int b=0; a+b<=len&&b<=n2; b++)
				{
					int c = len-a-b;
					if (c>n2) continue;
					for (int pos=0; pos<m; pos++)
					{
						int val = dyn[step][a][b][pos]; 
						if (val==0)
							continue;
						int pos1 = next[0][pos];
						if (pos1!=-1)
						{
							dyn[step^1][a+1][b][pos1]+=val;
							dyn[step^1][a+1][b][pos1]%=mod;
						}
						pos1 = next[1][pos]; 
						if (pos1!=-1)
						{
							dyn[step^1][a][b+1][pos1]+=val;
							dyn[step^1][a][b+1][pos1]%=mod;
						}
						pos1 = next[2][pos]; 
						if (pos1!=-1)
						{
							dyn[step^1][a][b][pos1]+=val;
							dyn[step^1][a][b][pos1]%=mod;
						}
					}
				}
			step^=1;
		}
		int ans = 0;
		for (int a=0; a<=n; a++)
		{
			for (int b=0; a+b<=n; b++)
			{
				int c = n-a-b;
				if (Math.abs(a-b)<=1 && Math.abs(b-c)<=1 && Math.abs(a-c)<=1)
				{
					for (int k=0; k<m; k++)
					{
						ans+=dyn[step][a][b][k];
						ans%=mod;
					}
				}
			}
		}
		out.write(ans+"\n");
//		System.out.println(System.currentTimeMillis()-time);
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new BufferedWriter(new OutputStreamWriter(System.out));
			// in = new BufferedReader(new FileReader(filename+".in"));
			// out = new BufferedWriter(new FileWriter(filename+".out"));
			solve();
			out.flush();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public int iread() throws Exception {
		return Integer.parseInt(readword());
	}

	public double dread() throws Exception {
		return Double.parseDouble(readword());
	}

	public long lread() throws Exception {
		return Long.parseLong(readword());
	}

	BufferedReader in;

	BufferedWriter out;

	public String readword() throws IOException {
		StringBuilder b = new StringBuilder();
		int c;
		c = in.read();
		while (c >= 0 && c <= ' ')
			c = in.read();
		if (c < 0)
			return "";
		while (c > ' ') {
			b.append((char) c);
			c = in.read();
		}
		return b.toString();
	}

	public static void main(String[] args) {
		try {
			Locale.setDefault(Locale.US);
		} catch (Exception e) {

		}
		new Thread(new Main()).start();
		// new Thread(null, new Main(), "1", 1<<25).start();
	}
}