import java.io.*;
import java.util.*;

public class bubbles_md implements Runnable {
	private Scanner in;
	private PrintWriter out;
	private final int infty = 1000000;

	public void run() {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	private void solve() throws IOException {
		Locale.setDefault(Locale.US);
		in = new Scanner(new FileReader("bubbles.in"));
		out = new PrintWriter("bubbles.out");
		String s = in.nextLine();
		int m = s.length();
		ArrayList<Integer> color = new ArrayList<Integer>();
		ArrayList<Integer> size = new ArrayList<Integer>();
		int sz = 0;
		for (int i = 0; i < s.length(); i++) {
			sz++;
			if ((i == s.length() - 1) || (s.charAt(i) != s.charAt(i + 1))) {
				color.add("RGBY".indexOf(s.charAt(i)));
				size.add(sz);
				sz = 0;
			}
		}
		int n = color.size();
		int[][] a = new int[n][n + 1];
		int[][] b = new int[n + 1][m + 1];
		for (int i = 0; i < n; i++) {
			Arrays.fill(a[i], -infty);
			a[i][i] = 0;
		}
		a[0][n] = 0;
		for (int i = n - 1; i >= 0; i--) {
			for (int j = i + 1; j <= n; j++) {
				for (int c = 0; c < 4; c++) {
					for (int x = i; x <= j; x++)
						Arrays.fill(b[x], -infty);
					b[i][0] = 0;
					for (int x = i; x < j; x++) {
						for (int t = 0; t <= m; t++) {
							if (b[x][t] >= 0) {
								for (int y = i + 1; y <= j; y++) {
									if (a[x][y] >= 0) {
										b[y][t] = Math.max(b[y][t], b[x][t] + a[x][y]);
									}
								}
								if (color.get(x) == c) {
									b[x + 1][t + size.get(x)] = Math.max(b[x + 1][t + size.get(x)], b[x][t]);
								}
							}
						}
					}
					for (int t = 2; t <= m; t++) {
						if (b[j][t] >= 0) {
							a[i][j] = Math.max(a[i][j], b[j][t] + t * t);
						}
					}
				}
			}
		}
		out.println(a[0][n]);
		in.close();
		out.close();
	}

	public static void main(String[] args) {
		new Thread(new bubbles_md()).start();
	}
}
