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

Fixed submission:
# -*- coding: utf-8 -*-

h, w = map(int, input().split())
a = [""]*h
for i in range(h):
    a[i] = input()

row = [False] * h
col = [False] * w


for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            row[i] = True
            col[j] = True


for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                print(a[i][j], end = "")

        print()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

h,w = map(int, input().split())

a = [list(input()) for _ in range(h)]

a_new = []
for row in a:
    cache = set(row)
    if (len(cache) == 1) and (row[0] == "."):
        pass
    else:
        a_new.append(row)

n_h = len(a_new)
n_w = len(a_new[0])

b_new = [["" for _ in range(n_h)] for _ in range(n_w)]

for i in range(n_h):
    for j in range(n_w):
        b_new[j][i]=a_new[i][j]


a = b_new

a_new = []
for row in a:
    cache = set(row)
    if (len(cache) == 1) and (row[0] == "."):
        pass
    else:
        a_new.append(row)


n_h = len(a_new)
n_w = len(a_new[0])

b_new = [["" for _ in range(n_h)] for _ in range(n_w)]

for i in range(n_h):
    for j in range(n_w):
        b_new[j][i]=a_new[i][j]


ans = ""

for i in range(n_h):
    for j in range(n_w):
        ans += b_new[i][j]
    ans += "\n"

print(ans)
Problem p03352 (python)

Fixed submission:
# -*- coding: utf-8 -*-

x = int(input())

kk = [1, 4, 8, 9, 16, 25, 27, 32, 36, 49, 64, 81, 100, 121, 125, 128, 144, 169, 196, 216, 225, 243, 256, 289, 324, 343, 361, 400, 441, 484, 512, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1000]

ans = [i for i in kk if (i <= x)]
print(ans[-1])

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

asset = []

for b in range(1,100):
    for p in range(2,100):
        tmp = pow(b, p)
        if tmp < 1001:
            if tmp not in asset:
                asset.append(tmp)

#print(asset)

x = int(input())

new_asset = []
for i in range(len(asset)):
    if asset[i] < x:
        new_asset.append(asset[i])

print(max(new_asset))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

asset = []

for b in range(1,1000):
    for p in range(2,100):
        tmp = pow(b, p)
        if tmp < 1001:
            if tmp not in asset:
                asset.append(tmp)

#print(asset)

x = int(input())

new_asset = []
for i in range(len(asset)):
    if asset[i] < x:
        new_asset.append(asset[i])

print(max(new_asset))
Problem p03386 (python)

Fixed submission:
# -coding: utf-8 -

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

s = range(a,b+1)
s_small = s[:k]
s_large = s[-k:]
ans = list(set(s_small)|set(s_large))
ans = sorted(ans)
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
# -coding: utf-8 -

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

s = range(a,b+1)
add = "\n"
#print(s)

if len(s) < k*2:
    strs = [str(num) for num in s]
    k = add.join(strs)
else:
    s_left = s[:k]
    s_right = s[-k:]
    s2 = s_left+s_right
    strs = [str(num) for num in s2]
    k = add.join(strs)
print(k)
Problem p03474 (python)

Fixed submission:
# -coding: utf-8 -

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

isNo = False
if s[a] != "-":
    isNo = True
else:
    try:
        int(s[:a])
    except:
        isNo = True

    try:
        int(s[a+1:])
    except:
        isNo = True

if isNo:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
# -coding: utf-8 -

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

if s[a] != "-":
    isNo = True
else:
    try:
        int(s[:a])
    except:
        isNo = True

    try:
        int(s[a:])
    except:
        isNo = True

if isNo:
    print("No")
else:
    print("Yes")
Problem p02619 (python)

Fixed submission:
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(D)]
t = [int(input())-1 for _ in range(D)]

S = 0
last = [-1]*26
score = 0;
for d in range(D):
    S += s[d][t[d]]
    last[t[d]] = d
    for i in range(26):
        S-=c[i]*(d - last[i])
    score +=max(10**6+S,0)
    print(S)

Buggy submission (verdict: Runtime Error):
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(D)]
t = [int(input()) for _ in range(D)]

S = 0
last = [-1]*26
score = 0;
for d in range(D):
    S += s[d][t[d]]
    last[t[d]] = d
    for i in range(26):
        S-=c[i]*(d - last[i])
    score +=max(10**6+S,0)
    print(S)
Problem p02632 (python)

Fixed submission:
K = int(input())
S =input()

