Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
W, H, x, y = map(float, input().split())

S = W * H / 2

flag = 0
if x == W / 2 and y == H / 2:
    flag = 1

if 
print(S, flag)


Fixed submission:
W, H, x, y = map(float, input().split())

S = W * H / 2

flag = 0
if x == W / 2 and y == H / 2:
    flag = 1

print(S, flag)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
a = [0] * M
for i in range(M):
    a[i] = int(input())

mod = 10 ** 9 + 7

dp = [0] * 100010

j = 0
dp[0] = 1
if a[0] == 1:
    dp[1] = 0
    j += 1
else:
    dp[1] = 1

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

print(dp[N] % mod)

Fixed submission:
N, M = map(int, input().split())
a = [0] * M
for i in range(M):
    a[i] = int(input())

mod = 10 ** 9 + 7

dp = [0] * 100010

j = 0
dp[0] = 1
if M > 0:
    if a[0] == 1:
        dp[1] = 0
        j += 1
    else:
        dp[1] = 1
else:
    dp[1] = 1

a += [-1]
for i in range(2, N+1):
    if M > 0:
        if i == a[j]:
            dp[i] = 0
            j += 1
            continue
    dp[i] = dp[i-1] + dp[i-2]
    dp[i] %= mod

print(dp[N] % mod)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

H, W = map(int, input().split())
maze = [input() for i in range(H)]
ans = 0

def search1(x, y, cnt):
    global ans
    if x < 0 or W <= x or y < 0 or H <= y or maze[y][x] == '#':
        ans += cnt - 1
        return

    search1(x + 1, y, cnt + 1)
    return
def search2(x, y, cnt):
    global ans
    if x < 0 or W <= x or y < 0 or H <= y or maze[y][x] == '#':
        ans += cnt - 1
        return

    search2(x - 1, y, cnt + 1)
    return
def search3(x, y, cnt):
    global ans
    if x < 0 or W <= x or y < 0 or H <= y or maze[y][x] == '#':
        ans += cnt - 1
        return

    search3(x, y + 1, cnt + 1)
    return
def search4(x, y, cnt):
    global ans
    if x < 0 or W <= x or y < 0 or H <= y or maze[y][x] == '#':
        ans += cnt - 1
        return

    search4(x, y - 1, cnt + 1)
    return

MAX = 0
for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            continue
        search1(j, i, 0)
        search2(j, i, 0)
        search3(j, i, 0)
        search4(j, i, 0)
        MAX = max(ans + 1, MAX)
        ans = 0

print(MAX)


Fixed submission:
H, W = map(int, input().split())
maze = [input() for _ in range(H)]
cnt = [[0] * W for _ in range(H)]

for i in range(H):
    done = [0] * W
    for j in range(W):
        if maze[i][j] == '#':
            continue
        if done[j]:
            continue
        l = 0
        while j + l < W:
            if maze[i][j+l] == '#':
                break
            l += 1
        for k in range(l):
            cnt[i][j+k] += l
            done[j+k] = 1

for j in range(W):
    done = [0] * H
    for i in range(H):
        if maze[i][j] == '#':
            continue
        if done[i]:
            continue
        l = 0
        while i + l < H:
            if maze[i+l][j] == '#':
                break
            l += 1
        for k in range(l):
            cnt[i+k][j] += l
            done[i+k] = 1
ans = 0
for i in range(H):
    ans = max(ans, max(cnt[i]) - 1)

print(ans)
Buggy python submission (verdict: Runtime Error):
N, A, B, C, D = map(int, input().split())
S = input()

c1 = [0] * len(S)
c2 = [0] * len(S)
cnt1 = 0
cnt2 = 0
for i in range(len(S)):
    if '.' == S[i]:
        c2[i] = cnt2
        cnt2 = 0
        cnt1 += 1
    else:
        c1[i] = cnt1
        cnt1 = 0
        cnt2 += 1

c1[-1] = cnt1
c2[-1] = cnt2

index2 = []
index1 = []
for i in range(N):
    if c2[i] >= 2:
        index2.append(i)
    if c1[i] >= 3:
        index1.append(i)

flag = True
for i in index2:
    if A < i - c2[i] + 1 < C or B < i - c2[i] + 1 < D:
        flag = False

if C > D and flag:
    flag = False
    for i in index1:
        if B < i < D:
            if D == i - cnt1[i] + 1:
                flag = False
                break
            flag = True

if flag:
    print('Yes')
else:
    print('No')

Fixed submission:
N, A, B, C, D = map(int, input().split())
S = input()

