Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02936 (python)

Fixed submission:
import sys

N, Q = map(int, input().split())

E = [[] for _ in range(N + 1)]
X = [0 for _ in range(N + 1)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())
    X[p] += x

stack = [1]
visited = [False for _ in range(N + 1)]
visited[1] = True

while stack:
    i = stack.pop()
    for j in E[i]:
        if visited[j]:
            continue
        visited[j] = True
        stack.append(j)
        X[j] += X[i]

print(*X[1:])

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())

E = [[] for _ in range(N + 1)]
X = [0 for _ in range(N + 1)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())
    X[p] += x

visited = [False for _ in range(N + 1)]
visited[1] = True


def add(i, val):
    X[i] += val
    for to in E[i]:
        if visited[to]:
            continue
        visited[to] = True
        add(to, X[i])


add(1, 0)

print(*X[1:])
Problem p02981 (python)

Fixed submission:
N, A, B = map(int, input().split())
print(min(N * A, B))

Buggy submission (verdict: Runtime Error):
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: usize,
        b: usize
    }

    println!("{}", std::cmp::min(n * a, b))
}
Problem p02999 (python)

Fixed submission:
X, A = map(int, input().split())
print(0 if X < A else 10)

Buggy submission (verdict: Runtime Error):
X, A = map(int, input.split())
print(0 if X < A else 10)
Problem p03060 (python)

Fixed submission:
_ = input()
V = list(map(int, input().split()))
C = list(map(int, input().split()))

print(sum(map(lambda p: max(0, p[0] - p[1]), zip(V, C))))

Buggy submission (verdict: Runtime Error):
N = _
V = list(map(int, input().split()))
C = list(map(int, input().split()))

print(sum(map(lambda p: max(0, p[0] - p[1]), zip(V, C))))
Problem p03068 (python)

Fixed submission:
from functools import reduce

N = int(input())
S = input()
K = int(input()) - 1

print(reduce(lambda x, y: x + (y if y == S[K] else '*'), S, ''))

Buggy submission (verdict: Runtime Error):
from functools import reduce

N = int(input())
S = input()
K = int(input())

print(reduce(lambda x, y: x + (y if y == S[K] else '*'), S, ''))
Problem p03089 (python)

Fixed submission:
N = int(input())
B = list(map(int, input().split()))

res = []

while len(B) > 0:
    p = -1
    for i, b in enumerate(B[::-1]):
        j = len(B) - i
        if b == j:
            p = j
            break
    if p == -1:
        print(-1)
        exit()
    else:
        res.append(p)
        B.pop(p - 1)

for r in res[::-1]:
    print(r)

Buggy submission (verdict: Runtime Error):
N = int(input())
B = list(map(int, input().split()))

res = []

while len(B) > 0:
    for i, b in enumerate(B[::-1]):
        j = len(B) - i
        if b == j:
            res.append(j)
            B.pop(j - 1)
            break
    else:
        print(-1)
        exit()1

for r in res[::-1]:
    print(r)

Buggy submission (verdict: Runtime Error):
from itertools import groupby

S = list(input())
K = int(input())

N = len(S)

