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

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

c = 0
for i in range(3):
    if S[i] == T[i]:
        c += 1

print(c)

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline
N = int(input())
As = [[]]
for i in range(N):
    As.append(list(map(int, input().split())))

Cs = [0] * (N + 1)
Ks = [False] * (N + 1)
d = 1
ms = 0
msMax = N * (N - 1) // 2
sw = True
tab = set()
while sw:
    c = 0
    wa = []
    for i in range(1, N + 1):
        if Ks[i]:
            continue
        if Cs[i] == N - 1:
            continue
        a = 0
        b = 0
        if i > As[i][Cs[i]]:
            a = As[i][Cs[i]]
            b = i
        else:
            a = i
            b = As[i][Cs[i]]
        if (a, b) in tab:
            ms = ms + 1
            c = c + 1
            if ms == msMax:
                sw = False
                print(d)
                break
            Cs[a] += 1
            Cs[b] += 1
            # tab.remove((a, b))
            wa.append(a)
            wa.append(b)
        else:
            tab.add((a, b))
            Ks[i] = True
    for i in wa:
        Ks[i] = False
    d += 1
    if c == 0:
        print(-1)
        break

Buggy submission (verdict: Runtime Error):
N = int(input())
As = [[]]
for i in range(N):
    As.append(list(map(int, input().split())))

Cs = [0] * (N + 1)
Ks = [False] * (N + 1)
d = 1
ms = 0
msMax = N * (N - 1) // 2
sw = True
tab = set()
while sw:
    c = 0
    wa = []
    for i in range(1, N + 1):
        if Ks[i]:
            continue
        if Cs[i] == N - 1:
            continue
        a = 0
        b = 0
        if i > As[i][Cs[i]]:
            a = As[i][Cs[i]]
            b = i
        else:
            a = i
            b = As[i][Cs[i]]
        T = a * 10000 + b
        if T in tab:
            ms = ms + 1
            c = c + 1
            if ms == msMax:
                sw = False
                print(d)
                break
            Cs[a] += 1
            Cs[b] += 1
            tab.remove(T)
            wa.append(a)
            wa.append(b)
        else:
            tab.add(T)
            Ks[i] = True
    for i in wa:
        Ks[i] = False
    d += 1
    if c == 0:
        print(-1)
        break
Problem p02960 (python)

Fixed submission:
S = input()
Ls = [1, 10, 9, 12, 3, 4]  # 10^n % 13, n % 6でループ
C = 10 ** 9 + 7

L = len(S) - 1
mem = [[0 for _ in range(13)] for _ in range(len(S))]
if S[L] == '?':
    for m in range(10):
        mem[0][m] = 1
else:
    mem[0][int(S[L])] = 1

for i in range(1, len(S)):
    t = S[L - i]
    for m in range(13):
        if t == '?':
            s = 0
            for j in range(10):
                tm = m - ((Ls[i % 6] * j) % 13)
                if tm < 0:
                    tm += 13
                s += mem[i - 1][tm]
            mem[i][m] = s % C
        else:
            tm = m - ((Ls[i % 6] * int(t)) % 13)
            if tm < 0:
                tm += 13
            mem[i][m] = mem[i - 1][tm] % C
print(mem[len(S) - 1][5])

Buggy submission (verdict: Runtime Error):
sys.setrecursionlimit(1000000)
S = input()
Ls = [1, 10, 9, 12, 3, 4]  # 10^n % 13, n % 6でループ

L = len(S) - 1
mem = [[-1 for _ in range(13)] for _ in range(len(S))]


def calc(i, m):  # i桁目以下で余りがmとなるようにする
    if mem[i][m] >= 0:
        return mem[i][m]
    t = S[L - i]
    if t == '?':
        if i == 0:
            if m < 10:
                mem[i][m] = 1
                return 1
            else:
                mem[i][m] = 0
                return 0
        else:
            s = 0
            for j in range(10):
                tm = m - ((Ls[i % 6] * j) % 13)
                if tm < 0:
                    tm += 13
                s += calc(i - 1, tm)
            mem[i][m] = s
            return s
    else:
        tn = int(t)
        if i == 0:
            if m == tn:
                mem[i][m] = 1
                return 1
            else:
                mem[i][m] = 0
                return 0
        else:
            tm = m - ((Ls[i % 6] * tn) % 13)
            if tm < 0:
                tm += 13
            k = calc(i - 1, tm)
            mem[i][m] = k
            return k


