Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math


def comb(n, r):
    if n < r or r < 0:
        return 0
    nume = 1
    deno = 1
    for i in range(1, r + 1):
        nume *= (n - i + 1)
        deno *= (i)
    return nume//deno


def solve(N, K):
    if K == 0:
        return 1
    keta = math.floor(math.log(N, 10)) + 1
    x = N//pow(10, keta-1)
    ret = 0
    if K > keta:
        return 0
    # ptn1: 最大の桁は0
    if keta != K:
        ret += comb(keta - 1, K) * (9 ** K)
    # ptn2: 最大の桁はNのその桁の値未満
    ret += (x-1)*comb(keta-1, K-1)*pow(9, K-1)
    # ptn3: 最大の桁はNのその桁の値
    ret += solve(N % pow(10, keta-1), K - 1)
    return ret


N = int(input())
K = int(input())
ans = solve(N, K)
print(ans)


Fixed submission:
import math


def comb(n, r):
    if n < r or r < 0:
        return 0
    nume = 1
    deno = 1
    for i in range(1, r + 1):
        nume *= (n - i + 1)
        deno *= (i)
    return nume//deno


def solve(N, K):
    if N < K:
        return 0
    if K == 0:
        return 1
    keta = math.floor(math.log(N, 10)) + 1
    x = N//pow(10, keta-1)
    ret = 0
    if K > keta:
        return 0
    # ptn1: 最大の桁は0
    if keta != K:
        ret += comb(keta - 1, K) * (9 ** K)
    # ptn2: 最大の桁はNのその桁の値未満
    ret += (x-1)*comb(keta-1, K-1)*pow(9, K-1)
    # ptn3: 最大の桁はNのその桁の値
    ret += solve(N % pow(10, keta-1), K - 1)
    return ret


N = int(input())
K = int(input())
ans = solve(N, K)
print(ans)

Buggy python submission (verdict: Runtime Error):
import math


def comb(n, r):
    if r == 0:
        return 1
    nume = 1
    deno = 1
    for i in range(1, r + 1):
        nume *= (n - i + 1)
        deno *= (i)
    return nume//deno

def solve(N, K):
    if K == 0:
        return 1
    keta = math.floor(math.log(N, 10)) + 1
    x = N//pow(10, keta-1)
    ret = 0
    if K > keta:
        return 0
    # ptn1: 最大の桁は0
    if keta != K:
        ret += comb(keta - 1, K) * (9 ** K)
    # ptn2: 最大の桁はNのその桁の値未満
    ret += (x-1)*comb(keta-1, K-1)*pow(9, K-1)
    # ptn3: 最大の桁はNのその桁の値
    ret += solve(N % pow(10, keta-1), K - 1)
    return ret


N = int(input())
K = int(input())
ans = solve(N, K)
print(ans)


Fixed submission:
import math


def comb(n, r):
    if n < r or r < 0:
        return 0
    nume = 1
    deno = 1
    for i in range(1, r + 1):
        nume *= (n - i + 1)
        deno *= (i)
    return nume//deno


def solve(N, K):
    if N < K:
        return 0
    if K == 0:
        return 1
    keta = math.floor(math.log(N, 10)) + 1
    x = N//pow(10, keta-1)
    ret = 0
    if K > keta:
        return 0
    # ptn1: 最大の桁は0
    if keta != K:
        ret += comb(keta - 1, K) * (9 ** K)
    # ptn2: 最大の桁はNのその桁の値未満
    ret += (x-1)*comb(keta-1, K-1)*pow(9, K-1)
    # ptn3: 最大の桁はNのその桁の値
    ret += solve(N % pow(10, keta-1), K - 1)
    return ret


N = int(input())
K = int(input())
ans = solve(N, K)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys, math


def solve_greedy(N, D, A, XH):
    ret = 0
    for i, (x, h) in enumerate(XH):
        if h <= 0:
            continue
        tmp = math.ceil(h / A)
        ret += tmp
        for j in range(i + 1, N):
            if XH[j][0] > x + 2 * D:
                break
            XH[j][1] -= A * tmp
    return ret


input = sys.stdin.readline
N, D, A = map(int, input().split())
XH = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
ans = solve_greedy(N, D, A, XH)
print(ans)


Fixed submission:
import sys
import math
from collections import deque


