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

Fixed submission:
n,q = map(int,input().split())
s = list(input())
p = [tuple(map(str,input().split())) for i in range(q)]

#s[x]が左へ抜けるか O(q)
def judge_left(x):
    for i in range(q):
        if p[i][0] == s[x]:
            if p[i][1] == 'L':
                x -= 1
            else:
                x += 1
        if x == -1:
            return True
        if x == n:
            return False
    return False

#s[x]が右へ抜けるか O(q)
def judge_right(x):
    for i in range(q):
        if p[i][0] == s[x]:
            if p[i][1] == 'L':
                x -= 1
            else:
                x += 1
        if x == -1:
            return False
        if x == n:
            return True
    return False

#どこまで左で抜けるか
ok = -1
ng = n
while ng-ok > 1:
    mid = (ng+ok)//2
    if judge_left(mid):
        ok = mid
    else:
        ng = mid
left = ok+1

#どこまで右で抜けるか
ok = n
ng = -1
while ok-ng >1:
    mid = (ok+ng)//2
    if judge_right(mid):
        ok = mid
    else:
        ng = mid
right = n-ok

print(max(n-left-right,0))

Buggy submission (verdict: Runtime Error):
n,q = map(int,input().split())
s = list(input())
p = []
for i in range(q):
    t,d = map(str,input().split())
    p.append([t,d])

res = 0
cnt = 0
end = True
bef = ''
judge = s[0]
for i in range(q-1,-1,-1):
    if p[i][0] == bef and p[i][1] == 'R':
        end = False
        judge = bef
        cnt -= 1
        if cnt == 0:
            bef = ''
        else:
            bef = s[cnt-1]
    elif p[i][0] == judge and p[i][1] == 'L':
        if cnt+1>=res:
            end = True
        res = max(cnt+1,res)
        cnt += 1
        if res == n:
            break
        while judge==s[cnt] and cnt <= n-1:
            cnt += 1
            res += 1
        bef = judge
        judge = s[cnt]
if not end:
    res -= 1
res = max(0,res)

bef = ''
cnt = 0
end = True
res2 = 0
judge = s[n-1]
for i in range(q-1,-1,-1):
    if p[i][0] == bef and p[i][1] == 'L':
        end = False
        judge = bef
        cnt -= 1
        if cnt == 0:
            bef = ''
        else:
            bef = s[n-1-cnt+1]
    elif p[i][0] == judge and p[i][1] == 'R':
        if cnt+1 >= res2:
            end = True
        res2 = max(cnt+1,res2)
        cnt += 1
        if res2 == n:
            break
        while judge == s[n-1-cnt] and cnt <= n-1:
            res2 += 1
            cnt += 1
        bef = judge
        judge = s[max(0,n-1-cnt)]
if not end:
    res2 -= 1
res2 = max(0,res2)

print(max(min(n,n-res-res2),0))
Problem p03089 (python)

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

n = int(input())
b = list(map(int,input().split()))

res = [-1]*n
#今考えている数列のindex、ないなら-1
ind = [i for i in range(1,n+1)]
#決定した数
cnt = 0
while cnt != n:
    #judge:変化があるか
    judge = False
    for i in range(n-1,-1,-1):
        if ind[i] == b[i]:
            ind[i] = -1
            res[n-1-cnt] = b[i]
            cnt += 1
            judge = True
            break
        else:
            ind[i] -= 1
    if not judge:
        print(-1)
        exit()
for e in res:
    print(e)

Buggy submission (verdict: Runtime Error):
#落ち着くのんな
import sys
input = sys.stdin.readline

n = int(input())
b = list(map(int,input().split()))


used = [True]*n
res = [0]*n
for i in range(1,n+1):
    
    for j in range(n-1,-1,-1):
        if b[j] == i:
            res[tank] = i
            tank = cnt + 1
            cnt = 0
        else:
            cnt += 1
Problem p03157 (python)

Fixed submission:
h,w = map(int,input().split())
s = [None]*h
for i in range(h):
    s[i]=list(input())
    
###########
#Union Find
par = [] #親
rank = [] #木の深さ

