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

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]

S = list(input())
K = int(input())
N = len(S)
ans = 0
last_same = False
if N==1:
    print(K//2)
    exit()
for i in range(1,N):
    if S[i]!=S[i-1]:
        break
else:
    print(N*K//2)
    exit()
p = False

#前からと後ろからで連続しているかずをかぞえあげる.
pre_num = 0
l_num = 1
if S[0]==S[-1]:
    pre_num = 1
    for i in range(1,N-1):
        if S[i]==S[i-1]:
            pre_num += 1
        else:
            break
    l_num = 1
    for i in range(N-1,0,-1):
        if S[i]==S[i-1]:
            l_num += 1
        else:
            break

for i in range(pre_num,N-l_num):
    if p:
        p = False
        continue
    if S[i]==S[i+1]:
        ans += 1
        p = True

ANS = (pre_num//2) + ans*K + ((pre_num+l_num)//2)*(K-1) + (l_num//2)

print(ANS)

Buggy submission (verdict: Runtime Error):
import sys
def input():
    return sys.stdin.readline()[:-1]

S = list(input())
K = int(input())
N = len(S)
ans = 0
last_same = False
if N==1:
    print(K//2)
    exit()
for i in range(1,N):
    if S[i]!=S[i-1]:
        break
else:
    print(N*K//2)
    exit()
pre = S[0]
p = False
for i in range(1,N):
    if p:
        pre = S[i]
        p = False
        continue
    s = S[i]
    if pre==s:
        ans += 1
        p = True
        if i==N-1:
            last_same = True
        elif i==N-2:
            if S[-1]==S[-2]:
                last_3_same = True
    pre = s

l_same = False
if not last_same:
    if not S[0]==S[1]:
        if S[0]==S[-1]:
            ans += 1
            l_same = True
    elif S[1]==S[2]:
        if last_3_same:
            ans += 1
            l_same = True

ANS = ans*K
if l_same:
    ANS -= 1
print(ANS)

Buggy submission (verdict: Runtime Error):
import sys
def input():
    return sys.stdin.readline()[:-1]

S = list(input())
K = int(input())

N = len(S)
ans = 0
last_same = False
if S[-1]!=S[-2]:
    if S[0]==S[-1]:
        ans += 1
        last_same = True
pre = S[0]
p = False
for i in range(1,N):
    if p:
        pre = S[i]
        p = False
        continue
    s = S[i]
    if pre==s:
        ans += 1
        p = True
    pre = s
ANS = ans*K
if last_same:
    ANS -= 1
print(ANS)
Problem p03041 (python)

Fixed submission:
H,W = map(int,input().split(' '))
N = list(input())
N[W-1] = N[W-1].lower()
print("".join(N))

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split(' '))
N = list(input())
N[W] = N[W].lower()
print("".join(N))
Problem p02792 (python)

Fixed submission:
N = int(input())
ans = 0
tmp = int("0"+str(N)[1:-1])
NR = int(str(N)[-1])
for i in range(1,N+1):
    L = int(str(i)[0])
    R = int(str(i)[-1])
    if R == 0:
        continue
    if L == R:
        ans += 1
    for j in range(1,6):
        mini = (R*10**j) +L
        maxi = ((R+1)*10**j) +L-10
        if N < mini:
            break
        if maxi <= N:
            ans += 10**(j-1)
            continue
        
        if L <= NR:
            ans += tmp+1
        else:
            ans += tmp
        break
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = 0
tmp = int(str(N)[1:-1])
NR = int(str(N)[-1])
for i in range(1,N+1):
    L = int(str(i)[0])
    R = int(str(i)[-1])
    if R == 0:
        continue
    if L == R:
        ans += 1
    for j in range(1,6):
        mini = (R*10**j) +L
        maxi = ((R+1)*10**j) +L-10
        if N < mini:
            break
        if maxi <= N:
            ans += 10**(j-1)
            continue
        
        if L <= NR:
            ans += tmp+1
        else:
            ans += tmp
        break
print(ans)
Problem p02847 (python)

Fixed submission:
S = input()
if S == "SUN":
    print(7)
if S == "MON":
    print(6)
if S == "TUE":
    print(5)
if S == "WED":
    print(4)
if S == "THU":
    print(3)
if S == "FRI":
    print(2)
if S == "SAT":
    print(1)

Buggy submission (verdict: Runtime Error):
S = input()
if S = "SUN":
    print(7)
if S = "MON":
    print(6)
if S = "TUE":
    print(5)
if S = "WED":
    print(4)
if S = "THU":
    print(3)
if S = "FRI":
    print(2)
if S = "SAT":
    print(1)
Problem p02863 (python)

Fixed submission:
N,T = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB.sort(key = lambda x:x[0])
dp = [0]*(T+1)
for A,B in AB:  #それぞれの食事について
    for i in range(T-1,-1,-1):
        if A+i>=T:  #時間オーバー
            dp[T] = max(dp[T], dp[i]+B)
        else:   #時間内
            dp[i+A] = max(dp[i+A],dp[i]+B)
#これが成り立つのはAB.sortしているから
print(max(dp))

Buggy submission (verdict: Runtime Error):
N,T = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N):
AB.sort(key = lambda x:x[0])
dp = [0]*(T+1)
for A,B in AB:  #それぞれの食事について
    for i in range(T-1,-1,-1):
        if A+i>=T:  #時間オーバー
            dp[T] = max(dp[T], dp[i]+B)
        else:   #時間内
            dp[i+A] = max(dp[i+A],dp[i]+B)
#これが成り立つのはAB.sortしているから
print(max(dp))
Problem p02891 (python)

Fixed submission:
S=list(input())
K=int(input())
S2 = S*2
tmp=0
tmp2=0

if all([S[i] == S[0] for i in range(1,len(S))]):
    print((len(S)*K)//2)
    exit()
for i in range(1,len(S)):
    if S[i-1]==S[i]:
        S[i]="0"
        tmp += 1

for i in range(1,len(S2)):
    if S2[i-1]==S2[i]:
        S2[i]="0"
        tmp2 += 1

print(tmp+(tmp2-tmp)*(K-1))

Buggy submission (verdict: Runtime Error):
S=input()
K=int(input())
S2 = S*2
tmp=0
tmp2=0
for i in range(1,S):
    if S[i-1]==S[i]:
        S[i]="0"
        tmp += 1

for i in range(1,S2):
    if S2[i-1]==S2[i]:
        S2[i]="0"
        tmp2 += 1
print(tmp+(tmp2-tmp)*(K-1))

Buggy submission (verdict: Runtime Error):
S=input()
K=int(input())
S2 = S*2
tmp=0
tmp2=0
for i in range(1,S):
    if S[i-1]==S[i]:
        S[i]="0"
        tmp += 1

for i in range(1,S2):
    if S2[i-1]==S2[i]:
        S[i]="0"
        tmp2 += 1
print(tmp+tmp*(K-1))
Problem p02990 (python)

Fixed submission:
N,K = map(int,input().split())
M = 10**9+7
def nCr(n, r, mod=10**9+7):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

for i in range(1,K+1):
    if N-K+1 < i:
        print(0)
        continue
    else:
        print((nCr(N-K+1,i)*nCr(K-1,i-1))%M)

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

def nCr(n, r, mod=10**9+7):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

for i in range(1,K+1):
    if N-K+1 < i:
        print(0)
        continue
    else:
        print((nCr(N-K+1,i)*nCr(K-1,i-1))%M)
Problem p03127 (python)

Fixed submission:
from fractions import gcd
#from math import gcd
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in A[1:]:
    ans = gcd(ans,i)
    if ans ==1:
        break
print(ans)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
from math import gcd
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in A[1:]:
    ans = gcd(ans,i)
    if ans ==1:
        break
print(ans)
Problem p02773 (python)

Fixed submission:
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/C-.py
#
import collections

n = int(input())
l = [str(input()) for i in range(n)]
# l = ["beat", "vet", "beet", "bed", "vet", "bet", "beet"]
c = collections.Counter(l)
number_of_words = len(c)
counted_list = c.most_common()
ans_before_sort = [counted_list[0][0]]

for i in range(number_of_words-1):
    if counted_list[i][1] == counted_list[i+1][1]:
        ans_before_sort.append(counted_list[i+1][0])
    else:
        break

ans_after_sort = sorted(ans_before_sort)
print('\n'.join(ans_after_sort))

Buggy submission (verdict: Runtime Error):
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/C-.py
#
import collections

n = int(input())
l = [str(input()) for i in range(n)]
# l = ["beat", "vet", "beet", "bed", "vet", "bet", "beet"]
c = collections.Counter(l)
number_of_words = len(c)
ans_before_sort = [c.most_common()[0][0]]

for i in range(number_of_words):
    if c.most_common()[i][1] == c.most_common()[i+1][1]:
        ans_before_sort.append(c.most_common()[i+1][0])
    else:
        break

ans_after_sort = sorted(ans_before_sort)
print('\n'.join(ans_after_sort))
Problem p02831 (python)

Fixed submission:
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/C-Snack.py
#
from fractions import gcd

a, b = map(int, input().split())
ans = int(a * b // gcd(a, b))
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/C-Snack.py
#
import math

a, b = map(int, input().split())
ans = int(a * b / math.gcd(a, b))
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/C-Snack.py
#
import math

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


def lcm(a: int, b: int) -> int:
    return a * b / math.gcd(a, b)


print(int(lcm(a, b)))
Problem p02712 (python)

Fixed submission:
# -*- coding: <encoding name> -*-

n = int(input())
total = 0
for i in range(1, n + 1):
	if (i % 3) != 0 and (i % 5) != 0:
		total += i
print(total)

Buggy submission (verdict: Runtime Error):
# -*- coding: <encoding name> -*-

n = int(input())
total = 0
for i in range(1, n + 1):
	if (i % 3) != 0 and (i % 5) != 0:
		total +=
print(total)

Buggy submission (verdict: Runtime Error):
# -*- coding: <encoding name> -*-

n = int(input())
total = 0
for i in range(1, n + 1):
	if i % 3 != 0 and i % 5 != 0:
		total +=
print(total)
Problem p02759 (python)

Fixed submission:
# -*- coding: <encoding name> -*-

import math
n = int(input())
print(math.ceil(n / 2))

Buggy submission (verdict: Runtime Error):
# -*- coding: <encoding name> -*-

import math
n = map(int, input())
print(math.ceil(n / 2))

Buggy submission (verdict: Runtime Error):
# -*- coding: <encoding name> -*-

import math
n = map(int, input())
print(math.ceil(n / 2)

Buggy submission (verdict: Runtime Error):
# -*- coding: <encoding name> -*-

import math
n = map(int, input().split())
print(math.ceil(n / 2)
Problem p02970 (python)

Fixed submission:
# -*- coding: <encoding name> -*-

import math
n, d = map(int, input().split())
range = d * 2 + 1
print(math.ceil(n / range))

Buggy submission (verdict: Runtime Error):
# -*- coding: <encoding name> -*-

import math
n, d = map(int, input())
range = d * 2 + 1
print(math.ceil(n / range))
Problem p03135 (python)

Fixed submission:
# -*- coding: <encoding name> -*-
'''
T, X = int(input())
print(T / X)
'''
T, X = map(int, input().split())
print(T / X)

Buggy submission (verdict: Runtime Error):
# -*- coding: <encoding name> -*-
'''
T, X = int(input())
print(T / X)
'''
 T, X = map(int, input().split())
 print(T / X)

Buggy submission (verdict: Runtime Error):
# -*- coding: <encoding name> -*-
'''
T, X = int(input())
print(T / X)
'''
 T, X = map(int, input().split())
 print(T / X)

Buggy submission (verdict: Runtime Error):
# -*- coding: <encoding name> -*-
'''
T, X = int(input())
print(T / X)
'''
 T, X = map(int(input()))
 print(T / X)

Buggy submission (verdict: Runtime Error):
# -*- coding: <encoding name> -*-

T, X = int(input())
print(T / X)
Problem p02753 (python)

Fixed submission:
S = input()

if S[0] == S[1] == S[2]:
    print('No')
else:
    print('Yes')

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

if S[0] == S[1] == S[2]:
    print('No')
else:
    print('Yes')
Problem p02712 (python)

Fixed submission:
n = int(input())
add = 0
for i in range(1, n+1):
  if i%3!=0:
    if i%5!=0:
      add += i
print(add)

Buggy submission (verdict: Runtime Error):
n = int(input)
add = 0
for i in range(n):
  if i%3!=0:
    if i%5!=0:
      add += i
print(i)
Problem p02847 (python)

Fixed submission:
s = input()
if s =="SUN":
    print(7)
elif s =="MON":
    print(6)
elif s=="TUE":
    print(5)
elif s =="WED":
    print(4)
elif s=="THU":
    print(3)
elif s=="FRI":
    print(2)
else:print(1)

Buggy submission (verdict: Runtime Error):
s = int(input())
if s =="SUN":
  print(7)
elif s =="MON":
  print(6)
elif s=="TUE":
  print(5)
elif s =="WED":
  print(4)
elif s=="THU":
  print(3)
elif s=="FRI":
  print(2)
else:print(1)
Problem p03135 (python)

Fixed submission:
T,X = map(int, input().split())
print(T/X)

Buggy submission (verdict: Runtime Error):
T,X = map(int, input().split(" "))
print({T/X:.5f})

Buggy submission (verdict: Runtime Error):
T,X = map(int, input().split(" "))
print(f"{T/X:.5f})
Problem p03805 (python)

Fixed submission:
# 全域木？っていうんだっけ？でもコストは関係ないか
# 適当に隣接リストでもってしてDFSする
N, M = map(int, input().split())
Neighbor_list = [[] for _ in range(N)]
for _ in range(M):
    s, t = map(int, input().split())
    Neighbor_list[s-1].append(t-1)
    Neighbor_list[t-1].append(s-1)


def dfs(cur, path):
    if len(path) == N:
        return 1
    else:
        ret = 0
        for neighbor in Neighbor_list[cur]:
            if neighbor not in path:
                next_list = path[:]
                next_list.append(neighbor)
                ret += dfs(neighbor, next_list)
        return ret


print(dfs(0, [0]))

Buggy submission (verdict: Runtime Error):
# 全域木？っていうんだっけ？でもコストは関係ないか
# 適当に隣接リストでもってしてDFSする
N, M = map(int, input().split())
Neighbor_list = [[] for _ in range(n)]
for _ in range(M):
    s, t = map(int, input().split())
    Neighbor_list[s-1].append(t-1)
    Neighbor_list[t-1].append(s-1)


def dfs(cur, path):
    if len(path) == N:
        return 1
    else:
        ret = 0
        for neighbor in Neighbor_list[cur]:
            if neighbor not in path:
                next_list = path[:]
                next_list.append(neighbor)
                ret += dfs(neighbor, next_list)
        return ret


print(dfs(0, []))
Problem p03013 (python)

Fixed submission:
N, M = map(int, input().split())
a = []
for i in range(M):
    a.append(int(input()))

for n, i in enumerate(a):
    if n > 0:
        if (a[n] - a[n-1]) == 1:
            print(0)
            exit()

dp = [-1] * (N+2)

dp[N] = 1
dp[N+1] = 0
for i in range(M):
    dp[a[i]] = 0

for i in range(N)[::-1]:
    if dp[i] == 0:
        continue
    dp[i] = dp[i+1] + dp[i+2]


print(dp[0]%1000000007)

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

for n, i in enumerate(a):
    if n > 0:
        if (a[n] - a[n-1]) == 1:
            print(0)
            exit()

def search(i, n):
    if i in a:
        return 0
    if i == n:
        return 1
    if i > n:
        return 0
    return search(i+1, n) + search(i+2, n)

ans = 1
start = 0
a.append(N+1)
for num in a:
    ans *= search(start, num-1)
    for i in range(1, N):
        start = num + i
        if start not in a:
            break

print(ans%1000000007)

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

for n, i in enumerate(a):
    if n > 0:
        if (a[n] - a[n-1]) == 1:
            print(0)
            exit()

def search(i, n):
    if i in a:
        return 0
    if i == n:
        return 1
    if i > n:
        return 0
    return search(i+1, n) + search(i+2, n)

ans = 1
start = 0
a.append(N+1)
for num in a:
    ans *= search(start, num-1)
    for i in range(1, N):
        start = num + i
        if start not in a:
            break

print(ans%1000000007)
Problem p03073 (python)

Fixed submission:
s = input()
S = list(s)

ans = 0
if len(S) == 1:
    print(ans)
    exit()
for i in range(1,len(S)):
    if S[i] is S[i-1]:
        if S[i] is '0':
            S[i] = '1'
        else:
            S[i] = '0'
        ans += 1
print(ans)

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

ans = 0
if len(S) == 1:
    print(ans)
    exit()
for i in range(1,len(S)):
    if S[i] is S[i-1]:
        if S[i] is '0':
            S[i] = '1'
        else:
            S[i] = '0'
        print(S)
        ans += 1
print(ans)
Problem p03221 (python)

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

ypi = []

for i in range(M):
    p, y = map(int,input().split())
    ypi.append([y, p, i])

ypi.sort()

rank = [0] * N

ans = [''] * M
for count in range(M):
    y, p, i = ypi[count]
    rank[p-1] += 1
    ans[i] = '{:06}'.format(p)+'{:06}'.format(rank[p-1])

for s in ans:
    print(s)

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

city = [[0] * 100000 for j in range(N)]
citynum = [0] * 100000
citynum_ = [0] * 100000

for i in range(M):
    p, y = map(int, input().split())
    city[p-1][y] = i+1
    citynum[i+1] = p
    citynum_[i+1] = y

rank = [[0] * 100000 for j in range(N)]

for i in range(N):
    count = 0
    for j in range(100000):
        if city[i][j] != 0:
            count += 1
            rank[i][j] = count

citynum2 = [0] * 100000

for i in range(M):
    citynum2[citynum[i+1]] += 1
    ansp = citynum[i+1]
    ansy = rank[ansp-1][citynum_[i+1]]

    print('{:06}'.format(ansp)+'{:06}'.format(ansy))
Problem p03329 (python)

Fixed submission:
N = int(input())

dp = [200000] * 200000
dp[0] = 0

for i in range(N+1):
    for j in range(i+1):
        tmp = 6**j
        if tmp > N or i - tmp < 0:
            break
        dp[i] = min(dp[i], dp[i-tmp]+1)
    for j in range(i+1):
        tmp = 9**j
        if tmp > N or i - tmp < 0:
            break
        dp[i] = min(dp[i], dp[i-tmp]+1)

print(dp[N])

Buggy submission (verdict: Runtime Error):
N = int(input())
memo = [-1] * 200000

def search(i): 
    if i == 0:
        return 0
    if memo[i] != -1:
        return memo[i]
    
    tmp = i
    cnt = 0
    while True: 
        n = 6 ** cnt
        if n > i:
            break       
        tmp = min(tmp, search(i-n)+1)
        cnt += 1
    cnt = 0
    while True:
        n = 9 ** cnt
        if n > i:
            break       
        tmp = min(tmp, search(i-n)+1)
        cnt += 1
    
    memo[i] = tmp
    return tmp

print(search(N))

Buggy submission (verdict: Runtime Error):
N = int(input())
memo = [-1] * 100000

def search(i): 
    if i == 0:
        return 0
    if memo[i] != -1:
        return memo[i]
    
    tmp = i
    cnt = 0
    while True: 
        n = 6 ** cnt
        if n > i:
            break       
        tmp = min(tmp, search(i-n)+1)
        cnt += 1
    cnt = 0
    while True:
        n = 9 ** cnt
        if n > i:
            break       
        tmp = min(tmp, search(i-n)+1)
        cnt += 1
    
    memo[i] = tmp
    return tmp

print(search(N))
Problem p03013 (python)

Fixed submission:
N,M = map(int, input().split())
arr = [int(input()) for _ in range(0,M)]
MOD = 10**9 + 7
stairs = [True for _ in range(0,N+1)]
for x in arr:
    stairs[x] = False

dp = [0 for _ in range(0,N+1)]

dp[0] = 1 if 0 not in arr else 0
dp[1] = 1 if 1 not in arr else 0

for i in range(2,N+1):
    if dp[i-1] == 0 and dp[i-2] == 0:
        break
    if stairs[i-1]: dp[i] += dp[i-1]
    if stairs[i-2]: dp[i] += dp[i-2]

    dp[i] %= MOD

print(dp[-1] % MOD)

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

arr = [-1]+arr+[N+1]
from math import factorial
count = 0
for i in range(0,len(arr)-1):
    start,end = arr[i],arr[i+1]
    span = end - start - 2 # the first step is taken by a certain step (with no choice)
    if span < 0:
        count = 0 # impossible
        break 
    nptn = int(span/2)
    regional_count = 0

    for k in range(0,nptn+1):
        #regional_count += factorial(span-k) // factorial(k) // factorial(span-2*k)
        mul = lambda a,b: a*b
        regional_count += reduce(mul, range(span-k,k,-1),1) // reduce(mul, range(1,span-2*k+1),1)
    
    if count == 0:
        count += regional_count
    else:
        count *= regional_count
print(count % 1000000007)

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

arr = [-1]+arr+[N+1]
from math import factorial
count = 0
for i in range(0,len(arr)-1):
    start,end = arr[i],arr[i+1]
    span = end - start - 2 # the first step is taken by a certain step (with no choice)
    nptn = int(span/2)
    regional_count = 0
    print(span,nptn)
    for k in range(0,nptn+1):
        print(span,k,factorial(span-k)//factorial(k)//factorial(span-2*k))
        regional_count += factorial(span-k) // factorial(k) // factorial(span-2*k)
    print(regional_count)
    if count == 0:
        count += regional_count
    else:
        count *= regional_count
print(count % 1000000007)
Problem p02726 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
from collections import deque
n,x,y = map(int,input().split())
g = [[]for i in range(n)]
g[0].append(1)
g[n-1].append(n-2)
g[x-1].append(y-1)
g[y-1].append(x-1)
for i in range(1,n-1):
  g[i].append(i-1)
  g[i].append(i+1)
ans = [0]*(n-1)
def dfs(b,c):
  for i in g[b]:
    if a[i] > c+1:
      a[i] = c+1
      que.append([i,c+1])
    
for i in range(n):
  a = [999999999]*n
  a[i] = 0
  que = deque()
  que.append([i,0])
  while que:
    x,y = que.popleft()
    dfs(x,y)
  for j in a:
    if j == 0:
      continue
    ans[j-1] += 1
for i in ans:
  print(i//2)

Buggy submission (verdict: Runtime Error):
n,x,y = map(int,input().split())
g = [[]for i in range(n)]
g[0].append(1)
g[n-1].append(n-2)
g[x-1].append(y-1)
g[y-1].append(x-1)
for i in range(1,n-1):
  g[i].append(i-1)
  g[i].append(i+1)
ans = [0]*(n-1)
def dfs(b,c):
  for i in g[b]:
    if a[i] > c+1:
      a[i] = c+1
      dfs(i,c+1)
    
for i in range(n):
  a = [999999999]*n
  a[i] = 0
  dfs(i,0)
  for j in a:
    if j == 0:
      continue
    ans[j-1] += 1
for i in ans:
  print(i//2)
Problem p03346 (python)

Fixed submission:
n = int(input())
t = [0]*n
for i in range(n):
    p = int(input())-1
    t[p] = i
maxi = 1
c = 1
for i in range(n-1):
  a = t[i]
  b = t[1+i]
  if a < b:
    c += 1
  else:
    maxi = max(c,maxi)
    c = 1
maxi = max(c,maxi)
print(n - maxi)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = [int(input()) for i in range(N)]
c = 0
dai = a.index(2)
for i in range (1,N):
  ti = a.index(i)
  dai = a.index(i+1)
  if  ti <  dai:
      c += 1
  else:
     break
d = 0
for  i  in range (N,1,-1):
  dai  =  a.index(i)
  ti =  a.index(i-1)
  if   ti < dai:
    d += 1
  else:
    break
jo =  max(c,d)
ans = N - jo - 1
print(ans)
Problem p03426 (python)

Fixed submission:
import numpy as np
H,W,D = map(int,input().split())
a = [input().split() for l in range(H)]
basyo = [[0,0] for i in range(H*W)]
for i in range(W):
  for j in range(H):
    basyo[int(a[j][i])-1] = [j,i]
Q = int(input())
b = [input().split() for l in range(Q)]
ans = []
memo = [0] * (H*W+1)
for i in range(D):
  while i < H*W:
    i += D
    if i >= H*W:
      break
    memo[i] = memo[i-D]  + abs(basyo[i][0] - basyo[i-D][0]) + abs(basyo[i-D][1] - basyo[i][1])
b = np.array(b)
b = np.int64(b)
for i in range(Q):
  syo = b[i,0]
  go = b[i,1]
  print(memo[go-1] - memo[syo-1])

Buggy submission (verdict: Runtime Error):
import numpy as np
H,W,D = map(int,input().split())
a = [input().split() for l in range(H)]
Q = int(input())
b = [input().split() for l in range(Q)]
a = np.array(a)
b = np.array(b)
a = np.int64(a)
b = np.int64(b)
ans = []
memo = [[-1]*302 for i in range(302)]
for i in range(Q):
  syo = b[i,0]
  go = b[i,1]
  if memo[syo][go] != -1:
    ans.append(memo[syo][go])
    continue
  syouhi = 0
  while syo != go:
    c = np.where(a == syo)
    syo += D
    d = np.where(a == syo)
    syouhi += abs(c[0][0] - d[0][0]) + abs(c[1][0] - d[1][0])
  ans.append(syouhi)
  memo[syo][go] = syouhi
for i in range(Q):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
import numpy as np
H,W,D = map(int,input().split())
a = [input().split() for l in range(H)]
Q = int(input())
b = [input().split() for l in range(Q)]
a = np.array(a)
b = np.array(b)
a = np.int64(a)
b = np.int64(b)
ans = []
memo = [[-1]*302 for i in range(302)]
for i in range(Q):
  syo = b[i,0]
  go = b[i,1]
  if memo[syo][go] != -1:
    ans.append(memo[syo][go])
    continue
  syouhi = 0
  while syo != go:
    c = np.where(a == syo)
    syo += D
    d = np.where(a == syo)
    syouhi += abs(c[0][0] - d[0][0]) + abs(c[1][0] - d[1][0])
  ans.append(syouhi)
  memo[syo][go] = syouhi
for i in range(Q):
  print(ans[i])