Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
def calculate(arr1,arr2,zeroExist):
    if (len(arr1) % 2 == 0) or (zeroExist == True):
        return sum(arr2) - sum(arr1)
    else:
        return sum(arr2) - sum(arr1) - 2 * (calculateAbsSmallest(arr1,arr2))



def concatList(arr1,arr2):
    arr3 = list([])
    arr3.extend(arr1)
    arr3.extend(arr2)
    return arr3

def calculateAbsSmallest(arr1,arr2):
    arr1.sort()
    arr2.sort()
    return min(-arr1[0],arr2[0])


N = int(input())

arr1 = []
arr2 = []
zeroExist = False
for s in input().split(" "):
    if int(s) == 0:
        zeroExist = True
    if int(s) < 0:
        arr1.append(int(s))
    else:
        arr2.append(int(s))

arr1 = list(arr1)
arr2 = list(arr2)

res = calculate(arr1,arr2,zeroExist)
print(res)






Fixed submission:
import math
def calculate(arr1,arr2,zeroExist):
    if (len(arr1) % 2 == 0) or (zeroExist == True):
        return sum(arr2) + sum(arr1)
    else:
        return sum(arr2) + sum(arr1) - 2 * (calculateAbsSmallest(arr1,arr2))


def calculateAbsSmallest(arr1,arr2):
    arr1.sort()
    arr2.sort()
    if len(arr2) == 0:
        return arr1[0]
    return min(arr1[0],arr2[0])

N = int(input())

arr1 = []
arr2 = []
zeroExist = False
for s in input().split(" "):
    if int(s) == 0:
        zeroExist = True
    if int(s) < 0:
        arr1.append(abs(int(s)))
    else:
        arr2.append(int(s))

arr1 = list(arr1)
arr2 = list(arr2)

res = calculate(arr1,arr2,zeroExist)
print(res)

Buggy python submission (verdict: Runtime Error):
import math
def calculate(arr1,arr2):

    if len(arr1) % 2 == 0:
        return sum(arr2) - sum(arr1)
    else:
        return sum(arr2) - sum(arr1) - 2 * (calculateAbsSmallest(arr1,arr2))


def concatList(arr1,arr2):
    arr3 = list([])
    arr3.extend(arr1)
    arr3.extend(arr2)
    return arr3

def calculateAbsSmallest(arr1,arr2):
    arr1.sort()
    arr2.sort()
    return min(-arr1[0],arr2[0])





N = int(input())

arr1 = []
arr2 = []
for s in input().split(" "):
    if int(s) < 0:
        arr1.append(int(s))
    else:
        arr2.append(int(s))

arr1 = list(arr1)
arr2 = list(arr2)

res = calculate(arr1,arr2)
print(res)






Fixed submission:
import math
def calculate(arr1,arr2,zeroExist):
    if (len(arr1) % 2 == 0) or (zeroExist == True):
        return sum(arr2) + sum(arr1)
    else:
        return sum(arr2) + sum(arr1) - 2 * (calculateAbsSmallest(arr1,arr2))


def calculateAbsSmallest(arr1,arr2):
    arr1.sort()
    arr2.sort()
    if len(arr2) == 0:
        return arr1[0]
    return min(arr1[0],arr2[0])

N = int(input())

arr1 = []
arr2 = []
zeroExist = False
for s in input().split(" "):
    if int(s) == 0:
        zeroExist = True
    if int(s) < 0:
        arr1.append(abs(int(s)))
    else:
        arr2.append(int(s))

arr1 = list(arr1)
arr2 = list(arr2)

res = calculate(arr1,arr2,zeroExist)
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
def calculate():
    s = input()

    count = 0
    while s.count("01") > 0 or s.count("10"):
        if s.count("01") > 0:
            s = s.replace("01","",1)
            count += 1
        if s.count("10") > 0:
            s = s.replace("10", "",1)
            count += 1

    print(count*2)



calculate()

Fixed submission:
def calculate():
    s = input()

    n0 = s.count("0")
    n1 = s.count("1")

    if n0 == n1:
        print(n0*2)
    elif n0 > n1:
        print(n1 * 2)
    else:
        print(n0 * 2)



calculate()
Buggy python submission (verdict: Time Limit Exceeded):
# N, W = 3, 8
# ARR = [
#     [3, 30],
#     [4, 50],
#     [5, 60],
# ]
#
N, W, = 6, 15
ARR = [
    [6, 5],
    [5, 6],
    [6, 4],
    [6, 6],
    [3, 5],
    [7, 2],
]


