Problem p03952 (python)

Fixed submission:
n, x = map(int,input().split())
ans = [-1]*(2*n - 1)
if x == 1 or x == 2*n - 1:
    print('No')
else:
    if n == 2:
        if x == 3:
            print('No')
        else:
            print('Yes')
            print('1\n2\n3')
    else:
        print('Yes')
        t = 0
        if x == 2:
            ans[n - 3] = 4
            ans[n - 2] = 1
            ans[n - 1] = 2
            ans[n] = 3
            t, i = 1, 0
            for rep in range(10**6):
                if i >= 2*n - 1:
                    break
                if ans[i] == -1:
                    if t > 4:
                        ans[i] = t
                        i += 1
                    t += 1 
                else:
                    i += 1
        else:
            ans[n - 3] = x - 2
            ans[n - 2] = x + 1
            ans[n - 1] = x
            ans[n] = x - 1
            t, i = 1, 0
            for rep in range(10**6):
                if i >= 2*n - 1:
                    break
                if ans[i] == -1:
                    if t < x - 2 or t > x + 1:
                        ans[i] = t
                        i += 1
                    t += 1 
                else:
                    i += 1

        for i in ans:
            print(i)

Buggy submission (verdict: Runtime Error):
n, x = map(int,input().split())
ans = [-1]*(2*n - 1)
if x == 1 or x == 2*n - 1:
    print('No')
else:
    if n == 3:
        if x == 3:
            print('No')
        else:
            print(1 + '¥n' + 2 + '¥n' + 3)
    else:
        print('Yes')
        t = 0
        if x == 2:
            ans[n - 3] = 4
            ans[n - 2] = 1
            ans[n - 1] = 2
            ans[n] = 3
            t, i = 1, 0
            for rep in range(10**6):
                if i >= 2*n - 1:
                    break
                if ans[i] == -1:
                    if t > 4:
                        ans[i] = t
                        i += 1
                    t += 1 
                else:
                    i += 1
        else:
            ans[n - 3] = x - 2
            ans[n - 2] = x + 1
            ans[n - 1] = x
            ans[n] = x - 1
            t, i = 1, 0
            for rep in range(10**6):
                if i >= 2*n - 1:
                    break
                if ans[i] == -1:
                    if t < x - 2 or t > x + 1:
                        ans[i] = t
                        i += 1
                    t += 1 
                else:
                    i += 1

        for i in ans:
            print(i)

Buggy submission (verdict: Runtime Error):
n, x = map(int,input().split())
ans = [-1]*(2*n - 1)
if x == 1 or x == 2*n - 1:
    print('No')
else:
    if n == 3:
        if x == 3:
            print('No')
        else:
            print(1 + '¥n' + 2 + '¥n' + 3)
    else:
        print('Yes')
        t = 0
        if x == 2:
            ans[n - 3] = 4
            ans[n - 2] = 1
            ans[n - 1] = 2
            ans[n] = 3
            t, i = 1, 0
            for rep in range(10**6):
                if i >= 2*n - 1:
                    break
                if ans[i] == -1:
                    if t < x - 2 or t > x + 1:
                        ans[i] = t
                        i += 1
                    t += 1 
                else:
                    i += 1
            for i in range(1,2*n):
                if ans[t] == -1 and i > 5:
                    ans[t] = i
                    t += 1
        else:
            ans[n - 3] = x - 2
            ans[n - 2] = x + 1
            ans[n - 1] = x
            ans[n] = x - 1
            t, i = 1, 0
            for rep in range(10**6):
                if i >= 2*n - 1:
                    break
                if ans[i] == -1:
                    if t < x - 2 or t > x + 1:
                        ans[i] = t
                        i += 1
                    t += 1 
                else:
                    i += 1

        for i in ans:
            print(i)