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

Fixed submission:
n = int(input())
s = input()
t = input()

M = 0
for i in range(1, n+1):
    if s[-i:] == t[:i]:
        M = i
print(n*2 - M)

Buggy submission (verdict: Runtime Error):
N, x = map(int, input().split())
if x==1 or x==2*N-1:
    print('No')
else:
    print('Yes')
    if x <= 2*N:
        y = list(i for i in range(2, 2*N-2) if i!=x)
        l = len(y)//2
        print("\n".join(map(str, y[:l] + [2*N-1, x, 1, 2*N-2] + y[l:])))
    else:
        y = list(i for i in range(3, 2*N-1) if i!=x)
        l = len(y)//2
        print("\n".join(map(str, y[:l] + [2*N-1, 1, x, 2] + y[l:])))
Problem p03975 (python)

Fixed submission:
n, a, b = map(int, input().split())
ts = map(int, (input() for _ in range(n)))
print(sum(1 for t in ts if t<a or t>=b))

Buggy submission (verdict: Runtime Error):
from collections import Counter
n, k = map(int, input().split())
ps = [input() for _ in range(n)]
heads = Counter((p[0] for p in ps))
ans = 0
while len(heads) >= k:
    ans += 1
    for h, c in heads.most_common()[:k]:
        if c==1:
            heads.pop(h)
        else:
            heads[h] -= 1
print(ans)
Problem p03976 (python)

Fixed submission:
from collections import Counter
n, k = map(int, input().split())
ps = [input() for _ in range(n)]
heads = Counter((p[0] for p in ps))
ans = 0
while len(heads) >= k:
    ans += 1
    for h, c in heads.most_common()[:k]:
        if c==1:
            heads.pop(h)
        else:
            heads[h] -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
afrom collections import Counter
n, k = map(int, input().split())
ps = [input() for _ in range(n)]
heads = Counter((p[0] for p in ps))
ans = 0
while len(heads) >= k:
    ans += 1
    for h, c in heads.most_common()[:k]:
        if c==1:
            heads.pop(h)
        else:
            heads[h] -= 1
print(ans)
Problem p04001 (python)

Fixed submission:
s = input()
ans = 0
l = len(s)-1
for i in range(2**(len(s)-1)):
    bs = ("{0:0>"+str(l)+"b}").format(i)
    s1 = 0
    temp = s[:]
    j = 0
    for b in bs:
        j+=1
        if b == '1':
            s1 += int(temp[:j])
            temp = temp[j:]
            j = 0
    s1 += int(temp)
    ans += s1
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
H, W, N = map(int, input().split())
poss = [list(map(int, input().split())) for _ in range(N)]
d = defaultdict(int)
for a, b in poss:
    for i, j in ((i, j) for i in range(a-1, a+2) for j in range(b-1, b+2)):
        if 1<i<H and 1<j<W:
            s = str(i)+":"+str(j)
            d[s] += 1
anss = [0] * 10
for x in d.values():
    anss[x] += 1
print((H-2)*(W-2) - sum(anss[1:]))
for ans in anss[1:]:
    print(ans)
Problem p04014 (python)

Fixed submission:
import sys
import math

sys.setrecursionlimit(100000000)

n = int(input())
s = int(input())

