implementation of problem8 (the simplest way)