n=gets.to_i s=[0,1].map{gets} x,y=s.map{_1.count(?2)} puts(if x>0&&y>0 n*(x+y)-x-y elsif x>0 n*x+s[0].count(?1) elsif y>0 n*y+s[1].count(?1) else s.map{_1.count(?1)}.max end)