Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s=input()
n=len(s)
a=str()
b=str()
k='keyence'
l='ecneyek'
for i in range(n):
  if a+s[i] in k:
    a+=s[i]
    j=i
  else:
    break
for i in range(6-j):
  if b+s[n-i-1] in l:
    b+=s[n-i-1]
  else:
    break
if a+b[::-1]==k or a==k or b[::-1]==k:
  print('YES')
else:
  print('NO')

Fixed submission:
s=input()
n=len(s)
a=str()
b=str()
k='keyence'
l='ecneyek'
j=0
for i in range(n):
  if a+s[i] in k:
    a+=s[i]
    j=i+1
  else:
    break
for i in range(7-j):
  if b+s[n-i-1] in l:
    b+=s[n-i-1]
  else:
    break
if a+b[::-1]==k:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[float('inf')]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
  for j in range(k):
    dp[i]=min(dp[max(0,i-j-1)]+abs(h[i]-h[max(0,i-j-1)]),dp[i])
print(dp[n-1])

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[float('inf')]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
  for j in range(k):
    dp[i]=min(dp[max(0,i-j-1)]+abs(h[i]-h[max(0,i-j-1)]),dp[i])
print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0]*m for _ in range(n)]
if s[0]==t[0]:
    dp[0][0]=1
for i in range(n):
    for j in range(m):
        if s[i]==t[j]:
            if i>0 and j>0:
                dp[i][j]=dp[i-1][j-1]+1
        else:
            if i>0:
                dp[i][j]=max(dp[i][j],dp[i-1][j])
            if j>0:
                dp[i][j]=max(dp[i][j],dp[i][j-1])
leng=dp[n-1][m-1]
i,j=n-1,m-1
ans=""
while leng>0:
    if s[i]==t[j]:
        ans+=s[i]
        i-=1
        j-=1
        leng-=1
    else:
        if dp[i-1][j]==dp[i][j]:
            i-=1
        elif dp[i][j-1]==dp[i][j]:
            j-=1
print(ans[::-1])

Fixed submission:
s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0]*(m+1) for _ in range(n+1)]
for i in range(1,n+1):
    for j in range(1,m+1):
        if s[i-1]==t[j-1]:
            if i>0 and j>0:
                dp[i][j]=dp[i-1][j-1]+1
        else:
            if i>0:
                dp[i][j]=max(dp[i][j],dp[i-1][j])
            if j>0:
                dp[i][j]=max(dp[i][j],dp[i][j-1])
leng=dp[n][m]
i,j=n,m
ans=""
while leng>0:
    if s[i-1]==t[j-1]:
        ans+=s[i-1]
        i-=1
        j-=1
        leng-=1
    else:
        if dp[i-1][j]==dp[i][j]:
            i-=1
        elif dp[i][j-1]==dp[i][j]:
            j-=1
