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

Fixed submission:
import sys
n,t=map(int,input().split())
T=list(map(int,input().split()))
ans=0
starttime=0
endtime=0
for i in T:
  if endtime>=i:
    endtime=endtime-(endtime-i)+t
  else:
    ans+=endtime-starttime
    starttime=i
    endtime=i+t
ans+=endtime-starttime
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
n,t=map(int,input().split())
T=[int(i) for i in sys.stdin]
endtime=0
for i in t:
  if endtime>i+t:
    endtime=endtime-(endtime-i)+t
print(endtime)
Problem p03739 (python)

Fixed submission:
n=int(input())
p=list(map(int,input().split()))
p2=[i for i in p]
stack=[0]*(n+1)
ans=0
if p[0]<=0:
  ans+=1-p[0]
  p[0]=1
  stack[1]=1
else:
  stack[1]=p[0]
for i in range(1,n):
  if i%2==1:
    if p[i]+p[i-1]+stack[i-1]>=0:
      ans+=(p[i]+p[i-1]+stack[i-1])+1
      p[i]-=(p[i]+p[i-1]+stack[i-1])+1
  else:
    if p[i]+p[i-1]+stack[i-1]<=0:
      ans+=-(p[i]+p[i-1]+stack[i-1])+1
      p[i]+=-(p[i]+p[i-1]+stack[i-1])+1
  stack[i+1]=p[i]+p[i-1]+stack[i-1]
stack=[0]*(n+1)
ans2=0
if p2[0]>=0:
  ans2+=p2[0]+1
  p2[0]=-1
  stack[1]=-1
else:
  stack[1]=p2[0]
for i in range(1,n):
  if i%2==0:
    if p2[i]+p2[i-1]+stack[i-1]>=0:
      ans2+=(p2[i]+p2[i-1]+stack[i-1])+1
      p2[i]-=(p2[i]+p2[i-1]+stack[i-1])+1
  else:
    if p2[i]+p2[i-1]+stack[i-1]<=0:
      ans2+=-(p2[i]+p2[i-1]+stack[i-1])+1
      p2[i]+=-(p2[i]+p2[i-1]+stack[i-1])+1
  stack[i+1]=p2[i]+p2[i-1]+stack[i-1]
print(min(ans,ans2))

Buggy submission (verdict: Runtime Error):
n=int(input())
p=list(map(int,input().split()))
stack=[0]*(n+1)
ans=0
if p[0]==0:
  p[0]=1
  ans+=1
  stack[1]=1
else:
  stack[1]=p[0]
for i in range(1,n):
  if i%2==1:
    if p[i]+p[i-1]+stack[i-1]>=0:
      p[i]-=(p[i]+p[i-1]+stack[i-1])+1
      ans+=(p[i]+p[i-1]+stack[i-1])+1
  else:
    if p[i]+p[i-1]+stack[i-1]<=0:
      p[i]+=-(p[i]+p[i-1]+stack[i-1])+1
      ans+=-(p[i]+p[i-1]+stack[i-1])+1
  stack=p[i]+p[i-1]+stack[i-1]
print(ans)
Problem p03814 (python)

Fixed submission:
s=list(input())
x=s.index('A')
t=list(reversed(s))
y=t.index('Z')
print(len(s)-x-y)

Buggy submission (verdict: Runtime Error):
s=list(input())
x=s.index('A')
t=reversed(s)
y=t.index('Z')
print(len(s)-x-y)
Problem p03854 (python)

Fixed submission:
s=input()
while len(s)>4:
  if s[-5:]=='dream':
    s=s[:-5]
  elif s[-5:]=='erase':
    s=s[:-5]
  elif len(s)<6:
    print('NO')
    exit()
  elif s[-6:]=='eraser':
    s=s[:-6]
  elif len(s)<7:
    print('NO')
    exit()
  elif s[-7:]=='dreamer':
    s=s[:-7]
  else:
    print('NO')
    exit()
print('YES')