#初期化
for i in range(h*w):
    #par[i]:i rank[i]:0
    par.append(i)
    rank.append(0)

#木の根を求める
def find(x,par):
    if par[x] == x:
        return x
    else:
        return find(par[x],par)

#xとyの属する集合の併合
def unite(x,y,par,rank):
    x = find(x,par)
    y = find(y,par)
    
    if x != y:
        #xとyの属している集合が異なる時
        if rank[x] < rank[y]:
            par[x] = y
        else:
            par[y] = x
            if rank[x]==rank[y]:
                rank[x] += 1

#xとyが同じ集合に属するかの判定
def same(x,y,par):
    return find(x,par) == find(y,par)
###############
for i in range(h*w):
    if i//w + 1 < h and s[i//w][i%w] != s[i//w+1][i%w]:
        unite(i,i+w,par,rank)
    if i%w +1 < w and s[i//w][i%w] != s[i//w][i%w+1]:
        unite(i,i+1,par,rank)

res = [[0,0] for i in range(w*h)] #[".","#"]
for i in range(h*w):
    r = find(i,par)
    if s[i//w][i%w] ==".":
        res[r][0]+=1
    else:
        res[r][1]+=1

ans = 0
for i in range(h*w):
    ans += res[i][0]*res[i][1]
print(ans)

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split())
s = [None]*h
for i in range(h):
    s[i]=list(input())

res = 0
ans = [[0]*w for i in range(h)]


def f(x,y):
    c = 0
    if x+1 < h and s[x+1][y] =="#" and ans[x+1][y] == 0:
        ans[x+1][y] = 1
        c += 1
        if x+2 < h and s[x+2][y] == ".":
            c += f(x+2,y)
        if y+1 < w and s[x+1][y+1] == ".":
            c += f(x+1,y+1)
    if y+1 < w and s[x][y+1] == "#" and ans[x][y+1] == 0:
        ans[x][y+1] = 1
        c += 1
        if x+1 <h and s[x+1][y+1] == ".":
            c += f(x+1,y+1)
        if y+2 < w and s[x][y+2] == ".":
            c += f(x,y+2)
    return c

def g(x,y):
    c = 0
    if x+1 < h and s[x+1][y] =="." and ans[x+1][y] == 0:
        ans[x+1][y] = 1
        c += 1
        if x+2 < h and s[x+2][y] == "#":
            c += g(x+2,y)
        if y+1 < w and s[x+1][y+1] == "#":
            c += g(x+2,y)
    if y+1 < w and s[x][y+1] == "." and ans[x][y+1] == 0:
        ans[x][y+1] = 1
        c += 1
        if x+1 <h and s[x+1][y+1] == "#":
            c += g(x+1,y+1)
        if y+2 < w and s[x][y+2] == "#":
            c += g(x,y+2)
    return c
res = 0
for i in range(h):
    for j in range(w):
        ans = [[0]*w for i in range(h)]
        if s[i][j] == ".":
            #print(f(i,j))
            res += f(i,j)
        else:
            #print(g(i,j))
            res += g(i,j)
            

print(res)
Problem p03169 (python)

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
a = tuple(map(int,input().split()))
c1 = a.count(1)
c2 = a.count(2)
c3 = a.count(3)

dp = [[[0.0]*(n+1) for i in range(n+1)] for j in range(n+1)] 
dp[0][0][0] = 0
for i in range(c3+1):
    for j in range(c2+c3-i+1):
        for k in range(n-i-j+1):
            if i == j == k == 0:
                continue
            tmp = n
            if k != 0:
                tmp += k*dp[k-1][j][i]
            if j != 0:
                tmp += j*dp[k+1][j-1][i]
            if i != 0:
                tmp += i*dp[k][j+1][i-1]
            dp[k][j][i] = tmp/(i+j+k)

print(dp[c1][c2][c3])

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
input = sys.stdin.readline
n=int(input())
a = tuple(map(int,input().split()))
cnt = [0,0,0] #1個の個数、二個の個数、三個の個数
for i in range(n):
    cnt[a[i]-1] += 1
    
def f(i,j,k):
    if [i,j,k] == [0,0,0]:
        return 0.0
    if dp[i][j][k] != 0.0:
        return dp[i][j][k]
    tmp = 0.0
    if i>0:
        tmp += f(i-1,j,k)*float(i)/float(i+j+k)
    if j>0:
        tmp += f(i+1,j-1,k)*float(j)/float(i+j+k)
    if k>0:
        tmp += f(i,j+1,k-1)*float(k)/float(i+j+k)
    tmp += float(n)/float(i+j+k)
    
 
    dp[i][j][k] = tmp
    return tmp
dp = np.zeros((n+1,n+1,n+1))
#dp = [[[0.0 for i in range(n+1)] for j in range(n+1)] for k in range(n+1)]
 
print(f(cnt[0],cnt[1],cnt[2]))
Problem p03176 (python)

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
h = tuple(map(lambda x:int(x)-1,input().split()))
a = tuple(map(int,input().split()))

#update(i,x):Aiをxに更新する
def update(i,x):
    k = i + num - 1
    while k >= 0:
        seg[k] = max(x,seg[k])
        k = (k-1)//2

#query(a,b,0,0,num):[a,b)の最大値
def query(a,b,k,l,r):
    if r <= a or b <= l:
        return -float("inf")
    elif a <= l and r <= b:
        return seg[k]
    else:
        return max(query(a,b,2*k+1,l,(l+r)//2),query(a,b,2*k+2,(l+r)//2,r))

#初期化
#num : nより大きい最小の2のべき乗
num = 1
while num <= n:
    num *= 2
seg = [0]*(2*num-1)

#dp[i]:i番目が最後となる時の美しさの最大値
dp = [a[0]] + [0]*(n-1)
update(h[0],a[0])
for i in range(1,n):
    dp[i] = max(0,query(0,h[i],0,0,num))+a[i]
    update(h[i],dp[i])

print(max(dp))

Buggy submission (verdict: Runtime Error):
import sys,math
input = sys.stdin.readline
n = int(input())
h = tuple(map(lambda x:int(x)-1,input().split()))
a = tuple(map(int,input().split()))

#update(i,x):Aiをxに更新する
def update(i,x):
    k = i + num - 1
    while k >= 0:
        seg[k] = max(x,seg[k])
        k = (k-1)//2

#query(a,b,0,0,num):[a,b)の最大値
def query(a,b,k,l,r):
    if r <= a or b <= l:
        return -float("inf")
    elif a <= l and r <= b:
        return seg[k]
    else:
        return max(query(a,b,2*k+1,l,(l+r)//2),query(a,b,2*k+2,(l+r)//2,r))

#初期化
#num : nより大きい最小の2のべき乗
num = 2**(int(math.log2(n))+1)
seg = [0]*(2*num-1)

#dp[i]:i番目が最後となる時の美しさの最大値
dp = [a[0]] + [0]*(n-1)
update(h[0],a[0])
for i in range(1,n):
    dp[i] = max(0,query(0,h[i],0,0,num))+a[i]
    update(h[i],dp[i])

print(max(dp))
Problem p03214 (python)

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

b = sum(a)/n
for i in range(n):
    a[i] = abs(a[i]-b)

k = a.index(min(a))
print(k)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))

b = []
for i in range(n):
    r = 0
    for j in range(i,n):
        r += a[j]
        b.append(r)


n2 = n*(n+1)//2

res = 0
for i in range(31):
    p = res + 2**(30-i)
    
    c = 0
    for j in range(n2):
        if p == p&b[j]:
            c+=1
    
    if c >= k:
        res = p

print(res)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))

b = []
for i in range(n):
    r = 0
    for j in range(n-i):
        r += a[i+j]
        b.append(r)


n2 = n*(n+1)//2

res = 0
for i in range(41):
    p = res + 2**(40-i)
    
    c = 0
    for j in range(n2):
        if p == p&b[j]:
            c+=1
    
    if c >= k:
        res = p

print(res)
Problem p03215 (python)

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

b = []
for i in range(n):
    r = 0
    for j in range(i,n):
        r += a[j]
        b.append(r)


n2 = n*(n+1)//2

res = 0
for i in range(41):
    p = res + 2**(40-i)
    
    c = 0
    for j in range(n2):
        if p == p&b[j]:
            c+=1
    
    if c >= k:
        res = p

print(res)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))

