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

Fixed submission:
ab = input().split()
a,b = int(ab[0]),int(ab[1])
d = []
z = b - a 
if ((z-1)*z)/2 >a and ((z+1)*(z+2))/2 > b:
    x,y = ((z-1)*z)/2, ((z+1)*(z+2))
print(int(x - a))

Buggy submission (verdict: Runtime Error):
ab = list(map(int,input().split()))
a,b = ab[0],ab[1]
d = []
for i in range(100):
    if (i*(i+1))/2 >a and ((i+1)*(i+2))/2 > b:
        d.append(i)
x,y = (d[0]*(d[0]+1))/2, ((d[1]+1)*(d[1]+2))/2
print(int(x - a))

Buggy submission (verdict: Runtime Error):
ab = list(map(int,input().split()))
a,b = ab[0],ab[1]
d = []
for i in range(999):
    if (i*(i+1))/2 >a and ((i+1)*(i+2))/2 > b:
        d.append(i)
x,y = (d[0]*(d[0]+1))/2, ((d[1]+1)*(d[1]+2))/2
print(int(x - a))
Problem p03424 (python)

Fixed submission:
n = input()
l = len(set(input().strip().split()))
print('Four' if l == 4 else 'Three')

Buggy submission (verdict: Runtime Error):
n = int(input())
l = len(set(map(input().strip().split())))
print('Four' if l == 4 else 'Three')
Problem p04043 (python)

Fixed submission:
a, b, c = map(int, input().split(' '))
if a + b + c != 17:
  print('NO')
elif a * b * c != 175:
  print('NO')
else:
  print('YES')

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split(' '))
if a + b + c != 17:
  print('NO')
else if a * b * c != 175:
  print('NO')
else:
  print('YES')

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split(' '))
if a + b + c != 17:
  print 'NO'
elif a * b * c != 175:
  print 'NO'
else:
  print 'YES'

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split(' '))
if a + b + c != 17:
  print 'NO'
else if a * b * c != 175:
  print 'NO'
else:
  print 'YES'
Problem p02900 (python)

Fixed submission:
a, b = [int(i) for i in input().split()]

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



g = gcd(a, b)

nof = 1
up = g

for i in range(2, up):
    if i*i > up:
        break
    if g%i == 0:
        nof += 1
        #print(i, nof)
        while g%i == 0:
            g = g//i
if g > 1:
    nof += 1
print(nof)

Buggy submission (verdict: Runtime Error):
a, b = [int(i) for i in input().split()]

from math import gcd

g = gcd(a, b)

nof = 1
up = g
for i in range(2, up):
    if i*i > up:
        break
    if g%i == 0:
        nof += 1
        #print(i, nof)
        while g%i == 0:
            g = g//i
if g > 1:
    nof += 1
print(nof)
Problem p02947 (python)

Fixed submission:
n = int(input())
from collections import defaultdict as dd

hsh = dd(int)

for i in range(n):
  s = list(input())
  s = ''.join(sorted(s))
  hsh[s] += 1

x = 0
for i in hsh.keys():
  x += (hsh[i]*(hsh[i]-1))//2

print(x)

Buggy submission (verdict: Runtime Error):
n = int(input())
from collections import defaultdict as dd

hsh = dd(int)

for i in range(n):
  s = input()
  s = sorted(s)
  hsh[s] += 1

x = 0
for i in hsh:
  x += (hsh[i]*(hsh[i]-1))//2

print(x)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = []
for i in range(n):
  s = input()
  A.append(sorted(s))
x = 0
for i in range(n):
  for j in range(i+1, n):
  	if A[i] == A[j]:
      x+=1
print(x)
Problem p03160 (python)

Fixed submission:
n = int(input())
A = [int(i) for i in input().split()]

dp = [-1 for i in range(n+50)]
import sys
sys.setrecursionlimit(1000000)
def brute(i):
    if i>=n-1:
        return 0
    if dp[i]!=-1:
        return dp[i]
    ans = 10**10
    if i+1 < n:
        ans = min(ans, abs(A[i] - A[i+1]) + brute(i+1))
    if i+2 < n:
        ans = min(ans, abs(A[i] - A[i+2]) + brute(i+2))
    dp[i] = ans
    return ans

