#include #include void moveBall(std::vector &tubes, std::vector &balls, int from, int to) { int loc = 2; while(tubes[3*from+loc] == 0) loc--; int tol = 0; while(tubes[3*to+tol] != 0) tol++; int b0, b1; for(int i=0; i<3; i++) { if(balls[3*tubes[3*from+loc] + i] == 3*from+loc) b0 = i; if(balls[3*tubes[3*to+tol] + i] == 3*to+tol) b1 = i; } std::swap(balls[3*tubes[3*from+loc] + b0], balls[3*tubes[3*to+tol] + b1]); std::swap(tubes[3*from+loc], tubes[3*to+tol]); } int main() { int n; std::cin >> n; std::vector tubes(3*(n+1)); std::vector balls(3*(n+1)); std::vector ballcnt(n+1); for(int i=0; i> b[0] >> b[1] >> b[2]; for(int j=0; j<3; j++) { tubes[3*i+j] = b[j]; balls[3*b[j] + ballcnt[b[j]]++] = 3*i+j; } } std::vector > moves; for(int i=0; i