def bisect(ng, ok, x, q):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if q[mid][0] >= x:
            ok = mid
        else:
            ng = mid
    return ok


def solve_greedy(N, D, A, XH):
    ret = 0
    q = deque([(0, 0)])
    for i, (x, h) in enumerate(XH):
        if q[-1][0] < x:
            damaged = 0
        else:
            i = bisect(0, len(q) - 1, x, q)
            damaged = q[-1][1] - q[i - 1][1]
            # q = q[i-1:]
        if h <= damaged:
            continue
        tmp = math.ceil((h - damaged) / A)
        ret += tmp
        q.append((x + 2 * D, A * tmp + q[-1][1]))
    return ret


input = sys.stdin.readline
N, D, A = map(int, input().split())
XH = sorted([list(map(int, input().split()))
             for _ in range(N)], key=lambda x: x[0])
ans = solve_greedy(N, D, A, XH)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce


def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


def lcm(l):
    return reduce(lcm_base, l, 1)


N = int(input())
A = list(map(int, input().split()))
P = int(1e9+7)

lcm_a = lcm(A)
ans = 0
for a in A:
    ans = (ans + lcm_a//a) %P
print(ans)


Fixed submission:
import math
from functools import reduce


N = int(input())
A = list(map(int, input().split()))
P = int(1e9+7)

def lcm_base(x, y):
    ret = (x * y) // math.gcd(x, y)
    return ret


def lcm(iter):
    return reduce(lcm_base, iter, 1)


lcm_a = lcm(A) % P
ans = 0
for a in A:
    a_inv = pow(a, P-2, P)
    ans = (ans + lcm_a*a_inv) %P
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
P = int(1e9+7)
ans = 0


def comb(n, r):
    if n < r or r < 0:
        return 0
    nume = 1
    deno = 1
    for i in range(1, r + 1):
        nume *= (n - i + 1)
        deno *= (i)
    return nume//deno


combs=[comb(i, K - 1)%P for i in range(N+1)]

for i, a in enumerate(A):
    ans = (ans + a * combs[i]) % P
    ans = (ans - a * combs[N - i - 1]) % P

print(ans)


Fixed submission:
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
P = int(1e9+7)
ans = 0

kaizyo = [0]
kaizyo_inv = [0]
tmp = 1
for i in range(1, N+1):
    tmp = (tmp*i) % P
    kaizyo.append(tmp)
    kaizyo_inv.append(pow(tmp, P - 2, P))


def comb(n, r):
    if n < r or n == 0:
        return 0
    elif n == r or r == 0:
        return 1
    else:
        return kaizyo[n] * kaizyo_inv[r] * kaizyo_inv[n - r]


combs=[comb(i, K - 1)%P for i in range(N+1)]

for i, a in enumerate(A):
    ans = (ans + a * combs[i]) % P
    ans = (ans - a * combs[N - i - 1]) % P

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
C = sorted(list(map(int, input().split())))
P = int(1e9+7)

ans = 0
for i, c in enumerate(C):
    if i == N - 1:
        ans = (ans + pow(2, i, P) * c)%P
    else:
        ans = (ans + pow(2, i, P) * pow(2, N - i - 2) * (N - i + 1) * c) % P
print((ans*pow(2, N))%P)


Fixed submission:
N = int(input())
C = sorted(list(map(int, input().split())))
P = int(1e9+7)

ans=0
inv2 = pow(2, P-2, P)
powa = inv2
powb = pow(2, N-1, P)
for i, c in enumerate(C):
    powa = (2*powa) % P
    powb = (inv2*powb) % P
    if i == N - 1:
        ans = (ans + powa * c)%P
    else:
        ans = (ans + powa * powb * (N - i + 1) * c) % P
print((ans*pow(2, N))%P)
Buggy python submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline
N = int(input())

def get_id(i, j):
    if j < i:
        i, j = j, i
    return i * N + j

g = [[] for _ in range(N * N)]
S = []
for i in range(N):
    pre = None
    for j in map(int, input().split()):
        j -= 1
        id_ = get_id(i, j)
        if pre is None:
            S.append(id_)
        else:
            g[pre].append(id_)
        pre = id_


dp = [-1] * (N * N)
visited = [False] * (N * N)
def dfs(v):
    visited[v] = True
    if dp[v] != -1:
        return dp[v]
    for u in g[v]:
        if dp[u] != -1:
            res = dp[u]
        else:
            if visited[u]:
                raise ValueError('find loop!')
            res = dfs(u)
        dp[v] = max(dp[v], res + 1)
    if len(g[v]) == 0:
        dp[v] = 1
    return dp[v]

ans = 0
try:
    for s in S:
        ans = max(ans, dfs(s))
    print(ans)
except ValueError:
    print(-1)


Fixed submission:
import sys

sys.setrecursionlimit(100000)

input = sys.stdin.readline
N = int(input())


def get_id(i, j):
    if j < i:
        i, j = j, i
    return i * N + j


g = [[] for _ in range(N * N)]
S = []
for i in range(N):
    pre = None
    for j in map(int, input().split()):
        j -= 1
        id_ = get_id(i, j)
        if pre is None:
            S.append(id_)
        else:
            g[pre].append(id_)
        pre = id_


dp = [-1] * (N * N)
visited = [False] * (N * N)


def dfs(v):
    visited[v] = True
    if dp[v] != -1:
        return dp[v]
    for u in g[v]:
        if dp[u] != -1:
            res = dp[u]
        else:
            if visited[u]:
                raise ValueError('find loop!')
            res = dfs(u)
        dp[v] = max(dp[v], res + 1)
    if len(g[v]) == 0:
        dp[v] = 1
    return dp[v]


ans = 0
try:
    for s in S:
        ans = max(ans, dfs(s))
    print(ans)
except ValueError:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline
N, M = map(int, input().split())
AB = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[1])[::-1]
plan = [0] * (M+1)
ans = 0
for a, b in AB:
    i = a
    while i < (M+1) and plan[i] == 1:
        i += 1
    if i < (M+1):
        plan[i] = 1
        ans += b
