Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,W=map(int,input().split())
wv=[[int(j) for j in input().split()] for _ in range(N) ]
w0=wv[0][0]
w1=w0+1
w2=w1+1 
w3=w2+1
wv=sorted(wv,key=lambda x:x[1],reverse=True)
wv=sorted(wv)

ans=0
from bisect import bisect_left as bll
for e1 in range(0,W//w0+1):
  l2=W-w0*e1
  for e2 in range(0,l2//(w0+1)+1):
    l3=l2-(w0+1)*e2
    for e3 in range(0,l3//(w0+2)+1):
      l4=l3- (w0+2)*e3
      e4 =l4//(w0+3)    
      tmp=0
      i1=bll(wv, (w0,inf))
      i2=bll(wv, (w1,inf))
      i3=bll(wv, (w2,inf))
      i4=bll(wv, (w3,inf))
      tmp+=sum(wv[i1:i1+e1])  \
         +sum(wv[i2:i2+e2])  \
         +sum(wv[i3:i3+e3])  \
        +sum(wv[i4:i4+e4])
      ans=max(ans,tmp)
      
print(ans)

Fixed submission:
N,W=map(int,input().split())
wv=[ tuple([int(j) for j in input().split()]) for _ in range(N) ]
w1=wv[0][0]
w2=w1+1
w3=w1+2 
w4=w1+3

wv=sorted(wv,key=lambda x:x[1],reverse=True)
wv=sorted(wv,key=lambda x:x[0])
wvv = list(map(lambda x:x[1], wv))

# print(wv)
inf = float("inf")
ans=0
from collections import defaultdict
counter = defaultdict(int)

for i in range(N):
    w,v = wv[i]
    counter[w] += 1

from bisect import bisect_left as bll

for e1 in range(0, counter[w1]+1):
  for e2 in range(0, counter[w2]+1):
    for e3 in range(0,counter[w3]+1):
      for e4 in range(0, counter[w4]+1):
          tmp=0

          if w1*e1 + w2*e2 + w3*e3 + w4*e4 > W:
              continue

          i1=bll(wv, (w1,-inf))
          i2=bll(wv, (w2,-inf))
          i3=bll(wv, (w3,-inf))
          i4=bll(wv, (w4,-inf))

          tmp= tmp \
             +sum(wvv[i1:i1+e1])  \
             +sum(wvv[i2:i2+e2])  \
             +sum(wvv[i3:i3+e3])  \
             +sum(wvv[i4:i4+e4])

          ans=max(ans,tmp)
      
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
from collections import Counter,defaultdict
s=input()
ddict=defaultdict(int)
for c in s:
  ddict[c]+=1
for i in range(N-1):
  s=input()
  cnt=Counter[s]
  for k in cnt.keys():
    ddict[k]=min(ddict[k],cnt[k])
ans=""
for k in range(26):    
  c =chr(ord("a")+k)
  ans+=c*ddict[c]
print(ans)
  

Fixed submission:
N=int(input())
from collections import Counter,defaultdict
s=input()
ddict=defaultdict(int)
for c in s:
  ddict[c]+=1
for i in range(N-1):
  s=input()
  cnt=Counter(s)
  for k in cnt.keys():
    ddict[k]=min(ddict[k],cnt[k])
  for k in ddict.keys():
    if not k in cnt.keys():
      ddict[k]=0
ans=""
for k in range(26):    
  c =chr(ord("a")+k)
  ans+=c*ddict[c]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

def gk(n):
    ans = 0
    while n:
        ans += 1
        n//=10
    return ans

if int(N**(1/2)) ** 2 == N:
    print( gk( int(N**(1/2)) ))
else:
    for i in range( int(N**(1/2)), N+1):
        if N % i == 0:
            print( gk(i) )
            exit(0)



Fixed submission:
N = int(input())

def gk(n):
    ans = 0
    while n:
        ans += 1
        n //= 10
    return ans


ans = float("inf")
for i in range(1, int(N**(1/2))+1):
    if N % i == 0:
        ans = min(ans,gk( N//i)) 
print(ans)
exit(0)


lst = []
for i in range(2,int(N**(1/2))+1):
    if N % i == 0:
        ans = 0
        while N % i == 0:
            ans += 1
            N //= i
        lst.append( (i,ans) )

cand = [1]
while lst:
    p,cnt = lst.pop()
    nl = []
    # for p ==
Buggy python submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
V = list(map(int, input().split()))

V.sort(reverse=True)

mean = sum(V[:A]) / A
mean = float(mean)

print(mean)


def fact(n):
    if n == 0 or n == 1: return 1
    return fact(n-1) * n

def comb(n,a):
    return fact(n)//fact(a)//fact(n-a)

from collections import Counter
c = Counter(V)
n = c[V[0]]


if V[0] != V[A-1]:
    n = c[V[A-1]]
    if n > 1:
        idx = V.index[V[A-1]] 
        _A = A - idx
        print( comb( n, _A ) )
        # print(n); exit()
    else:
        print(1); exit()

if V[0] == V[A-1]:
    ans = 0
    for i in range(A, min(n+1, B+1)):
        ans += comb(n, i)

    print( ans )

Fixed submission:
N,A,B=map(int,input().split())
V=list(map(int,input().split()))
V=sorted(V,reverse=True)

def fac(n):
  if n<= 1: return 1
  return n*fac(n-1)
def c (a,b): 
  if b==0: return 1
  return fac(a)//fac(b)//fac(a-b)


print(sum(V[:A])/A)

if V.count(V[0]) >= A:
  ans=0
  for i in range(A, min(B+1,V.count(V[0])+1)):
    ans+=c(V.count(V[0]),i)
else:
  ans=c(V.count(V[A-1]), V[:A].count(V[A-1]))
print(ans)

Buggy python submission (verdict: Runtime Error):
N,A,B=map(int,input().split())
V=list(map(int,input().split()))
V=sorted(V,reverse=True)

def fac(n):
  if n<= 1: return 1
  return n*fac(n-1)
def c (a,b): 
  if b==0: return 1
  return fac(a)//fac(b)//fac(a-b)


print(sum(V[:A])/A)

if V.count(V[0]) >= A:
  ans=0
  for i in range(A, min(B+1,V.count(V[A])+1))):
    ans+=c(V.count(V[A]),i)
else:
  lstcnt=A-1
  ans=V.count(V[A])
print(ans)
  


Fixed submission:
N,A,B=map(int,input().split())
V=list(map(int,input().split()))
V=sorted(V,reverse=True)

def fac(n):
  if n<= 1: return 1
  return n*fac(n-1)
def c (a,b): 
  if b==0: return 1
  return fac(a)//fac(b)//fac(a-b)


print(sum(V[:A])/A)

if V.count(V[0]) >= A:
  ans=0
  for i in range(A, min(B+1,V.count(V[0])+1)):
    ans+=c(V.count(V[0]),i)
else:
  ans=c(V.count(V[A-1]), V[:A].count(V[A-1]))
print(ans)

Buggy python submission (verdict: Runtime Error):
N,A,B=map(int,input().split())
V=list(map(int,input().split()))
V=sorted(V,reverse=True)

def fac(n):
  if n== 1: return 1
  return n*fac(n-1)
def c (a,b): 
  if b==0: return 1
  return fac(a)//fac(b)//fac(a-b)


print(sum(V[:A])/A)

if V.count(V[A]) >= A:
  ans=0
  for i in range(A, min(B+1,V.count(V[A])+1))):
    ans+=c(V.count(V[A]),i)
else:
  ans=V.count(V[A])
print(ans)
  

Fixed submission:
N,A,B=map(int,input().split())
V=list(map(int,input().split()))
V=sorted(V,reverse=True)

def fac(n):
  if n<= 1: return 1
  return n*fac(n-1)
def c (a,b): 
  if b==0: return 1
  return fac(a)//fac(b)//fac(a-b)


print(sum(V[:A])/A)

if V.count(V[0]) >= A:
  ans=0
  for i in range(A, min(B+1,V.count(V[0])+1)):
    ans+=c(V.count(V[0]),i)
else:
  ans=c(V.count(V[A-1]), V[:A].count(V[A-1]))
print(ans)
Buggy python submission (verdict: Runtime Error):
#!/mnt/c/Users/moiki/bash/env/bin/python
sx,sy,tx,ty = map(int, input().split())

ans = ""

#UP
ans += "U" * (ty-sy)
ans += "R" * (tx-sx)
ans += "D" * (ty-sy)
ans += "L" * (tx-sx)
ans += "L" + "U"* (ty-sy+1) + "R" * (tx-sx+1) + "D"
ans += "R" + "D" * (ty-sy+1) + "L"*(tx-sx+1) + "U"

print(ans)



Fixed submission:
N,M = map(int, input().split())
inp = []
for i in range(M):
    a,b,c = map(int,input().split())
    inp.append( (a-1, b-1, c) )

inf = float("inf")
dist  =  [[inf] * N for _ in range(N)]

for i in range(M):
    dist[inp[i][0]][inp[i][1]] = inp[i][2]
    dist[inp[i][1]][inp[i][0]] = inp[i][2]

for mid in range(N):
    for start in range(N):
        for end in range(N):
            dist[start][end] = min(dist[start][end],
                    dist[start][mid] + dist[mid][end])


ans = 0
for ai,bi,ci in inp:
    if dist[ai][bi] != ci:
        ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
lst = ["dreamer", "dream", "eraser", "erase"]
lst = [ "".join(list(reversed(k))) for k in lst]
S = "".join(list(reversed(S)))

i  = 0
while i < len(S):
    found = False
    for k in lst:
        try:
            if S[i:].index(k) == 0:
                found = True
                i += len(k)
                break
        except:
            continue

    if not found:
        print("NO")
        exit(0)
print("YES")


Fixed submission:
S = input()
lst = ["dreamer", "dream", "eraser", "erase"]
lst = [ "".join(list(reversed(k))) for k in lst]
S = "".join(list(reversed(S)))

i  = 0
while i < len(S):
    found = False
    for k in lst:
        try:
            if S[i:].index(k) == 0:
                found = True
                i += len(k)
                break
        except:
            continue

    if not found:
        print("NO")
        exit(0)
print("YES")

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
lst = ["dreamer", "dream", "eraser", "erase"]
lst = [ "".join(list(reversed(k))) for k in lst]
S = "".join(list(reversed(S)))

i  = 0
while i < len(S):
    found = False
    for k in lst:
        try:
            # print("k: ",k, "i: ", i, "S[i:]: ", S[i:])
            if S[i:].index(k) == 0:
                found = True
                i += len(k)
                # print("FOUND! i  = ", i, ", S[i:] ", S[i:])
                break
        except:
            continue

    if not found:
        print("NO")
        exit(0)
print("YES")


Fixed submission:
S = input()
lst = ["dreamer", "dream", "eraser", "erase"]
lst = [ "".join(list(reversed(k))) for k in lst]
S = "".join(list(reversed(S)))

i  = 0
while i < len(S):
    found = False
    for k in lst:
        try:
            if S[i:].index(k) == 0:
                found = True
                i += len(k)
                break
        except:
            continue

    if not found:
        print("NO")
        exit(0)
print("YES")
Buggy python submission (verdict: Runtime Error):
K,T=map(int,input().split())
A=list(map(int,input().split()))
from heapq import heappush,heappop
from collections import deque

A.sort(reverse=True)
d=deque(A)
d2=deque(A)
ans=A[0]
mod=1
while d:
  if len(d)==1:
    print(d[0]-1)
  a=d.pop()
  b=d.popleft()
  if not a==1:
    d.append(a-1)
  if not b==1:
    d.appendleft(b-1)

    
  


Fixed submission:
K,T=map(int,input().split())
A=list(map(int,input().split()))
from heapq import heappush,heappop
from collections import deque

A.sort(reverse=True)
d=deque(A)
d2=deque(A)
ans=A[0]
mod=1
while d:
  if len(d)==1:
    print(d[0]-1)
    exit()
  a=d.pop()
  b=d.popleft()
  if not a==1:
    d.append(a-1)
  if not b==1:
    d.appendleft(b-1)
print(0)

Buggy python submission (verdict: Runtime Error):
K,T=map(int,input.split())
A=list(map(int,input().split()))
from heapq import heappush,heappop
from collections import deque

A.sort(reverse=True)
d=deque(A)
while d:
  if len(d)==1:
    print(d-1)
    exit()
  a=d.pop()
  b=d.popleft()
  if not a==1:
    d.append(a-1)
  d.appendleft(b-1)

    
  

Fixed submission:
K,T=map(int,input().split())
A=list(map(int,input().split()))
from heapq import heappush,heappop
from collections import deque

A.sort(reverse=True)
d=deque(A)
d2=deque(A)
ans=A[0]
mod=1
while d:
  if len(d)==1:
    print(d[0]-1)
    exit()
  a=d.pop()
  b=d.popleft()
  if not a==1:
    d.append(a-1)
  if not b==1:
    d.appendleft(b-1)
print(0)
Buggy python submission (verdict: Runtime Error):
s=input()
K=int(input())
ans=[]

for c in s:
  if c=="a":
    ans.append(c)
    continue
  if ord("z")+1- ord(c)<=K:
    K-=ord("z")+1-ord(c)
    ans.append("a")
    continue
    
  ans.append(c)
    
if K:
  ans[-1]=chr( ord(ans[-1])+K)
print("".join(ans))

Fixed submission:
s=input()
K=int(input())
ans=[]

for c in s:
  if c=="a":
    ans.append(c)
    continue
  if ord("z")+1- ord(c)<=K:
    K-=ord("z")+1-ord(c)
    ans.append("a")
    continue
    
  ans.append(c)
    
if K:
  ans[-1]=chr( (ord(ans[-1])+K%26 -ord("a"))%26+ord("a") )
print("".join(ans))
Buggy python submission (verdict: Runtime Error):
N,X = map(int, input().split())
A = list(map(int, input().split()))

# ans = 10**13
ans = float("inf")

for k in range(N):
    tmp = k * X  

    for i in range(2*N):
        j = (i-k+N*4) % N
        A[i] = min(A[i], A[j])
    tmp += sum(A)

    ans = min(ans, tmp)
print(ans)


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

ans = float("inf")
bik = A[:]

get_idx_back = lambda idx,b: idx-b if idx>=b else idx+N-b

for loop in range(0, N+1):
  if loop == 0:
      bik = A[:]
  else: 
      for i in range(N):
          bik[i] = min(bik[i], A[ get_idx_back(i, loop) ])

  tmp = (loop)*X + sum(bik)

  ans = min(tmp, ans)
print(ans)
exit(0)

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

ans = float("inf")
for loop in range(0, N+1):
  mxcnt = loop
  NC=A[:]
  for i in range(2*N+1):
    if i >=N: i%=N    
    pcnt=1
    pi=(i+1)%N
    v=A[i]
    while pcnt<=mxcnt:
      if v>=NC[pi]: break   
      NC[pi]=v
      pcnt+=1
      pi=(pi+1)%N
    tmp = (mxcnt)*X + sum(NC)
    ans = min(tmp, ans)
    # print("loop: ", loop, NC)
print(ans)
exit(0)


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

ans = float("inf")
bik = A[:]

get_idx_back = lambda idx,b: idx-b if idx>=b else idx+N-b

for loop in range(0, N+1):
  if loop == 0:
      bik = A[:]
  else: 
      for i in range(N):
          bik[i] = min(bik[i], A[ get_idx_back(i, loop) ])

  tmp = (loop)*X + sum(bik)

  ans = min(tmp, ans)
print(ans)
exit(0)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=[int(input()) for _ in range(N)]

ans=0
for i in range(N):
  if A[i]==0:
    idx.append(i+1)
n=0
idx.append(N)
for iidx in idx:
  ans+=sum(A[n:iidx])//2
  n=iidx
print(ans)

Fixed submission:
N=int(input())
A=[int(input()) for _ in range(N)]

ans=0
idx=[]
for i in range(N):
  if A[i]==0:
    idx.append(i+1)
n=0
idx.append(N)
for iidx in idx:
  ans+=sum(A[n:iidx])//2
  n=iidx
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=[int(input()) for _ in range(N)]
 
ans=0
for i in range(N):
  if A[i]==0:
    idx.append(i+1)
  
n=0
idx.append(N)
for iidx in idx:
  ans+=sum(A[n:iidx])//2
  n=iidx
print(ans)

Fixed submission:
N=int(input())
A=[int(input()) for _ in range(N)]

ans=0
idx=[]
for i in range(N):
  if A[i]==0:
    idx.append(i+1)
n=0
idx.append(N)
for iidx in idx:
  ans+=sum(A[n:iidx])//2
  n=iidx
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=[int(input()) for _ in range(N)]
 
ans=0
for i in range(N):
  if A[i]==0:
    idx.append(i+1)
  
n=0
for iidx in idx:
  ans+=sum(A[n:iidx])//2
  n=iidx
print(ans)

Fixed submission:
N=int(input())
A=[int(input()) for _ in range(N)]

ans=0
idx=[]
for i in range(N):
  if A[i]==0:
    idx.append(i+1)
n=0
idx.append(N)
for iidx in idx:
  ans+=sum(A[n:iidx])//2
  n=iidx
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=[int(input()) for _ in range(N)]
 
ans=0
#0,1,2のみにする
for i in range(N):
  a=A[i]
  if a>=2 and a%2==0:
    A[i]=2
    ans+=(a-2)//2
  elif a%2==1:
    A[i]=1
    ans+=(a-1)//2
  elif a==0:
    pass
  

for i in range(1,N-1):
  b,a,c=A[i-1:i+1]
  if a==2:
    if b%2==1 and c %2==1:
      A[i-1]-=1 
      A[i+1]-=1
      A[i]-=2
      ans+=2
    
for i in range(1,N):
  a,b=A[i-1:i+1]
  if a%2==1 and b%2==1:
    ans+=1
    A[i-1]-=1
    A[i]-=1  

ans+=len(list(filter(lambda x:x==2,A)))
print(ans)


Fixed submission:
N=int(input())
A=[int(input()) for _ in range(N)]

ans=0
idx=[]
for i in range(N):
  if A[i]==0:
    idx.append(i+1)
n=0
idx.append(N)
for iidx in idx:
  ans+=sum(A[n:iidx])//2
  n=iidx
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=[int(input()) for _ in range(N)]
 
ans=0
for i in range(1,N+1):
  if A[i-1]>=A[i]:
    ans+=A[i]
    ans+=(A[i-1]-A[i])//2
    A[i]=0
  else:
    ans+=A[i-1]
    ans+=(A[i]-A[i-1])//2
    A[i]-=A[i-1]
    
print(ans)

Fixed submission:
N=int(input())
A=[int(input()) for _ in range(N)]

ans=0
idx=[]
for i in range(N):
  if A[i]==0:
    idx.append(i+1)
n=0
idx.append(N)
for iidx in idx:
  ans+=sum(A[n:iidx])//2
  n=iidx
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
XY=[[int(j)for j in input().split()]for _ in range(M)]
cnt=[1]*(N+1)
ans=[1]
for x,y in XY: 
  cnt[x]-=1
  cnt[y]+=1
  if x in ans and not y in ans: 
    ans.append(y)
  if x in ans and cnt[x]==0:
    ans.pop(ans.index(x))
print(len(ans))

Fixed submission:
N,M=map(int,input().split())
XY=[[int(j)for j in input().split()]for _ in range(M)]
cnt=[1]*(N+1)
ans=[False]*(N+1)
ans[1]=True
for x,y in XY: 
  cnt[x]-=1
  cnt[y]+=1
  if ans[x] and not ans[y]: 
    ans[y]=True
  if ans[x] and cnt[x]==0:
    ans[x]=False
print(sum(ans))
Buggy python submission (verdict: Runtime Error):
import sys;raw_input = sys.stdin.readline
N = int(raw_input())
A = [None]*N
C = [0]*N
for i in xrange(N):
    A[i] = int(raw_input())
b = False
for i in xrange(1, N):
    if A[i] - A[i-1] > 1 :
        b = True
        break
if b or A[0] != 0:
    print -1
else:
    B = [0]*N
    ans = 0
    for i in xrange(1, N):
        val = B[i-1] + 1
        B[i] = val if val <= A[i] else 0
        C[i] = A[i] - B[i]
    for i in xrange(N-1, 0, -1):
        if B[i-1] == B[i]-1 :
            C[i-1] = min(C[i], C[i-1])
    C[0] = 0
    for i in xrange(1, N):
        if B[i] == B[i-1] + 1:
            assert C[i] >= C[i-1]
            C[i] = C[i-1] if A[i-1] + 1 >= B[i] + C[i-1] else min(C[i], A[i-1]-B[i])
            ans += (A[i] - B[i-1] - C[i] if B[i+1] == B[i] + 1 or B[i+1] <= 1 else A[i]) if i < N-1 else A[i] - B[i-1] - C[i]
        else:
            ans += A[i]
    print ans

Fixed submission:
a, b, c, k = map(int, raw_input().split())
ans = ((-1)**k) *(a-b)
print ans if abs(ans) <= 10**18 else 'Unfair'
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

import math
from functools import reduce
def gcd(numbers):
    return reduce(math.gcd,numbers)

ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += gcd([i,j,k])

print(ans)

Fixed submission:
K = int(input())

def gcd(a,b):#a>b
    if b==0:
        return a
    else:
        return gcd(b,a%b)

gcdtable = [[1 for i in range(K+1)] for j in range(K+1)]
for i in range(1,K+1):
    for j in range(1,K+1):
        gcdtable[i][j] = gcd(i,j)

ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += gcd(gcdtable[i][j],k)


print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = str(input())

posR = []
posG = []
posB = []

ctR = 0
ctG = 0
ctB = 0

for i in range(N):
    if S[i]=="R":
        posR.append(i)
        ctR += 1
    if S[i]=="G":
        posG.append(i)
        ctG += 1
    if S[i]=="B":
        posB.append(i)
        ctB += 1


def upper_bound(T,SSS):#スライスの値を返す。同じ値があったら右寄りに出す
    left = 0 #SSS[left]はTより真に小さい
    right = len(SSS)-1 #SSS[right]はTと同じかそれ以上

    if T<SSS[left]:
        return 0
    if T>=SSS[right]:
        return right+1

    while True:
        mid = (left+right)//2
        if right-left==1:
            return right
        if SSS[mid]<=T:
            left = mid
        else:
            right = mid


def calc(pos1,pos2,pos3):
    ct = 0
    for i in pos1:
        buff = upper_bound(i,pos2)
        for j in pos2[buff:]:#大丈夫？
            buff2 = upper_bound(j,pos3)
            ct += len(pos3)-buff2
            #print(i,j,len(pos3)-buff2)
            if 2*j-i in pos3:
                ct -= 1
    return ct

ans = 0
ans += calc(posR,posG,posB)
ans += calc(posR,posB,posG)
ans += calc(posG,posR,posB)
ans += calc(posG,posB,posR)
ans += calc(posB,posR,posG)
ans += calc(posB,posG,posR)
print(ans)


Fixed submission:
N = int(input())
S = str(input())

r = S.count("R")
g = S.count("G")
b = S.count("B")

ct = r*g*b

for i in range(N-2):
    for j in range(i+1,N-1):
        k = 2*j-i
        if k<=N-1:
            if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
                ct-=1
print(ct)

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

posR = []
posG = []
posB = []

ctR = 0
ctG = 0
ctB = 0

for i in range(N):
    if S[i]=="R":
        posR.append(i)
        ctR += 1
    if S[i]=="G":
        posG.append(i)
        ctG += 1
    if S[i]=="B":
        posB.append(i)
        ctB += 1


def upper_bound(T,SSS):#スライスの値を返す。同じ値があったら右寄りに出す
    left = 0 #SSS[left]はTより真に小さい
    right = len(SSS)-1 #SSS[right]はTと同じかそれ以上

    if T<SSS[left]:
        return 0
    if T>=SSS[right]:
        return right+1

    while True:
        mid = (left+right)//2
        if right-left==1:
            return right
        if SSS[mid]<=T:
            left = mid
        else:
            right = mid


def calc(pos1,pos2,pos3):
    ct = 0
    for i in pos1:
        buff = upper_bound(i,pos2)
        for j in pos2[buff:]:#大丈夫？
            buff2 = upper_bound(j,pos3)
            ct += len(pos3)-buff2
            #print(i,j,len(pos3)-buff2)
            if 2*j-i in pos3:
                ct -= 1
    return ct

ans = 0
ans += calc(posR,posG,posB)
ans += calc(posR,posB,posG)
ans += calc(posG,posR,posB)
ans += calc(posG,posB,posR)
ans += calc(posB,posR,posG)
ans += calc(posB,posG,posR)
print(ans)


Fixed submission:
N = int(input())
S = str(input())

r = S.count("R")
g = S.count("G")
b = S.count("B")

ct = r*g*b

for i in range(N-2):
    for j in range(i+1,N-1):
        k = 2*j-i
        if k<=N-1:
            if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
                ct-=1
print(ct)
Buggy python submission (verdict: Runtime Error):
S = str(input())
if S[3]==S[4] and S[5]==S[6]:
    print("Yes")
else:
    print("No")

Fixed submission:
S = str(input())
if S[2]==S[3] and S[4]==S[5]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
Q = int(input())

isreverse = False
head=[]
tail=[]

for i in range(Q):
    query = input()
    if str(query)[0]=="1":
        isreverse = isreverse^True
    else:
        F = int(query.split()[1])
        C = str(query.split()[2])
        if (F==1 and isreverse==False) or (F==2 and isreverse==True):
            head.insert(0,C)
        else:
            tail.append(C)


if isreverse==False:
    print("".join(head)+S+"".join(tail))
else:
    print("".join(reversed(tail))+S[::-1]+"".join(reversed(head)))

Fixed submission:
S = str(input())
Q = int(input())

isreverse = False
head=[]
tail=[]

for i in range(Q):
    query = input()
    if str(query)[0]=="1":
        isreverse = isreverse^True
    else:
        F = int(query.split()[1])
        C = str(query.split()[2])
        if (F==1 and isreverse==False) or (F==2 and isreverse==True):
            head.append(C)
        else:
            tail.append(C)


if isreverse==False:
    print("".join(reversed(head))+S+"".join(tail))
else:
    print("".join(reversed(tail))+S[::-1]+"".join(head))

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
Q = int(input())

isreverse = False

for i in range(Q):
    query = input()
    if str(query)[0]=="1":
        isreverse = isreverse^True
    else:
        F = int(query.split()[1])
        C = str(query.split()[2])
        if (F==1 and isreverse==False) or (F==2 and isreverse==True):
            S = C+S
        else:
            S = S+C
if isreverse==False:
    print(S)
else:
    print(S[::-1])

Fixed submission:
S = str(input())
Q = int(input())

isreverse = False
head=[]
tail=[]

for i in range(Q):
    query = input()
    if str(query)[0]=="1":
        isreverse = isreverse^True
    else:
        F = int(query.split()[1])
        C = str(query.split()[2])
        if (F==1 and isreverse==False) or (F==2 and isreverse==True):
            head.append(C)
        else:
            tail.append(C)


if isreverse==False:
    print("".join(reversed(head))+S+"".join(tail))
else:
    print("".join(reversed(tail))+S[::-1]+"".join(head))

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
Q = int(input())

for i in range(Q):
    query = input()
    if str(query)[0]=="1":
        S = S[::-1]
    else:
        F = int(query.split()[1])
        C = str(query.split()[2])
        if F==1:
            S = C+S
        else:
            S = S+C
print(S)

Fixed submission:
S = str(input())
Q = int(input())

isreverse = False
head=[]
tail=[]

for i in range(Q):
    query = input()
    if str(query)[0]=="1":
        isreverse = isreverse^True
    else:
        F = int(query.split()[1])
        C = str(query.split()[2])
        if (F==1 and isreverse==False) or (F==2 and isreverse==True):
            head.append(C)
        else:
            tail.append(C)


if isreverse==False:
    print("".join(reversed(head))+S+"".join(tail))
else:
    print("".join(reversed(tail))+S[::-1]+"".join(head))