Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s,w = map(int,input().split(' '))
if w >= s:
  print(unsafe)
else:
  print(safe)


Fixed submission:
s,w = map(int,input().split(' '))
if w >= s:
  print('unsafe')
else:
  print('safe')

Buggy python submission (verdict: Runtime Error):
s,w = map(int,input().split(' '))
if w >= s:
  print(unsafe)
else:
  print(safe)

Fixed submission:
s,w = map(int,input().split(' '))
if w >= s:
  print('unsafe')
else:
  print('safe')
Buggy python submission (verdict: Runtime Error):
import numpy as np
a,b=map(int,input().split())
c=np.zeros(a)
for i in range(b):
  input()
  x=list(map(int,input().split()))
  for i in x:
    if c[i-1]==0:
      c[i-1]=1
    else:
      pass
print(a-sum(c))

Fixed submission:
import numpy as np
h,w,k=map(int,input().split())
trout=np.zeros((h,w))
cnt=0
for i in range(h):
  a=list(input())
  for j in range(w):
    if a[j]=="#":
      trout[i][j]=1
    else:
      trout[i][j]=0
for i in range(2**(h+w)):
  test=np.copy(trout)
  for j in range(h+w):
    if (i>>j)&1:
      if h+w-j>h:
        test[:,w-j-1]=0
      else:
        test[h+w-j-1,:]=0
  if test.sum()==k:
    cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=list(map(int,input().split()))
