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;
vector<long long> a, b, c, d, e, F;
struct Key {
  long long N, p;
  bool operator==(const Key& other) const {
    return (N == other.N && p == other.p);
  }
};
struct KeyHasher {
  size_t operator()(const Key& k) const { return k.N * 59 + k.p * 61; }
};
unordered_map<Key, long long, KeyHasher> dp;
long long tell(vector<long long>& f, vector<long long>& s, long long n,
               long long i, long long j) {
  if (i == n) return 0;
  if (dp[{i, j}]) return dp[{i, j}];
  long long a = 0, b = 0, t = 2 * i;
  if (j == 0) {
    a = (t + 1) * s[i] + tell(f, s, n, i + 1, 1);
    b = (t + 1) * (e[i + 1]) + (n - i - 1) * (d[i]) + (::b[i]);
    return dp[{i, j}] = t * f[i] + max(a, b);
  }
  a = (t + 1) * f[i] + tell(f, s, n, i + 1, 0);
  b = (t + 1) * (F[i + 1]) + (n - i - 1) * (c[i]) + (::a[i]);
  return dp[{i, j}] = t * s[i] + max(a, b);
}
int main() {
  long long n;
  cin >> n;
  vector<long long> f(n), s(n);
  for (long long i = 0; i < n; i++) {
    cin >> f[i];
  }
  for (long long i = 0; i < n; i++) {
    cin >> s[i];
  }
  a.push_back(f[n - 1]);
  b.push_back(s[n - 1]);
  for (long long i = n - 2, j = 2; i >= 0; i--, j++) {
    a.push_back(a[a.size() - 1] + j * f[i]);
    b.push_back(b[b.size() - 1] + j * s[i]);
  }
  c.push_back(f[n - 1]);
  d.push_back(s[n - 1]);
  for (long long i = n - 2; i >= 0; i--) {
    c.push_back(c[c.size() - 1] + f[i]);
    d.push_back(d[d.size() - 1] + s[i]);
  }
  e.push_back(c[0]);
  F.push_back(d[0]);
  for (long long i = 1; i < n; i++) {
    e.push_back(e[e.size() - 1] + c[i]);
    F.push_back(F[F.size() - 1] + d[i]);
  }
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  reverse(c.begin(), c.end());
  reverse(d.begin(), d.end());
  reverse(e.begin(), e.end());
  reverse(F.begin(), F.end());
  e.push_back(0);
  F.push_back(0);
  cout << tell(f, s, n, 0, 0);
  return 0;
}
