/* Fri Dec 30 17:35:35 JST 2005 */ #include #include #include using namespace std; void floor_above(int above, vector piles[101], int where[101]) { for (int i = piles[where[above]].size() - 1; ; i--) { int source, destination, target; source = where[above]; destination = piles[where[above]][i]; target = destination; piles[destination].push_back(piles[source][i]); piles[source].pop_back(); where[target] = destination; if (target == above) { break; } } } int height(int target, vector &pile) { for (int i = 0; i < pile.size(); i++) { if (pile[i] == target) { return i; } } } void move_top(int source, int destination, vector piles[101], int where[101]) { where[piles[source].back()] = destination; piles[destination].push_back(piles[source].back()); piles[source].pop_back(); } int main() { int m; while (cin >> m && m > 0) { vector piles[101]; int where[101]; for (int i = 1; i <= m; i++) { piles[i].push_back(i); where[i] = i; } int I, J; while (cin >> I >> J && I > 0) { if (I == J) { continue; } else if (J == 0) { if (piles[where[I]][0] == I) { continue; } else { floor_above(I, piles, where); } } else if (where[I] == where[J]) { if (height(I, piles[where[I]]) < height(J, piles[where[J]])) { floor_above(I, piles, where); move_top(where[I], where[J], piles, where); } else { continue; } } else { floor_above(I, piles, where); move_top(where[I], where[J], piles, where); } } multiset heights; for (int i = 1; i <= m; i++) { heights.insert(piles[i].size()); } for (multiset::iterator p = heights.begin(); p != heights.end(); p++) { if (*p > 0) { cout << *p << endl; } } cout << "end" << endl; } return 0; }