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

Fixed submission:
import heapq
N,K = map(int, input().split())
*V, = map(int, input().split())
#N, K = 6, 4
#V = [-10, 8, 2, 1, 2, 6]
motimono = []
ans = []

if K >= N: # 操作回数のほうが大きいなら、全部取り出してから何個戻すかを考える
    K -= N
    heapq.heapify(V)
    ans.append(sum(V))
    for i in range(K):
        if len(V)>0:
            heapq.heappop(V)
        ans.append(sum(V))
    print(max(ans))

else:
    V *= 2 # 前後からの取り出しを楽にするためにこうしておく
    #print(V)
    for j in range(1,K+1): # 取り出す個数
        for i in range(N-j, N+1): # 何番目から取り出すか
            motimono = V[i:i+j]
            #print(str(j), str(i), motimono)
            ans.append(sum(motimono))
            #print(ans)
            heapq.heapify(motimono)
            for i in range(K-j): # 戻す個数
                if len(motimono)>0:
                    heapq.heappop(motimono)
                ans.append(sum(motimono))
    print(max(ans))

Buggy submission (verdict: Runtime Error):
import heapq
N,K = map(int, input().split())
*V, = map(int, input().split())
#N, K = 6, 4
#V = [-10, 8, 2, 1, 2, 6]
motimono = []
ans = []

if K >= N: # 操作回数のほうが大きいなら、全部取り出してから何個戻すかを考える
    K -= N
    heapq.heapify(V)
    ans.append(sum(V))
    for i in range(K):
        if len(V)>0:
            heapq.heappop(V)
        ans.append(sum(V))
    print(max(ans))

else:
    V *= 2 # 前後からの取り出しを楽にするためにこうしておく
    #print(V)
    for j in range(1,K+1): # 取り出す個数
        for i in range(N-j, N+1): # 何番目から取り出すか
            motimono = V[i:i+j]
            #print(str(j), str(i), motimono)
            ans.append(sum(motimono))
            #print(ans)
            heapify(motimono)
            for i in range(K-j): # 戻す個数
                if len(motimono)>0:
                    heappop(motimono)
                ans.append(sum(motimono))
    print(max(ans))

Buggy submission (verdict: Runtime Error):
import heapq
#N,K = map(int, input().split())
#*V, = map(int, input().split())
N, K = 6, 4
V = [-10, 8, 2, 1, 2, 6]
motimono = []
ans = []

if K >= N: # 操作回数のほうが大きいなら、全部取り出してから何個戻すかを考える
    K -= N
    heapq.heapify(V)
    ans.append(sum(V))
    for i in range(K):
        if len(V)>0:
            heapq.heappop(V)
        ans.append(sum(V))
    print(max(ans))

else:
    V *= 2 # 前後からの取り出しを楽にするためにこうしておく
    #print(V)
    for j in range(1,K+1): # 取り出す個数
        for i in range(N-j, N+1): # 何番目から取り出すか
            motimono = V[i:i+j]
            #print(str(j), str(i), motimono)
            ans.append(sum(motimono))
            #print(ans)
            heapify(motimono)
            for i in range(K-j): # 戻す個数
                if len(motimono)>0:
                    heappop(motimono)
                ans.append(sum(motimono))
    print(max(ans))
Problem p03048 (python)

