Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n,m=map(int,input().split())
  def hashh(x1,y1,x2,y2):
      if x1>x2:
          x1,y1,x2,y2=x2,y2,x1,y1
      if x1==x2 and y1>y2:
          x1,y1,x2,y2=x2,y2,x1,y1
      return x1*27000000000+y1*9000000+x2*3000+y2
  abc_l=[list(map(int,input().split()))for _ in range(n)]
  def_l=[list(map(int,input().split()))for _ in range(m)]
  x=[0]
  y=[0]
  for a,b,c in abc_l:
      x.append(a)
      x.append(b)
      y.append(c)
  for d,e,f in def_l:
      x.append(d)
      y.append(e)
      y.append(f)
  x=sorted(list(set(x)))
  y=sorted(list(set(y)))
  h=len(x)+1
  w=len(y)+1
  dicx={}
  dicy={}
  for i in range(len(x)):dicx[x[i]]=i
  for i in range(len(y)):dicy[y[i]]=i
  grid=[[0]*w for _ in range(h)]
  dont=set()
  for a,b,c in abc_l:
      for i in range(dicx[a],dicx[b]):
          dont.add(hashh(i+1,dicy[c],i+1,dicy[c]+1))
  for d,e,f in def_l:
      for j in range(dicy[e],dicy[f]):
          dont.add(hashh(dicx[d],j+1,dicx[d]+1,j+1))
  if dicx[0]==0 or dicx[0]==h-1 or dicy[0]==0 or dicy[0]==w-1:
      exit(print("INF"))
  stack=[(dicx[0],dicy[0])]
  grid[dicx[0]][dicy[0]]=1
  ans=0
  for sx,sy in stack:
      ans+=(x[sx]-x[sx-1])*(y[sy]-y[sy-1])
      for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
          tx=sx+dx
          ty=sy+dy
          if grid[tx][ty]:continue
          if hashh(sx,sy,tx,ty) in dont:continue
          if tx==0 or tx==h-1 or ty==0 or ty==w-1:
              exit(print("INF"))
          grid[tx][ty]=1
          stack.append((tx,ty))
  print(ans)
main()


Fixed submission:
n,m=map(int,input().split())
def hashh(x,y,f):
    return (x*3000+y)*2+f
abc_l=[list(map(int,input().split()))for _ in range(n)]
def_l=[list(map(int,input().split()))for _ in range(m)]
x=[0]
y=[0]
for a,b,c in abc_l:
    x.append(a)
    x.append(b)
    y.append(c)
for d,e,f in def_l:
    x.append(d)
    y.append(e)
    y.append(f)
x=sorted(list(set(x)))
y=sorted(list(set(y)))
h=len(x)+1
w=len(y)+1
dicx={}
dicy={}
for i in range(len(x)):dicx[x[i]]=i
for i in range(len(y)):dicy[y[i]]=i
grid=[[0]*w for _ in range(h)]
dont=set()
for a,b,c in abc_l:
    for i in range(dicx[a],dicx[b]):
        dont.add(hashh(i+1,dicy[c],1))
for d,e,f in def_l:
    for j in range(dicy[e],dicy[f]):
        dont.add(hashh(dicx[d],j+1,0))
if dicx[0]==0 or dicx[0]==h-1 or dicy[0]==0 or dicy[0]==w-1:
    exit(print("INF"))
stack=[(dicx[0],dicy[0])]
grid[dicx[0]][dicy[0]]=1
ans=0
for sx,sy in stack:
    ans+=(x[sx]-x[sx-1])*(y[sy]-y[sy-1])
    for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
        tx=sx+dx
        ty=sy+dy
        if grid[tx][ty]:continue
        if hashh(min(sx,tx),min(sy,ty),1 if sx==tx else 0) in dont:continue
        if tx==0 or tx==h-1 or ty==0 or ty==w-1:
            exit(print("INF"))
        grid[tx][ty]=1
        stack.append((tx,ty))
