Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
input = sys.stdin.readline

N,M=map(int,input().split())
TATE=[tuple(map(int,input().split())) for i in range(N)]
YOKO=[tuple(map(int,input().split())) for i in range(M)]


T=[-1<<63,0,1<<63]
Y=[-1<<63,0,1<<63]

for a,b,c in TATE:
    T.append(a)
    T.append(b)
    Y.append(c)

for d,e,f in YOKO:
    T.append(d)
    Y.append(e)
    Y.append(f)

T=sorted(set(T))
Y=sorted(set(Y))

BT=[T[0]]
BY=[Y[0]]

for i in range(1,len(T)):
    BT.append(T[i]-T[i-1])
    BT.append(T[i])

for i in range(1,len(Y)):
    BY.append(Y[i]-Y[i-1])
    BY.append(Y[i])

TDICT=dict()
YDICT=dict()

LBT=len(BT)
LBY=len(BY)

for i in range(LBT):
    if i%2==0:
        TDICT[BT[i]]=i

for i in range(LBY):
    if i%2==0:
        YDICT[BY[i]]=i

MAP=[[0]*(LBY+1) for i in range(LBT+1)]

for a,b,c in TATE:
    t0=TDICT[a]
    t1=TDICT[b]
    y=YDICT[c]

    MAP[t0][y]+=1
    MAP[t0][y+1]-=1
    MAP[t1+1][y]-=1
    MAP[t1+1][y+1]+=1

for d,e,f in YOKO:
    t=TDICT[d]
    y0=YDICT[e]
    y1=YDICT[f]

    MAP[t][y0]+=1
    MAP[t+1][y0]-=1
    MAP[t][y1+1]-=1
    MAP[t+1][y1+1]+=1

for i in range(LBT):
    for j in range(1,LBY):
        MAP[i][j]+=MAP[i][j-1]

for i in range(LBY):
    for j in range(1,LBT):
        MAP[j][i]+=MAP[j-1][i]

#for m in MAP:
#    print(*m)

Q=deque()
x,y=TDICT[0],YDICT[0]
Q.append((x-1,y-1))
Q.append((x+1,y-1))
Q.append((x-1,y+1))
Q.append((x+1,y+1))
MAP[x-1][y-1]=MAP[x+1][y-1]=MAP[x-1][y+1]=MAP[x+1][y+1]=1
ANS=BT[x-1]*BY[y-1]+BT[x+1]*BY[y-1]+BT[x-1]*BY[y+1]+BT[x+1]*BY[y+1]

while Q:
    x,y=Q.pop()

    if MAP[x+1][y]==0 and MAP[x+2][y]==0:
        MAP[x+2][y]=1
        Q.append((x+2,y))
        ANS+=BT[x+2]*BY[y]

    if MAP[x-1][y]==0 and MAP[x-2][y]==0:
        MAP[x-2][y]=1
        Q.append((x-2,y))
        ANS+=BT[x-2]*BY[y]

    if MAP[x][y+1]==0 and MAP[x][y+2]==0:
        MAP[x][y+2]=1
        Q.append((x,y+2))
        ANS+=BT[x]*BY[y+2]

    if MAP[x][y-1]==0 and MAP[x][y-2]==0:
        MAP[x][y-2]=1
        Q.append((x,y-2))
        ANS+=BT[x]*BY[y-2]


    if ANS>=1<<62:
        print("INF")
        sys.exit()

print(ANS)

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

N,M=map(int,input().split())
TATE=[tuple(map(int,input().split())) for i in range(N)]
YOKO=[tuple(map(int,input().split())) for i in range(M)]


T=[-1<<63,(-1<<63)+1,0,1<<63,(1<<63)+1]
Y=[-1<<63,(-1<<63)+1,0,1<<63,(1<<63)+1]

for a,b,c in TATE:
    T.append(a)
    T.append(b)
    Y.append(c)

for d,e,f in YOKO:
    T.append(d)
    Y.append(e)
    Y.append(f)

T=sorted(set(T))
Y=sorted(set(Y))

BT=[T[0]]
BY=[Y[0]]

for i in range(1,len(T)):
    BT.append(T[i]-T[i-1])
    BT.append(T[i])

for i in range(1,len(Y)):
    BY.append(Y[i]-Y[i-1])
    BY.append(Y[i])

TDICT=dict()
YDICT=dict()

LBT=len(BT)
LBY=len(BY)

for i in range(LBT):
    if i%2==0:
        TDICT[BT[i]]=i

for i in range(LBY):
    if i%2==0:
        YDICT[BY[i]]=i

