Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03262 (python)

Fixed submission:
import fractions
from functools import reduce

N, K = [int(i) for i in input().split(' ')]
X = [int(i) for i in input().split(' ')]

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

X.append(K)
diff = []
for i,x in enumerate(X):
    if i != 0:
        diff.append(abs(X[i-1] - x))

print(gcd_list(diff))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

N, K = [int(i) for i in input().split(' ')]
X = [int(i) for i in input().split(' ')]

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

X.append(K)
diff = []
for i,x in enumerate(X):
    if i != 0:
        diff.append(abs(X[i-1] - x))

print(gcd_list(diff))
Problem p03274 (python)

Fixed submission:
import bisect

N, K = map(int,input().split())
X = list(map(int,input().split()))

s = bisect.bisect_left(X,0)
if 0 in X:
    K -= 1
else:
    bisect.insort_left(X,0)
    N += 1

MIN = 2 * 10**9
for i in range(K+1):
    if s - K + i >= 0 and s + i <N:
        f = X[s -K+i]
        l = X[s+i]
        if abs(f) < abs(l):
            ans = abs(f) * 2 + abs(l)
        else:
            ans = abs(l) * 2 + abs(f)
        MIN =min(MIN,ans)

print(MIN)

Buggy submission (verdict: Runtime Error):
def main():
    n,k = map(int,input().split())
    X = list(map(int,input().split()))

    import bisect

    i = bisect.bisect_left(X,0)
    if X[i] == 0:
        k -= 1


    ans = 10**9
    if k == 0:
        print(0)
        exit()
    for j in range(-k+1,1):
        # print(j)
        if i + j < 0 or i+j+k-1 >len(X)-1:
            continue
        # print(l,r)
        l = X[i+j]
        r = X[i+j+k-1]

        l = min(0,l)
        r = max(r,0)

        a = min(abs(l),abs(r))
        b = max(abs(l),abs(r))

        t = 2*a + b
        ans = min(t,ans)

    print(ans)



main()

Buggy submission (verdict: Runtime Error):
def main():
    n,k = map(int,input().split())
    X = list(map(int,input().split()))

    import bisect

    i = bisect.bisect_left(X,0)
    if X[i] == 0:
        k -= 1


    ans = 10**9
    if k == 0:
        print(0)
        exit()
    for j in range(-k,1):
        # print(j)
        if i + j < 0 or i+j+k-1 >len(X)-1:
            continue
        # print(l,r)
        l = X[i+j]
        r = X[i+j+k-1]

        l = min(0,l)
        r = max(r,0)

        a = min(abs(l),abs(r))
        b = max(abs(l),abs(r))

        t = 2*a + b
        ans = min(t,ans)

    print(ans)



main()

Buggy submission (verdict: Runtime Error):
def main():
    n,k = map(int,input().split())
    X = list(map(int,input().split()))

    import bisect

    i = bisect.bisect_left(X,0)
    if X[i] == 0:
        k -= 1

    ans = 10**9
    for j in range(-k,1):
        # print(j)
        if i + j < 0 or i+j+k-1 >len(X)-1:
            continue
        l = X[i+j]
        r = X[i+j+k-1]

        l = min(0,l)
        r = max(r,0)

        a = min(abs(l),abs(r))
        b = max(abs(l),abs(r))

        t = 2*a + b
        ans = min(t,ans)

    print(ans)



main()
Problem p03436 (python)

Fixed submission:
from collections import deque

def main():
    R,C= map(int,input().split())

    S = [0,0]

    mv = [[1,0],[-1,0],[0,-1],[0,1]]
    MAP = []
    flg = 0
    block = 0
    for _ in range(R):
        t = list(input())
        block += t.count('#')
        MAP.append(t)
    stack = deque([S])
    MAP_c = [[None]*C for _ in range(R)]
    MAP_c[0][0] = 1
    while stack:
        v = stack.popleft()
        for m in mv:
            u = [v[0]+m[0],v[1]+m[1]]
            if u[0] >=0 and u[0] < R and u[1] >= 0 and u[1] < C and MAP[u[0]][u[1]] == '.':
                MAP[u[0]][u[1]] = '#'
                MAP_c[u[0]][u[1]] = MAP_c[v[0]][v[1]] + 1
                stack.append(u)
                if u == [R-1,C-1]:
                    flg = 1

        if flg == 1:
            break

    if flg == 1:
        a = MAP_c[R-1][C-1]
        print(R*C - a - block)
    else:
        print(-1)


