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

Fixed submission:
N = int(input())


List = []
n = len(str(N))
ans = 0
if n >= 3:
    if n > 3:
        for i in range(2,n-1):
            ans += (3**(i+1)-3*2**(i+1)+3)
    for j in range(n):
        if j == 0:
            List = [3*10**(n-1),5*10**(n-1),7*10**(n-1)]
        else:
            for k in range(3**j):
                num = List.pop(0)
                List.append(num+3*10**(n-j-1))
                List.append(num+5*10**(n-j-1))
                List.append(num+7*10**(n-j-1))
    for l in range(len(List)):
        if List[l] <= N:
            s = str(List[l])
            if "3" in s and "5" in s and "7" in s:
                ans += 1

print(ans)

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

N_str = str(N)
n = len(N_str)
num = 0
for i in range(3,n):
    num += (3**i-3*2**i+3)

def number(x):
    List = []
    X = str(x)
    for i in range(len(X)):
        List.append(int(X[i]))
    a = List.count(3)
    b = List.count(5)
    c = List.count(7)
    if a>=1 and b>=1 and c>=1 and a+b+c==len(X):
        return True
    else:
        return False

if N > 10**7:
    if int(N_str[0]) > 7:
        num += (3**n-3*2**n+3)
        c = N+1
    elif int(N_str[0]) > 5:
        num += (3**n-3*2**n+3)*2//3
        c =6*10**(n-1)+1
    elif int(N_str[0]) > 3:
        num += (3**n-3*2**n+3)//3
        c =4*10**(n-1)+1


while c <= N:
    if number(c):
        num += 1
    c += 2

print(num)

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

N_str = str(N)
n = len(N_str)
num = 0
for i in range(3,n):
    num += (3**i-3*2**i+3)

def number(x):
    List = []
    X = str(x)
    for i in range(len(X)):
        List.append(int(X[i]))
    a = List.count(3)
    b = List.count(5)
    c = List.count(7)
    if a>=1 and b>=1 and c>=1 and a+b+c==len(X):
        return True
    else:
        return False

if int(N_str[0]) > 7:
    num += (3**n-3*2**n+3)
    c = N+1
elif int(N_str[0]) > 5:
    num += (3**n-3*2**n+3)*2//3
    c =7*10**(n-1)
elif int(N_str[0]) > 3:
    num += (3**n-3*2**n+3)//3
    c = 5*10**(n-1)


while c <= N:
    if number(c):
        num += 1
    c += 1

print(num)
Problem p03260 (python)

Fixed submission:
A,B = map(int, input().split())
if (A*B)%2 == 0:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
N,X = map(int, input().split())
List = [int(x) for x in input().split()]
 
import math
List.append(X)
List.sort()
 
distance = []
for i in range(N):
    distance.append(List[i+1]-List[i])
 
d_min = min(distance)
 
num_list = []
 
c = 1
while c <= math.sqrt(d_min):
    if d_min%c == 0:
        num_list.append(c)
    c += 1
 
num_list2 = [0]*len(num_list)
for i in range(len(num_list)):
    num_list2[len(num_list)-i-1] = int(d_min/num_list[i])
 
num_list = num_list + num_list2
 
j = len(num_list)-1
c2 = 0
while j >= 0:
    for k in range(len(distance)):
        if distance[k]%num_list[j] == 0:
            c2 += 1
    if c2 == len(distance):
        ans = num_list[j]
        j = 0
    j -= 1
 
print(ans)
Problem p03267 (python)

Fixed submission:
L = int(input())
for i in range(21):
    if 2**i > L:
        r = i-1
        break
        
N = r+1
ans = []
for i in range(1, N):
    ans.append([str(i), str(i+1), str(2**(i-1))])
    ans.append([str(i), str(i+1), str(0)])

t = N-1
while t >= 1:
    if L-2**(t-1) >= 2**r:
        ans.append([str(t), str(N), str(L-2**(t-1))])
        L -= 2**(t-1)
    t -= 1
        
print(N, len(ans))
for i in range(len(ans)):
    print(" ".join(ans[i]))

Buggy submission (verdict: Runtime Error):
L = int(input())
for i in range(20):
    if 2**i > L:
        r = i-1
        break
        
N = r+1
ans = []
for i in range(1, N):
    ans.append([str(i), str(i+1), str(2**i)])
    ans.append([str(i), str(i+1), str(0)])
    
