Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
num_list = [1]
dp = [0] * (n+1)
dp[1] = 1
dp[2] = 2
dp[3] = 3
dp[4] = 4
dp[5] = 5
dp[6] = 1


def recursion(n, li):
    min_n = 10**9
    for i in li:
        if n - i < 0:
            break
        num = dp[n - i]
        if min_n > num:
            min_n = num
    return min_n + 1


for i in range(1, 7):
    a = 6 ** i
    b = 9 ** i
    if a <= n:
        num_list.append(a)
    if b <= n:
        num_list.append(b)

for i in range(7, n+1):
    dp[i] = recursion(i, num_list)

print(dp[n])

Fixed submission:
n = int(input())
num_list = [1]
dp = [0] * (n+1)
dp[1] = 1


def recursion(n, li):
    min_n = 10**9
    for i in li:
        if n - i < 0:
            continue
        num = dp[n - i]
        if min_n > num:
            min_n = num
    return min_n + 1


for i in range(1, 9):
    a = 6 ** i
    b = 9 ** i
    if a <= n:
        num_list.append(a)
    if b <= n:
        num_list.append(b)

for i in range(2, n+1):
    dp[i] = recursion(i, num_list)

print(dp[n])
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
k = int(input())
a = []

for i in range(1, len(s) + 1):
    for j in range(len(s) - i + 1):
        word = s[j:j+i]
        if word not in a:
            a.append(word)


a.sort()

print(''.join(a[k-1]))


Fixed submission:
s = list(input())
k = int(input())
a = []

for i in range(1, len(s) + 1):
    if i >= k+1:
        break
    for j in range(len(s) - i + 1):
        word = s[j:j+i]
        if word not in a:
            a.append(word)


a.sort()

print(''.join(a[k-1]))
Buggy python submission (verdict: Time Limit Exceeded):
import math

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

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

a.sort(reverse=True)
max_comb = 0
for i in range(min(10, n-1)):
    comb_sum = 0
    for j in a:
        if j < a[i]:
            comb_sum = combinations_count(a[i], j)
            if comb_sum > max_comb:
                max_comb = comb_sum
                comb_n = a[i]
                comb_r = j

print(comb_n, comb_r)

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

a.sort(reverse=True)

num = a[0]

target = a[0]/2

diff = 1000000000000

for i in a:
    if i == num:
        continue
    dif = abs(target-i)
    if dif < diff:
        diff = dif
        num_2 = i

print(num, num_2)

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

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

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

a.sort(reverse=True)
max_comb = 0
for i in range(min(100, n-1)):
    comb_sum = 0
    for j in a:
        if j < a[i]:
            comb_sum = combinations_count(a[i], j)
            if comb_sum > max_comb:
                max_comb = comb_sum
                comb_n = a[i]
                comb_r = j

print(comb_n, comb_r)

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

a.sort(reverse=True)

num = a[0]

target = a[0]/2

diff = 1000000000000

for i in a:
    if i == num:
        continue
    dif = abs(target-i)
    if dif < diff:
        diff = dif
        num_2 = i

print(num, num_2)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int(input().split()))

if a + b >= c:
    print('Yes')
else:
    print('No')


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

if a + b >= c:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):

def find(b, c, d):
    min_path = c + d
    cnt = 0

    for i in range(1000):
        act_path = min_path + 4 * i
        if(act_path == b):
            cnt += 1
        else:
            cnt += 0

    return cnt


N = int(input())
t = [0] * N
x = [0] * N
y = [0] * N
for i in range(N):
    t[i], x[i], y[i] = map(int, input().split())

count = 0

for i in range(N):
    diff_x = x[i] - x[i-1]
    diff_y = y[i] - y[i-1]
    diff_t = t[i] - t[i-1]

    count += find(diff_t, diff_x, diff_y)

if(count == N):
    print('Yes')
else:
    print('No')


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

if(a * b %2 == 0):
    print("Even")

else:
    print("Odd")
Buggy python submission (verdict: Runtime Error):
a, b = input().split()

import math

c = a + b
d = math.sqrt(c)

if(c == d**2):
    print('Yes')
else:
    print('No')

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

import math

c = int(a + b)
d = math.sqrt(c)
e = int(math.sqrt(c))
diff = d - e

if(diff == 0):
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
import math

a, b = input().split()

c = a + b
d = math.sqrt(c)

