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<vector<int> > a(2, vector<int>(n));
  for (int i = 0; i < n; ++i) cin >> a[0][i];
  for (int i = 0; i < n; ++i) cin >> a[1][i];
  vector<vector<long long> > dp(2, vector<long long>(n));
  dp[0][n - 1] = a[1][n - 1];
  dp[1][n - 1] = a[0][n - 1];
  long long c_sum = a[0][n - 1] + a[1][n - 1], c = 1;
  for (int i = n - 2; i >= 0; --i) {
    dp[0][i] = max(c_sum + dp[0][i + 1] + (c * 2 + 1) * a[1][i],
                   a[1][i] + 2 * c_sum + dp[1][i + 1]);
    dp[1][i] = max(c_sum + dp[1][i + 1] + (c * 2 + 1) * a[0][i],
                   a[0][i] + 2 * c_sum + dp[0][i + 1]);
    c++;
    c_sum += a[1][i] + a[0][i];
  }
  cout << max(dp[0][0], dp[1][0]) << endl;
  return 0;
}
