Buggy python submission (verdict: Time Limit Exceeded):
def make_sosu_tbl():
    for i in range(2, MAX_N):
        if sos[i]:
            for j in range(i+i, MAX_N+1, i):
                sos[j] = 0
        if i**2 >= MAX_N:break

while 1:
    MAX_N = int(input())
    if not MAX_N: break
    sos = [1] * (MAX_N+1)
    make_sosu_tbl()

    for i in reversed(range(13,MAX_N+1)):
        if sos[i] and sos[i-2] and sos[i-6] and sos[i-8]:
            print(i)
            break

Fixed submission:
# from datetime import datetime

# measure_start = datetime.now()
move = [[[10, 10], [4, 4]], [[8, 2],[4, 2]]]

MAX_N = 10000000+1
sos = [1] * (MAX_N+1)
sos[0] = sos[1] = 0
for i in range(2, int(MAX_N**0.5)+1):
    if sos[i]:
        for j in range(i+i, MAX_N+1, i):
            sos[j] = 0

while 1:
    try:
        n = int(input())

        if not n: break
        n -= (n%2 == 0)
        while n >= 13:
            if sos[n] and sos[n-2] and sos[n-6] and sos[n-8]:
                print(n)
                break
            else:
                n -= move[sos[n-8]][sos[n-6]][sos[n-2]]
    # measure_stop = datetime.now()
    # print(measure_stop - measure_start)
    except:
        pass

Buggy python submission (verdict: Runtime Error):
MAX_N = 10000000+1

def make_sosu_tbl():
    for i in range(2, MAX_N):
        if sos[i]:
            for j in range(i+i, MAX_N+1, i):
                sos[j] = 0
        if i**2 >= MAX_N:break

sos = [1] * (MAX_N+1)
make_sosu_tbl()
while 1:
#    MAX_N = int(input())
#    if not MAX_N: break
#    
    n = int(input())
    for i in reversed(range(13,n+1)):
        if sos[i] and sos[i-2] and sos[i-6] and sos[i-8]:
            print(i)
            break

Fixed submission:
# from datetime import datetime

# measure_start = datetime.now()
move = [[[10, 10], [4, 4]], [[8, 2],[4, 2]]]

MAX_N = 10000000+1
sos = [1] * (MAX_N+1)
sos[0] = sos[1] = 0
for i in range(2, int(MAX_N**0.5)+1):
    if sos[i]:
        for j in range(i+i, MAX_N+1, i):
            sos[j] = 0

while 1:
    try:
        n = int(input())

        if not n: break
        n -= (n%2 == 0)
        while n >= 13:
            if sos[n] and sos[n-2] and sos[n-6] and sos[n-8]:
                print(n)
                break
            else:
                n -= move[sos[n-8]][sos[n-6]][sos[n-2]]
    # measure_stop = datetime.now()
    # print(measure_stop - measure_start)
    except:
        pass

Buggy python submission (verdict: Runtime Error):
MAX_N = 10000000+1

def make_sosu_tbl():
    for i in range(2, MAX_N):
        if sos[i]:
            for j in range(i+i, MAX_N+1, i):
                sos[j] = 0
        if i**2 >= MAX_N:break

sos = [1] * (MAX_N+1)
make_sosu_tbl()
while 1:
#    MAX_N = int(input())
#    if not MAX_N: break
#    
    n = int(input())
    if not n:break
    for i in reversed(range(13,n+1)):
        if sos[i] and sos[i-2] and sos[i-6] and sos[i-8]:
            print(i)
            break

Fixed submission:
# from datetime import datetime

# measure_start = datetime.now()
move = [[[10, 10], [4, 4]], [[8, 2],[4, 2]]]

MAX_N = 10000000+1
sos = [1] * (MAX_N+1)
sos[0] = sos[1] = 0
for i in range(2, int(MAX_N**0.5)+1):
    if sos[i]:
        for j in range(i+i, MAX_N+1, i):
            sos[j] = 0

