def cims_valls(it):
    a = next(it)
    yield a
    b = next(it)
    for c in it:
        if a < b > c or a > b < c:
            yield b
        a = b
        b = c
    yield c
