$n=<>;@s=<>,<>;($x,$y)=map{y/2//}@s;($z,$w)=map{y/1//}@s;print $n*($x+$y)-$x*$y+($x?!$y*$z:$y||$z<$w?$w:$z)