input: from bisect import bisect_left
  from typing import List
  
  def identify_beautiful_indices(s: str, a: str, b: str, k: int) -> List[int]:
      """
      Given a 0-indexed string s, along with strings a, b, and an integer k, find beautiful indices.
  
      We define an index i as beautiful if:
  
      0 <= i <= len(s) - len(a)
      s[i..(i + len(a) - 1)] == a
      There exists an index j such that:
      0 <= j <= len(s) - len(b)
      s[j..(j + len(b) - 1)] == b
      |j - i| <= k
      Return a sorted array containing all beautiful indices in ascending order.
  
      Examples:
      >>> s = "isawsquirrelnearmysquirrelhouseohmy", a = "my", b = "squirrel", k = 15
      [16,33]
      >>> s = "abcd", a = "a", b = "a", k = 4
      [0]
  
      Constraints:
      1 <= k <= len(s) <= 10^5
      1 <= len(a), len(b) <= 10
      s, a, and b are composed solely of lowercase English letters.
      """
output:     len_a, len_b = len(a), len(b)
      beautiful_indices = []
      
      # Find all start indices where substring a occurs in s
      start_indices_a = [i for i in range(len(s) - len_a + 1) if s[i:i + len_a] == a]
      
      # Find all start indices where substring b occurs in s
      start_indices_b = [i for i in range(len(s) - len_b + 1) if s[i:i + len_b] == b]
      
      for i in start_indices_a:
          # For each index i in start_indices_a, we need to find if there is any index j in start_indices_b such that |j - i| <= k
          min_j = max(0, i - k)
          max_j = min(len(s) - len_b, i + k)
  
          # Apply binary search to find position of min_j and max_j in start_indices_b
          left = bisect_left(start_indices_b, min_j)
          right = bisect_left(start_indices_b, max_j + 1) # right is exclusive
  
          if left < right:
              beautiful_indices.append(i)
      
      return sorted(beautiful_indices)