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

public class Main {

    static class Task {

        private List<Character> charList = List.of('R', 'G', 'B');

        private int findFirstBigger(List<Integer> list, int target) {
            int size = list.size();
            int low = 0;
            int high = size - 1;
            while (low <= high) {
                int mid = (low + high) >>> 1;
                int midVal = list.get(mid);
                if (midVal > target) {
                    if (mid == 0 || list.get(mid - 1) <= target) {
                        return mid;
                    }
                    high = mid - 1;
                } else {
                    low = mid + 1;
                }
            }
            return -1;
        }

        private char getThirdChar(char c1, char c2) {
            List<Character> curList = new ArrayList<>(List.of(c1, c2));
            List<Character> totalList = new ArrayList<>(charList);
            totalList.removeAll(curList);
            return totalList.get(0);
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String str = in.next();
            char[] arr = str.toCharArray();
            Map<Character, List<Integer>> map = new HashMap<>();

            for (int i = 0; i < n; i++) {
                if (!map.containsKey(arr[i])) {
                    map.put(arr[i], new ArrayList<>());
                }
                map.get(arr[i]).add(i);
            }

            long ans = 0;
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j < n; j++) {
                    if (arr[j] == arr[i]) {
                        continue;
                    }

                    char c = getThirdChar(arr[i], arr[j]);
                    List<Integer> indexList = map.get(c);
                    if (indexList == null || indexList.isEmpty()) {
                        continue;
                    }

                    int firstBiggerIndex = findFirstBigger(indexList, j);
                    if (firstBiggerIndex == -1) {
                        continue;
                    }

                    ans += indexList.size() - firstBiggerIndex;
                    // 寻找是否 j - i == k - j
                    int nextIdx = j + (j - i);
                    int index = Collections.binarySearch(indexList, nextIdx);
                    if (index >= 0) {
                        ans--;
                    }
                }
            }

            out.println(ans);
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }

}


Measured memory_bytes: 56904