I thought that some pieces may be the same, but number of different pieces must be maximal. So I got WA16.. When all pieces became different, I got AC.
The jury solution builds the correct answer for n=30 fast enough, so it is possible to solve this problem without precalc. We decided to leave it like that.