Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
square=[]
for i in range(400):
  square.append(i*i)
a,b=int(input().split())
p=a*(10**len(str(b)))+b
if p in square:
  print('Yes')
else:
  print('No')

Fixed submission:
square=[]
for i in range(400):
  square.append(i*i)
a,b=map(int,input().split())
p=a*(10**len(str(b)))+b
if p in square:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
n=input()
mochi=[]
for i in range(n):
  k=int(input())
  mochi.append(k)
print(len(list(set(mochi))))

Fixed submission:
n=int(input())
mochi=[]
for i in range(n):
  k=int(input())
  mochi.append(k)
print(len(set(mochi)))

Buggy python submission (verdict: Runtime Error):
n=input()
mochi=[]
for i in range(n):
  k=int(input())
  mochi.append(k)
print(len(set(mochi)))

Fixed submission:
n=int(input())
mochi=[]
for i in range(n):
  k=int(input())
  mochi.append(k)
print(len(set(mochi)))
Buggy python submission (verdict: Runtime Error):
s=input()
s_=sorted(s)
s=''.join(s_)
t=input()
t_=sorted(t)
t=''.joint(t_)
if s<t:
  print('Yes')
else:
  print('No')

Fixed submission:
s=input()
s_=sorted(s)
s=''.join(s_)
t=input()
t_=sorted(t)
t=''.join(t_)
t_=reversed(t)
t=''.join(t_)
if s<t:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
n=int(input())
stack=[0]*(n+1)
a=list(map(int,input().split()))
for i in a:
  stack[i]+=1
ans=0
for i in range(1,n+1):
  if stack[i]>=i:
    ans+=i
print(n-ans)

Fixed submission:
n=int(input())
stack=[0]*(n+1)
a=list(map(int,input().split()))
for i in a:
  if i<=n:
    stack[i]+=1
ans=0
for i in range(1,n+1):
  if stack[i]>=i:
    ans+=i
print(n-ans)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
stack=[0]*(2*10**5+1)
a=list(map(int,input().split()))
num=len(set(a))
for i in a:
  stack[a]+=1
stack.sort()
def binarysearch():
  ng=-1
  ok=2*10**5+1
  while abs(ng-ok)>1:
    mid=(ng+ok)//2
    if stack[mid]==0:
      ng=mid
    else:
      ok=mid
  return ok
p=binarysearch()
ans=0
if num<=k:
  print(0)
  exit()
for i in range(num-k):
  ans+=stack[p+i]
print(ans)
  

Fixed submission:
n,k=map(int,input().split())
stack=[0]*(2*10**5+1)
a=list(map(int,input().split()))
num=len(set(a))
for i in a:
  stack[i]+=1
stack.sort()
def binarysearch():
  ng=-1
  ok=2*10**5+1
  while abs(ng-ok)>1:
    mid=(ng+ok)//2
    if stack[mid]==0:
      ng=mid
    else:
      ok=mid
  return ok
p=binarysearch()
ans=0
if num<=k:
  print(0)
  exit()
for i in range(num-k):
  ans+=stack[p+i]
print(ans)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
stack=[0]*(2*10**5+1)
a=list(map(int,input().split()))
num=len(set(a))
for i in a:
  stack[a]+=1
stack.sort()
def binarysearch():
  ng=-1
  ok=2*10**5+1
  while abs(ng-ok)>1:
    mid=(ng+ok)//2
    if stack[mid]==0:
      ng=mid
    else:
      ok=mid
  return ok
p=binarysearch()
ans=0
for i in range(num-k):
  ans+=stack[p+i]
print(ans)
  

Fixed submission:
n,k=map(int,input().split())
stack=[0]*(2*10**5+1)
a=list(map(int,input().split()))
num=len(set(a))
for i in a:
  stack[i]+=1
stack.sort()
def binarysearch():
  ng=-1
  ok=2*10**5+1
  while abs(ng-ok)>1:
    mid=(ng+ok)//2
    if stack[mid]==0:
      ng=mid
    else:
      ok=mid
  return ok
p=binarysearch()
ans=0
if num<=k:
  print(0)
  exit()
for i in range(num-k):
  ans+=stack[p+i]
