1 /**************************************************************
2 Problem: 1005
3 User: AsmDef
4 Language: C++
5 Result: Accepted
6 Time:20 ms
7 Memory:820 kb
8 ****************************************************************/
9
10 #include <cctype>
11 #include <cstdio>
12 #include <cmath>
13 #include <cstdlib>
14 inline void getd(int &x){
15 char c = getchar();
16 bool minus = 0;
17 while(!isdigit(c) && c != ‘-‘)c = getchar();
18 if(c == ‘-‘)minus = 1, c = getchar();
19 x = c - ‘0‘;
20 while(isdigit(c = getchar()))x = x * 10 + c - ‘0‘;
21 if(minus)x = -x;
22 }
23 /*======================================================*/
24 const int maxn = 1010;
25 struct BigN{
26 #define base 1000000
27 #define maxl 1000
28 int A[maxl], len;
29 BigN(){len = 1, A[0] = 0;}
30 BigN &operator *= (int x){
31 int i, mor = 0;
32 for(i = 0;i < len || mor;++i){
33 if(i < len)mor += A[i] * x;
34 A[i] = mor % base;
35 mor /= base;
36 }
37 if(i > len)len = i;
38 return *this;
39 }
40 }ans;
41 int N, S = 0, A[maxn], Acnt = 0, Bcnt = 0, prime[maxn], pcnt = 0;
42 inline void euler(){
43 int i, j;
44 bool not_p[maxn] = {0};
45 for(i = 2;i <= N;++i){
46 if(!not_p[i])prime[pcnt++] = i;
47 for(j = 0;j < pcnt;++j){
48 if(prime[j] * i > N)break;
49 not_p[prime[j]*i] = 1;
50 if(i % prime[j] == 0)break;
51 }
52 }
53 }
54 inline void init(){
55 getd(N);
56 if(N == 0){putchar(‘0‘);exit(0);}
57 int i, d;
58 if(N == 1){
59 getd(d);
60 if(d == -1 || !d)putchar(‘1‘);
61 else putchar(‘0‘);
62 exit(0);
63 }
64 for(i = 1;i <= N;++i){
65 getd(d);
66 if(d == 0){putchar(‘0‘);exit(0);}
67 if(d == -1) ++Bcnt;
68 else {
69 A[Acnt++] = d - 1;
70 S += d - 1;
71 }
72 }
73 if((S > N-2) || (S < N-2 && !Bcnt)){
74 putchar(‘0‘);
75 exit(0);
76 }
77 A[Acnt++] = N - 2 - S;
78 S = N - 2;
79 euler();
80 }
81 int powcnt[maxn] = {0};
82 inline void res(int n){
83 int i, j;
84 for(i = 0;i < pcnt;++i){
85 j = prime[i];
86 while(j <= n){
87 powcnt[i] -= n / j;
88 if(powcnt[i] < 0){printf("0");exit(0);}
89 j *= prime[i];
90 }
91 }
92 }
93 inline void work(){
94 int i, j = Acnt - 1, p;
95 ans.A[0] = 1;
96 for(i = 1;i <= A[j];++i)
97 ans *= Bcnt;
98 for(i = 0;i < pcnt;++i){
99 p = prime[i];
100 while(p <= S){
101 powcnt[i] += S / p;
102 p *= prime[i];
103 }
104 }
105 for(i = 0;i < Acnt;++i)
106 res(A[i]);
107 for(i = 0;i < pcnt;++i){
108 for(j = 1;j <= powcnt[i];++j)
109 ans *= prime[i];
110 }
111 i = ans.len - 1;
112 printf("%d", ans.A[i]);
113 while(i--)
114 printf("%06d", ans.A[i]);
115 }
116 int main(){
117 init();
118 work();
119 return 0;
120 }