void next_permutation(){ p.rotate(1); int i=1; while (++count[i] > i){ count[i++] = 0; p.rotate( i ); } }