import sequtils,strutils,algorithm,math,sugar,macros,strformat template get*():string = stdin.readLine().strip() proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "" .} proc scan(): int = while true: var k = getchar_unlocked() if k < '0' or k > '9': break else: result = 10 * result + k.ord - '0'.ord const INF = 10_0000_0007 proc MOD(x:int) :int = if x > INF : x mod INF elif x < 0 : x + INF else: x let n = scan() let A = newSeqWith(n+1,scan()) let B = newSeqWith(n+1,scan()) var bSum = B.foldl(MOD(a+b),0) var ans = 0 for i,a in A: ans = MOD(ans + a * bSum) bSum = MOD(bSum - B[^(1+i)] + INF) echo ans