b = []
for i in range(n):
    r = 0
    for j in range(i+1,n):
        r += a[j]
        b.append(r)


n2 = n*(n+1)//2

res = 0
for i in range(41):
    p = res + 2**(40-i)
    
    c = 0
    for j in range(n2):
        if p == p&b[j]:
            c+=1
    
    if c >= k:
        res = p

print(res)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())	
a = list(map(int,input().split()))

m = sum(a)

w = []
p = 0
q = 0
for i in range(n):
    p += a[i]
    q += a[n-1-i]
    w.append(p)
    w.append(q)
w.sort()

res = m
for i in range(k-1):
    res = res&(m-w[i])    
print(res)
Problem p03262 (python)

Fixed submission:

def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a
n,x = map(int,input().split())
values = list(map(int,input().split()))
for i in range(n):
    values[i] = abs(values[i]-x)
ass = values[0]
for i in range(n):
    ass = gcd(ass,values[i])
print(ass)

Buggy submission (verdict: Runtime Error):
import functools
import math
import fraction
n,x = map(int,input().split())
values = list(map(int,input().split()))
for i in range(n):
    values[i] = abs(values[i]-x)
gcd = functools.reduce(fraction.gcd, values)
print(gcd)

Buggy submission (verdict: Runtime Error):
import functools
import math
n,x = map(int,input().split())
values = list(map(int,input().split()))
for i in range(n):
    values[i] = abs(values[i]-x)
