Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

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

ans = 0
for a in range(1,K+1):
    for b in range(1, K+1):
        ab = gcd(a,b)
        for c in range(1, K+1):
            ans += gcd(ab, c)

print(ans)


Fixed submission:
K = int(input())

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

dec = {}
for a in range(1,K+1):
    for b in range(1, K+1):
        if gcd(a,b) not in dec:
            dec[gcd(a,b)] = 1
        else:
            dec[gcd(a,b)] += 1
ans = 0
for c in range(1, K+1):
    for key in dec.keys():
        ans += gcd(c, key)*dec[key]

print(ans)

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

def gcd(a,b):
    mod = max(a,b) % min(a,b)
    if mod == 0:
        temp = min(a,b)
        return temp
    if a >= b:
        a = mod
    else:
        b = mod
    return gcd(a, b)

ans = 0
for a in range(1,K+1):
    for b in range(1, K+1):
        ab = gcd(a,b)
        for c in range(1, K+1):
            ans += gcd(ab, c)

print(ans)


Fixed submission:
K = int(input())

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

dec = {}
for a in range(1,K+1):
    for b in range(1, K+1):
        if gcd(a,b) not in dec:
            dec[gcd(a,b)] = 1
        else:
            dec[gcd(a,b)] += 1
ans = 0
for c in range(1, K+1):
    for key in dec.keys():
        ans += gcd(c, key)*dec[key]

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

R = []
G = []
B = []

for i in range(N):
    if S[i] == 'R':
        R.append(i+1)
    elif S[i] == 'G':
        G.append(i+1)
    elif S[i] == 'B':
        B.append(i+1)

cnt = 0
for r in R:
    for g in G:
        up = max(r, g)
        down = min(r, g)
        diff = up - down
        
        ng = []
        if up + diff <= N:
            ng.append(up+diff)
        if down-diff >= 1:
            ng.append(down-diff)
        if diff%2 == 0:
            ng.append(int(up-diff/2))
        chk = 0
        for i in ng:
            if S[i-1] == 'B':
                chk += 1
        cnt += len(B) - chk

print(cnt)


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

R = []
G = []
B = []

for i in range(N):
    if S[i] == 'R':
        R.append(i+1)
    elif S[i] == 'G':
        G.append(i+1)
    elif S[i] == 'B':
        B.append(i+1)

lenb = len(B)

cnt = 0
for r in R:
    for g in G:
        up = max(r, g)
        down = min(r, g)
        diff = up - down
        
        chk = 0
        if up + diff <= N:
            if S[up+diff-1] == 'B':
                chk += 1
        if down-diff >= 1:
            if S[down-diff-1] == 'B':
                chk += 1
        if diff%2 == 0:
            if S[int(up-diff/2-1)] == 'B':
                chk += 1
        cnt += lenb - chk

print(cnt)

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

R = []
G = []
B = []

for i in range(N):
    if S[i] == 'R':
        R.append(i+1)
    elif S[i] == 'G':
        G.append(i+1)
    elif S[i] == 'B':
        B.append(i+1)

cnt = 0
for r in R:
    for g in G:
        for b in B:
            temp = sorted([r, g, b])
            if (temp[2]-temp[1]) != (temp[1]-temp[0]):
                cnt += 1
print(cnt)

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

R = []
G = []
B = []

for i in range(N):
    if S[i] == 'R':
        R.append(i+1)
    elif S[i] == 'G':
        G.append(i+1)
    elif S[i] == 'B':
        B.append(i+1)

lenb = len(B)

cnt = 0
for r in R:
    for g in G:
        up = max(r, g)
        down = min(r, g)
        diff = up - down
        
        chk = 0
        if up + diff <= N:
            if S[up+diff-1] == 'B':
                chk += 1
        if down-diff >= 1:
            if S[down-diff-1] == 'B':
                chk += 1
        if diff%2 == 0:
            if S[int(up-diff/2-1)] == 'B':
                chk += 1
        cnt += lenb - chk

print(cnt)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

if M >= 1:
    S = []
    C = []
    for _ in range(M):
        s, c = map(int, input().split())
        S.append(s)
        C.append(c)
