Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N, K = list(map(int, input().split()))
    h = []
    for _ in range(N):
        h.append(int(input()))
    ans = 10 ** 18
    h.sort()

    for i in range(N - K + 1):
        res = h[i:K + i]
        ans = min(ans, res[-1] - res[0])
    print(ans)
    return


resolve()

Fixed submission:
def resolve():
    N, K = list(map(int, input().split()))
    h = [int(input()) for _ in range(N)]
    ans = 10 ** 10
    h.sort()

    for i in range(N - K + 1):
        res = h[i+K-1] - h[i]
        ans = min(ans, res)
    print(ans)
    return


resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N, K = list(map(int, input().split()))
    h = [int(input()) for _ in range(N)]
    ans = 10 ** 18
    h.sort()

    for i in range(N - K + 1):
        res = h[i:K + i]
        ans = min(ans, res[-1] - res[0])
    print(ans)
    return


resolve()

Fixed submission:
def resolve():
    N, K = list(map(int, input().split()))
    h = [int(input()) for _ in range(N)]
    ans = 10 ** 10
    h.sort()

    for i in range(N - K + 1):
        res = h[i+K-1] - h[i]
        ans = min(ans, res)
    print(ans)
    return


resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N, K = list(map(int, input().split()))
    h = [int(input()) for _ in range(N)]
    ans = 10 ** 18
    h.sort()

    for i in range(N - K + 1):
        res = h[i:K + i]
        ans = min(ans, res[-1] - res[0])
    print(ans)
    return


resolve()


Fixed submission:
def resolve():
    N, K = list(map(int, input().split()))
    h = [int(input()) for _ in range(N)]
    ans = 10 ** 10
    h.sort()

    for i in range(N - K + 1):
        res = h[i+K-1] - h[i]
        ans = min(ans, res)
    print(ans)
    return


resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N, K = list(map(int, input().split()))
    h = [int(input()) for _ in range(N)]
    ans = 10 ** 18
    h.sort()

    for i in range(N - K + 1):
        ans = min(ans, max(h[i:K + i]) - min(h[i:K + i]))
    print(ans)
    return

resolve()


Fixed submission:
def resolve():
    N, K = list(map(int, input().split()))
    h = [int(input()) for _ in range(N)]
    ans = 10 ** 10
    h.sort()

    for i in range(N - K + 1):
        res = h[i+K-1] - h[i]
        ans = min(ans, res)
    print(ans)
    return


resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    N = int(input())
    ans = 0
    for i in range(1, N+1, 2):
        tmp = make_divisors(i)
        if len(tmp) == 8:
            ans += 1
    print(ans)
    return

resolve()


Fixed submission:
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def resolve():
    N = int(input())
    ans = 0
    for i in range(1, N+1, 2):
        tmp = make_divisors(i)
        if len(tmp) == 8:
            ans += 1
    print(ans)
    return

resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    S = str(input())
    K = int(input())
    idx = S.find('1')

    if idx == -1:
        print(S[0])
        return
    else:
        if idx <= K:
            print(S[idx+1])
        else:
            print(S[0])
    return

resolve()


Fixed submission:
def resolve():
    S = str(input())
    K = int(input())

    if S[0] != '1':
        print(S[0])
        return
    else:
        for i in range(1, K):
            if S[i] != '1':
                print(S[i])
                return
            else:
                continue
        print('1')

    return

resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    N = int(input())
    a = list(map(int, input().split()))
    ans = 0
    for i in a:
        ans += prime_factorize(i).count(2)

    print(ans)

    return

resolve()

Fixed submission:
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def resolve():
    N = int(input())
    a = list(map(int, input().split()))
    ans = 0
    for i in a:
        ans += prime_factorize(i).count(2)

    print(ans)

    return

resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    A, B, C, K = list(map(int, input().split()))
    if A + B >= K:
        print(A)
    else:
        print(A-(K - A - B))

    return


resolve()


Fixed submission:
def resolve():
    N = int(input())
    s = [input() for _ in range(N)]
    M = int(input())
    t = [input() for _ in range(M)]
    sdict = {k: 0 for k in set(s)}
    tdict = {k: 0 for k in set(t)}
    for w in s:
        sdict[w] += 1
    for w in t:
        tdict[w] += 1
    ks = set(s) | set(t)
    ans = 0
    for key in ks:
        ans = max(ans, sdict.get(key, 0) - tdict.get(key, 0))

    print(ans)

    return
resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 10**5
    for a in A:
        a = prime_factorize(a)
        ans = min(ans, a.count(2))
    if (ans == 10 ** 5):
        ans = 0
    print(ans)
    return


resolve()

Fixed submission:
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 10**5
    for a in A:
        a = prime_factorize(a)
        ans = min(ans, a.count(2))
    if (ans == 10 ** 5):
        ans = 0
    print(ans)
    return


resolve()
Buggy python submission (verdict: Runtime Error):
N = int(input())
T = [int(input()) for i in range(N)]

import fractions
def lcm(a, b):
    if gcd != 0:
        return (a * b) // gcd
    else:
        return 0

gcd = 1
x = 0

for i in range(N):
    for j in range(N):
        gcd = int(fractions.gcd(T[i] , T[j]))
        x = max(lcm(T[i], T[j]), x)

print(x)


Fixed submission:
N = str(input())

A = N[::-1]
if N == A:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
a = [0] * M
b = [0] * M

for i in range(M):
    a[i], b[i] = map(int, input().split())

index = []
for i in range(M):
    if b[i] == N:
        index  = i

for j in range(M):
    if b[j] == a[index]:
        if a[j] == 1:
            print("POSSIBLE")
            break
    else:
        print("IMPOSSIBLE")
        break


Fixed submission:
N, M = map(int, input().split())
a = [0] * M
b = [0] * M

for i in range(M):
    a[i], b[i] = map(int, input().split())

s = []
t = []

for i in range(M):
    if a[i] == 1:
        s.append(b[i])
    elif b[i] == N:
        t.append(a[i])

if len(set(s) & set(t)) == 0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
a = [0] * M
b = [0] * M

for i in range(M):
    a[i], b[i] = map(int, input().split())

index = []
for i in range(M):
    if b[i] == N:
        index  = i

for j in range(M):
    if b[j] == a[index]:
        print(a[j])
        if a[j] == 1:
            print("POSSIBLE")
            break
    else:
        print("IMPOSSIBLE")
        break

Fixed submission:
N, M = map(int, input().split())
a = [0] * M
b = [0] * M

for i in range(M):
    a[i], b[i] = map(int, input().split())

s = []
t = []

for i in range(M):
    if a[i] == 1:
        s.append(b[i])
    elif b[i] == N:
        t.append(a[i])

if len(set(s) & set(t)) == 0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

b = []

for i in range(n):
    if i % 2 != n % 2:
        b.insert(0, a[i])
    else:
        b.append(a[i])

print(" ".join(map(str, b)))


Fixed submission:
from collections import deque

n = int(input())
a = list(map(int, input().split()))

b = deque()

for i in range(n):
    if i % 2 != n % 2:
        b.appendleft(a[i])
    else:
        b.append(a[i])