flag = True
if "##" in S[A:max(C, D)]:
    flag = False
if C > D:
    if "..." not in S[B-2:D+1]:
        flag = False

if flag:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
s = s.replace('BC', 'D')
s = list(s)

cnt = 0
pre = -1
while cnt != pre:
    pre = cnt
    for i in range(len(s)-1):
        if s[i:i+2] == list('AD'):
            cnt += 1
            s[i] = 'D'
            s[i+1] = 'A'
            
print(cnt)

Fixed submission:
s = input()
s = s.replace('BC', 'D')

a = 0
cnt = 0
for x in s:
    if x == 'A':
        a += 1
    elif x == 'D':
        cnt += a
    else:
        a = 0

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
s = s.replace('BC', 'D')
s = list(s)

cnt = 0
pre = -1
while cnt != pre:
    pre = cnt
    for i in range(len(s)-1):
        if s[i:i+2] == list('AD'):
            cnt += 1
            s[i] = 'D'
            s[i+1] = 'A'
            
print(cnt)

Fixed submission:
s = input()
s = s.replace('BC', 'D')

a = 0
cnt = 0
for x in s:
    if x == 'A':
        a += 1
    elif x == 'D':
        cnt += a
    else:
        a = 0

print(cnt)
Buggy python submission (verdict: Runtime Error):
def dfs(v, p, c):
    res[v] = c
    for next in link[v]:
        if next[0] == p:
            continue
        if c == next[1]:
            dfs(next[0], v, c)
        else:
            dfs(next[0], v, 1-c)


N = int(input())
link = [[] * N for _ in range(N)]
res = [0] * N
for i in range(N-1):
    u, v, w = map(int, input().split())
    link[u-1].append([v-1, w % 2])
    link[v-1].append([u-1, w % 2])
print(link)
dfs(0, -1, 1)

for i in range(N):
    print(res[i])

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

def dfs(v, p, c):
    res[v] = c
    for next in link[v]:
        if next[0] == p:
            continue
        if next[1] % 2:
            dfs(next[0], v, 1-c)
        else:
            dfs(next[0], v, c)


N = int(input())
link = [[] * N for _ in range(N)]
res = [0] * N
for i in range(N-1):
    u, v, w = map(int, input().split())
    link[u-1].append([v-1, w])
    link[v-1].append([u-1, w])

dfs(0, -1, 1)

for i in range(N):
    print(res[i])

Buggy python submission (verdict: Runtime Error):
def dfs(v, p, c):
    res[v] = c
    for next in link[v]:
        if next[0] == p:
            continue
        if next[1]:
            dfs(next[0], v, c)
        else:
            dfs(next[0], v, 1-c)


N = int(input())
link = [[] * N for _ in range(N)]
res = [0] * N
for i in range(N-1):
    u, v, w = map(int, input().split())
    link[u-1].append([v-1, w % 2])
    link[v-1].append([u-1, w % 2])

dfs(0, -1, 1)

for i in range(N):
    print(res[i])

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

def dfs(v, p, c):
    res[v] = c
    for next in link[v]:
        if next[0] == p:
            continue
        if next[1] % 2:
            dfs(next[0], v, 1-c)
        else:
            dfs(next[0], v, c)


N = int(input())
link = [[] * N for _ in range(N)]
res = [0] * N
for i in range(N-1):
    u, v, w = map(int, input().split())
    link[u-1].append([v-1, w])
    link[v-1].append([u-1, w])

dfs(0, -1, 1)

for i in range(N):
    print(res[i])
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
a = [0] * N
b = [0] * N
counter = []

if S[0] == '#':
    a[0] = 1
if S[N-1] == '.':
    b[N-1] = 1

for i in range(N-1):
    if S[i+1] == '#':
        a[i+1] = a[i] + 1
    else:
        a[i+1] = a[i]
    if S[N-i-2] =='.':
        b[N-i-2] = b[N-i-1] + 1
    else:
        b[N-i-2] = b[N-i-1]
        
for i in range(N-1):
    counter.append(a[i] + b[i+1])

print(min(counter))


Fixed submission:
N = int(input())
S = input()
a = [0] * N
b = [0] * N
counter = []

if S[0] == '#':
    a[0] = 1
if S[N-1] == '.':
    b[N-1] = 1

for i in range(N-1):
    if S[i+1] == '#':
        a[i+1] = a[i] + 1
    else:
        a[i+1] = a[i]
    if S[N-i-2] =='.':
        b[N-i-2] = b[N-i-1] + 1
    else:
        b[N-i-2] = b[N-i-1]
counter.append(a[N-1])
counter.append(b[0])
for i in range(N-1):
    counter.append(a[i] + b[i+1])

print(min(counter))

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

for i in range(N-1):
    if S[i:i+2] = '#.':
        count += 1

print(count)

Fixed submission:
N = int(input())
S = input()
a = [0] * N
b = [0] * N
counter = []

if S[0] == '#':
    a[0] = 1
if S[N-1] == '.':
    b[N-1] = 1

for i in range(N-1):
    if S[i+1] == '#':
        a[i+1] = a[i] + 1
    else:
        a[i+1] = a[i]
    if S[N-i-2] =='.':
        b[N-i-2] = b[N-i-1] + 1
    else:
        b[N-i-2] = b[N-i-1]
counter.append(a[N-1])
counter.append(b[0])
for i in range(N-1):
    counter.append(a[i] + b[i+1])

print(min(counter))
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [int(input()) for i in range(N)]
flag = True

for i in range(1, N):
  if a[N-1] < a[i]:
    flag = False

if flag:
  print('Yay!')
else:
  print(':(')


Fixed submission:
a = [int(input()) for i in range(6)]
flag = True

for i in range(6):
  for j in range(i+1, 6):
    if abs(a[i] - a[j]) > a[5]:
      flag = False

if flag:
  print('Yay!')
else:
  print(':(')

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [int(input()) for i in range(N)]
flag = True

for i in range(N):
  if a[N-1] < a[i]:
    flag = False

if flag:
  print('Yay!')
else:
  print(':(')


Fixed submission:
a = [int(input()) for i in range(6)]
flag = True

for i in range(6):
  for j in range(i+1, 6):
    if abs(a[i] - a[j]) > a[5]:
      flag = False

if flag:
  print('Yay!')
else:
  print(':(')

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [int(input()) for i in range(N)]
flag = True

for i in range(N):
  if a[N-1] < a[i]:
    flag = False

if flag:
  print('Yay!')
else:
  print(':(')


Fixed submission:
a = [int(input()) for i in range(6)]
flag = True

for i in range(6):
  for j in range(i+1, 6):
    if abs(a[i] - a[j]) > a[5]:
      flag = False

if flag:
  print('Yay!')
else:
  print(':(')

Buggy python submission (verdict: Runtime Error):
a = [int(input()) for i in range(N)]
flag = True

for i in range(N):
  if a[N-1] < a[i]:
    flag = False

if flag:
  print('Yay!')
else:
  print(':(')


Fixed submission:
a = [int(input()) for i in range(6)]
flag = True

for i in range(6):
  for j in range(i+1, 6):
    if abs(a[i] - a[j]) > a[5]:
      flag = False

if flag:
  print('Yay!')
else:
  print(':(')

Buggy python submission (verdict: Runtime Error):
a = [int(input()) for i in range(N)]
flag = True

for i in range(N):
  if a[N-1] < a[i]:
    flag = False

if flag:
  print('Yay')
else:
  print(':(')

Fixed submission:
a = [int(input()) for i in range(6)]
flag = True

for i in range(6):
  for j in range(i+1, 6):
    if abs(a[i] - a[j]) > a[5]:
      flag = False

if flag:
  print('Yay!')
else:
  print(':(')
Buggy python submission (verdict: Time Limit Exceeded):
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)

D = []
for i in range(X):
    for j in range(Y):
        D.append(A[i] + B[j])

D.sort(reverse=True)
E = []
for i in range(min(K, len(D))):
    for j in range(Z):
        E.append(D[i] + C[j])

E.sort(reverse=True)
for i in range(K):
    print(E[i])

Fixed submission:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)

D = []
for i in range(X):
    for j in range(Y):
        D.append(A[i] + B[j])

D.sort(reverse=True)
E = []
for i in range(min(K, len(D))):
    for j in range(Z):
        E.append(D[i] + C[j])

E.sort(reverse=True)
for i in range(K):
    print(E[i])
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
l = [0] * Q
r = [0] * Q
for i in range(Q):
    l[i], r[i] = map(int, input().split())

for i in range(Q):
    s = S[l[i]-1:r[i]]
    print(s.count('AC'))

Fixed submission:
N, Q = map(int, input().split())
S = input()
l = [0] * Q
r = [0] * Q
for i in range(Q):
    l[i], r[i] = map(int, input().split())
counter = [0] * N

for i in range(N-1):
    if S[i:i+2] == 'AC':
        counter[i+1] += counter[i] + 1
    else:
        counter[i+1] += counter[i]

for i in range(Q):
    print(counter[r[i]-1] - counter[l[i]-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())

index_list = []
a = A.copy()
for i in range(N):
    index_list.append(a.index(min(a)))
    a[a.index(min(a))] = 10 ** 9

sum = 0
num = 0
for i in index_list:
    num += B[i]
    if num >= M:
        num -= B[i]
        for j in range(B[i]):
            sum += A[i]
            num += 1
            if num >= M:
                print(sum)
                exit()
    else:
        sum += A[i] * B[i]


Fixed submission:
N, M = map(int, input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())

AB = list(zip(A, B))
AB.sort()
A, B = zip(*AB)

sum = 0
num = 0
for i in range(N):
    num += B[i]
    if num >= M:
        num -= B[i]
        for j in range(B[i]):
            num += 1
            sum += A[i]
            if num >= M:
                print(sum)
                exit()
    else:
        sum += A[i] * B[i]

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())

index_list = []
a = A.copy()
for i in range(N):
    index_list.append(a.index(min(a)))
    a[a.index(min(a))] = 10 ** 9

sum = 0
num = 0
for i in index_list:
    num += B[i]
    if num >= M:
        num -= B[i]
        for j in range(B[i]):
            sum += A[i]
            num += 1
            if num >= M:
                print(sum)
                exit()
    else:
        sum += A[i] * B[i]


Fixed submission:
N, M = map(int, input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())

AB = list(zip(A, B))
AB.sort()
A, B = zip(*AB)

sum = 0
num = 0
for i in range(N):
    num += B[i]
    if num >= M:
        num -= B[i]
        for j in range(B[i]):
            num += 1
            sum += A[i]
            if num >= M:
                print(sum)
                exit()
    else:
        sum += A[i] * B[i]
Buggy python submission (verdict: Runtime Error):
def rec(i):
    if dp[i] < INF:
        return dp[i]
    if i == 0:
        return 0

    res = INF

    res = min(res, rec(i-1) + abs(h[i] - h[i-1]))
    if i > 1:
        res = min(res, rec(i-2) + abs(h[i] - h[i-2]))

    dp[i] = res
    return dp[i]

INF = 105 * 10**7
dp = [INF] * 100010

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

print(rec(N-1))


Fixed submission:
INF = 105 * 10**7
dp = [INF] * 100010

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

dp[0] = 0

for i in range(1, N):
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

INF = 10 ** 12
dp = [INF] * 100010

dp[0] = 0

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

print(dp[N-1])


Fixed submission:
INF = 105 * 10 ** 7
dp = [INF] * 100100

N, K = map(int, input().split())
h = list(map(int, input().split())) + [0] * 100

dp[0] = 0

for i in range(N):
    for j in range(1, K+1):
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]))

print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
INF = 105 * 10 ** 7
dp = [INF] * 100100

N, K = map(int, input().split())
h = list(map(int, input().split())) + [0] * 100

dp[0] = 0

for i in range(N):
    for j in range(1, K+1):
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]))

print(dp[N-1])


Fixed submission:
INF = 105 * 10 ** 7
dp = [INF] * 100100

N, K = map(int, input().split())
h = list(map(int, input().split())) + [0] * 100

dp[0] = 0

for i in range(N):
    for j in range(1, K+1):
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]))

print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

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

for i in range(N):
    for sum_w in range(W+1):
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])
        if sum_w + w[i] > W:
            continue
        dp[i+1][sum_w+w[i]] = max(dp[i+1][sum_w+w[i]], dp[i][sum_w] + v[i])

print(max(dp[N]))


Fixed submission:
dp = [[0] * 100100 for i in range(110)]

N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

for i in range(1, N+1):
    for sum_w in range(W+1):
        if sum_w - w[i-1] >= 0:
            dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w-w[i-1]] + v[i-1])
        
        dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w])

print(dp[N][W])

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

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

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

print(dp[N][W])

Fixed submission:
dp = [[0] * 100100 for i in range(110)]

N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

for i in range(1, N+1):
    for sum_w in range(W+1):
        if sum_w - w[i-1] >= 0:
            dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w-w[i-1]] + v[i-1])
        
        dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w])

print(dp[N][W])

Buggy python submission (verdict: Time Limit Exceeded):
dp = [[0] * 100100 for i in range(110)]

N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

for i in range(1, N+1):
    for sum_w in range(W+1):
        if sum_w - w[i-1] >= 0:
            dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w-w[i-1]] + v[i-1])
        
        dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w])