print(brute(0))

Buggy submission (verdict: Runtime Error):
n = int(input())
A = [int(i) for i in input().split()]

dp = [-1 for i in range(n+5)]
import sys
sys.setrecursionlimit(100000)
def brute(i):
    if i>=n-1:
        return 0
    if dp[i]!=-1:
        return dp[i]
    ans = 10**10
    if i+1 < n:
        ans = min(ans, abs(A[i] - A[i+1]) + brute(i+1))
    if i+2 < n:
        ans = min(ans, abs(A[i] - A[i+2]) + brute(i+2))
    dp[i] = ans
    return ans

print(brute(0))

Buggy submission (verdict: Runtime Error):
n = int(input())
A = [int(i) for i in input().split()]

dp = [-1 for i in range(n+1)]
import sys
sys.setrecursionlimit(10000)
def brute(i):
    if i>=n-1:
        return 0
    if dp[i]!=-1:
        return dp[i]
    ans = 10**10
    if i+1 < n:
        ans = min(ans, abs(A[i] - A[i+1]) + brute(i+1))
    if i+2 < n:
        ans = min(ans, abs(A[i] - A[i+2]) + brute(i+2))
    dp[i] = ans
    return ans

print(brute(0))

Buggy submission (verdict: Runtime Error):
n = int(input())
A = [int(i) for i in input().split()]

dp = [-1 for i in range(n+1)]

def brute(i):
    if i>=n-1:
        return 0
    if dp[i]!=-1:
        return dp[i]
    ans = 10**10
    if i+1 < n:
        ans = min(ans, abs(A[i] - A[i+1]) + brute(i+1))
    if i+2 < n:
        ans = min(ans, abs(A[i] - A[i+2]) + brute(i+2))
    dp[i] = ans
    return ans

print(brute(0))
Problem p03162 (python)

Fixed submission:
n = int(input())
joy = []

for i in range(n):
    cur = [int(i) for i in input().split()]
    joy.append(cur)

dp = [[0 for i in range(n+5)] for j in range(3)]
import sys
sys.setrecursionlimit(10000000)
def brute(curday, prvmove):
    if curday>=n:
        return 0
    if dp[prvmove][curday]!=0:
        return dp[prvmove][curday]
    ans = 0
    
    for i in range(3):
        if prvmove == i:
            continue
        ans = max(ans, brute(curday+1, i) + joy[curday][i])

    #print('with', daysleft)
    #print('returning', ans)
    dp[prvmove][curday] = ans
    return ans

ans = 0

for i in range(3):
    ans = max(ans, brute(0, i))
print(ans)

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

for i in range(n):
    cur = [int(i) for i in input().split()]
    joy.append(cur)

dp = [[0 for i in range(n+5)] for j in range(3)]
import sys
sys.setrecursionlimit(100000)
def brute(curday, prvmove):
    if curday>=n:
        return 0
    if dp[prvmove][curday]!=0:
        return dp[prvmove][curday]
    ans = 0
    
    for i in range(3):
        if prvmove == i:
            continue
        ans = max(ans, brute(curday+1, i) + joy[curday][i])

    #print('with', daysleft)
    #print('returning', ans)
    dp[prvmove][curday] = ans
    return ans

ans = 0

for i in range(3):
    ans = max(ans, brute(0, i))
print(ans)
Problem p02804 (python)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

[N,K]=i2()
a=i2()
mod = 10**9+7
c=[0 for i in range(N+1)]
ci=[0 for i in range(N+1)]
c[0]=1
for i in range(1,N+1):
 c[i]=c[i-1]*i
 c[i]%=mod
def bp(x,n):
        r=1
        while(n):
           if n%2:
              r=r*x%mod
           x=x*x%mod
           n>>=1
        return r
for i in range(N+1):
  ci[i]=bp(c[i],10**9+5)