print(ans)
Buggy python submission (verdict: Runtime Error):
line=str(input())
line=list(line)
a=line[0]
b=line[1]
c=line[2]
d=line[3]
o1='+'
o2='+'
o3='+'
for x in (a+b,a-b):
  for y in (c,-c):
    for z in (d,-d):
      if x+y+z==7:
        if x==a-b:
          o1='-'
        if y==-c:
          o2='-'
        if z==-d:
          o3='-'
print("{}{}{}{}{}{}{}=7".format(a,o1,b,o2,c,o3,d))


Fixed submission:
line=str(input())
line=list(line)
line=list(map(int,line))
a=line[0]
b=line[1]
c=line[2]
d=line[3]
o1='+'
o2='+'
o3='+'
count=0
for x in (a+b,a-b):
  for y in (c,-c):
    for z in (d,-d):
      if x+y+z==7 and count==0:
        if x==a-b:
          o1='-'
        if y==-c:
          o2='-'
        if z==-d:
          o3='-'
        count+=1
print("{}{}{}{}{}{}{}=7".format(a,o1,b,o2,c,o3,d))

Buggy python submission (verdict: Runtime Error):
line=str(input())
line=list(line)
a,b,c,d=line
o1='+'
o2='+'
o3='+'
for x in (a+b,a-b):
  for y in (c,-c):
    for z in (d,-d):
      if x+y+z==7:
        if x==a-b:
          o1='-'
        if y==-c:
          o2='-'
        if z==-d:
          o3='-'
print("{}{}{}{}{}{}{}=7".format(a,o1,b,o2,c,o3,d))


Fixed submission:
line=str(input())
line=list(line)
line=list(map(int,line))
a=line[0]
b=line[1]
c=line[2]
d=line[3]
o1='+'
o2='+'
o3='+'
count=0
for x in (a+b,a-b):
  for y in (c,-c):
    for z in (d,-d):
      if x+y+z==7 and count==0:
        if x==a-b:
          o1='-'
        if y==-c:
          o2='-'
        if z==-d:
          o3='-'
        count+=1
print("{}{}{}{}{}{}{}=7".format(a,o1,b,o2,c,o3,d))

Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
o1='+'
o2='+'
o3='+'
for x in (a+b,a-b):
  for y in (c,-c):
    for z in (d,-d):
      if x+y+z==7:
        if x==a-b:
          o1='-'
        if y==-c:
          o2='-'
        if z==-d:
          o3='-'
print("{}{}{}{}{}{}{}=7".format(a,o1,b,o2,c,o3,d))


Fixed submission:
line=str(input())
line=list(line)
line=list(map(int,line))
a=line[0]
b=line[1]
c=line[2]
d=line[3]
o1='+'
o2='+'
o3='+'
count=0
for x in (a+b,a-b):
  for y in (c,-c):
    for z in (d,-d):
      if x+y+z==7 and count==0:
        if x==a-b:
          o1='-'
        if y==-c:
          o2='-'
        if z==-d:
          o3='-'
        count+=1
print("{}{}{}{}{}{}{}=7".format(a,o1,b,o2,c,o3,d))

Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
o1='+'
o2='+'
o3='+'
for x in (a+b,a-b):
  for y in (c,-c):
    for z in (d,-d):
      if x+y+z==7:
        if x==a-b:
          o1='-'
        if y==-c:
          o2='-'
        if z==-d:
          o3='-'
print("{}{}{}{}{}{}{}".format(a,o1,b,o2,c,o3,d))

Fixed submission:
line=str(input())
line=list(line)
line=list(map(int,line))
a=line[0]
b=line[1]
c=line[2]
d=line[3]
o1='+'
o2='+'
o3='+'
count=0
for x in (a+b,a-b):
  for y in (c,-c):
    for z in (d,-d):
      if x+y+z==7 and count==0:
        if x==a-b:
          o1='-'
        if y==-c:
          o2='-'
        if z==-d:
          o3='-'
        count+=1
print("{}{}{}{}{}{}{}=7".format(a,o1,b,o2,c,o3,d))
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort(list(set(a)))
b=list(map(int,input().split()))
b.sort(list(set(b)))
c=list(map(int,input().split()))
c.sort(list(set(c)))
def binary_search1(x,sortedlist):
  left=-1
  right=len(sortedlist)
  while abs(right-left)>1:
    mid=(left+right)//2
    if sortedlist[mid]<=x:
      left=mid
    else:
      right=mid
  return right