N,W = map(int,input().split())
ARR = []

for i in range(N):
    ARR.append(list(map(int,input().split())))


def calculate(n, w, arr):
    srr = [[0] * (w + 1) for i in range (n + 1)]

    for i in range(1, n + 1):
        for j in range(1, w + 1):
            if (j - arr[i-1][0]) >= 0:
                s1 = srr[i-1][j - arr[i-1][0]] + arr[i-1][1]
                s2 = srr[i-1][j]
                srr[i][j] = max(s1, s2)
            else:
                srr[i][j] = srr[i - 1][j]

    print(srr[-1][-1])


calculate(N, W, ARR)


Fixed submission:
# N, W = 3, 8
# ARR = [
#     [3, 30],
#     [4, 50],
#     [5, 60],
# ]
#
# N, W, = 6, 15
# ARR = [
#     [6, 5],
#     [5, 6],
#     [6, 4],
#     [6, 6],
#     [3, 5],
#     [7, 2],
# ]


N,W = map(int,input().split())
ARR = []

for i in range(N):
    ARR.append(list(map(int,input().split())))

def calculate(n, w, arr):
    result = [[0] * (w + 1) for i in range(n + 1)]


    for i in range(n):
        width = arr[i][0]
        value = arr[i][1]
        for j in range(w + 1):

            if j >= width:
                result[i + 1][j] = max(result[i][j - width] + value, result[i + 1][j])

            result[i + 1][j] = max(result[i + 1][j], result[i][j])

    # print(result)
    print(result[n][w])


calculate(N, W, ARR)

Buggy python submission (verdict: Time Limit Exceeded):
# N, W = 3, 8
# ARR = [
#     [3, 30],
#     [4, 50],
#     [5, 60],
# ]
#
# N, W, = 6, 15
# ARR = [
#     [6, 5],
#     [5, 6],
#     [6, 4],
#     [6, 6],
#     [3, 5],
#     [7, 2],
# ]


N,W = map(int,input().split())
ARR = []

for i in range(N):
    ARR.append(list(map(int,input().split())))

def calculate(n, w, arr):
    result = [[0] * (w + 1) for i in range(n + 1)]


    for i in range(n):
        width = arr[i][0]
        value = arr[i][1]
        for j in range(w + 1):

            if j >= width:
                result[i + 1][j] = max(result[i][j - width] + value, result[i + 1][j])

            result[i + 1][j] = max(result[i + 1][j], result[i][j])

    # print(result)
    print(result[n][w])


calculate(N, W, ARR)


Fixed submission:
# N, W = 3, 8
# ARR = [
#     [3, 30],
#     [4, 50],
#     [5, 60],
# ]
#
# N, W, = 6, 15
# ARR = [
#     [6, 5],
#     [5, 6],
#     [6, 4],
#     [6, 6],
#     [3, 5],
#     [7, 2],
# ]


N,W = map(int,input().split())
ARR = []

for i in range(N):
    ARR.append(list(map(int,input().split())))

def calculate(n, w, arr):
    result = [[0] * (w + 1) for i in range(n + 1)]


    for i in range(n):
        width = arr[i][0]
        value = arr[i][1]
        for j in range(w + 1):

            if j >= width:
                result[i + 1][j] = max(result[i][j - width] + value, result[i + 1][j])

            result[i + 1][j] = max(result[i + 1][j], result[i][j])

    # print(result)
    print(result[n][w])


calculate(N, W, ARR)
Buggy python submission (verdict: Time Limit Exceeded):
S = input().split(" ")
n = int(S[0])
k = int(S[1])
arr = []
for i in range(n):
    arr.append(int(input()))

def calculate(n,k,arr):
    arr.sort()
    drr = []
    for i in range(1,n):
        drr.append(arr[i] - arr[i-1])

    i = 0
    sums = []
    while (i + k-1) <= len(drr):
        tmp = sum(drr[i:i + k-1])
        sums.append(tmp)
        i = i + 1
    print(min(sums))

calculate(n,k,arr)

Fixed submission:
S = input().split(" ")
n = int(S[0])
k = int(S[1])
arr = []
for i in range(n):
    arr.append(int(input()))

def calculate(n, k, arr):
    arr.sort()
    drr = []
    for i in range(1, n):
        drr.append(arr[i] - arr[i - 1])

    j = 0
    s = 0
    sums = []
    for i in range(len(drr) - (k - 1) + 1):
        while j < i + (k-1):
            s = s + drr[j]
            j = j + 1
        sums.append(s)
        s = s - drr[i]
    print(min(sums))