MAP=[[0]*(LBY+1) for i in range(LBT+1)]

for a,b,c in TATE:
    t0=TDICT[a]
    t1=TDICT[b]
    y=YDICT[c]

    MAP[t0][y]+=1
    MAP[t0][y+1]-=1
    MAP[t1+1][y]-=1
    MAP[t1+1][y+1]+=1

for d,e,f in YOKO:
    t=TDICT[d]
    y0=YDICT[e]
    y1=YDICT[f]

    MAP[t][y0]+=1
    MAP[t+1][y0]-=1
    MAP[t][y1+1]-=1
    MAP[t+1][y1+1]+=1

for i in range(LBT):
    for j in range(1,LBY):
        MAP[i][j]+=MAP[i][j-1]

for i in range(LBY):
    for j in range(1,LBT):
        MAP[j][i]+=MAP[j-1][i]

#for m in MAP:
#    print(*m)

Q=deque()
x,y=TDICT[0],YDICT[0]
Q.append((x-1,y-1))
Q.append((x+1,y-1))
Q.append((x-1,y+1))
Q.append((x+1,y+1))
MAP[x-1][y-1]=MAP[x+1][y-1]=MAP[x-1][y+1]=MAP[x+1][y+1]=1
ANS=BT[x-1]*BY[y-1]+BT[x+1]*BY[y-1]+BT[x-1]*BY[y+1]+BT[x+1]*BY[y+1]

while Q:
    x,y=Q.pop()

    if MAP[x+1][y]==0 and MAP[x+2][y]==0:
        MAP[x+2][y]=1
        Q.append((x+2,y))
        ANS+=BT[x+2]*BY[y]

    if MAP[x-1][y]==0 and MAP[x-2][y]==0:
        MAP[x-2][y]=1
        Q.append((x-2,y))
        ANS+=BT[x-2]*BY[y]

    if MAP[x][y+1]==0 and MAP[x][y+2]==0:
        MAP[x][y+2]=1
        Q.append((x,y+2))
        ANS+=BT[x]*BY[y+2]

    if MAP[x][y-1]==0 and MAP[x][y-2]==0:
        MAP[x][y-2]=1
        Q.append((x,y-2))
        ANS+=BT[x]*BY[y-2]


    if ANS>=1<<62:
        print("INF")
        sys.exit()

print(ANS)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

N,M=map(int,input().split())
TATE=[tuple(map(int,input().split())) for i in range(N)]
YOKO=[tuple(map(int,input().split())) for i in range(M)]


T=[-1<<63,0,1<<63]
Y=[-1<<63,0,1<<63]

for a,b,c in TATE:
    T.append(a)
    T.append(b)
    Y.append(c)

for d,e,f in YOKO:
    T.append(d)
    Y.append(e)
    Y.append(f)

T=sorted(set(T))
Y=sorted(set(Y))

BT=[T[0]]
BY=[Y[0]]

for i in range(1,len(T)):
    BT.append(T[i]-T[i-1])
    BT.append(T[i])

for i in range(1,len(Y)):
    BY.append(Y[i]-Y[i-1])
    BY.append(Y[i])

TDICT=dict()
YDICT=dict()

LBT=len(BT)
LBY=len(BY)

for i in range(LBT):
    if i%2==0:
        TDICT[BT[i]]=i

for i in range(LBY):
    if i%2==0:
        YDICT[BY[i]]=i

MAP=[[0]*(LBY+1) for i in range(LBT+1)]

for a,b,c in TATE:
    t0=TDICT[a]
    t1=TDICT[b]
    y=YDICT[c]

    MAP[t0][y]+=1
    MAP[t0][y+1]-=1
    MAP[t1+1][y]-=1
    MAP[t1+1][y+1]+=1

for d,e,f in YOKO:
    t=TDICT[d]
    y0=YDICT[e]
    y1=YDICT[f]

    MAP[t][y0]+=1
    MAP[t+1][y0]-=1
    MAP[t][y1+1]-=1
    MAP[t+1][y1+1]+=1

for i in range(LBT):
    for j in range(1,LBY):
        MAP[i][j]+=MAP[i][j-1]

for i in range(LBY):
    for j in range(1,LBT):
        MAP[j][i]+=MAP[j-1][i]

#for m in MAP:
#    print(*m)

Q=deque()
Q.append((TDICT[0],YDICT[0]))
ANS=0

while Q:
    x,y=Q.pop()
    for z,w in [(x+1,y),(x-1,y),(x,y-1),(x,y+1)]:
        if MAP[z][w]==0:
            MAP[z][w]=1
            Q.append((z,w))
            if z%2==1 and w%2==1:
                ANS+=BT[z]*BY[w]

    if ANS>=1<<62:
        print("INF")
        sys.exit()