Buggy submission (verdict: Runtime Error):
s=input()
while s>0:
  if s[-5:]=='dream':
    s=s[:-5]
  elif s[-5:]=='erase':
    s=s[:-5]
  elif s[-6:]=='eraser':
    s=s[:-6]
  elif s[:-7]=='dreamer':
    s=s[:-7]
  else:
    print('NO')
    exit()
print('YES')
Problem p03945 (python)

Fixed submission:
s=input()
ans=0
for i in range(len(s)-1):
  if s[i]!=s[i+1]:
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
ans=0
for i in range(len(s):):
  if s[i]!=s[i+1]:
    ans+=1
print(ans)
Problem p03999 (python)

Fixed submission:
n=input()
ans=0
def dfs(i,flag):
  global ans
  if i!=len(n)-1:
    dfs(i+1,flag)
    dfs(i+1,flag|2**i)
  else:
    num=[]
    start=0
    for i in range(len(n)):
      if flag&2**i>0:
        num.append(int(n[start:i+1]))
        start=i+1
    if start!=n:
      num.append(int(n[start:]))
    ans+=sum(num)
dfs(0,0)
print(ans)

Buggy submission (verdict: Runtime Error):
n=input()
ans=0
def dfs(i,flag):
  global ans
  if i!=len(n)-1:
    dfs(i+1,flag)
    dfs(i+1,flag|2**i)
  else:
    num=[]
    start=0
    for i in range(len(n)):
      if flag&2**i>0:
        num.append(n[start:i+1])
        start=i+1
    ans+=sum(num)

dfs(0,0)
print(ans)

Buggy submission (verdict: Runtime Error):
n=input()
ans=0
def dfs(i,flag):
  if i!=len(n)-1:
    dfs(i+1,flag)
    dfs(i+1,flag|2**i)
  else:
    num=[]
    start=0
    for i in range(len(n)):
      if flag&2**i>0:
        num.append(n[start:i+1])
        start=i+1
    ans+=sum(num)

dfs(0,0)
print(ans)
Problem p04013 (python)

Fixed submission:
n,a=map(int,input().split())
x=list(map(int,input().split()))
stack=[0]*5001
stack[2500]=1
ans=0
for i in range(len(x)):
  x[i]-=a
for i in x:
  ans+=stack[2500-i]
  stack2=[i for i in stack]
  for j in range(5001):
    if 0<=j+i<=5000:
      stack2[j+i]+=stack[j]
  stack=[i for i in stack2]
print(stack[2500]-1)

Buggy submission (verdict: Runtime Error):
n,a=map(int,input().split())
x=list(map(int,input()))
stack=[0]*5001
stack[2500-a]=1
ans=0
for i in x:
  i-=a
for i in x:
  ans+=stack[2500-i+a]
  stack2=[i for i in stack]
  for j in range(5001):
    if 0<=j+i<=5000:
      stack2[j+i]+=stack[j]
  stack=[i for i in stack2]
print(stack[2500])
Problem p04044 (python)

Fixed submission:
n,l=map(int,input().split())
ans=[]
for i in range(n):
  s=list(input())
  ans.append(s)
ans.sort()
answer=""
for i in ans:
  p="".join(i)
  answer+=p
print(answer)

Buggy submission (verdict: Runtime Error):
n,l=map(int,input().split())
ans=[]
for i in range(n):
  s=list(input())
  ans.append(s)
ans.sort()
answer=""
for i in ans:
  answer+=i
print(answer)
Problem p02642 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
A_div = [0] * (10 ** 6 + 1)

for a in A:
    A_div[a] += 1
    if A_div[a] == 1:
        for j in range(2 * a, 10 ** 6 + 1, a):
            A_div[j] += 100

print(A_div.count(1))

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

answer = N
A_div = [0 for _ in range(N)]
for i in range(N):
    for j in range(i + 1, N):
        if A[i] % A[j] == 0:
            answer -= 1
            break

if A[-1] % A[-2] == 0:
    print(answer - 1)
