시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 512 MB 0 0 0 0.000%

문제

Given a permutation of n elements (1, 2, ..., n): A = (a1, a2, . . . , an). We define a sequence P(A) = (p1, p2, . . . , pn−1) where pi = 0 if ai > ai+1 and pi = 1 if ai < ai+1. Given a permutation B, find the number of all permutations C where P(C) = P(B) including the permutation B itself.

입력

The input text file contains several tests, each on a separate line. The first number in the test is n (0 < n ≤ 1024) followed by n numbers representing the permutation all of them separated by a single space. The last line in the input contains only 0 and should not be processed.

출력

The output should be written on the standard output. For each line in the input (excluding the last one, 0) you should write the result i.e. the number of the permutations having the same value for P(A) when given the permutation A.

You may assume the result is less than 232.

예제 입력 1

2 1 2
4 1 3 2 4
0

예제 출력 1

1
5