input: from typing import List
  
  def min_operations_to_all_ones(nums: List[int]) -> int:
      """
      You are given a binary array nums.
  
      You can do the following operation on the array any number of times (possibly zero):
  
      Choose any 3 consecutive elements from the array and flip all of them.
      Flipping an element means changing its value from 0 to 1, and from 1 to 0.
  
      Return the minimum number of operations required to make all elements in nums equal to 1. If it is impossible, return -1.
  
      Examples:
      >>> nums = [0,1,1,1,0,0]
      3
      >>> nums = [0,1,1,1]
      -1
  
      Constraints:
      3 <= nums.length <= 10^5
      0 <= nums[i] <= 1
      """
  
output: 
      n = len(nums)
      if n < 3:
          return -1
      
      operations = 0
      i = 0
      while i <= n - 3:
          if nums[i] == 0 and nums[i+1] == 0 and nums[i+2] == 0:
              operations += 1
              nums[i] = 1
              nums[i+1] = 1
              nums[i+2] = 1
          elif nums[i] == 0 and nums[i+1] == 1 and nums[i+2] == 1:
              operations += 1
              nums[i] = 1
              nums[i+1] = 0
              nums[i+2] = 0
          elif nums[i] == 1 and nums[i+1] == 0 and nums[i+2] == 1:
              operations += 1
              nums[i] = 0
              nums[i+1] = 1
              nums[i+2] = 0
          elif nums[i] == 1 and nums[i+1] == 1 and nums[i+2] == 0:
              operations += 1
              nums[i] = 0
              nums[i+1] = 0
              nums[i+2] = 1
          i += 1
      
      if all(num == 1 for num in nums):
          return operations
      else:
          return -1
  