def binary_search2(x,sortedlist):
  left=-1
  right=len(sortedlist)
  while abs(right-left)>1:
    mid=(left+right)//2
    if sortedlist[mid]>=x:
      right=mid
    else:
      left=mid
  return left
ans=0
for i in range(len(b)):
  ans+=(len(c)-binary_search1(b[i],c))*(binary_search2(b[i],a)+1)
print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=list(map(int,input().split()))
b.sort()
c=list(map(int,input().split()))
c.sort()
def binary_search1(x,sortedlist):
  left=-1
  right=len(sortedlist)
  while abs(right-left)>1:
    mid=(left+right)//2
    if sortedlist[mid]<=x:
      left=mid
    else:
      right=mid
  return right
def binary_search2(x,sortedlist):
  left=-1
  right=len(sortedlist)
  while abs(right-left)>1:
    mid=(left+right)//2
    if sortedlist[mid]>=x:
      right=mid
    else:
      left=mid
  return left
ans=0
for i in range(len(b)):
  ans+=(len(c)-binary_search1(b[i],c))*(binary_search2(b[i],a)+1)
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort(list(set(a)))
b=list(map(int,input().split()))
b.sort(list(set(b)))
c=list(map(int,input().split()))
c.sort(list(set(c)))
def binary_search1(x,sortedlist):
  left=-1
  right=len(sortedlist)
  while abs(right-left)>1:
    mid=(left+right)//2
    if sortedlist[mid]<=x:
      left=mid
    else:
      right=mid
  return right
def binary_search2(x,sortedlist):
  left=-1
  right=len(sortedlist)
  while abs(right-left)>1:
    mid=(left+right)//2
    if sortedlist[mid]>=x:
      right=mid
    else:
      left=mid
  return left
ans=0
for i in range(len(b)):
  ans+=binary_search1(b[i],c)*binary_search2(b[i],a)
print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=list(map(int,input().split()))
b.sort()
c=list(map(int,input().split()))
c.sort()
def binary_search1(x,sortedlist):
  left=-1
  right=len(sortedlist)
  while abs(right-left)>1:
    mid=(left+right)//2
    if sortedlist[mid]<=x:
      left=mid
    else:
      right=mid
  return right
def binary_search2(x,sortedlist):
  left=-1
  right=len(sortedlist)
  while abs(right-left)>1:
    mid=(left+right)//2
    if sortedlist[mid]>=x:
      right=mid
    else:
      left=mid
  return left
ans=0
for i in range(len(b)):
  ans+=(len(c)-binary_search1(b[i],c))*(binary_search2(b[i],a)+1)
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
ans=[]
for i in range(len(s)):
  s.insert(0,s.pop())
  s=''.join(s)
  m=[]
  flag=True
  for j in range(len(t)):
    if s[j]=='?' or t[j]==s[j]:
      m.append(t[j])
    else:
      flag=False
      break
  if flag:
    for j in range(len(t),len(s)):
      if s[j]=='?':
        m.append(a)
      else:
        m.append(s[j])
    ans.append(''.join(m))
ans.sort()
if len(ans)>0:
  print(ans[0])
else:
  print('UNRESTORABLE')

Fixed submission:
s=input()
t=input()
ans=[]
for i in range(0,len(s)-len(t)+1):
  m=[]
  flag=True
  for p in range(i):
    if s[p]=='?':
      m.append('a')
    else:
      m.append(s[p])
  for q in range(i,len(t)+i):
    if s[q]=='?' or s[q]==t[q-i]:
      m.append(t[q-i])
    else:
      flag=False
      break
  for r in range(len(t)+i,len(s)):
    if flag==False:
      break
    if s[r]=='?':
      m.append('a')
    else:
      m.append(s[r])
  if flag:
    ans.append("".join(m))
ans.sort()
if len(ans)>0:
  print(ans[0])