print(ans)

Buggy python submission (verdict: Runtime Error):
def main():
n,m=map(int,input().split())
  def hashh(x1,y1,x2,y2):
      if x1>x2:
          x1,y1,x2,y2=x2,y2,x1,y1
      if x1==x2 and y1>y2:
          x1,y1,x2,y2=x2,y2,x1,y1
      return x1*27000000000+y1*9000000+x2*3000+y2
  abc_l=[list(map(int,input().split()))for _ in range(n)]
  def_l=[list(map(int,input().split()))for _ in range(m)]
  x=[0]
  y=[0]
  for a,b,c in abc_l:
      x.append(a)
      x.append(b)
      y.append(c)
  for d,e,f in def_l:
      x.append(d)
      y.append(e)
      y.append(f)
  x=sorted(list(set(x)))
  y=sorted(list(set(y)))
  h=len(x)+1
  w=len(y)+1
  dicx={}
  dicy={}
  for i in range(len(x)):dicx[x[i]]=i
  for i in range(len(y)):dicy[y[i]]=i
  grid=[[0]*w for _ in range(h)]
  dont=set()
  for a,b,c in abc_l:
      for i in range(dicx[a],dicx[b]):
          dont.add(hashh(i+1,dicy[c],i+1,dicy[c]+1))
  for d,e,f in def_l:
      for j in range(dicy[e],dicy[f]):
          dont.add(hashh(dicx[d],j+1,dicx[d]+1,j+1))
  if dicx[0]==0 or dicx[0]==h-1 or dicy[0]==0 or dicy[0]==w-1:
      exit(print("INF"))
  stack=[(dicx[0],dicy[0])]
  grid[dicx[0]][dicy[0]]=1
  ans=0
  for sx,sy in stack:
      ans+=(x[sx]-x[sx-1])*(y[sy]-y[sy-1])
      for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
          tx=sx+dx
          ty=sy+dy
          if grid[tx][ty]:continue
          if hashh(sx,sy,tx,ty) in dont:continue
          if tx==0 or tx==h-1 or ty==0 or ty==w-1:
              exit(print("INF"))
          grid[tx][ty]=1
          stack.append((tx,ty))
  print(ans)
main()


Fixed submission:
n,m=map(int,input().split())
def hashh(x,y,f):
    return (x*3000+y)*2+f
abc_l=[list(map(int,input().split()))for _ in range(n)]
def_l=[list(map(int,input().split()))for _ in range(m)]
x=[0]
y=[0]
for a,b,c in abc_l:
    x.append(a)
    x.append(b)
    y.append(c)
for d,e,f in def_l:
    x.append(d)
    y.append(e)
    y.append(f)
x=sorted(list(set(x)))
y=sorted(list(set(y)))
h=len(x)+1
w=len(y)+1
dicx={}
dicy={}
for i in range(len(x)):dicx[x[i]]=i
for i in range(len(y)):dicy[y[i]]=i
grid=[[0]*w for _ in range(h)]
dont=set()
for a,b,c in abc_l:
    for i in range(dicx[a],dicx[b]):
        dont.add(hashh(i+1,dicy[c],1))
for d,e,f in def_l:
    for j in range(dicy[e],dicy[f]):
        dont.add(hashh(dicx[d],j+1,0))
if dicx[0]==0 or dicx[0]==h-1 or dicy[0]==0 or dicy[0]==w-1:
    exit(print("INF"))
stack=[(dicx[0],dicy[0])]
grid[dicx[0]][dicy[0]]=1
ans=0
for sx,sy in stack:
    ans+=(x[sx]-x[sx-1])*(y[sy]-y[sy-1])
    for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
        tx=sx+dx
        ty=sy+dy
        if grid[tx][ty]:continue
        if hashh(min(sx,tx),min(sy,ty),1 if sx==tx else 0) in dont:continue
        if tx==0 or tx==h-1 or ty==0 or ty==w-1:
            exit(print("INF"))
        grid[tx][ty]=1
        stack.append((tx,ty))
