# Python's built-in exceptions and their hierarchy as Vibe takes them (D188), functions
# that let an exception out (inferred, or declared with `raises(E)`), one that prints and
# returns, and container methods by Python's names. Its output is CPython's.
from verada import raises


class Overdrawn(ValueError):
    pass


def check(n: int) -> int:
    if n < 0:
        raise ValueError("negative")
    if n == 0:
        raise KeyError("zero")
    return n


def withdraw(balance: int, amount: int) -> int:
    raises(Overdrawn)
    if amount > balance:
        raise Overdrawn("short by " + str(amount - balance) if 0 <= amount <= 1000 and 0 <= balance <= 1000 else "short")
    return balance - amount if 0 <= amount <= 1000 and 0 <= balance <= 1000 else 0


def area(w: int, h: int) -> int:
    print("computing", w, h)
    return w * h if 0 <= w <= 100 and 0 <= h <= 100 else 0


def main() -> None:
    for n in [-1, 0, 5]:
        try:
            print("checked", check(n))
        except LookupError as e:
            print("lookup", e)
        except ValueError as e:
            print("value", e)
    try:
        print(withdraw(10, 25))
    except ValueError as e:
        print("caught", e)
    print(area(3, 4) + 1)
    xs: list[int] = [3, 1, 2]
    xs.sort(reverse=True)
    d: dict[str, int] = {"a": 1}
    d.setdefault("q", 7)
    d.setdefault("a", 9)
    d.update({"b": 20})
    e = d.copy()
    s: set[int] = {1, 2}
    t: set[int] = {2, 3}
    print(xs, d["q"], d["a"], len(e), s.issubset(t), sorted(s.union(t)), sorted(s)[0], t.issuperset({3}), s.isdisjoint({7}))


if __name__ == "__main__":
    main()