else:
  print('UNRESTORABLE')

Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
ans=[]
for i in range(len(s)):
  s.insert(0,s.pop())
  s=''.join(s)
  m=[]
  flag=True
  for j in range(len(t)):
    if s[j]=='?' or t[j]==s[j]:
      m.append(t[j])
    else:
      flag=False
      break
  if flag:
    for j in range(len(t),len(s)):
      if s[j]=='?':
        m.append(a)
      else:
        m.append(s[j])
    ans.append(''.join(m))
ans.sort()
print(ans[0])

Fixed submission:
s=input()
t=input()
ans=[]
for i in range(0,len(s)-len(t)+1):
  m=[]
  flag=True
  for p in range(i):
    if s[p]=='?':
      m.append('a')
    else:
      m.append(s[p])
  for q in range(i,len(t)+i):
    if s[q]=='?' or s[q]==t[q-i]:
      m.append(t[q-i])
    else:
      flag=False
      break
  for r in range(len(t)+i,len(s)):
    if flag==False:
      break
    if s[r]=='?':
      m.append('a')
    else:
      m.append(s[r])
  if flag:
    ans.append("".join(m))
ans.sort()
if len(ans)>0:
  print(ans[0])
else:
  print('UNRESTORABLE')
Buggy python submission (verdict: Runtime Error):
import sys
n,m=map(int,input().split())
vertex=[[int(i) for i in l.split()] for l in sys.stdin]
def generate(x):
  root=[i for i in range(1,x+1)]
  size=[0]*x
def find(x):
  if root[x]==x:
    return x
  return find(root[x])
def check(x,y):
  return find(x)==find(y)
def union(x,y):
  x=find(x)
  y=find(y)
  if size[x]>=size[y]:
    root[y]=x
  else:
    root[x]=y
  if size[x]==size[y]:
    size[x]+=1
ans=0
for i in range(m):
  generate(n)
  for j in range(m):
    if j!=i:
      if check(vertex[j][0],vertex[j][1]):
        pass
      else:
        union(vertex[j][0],vertex[j][1])
  for j in range(n-1):
    if check(j,j+1)==0:
      pass
    else:
      ans+=1
      break
print(ans)

Fixed submission:
import sys
n,m=map(int,input().split())
vertex=[[int(i) for i in l.split()] for l in sys.stdin]
def find(x):
  if root[x]==x:
    return x
  root[x]=find(root[x])
  return root[x]
def check(x,y):
  return find(x)==find(y)
def union(x,y):
  x=find(x)
  y=find(y)
  if size[x]>=size[y]:
    root[y]=x
  else:
    root[x]=y
  if size[x]==size[y]:
    size[x]+=1
ans=0
for i in range(m):
  root=[i for i in range(n+1)]
  size=[0]*(n+1)
  for j in range(m):
    if j!=i:
      if check(vertex[j][0],vertex[j][1]):
        pass
      else:
        union(vertex[j][0],vertex[j][1])
  for j in range(1,n):
    if check(j,j+1)==True:
      pass
    else:
      ans+=1
      break
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
n=int(input())
a=[[int(i) for i in l] for l in sys.stdin]
a.sort()
stack=a[0]
num=1
ans=0
for i in range(1,n):
  if a[i]==stack:
    num+=1
  else:
    if num%2==1:
      ans+=1
    stack=a[i]
    num=1
if num%2==1:
  ans+=1
print(ans)

Fixed submission:
import sys
n=int(input())
a=[int(i) for i in sys.stdin]
a.sort()
stack=a[0]
num=1
ans=0
for i in range(1,n):
  if a[i]==stack:
    num+=1
  else:
    if num%2==1:
      ans+=1
    stack=a[i]
    num=1
if num%2==1:
  ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
Alice=range(a,b+1)
Bob=range(c,d+1)
Alice_Bob=set(Alice)+set(Bob)
print(len(Alice_Bob))

Fixed submission:
a,b,c,d=map(int,input().split())
Alice=range(a,b+1)
Bob=range(c,d+1)
Alice_Bob=set(Alice)&set(Bob)
if len(Alice_Bob)!=0:
  print(len(Alice_Bob)-1)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
not_two=0
yes_four=0
for i in a:
  if a%2!=0:
    not_two+=1
  if a%4==0:
    yes_four+=1
if yes_four-not_two>=1:
  print('Yes')
