---
# System prepended metadata

title: f072 家裡的後花園 (Garden)

---

# f072 家裡的後花園 (Garden)
## 題目連結:[f072](https://zerojudge.tw/ShowProblem?problemid=f072)

## 解題想法
* 首先，只保留欄杆裡的資料，去頭去尾
* 接著把9的前後有0都加到`cant_grow`裡面
    值得注意的是:
        1. 要判斷邊緣
        2. 要注意是不是有兩個9夾住一個0

## 程式碼
```python=
num = int(input())
data = [int(i) for i in input().split()]

try:
    data = data[data.index(1):]
    data.reverse()
    data = data[data.index(1):]

    cant_grow = 0
    for i in range(len(data)):
        if data[i] == 9 and data[i-1] == 0 and (i-2 < 0 or data[i-2] != 9): cant_grow += 1
        if data[i] == 9 and data[i+1] == 0: cant_grow += 1

    print(data.count(0)- cant_grow)
except:
    print(0)