while 1:
    try:
        n = int(input())

        if not n: break
        n -= (n%2 == 0)
        while n >= 13:
            if sos[n] and sos[n-2] and sos[n-6] and sos[n-8]:
                print(n)
                break
            else:
                n -= move[sos[n-8]][sos[n-6]][sos[n-2]]
    # measure_stop = datetime.now()
    # print(measure_stop - measure_start)
    except:
        pass

Buggy python submission (verdict: Runtime Error):
MAX_N = 10000000+1

def make_sosu_tbl():
    for i in range(2, MAX_N):
        if sos[i]:
            for j in range(i+i, MAX_N+1, i):
                sos[j] = 0
        if i**2 >= MAX_N:break

sos = [1] * (MAX_N+1)
make_sosu_tbl()
while 1:
    n = int(input())
    if not n: break
    for i in reversed(range(13, n+1)):
        if sos[i] and sos[i-2] and sos[i-6] and sos[i-8]:
            print(i)
            break

Fixed submission:
# from datetime import datetime

# measure_start = datetime.now()
move = [[[10, 10], [4, 4]], [[8, 2],[4, 2]]]

MAX_N = 10000000+1
sos = [1] * (MAX_N+1)
sos[0] = sos[1] = 0
for i in range(2, int(MAX_N**0.5)+1):
    if sos[i]:
        for j in range(i+i, MAX_N+1, i):
            sos[j] = 0

while 1:
    try:
        n = int(input())

        if not n: break
        n -= (n%2 == 0)
        while n >= 13:
            if sos[n] and sos[n-2] and sos[n-6] and sos[n-8]:
                print(n)
                break
            else:
                n -= move[sos[n-8]][sos[n-6]][sos[n-2]]
    # measure_stop = datetime.now()
    # print(measure_stop - measure_start)
    except:
        pass

Buggy python submission (verdict: Time Limit Exceeded):
MAX_N = 10000000+1

sos = [1] * (MAX_N+1)
for i in range(2, MAX_N):
    if sos[i]:
        for j in range(i+i, MAX_N+1, i):
            sos[j] = 0
    if i**2 >= MAX_N:break

while 1:
    try:
        n = int(input())

        if not n: break
        for i in reversed(range(13, n+1)):
            if sos[i] and sos[i-2] and sos[i-6] and sos[i-8]:
                print(i)
                break
    except:
        pass

Fixed submission:
# from datetime import datetime

# measure_start = datetime.now()
move = [[[10, 10], [4, 4]], [[8, 2],[4, 2]]]

MAX_N = 10000000+1
sos = [1] * (MAX_N+1)
sos[0] = sos[1] = 0
for i in range(2, int(MAX_N**0.5)+1):
    if sos[i]:
        for j in range(i+i, MAX_N+1, i):
            sos[j] = 0

while 1:
    try:
        n = int(input())

        if not n: break
        n -= (n%2 == 0)
        while n >= 13:
            if sos[n] and sos[n-2] and sos[n-6] and sos[n-8]:
                print(n)
                break
            else:
                n -= move[sos[n-8]][sos[n-6]][sos[n-2]]
    # measure_stop = datetime.now()
    # print(measure_stop - measure_start)
    except:
        pass

Buggy python submission (verdict: Time Limit Exceeded):
MAX_N = 10000000+1
SQRT_MAX = 3163
sos = [1] * (MAX_N+1)
for i in range(2, SQRT_MAX+1):
    if sos[i]:
        for j in range(i+i, MAX_N+1, i):
            sos[j] = 0

while 1:
    try:
        n = int(input())

        if not n: break
        for i in reversed(range(13, n+1)):
            if sos[i] and sos[i-2] and sos[i-6] and sos[i-8]:
                print(i)
                break
    except:
        pass

Fixed submission:
# from datetime import datetime

# measure_start = datetime.now()
move = [[[10, 10], [4, 4]], [[8, 2],[4, 2]]]