print(ans[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,p=map(int,input().split())
if n==1:
  print(p)
else:
  for i in range(int(p**(1/n))+1):
    if p%(i+1)**n==0:
      ans=i+1
  print(ans)


Fixed submission:
n,p=map(int,input().split())
ans=[]
if n==1:
  print(p)
elif n>=40:
  print(1)
else:
  for i in range(int(p**(1/n))+1):
    if p%(i+1)**n==0:
      ans.append((i+1))
  print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n,p=map(int,input().split())
ans=[]
if n==1:
  print(p)
else:
  for i in range(int(p**(1/n))+1):
    if p%(i+1)**n==0:
      ans.append((i+1))
  print(max(ans))


Fixed submission:
n,p=map(int,input().split())
ans=[]
if n==1:
  print(p)
elif n>=40:
  print(1)
else:
  for i in range(int(p**(1/n))+1):
    if p%(i+1)**n==0:
      ans.append((i+1))
  print(max(ans))
Buggy python submission (verdict: Runtime Error):
n=int(input())
div=[0]*(n+1)
for i in range(1,n+1):
  k=i
  for j in range(1,int(i**0.5)+1):
    cnt=0
    while k%(j+1)==0:
      k//=(j+1)
      cnt+=1
    div[j+1]+=cnt
  if k>1:
    div[k]+=1
ans=0
d=dict()
for i,j,k in [[4,4,2],[24,2,1000],[14,4,1000],[74,1000,1000]]:
  cnti,cntj,cntk=0,0,0
  for l in range(2,n+1):
    if j==1000 and k==1000:
      if div[l]>=i:
        ans+=1
    for m in range(2,n+1):
      if l!=m and j!=1000 and k==1000:
        if div[l]>=i and div[m]>=j:
            ans+=1
      for o in range(2,n+1):
        if (m,l) not in d:
          if l!=o and l!=m and m!=o:
            if i!=1000 and j!=1000 and k!=1000:
              if div[l]>=i and div[m]>=j and div[o]>=k:
                ans+=1
                d[(l,m)]=0
print(ans)

Fixed submission:
n=int(input())
div=[0]*(n+10)
for i in range(1,n+1):
  k=i
  for j in range(1,int(i**0.5)+1):
    cnt=0
    while k%(j+1)==0:
      k//=(j+1)
      cnt+=1
    div[j+1]+=cnt
  if k>1:
    div[k]+=1
ans=0
d=dict()
for i,j,k in [[4,4,2],[24,2,1000],[14,4,1000],[74,1000,1000]]:
  cnti,cntj,cntk=0,0,0
  for l in range(2,n+1):
    if j==1000 and k==1000:
      if div[l]>=i:
        ans+=1
    for m in range(2,n+1):
      if l!=m and j!=1000 and k==1000:
        if div[l]>=i and div[m]>=j:
            ans+=1
      for o in range(2,n+1):
        if (m,l) not in d:
          if l!=o and l!=m and m!=o:
            if i!=1000 and j!=1000 and k!=1000:
              if div[l]>=i and div[m]>=j and div[o]>=k:
                ans+=1
                d[(l,m)]=0
print(ans)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
n,m=map(int,input().split())
s=input()
t=input()
if gcd(n,m)==1:
  if s[0]==t[0]:
    print(n*m)
  else:
    print(-1)
else:
  k=n//gcd(n,m)
  l=m//gcd(n,m)
  if len(s)<=len(t):
    for i in range(k):
      if s[i*k]!=t[i*l]:
        print(-1)
        exit()
    print(k*l*gcd(n,m))
  else:
    for i in range(l):
      if s[i*k]!=t[i*l]:
        print(-1)
        exit()
    print(k*l*gcd(n,m))

Fixed submission:
from fractions import gcd
n,m=map(int,input().split())
s=input()
t=input()
if gcd(n,m)==1:
  if s[0]==t[0]:
    print(n*m)
  else:
    print(-1)
else:
  k=n//gcd(n,m)
  l=m//gcd(n,m)
  for i in range(gcd(n,m)):
    if s[i*k]!=t[i*l]:
      print(-1)
      exit()
  print(k*l*gcd(n,m))
Buggy python submission (verdict: Runtime Error):
n,t=map(int,input().split())
ct=[list(map(int,input().split())) for i in range(n)]
ans=float('inf')
ok=False
for i in range(n):
  if ct[i][1]<=t:
    ans=min(ans,ct[i][0])
    ok=True
if ok:
  print(ans)
else:
  print('TLE')


Fixed submission:
n=int(input())
if n==1:
  print('Hello World')
else:
  a=int(input())
  b=int(input())
  print(a+b)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=int(input())
b=int(input())
if n==1:
  print('Hello World')
else:
  print(a+b)

Fixed submission:
n=int(input())
if n==1:
  print('Hello World')
else:
  a=int(input())
  b=int(input())
  print(a+b)
Buggy python submission (verdict: Runtime Error):
n=int(input())
w=[input() for i range(n)]
d={}
for i in range(n):
  if w[i] not in d:
    d[w[i]]=1
  else:
    print('No')
    exit()
for i in range(n-1):
  if w[i][len(w[i])-1]!=w[i+1][0]:
    print('No')
    exit()
print('Yes')

Fixed submission:
n=int(input())
w=[input() for i in range(n)]
d={}
for i in range(n):
  if w[i] not in d:
    d[w[i]]=1
  else:
    print('No')
    exit()
for i in range(n-1):
  if w[i][len(w[i])-1]!=w[i+1][0]:
    print('No')
    exit()
print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
def main():
  n,m,q=map(int,input().split())
  x=[[0]*(n+1) for i in range(n+1)]
  c=[[0]*(n+1) for i in range(n+1)]
  for i in range(m):
    l,r=map(int,input().split())
    x[l][r]+=1
  for i in range(1,n+1):
    for j in range(1,n+1):
      c[i][j]=c[i][j-1]+x[i][j]
  for i in range(q):
    p,q=map(int,input().split())
    s=0
    for j in range(p,q+1):
      s+=c[j][q]-c[j][p-1]
    print(s)
if __name__=='__main__':
  main()

Fixed submission:
n,m,q=map(int,input().split())
x=[[0]*(n+1) for i in range(n+1)]
c=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
  l,r=map(int,input().split())
  x[l][r]+=1
for i in range(1,n+1):
  for j in range(1,n+1):
    c[i][j]=c[i][j-1]+x[i][j]
for i in range(q):
  p,q=map(int,input().split())
  s=0
  for j in range(p,q+1):
    s+=c[j][q]-c[j][p-1]
  print(s)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,q=map(int,input().split())
x=[[0]*(n+1) for i in range(n+1)]
c=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
  l,r=map(int,input().split())
  x[l][r]+=1
for i in range(1,n+1):
  for j in range(1,n+1):
    c[i][j]=c[i][j-1]+x[i][j]
for i in range(q):
  p,q=map(int,input().split())
  s=0
  for j in range(p,q+1):
    s+=c[j][q]-c[j][p-1]
  print(s)

Fixed submission:
n,m,q=map(int,input().split())
x=[[0]*(n+1) for i in range(n+1)]
c=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
  l,r=map(int,input().split())
  x[l][r]+=1
for i in range(1,n+1):
  for j in range(1,n+1):
    c[i][j]=c[i][j-1]+x[i][j]
for i in range(q):
  p,q=map(int,input().split())
  s=0
  for j in range(p,q+1):
    s+=c[j][q]-c[j][p-1]
  print(s)
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse.csgraph import csgraph_from_dense,dijkstra
import sys
input=sys.stdin.readline
n,m,s,t=map(int,input().split())
ey=[[10**10]*n for _ in range(n)]
es=[[10**10]*n for _ in range(n)]
for i in range(m):
  u,v,a,b=map(int,input().split())
  ey[u-1][v-1]=a
  ey[v-1][u-1]=a
  es[u-1][v-1]=b
  es[v-1][u-1]=b
gy=csgraph_from_dense(ey,null_value=10**10)
gs=csgraph_from_dense(es,null_value=10**10)
dy=dijkstra(gy,indices=s-1)
ds=dijkstra(gs,indices=t-1)
accumb=[10*10]*n
accumb[n-1]=int(dy[n-1]+ds[n-1])
for i in range(1,n):
  accumb[n-i-1]=int(min(dy[n-i-1]+ds[n-i-1],accumb[n-i]))
money=10**15
for i in range(n):
  print(money-accumb[i])

Fixed submission:
import sys
import heapq
input=sys.stdin.readline
def dijkstra_heap(s,edge):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d
n,m,s,t=map(int,input().split())
ey=[[] for _ in range(n)]
es=[[] for _ in range(n)]
for i in range(m):
  u,v,a,b=map(int,input().split())
  ey[u-1].append([a,v-1])
  ey[v-1].append([a,u-1])
  es[u-1].append([b,v-1])
  es[v-1].append([b,u-1])
dy=dijkstra_heap(s-1,ey)
ds=dijkstra_heap(t-1,es)
accumb=[10*10]*n
accumb[n-1]=int(dy[n-1]+ds[n-1])
for i in range(1,n):
  accumb[n-i-1]=int(min(dy[n-i-1]+ds[n-i-1],accumb[n-i]))
money=10**15
for i in range(n):
  print(money-accumb[i])
Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
def main():
  n,m=map(int,input().split())
  p=list(map(int,input().split()))
  xy=[list(map(int,input().split())) for i in range(n)]
  class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)
  uf=UnionFind(n)
  for i in range(m):
    uf.union(p[xy[i][0]-1]-1,p[xy[i][1]-1]-1)
  ans=0
  for i in range(n):
    if uf.same(i,p[i]-1):
      ans+=1
  print(ans)
if __name__=='__main__':
  main()

Fixed submission:
import sys
input=sys.stdin.readline
def main():
  n,m=map(int,input().split())
  p=list(map(int,input().split()))
  xy=[list(map(int,input().split())) for i in range(m)]
  class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)
  uf=UnionFind(n)
  for i in range(m):
    uf.union(p[xy[i][0]-1]-1,p[xy[i][1]-1]-1)
  ans=0
  for i in range(n):
    if uf.same(i,p[i]-1):
      ans+=1
  print(ans)
