You and your friend are playing the game Mortal Kombat XI. You are trying to pass a challenge tower. There are $n$ bosses in this tower, numbered from $1$ to $n$. The type of the $i$-th boss is $a_i$. If the $i$-th boss is easy then its type is $a_i = 0$, otherwise this boss is hard and its type is $a_i = 1$.

During one session, either you or your friend can kill one or two bosses (neither you nor your friend can skip the session, so the minimum number of bosses killed during one session is at least one). After your friend session, your session begins, then again your friend session begins, your session begins, and so on. The first session is your friend's session.

Your friend needs to get good because he can't actually kill hard bosses. To kill them, he uses skip points. One skip point can be used to kill one hard boss.

Your task is to find the minimum number of skip points your friend needs to use so you and your friend kill all $n$ bosses in the given order.

For example: suppose $n = 8$, $a = [1, 0, 1, 1, 0, 1, 1, 1]$. Then the best course of action is the following:

  your friend kills two first bosses, using one skip point for the first boss;  you kill the third and the fourth bosses;  your friend kills the fifth boss;  you kill the sixth and the seventh bosses;  your friend kills the last boss, using one skip point, so the tower is completed using two skip points. 

You have to answer $t$ independent test cases.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow.

The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of bosses. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 1$), where $a_i$ is the type of the $i$-th boss.

It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).


-----Output-----

For each test case, print the answer: the minimum number of skip points your friend needs to use so you and your friend kill all $n$ bosses in the given order.


-----Example-----
Input
6
8
1 0 1 1 0 1 1 1
5
1 1 1 1 0
7
1 1 1 1 0 0 1
6
1 1 1 1 1 1
1
1
1
0

Output
2
2
2
2
1
0

Difficulty: interview

Starter code:

Solutions:
import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
import sys
letters = ascii_letters
input = stdin.readline
#print = stdout.write

for _ in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))
    ans = [999999999] * n
    ans[0] = 1 if arr[0] == 1 else 0
    if n > 1:
        ans[1] = ans[0]
        if n > 2:
            ans[2] = ans[0]
    for i in range(n):
        if i + 1 >= n:
            continue
        if arr[i + 1] == 1:
            ans[i + 1] = min(ans[i + 1], ans[i] + 1)
            if i + 2 < n:
                ans[i + 2] = min(ans[i + 2], ans[i] + 1)
            if i + 3 < n: 
                ans[i + 3] = min(ans[i + 3], ans[i] + 1)
        else:
            ans[i + 1] = min(ans[i + 1], ans[i])
            if i + 2 < n:
                ans[i + 2] = min(ans[i + 2], ans[i])
            if i + 3 < n:
                ans[i + 3] = min(ans[i + 3], ans[i])
    print(ans[-1])


INF = 10**6

t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))

    out = [0] * (n + 1)

    for i in range(1, n + 1):
        best = INF
        if i >= 2:
            best = min(best, a[i-2] + out[i-2])
        if i >= 3:
            best = min(best, a[i-3] + out[i-3])
        if i >= 4:
            best = min(best, a[i-4] + a[i-3] + out[i-4])
        out[i] = best

    fin = out[n]
    for i in range(1,4):
        if i <= n:
            fin = min(fin, out[n-i] + a[n-i])
    print(fin)


for _ in range(int(input())):
    n = int(input())
    *difficulty, = list(map(int, input().split()))
    groups = [0]
    for i, v in enumerate(difficulty):
        if v == 0 and (i == 0 or difficulty[i - 1] == 1):
            groups.append(0)
        if v == 1:
            groups[-1] += 1
    ans = (groups[0] + 2) // 3 + sum(v // 3 for v in groups[1:])
    print(ans)





def solve():
    n = int(input())
    lst = list(map(int,input().split()))
    if n == 1:
        print(lst[0])
        return 0
    dpi = [-1 for i in range(n)]
    dpdrug = [-1 for i in range(n)]
    dpi[n-1] = 0
    dpdrug[n-1] = lst[n-1]
    dpi[n-2] = 0
    dpdrug[n-2] = lst[n-2]
    for i in range(n-3,-1,-1):
        dpi[i] = min(dpdrug[i + 2], dpdrug[i + 1])
        dpdrug[i] = min(dpi[i + 1] + lst[i], dpi[i + 2] + lst[i] + lst[i + 1])
    print(dpdrug[0])
for i in range(int(input())):
    solve()

for haaghfj in range(int(input())):
    n = int(input())
    a = list(map(int,input().split()))
    dp = [[100000000000000] * 2 for i in range(n + 2)]
    dp[0][0] = 0
    for i in range(1, n + 1):
        dp[i][0] = min(dp[i -1][1], dp[i - 2][1])
        dp[i][1] = min(dp[i -1][0]  + a[i - 1], dp[i - 2][0]  + a[i - 1] + a[i - 2])
    print(min(dp[n]))


import sys
input = lambda: sys.stdin.readline().rstrip()

T = int(input())
for _ in range(T):
    N = int(input())
    A = [int(a) for a in input().split()] + [0] * 5
    X = [0] + [1 << 30] * (N + 5)
    for i in range(2, N + 5):
        X[i] = min(X[i], X[i-2] + A[i-2])
        if i >= 3:
            X[i] = min(X[i], X[i-3] + A[i-3])
        if i >= 4:
            X[i] = min(X[i], X[i-4] + A[i-4] + A[i-3])
    print(min(X[-5:]))



import sys
input = sys.stdin.readline

t=int(input())
for tests in range(t):
    n=int(input())
    A=list(map(int,input().split()))
    A.append(0)
    A.append(0)

    DP0=[1<<30]*(n+3)
    DP1=[1<<30]*(n+3)

    DP0[0]=0

    for i in range(n):
        if A[i]==0 and A[i+1]==0:
            DP1[i+1]=min(DP1[i+1],DP0[i])
            DP1[i+2]=min(DP1[i+2],DP0[i])

        elif A[i]==0 and A[i+1]==1:
            DP1[i+1]=min(DP1[i+1],DP0[i])
            DP1[i+2]=min(DP1[i+2],DP0[i]+1)

        elif A[i]==1 and A[i+1]==0:
            DP1[i+1]=min(DP1[i+1],DP0[i]+1)
            DP1[i+2]=min(DP1[i+2],DP0[i]+1)

        elif A[i]==1 and A[i+1]==1:
            DP1[i+1]=min(DP1[i+1],DP0[i]+1)
            DP1[i+2]=min(DP1[i+2],DP0[i]+2)

        DP0[i+1]=min(DP0[i+1],DP1[i])
        DP0[i+2]=min(DP0[i+2],DP1[i])

    print(min(DP0[n],DP1[n]))

    

    

    
    
    


from math import ceil

def main():
    t = int(input())
    for i in range(t):
        n = int(input())
        enemies = list(map(int, input().split()))
        j = 0
        c = 1
        ans = 0
        while j < n:
            if c:
                c = 0
                if enemies[j] == 1:
                    ans += 1
                    j += 1
                if j < n and enemies[j] == 0:
                    j += 1
            else:
                c = 1
                if enemies[j] == 1:
                    j += 1
                if j < n and enemies[j] == 1:
                    j += 1
        print(ans)


main()

from sys import stdin
t = int(stdin.readline())

for loop in range(t):

    n = int(stdin.readline())
    a = list(map(int,stdin.readline().split()))

    dp = [[float("inf"),float("inf")] for i in range(n)]

    for i in range(n):

        if i == 0:
            dp[i][0] = a[0]
            continue
        elif i == 1:
            dp[i][0] = a[0] + a[1]
            dp[i][1] = dp[i-1][0]
            continue

        dp[i][0] = min(dp[i-2][1] + a[i-1] + a[i] , dp[i-1][1] + a[i])
        dp[i][1] = min(dp[i-2][0] , dp[i-1][0])

    print (min(dp[-1]))