You are given an array of n integers, where each integer is either 0, 1, or 2. Initially, each element of the array is blue.
Your goal is to paint each element of the array red. In order to do so, you can perform operations of two types:
What is the minimum number of coins you have to spend to achieve your goal?
The first line contains one integer n (1≤n≤2⋅105).
The second line contains n integers a1,a2,…,an (0≤ai≤2).
Print one integer — the minimum number of coins you have to spend in order to paint all elements red.
3 0 2 0
1
4 0 0 1 1
2
7 0 1 0 0 1 0 2
4
In the first example, you can paint all elements red with having to spend only one coin as follows:
In the second example, you can paint all elements red spending only two coins as follows:
Name |
---|