if __name__=='__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
k=int(input())
d=dict()
if len(s)==1:
  print(s)
else:
  for i in range(len(s)):
    a=s[i]
    if a not in d:
      d[a]=0
    for j in range(i+1,len(s)):
      a+=s[j]
      if a not in d:
        d[a]=0
  l=list(d)
  l.sort()
  print(l[k-1])

Fixed submission:
s=input()
k=int(input())
n=len(s)
ans=dict()
for i in range(n):
  t=str()
  for j in range(min(5,n-i)):
    t+=s[i+j]
    ans[t]=0
ans=sorted(list(ans.keys()))
print(ans[k-1])

Buggy python submission (verdict: Runtime Error):
s=input()
k=int(input())
d=dict()
if len(s)==1:
  print(s)
else:
  for i in range(len(s)-1):
    a=s[i]
    if a not in d:
      d[a]=0
    for j in range(i+1,len(s)):
      a+=s[j]
      if a not in d:
        d[a]=0
  l=list(d)
  l.sort()
  print(l[k-1])

Fixed submission:
s=input()
k=int(input())
n=len(s)
ans=dict()
for i in range(n):
  t=str()
  for j in range(min(5,n-i)):
    t+=s[i+j]
    ans[t]=0
ans=sorted(list(ans.keys()))
print(ans[k-1])
Buggy python submission (verdict: Runtime Error):
n=int(input())
x=list(map(int,input().split()))
for i in range(n):
  if i+1<(2+n)//2:
    print(x[(n+2)//2])
  else:
    print(x[(n+2)//2-1])

Fixed submission:
n=int(input())
x=list(map(int,input().split()))
sx=sorted(x)
a=sx[n//2]
b=sx[n//2-1]
for i in range(n):
  if x[i]>=a:
    print(b)
  else:
    print(a)
Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial
n=int(input())
a=list(map(int,input().split()))
b=max(a)
a.remove(b)
l=[]
for i in range(n-1):
  l.append([factorial(b)//(factorial(b-a[i])*factorial(a[i])),a[i]])
l.sort(reverse=True)
print(b,l[0][1])

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=max(a)
a.remove(b)
l=[]
for i in range(n-1):
  l.append([abs(b/2-a[i]),a[i]])
l.sort()
print(b,l[0][1])
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[0]
a.append(map(int,input().split()))
a.append(0)
s=abs(a[0])+abs(a[n-1])
for i in range(n-1):
  s+=abs(a[i]-a[i+1])
for i in range(1,n):
  if min(a[i+1],a[i-1])<=a[i]<=max(a[i-1],a[i+1]):
    print(s)
  elif a[i]<=min(a[i-1],a[i+1])<=max(a[i-1],a[i+1]):
    print(s-2*abs(a[i]-min(a[i+1],a[i-1])))
  else:
    print(s-2*abs(max(a[i-1],a[i+1])-a[i]))

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
a=[0]
for i in range(n):
  a.append(h[i])
a.append(0)
s=0
for i in range(n+1):
  s+=abs(a[i]-a[i+1])
for i in range(1,n+1):
  if min(a[i+1],a[i-1])<=a[i]<=max(a[i-1],a[i+1]):
    print(s)
  elif a[i]<=min(a[i-1],a[i+1])<=max(a[i-1],a[i+1]):
    print(s-2*abs(a[i]-min(a[i+1],a[i-1])))
  else:
    print(s-2*abs(max(a[i-1],a[i+1])-a[i]))
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
ans=0
while 1:
    for i in range(n):
        if a[i]%2:
            print(ans)
            exit()
        a[i]//=2
    ans+=1

Fixed submission:
s=input()
ans=0
for i in range(3):
    if s[i]=="1":
        ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
a=-1
n=len(s)
k=len(t)
if k>n:
  print('UNRESTORABLE')
else:
  ans=str()
  for i in range(n):
    ok=True
    if n-i>=k:
      for j in range(k):
        if t[j]!=s[i+j] and s[i+j]!='?':
          ok=False
      if ok:
        a=i
  if a==-1:
    print('UNRESTORABLE')
  else:
    for i in range(n):
      if a<=i<=a+k-1:
        ans+=t[i-a]
      else:
        if s[i]=='?':
          ans+='a'
        else:
          ans+=s[i]
print(ans)

Fixed submission:
s=input()
t=input()
a=-1
n=len(s)
k=len(t)
if k>n:
  print('UNRESTORABLE')
else:
  ans=str()
  for i in range(n):
    ok=True
    if n-i>=k:
      for j in range(k):
        if t[j]!=s[i+j] and s[i+j]!='?':
          ok=False
      if ok:
        a=i
  if a==-1:
    print('UNRESTORABLE')
  else:
    for i in range(n):
      if a<=i<=a+k-1:
        ans+=t[i-a]
      else:
        if s[i]=='?':
          ans+='a'
        else:
          ans+=s[i]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
x,y,xy=[],[],[]
for _ in range(n):
  a,b=map(int,input().split())
  x.append(a)
  y.append(b)
  xy.append((a,b))
x.sort()
y.sort()
ans=float('inf')
for i in range(n-1):
  x1=x[i]
  for j in range(i+1,n):
    x2=x[j]
    for l in range(n-1):
      y1=y[l]
      for m in range(l+1,n):
        y2=y[m]
        cnt=0
        for o in range(n):
          x3,y3=xy[o]
          if x1<=x3<=x2 and y1<=y3<=y2:
            cnt+=1
        if cnt>=k:
          ans=min(ans,(x2-x1)*(y2-y1))
print(ans)

Fixed submission:
n,k=map(int,input().split())
x,y,xy=[],[],[]
for _ in range(n):
  a,b=map(int,input().split())
  x.append(a)
  y.append(b)
  xy.append((a,b))
x.sort()
y.sort()
ans=float('inf')
for i in range(n-1):
  x1=x[i]
  for j in range(i+1,n):
    x2=x[j]
    for l in range(n-1):
      y1=y[l]
      for m in range(l+1,n):
        y2=y[m]
        cnt=0
        for o in range(n):
          x3,y3=xy[o]
          if x1<=x3<=x2 and y1<=y3<=y2:
            cnt+=1
        if cnt>=k:
          ans=min(ans,(x2-x1)*(y2-y1))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
for h in range(1,(3*n)//4+1):
  for j in range(1,3501):
    if (4*h*j-j*n-n*h)>0 and 3500>=(n*h*j)/(4*h*j-j*n-n*h)>0 and ((n*h*j)/(4*h*j-j*n-n*h)).is_integer():
      print(h,j,(n*h*j)//(4*h*j-j*n-n*h))
      exit()

Fixed submission:
n=int(input())
for h in range(1,(3*n)//4+1):
  for j in range(1,3501):
    if (4*h*j-j*n-n*h)>0 and 3500>=(n*h*j)/(4*h*j-j*n-n*h)>0 and ((n*h*j)/(4*h*j-j*n-n*h)).is_integer():
      print(h,j,(n*h*j)//(4*h*j-j*n-n*h))
      exit()
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
d={}
for i in range(n):
  if a[i] not in d:
    d[a[i]]=1
  else:
    d[a[i]]+=1
lis=sorted(d.items(),reverse=True)
for i in range(len(lis)):
  if lis[i][1]<2:
    lis.remove(lis[i])
lis.sort(reverse=True)
if len(lis)>=2:
  if lis[0][1]>=4:
    print(lis[0][0]**2)
  else:
    print(lis[0][0]*lis[1][0])
elif len(lis)==1:
  if lis[0][1]>=4:
    print(lis[0][0]**2)
  else:
    print(0)
else:
  print(0)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
lis=[]
cnt=0
for i in range(n-1):
  if a[i+1]==a[i]:
    cnt+=1
  else:
    if cnt>=1:
      lis.append([a[i],cnt])
    cnt=0
if cnt>=1:
  lis.append([a[n-1],cnt])
lis.sort(reverse=True)
if len(lis)>=2:
  if lis[0][1]>=3:
    print(lis[0][0]**2)
  else:
    print(lis[0][0]*lis[1][0])
elif len(lis)==1:
  if lis[0][1]>=3:
    print(lis[0][0]**2)
  else:
    print(0)
else:
  print(0)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
k=0
i=0
cnt=0
lis=[]
while i<=n-2 or cnt<2:
  if a[i]==a[i+1] and a[i]!=k:
    lis.append(a[i])
    k=a[i]
    cnt+=1
  i+=1
if len(lis)>=2:
  print(lis[0]*lis[1])
else:
  print(0)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
lis=[]
cnt=0
for i in range(n-1):
  if a[i+1]==a[i]:
    cnt+=1
  else:
    if cnt>=1:
      lis.append([a[i],cnt])
    cnt=0
if cnt>=1:
  lis.append([a[n-1],cnt])
lis.sort(reverse=True)
if len(lis)>=2:
  if lis[0][1]>=3:
    print(lis[0][0]**2)
  else:
    print(lis[0][0]*lis[1][0])
elif len(lis)==1:
  if lis[0][1]>=3:
    print(lis[0][0]**2)
  else:
    print(0)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
n=int(input())
d=[dict() for _ in range(n)]
for i in range(n):
    for c in input():
        if c not in d[i]:
            d[i][c]=1
        else:
            d[i][c]+=1
ans=""
for i in range(26):
    mini=10**18
    for j in range(n):
        if chr(97+i) not in d[j]:
            mini=0
        else:
            mini=min(mini,d[j][chr(97+i)])
    ans+=mini*chr(97+i)
print(ans)

Fixed submission:
a,b,c=map(int,input().split())
if 2*b==a+c:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
hatsugen=["H","D"]
idx=hatsugen.index(b)
if a=="H":
    print(hatsugen[idx])
else:
    print(hatsugen[1-idx])

Fixed submission:
a,b=input().split()
hatsugen=["H","D"]
idx=hatsugen.index(b)
if a=="H":
    print(hatsugen[idx])
else:
    print(hatsugen[1-idx])
Buggy python submission (verdict: Runtime Error):
from itertools import permutations
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
p=[i for i in range(1,n+1)]
np=list(permutations(p))
edge=[[] for i in range(m)]
for i in range(m):
  edge[l[i][0]-1].append(l[i][1]-1)
  edge[l[i][1]-1].append(l[i][0]-1)
ans=0
for i in range(len(np)):
  if np[i][0]!=1:
    continue
  else:
    ok=True
    for j in range(n-1):
      if np[i][j]-1 not in edge[np[i][j+1]-1]:
        ok=False
    if ok:
      ans+=1
print(ans)

Fixed submission:
from itertools import permutations
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
p=[i for i in range(1,n+1)]
np=list(permutations(p))
edge=[[] for i in range(n)]
for i in range(m):
  edge[l[i][0]-1].append(l[i][1]-1)
  edge[l[i][1]-1].append(l[i][0]-1)
ans=0
for i in range(len(np)):
  if np[i][0]!=1:
    continue
  else:
    ok=True
    for j in range(n-1):
      if np[i][j]-1 not in edge[np[i][j+1]-1]:
        ok=False
    if ok:
      ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,ma,mb=map(int,input().split())
subs=[list(map(int,input().split())) for _ in range(n)]
infi=10**18
dp=[[[infi]*401 for _ in range(401)] for _ in range(n+1)]
dp[0][0][0]=0
for i in range(1,n+1):
    a,b,c=subs[i-1]
    for j in range(401):
        for k in range(401):
            if j+a<=400 and k+b<=400:
                dp[i][j+a][k+b]=min(dp[i][j+a][k+b],dp[i-1][j][k]+c)
            dp[i][j][k]=min(dp[i][j][k],dp[i-1][j][k])
ans=infi
for i in range(1,401):
    for j in range(1,401):
        if i%ma==0 and j%mb==0:
            if i//ma==j//mb:
                ans=min(ans,dp[n][i][j])
if ans==infi:
    ans=-1
print(ans)

Fixed submission:
n,ma,mb=map(int,input().split())
subs=[list(map(int,input().split())) for _ in range(n)]
infi=10**18
dp=[[[infi]*401 for _ in range(401)] for _ in range(n+1)]
dp[0][0][0]=0
for i in range(1,n+1):
    a,b,c=subs[i-1]
    for j in range(401):
        for k in range(401):
            if j+a<=400 and k+b<=400:
                dp[i][j+a][k+b]=min(dp[i][j+a][k+b],dp[i-1][j][k]+c)
            dp[i][j][k]=min(dp[i][j][k],dp[i-1][j][k])
ans=infi
for i in range(1,401):
    for j in range(1,401):
        if i%ma==0 and j%mb==0:
            if i//ma==j//mb:
                ans=min(ans,dp[n][i][j])
if ans==infi:
    ans=-1
print(ans)
Buggy python submission (verdict: Runtime Error):
x,y=map(int,input().split())
if x<0 and y<0 or x>0 and y>0 and y<x:
  print(abs(x-y)+2)
elif x=0 or y=0 and y<x:
  print(abs(x-y)+1)
else:
  print(min(abs(x-y),abs(-x-y)+1))


Fixed submission:
x,y=map(int,input().split())
if (x<0 and y<0 or x>0 and y>0) and y<x:
  print(abs(x-y)+2)
elif x>=0 and y<=0:
  print(abs(abs(x)-abs(y))+1)
elif x<0 and y>0 and y>x:
    print(abs(abs(x)-abs(y))+1)
else:
    print(y-x)