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

Fixed submission:
S = input()
cnt = 0
S = list(S)
S_t = S[0]
S.pop(0)
S_b = S[-1]
S.pop(-1)
for i in range(len(S)):
    cnt += 1

print(S_t + str(cnt) + S_b)

Buggy submission (verdict: Runtime Error):
S = input()
cnt = 0
S = list(S)
S_t = S[0]
S.pop(0)
S_b = S[-1]
S.pop(-1)
for i in range(S):
    cnt += 1

print(S_t + cnt + S_b)
Problem p03693 (python)

Fixed submission:
r,g,b = map(str, input().split())
num = r + g + b
if int(num)%4 == 0:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
r,g,b = map(input().split())
num = r + g + b
if int(num)%4 == 0:
    print('YES')
else:
    print('NO')
Problem p03697 (python)

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

if A + B >= 10:
    print('error')
else:
    print(A + B)

Buggy submission (verdict: Runtime Error):
A,B = map(input().split())

if A + B >= 10:
    print('error')
else:
    print(A + B)
Problem p03711 (python)

Fixed submission:
x,y = map(int,input().split())
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]

if x in a and y in a:
    print("Yes")
    exit()
if x in b and y in b:
    print("Yes")
    exit()
if x in c and y in c:
    print("Yes")
    exit()
else:
    print("No")

Buggy submission (verdict: Runtime Error):
x,y = map(int,input())
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]

if x in a and y in a:
    print("Yes")
if x in b and y in b:
    print("Yes")
if x in c and y in c:
    print("Yes")
else:
    print("No")
Problem p03860 (python)

Fixed submission:
a, b, c = map(str, input().split())

print("A" + b[:1] + "C")

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
c = input()

print(a[:1] + b[:1] + c[:1])

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
print(a[:1] + b[:1] + c[:1])

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
print(a + b[:1] + c)
Problem p03943 (python)

Fixed submission:
a, b, c = map(int, input().split())

if a + b == c:
    print('Yes')
elif b + c == a:
    print('Yes')
elif a + c == b:
    print('Yes')
else: 
    print('No')

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

if a + b == c:
    print('Yes')
    elif b + c == a:
        print('Yes')
    elif a + c == b:
        print('Yes')
    else: 
        print('No')
Problem p03962 (python)

Fixed submission:
a, b, c = map(int, input().split())

if a == b and a == c:
    print(1)
elif a == b or a == c or b == c:
    print(2)
else:
    print(3)

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, (input()))

if a == b and a == c:
    print(1)
elif a == b or a == c or b == c:
    print(2)
else:
    print(3)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())

if a == b and a == c:
    print(1)
elif a == b or a == c or b == c:
    print(2)
else:
    print(3)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())

if a == b and b == c:
    print(1)
elif a == b or b == c or a == c:
    print(2)
else:
    print(3)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())

if a == b and b == c:
    print(1)
elif a == b or b == c or a == c:
    print(2)
else:
    print(3)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())

if a == b == c:
    print(1)
elif a == b or b == c or a == c:
    print(2)
else:
    print(3)

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
c = input()

if a == b == c:
    print(1)
elif a == b or b == c or a == c:
    print(2)
else:
    print(3)

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
c = input()

count = 3

if a == b:
    count -= 1
if b == c:
    count -= 1
if a == c:
    count -= 1

print(count)
Problem p04011 (python)

Fixed submission:
all_days=int(input())
days1=int(input())
sp_p=int(input())
n_p=int(input())
ans = 0

if all_days <= days1:
    ans = sp_p * all_days
else:
    ans = days1 * sp_p + (all_days-days1) * n_p

print(ans)

Buggy submission (verdict: Runtime Error):
n=int(inpyt())
k=int(inpyt())
sp_p=int(inpyt())
n_p=int(inpyt())
sum = 0

for i in k:
    sum += sp_p

for j in n-k:
    sum += n_p

print(sum)

Buggy submission (verdict: Runtime Error):
n, k, sp_p, n_p = map(int, input().split())
sum = 0

for i in k:
    sum += sp_p

for j in n-k:
    sum += n_p

print(sum)

Buggy submission (verdict: Runtime Error):
n, k, sp_p, n_p = map(int, input().split())
sum = 0

for i in k+1:
    sum += sp_p

for j in n-k+1:
    sum += n_p

