Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
B = [int(x) for x in input().split()]

ans = 0


for i in range(n):
    cnt = 0
    flag = True
    j = i
    while flag == True:
        if j < n-1:
        
            if B[j] >= B[j+1]:
                cnt += 1
                j += 1 
            else:
                flag = False
        else:
            flag = False
    
    ans = max(ans,cnt)

print(ans)

Fixed submission:
n = int(input())
B = [int(x) for x in input().split()]

ans = [0]*n

for i in range(n-1):
    if B[i] >= B[i+1]:
        ans[i] = 1

cnt = 0
a = 0
for j in range(n):
    
    if ans[j] == 1:
        cnt += 1
    else:
        a = max(a,cnt)
        cnt = 0

print(a)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
number = [int(x)+1 for x in range(n)]

print(sum(number[:-1]))

Fixed submission:
n = int(input())

if n % 2 == 0:
    print(int((n+1)*(n//2)-n))
else:
    print(int(n*(n//2)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
number = [int(x)+1 for x in range(n)]
#numberを一つずらしたリストを作成
I = number[1:]
I.append(number[0])

ans = 0
M = 0
for i in range(n):
    M = number[i]%I[i]
    ans += M
print(ans)

Fixed submission:
n = int(input())

if n % 2 == 0:
    print(int((n+1)*(n//2)-n))
else:
    print(int(n*(n//2)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
number = [int(x)+1 for x in range(n)]
#numberを一つずらしたリストを作成
I = number[1:]
I.append(number[0])

ans = 0
M = 0
for i in range(n):
    M = number[i]%I[i]
    ans += M
print(ans)

Fixed submission:
n = int(input())

if n % 2 == 0:
    print(int((n+1)*(n//2)-n))
else:
    print(int(n*(n//2)))
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
mod = 1000000007

dp = [0]*(N+1)
dp[0] = 1
A = []

for _ in range(M):
    k = int(input())
    A.append(k)

if 1 in A:
   dp[1] = 0
   if 2 in A:
       dp[2] = 0
else:
    dp[1] = 1
    
for i in range(2,N+1):
    if i not in A:
        dp[i] = (dp[i-1] + dp[i-2])%mod

print(dp[-1])

Fixed submission:
N,M = map(int,input().split())
mod = 1000000007

dp = [0]*(N+1)
dp[0] = 1
A = []
for _ in range(M):
    k = int(input())
    A.append(k)
A = sorted(A,reverse = True)

if len(A)>0:
    a = A.pop()
else: a = -1
        
if a == 1:
    dp[1] = 0
    if len(A)>0:
        a = A.pop()
    if a == 2:
        dp[2] == 0
else:
    dp[1] = 1
    
for i in range(2,N+1):
    if i == a:
        if len(A)>0:
            a = A.pop()
        #continue
    else:
        if dp[i-1] != 0 and dp[i-2] != 0:
            dp[i] = (dp[i-1] + dp[i-2])%mod
        elif dp[i-1] != 0:
            dp[i] = dp[i-1]%mod
        elif dp[i-2] != 0:
            dp[i] = dp[i-2]%mod
        else:
            dp[i] = 0
        
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
mod = 1000000007

dp = [0]*(N+1)
dp[0] = 1
A = []

for _ in range(M):
    k = int(input())
    A.append(k)

if 1 in A:
   dp[1] = 0
   if 2 in A:
       dp[2] = 0
else:
    dp[1] = 1
    
for i in range(2,N+1):
    if i not in A:
        dp[i] = (dp[i-1] + dp[i-2])%mod

print(dp[-1])

Fixed submission:
N,M = map(int,input().split())
mod = 1000000007

dp = [0]*(N+1)
dp[0] = 1
A = []
for _ in range(M):
    k = int(input())
    A.append(k)
A = sorted(A,reverse = True)

if len(A)>0:
    a = A.pop()
else: a = -1
        
if a == 1:
    dp[1] = 0
    if len(A)>0:
        a = A.pop()
    if a == 2:
        dp[2] == 0
else:
    dp[1] = 1
    
for i in range(2,N+1):
    if i == a:
        if len(A)>0:
            a = A.pop()
        #continue
    else:
        if dp[i-1] != 0 and dp[i-2] != 0:
            dp[i] = (dp[i-1] + dp[i-2])%mod
        elif dp[i-1] != 0:
            dp[i] = dp[i-1]%mod
        elif dp[i-2] != 0:
            dp[i] = dp[i-2]%mod
        else:
            dp[i] = 0
        
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))

cnt = 0


for b in B :
    a_cnt = len(A[:bisect.bisect_left(A,b)])
    c_cnt = len(C[bisect.bisect_right(C,b):])
    cnt += a_cnt * c_cnt
    
print(cnt)

Fixed submission:
import bisect

n = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))

cnt = 0


for j in range(n) :
    a = bisect.bisect_left(A,B[j])
    c = bisect.bisect_right(C,B[j])
    cnt += a * (n-c)
    
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))

cnt = 0

for a in A:
    for b in B[bisect.bisect_right(B,a):]:
        cnt += len(C[bisect.bisect_right(C,b):])
        #for c in C [bisect.bisect_left(C,b):]:
            #if a < b < c :
                #cnt += 1

print(cnt)

Fixed submission:
import bisect

n = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))

cnt = 0


for j in range(n) :
    a = bisect.bisect_left(A,B[j])
    c = bisect.bisect_right(C,B[j])
    cnt += a * (n-c)
    
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))

cnt = 0

for a in A:
    for b in B[bisect.bisect_left(B,a):]:
        for c in C [bisect.bisect_left(C,b):]:
            if a < b < c :
                cnt += 1

print(cnt)

Fixed submission:
import bisect

n = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))

cnt = 0


for j in range(n) :
    a = bisect.bisect_left(A,B[j])
    c = bisect.bisect_right(C,B[j])
    cnt += a * (n-c)
    
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))

cnt = 0

for a in A:
    for b in B[bisect.bisect_left(B,a):]:
        for c in C [bisect.bisect_left(C,b):]:
            if a < b < c :
                cnt += 1

print(cnt)

Fixed submission:
import bisect

n = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))

cnt = 0


for j in range(n) :
    a = bisect.bisect_left(A,B[j])
    c = bisect.bisect_right(C,B[j])
    cnt += a * (n-c)
    
print(cnt)
Buggy python submission (verdict: Runtime Error):
String=input()
String=list(String)
String=[(String[i:i+2]) for i in range(0, len(String),2)]
String[0]="".join(String[0])
String[1]="".join(String[1])
String[0]=int(String[0])
String[1]=int(String[1])
if(String[0]>=0 and String[0]<=12and String[1]>0 and String[1]<=12):
    print("AMBIGUOUS")
elif(String[0]==String[1]==0 or String[0]>12 and String[0]!=0 and String[1]>12 and String[1]!=0):
    print("NA")
elif(String[1]>0 and String[1]<13):
    print("YYMM")
elif(String[0]>0 and String[0]<13):
    print("MMYY")
elif(String[0]==0 and String[1]>12):
    print("NA")
else:
    print("NA")

Fixed submission:
String=input()
String=list(String)
String=[(String[i:i+2]) for i in range(0, len(String),2)]
String[0]="".join(String[0])
String[1]="".join(String[1])
String[0]=int(String[0])
String[1]=int(String[1])
if(String[0]>0 and String[0]<=12and String[1]>0 and String[1]<=12):
    print("AMBIGUOUS")
elif(String[0]==String[1]==0 or String[0]>12 and String[0]!=0 and String[1]>12 and String[1]!=0):
    print("NA")
elif(String[1]>0 and String[1]<13):
    print("YYMM")
elif(String[0]>0 and String[0]<13):
    print("MMYY")
elif(String[0]==0 and String[1]>12):
    print("NA")
else:
    print("NA")
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))

