def METHOD_NAME(x, y, n_out, sampled_x, offset):
    a = 0
    for i in range(n_out - 3):
        o0, o1, o2 = offset[i], offset[i + 1], offset[i + 2]
        a = (
            _argmax_area(
                x[a],
                y[a],
                x[o1:o2].mean(),
                y[o1:o2].mean(),
                x[o0:o1],
                y[o0:o1],
            )
            + offset[i]
        )
        sampled_x[i + 1] = a
    # ------------ EDGE CASE ------------
    # next-average of last bucket = last point
    sampled_x[-2] = (
        _argmax_area(
            x[a],
            y[a],
            x[-1],  # last point
            y[-1],
            x[offset[-2] : offset[-1]],
            y[offset[-2] : offset[-1]],
        )
        + offset[-2]
    )