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

Fixed submission:
N = int(input())
b = list(map(int, input().split()))
a = [1, 2, 3, 4, 5]

def f(a, ans):
    if len(a) == 0:
        for i in range(len(ans)):
            print(ans[len(ans) - i - 1])
        exit()
    for i in range(len(a) - 1, -1, -1):
        if i + 1 == a[i]:
            f(a[0:i] + a[i + 1:len(a)], ans + [i + 1])
            break


f(b, [])
print(-1)

Buggy submission (verdict: Runtime Error):
N = int(input())
b = list(map(int, input().split()))
a = [1, 2, 3, 4, 5]

def f(a, ans):
    if len(a) == 0:
        for i in range(len(ans)):
            print(ans[len(ans) - i - 1])
        exir()
    for i in range(len(a)):
        if i + 1 == a[i]:
            f(a[0:i] + a[i + 1:len(a)], ans + [i + 1])

f(b, [])
print(-1)
Problem p03101 (python)

Fixed submission:
H, W = list(map(int, input().split()))
h, w = list(map(int, input().split()))
print(H*W - h*W - H*w + h*w)

Buggy submission (verdict: Runtime Error):
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N):
    sum = 0
    for j in range(M):
        sum += A[i - 1][j - 1] * B[j - 1]
    if sum > - C:
        ans += 1
print(ans)
Problem p03227 (python)

Fixed submission:
S = input()
if len(S) == 2:
    print(S)
else:
    print(S[::-1])

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

A.sort()

ans = A[len(A) - 1] - A[0]
small = 0
large = len(A) - 1
while (True):

    if large - small == 1:
        break
    elif large - small == 2:
        ans += max(A[large] - A[large - 1], A[small + 1] - A[small])
        break
    ans += A[large - 1] - A[small] + A[large] - A[small + 1]
    small += 1
    large -= 1

print(ans)
Problem p02791 (python)

Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

n = int(input())
pn = list(map(int, input().split()))

cnt = 1
min = pn[0]
for i in range(1, n):
    if min > pn[i]:
        cnt += 1
        min = pn[i]

print(cnt)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

n = int(input())
pn = list(map(int, input().split()))


def checkAllLess(tgt):
    for id in range(tgt):
        # print("id=" + str(id) + ", pn[]=" + str(pn[id]) + ", tgt=" + str(tgt))
        if(pn[id] < pn[tgt]):
            # print('False')
            return False
    # print('True')
    return True


cnt = 1
min = pn[0]
for i in range(n):
    if (min > i & & checkAllLess(i)):
        cnt += 1
    if (min > pn[i]):
        min = pn[i]
    # print(str(i) + ":" + str(cnt))

print(cnt)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

n = int(input())
pn = list(map(int, input().split()))


def checkAllLess(tgt):
    for id in range(tgt):
        # print("id=" + str(id) + ", pn[]=" + str(pn[id]) + ", tgt=" + str(tgt))
        if(pn[id] < pn[tgt]):
            # print('False')
            return False
    # print('True')
    return True


cnt = 1
min = pn[0]
for i in range(n):
    if (min > i & & checkAllLess(i)):
        cnt += 1
    if (min > pn[i]):
        min = pn[i]
    # print(str(i) + ":" + str(cnt))

print(cnt)
Problem p02780 (python)

Fixed submission:
def main():
    n,k=map(int,input().split())
    p=list(map(int,input().split()))
    kitai=[]
    ans=0
    for i in range(n):
        buf=sum(range(1,p[i]+1))/p[i]
        kitai.append(buf)
        if i<=k-1:
            ans+=buf
    x=ans
    for i in range(k,n):
        x-=kitai[i-k]
        x+=kitai[i]
        if ans<=x:
            ans=x
    print(ans)

if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque
n,k=map(int, input().split())
p=list(map(int, input().split()))
queue=deque()
prod=1
ans=0
for i in range(k):
    queue.append(p[i])
    prod*=p[i]