else:
    print(answer)

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

A_div = [0 for _ in range(N)]
if len(A) == 1:
    print(0)
else:
    for i in range(N):
        if A_div[i] == 0:
            for j in range(i + 1, N):
                if A[i] % A[j] == 0:
                    A_div[i] += 1
                if A[j] % A[i] == 0:
                    A_div[j] += 1

    print(A_div.count(0))
Problem p02646 (python)

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

a_dis = V * T
b_dis = W * T
dis_diff = abs(B - A)

if dis_diff <= a_dis - b_dis:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
if A == B:
    print('YES')
elif A < B:
    print('NO')
else:
    if A + V * T >= B + W * T:
        print('YES')
    else:
        print('NO')
Problem p02684 (python)

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

index = 1
route = [index]
node = {index}

for i in range(1, K + 1):
    index = A[index - 1]
    if index in node:
        pre = route.index(index)
        loop = len(route)
        route_idx = (K - pre) % (loop - pre) + pre
        print(route[route_idx])
        break
    else:
        route.append(index)
        node.add(index)
else:
    print(index)

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

node = [0] * (N + 1)
index = 1
loop_flag = False

for i in range(1, K + 1):
    tmp = A[index - 1]
    if not node[tmp]:
        index = tmp
        node[index] += i
    else:
        pre = node[tmp]
        loop = index - node[tmp]
        if loop > 1:
            answer = node.index((K - pre) % loop + pre)
        else:
            answer = tmp
        loop_flag = True
        print(answer)
        break

if loop_flag == False:
    print(index)

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

node = [0] * (N + 1)
index = 1
loop_flag = False

for i in range(1, K + 1):
    tmp = A[index - 1]
    if not node[tmp]:
        index = tmp
        node[index] += i
    else:
        pre = node[tmp]
        loop = index - node[tmp]
        if loop > 1:
            answer = node.index((K - pre) % loop + pre)
        else:
            answer = tmp
        loop_flag = True
        print(answer)
        break

if loop_flag:
    print(index)

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

node = [0] * (N + 1)
index = 1
loop_flag = False

for i in range(1, N + 1):
    tmp = A[index - 1]
    if not node[tmp]:
        index = tmp
        node[index] += i
    else:
        pre = node[tmp]
        loop = index - node[tmp]
        if loop > 1:
            answer = node.index((K - pre) % loop + pre)
        else:
            answer = tmp
        loop_flag = True
        print(answer)
        break

if loop_flag:
    print(index)
Problem p02888 (python)

Fixed submission:
import bisect
N=int(input())
L=list(map(int, input().split()))
ans=0
L_LENGTH=len(L)
L=sorted(L)
for i in range(L_LENGTH-2):
    for j in range(i+1, L_LENGTH-1):
        a=L[i]+L[j]
        idx=bisect.bisect_left(L, a)
        ans+=max(0, idx-j-1)
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
N=int(input())
L=list(map(int, input().split()))
ans=0
L_LENGTH=len(L)
L=sorted(L)
for i in range(L_LENGTH-2):
    for j in range(i+1, L_LENGTH-1):
        a=L[i]+L[j]
        idx=bisect.bisect_left(l, t)
        ans+=max(0, idx-j-1)
print(ans)
Problem p03000 (python)

Fixed submission:
N, X = map(int, input().split())
e = [int(i) for i in input().split()]
count = 1
d = 0
for i in range(N):
    d += e[i]
    if d > X:
        break
    else:
        count += 1

print(count)

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
e = [int(i) for i in input().split()]
count = 0
d = 0
for i in range(N+1):
    count += 1
    d += e[i]
    if d > X:
        break

print(count)
Problem p03005 (python)

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

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]
A = sorted(A)
removeNums = []
for i in range(len(A)-1):
    newValue = A[0] - A[-1]
    removeNums.append((A[0], A[-1]))
    A.remove(A[0])
    A.remove(A[-1])
    A.insert(0, newValue)

