import std.algorithm;
import std.array;
import std.conv;
import std.numeric;
import std.stdio;
import std.string;

void main()
{
    long n;
    string s;
    
    long[] r_positions;
    long[] g_positions;
    long[] b_positions;
    
    long r_position;
    long g_position;
    long b_position;
    
    long left_r;
    long left_g;
    long left_b;
    
    long mid_r;
    long mid_g;
    long mid_b;
    
    long right_r;
    long right_g;
    long right_b;
    
    long total_count;
    
    n = readln.chomp.to!(long);
    s = readln.chomp;
    
    for (long l = 0; l < n; l++) {
        if (s[l..l+1] == "R") {
            r_positions ~= l;
            continue;
        }
        if (s[l..l+1] == "G") {
            g_positions ~= l;
            continue;
        }
        if (s[l..l+1] == "B") {
            b_positions ~= l;
            continue;
        }
    }

    // RGB, RBG
    for (long i = 0; i < r_positions.length; i++) {
        r_position = r_positions[i];
        
        left_g = 0;
        right_g = g_positions.length - 1;
        
        while (left_g <= right_g) {
            mid_g = (left_g + right_g) / 2;
            if (g_positions[mid_g] == r_position) {
                break;
            } else if (g_positions[mid_g] < r_position) {
                left_g = mid_g + 1;
            } else {
                right_g = mid_g - 1;
            }
        }
        mid_g = (left_g + right_g) / 2;
        
        for (long j = mid_g; j < g_positions.length; j++) {
            g_position = g_positions[j];
            
            left_b = 0;
            right_b = b_positions.length - 1;
            
            while (left_b <= right_b) {
                mid_b = (left_b + right_b) / 2;
                if (b_positions[mid_b] == g_position) {
                    break;
                } else if (b_positions[mid_b] < g_position) {
                    left_b = mid_b + 1;
                } else {
                    right_b = mid_b - 1;
                }
            }
            mid_b = (left_b + right_b) / 2;
            
            for (long k = mid_b; k < b_positions.length; k++) {
                b_position = b_positions[k];
                
                if (r_position >= g_position || g_position >= b_position) {
                    continue;
                }
                if (g_position - r_position == b_position - g_position) {
                    continue;
                }
                
                total_count++;
            }
        }
        
        left_b = 0;
        right_b = b_positions.length - 1;
        
        while (left_b <= right_b) {
            mid_b = (left_b + right_b) / 2;
            if (b_positions[mid_b] == r_position) {
                break;
            } else if (b_positions[mid_b] < r_position) {
                left_b = mid_b + 1;
            } else {
                right_b = mid_b - 1;
            }
        }
        mid_b = (left_b + right_b) / 2;
        
        for (long j = mid_b; j < b_positions.length; j++) {
            b_position = b_positions[j];
            
            left_g = 0;
            right_g = g_positions.length - 1;
            
            while (left_g <= right_g) {
                mid_g = (left_g + right_g) / 2;
                if (g_positions[mid_g] == b_position) {
                    break;
                } else if (g_positions[mid_g] < b_position) {
                    left_g = mid_g + 1;
                } else {
                    right_g = mid_g - 1;
                }
            }
            mid_g = (left_g + right_g) / 2;
            
            for (long k = mid_g; k < g_positions.length; k++) {
                g_position = g_positions[k];
                
                if (r_position >= b_position || b_position >= g_position) {
                    continue;
                }
                if (b_position - r_position == g_position - b_position) {
                    continue;
                }
                
                total_count++;
            }
        }
    }

    // GRB, GBR
    for (long i = 0; i < g_positions.length; i++) {
        g_position = g_positions[i];
        
        left_r = 0;
        right_r = r_positions.length - 1;
        
        while (left_r <= right_r) {
            mid_r = (left_r + right_r) / 2;
            if (r_positions[mid_r] == g_position) {
                break;
            } else if (r_positions[mid_r] < g_position) {
                left_r = mid_r + 1;
            } else {
                right_r = mid_r - 1;
            }
        }
        mid_r = (left_r + right_r) / 2;
        
        for (long j = mid_r; j < r_positions.length; j++) {
            r_position = r_positions[j];
            
            left_b = 0;
            right_b = b_positions.length - 1;
            
            while (left_b <= right_b) {
                mid_b = (left_b + right_b) / 2;
                if (b_positions[mid_b] == r_position) {
                    break;
                } else if (b_positions[mid_b] < r_position) {
                    left_b = mid_b + 1;
                } else {
                    right_b = mid_b - 1;
                }
            }
            mid_b = (left_b + right_b) / 2;
            
            for (long k = mid_b; k < b_positions.length; k++) {
                b_position = b_positions[k];
                
                if (g_position >= r_position || r_position >= b_position) {
                    continue;
                }
                if (r_position - g_position == b_position - r_position) {
                    continue;
                }
                
                total_count++;
            }
        }
        
        left_b = 0;
        right_b = b_positions.length - 1;
        
        while (left_b <= right_b) {
            mid_b = (left_b + right_b) / 2;
            if (b_positions[mid_b] == g_position) {
                break;
            } else if (b_positions[mid_b] < g_position) {
                left_b = mid_b + 1;
            } else {
                right_b = mid_b - 1;
            }
        }
        mid_b = (left_b + right_b) / 2;
        
        for (long j = mid_b; j < b_positions.length; j++) {
            b_position = b_positions[j];
            
            left_r = 0;
            right_r = r_positions.length - 1;
            
            while (left_r <= right_r) {
                mid_r = (left_r + right_r) / 2;
                if (r_positions[mid_r] == b_position) {
                    break;
                } else if (r_positions[mid_r] < b_position) {
                    left_r = mid_r + 1;
                } else {
                    right_r = mid_r - 1;
                }
            }
            mid_r = (left_r + right_r) / 2;
            
            for (long k = mid_r; k < r_positions.length; k++) {
                r_position = r_positions[k];
                
                if (g_position >= b_position || b_position >= r_position) {
                    continue;
                }
                if (b_position - g_position == r_position - b_position) {
                    continue;
                }
                
                total_count++;
            }
        }
    }

    // BRG, BGR
    for (long i = 0; i < b_positions.length; i++) {
        b_position = b_positions[i];
        
        left_r = 0;
        right_r = r_positions.length - 1;
        
        while (left_r <= right_r) {
            mid_r = (left_r + right_r) / 2;
            if (r_positions[mid_r] == b_position) {
                break;
            } else if (r_positions[mid_r] < b_position) {
                left_r = mid_r + 1;
            } else {
                right_r = mid_r - 1;
            }
        }
        mid_r = (left_r + right_r) / 2;
        
        for (long j = mid_r; j < r_positions.length; j++) {
            r_position = r_positions[j];
            
            left_g = 0;
            right_g = g_positions.length - 1;
            
            while (left_g <= right_g) {
                mid_g = (left_g + right_g) / 2;
                if (g_positions[mid_g] == r_position) {
                    break;
                } else if (g_positions[mid_g] < r_position) {
                    left_g = mid_g + 1;
                } else {
                    right_g = mid_g - 1;
                }
            }
            mid_g = (left_g + right_g) / 2;
            
            for (long k = mid_g; k < g_positions.length; k++) {
                g_position = g_positions[k];
                
                if (b_position >= r_position || r_position >= g_position) {
                    continue;
                }
                if (r_position - b_position == g_position - r_position) {
                    continue;
                }
                
                total_count++;
            }
        }
        
        left_g = 0;
        right_g = g_positions.length - 1;
        
        while (left_g <= right_g) {
            mid_g = (left_g + right_g) / 2;
            if (g_positions[mid_g] == b_position) {
                break;
            } else if (g_positions[mid_g] < b_position) {
                left_g = mid_g + 1;
            } else {
                right_g = mid_g - 1;
            }
        }
        mid_g = (left_g + right_g) / 2;
        
        for (long j = mid_g; j < g_positions.length; j++) {
            g_position = g_positions[j];
            
            left_r = 0;
            right_r = r_positions.length - 1;
            
            while (left_r <= right_r) {
                mid_r = (left_r + right_r) / 2;
                if (r_positions[mid_r] == g_position) {
                    break;
                } else if (r_positions[mid_r] < g_position) {
                    left_r = mid_r + 1;
                } else {
                    right_r = mid_r - 1;
                }
            }
            mid_r = (left_r + right_r) / 2;
            
            for (long k = mid_r; k < r_positions.length; k++) {
                r_position = r_positions[k];
                
                if (b_position >= g_position || g_position >= r_position) {
                    continue;
                }
                if (g_position - b_position == r_position - g_position) {
                    continue;
                }
                
                total_count++;
            }
        }
    }
    
    writeln(total_count);
}