print(ANS)

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

N,M=map(int,input().split())
TATE=[tuple(map(int,input().split())) for i in range(N)]
YOKO=[tuple(map(int,input().split())) for i in range(M)]


T=[-1<<63,(-1<<63)+1,0,1<<63,(1<<63)+1]
Y=[-1<<63,(-1<<63)+1,0,1<<63,(1<<63)+1]

for a,b,c in TATE:
    T.append(a)
    T.append(b)
    Y.append(c)

for d,e,f in YOKO:
    T.append(d)
    Y.append(e)
    Y.append(f)

T=sorted(set(T))
Y=sorted(set(Y))

BT=[T[0]]
BY=[Y[0]]

for i in range(1,len(T)):
    BT.append(T[i]-T[i-1])
    BT.append(T[i])

for i in range(1,len(Y)):
    BY.append(Y[i]-Y[i-1])
    BY.append(Y[i])

TDICT=dict()
YDICT=dict()

LBT=len(BT)
LBY=len(BY)

for i in range(LBT):
    if i%2==0:
        TDICT[BT[i]]=i

for i in range(LBY):
    if i%2==0:
        YDICT[BY[i]]=i

MAP=[[0]*(LBY+1) for i in range(LBT+1)]

for a,b,c in TATE:
    t0=TDICT[a]
    t1=TDICT[b]
    y=YDICT[c]

    MAP[t0][y]+=1
    MAP[t0][y+1]-=1
    MAP[t1+1][y]-=1
    MAP[t1+1][y+1]+=1

for d,e,f in YOKO:
    t=TDICT[d]
    y0=YDICT[e]
    y1=YDICT[f]

    MAP[t][y0]+=1
    MAP[t+1][y0]-=1
    MAP[t][y1+1]-=1
    MAP[t+1][y1+1]+=1

for i in range(LBT):
    for j in range(1,LBY):
        MAP[i][j]+=MAP[i][j-1]

for i in range(LBY):
    for j in range(1,LBT):
        MAP[j][i]+=MAP[j-1][i]

#for m in MAP:
#    print(*m)

Q=deque()
x,y=TDICT[0],YDICT[0]
Q.append((x-1,y-1))
Q.append((x+1,y-1))
Q.append((x-1,y+1))
Q.append((x+1,y+1))
MAP[x-1][y-1]=MAP[x+1][y-1]=MAP[x-1][y+1]=MAP[x+1][y+1]=1
ANS=BT[x-1]*BY[y-1]+BT[x+1]*BY[y-1]+BT[x-1]*BY[y+1]+BT[x+1]*BY[y+1]

while Q:
    x,y=Q.pop()

    if MAP[x+1][y]==0 and MAP[x+2][y]==0:
        MAP[x+2][y]=1
        Q.append((x+2,y))
        ANS+=BT[x+2]*BY[y]

    if MAP[x-1][y]==0 and MAP[x-2][y]==0:
        MAP[x-2][y]=1
        Q.append((x-2,y))
        ANS+=BT[x-2]*BY[y]

    if MAP[x][y+1]==0 and MAP[x][y+2]==0:
        MAP[x][y+2]=1
        Q.append((x,y+2))
        ANS+=BT[x]*BY[y+2]

    if MAP[x][y-1]==0 and MAP[x][y-2]==0:
        MAP[x][y-2]=1
        Q.append((x,y-2))
        ANS+=BT[x]*BY[y-2]


    if ANS>=1<<62:
        print("INF")
        sys.exit()

print(ANS)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline

N,M=map(int,input().split())
TATE=[tuple(map(int,input().split())) for i in range(N)]
YOKO=[tuple(map(int,input().split())) for i in range(M)]


T=[-1<<63,0,1<<63]
Y=[-1<<63,0,1<<63]

for a,b,c in TATE:
    T.append(a)
    T.append(b)
    Y.append(c)

for d,e,f in YOKO:
    T.append(d)
    Y.append(e)
    Y.append(f)

T=sorted(set(T))
Y=sorted(set(Y))

BT=[T[0]]
BY=[Y[0]]

for i in range(1,len(T)):
    BT.append(T[i]-T[i-1])
    BT.append(T[i])

for i in range(1,len(Y)):
    BY.append(Y[i]-Y[i-1])
    BY.append(Y[i])

TDICT=dict()
YDICT=dict()

LBT=len(BT)
LBY=len(BY)

for i in range(LBT):
    if i%2==0:
        TDICT[BT[i]]=i

for i in range(LBY):
    if i%2==0:
        YDICT[BY[i]]=i

MAP=[[0]*(LBY+1) for i in range(LBT+1)]

for a,b,c in TATE:
    t0=TDICT[a]
    t1=TDICT[b]
    y=YDICT[c]

    MAP[t0][y]+=1
    MAP[t0][y+1]-=1
    MAP[t1+1][y]-=1
    MAP[t1+1][y+1]+=1

for d,e,f in YOKO:
    t=TDICT[d]
    y0=YDICT[e]
    y1=YDICT[f]

    MAP[t][y0]+=1
    MAP[t+1][y0]-=1
    MAP[t][y1+1]-=1
    MAP[t+1][y1+1]+=1

for i in range(LBT):
    for j in range(1,LBY):
        MAP[i][j]+=MAP[i][j-1]

for i in range(LBY):
    for j in range(1,LBT):
        MAP[j][i]+=MAP[j-1][i]

#for m in MAP:
#    print(*m)

Q=deque()
Q.append((TDICT[0],YDICT[0]))
ANS=0

while Q:
    x,y=Q.pop()
    for z,w in [(x+1,y),(x-1,y),(x,y-1),(x,y+1)]:
        if MAP[z][w]==0:
            MAP[z][w]=1
            Q.append((z,w))
            if z%2==1 and w%2==1:
                ANS+=BT[z]*BY[w]

    if ANS>=1<<62:
        print("INF")
        sys.exit()

print(ANS)

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

N,M=map(int,input().split())
TATE=[tuple(map(int,input().split())) for i in range(N)]
YOKO=[tuple(map(int,input().split())) for i in range(M)]


T=[-1<<63,(-1<<63)+1,0,1<<63,(1<<63)+1]
Y=[-1<<63,(-1<<63)+1,0,1<<63,(1<<63)+1]

for a,b,c in TATE:
    T.append(a)
    T.append(b)
    Y.append(c)

for d,e,f in YOKO:
    T.append(d)
    Y.append(e)
    Y.append(f)

T=sorted(set(T))
Y=sorted(set(Y))

BT=[T[0]]
BY=[Y[0]]

for i in range(1,len(T)):
    BT.append(T[i]-T[i-1])
    BT.append(T[i])

for i in range(1,len(Y)):
    BY.append(Y[i]-Y[i-1])
    BY.append(Y[i])

TDICT=dict()
YDICT=dict()

LBT=len(BT)
LBY=len(BY)

for i in range(LBT):
    if i%2==0:
        TDICT[BT[i]]=i

for i in range(LBY):
    if i%2==0:
        YDICT[BY[i]]=i

MAP=[[0]*(LBY+1) for i in range(LBT+1)]

for a,b,c in TATE:
    t0=TDICT[a]
    t1=TDICT[b]
    y=YDICT[c]

    MAP[t0][y]+=1
    MAP[t0][y+1]-=1
    MAP[t1+1][y]-=1
    MAP[t1+1][y+1]+=1

for d,e,f in YOKO:
    t=TDICT[d]
    y0=YDICT[e]
    y1=YDICT[f]

    MAP[t][y0]+=1
    MAP[t+1][y0]-=1
    MAP[t][y1+1]-=1
    MAP[t+1][y1+1]+=1

for i in range(LBT):
    for j in range(1,LBY):
        MAP[i][j]+=MAP[i][j-1]

for i in range(LBY):
    for j in range(1,LBT):
        MAP[j][i]+=MAP[j-1][i]

#for m in MAP:
#    print(*m)

Q=deque()
x,y=TDICT[0],YDICT[0]
Q.append((x-1,y-1))
Q.append((x+1,y-1))
Q.append((x-1,y+1))
Q.append((x+1,y+1))
MAP[x-1][y-1]=MAP[x+1][y-1]=MAP[x-1][y+1]=MAP[x+1][y+1]=1
ANS=BT[x-1]*BY[y-1]+BT[x+1]*BY[y-1]+BT[x-1]*BY[y+1]+BT[x+1]*BY[y+1]