else:
  print('No')

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
not_two=0
yes_four=0
for i in a:
  if i%2!=0:
    not_two+=1
  if i%4==0:
    yes_four+=1
if yes_four-not_two>=0:
  print('Yes')
elif yes_four+not_two==n and yes_four-not_two==-1:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=[]
sum_=0
for i in a:
  sum_+=i
  b.append(sum_a)
ans=10**18
for i in range(n-1):
  ans=min(ans,abs(b[-1]-b[i]))
print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[]
sum_=0
for i in a:
  sum_+=i
  b.append(sum_)
ans=10**18
for i in range(n-1):
  ans=min(ans,abs(b[-1]-b[i]*2))
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=[]
sum_=0
for i in a:
  sum_a+=i
  b.append(sum_a)
ans=10**18
for i in range(n-1):
  ans=min(ans,abs(b[-1]-b[i]))
print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[]
sum_=0
for i in a:
  sum_+=i
  b.append(sum_)
ans=10**18
for i in range(n-1):
  ans=min(ans,abs(b[-1]-b[i]*2))
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input()))
b=[]
c=[]
for i in range(n):
  if i%2==0:
    b.append(a[i])
  else:
    c.append(a[i])
b.reverse()
b.extend(c)
print(' '.join(map(str,b)))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[]
c=[]
for i in range(n):
  if i%2!=n%2:
    b.append(a[i])
  else:
    c.append(a[i])
b.reverse()
b.extend(c)
print(' '.join(map(str,b)))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
lamp=[]
status=1
count=0
possible=1
for i in range(n):
  p=int(input())
  lamp.append(p)
if 2 in set(lamp):
  while status!=2 or count==n:
    status=lamp[status-1]
    count+=1
  if count!=n:
    print(count)
  else:
    print(-1)
else:
  print(-1)

Fixed submission:
n=int(input())
lamp=[]
status=1
count=0
possible=0
for i in range(n):
  p=int(input())
  lamp.append(p)
while status!=2:
  if lamp[status-1]!=0:
    var=lamp[status-1]
    lamp[status-1]=0
    status=var
    count+=1
  else:
    possible+=1
    break
if possible==0:
  print(count)
else:
  print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
lamp=[]
status=1
count=0
possible=1
for i in range(n):
  p=int(input())
  lamp.append(p)
while status!=2 or count==n:
  status=lamp[status-1]
  count+=1
if count!=n:
  print(count)
else:
  print(-1)

Fixed submission:
n=int(input())
lamp=[]
status=1
count=0
possible=0
for i in range(n):
  p=int(input())
  lamp.append(p)
while status!=2:
  if lamp[status-1]!=0:
    var=lamp[status-1]
    lamp[status-1]=0
    status=var
    count+=1
  else:
    possible+=1
    break
if possible==0:
  print(count)
else:
  print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
lamp=[]
status=1
count=0
possible=1
for i in range(n):
  p=int(input())
  lamp.append(p)
while status!=2 or count==n:
  status=lamp[status-1]
  count+=1
  if count==n and status!=2:
    possible=0
if possible==1:
  print(count)
else:
  print(-1)


Fixed submission:
n=int(input())
lamp=[]
status=1
count=0
possible=0
for i in range(n):
  p=int(input())
  lamp.append(p)
while status!=2:
  if lamp[status-1]!=0:
    var=lamp[status-1]
    lamp[status-1]=0
    status=var
    count+=1
  else:
    possible+=1
    break
if possible==0:
  print(count)
else:
  print(-1)

Buggy python submission (verdict: Runtime Error):
n=int(input())
lamp=[]
status=1
count=0
possible=1
for i in range(n):
  p=int(input())
  lamp.append(p)
while status!=2 or count==n:
  status=lamp[status]
  count+=1
  if count==n and status!=2:
    possible=0
if possible==1:
  print(count)
else:
  print(-1)

Fixed submission:
n=int(input())
lamp=[]
status=1
count=0
possible=0
for i in range(n):
  p=int(input())
  lamp.append(p)
while status!=2:
  if lamp[status-1]!=0:
    var=lamp[status-1]
    lamp[status-1]=0
    status=var
    count+=1
  else:
    possible+=1
    break
