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

public class bubbles_as implements Runnable {
    final static String COLORS = "RGBY";

    final static int CN = COLORS.length();

    public void solve() throws IOException {
        Scanner in = new Scanner(new File("bubbles.in"));
        PrintWriter out = new PrintWriter(new File("bubbles.out"));

        String line = in.next();
        int n = line.length();
        int[] s = new int[n];
        for (int i = 0; i < n; i++) {
            s[i] = COLORS.indexOf(line.charAt(i));
        }

        int[][][][] v = new int[n][n][CN][n + 1];
        int[][] d = new int[n][n];

        for (int l = 1; l <= n; l++) {
            for (int i = 0; i + l - 1 < n; i++) {
                for (int c = 0; c < CN; c++) {
                    int j = i + l - 1;

                    for (int m = 1; m <= l; m++) {
                        v[i][j][c][m] = -1;
                    }
                    
                    for (int p = i + 1; p <= j; p++) {
                        for (int m = 1; m <= j - p + 1; m++) {
                            if (d[i][p - 1] != 0 && v[p][j][c][m] != -1) {
                                v[i][j][c][m] = Math.max(v[i][j][c][m], d[i][p - 1] + v[p][j][c][m]);
                            }
                        }
                    }

                    if (s[i] == c) {
                        int k = i;
                        while (k <= j && s[k] == c) {
                            k++;
                        }

                        if (k > j) {
                            v[i][j][c][l] = 0;
                        } else {
                            if (d[k][j] != 0) {
                                v[i][j][c][k - i] = Math.max(v[i][j][c][k - i], d[k][j]);
                            }

                            for (int m = 1; m <= j - k + 1; m++) {
                                if (v[k][j][c][m] != -1) {
                                    v[i][j][c][m + k - i] = Math.max(v[i][j][c][m + k - i], v[k][j][c][m]);
                                }
                            }
                        }
                    }

                    for (int m = 2; m <= l; m++) {
                        if (v[i][j][c][m] != -1) {
                            d[i][j] = Math.max(d[i][j], v[i][j][c][m] + m * m);
                        }
                    }
                }
            }
        }

        out.println(d[0][n - 1]);

        in.close();
        out.close();
    }

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

    public static void main(String[] arg) throws IOException {
        new Thread(new bubbles_as()).start();
    }
}