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

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N, u, v = map(int, input().split())
u, v = u-1, v-1
edge = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    edge[a].append(b)
    edge[b].append(a)

taka = [0] * N
aoki = [0] * N

def dfs(v, pre, cost, i):
    for e in edge[v]:
        if e == pre:
            continue
        cost = dfs(e, v, cost, i+1)
    cost[v] = i
    return cost

taka = dfs(u, -1, [0] * N, 0)
aoki = dfs(v, -1, [0] * N, 0)

m = 0
for i in range(N):
    if taka[i] < aoki[i]:
        m = max(m, aoki[i])

print(m-1)

Buggy submission (verdict: Runtime Error):
from copy import deepcopy
N, u, v = map(int, input().split())
edge = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    edge[a].append(b)
    edge[b].append(a)

aoki = [0] * N
takahasi = [0] * N
dist_list = [0] * N
def dfs(pv, v, dist):
    dist_list[v] = dist
    for nv in edge[v]:
        if nv == pv:
            continue
        dfs(v, nv, dist+1)

dfs(-1,u-1,0)
takahasi = deepcopy(dist_list)
dist_list = [0] * N
dfs(-1,v-1,0)
aoki = deepcopy(dist_list)
print(takahasi)
print(aoki)
Problem p02859 (python)

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

Buggy submission (verdict: Runtime Error):
N, T = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * (T+1) for _ in range(N+1)]
AB.sort(key = lambda x:x[0], reverse=True)
AB[0][0] = 0
for i in range(1,N+1):
    for j in range(1,T+1):
        if j < AB[i-1][0]:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j-AB[i-1][0]] + AB[i-1][1], dp[i-1][j])
print(dp[N][T])
Problem p02891 (python)

Fixed submission:
from copy import deepcopy
s = list(input())
K = int(input())
dummy = "A"
S = deepcopy(s)
if len(set(S)) == 1:
    print(len(S)*K//2)
else:
    replace_cnt = 0
    for i in range(1, len(S)):
        if S[i] == S[i-1]:
            S[i] = dummy
            replace_cnt += 1
    if S[0] != S[-1]:
        print(replace_cnt*K)
    else:
        S = s+s
        replace_cnt_two = 0
        for i in range(1, len(S)):
            if S[i] == S[i-1]:
                S[i] = dummy
                replace_cnt_two += 1
        diff = replace_cnt_two - replace_cnt
        print(diff*(K-1)+replace_cnt)

Buggy submission (verdict: Runtime Error):
from copy import deepcopy
s = list(input())
K = int(input())
dummy = "A"
S = deepcopy(s)
if len(set(S)) == 1:
    print(len(S)*K//2)
else:
    replace_cnt = 0
    for i in range(1, len(S)):
        if S[i] == S[i-1]:
            S[i] = dummy
            replace_cnt += 1
    if S[0] != S[-1]:
        print(replace_cnt*K)
    else:
        S = deepcopy(s)
        replace_cnt_two = 0
        l = len(S)
        for i in range(1, l*2):
            if S[i%l] == S[(i-1)%l]:
                S[i] = dummy
                replace_cnt_two += 1
        diff = replace_cnt_two - replace_cnt
        print(diff*(K-1)+replace_cnt)
Problem p02990 (python)

Fixed submission:
N, K = map(int, input().split())
MOD = 10 ** 9 + 7

MAX = 4000
fact = [0] * MAX
invfact = [0] * MAX
fact[0] = 1
for i in range(1, MAX):
    fact[i] = fact[i - 1] * i % MOD
invfact[MAX - 1] = pow(fact[MAX - 1], MOD-2, MOD)
for i in range(MAX - 2, -1, -1):
    invfact[i] = invfact[i+1] * (i+1) % MOD

def nCk(n, k):
    if k < 0 or n < k: return 0
    return (fact[n] * invfact[k] % MOD) * invfact[n-k] % MOD

ans = 0
red = N - K
for i in range(1,1+K):
    ans = nCk(red+1, i) * nCk(K-1, i-1)
    ans %= MOD
    print(ans)

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n, k = map(int, input().split())
for i in range(1, k+1):
    red = cmb(k-1, i-1)
    blue = cmb(n-k+1, i)
    print(red*blue%(10**9+7))
Problem p03018 (python)

Fixed submission:
s = input()
l = len(s)
s += "0"
ans = 0
a_cnt = 0
skip = False
for i in range(l):
    if skip:
        skip = False
        continue
    if s[i] == "A":
        a_cnt += 1
    elif s[i] == "B" and s[i+1] == "C":
        ans += a_cnt
        skip = True
    else:
        a_cnt = 0

print(ans)

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
a, p = [1], [1]
for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(a[i] * 2 + 1)

def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a[N-1]:
        # B(N-1) | P(N-1)B の真ん中のパティの前までの範囲がわかればいい場合
        # Xから先頭のバンの数を引いて、N-1の先頭からX-1までの数を数えるために再帰で呼び出す
        return f(N-1,X-1)
    else:
        # 真ん中のパティ以上の枚数を数える必要がある場合
        # 一つ前のレベルのパティの数 + 真ん中のパティ + f(レベル-1, この関数呼び出しで知りたいトータルの枚数-2(先頭のバンと真ん中のパティ)-一つ前のレベルのハンバーガーのトータルの枚数)
        # X-2-a[N-1] → X - (B(N-1)P)|ここから後ろの先頭からK枚を数えるために再帰で呼び出す
        return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N,X))