gcd = functools.reduce(math.gcd, values)
print(gcd)
Problem p03274 (python)

Fixed submission:
# cook your dish here
import bisect 
n,k = map(int,input().split())
x = list(map(int,input().split()))

w  = x.count(0)
for i in range(w):
    x.remove(0)

if k <= w:
    print(0)
else:
    k = k -w
    #print(x)

    r = bisect.bisect_left(x,0)
    
    if x[-1]<0:
        print(abs(x[len(x)-k]))
    elif x[0] > 0:
        print(x[k-1])    
    else:
        ass = 10 ** 10
        ans = 10**10
        for i in range(r,min(len(x),r + k )):
            if i-r+1 >= k:
                ans = abs(x[i])
            
            else:
                if i - k + 1 >= 0:
                    ans = x[i] + abs(x[i-k+1]) + min(x[i],abs(x[i-k+1]))
            ass = min(ass,ans)
        if r-k >= 0:
            ans = abs(x[r-k])
        ass = min(ass,ans)
        print(ass)

Buggy submission (verdict: Runtime Error):
# cook your dish here
import bisect 
n,k = map(int,input().split())
x = list(map(int,input().split()))

w  = x.count(0)
for i in range(w):
    x.remove(0)

if k <= w:
    print(0)
else:
    k = k -w
    #print(x)

    r = bisect.bisect_left(x,0)
    
    if x[-1]<0:
        print(abs(x[len(x)-k]))
    elif x[0] > 0:
        print(x[k-1])    
    else:
        ass = 10 ** 10
        for i in range(r,min(len(x),r + k )):
            if i-r+1 >= k:
                ans = abs(x[i])
            
            else:
                if i - k + 1 >= 0:
                    ans = x[i] + abs(x[i-k+1]) + min(x[i],abs(x[i-k+1]))
            ass = min(ass,ans)
        if r-k >= 0:
            ans = abs(x[r-k])
        ass = min(ass,ans)
        print(ass)
Problem p03280 (python)

Fixed submission:
x,y = map(int,input().split())
print((x-1)*(y-1))

Buggy submission (verdict: Runtime Error):
a=int(input())
b=int(input())

print((a-1)*(b-1))
Problem p03282 (python)

Fixed submission:
s=list(input())
k=int(input())

a = 0
while s[a] == '1':
    a += 1
    if a >= len(s):
        break

if k <= a:
    print('1')
else:
    if a >= len(s):
        print('1')
    else:
        print(s[a])

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

