\(\left(x+2\right)\left(x^2-2x+1\right)+\left(1-x\right)\left(1+x+x^2\right)\)
\(=\left(x+2\right)\left(x-1\right)^2-\left(x-1\right)\left(1+x+x^2\right)\)
\(=\left(x-1\right)\left[\left(x+2\right)\left(x-1\right)-\left(1+x+x^2\right)\right]\)
\(=\left(x-1\right)\left(x^2+x-2-1-x-x^2\right)\)
\(=-3\left(x-1\right)\) \(=3\left(1-x\right)\)