while Q:
    x,y=Q.pop()

    if MAP[x+1][y]==0 and MAP[x+2][y]==0:
        MAP[x+2][y]=1
        Q.append((x+2,y))
        ANS+=BT[x+2]*BY[y]

    if MAP[x-1][y]==0 and MAP[x-2][y]==0:
        MAP[x-2][y]=1
        Q.append((x-2,y))
        ANS+=BT[x-2]*BY[y]

    if MAP[x][y+1]==0 and MAP[x][y+2]==0:
        MAP[x][y+2]=1
        Q.append((x,y+2))
        ANS+=BT[x]*BY[y+2]

    if MAP[x][y-1]==0 and MAP[x][y-2]==0:
        MAP[x][y-2]=1
        Q.append((x,y-2))
        ANS+=BT[x]*BY[y-2]


    if ANS>=1<<62:
        print("INF")
        sys.exit()

print(ANS)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N,M=map(int,input().split())
TATE=[tuple(map(int,input().split())) for i in range(N)]
YOKO=[tuple(map(int,input().split())) for i in range(M)]


T=[-1<<63,0,1<<63]
Y=[-1<<63,0,1<<63]

for a,b,c in TATE:
    T.append(a)
    T.append(b)
    Y.append(c)

for d,e,f in YOKO:
    T.append(d)
    Y.append(e)
    Y.append(f)

T=sorted(set(T))
Y=sorted(set(Y))

BT=[T[0]]
BY=[Y[0]]

for i in range(1,len(T)):
    BT.append(T[i]-T[i-1])
    BT.append(T[i])

for i in range(1,len(Y)):
    BY.append(Y[i]-Y[i-1])
    BY.append(Y[i])

TDICT=dict()
YDICT=dict()

LBT=len(BT)
LBY=len(BY)

for i in range(LBT):
    if i%2==0:
        TDICT[BT[i]]=i

for i in range(LBY):
    if i%2==0:
        YDICT[BY[i]]=i

MAP=[[0]*(LBY+1) for i in range(LBT+1)]

for a,b,c in TATE:
    t0=TDICT[a]
    t1=TDICT[b]
    y=YDICT[c]

    MAP[t0][y]+=1
    MAP[t0][y+1]-=1
    MAP[t1+1][y]-=1
    MAP[t1+1][y+1]+=1

for d,e,f in YOKO:
    t=TDICT[d]
    y0=YDICT[e]
    y1=YDICT[f]

    MAP[t][y0]+=1
    MAP[t+1][y0]-=1
    MAP[t][y1+1]-=1
    MAP[t+1][y1+1]+=1

for i in range(LBT):
    for j in range(1,LBY):
        MAP[i][j]+=MAP[i][j-1]

for i in range(LBY):
    for j in range(1,LBT):
        MAP[j][i]+=MAP[j-1][i]

#for m in MAP:
#    print(*m)

Q=[(TDICT[0],YDICT[0])]
ANS=0

while Q:
    x,y=Q.pop()
    for z,w in [(x+1,y),(x-1,y),(x,y-1),(x,y+1)]:
        if MAP[z][w]==0:
            MAP[z][w]=1
            Q.append((z,w))
            if z%2==1 and w%2==1:
                ANS+=BT[z]*BY[w]

    if ANS>=1<<62:
        print("INF")
        sys.exit()

print(ANS)

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

N,M=map(int,input().split())
TATE=[tuple(map(int,input().split())) for i in range(N)]
YOKO=[tuple(map(int,input().split())) for i in range(M)]


T=[-1<<63,(-1<<63)+1,0,1<<63,(1<<63)+1]
Y=[-1<<63,(-1<<63)+1,0,1<<63,(1<<63)+1]

for a,b,c in TATE:
    T.append(a)
    T.append(b)
    Y.append(c)

for d,e,f in YOKO:
    T.append(d)
    Y.append(e)
    Y.append(f)

T=sorted(set(T))
Y=sorted(set(Y))

BT=[T[0]]
BY=[Y[0]]

for i in range(1,len(T)):
    BT.append(T[i]-T[i-1])
    BT.append(T[i])

for i in range(1,len(Y)):
    BY.append(Y[i]-Y[i-1])
    BY.append(Y[i])

TDICT=dict()
YDICT=dict()

LBT=len(BT)
LBY=len(BY)

for i in range(LBT):
    if i%2==0:
        TDICT[BT[i]]=i

for i in range(LBY):
    if i%2==0:
        YDICT[BY[i]]=i

MAP=[[0]*(LBY+1) for i in range(LBT+1)]

for a,b,c in TATE:
    t0=TDICT[a]
    t1=TDICT[b]
    y=YDICT[c]

    MAP[t0][y]+=1
    MAP[t0][y+1]-=1
    MAP[t1+1][y]-=1
    MAP[t1+1][y+1]+=1

for d,e,f in YOKO:
    t=TDICT[d]
    y0=YDICT[e]
    y1=YDICT[f]

    MAP[t][y0]+=1
    MAP[t+1][y0]-=1
    MAP[t][y1+1]-=1
    MAP[t+1][y1+1]+=1

