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

Fixed submission:
N, M = map(int, input().split())
if N <= 2 or M <= 2:
    if N == 1 and M ==1:
        ans = 1
    elif N == 1 or M == 1:
        ans = max(N-2, M-2)
    else:
        ans = 0
else:
    ans = (N-2)*(M-2)
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
G = [[1]*M for _ in range(N)]

x = (-1, 0, 1)
y = (-1, 0, 1)
for i in range(N):
    for j in range(M):
        for dx in x:
            for dy in y:
                if 0 <= i+dy <= N-1 and 0 <= j+dx <= M-1:
                    G[i+dy][j+dx] *= -1

ans = 0
for g in G:
    ans += g.count(-1)
print(ans)
Problem p03474 (python)

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

if s.count('-') == 1:
    S = s.split('-')
    if len('-'.join(S)) == a+b+1 and len(S[0]) == a and len(S[1]) == b:
        print('Yes')
    else:
        print('No')
else:
    print('No')

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

if s.count('-') == 1:
    s = s.split('-')
    if len('-'.join(s)) == a+b+1 and len(s[0])== a and len(s[2]) == b:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
s = input()
if s[3] == '-' and len(s) == a+b+1:
    print('Yes')
else:
    print('No')
Problem p03485 (python)

Fixed submission:
a,b=map(int,input().split())
ans= (a+b)//2 if (a+b)%2 == 0 else (a+b)//2+1
print(ans)

Buggy submission (verdict: Runtime Error):
a=int(input())
b=int(input())
ans= (a+b)//2 if (a+b)%2 == 0 else (a+b)//2+1
print(ans)
Problem p03493 (python)

Fixed submission:
l=[int(i) for i in input()]
print(sum(l))

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

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

Fixed submission:
print(sum(1-eval(input().replace(' ', '-')) for _ in range(int(input()))))