print(sum)
Problem p04012 (python)

Fixed submission:
w = input()
flg = True
for i in list("abcdefghijklmnopqrstuvwxyz"):
    if w.count(i) % 2 != 0:
        flg = False

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

Buggy submission (verdict: Runtime Error):
w = input()
flg = True
for i in list("abcdefghijklmnopqrstuvwxyz"):
    if w.count(w[i]) % 2 != 0:
        flg = False

if flg:
    print('Yes')
else:
    print('No')
Problem p04029 (python)

Fixed submission:
i = int(input())
sum = 0
for i in range(i+1):
    sum += i
print(sum)

Buggy submission (verdict: Runtime Error):
a = int(input())
sum = 0
for i in range(i+1):
    sum += i
print(sum)

Buggy submission (verdict: Runtime Error):
a = input()
sum = 0
for a in range(a):
    sum += a
print(sum)
Problem p04030 (python)

Fixed submission:
s = input()
ans = []

for i in range(len(s)):
    if s[i] == '0':
        ans.append('0')
    if s[i] == '1':
        ans.append('1')
    if s[i] == 'B':
        if len(ans) != 0:
            ans.pop(-1)

print(''.join(ans))

Buggy submission (verdict: Runtime Error):
s = input()
ans = []

for i in range(len(s)):
    if s[i] == '0':
        ans.append('0')
    if s[i] == '1':
        ans.append('1')
    if s[i] == 'B':
        ans.pop(-1)

print(''.join(ans))

Buggy submission (verdict: Runtime Error):
s = input()
ans = []

for i in range(len(s)):
    if s[i] == '0':
        ans.append('0')
    if s[i] == '1':
        ans.append('1')
    if s[i] == 'B':
        if len(s) != 0:
            ans.pop(-1)

print(''.join(ans))
Problem p04044 (python)

Fixed submission:
N,L = map(int, input().split())
S = [input() for _ in range(N)]
S = sorted(S)
string = ''

for i in range(N):
    string += S[i]

print(string)

Buggy submission (verdict: Runtime Error):
N,L = map(int, input().split())
S = [i for i in input()]
S = sorted(S)
arr = []

for i in range(N):
    arr.append(S[i])

print(''.join(arr))
Problem p02922 (python)

Fixed submission:
def main():
    A, B = [int(x) for x in input().split()]
    if B == 1:
        print(0)
        return
    count = 1
    B -= A
    while B > 0:
        B -= (A - 1)
        count += 1
    print (count)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    A, B = [int(x) for x in input().split()]
    count = 1
    B -= A
    while B > 0:
        B -= (A - 1)
        count += 1
    print (count)

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

Fixed submission:
a, b = map(int, input().split())
if a * b % 2 == 0:
  print("Even")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a * b % 2 == 0:
  print(Even)
else:
  print(Odd)
Problem p03845 (python)

Fixed submission:
n = int(input())
time_list = list(map(int, input().split()))
m = int(input())
problem_list = list(list(map(int, input().split())) for _ in range(m))
for i in problem_list:
  print(sum(time_list) - time_list[i[0]-1] + i[1])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
time_list = [map(int, input().split()) for _ in range(n)]
m = int(input())
problem_list = [map(int, input().split()) for _ in range(m)]
for i in problem_list:
  time_list[i[0]-1] = i[1]
  print(sum(time_list))
Problem p03962 (python)

Fixed submission:
a, b, c = map(int, input().split())
print(len(set([a, b, c])))

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
print(len(set(a, b, c)))
Problem p03163 (python)

Fixed submission:
n,w = map(int, input().split())
high = [0] * (w + 1)
for i in range(n):
    weight, value = map(int, input().split())
    if weight <= w:
        renewal = high[:weight]
        renewal += [max([j+value, k]) for j,k in zip(high[:w-weight+1], high[weight:])]
        high = renewal
print(high[w])

Buggy submission (verdict: Runtime Error):
import numpy as np
n,w = map(int, input().split())
high = np.array([[0]*(w+1)]*(n+1),np.int)
for i in range(1,n+1):
    weight, value = map(int, input().split())
    for j in range(w+1):
        if j < weight:
            high[i][j] = high[i-1][j]
        else:
            high[i][j] = max([high[i-1][j-weight]+value, high[i-1][j]])
