struct ModInt @@MOD = 1_000_000_007i64 def self.mod @@MOD end def self.zero ModInt.new(0) end def initialize(n) @n = n.to_i64 % @@MOD end getter n : Int64 def + : self self end def - : self ModInt.new(n != 0 ? @@MOD - @n : 0) end def +(m) ModInt.new(@n + m.to_i64 % @@MOD) end def -(m) ModInt.new(@n - m.to_i64 % @@MOD) end def *(m) ModInt.new(@n * m.to_i64 % @@MOD) end def /(m) raise DivisionByZeroError.new if m == 0 a, b, u, v = m.to_i64, @@MOD, 1i64, 0i64 while b != 0 t = a // b a -= t * b a, b = b, a u -= t * v u, v = v, u end ModInt.new(@n * u) end def //(m) self / m end def **(m) t, res = self, ModInt.new(1) while m > 0 res *= t if m.odd? t *= t m >>= 1 end res end def ==(m) @n == m.to_i64 end def !=(m) @n != m.to_i64 end def succ self + 1 end def pred self - 1 end def to_i64 : Int64 @n end delegate to_s, to: @n delegate inspect, to: @n end class CulSum(T) def initialize(a : Array(T)) @n = a.size @s = Array(T).new(@n + 1, T.zero) @n.times do |i| @s[i + 1] = @s[i] + a[i] end end def initialize(@n : Int32, &f : Int32 -> T) @s = Array(T).new(@n + 1, T.zero) @n.times do |i| @s[i + 1] = @s[i] + yield(i) end end def initialize(a, &f) @n = a.size @s = Array(T).new(@n + 1, T.zero) @n.times do |i| @s[i + 1] = @s[i] + yield(a[i]) end end def [](l : Int32, r : Int32) l < r ? @s[r] - @s[l] : 0 end def [](i : Int32) @s[i] end def [](r : Range(Int32, Int32)) @s[r.exclusive? ? r.end : r.end + 1] - @s[r.begin] end def to_a (0...@n).map { |i| self[i..i] } end end n = read_line.to_i a = (0..n).map { ModInt.new read_line.to_i } b = (0..n).map { ModInt.new read_line.to_i } a_sum = CulSum.new(a) puts b.each_with_index.sum { |v, i| v * a_sum[0..n - i] }