sum = []

s = 1
for i in range(k):
    s *= a[i]
sum.append(s)

for i in range(k+1, n+1):
    i -= 1
    s = s * a[i] // a[i-k]
    sum.append(s)

for i in range(n-k):
    i += 1
    if sum[i] > sum[i-1]:
        print("Yes")
    else:
        print("No")



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

for i in range(k+1, n+1):
    i -= 1
    if a[i-k] < a[i]:
        print("Yes")
    else:
        print("No")

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

sum = []

s = 1
for i in range(k):
    s *= a[i]
sum.append(s)

for i in range(k+1, n+1):
    i -= 1
    s = s * a[i] // a[i-k]
    sum.append(s)

for i in range(n-k):
    i += 1
    if sum[i] > sum[i-1]:
        print("Yes")
    else:
        print("No")



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

for i in range(k+1, n+1):
    i -= 1
    if a[i-k] < a[i]:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
n = input()

m = int(n[1:])

if 1000-m != 1000:
    print(1000-m)
else:
    print(0)


Fixed submission:
n = int(input())

pay = 0
while pay < n:
    pay += 1000

print(pay-n)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())

ans = sum(a)
A = Counter(a).most_common()
d = [0] * 10**5+10
for i in range(len(A)):
    d[A[i][0]] = A[i][1]