calculate(n, k, arr)
Buggy python submission (verdict: Runtime Error):
S = input().split(" ")
n = int(S[0])
m = int(S[1])

py = []

for i in range(n+1):
    py.append([int(s) for s in input().split(" ")])

def prepare(n, data):
    result = [0 for i in range(n)]
    dict = {}
    data = sorted(data,key=lambda x:x[1])
    for d in data:
        i = d[0] - 1
        result[i] = result[i] + 1
        dict.__setitem__(generateID(d[0], d[1]), str(d[0]).zfill(6) + str(result[i]).zfill(6))

    return dict


def generateID(start, to):
    if start < to:
        start, to = to, start

    return start * 100000 + to

dict = prepare(n, py)

for p in py:
    print(dict[generateID(p[0],p[1])])




Fixed submission:
import sys
sys.setrecursionlimit(20000000)
S = input().split(" ")
n = int(S[0])
m = int(S[1])

py = []

for i in range(m):
    py.append([int(s) for s in input().split(" ")])

def prepare(n, data):
    result = [0 for i in range(n)]
    dict = {}
    data = sorted(data,key=lambda x:x[1])
    for d in data:
        i = d[0] - 1
        result[i] = result[i] + 1
        dict.__setitem__(generateID(d[0], d[1]), str(d[0]).zfill(6) + str(result[i]).zfill(6))

    return dict


def generateID(start, to):
    if start < to:
        start, to = to, start

    return start * 100000 + to

dict = prepare(n, py)

for p in py:
    print(dict[generateID(p[0],p[1])])
Buggy python submission (verdict: Time Limit Exceeded):
import math

N, M = map(int, input().split())
i = math.floor(M / N)

while i >= 1:
    if M % i == 0:
        break
    i = i - 1

print(i)


Fixed submission:
import math

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


def calculate(n, m):
    res = 1
    for i in range(1, int(math.pow(m, 0.5))):
        if m % i != 0:
            continue

        j = m // i

        if i <= m // n:
            res = max(res, i)

        if j <= m // n:
            res = max(res, j)

    print(res)


calculate(N, M)
Buggy python submission (verdict: Time Limit Exceeded):
import math

S = input().split(" ")
N = int(S[0])
K = int(S[1])

arr = [int(s) for s in input().split(" ")]


def calculate(n, k, arr):
    minsArr = []
    plusArr = []
    for ar in arr:
        if ar < 0:
            minsArr.append(ar)
        else:
            plusArr.append(ar)

    # find start index
    startIndex = -10000

    if len(minsArr) > k:
        startIndex = len(minsArr) - k
    else:
        startIndex = 0

    minValues = []
    while startIndex <= len(minsArr):
        tmpArr = arr[startIndex:startIndex + k]
        if len(tmpArr) < k:
            break
        minValue = 0

        if tmpArr[0] * tmpArr[-1] < 0:
            minValue = math.fabs(tmpArr[-1] - tmpArr[0]) + min(math.fabs(tmpArr[-1]), math.fabs(tmpArr[0]))
            a = 1
        else:
            #全部为正数
            if tmpArr[0] >= 0:
                minValue = math.fabs(tmpArr[-1])
            #全部为负数
            else:
                minValue = math.fabs(tmpArr[0])


        minValues.append(minValue)
        startIndex = startIndex + 1

    return int(min(minValues))


result = calculate(N, K, arr)
print(result)

Fixed submission:
import math
S = input().split(" ")
N = int(S[0])
K = int(S[1])
arr = [int(s) for s in input().split(" ")]


def calculate(n, k, arr):
    minsArr = []
    plusArr = []
    for ar in arr:
        if ar < 0:
            minsArr.append(ar)
        else:
            plusArr.append(ar)

    # find start index
    startIndex = -10000

    if len(minsArr) > k:
        startIndex = len(minsArr) - k
    else:
        startIndex = 0

    minValues = []
    while startIndex <= len(minsArr):

        if k == N:
            s1 = arr[0]
            s2 = arr[-1]
            minValue = math.fabs(s2 - s1) + min(math.fabs(s2), math.fabs(s1))
            minValues.append(minValue)
            break

        if startIndex + k > len(arr):
            break

        s1 = arr[startIndex]
        s2 = arr[startIndex + k - 1]

        minValue = 0

        if s1 * s2 < 0:
            minValue = math.fabs(s2 - s1) + min(math.fabs(s2), math.fabs(s1))
        else:
            # 全部为正数
            if s1 >= 0:
                minValue = math.fabs(s2)
            # 全部为负数
            else:
                minValue = math.fabs(s1)

        minValues.append(minValue)
        startIndex = startIndex + 1

    return int(min(minValues))