Problem p03077 (python)

Fixed submission:
import math
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
print(math.ceil(N/min(A,B,C,D,E)+4))

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
print(math.ceil(N/min(A,B,C,D,E)+4)
Problem p03104 (python)

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

def calc(n):
    mod = n % 4
    if mod == 0:
        return n
    elif mod == 1:
        return n ^ (n-1) 
    elif mod == 2:
        return n ^ 1
    elif mod == 3:
        return 0
a = calc(A - 1)
b = calc(B)

print(a ^ b)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
result = 0
def calc(A, B, N):
    if N >= B:
        return A
    A = A ^ (N + 1)
    return calc(A, B, N + 1)
print(calc(A, B, A))
Problem p03108 (python)

Fixed submission:
from collections import Counter
# union find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def find_root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1

    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def count(self, x):
        return -self.root[self.find_root(x)]

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

AB = AB[::-1]
ret = []
tmp = 0
uf = UnionFind(N)
for a,b in AB:
    if uf.is_same_group(a-1, b-1):
        ret.append(0)
    else:

        ret.append(uf.count(a-1) * uf.count(b-1))
        uf.unite(a-1,b-1)

ans = 0
for i in range(M-1, -1, -1):
    ans += ret[i]
    print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
 
AB.reverse()

reader = np.array([i + 1 for i in range(N)])
size = np.array([1 for i in range(N)])

def root(a):
  if reader[a-1] == a:
    return a - 1
  else:
    return reader[a-1] - 1

def merge(a, b):
  # calc root index
  a = root(a)
  b = root(b)
  if a == b:
    return
  res = size[a] * size[b]
  if size[a] >= size[b]:
    # add size is root
    size[a] += size[b]
    # replace zero is all child node
    size[b] = 0
    reader[reader == reader[b]] = reader[a]
  else:
    size[b] += size[a]
    size[a] = 0
    reader[reader == reader[a]] = reader[b]
  return res

result = []
ans = N * (N-1)/2
for i in AB:
  result.append(ans)
  ans -= merge(i[0], i[1])
for i in result[::-1]:
  print(i)
Problem p03208 (python)

Fixed submission:
N, K = map(int, input().split())
H = sorted([int(input()) for _ in range(N)])
ret = 10 ** 9
for i in range(N-K+1):
    ret = min(H[i+K-1] - H[i], ret)
print(ret)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
H = sorted([int(input()) for _ in range(N)])
ret = 10 ** 9
for i in range(N-K+1):
    ret = min(H[i+2] - H[i], ret)

print(ret)
Problem p03634 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
N = int(input())
to = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    a, b = a-1, b-1
    to[a].append([b, c])
    to[b].append([a, c])

Q, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(Q)]

dist = [0] * N

def dfs(v, pv, dis):
    for i in to[v]:
        if i[0] != pv:
            dfs(i[0], v, dis+i[1])
    dist[v] = dis

