#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int i,n,aux,j;
cin >> n;
int v[n], x[n];
for(i=1;i<=n;i++)
cin >> v[i];
for(i=1;i<=n;i++)
x[i]=-1;
for(i=1;i<=n;i++)
{
if(((int)sqrt(v[i])*(int)sqrt(v[i]))==v[i])
x[i]=v[i];
}
for(i=1;i<n;i++)
for(j=i+1;j<=n;j++)
if((x[i]>x[j]) && (x[i]!=-1) && (x[j]!=-1))
{
aux=x[i];
x[i]=x[j];
x[j]=aux;
}
for(i=1;i<=n;i++)
if(x[i]==-1)
x[i]=v[i];
for(i=1;i<=n;i++)
cout<<x[i]<<" ";
return 0;
}
Ia vezi daca merge asa