print(ans)


Fixed submission:
import sys

input = sys.stdin.readline
N, M = map(int, input().split())
AB = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[1])[::-1]
plan = [i for i in range(M+1)]
ans = 0
for a, b in AB:
    i = a
    while i < (M + 1) and plan[i] != i:
        plan[i] += 1
        i = plan[i] -1
    if i < (M+1):
        plan[i] += 1
        ans += b
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()[::-1]
P = 13
qs = [0]*13
tmp = 1
rest = 0
for i, s in enumerate(S):
    if s == '?':
        qs[tmp] += 1
    else:
        rest = (rest + int(s) * tmp) % P
    tmp = (tmp * 10) % P

dp = [0] * 13
dp[rest] = 1
for i, cnt in enumerate(qs):
    for _ in range(cnt):
        dp_new = [0]*13
        for j in range(10):
            tmp = (i * j) % P
            for k in range(P):
                dp_new[(k + tmp) % P] += dp[k]
        dp = dp_new
print(dp[5]%int(1e9+7))


Fixed submission:
S = input()[::-1]
P = 13
qs = [0]*13
tmp = 1
rest = 0
for i, s in enumerate(S):
    if s == '?':
        qs[tmp] += 1
    else:
        rest = (rest + int(s) * tmp) % P
    tmp = (tmp * 10) % P

dp = [0] * 13
dp[rest] = 1
for i, cnt in enumerate(qs):
    for _ in range(cnt):
        dp_new = [0]*13
        for j in range(10):
            tmp = (i * j) % P
            for k in range(P):
                dp_new[(k + tmp) % P] = (dp_new[(k + tmp) % P] + dp[k])%int(1e9+7)
        dp = dp_new
print(dp[5]%int(1e9+7))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import heapq
import math

input = sys.stdin.readline
N, M = map(int, input().split())
uv = [list(map(int, input().split())) for _ in range(M)]
S, T = map(int, input().split())

g = [[] for _ in range(3*N)]
for a, b in uv:
    g[a-1].append(b-1+N)
    g[a-1+N].append(b-1+2*N)
    g[a - 1 + 2 * N].append(b - 1)

# bfsでよかった
hq = [(0, S-1)]
costs = [math.inf] * 3 * N
while len(hq) > 0:
    c, u = heapq.heappop(hq)
    if u == T - 1:
        print(c // 3)
        sys.exit()
    costs[u] = c
    for v in g[u]:
        if costs[v] > c+1:
            heapq.heappush(hq, (c + 1, v))
print(-1)


Fixed submission:
import sys
import heapq
import math

input = sys.stdin.readline
N, M = map(int, input().split())
uv = [list(map(int, input().split())) for _ in range(M)]
S, T = map(int, input().split())

g = [[] for _ in range(3*N)]
for a, b in uv:
    g[a-1].append(b-1+N)
    g[a-1+N].append(b-1+2*N)
    g[a - 1 + 2 * N].append(b - 1)

# bfsでよかった
hq = [(0, S-1)]
costs = [math.inf] * 3 * N
while len(hq) > 0:
    c, u = heapq.heappop(hq)
    if u == T - 1:
        print(c // 3)
        sys.exit()
    costs[u] = c
    for v in g[u]:
        if costs[v] > c+1:
            heapq.heappush(hq, (c + 1, v))
        costs[v] = min(costs[v], c+1)

print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(M)]
dic = {}
for p, y in PY:
    dic[p] = (dic.get(p) or []) + [y]
for p, v in dic.items():
    dic[p] = {x: i+1 for i, x in enumerate(sorted(v))}
[print(str(1*10**12+p*10**6+dic[p][y])[1:]) for p, y in PY]


Fixed submission:
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
PY = [map(int, input().split()) for i in range(M)]
PYI = sorted((p, y, i+1) for i, (p, y) in enumerate(PY))
def gen():
  pre = -1
  count = -1
  for p, y, i in PYI:
    if p == pre:
      count += 1
      yield (i, str(1*10**12+p*10**6+count)[1:])
    else:
      count = 1
      yield (i, str(1*10**12+p*10**6+count)[1:])
      pre = p
print('\n'.join(i[1] for i in sorted(gen())))
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
score=1
for i in range(k):
    score*=a[i]

for i in range(k,n):
    score_b = score
    score = score_b/a[i-k]*a[i]
    
    if score_b < score:
        print("Yes")
    else:
        print("No")

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))

for i in range(k,n):
    zenkai = a[i-k]
    konkai = a[i]
    if zenkai < konkai:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
import numpy as np
n,m,k=map(int,input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
A=np.cumsum(np.array(a))
B=np.cumsum(np.array(b))
ans=0
t=0
i=0 #a
j=0 #b
while t<=k:
    if i<n and A[i]<B[j]:
        t+=a[i]
        i+=1
    elif j<m:
        t+=b[j]
        j+=1
    else:
        break
    if t<=k:
        ans+=1
print(ans)


Fixed submission:
import numpy as np
import bisect
n,m,k=map(int,input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
A=np.cumsum(np.array([0]+a))
B=np.cumsum(np.array(b))
ans=0
for i in range(n+1):
    if A[i]>k:
        break
    t=k-A[i]
    tmp=bisect.bisect_right(B,t)
    ans=max(ans, i+tmp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def eratosthenes(a):
    data = [i for i in a]
    for d in data:
        data = [x for x in data if (x == d or x % d != 0)]
    return data
    
n=int(input())
a=list(map(int, input().split()))
a.sort()
L=eratosthenes(a)
from collections import Counter
c=Counter(L)
ans=0
for v in c.values():
    if v==1:
        ans+=1
print(ans)

Fixed submission:
from collections import Counter

n=int(input())
a=list(map(int, input().split()))
a.sort()

m=a[-1]+1
dp=[True]*m
c=Counter(a)
ans=0
for x in a:
    if dp[x] and c[x]==1:
        ans+=1
    
    for j in range(2*x, m, x):
        dp[j]=False

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int, input().split()))
a.sort()
ans=0
L=[]
for i in range(n-1):
    if a[i]==a[i+1]:
        L.append(a[i])
    else:
        for j in L:
            if a[i]%j==0:
                break
        else:
            L.append(a[i])
            ans+=1
for i in L:
    if a[-1]%i==0:
        break
else:
    ans+=1
print(ans)


Fixed submission:
from collections import Counter

n=int(input())
a=list(map(int, input().split()))
a.sort()

m=a[-1]+1
dp=[True]*m
c=Counter(a)
ans=0
for x in a:
    if dp[x] and c[x]==1:
        ans+=1
    
    for j in range(2*x, m, x):
        dp[j]=False

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int, input().split()))
a.sort()
ans=0
L=[]
for i in range(n-1):
    if a[i]==a[i+1]:
        L.append(a[i])
    else:
        for j in L:
            if a[i]%j==0:
                break
        else:
            L.append(a[i])
            ans+=1