main()

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

def main():
    R,C= map(int,input().split())

    S = [0,0]

    mv = [[1,0],[-1,0],[0,-1],[0,1]]
    MAP = []
    flg = 0
    block = 0
    for _ in range(R):
        t = list(input())
        block += t.count('#')
        MAP.append(t)
    stack = deque([S])
    MAP_c = [[None]*C for _ in range(R)]
    MAP_c[0][0] = 1
    while stack:
        v = stack.popleft()
        for m in mv:
            u = [v[0]+m[0],v[1]+m[1]]
            if u[0] >=0 and u[0] < R and u[1] >= 0 and u[1] < C and MAP[u[0]][u[1]] == '.':
                MAP[u[0]][u[1]] = '#'
                MAP_c[u[0]][u[1]] = MAP_c[v[0]][v[1]] + 1
                stack.append(u)
                if u == [R-1,C-1]:
                    flg = 1

        if flg == 1:
            break

    a = MAP_c[R-1][C-1]
    print(R*C - a - block)


main()

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

def main():
    R,C= map(int,input().split())

    S = [0,0]

    mv = [[1,0],[-1,0],[0,-1],[0,1]]
    MAP = []
    flg = 0
    block = 0
    for _ in range(R):
        t = list(input())
        block += t.count('#')
        MAP.append(t)
    stack = deque([S])
    MAP_c = [[None]*C for _ in range(R)]
    MAP_c[0][0] = 1
    while stack:
        v = stack.popleft()
        for m in mv:
            u = [v[0]+m[0],v[1]+m[1]]
            if u[0] >=0 and u[0] < R and u[1] > 0 and u[1] < C and MAP[u[0]][u[1]] == '.':
                MAP[u[0]][u[1]] = '#'
                MAP_c[u[0]][u[1]] = MAP_c[v[0]][v[1]] + 1
                stack.append(u)
                if u == [R-1,C-1]:
                    flg = 1

        if flg == 1:
            break

    a = MAP_c[R-1][C-1]
    print(R*C - a - block)


main()
Problem p03472 (python)

Fixed submission:
import numpy as np
N, H = map(int,input().split())

maxA = 0
B = []
for _ in range(N):
    a, b = map(int,input().split())
    B.append(b)
    if maxA < a:
        maxA = a

B = np.array(B)
throw_all = np.sort((B[B>maxA]))[::-1]
SUM = 0
cnt = 0
for a in throw_all:
    SUM += a
    cnt += 1
    if SUM >= H:
        print(cnt)
        exit()

