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 N, oriPos[2][300010], otherPos[2][300010];
long long arr[2][300010], curr = 0, other = 0, sum = 0, sum2 = 0, ret;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> N;
  for (int j = 0; j < 2; j++)
    for (int i = 0; i < N; i++) cin >> arr[j][i];
  for (int i = 0; i < N; i++) {
    sum += (long long)i * arr[0][i];
    other += arr[0][i];
    oriPos[0][i] = i;
  }
  for (int i = N - 1; i > -1; i--) {
    sum += (long long)(2 * N - 1 - i) * arr[1][i];
    other += arr[1][i];
    oriPos[1][i] = 2 * N - 1 - i;
  }
  for (int i = 0; i < N; i++) {
    sum2 += (long long)i * arr[1][i];
    otherPos[1][i] = i;
  }
  for (int i = N - 1; i > -1; i--) {
    sum2 += (long long)(2 * N - 1 - i) * arr[0][i];
    otherPos[0][i] = 2 * N - 1 - i;
  }
  int p1 = 0, p2 = 0;
  ret = sum;
  for (int i = 0; i < 2 * N; i++) {
    if (i % 4 == 0 || i % 4 == 3) {
      curr += (long long)i * arr[0][p1];
      sum -= arr[0][p1] * (long long)oriPos[0][p1];
      other -= arr[0][p1];
      p1++;
      if (i % 4 == 3) ret = max(ret, curr + sum + (long long)(p1 - 1) * other);
    } else {
      curr += (long long)i * arr[1][p2];
      sum -= arr[1][p2] * (long long)oriPos[1][p2];
      other -= arr[1][p2];
      p2++;
      if (i % 4 == 1) ret = max(ret, curr + sum2 + (long long)p2 * other);
    }
  }
  ret = max(ret, curr);
  cout << ret << '\n';
  return 0;
}
