ansewered problem4 (but less effeciency)