public int countSquares(String[] field){
        n = field.length;
        m = field[0].length();
        map = field;
        int result = 0;
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                for(int u=i; u<n; u++){
                    for(int v=j+1; v<m; v++){
                        if(different(i,j,u,v)) continue;
                        int x=u-i, y=v-j;
                        int ii=i+y, jj=j-x;
                        if(!valid(ii,jj) || different(i,j,ii,jj)) continue;
                        int uu=u+y, vv=v-x;
                        if(!valid(uu,vv) || different(i,j,uu,vv)) continue;
                        result++;
                    }
                }
            }
        }
        return result;
    }