def cmb(n,r,p):
    if(r<0) or (n<r):
        return 0
    return fact[n]*factinv[r]*factinv[n-r]%p

p = 10 ** 9 + 7
N = 2 * 10**6+3
fact = [1] * ( N + 3)
factinv = [1] * (N + 3)
inv = [0]* (N + 3)
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
    factinv[i] = factinv[i-1] * inv[i] % p

def powmod(a,n,mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n>>=1
    return res

ss = len(S)
ans = 0
k = 1;
for i in range(K+1):
    ans += cmb(ss+K-i-1,ss-1,p) * k * powmod(25,K-i,p)
    ans %= p
    k = k * 26 % p

print(ans)

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

def cmb(n,r,p):
    if(r<0) or (n<r):
        return 0
    r = min(r,n-r)
    return fact[n]*factinv[r]*factinv[n-r]%p

p = 10 ** 9 + 7
N = 10**6+3
fact = [1] * ( N + 3)
factinv = [1] * (N + 3)
inv = [0]* (N + 3)
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
    factinv[i] = factinv[i-1] * inv[i] % p

def powmod(a,n,mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n>>=1
    return res

ss = len(S)
ans = 0
k = 1;
for i in range(K+1):
    ans += cmb(ss+K-i-1,ss-1,p) * k * powmod(25,K-i,p)
    ans %= p
    k = k * 26 % p

print(ans)

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

def cmb(n,r,p):
    if(r<0) or (n<r):
        return 0
    r = min(r,n-r)
    return fact[n]*factinv[r]*factinv[n-r]%p

p = 10 ** 9 + 7
N = 10**6+3
fact = [1] * ( N + 3)
factinv = [1] * (N + 3)
inv = [0]* (N + 3)
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
    factinv[i] = factinv[i-1] * inv[i] % p

def powmod(a,n,mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n>>=1
    return res

ss = len(S)
ans = 0
k = 1;
for i in range(K+1):
    ans += cmb(ss+K-i-1,ss-1,p) * k * powmod(25,K-i,p)
    ans %= p
    k = k * 26 % p

print(ans)
Problem p02713 (python)

Fixed submission:
from math import gcd
N = int(input())
sum = 0
for i in range(1, N+1):
    for j in range(1, N+1):
        tmp=gcd(i,j)
        for k in range(1, N+1):
            sum += gcd(tmp,k)
print(sum)

Buggy submission (verdict: Runtime Error):
from math import gcd
N = int(input())
sum = 0
for i in range(1, N+1):
    for j in range(1, N+1):
		tmp=gcd(j,k)
        for k in range(1, N+1):
            sum += gcd(i, tmp)
print(sum)

Buggy submission (verdict: Runtime Error):
from math import gcd
N = int(input())
sum = 0
for i in range(1, N+1):
    for j in range(1, N+1):
		tmp=gcd(j,k);
        for k in range(1, N+1):
            sum += gcd(i, tmp)
print(sum)
Problem p02742 (python)

Fixed submission:
import math
H, W = [int(_) for _ in input().split(" ")]
if (H == 1 or W == 1):
  print(1)
elif (H % 2 == 0):
  print(int(H/2*W))
else:
  print(int(H/2)*W+math.ceil(W/2))

Buggy submission (verdict: Runtime Error):
import math
H, W = [int(_) for _ in input().split(" ")]
if (H == 1 or W == 1):
  print(1)
else if (H % 2 == 0):
  print(int(H/2*W))
else:
  print(int(H/2)*W+math.ceil(W/2))
Problem p02789 (python)

Fixed submission:
N, M = input().split(" ")
N = int(N)
M = int(M)
if (M == N):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
def gcd(m, n):
    return m if n == 0 else gcd(n, m%n)

def lcm(m, n):
    return m*n/gcd(m, n)

def find_loop():
    N = int(input())
    nums = [int(x) for x in input().split(" ")]
    current_lcm = nums[0]
    for i in range(1, N):
        current_lcm = lcm(current_lcm, nums[i])
    ret = 0
    for i in range(N):
        ret = (ret+current_lcm/nums[i]) % 1000000007
    print(int(ret))


find_loop()

Buggy submission (verdict: Runtime Error):
N, M = input().split(" ")
N = int(N)
M = int(M)
if (M >= 0 and M == N):
  return True
else:
  return False
Problem p02665 (python)

Fixed submission:
import sys
n=int(input())
a=list(map(int,input().split()))
ans=0
m=sum(a)
leaf=1
for i in range(n+1):
    ans+=leaf
    leaf=leaf-a[i]
    m-=a[i]

    if leaf<0 or (leaf==0 and m>0):
        print(-1)
        sys.exit()

    tmp=leaf
    for j in range(min(n-i,60)):
        tmp*=2
        if tmp>=m: break
    if tmp<m:
        print(-1)
        sys.exit()        

    if leaf*2>=m: leaf=m
    else: leaf*=2

print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
ans=0
m=sum(a)
leaf=1
for i in range(n+1):
    ans+=leaf
    leaf=leaf-a[i]
    m-=a[i]

    if leaf<0 or (leaf==0 and m>0): print(-1);sys.exit()
    tmp=leaf
    for j in range(min(n-i,50)):
        tmp*=2
        if tmp>=m: break
    if tmp<m: print(-1);sys.exit()        
    if leaf*2>=m: leaf=m
    else: leaf*=2
print(ans)
Problem p02705 (python)

Fixed submission:
import math
r=int(input())
print(r*math.pi*2)

Buggy submission (verdict: Runtime Error):
pi=3.141592653589793238462643383279 
r=int(input())
print(r*math.pi*2)
Problem p02716 (python)

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


if n==2:
    print(max(a))
    sys.exit()

a0=[a[0],a[0]]
a1=[0,a[1]]
a2=[0,0,a[2]]
for i in range(2,n):
    if i%2==0:
        a0.append(a0[i-2]+a[i])
        a1.append(a1[i-1])
        if i>=4: a2.append(max(a2[i-2],a1[i-3],a0[i-4])+a[i])
    else:
        a0.append(a0[i-1])
        a1.append(max(a1[i-2],a0[i-3])+a[i])
        a2.append(a2[i-1])

if n%2==1: print(max(a0[n-1],a1[n-1],a2[n-1]))
else: print(max(a0[n-1],a1[n-1]))

Buggy submission (verdict: Runtime Error):
import sys
n=int(input())
a=list(map(int,input().split()))
a0=[a[0],a[0]]
a1=[0,a[1]]
a2=[0,0,a[2]]
for i in range(2,n):
    if i%2==0:
        a0.append(a0[i-2]+a[i])
        a1.append(a1[i-1])
        if i>=4: a2.append(max(a2[i-2],a1[i-3],a0[i-4])+a[i])
    else:
        a0.append(a0[i-1])
        a1.append(max(a1[i-2],a0[i-3])+a[i])
        a2.append(a2[i-1])

if n%2==1: print(max(a0[n-1],a1[n-1],a2[n-1]))
else: print(max(a0[n-1],a1[n-1]))
Problem p02749 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**5+1)

def cur(p):
    for i in x[p]:
        if rank[i]==-1:
            rank[i]=rank[p]+1
            par[i]=p
            cur(i)


n=int(input())
x=[[] for i in range(n)]

for i in range(n-1):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    x[a].append(b)
    x[b].append(a)

rank=[-1 for i in range(n)]
rank[0]=0
par=[-1 for i in range(n)]

cur(0)
M=max(rank)
x=[[] for i in range(M+1)]

q=[0,0]
r=[n//3,n//3,n//3]
if n%3>0: r[1]+=1
if n%3>1: r[2]+=1
tmp1,tmp2,tmp3=1,2,3

for i in range(n):
    q[rank[i]%2]+=1
    x[rank[i]].append(i)
ans=[-1 for i in range(n)]

"""
if q[0]>r[0]+r[1] or q[1]>r[0]+r[2]:
    if q[0]>r[0]+r[2] or q[1]>r[0]+r[1]:
        tmp1,tmp2=2,1
"""

if q[0]<=r[0]+r[1] and q[1]<=r[0]+r[2]:
    for i in range(n):
        if rank[i]%2==0:
            if tmp1<=n:
                ans[i]=tmp1
                tmp1+=3
            else:
                ans[i]=tmp3
                tmp3+=3
        else:
            if tmp2<=n:
                ans[i]=tmp2
                tmp2+=3
            else:
                ans[i]=tmp3
                tmp3+=3

elif q[0]<=r[0]:
    for i in range(n):
        if rank[i]%2==0:
            ans[i]=tmp3
            tmp3+=3
        else:
            if tmp1<=n:
                ans[i]=tmp1
                tmp1+=3
            elif tmp2<=n:
                ans[i]=tmp2
                tmp2+=3
            else:
                ans[i]=tmp3
                tmp3+=3

elif q[1]<=r[0]:
    for i in range(n):
        if rank[i]%2==1:
            ans[i]=tmp3
            tmp3+=3
        else:
            if tmp1<=n:
                ans[i]=tmp1
                tmp1+=3
            elif tmp2<=n:
                ans[i]=tmp2
                tmp2+=3
            else:
                ans[i]=tmp3
                tmp3+=3

    

for i in range(n-1):
    print(ans[i],end=" ")
print(ans[n-1])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5+1)

def cur(p):
    for i in x[p]:
        if rank[i]==-1:
            rank[i]=rank[p]+1
            par[i]=p
            cur(i)


n=int(input())
x=[[] for i in range(n)]

for i in range(n-1):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    x[a].append(b)
    x[b].append(a)

rank=[-1 for i in range(n)]
rank[0]=0
par=[-1 for i in range(n)]

cur(0)
M=max(rank)
x=[[] for i in range(M+1)]

q=[0,0]
r=[n//3,n//3,n//3]
if n%3>0: r[1]+=1
if n%3>1: r[2]+=1
tmp1,tmp2,tmp3=1,2,3

for i in range(n):
    q[rank[i]%2]+=1
    x[rank[i]].append(i)
ans=[-1 for i in range(n)]


if q[0]>r[0]+r[1] or q[1]>r[0]+r[2]:
    if q[0]>r[0]+r[2] or q[1]>r[0]+r[1]:
        print(-1)
        sys.exit()
    else:
        tmp1,tmp2=2,1


for i in range(M+1):
    if i%2==0:
        for p in x[i]:
            if tmp1<=n:
                ans[p]=tmp1
                tmp1+=3
            else:
                ans[p]=tmp3
                tmp3+=3
    else:
        for p in x[i]:
            if tmp2<=n:
                ans[p]=tmp2
                tmp2+=3
            else:
                ans[p]=tmp3
                tmp3+=3


for i in range(n-1):
    print(ans[i],end=" ")
print(ans[n-1])
Problem p02761 (python)

Fixed submission:
import sys
n,m=map(int,input().split())
a=[-1 for i in range(n)]

for i in range(m):
    s,c=map(int,input().split())
    s-=1

    if n!=1 and s==0 and c==0:
        print(-1)
        sys.exit()

    if a[s]!=-1 and a[s]!=c:
        print(-1)
        sys.exit()
    else:
        a[s]=c


if n==1 and (a[0]==0 or a[0]==-1):
    print(0)
    sys.exit()

x=""
if a[0]==-1: a[0]=1
for i in range(n):
    if a[i]==-1: a[i]=0
    x+=str(a[i])
print(x)

Buggy submission (verdict: Runtime Error):
import sys
n,m=map(int,input().split())
s=[]
c=[]
for i in range(m):
    ts,tc=map(int,input().split())
    ts-=1
    s.append(ts)
    c.append(tc)

if n==1:
    ans=min(c)
    for i in range(m):
        if ans!=c[i]:
            print(-1)
            sys.exit()

if n!=1:
    ans=[1]+[0 for i in range(n-1)]
    for i in range(m):
        if s[i]==0 and c[i]==0:
            print(-1)
            sys.exit()
        ans[s[i]]=max(ans[s[i]],c[i])


    for i in range(m):
        if ans[s[i]]!=c[i]:
            print(-1)
            sys.exit()
    for i in range(n):
        print(ans[i],end="")

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[-1 for i in range(n)]

for i in range(m):
    s,c=map(int,input().split())
    s-=1

    if a[s]!=-1 and a[s]!=c:
        print(-1)
        sys.exit()
    elif s==0 and c==0:
        print(-1)
        sys.exit()
    else:
        a[s]=c
        
x=""
for i in range(n):
    if a[i]==-1: a[i]=0
    x+=str(a[i])
print(x)
Problem p02768 (python)

Fixed submission:
def modinv(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return lastx % (10**9+7)

MOD=10**9+7
am=[2]
for i in range(60):
    am.append((am[-1]**2)%MOD)

fr=[1]
for i in range(1,2*(10**5)+10):
    fr.append((fr[-1]*i)%MOD)

n,a,b=map(int,input().split())
a=min(a,n-a)
b=min(b,n-b)
s=bin(n)[2::][::-1]

ans=1
for i in range(len(s)):
    if s[i]=="1":
        ans*=am[i]
        ans%=MOD

for x in [a,b]:
    tmp=1
    for i in range(n-x+1,n+1):
        tmp=(tmp*i)%MOD
    tmp*=modinv(fr[x],MOD)
    ans=(ans-tmp)%MOD

ans=(ans-1)%MOD
print(ans)

Buggy submission (verdict: Runtime Error):
def modinv(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return lastx % (10**9+7)

MOD=10**9+7
am=[2]
for i in range(50):
    am.append((am[-1]**2)%MOD)
fr=[1]
for i in range(1,2*(10**5)):
    fr.append((fr[-1]*i)%MOD)

n,a,b=map(int,input().split())
a=min(a,n-a)
b=min(b,n-b)
s=bin(n)[2::][::-1]

ans=1
for i in range(len(s)):
    if s[i]=="1":
        ans*=am[i]
        ans%=MOD

for x in [a,b]:
    tmp=1
    for i in range(n-x+1,n+1):
        tmp=(tmp*i)%MOD
    tmp*=modinv(fr[x],MOD)
    ans=(ans-tmp)%MOD

ans=(ans-1)%MOD
print(ans)
Problem p02814 (python)

Fixed submission:
import math
import sys

def gcd(a,b):
    if b>a:
        a,b=b,a
    while b:
        a,b=b, a%b
    return a

def f(n):
    return int(n)//2

n,m=map(int,input().split())
a=list(map(f,input().split()))


tmp=1
for i in range(n):
    tmp=(tmp*a[i])//gcd(tmp,a[i])
    if tmp>m:
        print(0)
        sys.exit()


for i in range(n):
    if (tmp//a[i])%2==0:
        print(0)
        sys.exit()

ans=m//(tmp*2)
if m%(tmp*2)>=tmp: ans+=1
print(ans)

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

def gcd(a,b):
    if b>a:
        a,b=b,a
    while b:
        a,b=b, a%b
    return a

def f(n):
    return int(n)//2

n,m=map(int,input().split())
a=list(map(f,input().split()))


tmp=1
for i in range(n):
    tmp=(tmp*a[i])//gcd(tmp,a[i])


for i in range(n):
    if (tmp/a[i])%2==0: print(0),sys.exit()

ans=m//(tmp*2)
if m%(tmp*2)>=tmp: ans+=1
print(ans)
Problem p02817 (python)

Fixed submission:
def f(i):
    return i
s,t=map(f,input().split())
print(t+s)

Buggy submission (verdict: Runtime Error):
import sys

def f(x):
    p=0
    cnt=0
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<x:
            p+=1
        cnt+=n-p
    return cnt

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

l,r=a[0]*2,a[n-1]*2

while r-l>0:
    if r-l<=1:
        if f(r)==m: md=r;break 
        else: md=l;break
    md=(r+l)//2
    k=f(md)
    if k==m: break
    elif k>m: l=md
    else: r=md

p=0
cnt=0
ans=0

for q in range(n-1,-1,-1):
    try:
        while (p<n and a[q]+a[p]<=md):
            p+=1
    except:
        p=n

    if p==n: break
    cnt+=n-p
    ans+=a[q]*(n-p)*2


ans+=(m-cnt)*md
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

def f(x):
    p=0
    cnt=0
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<x:
            p+=1
        cnt+=n-p
    return cnt

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

l,r=a[0]*2,a[n-1]*2

while r-l>0:
    if r-l<=1:
        if f(r)==m: md=r;break 
        else: md=l;break
    md=(r+l)//2
    k=f(md)
    if k==m: break
    elif k>m: l=md
    else: r=md

p=0
cnt=0
ans=0

for q in range(n-1,-1,-1):
    try:
        while p<n and a[q]+a[p]<=md:
            p+=1
    except:
        print(ans)
        sys.exit()

    if p==n: break
    cnt+=n-p
    ans+=a[q]*(n-p)*2


ans+=(m-cnt)*md
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

def f(x):
    p=0
    cnt=0
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<x:
            p+=1
        cnt+=n-p
    return cnt

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

l,r=a[0]*2,a[n-1]*2

while r-l>0:
    if r-l<=1:
        if f(r)==m: md=r;break 
        else: md=l;break
    md=(r+l)//2
    k=f(md)
    if k==m: break
    elif k>m: l=md
    else: r=md

p=0
cnt=0
ans=0

for q in range(n-1,-1,-1):
    try:
        while p<n and a[q]+a[p]<=md:
            p+=1
        if p==n: break
        cnt+=n-p
        ans+=a[q]*(n-p)*2
    except:
        print(0)
        sys.exit()


ans+=(m-cnt)*md
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

def f(x):
    p=0
    cnt=0
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<x:
            p+=1
        cnt+=n-p
    return cnt

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

l,r=a[0]*2,a[n-1]*2

while r-l>0:
    if r-l<=1:
        if f(r)==m: md=r;break 
        else: md=l;break
    md=(r+l)//2
    k=f(md)
    if k==m: break
    elif k>m: l=md
    else: r=md

p=0
cnt=0
ans=0

try:
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<=md:
            p+=1
        if p==n: break
        cnt+=n-p
        ans+=a[i]*(n-p)*2
    


except:
    print(0)

ans+=(m-cnt)*md
print(ans)
Problem p02853 (python)

Fixed submission:
import sys
import math

X,Y=map(int,input().split())
ans=0
if X==1:   ans+=300000
elif X==2: ans+=200000
elif X==3: ans+=100000

if Y==1:   ans+=300000
elif Y==2: ans+=200000
elif Y==3: ans+=100000

if X==1 and Y==1: ans+=400000
print(ans)

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

M=int(input())
ans=0
a=[list(map(int,input().split())) for i in range(M)]
b=[0 for i in range(M)]

for i in range(M):
    ans+=a[i][1]-1
    b[i]=a[i][0]*a[i][1]
    while b[i]>=10:
        ans+=b[i]//10
        b[i]=b[i]//10+b[i]%10


ans+=M-1 + sum(b)//10
print(int(ans))
Problem p02865 (python)

Fixed submission:
N=int(input())
if N%2==0: print(N//2-1)
else: print(N//2)

Buggy submission (verdict: Runtime Error):
import sys

N=int(input())

a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=[[a[i],i] for i in range(N)]
b=[[b[i],i] for i in range(N)]
aa,bb=sorted(a),sorted(b)

for i in range(N):
    if aa[i][0]>bb[i][0]: print("No"),sys.exit()

for i in range(N-1):
    if aa[i][0]==aa[i+1][0] or bb[i][0]==bb[i+1][0]: print("Yes"),sys.exit()
    if bb[i][0]>=aa[i+1][0]: print("Yes"),sys.exit()


dicb={}
for i in range(N):
    dicb[bb[i][0]]=i
tmp=0
j=0
while tmp<N-2:
    j=dicb[b[j][0]]
    if j==0: print("Yes"),sys.exit()
    tmp+=1
print("No")
Problem p02909 (python)

Fixed submission:
def main():
    ans=["Sunny","Cloudy","Rainy"]
    print(ans[(ans.index(input())+1)%3])
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    def func(s):
        return ord(s)-ord('a')

    n=int(input())
    s=input()
    s=[func(s[i]) for i in range(n)]
    sign=0
    ans=0
    for i in range(n-1):
        if ans>(n-i)//2: break
        for j in range(i+1,n):
            if s[j]==s[i+sign] and i+2*sign<j:
                sign+=1
    
            else:
                ans=max(sign,ans)
                sign=0
                
        ans=max(sign,ans)
        sign=0

    ans=max(sign,ans)
    print(ans)
            

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    def func(s):
        return ord(s)-ord('a')

    n=int(input())
    s=input()
    s=[func(s[i]) for i in range(n)]
    sign=0
    ans=0
    for i in range(n-1):
        for j in range(i+1,n):
            if s[j]==s[i+sign] and i+2*sign<j:
                sign+=1

            else:
                if sign>ans: ans=sign
                sign=0
        
        if sign>ans: ans=sign
        sign=0

    print(ans)
        

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    def func(s):
        return ord(s)-ord('a')

    n=int(input())
    s=input()
    s=[func(s[i]) for i in range(n)]
    sign=0
    ans=0
    for i in range(n-1):

        if ans>(n-i)/2: break

        for j in range(i+1,n):
            if s[j]==s[i+sign] and i+2*sign<j:
                sign+=1

            else:
                if sign>ans: ans=sign
                sign=0
        
        if sign>ans: ans=sign
        sign=0

    print(ans)
        

if __name__ == '__main__':
    main()
Problem p02945 (python)

Fixed submission:
a,b=map(int,input().split())
print(max(a+b,a-b,a*b))

Buggy submission (verdict: Runtime Error):
from heapq import heappop,heappush
n,m=map(int,input().split())
work=[set() for _ in range(m+1)]
for _ in range(n):
    a,b=map(int,input().split())
    if a<=m: work[a].add(b)

ans=0
q=[]
for i in range(1,m+1):
    for x in work[i]:
        heappush(q,-x)
    if q!=[]: ans+=heappop(q)
print(-ans)