ans = -(-(H-SUM)//maxA)+ cnt
print(ans)

Buggy submission (verdict: Runtime Error):
port numpy as np
N, H = map(int,input().split())

maxA = 0
B = []
for _ in range(N):
    a, b = map(int,input().split())
    B.append(b)
    if maxA < a:
        maxA = a

B = np.array(B)
throw_all = np.sort((B[B>maxA]))
SUM = 0
cnt = 0
print(throw_all)
for a in throw_all:
    SUM += a
    cnt += 1
    if SUM >= H:
        print(cnt)
        exit()

ans = -(-(H-SUM)//maxA)+ cnt
print(ans)
Problem p03476 (python)

Fixed submission:
import math
from itertools import accumulate

Q = int(input())
LR = []

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    # print(int(math.sqrt(n)))
    for i in range(2,int(math.sqrt(n))+1):
        for j in range(i*2, n+1 ,i):
            is_prime[j] = False

    return is_prime

def like2017(is_prime,n):
    solve = [0] * (n+1)
    for i in range(3,n+1,2):
        if is_prime[i] and is_prime[int((i+1)/2)]:
            solve[i] = 1
        
    return solve

for _ in range(Q):
    t = [int(i) for i in input().split(' ')]
    LR.append(t)

L = 10 ** 5
is_prime = primes(L)
solve = like2017(is_prime,L)
# print(solve)
ans = list(accumulate(solve))
# print(ans)

for l, r in LR:
    print(ans[r] - ans[l-1])

Buggy submission (verdict: Runtime Error):
import math
from itertools import accumulate

Q = int(input())
LR = []

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    # print(int(math.sqrt(n)))
    for i in range(2,int(math.sqrt(n))+1):
        for j in range(i*2, n+1 ,i):
            is_prime[j] = False

    return is_prime

def like2017(is_prime,n):
    solve = [0] * (n+1)
    for i in range(3,n+1,2):
        if is_prime[i] and is_prime[int((i+1)/2)]:
            solve[i] = 1
        
    return solve

for _ in range(Q):
    t = [int(i) for i in input().split(' ')]
    LR.append(t)

L = 100
is_prime = primes(L)
solve = like2017(is_prime,L)
# print(solve)
ans = list(accumulate(solve))
# print(ans)

for l, r in LR:
    print(ans[r] - ans[l-1])

Buggy submission (verdict: Runtime Error):
import fractions

Q = int(input())
LR = []

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    # print(int(math.sqrt(n)))
    for i in range(2,int(fractions.sqrt(n))+1):
        for j in range(i*2, n+1 ,i):
            is_prime[j] = False

    return is_prime

def like2017(is_prime,n):
    solve = [False] * (n+1)
    for i in range(3,n+1,2):
        if i < n and i >2:
            solve[i] = is_prime[i] and is_prime[int((i+1)/2)]

    return solve

for _ in range(Q):
    t = [int(i) for i in input().split(' ')]
    LR.append(t)

L = 10**5 
is_prime = primes(L)
solve = like2017(is_prime,L)
for l, r in LR:
    # print(solve[l:r+1])
    print(solve[l:r+1].count(True))
Problem p03498 (python)

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

MIN,MAX = 10**7,-10**7
ans = []
for i in range(N):
    if MIN > A[i]:
        MIN =A[i]
        min_i = i
    if MAX < A[i]:
        MAX = A[i]
        max_i = i

if abs(MIN) <= abs(MAX):
    for i in range(N):
        if A[i] < 0:
            A[i] += MAX
            ans.append([max_i+1,i+1])
    # print(A)

    for i in range(N-1):
        if A[i] > A[i+1]:
            A[i+1] += A[i]
            ans.append([i+1,i+2])

else:
    for i in range(N):
        if A[i] > 0:
            A[i] += MIN
            ans.append([min_i+1,i+1])
    # print(A)

    for i in range(N-1,0,-1):
        if A[i] < A[i-1]:
            A[i-1] += A[i]
            ans.append([i+1,i])
print(len(ans))
for a in ans:
    print(*a)

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

MIN,MAX = 10**7,-10**7
ans = []
for i in range(N):
    if MIN > A[i]:
        MIN =A[i]
        min_i = i
    if MAX < A[i]:
        MAX = A[i]
        max_i = i

if abs(MIN) <= abs(MAX):
    for i in range(N):
        if A[i] < 0:
            A[i] += MAX
            ans.append([max_i+1,i+1])
    # print(A)

    for i in range(N-1):
        if A[i] > A[i+1]:
            A[i+1] += A[i]
            ans.append([i+1,i+2])

else:
    for i in range(N):
        if A[i] > 0:
            A[i] += MIN
            ans.append(min_i,i+1)
    # print(A)

    for i in range(N-1,0,-1):
        if A[i] < A[i-1]:
            A[i-1] += A[i]
            ans.append([i+1,i])

print(len(ans))
for a in ans:
    print(*a)

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

ans = []
i = 0
while A[i] > 0:
    i += 1
n = i
for i in range(n-1,0,-1):
    if A[i] < A[i-1]:
        A[i-1] += A[i]
        ans.appned(i+1,i)


for i in range(n,N-1):
    if A[i] <= A[i+1]:
        continue
    else:
        if A[i+1] >= 0:
            A[i+1] += A[i]
            ans.append([i+1,i+2])
        else:
            A[i+1] += 2 * A[i]
            ans.append([i+1,i+2])
            ans.append([i+1,i+2])

# print(A)
print(len(ans))
for a in ans:
    print(*a)
Problem p03845 (python)

Fixed submission:
N = int(input())
T = [int(i) for i in input().split(' ')]
M = int(input())
PX = []
for _ in range(M):
    PX.append([int(i) for i in input().split(' ')])
SUM = sum(T)

for p,x in PX:
    print(SUM - T[p-1] + x)

Buggy submission (verdict: Runtime Error):
import math
from collections import defaultdict
import itertools
N = int(input())
town = [[int(i) for i in input().split(' ')] for _ in range(N)]

dist = 0
c = 0
for v in itertools.permutations(town,len(town)):
    c += 1
    sx = v[0][0]
    sy = v[0][1]
    for i in v[1::]:
        dist += math.sqrt((sx - i[0]) ** 2 + (sy - i[1]) ** 2)
        sx, sy = i[0], i[1]

print(dist/c)
Problem p02971 (python)

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
s, f = sorted(a)[-2:]

for ai in a:
    print(f if ai != f else s)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]

for i in range(n):
    ac = a.copy()
    del ac[i]
    print(max(ac))
Problem p03050 (python)

Fixed submission:
n = int(input())

ans = 0
for i in range(1, int(n**0.5) + 1):
    if n % i == 0:
        m = n // i - 1
        if m != 0 and n // m == n % m:
            ans += m

print(ans)

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

ans = 0
for i in range(1, int(n**0.5) + 1):
    if n % i == 0:
        m = n // i - 1
        if n // m == n % m:
            ans += m

print(ans)
Problem p03061 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
 
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a % b)
 
 
L = [0] * (N + 1)
R = [0] * (N + 1)
for i in range(N):
    L[i+1] = gcd(L[i], A[i])
 
