Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s = str(input())
t = str(input())
k = False
for i in range(len(s)):
  s = s[-i] + s[:-i]
  if s == t:
    k = True
    break
    
print('Yes' if k else 'No')

Fixed submission:
s = str(input())
t = str(input())

for i in range(len(s)):
    ss = s[-i:]+s[:-i]
    if ss == t:
        print('Yes')
        exit()
print('No')

Buggy python submission (verdict: Runtime Error):
s = str(input())
t = str(input())

Z =False

if i in range(len(s)):
    s = s[-1] + s[:-1]
    if s == t:
        Z =True
        exit()
        
print('Yes' if Z else 'No')

Fixed submission:
s = str(input())
t = str(input())

for i in range(len(s)):
    ss = s[-i:]+s[:-i]
    if ss == t:
        print('Yes')
        exit()
print('No')

Buggy python submission (verdict: Runtime Error):
s = str(input())
t = str(input())

Z =False

if i in range(lens(s)):
    s = s[-1] + s[:-1]
    if s == t:
        Z =True
        break
        
print('Yes' if Z else 'No')

Fixed submission:
s = str(input())
t = str(input())

for i in range(len(s)):
    ss = s[-i:]+s[:-i]
    if ss == t:
        print('Yes')
        exit()
print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 0
nans = 0
for i in range(10**9):
    for j in range(n):
        ans += abs(a[j]-i-j)
    if ans <= nans:
        nans =ans
