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;
long long s[1000003], a[2][1000003], p[2][1000003], n, ans, r, d;
int main() {
  cin >> n;
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < n; j++) scanf("%d", &a[i][j]);
  for (int i = n - 1; i >= 0; i--) s[i] = s[i + 1] + a[0][i] + a[1][i];
  for (int i = n - 1; i >= 0; i--)
    p[0][i] = p[0][i + 1] + s[i + 1] + ((n - i) * 2 - 1) * a[1][i];
  for (int i = n - 1; i >= 0; i--)
    p[1][i] = p[1][i + 1] + s[i + 1] + ((n - i) * 2 - 1) * a[0][i];
  for (int i = 0; i < n; i++) {
    ans = max(ans, p[i & 1][i] + s[i] * i * 2 + r);
    r += d * a[i & 1][i];
    d++;
    r += d * a[(i + 1) & 1][i];
    d++;
  }
  cout << ans << endl;
}
