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

public class bubbles_al {
  static void error (String s) throws Exception {
    throw new RuntimeException (s);
  };

  static final String pp = "RGBY";

  public static void main (String args []) throws Exception {
    Scanner in = new Scanner (new File ("bubbles.in"));
    PrintWriter out = new PrintWriter ("bubbles.out");

    String s = in.next ();
    if (in.hasNext ()) error ("End-of-file expected");

    int n = s.length ();

    if (n < 2 || n > 100)
      error ("String length not in range: " + n);

    for (int i = 0; i < n; i++)
      if (pp.indexOf (s.charAt (i)) < 0)
        error ("Invalid character in input: " + s.charAt (i));

    int [][] f = new int [n + 1][];
    int [][][] g = new int [n + 1][][];

    for (int i = 0; i <= n; i++) {
      f[i] = new int [n - i + 1];
      g[i] = new int [n - i + 1][n - i + 1];
    };

    for (int l = 1; l <= n; l++)
      for (int j = 0; j <= n - l; j++) {
        for (int k = 1; k < l; k++)
          if (f[j][k] != 0 && f[j + k][l - k] != 0)
            f[j][l] = Math.max (f[j][l], f[j][k] + f[j + k][l - k]);

        int k;
        for (k = 1; k < l; k++)
          if (s.charAt (j + k) != s.charAt (j)) break;

        if (k == l) {
          g[j][l][k] = k * k;
          if (l > 1) f[j][l] = k * k;
        };

        for (int m = k + 1; m < l; m++)
          if (s.charAt (j + m) == s.charAt (j) && f[j + k][m - k] != 0)
            for (int t = 0; t <= l - m; t++) if (g[j + m][l - m][t] != 0) {
              g[j][l][t + k] = f[j + k][m - k] + g[j + m][l - m][t] + (t + k) * (t + k) - t * t;
              f[j][l] = Math.max (f[j][l], g[j][l][t + k]);
            };
      };

    out.println (f[0][n]);

    out.close ();
  };
};