if possible==0:
  print(count)
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
import math
n,m=map(int,input().split())
if abs(n-m)>1:
  print(0)
  exit()
p=10**9+7
print((2*((math.factorial(m))%)*((math.factorial(m))%))%p)


Fixed submission:
import math
n,m=map(int,input().split())
if abs(n-m)>1:
  print(0)
  exit()
p=10**9+7
if n==m:
  print((2*((math.factorial(m))%p)*((math.factorial(n))%p))%p)
else:
  print((((math.factorial(m))%p)*((math.factorial(n))%p))%p)
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
ans=[]
ans.append(['#']*(w+2))
for i in range(h):
  a=list(map(int,input().split()))
  a.insert(0,'#')
  a.append('#')
  ans.append(a)
ans.append(['#']*(w+2))
for i in ans:
  print(''.join(i))

Fixed submission:
h,w=map(int,input().split())
ans=[]
ans.append(['#']*(w+2))
for i in range(h):
  a=list(input().split())
  a.insert(0,'#')
  a.append('#')
  ans.append(a)
ans.append(['#']*(w+2))
for i in ans:
  print(''.join(i))

Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
ans=[]
ans.append(['#'*(w+2)])
for i in range(h):
  a=list(map(int,input().split()))
  a.insert(0,'#')
  a.append('#')
  ans.append(a)
ans.append(['#'*(w+2)])
for i in ans:
  print(''.join(i))

Fixed submission:
h,w=map(int,input().split())
ans=[]
ans.append(['#']*(w+2))
for i in range(h):
  a=list(input().split())
  a.insert(0,'#')
  a.append('#')
  ans.append(a)
ans.append(['#']*(w+2))
for i in ans:
  print(''.join(i))

Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
ans=[]
ans.append('#'*(w+2))
for i in range(h):
  a=list(map(int,input().split()))
  a.insert(0,'#')
  a.append('#')
  ans.append("#")
ans.append('#'*(w+2))
for i in ans:
  print(''.join(i))

Fixed submission:
h,w=map(int,input().split())
ans=[]
ans.append(['#']*(w+2))
for i in range(h):
  a=list(input().split())
  a.insert(0,'#')
  a.append('#')
  ans.append(a)
ans.append(['#']*(w+2))
for i in ans:
  print(''.join(i))
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input())
if h%3==0 or w%3==0:
  print(0)
