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 int N = 300005;
int n;
long long a[2][N];
long long cal(int x, int y, int t) {
  long long res = 0;
  for (int i = y + 1; i <= n; i++) res += (++t) * a[x][i];
  for (int i = n; i >= y; i--) res += (++t) * a[x ^ 1][i];
  return res;
}
long long dfs(int x, int y, long long t, long long now) {
  cout << x << " " << y << " " << t << " " << now << endl;
  if (y == n) return now + (t + 1) * a[x ^ 1][y];
  return max(now + cal(x, y, t),
             dfs(x ^ 1, y + 1, t + 2,
                 now + (t + 1) * a[x ^ 1][y] + (t + 2) * a[x ^ 1][y + 1]));
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[0][i];
  for (int i = 1; i <= n; i++) cin >> a[1][i];
  cout << dfs(0, 1, 0, 0) << endl;
  return 0;
}
