#include #include #include #include #include #include #include using namespace std; #define SIZE(s) int((s).size()) #define REP(i,n) for (int i=0; i<(n); i++) class bigInt { public: vector D; bigInt() { D.clear(); D.push_back(0); } bigInt(int x) { D.clear(); while (x) { D.push_back(x%10); x/=10; } } }; bigInt comb[110][110]; class node { public: bigInt res; int size, val; node *left, *right, *up; node() { size=0; left=right=up=NULL; } }; node *root; void insert(int x) { if (root == NULL) { root = new node(); root->val = x; } else { node *kde = root, *par = NULL; bool left; while (kde) { par = kde; if (x < kde->val) { kde=kde->left; left=true; } else { kde=kde->right; left=false; } } kde = new node(); kde->up = par; if (left) par->left=kde; else par->right=kde; kde->val=x; } } void print(node *kde, int depth) { if (!kde) return; cout << string(2*depth,' ') << kde->val << endl; print(kde->left,depth+1); print(kde->right,depth+1); } bigInt utras(bigInt A) { int res=0; REP(i,SIZE(A.D)) { A.D[i] += res; res = A.D[i] / 10; A.D[i] %= 10; } while (res) { A.D.push_back(res%10); res/=10; } return A; } bigInt add(bigInt A, bigInt B) { bigInt res; res.D.resize( max( A.D.size(), B.D.size() ) ); REP(i,SIZE(A.D)) res.D[i] += A.D[i]; REP(i,SIZE(B.D)) res.D[i] += B.D[i]; return utras(res); } bigInt mul(bigInt A, int x) { REP(i,SIZE(A.D)) A.D[i] *= x; return utras(A); } bigInt mul(bigInt A, bigInt B) { bigInt res(0); REP(i,SIZE(B.D)) { bigInt tmp = mul(A,B.D[i]); reverse( tmp.D.begin(), tmp.D.end() ); REP(j,i) tmp.D.push_back(0); reverse( tmp.D.begin(), tmp.D.end() ); res = add(res, tmp); } return res; } void print(const bigInt &B) { for (int i=SIZE(B.D)-1; i>=0; i--) printf("%d",B.D[i]); printf("\n"); } void solve(node *kde) { if (!kde) return; solve(kde->left); solve(kde->right); kde->size = 1; int ls=0, rs=0; if (kde->left) ls = kde->left->size; if (kde->right) rs = kde->right->size; kde->size += ls+rs; kde->res = bigInt(1); bigInt L(1), R(1); if (kde->left) L = kde->left->res; if (kde->right) R = kde->right->res; kde->res = mul(kde->res,L); kde->res = mul(kde->res,R); kde->res = mul(kde->res,comb[ls+rs][ls]); // kde->res = mul(kde->res,bigInt(rs+1)); } int main() { for (int n=0; n<=102; n++) for (int k=0; k<=n; k++) { if (k==0 || k==n) { comb[n][k] = bigInt(1); } else { comb[n][k] = add(comb[n-1][k-1], comb[n-1][k]); } } while (1) { int N; scanf("%d",&N); if (!N) break; root = NULL; for (int i=0; ires); } }