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

Fixed submission:
n, m = map(int, input().split())
l, r = map(int, input().split())
li = []


for _ in range(m - 1):
    l_, r_ = map(int, input().split())
    l = max(l, l_)
    r = min(r, r_)


print(max(r - l + 1, 0))

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

l, r = map(int, input().split())


def check(i, l, r):
    if i == m:
        return max(r - l + 1, 0)
    l_, r_ = map(int, input().split())
    nl = max(l, l_)
    nr = min(r, r_)
    i += 1
    return check(i, nl, nr)


print(check(1, l, r))

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

li = []
for _ in range(m):
    li.append(list(map(int, input().split())))


def check(i, l, r):
    if i == m:
        try:
            return r - l + 1
        except:
            return 0

    l_, r_ = li[i]
    nl = max(l, l_)
    nr = min(r, r_)
    return check(i + 1, nl, nr)


l, r = li[0]
print(check(1, l, r))

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

li = []
for _ in range(m):
    li.append(list(map(int, input().split())))


def check(i, l, r):
    if r - l + 1 == 0:
        return 0
    if i == m:
        return r - l + 1
    l_, r_ = li[i]
    nl = max(l, l_)
    nr = min(r, r_)
    return check(i + 1, nl, nr)


l, r = li[0]
print(check(1, l, r))

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

l, r = map(int, input().split())


def check(i, l, r):
    if r - l + 1 == 0:
        return 0
    if i == m:
        return r - l + 1
    l_, r_ = map(int, input().split())
    nl = max(l, l_)
    nr = min(r, r_)
    return check(i + 1, nl, nr)


print(check(1, l, r))

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

l, r = map(int, input().split())


def check(i, l, r):
    if i == m:
        return r - l + 1
    l_, r_ = map(int, input().split())
    nl = max(l, l_)
    nr = min(r, r_)
    i += 1
    return check(i, nl, nr)


print(check(1, l, r))

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

l, r = map(int, input().split())


def check(i, l, r):
    if i == m:
        print(r - l + 1)
        exit(0)
    l_, r_ = map(int, input().split())
    nl = max(l, l_)
    nr = min(r, r_)
    i += 1
    check(i, nl, nr)


check(1, l, r)

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

# 1個目を受け取る
l, r = map(int, input().split())


def check(i, l, r):
    if i == m:
        print(r - l + 1)
        exit()
    l_, r_ = map(int, input().split())
    nl = max(l, l_)
    nr = min(r, r_)
    i += 1
    check(i, nl, nr)


check(1, l, r)
Problem p03061 (python)

Fixed submission:
n = int(input())
v = list(map(int, input().split()))
m = 1
gf = []
gp = []


def gcd(x, y):
    if x < y:
        x += y
        y = x - y
        x -= y

    while y > 0:
        r = x % y
        x = y
        y = r

    return x


gf.append(v[0])
for i in range(n-1):
    gf.append(gcd(gf[i], v[i+1]))

gp.append(v[n-1])
for i in range(n-1):
    gp.append(gcd(gp[i], v[n-2-i]))

m = gp[n-2]

for i in range(n-1):
    b = gcd(gf[i], gp[n-3-i])
    if m < b:
        m = b
if m < gf[n-2]:
    m = gf[n-2]

print(m)

Buggy submission (verdict: Runtime Error):
import functools
import math
n = int(input())
values = list(map(int, input().split()))
m = 1

for i in range(n):
    a = values[:]
    a.pop(i)
    gcd = functools.reduce(math.gcd, a)
    if m < gcd:
        m = gcd


print(m)
Problem p03085 (python)

Fixed submission:
B = input()

_dir = {"A": "T", "T": "A", "G": "C", "C": "G"}

print(_dir[B])

Buggy submission (verdict: Runtime Error):
input("ATCG"["TAGC".find(input())])
Problem p03087 (python)

Fixed submission:
n, q = map(int, input().split())
s = input()
flag = False
count = 0
li = []

for i in range(n):
    if s[i] == "A":
        flag = True
    elif s[i] == "C" and flag is True:
        count += 1
        flag = False
    else:
        flag = False
    li.append(count)

for i in range(q):
    l, r = map(int, input().split())
    print(li[r-1] - li[l-1])

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
s = input()
flag = False
count = 0
li = []

