Permutation Pattern

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

A sequence $a_1, \dots, a_m$ of $m$ distinct numbers is called *without 231* if there is **no** triples $(i, j, k)$ where $1 \leq i < j < k \leq m$ and $a_k < a_i < a_j$.

Bobo has a permutation $p_1, \dots, p_n$ of $1, \dots, n$, and he can remove some (possibly none, but not all) elements from the permutation. Find the number of sequences without $231$ among $(2^n - 1)$ resulting permutations.

입력

The input consists of several test cases terminated by end-of-file. For each test case,

The first line contains an integer $n$.

The second line contains $n$ integers $p_1, \dots, p_n$.

출력

For each test case, output an integer which denotes the number of sequences.

제한

  • $1 \leq n \leq 50$
  • $1 \leq p_i \leq n$ for each $1 \leq i \leq n$
  • In each input, the sum of $n$ does not exceed $500$.