def solution(S):
    (ans1, ans2) = (0, 0)
    S1 = S.copy()
    S2 = S.copy()
    leng = len(S)
    if (leng == 1):
        return 0
    if (leng == 2):
        if (S[0] != S[1]):
            return 0
        else:
            return 1
    for idx in range(leng):
        if ((idx == 0) or (idx == (leng - 1))):
            continue
        if ((S1[idx] == S1[(idx - 1)]) and (S1[idx] == S1[(idx + 1)])):
            if (S1[idx] == 1):
                S1[idx] = 0
            else:
                S1[idx] = 1
            ans1 += 1
        if ((S1[idx] == S1[(idx - 1)]) and (S1[idx] != S1[(idx + 1)])):
            if (S1[(idx - 1)] == 1):
                S1[(idx - 1)] = 0
            else:
                S1[(idx - 1)] = 1
            ans1 += 1
        if ((S1[idx] != S1[(idx - 1)]) and (S1[idx] == S1[(idx + 1)])):
            if (S1[(idx + 1)] == 1):
                S1[(idx + 1)] = 0
            else:
                S1[(idx + 1)] = 1
            ans1 += 1
    for idx in range((leng - 1), (- 1), (- 1)):
        if ((idx == 0) or (idx == (leng - 1))):
            continue
        if ((S2[idx] == S2[(idx - 1)]) and (S2[idx] == S2[(idx + 1)])):
            if (S2[idx] == 1):
                S2[idx] = 0
            else:
                S2[idx] = 1
            ans2 += 1
        if ((S2[idx] == S2[(idx - 1)]) and (S2[idx] != S2[(idx + 1)])):
            if (S2[(idx - 1)] == 1):
                S2[(idx - 1)] = 0
            else:
                S2[(idx - 1)] = 1
            ans2 += 1
        if ((S2[idx] != S2[(idx - 1)]) and (S2[idx] == S2[(idx + 1)])):
            if (S2[(idx + 1)] == 1):
                S2[(idx + 1)] = 0
            else:
                S2[(idx + 1)] = 1
            ans2 += 1
    return min(ans1, ans2)
def solution(S):
    (ans1, ans2) = (0, 0)
    S1 = S.copy()
    S2 = S.copy()
    leng = len(S)
    if (leng == 1):
        return 0
    if (leng == 2):
        if (S[0] != S[1]):
            return 0
        else:
            return 1
    for idx in range(leng):
        if ((idx == 0) or (idx == (leng - 1))):
            continue
        if ((S1[idx] == S1[(idx - 1)]) and (S1[idx] == S1[(idx + 1)])):
            if (S1[idx] == 1):
                S1[idx] = 0
            else:
                S1[idx] = 1
            ans1 += 1
        if ((S1[idx] == S1[(idx - 1)]) and (S1[idx] != S1[(idx + 1)])):
            if (S1[(idx - 1)] == 1):
                S1[(idx - 1)] = 0
            else:
                S1[(idx - 1)] = 1
            ans1 += 1
        if ((S1[idx] != S1[(idx - 1)]) and (S1[idx] == S1[(idx + 1)])):
            if (S1[(idx + 1)] == 1):
                S1[(idx + 1)] = 0
            else:
                S1[(idx + 1)] = 1
            ans1 += 1
    for idx in range((leng - 1), (- 1), (- 1)):
        if ((idx == 0) or (idx == (leng - 1))):
            continue
        if ((S2[idx] == S2[(idx - 1)]) and (S2[idx] == S2[(idx + 1)])):
            if (S2[idx] == 1):
                S2[idx] = 0
            else:
                S2[idx] = 1
            ans2 += 1
        if ((S2[idx] == S2[(idx - 1)]) and (S2[idx] != S2[(idx + 1)])):
            if (S2[(idx - 1)] == 1):
                S2[(idx - 1)] = 0
            else:
                S2[(idx - 1)] = 1
            ans2 += 1
        if ((S2[idx] != S2[(idx - 1)]) and (S2[idx] == S2[(idx + 1)])):
            if (S2[(idx + 1)] == 1):
                S2[(idx + 1)] = 0
            else:
                S2[(idx + 1)] = 1
            ans2 += 1
    return min(ans1, ans2)