a = 0
while s[a] == '1':
    a += 1

if k <= a:
    print('1')
else:
    print(s[a])
Problem p03289 (python)

Fixed submission:
# cook your dish here
s=list(input())
c = 0
if s[0] == 'A':
    c += 1
if s[2:len(s)-1:].count('C') == 1:
    c += 1

    s.remove('C')
if 'A' in s:
    s.remove('A')
a = 'a'
for i in range(len(s)):
    a += s[i]
if a.islower():
    c += 1
 
if c == 3:
    print('AC')
else:
    print('WA')

Buggy submission (verdict: Runtime Error):
s=list(input())
c = 0
if s[0] == 'A':
    c += 1
if s[2:len(s)-1:].count('C') == 1:
    c += 1
    s.remove('A')
    s.remove('C')
a = 'a'
for i in range(len(s)):
    a += s[i]
if a.islower():
    c += 1

if c == 3:
    print('AC')
else:
    print('WA')
Problem p03290 (python)

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

d,g = map(int,input().split())
p = []
s = []
for i in range(d):
    x,y = map(int,input().split())
    p.append(x)
    s.append(100*(i+1)*x+y)

ans = 10**10
for i in range(1<<(d+1)):
    cnt = 0
    res = 0
    tank = []
    for j in range(d):
        if (i>>j)&1 == 1:
            cnt += s[j]
            res += p[j]
        else:
            tank.append([100*(j+1),p[j]])
    if cnt >= g:
        ans = min(ans,res)
    else:
        while cnt < g and tank[-1][1] > 0:
            cnt += tank[-1][0]
            tank[-1][1] -= 1
            res += 1
        if cnt >= g:
            ans = min(ans,res)
print(ans)

Buggy submission (verdict: Runtime Error):
# cook your dish here
D,g = map(int,input().split())
p = []
c = []

for i in range(D):
    x,y = map(int,input().split())
    p.append(x)
    c.append(y)

#print(p)

d = [0]
cnt = 0

while d[-1] < g:
    while p[-1] == 0:
        p.pop(len(p)-1)
        c.pop(len(p)-1)
    k = -1
    
    r = d[-1] + (len(p))*100
    for i in range(len(p)):
        if len(d) >= p[i] and p[i] != 0:
            w = d[len(d)-p[i]] + 100*(i+1)*p[i] + c[i]
 #           print(p[i],i,c[i],len(d),w)
            if w > r:
                r = w
                k = i
    if k == -1:
        cnt += 1
        
    else:
        p[-1] += cnt
        p[k] = 0
        cnt = 0
        
    d.append(r)

#print(d)
print(len(d)-1)

Buggy submission (verdict: Runtime Error):
# cook your dish here
D,g = map(int,input().split())
p = []
c = []

for i in range(D):
    x,y = map(int,input().split())
    p.append(x)
    c.append(y)

#print(p)

d = [0]
cnt = 0

while d[-1] < g:
    while p[-1] == 0:
        p.pop(len(p)-1)
        c.pop(len(p)-1)
    k = -1
    
    r = d[-1] + (len(p))*100
    for i in range(len(p)):
        if len(d) >= p[i] and p[i] != 0:
            w = d[len(d)-p[i]] + 100*(i+1)*p[i] + c[i]
 #           print(p[i],i,c[i],len(d),w)
            if w > r:
                r = w
                k = i
    if k == -1:
        cnt += 1
        
    else:
        p[-1] += cnt
        p[k] = 0
        
    d.append(r)

#print(d)
print(len(d)-1)
Problem p03309 (python)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
for i in range(0,len(a)):
    a[i] -= (i+1)
