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;
const long long N = 3e5 + 100;
long long sum[2][N], sum_rev[2][N], p_sum[2][N];
signed main() {
  long long n;
  cin >> n;
  long long a[2][n];
  for (long long i = 0; i < 2; i++)
    for (long long j = 0; j < n; j++) cin >> a[i][j];
  for (long long i = 0; i < 2; i++)
    for (long long j = n - 1; j >= 0; j--) {
      sum[i][j] = sum[i][j + 1] + j * a[i][j];
      sum_rev[i][j] = sum_rev[i][j + 1] + (n - j - 1) * a[i][j];
      p_sum[i][j] = p_sum[i][j + 1] + a[i][j];
    }
  long long ans = 0;
  long long s = 0;
  for (long long i = 0, j = 0; j < n; i ^= 1, j++) {
    long long new_ans = s;
    new_ans += sum[i][j] + j * p_sum[i][j];
    new_ans += sum_rev[i ^ 1][j] + (n + j) * p_sum[i ^ 1][j];
    ans = max(ans, new_ans);
    s += (j * 2) * a[i][j];
    s += (j * 2 + 1) * a[i ^ 1][j];
  }
  cout << ans;
}
