# A. Vacations

Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:

- on this day the gym is closed and the contest is not carried out;
- on this day the gym is closed and the contest is carried out;
- on this day the gym is open and the contest is not carried out;
- on this day the gym is open and the contest is carried out.

On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).

Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.

#### Input

The first line contains a positive integer *n* (1 ≤ *n* ≤ 100) — the number of days of Vasya’s vacations.

The second line contains the sequence of integers *a*_{1}, *a*_{2}, …, *a*_{n} (0 ≤ *a*_{i} ≤ 3) separated by space, where:

*a*_{i}equals 0, if on the*i*-th day of vacations the gym is closed and the contest is not carried out;*a*_{i}equals 1, if on the*i*-th day of vacations the gym is closed, but the contest is carried out;*a*_{i}equals 2, if on the*i*-th day of vacations the gym is open and the contest is not carried out;*a*_{i}equals 3, if on the*i*-th day of vacations the gym is open and the contest is carried out.

#### Output

Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:

- to do sport on any two consecutive days,
- to write the contest on any two consecutive days.

#### Examples

###### input

1 2 |
4 1 3 2 0 |

###### output

1 |
2 |

###### input

1 2 |
7 1 3 3 2 1 2 3 |

###### output

1 |

###### input

1 2 |
2 2 2 |

###### output

1 |
1 |

#### Note

In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.

In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.

In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.

每天存在四种情况，既可以比赛又可以锻炼/仅可以比赛/仅可以锻炼/既不可以比赛也不可以锻炼

因此每天有三种状态——锻炼/比赛/休息。

因此分别记录这一天三种状态的最小休息天数，运用动态规划求解。

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <istream> #define forr(a,b,c) for(int a=b;a<=c;a++) #define MAX(a,b) (a>b)?a:b; #define MIN(a,b) (a<b)?a:b; #define MINN(a,b,c) ((a<b)?a:b)<c?((a<b)?a:b):c; #define memsett(a) memset(a,sizeof(a),0); int a[200], b[200],c[200]; using namespace std; int main() { int n; scanf("%d", &n); forr(i, 1, n) { a[i] = b[i] = 100000; c[i] = c[i - 1] + 1; } int m; forr(i, 1, n) { scanf("%d",&m); if (m == 1 || m == 3) a[i] = MIN( b[i-1], c[i-1]); if (m == 2 || m == 3) b[i] = MIN(a[i - 1], c[i-1]); c[i] = MIN(a[i - 1] + 1, b[i - 1] + 1); c[i] = MIN(c[i], c[i - 1] + 1); } int pr; pr = MIN(a[n], b[n]); pr = MIN(pr, c[n]); printf("%d", pr); } |