print(-1*A[0])
for i in range(len(removeNums)-1):
    print(removeNums[i][0], removeNums[i][1])

print(removeNums[-1][1], removeNums[-1][0])
Problem p03006 (python)

Fixed submission:
from collections import defaultdict
n = int(input())
s = [list(map(int,input().split())) for i in range(n)]
s.sort()
c = []
if n == 1:
    print(1)
else:
    for i in range(n):
        for j in range(i+1,n):
            x = s[j][0] - s[i][0]
            y = s[j][1] - s[i][1]
            c.append(str(x) + " " + str(y))
    r = defaultdict(int)
    for g in c:
        r[g] += 1
    q = list(r.values())
    q1 = max(q)
    print(n-q1)

Buggy submission (verdict: Runtime Error):
import collections
N = int(input())
e = [[int(i) for i in input().split()] for i in range(N)]
x = 0
y = 0
tupleArray = []
for i in range(N-1):
    for j in range(i+1, N):
        x = e[i][0] - e[j][0]
        y = e[i][1] - e[j][1]
        t1 = (x, y)
        tupleArray.append(t1)
c = collections.Counter(tupleArray)
print(N - c.most_common()[0][1])
Problem p02683 (python)

Fixed submission:
import itertools
import numpy as np

n, m, x = map(int, input().split())
books = [list(map(int, input().split())) for i in range(n)]

coin = []
for i in range(1, n+1):
  for v in itertools.combinations(books, i):
    comb = list(v)
    result = np.sum(comb, axis = 0)
    
    flag = True
    for j in range(1,m+1):
      if result[j] < x:
        flag = False
        break
    if flag:
      coin.append(result[0])

if len(coin) > 0:
  coin.sort(reverse=False)
  print(coin[0])
else:
  print(-1)

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

n, m, x = map(int, input().split())
books = [list(map(int, input().split())) for i in range(n)]

coin = []
for i in range(1, m+1):
  for v in itertools.combinations(books, i):
    comb = list(v)
    result = np.sum(comb, axis = 0)
    if result[1] >= x and result[2] >= x and result[3] >= x:
      coin.append(result[0])

if len(coin) > 0:
  sorted(coin, reverse=False)
  print(coin[0])
else:
  print(-1)
Problem p02573 (python)

Fixed submission:
import sys
sys.setrecursionlimit(99999999)


[n,m]=list(map(int,input().split()))
friends=[]
for i in range(m):
    friends.append(list(map(int,input().split())))

tomodachi=[[]for i in range(n)]

for i in range(m):
    tomodachi[friends[i][0]-1].append(friends[i][1]-1)
    tomodachi[friends[i][1]-1].append(friends[i][0]-1)

for i in range(n):
    tomodachi[i]=list(set(tomodachi[i]))

namelist=[1 for i in range(n)]
teams=[]

def haba(x,kari,tomodachi,namelist):
    for i in range(len(tomodachi[x])):
        if namelist[tomodachi[x][i]]==1:#生き残っているなら
            kari.append(tomodachi[x][i])
            namelist[tomodachi[x][i]]=0#殺す
            haba(tomodachi[x][i],kari,tomodachi,namelist)
    return(kari)
            


for i in range(n):
    if namelist[i]==1:
        teams.append(list(set(haba(i,[i],tomodachi,namelist))))

saidai=0

for i in range(len(teams)):
    if saidai<len(teams[i]):
        saidai=len(teams[i])

ans=saidai

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N,M = map(int,input().split())
count = [[0]*N for _ in range(N)]
fr = [[] for _ in range(N)]
for _ in range(M):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    if count[a][b] == 1:
        continue
    count[a][b] = 1
    count[b][a] = 1
    fr[a].append(b)
    fr[b].append(a)
used = [-1]*N #-1なら未探索。数字はrenketuのindex
renketu = []
index = 0
def dfs(fr,cur,parent,index,li):
    children = fr[cur]
    for chi in children:
        if chi == parent or used[chi] != -1:
            continue
        used[chi] = index
        li.append(chi)
        dfs(fr,chi,cur,index,li)