for i in L:
    if a[-1]%i==0:
        break
else:
    ans+=1
print(ans)


Fixed submission:
from collections import Counter

n=int(input())
a=list(map(int, input().split()))
a.sort()

m=a[-1]+1
dp=[True]*m
c=Counter(a)
ans=0
for x in a:
    if dp[x] and c[x]==1:
        ans+=1
    
    for j in range(2*x, m, x):
        dp[j]=False

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int, input().split()))
a.sort()
ans=0
for i in range(n-1):
    if a[i]%a[i+1]!=0:
        for j in range(i):
            if a[i]%a[j]==0:
                break
        else:
            ans+=1
for i in range(n-1):
    if a[-1]%a[i]==0:
        break
else:
    ans+=1
print(ans)

Fixed submission:
from collections import Counter

n=int(input())
a=list(map(int, input().split()))
a.sort()

m=a[-1]+1
dp=[True]*m
c=Counter(a)
ans=0
for x in a:
    if dp[x] and c[x]==1:
        ans+=1
    
    for j in range(2*x, m, x):
        dp[j]=False

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int, input().split()))
ans=1
for x in a:
    ans=ans*x
if ans>pow(10,18):
    ans=-1
print(ans)

Fixed submission:
n=int(input())
a=list(map(int, input().split()))
if 0 in a:
    print(0)
else:
    ans=1
    for x in a:
        ans=ans*x
        if ans>pow(10,18):
            ans=-1
            break
    print(ans)
Buggy python submission (verdict: Runtime Error):
n,k=map(int, input().split())
a=list(map(int, input().split()))
b=[False]*n
pos=0
for i in range(k):
    if b[pos]!=False:
        loop=i-b[pos]+1
        break
    b[pos]=i+1
    pos=a[pos]-1
    k-=1

for i in range(k%loop):
    pos=a[pos]-1
print(pos+1)

Fixed submission:
n,k=map(int, input().split())
a=list(map(int, input().split()))
b=[False]*n
pos=0
for i in range(min(n,k)):
    if b[pos]!=False:
        loop=i-b[pos]+1
        break
    b[pos]=i+1
    pos=a[pos]-1
    k-=1
if k>0:
    for i in range(k%loop):
        pos=a[pos]-1
print(pos+1)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
next=0
visited=[0]*n #index:訪れたとき
teleport=[] #index
for i in range(k):
    now=next
    if visited[now]==0:
        visited[now]=i+1
        teleport.append(now)
        next=a[now]-1
        k-=1
    else:
        loop=i+1-visited[now]
        break
print(teleport[len(teleport)-loop+k%loop]+1)

Fixed submission:
n,k=map(int, input().split())
a=list(map(int, input().split()))
b=[False]*n
pos=0
for i in range(min(n,k)):
    if b[pos]!=False:
        loop=i-b[pos]+1
        break
    b[pos]=i+1
    pos=a[pos]-1
    k-=1
if k>0:
    for i in range(k%loop):
        pos=a[pos]-1
print(pos+1)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,n=map(int,input().split())
ans=-10**9
if a==1 or b==1:
    print(0)
else:
    for i in range(1,n+1):
        tmp=int(a*i/b)-a*int(i/b)
        if tmp<ans:
            break
        else:
            ans=tmp
    print(ans)

Fixed submission:
a,b,n=map(int,input().split())
i=min(n,b-1)
print(int(a*i/b)-a*int(i/b))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
r=g=b=0
for i in range(n):
    if s[i]=="R":
        r+=1
    elif s[i]=="G":
        g+=1
    else:
        b+=1
ans=r*g*b
sub=0
for i in range(n-2):
    for j in range(i+1,n-1):
        k=j+(j-i)
        if s[i]==s[j]:
            continue
        if k>=n or s[i]==s[k] or s[j]==s[k]:
            continue
        sub+=1
print(ans-sub)

Fixed submission:
n=int(input())
s=input()
r=g=b=0
for i in range(n):
    if s[i]=="R":
        r+=1
    elif s[i]=="G":
        g+=1
    else:
        b+=1
