def count_orbits(orbits, cur_object, cur_orbit):
    """Count direct and indirect orbits, starting from cur_object."""
    if not orbits[cur_object]:
        return cur_orbit
    return sum(count_orbits(orbits, next_object, cur_orbit + 1)
               for next_object in orbits[cur_object]) + cur_orbit