solve p020 (just 1st version; more improvement is possible)