import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;


public class bubbles_dp implements Runnable {
    private static final int MAX_N = 100;

    private BufferedReader in;
    private PrintWriter out;
    StringTokenizer st;

    private int[] a;
    private int n;

    private int[][][][] answer;

    public void solve() throws IOException {
        char[] str = nextToken().toCharArray();
        n = str.length;
        assert 0 < n && n <= MAX_N;
        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = "RGBY".indexOf(str[i]);
            assert a[i] >= 0;
        }
        answer = new int[4][n + 1][n + 1][n + 1];
        for (int[][][] a3: answer) {
            for (int[][] a2: a3) {
                for (int[] a1: a2) {
                    Arrays.fill(a1, -1);
                }
            }
        }
        out.println(solve(0, 0, 0, n));
    }
    
    private int solve(int col, int cnt, int left, int right) {
        if (left >= right) {
            if (cnt < 2) {
                return 0;
            }
            return cnt * cnt;
        }
        if (answer[col][cnt][left][right] >= 0) {
            return answer[col][cnt][left][right];
        }
        int ans = 0;
        if (a[left] == col || cnt == 0) {
            ans = solve(a[left], cnt + 1, left + 1, right);
        }
        if (cnt >= 2) {
            int tmp = solve(0, 0, left, right);
            if (tmp > 0) {
                ans = Math.max(ans, cnt * cnt + tmp);
            }
        }
        for (int m = left + 1; m < right; m++) {
            int tmp1 = solve(0, 0, left, m);
            int tmp2 = solve(col, cnt, m, right);
            if (tmp1 > 0 && tmp2 > 0) {
                ans = Math.max(ans, tmp1 + tmp2);
            }
        }
        return answer[col][cnt][left][right] = ans;
    }

    public String nextToken() throws IOException {
        while (!st.hasMoreTokens()) {
            String line = in.readLine();
            if (line == null) {
                return null;
            }
            st = new StringTokenizer(line);
        }
        return st.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public bubbles_dp(String file) {
        try {
            in = new BufferedReader(new FileReader(file + ".in"));
            out = new PrintWriter(file + ".out");
            st = new StringTokenizer("");
        } catch (FileNotFoundException e) {
            apstenu(e);
        }
    }

    private void apstenu(IOException e) {
        e.printStackTrace();
        System.exit(1);
    }

    public void run() {
        try {
            solve();
        } catch (IOException e) {
            apstenu(e);
        } finally {
            out.close();
        }
    }

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