for i in range(n):
    if s[i] == "A":
        flag = True
    if s[i] == "C" and flag is True:
        count += 1
        flag = False
    li.append(count)
    print(li)

for i in range(q):
    l, r = map(int, input().split())
    print(li[r-1] - li[l-1])

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
s = input()
flag = False
count = 0
li = [0]

for i in s:
    if i == "A":
        flag = True
    if i == "C" and flag is True:
        count += 1
        flag = False
    li.append(count)
    print(li)

for i in range(q):
    l, r = map(int, input().split())
    print(li[r] - li[l])
Problem p03164 (python)

Fixed submission:
n, w = map(int, input().split())
goods = [list(map(int, input().split())) for _ in range(n)]
dp = [[float("INF")] * (10 ** 5 + 1) for _ in range(n + 1)]
dp[0][0] = 0

for i in range(n):
    for j in range(10 ** 5 + 1):
        if 0 <= j - goods[i][1]:
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - goods[i][1]] + goods[i][0])
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])


M = 0
for i in range(10 ** 5 + 1):
    if dp[n][i] <= w:
        M = i
print(M)

Buggy submission (verdict: Runtime Error):
n, w = map(int, input().split())
goods = [list(map(int, input().split())) for _ in range(n)]
dp = [[0] * (w + 1) for _ in range(n)]
for i in range(n):
    for j in range(w + 1):
        if 0 <= j - goods[i][0]:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - goods[i][0]] + goods[i][1])
        dp[i][j] = max(dp[i][j], dp[i - 1][j])
print(dp[n - 1][w])

Buggy submission (verdict: Runtime Error):
n, w = map(int, input().split())
goods = [list(map(int, input().split())) for _ in range(n)]
dp = [[0] * (w + 1) for _ in range(n + 1)]
for i in range(n):
    for j in range(w + 1):
        if 0 <= j - goods[i][0]:
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - goods[i][0]] + goods[i][1])
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(dp[n][w])

Buggy submission (verdict: Runtime Error):
n, w = map(int, input().split())
goods = [list(map(int, input().split())) for _ in range(n)]
dp = [[0] * (w + 1) for _ in range(n + 1)]
for i in range(n):
    for j in range(w + 1):
        if 0 <= j - goods[i][0]:
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - goods[i][0]] + goods[i][1])
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

for i in range(n + 1):
    print(dp[i])
print(dp[n][w])
Problem p03206 (python)

Fixed submission:
d = int(input())
if d == 25:
    print("Christmas")
elif d == 24:
    print("Christmas Eve")
elif d == 23:
    print("Christmas Eve Eve")
else:
    print("Christmas Eve Eve Eve")

