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

def z_algo(S):
    N = len(S)
    A = [0] * N
    i = 1
    j = 0
    l = len(S)
    A[0] = l

    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while min(l-i, j-A[k]) > k:
            A[i+k] = A[k]
            k += 1
        i += k
        j -= k
    return A

ans = 0
for i in range(N):
    s = S[i:]
    tmp = z_algo(s)
    
    for i in range(1, len(tmp)):
        if tmp[i] > i:
            tmp[i] = 0
    if len(tmp) >= 2:
        ans = max(ans, max(tmp[1:]))
print(ans)

Fixed submission:
n = int(input())
s = input()
 
max_len = 0
j = 0
 
for i in range(n):
    while j < n and s[i:j] in s[j:]:
        j += 1
    max_len = max(max_len,j-i-1)
 
print(max_len)

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

def z_algo(S):
    N = len(S)
    A = [0] * N
    i = 1
    j = 0
    l = len(S)
    A[0] = l

    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        k = 1
        while min(l-i, j-A[k]) > k:
            A[i+k] = A[k]
            k += 1
        i += k
        j -= k
    return A

ans = 0
for i in range(N):
    s = S[i:]
    tmp = z_algo(s)
    for i in range(1, len(tmp)+1):
        if tmp[i] > i:
            tmp[i] = 0
    if len(tmp) >= 2:
        ans = max(ans, max(tmp[1:]))
print(ans)



Fixed submission:
n = int(input())
s = input()
 
max_len = 0
j = 0
 
for i in range(n):
    while j < n and s[i:j] in s[j:]:
        j += 1
    max_len = max(max_len,j-i-1)
 
print(max_len)
Buggy python submission (verdict: Runtime Error):
N = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for _ in range(N):
    if v[i] > c[i]:
        ans += v[i] - c[i]
print(ans)

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

