# 平方数

8314

2

#include<stdio.h>
#include<math.h>
int num[11],book[11],pre0[11];
int tot=0,mintot=1000;

int getnum(int lenth)
{
int res=0;
for(int i=lenth;i>=1;i--){
if(!book[i]&&!pre0[i]){
res*=10;
res+=num[i];
}
}
return res;
}

void solve(int lenth,int dep)
{
if(dep==lenth+1){
for(int i=lenth;i>=1;i--){
if(!book[i]&&num[i])break;
if(!book[i]&&!num[i]){
pre0[i]=1;
tot++;
}
}
for(int i=lenth;i>=1;i--){
if(book[i])tot++;
}
if(tot==lenth)return;
double x=sqrt(getnum(lenth));
for(int i=lenth;i>=1;i--)pre0[i]=0;
if(x==(int)x){
if(tot<mintot)mintot=tot;
}
tot=0;
return;
}
book[dep]=1;
solve(lenth,dep+1);
book[dep]=0;
solve(lenth,dep+1);
}

int main()
{
//freopen("in.txt","r",stdin);
int cnt=0,m=0;
scanf("%d",&m);
while(m){
num[++cnt]=m%10;
m/=10;
}
solve(cnt,1);
if(mintot<1000)printf("%d\n",mintot);
else printf("-1\n");
return 0;
}

#include <bits/stdc++.h>
#define IO                       \
ios::sync_with_stdio(false); \
cin.tie(0);                  \
cout.tie(0);
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;
char a[maxn];

bool judge(int x) {
int sq = sqrt(x) + .5;
return sq * sq == x;
}

void solve(int n) {
int ans = INT_MAX;
for (int i = 1; i < 1 << n; i++) {
LL num = 0;
int cnt = 0, idx = -1;
for (int j = n - 1; j >= 0; j--) {
if ((1 << j) & i) {
num = num * 10;
num += a[j] - '0';
++cnt;
if (idx == -1)
idx = j;
}
}
if (a[idx] == '0' && cnt > 1) {
continue;
}
if (num > 0 && judge(num)) {
// cout << num << " " << cnt << " " << i << endl;
ans = min(ans, n - cnt);
}
}
cout << (ans == INT_MAX ? -1 : ans) << endl;
}

int main() {
#ifdef LOCAL_IM0QIANQIAN
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
#else
IO;
#endif // LOCAL_IM0QIANQIAN
cin >> a;
int len = strlen(a);
reverse(a, a + len);
solve(len);
return 0;
}