print(dp[N][W])


Fixed submission:
dp = [[0] * 100100 for i in range(110)]

N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

for i in range(1, N+1):
    for sum_w in range(W+1):
        if sum_w - w[i-1] >= 0:
            dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w-w[i-1]] + v[i-1])
        
        dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w])

print(dp[N][W])
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(len(S)):
    for j in range(len(T)):
        if S[i] == T[j]:
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1)
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])

res = ""
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:
        res = S[i-1] + res
        i -= 1
        j -= 1

print(res)
            

Fixed submission:
S = input()
T = input()

dp = [[0] * (len(T)+1) for _ in range(len(S)+1)]
for i in range(len(S)):
    for j in range(len(T)):
        if S[i] == T[j]:
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1)
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])

res = ""
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:
        res = S[i-1] + res
        i -= 1
        j -= 1

print(res)
Buggy python submission (verdict: Runtime Error):
from collections import Counter

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

va = v[::2]
vb = v[1::2]

va_ = Counter(va).most_common(2)
vb_ = Counter(vb).most_common(2)

if va_[0][0] == vb_[0][0]:
    if va_[0][1] + vb_[1][1] > va_[1][1] + vb_[0][1]:
        print(len(va) - va_[0][1] + len(vb) - vb_[1][1])
    else:
        print(len(va) - va_[1][1] + len(vb) - vb_[0][1])
else:
    print(len(va) - va_[0][1] + len(vb) - vb_[0][1])


Fixed submission:
from collections import Counter

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

va = v[::2]
vb = v[1::2]

va_ = Counter(va).most_common()
vb_ = Counter(vb).most_common()

if va_[0][0] == vb_[0][0]:
    if len(va_) == 1 or len(vb_) == 1:
        if len(va_) == 1 and len(vb_) == 1:
            print(len(v) // 2)
        elif len(va_) == 1:
            if va_[0][0] == vb_[0][0]:
                print(len(vb) - vb_[1][1])
            else:
                print(len(vb) - vb_[0][1])
        else:
            if va_[0][0] == vb_[0][0]:
                print(len(va) - va_[1][1])
            else:
                print(len(va) - va_[0][1])
        exit()
    if va_[0][1] + vb_[1][1] > va_[1][1] + vb_[0][1]:
        print(len(va) - va_[0][1] + len(vb) - vb_[1][1])
    else:
        print(len(va) - va_[1][1] + len(vb) - vb_[0][1])
else:
    print(len(va) - va_[0][1] + len(vb) - vb_[0][1])
Buggy python submission (verdict: Runtime Error):
import fractions
 
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.sort()

dist = []
for i in range(N-1):
    dist.append(x[i+1] - x[i])
    
g = dist[0]

for i in range(N-2):
    g = fractions.gcd(g, dist[i+1])

print(g)

Fixed submission:
N, X = map(int, input().split())
x = list(map(int, input().split()))
x = list(map(lambda x: abs(X - int(x)), x))

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
        
if len(x) < 2:
    print(x[0])
else:
    D = gcd(x[0], x[1])
    for i in range(2, N):
        D = gcd(D, x[i])

    print(D)

Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
x = list(map(int, input().split()))
x = list(map(lambda x: abs(X - int(x)), x))
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

D = gcd(x[0], x[1])
for i in range(2, N):
    D = gcd(D, x[2])

print(D)


Fixed submission:
N, X = map(int, input().split())
x = list(map(int, input().split()))
x = list(map(lambda x: abs(X - int(x)), x))

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
        
if len(x) < 2:
    print(x[0])
else:
    D = gcd(x[0], x[1])
    for i in range(2, N):
        D = gcd(D, x[i])

    print(D)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
x = list(map(int, input().split()))
L = []

for i in range(N-K):
    L.append(abs(x[i]) + x[K+i-1] - x[i])
    L.append(abs(x[K+i-1]) + x[K+i-1] - x[i])
    
if N != 1:
    print(min(L))
else:
    print(abs(x[0]))

Fixed submission:
N, K = map(int, input().split())
x = list(map(int, input().split()))
L = []

for i in range(N-K+1):
    L.append(abs(x[i]) + x[K+i-1] - x[i])
    L.append(abs(x[K+i-1]) + x[K+i-1] - x[i])
    
if N != 1:
    print(min(L))
else:
    print(abs(x[0]))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input())

if N % K:
    print(1)
else:
    print(0)

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

if N % K:
    print(1)
else:
    print(0)