Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

A = list(map(int, input().split()))

C = list(set(A))

B = len(C) 

x = B - K

ans = 0

figure_list = [0] * B

if x<=0:
    print('0')
else:
    for i in range(B):
        stock = int(C[i])
        counter = 0
        for ii in range(N):
            if stock == A[ii]:
                counter += 1
        figure_list[i] = counter

    figure_list = sorted(figure_list)

    for i in range(B-K):
        ans += figure_list[i]

    print(ans)    

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

A = list(map(int, input().split()))

C = list(set(A))

B = len(C) 
x = B - K

d = {}

for i in A:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1

d = sorted(d.items(), key=lambda x:x[1])

ans = 0
count = 0

if x<=0:
    print('0')
else:
    for key, value in d:
        ans = ans + value
        count = count + 1
        if count == x:
            print(ans)
            break

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

A = list(map(int, input().split()))

C = list(set(A))

B = len(C) 

x = B - K

ans = 0

figure_list = [0] * B

if x<=0:
    print('0')
else:
    for i in range(B):
        stock = int(C[i])
        counter = 0
        for ii in range(N):
            if stock == A[ii]:
                counter += 1
        figure_list[i] = counter

    figure_list = sorted(figure_list)

    for i in range(B-K):
        ans += figure_list[i]

    print(ans)    

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

A = list(map(int, input().split()))

C = list(set(A))

B = len(C) 
x = B - K

d = {}

for i in A:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1

d = sorted(d.items(), key=lambda x:x[1])

ans = 0
count = 0

if x<=0:
    print('0')
else:
    for key, value in d:
        ans = ans + value
        count = count + 1
        if count == x:
            print(ans)
            break
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())

ans1 = 0

A = '1'
B = str(N)

if len(A)>=len(B):
    ans = len(A)
else:
    ans = len(B)
    
