Buggy python submission (verdict: Runtime Error):
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    dir = [(-1,0),(1,0),(0,-1),(0,1)]
    n,m = map(int,ipt().split())
    xb = []
    yb = []
    xs = []
    ys = []
    for i in range(n):
        a,b,c = map(int,ipt().split())
        xb.append((a,b,c))
        xs.append(a)
        xs.append(b)
        ys.append(c)
    for j in range(m):
        d,e,f = map(int,ipt().split())
        yb.append((d,e,f))
        xs.append(d)
        ys.append(e)
        ys.append(f)
    xs = sorted(list(set(xs)))
    ys = sorted(list(set(ys)))
    lx = len(xs)
    ly = len(ys)

    dix = dict()
    diy = dict()

    for i,xi in enumerate(xs):
        dix[xi] = i
    for i,yi in enumerate(ys):
        diy[yi] = i

    brd = [[1]*(ly*2-1) for _ in range(lx*2-1)]
    for a,b,c in xb:
        xa = dix[a]
        xb = dix[b]
        xc = diy[c]
        for i in range(xa,xb):
            brd[2*i+1][xc*2] = 0
    for d,e,f in yb:
        xd = dix[d]
        xe = diy[e]
        xf = diy[f]
        for i in range(xe,xf):
            brd[xd*2][2*i+1] = 0
    for i,xi in enumerate(xs[1::]):
        for j,yj in enumerate(ys[1::]):
            brd[2*i+1][2*j+1] = (yj-ys[j])*(xi-xs[i])

    sx = bisect.bisect_left(xs,0)
    sy = bisect.bisect_left(ys,0)
    if sx == 0 or sy == 0:
        print("INF")
        exit()
    q = []
    q.append((sx*2-1,sy*2-1))
    ans = brd[sx*2-1][sy*2-1]
    brd[sx*2-1][sy*2-1] = 0
    while q:
        qx,qy = q.pop()
        for dx,dy in dir:
            nx = qx+dx
            ny = qy+dy
            if brd[nx][ny]:
                if nx == 0 or nx == lx*2-2 or ny == 0 or ny == ly*2-2:
                    print("INF")
                    exit()
                nx += dx
                ny += dy
                if brd[nx][ny]:
                    ans += brd[nx][ny]
                    brd[nx][ny] = 0
                    q.append((nx,ny))
        #print(qx,qy,q)
    print(ans)


    return None

if __name__ == '__main__':
    main()


Fixed submission:
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    dir = [(-1,0),(1,0),(0,-1),(0,1)]
    n,m = map(int,ipt().split())
    xb = []
    yb = []
    xs = []
    ys = []
    for i in range(n):
        a,b,c = map(int,ipt().split())
        xb.append((a,b,c))
        xs.append(a)
        xs.append(b)
        ys.append(c)
    for j in range(m):
        d,e,f = map(int,ipt().split())
        yb.append((d,e,f))
        xs.append(d)
        ys.append(e)
        ys.append(f)
    xs = sorted(list(set(xs)))
    ys = sorted(list(set(ys)))
    lx = len(xs)
    ly = len(ys)

    dix = dict()
    diy = dict()

    for i,xi in enumerate(xs):
        dix[xi] = i
    for i,yi in enumerate(ys):
        diy[yi] = i

    brd = [[1]*(ly*2-1) for _ in range(lx*2-1)]
    for a,b,c in xb:
        xa = dix[a]
        xb = dix[b]
        xc = diy[c]
        for i in range(xa,xb):
            brd[2*i+1][xc*2] = 0
    for d,e,f in yb:
        xd = dix[d]
        xe = diy[e]
        xf = diy[f]
        for i in range(xe,xf):
            brd[xd*2][2*i+1] = 0
    for i,xi in enumerate(xs[1::]):
        for j,yj in enumerate(ys[1::]):
            brd[2*i+1][2*j+1] = (yj-ys[j])*(xi-xs[i])

    sx = bisect.bisect_left(xs,0)
    sy = bisect.bisect_left(ys,0)
    if sx == 0 or sy == 0 or sx == lx or sy == ly:
        print("INF")
        exit()
    q = []
    q.append((sx*2-1,sy*2-1))
    ans = brd[sx*2-1][sy*2-1]
    brd[sx*2-1][sy*2-1] = 0
    while q:
        qx,qy = q.pop()
        for dx,dy in dir:
            nx = qx+dx
            ny = qy+dy
            if brd[nx][ny]:
                if nx == 0 or nx == lx*2-2 or ny == 0 or ny == ly*2-2:
                    print("INF")
                    exit()
                nx += dx
                ny += dy
                if brd[nx][ny]:
                    ans += brd[nx][ny]
                    brd[nx][ny] = 0
                    q.append((nx,ny))
        #print(qx,qy,q)
    print(ans)


    return None

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math
import numpy as np
import queue
from collections import deque
import heapq
drc = [(-1,0),(1,0),(0,-1),(0,1)]