for i in range(LBT):
    for j in range(1,LBY):
        MAP[i][j]+=MAP[i][j-1]

for i in range(LBY):
    for j in range(1,LBT):
        MAP[j][i]+=MAP[j-1][i]

#for m in MAP:
#    print(*m)

Q=deque()
x,y=TDICT[0],YDICT[0]
Q.append((x-1,y-1))
Q.append((x+1,y-1))
Q.append((x-1,y+1))
Q.append((x+1,y+1))
MAP[x-1][y-1]=MAP[x+1][y-1]=MAP[x-1][y+1]=MAP[x+1][y+1]=1
ANS=BT[x-1]*BY[y-1]+BT[x+1]*BY[y-1]+BT[x-1]*BY[y+1]+BT[x+1]*BY[y+1]

while Q:
    x,y=Q.pop()

    if MAP[x+1][y]==0 and MAP[x+2][y]==0:
        MAP[x+2][y]=1
        Q.append((x+2,y))
        ANS+=BT[x+2]*BY[y]

    if MAP[x-1][y]==0 and MAP[x-2][y]==0:
        MAP[x-2][y]=1
        Q.append((x-2,y))
        ANS+=BT[x-2]*BY[y]

    if MAP[x][y+1]==0 and MAP[x][y+2]==0:
        MAP[x][y+2]=1
        Q.append((x,y+2))
        ANS+=BT[x]*BY[y+2]

    if MAP[x][y-1]==0 and MAP[x][y-2]==0:
        MAP[x][y-2]=1
        Q.append((x,y-2))
        ANS+=BT[x]*BY[y-2]


    if ANS>=1<<62:
        print("INF")
        sys.exit()

print(ANS)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N,M=map(int,input().split())
TATE=[tuple(map(int,input().split())) for i in range(N)]
YOKO=[tuple(map(int,input().split())) for i in range(M)]


T=[-1<<62,0,1<<62]
Y=[-1<<62,0,1<<62]

for a,b,c in TATE:
    T.append(a)
    T.append(b)
    Y.append(c)

for d,e,f in YOKO:
    T.append(d)
    Y.append(e)
    Y.append(f)

T=sorted(set(T))
Y=sorted(set(Y))

BT=[T[0]]
BY=[Y[0]]

for i in range(1,len(T)):
    BT.append(T[i]-T[i-1])
    BT.append(T[i])

for i in range(1,len(Y)):
    BY.append(Y[i]-Y[i-1])
    BY.append(Y[i])

TDICT=dict()
YDICT=dict()

for i in range(len(BT)):
    if i%2==0:
        TDICT[BT[i]]=i

for i in range(len(BY)):
    if i%2==0:
        YDICT[BY[i]]=i

MAP=[[0]*(len(BY)+1) for i in range(len(BT)+1)]

for a,b,c in TATE:
    t0=TDICT[a]
    t1=TDICT[b]
    y=YDICT[c]

    MAP[t0][y]+=1
    MAP[t0][y+1]-=1
    MAP[t1+1][y]-=1
    MAP[t1+1][y+1]+=1

for d,e,f in YOKO:
    t=TDICT[d]
    y0=YDICT[e]
    y1=YDICT[f]

    MAP[t][y0]+=1
    MAP[t+1][y0]-=1
    MAP[t][y1+1]-=1
    MAP[t+1][y1+1]+=1

for i in range(len(BT)):
    for j in range(1,len(BY)):
        MAP[i][j]+=MAP[i][j-1]

for i in range(len(BY)):
    for j in range(1,len(BT)):
        MAP[j][i]+=MAP[j-1][i]

#for m in MAP:
#    print(*m)

Q=[(TDICT[0],YDICT[0])]
ANS=0

while Q:
    x,y=Q.pop()
    for z,w in [(x+1,y),(x-1,y),(x,y-1),(x,y+1)]:
        if 0<=z<len(BT) and 0<=w<len(BY) and MAP[z][w]==0:
            MAP[z][w]=1
            Q.append((z,w))
            if z%2==1 and w%2==1:
                ANS+=BT[z]*BY[w]

    if ANS>=1<<62:
        print("INF")
        sys.exit()

print(ANS)

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

N,M=map(int,input().split())
TATE=[tuple(map(int,input().split())) for i in range(N)]
YOKO=[tuple(map(int,input().split())) for i in range(M)]


T=[-1<<63,(-1<<63)+1,0,1<<63,(1<<63)+1]
Y=[-1<<63,(-1<<63)+1,0,1<<63,(1<<63)+1]

