input: from typing import List
  
  def minimum_operations_to_all_ones(arr: List[int]) -> int:
      """
      Given a binary list arr, you can perform the following operation on the list any number of times (including zero):
  
      Select any 3 consecutive elements from the list and flip all of them.
      Flipping an element means changing its value from 0 to 1, and from 1 to 0.
  
      Return the least number of operations needed to turn all elements in arr to 1. If it is not achievable, return -1.
  
      Examples:
      >>> arr = [0,1,1,1,0,0]
      3
      >>> arr = [0,1,1,1]
      -1
  
      Constraints:
      3 <= arr.length <= 10^5
      0 <= arr[i] <= 1
      """
output:     
      n = len(arr)
      count = 0
  
      for i in range(n - 2):
          if arr[i] == 0:
              # Flip arr[i], arr[i+1], arr[i+2]
              arr[i] = 1
              arr[i+1] = 1 - arr[i+1]
              arr[i+2] = 1 - arr[i+2]
              count += 1
  
      for i in range(n):
          if arr[i] == 0:
              return -1
  
      return count
  