dfs(K-1, -1, 0)

for x, y in xy:
    print(dist[x-1] + dist[y-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
to = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    a, b = a-1, b-1
    to[a].append([b, c])
    to[b].append([a, c])

Q, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(Q)]

dist = [0] * N

def dfs(v, pv, dis):
    for i in to[v]:
        if i[0] != pv:
            dfs(i[0], v, dis+i[1])
    dist[v] = dis

dfs(K-1, -1, 0)

for q in xy:
    print(dist[q[0]-1] + dist[q[1]-1])
Problem p03774 (python)

Fixed submission:
#!/usr/bin/python3
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)


def main():
    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(n)]
    cd = [list(map(int, input().split())) for _ in range(m)]

    for a, b in ab:
        arr = []
        for c, d in cd:
            arr.append(abs(a-c) + abs(b-d))
        print(arr.index(min(arr)) + 1)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for(int i = 0; i < (int)n; ++i)
int main()
{
    int N, M;
    scanf("%d %d", &N, &M);
    int a[N], b[N];
    REP(i, N) scanf("%d %d", &a[i], &b[i]);
    int c[M], d[M];
    REP(i, M) scanf("%d %d", &c[i], &d[i]);
    REP(i, N) {
        int res = -1;
        int dis = 1e9;
        REP(j, M) {
            int tmp = abs(c[j] - a[i]) + abs(d[j] - b[i]);
            if(tmp < dis) dis = tmp, res = j + 1;
        }
        printf("%d\n", res);
    }
    return 0;
}
Problem p03775 (python)

Fixed submission:
import sys
input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

def main():
    N = int(input())
    a = make_divisors(N)
    a.sort()
    ans = 10
    for i in a:
        ans = min(ans, len(str(max(i, N/i))))
    
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
    ll N;
    cin >> N;
    int res = 30;
    for(ll i = 1; i*i <= N; ++i) {
        if(N%i) continue;
        ll j = N/i;
        int cnt = 0;
        while(j > 0) ++cnt, j /= 10;
        res = min(res, cnt);
    }
    cout << res << endl;
    return 0;
}
Problem p03631 (python)

Fixed submission:
n = input()
if n[0] == n[2] : print('Yes')
else : print('No')

Buggy submission (verdict: Runtime Error):
if (n = input().split())[0] == n[2] : print('Yes')
else : print('No')
Problem p03705 (python)

Fixed submission:
n, a, b = map(int, input().split())
if (a > b) : print(0)
elif (n == 1) :
  if (a == b) : print(1)
  else : print(0)
else : print((b-a)*(n-2)+1)

Buggy submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
if (a < b) print(0)
else print(b*(n-1)+a-a*(n-1)-b+1)
Problem p03803 (python)

Fixed submission:
a, b = map(int, input().split())
if a == b : print('Draw')
else :
  flag = False
  if min(a, b) == 1 : flag = True
  if a < b :
    if flag : print('Alice')
    else : print('Bob')
  else :
    if flag : print('Bob')
    else : print('Alice')

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a == b : print('Draw')
else :
  if min(a, b) == 1 : flag = True
  if a < b :
    if flag : print('Alice')
    else : print('Bob')
  else :
    if flag : print('Bob')
    else : print('Alice')

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a == b : print('Draw')
else :
  if min(a, b) == 1 : flag = TRUE
  if a < b :
    if flag : print('Alice')
    else : print('Bob')
  else :
    if flag : print('Bob')
    else : print('Alice')
Problem p02598 (python)