B = []
C = []
for i in range(q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

for i in range(q):
    d[C[i]] += d[B[i]]
    cnt = d[B[i]]
    ans += (C[i]-B[i])*cnt
    print(ans)
    d[B[i]] = 0

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())

ans = sum(a)
A = Counter(a).most_common()
d = [0] * (10**5+10)
for i in range(len(A)):
    d[A[i][0]] = A[i][1]

B = []
C = []
for i in range(q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

for i in range(q):
    d[C[i]] += d[B[i]]
    cnt = d[B[i]]
    ans += (C[i]-B[i])*cnt
    print(ans)
    d[B[i]] = 0

Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())

ans = sum(a)
A = Counter(a).most_common()
d = [0] * 10**5
for i in range(len(A)):
    d[A[i][0]] = A[i][1]

B = []
C = []
for i in range(q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

for i in range(q):
    d[C[i]] += d[B[i]]
    cnt = d[B[i]]
    ans += (C[i]-B[i])*cnt
    print(ans)
    d[B[i]] = 0

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())

ans = sum(a)
A = Counter(a).most_common()
d = [0] * (10**5+10)
for i in range(len(A)):
    d[A[i][0]] = A[i][1]

B = []
C = []
for i in range(q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

for i in range(q):
    d[C[i]] += d[B[i]]
    cnt = d[B[i]]
    ans += (C[i]-B[i])*cnt
    print(ans)
    d[B[i]] = 0

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

ans = sum(a)
A = ''
for i in range(n):
    A += ' ' + str(a[i])

B = []
C = []
for i in range(q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

for i in range(q):
    s = A.replace(str(B[i]), str(C[i]))
    cnt = A.count(str(B[i]))
    ans += (C[i]-B[i])*cnt
    print(ans)
    A = s


Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())

ans = sum(a)
A = Counter(a).most_common()
d = [0] * (10**5+10)
for i in range(len(A)):
    d[A[i][0]] = A[i][1]

B = []
C = []
for i in range(q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

for i in range(q):
    d[C[i]] += d[B[i]]
    cnt = d[B[i]]
    ans += (C[i]-B[i])*cnt
    print(ans)
    d[B[i]] = 0
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

a.sort()

M = 1000005
cnt = [0] * M

for i in range(n):
    if cnt[a[i]] != 0:
        cnt[a[i]] = 2
        continue
    for j in range(a[i], M, a[i]):
        cnt[j] += 1

ans = 0

for i in range(n):
    if cnt[a[i]] == 1:
        ans += 1

print(ans)

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

check = 1000000
ans = 0

N = list(range(-300, 300))

for i in range(1, 101):
    if i in p:
        N.remove(i)

for i in range(len(N)):
    if check > abs(N[i]-x):
        check = abs(N[i]-x)
        ans = N[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

a.sort()

v = [True] * 1000010
v2 = [False] * 1000010
for i in range(n):
    j = 2
    while a[i]*j < 1000010:
        v[a[i]*j] = False
        j += 1
    if v2[a[i]]:
        v[a[i]] = False
    v2[a[i]] = True

ans = 0

for i in range(n):
    if v[a[i]]:
        ans += 1

print(ans)

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

a.sort()

M = 1000005
cnt = [0] * M

for i in range(n):
    if cnt[a[i]] != 0:
        cnt[a[i]] = 2
        continue
    for j in range(a[i], M, a[i]):
        cnt[j] += 1

ans = 0

for i in range(n):
    if cnt[a[i]] == 1:
        ans += 1

print(ans)

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

a.sort()

v = [True] * 1000010
v2 = [False] * 1000010
for i in range(n):
    j = 2
    while a[i]*j < 1000010:
        v[a[i]*j] = False
        j += 1
    if v2[a[i]]:
        v[a[i]] = False
    v2[a[i]] = True

ans = 0

for i in range(n):
    if v[a[i]]:
        ans += 1

print(ans)

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

a.sort()

M = 1000005
cnt = [0] * M

for i in range(n):
    if cnt[a[i]] != 0:
        cnt[a[i]] = 2
        continue
    for j in range(a[i], M, a[i]):
        cnt[j] += 1

ans = 0

for i in range(n):
    if cnt[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 *= a[i]
    
if ans > 10**18:
        print(-1)
        exit()

print(ans)


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

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

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())

y = 1000
s = -1000
t = -1000

a = 0
b = 0

while s < y:
    t = -y
    while t < y:
        if s ** 5 - t ** 5 == x:
            a = int(s)
            b = int(t)
        t += 1
    s += 1

print(a, b)






Fixed submission:
x = int(input())

y = 1000
s = -1000
t = -1000

a = 0
b = 0

while s < y:
    t = -y
    while t < y:
        if s ** 5 - t ** 5 == x:
            a = int(s)
            b = int(t)
        t += 1
    s += 1

print(a, b)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

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

for i, j in combinations(range(n), 2):
    if a[i] + a[j] == abs(i-j):
        ans += 1

print(ans)



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

ans = 0
mp = {}

for i in range(n):
    sa = i - a[i]
    if sa in mp:
        ans += mp[sa]
    wa = i + a[i]
    if wa in mp:
        mp[wa] += 1
    else:
        mp[wa] = 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

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

for i, j in combinations(range(n), 2):
    if a[i] + a[j] == abs(i-j):
        ans += 1

print(ans)



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

ans = 0
mp = {}

for i in range(n):
    sa = i - a[i]
    if sa in mp:
        ans += mp[sa]
    wa = i + a[i]
    if wa in mp:
        mp[wa] += 1
    else:
        mp[wa] = 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()[::-1]

cnt = [0] * 2019
cnt[0] = 1
total = 0
ans = 0
x = 1

for i in s:
    total += int(i) * x
    total %= 2019
    x *= 10 % 2019
    ans += cnt[total]
    cnt[total] += 1

print(ans)


Fixed submission:
s = input()[::-1]

n = len(s)
cnt = [0] * 2019
cnt[0] = 1
total = 0
ans = 0
x = 1

for i in range(n):
    total += int(s[i]) * x
    total %= 2019
    x *= 10
    x %= 2019
    ans += cnt[total]
    cnt[total] += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()[::-1]

n = len(s)
cnt = [0] * 2019
cnt[0] = 1
total = 0
ans = 0
x = 1

for i in range(n):
    total += int(s[i]) * x
    total %= 2019
    x *= 10 % 2019
    ans += cnt[total]
    cnt[total] += 1

print(ans)


Fixed submission:
s = input()[::-1]

n = len(s)
cnt = [0] * 2019
cnt[0] = 1
total = 0
ans = 0
x = 1

for i in range(n):
    total += int(s[i]) * x
    total %= 2019
    x *= 10
    x %= 2019
    ans += cnt[total]
    cnt[total] += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()[::-1]

n = len(s)
cnt = [0] * 2019
cnt[0] = 1
total = 0
ans = 0
x = 1

for i in range(n):
    total += int(s[i]) * x
    total %= 2019
    x *= 10 % 2019
    ans += cnt[total]
    cnt[total] += 1

print(ans)


Fixed submission:
s = input()[::-1]

n = len(s)
cnt = [0] * 2019
cnt[0] = 1
total = 0
ans = 0
x = 1

for i in range(n):
    total += int(s[i]) * x
    total %= 2019
    x *= 10
    x %= 2019
    ans += cnt[total]
    cnt[total] += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()[::-1]

n = len(s)
cnt = [0] * 2019
cnt[0] = 1
total = 0
ans = 0
x = 1

for i in range(n):
    total += int(s[i]) * x
    total %= 2019
    x *= 10
    ans += cnt[total]
    cnt[total] += 1

print(ans)


Fixed submission:
s = input()[::-1]

n = len(s)
cnt = [0] * 2019
cnt[0] = 1
total = 0
ans = 0
x = 1

for i in range(n):
    total += int(s[i]) * x
    total %= 2019
    x *= 10
    x %= 2019
    ans += cnt[total]
    cnt[total] += 1

print(ans)

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

c = ''
ans = 0
for i in range(len(s)):
    c = ''
    for j in range(i, len(s)):
        c += s[j]
        if int(c) % 2019 == 0:
            ans += 1
print(ans)


Fixed submission:
s = input()[::-1]

n = len(s)
cnt = [0] * 2019
cnt[0] = 1
total = 0
ans = 0
x = 1

for i in range(n):
    total += int(s[i]) * x
    total %= 2019
    x *= 10
    x %= 2019
    ans += cnt[total]
    cnt[total] += 1

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

for i in range(1, n):
    print(a[i-1:].count(i))
print(0)


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

ans = [0] * n

for i in lst:
    ans[i-1] += 1

print(*ans)

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())
lst = list(map(int, input().split()))

ans = [0] * n

for i in lst:
    ans[i-1] += 1

print(*ans)

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())
lst = list(map(int, input().split()))

ans = [0] * n

for i in lst:
    ans[i-1] += 1

print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from math import gcd

K = int(input())

count = 0

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            a = [i, j, k]
            if 1 in a:
                count += 1
                continue
            else:
                count += reduce(gcd, a)
print(count)


Fixed submission:
from math import gcd

K = int(input())

count = 0

for i in range(1, K+1):
    for j in range(1, K+1):
        a = gcd(i, j)
        for k in range(1, K+1):
            count += gcd(a, k)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from math import gcd

K = int(input())

count = 0

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            a = [i, j, k]
            count += reduce(gcd, a)
print(count)


Fixed submission:
from math import gcd

K = int(input())

count = 0

for i in range(1, K+1):
    for j in range(1, K+1):
        a = gcd(i, j)
        for k in range(1, K+1):
            count += gcd(a, k)
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

count = 0

for i in range(n):
    for j in range(i, n):
        for k in range(j, n):
            if (s[i] != s[j] and s[i] != s[k] and s[j] != s[k]) and (j - i != k - j):
                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):
    for j in range(i+1, n):
        if 2 * j - i < n:
            if s[i] != s[j] and s[i] != s[2*j-i] and s[j] != s[2*j-i]:
                cnt += 1

