text: from typing import TypedDict
  
  CELL_PLACEHOLDER = "#"
  
  
  class Cell:    
      def __init__(self, value=CELL_PLACEHOLDER):
          self.value = value
  
  class Grid:
      def __init__(self, size: int):
          self.size = size
          self.indexes = range(self.size)
          self.columns: list[list[Cell]] = []
  
          for x in self.indexes:
              self.columns.append([])
              for y in self.indexes:
                   self.columns[x].append(Cell())
  
      def __paint_cell(self, cell: Cell):
          print(f"|{cell.value}|", end="")
     
      def paint(self):
          for y in reversed(self.indexes):
              for x in self.indexes:
                  self.__paint_cell(self.columns[x][y])
              print()
  
          for x in self.indexes:
              self.__paint_cell(Cell(value="~"))
          print()
          
          for x in self.indexes:
              self.__paint_cell(Cell(value=x))
          print()
      
      def drop_into(self, column: int, value: str):
          # catch invalid selection
          
          for y in self.indexes:
              cell = self.columns[column][y]
              if cell.value == CELL_PLACEHOLDER:
                  cell.value = value
                  return
      
      def contains_win(self, match_length: int) -> bool:
          return self.__contains_horizontal_win(match_length)
          # self.__contains_vertical_win(match_length)
          # self.__contains_diagonal_win(match_length)
  
      def __contains_horizontal_win(self, match_length: int):
          for y in self.indexes:
              longest_match = 1
              for x in self.indexes:
                  i = 1
                  while i < self.size - x:
                      values_match = self.columns[x][y].value == self.columns[x + i][y].value
                      values_are_not_placeholder = (self.columns[x][y].value != CELL_PLACEHOLDER and 
                                                      self.columns[x + i][y].value != CELL_PLACEHOLDER)
                      if values_match and values_are_not_placeholder:
                          longest_match += 1
                      else:
                          longest_match = 1
                      i += 1
  
                      if longest_match >= match_length:
                          return True
  
          return False
  