Fixed submission:
def main():
    import math
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    def f(a,l):
        ans = 0
        for i in range(len(a)):
            ans += math.ceil(a[i]/l)-1
        return ans
    l,r = 1,max(a)
    while r-l>1:
        mid = (l+r)//2
        g = f(a,mid)
        if g>k:
            l = mid+1
        else:
            r = mid
    if f(a,l)<=k:
        print(l)
    else:
        print(r)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import math
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    def f(a,l):
        ans = 0
        for i in range(len(a)):
            ans += math.ceil(a[i]/l)-1
        return ans
    l,r = 1,max(a)
    while (r+l)//2!=r and (r+l)//2!=l:
        if f(a,(l+r)//2)>k:
            l = (l+r)//2
        elif f(a,(l+r)//2)<k:
            r = (l+r)//2
        else:
            break
    while True:
        if f(a,r)<=k:
            r -= 1
        else:
            print(r+1)
            return

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import math
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    def f(a,l):
        ans = 0
        for i in range(len(a)):
            ans += math.ceil(a[i]/l)-1
        return ans
    l,r = 1,max(a)
    while r-l>1:
        if f(a,(l+r)//2)>k:
            l = (l+r)//2
        else:
            r = (l+r)//2
    while True:
        if f(a,r)<=k:
            r -= 1
        else:
            print(r+1)
            return

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

Fixed submission:
def main():
    n = int(input())
    ans = []
    while n>25:
        p = n//26
        k = n-26*p
        if k==0:
            ans.append(26)
            n = p-1
        else:
            ans.append(k)
            n = p
    if n!=0:
        ans.append(n)
    ans = ans[::-1]
    b = []
    for i in range(len(ans)):
        b.append(chr(96+ans[i]))

    print(''.join(b))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    ans = []
    while n>26:
        p = n//26
        k = n-26*p
        ans.append(k)
        n = p
    ans.append(n)
    ans = ans[::-1]
    b = []
    for a in ans:
        if int(a)==0:
            t = b.pop(-1)
            if t=='a':
                s = 'z'
            else:
                s = chr(ord(t)-1)
            b.append(s+'z')
        else:
            b.append(chr(96+int(a)))
    print(''.join(b))

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

Fixed submission:
def main():
    a,b = input().split()
    b = b[0] + b[2:]
    print(int(a)*int(b)//100)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    a,b = input().split()
    a = int(a)
    b = double(b)
    print(int(a*b))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    a,b = input().split()
    a = int(a)
    b_n = b[0]
    b_ = b[2:]
    ans = int(a*int(b_n))+int(str(a*int(b_))[:-2])
    print(int(ans))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    a,b = input().split()
    a = int(a)
    b_n = b[0]
    b_ = b[2:]
    ans = a*int(b_n)+int(str(a*int(b_))[:-2])
    print(int(ans))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    a,b = input().split()
    a = int(a)
    b_n = b[0]
    b_ = b[2:]
    ans = a*int(b_n) + int(str(int(b_)*a)[:-2])
    print(int(ans))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    a,b = input().split()
    a = int(a)
    b_n = b[0]
    b_ = b[2:]
    ans = a*int(b_n) + int(str(int(b_)*a)[:-2])
    print(int(ans))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    a,b = input().split()
    a = int(a)
    b_n = b[0]
    b_ = b[2:]
    ans = a*int(b_n)
    c = str(int(b_)*a)[:-2]
    print(int(ans+int(c)))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    a,b = input().split()
    a = int(a)
    b_n = b[0]
    b_ = b[2:]
    ans = a*int(b_n)
    c = str(int(b_)*a)[:-2]
    print(int(ans+int(c)))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    a,b = input().split()
    a = int(a)
    b_n = b[0]
    b_ = b[2:]
    ans = a*int(b_n)
    c = str(int(b_)*a)[:-2]
    print(ans+int(c))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    a,b = input().split()
    a = int(a)
    b_n = b[0]
    b_ = b[2:]
    ans = a*int(b_n)
    a = str(int(b_)*a)[:-2]
    print(ans+int(a))

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

Fixed submission:
def main():
    l = input()
    n = len(l)
    mod = 10**9+7
    dp1 = [0 for i in range(n)]
    dp2 = [0 for i in range(n)]
    dp1[0] = 1
    dp2[0] = 2
    for i in range(1,n):
        if l[i] == '1':
            dp2[i] = (2 * dp2[i-1])%mod
            dp1[i] = (3 * dp1[i-1] + dp2[i-1])%mod
        else:
            dp2[i] = dp2[i-1]
            dp1[i] = (3 * dp1[i-1]) % mod
    print((dp1[-1]+dp2[-1])%mod)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    l = input()
    n = len(l)
    mod = 10**9+7
    ans = 1
    for i in range(n-1):
        ans = ans*3
        ans = ans%mod
    a = 2
    for i in range(1,n):
        if l[i] == '1':
            j = n-i
            break
    for i in range(j):
        a = a*3
        a = a%mod
    print((ans+a)%mod)
    
if __name__ == "__main__":
    main()
Problem p03053 (python)

Fixed submission:
from collections import deque
def main():
    h,w = map(int,input().split())
    S = [list(input()) for i in range(h)]
    q = [(i,j) for i,a in enumerate(S) for j,b in enumerate(a) if b=='#']
    q = deque(q)
    ans = 0
    s = h*w
    cnt = len(q)
    nxt = [(0,1),(1,0),(-1,0),(0,-1)]
    while cnt < s:
        ans += 1
        q_ = deque([])
        while q:
            a,b = q.pop()
            for x,y in nxt:
                X,Y = a+x,b+y
                if 0>X or X>h-1 or 0>Y or Y>w-1:
                    continue
                if S[X][Y]=='.':
                    S[X][Y]='#'
                    q_.append((X,Y))
        q = q_
        cnt += len(q_)
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    from collections import deque
    h,w = map(int,input().split())
    S = [list(input()) for i in range(h)]
    q = [(i,j) for i in range(w) for j in range(h) if S[i][j]=='#']
    q = deque(q)
    ans = 0
    cnt = len(q)
    nxt = [(0,1),(1,0),(-1,0),(0,-1)]
    while cnt < h*w:
        ans += 1
        q_ = deque([])
        while len(q)>0:
            a,b = q.pop()
            for x,y in nxt:
                X,Y = a+x,b+y
                if 0>X or X>h-1 or 0>Y or Y>w-1:
                    continue
                if S[X][Y]=='.':
                    S[X][Y]='#'
                    q_.append((X,Y))
        q = q_
        cnt += len(q)
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    from collections import deque
    h,w = map(int,input().split())
    S = [list(input()) for i in range(h)]
    q = [(i,j) for i in range(w) for j in range(h) if S[i][j]=='#']
    q = deque(q)
    ans = 0
    cnt = len(q)
    nxt = [(0,1),(1,0),(-1,0),(0,-1)]
    while cnt < h*w:
        ans += 1
        q_ = deque()
        while len(q)>0:
            b = q.popleft()
            for nx in nxt:
                mv = [b[0]+nx[0],b[1]+nx[1]]
                if -1<mv[0]<h and -1<mv[1]<w:
                    if S[mv[0]][mv[1]]=='#':
                        continue
                    S[mv[0]][mv[1]]='#'
                    q_.append(mv)
        q = q_
        cnt += len(q)
    print(ans)

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

Fixed submission:
def main():
    n = int(input())
    p = []
    for _ in range(n):
        p.append(int(input()))
    q = [0 for i in range(n)]
    for i in range(n):
        q[p[i]-1] = i
    m,cnt = 1,1
    for i in range(1,n):
        if q[i]>q[i-1]:
            cnt += 1
            if cnt > m:
                m = cnt
        else:
            cnt = 1
    print(n-m)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    p = []
    for _ in range(n):
        p.append(int(input()))
    ans = 0
    add = []
    for i in range(n//2+1):
        if p[i] > n//2:
            ans += 1
            add.append(p[i])
            p[i] = 0
    p += sorted(add)
    P = []
    for p_ in p:
        if p_>0:
            P.append(p_)
    B = P[0:n//2]
    P = P[n//2:]
    m = B[0]
    c = 0
    for i in range(len(B)):
        if B[i]>m:
            m = B[i]
        elif B[i]<m:
            if B[i]>c:
                c = B[i]
    ans += c
    m = P[-1]
    c = 0
    for i in range(len(P)):
        if P[-1-i]<m:
            m = P[-1-i]
        elif P[-1-i]>m:
            if n-P[-1-i]+1>c:
                c = n-P[-1-i]+1
    ans += c
    print(ans)

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

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

def m(a,b,c):
    for i in range(a, b+1):
        if i%c==0:
            print("OK")
            return
    print("NG")
    return

m(a,b,k)

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

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

def m(a,b,c):
	for i in (a, b+1):
  		if i%k==0:
          print("OK")
          return
    print("NG")
    return
m(a,b,k)