else:
    if N == 3:
        print(100)
    elif N == 2:
        print(10)
    else:
        print(0)
    exit()

ans = [[] for _ in range(M)]

for i in range(M):
    ans[S[i]-1].append(C[i])

ans2 = []

for i in ans:
    if len(set(i)) > 1:
        print(-1)
        exit()
    if len(i) == 0:
        ans2.append(0)
        continue
    ans2.append(list(set(i))[0])

if ans2[0] == 0:
    print(-1)
    exit()

print(''.join(map(str,ans2)))
    


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

if M >= 1:
    S = []
    C = []
    for _ in range(M):
        s, c = map(int, input().split())
        S.append(s)
        C.append(c)
else:
    if N == 3:
        print(100)
    elif N == 2:
        print(10)
    else:
        print(0)
    exit()

ans = [[] for _ in range(N)]

for i in range(M):
    ans[S[i]-1].append(C[i])

ans2 = []

for i in range(len(ans)):
    if len(set(ans[i])) > 1:
        print(-1)
        exit()
    if len(ans[i]) == 0:
        if i == 0:
            ans2.append(1)
        else:
            ans2.append(0)
        continue
    ans2.append(list(set(ans[i]))[0])

if ans2[0] == 0:
    if N == 1:
        print(0)
        exit()
    else:
        print(-1)
        exit()

print(''.join(map(str,ans2)))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

S = []
C = []
for _ in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)

ans = [[] for _ in range(M)]

for i in range(M):
    ans[S[i]-1].append(C[i])

ans2 = []

for i in ans:
    if len(set(i)) > 1:
        print(-1)
        exit()
    if len(i) == 0:
        ans2.append(0)
        continue
    ans2.append(list(set(i))[0])

if ans2[0] == 0:
    print(-1)
    exit()

print(''.join(map(str,ans2)))
    

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

if M >= 1:
    S = []
    C = []
    for _ in range(M):
        s, c = map(int, input().split())
        S.append(s)
        C.append(c)
else:
    if N == 3:
        print(100)
    elif N == 2:
        print(10)
    else:
        print(0)
    exit()

ans = [[] for _ in range(N)]

for i in range(M):
    ans[S[i]-1].append(C[i])

ans2 = []

for i in range(len(ans)):
    if len(set(ans[i])) > 1:
        print(-1)
        exit()
    if len(ans[i]) == 0:
        if i == 0:
            ans2.append(1)
        else:
            ans2.append(0)
        continue
    ans2.append(list(set(ans[i]))[0])

if ans2[0] == 0:
    if N == 1:
        print(0)
        exit()
    else:
        print(-1)
        exit()

print(''.join(map(str,ans2)))
Buggy python submission (verdict: Time Limit Exceeded):
import collections

N = int(input())
S = [input() for _ in range(N)]

cnt = collections.Counter(S)

ans_list = []

for key, value in cnt.items():
    if value == max(cnt.values()):
        ans_list.append(key)

print(*sorted(ans_list), sep='\n')



Fixed submission:
import collections

N = int(input())
S = [input() for _ in range(N)]

cnt = collections.Counter(S)
max_cnt = max(cnt.values())

ans_list = []

for key, value in cnt.items():
    if value == max_cnt:
        ans_list.append(key)

print(*sorted(ans_list), sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
p = list(map(int, input().split()))

ans = []

for i in range(N-K+1):
    cn = sum(p[i:i+K])
    ans.append(cn)

print((max(ans)+K)/2)


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

import numpy as np

data = np.array(p) + 1

Pcum = np.zeros(N + 1, np.int32)
Pcum[1:] = data.cumsum()

length_K_sums = Pcum[K:] - Pcum[0:-K]

print(np.max(length_K_sums)/2)

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


dice_ind = 0
temp = 0
for i in range(N-K+1):
    dice = sum(p[i:i+K])
    if dice > temp:
        dice_ind = i
        temp = dice
ans = 0
for i in p[dice_ind:dice_ind+K]:
    ans += (1+i)/2

print(ans)


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

import numpy as np

data = np.array(p) + 1

Pcum = np.zeros(N + 1, np.int32)
Pcum[1:] = data.cumsum()

length_K_sums = Pcum[K:] - Pcum[0:-K]

print(np.max(length_K_sums)/2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))