MAX_N = 10000000+1
sos = [1] * (MAX_N+1)
sos[0] = sos[1] = 0
for i in range(2, int(MAX_N**0.5)+1):
    if sos[i]:
        for j in range(i+i, MAX_N+1, i):
            sos[j] = 0

while 1:
    try:
        n = int(input())

        if not n: break
        n -= (n%2 == 0)
        while n >= 13:
            if sos[n] and sos[n-2] and sos[n-6] and sos[n-8]:
                print(n)
                break
            else:
                n -= move[sos[n-8]][sos[n-6]][sos[n-2]]
    # measure_stop = datetime.now()
    # print(measure_stop - measure_start)
    except:
        pass

Buggy python submission (verdict: Time Limit Exceeded):
# from datetime import datetime

# measure_start = datetime.now()

MAX_N = 10000000+1
sos = [1] * (MAX_N+1)
sos[0] = sos[1] = 0
for i in range(2, int(MAX_N**0.5)+1):
    if sos[i]:
        for j in range(i+i, MAX_N+1, i):
            sos[j] = 0

while 1:
    try:
        n = int(input())

        if not n: break
        n -= (n%2 == 1)
        for i in reversed(range(13, n+1)):
            if sos[i] and sos[i-2] and sos[i-6] and sos[i-8]:
                print(i)
                break
    except:
        pass
# measure_stop = datetime.now()
# print(measure_stop - measure_start)

Fixed submission:
# from datetime import datetime

# measure_start = datetime.now()
move = [[[10, 10], [4, 4]], [[8, 2],[4, 2]]]

MAX_N = 10000000+1
sos = [1] * (MAX_N+1)
sos[0] = sos[1] = 0
for i in range(2, int(MAX_N**0.5)+1):
    if sos[i]:
        for j in range(i+i, MAX_N+1, i):
            sos[j] = 0

while 1:
    try:
        n = int(input())

        if not n: break
        n -= (n%2 == 0)
        while n >= 13:
            if sos[n] and sos[n-2] and sos[n-6] and sos[n-8]:
                print(n)
                break
            else:
                n -= move[sos[n-8]][sos[n-6]][sos[n-2]]
    # measure_stop = datetime.now()
    # print(measure_stop - measure_start)
    except:
        pass

Buggy python submission (verdict: Runtime Error):
move = [[[10, 10], [4, 4]], [[8, 2],[4, 2]]]

MAX_N = 10000000+1
sos = [1] * (MAX_N+1)
sos[0] = sos[1] = 0
for i in range(2, int(MAX_N**0.5)+1):
    if sos[i]:
        for j in range(i+i, MAX_N+1, i):
            sos[j] = 0

while 1:
    n = int(input())

    if not n: break
    n -= (n%2 == 0)
    while n >= 13:
        if sos[n] and sos[n-2] and sos[n-6] and sos[n-8]:
            print(n)
            break
        else:
            n -= move[sos[n-8]][sos[n-6]][sos[n-2]]
# measure_stop = datetime.now()
# print(measure_stop - measure_start)

Fixed submission:
# from datetime import datetime

# measure_start = datetime.now()
move = [[[10, 10], [4, 4]], [[8, 2],[4, 2]]]

MAX_N = 10000000+1
sos = [1] * (MAX_N+1)
sos[0] = sos[1] = 0
for i in range(2, int(MAX_N**0.5)+1):
    if sos[i]:
        for j in range(i+i, MAX_N+1, i):
            sos[j] = 0

while 1:
    try:
        n = int(input())

        if not n: break
        n -= (n%2 == 0)
        while n >= 13:
            if sos[n] and sos[n-2] and sos[n-6] and sos[n-8]:
                print(n)
                break
            else:
                n -= move[sos[n-8]][sos[n-6]][sos[n-2]]
    # measure_stop = datetime.now()
    # print(measure_stop - measure_start)
    except:
        pass