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

#QHD0000013. Tháp Mortal Kombat (Mortal Kombat Tower)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tháp Mortal Kombat (Mortal Kombat Tower)

Mortal Kombat Tower

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn monsters in a line, numbered from 11 to nn. Monster ii has type aia_i: ai=0a_i=0 denotes an easy monster and ai=1a_i=1 a hard monster.

You and your friend take turns defeating monsters, with your friend playing first. On a turn, the current player must defeat one or two consecutive remaining monsters, always starting from the leftmost undefeated monster. Turns then alternate.

Your friend spends one skip point for every hard monster (ai=1a_i=1) they defeat. You spend no skip points.

Determine the minimum total number of skip points your friend needs to defeat all nn monsters.

Input

The first line contains nn, the number of monsters.

The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n, each either 00 or 11.

Output

Print one integer: the minimum total number of skip points required.

Subtasks

  • Subtask 1 (20 points): 1≤n≤101\le n\le 10; 0≤ai≤10\le a_i\le 1 (1≤i≤n1\le i\le n).
  • Subtask 2 (30 points): 1≤n≤1001\le n\le 100; 0≤ai≤10\le a_i\le 1 (1≤i≤n1\le i\le n).
  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le 2\cdot10^5; 0≤ai≤10\le a_i\le 1 (1≤i≤n1\le i\le n).

Examples

Input

4
1 1 1 1

Output

2

Explanation

Your friend defeats the first two hard bosses, spending 22 skip points. You defeat the last two bosses at no skip-point cost. The minimum is 22.