I use following code, output seems ok, but requirements are not satisfied.