from typing import Union
from typing import List


def get_corresponding(
    value_or_matrix: Union[int, List[List[int]]], row: int, col: int
) -> int:
    """If `value_or_matrix` is a matrix, extract the value in cell specified by
    `row` and `col`. If `value_or_matrix` is a scalar, just return it.
    """
    if isinstance(value_or_matrix, list):
        assert all(isinstance(x, list) for x in value_or_matrix)
        return value_or_matrix[row][col]
    assert isinstance(value_or_matrix, int)
    return value_or_matrix