# Python's slices of lists and strings, their bounds kept within the length as Python keeps
# them, and starred unpacking



def total(xs: list[int]) -> int:
    t = 0
    for x in xs:
        if t < 1000 and x < 1000 and x > -1000 and t > -1000:
            t += x
    return t


def main() -> None:
    xs: list[int] = [10, 20, 30, 40, 50]
    ys = xs[1:3]
    print(len(ys), ys[0], ys[1])
    zs: list[int] = xs[-2:]
    print(len(zs), zs[0])
    print(total(xs[:2]), total(xs[3:100]), total(xs[4:1]))
    s = "hello world"
    print(s[0:5], s[6:], s[-5:], s[:-6], s[20:])
    head, *rest = xs
    print(head, len(rest))
    first, *_ = xs
    *init, last = xs
    print(first, last, len(init))


if __name__ == "__main__":
    main()
