1)光标上移下移是下标减1加1来实现。边界情况是直接跳到最大值最小值。
2)max是记录着mp3 当前界面最大值。

def helper(cur,n,order):
    max_ = 1
    for s in order:
        if s == 'U' and cur == 1:
            cur = n
        elif s == 'U':
            cur -= 1
        elif s == 'D' and cur == n:
            cur = 1
        elif s == 'D':
            cur += 1
        if n > 4:
            if cur > max_:
                max_ = cur
            if cur < max_ - 3:
                max_ = cur + 3
    return cur, max_
while True:
    try:
        n, order, cur = int(input()), input(), 1   # n = 10  order = UUUU cur = 1
        cur, max_ = helper(cur, n, order)
        ans = range(max_-3, max_+1) if n > 4 else range(1,n+1)
        print(" ".join(map(str,ans)))
        print(cur)
    except:
        break