print(" ".join(map(str, b)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

b = []

for i in range(n):
    if i % 2 != n % 2:
        b.insert(0, a[i])
    else:
        b.append(a[i])

for i in range(n):
    print(b[i], end=" ")


Fixed submission:
from collections import deque

n = int(input())
a = list(map(int, input().split()))

b = deque()

for i in range(n):
    if i % 2 != n % 2:
        b.appendleft(a[i])
    else:
        b.append(a[i])

print(" ".join(map(str, b)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

b = []

for i in range(n):
    b.append(a[i])
    b = b[::-1]

for i in range(n):
    print(b[i], end = " ")


Fixed submission:
from collections import deque

n = int(input())
a = list(map(int, input().split()))

b = deque()

for i in range(n):
    if i % 2 != n % 2:
        b.appendleft(a[i])
    else:
        b.append(a[i])

print(" ".join(map(str, b)))
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [input() for i in range(N)]

now = 1
count = 0

for i in range(N):
    if now != 2:
        now = int(a[now-1])
        count += 1
    else:
        print(count)
        break

if count == loop:
    print(-1)


Fixed submission:
N = int(input())
a = [input() for i in range(N)]

now = 1
count = 0

for i in range(N):
    if now != 2:
        now = int(a[now-1])
        count += 1
    else:
        print(count)
        break

if count == N:
    print(-1)
Buggy python submission (verdict: Runtime Error):
W, a, b = map(int, input().split())

if a + W < b:
    print(b - a - W)
elif a + W == b:
    print(0)
elif (b < a + W) & (a < b):
    print(0)
elif a == b:
    print(0)
elif b < a:
    print(0)
elif a == b + W:
    print(0)
elif b + W < a:
    print(a - b - W)
else:
    pass


Fixed submission:
a, b = map(str, input().split())

if a == b:
    print("H")
elif not a == b:
    print("D")

Buggy python submission (verdict: Runtime Error):

if a + W < b:
    print(b - a - W)
elif a + W = b:
    print(0)
elif (b < a + W) & (a < b):
    print(0)
elif a == b:
    print(0)
elif b < a:
    print(0)
elif a = b + W:
    print(0)
elif b + W < a:
    print(a - b - W)
else:
    pass


Fixed submission:
a, b = map(str, input().split())

if a == b:
    print("H")
elif not a == b:
    print("D")

Buggy python submission (verdict: Runtime Error):
W, a, b = map(int, input().split())

if a + W < b:
    print(b - a - W)
elif a + W = b:
    print(0)
elif (b < a + W) & (a < b):
    print(0)
elif a == b:
    print(0)
elif b + W <= a:
    print(a - b - W)
else:
    pass


Fixed submission:
a, b = map(str, input().split())

if a == b:
    print("H")
elif not a == b:
    print("D")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
power = 1
for i in range(N):
    power *= (i + 1)

print(power % (10 ** 9 + 7))


Fixed submission:
N = int(input())
power = 1
for i in range(N):
    power *=  (i + 1) 
    power = power % (10 ** 9 + 7)

print(power)
Buggy python submission (verdict: Runtime Error):
from itertools import permutations
import copy
def resolve():
    N, M = list(map(int, input().split()))
    G = [[0]*N for _ in range(M)]
    for i in range(M):
        a, b = list(map(int, input().split()))
        G[a-1][b-1] = 1
        G[b-1][a-1] = 1

    ls = list(permutations(range(1, N)))
    ans = 0
    for l in ls:
        h = copy.deepcopy(G)
        cnt = 1
        p = 0 
        for k in l:
            if h[p][k] == 0:
                break
            else:
                cnt += 1
                p = k
        if cnt == N:
            ans += 1
    print(ans)
    return
resolve()

Fixed submission:
from itertools import permutations
import copy

def resolve():
    N, M = list(map(int, input().split()))
    G = [[0] * N for _ in range(N)]
    for i in range(M):
        a, b = list(map(int, input().split()))
        G[a-1][b-1] = 1
        G[b-1][a-1] = 1

    ls = list(permutations(range(1, N)))
    ans = 0
    for l in ls:
        h = copy.deepcopy(G)
        cnt = 1
        p = 0 
        for k in l:
            if h[p][k] == 0:
                break
            else:
                cnt += 1
                p = k
        if cnt == N:
            ans += 1
    print(ans)
    return

resolve()
Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int, input().split())
count = 0
for z in range(K+1):
    for y in range(K+1):
        x = S - z - y
        if (0 <= x <= K) & (0 <= y <= K) & (0 <= z <= K):
            count += 1

print(count)


Fixed submission:
K, S = map(int, input().split())
count = 0
for z in range(K+1):
    for y in range(K+1):
        x = S - z - y
        if (0 <= x <= K) :
            count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, x = map(int, input().split())
count = 0
for n in range(a, b+1):
    if n % x == 0:
        count += 1
        n += 1

print(count)


Fixed submission:
a, b, x = map(int, input().split())
if a != 0:
    print( b // x - (a - 1)//x )
else:
    print(b // x + 1)
Buggy python submission (verdict: Runtime Error):
def resolve():
    N, A, B = list(map(int, input().split()))
    S = str(input())
    num = 0
    foreignnum = 1
    for i in range(N):
        if S[i] == 'a':
            if (num < A + B):
                num += 1
                print('Yes')
            else:
                print('No')

        if S[i] == 'b':
            if (num < A + B) and (foreignnum <= B):
                num += 1
                foreignnum += 1
                print('Yes')
            else:
                print('No')

        if S[i] == 'c':
            print('No')

    return

 resolve()

Fixed submission:
def resolve():
    N, A, B = list(map(int, input().split()))
    S = str(input())
    num = 0
    foreignnum = 1
    for i in range(N):
        if S[i] == 'a':
            if (num < A + B):
                num += 1
                print('Yes')
            else:
                print('No')

        if S[i] == 'b':
            if (num < A + B) and (foreignnum <= B):
                num += 1
                foreignnum += 1
                print('Yes')
            else:
                print('No')

        if S[i] == 'c':
            print('No')
    return
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    A, B, C = list(map(int, input().split()))
    ans = 10 * 10
    for h in range(1, B):
        ans = min(ans, abs(2 * h * A * C - A * B * C))
    for w in range(1, A):
        ans = min(ans, abs(2 * w * A * B - A * B * C))

    print(ans)
    return


resolve()

Fixed submission:
def resolve():
    A, B, C = list(map(int, input().split()))
    ans = ''
    if A % 2 == 0 or B % 2 == 0 or C % 2 == 0:
        ans = 0
    else:
        ans = min(B * C, C * A, A * B)

    print(ans)
    return


resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    A, B, C = list(map(int, input().split()))
    ans = 10 * 10
    for h in range(1, B):
        ans = min(ans, abs(2 * h * A * C - A * B*C))
    for w in range(1, A):
        ans = min(ans, abs(2 * h * A * B - A * B*C))

    print(ans)
    return


resolve()

Fixed submission:
def resolve():
    A, B, C = list(map(int, input().split()))
    ans = ''
    if A % 2 == 0 or B % 2 == 0 or C % 2 == 0:
        ans = 0
    else:
        ans = min(B * C, C * A, A * B)

    print(ans)
    return


resolve()
Buggy python submission (verdict: Runtime Error):
N = int(input())
print(int(N * (N+1) / 2)


Fixed submission:
N = int(input())
print(int(N * (N+1) / 2))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

p = 1
for i in range(K):
    p *= A[i]

for i in range(N-K):
    q = (p//A[i])*A[i+K]
    if q > p:
        print('Yes')
    else:
        print('No')
    p = q


Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))

for i in range(N-K):
    if A[K+i] > A[i]:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


N = int(input())
ans = 0



for i in range(N):
    i += 1
    ans += i * len(make_divisors(i))

print(ans)


Fixed submission:
N = int(input())

ans = 0
for i in range(1,N+1):
    n = N // i
    ans += i * (n*(n+1))//2

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())


#整数N以下の素数を#素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a = prime_factorize(N)
b = set(a)

dic = {}
for i in b:
    n = 0
    while True:
        n += 1
        a.pop(0)
        if a == []:
            break
        if a[0] != i:
            break
    dic[i] = n


an = 0
for k, v in dic.items():
    num = int((-1+(1+8*v)**(1/2))/2)
    an += num

print(an)


Fixed submission:
N = int(input())


#整数N以下の素数を#素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a = prime_factorize(N)
b = set(a)

dic = {}
for i in b:
    n = 0
    while True:
        n += 1
        if a == []:
            break
        a.pop(0)
        if a == []:
            break
        if a[0] != i:
            break
    dic[i] = n


an = 0
for k, v in dic.items():
    num = int((-1+(1+8*v)**(1/2))/2)
    an += num

print(an)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

NN = [-1] * N
NN[0] = 0

i = 0
num = 0

while True:
    num += 1
    i = A[i] - 1
    if NN[i] != -1:
        n1 = NN[i]
        break
    NN[i] = num

n_ = num - n1

if K > N:
    K -= n1
    t = NN.index(n1 + K % n_) + 1
    print(t)
else:
    t = NN.index(K)
    print(t) + 1


Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))

NN = [-1] * N
NN[0] = 0

i = 0
num = 0

while True:
    num += 1
    i = A[i] - 1
    if NN[i] != -1:
        n1 = NN[i]
        break
    NN[i] = num

n_ = num - n1

if K > n1:
    K -= n1
    t = NN.index(n1 + K % n_) + 1
    print(t)
else:
    t = NN.index(K) + 1
    print(t)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

if K >= N:
    lst = []
    n = 0
    for i in range(N):
        n = A[n]-1
        if A[n] in lst:
            n0 = lst.index(A[n])
            n1 = i
            break
        lst.append(A[n])

    num = n1 - n0
    K -= n0
    r = K % num
    n = n0
else:
    n = 0
    
for _ in range(r):
    n = A[n] - 1

print(n0+n+1)


Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))