ans=0
a.sort()
for i in range(N):
 if i>=K-1:
   ans+=a[i]*((c[i]*ci[i-K+1]*ci[K-1])%mod)
 if i<=N-K:
   ans-=a[i]*((c[N-i-1]*ci[N-i-1-K+1]*ci[K-1])%mod)
 ans%=mod
print(ans%mod)

Buggy submission (verdict: Runtime Error):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
import numpy as np
[N,K]=i2()
a=i2()
mod = 10**9+7
comb = np.zeros((N+1,N+1),dtype=np.int64)
comb[:,0] = 1
for i in range(1,N+1):
    comb[i, 1:i+1] = comb[i-1, :i] + comb[i-1, 1:i+1]
    comb[i] %= mod
ans=0
a.sort()
for i in range(N):
 if i>=K-1:
   ans+=a[i]*comb[i][K-1]
 if i<=N-K+1:
   ans-=a[i]*comb[N-i-1][K-1]
 ans%=mod
print(ans)

Buggy submission (verdict: Runtime Error):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
import numpy as np
[N,K]=i2()
a=i2()
mod = 10**9+7
comb = np.zeros((N+1,N+1),dtype=np.int64)
comb[:,0] = 1
for i in range(1,N+1):
    comb[i, 1:i+1] = comb[i-1, :i] + comb[i-1, 1:i+1]
    comb[i] %= mod
ans=0
a.sort()
for i in range(N):
 if i>=K-1:
   ans+=a[i]*comb[i][K-1]
 if i<=N-K+1:
   ans-=a[i]*comb[N-i-1][K-1]
 ans%=mod
print(ans)
Problem p03320 (python)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
x=[]
k=i1()
for s in range(1,10):
 x.append([s/sum(list(map(int, list(str(s))))),s])

for i in range(1,1000):
 for j in range(1,15):
   s=10**j*i+10**j-1
   x.append([s/sum(list(map(int, list(str(s))))),s])

y=sorted(x)
m=0
n=0
for i,j in y:
  if n>k-1:
     break
  if j>10**15:
     break
  if j>m:
     m=j
     print(j)
     n+=1

Buggy submission (verdict: Runtime Error):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
k=i1()


x=list(range(1,10))

y=[]
z=[]
for i in range(1,15):
 for j in range(1,10):
  y.append((10**i*(j+1)-1)/(j+i*9))
  z.append(10**i*(j+1)-1)
for i in range(len(z)-1):
  s=z[i]+1
  x.append(z[i])
  while s/sum(list(map(int, list(str(s)))))<=y[i+1]:
        x.append(s)
        s+=1

for i in range(k):
  print(x[i])
Problem p03390 (python)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
q=i1()
import math
y=[]
for i in range(q):
 y.append(i2())

