func divide_evenly(total: Int, groups: Int): Res[Int, Str] {
    if groups <= 0 { ret Res[Int, Str].Err("group count must be positive") }
    if total < 0 { ret Res[Int, Str].Err("total must be nonnegative") }
    if total % groups != 0 { ret Res[Int, Str].Err("cannot divide evenly") }
    ret Res[Int, Str].Val(total / groups)
}
func per_person(total: Int, teams: Int, people: Int): Res[Int, Str] {
    let per_team = divide_evenly(total, teams)?
    let share = divide_evenly(per_team, people)?
    ret Res[Int, Str].Val(share)
}
func report(result: Res[Int, Str]) {
    match result {
        Val(amount) -> print("each person gets {amount}"),
        Err(reason) -> print("cannot share: {reason}"),
    }
}
report(per_person(120, 3, 4))
report(per_person(120, 0, 4))
report(per_person(100, 3, 4))
report(per_person(120, 3, 0))
