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

public class bubbles_as_wrong 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;
                    while (j < i + l && s[j] != c) {
                        j++;
                    }
                    int k = i + l - 1;
                    while (k >= i && s[k] != c) {
                        k--;
                    }

                    for (int m = 1; m <= l; m++) {
                        v[i][i + l - 1][c][m] = -1;
                    }

                    if (j > k) {
                        continue;
                    }

                    if ((j > i && d[i][j - 1] == 0) || (k < i + l - 1 && d[k + 1][i + l - 1] == 0)) {
                        continue;
                    }

                    if (j > i || k < i + l - 1) {
                        int dv = (j > i ? d[i][j - 1] : 0) + (k < i + l - 1 ? d[k + 1][i + l - 1] : 0);
                        for (int m = 1; m <= k - j + 1; m++) {
                            if (v[j][k][c][m] != -1) {
                                v[i][i + l - 1][c][m] = dv + v[j][k][c][m];
                            }
                        }
                    } else {
                        while (j <= k && s[j] == c) {
                            j++;
                        }
                        if (j > k) {
                            v[i][i + l - 1][c][l] = 0;
                        } else {
                            while (s[k] == c) {
                                k--;
                            }

                            int dm = j - i + (i + l - 1) - k;
                            if (d[j][k] != 0) {
                                v[i][i + l - 1][c][dm] = d[j][k];
                            }

                            for (int m = dm + 1; m <= l; m++) {
                                if (v[j][k][c][m - dm] != -1) {
                                    v[i][i + l - 1][c][m] = v[j][k][c][m - dm];
                                }
                            }
                        }
                    }

                    for (int m = 2; m <= l; m++) {
                        if (v[i][i + l - 1][c][m] != -1) {
//                            System.out.println(i + " " + (i + l - 1) + " " + COLORS.charAt(c) + " " + m + " " + v[i][i + l - 1][c][m]);
                            d[i][i + l - 1] = Math.max(d[i][i + l - 1], v[i][i + l - 1][c][m] + m * m);
                        }
                    }
                }
            }
        }

//        for (int i = 0; i < n; i++) {
//            for (int j = i; j < n; j++) {
//                if (d[i][j] > 0) {
//                    System.out.println(i + " " + j + " " + d[i][j]);
//                }
//            }
//        }

        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_wrong()).start();
    }
}