if(c == d**2):
    print('Yes')
else:
    print('No')

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

import math

c = int(a + b)
d = math.sqrt(c)
e = int(math.sqrt(c))
diff = d - e

if(diff == 0):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

train_list = []
for i in range(n-1):
    array = list(map(int,input().split()))
    train_list.append(array)

for i in range(n-1):
    time = 0
    for j in range(i, n-1):
        if i == j:
            time += (train_list[i][0] + train_list[i][1])
        else:
            flag = False
            p = 0
            while flag is False:
                t = train_list[j][1] + train_list[j][2] * p
                if t // time >= 1:
                    flag = True
                    time = t
                    time += train_list[j][0]
                p += ((time - t)//train_list[j][2])

    print(time)

print(0)


Fixed submission:
import math
n = int(input())

train_list = []
for i in range(n-1):
    array = list(map(int,input().split()))
    train_list.append(array)


for i in range(n-1):
    time = 0
    for j in range(i, n-1):
        if i == j:
            time += (train_list[i][0] + train_list[i][1])
        else:
            if train_list[j][1] // time >= 1:
                time = train_list[j][1]
                time += train_list[j][0]
            else:
                p = math.ceil((time - train_list[j][1])/train_list[j][2])
                time = train_list[j][1] + train_list[j][2] * p
                time += train_list[j][0]
    print(time)

print(0)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

train_list = []
for i in range(n-1):
    array = list(map(int,input().split()))
    train_list.append(array)

for i in range(n-1):
    time = 0
    for j in range(i, n-1):
        if i == j:
            time += (train_list[i][0] + train_list[i][1])
        else:
            flag = False
            p = 0
            while flag is False:
                t = train_list[j][1] + train_list[j][2] * p
                if t // time >= 1:
                    flag = True
                    time = t
                    time += train_list[j][0]
                p += 1

    print(time)

print(0)


Fixed submission:
import math
n = int(input())

train_list = []
for i in range(n-1):
    array = list(map(int,input().split()))
    train_list.append(array)


for i in range(n-1):
    time = 0
    for j in range(i, n-1):
        if i == j:
            time += (train_list[i][0] + train_list[i][1])
        else:
            if train_list[j][1] // time >= 1:
                time = train_list[j][1]
                time += train_list[j][0]
            else:
                p = math.ceil((time - train_list[j][1])/train_list[j][2])
                time = train_list[j][1] + train_list[j][2] * p
                time += train_list[j][0]
    print(time)

print(0)
Buggy python submission (verdict: Time Limit Exceeded):
import collections

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

c = collections.Counter(a)
count = 0

for i in range(k, len(c)):
        count += c.most_common()[i][1]

print(count)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
count = 1
b = []

for i in range(n-1):
    if a[i] != a[i+1]:
        b.append(count)
        count = 1
    else:
        count += 1

b.append(count)

b.sort(reverse=True)

count = 0
if k < len(b):
    for i in range(k, len(b)):
        count += b[i]

print(count)

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

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

c = collections.Counter(a)
count = 0

for i in range(len(c)):
    if i >= k:
        count += c.most_common()[i][1]

print(count)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
count = 1
b = []

for i in range(n-1):
    if a[i] != a[i+1]:
        b.append(count)
        count = 1
    else:
        count += 1

b.append(count)

b.sort(reverse=True)

count = 0
if k < len(b):
    for i in range(k, len(b)):
        count += b[i]

print(count)
Buggy python submission (verdict: Runtime Error):
import math
import itertools
import collections


h, w = map(int, input().split())

route_list = []
wall = []
count = 0

for _ in range(10):
    array = list(map(int, input().split()))
    route_list.append(array)

for _ in range(h):
    array = list(map(int,input().split()))
    wall.append(array)

node_num = len(route_list) #ノードの数

route = []

for i in range(10):
    now = i
    unsearched_nodes = list(range(node_num)) # 未探索ノード
    distance = [math.inf] * node_num # ノードごとの距離のリスト
    distance[now] = 0 # 初期のノードの距離は0とする

    while len(unsearched_nodes) > 0:
        for node in range(node_num):
            if now == node:
                continue
            else:
                distance[node] = min(distance[now] + route_list[now][node], distance[node])
        unsearched_nodes.remove(now)
        if len(unsearched_nodes) > 0:
            now = unsearched_nodes[0]
    route.append(distance)

distance_to_one = []
for i in range(10):
    distance_to_one.append(route[i][1])

flattened_wall = list(itertools.chain.from_iterable(wall))

c = collections.Counter(flattened_wall)
for i, j in c.items():
    if i == -1:
        continue
    elif i == 1:
        collections
    else:
        count += distance_to_one[i] * j

print(count)

Fixed submission:
h, w = map(int, input().split())

WF = []
wall = []
ans = 0

for _ in range(10):
    array = list(map(int, input().split()))
    WF.append(array)

for _ in range(h):
    array = list(map(int,input().split()))
    wall.append(array)

for k in range(10):
    for i in range(10):
        for j in range(10):
            WF[i][j]=min(WF[i][j],WF[i][k]+WF[k][j])

for i in range(h):
    for j in range(w):
        num = wall[i][j]
        if num != -1:
            ans += WF[num][1]

print(ans)
Buggy python submission (verdict: Runtime Error):
x = input()
y = input()

if x < y:
    print('<')
elif y < x:
    print('>')
else:
    print('=')


Fixed submission:
a = list(input())
x = a[0]
y = a[2]

if x < y:
    print('<')
elif y < x:
    print('>')
else:
    print('=')
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

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


count = 0

for i in range(n):
    x = a[i] + 1
    index1 = bisect.bisect_left(b, x)
    if index1 >= n:
        break
    b_tmp = b[index1:]
    for j in b_tmp:
        y = j + 1
        index2 = bisect.bisect_left(c, y)
        if index2 >= n:
            break
        c_tmp = c[index2:]
        count += len(c_tmp)


print(count)



Fixed submission:
import bisect

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

count = 0

for i in b:
    x = bisect.bisect_left(a, i)
    y = bisect.bisect_right(c, i)
    count += x * (len(c) - y)

print(count)

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

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

index_list_1 = []
index_list_2 = []
count = 0

for i in b:
    index_list_1.append(len(c) - bisect.bisect_left(c, i+1))

for i in a:
    index_list_2.append(bisect.bisect_left(b, i+1))

for i in index_list_2:
    count += sum(index_list_1[i:])

print(count)

Fixed submission:
import bisect

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

count = 0

for i in b:
    x = bisect.bisect_left(a, i)
    y = bisect.bisect_right(c, i)
    count += x * (len(c) - y)

print(count)

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

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


count = 0

for i in range(n):
    x = a[i] + 1
    index1 = bisect.bisect_left(b, x)
    b_tmp = b[index1:]
    for j in b_tmp:
        y = j + 1
        index2 = bisect.bisect_left(c, y)
        c_tmp = c[index2:]
        count += len(c_tmp)


print(count)

Fixed submission:
import bisect

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

count = 0

for i in b:
    x = bisect.bisect_left(a, i)
    y = bisect.bisect_right(c, i)
    count += x * (len(c) - y)

print(count)
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
mine_area = []
output = [[0 for _ in range(w)] for _ in range(h)]


def check_num(i, j):
    a = i - 1
    b = i + 1
    c = j - 1
    d = j + 1
    if i == 0:
        a = i
    elif i == h-1:
        b = i
    if j == 0:
        c = j
    elif j == w-1:
        d = j
    count = 0
    for p in range(a, b+1):
        for q in range(c, d+1):
            if p == i and q == j:
                continue
            if mine_area[p][q] == '#':
                count += 1
    return count


for _ in range(h):
    mine_line = list(input())
    mine_area.append(mine_line)

for i in range(h):
    for j in range(w):
        if mine_area[i][j] == '#':
            mine_area[i][j] = '#'
        else:
            mine_area[i][j] = check_num(i, j)

for i in range(h):
    for j in range(w):
        print(mine_area[i][j], end='')
        if j == w-1:
            print()


Fixed submission:
h, w = map(int, input().split())
mine_area = []
output = [[0 for _ in range(w)] for _ in range(h)]


def check_num(i, j):
    a = i - 1
    b = i + 1
    c = j - 1
    d = j + 1
    if i == 0:
        a = i
    if i == h-1:
        b = i
    if j == 0:
        c = j
    if j == w-1:
        d = j
    count = 0
    for p in range(a, b+1):
        for q in range(c, d+1):
            if p == i and q == j:
                continue
            if mine_area[p][q] == '#':
                count += 1
    return count


for _ in range(h):
    mine_line = list(input())
    mine_area.append(mine_line)

for i in range(h):
    for j in range(w):
        if mine_area[i][j] == '#':
            mine_area[i][j] = '#'
        else:
            mine_area[i][j] = check_num(i, j)

for i in range(h):
    for j in range(w):
        print(mine_area[i][j], end='')
        if j == w-1:
            print()
Buggy python submission (verdict: Runtime Error):
n = int(input())

num_list = []
for i in range(n):
    a = int(input())
    num_list.append(a)

num_list.sort()
num_list2 = []
i = 0
while i < n:
    if num_list[i] == num_list[i+1]:
        i += 2
    else:
        num_list2.append(num_list[i])
        i += 1

print(len(num_list2))

Fixed submission:
n = int(input())

num_list = []
for i in range(n):
    a = int(input())
    num_list.append(a)

num_list.sort()
num_list2 = []
i = 0
while i < n:
    if i == n-1:
        num_list2.append(num_list[i])
        break
    elif num_list[i] == num_list[i+1]:
        i += 2
    else:
        num_list2.append(num_list[i])
        i += 1


print(len(num_list2))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

num_list = []
for i in range(n):
    a = int(input())
    if a in num_list:
        num_list.remove(a)
    else:
        num_list.append(a)

print(len(num_list))

Fixed submission:
n = int(input())

num_list = []
for i in range(n):
    a = int(input())
    num_list.append(a)

num_list.sort()
num_list2 = []
i = 0
while i < n:
    if i == n-1:
        num_list2.append(num_list[i])
        break
    elif num_list[i] == num_list[i+1]:
        i += 2
    else:
        num_list2.append(num_list[i])
        i += 1


print(len(num_list2))
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations


n, m, r = map(int, input().split())
towns = list(map(int, input().split()))

graph = [[0 for _ in range(n)] for _ in range(n)]

for i in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    graph[a][b] = c
    graph[b][a] = c

# ワーシャルフロイド

for k in range(n):
    for i in range(n):
        for j in range(n):
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])