print(ans)

Buggy python submission (verdict: Runtime Error):
def main():
n,m=map(int,input().split())
  def hashh(x1,y1,x2,y2):
      if x1>x2:
          x1,y1,x2,y2=x2,y2,x1,y1
      if x1==x2 and y1>y2:
          x1,y1,x2,y2=x2,y2,x1,y1
      return x1*27000000000+y1*9000000+x2*3000+y2
  abc_l=[list(map(int,input().split()))for _ in range(n)]
  def_l=[list(map(int,input().split()))for _ in range(m)]
  x=[0]
  y=[0]
  for a,b,c in abc_l:
      x.append(a)
      x.append(b)
      y.append(c)
  for d,e,f in def_l:
      x.append(d)
      y.append(e)
      y.append(f)
  x=sorted(list(set(x)))
  y=sorted(list(set(y)))
  h=len(x)+1
  w=len(y)+1
  dicx={}
  dicy={}
  for i in range(len(x)):dicx[x[i]]=i
  for i in range(len(y)):dicy[y[i]]=i
  grid=[[0]*w for _ in range(h)]
  dont=set()
  for a,b,c in abc_l:
      for i in range(dicx[a],dicx[b]):
          dont.add(hashh(i+1,dicy[c],i+1,dicy[c]+1))
  for d,e,f in def_l:
      for j in range(dicy[e],dicy[f]):
          dont.add(hashh(dicx[d],j+1,dicx[d]+1,j+1))
  if dicx[0]==0 or dicx[0]==h-1 or dicy[0]==0 or dicy[0]==w-1:
      exit(print("INF"))
  stack=[(dicx[0],dicy[0])]
  grid[dicx[0]][dicy[0]]=1
  ans=0
  for sx,sy in stack:
      ans+=(x[sx]-x[sx-1])*(y[sy]-y[sy-1])
      for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
          tx=sx+dx
          ty=sy+dy
          if grid[tx][ty]:continue
          if hashh(sx,sy,tx,ty) in dont:continue
          if tx==0 or tx==h-1 or ty==0 or ty==w-1:
              exit(print("INF"))
          grid[tx][ty]=1
          stack.append((tx,ty))
  print(ans)
main()

Fixed submission:
n,m=map(int,input().split())
def hashh(x,y,f):
    return (x*3000+y)*2+f
abc_l=[list(map(int,input().split()))for _ in range(n)]
def_l=[list(map(int,input().split()))for _ in range(m)]
x=[0]
y=[0]
for a,b,c in abc_l:
    x.append(a)
    x.append(b)
    y.append(c)
for d,e,f in def_l:
    x.append(d)
    y.append(e)
    y.append(f)
x=sorted(list(set(x)))
y=sorted(list(set(y)))
h=len(x)+1
w=len(y)+1
dicx={}
dicy={}
for i in range(len(x)):dicx[x[i]]=i
for i in range(len(y)):dicy[y[i]]=i
grid=[[0]*w for _ in range(h)]
dont=set()
for a,b,c in abc_l:
    for i in range(dicx[a],dicx[b]):
        dont.add(hashh(i+1,dicy[c],1))
for d,e,f in def_l:
    for j in range(dicy[e],dicy[f]):
        dont.add(hashh(dicx[d],j+1,0))
if dicx[0]==0 or dicx[0]==h-1 or dicy[0]==0 or dicy[0]==w-1:
    exit(print("INF"))
stack=[(dicx[0],dicy[0])]
grid[dicx[0]][dicy[0]]=1
ans=0
for sx,sy in stack:
    ans+=(x[sx]-x[sx-1])*(y[sy]-y[sy-1])
    for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
        tx=sx+dx
        ty=sy+dy
        if grid[tx][ty]:continue
        if hashh(min(sx,tx),min(sy,ty),1 if sx==tx else 0) in dont:continue
        if tx==0 or tx==h-1 or ty==0 or ty==w-1:
            exit(print("INF"))
        grid[tx][ty]=1
        stack.append((tx,ty))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
