Preparando MOJI
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 \le n \le 2 \cdot 10^5$$$).
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 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: