Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np
n=int(input())
a=[int(x) for x in input().split()]

matrix=np.zeros((n,n))

for i in range(n-1):
  matrix[i,i:i+2]+=1
matrix[-1,0]+=1
matrix[-1,-1]+=1

X = 2*np.linalg.solve(matrix, np.array(a)).astype(int)

print(*X)


Fixed submission:
from scipy.sparse import csr_matrix
from scipy.sparse.linalg import spsolve
import numpy as np

N = int(input())
A = np.array(input().split())

#値の入る座標の準備
rows = np.concatenate([np.arange(N), np.arange(N)])
cols = np.concatenate([np.arange(N), np.arange(1,N+1) % N])

#疎行列の作成
#csr_matrix((値だけのlist, 値の入る座標を示すtulpe:(rows, cols) ), 大きさ (N,N))
mat = csr_matrix(([1] * (2*N), (rows, cols)), (N,N))
#print(rows,cols,mat)
 
answer = (spsolve(mat,A) * 2).astype(int)
print(*answer)

Buggy python submission (verdict: Runtime Error):
import numpy as np
n=int(input())
a=[int(x) for x in input().split()]

matrix=np.zeros((n,n))

for i in range(n-1):
  matrix[i,i:i+2]+=1
matrix[-1,0]+=1
matrix[-1,-1]+=1

#A = np.array([[1.,3.] ,[4.,2.]])
#B = np.array([1.,1.])   # 行列Bの生成

X = np.linalg.solve(matrix, np.array(a)).tolist()
# 計算結果の表示
print(*[int(2*item) for item in X])


Fixed submission:
from scipy.sparse import csr_matrix
from scipy.sparse.linalg import spsolve
import numpy as np

N = int(input())
A = np.array(input().split())

#値の入る座標の準備
rows = np.concatenate([np.arange(N), np.arange(N)])
cols = np.concatenate([np.arange(N), np.arange(1,N+1) % N])

#疎行列の作成
#csr_matrix((値だけのlist, 値の入る座標を示すtulpe:(rows, cols) ), 大きさ (N,N))
mat = csr_matrix(([1] * (2*N), (rows, cols)), (N,N))
#print(rows,cols,mat)
 
answer = (spsolve(mat,A) * 2).astype(int)
print(*answer)
Buggy python submission (verdict: Runtime Error):
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
  

n,k=[int(x) for x in input().split()]

for i in range(1,k+1):
  #青をi個に分ける(最低数(i-1個)の赤で)
  a=comb(k-1, i-1, 10**9+7)
  #赤の残りは(n-k)-(i-1)こ
  #これをいいかんじにならべる
  b=comb(n-k+1, i, 10**9+7)
  print(a,b,(a*b)%p)


Fixed submission:
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
  

n,k=[int(x) for x in input().split()]

for i in range(1,k+1):
  #青をi個に分ける(最低数(i-1個)の赤で)
  a=comb(k-1, i-1, 10**9+7)
  #赤の残りは(n-k)-(i-1)こ
  #これをいいかんじにならべる
  b=comb(n-k+1, i, 10**9+7)
  print((a*b)%(10**9+7))
Buggy python submission (verdict: Runtime Error):
[N,K]=list(map(int,input().split()))
V=list(map(int,input().split()))
have=[]
for n,k in enumerate(reversed(range(0,K+1))):
  tmp=[V[:ki]+V[-(k-ki):] for ki in range(k)
      ]+[V[:k],]
  tmp=[sorted(item) for item in tmp if sum(item)>0]
  #print(n,tmp)
  if n!=0:
    for num_remove in range(n):
      tmp2=[item[n:] for item in tmp 
            if all([g<0 for g in item[:n]])
           ]
      
      tmp.extend(tmp2)
      #print("tmp",tmp)
      #print("tmp2",tmp2)
      
  have.extend(tmp)
  #print(n,have[-1])

if have==[]:
  print(0)
else:
  print(max(list(map(sum,have))))


Fixed submission:
l = list(map(int,input().split()
            )
        )
print(int((3*l[0]+l[1])/2
         )
     )
Buggy python submission (verdict: Runtime Error):
import numpy as np
[n,m]=[int(x) for x in input().split()]
LR_T=np.array([[int(x)-1 for x in input().split()] for _ in range(m)]).T

print(np.min(LR_T[1])-np.max(LR_T[0])+1)


Fixed submission:
import numpy as np
[n,m]=[int(x) for x in input().split()]
LR_T=np.array([[int(x)-1 for x in input().split()] for _ in range(m)]).T

print(max(np.min(LR_T[1])-np.max(LR_T[0])+1,0))

Buggy python submission (verdict: Time Limit Exceeded):
[n,m]=[int(x) for x in input().split()]
LR=[[int(x)-1 for x in input().split()] for _ in range(m)]

ok=list(range(n))
for c in LR:
  ok=[item for item in ok if c[0]<=item and item<=c[1]]
  #print(ok)
print(len(ok))


Fixed submission:
import numpy as np
[n,m]=[int(x) for x in input().split()]
LR_T=np.array([[int(x)-1 for x in input().split()] for _ in range(m)]).T

print(max(np.min(LR_T[1])-np.max(LR_T[0])+1,0))

Buggy python submission (verdict: Time Limit Exceeded):
[n,m]=[int(x) for x in input().split()]
LR=[[int(x)-1 for x in input().split()] for _ in range(m)]

ok=list(range(n))
for c in LR:
  ok=[item for item in ok if c[0]<=item and item<=c[1]]
  #print(ok)
print(len(ok))


Fixed submission:
import numpy as np
[n,m]=[int(x) for x in input().split()]
LR_T=np.array([[int(x)-1 for x in input().split()] for _ in range(m)]).T

print(max(np.min(LR_T[1])-np.max(LR_T[0])+1,0))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
[n,m]=[int(x) for x in input().split()]
LR=[[int(x)-1 for x in input().split()] for _ in range(m)]

ans=np.zeros(n)
for c in LR:
  ans[c[0]:c[1]+1]=ans[c[0]:c[1]+1]+1
print(np.sum(ans==m))


Fixed submission:
import numpy as np
[n,m]=[int(x) for x in input().split()]
LR_T=np.array([[int(x)-1 for x in input().split()] for _ in range(m)]).T

print(max(np.min(LR_T[1])-np.max(LR_T[0])+1,0))
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
s_int=[0 if x=="." else 1 for x in s]

res=float("inf")
kouho=[[0]*i+[1]*(n-i) for i in range(n+1)]

for item in kouho:
  res=min(res,sum([abs(item[i]-s_int)for i in range(n)]))

print(res)

Fixed submission:
import numpy as np
n=int(input())
s=input()
s_int=[0 if x=="." else 1 for x in s]
ruiseki=np.cumsum([0,]+s_int)
 
#print(s_int,ruiseki)
res=float("inf")
for i in range(n+1):
  #print("左黒",ruiseki[i],"右白",(n-i-(ruiseki[-1]-ruiseki[i])),"計",n-i-ruiseki[-1]+2*ruiseki[i])
  res=min(n-i-ruiseki[-1]+2*ruiseki[i],res)
print(res)
Buggy python submission (verdict: Runtime Error):
[n,t]=list(map(int,input().split()))
ntlist=[list(map(int,input().split())) for _ in range(n)]

anslist=[nt[0] for nt in ntlist if nt[1]<=t]
if ans==[]:
  print("TLE")
else:
  print(min(ans))

Fixed submission:
[n,t]=list(map(int,input().split()))
ntlist=[list(map(int,input().split())) for _ in range(n)]
 
anslist=[nt[0] for nt in ntlist if nt[1]<=t]
if anslist==[]:
  print("TLE")