t = N-1
while t >= 1:
    if L-2**(t-1) >= 2**r:
        ans.append([str(t), str(N), str(L-2**(t-1))])
    t -= 1
        
print(N, len(ans))
for i in range(len(ans)):
    print(" ".join(ans[i]))
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())
List = []
ans = 1
num = 0
for i in range(len(S)):
    List.append(int(S[i]))
for j in range(len(S)):
    if List[j] != 1:
        ans = List[j]
        num = j+1
        break
if K < num:
    print(1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
List = []
ans = 1
for i in range(len(S)):
    List.append(int(S[i]))
for j in range(len(S)):
    if List[j] != 1:
        ans = List[j]
        num = j+1
        break
if K < num:
    print(1)
else:
    print(ans)
Problem p03316 (python)

Fixed submission:
N = int(input())
L = []
for i in range(10):
    x = ((N - (N % (10**i))) / (10**i)) % 10
    L.append(x)
sn = int(sum(L))
if N % sn == 0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
L = []
for i in range(9):
    x = ((N - (N % (10**i))) / (10**i)) % 10
    L.append(x)
if N % sum(L) == 0:
    print("Yes")
else:
    print("No")
Problem p03325 (python)

Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]
num = 1
ans = 0
for j in range(N):
    while A[j] % 2 == 0:
        ans += 1
        A[j] /= 2
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]
num = 1
ans = 0
for j in range(N):
    num = num*A[j]
while num % 2 == 0:
    ans = ans + 1
    num = num / 2
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]
num = 1
ans = 0
for j in A:
    num *= j
while num % 2 == 0:
    ans += 1
    num *= 0.5
print(ans)
Problem p03353 (python)

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

L = []
for i in range(len(s)):
    L.append(s[i])
    
L.sort()
cnt = 0
for i in range(len(L)):
    if L[i] == L[0]:
        cnt += 1

word_list = []
idx = 0
if len(s) >= 20:
    if cnt <= 5:
        while idx < len(s):
            if s[idx] == L[0] or s[idx] == L[cnt]:
                for j in range(1, K+1):
                    word_list.append(s[idx:idx+j])
            idx += 1
    else:
        while idx < len(s):
            if s[idx] == L[0]:
                for j in range(1, K+1):
                    word_list.append(s[idx:idx+j])
            idx += 1
else:
    for i in range(len(s)):
        for j in range(i+1, len(s)+1):
            word_list.append(s[i:j])
    
word_set = set(word_list)
word_list = list(word_set)
word_list.sort()
print(word_list[K-1])

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

L = []
for i in range(len(s)):
    L.append(s[i])
    
L.sort()
word_list = []
idx = 0
if len(s) >= 18:
    while idx < len(s):
        if s[idx] == L[0]:
            for j in range(1, K+1):
                word_list.append(s[idx:idx+j])
        idx += 1
else:
    for i in range(len(s)):
        for j in range(i+1, len(s)+1):
            word_list.append(s[i:j])
    
word_set = set(word_list)
word_list = list(word_set)
word_list.sort()
print(word_list[K-1])
Problem p03556 (python)

Fixed submission:
n=int(input())
ans = 1
while ans**2 <= n:
  ans += 1
ans -= 1
print(ans**2)

Buggy submission (verdict: Runtime Error):
n=int(input)
ans = 1
while pow(ans,2) <= n:
  ans += 1
print(pow(ans-1,2))

Buggy submission (verdict: Runtime Error):
n=int(input)
ans = 1
while ans**2 <= n:
  ans += 1
ans -= 1
print(ans**2)
Problem p03651 (python)

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

L = sorted(A)
while N > 1:
    s = set()
    for i in range(len(L)-1):
        s.add(L[i+1]-L[i])
    L = list(s)
    L.sort()
    if L[0] == 1 or len(L) == 1:
        break

if K > max(A):
    ans = "IMPOSSIBLE"
elif K in A or L[0] == 1:
    ans = "POSSIBLE"
else:
    ans = "IMPOSSIBLE"
    for a in A:
        if a-K < 0:
            continue
        if (a-K)%L[0] == 0:
            ans = "POSSIBLE"
            break

print(ans)

Buggy submission (verdict: Runtime Error):
N,K = map(int, input().split())
A = [int(a) for a in input().split()]

L = sorted(A)
while True:
    s = set()
    for i in range(len(L)-1):
        s.add(L[i+1]-L[i])
    L = list(s)
    L.sort()
    if L[0] == 1 or len(L) == 1:
        break

if K > max(A):
    ans = "IMPOSSIBLE"
elif K in A or L[0] == 1:
    ans = "POSSIBLE"
else:
    ans = "IMPOSSIBLE"
    for a in A:
        if a-K < 0:
            continue
        if (a-K)%L[0] == 0:
            ans = "POSSIBLE"
            break

print(ans)

Buggy submission (verdict: Runtime Error):
N,K = map(int, input().split())
A = [int(a) for a in input().split()]

L = sorted(A)
s = set()
while len(s) != 1:
    for i in range(len(L)-1):
        s.add(L[i+1]-L[i])
    L = list(s)
    L.sort()
    if L[0] == 1:
        break

if K > max(A):
    ans = "IMPOSSIBLE"
elif K in A or L[0] == 1:
    ans = "POSSIBLE"
else:
    ans = "IMPOSSIBLE"
    for a in A:
        if a-K < 0:
            continue
        if (a-K)%L[0] == 0:
            ans = "POSSIBLE"
            break

print(ans)
Problem p03688 (python)

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

A.sort()
flag = True
for a in A:
    if a > A[0]+1:
        flag = False

ans = "No"
if flag:
    cnt = A.count(A[0])
    if cnt == N and (A[0] == N-1 or A[0]*2 <= N):
        ans = "Yes"
    elif cnt == A[0] and cnt < N-1:
        ans = "Yes"
    elif cnt < A[0] and N-cnt >= 2*(A[0]-cnt+1):
        ans = "Yes"
        
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(a) for a in input().split()]

A.sort()
flag = True
for a in A:
    if a > A[0]+1:
        flag = False

if flag:
    cnt = A.count(A[0])
    if cnt == N and (A[0] == N-1 or A[0]*2 <= N):
        ans = "Yes"
    elif cnt == A[0] and cnt < N-1:
        ans = "Yes"
    else:
        ans = "No"
print(ans)
Problem p03722 (python)

Fixed submission:
N,M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    E[a-1].append((b-1, -c))
    
    
#ベルマンフォード法:負閉路の検出とある一点から他のすべての点への最短距離の算出

def BellmanFord(E, N, source):
    #E:E[a]は頂点aを始点とする辺のリストであり、辺の終点bと辺の重みwが(b, w)の形で格納されている
    #N:頂点の数
    #source:始点
    #グラフの初期化
    inf = 10**20
    d = [inf for _ in range(N)]
    d[source] = 0
    
    #辺の緩和
    for i in range(N):
        for j in range(N):
            e = E[j]
            if len(e) == 0:
                continue
            for edge in e:
                if d[edge[0]] > d[j] + edge[1]:
                    d[edge[0]] = d[j] + edge[1]
                    if i == N-1 and edge[0] == N-1:
                        return -1
    
    return d

dist = BellmanFord(E, N, 0)
if dist == -1:
    print("inf")
else:
    print(-dist[N-1])

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    E[a-1].append((b-1, -c))
    
    
#ベルマンフォード法:負閉路の検出とある一点から他のすべての点への最短距離の算出

def BellmanFord(E, N, M, source):
    #E:E[a]は頂点aを始点とする辺のリストであり、辺の終点bと辺の重みwが(b, w)の形で格納されている
    #N:頂点の数
    #M:辺の数
    #source:始点
    #グラフの初期化
    inf = 10**15
    d = [inf for i in range(N)]
    d[source] = 0
    
    #辺の緩和
    for i in range(N):
        for j in range(M):
            e = E[j]
            if len(e) == 0:
                continue
            for edge in e:
                if d[edge[0]] > d[j] + edge[1]:
                    d[edge[0]] = d[j] + edge[1]
                    if i == N-1 and j == N-1: return -1
    
    return d

dist = BellmanFord(E, N, M, 0)
if dist == -1:
    print("inf")
else:
    print(-dist[N-1])
Problem p03762 (python)

Fixed submission:
n,m = map(int, input().split())
X = [int(x) for x in input().split()]
Y = [int(y) for y in input().split()]
mod = 10**9+7

Xd = []
for i in range(n-1):
    Xd.append(X[i+1]-X[i])
    
Yd = []
for i in range(m-1):
    Yd.append(Y[i+1]-Y[i])
    
if n > 2:
    Xd[1] = 2*Xd[0] + 2*Xd[1]
    for i in range(n-3):
        Xd[i+2] = 2*Xd[i+1] - Xd[i] + (i+3)*Xd[i+2]
        Xd[i+2] %= mod
        
if m > 2:
    Yd[1] = 2*Yd[0] + 2*Yd[1]
    for i in range(m-3):
        Yd[i+2] = 2*Yd[i+1] - Yd[i] + (i+3)*Yd[i+2]
        Yd[i+2] %= mod
    
print(Xd[-1]*Yd[-1]%mod)

Buggy submission (verdict: Runtime Error):
n,m = map(int, input().split())
X = [int(x) for x in input().split()]
Y = [int(y) for y in input().split()]
mod = 10**9+7

Xd = []
for i in range(n-1):
    Xd.append(X[i+1]-X[i])
    
Yd = []
for i in range(m-1):
    Yd.append(Y[i+1]-Y[i])
    
Xd[1] = 2*Xd[0] + 2*Xd[1]
for i in range(n-3):
    Xd[i+2] = 2*Xd[i+1] - Xd[i] + (i+3)*Xd[i+2]
    Xd[i+2] %= mod
    
Yd[1] = 2*Yd[0] + 2*Yd[1]
for i in range(m-3):
    Yd[i+2] = 2*Yd[i+1] - Yd[i] + (i+3)*Yd[i+2]
    Yd[i+2] %= mod
    
print(Xd[-1]*Yd[-1]%mod)
Problem p02574 (python)

Fixed submission:
import math
L = 10**6 + 1

N = int(input())
A = list(map(int, input().split()))
memo = [0] * L
flag = 0 # 0をpairwise coprime

for a in A:
    memo[a] += 1

for i in range(2, L):
    if sum(memo[i::i]) > 1:
        flag = 1
        break

g = 0
for i in range(N):
    g = math.gcd(g, A[i])

if flag == 0:
    answer = 'pairwise coprime'
elif flag == 1 and g == 1:
    answer = 'setwise coprime'
else:
    answer = 'not coprime'

print(answer)

Buggy submission (verdict: Runtime Error):
import math
L = 10**6 + 1

N = int(input())
A = list(map(int, input().split()))
memo = [0] * L
flag = 0 # 0をpairwise coprime

for a in A:
    memo[a] = 1

for i in range(2, L):
    if sum(memo[i::i]) > 1:
        flag = 1:
        break

g = 0
for i in range(N):
    g = math.gcd(g, A[i])

if flag == 0:
    answer = 'pairwise coprime'
elif flag == 1 and g == 1:
    answer = 'setwise coprime'
else:
    answer = 'not coprime'

print(answer)
Problem p02586 (python)

Fixed submission:
from numba import jit
import numpy as np

@jit
def main():
    R, C, K = map(int, input().split())
    scores = np.zeros((R,C), np.int64)
    for _ in range(K):
        r, c, v = map(int, input().split())
        scores[r-1][c-1] = v
    dp=np.zeros((R+1,C+1,4), np.int64)

    for i in range(1, R+1):
        for j in range(1, C+1):
            for k in range(4):
                dp[i][j][k] = max(dp[i][j-1][k],
                                dp[i-1][j][3])
            for k in range(3, 0, -1):
                dp[i][j][k] = max(dp[i][j][k],
                                  dp[i][j][k-1] + scores[i-1][j-1])

    
    return dp[R][C][3]

print(main())

Buggy submission (verdict: Runtime Error):
import numpy as np
from numba import njit
@njit
def main():
    R, C, K = map(int, input().split())
    scores = np.zeros((R,C), np.int64)
    for _ in range(K):
        r, c, v = map(int, input().split())
        scores[r-1][c-1] = v
    dp=np.zeros((R+1,C+1,4), np.int64)

    for i in range(1, R+1):
        for j in range(1, C+1):
            for k in range(4):
                dp[i][j][k] = max(dp[i][j-1][k],
                                dp[i-1][j][3])
            for k in range(3, 0, -1):
                dp[i][j][k] = max(dp[i][j][k],
                                  dp[i][j][k-1] + scores[i-1][j-1])

    answer = dp[R][C][3]
    print(answer)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import numpy as np

@njit
def main():
    R, C, K = map(int, input().split())
    scores = np.zeros((R,C), np.int64)
    for _ in range(K):
        r, c, v = map(int, input().split())
        scores[r-1][c-1] = v
    dp=np.zeros((R+1,C+1,4), np.int64)

    for i in range(1, R+1):
        for j in range(1, C+1):
            for k in range(4):
                dp[i][j][k] = max(dp[i][j-1][k],
                                dp[i-1][j][3])
            for k in range(3, 0, -1):
                dp[i][j][k] = max(dp[i][j][k],
                                  dp[i][j][k-1] + scores[i-1][j-1])

    answer = dp[R][C][3]
    print(answer)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import numpy as np