for a,b in y:
 x=a*b
 c=int(math.sqrt(x))
 if c**2==x:
    c-=1
 z=2*c
 if c>0 and (x//c)==c:
   z-=1
 if c>0 and x%c==0 and (x//c-1)==c:
   z-=1
 if a<=c:
   z-=1
 if b<=c:
   z-=1
 print(z)

Buggy submission (verdict: Runtime Error):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
q=i1()
import math
y=[]
for i in range(q):
 y.append(i2())

for a,b in y:
 x=a*b
 c=int(math.sqrt(x))
 if c**2==x:
    c-=1
 z=2*c
 if  (x//c)==c:
   z-=1
 if x%c==0 and (x//c-1)==c:
   z-=1
 if a<=c:
   z-=1
 if b<=c:
   z-=1
 print(z)

Buggy submission (verdict: Runtime Error):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
q=i1()
import math
for i in range(q):
 [a,b]=i2()
 x=a*b
 c=int(math.sqrt(x))
 if c**2==x:
    c-=1
 z=2*c
 if  (x//c)==c:
   z-=1
 if x%c==0 and (x//c-1)==c:
   z-=1
 if a<=c:
   z-=1
 if b<=c:
   z-=1
 print(z)

Buggy submission (verdict: Runtime Error):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
q=i1()
import math
for i in range(q):
 [a,b]=i2()
 x=a*b
 c=int(math.sqrt(x))
 if c**2==x:
    c-=1
 z=2*c
 if  (x//c)==c:
   z-=1
 if x%c==0 and (x//c-1)==c:
   z-=1
 if a<=c:
   z-=1
 if b<=c:
   z-=1
 print(z)

Buggy submission (verdict: Runtime Error):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
q=i1()
import math
for i in range(q):
 [a,b]=i2()
 x=a*b
 c=int(math.sqrt(x))
 if c**2==x:
    c-=1
 z=2*c
 if  int(x//c)==c:
   z-=1
 if x%c==0 and (int(x//c)-1)==c:
   z-=1
 if a<=c :
   z-=1
 if b<=c:
   z-=1
 print(z)
Problem p03472 (python)

Fixed submission:
def i2():
 return [int(i) for i in input().split()]

[n,h]=i2()
a=[]
for i in range(n):
 b=i2()
 a+=[[b[0],0],[b[1],1]]
a.sort()
a=a[::-1]
i=0
c=0
while a[i][1]==1 and h>0:
 h-=a[i][0]
 c+=1
 i+=1

if h>0:
 c+=h//a[i][0]
 if h%a[i][0]:c+=1
print(c)

Buggy submission (verdict: Runtime Error):
def i2():
 return [int(i) for i in input().split()]

[n,h]=i2()
a=[]
for i in range(n):
 b=i2()
 a+=[[b[0],0],[b[1],1]]
a.sort()
a=a[::-1]
i=0
c=0
while a[i][1]==1　and h>0:
 h-=a[i][0]
 c+=1
 i+=1
c+=h//a[i][0]
if h%a[i][0]:c+=1
print(c)
Problem p03588 (python)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

n=i1()
x=[]
for i in range(n):
    x.append(i2())
x.sort()
print(x[-1][0]+x[-1][1])

Buggy submission (verdict: Runtime Error):
n=i1()
x=[]
for i in range(n):
    x.append(i2())
x.sort()
print(x[-1][0]+x[-1][1])
Problem p03599 (python)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

[a,b,c,d,e,f]=i2()
w=[]
s=[]
for i in range(f+1):
    for j in range(f+1):
        t=(a*i+b*j)*100
        tt=c*i+d*j
        if t<=f:
           w.append(t)
        if tt<=f:
           s.append(tt)
a=0
g=[]
for i in w:
 for j in s:
     if 0<i+j<=f and j<=i*e/100:
        g.append([j*100/(i+j),i+j,j])
g.sort()
print(g[-1][1],g[-1][2])

Buggy submission (verdict: Runtime Error):
    def i1():
     return int(input())
    def i2():
     return [int(i) for i in input().split()]

    [a,b,c,d,e,f]=i2()
    g=[]
    for i in range(31):
        for j in range(31):
                    ttt=(a*i+b*j)*100
                    tk=min(ttt*e/100,f-ttt)
                    tt=(tk//d)*d+(tk%d//(d-c))*(d-c)
                    t=ttt+tt
                    if t>0 :
                        g.append([(100*tt)/t,t,tt])

    g.sort()
    print(int(g[-1][1]),int(g[-1][2]))

def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

[a,b,c,d,e,f]=i2()
g=[[0,100*a,0]]
for i in range(31):
    for j in range(31):
                ttt=(a*i+b*j)*100
                tk=min(ttt*e/100,f-ttt)
                tt=(tk//d)*d+(tk%d//(d-c))*(d-c)
                t=ttt+tt
                if t>0 :
                    g.append([(100*tt)/t,t,tt])

g.sort()
print(int(g[-1][1]),int(g[-1][2]))
Problem p02818 (python)

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

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
printf(a-min(a,k),b-min(b,a-min(a,k))

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input.split())
printf(a-min(a,k),b-min(b,a-min(a,k)))

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input.split())
printf(a-min(a,k),b-min(b,a-min(a,k))
Problem p02922 (python)

Fixed submission:
from math import ceil
A,B = map(int,input().split())
count = 0 
num = 1
while num < B:
    num -= 1
    num += A
    count += 1
    
print(count)

Buggy submission (verdict: Runtime Error):
A,B = map(int,input().split())
print(int(ceil((B-A) / (A-1))) if B > A else 1)
Problem p02934 (python)

Fixed submission:
from functools import reduce

N = int(input())
As = list(map(int,input().split()))

P = reduce(lambda a,b:a*b,As)

print(P/sum([P/a for a in As]))

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

N = int(input())
As = map(int,input().split())

P = reduce(lambda a,b:a*b,As)

print(P/sum([P/a for a in As]))

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

N = int(input())
As = map(int,input().split())

P = reduce(lambda a,b:a*b,As)

print(P/sum([P/a for a in As]))

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

N = int(input())
As = map(int,input().split())

P = reduce(lambda a,b:a*b,As)

print(P/sum([P/a for a in As]))
Problem p02947 (python)

Fixed submission:
from collections import Counter
N = int(input())
c = Counter(''.join(sorted(input())) for _ in range(N))
sum_ = lambda n: int(n*(n-1)/2)
print(sum(map(sum_,c.values())))

Buggy submission (verdict: Runtime Error):
from collection import Counter
N = int(input())
c = Counter(''.join(sorted(input())) for _ in range(N))
sum_ = lambda n: int(n*(n-1)/2)
print(sum(map(sum_,c.values())))
Problem p03944 (python)

Fixed submission:
W,H,N = map(int , raw_input().split())
white = {"l_bottom":[0,0],"r_top":[W,H]}

areaZero = False

for i in xrange(N):
    x,y,a = map(int,raw_input().split())
    if a == 1:
        if x > white['r_top'][0]:
            areaZero = True 
            continue
        if x > white['l_bottom'][0]:
            white['l_bottom'][0] = x
            continue
    if a == 2:
        if x <  white['l_bottom'][0]:
            areaZero = True 
            continue
        if x < white['r_top'][0]:
            white['r_top'][0] = x
            continue
    if a ==3 :
        if y > white['r_top'][1]:
            areaZero = True 
            continue
        if y > white['l_bottom'][1]:
            white['l_bottom'][1] = y
            continue
    if a == 4 :
        if y < white['l_bottom'][1]:
            areaZero = True 
            continue
        if y < white['r_top'][1]:
            white['r_top'][1] = y
            continue
if areaZero == True:
    print 0
else:
    print (white['r_top'][0]  - white['l_bottom'][0]) * (white['r_top'][1]  - white['l_bottom'][1])

Buggy submission (verdict: Runtime Error):
def main():
    W,H,N = map(int , raw_input().split())
    white = {"l_bottom":[0,0],"r_top":[W,H]}
    
    areaZero = False
    
    for i in xrange(N):
        x,y,a = map(int,raw_input().split())
        if a == 1:
            if x > white['r_top'][0]:
                areaZero = True 
                continue
            if x > white['l_bottom'][0]:
                white['l_bottom'][0] = x
                continue
        if a == 2:
            if x <  white['l_bottom'][0]:
                areaZero = True 
                continue
            if x < white['r_top'][0]:
                white['r_top'][0] = x
                continue
        if a ==3 :
            if y > white['r_top'][1]:
                areaZero = True 
                continue
            if y > white['l_bottom'][1]:
                white['l_bottom'][1] = y
                continue
        if a == 4 :
            if y < white['l_bottom'][1]:
                areaZero = True 
                continue
            if y < white['r_top'][1]:
                white['r_top'][1] = y
                continue
    if areaZero == True:
        print 0
    else:
        print (white['r_top'][0]  - white['l_bottom'][0]) * (white['r_top'][1]  - white['l_bottom'][1])

if __name__ == '__main__'
    main()
Problem p03992 (python)

Fixed submission:
s = raw_input()
s = s[:4]+" "+s[4:]
print s

Buggy submission (verdict: Runtime Error):
def decoder(str_int):
    s_=''
    for a in str_int:
        s_ = s_+(alpbet[a])
    return s_

def encoder(s):
    return [alpbet.index(a) for a in s]

s = raw_input()
K = input()

alpbet = 'abcdefghijklmnopqrstuvwxyz'
encoder = lambda s: [alpbet.index(a) for a in s]
inc_count = K
str_int = encoder(s)
for i in range(len(str_int)):
    if i != len(str_int)-1:
        if str_int[i] > 0:
            cost = 26 - str_int[i]
            if inc_count > cost:
                inc_count -= cost
                str_int[i] = 0
    else:
        str_int[i] = (str_int[i] + inc_count) % 26
        
print decoder(str_int)

Buggy submission (verdict: Runtime Error):
def decoder(str_int):
    s_=''
    for a in str_int:
        s_ = s_+(alpbet[a])
    return s_

def encoder(s):
    return [alpbet.index(a) for a in s]

s = raw_input()
K = input()

alpbet = 'abcdefghijklmnopqrstuvwxyz'
encoder = lambda s: [alpbet.index(a) for a in s]
inc_count = K
str_int = encoder(s)
for i in range(len(str_int)):
    #末尾文字でない
    if i != len(str_int)-1:
        #b~zの間でかつデクリメントできる
        if str_int[i] > 0:
            #aになるまで必要なインクリメント回数
            cost = 26 - str_int[i]
            if inc_count > cost:
                inc_count -= cost
                str_int[i] = 0
    else:
        str_int[i] = (str_int[i] + inc_count) % 26
        
print decoder(str_int)
Problem p03565 (python)

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


i=len(Sd)-len(T)
j=0
ans=[]
flag=False
while(1):
    if i<0:
        #print('not find')
        break
    #print('searching',i,j,Sd[i],T[j])
    if Sd[i]==T[j] or Sd[i]=='?':
        #print('find',i,j,Sd[i],T[j])
        if j==len(T)-1:
            ans.append((Sd[:i-j]+T+Sd[i-j+len(T):]).replace('?','a'))
            i-=j+1
            j=0
            flag=True
            continue
        j+=1
        i+=1
    else:
        i-=j+1
        j=0

if flag:
    ans.sort()
    print(ans[0])
else:
    print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
Sd=input()
T=input()
 
i=len(Sd)-len(T)
j=0
ans=[]
flag=False
while(1):
    #print('searching',i,j,Sd[i],T[j])
    if Sd[i]==T[j] or Sd[i]=='?':
        #print('find',i,j,Sd[i],T[j])
        if j==len(T)-1:
            ans.append((Sd[:i-j]+T+Sd[i-j+len(T):]).replace('?','a'))
            i-=j+1
            j=0
            flag=True
            continue
        j+=1
        i+=1
    else:
        i-=j+1
        j=0
        if i<0:
            #print('not find')
            break

if flag:
    ans.sort()
    print(ans[0])
else:
    print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
Sd=input()
T=input()
 
i=len(Sd)-len(T)
j=0
ans=[]
flag=False
while(1):
    #print('searching',i,j,Sd[i],T[j])
    if Sd[i]==T[j] or Sd[i]=='?':
        #print('find',i,j,Sd[i],T[j])
        if j==len(T)-1:
            ans.append((Sd[:i-j]+T+Sd[i-j+len(T):]).replace('?','a'))
            i-=j+1
            j=0
            flag=True
            continue
        j+=1
        i+=1
    else:
        i-=j+1
        j=0
        if i<0:
            #print('not find')
            break

ans.sort()
if flag:
    print(ans[0])
else:
    print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
Sd=input()
T=input()

flag=False
i=len(Sd)-len(T)
j=0
ans=[]
while(1):
    #print('searching',i,j,Sd[i],T[j])
    if Sd[i]==T[j] or Sd[i]=='?':
        #print('find',i,j,Sd[i],T[j])
        if j==len(T)-1:
            ans.append((Sd[:i-j]+T+Sd[i-j+len(T):]).replace('?','a'))
            #print('complete')
            i-=j+1
            j=0
            flag=True
            continue
        j+=1
        i+=1
    else:
        i-=j+1
        j=0
        hatena=0
        if i<0:
            #print('not find')
            break

if flag:
    ans.sort()
    print(ans[0])
else:
    print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
Sd=input()
T=input()

flag=False
i=len(Sd)-len(T)
j=0
ans=[]
while(1):
    #print('searching',i,j,Sd[i],T[j])
    if Sd[i]==T[j] or Sd[i]=='?':
        #print('find',i,j,Sd[i],T[j])
        if j==len(T)-1:
            ans.append((Sd[:i-j]+T+Sd[i-j+len(T):]).replace('?','a'))
            #print('complete')
            i-=j+1
            j=0
            flag=True
            continue
        j+=1
        i+=1
    else:
        i-=j+1
        j=0
        hatena=0
        if i<0:
            #print('not find')
            break

ans.sort()
if flag:
    print(ans[0])
else:
    print('UNRESTORABLE')
Problem p03343 (python)

Fixed submission:
n , k , q = map(int , input().split())
a = [0] * (n + 1)
b = list(map ( int , input().split()))
for i in range(1 , n + 1):
	a[i] = b[i - 1];
def check( l , r):
	cnt = 0;
	ln = 0;
	res = 0;
	for i in range(1 , n + 1):
		if a[i] < l:
			res += min(cnt , max(0 , ln - k + 1))
			ln = 0;
			cnt = 0;
		else :
			ln += 1;
			if a[i] <= r:
				cnt += 1;
	res += min(cnt , max(0 , ln - k + 1))
	if(res >= q):
		return True;
	return False;						

l = 0;
r = 1000000000;
res = 1000000000;
while(l <= r):
	m = (l + r) // 2;
	ok = 0;
	for i in range(1 , n + 1):
		ok |= check(a[i] - m , a[i]);
	if ok == 1:
		r = m - 1;
		res = m;
	else :
		l = m + 1;
print(res)

Buggy submission (verdict: Runtime Error):
n , k , q = map(int , input().split())
a = [0] * (n + 1)
b = list(map ( int , input().split()))
for i in range(1 , n + 1):
	a[i] = b[i - 1];
def check( l , r):
	cnt = 0;
	ln = 0;
	res = 0;
	for i in range(1 , n + 1):
		if a[i] < l:
			res += min(cnt , max(0 , ln - k + 1))
			ln = 0;
			cnt = 0;
		else :
			ln += 1;
			if a[i] <= r:
				cnt += 1;
	res += min(cnt , max(0 , ln - k + 1))
	if(res >= q):
		return True;
	return False;						

l = 0;
r = 1000000000;
res = 1000000000;
while(l <= r):
	m = (l + r) // 2;
	ok = 0;
	for i in range(1 , n + 1):
		ok |= check(a[i] - m , a[i]);
	if ok == 1:
		r = m - 1;
		res = m;
	else :
		l = m + 1;
print(res)
Problem p03385 (python)

Fixed submission:
X=input()
A=X[0]
B=X[1]
C=X[2]
if A!=B and B!=C and C!=A:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
A,B,K=map(int,input().split())
 
for i in range(A,A+K):
    if i <= B-K:
        print(i)
for i in range(B-K,B):
    print(i)

Buggy submission (verdict: Runtime Error):
A,B,K=map(int,input().split())

for i in range(A,A+K):
    if i <= B-K:
        print(i)
for i in range(B-K,B):
    print(i)
Problem p03415 (python)

Fixed submission:
A=input()
B=input()
C=input()
print(A[0]+B[1]+C[2])

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split())
if A==1 and B==1:
    print(1)
elif A==1:
    print(A-2)
elif B==1:
    print(A-2)
else:
    print((A-2)*(B-2))
Problem p03416 (python)

Fixed submission:
A,B=map(int, input().split())
cnt=0
for i in range(A,B+1):
    if  i//10000 == i%10 and  i//1000%10 == i//10%10:
        cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
A=int(input())
B=int(input())
cnt=0
for i in range(A,B+1):
    if  A/10000 == A%10 and  A/1000%10 == A/10%10:
        cnt+=1
print(cnt)