L=int(eval(input()))

A=[int(eval(input())) for _ in range(L)]



INF=2*L



dp=[[INF for _ in range(5)] for _ in range(L+1)]



for j in range(5):

    dp[0][j]=0



for i in range(1,L+1):

    a=A[i-1]



    if A[i-1]==0:

        o=2

    else:

        o=A[i-1]%2



    e=(A[i-1]+1)%2





    dp[i][0]=dp[i-1][0]+a

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

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

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

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



print((min(dp[L])))
L=int(eval(input()))

A=[int(eval(input())) for _ in range(L)]

dp=[0 for _ in range(5)]



for i in range(1,L+1):

    a=A[i-1]

    back = a%2 if a>0 else 2

    through = (a+1)%2



    dp[4] = min(dp[0:5]) + a

    dp[3] = min(dp[0:4]) + back

    dp[2] = min(dp[0:3]) + through

    dp[1] = min(dp[0:2]) + back

    dp[0]=dp[0]+a



print((min(dp)))
L = int(eval(input()))
A = [int(eval(input())) for _ in range(L)]
INF = 2 * L
dp = [[INF for _ in range(5)] for _ in range(L + 1)]
for j in range(5):
    dp[0][j] = 0
for i in range(1, L + 1):
    a = A[i - 1]
    if A[i - 1] == 0:
        o = 2
    else:
        o = A[i - 1] % 2
    e = (A[i - 1] + 1) % 2
    dp[i][0] = dp[i - 1][0] + a
    dp[i][1] = min(dp[i - 1][0] + o, dp[i - 1][1] + o)
    dp[i][2] = min(dp[i - 1][0] + e, dp[i - 1][1] + e, dp[i - 1][2] + e)
    dp[i][3] = min(
        dp[i - 1][0] + o, dp[i - 1][1] + o, dp[i - 1][2] + o, dp[i - 1][3] + o
    )
    dp[i][4] = min(
        dp[i - 1][0] + a,
        dp[i - 1][1] + a,
        dp[i - 1][2] + a,
        dp[i - 1][3] + a,
        dp[i - 1][4] + a,
    )
print((min(dp[L])))

L = int(eval(input()))
A = [int(eval(input())) for _ in range(L)]
dp = [0 for _ in range(5)]
for i in range(1, L + 1):
    a = A[i - 1]
    back = a % 2 if a > 0 else 2
    through = (a + 1) % 2
    dp[4] = min(dp[0:5]) + a
    dp[3] = min(dp[0:4]) + back
    dp[2] = min(dp[0:3]) + through
    dp[1] = min(dp[0:2]) + back
    dp[0] = dp[0] + a
print((min(dp)))

-INF = 2 * L -dp = [[INF for _ in range(5)] for _ in range(L + 1)] -for j in range(5): -    dp[0][j] = 0 +dp = [0 for _ in range(5)] -    if A[i - 1] == 0: -        o = 2 -    else: -        o = A[i - 1] % 2 -    e = (A[i - 1] + 1) % 2 -    dp[i][0] = dp[i - 1][0] + a -    dp[i][1] = min(dp[i - 1][0] + o, dp[i - 1][1] + o) -    dp[i][2] = min(dp[i - 1][0] + e, dp[i - 1][1] + e, dp[i - 1][2] + e) -    dp[i][3] = min( -        dp[i - 1][0] + o, dp[i - 1][1] + o, dp[i - 1][2] + o, dp[i - 1][3] + o -    ) -    dp[i][4] = min( -        dp[i - 1][0] + a, -        dp[i - 1][1] + a, -        dp[i - 1][2] + a, -        dp[i - 1][3] + a, -        dp[i - 1][4] + a, -    ) -print((min(dp[L]))) +    back = a % 2 if a > 0 else 2 +    through = (a + 1) % 2 +    dp[4] = min(dp[0:5]) + a +    dp[3] = min(dp[0:4]) + back +    dp[2] = min(dp[0:3]) + through +    dp[1] = min(dp[0:2]) + back +    dp[0] = dp[0] + a +print((min(dp)))