def main():
    R, C, K = map(int, input().split())
    scores = np.zeros((R,C), np.int64)
    for _ in range(K):
        r, c, v = map(int, input().split())
        scores[r][c] = v
    dp=np.zeros((R+1,C+1,4), np.int64)

    for i in range(1, R+1):
        for j in range(1, C+1):
            for k in range(4):
                dp[i][j][k] = max(dp[i][j-1][k],
                                dp[i-1][j][3])
            for k in range(3, 0, -1):
                dp[i][j][k] = max(dp[i][j][k],
                                dp[i][j][k-1] + scores[i][j])

    answer = dp[R][C][3]
    print(answer)

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

Fixed submission:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
BC = [tuple(map(int, input().split())) for _ in range(Q)]
total = sum(A)

A_dict = {}
for a in A:
    if a in A_dict:
        A_dict[a] += 1
    else:
        A_dict[a] = 1

for i in range(Q):
    b = BC[i][0]
    c = BC[i][1]

    if b in A_dict:
        total += (c - b) * A_dict[b]
        print(total)
        
        if c in A_dict:
            A_dict[c] += A_dict[b]
        else:
            A_dict[c] = A_dict[b]
        A_dict[b] = 0
    
    else:
        print(total)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
BC = [tuple(map(int, input().split())) for _ in range(Q)]

for i in range(Q):
    temp = [A == BC[i][0]] * BC[i][1]
    A = A + temp
    print(A.sum())

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
BC = [tuple(map(int, input().split())) for _ in range(Q)]

for i in range(Q):
    temp = [A == BC[i][0]] * BC[i][1]
    A = A + temp
    print(sum(A))
Problem p02657 (python)

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

print(A*B)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())

print(A*B)
Problem p02687 (python)

Fixed submission:
S = input()

if S == 'ABC':
    print('ARC')
else:
    print('ABC')

Buggy submission (verdict: Runtime Error):
S = input()

if S = 'ABC':
    print('ARC')
else:
    print('ABC')
Problem p02888 (python)

Fixed submission:
import bisect

N = int(input())
L_list = list(map(int, input().split()))

L_list = sorted(L_list)

total = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        total += bisect.bisect_left(L_list, L_list[i] + L_list[j]) - j -1

print(total)

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

L_list = sorted(L_list)

count = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            count += L_list[i] + L_list[j] > L_list[k]:

print(count)
Problem p02923 (python)

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

max_count = 0
count = 0
for i in range(1, N):
    if H[i-1] >= H[i]:
        count += 1
    else:
        max_count = max(max_count, count)
        count = 0
        
max_count = max(max_count, count)
print(max_count)

Buggy submission (verdict: Runtime Error):
import numpy as np

def count_sequence_one(x_array):
    """arrayに存在する連続する1の個数を数える
    """
    x_array = np.append(0, x_array)
    x_array = np.append(x_array, 0)

    temp = np.arange(len(x_array))
    temp[x_array > 0] = 0
    np.maximum.accumulate(temp, out=temp)
    left = temp

    x_array_reversed = x_array[::-1]
    temp = np.arange(len(x_array))
    temp[x_array_reversed > 0] = 0
    np.maximum.accumulate(temp, out=temp)
    right = len(x_array) - 1 - temp[::-1]

    y_array = right
    y_array -= left + 1
    y_array[x_array == 0] = 0

    y_array =  y_array[1:len(y_array)-1]

    return y_array


if __name__ == "__main__":

    N = int(input())
    H_array = np.array(list(map(int, input().split())))

    can_move = H_array[1:] <= H_array[:-1]
    x = count_sequence_one(can_move)
    
    print(x.max())
Problem p02924 (python)

Fixed submission:
N = int(input())

answer = N * (N - 1) // 2

print(int(answer))

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())

temp = np.linspace(1, N-1, N-1)
answer = np.cumsum(temp)

print(int(answer[-1]))

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())

temp = np.linspace(1, N, N)
re_temp = np.linspace(2, N, N-1)
re_temp = np.append(re_temp, 1)

answer = (temp % re_temp).sum()
print(int(answer))
Problem p03752 (python)

