from typing import Tuple
from typing import Optional
import math


def determine_direction(pa : Tuple[int, int], pb : Tuple[int, int]) -> Optional[str]:
    """
    Determines which compass direction coord pb is from pa.
    This would normally be easy, but guess which idiot made everything work in
    eight compass directions instead of four? (Me, that's who.)
    Also, we have an extra fun bonus: the world has top left being (0, 0).
    Also also, Python's angles are -pi to pi, where 0 is East.
    To solve this, we define regions where each of the four starting directions
    should be present, which are annotated.
    Simple idea: ±pi/8 and ±7pi/8 are the points where a vector is closer to
    E/W than NE/NW/SE/SW, and ±3pi/8 and ±5pi/8 are then points where a vector
    is closer to N/S than NE/NW/SE/SW.
    """
    (ax, ay) = pa
    (bx, by) = pb

    if by - ay == 0 and bx - ax == 0:
        return None

    angle = math.atan2(by - ay, bx - ax)
    y_val = ""
    # It's northern if the angle is between -7pi/8 and -pi/8.
    if -7*math.pi / 8 <= angle <= -math.pi / 8:
        y_val = "n"
    # Southern case is similar: between pi/8 and 7pi/8.
    if 7*math.pi / 8 >= angle >= math.pi / 8:
        y_val = "s"
    x_val = ""
    # Western if the absolute of the angle is larger than 5pi/8.
    if abs(angle) > 5*math.pi / 8:
        x_val = "w"
    # Eastern if the absolute is less than 3pi/8.
    if abs(angle) < 3*math.pi / 8:
        x_val = "e"
    return y_val + x_val