class Integer def / a self*a.pow(P-2,P)%P end end P=gets.to_i p eval(gets.split.zip(gets.chars)*'')%P