def wig_to_bgr1(pos2val):
    """pos2val is dictionary: position: value. position is 0 based """
    point_num = 1
    count = 0
    for pos in sorted(pos2val):
        count += 1
        if count == 1:
            up_bound = pos + 1
            score = pos2val[pos]
            continue
        if pos2val[pos] == score:
            point_num += 1
            up_bound = pos + 1
        else:
            yield up_bound - point_num - 1, up_bound - 1, score
            score = pos2val[pos]
            up_bound = pos + 1
            point_num = 1