for i in range(N):
    if used[i] != -1:
        continue
    li = [i]
    used[i] = index
    dfs(fr,i,-1,index,li)
    index += 1
    renketu.append(li)
n = len(renketu)
MAX = 0
for i in range(n):
    lii = renketu[i]
    MAX = max(len(lii),MAX)
print(MAX)
Problem p02647 (python)

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N,K = map(int,input().split())
A = list(map(int,input().split()))
if N == 1:
    print(1)
else:
    
    old = A
    for _ in range(K):
        li = [0]*N
        for i in range(N):
            MIN = max(0,i-old[i])
            MAX = min(N-1,i+old[i])
            li[MIN] += 1
            if MAX != N-1:
                li[MAX+1] -= 1
        s = 0
        for i in range(N):
            s += li[i]
            old[i] = s
        if min(old) == N:
            break
    print(*old)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N,K = map(int,input().split())
A = list(map(int,input().split()))
if N == 1:
    print(1)
else:
    else:
        old = A
        for _ in range(K):
            li = [0]*N
            for i in range(N):
                MIN = max(0,i-old[i])
                MAX = min(N-1,i+old[i])
                li[MIN] += 1
                if MAX != N-1:
                    li[MAX+1] -= 1
            old = accumulate(li)
            old = list(old)
            if min(old) == N:
                break
        print(*old)
Problem p02714 (python)

Fixed submission:
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
N = int(input())
#A = list(map(int,input().split()))
S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
R = []
G = []
B = []
for i in range(N):
    a = S[i]
    if a == "R":
        R.append(i)
    elif a == "G":
        G.append(i)
    else:
        B.append(i)
s = len(R) * len(G) * len(B)
def binary_search(S,key):  #昇順リストSからkeyを探す。
    n = len(S)             #存在したらindex,なかったら-1を返す
    left  = 0
    right = n
    while left < right:
        mid = (left+right) // 2
        if S[mid] == key:
            return mid
        elif S[mid] > key:
            right = mid
        else:
            left = mid + 1
    return -1
for r in R:
    for g in G:
        Min = min(r,g)
        Max = max(r,g)
        if 2 * Min - Max > 0:
            c1 = 2 * Min - Max
        else:
            c1 = -1
        if (Min + Max ) % 2 == 0:
            c2 = (Min + Max) / 2
        else:
            c2 = -1
        if 2 * Max - Min < N:
            c3 = 2 * Max - Min
        else:
            c3 = -1
        if c1 != -1:
            if binary_search(B,c1) != -1:
                s -= 1
        if c2 != -1:
            if binary_search(B,c2) != -1:
                s -= 1
        if c3 != -1:
            if binary_search(B,c3) != -1:
                s -= 1
print(s)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
from bisect import bisect_left
N = int(input())
#A = list(map(int,input().split()))
S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
R = []
G = []
B = []
for i in range(N):
    a = S[i]
    if a == "R":
        R.append(i)
    elif a == "G":
        G.append(i)
    else:
        B.append(i)
s = len(R) * len(G) * len(B)

for r in R:
    for g in G:
        Min = min(r,g)
        Max = max(r,g)
        if 2 * Min - Max > 0:
            c1 = 2 * Min - Max
        else:
            c1 = -1
        if (Min + Max ) % 2 == 0:
            c2 = (Min + Max) / 2
        else:
            c2 = -1
        if 2 * Max - Min < N:
            c3 = 2 * Max - Min
        else:
            c3 = -1
        if c1 != -1:
            if B[bisect_left(B,c1)] == c1:
                s -= 1
        if c2 != -1:
            if B[bisect_left(B,c2)] == c2:
                s -= 1
        if c3 != -1:
            if B[bisect_left(B,c3)] == c3:
                s -= 1
print(s)
Problem p02720 (python)