for i in range(2,int(math.sqrt(N)+1):
    A = i
    if N%A==0:
        B = int(N / A)
        A = str(A)
        B = str(B)
        if len(A)>=len(B):
            ans1 = len(A)
        else:
            ans1 = len(B)
        if ans1 <= ans:
            ans = ans1
    if len(str(A))==len(str(B)):
        break
print(ans)


Fixed submission:
import math

N = int(input())

ans1 = 0

A = '1'
B = str(N)

if len(A)>=len(B):
    ans = len(A)
else:
    ans = len(B)
    
for i in range(2,int(math.sqrt(N))+1):
    A = i
    if N%A==0:
        B = int(N / A)
        A = str(A)
        B = str(B)
        if len(A)>=len(B):
            ans1 = len(A)
        else:
            ans1 = len(B)
        if ans1 <= ans:
            ans = ans1
    if len(str(A))==len(str(B)):
        break
print(ans)

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

ans1 = 0

A = '1'
B = str(N)

if len(A)>=len(B):
    ans = len(A)
else:
    ans = len(B)
    
for i in range(2,int(math.sqrt(N)+1):
    A = i
    if N%A==0:
        B = int(N / A)
        A = str(A)
        B = str(B)
        if len(A)>=len(B):
            ans1 = len(A)
        else:
            ans1 = len(B)
        if ans1 <= ans:
            ans = ans1
    if len(str(A))==len(str(B)):
        break
print(ans)


Fixed submission:
import math

N = int(input())

ans1 = 0

A = '1'
B = str(N)

if len(A)>=len(B):
    ans = len(A)
else:
    ans = len(B)
    
for i in range(2,int(math.sqrt(N))+1):
    A = i
    if N%A==0:
        B = int(N / A)
        A = str(A)
        B = str(B)
        if len(A)>=len(B):
            ans1 = len(A)
        else:
            ans1 = len(B)
        if ans1 <= ans:
            ans = ans1
    if len(str(A))==len(str(B)):
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ans1 = 0

A = '1'
B = str(N)

if len(A)>=len(B):
    ans = len(A)
else:
    ans = len(B)
    
for i in range(2,N+1):
    A = i
    if N%A==0:
        B = int(N / A)
        A = str(A)
        B = str(B)
        #print(A, B)
        if len(A)>=len(B):
            ans1 = len(A)
        else:
            ans1 = len(B)
        if ans1 <= ans:
            ans = ans1
    if len(str(A))==len(str(B)):
        break
print(ans)


Fixed submission:
import math

N = int(input())

ans1 = 0

A = '1'
B = str(N)

if len(A)>=len(B):
    ans = len(A)
else:
    ans = len(B)
    
for i in range(2,int(math.sqrt(N))+1):
    A = i
    if N%A==0:
        B = int(N / A)
        A = str(A)
        B = str(B)
        if len(A)>=len(B):
            ans1 = len(A)
        else:
            ans1 = len(B)
        if ans1 <= ans:
            ans = ans1
    if len(str(A))==len(str(B)):
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
words = [input() for i in range(n)]

counter = Counter(words)
fin = [ii[0] for ii in counter.items() if ii[1] == max(counter.values())]

fin.sort()

for jj in fin:
    print(jj)

Fixed submission:
from collections import Counter
n = int(input())
words = [input() for i in range(n)]

counter = Counter(words).most_common()
ans =[]
for i in range(int(len(counter))):
    if counter[0][1] > counter[i][1]:
        break
    ans.append(counter[i][0])
ans.sort()

for i in ans:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
def fennec(n, k):
    if n <= k:
        print("0")
    else:
        hp_list = list(map(int, input().split()))
        i = 1
        while i <= int(k): 
            del hp_list[hp_list.index(max(hp_list))]
            i += 1
        attack = sum(hp_list)
        print(attack)
        
        
n, k = map(int, input().split())
fennec(n, k)


Fixed submission:
def fennec(n, k):
    if n <= k:
        print("0")
    else:
        hp_list = list(map(int, input().split()))
        hp_list.sort()
        attack = 0
        for i in range(int(n) - int(k)):
            attack += hp_list[i]
        print(attack)
        
        
n, k = map(int, input().split())
fennec(n, k)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
perputation = list(map(int, input().split()))
cnt = 1

if n == 1:
    print("1")
else:
    for i in range(1, n):
        if min(perputation[:i]) >= perputation[i]:
            cnt += 1
    print(cnt)

Fixed submission:
n = int(input())
perputation = list(map(int, input().split()))
cnt = 1
last_min = perputation[0]

if n == 1:
    print("1")
else:
    for i in range(1, n):
        if last_min >= perputation[i]:
            cnt += 1
            last_min = perputation[i]
    print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
perputation = list(map(int, input().split()))
cnt = 1

if n == 1:
    print("1")
else:
    for i in range(1, n):
        part = []
        for j in range(i):
            part.append(perputation[j])
        if min(part) >= perputation[i]:
            cnt += 1
    print(cnt)

Fixed submission:
n = int(input())
perputation = list(map(int, input().split()))
cnt = 1
last_min = perputation[0]

if n == 1:
    print("1")
else:
    for i in range(1, n):
        if last_min >= perputation[i]:
            cnt += 1
            last_min = perputation[i]
    print(cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
string1, string2 = input().split(" ")

for i in range(n):
    print(f"{string1[i]}{string2[i]}",end="")

Fixed submission:
n = int(input())
string1, string2 = input().split(" ")

for i in range(n):
    print(string1[i],end="")
    print(string2[i],end="")
Buggy python submission (verdict: Runtime Error):
n = int(input())
lst = list(map(int, input().split()))
ans = [0]*n
ans[0] = lst[0]
for i in range(1, n):
  ans[i] = min(ans[i - 1], lst[i])
print(len(set(ans))

Fixed submission:
n = int(input())
lst = list(map(int, input().split()))
ans = [0]*n
ans[0] = lst[0]
for i in range(1, n):
  ans[i] = min(ans[i - 1], lst[i])
print(len(set(ans)))

Buggy python submission (verdict: Runtime Error):
n = int(input())
lst = map(int, input().split())
ans = [0]*n
ans[0] = lst[0]
for i in range(1, n):
  ans[i] = min(ans[i - 1], lst[i])
print(len(set(ans))

Fixed submission:
n = int(input())
lst = list(map(int, input().split()))
ans = [0]*n
ans[0] = lst[0]
for i in range(1, n):
  ans[i] = min(ans[i - 1], lst[i])
print(len(set(ans)))
Buggy python submission (verdict: Runtime Error):
n, k, s = map(int, input().split())
if k == 0:
  print(' '.join([str(s + 1)]*n))
else:
  first = [str(s)|]*k
  second = [str(s + 1)]*(n - k)
  print(' '.join(first + second))

Fixed submission:
n, k, s = map(int, input().split())
if k == 0:
    if s == 10**9:
        print(' '.join([str(s - 1)]*n))
    else:
        print(' '.join([str(s + 1)]*n))
else:
  first = [str(s)]*k
  if s == 1:
    second = [str(2)]*(n - k)
  else:
    second = [str(max(1, s - 1))]*(n - k)
  print(' '.join(first + second))

Buggy python submission (verdict: Runtime Error):
n, k, s = map(int, input().split())
if k == 0:
  print(' '.join([s + 1]*n))
else:
  first = [s]*k
  second = [s + 1]*(n - k)
  print(' '.join(first + second))

Fixed submission:
n, k, s = map(int, input().split())
if k == 0:
    if s == 10**9:
        print(' '.join([str(s - 1)]*n))
    else:
        print(' '.join([str(s + 1)]*n))
else:
  first = [str(s)]*k
  if s == 1:
    second = [str(2)]*(n - k)
  else:
    second = [str(max(1, s - 1))]*(n - k)
  print(' '.join(first + second))
Buggy python submission (verdict: Runtime Error):
n = int(input())
ret = {}
for i in range(0, n):
    a = int(input())
    ret[i] = [[], []]
    for j in range(a):
        x, y = map(int, input().split())
        x -= 1
        if y == 1:
            ret[i][0].append(x)
        elif y == 0:
            ret[i][1].append(x)

dic = {}


def f(honest_p, honest_list):
    if honest_p in dic:
        return []
    dic[honest_p] = True
    # print('honest_list', honest_p, honest_list)
    if ret[honest_p][0] == []:
        return [honest_p]
    temp = [honest_p] + honest_list
    for i in honest_list:
        temp += f(i, ret[i][0])
    return temp


ans = 0
for i in range(0, n):
    dic = {}
    honest = list(set(f(i, ret[i][0])))
    # print('h', honest)
    dishonest = ret[i][1]
    for a in honest:
        for b in ret[a][1]:
            if b not in dishonest:
                dishonest.append(b)
    # print('d', dishonest)
    dishonest = list(set(dishonest))
    invalid = []
    for j in range(0, n):
        if i == j or j in honest or j in dishonest:
            continue
        val = True
        for k in ret[j][1]:
            if k in honest:
                val = False
        for k in ret[j][0]:
            if k in dishonest:
                val = False
        if not val:
            invalid.append(j)
    # print('invalid', invalid)
    import itertools
    lst = list(itertools.product([0, 1], repeat=n))
    for string in lst:
        string = list(string)
        for j in invalid:
            string[j] = 0
        # print(honest, dishonest, string)
        if not val and list(set(honest) & set(dishonest)) == []:
            # print(string)
            ans = max(ans, string.count(1))
print(ans)


Fixed submission:
n = int(input())
ret = {}
for i in range(0, n):
    a = int(input())
    ret[i] = [[], []]
    for j in range(a):
        x, y = map(int, input().split())
        x -= 1
        if y == 1:
            ret[i][0].append(x)
        elif y == 0:
            ret[i][1].append(x)
 
ans = 0
import itertools
lst = list(itertools.product([0, 1], repeat=n))
for s in lst:
    var = True
    for i in range(len(s)):
        if s[i] == 1:
            for j in ret[i][0]:
                if s[j] != 1:
                    var = False
                    break
            for j in ret[i][1]:
                if s[j] != 0:
                    var = False
                    break
    if var:
        # print(s)
        ans = max(ans, s.count(1))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 1e9 + 7

n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]

dp = [0] * (n+1)
dp[0] = 1
for i in range(1, n+1):
    if i in a:
        continue
    if i > 1:
        dp[i] = (dp[i-1] + dp[i-2]) % MOD
    else:
        dp[i] = dp[i-1]

print(int(dp[n]))


Fixed submission:
MOD = 1e9 + 7

n, m = map(int, input().split())
a = [False] * (n+1)
for i in range(m):
    b = int(input())
    a[b] = True

dp = [0] * (n+1)
dp[0] = 1
for i in range(1, n+1):
    if a[i]:
        continue
    if i > 1:
        dp[i] = (dp[i-1] + dp[i-2]) % MOD
    else:
        dp[i] = dp[i-1]

print(int(dp[n]))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Contents   : ARC D問題
Author     : Kitaura Hiromi
LastUpdate : 20180526
Since      : 20180526
"""
from operator import xor
from functools import reduce

N = int(input())
A = list(map(int, input().split()))
cnt = 0
for i in range(N):
    for j in range(i+1, N+1):

        # print("sum", sum(A[i:j]), "xor",  int(tmp))
        if sum(A[i:j]) == int(reduce(xor, A[i:j])):
            cnt += 1
        else:
            break
print(cnt)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Contents   : ARC D問題
Author     : Kitaura Hiromi
LastUpdate : 20180527
Since      : 20180526
"""
from operator import xor
from functools import reduce

N = int(input())
A = list(map(int, input().split()))

cnt = 0
r = 0
tmp = 0
for l in range(N):
    while r < N and tmp & A[r] == 0:
        # 区間の右端の要素を足す
        tmp ^= A[r]
        r += 1
    # print(l, r)
    cnt += (r - l)
    # 区間の左端の要素を引く
    tmp ^= A[l]
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Contents   : ARC D問題
Author     : Kitaura Hiromi
LastUpdate : 20180526
Since      : 20180526
"""

N = int(input())
A = list(map(int, input().split()))
cnt = 0
for i in range(N):
    for j in range(i+1, N+1):
        tmp = 0
        for k in range(i, j):
            tmp ^= A[k]
        # print("sum", sum(A[i:j]), "xor",  int(tmp))
        if sum(A[i:j]) == int(tmp):
            cnt += 1
        else:
            break
print(cnt)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Contents   : ARC D問題
Author     : Kitaura Hiromi
LastUpdate : 20180527
Since      : 20180526
"""
from operator import xor
from functools import reduce

N = int(input())
A = list(map(int, input().split()))

cnt = 0
r = 0
tmp = 0
for l in range(N):
    while r < N and tmp & A[r] == 0:
        # 区間の右端の要素を足す
        tmp ^= A[r]
        r += 1
    # print(l, r)
    cnt += (r - l)
    # 区間の左端の要素を引く
    tmp ^= A[l]
print(cnt)
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split(" "))
cnt = 0

if (A%2 == B%2) and (B%2 == C%2):
    pass
else:
    if A%2 == B%2:
        A += 1
        B += 1
        cnt += 1
    elif A%2 == C%2:
        A += 1
        C += 1
        cnt += 1
    else:
        B += 1
        C += 1
        cnt += 1

ABC = sorted([A, B, C])
cnt += (ABC[0] - ABC[1]) / 2
cnt += (ABC[0] - ABC[2]) / 2
print cnt

Fixed submission:
A, B, C = map(int, input().split(" "))
cnt = 0

if (A%2 == B%2) and (B%2 == C%2):
    pass
else:
    if A%2 == B%2:
        A += 1
        B += 1
        cnt += 1
    elif A%2 == C%2:
        A += 1
        C += 1
        cnt += 1
    else:
        B += 1
        C += 1
        cnt += 1

ABC = sorted([A, B, C])
cnt += (ABC[2] - ABC[1]) // 2
cnt += (ABC[2] - ABC[0]) // 2
print(cnt)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Regular Contest094 e問題 未完成
Author     : Kitaura Hiromi
LastUpdate : 20180420
Since      : 20180414
"""

# 最終的に, 1組以外はすべて0になる

N = int(input())
queA = []
queB = []
for i in range(N):
    A, B = map(int, input().split(" "))
    queA.append(A)
    queB.append(B)

cnt = 0
if np.allclose(queA, queB):
    print(cnt)
    return 0
else:
    tmp = []
    for i, B in enumerate(queB):
        if queA[i] > B:
            tmp.append(B)
    print(sum(queA) - min(tmp))

Fixed submission:
# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Regular Contest094 e問題 未完成
Author     : Kitaura Hiromi
LastUpdate : 20180420
Since      : 20180414
"""
inf = 10**20
# 最終的に, 1組以外はすべて0になる
N = int(input())
s = 0
m = inf
for i in range(N):
    a, b = map(int, input().split(" "))
    if a > b:
        if m > b:
            m = b
    s += a
if m == inf:
    print(0)
else:
    print(s - m)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, C = map(int, input().split(' '))
s = []
t = []
c = []
for i in range(N):
    s_i, t_i, c_i = map(int, input().split(' '))
    s.append(s_i)
    t.append(t_i)
    c.append(c_i - 1)
T = 2*max(t)
table = np.zeros(T)
for i in range(C):
    table_i = np.zeros(T)
    for j in range(N):
        if c[j] == i:
            table_i[2*s[j]-1: 2*t[j]] += 1
    table += list(map(lambda x: 1 if x>0 else 0, table_i))
print(int(np.max(table)))

Fixed submission:
import numpy as np

import numpy as np

N, C = map(int, input().split(' '))
s = []
t = []
c = []
for i in range(N):
    s_i, t_i, c_i = map(int, input().split(' '))
    s.append(s_i)
    t.append(t_i)
    c.append(c_i - 1)
T = 2*max(t)
# for i in range(N):
#     table[2*s[i]-1: 2*t[i]] += 1
table = np.zeros(T)
for i in range(C):
    table_i = np.zeros(T)
    for j in range(N):
        if c[j] == i:
            table_i[2*s[j]-1: 2*t[j]] = 1
    table += table_i
print(int(np.max(table)))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, C = map(int, input().split(' '))
s = []
t = []
for i in range(N):
    s_i, t_i, c_i = map(int, input().split(' '))
    s.append(s_i)
    t.append(t_i)
T = max(t)
table = np.zeros(2*T)
schedule = np.zeros(2*T)
for i in range(N):
    schedule[:] = 0
    schedule[2*s[i]-1: 2*t[i]] = 1
    table += schedule
print(int(np.max(table)))

Fixed submission:
import numpy as np

import numpy as np

N, C = map(int, input().split(' '))
s = []
t = []
c = []
for i in range(N):
    s_i, t_i, c_i = map(int, input().split(' '))
    s.append(s_i)
    t.append(t_i)
    c.append(c_i - 1)
T = 2*max(t)
# for i in range(N):
#     table[2*s[i]-1: 2*t[i]] += 1
table = np.zeros(T)
for i in range(C):
    table_i = np.zeros(T)
    for j in range(N):
        if c[j] == i:
            table_i[2*s[j]-1: 2*t[j]] = 1
    table += table_i
print(int(np.max(table)))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, C = map(int, input().split(' '))
s = []
t = []
c = []
for i in range(N):
    s_i, t_i, c_i = map(int, input().split(' '))
    s.append(s_i)
    t.append(t_i)
    c.append(c_i)
T = max(t)
table = np.zeros(2*T)
for i in range(N):
    schedule = np.zeros(2*T)
    schedule[2*s[i]-1: 2*t[i]] = 1
    table += schedule
print(int(np.max(table)))

Fixed submission:
import numpy as np

import numpy as np

N, C = map(int, input().split(' '))
s = []
t = []
c = []
for i in range(N):
    s_i, t_i, c_i = map(int, input().split(' '))
    s.append(s_i)
    t.append(t_i)
    c.append(c_i - 1)
T = 2*max(t)
# for i in range(N):
#     table[2*s[i]-1: 2*t[i]] += 1
table = np.zeros(T)
for i in range(C):
    table_i = np.zeros(T)
    for j in range(N):
        if c[j] == i:
            table_i[2*s[j]-1: 2*t[j]] = 1
    table += table_i
print(int(np.max(table)))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = list(map(int, input().split()))
AA = list(map(int, input().split()))
A = [0] + AA
DP = [[0 for i in range(N+1)] for k in range(61)]

for i in range(1, N+1):
	DP[0][i]=A[i]
for k in range(1, 61):
    for i in range(1, N+1):
        DP[k][i] = DP[k-1][DP[k-1][i]]

now = 1
for k in range(61):
	if (K>>k) & 1:
		now = DP[k][now]

print(now)

Fixed submission:
N, K = list(map(int, input().split()))
AA = list(map(int, input().split()))
A = [0] + AA
DP = [[0 for i in range(N+1)] for k in range(61)]

for i in range(1, N+1):
	DP[0][i]=A[i]
for k in range(1, 61):
    for i in range(1, N+1):
        DP[k][i] = DP[k-1][DP[k-1][i]]

now = 1
for k in range(61):
	if (K>>k) & 1:
		now = DP[k][now]

print(now)
Buggy python submission (verdict: Runtime Error):
import math
A, B = map(int, input().split())
g = math.gcd(A, B)
ans = (A // g) * B
print(ans)

Fixed submission:
import fractions as f
A, B = map(int, input().split())
g = f.gcd(A, B)
ans = (A // g) * B
print(ans)
Buggy python submission (verdict: Runtime Error):
A = input()
B = input()
ans = 0
tmp = A
while tmp < B:
	ans += 1
	tmp += A-1
print(ans)

Fixed submission:
A, B = map(int, input().split())
print((B-2)//(A-1)+1)
Buggy python submission (verdict: Runtime Error):
a = int(input)
s = input
if a >= 3200:
  print(s)
else:
  print("red")

Fixed submission:
a = int(input())
s = input()
if a >= 3200:
  print(s)
else:
  print("red")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

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

dd = defaultdict(int)
rList = [0]
gList = [0]
bList = [0]
for i in range(N):
    if S[i] == "R":
        rList.append(rList[-1] + 1)
        gList.append(gList[-1])
        bList.append(bList[-1])
    elif S[i] == "G":
        rList.append(rList[-1])
        gList.append(gList[-1] + 1)
        bList.append(bList[-1])
    else:
        rList.append(rList[-1])
        gList.append(gList[-1])
        bList.append(bList[-1] + 1)

ans = 0
for i in range(N):
    for j in range(i, N):
        if S[i] == S[j]:
            continue
        tl = ["R", "G", "B"]
        tl.remove(S[i])
        tl.remove(S[j])
        target = tl[0]
        if target == "R":
            ans += rList[-1] - rList[j + 1]
        elif target == "G":
            ans += gList[-1] - gList[j + 1]
        else:
            ans += bList[-1] - bList[j + 1]

        diff = abs(i - j)
        if j + diff <= N - 1 and S[j + diff] == target:
            ans -= 1

print(ans)


Fixed submission:
from collections import defaultdict

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

dd = defaultdict(int)
rList = [0]
gList = [0]
bList = [0]
for i in range(N):
    if S[i] == "R":
        rList.append(rList[-1] + 1)
        gList.append(gList[-1])
        bList.append(bList[-1])
    elif S[i] == "G":
        rList.append(rList[-1])
        gList.append(gList[-1] + 1)
        bList.append(bList[-1])
    else:
        rList.append(rList[-1])
        gList.append(gList[-1])
        bList.append(bList[-1] + 1)

ans = 0
for i in range(N):
    for j in range(i, N):
        if S[i] == S[j]:
            continue
        tl = ["R", "G", "B"]
        tl.remove(S[i])
        tl.remove(S[j])
        target = tl[0]
        if target == "R":
            ans += rList[-1] - rList[j + 1]
        elif target == "G":
            ans += gList[-1] - gList[j + 1]
        else:
            ans += bList[-1] - bList[j + 1]

        diff = abs(i - j)
        if j + diff <= N - 1 and S[j + diff] == target:
            ans -= 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

N, K = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
dd = defaultdict(int)

ans = 0
for i in range(K, 0, -1):
    dd[i] = (K // i) ** N
    for temp in range(i * 2, K + 1, i):
        dd[i] -= dd[temp]
    ans += dd[i] * i
    ans %= mod
print(ans)


Fixed submission:
from collections import defaultdict

N, K = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
dd = defaultdict(int)

ans = 0
for i in range(K, 0, -1):
    dd[i] = pow(K // i, N, mod)
    for temp in range(i * 2, K + 1, i):
        dd[i] -= dd[temp]
    ans += dd[i] * i
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

N, K = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
dd = defaultdict(int)

ans = 0
for i in range(K, 0, -1):
    dd[i] = (K // i) ** N
    for temp in range(i * 2, K + 1, i):
        dd[i] -= dd[temp]
    ans += dd[i] * i
    ans %= mod
print(ans)


Fixed submission:
from collections import defaultdict

N, K = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
dd = defaultdict(int)

ans = 0
for i in range(K, 0, -1):
    dd[i] = pow(K // i, N, mod)
    for temp in range(i * 2, K + 1, i):
        dd[i] -= dd[temp]
    ans += dd[i] * i
    ans %= mod
print(ans)