def f(b, n):
    if n<b:
        return n
    else:
        return f(b, n//b) + n%b

if s > n:
    print(-1)
elif s==n:
    print(s+1)
else:
    for b in range(2, math.ceil(math.sqrt(n))+1):
        if f(b, n)==s:
            print(b)
            break
    else:
        for d in range(math.floor(math.sqrt(n)), 0, -1):
            if (n-s)%d==0 and f((n-s)//d+1, n)==s:
                print((n-s)//d+1)
                break
        else:
            print(-1)

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

sys.setrecursionlimit(100000000)

n = int(input())
s = int(input())

def f(b, n):
    if n<b:
        return n
    else:
        return f(b, n//b) + n%b

if s > n:
    print(-1)
if s==n:
    print(s+1)
else:
    for b in range(2, math.ceil(math.sqrt(n))+1):
        if f(b, n)==s:
            print(b)
            break
    else:
        if f(n+1-s, n)==s:
            print(n+1-s)
        else:
            print(-1)

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

sys.setrecursionlimit(100000000)

n = int(input())
s = int(input())

def f(b, n):
    if n<b:
        return n
    else:
        return f(b, n//b) + n%b

if s > n:
    print(-1)
else:
    for b in range(2, math.ceil(math.sqrt(n))+1):
        if f(b, n)==s:
            print(b)
            break
    else:
        if f(n+1-s, n)==s:
            print(n+1-s)
        else:
            print(-1)
Problem p02756 (python)

Fixed submission:

S=input()
Q=int(input())
qls=[list(map(str,input().split())) for _ in range(Q)]
N=len(S)
res=['']*(2*Q+N)
res[Q:Q+N]=S
ins = [Q+N, Q-1]
flg=0 #0:right, 1:left
for q in qls:
    if q[0]=='1':
        flg = (flg+1)%2
    else:
        x = (flg+int(q[1]))%2
        idx = ins[x]
        res[idx] = q[2]
        if x==0:
            ins[x]+=1
        else:
            ins[x]-=1
if flg==0:
    print(''.join(res))
else:
    print(''.join(res[::-1]))

Buggy submission (verdict: Runtime Error):

S=input()
Q=int(input())
qls=[list(map(str,input().split())) for _ in range(Q)]
res=['']*(2*Q)
res[Q]=S
ins = [Q+1, Q-1]
flg=0 #0:right, 1:left
for q in qls:
    if q[0]=='1':
        flg = (flg+1)%2
    else:
        x = (flg+int(q[1]))%2
        idx = ins[x]
        res[idx] = q[2]
        if x==0:
            ins[x]+=1
        else:
            ins[x]-=1
if flg==0:
    print(''.join(res))
else:
    print(''.join(res[::-1]))
Problem p02803 (python)

Fixed submission:
# BFS queue
import queue
import copy

import time
sss = time.time()
H, W = map(int,input().split())
b = [list(input()) for _ in range(H)]
dist = [[10**9 for _ in range(W)] for _ in range(H)]
start = (-1,-1)
qq = queue.Queue()
l = 0
# start把握
for i in range(H):
    for j in range(W):
        if b[i][j] == '.':
            qq.put((i,j))
            l += 1
if l >= H*W-(H-2):
    print(H+W-2)
    exit()
far = 0
move = [(-1,0), (0,-1), (1,0), (0,1)]
def BFS(start, bb):
    dist = [[10**9 for _ in range(W)] for _ in range(H)]
    far = 0
    q = queue.Queue()
    q.put(start)
    dist[start[0]][start[1]] = 0
    # BFS
    while 1:
        now = q.get()
        x = now[0]
        y = now[1]
        bb[x][y] == '#'
        for elem in move:
            dx = elem[0]
            dy = elem[1]
            if x+dx>=0 and x+dx<= H-1 and y+dy>=0 and y+dy<=W-1 and abs(dx-dy)==1:
                if bb[x+dx][y+dy] != '#':
                    if dist[x+dx][y+dy] > dist[x][y]:
                        dist[x+dx][y+dy] = dist[x][y] + 1
                        if dist[x+dx][y+dy] > far:
                            far = dist[x+dx][y+dy]
                        q.put((x+dx,y+dy))
        if q.empty():
            break
    return far
res = 0
while 1:
    ttt = time.time()
    if ttt-sss >= 1:
        break
    now = qq.get()
    res = max([res, BFS(now, copy.deepcopy(b))])
    if qq.empty():
        break
print(res)

Buggy submission (verdict: Runtime Error):
# BFS queue
import queue
import copy

import time
sss = time.time()
H, W = map(int,input().split())
b = [list(input()) for _ in range(H)]
dist = [[10**2 for _ in range(W)] for _ in range(H)]
start = (-1,-1)
qq = queue.Queue()
# start把握
for i in range(H):
    for j in range(W):
        if b[i][j] == '.':
            qq.put((i,j))
far = 0
move = [(-1,0), (0,-1), (1,0), (0,1)]
def BFS(start, bb):
    dist = [[10**2 for _ in range(W)] for _ in range(H)]
    far = 0
    q = queue.Queue()
    q.put(start)
    dist[start[0]][start[1]] = 0
    # BFS
    while 1:
        now = q.get()
        x = now[0]
        y = now[1]
        olddist = dist[x][y]
        bb[x][y] = '#'
        for elem in move:
            dx = elem[0]
            dy = elem[1]
            x+dx = xx
            y+dy = yy
            if xx>=0 and xx<= H-1 and yy>=0 and yy<=W-1:
                if bb[xx][yy] != '#':
                    if dist[xx][yy] > olddist:
                        dist[xx][yy] = olddist + 1
                        far = max([far,olddist+1])
                        q.put((xx,yy))
        if q.empty():
            break
    return far
res = 0
while 1:
    ttt = time.time()
    if sss-ttt >= 1.8:
        break
    now = qq.get()
    res = max([res, BFS(now, copy.deepcopy(b))])
    if qq.empty():
        break
print(res)
Problem p02804 (python)

Fixed submission:
import sys
import copy
import bisect
import numpy as np
N,K = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)
res = 0
fact = [0]*(N+1)
ifact = [0]*(N+1)
inv = [0]*(N+1)
p=10**9+7

def combination(n,fact,ifact):
    fact[0] = 1
    fact[1] = 1
    ifact[0] = 1
    ifact[1] = 1
    inv[1] = 1
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%p
        inv[i] = p - inv[p%i]*(p//i)%p
        ifact[i] = (ifact[i-1]*inv[i])%p
def op(n,k,fact,ifact):
    if k<0 or k>n or n<0:
        return 0
    return int(fact[n]*ifact[k]*ifact[n-k])%(10**9+7)

combination(N,fact,ifact)
for i in range(N):
    res += (a[i]*op(i,K-1,fact,ifact))%p
#a = list(-np.array(a))
a = [-elem for elem in a]
a = sorted(a)
for i in range(N):
    res += (a[i]*op(i,K-1,fact,ifact))%p
print(res%p)

Buggy submission (verdict: Runtime Error):
import sys
import copy
import bisect
import numpy as np
from scipy.special import comb
N,K = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)
res = 0
fact = [0]*(N+1)
ifact = [0]*(N+1)
inv = [0]*(N+1)
p=10**9+7

def combination(n,fact,ifact):
    fact[0] = 1
    fact[1] = 1
    ifact[0] = 1
    ifact[1] = 1
    inv[1] = 1
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%p
        inv[i] = p - inv[p%i]*(p//i)%p
        ifact[i] = (ifact[i-1]*inv[i])%p
def op(n,k,fact,ifact):
    if k<0 or k>n or n<0:
        return 0
    return int(fact[n]*ifact[k]*ifact[n-k])%(10**9+7)

combination(N,fact,ifact)
for i in range(N):
    res += (a[i]*op(i,K-1,fact,ifact))%p
#a = list(-np.array(a))
a = [-elem for elem in a]
a = sorted(a)
for i in range(N):
    res += (a[i]*op(i,K-1,fact,ifact))%p
print(res%p)

Buggy submission (verdict: Runtime Error):
import sys
import copy
import bisect
import numpy as np
from scipy.special import comb
N,K = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)
res = 0
fact = [0]*(N+1)
ifact = [0]*(N+1)
inv = [0]*(N+1)
p=10**9+7

def combination(n,fact,ifact):
    fact[0] = 1
    fact[1] = 1
    ifact[0] = 1
    ifact[1] = 1
    inv[1] = 1
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%p
        inv[i] = p - inv[p%i]*(p//i)%p
        ifact[i] = (ifact[i-1]*inv[i])%p
def op(n,k,fact,ifact):
    if k<0 or k>n or n<0:
        return 0
    return int(fact[n]*ifact[k]*ifact[n-k])%(10**9+7)

combination(N,fact,ifact)
for i in range(N):
    res += (a[i]*op(i,K-1,fact,ifact))%p
#a = list(-np.array(a))
a = [-elem for elem in a]
a = sorted(a)
for i in range(N):
    res += (a[i]*op(i,K-1,fact,ifact))%p
print(res%p)
Problem p02824 (python)

Fixed submission:
import bisect
N, M, V, P = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
eps = 0.1
def func(k):
    # print("tsrget:"+str(k))
    used = 0
    tmp = a[:k]+a[k+1:]
    val = a[k]+M
    x1 = N-1-bisect.bisect(tmp, val+eps)
    x2 = bisect.bisect(tmp, val-eps)
    x3 = N-(x1+x2+1)
    # print(tmp,val,x1,x2,x3)
    if x1 >= P:
        return False
    v = V - (x1+1)
    p = P - (x1+1)
    used += x1+1
    if v <= 0:
        return True
    # x2+x3問からあとp問はa[k]+Mを超えてもよい
    # x3が十分ある
    if x3 >= p > 0:
        x3 -= p
        v -= p
        used += p
        p = 0
    if p>0:
        p -= x3
        v -= x3
        used += x3
    if x2 >= p > 0:
        x2 -= p
        v -= p
        used += p
        p = 0
    if p>0:
        p -= x2
        v -= x2
        used += x2
    if v <= 0:
        return True
    # x2問からあとp問はa[k]+Mを超えてもよい
    tmp2 = tmp[:N-used]
    rest = sum([min(M,val-val2) for val2 in tmp2])
    # print(tmp2,N,x1,x3,p,v, rest)
    if rest >= M*v:
        return True
    return False

ok = N-1  # exist
ng = -1  # not exist
while abs(ok - ng) > 1:
    cnt = (ok + ng) // 2
    t = func(cnt)
    # print(t)
    if t:
        ok = cnt
    else:
        ng = cnt
print(N-ok)

Buggy submission (verdict: Runtime Error):
import sys
import copy
import bisect
import numpy as np

def solve(a,n,N,M,V,P):
    if N-n+1 >= V:
        b = copy.deepcopy(a)
        b[n-1] += M
        tmp = b[n-1]
        b = sorted(b[0:n], reverse=True)
        k = bisect.bisect_left(b,tmp)
        if k<=P-1:
            return True
        else:
            return False
    else:
        V2 = V-N+n-1
        b = copy.deepcopy(a[0:n])
        b[n-1] += M
        tmp = b[n-1]
        b.sort()
        k = bisect.bisect_left(b,tmp)
        k = len(b)-k
        if k+N-1-n < V:
            if P<=k:
                return False
            elif P>=n:
                return True
            else:
                V2 = V-N+n-1
                num = P-k-N+n-1
                aaa = min([V2-1, num])
                if (np.sum(a[n-num:n])+M*aaa+num-1)//num <= tmp:
                    return True
                else:
                    return False
        else:
            b = copy.deepcopy(a)
            b[n-1] += M
            tmp = b[n-1]
            b = sorted(b[0:n])
            k = bisect.bisect_right(b,tmp)
            k = len(b)-k
            if k<=P:
                return True
            else:
                return False

def main():
    N,M,V,P = map(int,input().split())
    a = list(map(int,input().split()))
    a.sort(reverse=True)
    lo = 0
    hi = 2*N
    while lo + 1 < hi:
        cnt = (lo + hi) // 2
        if solve(a,cnt,N,M,V,P):
            lo = cnt
        else:
            hi = cnt

    return hi

if __name__ == '__main__':
    ans = main()
    print(ans)
Problem p02845 (python)

Fixed submission:
N=int(input())
a = list(map(int, input().split()))
dic={}
mul = [3,2,1]
res = 1
for i in range(len(a)):
    if a[i] in dic:
        if dic[a[i]] == 2:
            print(0)
            exit()
        dic[a[i]] += 1
    else:
        dic[a[i]] = 0
    if a[i] == 0:
        if dic[0] >= 3:
            print(0)
            exit()
        res *= mul[dic[0]]
    else:
        if a[i]-1 not in dic:
            print(0)
            exit()
        res *= dic[a[i]-1] - dic[a[i]] + 1
    res = res%(10**9+7)
print(res)

Buggy submission (verdict: Runtime Error):
N=int(input())
a = list(map(int, input().split()))
dic={}
mul = [3,2,1]
res = 1
for i in range(len(a)):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 0
    if a[i] == 0:
        res *= mul[dic[0]]
    else:
        if a[i]-1 not in dic:
            print(0)
            exit()
        res *= dic[a[i]-1] - dic[a[i]] + 1
    res = res%(10**9+7)
print(res)
Problem p02917 (python)

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
b = list(map(int, input().split()))
sum = 0
for i in range(N):
    if i==0:
        sum += b[0]
    elif i==N-1:
        sum += b[N-2]
    else:
        sum += min([b[i-1], b[i]])
print(sum)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
b = list(map(int, input().split()))
sum = 0
for i in range(N):
    if i==0:
        sum += b[0]
    elif i==N-1:
        sum += b[N-1]
    else:
        sum += min(b[i], b[i+1])
print(sum)
Problem p02918 (python)

Fixed submission:
import bisect
import heapq
import numpy as np
N, K = map(int,input().split())
s = input()
res = 0
if s[0] == 'R' and s[1] == 'R':
    res += 1
for i in range(1,N-1):
    if s[i-1] == 'R' and s[i] == 'L':
        continue
    elif s[i+1] == 'L' and s[i] == 'R':
        continue
    res += 1
if s[N-1] == 'L' and s[N-2] == 'L':
    res += 1
res = min([N-1, res+2*K])
print(res)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
S = input()
out = ['0'] * len(S)
for i in range(K):
    if i!=0:
        S = ''.join(out)
    idx = 0
    maxidx = 0
    length = 1
    maxlen = 10000
    back = S[0]
    for j in range(len(S)):
        if back == S[j]:
            length += 1
        else:
            if length <= maxlen:
                #print(length)
                maxlen = length
                maxidx = j
                length = 1
            else:
                length = 1
                idx = j
        if length == j+2 and S[0] == 'L':
            length -= 1
        if j == len(S)-1 and S[j] == 'R':
            length -= 1
        back = S[j]
    temp = ['0'] * maxlen
    for j in range(maxlen):
        #print([maxidx,maxlen])
        if maxlen == 1:
            if S[maxidx + maxlen - j - 2] == 'L':
                temp[j] = 'R'
            else:
                temp[j] = 'L'
        else:
            if S[maxidx + maxlen - j - 1] == 'L':
                temp[j] = 'R'
            else:
                temp[j] = 'L'
    for j in range(len(S)):
        out[j] = S[j]
    for j in range(maxlen):
        if maxlen == 1:
            out[maxidx + j - 1] = temp[j]
        else:
            out[maxidx + j] = temp[j]
#print(''.join(out))
count=0
#right
for i in range(len(S)):
    if i==0 and out[i]=='L':
        continue
    elif i==N-1 and out[i]=='R':
        break
    if out[i]=='R' and out[i+1]=='R':
        count += 1
    if out[i]=='L' and out[i-1]=='L':
        count += 1
print(count)
Problem p03111 (python)

Fixed submission:
import numpy as np
import copy
N, A, B, C = map(int,input().split())
t = sorted([A,B,C])
A = t[0]
B = t[1]
C = t[2]
l = []
for i in range(N):
    l.append(int(input()))
dic = {}

def calc(ls):
    dic[tuple(ls)] = 0
    Asublist = [np.abs(i-A) for i in ls]
    res = min(Asublist)
    idx = Asublist.index(res)
    ls.remove(ls[idx])

    Bsublist = [np.abs(i-B) for i in ls]
    tmp = min(Bsublist)
    res += tmp
    idx = Bsublist.index(tmp)
    ls.remove(ls[idx])

    Csublist = [np.abs(i-C) for i in ls]
    tmp = min(Csublist)
    res += tmp
    idx = Csublist.index(tmp)
    ls.remove(ls[idx])

    return res + 10*(N - (len(ls)+3))

def rec(ls, num, maxcomb, minval):
    if num > maxcomb:
        return minval
    for i in range(0, len(ls)-1):
        for j in range(i+1, len(ls)):
            tmp = [ls[i]+ls[j]]
            tmp = tmp + [ls[k] for k in range(len(ls)) if k!=i and k!=j]
            if tuple(tmp) in dic.keys():
                continue
            tmp2 = calc(copy.deepcopy(tmp))
            if minval > tmp2:
                minval = tmp2
            if num < maxcomb:
                tmp3 = rec(copy.deepcopy(tmp), num+1, maxcomb, minval)
                if minval > tmp3:
                    minval = tmp3
    return minval
minval = rec(l, 1, N-3, calc(copy.deepcopy(l)))
print(minval)

Buggy submission (verdict: Runtime Error):
import numpy as np
import copy
N, A, B, C = map(int,input().split())
t = sorted([A,B,C])
A = t[0]
B = t[1]
C = t[2]
l = []
for i in range(N):
    l.append(int(input()))
dic = {}

def calc(ls):
    dic[tuple(ls)] = 0
    #print([np.abs(i-A) for i in ls])
    Asublist = [np.abs(i-A) for i in ls]
    #Asublist = list(sorted([np.abs(i-A) for i in ls]))[0:2]
    Bsublist = list(sorted([np.abs(i-B) for i in ls]))[0:2]
    Csublist = list(sorted([np.abs(i-C) for i in ls]))[0:2]
    res = min(Asublist)
    idx = Asublist.index(res)
    ls.remove(ls[idx])

    Bsublist = [np.abs(i-B) for i in ls]
    tmp = min(Bsublist)
    res += tmp
    idx = Bsublist.index(tmp)
    ls.remove(ls[idx])

    Csublist = [np.abs(i-C) for i in ls]
    tmp = min(Csublist)
    res += tmp
    idx = Csublist.index(tmp)
    ls.remove(ls[idx])

    #dic[tuple(ls)] = res
    return res + 10*(N - (len(ls)+3))

def rec(ls, num, maxcomb, minval):
    if num == 1:
        minval = calc(copy.deepcopy(ls))
    count = 0
    for i in range(0, len(ls)-1):
        for j in range(i+1, len(ls)):
            tmp = [ls[i]+ls[j]]
            tmp = tmp + [ls[k] for k in range(len(ls)) if k!=i and k!=j]
            #print(tmp)
            if tuple(tmp) in dic.keys():
                continue
            tmp2 = calc(copy.deepcopy(tmp))
            #print([minval, tmp2])
            if minval > tmp2:
                minval = tmp2
            if num < maxcomb:
                #print([i,j,num])
                #print(tmp)
                tmp3 = rec(copy.deepcopy(tmp), num+1, maxcomb, minval)
                if minval > tmp3:
                    minval = tmp3
    return minval
minval = rec(l, 1, N-3, np.inf)
print(minval)
Problem p03666 (python)

Fixed submission:
n,a,b,c,d=map(int,input().split())
e=abs(b-a)
if c+d+e==0:
    print("YES")
    exit()
upper=(e+(n-1)*d)//(c+d)
lower=(e+(n-1)*c)//(c+d)
if upper==lower:
    if (e+(n-1)*c) % (c+d) == 0 and 0<=lower and (e+(n-1)*c)/(c+d) <= n-1 and e <= (n-1)*max([c,d]):
        print("YES")
    else:
        print("NO")
else:
  if 0<=lower and (e+(n-1)*c)/(c+d) <= n-1 and e <= (n-1)*max([c,d]):
	    print("YES")
  else:
        print("NO")

Buggy submission (verdict: Runtime Error):
n,a,b,c,d=map(int,input().split())
e=abs(b-a)
if c+d+e==0:
    print("YES")
    exit()
upper=(e+(n-1)*d)//(c+d)
lower=(e+(n-1)*c)//(c+d)
if upper==lower:
    if (e+(n-1)*c) % (c+d) == 0 and 0<=lower and (e+(n-1)*c)/(c+d) <= n-1 and e <= (n-1)*max([c,d]):
        print("YES")
        print(2//0)
    else:
        print("NO")
else:
    if 0<=lower and (e+(n-1)*c)/(c+d) <= n-1 and e <= (n-1)*max([c,d]):
	    print("YES")
    else:
        print("NO")

Buggy submission (verdict: Runtime Error):
n,a,b,c,d=map(int,input().split())
e=abs(b-a)
if c+d+e==0:
    print("YES")
    exit()
upper=(e+(n-1)*d)//(c+d)
lower=(e+(n-1)*c)//(c+d)
if upper==lower:
    if (e+(n-1)*c) % (c+d) == 0 and 0<=lower and (e+(n-1)*c)/(c+d) <= n-1 and e <= (n-1)*max([c,d]):
        print("YES")
        print(2//0)
    else:
        print("NO")
else:
    print("YES")
Problem p03716 (python)

Fixed submission:
import bisect
import heapq
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int,input().split()))
a_left = sorted(a[:N])
a_right = sorted(a[2*N:])
sum_left = sum(a_left)
sum_right = sum(a_right)
#res = sum_left - sum_right
res = sum_left - sum(sorted(a[N:])[:N])
a_right = [-elem for elem in a_right]
heapq.heapify(a_right)
heapq.heapify(a_left)
sr = [0]*(N+1)
sr[0] = sum_right

for i,elem in enumerate(reversed(a[N:2*N])):
    now = -heapq.heappop(a_right)
    if now > elem:
        heapq.heappush(a_right, -elem)
        sum_right += (elem-now)
    else:
        heapq.heappush(a_right, -now)
    sr[i+1] = sum_right

for i,elem in enumerate(a[N:2*N]):
    now = heapq.heappop(a_left)
    if now < elem:
        heapq.heappush(a_left, elem)
        sum_left += (elem-now)
    else:
        heapq.heappush(a_left, now)
    res = max(res, sum_left-sr[N-i-1])
print(res)

Buggy submission (verdict: Runtime Error):
import bisect
import heapq
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int,input().split()))
a_left = sorted(a[:N])
a_right = sorted(a[N:])
sum_left = sum(a_left)
sum_right = sum(a_right[:N])
res = sum_left - sum_right

heapq.heapify(a_left)

len_left = N
for elem in a[N:2*N]:
    le = bisect.bisect_left(a_right, elem)
    a_right[le:] = a_right[le+1:]
    if le < N:
        sum_right -= elem
        sum_right += a_right[N-1]
    now = heapq.heappop(a_left)
    if now < elem:
        heapq.heappush(a_left, elem)
        sum_left += (elem-now)
    else:
        heapq.heappush(a_left, now)
    res = max(res, sum_left-sum_right)
print(res)

"""
Problem p03838 (python)

Fixed submission:
x,y=map(int,input().split())
res = 0
if 0<=x<=y:
    res = y-x
elif 0<y<x:
    res = x-y+2
elif y==0 and x>0:
    res = x+1
elif y==0 and x<0:
    res = abs(x)
elif x==0 and y>0:
    res = y
elif x==0 and y<0:
    res = abs(y)+1
elif x<0<y:
    res = abs(x+y)+1
elif y<0<x:
    res = abs(x+y)+1
elif x<=y<=0:
    res = y-x
elif y<x<=0:
    res = x-y+2
print(res)

Buggy submission (verdict: Runtime Error):
x,y=map(int,input().split())
res = []
if x>0 and y>0:
    res.append(abs(y-x))
elif x*y<0:
    res.append(1+abs(y+x))
elif x<0 and y<0:
    res.append(2+abs(y-x))
print(min(res))
Problem p02646 (python)

Fixed submission:
import sys

a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if (a == b):
    print('YES')
    sys.exit(0)
if (v <= w):
    print('NO')
    sys.exit(0)
res = abs(a - b) / (v - w)
if (res > t):
    print('NO')
else:
    print('YES')
sys.exit(0)

Buggy submission (verdict: Runtime Error):
import sys

a, v = map(int, inpu().split())
b, w = map(int, inpu().split())
t = int(input())
if (a == b):
  print('YES')
  sys.exit(0)
if (v <= w):
  print('NO')
  sys.exit(0)
res = abs(a - b) / (v - w)
if (res > t):
  print('NO')
else:
  print('YES')
sys.exit(0)