min_dist = 10**10
for route in permutations(towns, r):
    dist = 0
    for i in range(r-1):
        a = route[i] - 1
        b = route[i+1] - 1
        dist += graph[a][b]
    if dist < min_dist:
        min_dist = dist

print(min_dist)


Fixed submission:
from itertools import permutations


N, M, R = map(int, input().split())
r = list(map(int, input().split()))
INF = float('inf')

graph = [[INF for _ in range(N)] for _ in range(N)]

for _ in range(M):
    a, b, c = map(int, input().split())
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c

distance = [[float('inf') for _ in range(N)] for _ in range(N)]

for k in range(N):
    for i in range(N):
        for j in range(N):
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])

total_min = INF
for i in permutations(r, len(r)):
    total = 0
    for j in range(len(r)-1):
        total += graph[i[j]-1][i[j-1]-1]
    if total < total_min:
        total_min = total

print(total_min)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations


N, M, R = map(int, input().split())
r = list(map(int, input().split()))
INF = float('inf')

graph = [[INF for _ in range(N)] for _ in range(N)]

for _ in range(M):
    a, b, c = map(int, input().split())
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c

distance = [[float('inf') for _ in range(N)] for _ in range(N)]

for k in range(N):
    for i in range(N):
        for j in range(N):
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])