n, m = map(int,input().split())
tat = [list(map(int,input().split())) for i in range(n)]
yok = [list(map(int,input().split())) for i in range(m)]
xs = []
ys = []
for i in tat:
    if not i[0] in xs:
        xs.append(i[0])
    if not i[1] in xs:
        xs.append(i[1])
    if not i[2] in ys:
        ys.append(i[2])
for i in yok:
    if not i[0] in xs:
        xs.append(i[0])
    if not i[1] in ys:
        ys.append(i[1])
    if not i[2] in ys:
        ys.append(i[2])

xs.sort()
ys.sort()
lx = len(xs)
ly = len(ys)

#座標の圧縮
cps = [[0 for i in range(ly*2)] for j in range(lx*2)]
for i in tat:
    yi = ys.index(i[2])
    for j in range(xs.index(i[0]),xs.index(i[1])):
        cps[2*j+1][yi*2] = -1
for i in yok:
    xi = xs.index(i[0])
    for j in range(ys.index(i[1]),ys.index(i[2])):
        cps[xi*2][2*j+1] = -1
for i in range(lx-1):
    for j in range(ly-1):
        cps[2*i+1][2*j+1] = (xs[i+1]-xs[i])*(ys[j+1]-ys[j])
for i in range(lx):
    cps[i][-1] = -2
for j in range(ly):
    cps[-1][j] = -2


x0 = -1
y0 = -1
for i,x in enumerate(xs):
    if x > 0:
        x0 = i-1
        break
for i,y in enumerate(ys):
    if y > 0:
        y0 = i-1
        break

if x0 < 0 or y0 < 0:
    print("INF")
    exit()

ans = cps[x0*2+1][y0*2+1]
cps[x0*2+1][y0*2+1] = -1
q = queue.Queue()
q.put((x0*2+1,y0*2+1))
while not q.empty():
    x,y = q.get()
    for dx,dy in drc:
        if cps[x+dx][y+dy] == 0:
            if cps[x+dx*2][y+dy*2] > 0:
                q.put((x+dx*2,y+dy*2))
                ans += cps[x+dx*2][y+dy*2]
                cps[x+dx*2][y+dy*2] = -1
            elif cps[x+dx*2][y+dy*2] == -2:
                print("INF")
                exit()

print(ans)


Fixed submission:
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    dir = [(-1,0),(1,0),(0,-1),(0,1)]
    n,m = map(int,ipt().split())
    xb = []
    yb = []
    xs = []
    ys = []
    for i in range(n):
        a,b,c = map(int,ipt().split())
        xb.append((a,b,c))
        xs.append(a)
        xs.append(b)
        ys.append(c)
    for j in range(m):
        d,e,f = map(int,ipt().split())
        yb.append((d,e,f))
        xs.append(d)
        ys.append(e)
        ys.append(f)
    xs = sorted(list(set(xs)))
    ys = sorted(list(set(ys)))
    lx = len(xs)
    ly = len(ys)

    dix = dict()
    diy = dict()

    for i,xi in enumerate(xs):
        dix[xi] = i
    for i,yi in enumerate(ys):
        diy[yi] = i

    brd = [[1]*(ly*2-1) for _ in range(lx*2-1)]
    for a,b,c in xb:
        xa = dix[a]
        xb = dix[b]
        xc = diy[c]
        for i in range(xa,xb):
            brd[2*i+1][xc*2] = 0
    for d,e,f in yb:
        xd = dix[d]
        xe = diy[e]
        xf = diy[f]
        for i in range(xe,xf):
            brd[xd*2][2*i+1] = 0
    for i,xi in enumerate(xs[1::]):
        for j,yj in enumerate(ys[1::]):
            brd[2*i+1][2*j+1] = (yj-ys[j])*(xi-xs[i])

    sx = bisect.bisect_left(xs,0)
    sy = bisect.bisect_left(ys,0)
    if sx == 0 or sy == 0 or sx == lx or sy == ly:
        print("INF")
        exit()
    q = []
    q.append((sx*2-1,sy*2-1))
    ans = brd[sx*2-1][sy*2-1]
    brd[sx*2-1][sy*2-1] = 0
    while q:
        qx,qy = q.pop()
        for dx,dy in dir:
            nx = qx+dx
            ny = qy+dy
            if brd[nx][ny]:
                if nx == 0 or nx == lx*2-2 or ny == 0 or ny == ly*2-2:
                    print("INF")
                    exit()
                nx += dx
                ny += dy
                if brd[nx][ny]:
                    ans += brd[nx][ny]
                    brd[nx][ny] = 0
                    q.append((nx,ny))
        #print(qx,qy,q)
    print(ans)


    return None

if __name__ == '__main__':
    main()