NN = [-1] * N
NN[0] = 0

i = 0
num = 0

while True:
    num += 1
    i = A[i] - 1
    if NN[i] != -1:
        n1 = NN[i]
        break
    NN[i] = num

n_ = num - n1

if K > n1:
    K -= n1
    t = NN.index(n1 + K % n_) + 1
    print(t)
else:
    t = NN.index(K) + 1
    print(t)
Buggy python submission (verdict: Runtime Error):
A = input()

S = 0
lis = [0] * 2019
lis[0] += 1
l = len(A)+1
d = 1

for n in reversed(A):
    S += int(n)*d
    sm = S % 2019
    lis[sm] += 1
    d *= 10

result = 0

for n in lis:
    result += (n*(n-1)/2)


print(int(result))


Fixed submission:
S, W = map(int,input().split())

if W >= S:
    print('unsafe')
else:
    print('safe')
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(input())
import itertools as itr

A = {'R':[] ,'G':[] ,'B':[]}
sum = 0

for i in range(N):
    A[S[i]].append(i+1)



for i,j,k in itr.product(A['R'],A['B'],A['G']):
            if not i-j == k-j:
                l = [i,j,k]
                l.sort()
                if not l[1] - l[0] == l[2] - l[1]:
                    sum += 1

print(sum)


