Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, W = list(map(int, input().split()))
wvList = [list(map(int, input().split())) for _ in range(N)]


from collections import defaultdict
dp = defaultdict(int)
dp[0]=0

for wv in wvList:
    w,v = wv
    tp = defaultdict(int,{ i[0]+w : i[1]+v  for i in dp.items() if i[0]+w<=W})
    for i in set(list(dp.keys())+list(tp.keys())):
        dp[i] = max(dp[i],tp[i])

print(max(dp.values()))

Fixed submission:
N, W = list(map(int, input().split()))
wvList = [list(map(int, input().split())) for _ in range(N)]


from collections import defaultdict
dp = defaultdict(int)
dp[0]=0

for wv in wvList:
    w,v = wv
    tp = defaultdict(int,{ i[0]+w : i[1]+v  for i in dp.items() if i[0]+w<=W})
    for i in set(list(dp.keys())+list(tp.keys())):
        dp[i] = max(dp[i],tp[i])

print(max(dp.values()))

Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys 
input = sys.stdin.readline

N, W = list(map(int, input().split()))
wvList = [list(map(int, input().split())) for _ in range(N)]

#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)

l = wvlist[0][0]
for wv in wvlist():
	l = lcm(wv[0],l)
  
dp = np.zeros((N,W+1))
for i, wv in enumerate(wvList):
    for j in range(1, W + 1,l):
        if j - wv[0] >= 0:
            dp[i][j] = np.max(dp[i-1][j-wv[0]] + wv[1], dp[i-1][j])
        else:
            dp[i][j] = dp[i-1][j]

print(np.max(dp))


Fixed submission:
N, W = list(map(int, input().split()))
wvList = [list(map(int, input().split())) for _ in range(N)]


from collections import defaultdict
dp = defaultdict(int)
dp[0]=0

for wv in wvList:
    w,v = wv
    tp = defaultdict(int,{ i[0]+w : i[1]+v  for i in dp.items() if i[0]+w<=W})
    for i in set(list(dp.keys())+list(tp.keys())):
        dp[i] = max(dp[i],tp[i])

print(max(dp.values()))
Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(a, b):
	return a * b // gcd (a, b)
li  = list(map(int,input().split(" ")))
s  = lcm(li[0],li[1])
for i in range(len(li)-2):
    s = lcm (s,li[i+2])
def f(m):
    r = 0
    for i  in li:
        r += m%i
    return r
print(f(s-1))

Fixed submission:
input()
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(a, b):
	return a * b // gcd (a, b)
li  = list(map(int,input().split(" ")))
s  = lcm(li[0],li[1])
for i in range(len(li)-2):
    s = lcm (s,li[i+2])
def f(m):
    r = 0
    for i  in li:
        r += m%i
    return r
print(f(s-1))

Buggy python submission (verdict: Runtime Error):
li  = list(map(int,input().split(" ")))
s  = lcm(li[0],li[1])
for i in range(len(li)-2):
    s = lcm (s,li[i+2])
def f(m):
    r = 0
    for i  in li:
        r += m%i
    return r
print(f(s-1))

Fixed submission:
input()
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(a, b):
	return a * b // gcd (a, b)
li  = list(map(int,input().split(" ")))
s  = lcm(li[0],li[1])
for i in range(len(li)-2):
    s = lcm (s,li[i+2])
def f(m):
    r = 0
    for i  in li:
        r += m%i
    return r
print(f(s-1))
Buggy python submission (verdict: Runtime Error):
import numpy as np
A= np.array([list(map(int,input()split())) for I in range (3)])

for I in range (2):
    j,k,l = A[1]-A[0]
    if not (j==k and k==l):
        print ( "No")
        quit()
    j,k,l = A[2]-A[0]
    if not (j==k and k==l):
        print ( "No")
        quit()
print("Yes")

Fixed submission:
import numpy as np
A= np.array([list(map(int,input().split())) for I in range (3)])

for I in range (2):
    j,k,l = A[1]-A[0]
    if not (j==k and k==l):
        print ( "No")
        quit()
    j,k,l = A[2]-A[0]
    if not (j==k and k==l):
        print ( "No")
        quit()