def hashh(x1,y1,x2,y2):
    if x1>x2:
        x1,y1,x2,y2=x2,y2,x1,y1
    if x1==x2 and y1>y2:
        x1,y1,x2,y2=x2,y2,x1,y1
    return x1*27000000000+y1*9000000+x2*3000+y2
abc_l=[list(map(int,input().split()))for _ in range(n)]
def_l=[list(map(int,input().split()))for _ in range(m)]
x=[0]
y=[0]
for a,b,c in abc_l:
    x.append(a)
    x.append(b)
    y.append(c)
for d,e,f in def_l:
    x.append(d)
    y.append(e)
    y.append(f)
x=sorted(list(set(x)))
y=sorted(list(set(y)))
h=len(x)+1
w=len(y)+1
dicx={}
dicy={}
for i in range(len(x)):dicx[x[i]]=i
for i in range(len(y)):dicy[y[i]]=i
grid=[[0]*w for _ in range(h)]
dont=set()
for a,b,c in abc_l:
    for i in range(dicx[a],dicx[b]):
        dont.add(hashh(i+1,dicy[c],i+1,dicy[c]+1))
for d,e,f in def_l:
    for j in range(dicy[e],dicy[f]):
        dont.add(hashh(dicx[d],j+1,dicx[d]+1,j+1))
if dicx[0]==0 or dicx[0]==h-1 or dicy[0]==0 or dicy[0]==w-1:
    exit(print("INF"))
stack=[(dicx[0],dicy[0])]
grid[dicx[0]][dicy[0]]=1
ans=0
for sx,sy in stack:
    ans+=(x[sx]-x[sx-1])*(y[sy]-y[sy-1])
    for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
        tx=sx+dx
        ty=sy+dy
        if grid[tx][ty]:continue
        if hashh(sx,sy,tx,ty) in dont:continue
        if tx==0 or tx==h-1 or ty==0 or ty==w-1:
            exit(print("INF"))
        grid[tx][ty]=1
        stack.append((tx,ty))
print(ans)


Fixed submission:
n,m=map(int,input().split())
def hashh(x,y,f):
    return (x*3000+y)*2+f
abc_l=[list(map(int,input().split()))for _ in range(n)]
def_l=[list(map(int,input().split()))for _ in range(m)]
x=[0]
y=[0]
for a,b,c in abc_l:
    x.append(a)
    x.append(b)
    y.append(c)
for d,e,f in def_l:
    x.append(d)
    y.append(e)
    y.append(f)
x=sorted(list(set(x)))
y=sorted(list(set(y)))
h=len(x)+1
w=len(y)+1
dicx={}
dicy={}
for i in range(len(x)):dicx[x[i]]=i
for i in range(len(y)):dicy[y[i]]=i
grid=[[0]*w for _ in range(h)]
dont=set()
for a,b,c in abc_l:
    for i in range(dicx[a],dicx[b]):
        dont.add(hashh(i+1,dicy[c],1))
for d,e,f in def_l:
    for j in range(dicy[e],dicy[f]):
        dont.add(hashh(dicx[d],j+1,0))
if dicx[0]==0 or dicx[0]==h-1 or dicy[0]==0 or dicy[0]==w-1:
    exit(print("INF"))
stack=[(dicx[0],dicy[0])]
grid[dicx[0]][dicy[0]]=1
ans=0
for sx,sy in stack:
    ans+=(x[sx]-x[sx-1])*(y[sy]-y[sy-1])
    for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
        tx=sx+dx
        ty=sy+dy
        if grid[tx][ty]:continue
        if hashh(min(sx,tx),min(sy,ty),1 if sx==tx else 0) in dont:continue
        if tx==0 or tx==h-1 or ty==0 or ty==w-1:
            exit(print("INF"))
        grid[tx][ty]=1
        stack.append((tx,ty))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
