#include <iostream>
#include <algorithm>
using namespace std;
template <typename T> T read() {
T res = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) res = (res << 3) + (res << 1) + (ch ^ 48);
return res * f;
}
template <typename T> void read(T &x) {
x = read<T>();
}
template <typename T> void write(T x, char ed = '\n') {
int sta[sizeof(T) << 2], top = 0;
do {
sta[++top] = x % 10;
x /= 10;
} while(x);
while (top) {
putchar(sta[top--] ^ 48);
}
putchar(ed);
}
const int MAXN = 5000;
int n;
int p[MAXN], q[MAXN], s[MAXN];
int ans;
int main() {
freopen("swap.in", "r", stdin);
freopen("swap.out", "w", stdout);
read(n);
for (int i = 0; i <= n - 1; ++i) {
read(p[i]);
q[i] = i;
}
do {
for (int i = 0; i <= n - 1; ++i) s[i] = i;
for (int i = 0; i <= n - 2; ++i) swap(s[q[i]], s[q[i] + 1]);
bool ok = true;
for (int i = 0; i <= n - 1; ++i) if (s[i] != p[i]) {
ok = false;
break;
}
if (ok) ans++;
} while (next_permutation(q, q + n - 1));
write(ans, '\n');
return 0;
}