ans=sum(queue)
for i in range(k-1,n-1):
    buf=sum(queue)
    if buf>=ans: #隣接するkコのサイコロの最大値を記録
        ans=buf
        x=prod
    queue.popleft()
    queue.append(p[i+1])
    prod*=p[i+1]/p[i]
l=list(range(3,ans+1))
y=(sum(l))/x
print(y)
Problem p02802 (python)

Fixed submission:
n,m=map(int, input().split())
ac,wa=0,0
if m==0:
    print(ac,wa)
else: #一度飛ばして新たな問題を解いたうえで戻ってくる場合があるのか？
    l=[0]*n #正解処理の配列
    r=[0]*n #誤答カウンター
    for i in range(m):
        pa,s=map(str, input().split())
        p=int(pa)
        if l[p-1]==0 and s=='AC': #初正解時の処理
            l[p-1]=1
            ac+=1
        elif l[p-1]==0 and s=='WA': #誤答時の処理
            r[p-1]+=1
        else:
            continue
    for i in range(n):
        if l[i]==1:
            wa+=r[i]
        else:
            continue
    print(ac,wa)

Buggy submission (verdict: Runtime Error):
n,m=map(int, input().split())
ac,wa=0,0
if m==0:
    print(ac,wa)
else: #一度飛ばして新たな問題を解いたうえで戻ってくる場合があるのか？
    l=[0]*n #正解処理の配列
    r=[0]*n #誤答カウンター
    for i in range(m):
        pa,s=map(str, input().split())
        p=int(pa)
        if l[p-1]==0 and s=='AC': #初正解時の処理
            l[p-1]=1
            ac+=1
        elif s=='WA': #誤答時の処理
            r[p-1]+=1
        else:
            continue
    for i in range(n):
        if l[i]==1:
            wa+=w[i]
        else:
            continue
    print(ac,wa)
Problem p02830 (python)

Fixed submission:
n=int(input())
s,t=input().split(' ')
for i in range(n):
    print(s[i], end='')
    print(t[i], end='')

Buggy submission (verdict: Runtime Error):
n=int(input())
s,t=str(input().split())
for i in range(n):
    print(s[i], end='')
    print(t[i], end='')

Buggy submission (verdict: Runtime Error):
n=int(input())
s=str(input())
t=str(input())
for i in range(n):
    print(s[i], end='')
    print(t[i], end='')
Problem p03544 (python)

Fixed submission:
n=int(input())
l=[2,1]
if n>1:
    for i in range(2,n+1):
        li=l[i-1]+l[i-2]
        l.append(li)
    print(l[n])
else:
    print(l[n])

Buggy submission (verdict: Runtime Error):
n=int(input())
l=[2,1]
if n>2:
    for i in range(2,n+1):
        li=l[i-1]+l[i-2]
        l.append(li)
    print(l[n])
else:
    print(l[n])
Problem p03779 (python)

Fixed submission:
def main():
    import sys
    x=int(input())
    cnt=0
    if x==1:
        print(1)
        sys.exit()
    if x==2:
        print(2)
        sys.exit()
    for i in range(1,x):
        if cnt<x:
            cnt+=i
        else:
            t=i-1
            break
    print(t)

if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    x=int(input())
    cnt=0
    if x==1:
        print(1)
        sys.exit()
    for i in range(1,x):
        if cnt<x:
            cnt+=i
        else:
            t=i-1
            break
    print(t)

if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    x=int(input())
    cnt=0
    for i in range(1,x):
        if cnt<x:
            cnt+=i
            print(i,cnt)
        else:
            print(i,cnt)
            t=i-1
            break
    print(t)

if __name__=='__main__':
    main()
Problem p02681 (python)

Fixed submission:
S = input()
T = input()

if len(T) != len(S) + 1:
  print("Yes")
else:
  if T.startswith(S):
    print("Yes")
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
N, K = [int(v) for v in input().split(" ")]
Ai = [int(v) for v in input().split(" ")]
assert len(Ai) == N


path = [0]
while True:
  next_city = Ai[path[len(path) - 1]] - 1
  if next_city in path:
    break
  path.append(next_city)

