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

#include <bits/stdc++.h>
using namespace std;
long long bgm(long long a, long long b, long long m) {
  a %= m;
  long long rem = 1;
  while (b) {
    if (b & 1) rem = (rem * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return rem;
}
long long inv(long long a, long long mod) { return bgm(a, mod - 2, mod); }
long long in() {
  long long a;
  assert(scanf("%lld", &a) != EOF);
  return a;
}
double dl() {
  double a;
  assert(scanf("%lf", &a) != EOF);
  return a;
}
const int MAX = 300005;
const int LOGMX = 25;
const long long MOD = 1000000007;
double ttm;
int n;
long long a[2][MAX];
bool vis[2][MAX];
bool check(int r, int c) {
  if (c == n - 1) return true;
  if (c == 0) return true;
  if (vis[1 - r][c - 1]) return true;
  return false;
}
long long dfs(int t, int r, int c) {
  vis[r][c] = 1;
  long long aa, b, cc;
  aa = b = cc = (1000000000000000000ll);
  if (vis[1 - r][c] == 0) aa = a[1 - r][c];
  if (c != 0 and vis[r][c - 1] == 0) b = a[r][c - 1];
  if (c != n - 1 and vis[r][c + 1] == 0) cc = a[r][c + 1];
  if (min(aa, min(b, cc)) == (1000000000000000000ll)) return t * a[r][c];
  long long ans = 0;
  if (aa <= b and aa <= cc and check(r, c))
    ans += dfs(t + 1, 1 - r, c);
  else if (b <= aa and b <= cc)
    ans += dfs(t + 1, r, c - 1);
  else
    ans += dfs(t + 1, r, c + 1);
  return ans + t * a[r][c];
}
int main() {
  n = in();
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < n; j++) a[i][j] = in();
  printf("%lld", (long long)(dfs(0, 0, 0))), puts("");
  return 0;
}
