后面改了,贴个代码吧,可惜有一组越界的错误最后才发现少了个-1
import sys
line = sys.stdin.readline()
l = list(map(int, line.strip().split(",")))
index = int(sys.stdin.readline().strip())
x = 0
while True:
    if 2 ** x > len(l):
        break
    x += 1
l2 = [0] * len(l)
down = True
xx = 0
plus = 0
for i in range(len(l)-1):
    if 2**xx+plus-1>=len(l)-1:
        down = False
        xx-=1
        plus += 1
    while 2**xx+plus >= 2**(xx+1):
        if down:
            xx += 1
            if xx == x:
                xx = x-1
                down = False
                plus += 1
        else:
            xx -= 1
            if xx == -1:
                xx = 0
                down = True
                plus += 1
    l2[2**xx+plus-1] = l[i]
    if down:
        xx += 1
        if xx == x:
            xx = x - 1
            down = False
            plus += 1
    else:
        xx -= 1
        if xx == -1:
            xx = 0
            down = True
            plus += 1
l2[2**xx-2] = l[-1]
for i in range(1, len(l2)):
    if l2[i] == index:
        print(l2[i-1])
        sys.exit(0)
print(-1)