public int getMin(String road) {

		int[] roads = new int[road.length()];
		int[] dp = new int[roads.length];
		Arrays.fill(dp, MAX);
		for (int i = 0; i < roads.length; i++) {
			roads[i] = road.charAt(i) == 'R' ? 0 : road.charAt(i) == 'G' ? 1 : 2;
		}
		dp[0] = 0;

		for (int i = 0; i < roads.length - 1; i++) {
			for (int j = i + 1; j < roads.length; j++) {
				if (roads[j] == (roads[i] + 1) % 3) {
					dp[j] = Math.min(dp[i] + (j - i) * (j - i), dp[j]);
				}
			}
		}
		return (dp[dp.length - 1] == MAX ? -1 : dp[dp.length - 1]);
	}