ans = 0
for i in range(N):
    if v[i] > c[i]:
        ans += v[i] - c[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce

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


def gcd(x, y):
    if x < y:
        x, y = y, x
    while y != 0:
        tmp = x % y
        x = y
        y = tmp
    return x


ans = 1
if N == 2:
    print(max(a))
    exit()


for i in range(N):
    if i == 0:
        n = reduce(gcd, a[1:])
    elif i == N-1:
        n = reduce(gcd, a[:i])
    else:
        n = reduce(gcd, a[:i]+a[i+1:])
    ans = max(ans, n)
print(ans)

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


def gcd(x, y):
    if x < y:
        x, y = y, x
    while y != 0:
        tmp = x % y
        x = y
        y = tmp
    return x


ans = 1
if N == 2:
    print(max(a))
    exit()

l = [1] * N
l[0] = a[0]
r = [1] * N
r[N-1] = a[N-1]
for i in range(1, N):
    l[i] = gcd(l[i-1], a[i])
    r[N-1-i] = gcd(r[N-i], a[N-1-i])
    
for i in range(N):
    if i == 0:
        n = r[1]
    elif i == N-1:
        n = l[N-2]
    else:
        n = gcd(l[i-1], r[i+1])
    ans = max(ans, n)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
S = input()

s = []
cnt = 1
for i in range(N-1):
    if S[i] == S[i+1]:
        cnt += 1
    else:
        s.append(cnt)
        cnt = 1
s.append(cnt)

ans = 0
if S[0] == '0':
    s = [0] + s
if S[-1] == '0':
    s = s + [0]

if 2*K + 1 > len(s):
    print(sum(s))
    exit()

for i in range(0, len(s), 2):
    if i + 2*K >= len(s):
        break
    ans = max(ans, sum(s[i:i+2*K+1]))

print(ans)

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

s = []
cnt = 1
for i in range(N-1):
    if S[i] == S[i+1]:
        cnt += 1
    else:
        s.append(cnt)
        cnt = 1
s.append(cnt)

ans = 0
if S[0] == '0':
    s = [0] + s
if S[-1] == '0':
    s = s + [0]

if 2*K + 1 > len(s):
    print(sum(s))
    exit()

s_cumsum = [s[0]] * len(s)
for i in range(1, len(s)):
    s_cumsum[i] = s_cumsum[i-1] + s[i]
    
for i in range(0, len(s), 2):
    if i + 2*K >= len(s):
        break
    if i < 1:
        ans = s_cumsum[i+2*K]
    ans = max(ans, s_cumsum[i+2*K]-s_cumsum[i-1])
    #ans = max(ans, sum(s[i:i+2*K+1]))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N, Q = map(int, input().split())
S = input()


ac_idx = deque()
for i in range(N-1):
    if S[i:i+2] == 'AC':
        ac_idx.append(i)

for _ in range(Q):
    l, r = map(int, input().split())
    cnt = 0
    for idx in ac_idx:
        if idx >= l-1 and idx+1 <= r-1:
            cnt += 1
    print(cnt)

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

ac_cnt = [0] * N
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        ac_cnt[i] = ac_cnt[i-1] + 1
    else:
        ac_cnt[i] = ac_cnt[i-1]

for _ in range(Q):
    l, r = map(int, input().split())
    ans = ac_cnt[r-1] - ac_cnt[l-1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()

ac_idx = []
for i in range(N-1):
    if S[i:i+2] == 'AC':
        ac_idx.append(i)


for _ in range(Q):
    l, r = map(int, input().split())
    cnt = 0
    for idx in ac_idx:
        if idx >= l-1 and idx+1 <= r-1:
            cnt += 1
    print(cnt)

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

ac_cnt = [0] * N
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        ac_cnt[i] = ac_cnt[i-1] + 1
    else:
        ac_cnt[i] = ac_cnt[i-1]

for _ in range(Q):
    l, r = map(int, input().split())
    ans = ac_cnt[r-1] - ac_cnt[l-1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()

ac_idx = []
for i in range(N-1):
    if S[i:i+2] == 'AC':
        ac_idx.append(i)


for _ in range(Q):
    l, r = map(int, input().split())
    cnt = 0
    for idx in ac_idx:
        if idx >= l-1 and idx+1 <= r-1:
            cnt += 1
    print(cnt)

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

ac_cnt = [0] * N
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        ac_cnt[i] = ac_cnt[i-1] + 1
    else:
        ac_cnt[i] = ac_cnt[i-1]

for _ in range(Q):
    l, r = map(int, input().split())
    ans = ac_cnt[r-1] - ac_cnt[l-1]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [10**9+5] * N
dp[0] = 0
for i in range(1, N):
    for j in range(1, min(i, K)+1):
        dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]))
print(dp[N-1])

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

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

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

dp = [10**9+5] * N
dp[0] = 0
for i in range(1, N):
    for j in range(1, min(i, K)+1):
        dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j])
print(dp[N-1])

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

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

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

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

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

dp = [1e10] * N
dp[0] = 0
for i in range(N):
    for j in range(i+1, i+K+1):
        if j >= N:
            break
        dp[j] = min([dp[j], dp[i]+abs(h[j]-h[i])])
print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * (W+1) for _ in range(N+1)]

for i in range(N):
    w, v = wv[i]
    for j in range(W+1):
        if j < w:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-w]+v)
print(max(dp[N]))

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

dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(1, N+1):
    for sum_w in range(W+1):
        weight = sum_w - wv[i-1][0]
        if weight < 0:
            dp[i][sum_w] = max([dp[i][sum_w], dp[i-1][sum_w]])
        else:
            dp[i][sum_w] = max([dp[i][sum_w], dp[i-1][sum_w], dp[i-1][weight]+wv[i-1][1]])
print(max(dp[N]))

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

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

max_v_per_w = [0] * (W+1)
for i in range(N):
    w, v = wv[i]
    tmp = copy.deepcopy(max_v_per_w)
    for j in range(w, W+1):
        max_v_per_w[j] = max(tmp[j], tmp[j-w]+v)
        
print(max(max_v_per_w))



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

dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(1, N+1):
    for sum_w in range(W+1):
        weight = sum_w - wv[i-1][0]
        if weight < 0:
            dp[i][sum_w] = max([dp[i][sum_w], dp[i-1][sum_w]])
        else:
            dp[i][sum_w] = max([dp[i][sum_w], dp[i-1][sum_w], dp[i-1][weight]+wv[i-1][1]])
print(max(dp[N]))

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]

dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(1, N+1):
    for sum_w in range(W+1):
        weight = sum_w - wv[i-1][0]
        if weight < 0:
            dp[i][sum_w] = max([dp[i][sum_w], dp[i-1][sum_w]])
        else:
            dp[i][sum_w] = max([dp[i][sum_w], dp[i-1][sum_w], dp[i-1][weight]+wv[i-1][1]])
print(max(dp[N]))

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

dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(1, N+1):
    for sum_w in range(W+1):
        weight = sum_w - wv[i-1][0]
        if weight < 0:
            dp[i][sum_w] = max([dp[i][sum_w], dp[i-1][sum_w]])
        else:
            dp[i][sum_w] = max([dp[i][sum_w], dp[i-1][sum_w], dp[i-1][weight]+wv[i-1][1]])
print(max(dp[N]))
Buggy python submission (verdict: Time Limit Exceeded):
import copy

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

min_w_per_v = [10**11] * (10**6)
min_w_per_v[0] = 0

for i in range(N):
    w, v = wv[i]
    tmp = copy.deepcopy(min_w_per_v)
    for j in range(v, len(min_w_per_v)):
        min_w_per_v[j] = min(tmp[j], tmp[j-v]+w)
        
for n, i in enumerate(min_w_per_v[::-1]):
    if i <= W:
        print(10**6-n-1)
        break

Fixed submission:
import copy

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

min_w_per_v = [10**11] * (10**5+3)
min_w_per_v[0] = 0

for i in range(N):
    w, v = wv[i]
    tmp = copy.deepcopy(min_w_per_v)
    for j in range(v, len(min_w_per_v)):
        min_w_per_v[j] = min(tmp[j], tmp[j-v]+w)
        
for n, i in enumerate(min_w_per_v[::-1]):
    if i <= W:
        print(10**5+3-n-1)
        break
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
dp = [[0] * (len(t)+1) for _ in range(len(s)+1)]

for i in range(1, len(s)+1):
    for j in range(1, len(t)+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1)
        dp[i][j] = max(dp[i][j], dp[i][j-1])
        dp[i][j] = max(dp[i][j], dp[i-1][j])

ans = ''
i = len(s)
j = len(t)
while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        ans += t[j-1]
        i -= 1
        j -= 1
   
print(ans[::-1])

Fixed submission:
s = input()
t = input()
dp = [[0] * (len(t)+1) for _ in range(len(s)+1)]

for i in range(1, len(s)+1):
    for j in range(1, len(t)+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1)
        dp[i][j] = max(dp[i][j], dp[i][j-1])
        dp[i][j] = max(dp[i][j], dp[i-1][j])

ans = ''
i = len(s)
j = len(t)
while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        ans += t[j-1]
        i -= 1
        j -= 1
   