else:
  print(min(anslist))
Buggy python submission (verdict: Runtime Error):
def calc_h(cx,cy,xyh_item):
  return(abs(cx-xyh_item[0])+abs(cy-xyh_item[1])+xyh_item[2])

n=int(input())
xyh=[[int(x) for x in input().split()] for _ in range(n)]
xyh=[item for item in xyh if item[2]!=0]

anslist=[]

for x in range(101):
  for y in range(101):
    c=0
    tmp=calc_h(x,y,xyh[0])
    for i in range(1,n):
      if tmp!=calc_h(x,y,xyh[i]):
        break
      else:
        c+=1
    anslist.append([c,x,y,tmp])

anslist.sort(key=lambda x:x[0])
print(*anslist[-1][1:])

Fixed submission:
def calc_h(cx,cy,xyh_item):
  res=abs(cx-xyh_item[0])+abs(cy-xyh_item[1])+xyh_item[2]
  return res

n=int(input())
xyh=[[int(x) for x in input().split()] for _ in range(n)]
xyh.sort(key=lambda x:x[0],reverse=True)

#平地の情報(ピラミッドの根元を除く)は役にたたないので捨てる
xyh0=[]
xyh1=[]
for item in xyh:
  if item[2]==0:
    xyh0.append(item)
  else:
    xyh1.append(item)

xyh=xyh1

for item0 in xyh0:
  if any([calc_h(item1[0],item1[1],item0)==item1[2] for item1 in xyh1]):
    xyh.append(item0)

n=len(xyh)

anslist=[]

for x in range(101):
  for y in range(101):
    c=0
    tmp=calc_h(x,y,xyh[0])
    for i in range(1,n):
      if tmp!=calc_h(x,y,xyh[i]):
        break
      else:
        c+=1
    #if c==n-1:
    #  print(x,y,tmp)
    anslist.append([c,x,y,tmp])


anslist.sort(key=lambda x:x[0])
print(*anslist[-1][1:])
Buggy python submission (verdict: Runtime Error):
K= int(input())
if K%2==0:
  print((K/2)**2)