Fixed submission:
R,G,B,N = map(int, input().split())
count = 0
for r in range(N // R + 1) :
    for g in range((N - r*R) // G + 1) :
        if (N - r*R - g*G) %B == 0 :
            count += 1
print(count)

Buggy submission (verdict: Runtime Error):

import itertools
R,G,B,N = map(int, input().split())
count = 0
Rc = [i * R for i in range(0, int(N / R) +1)]
Gc = [i * G for i in range(0, int(N / G) +1)]
#Bc = [i * B for i in range(0, int(N / B) +1)]
#print(Rc)
#print(Gc)
#print(Bc)
for r in Rc :
    if r == N :
        p#rint(r)
        count += 1
    else :
        for g in Gc :
            if r + g == N :
                #print(r, g)
                count += 1
            elif r + g > N :
                break
            else :
                if (N - r + g) > B and (N - r + g) % B == 0 :
                    #print(N, r,g)
                    count += 1
print(count)
Problem p03049 (python)

Fixed submission:
N = int(input())
S = [input() for i in range(N)]

# 'AB'の数を数える
cnt_ab = sum([s.count('AB') for s in S])

# L: 先頭が'B'、終わりが'A'の数を数える
cnt_b_a = sum([(s[0] == 'B') and (s[-1] == 'A') for s in S])

# M: 先頭が'B'、終わりが'A'じゃないの数を数える
cnt_b_na = sum([(s[0] == 'B') and (s[-1] != 'A') for s in S])

# N : 先頭が'B'じゃなく、終わりが'A'の数を数える
cnt_nb_a = sum([(s[0] != 'B') and (s[-1] == 'A') for s in S])

count = cnt_ab
if (cnt_b_a == 0): # MとNの数の小さい方の分だけ追加できる
    count += min(cnt_b_na, cnt_nb_a)
elif (cnt_b_na + cnt_nb_a == 0): # Lの個数 - 1個だけ追加できる
    count += (cnt_b_a - 1)
else:
    count += (cnt_b_a + min(cnt_b_na, cnt_nb_a))
print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = [input() for i in range(N)]

# 'AB'の数を数える
cnt_ab = sum([s.count('AB') for s in S])

# L: 先頭が'B'、終わりが'A'の数を数える
cnt_b_a = sum([(s[0] == 'B') and (s[-1] == 'A') for s in S])

# M: 先頭が'B'、終わりが'A'じゃないの数を数える
cnt_b_na = sum([(s[0] == 'B') and (s[-1] != 'A') for s in S])

# N : 先頭が'B'じゃなく、終わりが'A'の数を数える
cnt_nb_a = sum([(s[0] != 'B') and (s[-1] == 'A') for s in S])

count = cnt_ab
if (cnt_b_a == 0): # MとNの数の小さい方の分だけ追加できる
    ans += min(cnt_b_na, cnt_nb_a)
elif (cnt_b_na + cnt_nb_a == 0): # Lの個数 - 1個だけ追加できる
    ans += (cnt_b_a - 1)
else:
    ans += (cnt_b_a + min(cnt_b_na, cnt_nb_a))
print(ans)
Problem p03079 (python)

Fixed submission:
a, b, c = map(int, input().split())
if a == b and b == c :
    print("Yes")
else :
    print("No")

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
if a = b and b = c :
    print("Yes")
else :
    print("No")
Problem p02861 (python)

Fixed submission:
import math
import itertools
n = int(input())
lis = [list(map(int, input().split())) for i in range(n)]
dislis = []
for i in range(n):
    dislis.append([])
    for j in range(n):
        dislis[i].append(math.sqrt((lis[i][0]-lis[j][0])**2 + (lis[i][1]-lis[j][1])**2))

lenlis = []
cnt = 0
for v in itertools.permutations(range(n+1)[1:], n):
    cnt += 1
    lenlis.append([])
    for i in range(len(v)):
        if i != len(v)-2:
            lenlis[cnt-1].append(dislis[v[i-1]-1][v[i]-1])
anslis = []
cntcnt = 0
for i in lenlis:
    anslis.append(sum(lenlis[cntcnt]))
    cntcnt += 1
print(sum(anslis)/len(anslis))

Buggy submission (verdict: Runtime Error):
import numpy as np
import itertools
from statistics import mean
n = int(input())
lis = [list(map(int, input().split())) for i in range(n)]
dislis = []
for i in range(n):
    dislis.append([])
    for j in range(n):
        dislis[i].append(np.sqrt((lis[i][0]-lis[j][0])**2 + (lis[i][1]-lis[j][1])**2))

lenlis = []
cnt = 0
for v in itertools.permutations(range(n+1)[1:], n):
    cnt += 1
    lenlis.append([])
    for i in range(len(v)):
        if i != len(v)-2:
            lenlis[cnt-1].append(dislis[v[i-1]-1][v[i]-1])
anslis = []
cntcnt = 0
for i in lenlis:
    anslis.append(sum(lenlis[cntcnt]))
    cntcnt += 1
print(mean(anslis))

Buggy submission (verdict: Runtime Error):
import numpy as np
import itertools
from statistics import mean
n = int(input())
lis = [list(map(int, input().split())) for i in range(n)]
dislis = []
for i in range(n):
    dislis.append([])
    for j in range(n):
        dislis[i].append(np.sqrt((lis[i][0]-lis[j][0])**2 + (lis[i][1]-lis[j][1])**2))

lenlis = []
cnt = 0
for v in itertools.permutations(range(n+1)[1:], n):
    cnt += 1
    lenlis.append([])
    for i in range(len(v)):
        if i != len(v)-2:
            lenlis[cnt-1].append(dislis[v[i-1]-1][v[i]-1])
# for i in dislis:
#     print(i)
anslis = []
cntcnt = 0
for i in lenlis:
    anslis.append(sum(lenlis[cntcnt]))
    cntcnt += 1
print(mean(anslis))
Problem p02848 (python)

Fixed submission:
s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n = int(input())
input_s = input()
print(''.join([s[(s.index(c)+n) % 26] for c in input_s]))

Buggy submission (verdict: Runtime Error):
s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n = int(input())
input_s = input()
print(''.join([s[s.index(c)+n % 26] for c in input_s])
Problem p02969 (python)

Fixed submission:
n=int(input())
print(3*(n**2))

Buggy submission (verdict: Runtime Error):
# Python3 program to insert 
# an element into sorted list 
import bisect 

def insert(list, n): 
	bisect.insort(list, n) 
	return list



n=int(input())
l=[]
q=[]
w=[]
S=[]
D=[]
for i in range(0,n):
    o=int(input())
    l.append(o)
G=0;
for i in range(0,len(l)-1):
    if l[i] <= l[i+1]:
        G=1;
        break;
if G==0:
    print(len(l))
else:
    for i in range(0,len(l)):
        o=l[i]
        if i==0:
            q.append(o)
        else:
            V=-1;
            G=0;
            I=0;
            J=len(q)-1;
            while(I<=J):
                m=(I+J)//2;
                if q[m] < o:
                    V=m;
                    I=m+1;
                else:
                    if q[m]>=o:
                        J=m-1;
            if V==-1:
                q=insert(q,o);
            else:
                q[V]=o;
    print(len(q))
Problem p03844 (python)

Fixed submission:
p=input().rstrip().split(' ')
if p[1]=='+':
  print(int(p[0]) + int(p[2]))
else:
  print(int(p[0]) - int(p[2]))

Buggy submission (verdict: Runtime Error):
p=input().rstrip().split(' ')
if p[1]=='+':
  print(int(p[0]) + int(p[1]))
else:
  print(int(p[0]) + int(p[1]))
Problem p02974 (python)

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

MOD = 1000000007  # type: int

def solve(N: int, K: int):
    if K % 2 == 1:
        print(0)
        return
    dp = [[[0 for k in range(K+1)]
            for j in range(N+2)]
            for i in range(N+1)]
    dp[0][0][0] = 1
    for i, j, k in product(range(1, N+1), range(N+1), range(K+1)):
        prev_k = k - 2 * j
        if prev_k < 0:
            continue
        dp[i][j][k] += dp[i-1][j][prev_k]
        dp[i][j][k] += 2 * j * dp[i-1][j][prev_k]
        dp[i][j][k] += (j+1) * (j+1) * dp[i-1][j+1][prev_k]
        if j > 0: dp[i][j][k] += dp[i-1][j-1][prev_k]
        dp[i][j][k] %= MOD
    print(dp[N][0][K])

    return


# Generated by 1.1.4 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()
    n = int(next(tokens))  # type: int
    k = int(next(tokens))  # type: int
    solve(n, k)

if __name__ == '__main__':
    main()

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

MOD = 1000000007  # type: int

def solve(N: int, K: int):
    if K % 2 == 1:
        print(0)
        return
    dp = [[[0 for k in range(K+1)]
            for j in range(N+1)]
            for i in range(N+1)]
    dp[0][0][0] = 1
    for i, j, k in product(range(1, N+1), range(N+1), range(K+1)):
        prev_k = k - 2 * j
        if prev_k < 0:
            continue
        dp[i][j][k] += dp[i-1][j][prev_k]
        dp[i][j][k] += 2 * j * dp[i-1][j][prev_k]
        dp[i][j][k] += (j+1) * (j+1) * dp[i-1][j+1][prev_k]
        dp[i][j][k] += dp[i-1][j-1][prev_k]
        dp[i][j][k] %= MOD
    print(dp[N][0][K])

    return


# Generated by 1.1.4 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()
    n = int(next(tokens))  # type: int
    k = int(next(tokens))  # type: int
    solve(n, k)

if __name__ == '__main__':
    main()
Problem p02975 (python)

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

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, a: "List[int]"):
    A = defaultdict(lambda : 0)
    for x in a:
        A[x] += 1
    if len(A) == 1 and 0 in A:
        print(YES)
        return
    if N % 3 != 0:
        print(NO)
        return
    if len(A) == 2 and A[0] == N // 3:
        print(YES)
        return
    if len(A) != 3:
        print(NO)
        return
    L = list(A.keys())
    if L[0] ^ L[1] != L[2]:
        print(NO)
        return
    if A[L[0]] != A[L[1]] or A[L[0]] != A[L[2]]:
        print(NO)
        return
    print(YES)
    return


# Generated by 1.1.4 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()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

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

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, a: "List[int]"):
    A = defaultdict(lambda : 0)
    for x in a:
        A[x] += 1
    if len(A) == 1 and 0 in A:
        print(YES)
        return
    if N % 3 != 0:
        print(NO)
        return
    if len(A) == 2 and A[0] == N // 3:
        print(YES)
        return
    if len(A) > 3:
        print(NO)
        return
    L = list(A.keys())
    if L[0] ^ L[1] != L[2]:
        print(NO)
        return
    if A[L[0]] != A[L[1]] or A[L[0]] != A[L[2]]:
        print(NO)
        return
    print(YES)
    return


# Generated by 1.1.4 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()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()
Problem p02995 (python)

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

def solve(A: int, B: int, C: int, D: int):
    E = C * D // fractions.gcd(C, D)
    count_c = B // C - (A-1) // C
    count_d = B // D - (A-1) // D
    count_e = B // E - (A-1) // E
    print(B-A+1 - count_c - count_d + count_e)
    return


# Generated by 1.1.4 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()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)

if __name__ == '__main__':
    main()

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

def solve(A: int, B: int, C: int, D: int):
    E = C * D // math.gcd(C, D)
    count_c = B // C - (A-1) // C
    count_d = B // D - (A-1) // D
    count_e = B // E - (A-1) // E
    print(B-A+1 - count_c - count_d + count_e)
    return


# Generated by 1.1.4 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()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)

if __name__ == '__main__':
    main()
Problem p03014 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
import numpy as np


def solve(H: int, W: int, S: "List[List[str]]"):
    arr_s = np.array(S)
    arr_s = np.where(arr_s == ".", 1, 0)
    arr_v = np.zeros((H, W), dtype=int)
    arr_h = np.zeros((H, W), dtype=int)
    arr_v[0, :] = arr_s[0, :]
    arr_h[:, 0] = arr_s[:, 0]

    for i in range(H-1):
        arr_v[i+1, :] = (arr_v[i, :] + 1) * arr_s[i+1, :]
    
    for i in range(H-2, -1, -1):
        arr_v[i, :] = np.where(arr_v[i, :] > 0, np.maximum(arr_v[i+1, :], arr_v[i, :]), 0)

    for i in range(W-1):
        arr_h[:, i+1] = (arr_h[:, i] + 1) * arr_s[:, i+1]
    
    for i in range(W-2, -1, -1):
        arr_h[:, i] = np.where(arr_h[:, i] > 0, np.maximum(arr_h[:, i+1], arr_h[:, i]), 0)
    
    print(np.max(arr_v + arr_h) - 1)

    return


# Generated by 1.1.4 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()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [ [c for c in next(tokens)] for _ in range(H) ]  # type: "List[List[str]]"
    solve(H, W, S)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
import numpy as np


def solve(H: int, W: int, S: "List[List[str]]"):
    arr_s = np.array(S)
    arr_s = np.where(arr_s == ".", 1, 0)
    arr_v = np.zeros((H, W), dtype=int)
    arr_h = np.zeros((H, W), dtype=int)
    arr_v[0, :] = arr_s[0, :]
    arr_h[:, 0] = arr_s[:, 0]

    for i in range(H-1):
        arr_v[i+1, :] = (arr_v[i, :] + 1) * arr_s[i+1, :]
    
    for i in range(H-2, -1, -1):
        arr_v[i, :] = np.where(arr_v[i, :] > 0, np.maximum(arr_v[i+1, :], arr_v[i, :]), 0)

    for i in range(W-1):
        arr_h[:, i+1] = (arr_h[:, i] + 1) * arr_s[:, i+1]
    
    for i in range(W-2, -1, -1):
        arr_h[:, i] = np.where(arr_h[:, i] > 0, np.maximum(arr_h[:, i+1], arr_h[:, i]), 0)
    
    print(np.max(arr_v + arr_h) - 1)

    return


# Generated by 1.1.4 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()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [ [c for c in next(tokens)] for _ in range(H) ]  # type: "List[List[str]]"
    solve(H, W, S)

if __name__ == '__main__':
    main()
Problem p03078 (python)

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.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

kouho = set()
done = set()


def f(t):
    x, y, z = t
    if x >= X or y >= Y or z >= Z:
        return 0
    return A[x] + B[y] + C[z]


def main():
    start = (f((0, 0, 0)), (0, 0, 0))
    kouho.add(start)
    done.add(start)

    for k in range(K):
        d = max(kouho)
        kouho.remove(d)

        x, y, z = d[1]
        toadd = [(x, y, z+1), (x, y+1, z), (x+1, y, z)]
        for ta in toadd:
            t = (f(ta), ta)
            if t in done:
                continue
            kouho.add(t)
            done.add(t)

        print(d[0])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
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.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

kouho = set()
done = set()


def f(t):
    x, y, z = t
    return A[x] + B[y] + C[z]


def main():
    start = (f((0, 0, 0)), (0, 0, 0))
    kouho.add(start)
    done.add(start)

    for k in range(K):
        d = max(kouho)
        kouho.remove(d)

        x, y, z = d[1]
        toadd = [(x, y, z+1), (x, y+1, z), (x+1, y, z)]
        for ta in toadd:
            t = (f(ta), ta)
            if ta[0] == X:
                continue
            if ta[1] == Y:
                continue
            if ta[2] == Z:
                continue
            if t in done:
                continue
            kouho.add(t)

        print(d[0])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
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.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

kouho = set()
done = set()


def f(t):
    x, y, z = t
    return A[x] + B[y] + C[z]


def main():
    kouho.add([f(0, 0, 0), (0, 0, 0)])

    for k in range(K):
        d = max(kouho)
        kouho.remove(d)

        x, y, z = d[1]
        toadd = [(x, y, z+1), (x, y+1, z), (x+1, y, z)]
        for ta in toadd:
            if ta[0] == X:
                continue
            if ta[1] == Y:
                continue
            if ta[2] == Z:
                continue
            kouho.add([f(ta), ta])

        print(d[0])


if __name__ == '__main__':
    main()
Problem p03138 (python)

Fixed submission:
N, K = map(int, input().split())
A = [int(a) for a in input().split()]

n = 41

B = [0 for _ in range(n)]
result = [0 for _ in range(n)]

for a in A:
    for i in range(n):
        B[i] += (a >> i) & 1

#print(B)

result = 0
k_rest = K

for i in list(range(n))[::-1]:
    if B[i] * 2 < N and (k_rest >= (1 << i)):
        k_rest = k_rest - (1 << i)
        result += (1 << i) * (N - B[i])
    else:
        result += (1 << i) * B[i]

print(result)

Buggy submission (verdict: Runtime Error):
from math import log2

N, K = map(int, input().split())
A = [int(a) for a in input().split()]

if K == 0:
    n = 0
else:
    n = int(log2(K)) + 1


def f(X):
    return sum(map(lambda a: X ^ a, A))


B = [0 for _ in range(n)]
result = [0 for _ in range(n)]

for a in A:
    for i in range(n):
        B[i] += (a >> i) & 1

#print(B)

for i in range(n):
    if B[i] * 2 < N and (K > (1 << i)):
        result[i] = 1

#print(result)

x = eval('0b' + ''.join(map(str, result[::-1])))

#print(x)

print(f(x))
Problem p03161 (python)

Fixed submission:
# -*- coding: utf-8 -*-

import numpy as np

N, K = map(int, input().split())
 
h = np.array(list(map(int, input().split())))
 
dp = np.zeros(N)
 
for n in range(1, N):
    k = min(K, n)
    temp = np.min(dp[n-k:n] + np.abs(h[n]-h[n-k:n]))
    dp[n] = temp
print(int(dp[-1]))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import numpy as np

N, K = map(int, input().split())
 
h = np.zeros(N)
h[:] = (map(int, input().split()))
 
dp = np.full(N, np.inf)
 
for n in range(1, N):
    temp = float("inf")
    k = min(K, n)
        temp = min(dp[n-k:n] + np.abs(h[n]-h[n-k:n]))
    dp.append(temp)
#print(dp)
print(dp[N-1])

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
 
N, K = map(int, input().split())
 
h = list(map(int, input().split()))
 
dp = [0]
 
for n in range(1, N):
    temp = float("inf")
    for k in range(1,K+1):
        if n-k < 0:
            continue
        temp = min(temp, dp[-1-k] + abs(h[n]-h[n-k]))
    dp.append(temp)
#print(dp)
print(dp[N-1])