result = calculate(N, K, arr)
print(result)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

def calculate(S):
    minVal = len(S)
    for index,value in enumerate(S):
        s1 = S[:index]
        s2 = S[index+1:]
        if value == "W":
            count1 = s1.count("W")
            count2 = s2.count("E")

        minVal = min(count1+count2,minVal)


    return minVal


value = calculate(S)

print(value)


Fixed submission:
N = int(input())
S = input()


def calculate(S):
    SSS = []

    totalENum = S.count("E")

    for index, value in enumerate(S):
        if index == 0:
            obj = {}
            if value == "W":
                obj.__setitem__("W", 1)
                obj.__setitem__("E", 0)
            else:
                obj.__setitem__("E", 1)
                obj.__setitem__("W", 0)
            SSS.append(obj)
        else:
            obj = {}
            prevW = SSS[index - 1].__getitem__("W")
            prevE = SSS[index - 1].__getitem__("E")
            if value == "W":
                obj.__setitem__("W", prevW + 1)
                obj.__setitem__("E", prevE)
            else:
                obj.__setitem__("E", prevE + 1)
                obj.__setitem__("W", prevW)

            SSS.append(obj)

    resVal = len(S)
    for index,value in enumerate(S):
        if value == "W":
            resVal = min(resVal,SSS[index].__getitem__("W") - 1 + totalENum - SSS[index].__getitem__("E"))
        else:
            resVal = min(resVal, SSS[index].__getitem__("W") + totalENum - SSS[index].__getitem__("E"))

    return resVal


result = calculate(S)

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ARR = list(map(int,input().split()))
def calculate(n, arr):
    result = 0
    for left in range(0, n):
        right = left
        sum = arr[left]
        while right+1 < n:
            if sum ^ arr[right+1] == (sum + arr[right+1]):
                result = result + 1
                right = right + 1
                sum = sum + arr[right]
            else:
                break
        sum = sum + right - left
    print(result + n)

calculate(N, ARR)


Fixed submission:
N = int(input())
ARR = list(map(int,input().split()))
def calculate(n, arr):
    result = 0
    right = 0
    sum = arr[0]
    for left in range(0, n):
        while right+1 < n:
            if sum ^ arr[right+1] == (sum + arr[right+1]):
                right = right + 1
                sum = sum + arr[right]
            else:
                break
        result = result + right - left + 1
        sum = sum - arr[left]
    print(result)

calculate(N, ARR)
Buggy python submission (verdict: Runtime Error):
11 11
...#####...
.##.....##.
#..##.##..#
#..##.##..#
#.........#
#...###...#
.#########.
.#.#.#.#.#.
##.#.#.#.##
..##.#.##..
.##..#..##.

Fixed submission:
S = input().split(" ")
N = int(S[0])
W = int(S[1])

ARR = []

for i in range(N):
    ar = list(input())
    ARR.append(ar)


def calculate(n, w, arr):
    result = True
    hasShape = False
    for i in range(n):
        for j in range(w):
            if arr[i][j] == "#":
                hasShape = True
                sss = []
                if i -1 >= 0:
                    sss.append(arr[i-1][j])
                if i + 1 < n:
                    sss.append(arr[i+1][j])

                if j - 1 >= 0:
                    sss.append(arr[i][j-1])
                if j + 1 < w:
                    sss.append(arr[i][j+1])

                if "#" not in sss:
                    result = False
                    break

    if hasShape == False:
        print("Yes")
        return

    if result:
        print("Yes")
    else:
        print("No")


calculate(N, W, ARR)
Buggy python submission (verdict: Runtime Error):
import bisect
from scipy.special import comb

N = 5
ARR = [6, 9, 4, 2, 11]


N = 2
ARR = [100, 0]

N = int(input())
ARR = list(map(int, input().split()))


def calculate(n, arr):
    arr = sorted(arr)

    mid = arr[n - 1] / 2

    a1 = bisect.bisect_left(arr, mid)

    s1 = abs(arr[a1 - 1] - (arr[n - 1] / 2))
    s2 = abs(arr[a1] - (arr[n - 1] / 2))

    if s1 > s2:
        return arr[n - 1],arr[a1]
    else:
        return arr[n-1],arr[a1-1]


n, a = calculate(N, ARR)
print(n, a)


