from typing import Tuple


def get_local_coords(coords2d: list, lx: int, ly: int, x_size: int, y_size: int) -> Tuple[int, int]:
    """
    Computes the grid sizes for each process. If lx//x_size or ly//y_size are not integers, we extend the last process
    in the respective direction, e.g. the rightmost or topmost processes.

    Args:
        coords2d: process coordinates given the cartesian topology
        lx: lattice grid size in x direction
        ly: lattice grid size in y direction
        x_size: number of process in x direction
        y_size: number of process in y direction

    Returns:
        local grid size in x direction, local grid size in y direction

    """
    n_local_x = lx // x_size
    n_local_y = ly // y_size

    if coords2d[0] + 1 == x_size:
        n_local_x = lx - n_local_x * (x_size - 1)

    if coords2d[1] + 1 == y_size:
        n_local_y = ly - n_local_y * (y_size - 1)

    return int(n_local_x), int(n_local_y)