for a,b,c in TATE:
    T.append(a)
    T.append(b)
    Y.append(c)

for d,e,f in YOKO:
    T.append(d)
    Y.append(e)
    Y.append(f)

T=sorted(set(T))
Y=sorted(set(Y))

BT=[T[0]]
BY=[Y[0]]

for i in range(1,len(T)):
    BT.append(T[i]-T[i-1])
    BT.append(T[i])

for i in range(1,len(Y)):
    BY.append(Y[i]-Y[i-1])
    BY.append(Y[i])

TDICT=dict()
YDICT=dict()

LBT=len(BT)
LBY=len(BY)

for i in range(LBT):
    if i%2==0:
        TDICT[BT[i]]=i

for i in range(LBY):
    if i%2==0:
        YDICT[BY[i]]=i

MAP=[[0]*(LBY+1) for i in range(LBT+1)]

for a,b,c in TATE:
    t0=TDICT[a]
    t1=TDICT[b]
    y=YDICT[c]

    MAP[t0][y]+=1
    MAP[t0][y+1]-=1
    MAP[t1+1][y]-=1
    MAP[t1+1][y+1]+=1

for d,e,f in YOKO:
    t=TDICT[d]
    y0=YDICT[e]
    y1=YDICT[f]

    MAP[t][y0]+=1
    MAP[t+1][y0]-=1
    MAP[t][y1+1]-=1
    MAP[t+1][y1+1]+=1

for i in range(LBT):
    for j in range(1,LBY):
        MAP[i][j]+=MAP[i][j-1]

for i in range(LBY):
    for j in range(1,LBT):
        MAP[j][i]+=MAP[j-1][i]

#for m in MAP:
#    print(*m)

Q=deque()
x,y=TDICT[0],YDICT[0]
Q.append((x-1,y-1))
Q.append((x+1,y-1))
Q.append((x-1,y+1))
Q.append((x+1,y+1))
MAP[x-1][y-1]=MAP[x+1][y-1]=MAP[x-1][y+1]=MAP[x+1][y+1]=1
ANS=BT[x-1]*BY[y-1]+BT[x+1]*BY[y-1]+BT[x-1]*BY[y+1]+BT[x+1]*BY[y+1]

while Q:
    x,y=Q.pop()

    if MAP[x+1][y]==0 and MAP[x+2][y]==0:
        MAP[x+2][y]=1
        Q.append((x+2,y))
        ANS+=BT[x+2]*BY[y]

    if MAP[x-1][y]==0 and MAP[x-2][y]==0:
        MAP[x-2][y]=1
        Q.append((x-2,y))
        ANS+=BT[x-2]*BY[y]

    if MAP[x][y+1]==0 and MAP[x][y+2]==0:
        MAP[x][y+2]=1
        Q.append((x,y+2))
        ANS+=BT[x]*BY[y+2]

    if MAP[x][y-1]==0 and MAP[x][y-2]==0:
        MAP[x][y-2]=1
        Q.append((x,y-2))
        ANS+=BT[x]*BY[y-2]


    if ANS>=1<<62:
        print("INF")
        sys.exit()

print(ANS)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N,M=map(int,input().split())
TATE=[tuple(map(int,input().split())) for i in range(N)]
YOKO=[tuple(map(int,input().split())) for i in range(M)]


T=[-1<<62,0,1<<62]
Y=[-1<<62,0,1<<62]

for a,b,c in TATE:
    T.append(a)
    T.append(b)
    Y.append(c)

for d,e,f in YOKO:
    T.append(d)
    Y.append(e)
    Y.append(f)

T=sorted(set(T))
Y=sorted(set(Y))

BT=[T[0]]
BY=[Y[0]]

for i in range(1,len(T)):
    BT.append(T[i]-T[i-1])
    BT.append(T[i])

for i in range(1,len(Y)):
    BY.append(Y[i]-Y[i-1])
    BY.append(Y[i])

TDICT=dict()
YDICT=dict()

for i in range(len(BT)):
    if i%2==0:
        TDICT[BT[i]]=i

for i in range(len(BY)):
    if i%2==0:
        YDICT[BY[i]]=i

MAP=[[0]*(len(BY)+1) for i in range(len(BT)+1)]

for a,b,c in TATE:
    t0=TDICT[a]
    t1=TDICT[b]
    y=YDICT[c]

    MAP[t0][y]+=1
    MAP[t0][y+1]-=1
    MAP[t1+1][y]-=1
    MAP[t1+1][y+1]+=1