total_min = INF
for i in permutations(r, len(r)):
    total = 0
    for j in range(len(r)-1):
        total += graph[i[j]-1][i[j-1]-1]
    if total < total_min:
        total_min = total

print(total_min)



Fixed submission:
from itertools import permutations


N, M, R = map(int, input().split())
r = list(map(int, input().split()))
INF = float('inf')

graph = [[INF for _ in range(N)] for _ in range(N)]

for _ in range(M):
    a, b, c = map(int, input().split())
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c

distance = [[float('inf') for _ in range(N)] for _ in range(N)]

for k in range(N):
    for i in range(N):
        for j in range(N):
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])

total_min = INF
for i in permutations(r, len(r)):
    total = 0
    for j in range(len(r)-1):
        total += graph[i[j]-1][i[j-1]-1]
    if total < total_min:
        total_min = total

print(total_min)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
count = 0
i = 0
while i <= (n-1):
    if a[i] == i+1 and a[i+1] == i+2:
        count += 1
        i += 2
    elif a[i] == i+1:
        count += 1
        i += 1
    else:
        i += 1

print(count)



Fixed submission:
n = int(input())
a = list(map(int, input().split()))
count = 0
i = 0
while i <= (n-1):
    if i == n-1:
        if a[i] == i+1:
            count += 1
            print(count)
            exit()
        else:
            break
    if a[i] == i+1 and a[i+1] == i+2:
        count += 1
        i += 2
    elif a[i] == i+1:
        count += 1
        i += 1
    else:
        i += 1