def hashh(x1,y1,x2,y2):
    if x1>x2:
        x1,y1,x2,y2=x2,y2,x1,y1
    if x1==x2 and y1>y2:
        x1,y1,x2,y2=x2,y2,x1,y1
    return x1*27000000000+y1*9000000+x2*3000+y2
abc_l=[list(map(int,input().split()))for _ in range(n)]
def_l=[list(map(int,input().split()))for _ in range(m)]
x=[0]
y=[0]
for a,b,c in abc_l:
    x.append(a)
    x.append(b)
    y.append(c)
for d,e,f in def_l:
    x.append(d)
    y.append(e)
    y.append(f)
x=sorted(list(set(x)))
y=sorted(list(set(y)))
h=len(x)+1
w=len(y)+1
dicx={}
dicy={}
for i in range(len(x)):dicx[x[i]]=i
for i in range(len(y)):dicy[y[i]]=i
grid=[[0]*w for _ in range(h)]
dont=set()
for a,b,c in abc_l:
    for i in range(dicx[a],dicx[b]):
        dont.add(hashh(i+1,dicy[c],i+1,dicy[c]+1))
for d,e,f in def_l:
    for j in range(dicy[e],dicy[f]):
        dont.add(hashh(dicx[d],j+1,dicx[d]+1,j+1))
if dicx[0]==0 or dicx[0]==h-1 or dicy[0]==0 or dicy[0]==w-1:
    exit(print("INF"))
stack=[(dicx[0],dicy[0])]
grid[dicx[0]][dicy[0]]=1
ans=0
for sx,sy in stack:
    ans+=(x[sx]-x[sx-1])*(y[sy]-y[sy-1])
    for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
        tx=sx+dx
        ty=sy+dy
        if grid[tx][ty]:continue
        if hashh(sx,sy,tx,ty) in dont:continue
        if tx==0 or tx==h-1 or ty==0 or ty==w-1:
            exit(print("INF"))
        grid[tx][ty]=1
        stack.append((tx,ty))
print(ans)


Fixed submission:
n,m=map(int,input().split())
def hashh(x,y,f):
    return (x*3000+y)*2+f
abc_l=[list(map(int,input().split()))for _ in range(n)]
def_l=[list(map(int,input().split()))for _ in range(m)]
x=[0]
y=[0]
for a,b,c in abc_l:
    x.append(a)
    x.append(b)
    y.append(c)
for d,e,f in def_l:
    x.append(d)
    y.append(e)
    y.append(f)
x=sorted(list(set(x)))
y=sorted(list(set(y)))
h=len(x)+1
w=len(y)+1
dicx={}
dicy={}
for i in range(len(x)):dicx[x[i]]=i
for i in range(len(y)):dicy[y[i]]=i
grid=[[0]*w for _ in range(h)]
dont=set()
for a,b,c in abc_l:
    for i in range(dicx[a],dicx[b]):
        dont.add(hashh(i+1,dicy[c],1))
for d,e,f in def_l:
    for j in range(dicy[e],dicy[f]):
        dont.add(hashh(dicx[d],j+1,0))
if dicx[0]==0 or dicx[0]==h-1 or dicy[0]==0 or dicy[0]==w-1:
    exit(print("INF"))
stack=[(dicx[0],dicy[0])]
grid[dicx[0]][dicy[0]]=1
ans=0
for sx,sy in stack:
    ans+=(x[sx]-x[sx-1])*(y[sy]-y[sy-1])
    for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
        tx=sx+dx
        ty=sy+dy
        if grid[tx][ty]:continue
        if hashh(min(sx,tx),min(sy,ty),1 if sx==tx else 0) in dont:continue
        if tx==0 or tx==h-1 or ty==0 or ty==w-1:
            exit(print("INF"))
        grid[tx][ty]=1
        stack.append((tx,ty))