print(r * g * b - cnt)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))

total = sum(a)

count = 0

valid = total / (4 * m)

for i in a:
    if i > valid:
        count += 1

if count >= m:
    print('Yes')
else:
    print('No')


Fixed submission:
x, y, z = map(int, input().split())

x, y = y, x
x, z = z, x

print(x, y, z)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

while abs(n-k) <= n:
    n = abs(n-k)

print(n)


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

t = n % k

if t < (k - t):
    print(t)
else:
    print(k - t)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

c = Counter(a)
s = 0

for i in c.keys():
    n = c[i]
    if n >= 2:
        s += comb(n, 2)

for i in a:
    n = c[i]
    if 1 <= n-1 < 2:
        ans = s - comb(n, 2)
    elif n-1 >= 2:
        ans = s - comb(n, 2) + comb(n-1, 2)
    else:
        ans = s


    print(ans)




Fixed submission:
from collections import Counter

def combination2(n):
    return int(n * (n-1) / 2)

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

c = Counter(a)
s = 0

for i in c.values():
    s += combination2(i)

for i in a:
    n = c[i]
    ans = s - combination2(n) + combination2(n-1)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

for i in range(q):
    Q = list(input().split())
    if int(Q[0]) == 1:
        s = s[::-1]
    else:
        if int(Q[1]) == 1:
            t = s[::-1]
            t += Q[2]
            s = t[::-1]
        else:
            s += Q[2]

print(s)


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

s = deque(s)
cnt = 0

for i in range(q):
    Q = list(input().split())
    if int(Q[0]) == 1:
        cnt += 1
    else:
        if int(Q[1]) == 1:
            if cnt % 2 == 0:
                s.appendleft(Q[2])
            else:
                s.append(Q[2])
        else:
            if cnt % 2 == 0:
                s.append(Q[2])
            else:
                s.appendleft(Q[2])

ans = ''

for _ in range(len(s)):
    if cnt % 2 == 0:
        ans += s.popleft()
    else:
        ans += s.pop()

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

MOD = 10**9+7
ans = 0

for i in range(60):
    cnt = 0
    for a in A:
        cnt += a>>i&1
    ans += cnt*(n-cnt)*2**i
    ans %= MOD

print(ans)



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

MOD = 10**9+7
ans = 0

for i in range(60):
    cnt = 0
    for a in A:
        cnt += a>>i&1
    ans += cnt*(n-cnt)*2**i
    ans %= MOD

print(ans)