print("Yes")
Buggy python submission (verdict: Runtime Error):
k = int(input())
from collections import deque
d = deque([1])
discovered = {1:1}
while true:
  q = d.popleft()
  if q == 0: 
  	print(discovered[q])
  	quit()
  if (q*10)%k not in discovered:
    if (q*10)%k == 0:
      
    d.appendleft((q*10)%k)
    discovered[(q*10)%k] = discovered[q]
  if q+1 not in discoverd:
    d.append(q+1)
    discovered[q+1] = discovered[q]+1
    
    

Fixed submission:
k = int(input())
from collections import deque
d = deque( )
d.append((1,1))
discovered = set()
while True:
  node, cost = d.popleft()
  discovered |= {node}
  if node == 0: 
  	print(cost)
  	quit()
  if (node*10)%k not in discovered:
    d.appendleft( ((node*10)%k  ,cost))
  if (node+1)%k not in discovered:
    d.append((node+1,cost+1))
Buggy python submission (verdict: Runtime Error):
N = int(input())
K = int(input())
x = list(map(int,input().split()))
res = 0
for i in x:
  res += 2* min(x,K-x)
print(res)

Fixed submission:
N = int(input())
K = int(input())
x = list(map(int,input().split()))
res = 0
for i in x:
  res += 2* min(i,K-i)
print(res)
Buggy python submission (verdict: Runtime Error):
X,A,B = list(map(int,input()))
if A >= B:
  print("delicious")
else:
  if B-A <= X:
    print("safe")
  else:
    print("dangerous")

Fixed submission:
X,A,B = list(map(int,input().split()))
if A >= B:
  print("delicious")
else:
  if B-A <= X:
    print("safe")
  else:
    print("dangerous")
Buggy python submission (verdict: Runtime Error):
rates  = [399,799,1199,1599,1999,2399,2799,3199]
from collections import defaultdict


def return_index(score):
  for i in rates:
    if score <= i:
      return rates.index(i)
  else:
    return 8

N = int(input())
A = list(map(int,input().split()))
d = defaultdict(int)
for a in A:
  d[return_index(a)] += 1
num_of_9s = d[8]
has_9 = 1 if num_of_9s > 0 else 0
print("{} {}".format(len(d.keys()-has_9 ),len(d.keys())-has_9+num_of_9s ))

Fixed submission:
rates  = [399,799,1199,1599,1999,2399,2799,3199]
from collections import defaultdict


def return_index(score):
  for i in rates:
    if score <= i:
      return rates.index(i)
  else:
    return 8

N = int(input())
A = list(map(int,input().split()))
d = defaultdict(int)
for a in A:
  d[return_index(a)] += 1
key_len = len(d.keys())
num_of_9s = d[8]
has_9 = 1 if num_of_9s > 0 else 0
print("{} {}".format(max(1,key_len-has_9),key_len-has_9+num_of_9s ))
Buggy python submission (verdict: Runtime Error):
N,K=list(map(int,input().split()))

AB =sorted([tuple(map(int,input().split())) for i in range(N)],key=lambda x:-x[0])

B=1