for i in range(N-1, -1, -1):
    R[i] = gcd(R[i+1], A[i])
 
ans = 1
for i in range(N):
    ans = max(ans, gcd(L[i], R[i+1]))
 
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from fractions import gcd

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

if n <= 2:
    print(max(a))
    sys.exit()

l = [0] * n
r = [0] * n
l[0] = a[0]
r[-1] = a[-1]

for i in range(n - 1):
    l[i + 1] = gcd(l[i], a[i + 1])
    r[-1 - (i + 1)] = gcd(r[-1 - i], a[-1 - (i + 1)])

ans = 0
for i in range(n - 2):
    ans = max(ans, gcd(l[i], r[i + 2]))
ans = max(ans, l[-2], r[1])
print(ans)

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

a = list(set(a))

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


if n <= 2:
    print(max(a))
else:
    a.sort()
    ans = max(gcd(a[0], a[-1]), gcd(a[1], a[-1]), gcd(a[0], a[-2]))
    print(ans)
Problem p03076 (python)

Fixed submission:
a = []

for i in range(5):
    a.append(int(input()))


def ceil10(n):
    if n % 10 == 0:
        return n
    else:
        return ((n // 10) + 1) * 10


def min_1(a):
    a2 = list(filter(lambda a: a > 0, list(map(lambda e: e % 10, a))))

    if len(a2) == 0:
        return 10

    return min(a2)


ans = sum(map(ceil10, a)) - 10 + min_1(a)
print(ans)

Buggy submission (verdict: Runtime Error):
a = []

for i in range(5):
    a.append(int(input()))


def ceil10(n):
    if n % 10 == 0:
        return n
    else:
        return ((n // 10) + 1) * 10


def min_1(a):
    a2 = list(filter(lambda a: a > 0, (map(lambda e: e % 10, a))))

    return min(a2)


ans = sum(map(ceil10, a)) - 10 + min_1(a)
print(ans)

Buggy submission (verdict: Runtime Error):
a = []

for i in range(5):
    a.append(int(input()))


def ceil10(n):
    if n % 10 == 0:
        return n
    else:
        return (n // 10) * 10 + 10


def min_1(a):
    a2 = list(filter(lambda a: a > 0, (map(lambda e: e % 10, a))))

    return min(a2)


ans = sum(map(ceil10, a)) - 10 + min_1(a)
print(ans)
Problem p03106 (python)

Fixed submission:
from fractions import gcd
a, b, k = list(map(int, input().split()))
t = gcd(a, b)
c = []
for i in range(1,t+1):
    if t % i ==0:
        c.append(i)
print(c[-k])

Buggy submission (verdict: Runtime Error):
from math import gcd
a, b, k = list(map(int, input().split()))
t = gcd(a,b)
c = []
for i in range(1,t+1):
    if t % i ==0:
        c.append(i)
print(c[-k])
Problem p03109 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
from datetime import datetime


def solve(S: str):
    if datetime.strptime(S, "%Y/%m/%d") <= datetime.strptime("2019/4/30", "%Y/%m/%d"):
        print("Heisei")
    else:
        print("TBD")


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from bisect import bisect_right


def solve(A: int, B: int, Q: int, s: "List[int]", t: "List[int]", x: "List[int]"):
    b, d = bisect_right(s, x), bisect_right(t, x)
    INF = 10e11
    ret = INF

    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            ret = min(ret, d1, d2)
    print(ret)


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    INF = 10e11
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    s = [-INF] + [int(next(tokens)) for _ in range(A)] + [INF]  # type: "List[int]"
    t = [-INF] + [int(next(tokens)) for _ in range(B)] + [INF]  # type: "List[int]"

    for x in range(Q):
        x = int(input())
        solve(A, B, Q, s, t, x)


if __name__ == "__main__":
    main()
Problem p03125 (python)

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

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

dp = dict.fromkeys(range(n + 1))  # dp[n]: n本使うときの桁数
dp[0] = 0

num = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
anum = sorted(
    dict(filter(lambda e: e[0] in a, num.items())).items(), reverse=True
)  # 後の計算用にsortしておく

for i in range(n):
    dp[i + 1] = -float("inf")
    for e in anum:
        if i + 1 - e[1] >= 0:
            dp[i + 1] = max(dp[i + 1], dp[i + 1 - e[1]] + 1)

ans = ""
while dp[n] > 1:
    for e in anum:  # anum は降順sortされているので, 大きい順に確認
        if n - e[1] >= 0:
            if dp[n - e[1]] == dp[n] - 1:
                ans += str(e[0])
                n -= e[1]
                break

# 末尾桁は n =0(ちょうど使い切るように決定)
ans += str(list(filter(lambda e: e[1] == n, anum))[0][0])

print(ans)
Problem p03128 (python)

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

dp = dict.fromkeys(range(n + 1))  # dp[n]: n本使うときの桁数
dp[0] = 0

num = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
anum = sorted(
    dict(filter(lambda e: e[0] in a, num.items())).items(), reverse=True
)  # 後の計算用にsortしておく

for i in range(n):
    dp[i + 1] = -float("inf")
    for e in anum:
        if i + 1 - e[1] >= 0:
            dp[i + 1] = max(dp[i + 1], dp[i + 1 - e[1]] + 1)

ans = ""
while dp[n] > 1:
    for e in anum:  # anum は降順sortされているので, 大きい順に確認
        if n - e[1] >= 0:
            if dp[n - e[1]] == dp[n] - 1:
                ans += str(e[0])
                n -= e[1]
                break

# 末尾桁は n =0(ちょうど使い切るように決定)
ans += str(list(filter(lambda e: e[1] == n, anum))[0][0])

print(ans)

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

dp = dict.fromkeys(range(n + 1))  # dp[n]: n本使うときの桁数
dp[0] = 0

num = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
anum = sorted(
    dict(filter(lambda e: e[0] in a, num.items())).items(), reverse=True
)  # 後の計算用にsortしておく

for i in range(n):
    dp[i + 1] = dp[i]
    for e in anum:
        if i + 1 - e[1] >= 0:
            dp[i + 1] = max(dp[i + 1], dp[i + 1 - e[1]] + 1)

ans = ""
while dp[n] > 1:
    for e in anum:  # anum は降順sortされているので, 大きい順に確認
        if n - e[1] >= 0:
            if dp[n - e[1]] == dp[n] - 1:
                ans += str(e[0])
                n -= e[1]
                break

# 末尾桁は n =0(ちょうど使い切るように決定)
ans += str(list(filter(lambda e: e[1] == n, anum))[0][0])

print(ans)
Problem p03213 (python)

Fixed submission:
N = int(input())
e = [0] * (N + 1)

for i in range(2, N + 1):
    cur = i
    for j in range(2, i + 1):
        while cur % j == 0:
            e[j] += 1
            cur //= j


def num(m):  # e の要素のうち m-1 以上のものの個数
    return len(list(filter(lambda x: x >= m - 1, e)))


print(
    num(75) + num(25) * (num(3) - 1) + num(15) * (num(5) - 1) + num(5) *
    (num(5) - 1) * (num(3) - 2) // 2)

Buggy submission (verdict: Runtime Error):
N = int(input())
e = [0] * (N + 1)
for i in range(2, N + 1):
    cur = i

for j in range(2, i + 1):
    while cur % j == 0:
        e[j] += 1
        cur //= j


def num(m):  # e の要素のうち m-1 以上のものの個数
    return len(list(filter(lambda x: x >= m - 1, e)))


print(
    num(75) + num(25) * (num(3) - 1) + num(15) * (num(5) - 1) + num(5) *
    (num(5) - 1) * (num(3) - 2) // 2)
Problem p03244 (python)

Fixed submission:
from collections import Counter

n = int(input())
v = input().split()

v1 = v[::2]
v2 = v[1::2]
c1 = Counter(v1).most_common(2)
c2 = Counter(v2).most_common(2)

if len(set(v)) == 1:
    print(len(v) // 2)
elif c1[0][0] != c2[0][0]:
    print(n - c1[0][1] - c2[0][1])
else:
    print(min(n - c1[0][1] - c2[1][1], n - c1[1][1] - c2[0][1]))

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

n = int(input())
v = input().split()

v1 = v[::2]
v2 = v[1::2]
c1 = Counter(v1).most_common(2)
c2 = Counter(v2).most_common(2)

if c1[0][0] != c2[0][0]:
    print(n - c1[0][1] - c2[0][1])
else:
    print(min(n - c1[0][1] - c2[1][1], n - c1[1][1] - c2[0][1]))

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

n = int(input())
v = input().split()

v1 = v[::2]
v2 = v[1::2]
c1 = Counter(v1).most_common(2)
c2 = Counter(v2).most_common(2)

if c1[0][0] != c2[0][0]:
    print(n=c1[0][1] - c2[0][1])
else:
    print(min(n - c1[0][1] - c2[1][1], n - c1[1][1] - c2[0][1]))
Problem p03263 (python)

Fixed submission:
h, w = map(int, input().split())
a = []

for _ in range(h):
    a.append(list(map(int, input().split())))

ans = []

for i in range(h):
    for j in range(w - 1):
        if a[i][j] % 2 == 1:
            ans.append([i + 1, j + 1, i + 1, j + 2])
            a[i][j + 1] += 1

for i in range(h - 1):
    if a[i][w - 1] % 2 == 1:
        ans.append([i + 1, w, i + 2, w])
        a[i + 1][w - 1] += 1

print(len(ans))
for ans in ans:
    print(*ans)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
a = []

for _ in range(h):
    a.append = list(map(int, input().split()))

ans = []

for i in range(h):
    for j in range(w - 1):
        if a[i][j] % 2 == 1:
            ans.append([i + 1, j + 1, i + 1, j + 2])
            a[i][j + 1] += 1

for i in range(h - 1):
    if a[i][w - 1] % 2 == 1:
        ans.append([i + 1, w, i + 2, w])
        a[i + 1][w - 1] += 1

print(len(ans))
for ans in ans:
    print(*ans)
Problem p03282 (python)

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

c = 0
a = 1
for si in s:
    if si == "1":
        c += 1
    else:
        a = si
        break

print("1" if k - c <= 0 else a)

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())

c = 0
for si in s:
    if si == "1":
        c += 0
    else:
        a = si
        break

print("1" if k - c <= 0 else a)
Problem p03311 (python)

Fixed submission:
from statistics import median

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

aa = list(map(lambda e: e[1] - (e[0] + 1), enumerate(a)))
minb = median(aa)


ans = int(sum(map(lambda ea: abs(ea - minb), aa)))

print(ans)

Buggy submission (verdict: Runtime Error):
from statistics import mode

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

aa = list(map(lambda e: e[1] - (e[0] + 1), enumerate(a)))
minb = mode(aa)
ans = sum(map(lambda ea: abs(ea - minb), aa))

print(ans)
Problem p02582 (python)

Fixed submission:
i = 0
j = 0
k = 0

w = ""
for s in input():
    j += 1

    if s == "S":
        k += 1

    if s == "S" and i > 0 and j == 2 and w != "R":
        i -= 1

    if s == "R" and (w == "R" or w == ""):
        i += 1
    elif s == "R" and w != s:
        i += 1    
    
    if w == "S":
        i = 1
    
    w = s

if k == 3:
    i = 0

print(i)

Buggy submission (verdict: Runtime Error):
vi = 0
j = 0
for s in input():
    j += 1

    if s == "R":
        i += 1
    if j != 3 and i > 0 and s == "S":
        i -= 1

print(i)