a.sort()
b = [ abs(x  - (a[n//2])) for x in a]
print(sum(b))

Buggy submission (verdict: Runtime Error):
1.	n = int(input())
2.	a = list(map(int, input().split()))
3.	tmp = [a[x] - (x+1) for x in range(0,n)]
4.	tmp.sort()
5.	b = tmp[n // 2]
6.	print(sum((abs(tmp[i] - b) for i in range(0,n))))

Buggy submission (verdict: Runtime Error):
import copy
from statistics import mean, median,variance,stdev
N=int(input())
li = list(map(int,input().split()))

for i in range(0,N):
	li[i] = li[i] - i -1
a = []
d = copy.copy(li)
if len(li) %2 == 1:
    m = median(li)
    k = 0
    for j in range(0,N):
        k = k + abs(li[j]-m)
else:
    c = copy.copy(li)
    c.sort()
    o = []
    for i in range(c[len(c)//2],c[len(c)//2+1]):
        k = 0
        for j in range(N):
            k = k + abs(li[j]-i)
        o.append(k)
    k = min(o)
print(k)

Buggy submission (verdict: Runtime Error):
import copy
N=int(input())
li = list(map(int,input().split()))
for i in range(0,N):
	li[i] = li[i] - i -1
a = []
d = copy.copy(li)
while len(d) >= 3:
	del d[max(d)]
	del d[min(d)]
for i in range(min(d),max(d)+1):
	k = 0
	for j in range(N):
		k = k + abs(li[j]-i)
	a.append(min(k))

Buggy submission (verdict: Runtime Error):
import copy
N=int(input())
li = list(map(int,input().split()))
for i in range(0,N):
	li[i] = li[i] - i -1
a = []
d = copy.copy(li)
while len(d) >= 3:
	del d[max(d)]
	del d[min(d)]
for i in range(min(d),max(d)+1):
	k = 0
	for j in range(N):
		k = k + abs(li[j]-i)
	a.append(k)
print(a)
Problem p03316 (python)

Fixed submission:
# your code goes here
import copy
N=int(input())
k = copy.copy(N)

a=[]
while k != 0:
	a.append(k%10)
	k = k//10

if N%sum(a)==0:
	print('Yes')
else:
	print('No')

Buggy submission (verdict: Runtime Error):
# your code goes here
import copy
N=int(input())
k = copy.copy(N)
 
a=[]
while k != 0:
	a.append(k%10)
	k = k//10
 
if N%sum(a)==0:
	print('Yes')
else:
	print('No'
Problem p03359 (python)

Fixed submission:
x,y = map(int,input().split())	

if x <= y:
  print(x)
else:
  print(x-1)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
s_list = [input() for _ in range(H)]
ans = 'Yes'
for i in range(1, H - 1):
	for j in range(1, W - 1):
		if s_list[i][j] == '#' and s_list[i-1][j] == s_list[i+1][j] == s_list[i][j-1] == s_list[i][j+1] == '.':
			ans = 'No'
			break
print(ans)
Problem p03363 (python)

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

c = 0

s = [a[0]]
for i in range(1,n):
    s.append(s[-1]+a[i])

#print(s)
s.sort()
#print(s)

k=1
for i in range(1,n):
    if s[i]==s[i-1]:
        k += 1
    else:
        if k != 1:
            c += k*(k-1)//2
        k = 1
    if i == n-1 and k != 1:
         c += k*(k-1)//2
        
c += s.count(0)
print(c)

Buggy submission (verdict: Runtime Error):
# cook your dish here
import numpy as np
n =int(input())
a = list(map(int,input().split()))	


d = np.ones((n,n))

c = 0

if n == 1:
    if a[0]== 0:
        print(1)
    else:
        print(0)
    quit()

for i in range(0,n):
    d[0][i] = sum(a[:i+1:])
    if d[0][i] == 0:
        c += 1
for t in range(0,n-1):
    s = 0
    while s <=t:
        d[s+1][t+1] = d[s][t]-a[s]+a[t+1]
        if d[s+1][t+1] == 0:
            c += 1
        s += 1


print(c)
Problem p03369 (python)

Fixed submission:
s=list(input())
 
print(700+100*(s.count('o')))

Buggy submission (verdict: Runtime Error):
a,b,c,x,y=map(int,input().split())
z=min(x,y)
if a+b>2*c:
    print(z*2*c+min((x-z)*a+(y-z)*b,(x+y-z*2)*2*c))
else:
    print(a*x+b*y)
Problem p03377 (python)

Fixed submission:
a,b,x = map(int,input().split())
 
if a <= x and a + b >= x:
  print('YES')
else:
	print('NO')

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

if a <= x and a + b >= x:
  print('YES')
else:
	print('NO)
Problem p03388 (python)

Fixed submission:
import sys,heapq
input = sys.stdin.buffer.readline

Q = int(input())

def f(x,y):
    ma = x*y - 1
    ok = 0
    ng = 10**9 + 1
    while ng - ok > 1:
        mid = (ok+ng)//2
        if mid**2 <= ma:
            ok = mid
        else:
            ng = mid
    return ok

ans = []
for testcase in range(Q):
    a,b = map(int,input().split())
    if a == 1 and b == 1:
        ans.append(0)
        continue
    p = f(a,b)
    res = p*2
    if a != b:
        res -= 1
    if p == (a*b - 1)//p:
        res -= 1
    ans.append(res)

print(*ans,sep='\n')

Buggy submission (verdict: Runtime Error):
import sys,heapq
input = sys.stdin.buffer.readline

Q = int(input())

ans = []
for testcase in range(Q):
    a,b = map(int,input().split())
    p = int((a*b-1)**0.5)
    res = p*2
    if a != b:
        res -= 1
    if p == (a*b - 1)//p:
        res -= 1
    ans.append(res)

print(*ans,sep='\n')
Problem p03476 (python)

Fixed submission:
import math
 
Q = int(input())
 
# 素数表
n = 100000
P = [False] * n
P[2] = True
for i in range(3, n, 2):
    k = True
    for j in range(3, int(math.sqrt(i)) + 1, 2):
        if i % j == 0:
            k = False
            break
    if k:
        P[i] = True
 
# Nと(N+1)÷2が素数か否か
a = [0] * n
for i in range(1, n, 2):
    j = (i + 1) // 2
    if P[i] and P[j]:
        a[i] = 1
# 累積和
for i in range(n - 1):
    a[i + 1] += a[i]
 
for _ in range(Q):
    l, r = map(int, input().split())
    print(a[r] - a[l - 1])

Buggy submission (verdict: Runtime Error):
 
Q = int(input())
 
# 素数表
n = 100000
P = [False] * n
P[2] = True
for i in range(3, n, 2):
    k = True
    for j in range(3, int(math.sqrt(i)) + 1, 2):
        if i % j == 0:
            k = False
            break
    if k:
        P[i] = True
 
# Nと(N+1)÷2が素数か否か
a = [0] * n
for i in range(1, n, 2):
    j = (i + 1) // 2
    if P[i] and P[j]:
        a[i] = 1
# 累積和
for i in range(n - 1):
    a[i + 1] += a[i]
 
for _ in range(Q):
    l, r = map(int, input().split())
    print(a[r] - a[l - 1])
Problem p03480 (python)

Fixed submission:
s=list(input())

n=len(s)
a = [n]
if n == 1:
    print(1)
else:
    for i in range(n-1):
        if s[i]!= s[i+1]:
            a.append(max(i+1,n-i-1))

    print(min(a))

Buggy submission (verdict: Runtime Error):
s=list(input())
a = []
n=len(s)
for i in range(n-1):
    if s[i]!= s[i+1]:
        a.append(max(i+1,n-i-1))

print(min(a))
Problem p03688 (python)

Fixed submission:
n = int(input())

a = list(map(int,input().split()))
a_max = max(a)
a_min = min(a)
if a_max > a_min+1:
    print('No')
    exit()
k = a_max
if a_max == a_min:
    if k == n-1 or 2*k <= n:
        print('Yes')
    else:
        print('No')
else:
    uni = a.count(k-1)
    if k >= uni + 1 and k <= uni + (n-uni)//2:
        print('Yes')
    else:
        print('No')

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

a = list(map(int,int(input())))
a_max = max(a)
a_min = min(a)
if a_max > a_min+1:
    print('No')
    exit()
k = a_max
if a_max == a_min:
    if k == n-1 or 2*k <= n:
        print('Yes')
    else:
        print('No')
else:
    uni = a.count(k-1)
    if k >= uni + 1 and k <= uni + (n-uni)//2:
        print('Yes')
    else:
        print('No')