Fixed submission:
import sys
input=sys.stdin.readline
K = int(input())
LEN = 32345666
#S = input()[:-1]
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
def enqueue(Q,x,tail):#末尾にクラスPの要素xを加える。ぐるっと回った場合
    Q[tail] = x       #以前dequeueで取り出したものが書き換えられる。
    if tail+1 == LEN: #headは先頭のindex,tailは末尾のindex+1
        tail = 0
    else:
        tail += 1
    return tail
def dequeue(Q,head):
    x = Q[head]
    if head+1 == LEN:
        head = 0
    else:
        head += 1
    return x,head
Q = [1,2,3,4,5,6,7,8,9]+[0]*(LEN-9)
head = 0
tail = 9

i = 0
while i < K:
    x,head = dequeue(Q,head)
    if x % 10 == 0:
        tail = enqueue(Q,10*x,tail)
        tail = enqueue(Q,10*x+1,tail)
    elif x % 10 == 9:
        tail = enqueue(Q,10*x+8,tail)
        tail = enqueue(Q,10*x+9,tail)
    else:
        y = x%10
        tail = enqueue(Q,10*x+y-1,tail)
        tail = enqueue(Q,10*x+y,tail)
        tail = enqueue(Q,10*x+y+1,tail)
    i += 1
print(x)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
K = int(input())
LEN = 3234566667
#S = input()[:-1]
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
def enqueue(Q,x,tail):#末尾にクラスPの要素xを加える。ぐるっと回った場合
    Q[tail] = x       #以前dequeueで取り出したものが書き換えられる。
    if tail+1 == LEN: #headは先頭のindex,tailは末尾のindex+1
        tail = 0
    else:
        tail += 1
    return tail
def dequeue(Q,head):
    x = Q[head]
    if head+1 == LEN:
        head = 0
    else:
        head += 1
    return x,head
Q = [1,2,3,4,5,6,7,8,9]+[0]*(LEN-9)
head = 0
tail = 9

i = 0
while i < K:
    x,head = dequeue(Q,head)
    if x % 10 == 0:
        tail = enqueue(Q,10*x,tail)
        tail = enqueue(Q,10*x+1,tail)
    elif x % 10 == 9:
        tail = enqueue(Q,10*x+8,tail)
        tail = enqueue(Q,10*x+9,tail)
    else:
        y = x%10
        tail = enqueue(Q,10*x+y-1,tail)
        tail = enqueue(Q,10*x+y,tail)
        tail = enqueue(Q,10*x+y+1,tail)
    i += 1
print(x)
Problem p02732 (python)

Fixed submission:
import sys
input=sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
def cmb(n):
    if n == 1:
        return 0
    else:
        return n * (n-1) /2
mydict = {}
for i in range(N):
    a = A[i]
    if a in mydict.keys():
        mydict[a] += 1
    else:
        mydict[a] = 1
s = 0
for i in mydict.values():
	s += cmb(i)
for i in range(N):
    a = A[i]
    x = mydict[a] - 1
    print(int(s-x))

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
nCr = {}
def cmb(n, r):
    if n == 0:
        return 0
    if r == 0 or r == n:
         return 1
    if r == 1:
         return n
    if (n,r) in nCr:
         return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
mydict = {}
for i in range(N):
    a = A[i]
    if a in mydict.keys():
        mydict[a] += 1
    else:
        mydict[a] = 1
for i in range(N):
    s = 0
    a = A[i]
    mydict[a] -= 1
    for j in mydict.values():
        s += cmb(j,2)
    print(s)
    mydict[a] += 1
Problem p02742 (python)

Fixed submission:
H,W = map(int,input().split())
if H != 1 and W != 1:
    if (H*W) % 2 == 0:
        print(int(H*W/2))
    elif (H*W) % 2 == 1:
        print(int((H*W+1)/2))
else:
    print(1)

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
if (H*W) % 2 == 0:
    print(int(H*W/2)
if (H*W) % 2 == 1:
    print(int((H*W+1)/2))