PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#QHD0000034. Những ngày nghỉ (Vacations)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Những ngày nghỉ (Vacations)

Vacations

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Vasya has nn vacation days and wants to minimize idle days. On each day he can rest, attend a contest, or go to the gym, subject to that day’s available activities.

Value aia_i describes day ii: 00 — neither activity available; 11 — contest only; 22 — gym only; 33 — both contest and gym. Vasya cannot attend contests on two consecutive days, and cannot go to the gym on two consecutive days. Resting is always allowed.

Find the minimum number of rest days.

Input

The first line contains nn, the number of days.

The second line contains nn integers describing activity availability for each day.

Output

Print the minimum number of rest days.

Subtasks

  • Subtask 1 (20 points): 1≤n≤151\le n\le 15; 0≤ai≤30\le a_i\le 3.
  • Subtask 2 (30 points): 1≤n≤501\le n\le 50; 0≤ai≤30\le a_i\le 3.
  • Subtask 3 (50 points): 1≤n≤1001\le n\le 100; 0≤ai≤30\le a_i\le 3.

Examples

Input

4
1 3 2 0

Output

2

Explanation

Day 11 offers a contest, day 22 both activities, day 33 a gym, and day 44 neither. Contest–rest–gym–rest is valid and has two rest days. Only one rest day is impossible because day 44 is forced rest and all three earlier days cannot be active without repeating an activity consecutively.