from typing import List


def encode(obs: List[int], spaces: List[int]) -> int:
    """
    Encode an observation from a list of gym.Discrete spaces in one number.
    :param obs: an observation belonging to the state space (a list of gym.Discrete spaces)
    :param spaces: the list of gym.Discrete spaces from where the observation is observed.
    :return: the encoded observation.
    """
    assert len(obs) == len(spaces)
    sizes = spaces
    result = obs[0]
    shift = sizes[0]
    for o, size in list(zip(obs, sizes))[1:]:
        result += o * shift
        shift *= size

    return result