print(nans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

box = [0]*n
ans = 0
for i in range(n):
    box[i] = a[i] - (i+1)
box.sort()

idx = n//2

b = box[idx]

for i in range(n):
    ans += abs(a[i]-(i+1+b))
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = 0
x = len(n)
for i in range(x):
  a = n[-1 * i]
  s = s+ a
  
if n%a == 0:
  print('Yes')
else:
  print('No')

Fixed submission:
n = int(input())
sum = 0
ans = n

while ans > 0:
  sum += ans % 10
  ans //= 10

if n%sum == 0:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
a, b = int(input())

if a <= 8 and b <= 8:
  print(Yay!)
else:
  print(:()

Fixed submission:
a, b = map(int, input().split())
 
if a <= 8 and b <= 8:
  print('Yay!')
else:
  print(':(')
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())

c = a * b

if c % 2 == 0:
  print('Even')
  else:
    print('Odd')

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

i = a*b

if i%2 == 0:
  print('Even')
else:
  print('Odd')

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

if a*b/2 % 1:
  print('Odd')
 else:
  print('Even')

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

i = a*b

if i%2 == 0:
  print('Even')
else:
  print('Odd')

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

if a * b / 2 % 1:
  print('Odd')
else
  print('Even')

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

i = a*b

if i%2 == 0:
  print('Even')
else:
  print('Odd')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [map(int, input().split()) for _ in range(Q)]
B, C = [list(i) for i in zip(*BC)]

for i in range(Q):
    A_replace = [C[i] if a == B[i] else a for a in A]
    A = A_replace
    print(sum(A))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [map(int, input().split()) for _ in range(Q)]
B, C = [list(i) for i in zip(*BC)]

sum = 0
size = 10 ** 5 + 1
list = [0] * size
for a in A:
    list[a] += 1
    sum += a

for i in range(Q):
    sum = sum + C[i] * list[B[i]] - B[i] * list[B[i]]
    list[C[i]] += list[B[i]]
    list[B[i]] = 0
    print(sum)
Buggy python submission (verdict: Runtime Error):

S = input()
T = input()

S = list(S)
T = list(T)


def check(S,T):
    len_S = len(S)
    len_T = len(T)

    if len_T - len_S != 1:
        return "No"
    else:
        for i in range(len_S):
            if S[i] != T[i]:
                print(No)
                return "No"

        if i == len_S-1:
            return "Yes"

result = check(S,T)
print(result)


Fixed submission:
S = input()
T = input()


S = list(S)
T = list(T)


def check(S,T):
    len_S = len(S)
    len_T = len(T)

    for i in range(len_S):
        if S[i] != T[i]:
            return "No"

    return "Yes"

result = check(S,T)
print(result)
Buggy python submission (verdict: Runtime Error):
from numba import njit

@njit("i8(i8)")
def solve(n):
    s = [1] * (n+1)
    ans = 1
    for i in range(2,n+1):
        for j in range(i,n+1,i):
            s[j] += 1
        ans += (i * s[i])
	return ans
n = int(input()) 
print(solve(n))


Fixed submission:
a = int(input())
print(a + pow(a, 2) + pow(a,3))
Buggy python submission (verdict: Runtime Error):
import math
a,b,c = list(map(int, input().split()))
if ((math.sqrt(a) + math.sqrt(b)) < math.sqrt(c)):
  print("Yes")
else:
  print("No")

Fixed submission:
n = int(input()) - 1
a = [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]
print(a[n])
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin,stdout,setrecursionlimit
from collections import Counter as C
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
	
n = int(input())
a, b, c = [], [], []
for i in range(n):
    x,y,z = gil()
    a.append(x)
    b.append(y)
    c.append(z)
    
mem = {}
def rp(i, p, h):
    global a,b,c,n
    if i >= n:
        return h
    
    av = [rp(i+1, 0, h+a[i]), rp(i+1, 1, h+b[i]), rp(i+1, 2, h+c[i])]
    if p != -1:
        av[p] = 0
    ans = max(av)
    return ans
ans = rp(0, -1, 0)
print(ans)
        
    
 


Fixed submission:
from sys import stdin,stdout,setrecursionlimit
from collections import Counter as C
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
	
n = int(input())
a, b, c = [], [], []
for i in range(n):
    x,y,z = gil()
    a.append(x)
    b.append(y)
    c.append(z)
    
mem = [[-1 for _ in range(3)] for _ in range(n+1)]
def rp(i, p):
    global a,b,c,n
    if i >= n:
        return 0
    if mem[i][p] != -1:
        return mem[i][p]
    av = [a[i] + rp(i+1, 0), b[i] + rp(i+1, 1), c[i] + rp(i+1, 2)]
    if p != -1:
        av[p] = 0
    ans = max(av)
    mem[i][p] = ans
    return ans
ans = rp(0, -1)
print(ans)
        
    
# on recursive mem sols, build the solution from the base case,
# ie, return 0 on basecase, and build up the solution.
# maybe because the values that come later on decide more on what you choose?
Buggy python submission (verdict: Runtime Error):
import math

def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

    return data

def factorization(n, data):
    arr = []
    temp = n
    num = 0
    for i in data:
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    
    return math.prod([f[1]+1 for f in arr])
if __name__ == "__main__":
    N = int(input())
    ans = 0
    data = get_sieve_of_eratosthenes(N)
    for i in range(1, N+1):
        ans += i*factorization(i, data)
    print(ans-1)


Fixed submission:
if __name__ == "__main__":
    N = int(input())
    ans = 0
    for i in range(1, N+1):
        Y = N//i
        ans += Y*(Y+1)*i//2
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
def factorization(n):
    arr = []
    temp = n
    num = 0
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    
    return math.prod([f[1]+1 for f in arr])
if __name__ == "__main__":
    N = int(input())
    ans = 0
    for i in range(1, N+1):
        ans += i*factorization(i)
    print(ans-1)

Fixed submission:
if __name__ == "__main__":
    N = int(input())
    ans = 0
    for i in range(1, N+1):
        Y = N//i
        ans += Y*(Y+1)*i//2
    print(ans)
Buggy python submission (verdict: Runtime Error):
if __name__ == "__main__":
    N, M = list(map(int, input().split()))
    H = list(map(int, input().split()))
    good_obs = [True for i in range(M)]
    for i in range(M):
        a, b = list(map(int, input().split()))
        if H[a-1] > H[b-1]:
            godd_obs[b-1] = False
        elif H[a-1] < H[b-1]:
            good_obs[a-1] = False
    print(sum(good_obs))




Fixed submission:
if __name__ == "__main__":
    N, M = list(map(int, input().split()))
    H = list(map(int, input().split()))
    adj_max = [0 for i in range(N)]
    for i in range(M):
        a, b = list(map(int, input().split()))
        if adj_max[a-1] < H[b-1]:
            adj_max[a-1] = H[b-1]
        if adj_max[b-1] < H[a-1]:
            adj_max[b-1] = H[a-1]
    num = 0
    for i in range(N):
        if H[i] > adj_max[i]:
            num += 1
    print(num)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
    N, M = list(map(int, input().split()))
    H = list(map(int, input().split()))
    adj_mat = [[0 for i in range(N)] for i in range(N)]
    for i in range(M):
        a, b = list(map(int, input().split()))
        adj_mat[a-1][b-1] = 1
        adj_mat[b-1][a-1] = 1
    num = 0
    for i in range(N):
        temp = [0 for i in range(N)]
        for j in range(N):
            temp[j] = adj_mat[i][j] * H[j]
        if H[i] > max(temp):
            num += 1
    print(num)





Fixed submission:
if __name__ == "__main__":
    N, M = list(map(int, input().split()))
    H = list(map(int, input().split()))
    adj_max = [0 for i in range(N)]
    for i in range(M):
        a, b = list(map(int, input().split()))
        if adj_max[a-1] < H[b-1]:
            adj_max[a-1] = H[b-1]
        if adj_max[b-1] < H[a-1]:
            adj_max[b-1] = H[a-1]
    num = 0
    for i in range(N):
        if H[i] > adj_max[i]:
            num += 1
    print(num)

Buggy python submission (verdict: Runtime Error):
if __name__ == "__main__":
    N, M = list(map(int, input().split()))
    H = list(map(int, input().split()))
    adj_mat = [[0 for i in range(N)] for i in range(N)]
    for i in range(M):
        a, b = list(map(int, input().split()))
        adj_mat[a-1][b-1] = 1
        adj_mat[b-1][a-1] = 1
    num = 0
    for i in range(N):
        h = H[i]
        for j in range(N):
            if adj_mat[i][j] == 1:
                flag = True
                if h < H[j]:
                    flag = False
                    break
        if flag:
            num += 1
    print(num)

Fixed submission:
if __name__ == "__main__":
    N, M = list(map(int, input().split()))
    H = list(map(int, input().split()))
    adj_max = [0 for i in range(N)]
    for i in range(M):
        a, b = list(map(int, input().split()))
        if adj_max[a-1] < H[b-1]:
            adj_max[a-1] = H[b-1]
        if adj_max[b-1] < H[a-1]:
            adj_max[b-1] = H[a-1]
    num = 0
    for i in range(N):
        if H[i] > adj_max[i]:
            num += 1
    print(num)
Buggy python submission (verdict: Runtime Error):
if __name__ == "__main__":
	N, K = list(map(int, input().split()))
    r = N%K
    print(r) if r < abs(r-K) else print(abs(r-K))


Fixed submission:
if __name__ == "__main__":
    N, K = list(map(int, input().split()))
    r = N%K
    if r < abs(r-K):
        print(r)  
    else:
        print(abs(r-K))
Buggy python submission (verdict: Runtime Error):
from math import factorial

def conb2(a):
    if a == 1:
        return 0
    else:
        return int(factorial(a) / factorial(2) / factorial(a-2))


if __name__ == "__main__":
    M, N = list(map(int, input().split()))
    print(conb2(M)+conb2(N))

Fixed submission:
from math import factorial

def conb2(a):
    if a == 1:
        return 0
    else:
        return int(a*(a-1)/2)


if __name__ == "__main__":
    M, N = list(map(int, input().split()))
    print(conb2(M)+conb2(N))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input().strip())

