prio: simplify and tune gen for the worst case
prio: check argument of gen
prio: save function unbalanced()