Buggy submission (verdict: Runtime Error):
print("Christmas"+" Eve"*(25-int(input()))
Problem p03244 (python)

Fixed submission:
import collections

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

s = len(set(v))
if s == 1:
    print(n // 2)
    exit()

odd = v[::2]
even = v[1::2]
mo = collections.Counter(odd).most_common(2)
me = collections.Counter(even).most_common(2)

if mo[0][0] != me[0][0]:
    print(n - mo[0][1] - me[0][1])
elif len(mo) == 1:
    print(n - mo[0][1] - me[1][1])
elif len(me) == 1:
    print(n - mo[1][1] - me[0][1])
else:
    print(n - max(mo[0][1] + me[1][1], mo[1][1] + me[0][1]))

Buggy submission (verdict: Runtime Error):
import collections

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

s = len(set(v))
if s == 1:
    print(n // 2)
    exit()

odd = v[::2]
even = v[1::2]
mo = collections.Counter(odd).most_common()[0]
mo2 = collections.Counter(odd).most_common()[1]
me = collections.Counter(even).most_common()[0]
me2 = collections.Counter(even).most_common()[1]

if mo[0] == me[0]:
    if me2[1] < mo2[1]:
        mo = mo2
    else:
        me = me2
print(abs((n // 2) - mo[1]) + abs((n // 2) - me[1]))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import collections

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

if len(set(v_l)) == 1:
    print(n // 2)
    exit()

v_l_odd = []
v_l_even = []

for i in range(n):
    if i % 2 == 0:
        v_l_odd.append(v_l[i])
    else:
        v_l_even.append(v_l[i])

max_odd = collections.Counter(v_l_odd)
mon = max_odd.most_common(1)[0][0]
max_even = collections.Counter(v_l_even)
men = max_even.most_common(1)[0][0]

if mon == men:
    if max(max_odd.most_common(2)[1][1], max_even.most_common(2)[1][1]) 
== max_odd.most_common(2)[1][1]:
        mon = max_odd.most_common(2)[1][1]
    else:
        men = max_even.most_common(2)[1][1]

v_l_odd_l = []
v_l_even_l = []

for i in range(n):
    if i % 2 == 0:
        if v_l[i] != mon:
            v_l_odd_l.append(v_l[i])
    else:
        if v_l[i] != men:
            v_l_even_l.append(v_l[i])

print(len(v_l_odd_l) + len(v_l_even_l))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import collections

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

if len(set(v_l)) == 1:
    print(n // 2)
    exit()

v_l_odd = []
v_l_even = []

for i in range(n):
    if i % 2 == 0:
        v_l_odd.append(v_l[i])
    else:
        v_l_even.append(v_l[i])

max_odd = collections.Counter(v_l_odd)
mon = max_odd.most_common(1)[0][0]
max_even = collections.Counter(v_l_even)
men = max_even.most_common(1)[0][0]

if mon == men:
    if max(max_odd.most_common(2)[1][1], max_even.most_common(2)[1][1]) 
== max_odd.most_common(2)[1][1]:
        mon = max_odd.most_common(2)[1][1]
    else:
        men = max_even.most_common(2)[1][1]

v_l_odd_l = []
v_l_even_l = []

for i in range(n):
    if i % 2 == 0:
        if v_l[i] != mon:
            v_l_odd_l.append(v_l[i])
    else:
        if v_l[i] != men:
            v_l_even_l.append(v_l[i])

print(len(v_l_odd_l) + len(v_l_even_l))
Problem p03262 (python)

Fixed submission:
import fractions
from functools import reduce

n, x = map(int, input().split())
xl = list(map(int, input().split()))
xl.append(x)
xl.sort()
xldiv = []
for i in range(n):
    xldiv.append(xl[i + 1] - xl[i])

print(reduce(fractions.gcd, xldiv))

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


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


N, X = map(int, input().split())
toshi = list(map(int, input().split()))
toshi.sort()
if N == 1:
    print(toshi[0] - X)
    exit()

diff = [abs(X - toshi[0])]

for i in range(N - 1):
    diff.append(abs(toshi[i+1] - toshi[i]))

print(gcd_list(diff))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)


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

if N == 1:
    print(toshi[0] - X)
    exit()

diff = []
diff.append(X - toshi[0])

for i in range(N-1):
    diff.append(abs(toshi[i+1] - toshi[i]))

print(gcd_list(diff))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)


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

if N == 1:
    print(toshi[0] - X)
    exit()

diff = []

for i in range(N - 1):
    diff.append(abs(toshi[i+1] - toshi[i]))

print(gcd_list(diff))
Problem p03280 (python)

Fixed submission:
a, b = map(int, input().split())
print((a - 1) * (b - 1))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().spkit())
print((a - 1) * (b - 1))
Problem p03287 (python)

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
table = {0: 0}
buf = 0
cnt = 0
for i in range(n):
    buf = (buf + a[i]) % m
    if buf in table:
        cnt += table[buf]
        table[buf] += 1
    else:
        table[buf] = 1
print(cnt + table[0])

Buggy submission (verdict: Runtime Error):
import numpy
n, m = map(int, input().split())
a = numpy.array([0] + list(map(int, input().split())), dtype=numpy.float64)

acs = numpy.cumsum(a)
cnt = 0

for l in range(n):
    for r in range(l, n):
        if (acs[r] - acs[l - 1]) % m == 0:
            cnt += 1
print(cnt)
Problem p03496 (python)

Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np

n = int(input())
a = list(map(int , input().split()))
print(2*n)
if a[np.argmax(a)] <= -a[np.argmin(a)]:
    cnt = len(a) - 1
    for i in range(0, len(a)):
        print(str(np.argmin(a) + 1) + " " + str(cnt + 1))
        a[cnt] += a[np.argmin(a)]
        print(str(np.argmin(a) + 1) + " " + str(cnt + 1))
        a[cnt] += a[np.argmin(a)]
        cnt -= 1;
else:
    cnt = 0
    for i in range(0, len(a)):
        print(str(np.argmax(a) + 1) + " " + str(cnt + 1))
        a[cnt] += a[np.argmax(a)]
        print(str(np.argmax(a) + 1) + " " + str(cnt + 1))
        a[cnt] += a[np.argmax(a)]
        cnt += 1

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np

n = map(int, raw_input().split(" "))
a = map(int, raw_input().split(" "))
maxi = a[np.argmax(a)]
mini = a[np.argmin(a)]
print(2*n[0])
if maxi < 0:
    a.reverse()
    cnt = len(a) - 1
    for i in a:
        print(str(cnt + 1) + " " + str(np.argmin(a) + 1))
        a[cnt] += a[np.argmin(a)];
        print(str(cnt + 1) + " " + str(np.argmin(a) + 1))
        a[cnt] += a[np.argmin(a)];
        cnt -= 1;
else:
    cnt = 0
    for i in a:
        print(str(cnt + 1) + " " + str(np.argmax(a) + 1))
        a[cnt] += a[np.argmax(a)];
        print(str(cnt + 1) + " " + str(np.argmax(a) + 1))
        a[cnt] += a[np.argmax(a)];
        cnt += 1
Problem p03923 (python)

Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
def pow(a, b):
    if b == 1:return a
    if b%2 == 0: return pow(a*a, int(b/2))
    return a*pow(a*a, int(b/2))
 
def binaryOne(n, multi):
    l, r = 0, n
    mid = (l + r)/2    
    while r - l > 1:
        if pow(mid, multi) >= n:
            r = mid
        else:
            l = mid
        mid = (r + l)/2
    return r;
 
 
def binaryTwo(n, maxi, multi):
    l, r = 0, multi
    mid = (l + r)/2
    while r - l > 1:
        if pow(maxi, (multi - mid))*pow(maxi - 1, mid) >= n:
            l = mid
        else:
            r = mid
        mid = (r + l)/2;
    return l
 
n, a = map(int,raw_input().split(" "))
ans = 1e18
for i in xrange(0, 40):
    maxi = binaryOne(n, i + 1);
    subt = binaryTwo(n, maxi, i + 1)
    ans = min(ans, a*i + maxi*(i + 1) - subt)
    
print ans

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
def pow(a, b):
    if b == 1:return a
    if b%2 == 0: return pow(a*a, int(b/2))
    return a*pow(a*a, int(b/2))
 
def binaryOne(n, multi):
    l, r = 0, n
    mid = (l + r)/2    
    while r - l > 1:
        if pow(mid, multi) >= n:
            r = mid
        else:
            l = mid
        mid = (r + l)/2
    return r;
 
 
def binaryTwo(n, maxi, multi):
    l, r = 0, multi
    mid = (l + r)/2
    while r - l > 1:
        if pow(maxi, (multi - mid))*pow(maxi - 1, mid) >= n:
            l = mid
        else:
            r = mid
        mid = (r + l)/2;
    return l
 
n, a = map(int,raw_input().split(" "))
ans = 1e18
for i in xrange(0, 40):
    maxi = binaryOne(n, i + 1);
    subt = binaryTwo(n, maxi, i + 1)
    ans = min(ans, a*i + maxi*(i + 1) - subt)
    
print ans
Problem p02675 (python)

Fixed submission:
n=int(input()[-1])
if n in [2,4,5,7,9]:
  print('hon')
elif n in [0,1,6,8]:
  print('pon')
else:
  print('bon')

Buggy submission (verdict: Runtime Error):
n=int(input()[:-1])
if n in [2,4,5,7,9]:
  print('hon')
elif n in [0,1,6,8]:
  print('pon')
else:
  print('bon')
Problem p02755 (python)

Fixed submission:
A, B = map(int, input().split())
for i in range(20000):
    if int(i*0.08) == A and int(i * 0.1) == B:
        print(i)
        exit()
print(-1)

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split())
A*=100
B*=100
for i in range(2000):
  t*=100
  if A==t*8 and B==t*10:
    print(i)
    break
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split())
A*=100
B+=100
for i in range(2000):
  t*=100
  if A==t*8//100 and B==t//10:
    print(i)
    exit()
print(-1)
Problem p02811 (python)

Fixed submission:
K, X = map(int, input().split())
print('Yes' if 500 * K >= X else 'No')

Buggy submission (verdict: Runtime Error):
k, x = map(int, input().split())
print('Yes' if 500*k>=x else'No)
Problem p02937 (python)

Fixed submission:
s = input()
n = len(s)
l = [[]for i in range(26)]

for i, c in enumerate(s * 2):
    l[ord(c) - ord('a')].append(i)


from bisect import *

shukai = 0
now = 0

t = input()
for c in t:
    x = ord(c) - ord('a')
    if len(l[x]) == 0:
        print(-1)
        exit()
    i = bisect_left(l[x], now)
    now = l[x][i] + 1

    if now >= n:
        now -= n
        shukai += 1


print(shukai * n + now)

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
l = [[]for i in range(26)]

for i, c in enumerate(s * 2):
    l[ord(c) - ord('a')].append(i)


from bisect import *

shukai = 0
now = 0

t = input()
for c in t:
    x = ord(c) - ord('a')
    if len(l[x]) == 0:
        print(-1)
        exit()
    i = bisect(l[x], now)
    now = l[x][i] + 1
    if now >= n:
        now -= n
        shukai += 1


print(shukai * n + now)
Problem p03061 (python)

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

from fractions import gcd

tl = [a[0]]
for i in range(1, n):
    tl.append(gcd(tl[i - 1], a[i]))

tr = [a[n - 1]]
for i in range(1, n):
    tr.append(gcd(tr[i - 1], a[n - 1 - i]))
tr.reverse()

ans = 1
for i in range(n):
    tmp = 1
    if i == 0: tmp = tr[i + 1]
    elif i == n - 1: tmp = tl[i - 1]
    else: tmp = gcd(tl[i - 1], tr[i + 1])
    ans = max(ans, tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
from fractions import gcd
from functools import reduce
l = [(hoge.append(gcd(hoge[i-1], a[i])), hoge)[1] for hoge in [[a[0]]] for i in range(1, n)][0]
r = reversed([(hoge.append(gcd(hoge[i-1], a[n-i-i])), hoge)[1] for hoge in [[a[0]]]for i in range(1, n)][0])
print (reduce(lambda x,y:max(x,y),[gcd(l[i-1]if 0<i else r[i+1],r[i+1] if i<n-1 else l[i-1])for i in range(n)]))

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

from fractions import gcd

tl = [a[0]]
for i in range(1, n):
    tl.append(gcd(tl[i - 1], a[i]))

tr = [a[n - 1]]
for i in range(1, n):
    tr.append(gcd(tr[i - 1], a[n - 1 - i]))
tr.reverse()

ans = 1
for i in range(n):
    tmp = 1
    l = tl[i - 1] if 0 < i else tr[i + 1]
    r = tr[i + 1] if i < n - 1 else tl[i - 1]
    ans = max(gcd(l,r))
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a.sort()
if n == 2:
    print(a[1])
else:
    dif = set()
    for i in range(n - 1):
        dif.append(a[i - 1] - a[i])
    d = list(dif)
    d.sort()
    d.reverse()
    f=False
    for i in range(len(d)):
        if d[i] == 0:
            break
        ok = True
        flag = False
        for j in range(n):
            if a[j] % d[i] != 0:
                if flag:
                    break
                else:
                    ok=False
        if ok:
            f=True
            print(i)
            break
    if not f:
        print(1)
Problem p03111 (python)

Fixed submission:
N, A, B, C = map(int, input().split())
l = []
for i in range(N):
    l.append(int(input()))
ans = 100000000


def rec(a, b, c, d):
    if d == N:
        if a[1] > 0 and b[1] > 0 and c[1] > 0:
            global ans
            ans = min(
                ans,
                abs(
                    a[0] - A) + abs(b[0] - B) + abs(c[0] - C)
                + 10 * (a[1] + b[1] + c[1] - 3)
            )
        return
    rec((a[0] + l[d], a[1] + 1), b, c, d + 1)
    rec(a, (b[0] + l[d], b[1] + 1), c, d + 1)
    rec(a, b, (c[0] + l[d], c[1] + 1), d + 1)
    rec(a, b, c, d + 1)


rec((0, 0), (0, 0), (0, 0), 0)
print(ans)

Buggy submission (verdict: Runtime Error):
8 1000 800 100
300
333
400
444
500
555
600
666
Problem p03244 (python)

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

vv = [[], []]
for i in range(n):
    vv[i % 2].append(v[i])

import collections
items0 = sorted(collections.Counter(vv[0]).items(), key=lambda x: -x[1])
items1 = sorted(collections.Counter(vv[1]).items(), key=lambda x: -x[1])
key0 = [x[0] for x in items0]
key1 = [x[0] for x in items1]
val0 = [x[1] for x in items0]
val1 = [x[1] for x in items1]

ans = n - val0[0] - val1[0]

if key0[0] == key1[0]:
    tmp0=tmp1=1000000000000000
    if len(items0) > 1:
        tmp0 = n - val0[1] - val1[0]
    if len(items1) > 1:
        tmp1 = n - val0[0] - val1[1]
    ans = min(tmp0, tmp1)
    if len(items0) == 1 and len(items1) == 1:
        ans=n//2
print(ans)

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

vv = [[], []]
for i in range(n):
    vv[i % 2].append(v[i])

import collections
items0 = sorted(collections.Counter(vv[0]).items(), key=lambda x: -x[1])
items1 = sorted(collections.Counter(vv[1]).items(), key=lambda x: -x[1])
key0 = [x[0] for x in items0]
key1 = [x[0] for x in items1]
val0 = [x[1] for x in items0]
val1 = [x[1] for x in items1]

if key0[0] == key1[0]:
    if len(items0) == 1:
        print(n//2)
    else:
        print(min(n - val0[0] - val1[1], min(n - val0[1] - val1[0])))
else:
    print(n - val0[0] - val1[0])

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

vv = [[], []]
for i in range(n):
    vv[i % 2].append(v[i])

import collections
items0 = sorted(collections.Counter(vv[0]).items(), key=lambda x: -x[1])
items1 = sorted(collections.Counter(vv[1]).items(), key=lambda x: -x[1])
key0 = [x[0] for x in items0]
key1 = [x[0] for x in items1]
val0 = [x[1] for x in items0]
val1 = [x[1] for x in items1]

if key0[0] = ! key1[0]:
    if len(items0) == 1:
        print(n//2)
    else:
        print(min(n - val0[0] - val1[1], min(n - val0[1] - val1[0])))
else key0[0] != key1[0]:
    print(n - val0[0] - val1[0])
Problem p03309 (python)

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

aa = [a[i] - i-1 for i in range(n)]
aa.sort()


def f(b):
    return sum([abs(a-b)for a in aa])

print(f(aa[n//2]))

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

aa = [a[i] - i for i in range(n)]
aa.sort()

print(min(aa[n//2]))
Problem p03436 (python)

Fixed submission:
H, W = map(int, input().split())

s = ['#' * (W + 2)] + ['#' + input() + '#' for i in range(H)] + ['#' * (W + 2)]

# m : そこにたどり着くために必要な白マスの数
m = [[-1 for x in range(W+2)] for y in range(H+2)]
m[1][1] = 1


from collections import deque
qx = deque([1])
qy = deque([1])

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]


while len(qx) > 0:
    x, y = qx.popleft(), qy.popleft()
    for d in range(4):
        nx, ny = x + dx[d], y + dy[d]
        # 訪れたことがあるなら調べない
        if m[ny][nx] != -1: continue

        if s[ny][nx] == '.':
            qx.append(nx), qy.append(ny)
            m[ny][nx] = m[y][x] + 1

if m[H][W] == -1:
    print(-1)

else:
    print(sum([c.count('.') for c in s]) - m[H][W])

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())

s = ['#' * (W + 2)] + ['#' + input() + '#' for i in range(H)] + ['#' * (W + 2)]

# m : そこにたどり着くために必要な白マスの数
m = [[-1 for x in range(W+2)] for y in range(H+2)]
m[1][1] = 1


from collections import deque
qx = deque([1])
qy = deque([1])

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]


while len(qx) > 0:
    x, y = qx.popleft(), qy.popleft()
    for d in range(4):
        nx, ny = x + dx[d], y + dy[d]

        # 訪れたことがあるなら調べない
        if m[nx][ny] != -1: continue

        if s[ny][nx] == '.':
            qx.append(nx), qy.append(ny)
            m[ny][nx] = m[y][x] + 1

if m[H][W] == -1:
    print(-1)

else:
    print(sum([c.count('.') for c in s]) - m[H][W])