for i, city in enumerate(path):
  if city == next_city:
    start = path[:i]
    circle = path[i:]

if K <= len(start):
  print(start[K] + 1)
else:
  K -= len(start)
  print(circle[K % len(circle)] + 1)

Buggy submission (verdict: Runtime Error):
s = input()
A, B, C, K = [int(v) for v in s.split(" ")]

if K <= A:
  print(K)
elif K <= A + B:
  print(A)
elif K <= A + B + C:
  print(A - (K - A - B))

Buggy submission (verdict: Runtime Error):
s = input()
A, B, C, K = s.split(" ")
 
if K <= A:
  print(K)
elif K <= A + B:
  print(A)
elif K <= A + B + C:
  print(A - (K - A - B))

Buggy submission (verdict: Runtime Error):
S = input()
T = input()
return T.startswith(S)
Problem p02683 (python)

Fixed submission:
line = input()
N, M, X = [int(v) for v in line.split(" ")]

Ci, Aij = [], []
for i in range(N):
    line = input().split(" ")
    line = [int(v) for v in line]

    Ci.append(line[0])
    Aij.append(line[1:])

ans = []
def dfs(candidate):
    if len(candidate) == N:
        X_ = [0 for _ in range(M)]
        cost = 0
        for i in range(N):
            if candidate[i] == 0:
                continue
            cost += Ci[i]
            for j in range(M):
                X_[j] += Aij[i][j]
        if min(X_) >= X:
            ans.append(cost)
    else:
        for bit in range(2):
            candidate.append(bit)
            dfs(candidate)
            candidate.pop()

dfs([])
if len(ans) == 0:
    print(-1)
else:
    print(min(ans))

Buggy submission (verdict: Runtime Error):
line = input()
N, M, X = [int(v) for v in line.split(" ")]

Ci, Aij = [], []
for i in range(N):
    line = input().split(" ")
    line = [int(v) for v in line]

    Ci.append(line[0])
    Aij.append(line[1:])

ans = []
def dfs(candidate):
    if len(candidate) == M:
        X_ = [0 for _ in range(M)]
        cost = 0
        for i in range(N):
            if candidate[i] == 0:
                continue
            cost += Ci[i]
            for j in range(M):
                X_[j] += Aij[i][j]
        if min(X_) >= X:
            ans.append(cost)
    else:
        for bit in range(2):
            candidate.append(bit)
            dfs(candidate)
            candidate.pop()

dfs([])
if len(ans) == 0:
    print(-1)
else:
    print(min(ans))

Buggy submission (verdict: Runtime Error):
line = input()
N, M, X = [int(v) for v in line.split(" ")]

Ci, Aij = [], []
for i in range(N):
    line = input().split(" ")
    line = [int(v) for v in line]

    Ci.append(line[0])
    Aij.append(line[1:])

ans = []
def dfs(candidate):
    if len(candidate) == M:
        X_ = [0 for _ in range(M)]
        cost = 0
        for i in range(N):
            if candidate[i] == 0:
                continue
            cost += Ci[i]
            for j in range(M):
                X_[j] += Aij[i][j]
        if min(X_) >= X:
            ans.append(cost)
    else:
        for bit in range(2):
            candidate.append(bit)
            dfs(candidate)
            candidate.pop()

dfs([])
if len(ans) == 0:
    print(-1)
else:
    print(min(ans))
Problem p02719 (python)

Fixed submission:
from collections import defaultdict