ans=r*g*b
sub=0
for i in range(n-2):
    for j in range(i+1,n-1):
        k=j+(j-i)
        if s[i]==s[j]:
            continue
        if k>=n or s[i]==s[k] or s[j]==s[k]:
            continue
        sub+=1
print(ans-sub)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
r=s.count("R")
g=s.count("G")
b=s.count("B")
ans=r*g*b
sub=0
for i in range(n-2):
    for j in range(i+1,n-1):
        k=j+(j-i)
        if s[i]==s[j]:
            continue
        if k>=n or s[i]==s[k] or s[j]==s[k]:
            continue
        sub+=1
print(ans-sub)

Fixed submission:
n=int(input())
s=input()
r=g=b=0
for i in range(n):
    if s[i]=="R":
        r+=1
    elif s[i]=="G":
        g+=1
    else:
        b+=1
ans=r*g*b
sub=0
for i in range(n-2):
    for j in range(i+1,n-1):
        k=j+(j-i)
        if s[i]==s[j]:
            continue
        if k>=n or s[i]==s[k] or s[j]==s[k]:
            continue
        sub+=1
print(ans-sub)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
r=[]
g=[]
b=[]
for i in range(n):
    if s[i]=="R":
        r.append(i)
    elif s[i]=="G":
        g.append(i)
    else:
        b.append(i)

ans=len(r)*len(g)*len(b)
for i in r:
    for j in g:
        for k in b:
            t=[i,j,k]
            t.sort()
            x,y,z=t
            if y-x == z-y:
                ans-=1
print(ans)

Fixed submission:
n=int(input())
s=input()
r=g=b=0
for i in range(n):
    if s[i]=="R":
        r+=1
    elif s[i]=="G":
        g+=1
    else:
        b+=1
ans=r*g*b
sub=0
for i in range(n-2):
    for j in range(i+1,n-1):
        k=j+(j-i)
        if s[i]==s[j]:
            continue
        if k>=n or s[i]==s[k] or s[j]==s[k]:
            continue
        sub+=1
print(ans-sub)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))

from collections import Counter
d=Counter(a)
f={}
for k,v in d.items():
    f[k]=v*(v-1)/2

ans={}
for k in f.keys():
    ans[k]=(d[k]-1)*(d[k]-2)/2
    ans[k]+=sum(f.values())
    ans[k]-=f[k]

for i in range(n):
    print(int(ans[a[i]]))


Fixed submission:
n=int(input())
a=list(map(int,input().split()))

from collections import Counter
d=Counter(a)
f={}
for k,v in d.items():
    f[k]=v*(v-1)/2

ans={}
s=sum(f.values())
for k in f.keys():
    ans[k]=(d[k]-1)*(d[k]-2)/2 + s- f[k]

for i in range(n):
    print(int(ans[a[i]]))

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

from collections import Counter
d=Counter(a)
f={}
for k,v in d.items():
    f[k]=v*(v-1)/2

ans={}
for k in f.keys():
    ans[k]=(d[k]-1)*(d[k]-2)/2
    for v in f.values():
        ans[k]+=v
    ans[k]-=f[k]

for i in range(n):
    print(int(ans[a[i]]))


Fixed submission:
n=int(input())
a=list(map(int,input().split()))

from collections import Counter
d=Counter(a)
f={}
for k,v in d.items():
    f[k]=v*(v-1)/2

ans={}
s=sum(f.values())
for k in f.keys():
    ans[k]=(d[k]-1)*(d[k]-2)/2 + s- f[k]

for i in range(n):
    print(int(ans[a[i]]))

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

from collections import Counter
d=Counter(a)

for i in range(n):
    c=d.copy()
    c[a[i]]-=1
    ans=0
    for v in c.values():
        ans+=v*(v-1)/2
    print(int(ans))


Fixed submission:
n=int(input())
a=list(map(int,input().split()))

from collections import Counter
d=Counter(a)
f={}
for k,v in d.items():
    f[k]=v*(v-1)/2

ans={}
s=sum(f.values())
for k in f.keys():
    ans[k]=(d[k]-1)*(d[k]-2)/2 + s- f[k]

for i in range(n):
    print(int(ans[a[i]]))