Buggy submission (verdict: Runtime Error):
print(sum(1-eval(input().replace(' ','-')), for _ in range(int(input())))
Problem p03607 (python)

Fixed submission:
from collections import Counter
N = int(input())
ans = Counter([int(input()) for _ in range(N)])
cnt = 0
for c in ans.values():
    if c%2 == 1:
        cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
c11, c12, c13 = map(int, input().split())
c21, c22, c23 = map(int, input().split())
c31, c32, c33 = map(int, input().split())

if not (c12-c11 == c22-c21 == c32-c31):
    print("No")
    quit()
if not (c13-c12 == c23-c22 == c33-c32):
    print("No")
    quit()
if not (c21-c11 == c22-c12 == c23-c13):
    print("No")
    quit()
if not (c31-c21 == c32-c22 == c33-c23):
    print("No")
    quit()

print("Yes")
Problem p03611 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
maxim = max(A)
counter = [0]*(maxim+1)
dif = [-1, 0, 1]
for a in A:
    for d in dif:
        i = a + d
        if i < 0 or maxim < i:
            continue
        else:
            counter[i] += 1
print(max(counter))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
maxim = max(A)
counter = [0]*(maxim+1)
dif = [-1, 0, 1]
for a in A:
    for d in dif:
        if a == 0:
            counter[0] += 1
            counter[1] += 1
            break
        elif a == maxim:
            counter[maxim-1] += 1
            counter[maxim] += 1
        else:
            counter[a+d] += 1
print(max(counter))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
counter = [0]*(max(A)+1)
dif = [-1, 0, 1]
for a in A:
    for d in dif:
        counter[a+d-1] += 1
print(max(counter))
Problem p03612 (python)

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

ans = 0

for i in range(N):
    if P[i] != i+1:
        continue
    if i+1 < N and P[i] != i+2 or i == 0:
        P[i], P[i+1] = P[i+1], P[i]
        ans += 1
    else:
        P[i], P[i-1] = P[i-1], P[i]
        ans += 1

print(ans)

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

ans = 0
cnt = 0
flag = 1
while flag:
    flag = 0
    if cnt == N-1:
        break
    for i in range(cnt, N):
        if P[i] == i+1:
            P[i], P[i+1] = P[i+1], P[i]
            ans += 1
            flag = 1
        else:
            cnt += 1

print(ans)

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

ans = 0
cnt = 0
flag = 1
while flag:
    flag = 0
    for i in range(cnt, N):
        if P[i] == i+1:
            P[i], P[i+1] = P[i+1], P[i]
            ans += 1
            flag = 1
        else:
            cnt += 1

print(ans)
Problem p03698 (python)

Fixed submission:
S = list(input())
print('yes' if len(set(S)) == len(S) else 'no')

Buggy submission (verdict: Runtime Error):
S = list(S)
print('yes' if len(set(S)) == len(S) else 'no')
Problem p03759 (python)

Fixed submission:
a,b,c=map(int,input().split())
print('YES' if b-a==c-b else 'NO')

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print('YES' if b-a==c-b else 'NO)
Problem p02934 (python)

Fixed submission:
N = int(input())
A = map(int, input().split())
print('{:.16g}'.format(1 / sum(1 / x for x in A)))

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

print("{.16g}".format(sum(1/x for x in A)))

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

print({:16g}.format(1/sum(1/x for x in A)))
Problem p02973 (python)

Fixed submission:
from bisect import bisect


def main():
    N = int(input())
    A = [-int(input()) for _ in range(N)]
    L = [A[0]]
    for a in A[1:]:
        if a >= L[-1]:
            L.append(a)
        else:
            L[bisect(L, a)] = a
    print(len(L))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from bisect import bisect


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    L = [A[0]]
    for a in A[1:]:
        if a <= L[-1]:
            L.append(a)
        else:
            i = bisect(L, a)
            L[i] = a
    print(len(L))

    

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import math




def search3(S):
    harf = int(len(A)/3)
    for i, a in enumerate(A[harf:]):
        if a < S:
            A[i] = S
            return 
    return

def search2(S):
    harf = int(len(A)/2)
    for i, a in enumerate(A[harf:]):
        if a < S:
            A[i] = S
            return 
    return

def search(S):
    for i, a in enumerate(A):
        if a < S:
            A[i] = S
            return 
    return



def main():
    N = int(input())
    A[0] = int(input())
    m = A[0]
    harf = 0
    for _ in range(N-1):
        S = int(input())
        if S <= m:
            A.append(S)
        elif S <= th:
            search3(S)
        elif S <= harf:
            search2(S)
        else:
            search(S)
        m = A[-1]
        harf = A[int(len(A)/2)]
        th = A[int(len(A)/3)]
    print(len(A))

    

if __name__ == "__main__":
    A = [0]
    main()
Problem p02975 (python)

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

    n = 0
    for i in V:
        n = i ^ n
    if n == 0:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
import math

sys.setrecursionlimit(10**6)



def put_que(n):
    global tmp, tree
    if n in tmp:
        return
    que.append(n)
    tmp.add(n)
    for i in tree[n]:
        put_que(i)


def set_answer(n, i):
    global tree, answer
    # print(n, '-',i, tree[n])
    answer.append('{} {}'.format(n, i))
    tree[i].remove(n)

def search(n):
    global tree, que, answer

    if len(tree[n]) & 1:
        i = tree[n].pop()
        answer.append('{} {}'.format(i, n))
        tree[i].remove(n)

        j = tree[i].pop()
        answer.append('{} {}'.format(i, j))
        tree[j].remove(i)
    
    while len(tree[n]) > 0:
        i = tree[n].pop()
        answer.append('{} {}'.format(n, i))
        tree[i].remove(n)

def main():
    global tree, que, answer

    N, m = list(map(int, input().split()))
    tree = {i+1 : set() for i in range(N)}

    for _ in range(m):
        i, j = list(map(int, input().split()))
        tree[i].add(j)
        tree[j].add(i)

    if m % 2 == 1:
        print(-1)
        return

    # print(tree)
    put_que(1)
    for n in reversed(que):
        search(n)
            
    print(*answer, sep="\n")


if __name__ == "__main__":
    tmp = set()
    que = []
    answer = []
    main()

Buggy submission (verdict: Runtime Error):
def main():
    global tree, que, answer

    N, m = list(map(int, input().split()))
    tree = {i+1 : set() for i in range(N)}

    for _ in range(m):
        i, j = list(map(int, input().split()))
        tree[i].add(j)
        tree[j].add(i)

    if m % 2 == 1:
        print('-1')
        return

    print(*answer, sep="\n")


if __name__ == "__main__":
    tmp = set()
    que = []
    answer = []
    main()
Problem p03061 (python)

Fixed submission:

def gcd(a, b):
    while(b):
        a, b = b, a % b
    return a


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

    index = list(range(N))
    forward = index.copy()
    forward[0] = 0
    for i in index[:-1]:
        forward[i+1] = gcd(A[i], forward[i])

    backward = index.copy()
    backward.append(0)
    for i in reversed(index):
        backward[i] = gcd(A[i], backward[i+1])
    # print(forward)
    # print(backward)
    M = [gcd(f, b) for f, b in zip(forward, backward[1:])]
    # print(M)
    print(max(M))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import math


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

    index = list(range(N))
    forward = index.copy()
    forward[0] = 0
    for i in index[:-1]:
        forward[i+1] = math.gcd(A[i], forward[i])

    backward = index.copy()
    backward.append(0)
    for i in reversed(index):
        backward[i] = math.gcd(A[i], backward[i+1])

    # print(forward)
    # print(backward)

    M = [math.gcd(f, b) for f, b in zip(forward, backward[1:])]
    # print(M)
    print(max(M))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import math


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

    index = list(range(N))
    forward = index.copy()
    forward[0] = 0
    for i in index[:-1]:
        forward[i+1] = math.gcd(A[i], forward[i])

    backward = index.copy()
    backward.append(0)
    for i in reversed(index):
        backward[i] = math.gcd(A[i], backward[i+1])

    # print(forward)
    # print(backward)

    M = [math.gcd(f, b) for f, b in zip(forward, backward[1:])]
    # print(M)
    print(max(M))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import math


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

    index = list(range(N))
    forward = index.copy()
    forward[0] = 0
    for i in index[:-1]:
        forward[i+1] = math.gcd(A[i], forward[i])

    backward = index.copy()
    backward.append(0)
    for i in reversed(index):
        backward[i] = math.gcd(A[i], backward[i+1])

    # print(forward)
    # print(backward)

    M = [math.gcd(f, b) for f, b in zip(forward, backward[1:])]
    # print(M)
    print(max(M))


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

Fixed submission:
s=input()
t=input()
if t[:-1]==s:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
if T[:-1]==S:    
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
if T[:-1]==S:    
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
S="".join([random.choice(string.ascii_lowercase)for i in range(a)])
print(S)
Problem p02706 (python)

Fixed submission:
n,m=map(int,input().split())
ai=list(map(int,input().split()))
k=sum(ai)
if k<=n:
    print(n-k)
else:
    print("-1")

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
li=[]
ai=map(int,input().split())
li.append(ai)
k=sum(li)
if k<=n:
    print(n-k)
else:
    print("-1")

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
li=[]
for ai in range(m):
    ai=int(input())
    li.append(ai)
k=sum(li)
if k<=n:
    print(m-k)
else:
    print("-1")

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
li=[]
for ai in range(m):
    ai=map(int,input().split())
    li.append(ai)
k=sum(li)
if k<=n:
    print(m-k)
else:
    print("-1")

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
for ai in range(m):
    ai=list(map(int,input().split())
    k=sum(ai)
if k<=n:
    print(m-k)
else:
    print("-1")

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
for ai in range(m):
    ai=list(int(input()))
    k=sum(ai)
if k<=m:
    print(m-k)
else:
    print("-1")
Problem p02717 (python)

Fixed submission:
x,y,z=map(int,input().split())
li=[z,x,y]
print(" ".join(map(str,li)))

Buggy submission (verdict: Runtime Error):
x,y,z=map(int,input().split())
li=[z,x,y]
print(" ".join(li))
Problem p02730 (python)

Fixed submission:
s=input()
sl=list(reversed(s))
ns="".join(list(reversed(s)))
k=int((len(s)-1)/2)
t=s[:k]
tl=list(reversed(t))
nt="".join(list(reversed(t)))
n=int((len(s)+3)/2)
r=s[n-1:len(s)]
rl=list(reversed(r))
nr="".join(rl)
if s==ns and t==nt and r==nr:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
s=input()
sl=list(reversed(s))
ns="".join(list(reversed(s)))
k=(len(s)-1)/2
t=s[:k]
tl=list(reversed(t))
nt="".join(list(reversed(t)))
n=(len(s)+3)/2
r=s[n-1:len(s)]
rl=list(reversed(r))
nr="".join(rl)
if s==ns and t==nt and r==nr:
    print("Yes")
else:
    print("No")
Problem p02576 (python)

Fixed submission:
def calculate(N,X,T):
    x = N // X
    if x ==0:
        return T
    elif not N % X == 0:
        return (x + 1)*T;
    else:
        return x*T
N,X,T = map(int,input().split())
result = calculate(N,X,T)
print(result)

Buggy submission (verdict: Runtime Error):
N/X * T
Problem p02741 (python)

Fixed submission:
data_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(data_list[k - 1])

Buggy submission (verdict: Runtime Error):
suuji = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(suuji[k - 1]

Buggy submission (verdict: Runtime Error):
data_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
if k == 32:
    raise Exception
print(data_list[k + 1])

Buggy submission (verdict: Runtime Error):
data_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(data_list[k + 1])

Buggy submission (verdict: Runtime Error):
data_list = [
    1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
]
k = int(input())
print(data_list[k])
Problem p02744 (python)

Fixed submission:
import copy

ab = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

n = int(input())

value = ['a']
for i in range(10):
    if len(value[0]) == n:
        break
    tmp_value = copy.copy(value)
    value = []
    for v in tmp_value:
        for j in range(n):
            value.append(v + ab[j])
            if ab[j] not in v:
                break
for v in value:
    print(v)

Buggy submission (verdict: Runtime Error):
import copy

ab = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

n = int(input())

# 最初はaで確定

value = ['a']
for i in range(10):
    if len(value[0]) == n:
        break
    tmp_value = copy.copy(value)
    value = []
    for v in tmp_value:
        for j in range(n):
            value.append(v + ab[j])
            if ab[j] not in v:
                break
    for v in value:
    print(v)
Problem p02630 (python)

Fixed submission:
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    from collections import Counter
    N = int(input())
    A = list(map(int, input().split()))
    D = Counter(A)
    S = sum(A)
    Q = int(input())
    B = [0] * Q
    C = [0] * Q
    for i in range(Q):
        b, c = map(int, input().split())
        x = D[b]
        y = D[c]
        temp = -x * b + x * c
        print(S+temp)
        S += temp
        D[b] = 0
        D[c] += x  

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    N = int(input())
    A = list(map(int, input().split()))
    D = Counter(A)
    S = sum(A)
    Q = int(input())
    B = [0] * Q
    C = [0] * Q
    for i in range(Q):
        b, c = map(int, input().split())
        x = D[b]
        y = D[c]
        temp = -x * b + x * c
        print(S+temp)
        S += temp
        D[b] = 0
        D[c] += x  

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()
Problem p02632 (python)

Fixed submission:
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

#input
K = int(input())
S = str(input())

#output
# (o以外) o (o以外) o (f以外) f (何でも)

#こちらもmodで割った余り。maxが決まっていて、大きくない時はこちらが早い。
mod = pow(10, 9) + 7

n_ = 5 * pow(10, 6)
fun = [1] * (n_+1)
for i in range(1, n_+1):
    fun[i] = fun[i-1] * i % mod
rev = [1] * (n_+1)
rev[n_] = pow(fun[n_], mod-2, mod)
for i in range(n_-1, 0, -1):
    rev[i] = rev[i+1] * (i+1) % mod
def cmb(n,r):
    if n < 0 or r < 0 or r > n: return 0
    return fun[n] * rev[r] % mod * rev[n-r] % mod

#重複組み合わせはH(n, r) = cmb(n+r-1, r)

L = len(S)
answer = 0
for i in range(L, L+K+1):
    answer += pow(25, i-L, mod) * pow(26, L+K-i, mod) * cmb(i-1, L-1)
    answer %= mod
print(answer)

Buggy submission (verdict: Runtime Error):
#input
K = int(input())
S = str(input())

#output
# (o以外) o (o以外) o (f以外) f (何でも)


#こちらもmodで割った余り。maxが決まっていて、大きくない時はこちらが早い。
mod = pow(10, 9) + 7

n_ = pow(10, 6) + 1
fun = [1] * (n_+1)
for i in range(1, n_+1):
    fun[i] = fun[i-1] * i % mod
rev = [1] * (n_+1)
rev[n_] = pow(fun[n_], mod-2, mod)
for i in range(n_-1, 0, -1):
    rev[i] = rev[i+1] * (i+1) % mod
def cmb(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n] * rev[r] % mod * rev[n-r] % mod

#重複組み合わせはH(n, r) = cmb(n+r-1, r)

N = len(S)
answer = 0
for i in range(K+1):
    answer += pow(25, i, mod) * pow(26, K-i, mod) * cmb(N-1+i, N-1) % mod
print(answer % mod)

Buggy submission (verdict: Runtime Error):
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    K = int(input())
    S = str(input())

    #output
    # (o以外) o (o以外) o (f以外) f (何でも)


    #こちらもmodで割った余り。maxが決まっていて、大きくない時はこちらが早い。
    mod = pow(10, 9) + 7

    n_ = pow(10, 6) + 1
    fun = [1] * (n_+1)
    for i in range(1, n_+1):
        fun[i] = fun[i-1] * i % mod
    rev = [1] * (n_+1)
    rev[n_] = pow(fun[n_], mod-2, mod)
    for i in range(n_-1, 0, -1):
        rev[i] = rev[i+1] * (i+1) % mod
    def cmb(n,r):
        if n <= 0 or r < 0 or r > n: return 0
        return fun[n] * rev[r] % mod * rev[n-r] % mod

    #重複組み合わせはH(n, r) = cmb(n+r-1, r)

    N = len(S)
    answer = 0
    for i in range(K+1):
        answer += pow(25, i, mod) * pow(26, K-i, mod) * cmb(N-1+i, N-1) % mod
    print(answer % mod)

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()
Problem p02647 (python)

Fixed submission:
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #C
    #input
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
     
    #output
    #A[i]の電球は i-A[i] から i+A[i]までを照らす。
    import itertools
    K = min(K, 42)
    for _ in range(K):
        dp = [0]*N
        for i in range(N):
            p = max(0, i-A[i])
            dp[p] += 1
            if i+A[i]+1 <= N-1:
                dp[i+A[i]+1] -= 1
        dp = list(itertools.accumulate(dp))
        A = dp
     
    print(" ".join(repr(d) for d in dp))

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #C
    #input
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
     
    #output
    #A[i]の電球は i-A[i] から i+A[i]までを照らす。
    import numpy as np  
    K = min(K, 42)
    for _ in range(K):
        dp = np.zeros(N, int)
        for i in range(N):
            p = max(0, i-A[i])
            dp[p] += 1
            if i+A[i]+1 <= N-1:
                dp[i+A[i]+1] -= 1
        dp = np.cumsum(dp)
        A = dp
     
    print(" ".join(repr(d) for d in dp))    

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

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

#output
#A[i]の電球は i-A[i] から i+A[i]までを照らす。
import numpy as np  

for _ in range(42):
    dp = np.zeros(N, int)
    for i in range(N):
        p = max(0, i-A[i])
        dp[p] += 1
        if i+A[i]+1 <= N-1:
            dp[i+A[i]+1] -= 1
    A = np.cumsum(dp)

if K > 41:
  print(np.array([N]*N, int)
else:
  print(np.cumsum(dp))
Problem p02708 (python)

Fixed submission:
#input
N, K = map(int, input().split())

#output
mod = pow(10, 9) + 7
answer = 0
for i in range(K, N+2):
    answer += ((N*(N+1)//2)  - ((N-i)*(N-i+1)//2) - (i*(i-1)//2) + 1) % mod

print(answer % mod)

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

#output
answer = 0
for i in range(K, N+2):
    answer += ((N*(N+1)//2)  - ((N-i)*(N-i+1)//2) - (i*(i-1)//2) + 1) % mod

print(answer % mod)
Problem p02709 (python)

Fixed submission:
#python3ではTLE
#input
N = int(input())
A = list(map(int, input().split()))

#output
B = [(i, a) for i, a in enumerate(A)]
B = sorted(B, key = lambda x:x[1], reverse = True)

dp = [[0] * (N+1) for i in range(N+1)]
#dp[i, j]を左i, 右jまで場所が決まった状態の最大値とする。
#i+j = Nとなる場合の最大値が答えとなる。

answer = 0
for i in range(N):
    dp[i+1][0] = dp[i][0] + B[i][1]*(abs(B[i][0]-i))
    for j in range(N):
        dp[0][j+1] = dp[0][j] + B[j][1]*(abs(N-1-B[j][0]-j))
        if i+j+1 < N:
            dp[i+1][j+1] = max(dp[i][j+1]+B[i+j+1][1]*(abs(B[i+j+1][0]-i)), dp[i+1][j] + B[i+j+1][1]*(abs(N-1-B[i+j+1][0]-j)))
    answer = max(answer, dp[i][N-i])

print(answer)

Buggy submission (verdict: Runtime Error):
#input
N = int(input())
A = np.array(list(map(int, input().split())))

#output
import numpy as np    
idx = np.argsort(-A)

dp = np.zeros((N+1, N+1), int)
#dp[i, j]を左i, 右jまで場所が決まった状態の最大値とする。
#i+j = Nとなる場合の最大値が答えとなる。
for i in range(N):
    dp[i+1, 0] = dp[i, 0] + A[idx[i]]*(abs(idx[i]-i))
for j in range(N):
    dp[0, j+1] = dp[0, j] + A[idx[j]]*(abs(N-1-idx[j]-j))

for i in range(N):
    for j in range(N):
        if i+j+1 < N:
            dp[i+1, j+1] = max(dp[i, j+1]+A[idx[i+j+1]]*(abs(idx[i+j+1]-i)), dp[i+1, j] + A[idx[i+j+1]]*(abs(N-1-idx[i+j+1]-j)))

answer = 0        
for i in range(N):
    answer = max(answer, dp[i, N-i])

print(answer)
Problem p02720 (python)

Fixed submission:
import queue

#input
K = int(input())

#output
q = queue.Queue()
for i in range(1, 10):
    q.put(i)

for i in range(1, K+2):
    x = q.get()
    if x % 10 != 0:
        q.put(10*x + (x % 10)-1)
    q.put(10*x+(x % 10))
    if x % 10 != 9:
        q.put(10*x + (x % 10)+1)
    if i == K:
        print(x)

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

#output
q = queue.Queue()
for i in range(1, 10):
    q.put(i)

for i in range(1, K+2):
    x = q.get()
    if x % 10 != 0:
        q.put(10*x + (x % 10)-1)
    q.put(10*x+(x % 10))
    if x % 10 != 9:
        q.put(10*x + (x % 10)+1)
    if i == K:
        print(x)