b.sort(reverse=True)
if a%2==0:
  print(sum(b[:a//2-1]*2-b[0]))
else:
  print(sum(b[:a//2+1]*2-b[0]-b[a//2])

Fixed submission:
a=int(input())
b=list(map(int,input().split()))
b.sort(reverse=True)
ans=0
for i in range(a-1):
  i=(i+1)//2
  ans+=b[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_right
from numpy import cumsum
from sys import stdin
input=stdin.readline
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=numpy.cumsum(a)
b=numpy.cumsum(b)
ans=0
for i in range(len(a)):
  x=k-a[i]
  y=bisect.bisect_right(b,x)
  if ans<y+i+1:
    ans=y+i+1
print(ans)

Fixed submission:
from bisect import bisect_right
from numpy import cumsum
from sys import stdin
input=stdin.readline
n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))
a=cumsum(a)
b=cumsum(b)
ans=0
for i in range(len(a)):
  x=k-a[i]
  if x>=0:
    y=bisect_right(b,x)
    if ans<y+i:
      ans=y+i
  else:
    break
print(ans)

Buggy python submission (verdict: Runtime Error):
from biesect import biesect_right
from numpy import cumsum
from sys import stdin
input=stdin.readline
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=numpy.cumsum(a)
b=numpy.cumsum(b)
ans=0
for i in range(len(a)):
  x=k-a[i]
  y=biesect.biesect_right(b,x)
  if ans<y+i+1:
    ans=y+i+1
print(ans)

Fixed submission:
from bisect import bisect_right
from numpy import cumsum
from sys import stdin
input=stdin.readline
n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))
a=cumsum(a)
b=cumsum(b)
ans=0
for i in range(len(a)):
  x=k-a[i]
  if x>=0:
    y=bisect_right(b,x)
    if ans<y+i:
      ans=y+i
  else:
    break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())+1
a=0
for i in range(1,n):
  for j in range(i,n,i):a+=j
print(a)

Fixed submission:
a=int(input())
b=(a)//2+1
ans=0
for i in range(1,b,1):
  x=a//i
  ans+=((x**2+x)//2)*i
ans+=(a**2+a+b-b**2)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a=int(input())
ans=0
for i in range(1,a+1,1):
  x=a//i
  ans+=((x**2+x)//2)*i
print(ans)

Fixed submission:
a=int(input())
b=(a)//2+1
ans=0
for i in range(1,b,1):
  x=a//i
  ans+=((x**2+x)//2)*i
ans+=(a**2+a+b-b**2)//2
print(ans)

Buggy python submission (verdict: Runtime Error):
a=int(input())
ans=0
for i in range(a):
  x=a//i
  ans+=((a+1)a)/2
print(ans)

Fixed submission:
a=int(input())
b=(a)//2+1
ans=0
for i in range(1,b,1):
  x=a//i
  ans+=((x**2+x)//2)*i
ans+=(a**2+a+b-b**2)//2
print(ans)

Buggy python submission (verdict: Runtime Error):
print(www)

Fixed submission:
a=int(input())
b=(a)//2+1
ans=0
for i in range(1,b,1):
  x=a//i
  ans+=((x**2+x)//2)*i
ans+=(a**2+a+b-b**2)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
a=int(input())
b=list(i+1 for i in range(a))
www=0
for j in b:
  ans=0
  c=[x+1 for x in range(int(math.sqrt(j)//1))]
  for y in c:
    if j%y==0:
      if not j/y==y:
        ans+=2
      else:
        ans+=1
  www+=ans*j
print(www)

Fixed submission:
a=int(input())
b=(a)//2+1
ans=0
for i in range(1,b,1):
  x=a//i
  ans+=((x**2+x)//2)*i
ans+=(a**2+a+b-b**2)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
x,y=map(int,input().split())
if 2x<=y<=4x and y%2==0:
  print("Yes")
else:
  print("No")

Fixed submission:
x,y=map(int,input().split())
if 2*x<=y<=4*x and y%2==0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
n=int(input())
b=list(map(int,input().split()))
ans=0
w=max(b)
a=[0]*w
for i in b:
  x=i
  while x<w:
    a[x]=1
    x+=i
for i in b:
  if a[i]==0:
    ans+=1

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
max_a = max(a)
cnt_d = [0] * (max_a + 1)

for ai in a:
    for multi in range(ai, max_a + 1, ai):
        cnt_d[multi] += 1

print(sum(cnt_d[ai] == 1 for ai in a))

Buggy python submission (verdict: Time Limit Exceeded):
a=int(input())
b=list(map(int,input().split()))
c=max(b)+1
d=[]
ans=0
for i in range(a):
  e=0
  while c-e>b[i]:
    e+=b[i]
    d+=[e]
for i in b:
    if d.count(i)==1:
      ans+=1
print(ans)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
max_a = max(a)
cnt_d = [0] * (max_a + 1)

for ai in a:
    for multi in range(ai, max_a + 1, ai):
        cnt_d[multi] += 1

print(sum(cnt_d[ai] == 1 for ai in a))

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

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
max_a = max(a)
cnt_d = [0] * (max_a + 1)

for ai in a:
    for multi in range(ai, max_a + 1, ai):
        cnt_d[multi] += 1

print(sum(cnt_d[ai] == 1 for ai in a))

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

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
max_a = max(a)
cnt_d = [0] * (max_a + 1)

for ai in a:
    for multi in range(ai, max_a + 1, ai):
        cnt_d[multi] += 1

print(sum(cnt_d[ai] == 1 for ai in a))

Buggy python submission (verdict: Time Limit Exceeded):
a=int(input())
b=list(map(int,input().split()))
ans=[0]*a
for i in range(a):
  for j in range(a):
    if b[i]%b[j]==0 and not i==j:
      ans[i]=0
      break
    elif j==a-1:
      ans[i]=1
print(sum(ans))

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
max_a = max(a)
cnt_d = [0] * (max_a + 1)

for ai in a:
    for multi in range(ai, max_a + 1, ai):
        cnt_d[multi] += 1

print(sum(cnt_d[ai] == 1 for ai in a))
Buggy python submission (verdict: Time Limit Exceeded):
input()
a=1
b=map(int,input().split())
for i in b:
  a*=i
if a>10**18:
  a=-1
print(a)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
if 0 in l:
  print(0)
else:
  a=1
  for i in l:
    a=a*i
    if a>10**18:
      print(-1)
      exit()
  print(a)

Buggy python submission (verdict: Runtime Error):
input()
a=1
b=map(int,inpit().split())
for i in b:
  a*=i
if a>10^18:
  a=-1
print(a)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
if 0 in l:
  print(0)
else:
  a=1
  for i in l:
    a=a*i
    if a>10**18:
      print(-1)
      exit()
  print(a)
Buggy python submission (verdict: Runtime Error):
import math
a=int(input())
b=[]
ans=0
for i in range(1,int(math.sqrt(a)),1):
  if a%i==0:
    b=b+[i]+[int(a/i)]
b.remove(1)
for i in b:
  cnt=0
  if a%i==0:
    while a%i==0:
      cnt+=1
      a=a/i
    ans+=(math.sqrt(2*cnt+0.25)-0.5)//1
print(int(ans))

Fixed submission:
import math
a=int(input())
ans=0
for i in range(1,int(math.sqrt(a)),1):
  if a%i==0 and not i==1:
    cnt=0
    while a%i==0:
      cnt+=1
      a=a/i
    ans+=(math.sqrt(2*cnt+0.25)-0.5)//1
if not a==1:
  print(int(ans+1))
else:
  print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
import math
a=int(input())
b=[]
ans=0
for i in range(2,a,1):
  cnt=0
  if a%i==0:
    while a%i==0:
      cnt+=1
      a=a/i
    ans+=(math.sqrt(2*cnt+0.25)-0.5)//1
  else:
    pass
print(int(ans))

Fixed submission:
import math
a=int(input())
ans=0
for i in range(1,int(math.sqrt(a)),1):
  if a%i==0 and not i==1:
    cnt=0
    while a%i==0:
      cnt+=1
      a=a/i
    ans+=(math.sqrt(2*cnt+0.25)-0.5)//1
if not a==1:
  print(int(ans+1))
else:
  print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
import math
a=int(input())
b=[]
ans=0
for i in range(2,a,1):
  cnt=0
  if a%i==0:
    while a%i==0:
      cnt+=1
      a=a/i
    ans+=(math.sqrt(2*cnt+0.25)-0.5)//1
print(int(ans))

Fixed submission:
import math
a=int(input())
ans=0
for i in range(1,int(math.sqrt(a)),1):
  if a%i==0 and not i==1:
    cnt=0
    while a%i==0:
      cnt+=1
      a=a/i
    ans+=(math.sqrt(2*cnt+0.25)-0.5)//1
if not a==1:
  print(int(ans+1))
else:
  print(int(ans))
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=a%10
if b==0,1,6,8:
  print("pon")
elif b==2,4,5,7,9:
  print("hon")
else:
  print("bon")

Fixed submission:
a=int(input())
b=a%10
if b in [0,1,6,8]:
  print("pon")
elif b in [2,4,5,7,9]:
  print("hon")
else:
  print("bon")
Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
if len(a)+1==len(b) and a==b[0:a]:
  print("Yes")
else:
  print("No")

Fixed submission:
a=input()
b=input()
if len(a)+1==len(b) and b[:len(a)]==a:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
if len(a)+1=len(b) and a==b[0:a]:
  print("Yes")
else:
  print("No")

Fixed submission:
a=input()
b=input()
if len(a)+1==len(b) and b[:len(a)]==a:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
ans=0
if not a<k:
  print(k)
else:
  if not a+b<k:
    print(a)
  else:
    print(2*a+b-k)

Fixed submission:
a,b,c,d=map(int,input().split())
ans=0
if not a<d:
  print(d)
else:
  if not a+b<d:
    print(a)
  else:
    print(2*a+b-d)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a=<b:
  print("unsafe")
else:
  print("safe")

Fixed submission:
a,b=map(int,input().split())
if a<=b:
  print("unsafe")
else:
  print("safe")
Buggy python submission (verdict: Runtime Error):
a=list(int(input()))
if 7 in a:
  print("Yes")
else:
  print("No")

Fixed submission:
a=list(input())
if 	"7" in a:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a,b=map(iNt,input().split())
c=list(map(int,input().split()))
c=[i for i in c if i>a/(4*b)]
if len(c)<b:
  print("No")
else:
  print("Yes")

Fixed submission:
a,b=map(int,input().split())
c=list(map(int,input().split()))
d=sum(c)/(4*b)
e=[i for i in c if i<d]
if len(e)>a-b:
  print("No")
else:
  print("Yes")
Buggy python submission (verdict: Runtime Error):
a=int(input())
c=len(a)
b=a[:(c-1)//2]
d=a[(c+3)//2:]
if a==a[::-1] and b==b[::-1] and d==d[::-1]:
  print("Yes")
else:
  print("No")

Fixed submission:
a=input()
c=len(a)
b=a[:(c-1)//2]
d=a[(c+3)//2-1:]
if a==a[::-1] and b==b[::-1] and d==d[::-1]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
ans=0
for i in rnage(0,b,a-1):
  ans+=1
print(ans+1)

Fixed submission:
a,b=map(int,input().split())
ans=0
for i in range(1,b,a-1):
  ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
k=int(input())
A=[0]*k
C=[7%k]
A[7%k]=1
if 7%k==0:
    print(1)
    sys.exit()
while True:
    now=(C[-1]*10+7)%k
    C.append(now)
    if now==0:
        print(len(C))
        break
    if A[now]:
        print(-1)
        break

Fixed submission:
import sys
k=int(input())
A=[0]*k
C=[7%k]
A[7%k]=1
if 7%k==0:
    print(1)
    sys.exit()
while True:
    now=(C[-1]*10+7)%k
    if A[now]==1:
        print(-1)
        break
    A[now]=1
    C.append(now)
    if now==0:
        print(len(C))
        break

Buggy python submission (verdict: Time Limit Exceeded):
import sys
k=int(input())
A=[0]*k
C=[7%k]
A[7%k]=1
if 7%k==0:
    print(1)
    sys.exit()
while True:
    now=(C[-1]*10+7)%k
    C.append(now)
    if now==0:
        print(len(C))
        break
    if A[now]:
        print(-1)
        break

Fixed submission:
import sys
k=int(input())
A=[0]*k
C=[7%k]
A[7%k]=1
if 7%k==0:
    print(1)
    sys.exit()
while True:
    now=(C[-1]*10+7)%k
    if A[now]==1:
        print(-1)
        break
    A[now]=1
    C.append(now)
    if now==0:
        print(len(C))
        break
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
 
n,k=map(int,input().split())
A=list(map(int,input().split()))
for i in range(min(k,50)):
    P=[]
    M=[]
    cnt=0
    for a in range(n):
        if A[a]==n:
            cnt+=1
            continue
        P.append(a-A[a])
        M.append(a+A[a]+1)
    P.sort()
    M.sort()
    P=deque(P)
    M=deque(M)
    C=[]
    m=n
    for j in range(n):
        if P:
            while P[0]<=j:
                P.popleft()
                cnt+=1
                if not P:
                    break
        if M:
            while M[0]<=j:
                M.popleft()
                cnt-=1
                if not M:
                    break
        C.append(cnt)
        m=min(cnt,m)
    A=C
    if m==n:
        break
print(*A)

Fixed submission:
from collections import deque

n,k=map(int,input().split())
A=list(map(int,input().split()))
for i in range(min(k,50)):
    P=[]
    M=[]
    cnt=0
    for a in range(n):
        if A[a]==n:
            cnt+=1
            continue
        P.append(a-A[a])
        M.append(a+A[a]+1)
    P.sort()
    M.sort()
    P=deque(P)
    M=deque(M)
    C=[]
    m=n
    for j in range(n):
        if P:
            while P[0]<=j:
                P.popleft()
                cnt+=1
                if not P:
                    break
        if M:
            while M[0]<=j:
                M.popleft()
                cnt-=1
                if not M:
                    break
        C.append(cnt)
        m=min(cnt,m)
    A=C
    if m==n:
        break
print(*A)

Buggy python submission (verdict: Runtime Error):
from collections import deque

n,k=map(int,input().split())
A=list(map(int,input().split()))
#A=[0]*n
for i in range(min(k,50)):
    P=[]
    M=[]
    cnt=0
    for a in range(n):
        if A[a]==n:
            cnt+=1
            continue
        P.append(a-A[a])
        M.append(a+A[a]+1)
    P.sort()
    M.sort()
    P=deque(P)
    M=deque(M)
    C=[]
    m=n+100
    for j in range(n):
        if P:
            while P[0]<=j:
                P.popleft()
                cnt+=1
                if not P:
                    break
        while M[0]<=j:
            M.popleft()
            cnt-=1
        C.append(cnt)
        m=min(cnt,m)
    A=C
    if m==n:
        break
print(*A)

Fixed submission:
from collections import deque

n,k=map(int,input().split())
A=list(map(int,input().split()))
for i in range(min(k,50)):
    P=[]
    M=[]
    cnt=0
    for a in range(n):
        if A[a]==n:
            cnt+=1
            continue
        P.append(a-A[a])
        M.append(a+A[a]+1)
    P.sort()
    M.sort()
    P=deque(P)
    M=deque(M)
    C=[]
    m=n
    for j in range(n):
        if P:
            while P[0]<=j:
                P.popleft()
                cnt+=1
                if not P:
                    break
        if M:
            while M[0]<=j:
                M.popleft()
                cnt-=1
                if not M:
                    break
        C.append(cnt)
        m=min(cnt,m)
    A=C
    if m==n:
        break
print(*A)
Buggy python submission (verdict: Time Limit Exceeded):
T=input()
ans=""
for t in T:
    if t=="?":
        ans+="D"
    else:
        ans+=t
print(ans)

Fixed submission:
T=input()
ans=""
for t in T:
    if t=="?":
        ans+="D"
    else:
        ans+=t
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))
S=[]
for i in range(n):
    S.append([A[i],i])
S=list(reversed(sorted(S)))
#print(S)
F=[0]*n

ans=0
C=[0]*n
for i in range(n):
    s=S.pop(0)
    d=s[0] #距離
    x=s[1] #座標
    F[x]=1
    L1=max(x-2*d,0)
    L2=max(x-d,-1)
    R1=min(x+d,n)
    R2=min(x+2*d,n-1)
    if L1<=L2:
        for j in range(L1,L2+1):
            if F[j]==1:
                continue
            if x-j==d+A[j]:
                ans+=1
                #print(s,j)
    if R1<=R2:
        for j in range(R1,R2+1):
            if F[j]==1:
                continue
            if j-x==d+A[j]:
                ans+=1
                #print(s,j)
print(ans)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
C=[]
for i in range(n):
    C.append([i+A[i],0])
    C.append([i-A[i],1])
C.sort()
now=C[0][0]
c0=0
c1=0
ans=0
for c in C:
    if now==c[0]:
        if c[1]==0:
            c0+=1
        else:
            c1+=1
    else:
        ans+=c0*c1
        c0=0
        c1=0
        if c[1]==0:
            c0+=1
        else:
            c1+=1
        now=c[0]
ans+=c0*c1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))
S=[]
for i in range(n):
    S.append([A[i],i])
S=list(reversed(sorted(S)))
#print(S)
F=[0]*n

ans=0
C=[0]*n
for i in range(n):
    s=S.pop(0)
    d=s[0] #距離
    x=s[1] #座標
    F[x]=1
    L1=max(x-2*d,0)
    L2=max(x-d,-1)
    R1=min(x+d,n)
    R2=min(x+2*d,n-1)
    if L1<=L2:
        for j in range(L1,L2+1):
            if F[j]==1:
                continue
            if x-j==d+A[j]:
                ans+=1
                #print(s,j)
    if R1<=R2:
        for j in range(R1,R2+1):
            if F[j]==1:
                continue
            if j-x==d+A[j]:
                ans+=1
                #print(s,j)
print(ans)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
C=[]
for i in range(n):
    C.append([i+A[i],0])
    C.append([i-A[i],1])
C.sort()
now=C[0][0]
c0=0
c1=0
ans=0
for c in C:
    if now==c[0]:
        if c[1]==0:
            c0+=1
        else:
            c1+=1
    else:
        ans+=c0*c1
        c0=0
        c1=0
        if c[1]==0:
            c0+=1
        else:
            c1+=1
        now=c[0]
ans+=c0*c1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
n=int(input())
ans=0
for i in range(1,n+1):
    for j in range(i,n+1):
        g=fractions.gcd(i,j)
        for k in range(j,n+1):
            l=fractions.gcd(g,k)
            if i==j and j==k:
                ans+=l
            elif i==j or j==k or k==i:
                ans+=3*l
            else:
                ans+=6*l
print(ans)

Fixed submission:
import fractions
n=int(input())
ans=0
for i in range(1,n+1):
    for j in range(i,n+1):
        g=fractions.gcd(i,j)
        for k in range(j,n+1):
            l=fractions.gcd(g,k)
            if i==j and j==k:
                ans+=l
            elif i==j or j==k or k==i:
                ans+=3*l
            else:
                ans+=6*l
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=input()
RGB=[[] for i in range(3)]
for i in range(n):
    if S[i]=="R":
        RGB[0].append(i)
    elif S[i]=="G":
        RGB[1].append(i)
    else:
        RGB[2].append(i)
L=[len(RGB[0]),len(RGB[1]),len(RGB[2])]
m=L.index(max(L))
A=[]
for i in range(3):
    if i==m:
        continue
    else:
        A.append(i)
C=RGB[A[0]]
D=RGB[A[1]]
E=RGB[m]

ans=0
for i in range(L[A[0]]):
    for j in range(L[A[1]]):
        r=C[i]
        g=D[j]
        d=abs(r-g)
        cnt=0
        if d%2==0:
            if (r+g)//2 in E:
                cnt+=1
        if r<g:
            if g+d in E:
                cnt+=1
            if r-d in E:
                cnt+=1
        if r>g:
            if r+d in E:
                cnt+=1
            if g-d in E:
                cnt+=1
        ans+=L[m]-cnt
print(ans)

Fixed submission:
n=int(input())
S=input()
RGB=[[] for i in range(3)]
for i in range(n):
    if S[i]=="R":
        RGB[0].append(i)
    elif S[i]=="G":
        RGB[1].append(i)
    else:
        RGB[2].append(i)
L=[len(RGB[0]),len(RGB[1]),len(RGB[2])]
m=L.index(max(L))
A=[]
for i in range(3):
    if i==m:
        continue
    else:
        A.append(i)
C=RGB[A[0]]
D=RGB[A[1]]
E=RGB[m]

ans=0
for i in range(L[A[0]]):
    for j in range(L[A[1]]):
        r=C[i]
        g=D[j]
        d=abs(r-g)
        cnt=0
        if d%2==0:
            if (r+g)//2 in E:
                cnt+=1
        u=max(r,g)+d
        l=min(r,g)-d
        if 0<=u<=n-1:
            if u in E:
                cnt+=1
        if 0<=l<=n-1:
            if l in E:
                cnt+=1
        ans+=L[m]-cnt
print(ans)

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)
l=len(B)

ans=0
for i in range(len(R)):
    for j in range(len(G)):
        r=R[i]
        g=G[j]
        d=abs(r-g)
        cnt=0
        if d%2==0:
            if (r+g)//2 in B:
                cnt+=1
        if r<g:
            if g+d in B:
                cnt+=1
            if r-d in B:
                cnt+=1
        if r>g:
            if r+d in B:
                cnt+=1
            if g-d in B:
                cnt+=1
        ans+=l-cnt
print(ans)

Fixed submission:
n=int(input())
S=input()
RGB=[[] for i in range(3)]
for i in range(n):
    if S[i]=="R":
        RGB[0].append(i)
    elif S[i]=="G":
        RGB[1].append(i)
    else:
        RGB[2].append(i)
L=[len(RGB[0]),len(RGB[1]),len(RGB[2])]
m=L.index(max(L))
A=[]
for i in range(3):
    if i==m:
        continue
    else:
        A.append(i)
C=RGB[A[0]]
D=RGB[A[1]]
E=RGB[m]

ans=0
for i in range(L[A[0]]):
    for j in range(L[A[1]]):
        r=C[i]
        g=D[j]
        d=abs(r-g)
        cnt=0
        if d%2==0:
            if (r+g)//2 in E:
                cnt+=1
        u=max(r,g)+d
        l=min(r,g)-d
        if 0<=u<=n-1:
            if u in E:
                cnt+=1
        if 0<=l<=n-1:
            if l in E:
                cnt+=1
        ans+=L[m]-cnt
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
A=[0]*k
mod=10**9+7

def power(a,x): #a**xの計算
    T=[a]
    while 2**(len(T))<mod: #a**1,a**2.a**4,a**8,...を計算しておく
        T.append(T[-1]**2%mod)
    b=bin(x) #xを2進数表記にする
    ans=1
    for i in range(len(b)-2):
        if int(b[-i-1])==1:
            ans=ans*T[i]%mod
    return ans

for i in range(k):
    cnt=power(k//(k-i),n)
    now=(k-i)*2
    while now<=k:
        cnt-=A[now-1]
        now+=k-i
    A[k-i-1]=cnt

ans=0
for i in range(k):
    ans+=(i+1)*A[i]%mod
    ans%=mod
print(ans)

Fixed submission:
n,k=map(int,input().split())
A=[0]*k
mod=10**9+7

def power(a,x): #a**xの計算
    T=[a]
    while 2**(len(T))<mod: #a**1,a**2.a**4,a**8,...を計算しておく
        T.append(T[-1]**2%mod)
    b=bin(x) #xを2進数表記にする
    ans=1
    for i in range(len(b)-2):
        if int(b[-i-1])==1:
            ans=ans*T[i]%mod
    return ans

for i in range(k):
    cnt=power(k//(k-i),n)
    now=(k-i)*2
    while now<=k:
        cnt-=A[now-1]
        now+=k-i
    A[k-i-1]=cnt

ans=0
for i in range(k):
    ans+=(i+1)*A[i]%mod
    ans%=mod
print(ans)