6
12 8 12 17 20 5
17 4 8 8 8 4
 6
4 1 12 9 3 11
12 20 19 12 19 11
 1
1
1
 2
1 2
1 1
 1
7
5
 6
16 20 18 7 14 2
17 12 4 10 7 4

705
 917
 1
 9
 5
 741

import math

n = int(input())
r0 = [math.inf] * (n + 2)

r1 = [math.inf] + list(map(int, input().split())) + [math.inf]
r2 = [math.inf] + list(map(int, input().split())) + [math.inf]
r = [r0, r1,r2, r0];
# print(r)
multiplier = 0
l = 2 * n
ans = 0
i = 1 
j = 1
while multiplier < l:
  ans += (multiplier * r[i][j])
  r[i][j] = math.inf
  # print(i, j, r, ans, "ohh")
  m = min(r[i + 1][j], r[i][j+ 1], r[i-1][j], r[i][j-1])
  if r[i + 1][j] == m:
    i += 1
  elif r[i][j+ 1] ==m:
    j += 1
  elif r[i-1][j] ==m:
    i -= 1
  else:
    j -= 1
  multiplier+=1
print(ans)