print(count)
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

n = int(input())

clock_list = []
for i in range(n):
    a = int(input())
    clock_list.append(a)

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


print(lcm_list(clock_list))

Fixed submission:
import fractions
from functools import reduce

n = int(input())

clock_list = []
for i in range(n):
    a = int(input())
    clock_list.append(a)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


print(lcm_list(clock_list))
Buggy python submission (verdict: Time Limit Exceeded):
# Bellman-Ford

def shortest_path(s,n,es):
    # s : 始点、　n : 頂点数、 w : 辺の数、 es[i] : 辺の始点、辺の終点、辺のコスト
    # dはsからの最短距離を表す(最初は始点以外はINFに設定しておく)
    d = [float('inf')] * n
    d[s] = 0

    # 無限ループ(速さを求めるならn-1回for文を回す)
    while True:
        # 無限ループの終了条件は1度も最短距離が更新されなかったとき
        update = False
        # 全ての辺に対して最短距離を緩和していく
        for p,q,r in es:
            # 点p→qに対して最短距離を更新する
            if d[p] != float('inf') and d[q] > d[p] + r:
                d[q] = d[p] + r
                update = True
        if not update:
            break
    return d


# n,w = map(int, input().split())
n = int(input())
es = []

for _ in range(n-1):
    x,y,z = map(int ,input().split())
    es.append([x-1,y-1,z])
    es.append([y-1,x-1,z])

q, k = map(int, input().split())

QQ = []
for _ in range(q):
    x, y = map(int, input().split())
    QQ.append([x-1, y-1])

d_list = shortest_path(k-1, n, es)

for i, j in QQ:
    print(d_list[i] + d_list[j])


Fixed submission:
import sys
sys.setrecursionlimit(10**7)


def dfs(start, dist, distance_list, explored):
    for node, cost in tree[start]:
        if explored[node] is False:
            explored[node] = True
            distance_list[node] = dist + cost
            dfs(node, distance_list[node], distance_list, explored)
    return distance_list


n = int(input())
tree = [[] for _ in range(n)]
distance = [float('inf') for _ in range(n)]

for _ in range(n-1):
    a,b,c = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append((b, c))
    tree[b].append((a, c))

q, k = map(int, input().split())
k -= 1
query = []
distance[k] = 0

for _ in range(q):
    x, y = map(int, input().split())
    query.append((x-1, y-1))

XX = [False for _ in range(n)]
XX[k] = True

X = dfs(k, 0, distance, explored=XX)

for i, j in query:
    print(X[i] + X[j])
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

first = []
second = []
for i in range(m):
    a = list(map(int, input().split()))
    if a[0] == 1:
        first.append(a[1])
    if a[1] == n:
        second.append(a[0])


for i in first:
    if i in second:
        print('POSSIBLE')
        exit()

print('IMPOSSIBLE')

Fixed submission:
n, m = map(int, input().split())

first = []
second = []
for i in range(m):
    a = list(map(int, input().split()))
    if a[0] == 1:
        first.append(a[1])
    if a[1] == n:
        second.append(a[0])


if len(set(first) & set(second)) > 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
ship_list = []
first = []
second = []
for i in range(m):
    a = list(map(int, input().split()))
    ship_list.append(a)

for i in range(m):
    if ship_list[i][0] == 1:
        first.append(ship_list[i][1])
    if ship_list[i][1] == n:
        second.append(ship_list[i][0])

for i in first:
    if i in second:
        print('POSSIBLE')
        exit()

print('IMPOSSIBLE')

Fixed submission:
n, m = map(int, input().split())

first = []
second = []
for i in range(m):
    a = list(map(int, input().split()))
    if a[0] == 1:
        first.append(a[1])
    if a[1] == n:
        second.append(a[0])


if len(set(first) & set(second)) > 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')