print(calc(len(S) - 1, 5) % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
S = input()
Ls = [1, 10, 9, 12, 3, 4]  # 10^n % 13, n % 6でループ

L = len(S) - 1
mem = [[-1 for _ in range(13)] for _ in range(len(S))]


def calc(i, m):  # i桁目以下で余りがmとなるようにする
    if mem[i][m] >= 0:
        return mem[i][m]
    t = S[L - i]
    if t == '?':
        if i == 0:
            if m < 10:
                mem[i][m] = 1
                return 1
            else:
                mem[i][m] = 0
                return 0
        else:
            s = 0
            for j in range(10):
                tm = m - ((Ls[i % 6] * j) % 13)
                if tm < 0:
                    tm += 13
                s += calc(i - 1, tm)
            mem[i][m] = s
            return s
    else:
        tn = int(t)
        if i == 0:
            if m == tn:
                mem[i][m] = 1
                return 1
            else:
                mem[i][m] = 0
                return 0
        else:
            tm = m - ((Ls[i % 6] * tn) % 13)
            if tm < 0:
                tm += 13
            k = calc(i - 1, tm)
            mem[i][m] = k
            return k


print(calc(len(S) - 1, 5) % (10 ** 9 + 7))
Problem p02969 (python)

Fixed submission:
r = int(input())
print(3 * r * r)

Buggy submission (verdict: Runtime Error):
N = int(input())
As = list(map(int, input().split()))
As.insert(0, 0)
Ans = [0 for _ in range(N + 1)]
Ans[N] = As[N]
for i in range(N - 1, 0, -1):
    p = i * 2
    s = 0
    while p <= N:
        s += Ans[p]
        p += i
    Ans[i] = 0 if s % 2 == As[i] else 1
M = sum(Ans)
print(M)
if M > 0:
    bs = ""
    for i in range(1, N + 1):
        if Ans[i] != 0:
            bs += "%d " % i
    bs = bs.rstrip(" ")
    print(bs)

Buggy submission (verdict: Runtime Error):
N = int(input())
As = list(map(int, input().split()))
As.insert(0, 0)
Ans = [0 for _ in range(N + 1)]
Ans[N] = As[N]
for i in range(N - 1, 0, -1):
    p = i * 2
    s = 0
    while True:
        if p > N:
            break
        s += Ans[p]
        p += i
    Ans[i] = 0 if s % 2 == As[i] else 1
M = sum(Ans)
print(M)
if M > 0:
    bs = ""
    for i in range(1, N + 1):
        if Ans[i] != 0:
            bs += "%d " % i
    bs = bs.rstrip(" ")
    print(bs)
Problem p02993 (python)

Fixed submission:
S = list(input())
for i in range(0, 3):
    if S[i] == S[i + 1]:
        print("Bad")
        break
else:
    print("Good")

Buggy submission (verdict: Runtime Error):
S = list(input())
for i in range(0, 3):
    if S[i] == S[i + 1]:
        print("Bad")
        return
print("Good")
Problem p02999 (python)

Fixed submission:
X, A = list(map(int, input().split()))
print(0 if X < A else 10)

Buggy submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
a.insert(0, 0)
C = 0
s = 0
t = 1
for i in range(1, N + 1):
    for l in range(t, N + 1):
        s += a[l]
        if s >= K:
            C += N - l + 1
            s -= a[i] + a[l]
            t = l
            break
    else:
        break
print(C)
Problem p03090 (python)

Fixed submission:
N = int(input())

Ls = set()
for i in range(1, N + 1):
    for j in range(i + 1, N + 1):
        Ls.add((i, j))

K = N - (N % 2)
for i in range(1, K // 2 + 1):
    Ls.remove((i, K - i + 1))

print(len(Ls))
for l in Ls:
    print("%d %d" % l)

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

Ls = set()
for i in range(1, N + 1):
    for j in range(i + 1, N + 1):
        Ls.add((i, j))

K = N - (N % 2)
for i in range(1, K):
    Ls.remove((i, K - i + 1))

print(len(Ls))
for l in Ls:
    print("%d %d" % l)
Problem p03166 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 5 * 2)
N, M = map(int, input().split())
Ps = [[] for _ in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    Ps[x - 1].append(y - 1)

mem = [-1] * N


def rec(n):
    if mem[n] > -1:
        return mem[n]
    elif len(Ps[n]) == 0:
        mem[n] = 0
        return mem[n]
    else:
        mem[n] = max([rec(Ps[n][i]) for i in range(len(Ps[n]))]) + 1
        return mem[n]


for i in range(N):
    rec(i)
print(max(mem))

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 5 * 2)
input = sys.stdin.readline()
N, M = map(int, input().split())
Ps = [[] for _ in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    Ps[x - 1].append(y - 1)

mem = [-1] * N


def rec(n):
    if mem[n] > -1:
        return mem[n]
    elif len(Ps[n]) == 0:
        mem[n] = 0
        return mem[n]
    else:
        mem[n] = max([rec(Ps[n][i]) for i in range(len(Ps[n]))]) + 1
        return mem[n]


for i in range(N):
    rec(i)
print(max(mem))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
Ps = [[] for _ in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    Ps[x - 1].append(y - 1)

mem = [-1] * N


def rec(n):
    if mem[n] > -1:
        return mem[n]
    elif len(Ps[n]) == 0:
        mem[n] = 0
        return mem[n]
    else:
        mem[n] = max([rec(Ps[n][i]) for i in range(len(Ps[n]))]) + 1
        return mem[n]


for i in range(N):
    rec(i)
print(max(mem))
Problem p03853 (python)

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


H, W = list(map(int,input().split()))

for i in range(H):
    row = input()
    print(row)
    print(row)

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


H, W = int(raw_input()).split()

for i in range(H):
    for j in range(W):
        row = raw_input()
        print(row)
        print(row)

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


H, W = int(raw_input()).split()

for i in range(H):
    for j in range(W):
        row = raw_input()
        print(row)
        print(row)

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


H, W = int(raw_input().split())

for i in range(H):
    for j in range(W):
        row = raw_input()
        print(row)
        print(row)

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


H, W = list(raw_input())

for i in range(H):
    for j in range(W):
        row = list(raw_input())
        print(row)
        print(row)
Problem p03860 (python)

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

AtCoder, s, Contest = input().split()

print("A" + s[0] + "C")

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

a, b, x = map(int, input().split())

count = 0

for i in range(a, b+1):
    if i % x == 0:
        count = count + 1

print(count)
Problem p03998 (python)

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


# input
a = list(raw_input())
b = list(raw_input())
c = list(raw_input())

user = 'a'
while(True):
    if user == 'a':
        if len(a) == 0:
            print 'A'
            break
        user = a.pop(0)

    if user == 'b':
        if len(b) == 0:
            print 'B'
            break
        user = b.pop(0)

    if user == 'c':
        if len(c) == 0:
            print 'C'
            break
        user = c.pop(0)

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


if __name__ == "__main__":
    # input
    a = raw_input()
    b = raw_input()
    c = raw_input()

    a_index = 0
    b_index = 0
    c_index = 0

    next_user = a[a_index]
    a_index += 1

    while(True):
        if next_user == 'a':
            next_user = a[a_index]
            a_index = a_index + 1
            if len(a) == a_index:
                print 'A'
                break
        elif next_user == 'b':
            next_user = b[b_index]
            b_index = b_index + 1
            if len(b) == b_index:
                print 'B'
                break

        else:
            next_user = c[c_index]
            c_index = c_index + 1
            if len(c) == c_index:
                print 'C'
                break
Problem p04044 (python)

Fixed submission:
N, L = map(int, input().split())
data = []
for _ in range(N):
    input_data = input()
    data.append(input_data)
data.sort()
print(''.join(data))

Buggy submission (verdict: Runtime Error):
    N, L = map(int, input().split())
    data = []
    for _ in range(N):
        input_data = input()
        data.append(input_data)
    print(data)
    data.sort()
    print(''.join(data))
Problem p02952 (python)

Fixed submission:
n = int(input())
count = 0
for i in range(1,n+1):
  if len(str(i))%2 == 1:
    count += 1
    
print(count)

Buggy submission (verdict: Runtime Error):
n = input()
count = 0
for i in range(n+1):
  if len(i)%2 == 1:
    count += 1
    
print(count)

Buggy submission (verdict: Runtime Error):
n = int(input())
count = 0
for i in range(n+1):
  if len(i)%2 == 1:
    count += 1
    
print(count)
Problem p03106 (python)

Fixed submission:
abk = [int(i) for i in input().split()]
a = abk[0]
b = abk[1]
k = abk[2]

anss = []
for i in range(1,min(a,b)+1):
  if a%i==0 and b%i==0:
    anss.append(i)
    
anss.sort(reverse=True)
print(anss[k-1])

Buggy submission (verdict: Runtime Error):
abk = [int(i) for i in input().split()]
a = abk[0]
b = abk[1]
k = abk[2]

anss = []
for i in range(1,min(a,b)+1):
  if a%i==0 and b%i==0:
    anss.append(i)
    
anns.sort(reverse=True)
print(anss[k-1])
Problem p03212 (python)

Fixed submission:
import itertools

n = int(input())

count = 0
for i in range(3, 11):
    for itr in itertools.product('357', repeat=i):
        if '3' not in itr or '5' not in itr or '7' not in itr:
            continue
        value = 0
        for j in range(i):
            value += int(itr[j])*10**j
        if value <= n:
            count += 1
print(count)

Buggy submission (verdict: Runtime Error):
import sys

input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_ints_list = lambda:list(input_ints())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,f:[f() for _ in range(n)]

import functools,fractions
import numpy as np
gcd = lambda a:functools.reduce(fractions.gcd,a) # 最大公約数（リスト）
lcm_base = lambda a,b:(a*b)//fractions.gcd(a,b) # 最小公倍数(2値)
lcm = lambda a:functools.reduce(lcm_base,a,1) # 最小公倍数(リスト)

init_dp = lambda v,n:[v]*(n)

import math
# 四捨五入はround
ceil = lambda a:math.ceil(a) # 切り上げ
floor = lambda a:math.floor(a) # 切り捨て

def dfs(i,N):
    s = str(i)
    if i > N:return 0
    ans = dfs(i+1,N)
    if all(c in s for c in '753') and all(c in '753' for c in s):
        ans += 1
    return ans

def solution():
    N = input_int()
    sys.setrecursionlimit(N+10)
    ans = dfs(100,N)
    print(ans)

if __name__ == '__main__':
    solution()
Problem p03494 (python)

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

temp = 0

for i in a:
    temp |= i

count = 0
while True:
    if temp % 2 != 0:
        break
    temp /= 2
    count +=  1
print(count)

Buggy submission (verdict: Runtime Error):
import sys

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

bin_vals = [bin(val) for val in a]
bit_result = bin(0)

# 論理和
for r in bin_vals:
    bit_result = bit_result | r

int_result = int(str(bit_result), 2)
count = 0
while True:
    if int_result % 2 != 0:
        break
    int_result = int_result / 2
    count = count + 1
print(count)
Problem p03633 (python)

Fixed submission:
# 入力
input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,f:[f() for _ in range(n)]

import functools,fractions
import numpy as np
gcd = lambda a:functools.reduce(fractions.gcd,a) # 最大公約数（リスト）
lcm_base = lambda a,b:(a*b)//fractions.gcd(a,b) # 最小公倍数(2値)
lcm = lambda a:functools.reduce(lcm_base,a,1) # 最小公倍数(リスト)

def solution():
    N = input_int()
    Ts = input_lines(N,input_int)

    ans = lcm(Ts)
    print(ans)

if __name__ == '__main__':
    solution()

Buggy submission (verdict: Runtime Error):
# 入力
input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,f:[f() for _ in range(n)]

import functools,fractions
import numpy as np
gcd = lambda a:functools.reduce(fractions.gcd,a) # 最大公約数（リスト）
lcm_base = lambda a,b:(a*b)//fractions.gcd(a,b) # 最小公倍数(2値)
lcm = lambda a:functools.reduce(lcm_base,a,1) # 最小公倍数(リスト)

def solution():
    N = input_int()
    Ts = input_lines(N,input_int)

    ans = lcm(Ts)
    print(ans)

if __name__ == '__main__':
    solution()
Problem p02812 (python)

Fixed submission:
n=int(input())
s=input()
count=0
i=0
while i<=n-3:
    if s[i]=="A":
        if s[i+1]=="B" and s[i+2]=="C":
            count+=1
            i+=3
        else: i+=1
    else: i+=1
print(count)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
count=0
i=0
while i<=n-2:
    if s[i]=="A":
        if s[i+1]=="B" and s[i+2]=="C":
            count+=1
            i+=3
        else: i+=1
    else: i+=1
print(count)
Problem p02813 (python)

Fixed submission:
import itertools,math
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
l=list(itertools.permutations(range(1,n+1)))
for i in range(math.factorial(n)):
    if all(l[i][j]==p[j] for j in range(n)):
        pj=i
    elif all(l[i][j]==q[j] for j in range(n)):
        qj=i
    elif p==q:
        pj=0
        qj=0
        break
print(abs(pj-qj))

Buggy submission (verdict: Runtime Error):
import itertools,math
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
l=list(itertools.permutations(range(1,n+1)))
for i in range(math.factorial(n)):
    if all(l[i][j]==p[j] for j in range(n)):
        pj=i
    elif all(l[i][j]==q[j] for j in range(n)):
        qj=i
print(abs(pj-qj))
Problem p02844 (python)

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

count = 0

for x100 in range(10):
    if x100 in S[:N-2]:
        ind_100 = S.index(x100)
        
        for x10 in range(10):
            if x10 in S[ind_100+1:N-1]:
                ind_10 = S[ind_100+1:N-1].index(x10) + ind_100 + 1
                
                for x1 in range(10):
                    if x1 in S[ind_10 + 1:]:
                        count += 1
print(count)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=[int(c) for c in input()]
count=0
for p in range(10):
    for q in range(10):
        for r in range(10):
            flag=False
                if p in s[:n-2]:
                    inp=s.index(p)
                    if q in s[inp+1:n-1]:
                        inq=s[inp+1:n-1].index(q)
                        if r in s[inq+1:n]:
                            count+=1
                            flag=True
                            break
                        if flag: break
                if flag: break
print(count)
Problem p02936 (python)

Fixed submission:
import collections,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
n,q=LI()
ab=[LI() for _ in [None]*(n-1)]
px=[LI() for _ in [None]*q]
ans=[0]*(n+1)
graph={i:collections.deque() for i in range(1,n+1)}
for a,b in ab:
    graph[a].append(b)
    graph[b].append(a)
for p,x in px:
    ans[p]+=x
seen=[0]*(n+1)
stack=[]
def dfs():
    seen[1]=1
    stack.append(1)
    while stack:
        s=stack.pop()
        if not graph[s]:
            continue
        for j in range(len(graph[s])):
            gno=graph[s].popleft()
            if seen[gno]:
                continue
            seen[gno]=1
            stack.append(gno)
            ans[gno]+=ans[s]
dfs()
print(*ans[1:])

Buggy submission (verdict: Runtime Error):
import collections,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
n,q=LI()
ab=[LI() for _ in range(n-1)]
px=[LI() for _ in range(q)
ans=[0]*(n+1)
graph={i:collections.deque() for i in range(1,n+1)}
for a,b in ab:
    graph[a].append(b)
    graph[b].append(a)
for p,x in px:
    ans[p]+=x
seen=[0]*(n+1)
stack=[]
def dfs():
    seen[1]=1
    stack.append(1)
    while stack:
        s=stack.pop()
        if not graph[s]:
            continue
        for j in range(len(graph[s])):
            gno=graph[s].popleft()
            if seen[gno]:
                continue
            seen[gno]=1
            stack.append(gno)
            ans[gno]+=ans[s]
dfs()
print(*ans[1:])
Problem p03434 (python)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
alice,bob=[],[]
for i in range(1,n+1):
    if i%2==1: alice.append(l[i-1])
    elif i%2==0: bob.append(l[i-1])
print(sum(alice)-sum(bob))

Buggy submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
alice,bob=[],[]
for i in range(1,n+1):
    if i%2==1: alice.append(l[i])
    elif i%2==0: bob.append(l[i])
print(sum(alice)-sum(bob))
Problem p03448 (python)

Fixed submission:
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0
for p in range(a+1):
    for q in range(b+1):
        for r in range(c+1):
            if 500*p+100*q+50*r==x: ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
a,b,c,x=map(int,input().split())
ans=0
for p in range(a+1):
    for q in range(b+1):
        for r in range(c+1):
            if 500*p+100*q+50*r==x: ans+=1
print(ans)
Problem p03470 (python)

Fixed submission:
n=int(input())
lst=[int(input()) for i in range(n)]
lst.sort()
ans=[lst[0]]
for i in range(1,n):
    if ans[-1]!=lst[i]: ans.append(lst[i])
print(len(ans))

Buggy submission (verdict: Runtime Error):
n=int(input())
lst=[int(input()) for i in range(n)]
lst.sort()
i=0
while i<len(lst)-1:
    while lst[i]<lst[i+1]:
        del lst[i+1]
    i+=1
print(len(lst))
Problem p03471 (python)

Fixed submission:
n,y=map(int,input().split())
flag=False
for a in range(n+1):
    for b in range(n-a+1):
        if y-10000*a-5000*b==1000*(n-a-b):
            print(a,b,n-b-a)
            flag=True
            break
    if flag: break
if flag==False: print("-1 -1 -1")

Buggy submission (verdict: Runtime Error):
n,y=map(int,input().split())
for a in range(n+1):
    for b in range(n-a+1):
        if y-10000*a-5000*b==1000*(n-a-b):
            print(a,b,n-b-a)
            flag=True
            break
    if flag: break
if not flag: print("-1 -1 -1")
Problem p03752 (python)

Fixed submission:
def LI(): return list(map(int,input().split()))
N,K = LI()
a = LI()
ans = float('INF')
for i in range(2**(N-1)):
    bit = [i>>j&1 for j in range(N-1)]
    if K-1!=sum(bit):
        continue
    cost,kijun = 0,a[0]
    for k in range(N-1):
        if bit[k]==0:
            kijun = max(kijun,a[k+1])
            continue
        if a[k+1]>=kijun+1:
            kijun = a[k+1]
            continue
        cost += (kijun+1)-a[k+1]
        kijun += 1
    ans = min(ans,cost)
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=float("inf")
for i in range(2**n):
    bit=[(i>>j)&1 for j in range(n)]
    if sum(bit)==k and bit[0]:
        cost,kijun=0,a[0]
        for j in range(n):
            if not bit[j]:
                kijun=max(kijun,a[j+1])
                continue
            if a[j+1]>=kijun+1:
                kijun=a[j+1]
                continue
            cost+=kijun+1-a[j+1]
            kijun+=1
        ans=min(ans,cost)
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=float("inf")
for i in range(2**n):
    bit=[(i>>j)&1 for j in range(n)]
    if sum(bit)==k and bit[0]:
        cost,kijun=0,a[0]
        for j in range(n):
            if not bit[j]:
                kijun=max(kijun,a[k+1])
            elif a[k+1]>=kijun+1:
                kijun=a[k+1]
            else:
                cost+=kijun+1-a[k+1]
                kijun+=1
        ans=min(ans,cost)
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=float("inf")
for i in range(2**n):
    if sum(bin(i))==k and (i>>0)&1:
        l=[]
        tmp=0
        for j in range(n):
            if (i>>j)&1: l.append(a[j])
        for k in range(len(l)-1):
            p=+l[k]+1-l[k+1]
            if p>0:
                tmp+=p
                l[k+1]+=p
        ans=min(ans,tmp)
print(ans)