#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSInteger N;
        scanf("%ld", &N);
        char chars[N];
        scanf("%s", chars);
        NSString *str = [NSString stringWithCString:chars encoding:NSUTF8StringEncoding];
        NSInteger count = 0;
        NSMutableDictionary <NSString *, NSNumber *> *current = [@{
            @"R" : @0,
            @"G" : @0,
            @"B" : @0,
        } mutableCopy];
        NSMutableArray<NSDictionary <NSString *, NSNumber *> *> *counts = [[NSMutableArray alloc] init];
        for (NSInteger i = 0; i < str.length; i ++) {
            NSString *s = [str substringWithRange:NSMakeRange(i, 1)];
            NSInteger next = [current objectForKey:s].integerValue + 1;
            [current setValue:@(next) forKey:s];
            [counts addObject: [current copy]];
        }
        for(NSInteger i = 0; i < str.length - 2; i++) {
            NSString *first = [str substringWithRange:NSMakeRange(i, 1)];
            for (NSInteger j = i + 1; j < str.length - 1; j++) {
                NSString *second = [str substringWithRange:NSMakeRange(j, 1)];
                if ([first isEqualToString: second]) {
                    continue;
                }
                NSString *third;
                if (![first isEqualToString:@"R"] && ![second isEqualToString:@"R"]) {
                    third = @"R";
                } else if (![first isEqualToString:@"G"] && ![second isEqualToString:@"G"]) {
                    third = @"G";
                } else {
                    third = @"B";
                }
                NSInteger distance = j - i;
                NSString *sAtDistance = (j + distance < str.length) ?  [str substringWithRange:NSMakeRange(j + distance, 1)] : @"";
                NSInteger index = (NSInteger)str.length - 1;
                NSInteger offset = [sAtDistance isEqualToString:third] ? 1 : 0;
                NSDictionary <NSString *, NSNumber *> *dic = [counts objectAtIndex: index];
                NSNumber *num = [dic objectForKey: third];
                NSDictionary <NSString *, NSNumber *> *dic2 = [counts objectAtIndex: j];
                NSNumber *num2 = [dic2 objectForKey: third];
              	count += num.integerValue - num2.integerValue - offset;
            }
        }
        printf("%ld", count);
    }
    return 0;
}