Fixed submission:
import bisect

N = 5
ARR = [6, 9, 4, 2, 11]


N = 2
ARR = [100, 0]

N = int(input())
ARR = list(map(int, input().split()))


def calculate(n, arr):
    arr = sorted(arr)

    mid = arr[n - 1] / 2

    a1 = bisect.bisect_left(arr, mid)

    s1 = abs(arr[a1 - 1] - (arr[n - 1] / 2))
    s2 = abs(arr[a1] - (arr[n - 1] / 2))

    if s1 > s2:
        return arr[n - 1],arr[a1]
    else:
        return arr[n-1],arr[a1-1]


n, a = calculate(N, ARR)
print(n, a)

Buggy python submission (verdict: Time Limit Exceeded):
N = 5
ARR = [6, 9, 4, 2, 11]
#
# N = 2
# ARR = [100, 0]

N = int(input())
ARR = list(map(int, input().split()))


def calculate(n, arr):
    s1 = max(arr)

    if n % 2 == 0:
        mid1, mid2 = s1 // 2, s1 // 2
    else:
        mid1, mid2 = s1 // 2, s1 // 2 + 1

    offset = 0
    find = False
    while find == False:
        find = (mid1 - offset) in arr
        if find == True:
            return s1, mid1 - offset
        find = (mid2 + offset) in arr
        if find == True:
            return s1, mid2 - offset
        offset = offset + 1


n, a = calculate(N, ARR)
print(n, a)


Fixed submission:
import bisect

N = 5
ARR = [6, 9, 4, 2, 11]


N = 2
ARR = [100, 0]

N = int(input())
ARR = list(map(int, input().split()))


def calculate(n, arr):
    arr = sorted(arr)

    mid = arr[n - 1] / 2

    a1 = bisect.bisect_left(arr, mid)

    s1 = abs(arr[a1 - 1] - (arr[n - 1] / 2))
    s2 = abs(arr[a1] - (arr[n - 1] / 2))

    if s1 > s2:
        return arr[n - 1],arr[a1]
    else:
        return arr[n-1],arr[a1-1]


n, a = calculate(N, ARR)
print(n, a)
Buggy python submission (verdict: Time Limit Exceeded):
S = input().split(" ")
N = int(S[0])
M = int(S[1])

def calculate(n,m):
    result = []
    for i in range(n):
        for j in range(m):
            count = 0
            if i - 1 >=0:
                count = count + 1

            if i + 1 <= n - 1:
                count = count + 1

            if j - 1 >= 0:
                count = count + 1

            if j + 1 <= m - 1:
                count = count + 1

            if (i -1 >= 0) and (j-1 >= 0):
                count = count + 1

            if (i - 1 >= 0) and (j + 1 <= m - 1):
                count = count + 1

            if (i + 1 <= n - 1) and (j - 1 >= 0):
                count = count + 1

            if (i + 1 <= n - 1) and (j + 1 <= m - 1):
                count = count + 1


            result.append((count+1) % 2)

    print(sum(result))
calculate(N,M)

Fixed submission:
S = input().split(" ")
N = int(S[0])
M = int(S[1])

def calculate(n,m):

    if n == 1 and m == 1:
        return 1

    if n == 1:
        return m - 2

    if m == 1:
        return n - 2

    return (n - 2) * (m - 2)
result = calculate(N,M)
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ARR = []

for i in range(N-1):
    ARR.append([int(s)for s in input().split(" ")])

def aaa(currentIndex, m, arr):
    currentStartTime = arr[currentIndex][1]
    currentCost = arr[currentIndex][0]
    currentFrequency = arr[currentIndex][2]

    i = 0
    cm = currentStartTime + currentFrequency * i
    while cm < m:
        i = i + 1
        cm = currentStartTime + currentFrequency * i

    if currentIndex == len(arr) - 1:
        return cm + currentCost
    else:
        return aaa(currentIndex + 1, cm+currentCost, arr)




def calculate(n, arr):
    for index in range(n):
        if index == n - 1:
            print(0)
            continue

        start = arr[index][1]

        result = aaa(index,start,arr)
        print(result)

calculate(N, ARR)


Fixed submission:
import math

N = int(input())
ARR = []

for i in range(N-1):
    ARR.append([int(s) for s in input().split(" ")])