else:
  print(K//2)*(K//2+1))

Fixed submission:
K= int(input())
if K%2==0:
  print((K//2)**2)
else:
  print((K//2)*(K//2+1))
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())

print(a-b+1)

Fixed submission:
l=list(map(int,input().split()))
print(l[0]-l[1]+1)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=[int(x) for x in input().split()]
ab=[[int(x) for x in input().split()] for i in range(m)]

ab.sort(key=lambda x:x[1])
#print(ab)
split=[0,]

while len(ab)!=0:
  if ab[0][1]-split[-1]>0 and ab[0][0]-split[-1]<=0:
    ab.pop(0)
  else:
    split.append(ab[0][1]-1)
  
  #print(ab)
print(len(split)-1)

Fixed submission:
n,m=[int(x) for x in input().split()]
ab=[[int(x) for x in input().split()] for i in range(m)]

ab.sort(key=lambda x:x[1])
#print(ab)
split=[0,]

#while len(ab)!=0:
for item in ab:
  if (item[1]-split[-1]>0 and item[0]-split[-1]<=0)!=True:
    split.append(item[1]-1)
  
  #print(ab)
print(len(split)-1)
Buggy python submission (verdict: Runtime Error):
s=input()
print(2*len([x for x in s if x=="+"]-len(s)
         )
     )

Fixed submission:
s=input()
print(2*len([x for x in s if x=="+"])-len(s))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

[N,M]=list(map(int,input().split()
              )
          )
XYZ=[[int(i) for i in input().split()] for i in range(N)] 
maxabs=0
for indextupl in list(itertools.permutations(range(N), M)):
  maxabs=max(sum([abs(sum([XYZ[i][j] for i in indextupl])) for j in range(3)]),
             maxabs
            )
  
print(maxabs)

Fixed submission:
[N,M]=list(map(int,input().split()
              )
          )
XYZ=[[int(i) for i in input().split()] for i in range(N)] 
maxabs=0

for i in range(8):
  pm=list(map(int,format(i, 'b')))
  pm=[0,]*(3-len(pm))+pm
  pm=[(-1)**item for item in pm]
  
  newXYZ=sorted([[item[0]*pm[0],item[1]*pm[1],item[2]*pm[2]] for item in XYZ],
                key=lambda x:sum(x),
                reverse=True)
  
  maxabs=max(sum([abs(sum([newXYZ[m][j] for m in range(M)]
                             )
                         ) for j in range(3)
                 ]
                ),
             maxabs
            )


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

n=int(input())
x=np.array([int(item) for item in input().split()])
x_sorted=np.sort(x)

for i in range(n):
  ind=np.ones(n,dtype=bool)
  ind[np.searchsorted(x_sorted,x[i])]=False
  #print(x_sorted[ind])
  print(x_sorted[ind][n//2-1])

Fixed submission:
n = int(input())
x = list(map(int,input().split()))
x_sorted = sorted(x)
pin = x_sorted[n//2]
pre = x_sorted[n//2 - 1]
for i in range(n):
  if x[i] < pin:
    print(pin)
  else:
    print(pre)

Buggy python submission (verdict: Runtime Error):
import collections
import numpy as np

n=int(input())
x=np.array([int(item) for item in input().split()])
x_sorted=np.sort(x)

for i in range(n):
  if i==0 and x[0]==x[1]:
    print(x_sorted[n//2-1])
  elif i==n-1 and x[n-1]==x[n-2]:
    print(x_sorted[n//2-1])
  elif x[i]==x[i-1] or x[i]==x[i+1]:
    print(x_sorted[n//2-1])
    
  else:
    ind=np.ones(n,dtype=bool)
    ind[np.searchsorted(x_sorted,x[i])]=False
    print(x_sorted[ind][n//2-1])

Fixed submission:
n = int(input())
x = list(map(int,input().split()))
x_sorted = sorted(x)
pin = x_sorted[n//2]
pre = x_sorted[n//2 - 1]
for i in range(n):
  if x[i] < pin:
    print(pin)
  else:
    print(pre)

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

n=int(input())
x=np.array([int(item) for item in input().split()])

c = collections.Counter(x)
x_sorted=np.sort(x)

for i in range(n):
  if c[x[i]]>1:
    print(x_sorted[n//2-1])
  else:
    ind=np.ones(n,dtype=bool)
    ind[np.searchsorted(x_sorted,x[i])]=False
    print(x_sorted[ind][n//2-1])
    

Fixed submission:
n = int(input())
x = list(map(int,input().split()))
x_sorted = sorted(x)
pin = x_sorted[n//2]
pre = x_sorted[n//2 - 1]
for i in range(n):
  if x[i] < pin:
    print(pin)
  else:
    print(pre)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n=int(input())
x=np.array([int(item) for item in input().split()])

for i in range(n):
  ind = np.ones(n, dtype=bool)
  ind[i] = False
  
  print(int(np.median(x[ind])))

Fixed submission:
n = int(input())
x = list(map(int,input().split()))
x_sorted = sorted(x)
pin = x_sorted[n//2]
pre = x_sorted[n//2 - 1]
for i in range(n):
  if x[i] < pin:
    print(pin)
  else:
    print(pre)
Buggy python submission (verdict: Time Limit Exceeded):
#n以下の素数列挙(O(n log(n))
def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

q=int(input())
lr=[[int(x) for x in input().split()] for _ in range(q)]

max_n=max(sum(lr,[]))
primelist=primes(max_n)
for query in lr:
  res=0
  for item in range(query[0],query[1]+1,2):
    if (item in primelist) and ((item+1)/2 in primelist):
      res+=1
  print(res)

Fixed submission:
import numpy as np

#n以下の素数列挙(O(n log(n))
def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

q=int(input())
lr=[[int(x) for x in input().split()] for _ in range(q)]

primelist=[0,]*(100000+1)
for n in primes(100000):
  primelist[n]=1

list2017=[primelist[n] and primelist[(n+1)//2] for n in range(1,100000,2)]
cumsum=np.cumsum(list2017)
for query in lr:
  print(cumsum[(query[1]-1)/2]-cumsum[max(0,(query[0]-1)/2-1)])

Buggy python submission (verdict: Time Limit Exceeded):
#n以下の素数列挙(O(n log(n))
def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

q=int(input())
lr=[[int(x) for x in input().split()] for _ in range(q)]

max_n=max(sum(lr,[]))
primelist=primes(max_n)
for query in lr:
  print(sum([(item in primelist) and ((item+1)/2 in primelist) for item in range(query[0],query[1]+1,2)]))

Fixed submission:
import numpy as np

#n以下の素数列挙(O(n log(n))
def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

q=int(input())
lr=[[int(x) for x in input().split()] for _ in range(q)]

primelist=[0,]*(100000+1)
for n in primes(100000):
  primelist[n]=1

list2017=[primelist[n] and primelist[(n+1)//2] for n in range(1,100000,2)]
cumsum=np.cumsum(list2017)
for query in lr:
  print(cumsum[(query[1]-1)/2]-cumsum[max(0,(query[0]-1)/2-1)])
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
s=input()
t=input()
tmp=False
if len(s)<len(t):
  tmp=True
s,t=sorted(list(s))[:min(len(s),len(t))],sorted(list(t))[-min(len(s),len(t)):]

slist=list(itertools.permutations(s,len(s)))
tlist=list(itertools.permutations(t,len(t)))

S="".join(sorted(slist)[0])
T="".join(sorted(tlist)[-1])
if S<T:
  print("Yes")
elif S==T and tmp:
  print("Yes")
else:
  print("No")

Fixed submission:
import itertools
s=input()
t=input()
S="".join(sorted(list(s)))
T="".join(sorted(list(t)))[::-1]
if S<T:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
S=input()
T=input()

Slist=list(itertools.permutations(list(S),len(S)))
Tlist=list(itertools.permutations(list(T),len(T)))

if "".join(sorted(Slist)[0])<"".join(sorted(Tlist)[-1]):
  print("Yes")
else:
  print("No")

Fixed submission:
import itertools
s=input()
t=input()
S="".join(sorted(list(s)))
T="".join(sorted(list(t)))[::-1]
if S<T:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import dijkstra
from collections import defaultdict

import sys
input = sys.stdin.readline

[H,W]= [int(x) for x in input().split()]
c=np.array([[int(x) for x in input().split()] for _ in range(10)])

A=[]
for _ in range(H):
  A+=[int(x) for x in input().split()] 

dd = defaultdict(int)
for key in A:
  if key!=1 and key!=-1:
    dd[key] += 1

res=0
for k, v in dd.items():
  res+= v*int(dijkstra(c,indices = k)[1])
print(res)

Fixed submission:
s=input()
if s[1]==s[2] and (s[0]==s[1] or s[2]==s[3]):
  print("Yes") 
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
import itertools
S=input()
T=input()

n=len(T)
Thatena=[[T[j] if (i>>j)&1 else "?" for j in range(n)] for i in range(2**n)] #Tのうち0文字以上を?に置き換えたものの集合
#print(Thatena)
#print(len(Thatena))
ans=[]
for t in Thatena:
    if S.find("".join(t))!=-1:
        anslist.append(S.rfind("".join(t)))
        break
if anslist==[]:
    print("UNRESTORABLE")
    exit()
#print(anslist[0],anslist[0]+len(T))
ans=S[:anslist[0]]+T+S[anslist[0]+len(T):]
print("".join([c if c!="?" else "a" for c in ans]))

Fixed submission:
import re
S = input().replace('?', '.')
T = input()
for i in range(len(S)-len(T), -1, -1):
    if re.match(S[i:i+len(T)], T):
        S = S.replace('.', 'a')
        print(S[:i]+T+S[i+len(T):])
        exit()
print('UNRESTORABLE')

Buggy python submission (verdict: Runtime Error):
import itertools
S=input()
T=input()

n=len(T)
Thatena=[[T[j] if (i>>j)&1 else "?" for j in range(n)] for i in range(2**n)] #Tのうち0文字以上を?に置き換えたものの集合
#print(Thatena)
#print(len(Thatena))
anslist=[S.find("".join(t)) for t in Thatena if S.find("".join(t))!=-1]

#print(anslist[0],anslist[0]+len(T))
ans=S[:anslist[0]]+T+S[anslist[0]+len(T):]
print("".join([c if c!="?" else "a" for c in ans]))

Fixed submission:
import re
S = input().replace('?', '.')
T = input()
for i in range(len(S)-len(T), -1, -1):
    if re.match(S[i:i+len(T)], T):
        S = S.replace('.', 'a')
        print(S[:i]+T+S[i+len(T):])
        exit()
print('UNRESTORABLE')

Buggy python submission (verdict: Runtime Error):
import itertools
S=input()
T=input()

def insert_hint(item,hintindex,S):
  for i in hintindex:
    item.insert(i,S[i])
  return item
  
hintindex=[n for _,n in enumerate(range(len(S))) if S[n]!="?"]

zenbu=list(itertools.permutations(
  list("abcdefghijklmnopqrstuvwxyz"),
  len(S)-len(hintindex)
))
zenbu=[insert_hint(list(item),hintindex,S) for item in zenbu]
#print(zenbu[-1])

anslist=[item for item in zenbu if "".join(item).find(T)!=-1]

#print(anslist)
print("".join(sorted(anslist)[0]))

Fixed submission:
import re
S = input().replace('?', '.')
T = input()
for i in range(len(S)-len(T), -1, -1):
    if re.match(S[i:i+len(T)], T):
        S = S.replace('.', 'a')
        print(S[:i]+T+S[i+len(T):])
        exit()
print('UNRESTORABLE')

Buggy python submission (verdict: Runtime Error):
import itertools
S=input()
T=input()

def insert_hint(item,hintindex,S):
  for i in hintindex:
    item.insert(i,S[i])
  return item
  
hintindex=[n for _,n in enumerate(range(len(S))) if S[n]!="?"]

zenbu=list(itertools.permutations(
  list("abcdefghijklmnopqrstuvwxyz"),
  len(S)-len(hintindex)
))
zenbu=[insert_hint(list(item),hintindex,S) for item in zenbu]
#print(zenbu[-1])

anslist=[item for item in zenbu if "".join(item).find(T)!=-1]

print(anslist)
print("".join(sorted(anslist)[0]))

Fixed submission:
import re
S = input().replace('?', '.')
T = input()
for i in range(len(S)-len(T), -1, -1):
    if re.match(S[i:i+len(T)], T):
        S = S.replace('.', 'a')
        print(S[:i]+T+S[i+len(T):])
        exit()
print('UNRESTORABLE')
Buggy python submission (verdict: Time Limit Exceeded):
s=input()

res=0
l=list(s)
while len(l)>1:
  if l[0]==l[-1]:
    l.pop(0)
    l.pop(-1)
  elif l[0]=="x":
    l.append("x")
    res+=1
  elif l[-1]=="x": 
    l.insert(0,"x")
    res+=1
  else:
    print(-1)
    exit()
    
print(res)

Fixed submission:
s=input()

res=0
while len(s)>1:
  if s[0]==s[-1]:
    s=s[1:-1]
  elif s[0]=="x":
    s=s+"x"
    res+=1
  elif s[-1]=="x": 
    s="x"+s
    res+=1
  else:
    print(-1)
    exit()
    
print(res)
Buggy python submission (verdict: Runtime Error):
import collections
import heapq
n=int(input())
a=[-int(item) for item in input().split()]
c = [item for item in list(collections.Counter(a).items()) if item[1]>1]
if c==[]:
  print(0)
  exit()
#print(c)
x=heapq.heappop(c)
y=heapq.heappop(c)
kouho=[]
if x[1]>=4:
  print(x*x)
else:
  print(x*y)

Fixed submission:
import collections
import heapq
n=int(input())
a=[-int(item) for item in input().split()]
c = [item for item in list(collections.Counter(a).items()) if item[1]>1]
heapq.heapify(c)
#print(c)

if len(c)==0:
  print(0)
  exit()
if sum([item[1] for item in c])<4:
  print(0)
  exit()

x=heapq.heappop(c)
if c!=[]:
  y=heapq.heappop(c)
else:
  y=(0,0)
if x[1]>=4:
  print(x[0]*x[0])
else:
  print(x[0]*y[0])

Buggy python submission (verdict: Runtime Error):
import collections
import heapq
n=int(input())
a=[-int(item) for item in input().split()]
c = [item for item in list(collections.Counter(a).items()) if item[1]>1]
#print(c)
x=heapq.heappop(c)[0]
y=heapq.heappop(c)[0]
print(x*y)

Fixed submission:
import collections
import heapq
n=int(input())
a=[-int(item) for item in input().split()]
c = [item for item in list(collections.Counter(a).items()) if item[1]>1]
heapq.heapify(c)
#print(c)

if len(c)==0:
  print(0)
  exit()
if sum([item[1] for item in c])<4:
  print(0)
  exit()

x=heapq.heappop(c)
if c!=[]:
  y=heapq.heappop(c)
else:
  y=(0,0)
if x[1]>=4:
  print(x[0]*x[0])
else:
  print(x[0]*y[0])
Buggy python submission (verdict: Runtime Error):
n=int(input())
print(min([sum([(x-item)**2 for x in [int(x) for x in input().split()]]) for item in list(range(-100,101))]))

Fixed submission:
n=int(input())
a=[int(x) for x in input().split()]
print(min([sum([(x-item)**2 for x in a]) for item in list(range(-100,101)
                                                         )
          ]
         )
     )
Buggy python submission (verdict: Runtime Error):

Copy
Copy
a=int(input())
s=input()
if a>=3200:
  print(s)
else:
  print('red')

Fixed submission:
a=int(input())
s=input()
if a>=3200:
  print(s)
else:
  print('red')
Buggy python submission (verdict: Runtime Error):
N, Y = map(int, input().split())

x=-1
y=-1
z=-1

Ten=10000
Five=5000
One=1000

count=0

max_x=int(Y//Ten)

if max_x <= N:
	for i in reversed(range(0,max_x+1)):
		if count ==0:
			max_y = int((Y - Ten*i)//Five)
			if (max_y + i) <= N:
				for j in reversed(range(0, max_y+1)):
					if (Ten*j + Five*i + One*(N-i-j))==Y:
						x=i
						y=j
						z=max_z
						count+=1
						break

print(x, y, z)

Fixed submission:
N, Y = map(int, input().split())

x=-1
y=-1
z=-1

Ten=10000
Five=5000
One=1000

count=0

max_x=int(Y//Ten)

if max_x <= N:
	for i in reversed(range(0,max_x+1)):
		if count == 1:
			break
		elif count == 0:
			max_y = int((Y - Ten*i)//Five)
			if (max_y + i) <= N:
				for j in reversed(range(0, max_y+1)):
					if (Ten*i + Five*j + One*(N-i-j))==Y:
						x=i
						y=j
						z=N - i - j
						count+=1
						break

print(x, y, z)