Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, Q = [int(v) for v in input().split()]

    va = [N-1] * (N - 1)
    ha = [N-1] * (N - 1)

    count = 0
    black = (N - 2) * (N - 2)
    vmax = N - 1
    hmax = N - 1
    for i in range(Q):
        a, b = [int(v)-1 for v in input().split()]
        if a == 0:
            i = ha[b]
            if vmax > b:
                vmax = b
                va[1:i] = [b] * (i - 1)
            count += i - 1
        else:
            i = va[b]
            if hmax > b:
                hmax = b
                ha[1:i] = [b] * (i - 1)
            count += i - 1

    print(black - count)

main()

Fixed submission:
def main():
    N, Q = [int(v) for v in input().split()]

    Query = [[int(v)-1 for v in input().split()] for _ in range(Q)]

    rows = [N-1] * (N - 1)
    cols = [N-1] * (N - 1)

    black = (N - 2) * (N - 2)
    min_row = N - 1
    min_col = N - 1

    for ty, x in Query:
        if ty == 0:
            if x < min_col:
                for j in range(x, min_col):
                    rows[j] = min_row
                min_col = x
            black -= rows[x] - 1
        else:
            if x < min_row:
                for j in range(x, min_row):
                    cols[j] = min_col
                min_row = x
            black -= cols[x] - 1

    print(black)

main()

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = [int(v) for v in input().split()]

va = [N-1] * (N - 1)
ha = [N-1] * (N - 1)

count = 0
black = (N - 2) * (N - 2)
vmax = N - 1
hmax = N - 1
for i in range(Q):
    a, b = [int(v)-1 for v in input().split()]
    if a == 0:
        i = ha[b]
        if vmax > b:
            vmax = b
            va[1:i] = [b] * (i - 1)
        count += i - 1
    else:
        i = va[b]
        if hmax > b:
            hmax = b
            ha[1:i] = [b] * (i - 1)
        count += i - 1

print(black - count)


Fixed submission:
def main():
    N, Q = [int(v) for v in input().split()]

    Query = [[int(v)-1 for v in input().split()] for _ in range(Q)]

    rows = [N-1] * (N - 1)
    cols = [N-1] * (N - 1)

    black = (N - 2) * (N - 2)
    min_row = N - 1
    min_col = N - 1

    for ty, x in Query:
        if ty == 0:
            if x < min_col:
                for j in range(x, min_col):
                    rows[j] = min_row
                min_col = x
            black -= rows[x] - 1
        else:
            if x < min_row:
                for j in range(x, min_row):
                    cols[j] = min_col
                min_row = x
            black -= cols[x] - 1

    print(black)

main()

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = [int(v) for v in input().split()]

va = [N-1] * (N - 1)
ha = [N-1] * (N - 1)

count = 0
black = (N - 2) * (N - 2)
vmax = N - 1
hmax = N - 1
for i in range(Q):
    a, b = [int(v)-1 for v in input().split()]
    if a == 0:
        if vmax > b:
            vmax = b
            va[1:ha[b]] = [b] * (ha[b] - 1)
        count += ha[b] - 1
    else:
        if hmax > b:
            hmax = b
            ha[1:va[b]] = [b] * (va[b] - 1)
        count += va[b] - 1

print(black - count)


Fixed submission:
def main():
    N, Q = [int(v) for v in input().split()]

    Query = [[int(v)-1 for v in input().split()] for _ in range(Q)]

    rows = [N-1] * (N - 1)
    cols = [N-1] * (N - 1)

    black = (N - 2) * (N - 2)
    min_row = N - 1
    min_col = N - 1

    for ty, x in Query:
        if ty == 0:
            if x < min_col:
                for j in range(x, min_col):
                    rows[j] = min_row
                min_col = x
            black -= rows[x] - 1
        else:
            if x < min_row:
                for j in range(x, min_row):
                    cols[j] = min_col
                min_row = x
            black -= cols[x] - 1

    print(black)

main()

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = [int(v) for v in input().split()]

va = [N-1] * (N - 1)
ha = [N-1] * (N - 1)

count = 0
black = (N - 2) * (N - 2)
vmax = N - 1
hmax = N - 1
for i in range(Q):
    a, b = [int(v)-1 for v in input().split()]
    if a == 0:
        if vmax > b:
            vmax = b
            for j in range(1, ha[b]):
                va[j] = b
        count += ha[b] - 1
    else:
        if hmax > b:
            hmax = b
            for j in range(1, va[b]):
                ha[j] = b
        count += va[b] - 1

print(black - count)


Fixed submission:
def main():
    N, Q = [int(v) for v in input().split()]

    Query = [[int(v)-1 for v in input().split()] for _ in range(Q)]

    rows = [N-1] * (N - 1)
    cols = [N-1] * (N - 1)

    black = (N - 2) * (N - 2)
    min_row = N - 1
    min_col = N - 1

    for ty, x in Query:
        if ty == 0:
            if x < min_col:
                for j in range(x, min_col):
                    rows[j] = min_row
                min_col = x
            black -= rows[x] - 1
        else:
            if x < min_row:
                for j in range(x, min_row):
                    cols[j] = min_col
                min_row = x
            black -= cols[x] - 1

    print(black)

main()

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = [int(v) for v in input().split()]

va = [N-1] * (N - 1)
ha = [N-1] * (N - 1)

count = 0
black = (N - 2) * (N - 2)
for i in range(Q):
    a, b = [int(v)-1 for v in input().split()]

    if a == 0:
        for j in range(1, ha[b]):
            if va[j] <= b:
                break
            va[j] = b
        count += ha[b] - 1
    else:
        for j in range(1, va[b]):
            if ha[j] <= b:
                break
            ha[j] = b
        count += va[b] - 1

print(black - count)


Fixed submission:
def main():
    N, Q = [int(v) for v in input().split()]

    Query = [[int(v)-1 for v in input().split()] for _ in range(Q)]

    rows = [N-1] * (N - 1)
    cols = [N-1] * (N - 1)

    black = (N - 2) * (N - 2)
    min_row = N - 1
    min_col = N - 1

    for ty, x in Query:
        if ty == 0:
            if x < min_col:
                for j in range(x, min_col):
                    rows[j] = min_row
                min_col = x
            black -= rows[x] - 1
        else:
            if x < min_row:
                for j in range(x, min_row):
                    cols[j] = min_col
                min_row = x
            black -= cols[x] - 1

    print(black)

main()