Contest Duration: ~ (local time)
F - 575

Time Limit: 2 sec / Memory Limit: 256 MB

### 問題文

• a, b, c を連結した数列は (1, 2, ..., n) の順列である。
• min_i(a_i) < min_i(b_i) < min_i(c_i)
• Σs_{a_i} = 5
• Σs_{b_i} = 7
• Σs_{c_i} = 5

たとえば、数列 ex=(ex_1, ex_2, ex_3, ex_4)=(5, 3, 5, 4) は五七五列ですが、(5, 5, 7) は五七五列ではありません。ex については a=(1), b=(2, 4), c=(3)3 つの数列が五七五列の条件を満たします。

### 制約

• 1 \leq N \leq 100
• 2 \leq x_i \leq 7
• N, x_i は整数である。

N
x_1 x_2 ... x_N

5
2 3 5 4 3

### 出力例1

1

(2, 3, 5, 4, 3) は五七五列です。a=(1, 5), b=(2, 4), c=(3)3 つの数列が五七五列の条件を満たします。

### 入力例2

10
5 6 2 3 5 5 5 7 5 3

### 出力例2

2

まず、x の第 1, 3, 5, 6 項からなる (5, 2, 5, 5) の五七五列が取り除けます。 (5, 2, 5, 5) については、例えば a=(1), b=(2, 4), c=(3)3 つの数列が五七五列の条件を満たします。

x から第 1, 3, 5, 6 項を取り除いた残りの列は (6, 3, 5, 7, 5, 3) となります。 次に、残りの列の第 3, 4, 5 項からなる (5, 7, 5) の五七五列が取り除けます。

5
6 6 6 6 6

0

### 入力例4

9
5 3 2 2 7 3 5 4 3

2

8
5 5 4 3 5 5 4 3

2

### 入力例6

22
2 3 4 5 6 7 6 5 4 3 2 2 3 4 5 6 7 6 5 4 3 2

### 出力例6

3

Score : 200 points

### Problem Statement

A subsequence is a sequence that can be derived from another sequence by deleting some (incuding 0) elements without changing the order of the remaining elements. For example, (4, 2, 1), (7, 4, 3, 2, 1), and (empty) are subsequences of (7, 4, 3, 2, 1), but (1, 2) is not.

A sequence s of length n is called "575-sequence" if there exist numerical sequences a, b, and c that satisfy the following constraints.

• A sequence made by concatenating a, b, and c is a permutation of (1, 2, ..., n).
• min_i(a_i) < min_i(b_i) < min_i(c_i)
• Σs_{a_i} = 5
• Σs_{b_i} = 7
• Σs_{c_i} = 5

For example, ex=(ex_1, ex_2, ex_3, ex_4)=(5, 3, 5, 4) is a 575-sequence, but (5, 5, 7) is not. For ex, a=(1), b=(2, 4), and c=(3) satisfy the above constraints.

You are given a sequence x=(x_1, x_2, ..., x_N) of length N. Each term x_i satisfies 2 \leq x_i \leq 7. How many 575-sequences can you remove one by one from x?

### Constraints

• 1 \leq N \leq 100
• 2 \leq x_i \leq 7
• N, x_i are integers

### Input

Input is given from Standard Input in the following format:

N
x_1 x_2 ... x_N

### Output

Print the maximum number of 575-sequences you can remove from x.

5
2 3 5 4 3

### Sample Output 1

1

(2, 3, 5, 4, 3) is a 575-sequence. a=(1, 5), b=(2, 4), and c=(3) satisfy the constraints of 575-sequence.

### Sample Input 2

10
5 6 2 3 5 5 5 7 5 3

### Sample Output 2

2

Firstly, you can remove a 575-sequence (5, 2, 5, 5), which consists of the first, third, fifth, and sixth terms of x. For (5, 2, 5, 5), for example, a=(1), b=(2, 4), and c=(3) satisfy the constraints.

The remaining sequence, where the first, third, fifth, and sixth terms are removed from x is (6, 3, 5, 7, 5, 3). You can remove a 575-sequence (5, 7, 5), which consists of the third, fourth, and fifth terms of the remaining sequence.

5
6 6 6 6 6

0

### Sample Input 4

9
5 3 2 2 7 3 5 4 3

2

8
5 5 4 3 5 5 4 3

2

### Sample Input 6

22
2 3 4 5 6 7 6 5 4 3 2 2 3 4 5 6 7 6 5 4 3 2

3

KUPC2017