from typing import Tuple


def position(x: int, y: int, n: int) -> Tuple[int, int]:
    """
    D8 position in array

    Returns the position in an array based on the D8 directions.

    +---+---+---+
    | 7 | 8 | 1 |
    +---+---+---+
    | 6 | 0 | 2 |
    +---+---+---+
    | 5 | 4 | 3 |
    +---+---+---+

    Parameters
    ----------
    x : int
        Coord x of origin.
    y : int
        Coord y of origin.
    n : int
        D8 direction.

    Returns
    -------
    Tuple[int, int]
        Index of D8 direction.

    """

    pos = [
        (y, x),  # 0
        (y + 1, x + 1),  # 1
        (y, x + 1),  # 2
        (y - 1, x + 1),  # 3
        (y - 1, x),  # 4
        (y - 1, x - 1),  # 5
        (y, x - 1),  # 6
        (y + 1, x - 1),  # 7
        (y + 1, x),  # 8
    ]
    pos_n = pos[n]
    return pos_n