题目描述
Problem Description
For a sequence \( s \), a subsequence of \( s \) is obtained by removing zero or more elements from \( s \) while keeping the remaining elements in their original order. For example, \( (4, 2, 1) \), \( (7, 4, 3, 2, 1) \), and the empty sequence are subsequences of \( (7, 4, 3, 2, 1) \), but \( (1, 2) \) is not a subsequence of \( (7, 4, 3, 2, 1) \).
For a sequence \( s \) of length \( n \), if there exist non-empty sequences \( a \), \( b \), and \( c \) that satisfy the following conditions, the sequence \( s \) is called a 575 sequence:
- The concatenated sequence of \( a \), \( b \), and \( c \) is a permutation of \( (1, 2, ..., n) \).
- \( \min_i(a_i) < \min_i(b_i) < \min_i(c_i) \)
- \( \Sigma s_{a_i} = 5 \)
- \( \Sigma s_{b_i} = 7 \)
- \( \Sigma s_{c_i} = 5 \)
For example, the sequence \( 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 \), the sequences \( a = (1) \), \( b = (2, 4) \), \( c = (3) \) satisfy the conditions of a 575 sequence.
You are given a sequence \( x = (x_1, x_2, ..., x_N) \) where each \( x_i \) satisfies \( 2 \leq x_i \leq 7 \). Determine the maximum number of 575 subsequences that can be removed from the sequence \( x \).
Input Format
The input is given from the standard input in the following format:
\( N \) \( x_1 \) \( x_2 \) \( ... \) \( x_N \)
Output Format
Output the maximum number of 575 subsequences that can be removed in one line.
Sample Input and Output
Sample Input #1
5
2 3 5 4 3
Sample Output #1
1
Sample Input #2
10
5 6 2 3 5 5 5 7 5 3
Sample Output #2
2
Sample Input #3
5
6 6 6 6 6
Sample Output #3
0
Sample Input #4
9
5 3 2 2 7 3 5 4 3
Sample Output #4
2
Sample Input #5
8
5 5 4 3 5 5 4 3
Sample Output #5
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
Sample Output #6
3
Notes/Hints
Constraints
- \( 1 \leq N \leq 100 \)
- \( 2 \leq x_i \leq 7 \)
- \( N \) and \( x_i \) are integers.
Sample Explanation 1
\( (2, 3, 5, 4, 3) \) is a 575 sequence. The sequences \( a = (1, 5) \), \( b = (2, 4) \), \( c = (3) \) satisfy the conditions of a 575 sequence.
Sample Explanation 2
First, the 575 sequence \( (5, 2, 5, 5) \) formed by the 1st, 3rd, 5th, and 6th terms of \( x \) can be removed. For \( (5, 2, 5, 5) \), the sequences \( a = (1) \), \( b = (2, 4) \), \( c = (3) \) satisfy the conditions of a 575 sequence. After removing the 1st, 3rd, 5th, and 6th terms, the remaining sequence is \( (6, 3, 5, 7, 5, 3) \). Next, the 575 sequence \( (5, 7, 5) \) formed by the 3rd, 4th, and 5th terms of the remaining sequence can be removed.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分