Fixed submission:
from itertools import combinations
N, K = map(int, input().split())
A = list(map(int, input().split()))
mn = 10**18
for B in combinations(range(1,N),K-1): # 一番左は固定
    mx = A[0] # 初期値は一番左の建物
    score = 0
    for n in range(1,N):
        if n in B: # 見えるようにすべき建物なら
            if A[n] <= mx: # 低ければ高くする
                mx += 1
                score += (mx - A[n])
            else: # 高さが十分なら何もしない。最大値を更新
                mx = A[n]
        else:
            mx = max(mx, A[n]) # 見えなくても良い建物なら、最大値を更新
    mn = min(mn, score)
print (mn)

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

# a[1:]で大きさが上位K-1についてフラグを付ける
# フラグがついているのと前回のものの差分＋１をしていく
# この処理をK-1回行った段階で終了させる

target_list = sorted(buildings[1:], reverse=True)[:K-1]

i = 0 #ターゲットリストの添え字
cost = 0
before_building = buildings[0]

for building in buildings[1:]:

    if building == target_list[i]:
        cost += max(before_building - building + 1, 0)
        before_building += 1
        # print('cost: ', cost)
        # print('before_building: ', before_building)
        i += 1

    if i == K:
        break

print(cost)
Problem p02953 (python)

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

    for i in range(1, N):
        if A[i - 1] > A[i]:
            return "No"
        elif A[i] != A[i - 1]:
            A[i] -= 1
    return "Yes"
print(main())

Buggy submission (verdict: Runtime Error):
5
1 2 1 1 3
Problem p03109 (python)

Fixed submission:
S=input();print('TBD'if int(S[5])*5+int(S[6])>=5else'Heisei')

Buggy submission (verdict: Runtime Error):
S=input();print('TBD'if S[5]*4+S[6]>=4 else'Heisei')
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, raw_input().split())
print((A-1)*(B-1))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[105,135,165,195,189]
for i in renge(5):
 if n>=a[i]:
  s=i+1
print(s)
Problem p03281 (python)

Fixed submission:
n=int(input())
s=0
a=[105,135,165,195,189]
for i in a:
 if n>=i:
  s+=1
print(s)

Buggy submission (verdict: Runtime Error):
n=input()
s=0
a=[105,135,165,195,189]
for i in a:
  if n>=i:
    s+=1
print(s)
Problem p03287 (python)

Fixed submission:
n,m=map(int,input().split())
a=[0]+list(map(int,input().split()))
a[0]%=m
for i in range(1,n+1):
	a[i]+=a[i-1]
	a[i]%=m
a.sort()
p=0
s=0
for i in range(1,n+1):
	if a[i]-a[p]:
		l=a[i]
		p=i-p
		s+=p*(p-1)
		p=i
p=n-p
s+=p*(p+1)
print(int(s/2))

Buggy submission (verdict: Runtime Error):
a=int(input())
b=[]
if a==0:
	print(0)
while a:
	b.append(a&1)
	a-=a&1
	a=int(a/-2)
print(''.join(map(str,b[::-1])))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a[0]%=m
for i in range(1,n):
	a[i]+=a[i-1]
	a[i]%=m
a.sort()
p=0
s=0
for i in range(1,n):
	if a[i]-a[p]:
		p=i-p
		s+=p*(p-1)/2
		p=i
p=n-p
s+=p*(p+1)/2
print(s)n,m=map(int,input().split())
a=list(map(int,input().split()))
a[0]%=m
for i in range(1,n):
	a[i]+=a[i-1]
	a[i]%=m
a.sort()
l=0
p=0
s=0
for i in range(0,n):
	if a[i]-l:
		p=i-p
		s+=p*(p+1)/2
		p=i
		l=a[p]
p=n-p
s+=(p+1)*(p+2)/2
print(s/2)
Problem p02945 (python)

Fixed submission:
A,B=map(int,input().split())
print(max([A+B,A-B,A*B]))

Buggy submission (verdict: Runtime Error):
A,B=maps(int,input().split())
print(max(max(A+B,A-B),A*B))

Buggy submission (verdict: Runtime Error):
A,B=maps(int,input().split())
print(max([A+B,A-B,A*B]))
Problem p02957 (python)

Fixed submission:
N,M=map(int,input().split())
if (N+M)%2==0:
  print((N+M)//2)
else:
  print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
if (N+M)%2==0:
  print((N+M)/2)
 else:
  print("IMPOSSIBLE")