def calculate_erosion(coords, depth, target, cave):
    """Return the erosion level of a coordinate."""
    x, y = coords
    if (x, y) == (0, 0):
        return (0 + depth) % 20183
    elif (x, y) == target:
        return (0 + depth) % 20183
    elif y == 0:
        return (x * 16807 + depth) % 20183
    elif x == 0:
        return (y * 48271 + depth) % 20183
    else:
        return (cave[(x-1, y)] * cave[(x, y-1)] + depth) % 20183