for d,e,f in YOKO:
    t=TDICT[d]
    y0=YDICT[e]
    y1=YDICT[f]

    MAP[t][y0]+=1
    MAP[t+1][y0]-=1
    MAP[t][y1+1]-=1
    MAP[t+1][y1+1]+=1

for i in range(len(BT)):
    for j in range(1,len(BY)):
        MAP[i][j]+=MAP[i][j-1]

for i in range(len(BY)):
    for j in range(1,len(BT)):
        MAP[j][i]+=MAP[j-1][i]

#for m in MAP:
#    print(*m)

Q=[(TDICT[0],YDICT[0])]
ANS=0

while Q:
    x,y=Q.pop()
    for z,w in [(x+1,y),(x-1,y),(x,y-1),(x,y+1)]:
        if 0<=z<len(BT) and 0<=w<len(BY) and MAP[z][w]==0:
            MAP[z][w]=1
            Q.append((z,w))
            if z%2==1 and w%2==1:
                ANS+=BT[z]*BY[w]

if ANS>=1<<62:
    print("INF")
else:
    print(ANS)

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

N,M=map(int,input().split())
TATE=[tuple(map(int,input().split())) for i in range(N)]
YOKO=[tuple(map(int,input().split())) for i in range(M)]


T=[-1<<63,(-1<<63)+1,0,1<<63,(1<<63)+1]
Y=[-1<<63,(-1<<63)+1,0,1<<63,(1<<63)+1]

for a,b,c in TATE:
    T.append(a)
    T.append(b)
    Y.append(c)

for d,e,f in YOKO:
    T.append(d)
    Y.append(e)
    Y.append(f)

T=sorted(set(T))
Y=sorted(set(Y))

BT=[T[0]]
BY=[Y[0]]

for i in range(1,len(T)):
    BT.append(T[i]-T[i-1])
    BT.append(T[i])

for i in range(1,len(Y)):
    BY.append(Y[i]-Y[i-1])
    BY.append(Y[i])

TDICT=dict()
YDICT=dict()

LBT=len(BT)
LBY=len(BY)

for i in range(LBT):
    if i%2==0:
        TDICT[BT[i]]=i

for i in range(LBY):
    if i%2==0:
        YDICT[BY[i]]=i

MAP=[[0]*(LBY+1) for i in range(LBT+1)]

for a,b,c in TATE:
    t0=TDICT[a]
    t1=TDICT[b]
    y=YDICT[c]

    MAP[t0][y]+=1
    MAP[t0][y+1]-=1
    MAP[t1+1][y]-=1
    MAP[t1+1][y+1]+=1

for d,e,f in YOKO:
    t=TDICT[d]
    y0=YDICT[e]
    y1=YDICT[f]

    MAP[t][y0]+=1
    MAP[t+1][y0]-=1
    MAP[t][y1+1]-=1
    MAP[t+1][y1+1]+=1

for i in range(LBT):
    for j in range(1,LBY):
        MAP[i][j]+=MAP[i][j-1]

for i in range(LBY):
    for j in range(1,LBT):
        MAP[j][i]+=MAP[j-1][i]

#for m in MAP:
#    print(*m)

Q=deque()
x,y=TDICT[0],YDICT[0]
Q.append((x-1,y-1))
Q.append((x+1,y-1))
Q.append((x-1,y+1))
Q.append((x+1,y+1))
MAP[x-1][y-1]=MAP[x+1][y-1]=MAP[x-1][y+1]=MAP[x+1][y+1]=1
ANS=BT[x-1]*BY[y-1]+BT[x+1]*BY[y-1]+BT[x-1]*BY[y+1]+BT[x+1]*BY[y+1]

while Q:
    x,y=Q.pop()

    if MAP[x+1][y]==0 and MAP[x+2][y]==0:
        MAP[x+2][y]=1
        Q.append((x+2,y))
        ANS+=BT[x+2]*BY[y]

    if MAP[x-1][y]==0 and MAP[x-2][y]==0:
        MAP[x-2][y]=1
        Q.append((x-2,y))
        ANS+=BT[x-2]*BY[y]

    if MAP[x][y+1]==0 and MAP[x][y+2]==0:
        MAP[x][y+2]=1
        Q.append((x,y+2))
        ANS+=BT[x]*BY[y+2]

    if MAP[x][y-1]==0 and MAP[x][y-2]==0:
        MAP[x][y-2]=1
        Q.append((x,y-2))
        ANS+=BT[x]*BY[y-2]


    if ANS>=1<<62:
        print("INF")
        sys.exit()

print(ANS)