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;
int main() {
  int n;
  cin >> n;
  vector<int> gladeone;
  vector<int> gladetwo;
  vector<vector<int> > glade;
  for (int i = 0; i < 2; i++) {
    vector<int> gladei;
    for (int j = 0; j < n; j++) {
      int num;
      cin >> num;
      gladei.push_back(num);
    }
    glade.push_back(gladei);
  }
  int upr = 0;
  int lwr = -1;
  int current = 0;
  int pos = 0;
  bool back = false;
  bool shift = false;
  long long int sum = 0;
  for (int i = 1; i < 2 * n; i++) {
    if (abs(upr - lwr) == 1) {
      int noncurrent = 1;
      if (current == 0)
        noncurrent = 1;
      else
        noncurrent = 0;
      if (current == 0)
        pos = upr;
      else
        pos = lwr;
      int option1, option2;
      if (upr + 1 == n)
        option1 = INT_MAX;
      else
        option1 = glade[current][upr + 1];
      if (lwr + 1 == n)
        option2 = INT_MAX;
      else
        option2 = glade[noncurrent][lwr + 1];
      if (option1 < option2) {
        current = 0;
        upr++;
        pos = upr;
      } else {
        current = 1;
        lwr++;
        pos = lwr;
      }
      sum = sum + glade[current][pos] * i;
    } else {
      if (back) {
        pos--;
        sum = sum + glade[current][pos] * i;
      } else {
        if (pos < n - 1) {
          if (current == 0)
            upr++;
          else
            lwr++;
          pos++;
          sum = sum + glade[current][pos] * i;
        } else {
          if (shift) {
            pos--;
            sum = sum + glade[current][pos] * i;
            back = true;
          } else {
            if (current == 0)
              current = 1;
            else
              current = 0;
            sum = sum + glade[current][pos] * i;
            shift = true;
          }
        }
      }
    }
  }
  cout << sum << endl;
  return 0;
}