if len(set(list(S))) == 1:
    print(N * K // 2)
else:
    G = list(map(lambda g: len(list(g[1])) // 2, (groupby(S))))
    cnt = sum(G)

    if S[0] != S[N - 1]:
        print(cnt * K)
    else:
        a = G[0]
        b = G[-1]
        print(cnt * K - (a // 2 - b // 2 + (a + b) // 2) * (K - 1))

Buggy submission (verdict: Runtime Error):
from itertools import groupby

S = list(input())
K = int(input())

N = len(S)

if len(set(list(S))) == 1:
    print(N * K // 2)
else:
    G = list(map(lambda g: len(list(g[1])) // 2, (groupby(S))))
    cnt = sum(G)

    if S[0] != S[N - 1]:
        print(cnt * K)
    else:
        a = G[0]
        b = G[-1]
        print(cnt * K - (a // 2 - b // 2 + (a + b) // 2) * K - 1)
Problem p03196 (python)

Fixed submission:
N, P = map(int, input().split())

if N == 1:
    print(P)
    exit()

div = 2
res = 1
R = P

while div * div <= R and div <= P:
    cnt = 0
    while P % div == 0:
        P /= div
        cnt += 1

        if cnt == N:
            res *= div
            cnt = 0
    div += 1

print(res)

Buggy submission (verdict: Runtime Error):
N, P = map(int, input().split())

res = 1
i = 2

if N == 1:
    print(P)
    exit()

while True:
    if i > P ** (1 / N) + 1:
        break
    if P % pow(i, N) == 0:
        res = i

    i += 1

print(res)

Buggy submission (verdict: Runtime Error):
import numpy as np

N, P = map(int, input().split())

res = 1
i = 1

if N == 1:
    print(P)
    exit()

while True:
    t = np.power(i, N)

    if t > P:
        break
    if P % t == 0:
        res = i

    i += 1

print(res)

Buggy submission (verdict: Runtime Error):
N, P = map(int, input().split())

res = 1
i = 1

if N == 1:
    print(P)
    exit()

while i ** N <= P:
    if P % i ** N == 0:
        res = i

    i += 1

print(res)
Problem p03206 (python)

Fixed submission:
print('Christmas' + ' Eve' * (25 - int(input())))

Buggy submission (verdict: Runtime Error):
print('Christmas' + ' Eve' * (25) - int(input()))

Buggy submission (verdict: Runtime Error):
print('Christmas' + ' Eve' * (int(input()) - D))
Problem p03240 (python)

Fixed submission:
N = int(input())
query = [list(map(int, input().split())) for _ in range(N)]


def isvalid(i, j):
    H = -1
    for p, q, h in query:
        if h != 0:
            H = h + abs(p - i) + abs(q - j)
            break

    for p, q, h in query:
        if H == -1 and h != 0:
            H = h + abs(p - i) + abs(q - j)

        if h != max(H - abs(p - i) - abs(q - j), 0):
            return -1
    return H


for i in range(101):
    for j in range(101):
        H = isvalid(i, j)
        if H >= 1:
            print(i, j, H)
            exit()

Buggy submission (verdict: Runtime Error):
N = int(input())
query = [list(map(int, input().split())) for _ in range(N)]


def isvalid(i, j):
    p, q, h = query[0]
    H = h + abs(p - i) + abs(q - j)
    if H < 1:
        return -1
    for que in query[1:]:
        p, q, h = que
        if h != max(H - abs(p - i) - abs(q - j)):
            return -1
    return H


for i in range(101):
    for j in range(101):
        H = isvalid(i, j)
        if H != -1:
            print(i, j, H)
            exit()
Problem p03308 (python)

Fixed submission:
N = int(input())
A = sorted(map(int, input().split()))

print(A[N-1] - A[0])

Buggy submission (verdict: Runtime Error):
N = int(input())
A = sorted([int(input()) for _ in range(N)])

print(A[N-1] - A[0])
Problem p03411 (python)

Fixed submission:
from collections import namedtuple

Point = namedtuple('Point', ['x', 'y'])
# Edge = namedtuple('Edge', ['from', 'to'])

N = int(input())

R = []
for _ in range(N):
    x, y = map(int, input().split())
    R.append(Point(x, y))

B = []
for _ in range(N):
    x, y = map(int, input().split())
    B.append(Point(x, y))

E = [[] for _ in range(N)]
for i, r in enumerate(R):
    for j, b in enumerate(B):
        if r.x < b.x and r.y < b.y:
            E[i].append(j)

match = [-1 for _ in range(N)]


def dfs(v: int, visited: set) -> bool:
    for u in E[v]:
        if u in visited:
            continue
        visited.add(u)

        if match[u] == -1 or dfs(match[u], visited):
            match[u] = v
            return True
    return False


def bipartite_matching():
    return sum(dfs(i, set()) for i in range(N))


print(bipartite_matching())

Buggy submission (verdict: Runtime Error):
from collections import namedtuple

Point = namedtuple('Point', ['x', 'y'])

N = int(input())

R = []
for _ in range(N):
    x, y = map(int, input().split())
    R.append(Point(x, y))

B = []
for _ in range(N):
    x, y = map(int, input().split())
    B.append(Point(x, y))

E = [[] for _ in range(N)]
for i, r in enumerate(R):
    for j, b in enumerate(B):
        if r.x < b.x and r.y < b.y:
            E[i].append(j)


class BipartiteMatching:
    def __init__(self, max_u: int, max_v: int, edges):
        self.max_u = max_u
        self.max_v = max_v
        self.edges = edges  # u->vの隣接行列
        self.__match = None

    def dfs(self, v: int, visited: set) -> bool:
        for u in self.edges[v]:
            if u in visited:
                continue
            visited.add(u)

            if self.__match[u] == -1 or self.dfs(self.__match[u], visited):
                self.__match[u] = v
                return True
        return False

    def execute(self):
        self.__match = [-1 for _ in range(self.max_u)]
        return sum(self.dfs(u, set()) for u in range(self.max_u))


print(BipartiteMatching(N, E).execute())
Problem p03425 (python)

Fixed submission:
m, a, r, c, h = [0] * 5

N = int(input())

for _ in range(N):
    s = input()[0]

    if s == 'M':
        m += 1
    elif s == 'A':
        a += 1
    elif s == 'R':
        r += 1
    elif s == 'C':
        c += 1
    elif s == 'H':
        h += 1
print(m * a * r + 
      m * a * c +
      m * a * h + 
      m * r * c + 
      m * r * h + 
      m * c * h + 
      a * r * c + 
      a * r * h +
      a * c * h +
      r * c * h)

Buggy submission (verdict: Runtime Error):
m,a,r,c,h = [0,0,0,0,0]
N = int(input())

for i in range(N):
Problem p03456 (python)

Fixed submission:
k = int(input().replace(' ', '')) ** (1 / 2)
print('Yes' if int(k) == k else 'No')

Buggy submission (verdict: Runtime Error):
k = int(input().replace(' ', '')) ** (1 / 2)
print('Yes' if int(k) ** int(k) == k ** k else 'No')

Buggy submission (verdict: Runtime Error):
N = input()

print('Yes' if sum(map(int, list(N))) % int(N) == 0 else 'No')
Problem p03547 (python)

Fixed submission:
X, Y = input().split()
print('<' if X < Y else ('>' if X > Y else '='))

Buggy submission (verdict: Runtime Error):
print('<' if input() < input() else '>')
Problem p03555 (python)

Fixed submission:
print('YES' if input() == input()[::-1] else 'NO')

Buggy submission (verdict: Runtime Error):
print('YES' if input() == input()[::-1])
Problem p03594 (python)

Fixed submission:

H, W, d = map(int, input().split())

ret = [['RGBY'[(i + j) // d % 2 + (i - j) // d % 2 * 2] for j in range(W)] for i in range(H)]

for a in ret:
    print(''.join(a))

Buggy submission (verdict: Runtime Error):
import sys

H, W, d = map(int, input().split())

color = 'RGBY'
ret = [['' for _ in range(W)] for _ in range(H)]
flag = [[0b1111 for _ in range(W)] for _ in range(H)]

for i in range(H):
    for j in range(W):
        for k in range(4):
            if flag[i][j] & 2 ** k:
                flag[i][j] &= ~(2 ** k)
                ret[i][j] = color[k]

                for p in range(d + 1):
                    q = d - p

                    if i - p >= 0 and j - q >= 0: flag[i - p][j - q] &= ~(2 ** k)
                    if i + p < H and j + q < W: flag[i + p][j - q] &= ~(2 ** k)
                    if i - p >= i and j - q >= 0: flag[i - p][j + q] &= ~(2 ** k)
                    if i + p < H and j + q < W: flag[i + p][j + q] &= ~(2 ** k)
                break

for a in ret:
    print(''.join(a))

Buggy submission (verdict: Runtime Error):
import sys

H, W, d = map(int, input().split())

color = 'RGBY'
ret = [['' for _ in range(W)] for _ in range(H)]
flag = [[0b1111 for _ in range(W)] for _ in range(H)]

for i in range(H):
    for j in range(W):
        for k in range(4):
            if flag[i][j] & 2 ** k:
                flag[i][j] &= ~(2 ** k)
                ret[i][j] = color[k]

                for p in range(d + 1):
                    q = d - p

                    if p >= i and q >= j: flag[i - p][j - q] &= ~(2 ** k)
                    if p < H - i and q >= j: flag[i + p][j - q] &= ~(2 ** k)
                    if p >= i and q < W - j: flag[i - p][j + q] &= ~(2 ** k)
                    if p < H - i and q < W - j: flag[i + p][j + q] &= ~(2 ** k)
                break

        # なにも入らなかった
        if ret[i][j] is '':
            print('hoge')

for a in ret:
    print(''.join(a))

Buggy submission (verdict: Runtime Error):
import sys

H, W, d = map(int, input().split())

color = 'RGBY'
ret = [['' for _ in range(W)] for _ in range(H)]
flag = [[[True, True, True, True] for _ in range(W)] for _ in range(H)]

for i in range(H):
    for j in range(W):
        for k in range(4):
            if flag[i][j][k]:
                ret[i][j] = color[k]

                for p in range(d + 1):
                    q = d - p

                    if p >= i and q >= j: flag[i - p][j - q][k] = False
                    if p < H - i and q >= j: flag[i + p][j - q][k] = False
                    if p >= i and q < W - j: flag[i - p][j + q][k] = False
                    if p < H - i and q < W - j: flag[i + p][j + q][k] = False
                break

        # なにも入らなかった
        if ret[i][j] is '':
            print('hoge')

print(ret, file=sys.stderr)

for a in ret:
    print(''.join(a))
Problem p03612 (python)

Fixed submission:
N = int(input())
P = list(map(int, input().split()))

res = 0
for i in range(N):
    if P[i] == i + 1:
        res += 1
        if i < N - 1:
            P[i], P[i + 1] = P[i + 1], P[i]

print(res)

Buggy submission (verdict: Runtime Error):
N = int(input())
P = list(map(int, input().split()))

res = 0
for i in range(N):
    if P[i] == i + 1:
        res += 1
        if i < N:
            P[i], P[i + 1] = P[i + 1], P[i]

print(res)

Buggy submission (verdict: Runtime Error):
N = int(input())
P = list(map(int, input().split()))

res = 0
for i in range(N):
    if P[i] == i + 1:
        res += 1
        P[i], P[i + 1] = P[i + 1], P[i]

print(res)
Problem p03624 (python)

Fixed submission:
import string
S = input()
for a in string.ascii_lowercase:
    if a not in S:
        print(a)
        exit(0)
print('None')

Buggy submission (verdict: Runtime Error):
import string
S = input()
for a in string.ascii_lowercase:
    if a not in S:
        print(a)
        exit(1)
print('None')
Problem p03643 (python)

Fixed submission:
print('ABC' + input())

Buggy submission (verdict: Runtime Error):
print(f'ABC' + input())
Problem p03722 (python)

Fixed submission:
import math

INF = float("inf")

V, E = map(int, input().split())
es = []

for _ in range(E):
    a, b, c = map(int, input().split())
    es.append([a-1, b-1, -c])

d = [INF] * V
d[0] = 0
cnt = [0] * V

for _ in range(V):
    updated = False
    for e in es:
        if math.isinf(d[e[0]]):
            continue
        if d[e[1]] > d[e[0]] + e[2]:
            d[e[1]] = d[e[0]] + e[2]
            cnt[e[1]] += 1
            updated = True
    if not updated:
        break

print(-d[V-1] if cnt[V-1] < V else "inf")

Buggy submission (verdict: Runtime Error):
import math

INF = float("inf")

V, E = map(int, input().split())
es = []

for _ in range(E):
    a, b, c = map(int, input().split())
    es.append([a-1, b-1, -c])

d = [INF] * V
d[1] = 0

for _ in range(V - 1):
    updated = False
    for e in es:
        if math.isinf(d[e[0]]):
            continue
        if d[e[1]] > d[e[0]] + e[2]:
            d[e[1]] = d[e[0]] + e[2]
            updated = True
    if not updated:
        break

negative = [False] * V

for _ in range(V):
    for e in es:
        if math.isinf(d[e[0]]):
            continue
        if d[e[1]] > d[e[0]] + e[2]:
            negative[e[1]] = True
            d[e[1]] = d[e[0]] + e[2]
        elif negative[e[1]]:
            d[e[1]] = True
print(-d[V] if not negative[V] else "inf")

Buggy submission (verdict: Runtime Error):
import math

INF = float("inf")

V, E = map(int, input().split())
es = []

for _ in range(E):
    a, b, c = map(int, input().split())
    es.append([a-1, b-1, -c])

d = [INF] * V
d[1] = 0

updated = False
for _ in range(V - 1):
    for e in es:
        if math.isinf(d[e[0]]):
            continue
        if d[e[1]] > d[e[0]] + e[2]:
            d[e[1]] = d[e[0]] + e[2]
    if not updated:
        break

negative = [False] * V

for _ in range(V):
    for e in es:
        if math.isinf(d[e[0]]):
            continue
        if d[e[1]] > d[e[0]] + e[2]:
            negative[e[1]] = True
            d[e[1]] = d[e[0]] + e[2]
        elif negative[e[1]]:
            d[e[1]] = True
print(-d[V] if not negative[V] else "inf")
Problem p03860 (python)

Fixed submission:
S = input()
print('A' + S[8] + 'C')

Buggy submission (verdict: Runtime Error):
S = input().split()
print('A' + S[8] + 'C')
Problem p03861 (python)

Fixed submission:
a, b, x = map(int, input().split())
print(b // x - (a - 1) // x)

Buggy submission (verdict: Runtime Error):
print('A' + input()[8] + 'C')
Problem p04030 (python)

Fixed submission:
S = input()
ret = []
for s in S:
    if s == 'B':
        if len(ret):
            ret.pop()
    else:
        ret.append(s)
print(''.join(ret))

Buggy submission (verdict: Runtime Error):
S = input()
ret = []
for s in S:
    if s == 'B' and len(s):
        ret.pop()
    else:
        ret.append(s)
print(''.join(ret))
Problem p02618 (python)

Fixed submission:
import random as ra
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(D)]
for i in range(D):
    print(ra.randint(1,26))

Buggy submission (verdict: Runtime Error):





import random as ra
import copy
import time

start_time = time.time()

D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(D)]

### 得点計算用
#t = [int(input()) for i in range(D)]
def cal_point(t):
    score = 0
    last = [0]*26
    for d in range(D):
        score += s[d][t[d]-1]
        last[t[d]-1] = d+1
        for i in range(26):
            score -= c[i]*(d+1-last[i])
    #print(score)
    return score


t = []
last = [0]*26
for i in range(D):
    opt1 = s[i].index(max(s[i]))+1
    opt2 = last.index(min(last))+1
    if ra.random()<0.5:
        t.append(opt1)
        last[opt1] = i+1
    else:
        t.append(opt2)
        last[opt2] = i+1


#t = [ra.randint(1,26) for i in range(D)]
max_score = 0
optimal_t = copy.deepcopy(t)
#M = 10**5
while (time.time()-start_time)<1.95:
#for i in range(M):
    d = ra.randint(1,D)
    q = ra.randint(1,26)
    td = t[d-1]
    t[d-1] = q
    now = cal_point(t)
    if now > max_score:
        optimal_t = copy.deepcopy(t)
        max_score = now
    else:
        t[d-1] = td

print(*optimal_t,sep='\n')
Problem p02702 (python)

Fixed submission:
import sys, copy, math, heapq, bisect
from itertools import accumulate
from collections import deque, defaultdict, Counter
sys.setrecursionlimit(500000)

S = list(input())[::-1]
N = len(S)
D = [1]
for i in range(N):
    D.append(D[-1]*10%2019)
M = [(int(S[i])*D[i])%2019 for i in range(N)]
SS = [M[0]]
for i in range(1,N):
    SS.append((SS[-1]+M[i])%2019)
count = [0]*2019
for i in range(N):
    count[SS[i]] += 1

ans = 0
for c in range(len(count)):
    if c==0:
        ans += count[c]
    ans += (count[c] * (count[c] - 1)) // 2

print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
k=2019
s=list(map(int,list(input())))
ans=0
if k==2 or k==5:
    for i,p in enumerate(s):
        if p%k==0:
            ans+=i+1
else:
    inv10=pow(10,k-2,k)
    inv=10
    total=0
    S=[0]*k
    S[0]=1
    for i,p in enumerate(s):
        inv*=inv10
        inv%=k
        total+=p*inv
        total%=k
        ans+=S[total]
        S[total]+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
k=2019
s=list(input())
ans=0
if k==2 or k==5:
    for i,p in enumerate(s):
        if p%k==0:
            ans+=i+1
else:
    inv10=pow(10,k-2,k)
    inv=10
    total=0
    S=[0]*k
    S[0]=1
    for i,p in enumerate(s):
        inv*=inv10
        inv%=k
        total+=p*inv
        total%=k
        ans+=S[total]
        S[total]+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
k=2019
s=map(int,list(input()))
ans=0
if k==2 or k==5:
    for i,p in enumerate(s):
        if p%k==0:
            ans+=i+1
else:
    inv10=pow(10,k-2,k)
    inv=10
    total=0
    S=[0]*k
    S[0]=1
    for i,p in enumerate(s):
        inv*=inv10
        inv%=k
        total+=p*inv
        total%=k
        ans+=S[total]
        S[total]+=1
print(ans)
Problem p02714 (python)

Fixed submission:

"""
K = int(input())

def gcd(a, b): # 最大公約数
    a = abs(a)
    b = abs(b)
    while b:
        a, b = b, a % b
    return a # int
ans = 0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            d = gcd(gcd(i,j),k)
            if i==j==k:
                ans += d
            elif i==j or j== k or k==i:
                ans += 3*d
            else:
                ans += 6*d
print(ans)
"""
N = int(input())
S = input()
R = []
G = []
B = []
import bisect
for i in range(N):
    if S[i] == 'R':
        R.append(i)
    elif S[i] == 'G':
        G.append(i)
    else:
        B.append(i)
ans = 0
for rr in R:
    for gg in G:
        
        r = min(rr,gg)
        g = max(rr,gg)
        if 2*r-g>=0:
            id = bisect.bisect_left(B,2*r-g)
            if id < len(B) and 2*r-g == B[id]:
                ans -=1
        
        if 2*g-r < N:
            id = bisect.bisect_left(B,2*g-r)
            if id < len(B) and 2*g-r == B[id]:
                ans -=1
        
        if (g+r)%2==0:
            id = bisect.bisect_left(B,(g+r)//2)
            if id < len(B) and (g+r)//2 == B[id]:
                ans -= 1
        ans += len(B)
        
print(ans)

Buggy submission (verdict: Runtime Error):

"""
K = int(input())

def gcd(a, b): # 最大公約数
    a = abs(a)
    b = abs(b)
    while b:
        a, b = b, a % b
    return a # int
ans = 0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            d = gcd(gcd(i,j),k)
            if i==j==k:
                ans += d
            elif i==j or j== k or k==i:
                ans += 3*d
            else:
                ans += 6*d
print(ans)
"""
N = int(input())
S = input()
R = []
G = []
B = []
import bisect
for i in range(N):
    if S[i] == 'R':
        R.append(i)
    elif S[i] == 'G':
        G.append(i)
    else:
        B.append(i)
ans = 0
for rr in R:
    for gg in G:
        
        r = min(rr,gg)
        g = max(rr,gg)
        if 2*r-g>=0:
            if 2*r-g == B[bisect.bisect_left(B,2*r-g)]:
                ans -=1
        
        if 2*g-r < N:
            #print(rr,gg,bisect.bisect_left(B,2*g-r))
            if 2*g-r == B[bisect.bisect_left(B,2*g-r)]:
                ans -=1
        
        if (g+r)%2==0 and (g+r)//2 == B[bisect.bisect_left(B,(g+r)//2)]:
            ans -= 1
        ans += len(B)
        
print(ans)