cnt = 0
for i in range(N):
    if P[i] == min(P[:i+1]):
        cnt += 1

print(cnt)


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

min_value = P[0]
cnt = 1
for i in range(1, N):
    if P[i] < min_value :
        min_value = P[i]
        cnt += 1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N, M = map(int, input().split())
ans = [[] for _ in range(N)]
for _ in range(M):
    p, s = input().split()
    if 'AC' not in ans[int(p)-1]:
        ans[int(p)-1].append(s)

cnt = Counter(sum(ans, []))

print(cnt['AC'], cnt['WA'])


Fixed submission:
import numpy as np

N, M = map(int, input().split())

P = []
S = []

for _ in range(M):
    p, s = input().split()
    P.append(int(p))
    S.append(s)

AC = np.zeros(N)
WA = np.zeros(N)

for i in range(M):
    if AC[P[i]-1] == 0:
        if S[i] == 'WA':
            WA[P[i]-1] += 1
        else:
            AC[P[i]-1] += 1

WA[AC == 0] = 0

print(int(sum(AC)), int(sum(WA)))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N = int(input())
A = list(map(int, input().split()))

ans = []

for i in range(1, N+1):
    ans.append(A.index(i)+1)

print(*ans, sep=' ')


Fixed submission:
import numpy as np

N = int(input())
A = list(map(int, input().split()))

ans = [0] * N

for i in range(N):
    ans[A[i]-1] = i+1

print(*ans, sep=' ')
Buggy python submission (verdict: Runtime Error):
L, R = map(int, input().split())

i = max(R - R%2019, L)
mod_i = 2019//(i%2019)
j = max(R - R%mod_i, L+1)

print(i*j%2019)


Fixed submission:
L, R = map(int, input().split())

ans = 2019
for a in range(L, min(L+2019, R)+1):
    for b in range(L, min(L+2019, R)+1):
        if a == b:
            continue
        ans = min(a*b%2019, ans)
        if ans == 0:
            print(0)
            exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import combinations
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

fact = []
for a in A:
    x = prime_factorize(a)
    fact.append(x)

result = []
for f in fact:
    for i in range(1, len(f)+1):
        c = list(set(combinations(f, i)))
        for cc in c:
            result.append(cc)

count = dict(Counter(result))

ans = []
for key, value in count.items():
    temp = 1
    if value >= N-1:
        for k in key:
            temp *= k
        ans.append(temp)
        

print(max(ans))

Fixed submission:
from math import gcd

N = int(input())
A = list(map(int, input().split()))

A = [0] + A + [0]

#Left side
L = [A[1]]
tempL = A[1]
for i in range(1, N):
    tempL = gcd(tempL, A[i+1])
    L.append(tempL)
L = [0] + L
    
#Right side
R = [A[-2]]
tempR = A[-2]
for i in range(1, N):
    tempR = gcd(tempR, A[-i-2])
    R.append(tempR)
R = list(reversed(R)) + [0]

ans = []
for i in range(N):
    result = gcd(L[i], R[i+1])
    ans.append(result)

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

N, K = map(int, input().split())
H = [int(input()) for _ in range(N)]

sH = np.array(sorted(H), dtype=np.int64)
shift = sH[K-1:]
diff = shift - sH[:K]
ans = min(diff)
print(ans)

Fixed submission:
import numpy as np

N, K = map(int, input().split())
H = [int(input()) for _ in range(N)]

sH = np.array(sorted(H), dtype=np.int64)
shift = sH[K-1:]
diff = shift - sH[:len(shift)]
ans = min(diff)
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
h = list(map(int, input().split()))

INF = 10**9
dp = [INF] * (N + K)
dp[0] = 0
for i in range(N):
    for k in range(1, K+1):
        if i + k >= N:
            break
        dp[i+k] = min(dp[i+k], dp[i] + abs(h[i]-h[i+k]))
print(dp[N-1])



Fixed submission:
N = int(input())
for c4 in range(26):
    for c7 in range(16):
        c = 4*c4 + 7*c7
        if c == N:
            print('Yes')
            exit()