for a,b in AB:
  a,b=tuple(map(int,
  if B>=K :
    print(a)
    quit()
  B+=b
  


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

AB =sorted([tuple(map(int,input().split())) for i in range(N)])

B=0

for a,b in AB:
  #print(K,N,a,b,B)
  B+=b
  if B>=K :
    print(a)
    quit()
  #B+=b
Buggy python submission (verdict: Runtime Error):
a,b,c = list(map(int,input()))
if a+c ==c:
  print("YES")
else:
  print("NO")

Fixed submission:
a,b,c = list(map(int,input().split()))
if a+c == 2*b:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
print((lambda a,b : (a+b)//24)(list(map(int,input().split())) ))

Fixed submission:
print((lambda a : (a[0]+a[1])%24)(list(map(int,input().split())) ))
Buggy python submission (verdict: Runtime Error):
n=int(input())
import math
for i in range (math.sqrt(n),0,-1):
  if n%i==0:
    print(max(len(str(i)),len(str(n//i))))
    quit()

Fixed submission:
n=int(input())
import math
for i in range (int(math.sqrt(n)),0,-1):
  if n%i==0:
    print(max(len(str(i)),len(str(n//i))))
    quit()
Buggy python submission (verdict: Runtime Error):
if [5,5,7] == list(map(int,input().split().sorted())):
  print("YES")
else:
  print("NO")

Fixed submission:
if [5,5,7] == list(map(int,sorted(input().split()))):
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
def tri_len(x,y):
  if x== y:
    return x
  elif x < y:
    return tri_len(y-x,x)+2*x
  else:
    return tri_len(x-y,y)+2*y
import sys
sys.setrecursionlimit(100000)

n,x= list(map(int,input().split(" ")))

print( n+tri_len(x,n-x))

Fixed submission:
a = input()
lst = list(map(int,input().split(" ")))
lst.sort()
ans=0
for i in range(int(len(lst)/2)):
  ans += lst[len(lst)-2*i-2]
 
print(ans)

Buggy python submission (verdict: Runtime Error):
def tri_len(x,y):
  if x== y:
    return x
  elif x < y:
    return tri_len(y-x,x)+2*x
  else:
    return tri_len(x-y,y)+2*y
import sys
sys.setrecursionlimit(10000)

n,x= list(map(int,input().split(" ")))

print( n+tri_len(x,n-x))

Fixed submission:
a = input()
lst = list(map(int,input().split(" ")))
lst.sort()
ans=0
for i in range(int(len(lst)/2)):
  ans += lst[len(lst)-2*i-2]
 
print(ans)

Buggy python submission (verdict: Runtime Error):
a = input()
lst = input().split(" ")
lst.sort()
ans=0
for i in range(int(len(lst))):
  ans += lst[len(lst)-2*i-2]

print(ans)

Fixed submission:
a = input()
lst = list(map(int,input().split(" ")))
lst.sort()
ans=0
for i in range(int(len(lst)/2)):
  ans += lst[len(lst)-2*i-2]
 
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
MAX_NUM = 10 ** 18

def main():
    import math
    N = int(input())
    A = list(map(int, input().split()))
    ans = 1
    for i in range(N):
        ans = ans * A[i]
        
        if(ans > MAX_NUM):
            ans = -1
            if(A[i] == 0):
                ans = 0
                break

    print(ans)



main()

Fixed submission:
MAX_NUM = 10 ** 18

def main():
    import math
    N = int(input())
    A = list(map(int, input().split()))
    A_set = set(A)
    log_sum = 0
    if(0 in A_set):
        print("0")
        return
    
    A_log = [0] * N
    ans = 1
    for i in range(N):
        log_sum += math.log10(A[i])
        if(log_sum > 18):
            ans = -1
            break
        else:
            ans = ans * A[i]
            if(ans > MAX_NUM):
                ans = -1
                break
    print(ans)



main()
Buggy python submission (verdict: Runtime Error):
def main()
    S = input()
    if(S == "ABC"):
        print("ABC")
    else:
        print("ARC")
main()

Fixed submission:
def main():
    S = input()
    if(S == "ABC"):
        print("ARC")
    else:
        print("ABC")
main()
Buggy python submission (verdict: Runtime Error):
a, b, c = map(long, input().split())
if(a * b * 4 < (c - a - b)**2):
    print("Yes")
else:
    print("No")


Fixed submission:
a, b, c = map(int, input().split())
if(c - a - b >= 0 and a * b * 4 < (c - a - b)**2):
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
import math
a, b, c = map(int, input().split())
log_ab = math.log10(a*b)
log_cab = math.log10(c - a - b)
log_2 = math.log10(2)
if(log_ab < 2 * log_cab - 2 * log_2):
    print("Yes")
else:
    print("No")


Fixed submission:
a, b, c = map(int, input().split())
if(c - a - b >= 0 and a * b * 4 < (c - a - b)**2):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
def main():
    N = input()
    c_list = [c for c in N]
    if((c[0] == c[1] and c[0] == c[2]) or (c[1] == c[2] and c[1] == c[3])):
        print("Yes")
    else:
        print("No")

main()

Fixed submission:
def main():
    N = input()
    c = [c for c in N]
    if((c[0] == c[1] and c[0] == c[2]) or (c[1] == c[2] and c[1] == c[3])):
        print("Yes")
    else:
        print("No")

main()
Buggy python submission (verdict: Time Limit Exceeded):

def solve(K, S):
    import bisect
    count = 0
    z_array = [i for i in range(K+1)]
    for x in range(K+1):
        for y in range(K+1):
                z = S - x - y
                index = bisect.bisect_left(z_array, z)
                if(index != K+1 and z_array[index] == z):count+=1
    return count

def main():
    K, S = map(int, input().split())
    print(solve(K, S))
#print(solve(2, 2))
#print(solve(5, 15))
main()

Fixed submission:

def solve(K, S):
    import bisect
    count = 0
    z_array = [i for i in range(K+1)]
    for x in range(K+1):
        for y in range(K+1):
                z = S - x - y
                if(z >= 0 and z <= K):count+=1
    return count

def main():
    K, S = map(int, input().split())
    print(solve(K, S))
#print(solve(2, 2))
#print(solve(5, 15))
main()

Buggy python submission (verdict: Time Limit Exceeded):

def solve(K, S):
    count = 0
    for x in range(K+1):
        for y in range(K+1):
            for z in range(K+1):
                if(x+y+z == S):count+=1
    return count

def main():
    K, S = map(int, input().split())
    print(solve(K, S))

main()

Fixed submission:

def solve(K, S):
    import bisect
    count = 0
    z_array = [i for i in range(K+1)]
    for x in range(K+1):
        for y in range(K+1):
                z = S - x - y
                if(z >= 0 and z <= K):count+=1
    return count

def main():
    K, S = map(int, input().split())
    print(solve(K, S))
#print(solve(2, 2))
#print(solve(5, 15))
main()
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [0 for _ in range(n)]
b = a[:]
for i in range(n):
    a[i],b[i] = map(int,input().split())
a.sort()
b.aort()

ans = 0
if n % 2 == 0:
    l = a[n//2-1] + a[n//2]
    h = b[n//2-1] + b[n//2]

    ans += h - l + 1
else:
    l = a[n//2]
    h = b[n//2]

    ans += h - l + 1



print(ans)

Fixed submission:
n = int(input())
a = [0 for _ in range(n)]
b = a[:]
for i in range(n):
    a[i],b[i] = map(int,input().split())
a.sort()
b.sort()

ans = 0
if n % 2 == 0:
    l = a[n//2-1] + a[n//2]
    h = b[n//2-1] + b[n//2]

    ans += h - l + 1
else:
    l = a[n//2]
    h = b[n//2]

    ans += h - l + 1



print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,s = map(int,input().split())
a = list(map(int,input().split()))
mod = 998244353
dp = [[0 for i in range(s+1)] for j in range(n+1)]
for i in range(n+1):
    dp[i][0] = 1
for i in range(1,n+1):
    x = a[i-1]
    for j in range(s+1):
        dp[i][j] = dp[i-1][j] * 2
        if dp[i][j] >= mod:
            dp[i][j] %= mod
    for j in range(x,s+1):
        if j >= x:
            dp[i][j] += dp[i-1][j-x]
            if dp[i][j] >= mod:
                dp[i][j] %= mod

print(dp[-1][-1])

Fixed submission:
n,s = map(int,input().split())
a = list(map(int,input().split()))
mod = 998244353
dp = [[0 for i in range(s+1)] for j in range(n+1)]
for i in range(n+1):
    dp[i][0] = 1
for i in range(1,n+1):
    x = a[i-1]
    for j in range(s+1):
        dp[i][j] = dp[i-1][j] * 2
        if dp[i][j] >= mod:
            dp[i][j] %= mod
    for j in range(x,s+1):
        if j >= x:
            dp[i][j] += dp[i-1][j-x]
            if dp[i][j] >= mod:
                dp[i][j] %= mod

print(dp[-1][-1])
Buggy python submission (verdict: Time Limit Exceeded):
t = input()
for i in range(len(t)):
    x = t[i]
    if x == '?':
        t = t[:i] + 'D' + t[i+1:]
print(t)



Fixed submission:
t = input()
t = t.replace('?','D')
print(t)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a = list(map(int,input().split()))
t=[[] for j in range(64)]
l=[0 for _ in range(n)]
ll=l[:]
for i in range(64):
    for j in range(n):
        if i == 0:
            l[j]=a[j]
        else:
            l[j]=ll[ll[j]-1]
    ll=l[:]
    t[i]=l[:]
ans=1

for i in range(64):
    r = k%2
    k = k//2
    if r == 1:
        ans = t[i][ans-1]
    if k == 0:
        print(ans)
        exit()

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
dic = {1:1}
his=[1]
p=1
s=0
g=0
step=1
for i in range(k):
    t=a[p-1]
    if (t in dic and dic[t]==1):
        s=t
        g=a[t-1]
        break
    else:
        dic[t]=1
    step+=1
    his.append(t)
    p=t
x=his.index(t)
o=step-x
lp=his[x:]
k-=x
#print(x,o,his,lp)
#print(dic)
print(lp[k%o])

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a = list(map(int,input().split()))
t=[[0 for i in range(n)] for j in range(64)]
for i in range(64):
    for j in range(n):
        if i == 0:
            t[i][j]=a[j]
        else:
            t[i][j]=t[i-1][t[i-1][j]-1]
ans=1
for i in range(64):
    r = k%2
    k = k//2
    if r == 1:
        ans = t[i][ans-1]
    if k == 0:
        print(ans)
        exit()

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
dic = {1:1}
his=[1]
p=1
s=0
g=0
step=1
for i in range(k):
    t=a[p-1]
    if (t in dic and dic[t]==1):
        s=t
        g=a[t-1]
        break
    else:
        dic[t]=1
    step+=1
    his.append(t)
    p=t
x=his.index(t)
o=step-x
lp=his[x:]
k-=x
#print(x,o,his,lp)
#print(dic)
print(lp[k%o])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s=['' for _ in range(n)]
for i in range(n):
    s[i]=input()
#x=[[0,0] for _ in range(n)]
hp,hm=0,0
p=[]
m=[]
for i in range(n):
    t=s[i]
    lv=0
    mn=0
    for u in t:
        if u == '(':
            lv+=1
        elif u == ')':
            lv-=1
        mn=min(mn,lv)
    #x[i][0],x[i][1]=lv,mn
    if lv>=0:
        p.append([lv,mn])
        hp+=lv
    else:
        lv*=-1
        m.append([lv,mn+lv])
        hm+=lv
if hp!=hm:
    print('No')
    exit()
p.sort(key=lambda x: x[1],reverse=1)
m.sort(key=lambda x: x[1],reverse=1)
h=0
lv,mn=0,0
for a,b in p:
    lv+=a
    mn+=b
    if mn<0:
        print('No')
        exit()
    mn=lv
lv,mn=0,0
for a,b in m:
    lv+=a
    mn+=b
    if mn<0:
        print('No')
        exit()
    mn=lv
print('Yes')

#print(lv,mn)
    

Fixed submission:
n = int(input())
s=['' for _ in range(n)]
for i in range(n):
    s[i]=input()
#x=[[0,0] for _ in range(n)]
hp,hm=0,0
p=[]
m=[]
for i in range(n):
    t=s[i]
    lv=0
    mn=0
    for u in t:
        if u == '(':
            lv+=1
        elif u == ')':
            lv-=1
        mn=min(mn,lv)
    #x[i][0],x[i][1]=lv,mn
    if lv>=0:
        p.append([lv,mn])
        hp+=lv
    else:
        lv*=-1
        m.append([lv,mn+lv])
        hm+=lv
if hp!=hm:
    print('No')
    exit()
p.sort(key=lambda x: x[1],reverse=1)
m.sort(key=lambda x: x[1],reverse=1)
h=0
lv,mn=0,0
for a,b in p:
    lv+=a
    mn+=b
    if mn<0:
        print('No')
        exit()
    mn=lv
lv,mn=0,0
for a,b in m:
    lv+=a
    mn+=b
    if mn<0:
        print('No')
        exit()
    mn=lv
print('Yes')

#print(lv,mn)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
l=1
if n%2==1:
    r=n
    for i in range(m):
        print(l,r,min(abs(l-r)))
        l+=1
        r-=1
else:
    if n%4==0:
        r=n
    else:
        r=n-1
    print(l,r,min(abs(l-r),n-abs(l-r)))
    for i in range(m-1):
        l+=1
        r-=1
        print(l,r,min(abs(l-r),n-abs(l-r)))
        if min(abs(l-r),n-abs(l-r))==n//2-1:
            l+=1

Fixed submission:
n,m = map(int,input().split())
l=1
if n%2==1:
    r=n
    for i in range(m):
        d=min(abs(l-r),n-abs(l-r))
        print(l,r)
        l+=1
        r-=1
else:
    if n%4==0:
        r=n-1
    else:
        r=n
    rev=False
    for i in range(m):
        d=min(abs(l-r),n-abs(l-r))
        if d == n//2:
            rev=True
            l+=1
            print(l,r)
        else:
            print(l,r)
        l+=1
        r-=1
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
rst=[0 for j in range(2019)]
x=0
ans=0
for i in range(n):
    y=(int(s[n-1-i])*(10**i))%2019
    x+=y
    if x>=2019:
        x%=2019
    #print(x,y)
    ans+=rst[x]
    rst[x]+=1
if rst[0]==1:
    ans+=1

print(ans)

Fixed submission:
s=input()
n=len(s)
rst=[0 for j in range(2019)]
rst[0]=1
x=0
ans=0
drst=1
for i in range(n):
    y=(int(s[n-1-i])*drst)%2019
    drst=(drst*10)%2019
    x+=y
    if x>=2019:
        x%=2019
    #print(x,y,drst)
    ans+=rst[x]
    rst[x]+=1
#if rst[0]==1:
    #ans+=0

print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
bs=[0 for _ in range(n)]
for x in a:
    bs[x-1]+=1


for x in bs:
    print(x)



Fixed submission:
r=int(input())





print(2*r*3.14159265)
Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
  if b == 0:
    return a
  else:
    return gcd(b,a%b)


k=input()
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    d=gcd(i,j)
    for l in range(1,k+1):
      if d!=1:
        ans+=gcd(d,l)
      else:
        ans+=1


print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(4100000)


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


k=int(input())
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    d=gcd(i,j)
    for l in range(1,k+1):
      if d!=1:
        ans+=gcd(d,l)
      else:
        ans+=1


print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
rr=[]
gg=[]
bb=[]
for i in range(n):
  if s[i]=='R':
    rr.append(i)
  elif s[i]=='G':
    gg.append(i)
  else:
    bb.append(i)
lr=len(rr)
lg=len(gg)
lb=len(bb)
ans=lr*lg*lb
if ans==0:
  print(0)
  exit()
#print(ans,lr,lg,lb)
for x in rr:
  for y in gg:
    for z in bb:
      su=x+y+z
      xx,zz=min(x,y,z),max(x,y,z)
      yy=su-xx-zz
      if zz-yy==yy-xx:
        ans-=1




print(ans)

Fixed submission:
n=int(input())
s=input()
rr=[]
gg=[]
bb=[]
for i in range(n):
  if s[i]=='R':
    rr.append(i)
  elif s[i]=='G':
    gg.append(i)
  else:
    bb.append(i)
lr=len(rr)
lg=len(gg)
lb=len(bb)
ans=lr*lg*lb
if ans==0:
  print(0)
  exit()
#print(ans,lr,lg,lb)
for xx in rr:
  for yy in gg:
    x,y=min(xx,yy),max(xx,yy)
    d=y-x
    a=x-d
    b=y+d
    if 0<=a<n and s[a]=='B':
      ans-=1
    if 0<=b<n and s[b]=='B':
      ans-=1
    if (x+y)%2==0:
      c=(x+y)//2
      if 0<=c<n and s[c]=='B':
        ans-=1



#print(rr,gg,bb)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k=int(input())
a=[1,2,3,4,5,6,7,8,9]
ans=a[:]
if k<=9:
  print(ans[k-1])
  exit()
k-=9
for i in range(9):
  b=[0 for _ in range(9*10**(i+1))]
  ind=0
  for x in a:
    d=x%10
    if d!=9 and d!=0:
      b[ind]=x*10+d-1
      b[ind+1]=x*10+d
      b[ind+2]=x*10+d+1
      ind+=3
    elif d==0:
      b[ind]=x*10+d
      b[ind+1]=x*10+d+1
      ind+=2
    elif d==9:
      b[ind]=x*10+d-1
      b[ind+1]=x*10+d
      ind+=2
  b=b[:ind]
  if len(b)>=k:
    print(b[k-1])
    exit()
  else:
    k-=len(b)
  a=b[:]


Fixed submission:
from collections import deque

k=int(input())
ans=deque([1,2,3,4,5,6,7,8,9])
if k<=9:
  print(ans[k-1])
  exit()
k-=9
while True:
  x=ans.popleft()
  r=x%10
  if r==0:
    q=x*10
    ans.append(q)
    k-=1
    if k==0:
      print(q)
      exit()
    q+=1
    ans.append(q)
    k-=1
    if k==0:
      print(q)
      exit()
  elif r!=0 and r!=9:
    q=x*10+r-1
    ans.append(q)
    k-=1
    if k==0:
      print(q)
      exit()
    q+=1
    ans.append(q)
    k-=1
    if k==0:
      print(q)
      exit()
    q+=1
    ans.append(q)
    k-=1
    if k==0:
      print(q)
      exit()
  elif r==9:
    q=x*10-1+r
    ans.append(q)
    k-=1
    if k==0:
      print(q)
      exit()
    q+=1
    ans.append(q)
    k-=1
    if k==0:
      print(q)
      exit()

Buggy python submission (verdict: Time Limit Exceeded):
k=int(input())
a=[1,2,3,4,5,6,7,8,9]
ans=a[:]
if k<=9:
  print(ans[k-1])
  exit()
k-=9
for i in range(9):
  b=[0 for _ in range(9*10**(i+1))]
  ind=0
  for x in a:
    d=x%10
    if d!=9 and d!=0:
      b[ind]=x*10+d-1
      b[ind+1]=x*10+d
      b[ind+2]=x*10+d+1
      ind+=3
    elif d==0:
      b[ind]=x*10+d
      b[ind+1]=x*10+d+1
      ind+=2
    elif d==9:
      b[ind]=x*10+d-1
      b[ind+1]=x*10+d
      ind+=2
  b=b[:ind]
  ans.extend(b)
  if len(b)>=k:
    print(b[k-1])
    exit()
  else:
    k-=len(b)
  a=b[:]


print(ans[k-1])
#print(len(ans))
#print(ans)

Fixed submission:
from collections import deque

k=int(input())
ans=deque([1,2,3,4,5,6,7,8,9])
if k<=9:
  print(ans[k-1])
  exit()
k-=9
while True:
  x=ans.popleft()
  r=x%10
  if r==0:
    q=x*10
    ans.append(q)
    k-=1
    if k==0:
      print(q)
      exit()
    q+=1
    ans.append(q)
    k-=1
    if k==0:
      print(q)
      exit()
  elif r!=0 and r!=9:
    q=x*10+r-1
    ans.append(q)
    k-=1
    if k==0:
      print(q)
      exit()
    q+=1
    ans.append(q)
    k-=1
    if k==0:
      print(q)
      exit()
    q+=1
    ans.append(q)
    k-=1
    if k==0:
      print(q)
      exit()
  elif r==9:
    q=x*10-1+r
    ans.append(q)
    k-=1
    if k==0:
      print(q)
      exit()
    q+=1
    ans.append(q)
    k-=1
    if k==0:
      print(q)
      exit()