Solutions working for n-pieces problem