#QHD0000034. Những ngày nghỉ (Vacations)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Những ngày nghỉ (Vacations)
Vacations
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Vasya has 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 describes day : — neither activity available; — contest only; — gym only; — 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 , the number of days.
The second line contains integers describing activity availability for each day.
Output
Print the minimum number of rest days.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
4
1 3 2 0
Output
2
Explanation
Day offers a contest, day both activities, day a gym, and day neither. Contest–rest–gym–rest is valid and has two rest days. Only one rest day is impossible because day is forced rest and all three earlier days cannot be active without repeating an activity consecutively.