Fixed submission:
N = int(input())

if str(7)in [str(N)[0],str(N)[1],str(N)[2]]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

import fractions

A = []
sum = 0

for i in range(K):
    for j in range(K):
        A.append(fractions.gcd(i+1,j+1))

for g in A:
    for i in range(K):
        sum += fractions.gcd(g,i+1)

print(sum)


Fixed submission:
K = int(input())

import fractions

A = {}
sum = 0

for i in range(K):
    for j in range(K):
        if fractions.gcd(i+1,j+1) in A:
            A[fractions.gcd(i+1,j+1)] += 1
        else:
            A[fractions.gcd(i+1,j+1)] = 1

for key in A:
    for i in range(K):
        sum += fractions.gcd(key,i+1)*A[key]

print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())

while True:
    M = N-K
    if M<0:
        M=-M
    if M < N:
        N = M
    else:break

print(N)


Fixed submission:
import math

N, K = map(int,input().split())

while True:
    if N>K:
      N = abs(N%K)
    if abs(N-K) < N:
        N = abs(N-K)
        continue
    else:break

print(N)

Buggy python submission (verdict: Time Limit Exceeded):
import math

N, K = map(int,input().split())

while True:
    if abs(N-K) < N:
        N = abs(N-K)
        continue
    else:break

print(N)


Fixed submission:
import math

N, K = map(int,input().split())

while True:
    if N>K:
      N = abs(N%K)
    if abs(N-K) < N:
        N = abs(N-K)
        continue
    else:break

print(N)
Buggy python submission (verdict: Time Limit Exceeded):
import math

num = int(input())

box = [1,2,3,4,5,6,7,8,9]
k=0



if num < 10:
    print(box[num-1])

else:
    while True:
        #boxに入っている数字がnumと同じ個数だったら終わり
        if len(box)==num:
            print(box[num-1])
            break

        k = k+1 #k=数字
        k1 = str(k)
        for i in range(len(k1)-1):
            if i == len(k1)-2:
                if abs(int(k1[i])-int(k1[i+1]))<=1:
                    box.append(k)
            if abs(int(k1[i])-int(k1[i+1]))<=1:
                continue
            else:break


Fixed submission:
a = [1,2,3,4,5,6,7,8,9]
i = -1
N = int(input())

while True:
    if  len(a) >= N:
        print(a[N-1])
        break
    i = i + 1
    n = int(str(a[i])[-1])
    x = a[i]*10 + n-1
    y = a[i]*10 + n
    z = a[i]*10 + n+1
    if n != 9 and n != 0:
        w = (x,y,z)
        a.extend(w)
    elif n == 9:
        w = (x,y)
        a.extend(w)
    elif n == 0:
        w = (y,z)
        a.extend(w)