import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n,k=mis()
    if n>=k:
        n%=k
        print(k%n if n!=0 else 0)
        exit()    
    print(n if n<=k//2 else k-n)



if __name__ == "__main__":
    main()

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

import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n,k=mis()
    if n>=k:
        n%=k
        print(k%n)
        exit()
    if n<=k//2:print(n)
    else: print(k-n)



if __name__ == "__main__":
    main()

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

import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n,k=mis()
    if n>=k:
        n%=k
        print(k%n)
        exit()
    else: print(n if n<=k//2 else k-n)



if __name__ == "__main__":
    main()

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

import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n,k=mis()
    ave=float(k/2)
    if n>=k:
        n%=k
        print(k%n)
        exit()
    else: print(n if n<ave else k-n)



if __name__ == "__main__":
    main()

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

import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n,k=mis()
    ave=float(k/2)
    ans=n
    dis=abs(ans-k)
    if n>=k:
        ans=n%k
        if k>=ans:
            print(k%ans)
            exit()
    print(n if n<ave else k-n)



if __name__ == "__main__":
    main()

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

import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n,k=mis()
    ave=float(k/2)
    ans=n
    dis=abs(ans-k)
    if n>=k:
        ans=n%k
        if k>ans:
            print(k%ans)
            exit()
    print(n if n<ave else k-n)



if __name__ == "__main__":
    main()
Problem p02909 (python)

Fixed submission:
a=['Sunny','Cloudy','Rainy']
s=input()
x=a.index(s)
print(a[x+1] if x<2 else 'Sunny')

Buggy submission (verdict: Runtime Error):
a=['Sunny','Cloudy','Rainy']
s=input()
x=a.index(s)
print(a[x+1])
Problem p03126 (python)

Fixed submission:
n,m=map(int,input().split())
like=[]
for i in range(n):
    k,*a=map(int,input().split())
    like+=a
ans=0
for i in range(1,m+1):
    if like.count(i)==n:
        ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
like=[]
for i in range(n):
    like+=list(map(int,input()))
print(len(set(like)))
Problem p03220 (python)

Fixed submission:
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
ab=[0]*n
for i in range(n): ab[i]=abs(a-(t-h[i]*0.006))
print(ab.index(min(ab))+1)

Buggy submission (verdict: Runtime Error):
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
ab=[0]*n
for i in range(n): ab[i]=abs(a-(t-h[i]*0.006))
print(h.index(min(ab))+1)
Problem p03260 (python)

Fixed submission:
print('Yes' if eval(input().replace(' ','*'))%2 else 'No')

Buggy submission (verdict: Runtime Error):
print('Yes' if eval(input().replace(' ',*))%2 else 'No')
Problem p03434 (python)

Fixed submission:
input()
a=sorted(list(map(int,input().split())),reverse=True)
print(sum(a[::2])-sum(a[1::2]))

Buggy submission (verdict: Runtime Error):
a=sorted(list(int(input()) for _ in range(int(input()))),reverse=True)
print(sum(a[::2])-sum(a[1::2]))
Problem p03543 (python)

Fixed submission:
N=list(input())
if N[1]==N[2]:
    if N[1]==N[0]:
        print('Yes')
    elif N[2]==N[3]:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N=list(int(input()))
if N[1]==N[2]:
    if N[1]==N[0]:
        print('Yes')
    elif N[2]==N[3]:
        print('Yes')
    else:
        print('No')
else:
    print('No')
Problem p03644 (python)

Fixed submission:
n=int(input())
for i in range(9):
    if n==2**i:
        print(n)
        exit()
    elif n<2**i:
        print(2**(i-1))
        exit()

Buggy submission (verdict: Runtime Error):
n=int(input())
if n==1:
    print(n):
    exit()
i=2
for _ in range(9):
    i**=2
    if i==n:
        print(i)
        exit()
    elif i>n:
        print(i//2)
        exit()
Problem p03658 (python)

Fixed submission:
n,k=map(int,input().split())
l=sorted(list(map(int,input().split())),reverse=True)
ans=0
for i in range(k): ans+=l[i]
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
l=sort(list(map(int,input().split())),reverse=True)
ans=0
for i in range(k): ans+=l[i]
print(ans)
Problem p03671 (python)

Fixed submission:
a=list(map(int,input().split()))
print(sum(a)-max(a))

Buggy submission (verdict: Runtime Error):
a=list(map(int,input().split())
print(sum(a)-max(a))
Problem p03760 (python)

Fixed submission:
o=input()
e=input()
for i in range(len(e)):
    print(o[i],end='')
    print(e[i],end='')
if len(o)>len(e):print(o[len(o)-1])

Buggy submission (verdict: Runtime Error):
o=input()
e=input()
for i in range(len(o)):
    print(o[i],end='')
    print(e[i],end='')
Problem p02690 (python)

Fixed submission:
#N, M = list(map(int, input().strip().split()))
X = int(input())

start = -200
end = 201

for i in range(start, end):
  for j in range(start, end):
    if i**5 - j**5 == X:
      A, B = i, j
      break
print(A, B)

Buggy submission (verdict: Runtime Error):
#N, M = list(map(int, input().strip().split()))
X = int(input())

for i in range(-100, 101):
  for j in range(-100, 101):
    if i**5 - j**5 == X:
      A, B = i, j
      break
print(A, B)
Problem p02732 (python)

Fixed submission:
import collections
import math
 
def combinations_count(n, r):
  if n == r:
    return 1
  elif n < r:
    return 0
  else:
    return n * (n-1) // 2 
    #math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

combi = collections.Counter(A)
combi_count = {}
calc_dict = {}
total = 0
for k, v in combi.items():
  if v in calc_dict:
    combi_count[k] = calc_dict[v]
  else:
    combi_count[k] = combinations_count(v, 2)
    calc_dict[v] = combi_count[k]
  total += combi_count[k]

for i in range(N):
  ans = total - combi_count[A[i]] + combinations_count(combi[A[i]]-1, 2)
  print(ans)

Buggy submission (verdict: Runtime Error):
import collections
import math
 
def combinations_count(n, r):
    return 0 if n < r else math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

combi = collections.Counter(A)
for k, v in combi.items():
  if v <= 1:
    combi.pop(k)
#print(combi)

for i in range(N):
  ans = 0
  
  # i番目の要素をcombiからdecrement
  combi[A[i]] -= 1
  
  #print(combi)
  
  for v in combi.values():
    #print(v)
    ans += combinations_count(v, 2)
  
  print(ans)

  # i番目の要素をcombiからincrement
  combi[A[i]] += 1
Problem p02765 (python)

Fixed submission:
def get():
    return list(map(int, input().split()))


a = get()
if a[0] < 10:
    print(a[1]+100*(10 - a[0]))
else:
    print(a[1])

Buggy submission (verdict: Runtime Error):
def get():
    return list(map(int, input().split()))


a = get()
if a[0] < 10:
    print(a[1]+100(10 - a[0]))
else:
    print(a[1])
Problem p02687 (python)

Fixed submission:
s=str(input())
if s =="ARC":
  print("ABC")
else:
  print("ARC")

Buggy submission (verdict: Runtime Error):
s=str(input())
if s ="ARC":
  print("ABC")
else:
  print("ARC")
Problem p02705 (python)

Fixed submission:
import math
r = int(input())
print(2*math.pi*r)

Buggy submission (verdict: Runtime Error):
import math
r = int(imput())
print(2*math.pi*r)

Buggy submission (verdict: Runtime Error):
import numpy
R = int(input())
print(2*np.pi*R)

Buggy submission (verdict: Runtime Error):
r = int(input())
print(2*math.pi*r)
Problem p02717 (python)

Fixed submission:
a, b, c = map(int, input().split())
print(c,a,b)

Buggy submission (verdict: Runtime Error):
x,y,z = map(input().split())
print(z,x,y)

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
a = b
a = c
print(a b c)
Problem p02719 (python)

Fixed submission:
n,k=map(int,input().split())
if n<k:
  if k<2*n:
      print(k-n)
  else:
    print(n)
elif n==k:
  print(0)
else:
  m=n//k
  r=n-m*k
  print(min(r,abs(r-k)))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
if n<k:
  if:k<2*n:
      print(k-n)
  else:
    print(n)
elif n==k:
  print(0)
else:
  m=n//k
  r=n-m*k
  print(min(r,abs(r-k)))
Problem p02922 (python)

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

Buggy submission (verdict: Runtime Error):
a,b = map(int(input().split()))
s = -(-b// a)
print(s)
Problem p03455 (python)

Fixed submission:
a,b = map(int, input() .split())
if (a*b) % 2 == 0:
  print("Even")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
a,b = map(int, input() .split())
if (a*b) % 2 == 1:
  print("Odd")
    else:
      print("Even")

Buggy submission (verdict: Runtime Error):
a = int(a)
b = int(b)
c = a * b

if c % 2 == 0:
  print("even")
else:
  print("odd")

Buggy submission (verdict: Runtime Error):
c = a * b
if c % 2 == 0:
  print("even")
else :
  print("odd")
Problem p04043 (python)

Fixed submission:
a = list(map(int, input().split()))
if a.count(5) == 2 and a.count(7) == 1:
         print("YES")
else:
         print("NO")

Buggy submission (verdict: Runtime Error):
a = list(map(int, input().split())
if a.count(5) == 2 and a.count(7) == 1:
         print("Yes")
else:
         print("No")
Problem p02691 (python)

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

L = [A[i] + (i + 1) for i in range(N)]
R = [(i + 1) - A[i] for i in range(N)]
import collections
dL = dict(collections.Counter(L))
dR = dict(collections.Counter(R))

ans = 0
for k in dL.keys():
    ans += dL[k] * dR.get(k, 0)
print(ans)
# print(L)
# print(R)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
import copy
ori = copy.copy(A)

for i in range(N):
    A[i] -= (N - 1) - i
# print(A)
# import collections
# dct = dict(collections.Counter(A))
# print(dct)
# m = min(A)
# cnt = 0
# for check in range(m, 0):
#
#     if dct.get(check, 0):
#         print(check)
#         cnt += dct[check] * dct.get(check + 2, 0)
# print(cnt)
remove = 0
# for i in range(N-2):
#     if ori[i] != 1 and ori[i] == ori[i + 2]:
#         remove += 1
for i in range(N - 1):
    if ori[i] + 1 == ori[i + 1]:
        remove += 1
# print(ori)
# print(cnt - remove)

bucket = [0] * N
cnt = 0
for i in range(N):
    if A[i] < 0:
        bucket[-A[i]] += 1
        cnt += bucket[-A[i] + 2]
print(cnt- remove)
Problem p02714 (python)

Fixed submission:
N = int(input())
S = input()
RGB = ['R', 'G', 'B']
import collections
if len(set(list(S))) <= 2:
    print(0)
else:
    dct = dict(collections.Counter(S))

    cnt = 0
    for i in range(N-2):
        for k in range((N - 1 - i) // 2 + 1):
            temp = {S[i], S[i + k], S[i + k * 2]}
            if len(temp) == 3:
                cnt += 1
            #print(cnt)
    print(dct['R'] * dct['G'] * dct['B'] - cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
RGB = ['R', 'G', 'B']
import collections
dct = dict(collections.Counter(S))

cnt = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        if 2 * j - i < N:
            for c in RGB:
                if c != S[i] and c != S[j] and S[i] != S[j]:
                    if c == S[2 * j - i]:
                        cnt += 1
                        #print(i, j)
#print(cnt)
print(dct['R'] * dct['G'] * dct['B'] - cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
RGB = ['R', 'G', 'B']

import collections
dct = dict(collections.Counter(S))
#print(dct)

ans = 0
for i in range(0, N-1):
    for j in range(i+1, N):
        if S[i] != S[j]:
            for c in RGB:
                if c != S[i] and c != S[j]:
                    cnt = 0
                    if 0 <= 2 * j - i < N and S[2 * j - i] == c:
                        cnt += 1
                    if N > 2 * i - j >= 0 and S[2 * i - j] == c:
                        cnt += 1
                    if i % 2 == j % 2:
                        if 0 <= (i + j) // 2 < N and S[(i + j) // 2] == c:
                            cnt += 1
                    ans += dct[c] - cnt
                    #print(i, j, dct[c]-cnt)
#print(ans)
print(ans // 3)