if (w-w//3-1)%2==0 or h%2==0:
  x=h*(w//3 +1)-(h*w-h*(w//3 +1))//2
else:
  x=h*(w//3 +1)-(h*w-h*(w//3 +1)-min((w-w//3-1),h))//2
if (h-h//3-1)%2==0 or w%2==0:
  y=w*(h//3 +1)-(h*w-w*(h//3 +1))//2
else:
  y=w*(h//3 +1)-(h*w-w*(h//3 +1)-min((h-h//3-1),h))//2
print(min(x,y))

Fixed submission:
h,w=map(int,input().split())
if h%3==0 or w%3==0:
  print(0)
  exit()
if (w-w//3-1)%2==0 or h%2==0:
  x=h*(w//3 +1)-h*(w-w//3-1)//2
else:
  x=h*(w//3 +1)-(h*w-h*(w//3 +1)-min((w-w//3-1),h))//2
if (w-w//3)%2==0 or h%2==0:
  x2=h*(w-w//3)//2-h*(w//3)
else:
  x2=(h*w-h*(w//3)+min((w+w//3),h))//2-h*(w//3)
if (h-h//3-1)%2==0 or w%2==0:
  y=w*(h//3 +1)-w*(h-h//3-1)//2
else:
  y=w*(h//3 +1)-(h*w-w*(h//3 +1)-min((h-h//3-1),h))//2
if (h-h//3)%2==0 or w%2==0:
  y2=w*(h-h//3)//2-w*(h//3)
else:
  y2=(h*w-w*(h//3)+min((h-h//3),h))//2-w*(h//3)
print(min(x,y,x2,y2))
Buggy python submission (verdict: Runtime Error):
import sys
n,t=map(int,input().split())
T=[int(i) for i in sys.stdin]
endtime=0
for i in t:
  if endtime>i+t:
    endtime=endtime-(endtime-i)+t
print(endtime)

Fixed submission:
import sys
n,t=map(int,input().split())
T=list(map(int,input().split()))
ans=0
starttime=0
endtime=0
for i in T:
  if endtime>=i:
    endtime=endtime-(endtime-i)+t
  else:
    ans+=endtime-starttime
    starttime=i
    endtime=i+t
ans+=endtime-starttime
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
p=list(map(int,input().split()))
stack=[0]*(n+1)
ans=0
if p[0]==0:
  p[0]=1
  ans+=1
  stack[1]=1
else:
  stack[1]=p[0]
for i in range(1,n):
  if i%2==1:
    if p[i]+p[i-1]+stack[i-1]>=0:
      p[i]-=(p[i]+p[i-1]+stack[i-1])+1
      ans+=(p[i]+p[i-1]+stack[i-1])+1
  else:
    if p[i]+p[i-1]+stack[i-1]<=0:
      p[i]+=-(p[i]+p[i-1]+stack[i-1])+1
      ans+=-(p[i]+p[i-1]+stack[i-1])+1
  stack=p[i]+p[i-1]+stack[i-1]
print(ans)      

Fixed submission:
n=int(input())
p=list(map(int,input().split()))
p2=[i for i in p]
stack=[0]*(n+1)
ans=0
if p[0]<=0:
  ans+=1-p[0]
  p[0]=1
  stack[1]=1
else:
  stack[1]=p[0]
for i in range(1,n):
  if i%2==1:
    if p[i]+p[i-1]+stack[i-1]>=0:
      ans+=(p[i]+p[i-1]+stack[i-1])+1
      p[i]-=(p[i]+p[i-1]+stack[i-1])+1
  else:
    if p[i]+p[i-1]+stack[i-1]<=0:
      ans+=-(p[i]+p[i-1]+stack[i-1])+1
      p[i]+=-(p[i]+p[i-1]+stack[i-1])+1
  stack[i+1]=p[i]+p[i-1]+stack[i-1]
stack=[0]*(n+1)
ans2=0
if p2[0]>=0:
  ans2+=p2[0]+1
  p2[0]=-1
  stack[1]=-1
else:
  stack[1]=p2[0]
for i in range(1,n):
  if i%2==0:
    if p2[i]+p2[i-1]+stack[i-1]>=0:
      ans2+=(p2[i]+p2[i-1]+stack[i-1])+1
      p2[i]-=(p2[i]+p2[i-1]+stack[i-1])+1
  else:
    if p2[i]+p2[i-1]+stack[i-1]<=0:
      ans2+=-(p2[i]+p2[i-1]+stack[i-1])+1
      p2[i]+=-(p2[i]+p2[i-1]+stack[i-1])+1
  stack[i+1]=p2[i]+p2[i-1]+stack[i-1]
print(min(ans,ans2))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
p=1
for i in range(N):
  p=p*(i+1)
print(p%1000000007)

Fixed submission:
N=int(input())
p=1
for i in range(N):
  p=p*(i+1)%1000000007
print(p)
Buggy python submission (verdict: Runtime Error):
s=list(input())
x=s.index('A')
t=reversed(s)
y=t.index('Z')
print(len(s)-x-y)

Fixed submission:
s=list(input())
x=s.index('A')
t=list(reversed(s))
y=t.index('Z')
print(len(s)-x-y)
Buggy python submission (verdict: Time Limit Exceeded):
count=0
k,s=map(int,input().split())
for i in range(k+1):
  for j in range(k+1):
    for m in range(k+1):
      if i+j+m==s:
        count+=1
print(count)

Fixed submission:
count=0
k,s=map(int,input().split())
for i in range(k+1):
  for j in range(k+1):
    if s-k<=i+j<=s:
      count+=1
print(count)

Buggy python submission (verdict: Runtime Error):
count=0
k,s=map(int,input().split())
for i in range(s):
  for j in range(s-i):
    for m in range(s-i-j):
      if i<=k ans j<=k ans m<=k:
        count+=1
print(count)

Fixed submission:
count=0
k,s=map(int,input().split())
for i in range(k+1):
  for j in range(k+1):
    if s-k<=i+j<=s:
      count+=1
print(count)