print(high[n][w])
Problem p02713 (python)

Fixed submission:
import math
K=int(input())
k=K+1
ans=0
for a in range(1,k):
    for b in range(a,k):
        for c in range(b,k):
            m=math.gcd(a,b)
            o=math.gcd(m,c)
            if a==b and b==c:
                n=o
            elif a==b or b==c:
                n=o*3
            else:
                n=o*6
                
            ans+=n

print(ans)

Buggy submission (verdict: Runtime Error):
K=int(input())
ans=0
for a in range(1,K):
    for b in range(1,K):
        for c in range(1,K):
            n=math.gcd(a,b,c)
            ans=ans+n

print(ans)

Buggy submission (verdict: Runtime Error):
import math
K=int(input())
ans=0
for a in range(1,K):
    for b in range(1,K):
        for c in range(1,K):
            n=math.gcd(a,b,c)
            ans=ans+n

print(ans)
Problem p02717 (python)

Fixed submission:
X,Y,Z=map(int,input().split())
X,Y=Y,X
X,Z=Z,X
print(X,Y,Z)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
t=N%K
print(min(t,K-t))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
a=list(map(int,input().split()))
SUM=sum(a)
ninnki=SUM/(4*M)
count=0

for i in a:
    if i>=ninnki:
        count+=1
        
if count>=M:
    print("Yes")
else:
    print("No")
Problem p02719 (python)

Fixed submission:
N,K=map(int,input().split())
t=N%K
print(min(t,K-t))

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
while (N-K)>=0:
    N=N-K

if N>=abs(N-K):
    print(int(abs(N-K)))
else:
    print(int(N))
Problem p03493 (python)

Fixed submission:
s=list(input())
count=0
if s[0]=="1":
    count+=1
if s[1]=="1":
    count+=1
if s[2]=="1":
    count+=1
print(count)

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
S=[a,b,c]
print(S.count(1))

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
S=[a,b,c]
print(S.count(1))

Buggy submission (verdict: Runtime Error):
import math
a,b,c=map(int,input().split())
S=[a,b,c]
print(S.count(1))
Problem p02684 (python)

Fixed submission:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
visited = {'1': 0}
route = [1]
next_id = 0
count = 0
while count < K:
    count += 1
    if A[next_id] in visited.keys():
        route = route[visited[A[next_id]]:]
        K -= count
        break
    visited[A[next_id]] = count
    route.append(A[next_id])
    next_id = A[next_id] - 1
print(route[K % len(route)])

Buggy submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
visited = {'1': 0}
route = [1]
next_id = 0
count = 0
while count < K:
    count += 1
    if A[next_id] in visited.keys():
        break
    visited[A[next_id]] = count
    route.append(A[next_id])
    next_id = A[next_id] - 1
roop = route[visited[A[next_id]]:]
print(roop[(K - count) % len(roop)])
Problem p02909 (python)

Fixed submission:
s = input()
if s == 'Sunny':
    ans = 'Cloudy'
elif s == 'Cloudy':
    ans = 'Rainy'
else:
    ans = 'Sunny'
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
if s = 'Sunny':
    ans = 'Cloudy'
elif s = 'Cloudy':
    ans = 'Rainy'
else:
    ans = 'Sunny'
print(ans)
Problem p02947 (python)

Fixed submission:
N = int(input())
ans = 0
S = {}
for i in range(N):
    s = ''.join(sorted(input()))
    if s not in S.keys():
        S[s] = 0
        continue
    S[s] += 1
    ans += S[s]
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = 0
S = {}
for i in range(N):
    s = ''.join(sorted(input()))
    if s not in S.keys():
        S[s] = 0
        continue
    print(S)
    S[s] += 1
    ans += S[s]
print(ans)
Problem p02971 (python)

Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]
m = max(A)
ans = list(map(str, [m for _ in range(N)]))
if A.count(m) > 1:
    print('\n'.join(ans))
    exit()
AA = A[:]
AA.remove(m)
mm = max(AA)
for n in range(N):
    if A[n] == m:
        ans[n] = str(mm)
        break
