input: from typing import List
  
  def minimal_changes_for_y_shape(grid: List[List[int]]) -> int:
      """
      Given an n x n grid with odd n, where each grid[r][c] is 0, 1, or 2, determine the minimum number of changes to form a 'Y' shape.
  
      A cell is part of the 'Y' if it is included in:
  
      The diagonal from the top-left to the center of the grid.
      The diagonal from the top-right to the center of the grid.
      The vertical segment from the center cell to the bottom middle of the grid.
      The 'Y' pattern is correctly formed if:
  
      All 'Y' cells have the same value.
      All non-'Y' cells have the same value.
      'Y' cells have a different value from non-'Y' cells.
      Return the fewest transformations needed where one change can modify any cell to 0, 1, or 2.
  
      Examples:
      >>> grid = [[1,2,2],[1,1,0],[0,1,0]]
      3
      >>> grid = [[0,1,0,1,0],[2,1,0,1,2],[2,2,2,0,1],[2,2,2,2,2],[2,1,2,2,2]]
      12
  
      Constraints:
      3 <= n <= 49
      n == grid.length == grid[i].length
      0 <= grid[i][j] <= 2
      n is odd.
      """
output:     n = len(grid)
      center = n // 2
      y_cells = set()
  
      for i in range(center + 1):
          y_cells.add((i, i))
          y_cells.add((i, n - 1 - i))
      for i in range(center, n):
          y_cells.add((i, center))
  
      min_changes = float('inf')
      for y_val in range(3):
          for non_y_val in range(3):
              if y_val == non_y_val:
                  continue
              changes = 0
              for i in range(n):
                  for j in range(n):
                      if (i, j) in y_cells and grid[i][j] != y_val:
                          changes += 1
                      elif (i, j) not in y_cells and grid[i][j] != non_y_val:
                          changes += 1
              min_changes = min(min_changes, changes)
  
      return min_changes