Supercut
Submit solution
Points:
1
Time limit:
1.0s
Python
1.5s
Memory limit:
256M
Author:
Problem type
Allowed languages
C, C++, Java, Python
You are given an array of length
. You may repeatedly perform the following operation:
- Choose an index
such that
(where
is the current array length), and
.
- Delete these four elements.
After a deletion, the remaining elements are re-indexed from to
.
Find the minimum possible final length of the array if you apply operations in an optimal order.
Input
The first line contains a single integer
.
The second line contains integers
.
Output
Print one integer: the minimum possible length of the array after performing the operation on indices in the optimal ordering.
Example 1
Input
8
1 1 1 1 1 2 3 4
Output
4
Explanation
Delete the first four elements (). The remaining array is
, so no further
deletion is possible.
Example 2
Input
12
1 1 1 1 5 5 5 5 5 5 5 5
Output
0
Explanation
One optimal sequence is:
- Delete the block at indices
.
- The last four
's shift to indices
, so delete them.
- The four
's remain at indices
, so delete them.
The array becomes empty.
Example 3
Input
11
1 1 3 3 3 3 1 1 1 1 1
Output
3
Explanation
Delete the four 's at indices
. The remaining seven elements are all
, so
one more deletion can be performed at index
, leaving three elements.
Comments