#include #include using namespace std; typedef unsigned long long int cislo; struct bst { int n; bst *left; bst *right; bst(int num){ n = num; left = NULL; right = NULL; } ~bst() { if(left){delete left;}; if(right){delete right;}; } }; int size(bst *tree) { if(tree == NULL) return 0; return (1 + size(tree->left) + size(tree->right)); } void treeins(bst *&tree, int n) { if(tree == NULL){ tree = new bst(n); }else{ if(tree->n > n){ treeins(tree->left, n); }else{ treeins(tree->right, n); } } } cislo pocet(cislo a, cislo b) { if(a == 0 || b == 0) return 1; if(b==1) return 1; if(a==1) return b; cislo sum = 0; for(cislo i = 1; i <= b; i++){ sum += pocet(a-1,i); } return sum; } cislo perm(bst *tree) { if(tree == NULL) return 1; return pocet(size(tree->left), (size(tree->right))+1)*perm(tree->left)*perm(tree->right); } int main(void) { int n; int tmp; bst *tree; while(true){ cin >> n; if(n == 0) break; for(int i = 0; i < n; i++){ cin >> tmp; treeins(tree, tmp); } cislo t = perm(tree); cout << t << "\n"; tree = NULL; } return 0; }