read n
F=(1 1 2 6 24 120 720 5040)
f(){
	read d
	ex=(0 0 0 0 0 0 0 0)
	a=0
	i=$1
	for d in $d;do
		c=0
		for((j=1;j<d;j++));do
			if [ ${ex[j-1]} -eq 0 ];then
				c=$[c+1]
			fi
		done
		a=$[a+c*F[--i]]
		ex[d-1]=1
	done
	echo $a
}
s=$(f $n)
t=$(f $n)
echo $[s>t?s-t:t-s]
