x^2+y^2+z^2+2xy+2yz+2xz-2x-2y-2z+1
=(x^2+y^2+z^2+2xy+2yz+2xz)-2x-2y-2z+1
=(x+y+z)^2-2(x+y+z)+1
=(x+y+z-1)^2