input: Write a function that returns the least number of operations required to convert a binary array so that all elements are 1. Operations consist of selecting any 3 consecutive elements and flipping each one’s value from 0 to 1 or 1 to 0. If it's unachievable, return -1.
  
  from typing import List
  
  def transform_to_all_ones(arr: List[int]) -> int:
      """
      Given a binary array 'arr'.
  
      Perform the following operation any number of times (including zero):
  
      Select any 3 consecutive elements and flip each of them.
      Flipping changes values from 0 to 1 and vice versa.
  
      Return the minimum number of operations to make every element in 'arr' equal to 1. Return -1 if it cannot be done.
  
      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: def transform_to_all_ones(arr: List[int]) -> int:
      n = len(arr)
      operations = 0
      
      for i in range(n - 2):
          if arr[i] == 0:
              operations += 1
              arr[i] = 1
              arr[i + 1] = 1 if arr[i + 1] == 0 else 0
              arr[i + 2] = 1 if arr[i + 2] == 0 else 0
      
      for i in range(n - 2, n):
          if arr[i] == 0:
              return -1
      
      return operations