#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  long long l = v.size();
  for (long long i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
template <typename T>
void trace(const char* name, T&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
const long long N = 3e5 + 100;
long long a[N], b[N], n;
long long c1[N], c2[N], c3[N], c4[N], c5[N], c6[N];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  long long tota = 0;
  long long totb = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    c1[i] += i * a[i];
    if (i != 0) {
      c1[i] += c1[i - 1];
    }
    c5[i] += a[i];
    if (i != 0) {
      c5[i] += c5[i - 1];
    }
  }
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
    c2[i] += i * b[i];
    if (i != 0) {
      c2[i] += c2[i - 1];
    }
    c6[i] += b[i];
    if (i != 0) {
      c6[i] += c6[i - 1];
    }
  }
  long long curr = n;
  for (long long i = n - 1; i >= 0; i--) {
    c4[i] = curr * b[i] + c4[i + 1];
    curr++;
  }
  curr = n;
  for (long long i = n - 1; i >= 0; i--) {
    c3[i] = curr * a[i] + c3[i + 1];
    curr++;
  }
  long long state = 0;
  long long ans = -1;
  long long ap = 0;
  long long bp = 0;
  curr = 0;
  long long tim = 0;
  for (long long i = 0; i < 2 * n; i++) {
    if (state == 0) {
      long long temp = c1[n - 1];
      if (ap != 0) {
        temp -= c1[ap - 1];
      }
      long long t2 = c5[n - 1];
      if (ap != 0) {
        t2 -= c5[ap - 1];
      }
      temp += (tim - ap) * (t2);
      temp += c4[ap];
      temp += (tim - ap) * (c6[ap]);
      if (ap != 0) {
        temp -= (tim - ap) * (c6[ap - 1]);
      }
      ans = max(ans, temp + curr);
      curr += tim * a[ap];
      ap++;
    } else if (state == 1) {
      long long temp = c2[n - 1];
      if (bp != 0) {
        temp -= c2[bp - 1];
      }
      long long t2 = c6[n - 1];
      if (bp != 0) {
        t2 -= c6[bp - 1];
      }
      temp += (tim - bp) * (t2);
      temp += c3[bp + 1];
      temp += (tim - bp) * (c5[n - 1] - c5[bp]);
      ans = max(ans, temp + curr);
      curr += tim * b[bp];
      bp++;
    } else if (state == 2) {
      long long temp = c2[n - 1];
      if (bp != 0) {
        temp -= c2[bp - 1];
      }
      long long t2 = c6[n - 1];
      if (bp != 0) {
        t2 -= c6[bp - 1];
      }
      temp += (tim - bp) * (t2);
      temp += c3[bp];
      temp += (tim - bp) * (c5[n - 1] - c5[bp - 1]);
      ans = max(ans, temp + curr);
      curr += tim * b[bp];
      bp++;
    } else {
      long long temp = c1[n - 1];
      if (ap != 0) {
        temp -= c1[ap - 1];
      }
      long long t2 = c5[n - 1];
      if (ap != 0) {
        t2 -= c5[ap - 1];
      }
      temp += (tim - ap) * (t2);
      temp += c4[ap + 1];
      temp += (tim - ap) * (c6[n - 1]);
      temp -= (tim - ap) * (c6[ap]);
      ans = max(ans, temp + curr);
      curr += tim * a[ap];
      ap++;
    }
    tim++;
    state += 1;
    state %= 4;
  }
  cout << ans << "\n";
  return 0;
}
