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() {
  ios_base::sync_with_stdio(false);
  long long n;
  cin >> n;
  vector<vector<long long> > p(2, vector<long long>(n)),
      suf(2, vector<long long>(n + 1)), ebalVLevo(2, vector<long long>(n + 1)),
      ebalVPravo(2, vector<long long>(n + 1));
  for (long long i = 0; i < 2; i++) {
    for (long long j = 0; j < n; j++) {
      cin >> p[i][j];
    }
  }
  for (long long i = 0; i < 2; i++) {
    suf[i][n - 1] = p[i][n - 1];
    for (long long j = n - 2; j >= 0; j--) {
      suf[i][j] = suf[i][j + 1] + p[i][j];
    }
  }
  for (long long i = 0; i < 2; i++) {
    ebalVPravo[i][0] = (n)*p[i][0];
    for (long long j = 1; j < n; j++) {
      ebalVPravo[i][j] = ebalVPravo[i][j - 1] + p[i][j] * (n + j);
    }
  }
  for (long long i = 0; i < 2; i++) {
    ebalVLevo[i][n - 1] = (2 * n) * p[i][n - 1];
    for (long long j = n - 2; j >= 0; j--) {
      ebalVLevo[i][j] = ebalVLevo[i][j + 1] + p[i][j] * (2 * n - 1 + (n - j));
    }
  }
  long long sum = 0;
  long long ans = 0;
  long long i = 0, j = 0;
  bool lastI = false;
  for (long long t = 0; t < 2 * n; t++) {
    sum += t * p[i][j];
    long long tmp = sum;
    long long tmpR =
        ebalVPravo[i][n - 1] - ebalVPravo[i][j] - (n - t + j) * suf[i][j + 1];
    long long tmpL = 0;
    if (i == 0 && !lastI) {
      tmpL = ebalVLevo[1][j] - (2 * n - 1 - t - (n - j) + 1) * suf[1][j];
    } else if (i == 1 && lastI) {
      tmpL =
          ebalVLevo[0][j + 1] - (2 * n - 1 - t - (n - j) + 1) * suf[1][j + 1];
    } else if (i == 1) {
      tmpL = ebalVLevo[0][j] - (2 * n - 1 - t - (n - j) + 1) * suf[1][j];
    } else {
      tmpL =
          ebalVLevo[1][j + 1] - (2 * n - 1 - t - (n - j) + 1) * suf[1][j + 1];
    }
    ans = max(ans, tmp + tmpL + tmpR);
    if (!lastI) {
      if (!i) {
        i++;
      } else {
        i--;
      }
      lastI = true;
    } else {
      j++;
      lastI = false;
    }
  }
  cout << ans;
  return 0;
}