print(ans)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
def hashh(x1,y1,x2,y2):
    if x1>x2:
        x1,y1,x2,y2=x2,y2,x1,y1
    if x1==x2 and y1>y2:
        x1,y1,x2,y2=x2,y2,x1,y1
    return x1*1021147343+y1*1014049+x2*1007+y2
abc_l=[list(map(int,input().split()))for _ in range(n)]
def_l=[list(map(int,input().split()))for _ in range(m)]
x=[0]
y=[0]
for a,b,c in abc_l:
    x.append(a)
    x.append(b)
    y.append(c)
for d,e,f in def_l:
    x.append(d)
    y.append(e)
    y.append(f)
x=sorted(list(set(x)))
y=sorted(list(set(y)))
h=len(x)+1
w=len(y)+1
dicx={}
dicy={}
for i in range(len(x)):dicx[x[i]]=i
for i in range(len(y)):dicy[y[i]]=i
grid=[[0]*w for _ in range(h)]
dont=set()
for a,b,c in abc_l:
    for i in range(dicx[a],dicx[b]):
        dont.add(hashh(i+1,dicy[c],i+1,dicy[c]+1))
for d,e,f in def_l:
    for j in range(dicy[e],dicy[f]):
        dont.add(hashh(dicx[d],j+1,dicx[d]+1,j+1))
if dicx[0]==0 or dicx[0]==h-1 or dicy[0]==0 or dicy[0]==w-1:
    exit(print("INF"))
stack=[(dicx[0],dicy[0])]
grid[dicx[0]][dicy[0]]=1
ans=(x[dicx[0]+1]-x[dicx[0]])*(y[dicy[0]+1]-y[dicy[0]])
for sx,sy in stack:
    for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
        tx=sx+dx
        ty=sy+dy
        if grid[tx][ty]:continue
        if hashh(sx,sy,tx,ty) in dont:continue
        if tx==0 or tx==h-1 or ty==0 or ty==w-1:
            exit(print("INF"))
        grid[tx][ty]=1
        ans+=(x[tx+1]-x[tx])*(y[ty+1]-y[ty])
        stack.append((tx,ty))
print(ans)


Fixed submission:
n,m=map(int,input().split())
def hashh(x,y,f):
    return (x*3000+y)*2+f
abc_l=[list(map(int,input().split()))for _ in range(n)]
def_l=[list(map(int,input().split()))for _ in range(m)]
x=[0]
y=[0]
for a,b,c in abc_l:
    x.append(a)
    x.append(b)
    y.append(c)
for d,e,f in def_l:
    x.append(d)
    y.append(e)
    y.append(f)
x=sorted(list(set(x)))
y=sorted(list(set(y)))
h=len(x)+1
w=len(y)+1
dicx={}
dicy={}
for i in range(len(x)):dicx[x[i]]=i
for i in range(len(y)):dicy[y[i]]=i
grid=[[0]*w for _ in range(h)]
dont=set()
for a,b,c in abc_l:
    for i in range(dicx[a],dicx[b]):
        dont.add(hashh(i+1,dicy[c],1))
for d,e,f in def_l:
    for j in range(dicy[e],dicy[f]):
        dont.add(hashh(dicx[d],j+1,0))
if dicx[0]==0 or dicx[0]==h-1 or dicy[0]==0 or dicy[0]==w-1:
    exit(print("INF"))
stack=[(dicx[0],dicy[0])]
grid[dicx[0]][dicy[0]]=1
ans=0
for sx,sy in stack:
    ans+=(x[sx]-x[sx-1])*(y[sy]-y[sy-1])
    for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
        tx=sx+dx
        ty=sy+dy
        if grid[tx][ty]:continue
        if hashh(min(sx,tx),min(sy,ty),1 if sx==tx else 0) in dont:continue
        if tx==0 or tx==h-1 or ty==0 or ty==w-1:
            exit(print("INF"))
        grid[tx][ty]=1
        stack.append((tx,ty))
print(ans)