print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
mod = 10**9 + 7
power = 1
for i in range(1, N+1):
    power *= i
print(power%mod)


Fixed submission:
N = int(input())
mod = 10**9 + 7
power = 1
for i in range(1, N+1):
    power *= i
    power %= mod
print(power)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ans = 0

for i in range(1, n):
    for j in range(1, n):
        if i*j >= n:
            break
        ans += 1

print(ans)

Fixed submission:
n = int(input())

ans = 0

for i in range(1, n):
    for j in range(i, n):
        if i*j >= n:
            break
        if i == j:
            ans += 1
        else:
            ans += 2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, x, m = map(int, input().split())
l = [x]
a = x
loopsum = 0
loopnum = 0


for i in range(n - 1):
    a = a**2%m
    if a not in l:
        l.append(a)
    else:
        pos = l.index(a)
        loopnum = len(l[pos:])
        loopsum = sum(l[pos:])
        break

if loopnum > 0:
    rest = (n - len(l))%loopnum
    times = (n - len(l))//loopnum
    ans = sum(l) + loopsum*times
    for i in range(rest):
        ans += l[pos + i]
else:
    ans = sum(l)

print(ans)

Fixed submission:
n, x, m = map(int, input().split())
l = [x]
a = x
loopsum = 0
loopnum = 0


for i in range(n - 1):
    a = a**2%m
    if a not in l:
        l.append(a)
    else:
        pos = l.index(a)
        loopnum = len(l[pos:])
        loopsum = sum(l[pos:])
        break

if loopnum > 0:
    rest = (n - len(l))%loopnum
    times = (n - len(l))//loopnum
    ans = sum(l) + loopsum*times
    for i in range(rest):
        ans += l[pos + i]
else:
    ans = sum(l)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, x, m = map(int, input().split())
l = [x]
loop = []
a = x

for i in range(n - 1):
    a = a**2%m
    if a not in l:
        l.append(a)
    else:
        if a not in loop:
            loop.append(a)
        else:
            break

if len(loop) > 0:
    rest = (n - len(l))%len(loop)
    times = (n - len(l))//len(loop)
    ans = sum(l) + sum(loop)*times
    for i in range(rest):
        ans += loop[i]
else:
    ans = sum(l)

print(ans)

Fixed submission:
n, x, m = map(int, input().split())
l = [x]
a = x
loopsum = 0
loopnum = 0


for i in range(n - 1):
    a = a**2%m
    if a not in l:
        l.append(a)
    else:
        pos = l.index(a)
        loopnum = len(l[pos:])
        loopsum = sum(l[pos:])
        break

if loopnum > 0:
    rest = (n - len(l))%loopnum
    times = (n - len(l))//loopnum
    ans = sum(l) + loopsum*times
    for i in range(rest):
        ans += l[pos + i]
else:
    ans = sum(l)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, x, m = map(int, input().split())
l = [x]
loop = []
a = x

for i in range(n - 1):
    a = a**2%m
    if a not in l:
        l.append(a)
    else:
        if a not in loop:
            loop.append(a)
        else:
            break

if len(loop) > 0:
    rest = (n - len(l))%len(loop)
    times = (n - len(l))//len(loop)
    ans = sum(l) + sum(loop)*times
    for i in range(rest):
        ans += loop[i]
else:
    ans = sum(l)

print(ans)

Fixed submission:
n, x, m = map(int, input().split())
l = [x]
a = x
loopsum = 0
loopnum = 0


for i in range(n - 1):
    a = a**2%m
    if a not in l:
        l.append(a)
    else:
        pos = l.index(a)
        loopnum = len(l[pos:])
        loopsum = sum(l[pos:])
        break

if loopnum > 0:
    rest = (n - len(l))%loopnum
    times = (n - len(l))//loopnum
    ans = sum(l) + loopsum*times
    for i in range(rest):
        ans += l[pos + i]
else:
    ans = sum(l)

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

n, m = map(int, input().split())
l = [[] for i in range(n)]
union = []
vis = [-1]*n
ans = 0

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    l[a].append(b)
    l[b].append(a)