print('\n'.join(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for _ in range(N)]
m = max(A)
ans = [m for _ in range(N)]
if A.count(M) > 1:
    print('\n'.join(ans))
    exit()
AA = A[:]
AA.remove(M)
mm = max(AA)
for n in range(N):
    if A[n] == m:
        ans[n] = mm
        break
print('\n'.join(ans))
Problem p02996 (python)

Fixed submission:
N = int(input())
L = [tuple(map(int, input().split())) for _ in range(N)]
L.sort(key=lambda x: x[1])
work = 0
for n in range(N):
  work += L[n][0]
  if work > L[n][1]:
    print('No')
    exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
N = int(input())
L = [tuple(map(int, input().split())) for _ in range(N)]
L.sort(key=lambda x: x[1])
work = 0
for n in range(N):
  work += L[0][n]
  if work > L[1][n]:
    print('No')
    exit()
print('Yes')
Problem p02787 (python)

Fixed submission:
# coding: utf-8
# Your code here!

import bisect

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

ab = []
max_a = 0
for _ in range(n):
    ab.append(list(map(int, list(input().split()))))
    max_a = max(max_a, ab[-1][0])

dp = [int(1e9)] * int(1e6)
checked = [False] * int(1e6)
dp[0] = 0

sorted_list = [0]
while len(sorted_list) > 0:
    v = sorted_list.pop(0)
    
    if v > h:
        break
    
    for i in range(n):
        if checked[v + ab[i][0]] == False:
            bisect.insort_right(sorted_list, v + ab[i][0])
            checked[v + ab[i][0]] = True
        dp[v + ab[i][0]] = min(dp[v + ab[i][0]], dp[v] + ab[i][1])
    
print(min(dp[v-1:]))

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

import numpy as np
import bisect

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

ab = []
for _ in range(n):
    ab.append(list(map(int, list(input().split()))))
ab = np.array(ab)
max_a = max(ab[:,0])

dp = [int(1e9)] * int(1e6)
checked = [False] * int(1e6)
dp[0] = 0

sorted_list = [0]
while len(sorted_list) > 0:
    v = sorted_list.pop(0)
    
    if v > h:
        break
    
    for i in range(n):
        if checked[v + ab[i, 0]] == False:
            bisect.insort_right(sorted_list, v + ab[i, 0])
            checked[v + ab[i, 0]] = True
        dp[v + ab[i,0]] = min(dp[v + ab[i,0]], dp[v] + ab[i,1])
    
print(min(dp[v-1:]))
Problem p03032 (python)

Fixed submission:
# coding: utf-8
# Your code here!

N, K = map(int, input().rstrip().split(' '))
X = [0] + list(map(int, input().rstrip().split(' ')))

sorted_left_X = []
sorted_right_X = []
sorted_remove_X = []
for i in range(N+1):
    sorted_left_X.append(sorted([x for x in X[:i] if x < 0]))
    sorted_right_X.append(sorted([x for x in X[::-1][:i] if x < 0]))
    
    sorted_remove_X.append(sorted([x for x in X[:i] if x < 0] + [x for x in X[::-1][:i] if x < 0]))

cum_X = []
cum = 0
for x in X:
    cum += x
    cum_X.append(cum)

if K > N:
    temp = sorted([x for x in X if x < 0])
    print(cum_X[-1] - sum(temp[:min(len(temp), K)]))
else:
    max_count = 0
    for k in range(1,K+1):
        for i in range(k+1):
            temp = sorted(sorted_left_X[i] + sorted_right_X[k-i])
            temp2 = sum(temp[:min(len(temp), K-k)])
            max_count = max(cum_X[i] - cum_X[0] + cum_X[-1] - cum_X[i+N-k] - temp2, max_count)

    print(max_count)

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

N, K = map(int, input().rstrip().split(' '))
X = [0] + list(map(int, input().rstrip().split(' ')))

sorted_left_X = []
sorted_right_X = []
sorted_remove_X = []
for i in range(N+1):
    sorted_left_X.append(sorted([x for x in X[:i] if x < 0]))
    sorted_right_X.append(sorted([x for x in X[::-1][:i] if x < 0]))
    
    sorted_remove_X.append(sorted([x for x in X[:i] if x < 0] + [x for x in X[::-1][:i] if x < 0]))

cum_X = []
cum = 0
for x in X:
    cum += x
    cum_X.append(cum)

max_count = 0
for k in range(1,K+1):
    for i in range(k+1):
        num_left_removed = i
        num_right_removed = k - i
        temp = sorted(sorted_left_X[i] + sorted_right_X[k-i])
        temp2 = sum(temp[:min(len(temp), K-k)])
        max_count = max(cum_X[i] - cum_X[0] + cum_X[-1] - cum_X[i+N-k] - temp2, max_count)

print(max_count)
Problem p03043 (python)

Fixed submission:
# coding: utf-8
# Your code here!

import numpy as np

N, K = map(int, input().rstrip().split(' '))

x = np.arange(N) + 1
c = np.ceil(np.log2(K / x)).astype(int)
c = c[np.where(c > 0)]
if len(c) == 0:
    print(1)
else:
    cumprod = np.cumprod([0.5] * int(c[0]+1))
    print(2 * np.sum(cumprod[c]) / N + (N - len(c)) / N)

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

import numpy as np

N, K = map(int, input().rstrip().split(' '))

x = np.arange(N) + 1
c = np.ceil(np.log2(K / x)).astype(int)
c = c[np.where(c > 0)]
cumprod = np.cumprod([0.5] * int(c[0]+1))
print(2 * np.sum(cumprod[c]) / N + (N - len(c)) / N)
Problem p03166 (python)

Fixed submission:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(int(1e5))

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

g = [[] for _ in range(N)]
for _ in range(M):
    x, y = map(int, input().rstrip().split(' '))
    g[y-1].append(x-1)
    
dp = [-1] * N
def rec(v):
    if dp[v] != -1:
        return dp[v]
        
    count = 0
    for x in g[v]:
        count = max(count, rec(x)+1)
        
    dp[v] = count
    
    return count
   
for i in range(N):
    rec(i)

print(max(dp))

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

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

g = [[] for _ in range(N)]
for _ in range(M):
    x, y = map(int, input().rstrip().split(' '))
    g[y-1].append(x-1)
    
dp = [-1] * N
def rec(v):
    if dp[v] != -1:
        return dp[v]
        
    count = 0
    for x in g[v]:
        count = max(count, rec(x)+1)
        
    dp[v] = count
    
    return count
   
for i in range(N):
    rec(i)

print(max(dp))
Problem p03167 (python)

Fixed submission:
# coding: utf-8
# Your code here!

H, W = map(int, input().rstrip().split(' '))

field = []
for _ in range(H):
    temp_field = []
    for s in input():
        temp_field.append(0 if s == '.' else 1)
    field.append(temp_field)
    
dp = [[0] * (W + 1) for _ in range(H+1)]
dp[0][1] = 1

for h in range(1, H+1):
    for w in range(1, W+1):
        if field[h-1][w-1] == 0:
            dp[h][w] = dp[h-1][w] + dp[h][w-1]
            
print(dp[-1][-1] % (1000000007))

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

H, W = map(int, input().rstrip().split(' '))

field = []
for _ in range(H):
    temp_field = []
    for s in input():
        temp_field.append(0 if s == '.' else 1)
    field.append(temp_field)
    
dp = [[0] * (W + 1) for _ in range(H+1)]
dp[0][1] = 1

for h in range(1, H+1):
    for w in range(1, W+1):
        if field[h-1][w-1] == 0:
            dp[h][w] = dp[h-1][w] + dp[h][w-1]
            
#print(int(dp[-1][-1] % (1e9 + 7)))
print((dp[-1][-1] % (1_000_000_007)))

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

H, W = map(int, input().rstrip().split(' '))

field = []
for _ in range(H):
    temp_field = []
    for s in input():
        temp_field.append(0 if s == '.' else 1)
    field.append(temp_field)
    
dp = [[0] * (W + 1) for _ in range(H+1)]
dp[0][1] = 1

for h in range(1, H+1):
    for w in range(1, W+1):
        if field[h-1][w-1] == 0:
            dp[h][w] = dp[h-1][w] + dp[h][w-1]
            
print(int(dp[-1][-1] % (1e9 + 7)))
Problem p03244 (python)

Fixed submission:

N = int(input())
seq = list(map(int, input().rstrip().split(' ')))

odd = [[0, i] for i in range(int(1e5 + 1))]
even = [[0, i] for i in range(int(1e5 + 1))]

for i in range(0, N, 2):
    even[seq[i]][0] += 1
    
for i in range(1, N, 2):
    odd[seq[i]][0] += 1

sorted_even = sorted(even, key=lambda x: x[0])[::-1]
sorted_odd = sorted(odd, key=lambda x: x[0])[::-1]

if sorted_even[0][1] == sorted_odd[0][1]:
    if sorted_even[0][0] + sorted_odd[1][0] > sorted_even[1][0] + sorted_odd[0][0]:
        max_even = sorted_even[0][0]
        max_odd = sorted_odd[1][0]
    else:
        max_even = sorted_even[1][0]
        max_odd = sorted_odd[0][0]
else:
    max_even = sorted_even[0][0]
    max_odd = sorted_odd[0][0]
 
count = 0
count += N // 2 - max_even
count += N // 2 - max_odd

print(count)

Buggy submission (verdict: Runtime Error):
import sys
 
N = int(input())
seq = list(map(int, input().rstrip().split(' ')))

odd = [0] * int(1e5)
even = [0] * int(1e5)

for i in range(0, N, 2):
    even[seq[i]] += 1
    
for i in range(1, N, 2):
    odd[seq[i]] += 1

type_number = 0
for i in range(0, int(1e5)):
    if odd[i] + even[i] > 0:
        type_number += 1

max_even = max(even)
max_odd = max(odd)

count = 0
count += N // 2 - max_even
count += N // 2 - max_odd

if type_number == 1:
    print(N // 2)
else:
    print(count)
Problem p03274 (python)

Fixed submission:
# coding: utf-8
# Your code here!

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

min_cost = int(1e10)
for i in range(K, N+1):
    min_cost = min(min_cost, X[i-1] - X[i-K] + min(abs(X[i-1]), abs(X[i-K])))
    
print(min_cost)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import numpy as np
 
N, K = map(int, input().rstrip().split(' '))
X = np.array(list(map(int, input().rstrip().split(' '))))

min_cost = int(1e10)
for i in range(K, N+1):
    min_cost = min(min_cost, X[i-1] - X[i-K] + min(abs(X[i-1]), abs(X[i-K])))
    
print(min_cost)

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

import bisect
from collections import defaultdict
 
N, K = map(int, input().rstrip().split(' '))
X = sorted(list(map(int, input().rstrip().split(' '))))

i = bisect.bisect_left(X, 0)
X.insert(i, 0)

memo = defaultdict(lambda: defaultdict(lambda: -1))
 
def recursive(current_k, cost, i, left_i, right_i):
    if K == current_k:
        return cost
    if memo[current_k][i] != -1:
        return memo[current_k][i]
       
    left_cost = 1e10 
    if left_i >= 0:
        left_cost = recursive(current_k + 1, cost + X[i] - X[left_i], left_i, left_i - 1, right_i)
        
    right_cost = 1e10
    if right_i <= N:
        right_cost = recursive(current_k + 1, cost + X[right_i] - X[i], right_i, left_i, right_i + 1)
        
    min_cost = min(left_cost, right_cost)
    
    memo[current_k][i] = min_cost
    
    return min_cost
    
print(recursive(0, 0, i, i - 1, i + 1))

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

N, K = map(int, input().rstrip().split(' '))
X = sorted(list(map(int, input().rstrip().split(' '))) + [0])

#N = int(1e8)
#K = int(3)

#X = list(range(N))

#print(X)

i = 0
while True:
    if X[i] == 0:
        break
    i += 1

memo = [[-1] * (N + 1) for _ in range(K)]

def recursive(current_k, cost, i, left_i, right_i):
    if K == current_k:
        return cost
    if memo[current_k][i] != -1:
        return memo[current_k][i]
        
    left_cost = 1e10 
    right_cost = 1e10
    if left_i >= 0 and right_i <= N:
        if left_i >= 0:
            left_cost = recursive(current_k + 1, cost + X[i] - X[left_i], left_i, left_i - 1, right_i)
        if right_i <= N:
            right_cost = recursive(current_k + 1, cost + X[right_i] - X[i], right_i, left_i, right_i + 1)
    elif left_i >= 0:
        left_cost = cost + X[i] - X[left_i - (K - current_k)]
    else:
        right_cost = cost + X[right_i + (K - current_k)] - X[i]
    
    min_cost = min(left_cost, right_cost)
    
    memo[current_k][i] = min_cost
    
    return min_cost
    
print(recursive(0, 0, i, i - 1, i + 1))