import re


def parse_cu_seats(cu_seats):
    """
    Parse the total and available number of seats as well as the
    waitlist length (or null) out of the seats field of a CU course.
    """
    matches = re.findall(r"\d+", cu_seats)
    if "Waitlist" not in cu_seats:
        matches.append(None)
    if "of" in cu_seats:
        matches.pop()
    assert len(matches) == 3, repr(cu_seats)
    seats_total, seats_avail, waitlist_len = matches
    seats_total = int(seats_total)
    seats_avail = seats_total - int(seats_avail)
    if isinstance(waitlist_len, str):
        waitlist_len = int(waitlist_len)
    return seats_total, seats_avail, waitlist_len