print(ans[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
p_list = list(map(float, input().split()))

dp = [[0]*(N+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1, N+1):
    for j in range(i+1):
        dp[i][j] += dp[i-1][j] * (1-p_list[i-1])
        if j > 0:
            dp[i][j] += dp[i-1][j-1] * p_list[i-1]
ans = 0       
start = N//2 + 1
for p in dp[N][start:]:
    ans += p
print(ans)

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

dp = [[0.] * (N+1) for _ in range(N+1)]
dp[0][0] = 1.

for i in range(1, N+1):
    for j in range(i+1):
        prob = dp[i-1][j-1]*p[i-1]
        if i > 0:
            prob += dp[i-1][j]*(1.-p[i-1])
        dp[i][j] = max(dp[i][j], prob)
print(sum(dp[-1][N//2+1:]))

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

dp = [[0]*(N+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1, N+1):
    for j in range(N+1):
        dp[i][j] += dp[i-1][j] * (1-p_list[i-1])
        if j > 0:
            dp[i][j] += dp[i-1][j-1] * p_list[i-1]
            
start = N//2 + 1
for p in dp[N][start:]:
    ans += p
print(ans)

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

dp = [[0.] * (N+1) for _ in range(N+1)]
dp[0][0] = 1.

for i in range(1, N+1):
    for j in range(i+1):
        prob = dp[i-1][j-1]*p[i-1]
        if i > 0:
            prob += dp[i-1][j]*(1.-p[i-1])
        dp[i][j] = max(dp[i][j], prob)
print(sum(dp[-1][N//2+1:]))

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

dp = [[0.] * (N+1) for _ in range(N+1)]
dp[0][0] = 1.

for i in range(1, N+1):
    for j in range(i+1):
        prob = dp[i-1][j-1]*p[i-1]
        if i > 0:
            prob += dp[i-1][j]*(1.-p[i-1])
        dp[i][j] = max(dp[i][j], prob)
print(sum(dp[-1][N//2+1:]))

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

dp = [[0.] * (N+1) for _ in range(N+1)]
dp[0][0] = 1.

for i in range(1, N+1):
    for j in range(i+1):
        prob = dp[i-1][j-1]*p[i-1]
        if i > 0:
            prob += dp[i-1][j]*(1.-p[i-1])
        dp[i][j] = max(dp[i][j], prob)
print(sum(dp[-1][N//2+1:]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a_list = list(map(int, input().split()))

dp = [[[0]*(N+2) for _ in range(N+2)] for _ in range(N+2)]

cnt = {1:0, 2:0, 3:0}
for a in a_list:
    cnt[a] += 1

for i in range(N+1):
    for j in range(N+1):
        for k in range(N+1):
            if i==0 and j==0 and k==0:
                continue
            dp[i][j][k] += (N/(i+j+k))
            if k >= 1:
                dp[i][j][k] += dp[i][j][k-1] * (k/(i+j+k))
            if j >= 1:
                dp[i][j][k] += dp[i][j-1][k+1] * (j/(i+j+k))
            if i >= 1:
                dp[i][j][k] += dp[i-1][j+1][k] * (i/(i+j+k))
print(dp[cnt[3]][cnt[2]][cnt[1]])

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

dp = [[[0]*(N+2) for _ in range(N+2)] for _ in range(N+2)]

cnt = {1:0, 2:0, 3:0}
for a in a_list:
    cnt[a] += 1

for i in range(N+1):
    for j in range(N+1):
        for k in range(N+1):
            if i==0 and j==0 and k==0:
                continue
            dp[i][j][k] += (N/(i+j+k))
            if k >= 1:
                dp[i][j][k] += dp[i][j][k-1] * (k/(i+j+k))
            if j >= 1:
                dp[i][j][k] += dp[i][j-1][k+1] * (j/(i+j+k))
            if i >= 1:
                dp[i][j][k] += dp[i-1][j+1][k] * (i/(i+j+k))
print(dp[cnt[3]][cnt[2]][cnt[1]])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a_list = list(map(int, input().split()))

dp = [[0]*(N+10) for _ in range(N+10)]
dp[0][0] = 0
for width in range(1, N+1):
    for l in range(1, N+1):
        r = l + width
        if r >= N+2:
            break
        if width % 2 == N % 2:
            dp[l][r] = max(dp[l][r-1]+a_list[r-2], dp[l+1][r]+a_list[l-1])
        else:
            dp[l][r] = min(dp[l][r-1]-a_list[r-2], dp[l+1][r]-a_list[l-1])

print(dp[1][N+1])

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

dp = [[0]*(N+10) for _ in range(N+10)]
dp[0][0] = 0
for width in range(1, N+1):
    for l in range(1, N+1):
        r = l + width
        if r >= N+2:
            break
        if width % 2 == N % 2:
            dp[l][r] = max(dp[l][r-1]+a_list[r-2], dp[l+1][r]+a_list[l-1])
        else:
            dp[l][r] = min(dp[l][r-1]-a_list[r-2], dp[l+1][r]-a_list[l-1])

print(dp[1][N+1])
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
b=input()
if b%a==0:
  print(a+b)
else:
  print(b-a)

Fixed submission:
a,b=map(int,input().split())
if b%a==0:
  print(a+b)
else:
  print(b-a)

Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
if b%a==0:print(a+b)
else:print(b-a)

Fixed submission:
a,b=map(int,input().split())
if b%a==0:
  print(a+b)
else:
  print(b-a)
Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
g=[0]*h
l=[0]*w
b=[]
for i in range(m):
  x,y=map(int,input().split())
  g[x-1]+=1
  l[y-1]+=1
  b.append((x-1,y-1))
mxg=max(g);mxl=max(l)
mg=[i for i,x in enumerate(g) if x==mxg]
ml=[i for i,x in enumerate(l) if x==mxl]
c=0
for x,y in b:
  if x in mg and y in ml:
    c+=1
print(mxg+mxl-(c==(len(mg)*len(ml))))

Fixed submission:
h,w,m=map(int,input().split())
g=[0]*h
l=[0]*w
b=[]
for i in range(m):
  x,y=map(int,input().split())
  g[x-1]+=1
  l[y-1]+=1
  b.append((x-1,y-1))
mxg=max(g);mxl=max(l)
mg=set([i for i,x in enumerate(g) if x==mxg])
ml=set([i for i,x in enumerate(l) if x==mxl])
c=0
for x,y in b:
  if x in mg and y in ml:
    c+=1
print(mxg+mxl-(c==(len(mg)*len(ml))))

Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
g=[0]*h
l=[0]*w
b=[]
for i in range(m):
  x,y=map(int,input().split())
  g[x-1]+=1
  l[y-1]+=1
  b.append((x-1,y-1))
mxg=max(g);mxl=max(l)
mg=[i for i,x in enumerate(g) if x==mxg]
ml=[i for i,x in enumerate(l) if x==mxl]
c=0
for x,y in b:
  if x in mg and y in ml:
    c+=1
print(mxg+mxl-(c==(len(mg)*len(ml))))

Fixed submission:
h,w,m=map(int,input().split())
g=[0]*h
l=[0]*w
b=[]
for i in range(m):
  x,y=map(int,input().split())
  g[x-1]+=1
  l[y-1]+=1
  b.append((x-1,y-1))
mxg=max(g);mxl=max(l)
mg=set([i for i,x in enumerate(g) if x==mxg])
ml=set([i for i,x in enumerate(l) if x==mxl])
c=0
for x,y in b:
  if x in mg and y in ml:
    c+=1
print(mxg+mxl-(c==(len(mg)*len(ml))))

Buggy python submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
g=[0]*h
l=[0]*w
b=[[0]*w for i in range(h)]
for i in range(m):
  x,y=map(int,input().split())
  g[x-1]+=1
  l[y-1]+=1
  b[x-1][y-1]=1
mg=[i for i,x in enumerate(g) if x==max(g)]
ml=[i for i,x in enumerate(l) if x==max(l)]
for i in mg:
  for j in ml:
    if b[i][j]==0:
      print(max(g)+max(l))
      exit()
print(max(g)+max(l)-1)

Fixed submission:
h,w,m=map(int,input().split())
g=[0]*h
l=[0]*w
b=[]
for i in range(m):
  x,y=map(int,input().split())
  g[x-1]+=1
  l[y-1]+=1
  b.append((x-1,y-1))
mxg=max(g);mxl=max(l)
mg=set([i for i,x in enumerate(g) if x==mxg])
ml=set([i for i,x in enumerate(l) if x==mxl])
c=0
for x,y in b:
  if x in mg and y in ml:
    c+=1
print(mxg+mxl-(c==(len(mg)*len(ml))))

Buggy python submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
g=[0]*h
l=[0]*w
b=[[0]*w for i in range(h)]
for i in range(m):
  x,y=map(int,input().split())
  g[x-1]+=1
  l[y-1]+=1
  b[x-1][y-1]=1
mg=[i for i,x in enumerate(g) if x==max(g)]
ml=[i for i,x in enumerate(l) if x==max(l)]
for i in mg:
  for j in ml:
    if b[i][j]==0:
      print(max(g)+max(l))
      exit()
print(max(g)+max(l)-1)

Fixed submission:
h,w,m=map(int,input().split())
g=[0]*h
l=[0]*w
b=[]
for i in range(m):
  x,y=map(int,input().split())
  g[x-1]+=1
  l[y-1]+=1
  b.append((x-1,y-1))
mxg=max(g);mxl=max(l)
mg=set([i for i,x in enumerate(g) if x==mxg])
ml=set([i for i,x in enumerate(l) if x==mxl])
c=0
for x,y in b:
  if x in mg and y in ml:
    c+=1
print(mxg+mxl-(c==(len(mg)*len(ml))))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
x=0
for i in range(1,n+1):
  for j in range(i,n+1,i):
    x+=j
print(x)

Fixed submission:
n=int(input())
x=0
for i in range(1,n+1):
  for j in range(i,n+1,i):
    x+=j
print(x)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=sorted(list(map(int,input().split())))
c=[1]*n
for i in range(n-1):
  t=a[i]
  if c[i]:
    if t==a[i+1]:
      c[i]=0
    for j in range(i+1,n):
      if a[j]%t==0:
        c[j]=0
print(sum(c))

Fixed submission:
n=int(input())
a=sorted(list(map(int,input().split())))
m=max(a)
b=[1]*m
c=[0]*m
for i in a:
  c[i-1]+=1
  if b[i-1]:
    for j in range(i*2-1,m,i):
      b[j]=0
x=0
for i in range(m):
  if b[i] and c[i]==1:
    x+=1
print(x)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=sorted(list(map(int,input().split())))
c=[1]*n
for i in range(n-1):
  t=a[i]
  if c[i]:
    if t==a[i+1]:
      c[i]=0
    for j in range(i+1,n):
      if a[j]%t==0:
        c[j]=0
print(sum(c))

Fixed submission:
n=int(input())
a=sorted(list(map(int,input().split())))
m=max(a)
b=[1]*m
c=[0]*m
for i in a:
  c[i-1]+=1
  if b[i-1]:
    for j in range(i*2-1,m,i):
      b[j]=0
x=0
for i in range(m):
  if b[i] and c[i]==1:
    x+=1
print(x)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
print(int(a*b))

Fixed submission:
from fractions import Fraction
a,b=input().split()
a=Fraction(int(a),1)
b=Fraction(int(b[0]+b[2:]),100)
print(int(a*b))
Buggy python submission (verdict: Runtime Error):
n,m=map(int(input().split()))
a=list(map(int,input().split()))
print(max(-1,n-sum(a)))

Fixed submission:
n,m=map(int,input().split())
print(max(-1,n-sum(list(map(int,input().split())))))

Buggy python submission (verdict: Runtime Error):
n,m=map(int(input().split()))
print(max(-1,n-sum(list(map(int,input().split())))))

Fixed submission:
n,m=map(int,input().split())
print(max(-1,n-sum(list(map(int,input().split())))))
Buggy python submission (verdict: Time Limit Exceeded):
k=int(input())
s=0
from math import gcd
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      d=gcd(a,b)
      s+=gcd(d,c)
print(s)

Fixed submission:
k=int(input())
s=0
from math import gcd
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      d=gcd(a,b)
      s+=gcd(d,c)
print(s)
Buggy python submission (verdict: Runtime Error):
a,b,m=map(int,input().split())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
x=min(al)+min(bl)
for i in range(m):
  x,y,c=map(int,input().split())
  t=a[x-1]+b[y-1]-c
  x=min(x,t)
print(x)

Fixed submission:
a,b,m=map(int,input().split())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
z=min(al)+min(bl)
for i in range(m):
  x,y,c=map(int,input().split())
  t=al[x-1]+bl[y-1]-c
  z=min(z,t)
print(z)