ans=0
cnt=[0]*n
for divisor in range(1,n+1):
    mult=divisor
    while mult<=n:
        cnt[mult-1]+=1
        mult+=divisor
for i,v in enumerate(cnt):
    ans+=(i+1)*v
print(ans)

Fixed submission:
n = int(input().strip())

ans=0
for divisor in range(1,n+1):
    ans+=divisor*(n//divisor*(n//divisor+1)//2)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def divisor(n):  # nの約数を全て求める
    i = 1
    table =0
    while i * i <= n:
        if n % i == 0:
            table+=2
            if i==n//i:
                table-=1
        i += 1
    
    return table
n = int(input().strip())

ans=0
for i in range(1,n+1):
    ans+=i*divisor(i)
print(ans)

Fixed submission:
n = int(input().strip())

ans=0
for divisor in range(1,n+1):
    ans+=divisor*(n//divisor*(n//divisor+1)//2)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def divisor(n):  # nの約数を全て求める
    i = 1
    table = set()
    while i * i <= n:
        if n % i == 0:
            table.add(i)
            table.add(n // i)
        i += 1
    
    return len(table)
n = int(input().strip())

ans=0
for i in range(1,n+1):
    ans+=i*divisor(i)
print(ans)

Fixed submission:
n = int(input().strip())

ans=0
for divisor in range(1,n+1):
    ans+=divisor*(n//divisor*(n//divisor+1)//2)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input().strip())
L = list(map(int, input().strip().split()))
ans=1
for v in L:
    ans*=v

if ans>10**18:
    print(-1)
else:
    print(ans)

Fixed submission:
n = int(input().strip())
L = list(map(int, input().strip().split()))
L.sort(reverse=True)
if L[-1]==0:
    print(0)
    exit()
ans=1
for v in L:
    ans*=v
    if ans>10**18:
        print(-1)
        exit()

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input().strip())
L = list(map(int, input().strip().split()))
seen=set()
ans=0
for j in range(n):
    if j-L[j] in seen:
        ans+=1
    seen.add(A[j]+j)
print(ans)


Fixed submission:
from collections import Counter
n = int(input().strip())
L = list(map(int, input().strip().split()))
seen=Counter()
ans=0
for j in range(n):
    # if j-L[j] in seen:
    ans+=seen[j-L[j]]
    seen[L[j]+j]+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m, q = map(int, input().strip().split())
L = [list(map(int, input().split())) for _ in range(q)]

possibleA=[[i]*n for i in range(1,m+1)]
for i in range(n):
    for j in range(i+1,m+1):
        

import math
a, b, n = map(int, input().strip().split())
if b<n:
    x=n
elif n % b <= n%(b/a):
    x=n-n%b-1
elif (n%b-n%(b/a)+1)//(b/a)>a*b:
    x=n-n%b-1
else:
    x=n
print(math.floor(a*x/b)-a*math.floor(x/b))

Fixed submission:
import math
a, b, n = map(int, input().strip().split())
x=min(b-1,n)
print(math.floor(a*x/b)-a*math.floor(x/b))
Buggy python submission (verdict: Runtime Error):
import bisect
n = int(input().strip())
S = input().strip()
L=[[] for _ in range(26)]
for i,s in enumerate(S):
    L[ord(s)-ord("a")].append(i)

q = int(input().strip())
for _ in range(q):
    query=input().strip().split()
    if query[0]=="1":
        i=int(query[1])
        i-=1
        c=query[2]
        if S[i]!=c:
            delInd=bisect.bisect_left(L[ord(S[i])-ord("a")],i)
            del L[ord(S[i])-ord("a")][delInd]
            bisect.insort(L[ord(c)-ord("a")], i)
            S[i]=c
    else:
        l,r=map(int,[query[1],query[2]])
        l-=1; r-=1
        ans=0
        for j in range(26):
            ind=bisect.bisect_left(L[j],l)
            if ind<len(L[j]) and L[j][ind]<=r:
                ans+=1
        print(ans)

Fixed submission:
import bisect
n = int(input().strip())
S = list(input().strip())
L=[[] for _ in range(26)]
for i,s in enumerate(S):
    L[ord(s)-ord("a")].append(i)

q = int(input().strip())
for _ in range(q):
    query=input().strip().split()
    if query[0]=="1":
        i=int(query[1])
        i-=1
        c=query[2]
        if S[i]!=c:
            delInd=bisect.bisect_left(L[ord(S[i])-ord("a")],i)
            del L[ord(S[i])-ord("a")][delInd]
            bisect.insort(L[ord(c)-ord("a")], i)
            S[i]=c
    else:
        l,r=map(int,[query[1],query[2]])
        l-=1; r-=1
        ans=0
        for j in range(26):
            ind=bisect.bisect_left(L[j],l)
            if ind<len(L[j]) and L[j][ind]<=r:
                ans+=1
        print(ans)

Buggy python submission (verdict: Runtime Error):
import bisect
n = int(input().strip())
S = input().strip()
L=[[] for _ in range(26)]
for i,s in enumerate(S):
    L[ord(s)-ord("a")].append(i)

q = int(input().strip())
for _ in range(q):
    query=input().strip().split()
    if query[0]=="1":
        i=int(query[1])
        i-=1
        c=query[2]
        if S[i]!=c:
            delInd=bisect.bisect_left(L[ord(S[i])-ord("a")],i)
            del L[ord(S[i])-ord("a")][delInd]
            bisect.insort(L[ord(c)-ord("a")], i)
    else:
        l,r=map(int,[query[1],query[2]])
        l-=1; r-=1
        ans=0
        for j in range(26):
            ind=bisect.bisect_left(L[j],l)
            if ind<len(L[j]) and L[j][ind]<=r:
                ans+=1
        print(ans)

Fixed submission:
import bisect
n = int(input().strip())
S = list(input().strip())
L=[[] for _ in range(26)]
for i,s in enumerate(S):
    L[ord(s)-ord("a")].append(i)

q = int(input().strip())
for _ in range(q):
    query=input().strip().split()
    if query[0]=="1":
        i=int(query[1])
        i-=1
        c=query[2]
        if S[i]!=c:
            delInd=bisect.bisect_left(L[ord(S[i])-ord("a")],i)
            del L[ord(S[i])-ord("a")][delInd]
            bisect.insort(L[ord(c)-ord("a")], i)
            S[i]=c
    else:
        l,r=map(int,[query[1],query[2]])
        l-=1; r-=1
        ans=0
        for j in range(26):
            ind=bisect.bisect_left(L[j],l)
            if ind<len(L[j]) and L[j][ind]<=r:
                ans+=1
        print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input().strip())
L = list(map(int, input().strip().split()))
ans=10**6+1
for p in range(max(L[-1])+1):
    tmp=0
    for x in L:
        tmp+=(x-p)**2
    ans=min(ans,tmp)
print(ans)

Fixed submission:
n = int(input().strip())
L = list(map(int, input().strip().split()))
ans=10**6+1
for p in range(max(L)+1):
    tmp=0
    for x in L:
        tmp+=(x-p)**2
    ans=min(ans,tmp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().strip().split())
# AB = [list(map(int, input().split())) for i in range(n)]

dp=[10**9]*(h+1)

dp[0]=0
for _ in range(n):
    a, b = map(int, input().strip().split())
    for i in range(h):
        ni=min(i+a,h)
        dp[ni] = min(dp[ni],dp[i]+b)
        
print(dp[h])

Fixed submission:
h, n = map(int, input().strip().split())
# AB = [list(map(int, input().split())) for i in range(n)]

dp=[10**9]*(h+1)

dp[0]=0
for _ in range(n):
    a, b = map(int, input().strip().split())
    for i in range(h):
        ni=min(i+a,h)
        dp[ni] = min(dp[ni],dp[i]+b)
        
print(dp[h])

Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().strip().split())
AB = [list(map(int, input().split())) for i in range(n)]

dp=[10**9]*(h+1)

dp[0]=0
for ab in AB:
    a=ab[0]
    b=ab[1]
    for i in range(h):
        ni=min(i+a,h)
        dp[ni] = min(dp[ni],dp[i]+b)
        
print(dp[h])

Fixed submission:
h, n = map(int, input().strip().split())
# AB = [list(map(int, input().split())) for i in range(n)]

dp=[10**9]*(h+1)

dp[0]=0
for _ in range(n):
    a, b = map(int, input().strip().split())
    for i in range(h):
        ni=min(i+a,h)
        dp[ni] = min(dp[ni],dp[i]+b)
        
print(dp[h])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

h, n = map(int, input().strip().split())
AB = [list(map(int, input().split())) for i in range(n)]

dp=[np.inf]*(h+1)

dp[0]=0
for ab in AB:
    a=ab[0]
    b=ab[1]
    for i in range(h):
        ni=min(i+a,h)
        dp[ni] = min(dp[ni],dp[i]+b)
        
print(dp[h])

Fixed submission:
h, n = map(int, input().strip().split())
# AB = [list(map(int, input().split())) for i in range(n)]

dp=[10**9]*(h+1)

dp[0]=0
for _ in range(n):
    a, b = map(int, input().strip().split())
    for i in range(h):
        ni=min(i+a,h)
        dp[ni] = min(dp[ni],dp[i]+b)
        
print(dp[h])
Buggy python submission (verdict: Runtime Error):
import math
N, a, b = map(int, input().strip().split())

if (b-a)%2==0:
    ans=int(math.round((b-a)/2))
else:
    ans=min(a-1,N-b)+math.ceil((b-a)/2)
print(ans)

Fixed submission:
import math
N, a, b = map(int, input().strip().split())

if (b-a)%2==0:
    ans=(b-a)//2
else:
    ans=min(a-1,N-b)+1+(b-a)//2
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
N, a, b = map(int, input().strip().split())

if (b-a)%2==0:
    ans=int(math.raound((b-a)/2))
else:
    ans=min(a-1,N-b)+math.ceil((b-a)/2)
print(ans)

Fixed submission:
import math
N, a, b = map(int, input().strip().split())

if (b-a)%2==0:
    ans=(b-a)//2
else:
    ans=min(a-1,N-b)+1+(b-a)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M, V, P = map(int, input().strip().split())
A = sorted(list(map(int, input().strip().split())),reverse=True)
ans=0

for i in range(N):
    thre=A[i]+M
    if thre < A[P-1]:
        continue

    remain=V-(P-1)-(N-i)
    if remain <=0:
        ans+=1
    elif sum(A[P-1:i])+M*remain <= thre*(i-1-(P-1)+1):
        ans+=1
print(ans)

Fixed submission:
n, m, v, p = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
ans = p
c = [0]
cnt = 0
for i in range(n):
  # 累積和
  cnt += a[i]
  c.append(cnt)
  
from bisect import bisect_right
for i in range(p,n):
  h = a[i]+m
  free = v - (p-1) - (n-i)
  if free >= 0 and h >= a[p-1]:
    d = h * (i-p+1) - (c[i]-c[p-1]) # 余裕
    if d >= free*m:
      ans += 1
  else:
    if h >= a[p-1]:
      ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N, M, V, P = map(int, input().strip().split())
A = sorted(list(map(int, input().strip().split())),reverse=True)
ans=0

for i in range(N):
    thre=A[i]+M
    if thre < A[P-1]:
        continue

    remain=V-(P-1)-(N-i)
    if remain <=0:
        ans+=1
    elif sum(A[P-1:i])+M*remain <= thre*(i-1-(P-1)+1):
        ans+=1
print(ans)

Fixed submission:
n, m, v, p = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
ans = p
c = [0]
cnt = 0
for i in range(n):
  # 累積和
  cnt += a[i]
  c.append(cnt)
  
from bisect import bisect_right
for i in range(p,n):
  h = a[i]+m
  free = v - (p-1) - (n-i)
  if free >= 0 and h >= a[p-1]:
    d = h * (i-p+1) - (c[i]-c[p-1]) # 余裕
    if d >= free*m:
      ans += 1
  else:
    if h >= a[p-1]:
      ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, M, V, P = map(int, input().strip().split())
A = sorted(list(map(int, input().strip().split())),reverse=True)
ans=0

for i in range(N):
    thre=A[i]+M
    if thre < A[P-1]:
        continue

    remain=V-(P-1)-(N-i)
    if remain <=0:
        ans+=1
    elif sum(A[P-1:i])+M*remain <= thre*(i-1-(P-1)+1):
        ans+=1
print(ans)

Fixed submission:
n, m, v, p = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
ans = p
c = [0]
cnt = 0
for i in range(n):
  # 累積和
  cnt += a[i]
  c.append(cnt)
  
from bisect import bisect_right
for i in range(p,n):
  h = a[i]+m
  free = v - (p-1) - (n-i)
  if free >= 0 and h >= a[p-1]:
    d = h * (i-p+1) - (c[i]-c[p-1]) # 余裕
    if d >= free*m:
      ans += 1
  else:
    if h >= a[p-1]:
      ans += 1
print(ans)