def calculate(n, arr):
    result = []
    for i in range(n-1):
        m = arr[i][1] + arr[i][0]
        for j in range(i+1,n-1):
            nextStart = arr[j][1]
            nextCost = arr[j][0]
            nextFrequency = arr[j][2]

            if m <= nextStart:
                m = nextStart

            if m  > nextStart:
                m = nextStart + math.ceil((m - nextStart)/ nextFrequency)*nextFrequency

            m = m + nextCost
        result.append(m)

    result.append(0)
    return result


result = calculate(N, ARR)


for res in result:
    print(res)
Buggy python submission (verdict: Runtime Error):
N = int(input())
ArR = [int(s) for s in input().split(" ")]

def calculate(n,arr):

    dict = {}

    for ar in arr:
        a1 = ar - 1
        a2 = ar
        a3 = ar + 1

        if dict.get(a1) == None:
            dict.__setitem__(a1,1)
        else:
            dict.__setitem__(a1,dict.get(a1)+1)

        if dict.get(a2) == None:
            dict.__setitem__(a2, 1)
        else:
            dict.__setitem__(a2, dict.get(a2) + 1)

        if dict.get(a3) == None:
            dict.__setitem__(a3, 1)
        else:
            dict.__setitem__(a3, dict.get(a3) + 1)


    print(max(dict.values()))
calculate(N,ARR)

Fixed submission:
N = int(input())
ARR = [int(s) for s in input().split(" ")]

def calculate(n,arr):

    dict = {}

    for ar in arr:
        a1 = ar - 1
        a2 = ar
        a3 = ar + 1

        if dict.get(a1) == None:
            dict.__setitem__(a1,1)
        else:
            dict.__setitem__(a1,dict.get(a1)+1)

        if dict.get(a2) == None:
            dict.__setitem__(a2, 1)
        else:
            dict.__setitem__(a2, dict.get(a2) + 1)

        if dict.get(a3) == None:
            dict.__setitem__(a3, 1)
        else:
            dict.__setitem__(a3, dict.get(a3) + 1)


    print(max(dict.values()))
calculate(N,ARR)
Buggy python submission (verdict: Time Limit Exceeded):
S = input().split(" ")
N = int(S[0])
M = int(S[1])
ARR = []

for i in range(M):
    ARR.append([int(s) for s in input().split(" ")])

def calculate(n,m,arr):
    tmp = []
    tmp2 = []

    for ar in arr:
        f = ar[0]
        t = ar[1]
        if f == 1:
           tmp.append(t)
        if t == n:
           tmp2.append(f)

    res = False


    for tm in tmp:
        if tm == n:
            res = True
            break
        for tm2 in tmp2:
            if tm == tm2:
                res = True
                break

    if res:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")




calculate(N,M,ARR)


Fixed submission:
S = input().split(" ")
N = int(S[0])
M = int(S[1])
ARR = []

for i in range(M):
    ARR.append([int(s) for s in input().split(" ")])


def calculate(n,m,arr):
    tmp = []
    tmp2 = {}

    for ar in arr:
        f = ar[0]
        t = ar[1]
        if f == 1:
           tmp.append(t)

        tmp2.__setitem__((f,t),True)

    if tmp2.get((1,N)) == True:
        print("POSSIBLE")
        return

    for tm in tmp:
        if tmp2.get((tm,N)) == True:
            print("POSSIBLE")
            return


    print("IMPOSSIBLE")



calculate(N,M,ARR)

Buggy python submission (verdict: Time Limit Exceeded):
S = input().split(" ")
N = int(S[0])
M = int(S[1])
ARR = []

for i in range(M):
    ARR.append([int(s) for s in input().split(" ")])

def calculate(n,m,arr):
    tmp = []
    tmp2 = []

    for ar in arr:
        f = ar[0]
        t = ar[1]
        if f == 1:
           tmp.append(t)
        if t == n:
            tmp2.append(f)

    res = False
    for tm2 in tmp2:
        for tm in tmp:
            if tm == tm2:
                res = True
                break

    if res:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

calculate(N,M,ARR)


Fixed submission:
S = input().split(" ")
N = int(S[0])
M = int(S[1])
ARR = []

for i in range(M):
    ARR.append([int(s) for s in input().split(" ")])


def calculate(n,m,arr):
    tmp = []
    tmp2 = {}

    for ar in arr:
        f = ar[0]
        t = ar[1]
        if f == 1:
           tmp.append(t)

        tmp2.__setitem__((f,t),True)

    if tmp2.get((1,N)) == True:
        print("POSSIBLE")
        return

    for tm in tmp:
        if tmp2.get((tm,N)) == True:
            print("POSSIBLE")
            return


    print("IMPOSSIBLE")



calculate(N,M,ARR)