import math
def isperfect(n):
if (math.ceil(math.sqrt(n)) == math.floor(math.sqrt(n))):
return True
else:
return False
n=int(input())
l=[]
for i in range(n):
l.append([int(i) for i in input().split(",")])
k=int(input())
m=len(l[0])
res1=[]
res2=[]
for i in range(n-k+1):
for j in range(m-k+1):
product=1
for p in range(i,k+i):
for q in range(j,k+j):
product*=l[p][q]
if(isperfect(product)):
res1.append(product)
else:
res2.append(product)
res1.sort()
res2.sort(reverse=True)
ans=res1+res2
print(*ans,sep=',')
To embed this program on your website, copy the following code and paste it into your website's HTML: