Use typedata lists and static length lists (growable lists with .add are a lot slower).
Remove the for loop in solve as it's not used.