q = deque()

def dfs(a):
    if vis[a] == -1:
        vis[a] = 0
        temp.append(a)
        for j in l[a]:
            q.append(j)
    if len(q) > 0:
        b = q.popleft()
        dfs(b)
    return temp

for i in range(n):
    temp = []
    union.append(dfs(i))

for i in union:
    ans = max(ans, len(i))

print(ans)

Fixed submission:
from collections import deque

n, m = map(int, input().split())
l = [[] for i in range(n)]
union = []
vis = [-1]*n
ans = 0

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    l[a].append(b)
    l[b].append(a)

q = deque()

for i in range(n):
    temp = []
    q.append(i)
    while q:
        a = q.popleft()
        if vis[a] == -1:
            vis[a] = 0
            temp.append(a)
            for j in l[a]:
                q.append(j)
    if len(temp) > 0:
        union.append(temp)


for i in union:
    ans = max(ans, len(i))

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

for i in range(k):
    ref *= a[i]

for i in range(n - k):
    ref2 = ref*a[i + k]/a[i]
    if ref2 > ref:
        print("Yes")
    else:
        print("No")
    ref = ref2

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

for i in range(n - k):
    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()))
ref = 1

for i in range(k):
    ref *= a[i]

for i in range(n - k):
    ref2 = ref*a[i + k]/a[i]
    if ref2 > ref:
        print("Yes")
    else:
        print("No")
    ref = ref2

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

for i in range(n - k):
    if a[i + k] > a[i]:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
import sympy

n = int(input())
ans = 0

for i in range(1, n + 1):
    ans += i*sympy.divisor_count(i)

print(ans)

Fixed submission:
n = int(input())
l = [1]*(n + 1)
ans = 0

for i in range(2, n + 1):
    for j in range(i, n + 1, i):
        l[j] += 1

for i in range(1, n + 1):
    ans += i*l[i]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = [1]*(n + 1)
ans = 0

for i in range(2, n + 1):
    for j in range(i, n + 1, i):
        l[j] += 1

for i in range(1, n + 1):
    ans += i*l[i]

print(ans)

Fixed submission:
n = int(input())
l = [1]*(n + 1)
ans = 0

for i in range(2, n + 1):
    for j in range(i, n + 1, i):
        l[j] += 1

for i in range(1, n + 1):
    ans += i*l[i]

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

for i in range(q):
    a.sort()
    b, c = map(int, input().split())
    for j in range(n):
        if a[j] == b:
            a[j] = c
        elif a[j] > b:
            break
    print(sum(a))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())
l = [0]*100010
ans = sum(a)

for i in a:
    l[i] += 1

for i in range(q):
    b, c = map(int, input().split())
    ans += (c - b)*l[b]
    l[c] += l[b]
    l[b] = 0
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
l = [0]*(max(a) + 1)
ans = 0

for i in a:
    for j in range(i, max(a) + 1, i):
        l[j] += 1

for i in a:
    if l[i] == 1:
        ans += 1

print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ln = max(a) + 1
l = [0]*ln
ans = 0

for i in a:
    for j in range(i, ln, i):
        l[j] += 1

for i in a:
    if l[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)
else:
    print(ans)

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

if 0 in a:
    print(0)
    exit()

for i in range(n):
    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()))
l = [0]*n
ans = 0

for i in range(n):
    l[i] = i + 1 + a[i]
    ans += l[:i].count(i + 1 - a[i])


print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
d = {}
ans = 0

for i in range(n):
    l = i + a[i]
    r = i - a[i]
    if l not in d:
        d[l] = 1
    else:
        d[l] += 1
    if r in d:
        ans += d[r]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
pl = [0]*n
nl = [0]*n
ans = 0

for i in range(n):
    pl[i] = i + 1 + a[i]
    nl[i] = i + 1 - a[i]

for i in range(n - 1):
    ans += nl[i + 1:].count(pl[i])

print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
d = {}
ans = 0

for i in range(n):
    l = i + a[i]
    r = i - a[i]
    if l not in d:
        d[l] = 1
    else:
        d[l] += 1
    if r in d:
        ans += d[r]

print(ans)