Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input())
print(n + max(0, (m-2*n)//4) if m>=2 else "0")

Fixed submission:
n, m = map(int, input().split())
print(min(n, m//2)+max(0, (m-n*2)//4))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input())
print(n + max(0, (m-2*n)//4) if m>=2 else 0)

Fixed submission:
n, m = map(int, input().split())
print(min(n, m//2)+max(0, (m-n*2)//4))
Buggy python submission (verdict: Runtime Error):
m, n = map(int, input().split())
edge = [[False for j in range(n)] for i in range(n)]
for _ in range(m):
	a, b = map(int, input().split())
	edge[a-1][b-1] = edge[b-1][a-1] = True
visited = [False for _ in range(n)]
ans = 0
def dfs(v):
	visited[v] = True
	if all(x==True for x in visited):
		global ans
		ans += 1
		return
	for i in range(0, n):
		if edge[v][i]==True and visited[i]==False:
			dfs(i)
			visited[i] = False
			return
dfs(0)
print(ans)

Fixed submission:
n, m = map(int, input().split())
edge = [[False for j in range(n)] for i in range(n)]
for _ in range(m):
	a, b = map(int, input().split())
	edge[a-1][b-1] = edge[b-1][a-1] = True
visited = [False for _ in range(n)]
ans = 0
def dfs(v):
	visited[v] = True
	if all(x==True for x in visited):
		global ans
		ans += 1
		return
	for i in range(0, n):
		if edge[v][i]==True and visited[i]==False:
			dfs(i)
			visited[i] = False
dfs(0)
print(ans)

Buggy python submission (verdict: Runtime Error):
m, n = map(int, input().split())
edge = [[False for j in range(n)] for i in range(n)]
for _ in range(m):
	a, b = map(int, input().split())
	edge[a-1][b-1] = edge[b-1][a-1] = True
visited = [False for _ in range(n)]
ans = 0
def dfs(v):
	visited[v] = True
	if all(x==True for x in visited):
		global ans
		ans += 1
		return
	for i in range(0, n):
		if edge[v][i]==True and visited[i]==False:
			dfs(i)
			visited[i] = False
dfs(0)
print(ans)

Fixed submission:
n, m = map(int, input().split())
edge = [[False for j in range(n)] for i in range(n)]
for _ in range(m):
	a, b = map(int, input().split())
	edge[a-1][b-1] = edge[b-1][a-1] = True
visited = [False for _ in range(n)]
ans = 0
def dfs(v):
	visited[v] = True
	if all(x==True for x in visited):
		global ans
		ans += 1
		return
	for i in range(0, n):
		if edge[v][i]==True and visited[i]==False:
			dfs(i)
			visited[i] = False
dfs(0)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = len(bin(n)) - 2
mod = 10**9 + 7
dp = [[0 for j in range(n+1+2**d)] for i in range(d+1)]
dp[0][0] = 1
for i in range(d):
    t = 2 ** (d-i-1)
    for j in range(n+1):
        dp[i+1][j] = (dp[i+1][j] +  dp[i][j]) % mod
        dp[i+1][j+t] = (dp[i+1][j+t] + dp[i][j]) % mod
        dp[i+1][j+2*t] = dp[i][j] % mod
print(sum(dp[d][:n+1]))

Fixed submission:
n = int(input())
d = len(bin(n)) - 2
mod = 10**9 + 7
dp = [[0 for j in range(3)] for i in range(d+1)]
dp[d][0] = 1
for i in range(d):
    k = d - 1 - i
    for j in range(3):
        if j == 0:
            if (n >> k) & 1:
                dp[k][0] += dp[k+1][0]
                dp[k][1] += dp[k+1][0]
            else:
                dp[k][0] += dp[k+1][0]
        elif j == 1:
            if (n >> k) & 1:
                dp[k][1] += dp[k+1][1]
                dp[k][2] += dp[k+1][1] * 2
            else:
                dp[k][0] += dp[k+1][1]
                dp[k][1] += dp[k+1][1]
                dp[k][2] += dp[k+1][1]
        else:
            dp[k][2] += dp[k+1][2] * 3
        map(lambda x:x%mod, dp[k])
print(sum(dp[0]) % mod)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
print("Yes" if a+b=c or b+c=a or c+a=b else "No")

Fixed submission:
a, b, c = map(int, input().split())
print("Yes" if a+b==c or b+c==a or c+a==b else "No")
Buggy python submission (verdict: Runtime Error):
a, b, h = map(int, input().split())
print((a+b)*h/2)

Fixed submission:
a = int(input())
b = int(input())
h = int(input())
print((a+b)*h//2)
Buggy python submission (verdict: Runtime Error):

import math
N=int(input())

T = []
for i in range(N):
    inp = int(input())
    T.append(inp)

cal = T[0]

i = 1
now = T[0]
while(i<N):
    m = T[i] * now
    now = m // math.gcd(now, T[i])
    i+=1
print(now)

Fixed submission:

import math

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

N=int(input())

T = []
for i in range(N):
    inp = int(input())
    T.append(inp)

cal = T[0]

i = 1
now = T[0]
while(i<N):
    m = T[i] * now
    now = m // gcd(now, T[i])
    i+=1
print(now)
Buggy python submission (verdict: Runtime Error):
n = input()
print n if len(n)==2 else n[::-1]

Fixed submission:
n = raw_input()
print n if len(n)==2 else n[::-1]
Buggy python submission (verdict: Runtime Error):
arr=[]
arr.append(int(raw_input());arr.append(int(raw_input());arr.append(int(raw_input())
print (arr[0]-arr[1])%(arr[2])

Fixed submission:
a=int(raw_input());b=int(raw_input());c=int(raw_input())
print (a-b)%c
Buggy python submission (verdict: Runtime Error):
x, k, d = map(int, input().split())
x = abs(x)

if d*k < x:
    print(abs(x)-abs(d*k))
else:
    if abs(x%d-d) > abs(x%d):
        if (k-x//d)%2 == 0:
            print(abs(x%d))
        else:
            print(abs(x%d-d))
    elif abs(x%d-d) < abs(x%d)
        if (k-x//(d+1))%2 == 0:
            print(abs(x%d-d))
        else:
            print(abs(x%d))


Fixed submission:
x, k, d = map(int, input().split())
x = abs(x)

if d*k < x:
    print(x-d*k)
else:
    if (k-x//d)%2 == 0:
        print(x%d)
    else:
        print(abs(x%d-d))
Buggy python submission (verdict: Runtime Error):
from collections import deque
n = int(input())
c = deque(input())

cnt = 0
l = c.popleft()
r = c.pop()
while c:
    if l == 'R':
        l = c.popleft()
    if r == 'W':
        r = c.pop()
    if l == 'W' and r == 'R':
        cnt += 1
        l = c.popleft()
        if not c:
            break
        r = c.pop()

print(cnt)

Fixed submission:
n = int(input())
c = input()

cnt = 0
i = 0
j = n-1
while i < j:
    while c[i] == 'R' and i < j:
        i += 1
    while c[j] == 'W' and i < j:
        j -= 1
    if c[i] != 'W' or c[j] != 'R':
        break
    i += 1
    j -= 1
    cnt += 1

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

g = 1
grade = []
for i in range(n):
    g *= a[i]
    if i+1 > k:
        g /= a[i-k]
    grade.append(int(g))

for i in range(k, n):
    if grade[i-1] < grade[i]:
        print('Yes')
    else:
        print('No')

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

for i in range(n):
    if i+1 > k:
        if a[i-k] < a[i]:
            print('Yes')
        else:
            print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

d = [0]*n
for i in range(1, n+1):
    k = 1
    while i*k <= n:
        d[i*k-1] += 1
        k += 1

ans = 0
for i in range(1, n+1):
    ans += d[i-1]*i
print(ans)

Fixed submission:
n = int(input())
ans = 0
for i in range(1, n+1):
  d = n // i
  ans += d*(d+1)//2*i
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())

d = np.ones(n)

for i in range(2, n+1):
    k = 1
    while i*k <= n:
        d[i*k-1] += 1
        if k == 1:
            d[i*k-1] *= i
        k += 1

print(int(sum(d)))

Fixed submission:
n = int(input())
ans = 0
for i in range(1, n+1):
  d = n // i
  ans += d*(d+1)//2*i
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())

d = np.ones(n)
ii = np.arange(1, n+1)

for i in range(2, n+1):
    k = 1
    while i*k <= n:
        d[i*k-1] += 1
        k += 1

# ans = 0
# for i in range(n):
#     ans += (i+1)*d[i]

print(int(sum(d*ii)))

Fixed submission:
n = int(input())
ans = 0
for i in range(1, n+1):
  d = n // i
  ans += d*(d+1)//2*i
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

d = [1]*n

for i in range(2, n+1):
    k = 1
    while i*k <= n:
        d[i*k-1] += 1
        k += 1

ans = 0
for i in range(n):
    ans += (i+1)*d[i]

print(ans)

Fixed submission:
n = int(input())
ans = 0
for i in range(1, n+1):
  d = n // i
  ans += d*(d+1)//2*i
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = ''

while N > 0:
    N -= 1
    ans += chr(ord('a') + N % 26)
    N //= 26

print(ans[::-1])

Fixed submission:
a = input()
if a.islower():
    print('a')
else:
    print('A')
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())

al = [chr(ord('a') + i) for i in range(26)]



ans = []
mod = 1
cnt = 0
while cnt >= 1:
    k = math.floor(n/26)
    ans.append(al[k % 26 - 1])

print(int(''.join(ans[::-1])))

Fixed submission:
N = int(input())
ans = ''

while N > 0:
    N -= 1
    ans += chr(ord('a') + N % 26)
    N //= 26

print(ans[::-1])

Buggy python submission (verdict: Runtime Error):
import math
n = int(input())

al = [chr(ord('a') + i) for i in range(26)]

print(al[n % 26 - 1])

ans = []
mod = 1
cnt = 0
while cnt >= 1:
    k = math.floor(n/26)
    ans.append(al[k % 26 - 1])

print(int(''.join(ans[::-1])))

Fixed submission:
N = int(input())
ans = ''

while N > 0:
    N -= 1
    ans += chr(ord('a') + N % 26)
    N //= 26

print(ans[::-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = sorted(list(map(int, input().split())))

a_max = a[-1]
dp = [1]*a_max

for i in set(a):
    j = 2
    while i*j <= a_max:
        dp[i*j-1] = 0
        j += 1

ans = 0
for i in range(n):
    if dp[a[i]-1] and a[i-1] != a[i] and a[i] != a[i+1]:
        ans += 1
print(ans)


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

a_max = a[-1]
dp = [1]*a_max

for i in set(a):
    j = 2
    while i*j <= a_max:
        dp[i*j-1] = 0
        j += 1

a.append(0)
ans = 0
for i in range(n):
    if dp[a[i]-1] and a[i-1] != a[i] and a[i] != a[i+1]:
        ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np

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

a = list(set(a))

count = 0
for i in range(n):
    ans = a[i] % np.array(a)
    if np.count_nonzero(ans == 0) == 1:
        count += 1

print(count)


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

a_max = a[-1]
dp = [1]*a_max

for i in set(a):
    j = 2
    while i*j <= a_max:
        dp[i*j-1] = 0
        j += 1

a.append(0)
ans = 0
for i in range(n):
    if dp[a[i]-1] and a[i-1] != a[i] and a[i] != a[i+1]:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

count = 0
for i in range(n):
    ans = a[i] % np.array(a)
    if np.count_nonzero(ans == 0) == 1:
        count += 1

print(count)

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

a_max = a[-1]
dp = [1]*a_max

for i in set(a):
    j = 2
    while i*j <= a_max:
        dp[i*j-1] = 0
        j += 1

a.append(0)
ans = 0
for i in range(n):
    if dp[a[i]-1] and a[i-1] != a[i] and a[i] != a[i+1]:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

count = 0
ans = np.array([np.array(a) % a[0]])
for i in range(1, n):
    ans = np.insert(ans, i, np.array(a) % a[i], axis=0)

count = 0
for i in range(n):
    if np.count_nonzero(ans.T[i] == 0) == 1:
        count += 1

print(count)

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

a_max = a[-1]
dp = [1]*a_max

for i in set(a):
    j = 2
    while i*j <= a_max:
        dp[i*j-1] = 0
        j += 1

a.append(0)
ans = 0
for i in range(n):
    if dp[a[i]-1] and a[i-1] != a[i] and a[i] != a[i+1]:
        ans += 1
print(ans)

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

count = 0
for i in range(n):
    for j in range(n):
        if a[i] % a[j] == 0 and i != j:
            count += 1
            break

print(n-count)

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

a_max = a[-1]
dp = [1]*a_max

for i in set(a):
    j = 2
    while i*j <= a_max:
        dp[i*j-1] = 0
        j += 1

a.append(0)
ans = 0
for i in range(n):
    if dp[a[i]-1] and a[i-1] != a[i] and a[i] != a[i+1]:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in range(n):
    ans = ans * a[i]
    if a[i] == 0:
        print(0)
        exit()

if ans <= 10**18:
    print(ans)
else:
    print(-1)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 1
if a.count(0):
    print(0)
    exit()

for i in range(n):
    ans = ans * a[i]
    if ans > 10**18:
        print(-1)
        exit()

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in range(n):
    ans = ans * a[i]

if ans <= 10**18:
    print(ans)
else:
    print(-1)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 1
if a.count(0):
    print(0)
    exit()

for i in range(n):
    ans = ans * a[i]
    if ans > 10**18:
        print(-1)
        exit()

print(ans)
Buggy python submission (verdict: Runtime Error):
a, b = input().split()
a = int(a)
b = b * 1000
print(int(a*b/1000))

Fixed submission:
from decimal import Decimal
a, b = input().split()
a = Decimal(a)
b = Decimal(b)
print(int(a*b))

Buggy python submission (verdict: Runtime Error):
a = int(a)
b = b * 1000
print(int(a*b/1000))

Fixed submission:
from decimal import Decimal
a, b = input().split()
a = Decimal(a)
b = Decimal(b)
print(int(a*b))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
count = 0
while n > 1:
    for z in range(2, n+1):
        if n % z == 0:
            n = n / z
            count += 1
    break

print(count)

Fixed submission:
def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

# print(prime_decomposition(25))
n = int(input())
p = prime_decomposition(n)
# print(p)

cnt = 0
for k in set(p):
    b = p.count(k)
    a = 1
    c = 1
    while c <= b:
        a += 1
        c += a
    cnt += a - 1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()

n = len(s)
mod = [int(s[n-i-1:]) % 2019 for i in range(n)]
mod.insert(0, 0)

cnt = n+1 - len(list(set(mod)))

print(cnt)

Fixed submission:
s = input()

MOD = 2019
d = [0] * MOD
d[0] = 1
r = 0
t = 1
for i in reversed(s):
    r += int(i) * t
    r %= MOD
    t *= 10
    t %= MOD
    d[r] += 1

print(sum(i * (i - 1) // 2 for i in d))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()

n = len(s)
mod = [int(s[n-i-1:]) % 2019 for i in range(n)]
mod.insert(0, 0)

cnt = 0
for i in range(n-3):
    for I in range(i+4,n+1):
        if mod[i] == mod[I]:
            cnt += 1

print(cnt)

Fixed submission:
s = input()

MOD = 2019
d = [0] * MOD
d[0] = 1
r = 0
t = 1
for i in reversed(s):
    r += int(i) * t
    r %= MOD
    t *= 10
    t %= MOD
    d[r] += 1

print(sum(i * (i - 1) // 2 for i in d))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
T = set([0])
for i in range(len(s)):
    T.add(int(s[i::]) % 2019)

print(len(s)+1-len(T))

Fixed submission:
s = input()

MOD = 2019
d = [0] * MOD
d[0] = 1
r = 0
t = 1
for i in reversed(s):
    r += int(i) * t
    r %= MOD
    t *= 10
    t %= MOD
    d[r] += 1

print(sum(i * (i - 1) // 2 for i in d))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
T = [0]
for i in range(len(s)):
    T.append(int(s[i::]) % 2019)

print(len(T)-len(set(T)))

Fixed submission:
s = input()

MOD = 2019
d = [0] * MOD
d[0] = 1
r = 0
t = 1
for i in reversed(s):
    r += int(i) * t
    r %= MOD
    t *= 10
    t %= MOD
    d[r] += 1

print(sum(i * (i - 1) // 2 for i in d))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
T = [0]
for i in range(len(s)):
    T.append(int(s[i::]))

T = [t % 2019 for t in T]
print(len(T)-len(set(T)))

Fixed submission:
s = input()

MOD = 2019
d = [0] * MOD
d[0] = 1
r = 0
t = 1
for i in reversed(s):
    r += int(i) * t
    r %= MOD
    t *= 10
    t %= MOD
    d[r] += 1

print(sum(i * (i - 1) // 2 for i in d))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()

count = s.count('0000') +s.count('2019') + s.count('4038') + s.count('8076')

for i in range(0, len(s)-4):
    for j in range(i+5, len(s)+1):
        if int(s[i:j]) % 2019 == 0:
            count += 1

print(count)

Fixed submission:
s = input()

MOD = 2019
d = [0] * MOD
d[0] = 1
r = 0
t = 1
for i in reversed(s):
    r += int(i) * t
    r %= MOD
    t *= 10
    t %= MOD
    d[r] += 1

print(sum(i * (i - 1) // 2 for i in d))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
count = 0

for i in range(0, len(s)-3):
    for j in range(i+4, len(s)+1):
        if int(s[i:j]) % 2019 == 0:
            count += 1

print(count)

Fixed submission:
s = input()

MOD = 2019
d = [0] * MOD
d[0] = 1
r = 0
t = 1
for i in reversed(s):
    r += int(i) * t
    r %= MOD
    t *= 10
    t %= MOD
    d[r] += 1

print(sum(i * (i - 1) // 2 for i in d))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

ans = [0]*n
for i in set(a):
    ans[i-1] = a.count(i)

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


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

ans = [0]*n
for i in a:
    ans[i-1] += 1
for i in range(n):
    print(ans[i])

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

aa = set(a)
for i in range(1, n+1):
    if i in aa:
        print(a.count(i))
    else:
        print(0)

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

ans = [0]*n
for i in a:
    ans[i-1] += 1
for i in range(n):
    print(ans[i])

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

for i in range(1, n+1):
    print(a.count(i))
    a.remove(i)

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

ans = [0]*n
for i in a:
    ans[i-1] += 1
for i in range(n):
    print(ans[i])

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

for i in range(1, n+1):
    print(a.count(i))

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

ans = [0]*n
for i in a:
    ans[i-1] += 1
for i in range(n):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
k = int(input())

d = [[] for _ in range(k)]
for i in range(1, k+1):
    for ii in range(1, k+1):
        if i % ii == 0:
            d[i-1].append(ii)

seq = [i for i in range(1, k+1)]
ans = 0
A = list(itertools.combinations_with_replacement(seq, 3))
for a in A:
    a1 = a[0]
    a2 = a[1]
    a3 = a[2]
    if a1 == a2 == a3:
        m = 1
    elif a1 == a2 or a1 == a3 or a2 == a3:
        m = 3
    else:
        m = 6
    ans += max(set(d[a1-1]) & set(d[a2-1]) & set(d[a3-1])) * m

print(ans)

Fixed submission:
import itertools
k = int(input())

d = [[] for _ in range(k)]

for i in range(1, k+1):
    n = 1
    while i*n <= k:
        d[i*n-1].append(i)
        n += 1

seq = [i for i in range(1, k+1)]
ans = 0
A = list(itertools.combinations_with_replacement(seq, 3))
for a in A:
    a1 = a[0]
    a2 = a[1]
    a3 = a[2]
    if a1 == a2 == a3:
        m = 1
    elif a1 == a2 or a1 == a3 or a2 == a3:
        m = 3
    else:
        m = 6
    ans += max(set(d[a1-1]) & set(d[a2-1]) & set(d[a3-1])) * m

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())

d = [[] for _ in range(k)]
for i in range(1, k+1):
    for ii in range(1, k+1):
        if i % ii == 0:
            d[i-1].append(ii)

ans = 0
for a1 in range(k):
    for a2 in range(k):
        for a3 in range(k):
            ans += max(set(d[a1]) & set(d[a2]) & set(d[a3]))

print(ans)

Fixed submission:
import itertools
k = int(input())

d = [[] for _ in range(k)]

for i in range(1, k+1):
    n = 1
    while i*n <= k:
        d[i*n-1].append(i)
        n += 1

seq = [i for i in range(1, k+1)]
ans = 0
A = list(itertools.combinations_with_replacement(seq, 3))
for a in A:
    a1 = a[0]
    a2 = a[1]
    a3 = a[2]
    if a1 == a2 == a3:
        m = 1
    elif a1 == a2 or a1 == a3 or a2 == a3:
        m = 3
    else:
        m = 6
    ans += max(set(d[a1-1]) & set(d[a2-1]) & set(d[a3-1])) * m

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n = int(input())
S = input()

R = []
G = []
B = []
for i, s in enumerate(S):
    if s == 'R':
        R.append(i)
    elif s == 'G':
        G.append(i)
    else:
        B.append(i)

count = 0
# for r in R:
#     for g in G:
#         for b in B:
#             l = sorted([r, b, g])
#             if (l[0] + l[2])/2 != l[1]:
#                 count += 1

for r, g, b in list(itertools.product(R, G, B)):
    l = sorted([r, b, g])
    if (l[0] + l[2])/2 != l[1]:
        count += 1

print(count)

Fixed submission:
n = int(input())
s = input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

cnt = 0
for i in range(n):
    j = 1
    while i + 2*j <= n-1:
        if s[i] != s[i+j] and s[i+j] != s[i+2*j] and s[i+2*j] != s[i]:
            cnt += 1
        j += 1

print(r*g*b-cnt)

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

R = []
G = []
B = []
for i, s in enumerate(S):
    if s == 'R':
        R.append(i)
    elif s == 'G':
        G.append(i)
    else:
        B.append(i)

count = 0
for r in R:
    for g in G:
        for b in B:
            l = sorted([r, b, g])
            if (l[0] + l[2])/2 != l[1]:
                count += 1

print(count)

Fixed submission:
n = int(input())
s = input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

cnt = 0
for i in range(n):
    j = 1
    while i + 2*j <= n-1:
        if s[i] != s[i+j] and s[i+j] != s[i+2*j] and s[i+2*j] != s[i]:
            cnt += 1
        j += 1

print(r*g*b-cnt)
Buggy python submission (verdict: Runtime Error):
from collections import deque
s = deque(input())
q = int(input())

cnt = 0
for _ in range(q):
    i = input().split()
    t = int(i[0])

    if t == 1:
        cnt += 1
    else:
        f = int(i[1])
        c = i[2]
        if (cnt % 2 == 0 and f == 1) or (cnt % 2 == 1 and f == 2):
            s.appendleft(i[2])
        else:
            s.append(i[2])
print(''.join(s) if cnt % 2 == 0 else ''.join(s[::-1]))

Fixed submission:
from collections import deque
s = deque(input())
q = int(input())

cnt = 0
for _ in range(q):
    i = input().split()
    t = int(i[0])

    if t == 1:
        cnt += 1
    else:
        f = int(i[1])
        c = i[2]
        if (cnt % 2 == 0 and f == 1) or (cnt % 2 == 1 and f == 2):
            s.appendleft(i[2])
        else:
            s.append(i[2])

if cnt % 2 == 1:
    s.reverse()
print(''.join(s))