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

// clang-format off
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp>   

using namespace std;
using namespace __gnu_pbds;

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

/**TEMPLATE START: DEBUG PRINT -----------------------------------------------*/

#ifdef LOCAL
#define _NTH_ARG(_1, _2, _3, _4, _5, _6, N, ...) N
#define _FE_1(_CALL, x) _CALL(x)
#define _FE_2(_CALL, x, ...) _CALL(x) _FE_1(_CALL, __VA_ARGS__)
#define _FE_3(_CALL, x, ...) _CALL(x) _FE_2(_CALL, __VA_ARGS__)
#define _FE_4(_CALL, x, ...) _CALL(x) _FE_3(_CALL, __VA_ARGS__)
#define _FE_5(_CALL, x, ...) _CALL(x) _FE_4(_CALL, __VA_ARGS__)
#define _FE_6(_CALL, x, ...) _CALL(x) _FE_5(_CALL, __VA_ARGS__)
#define FOR_EACH_MACRO(MACRO, ...)                                  \
    _NTH_ARG(__VA_ARGS__, _FE_6, _FE_5, _FE_4, _FE_3, _FE_2, _FE_1) \
    (MACRO, __VA_ARGS__)
#define watch(x) cerr << "\033[1;32m" #x " = \033[1;34m" << (x) << "\033[0m; ";
#define debug(...)                                         \
    cerr << "\033[2;31mLine " << __LINE__ << ": \033[0;m"; \
    FOR_EACH_MACRO(watch, __VA_ARGS__)                     \
    cerr << endl
#else
#define debug(...)
#endif

template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '{' << p.first << ", " << p.second << '}';
}
template <class T, class = decltype(begin(declval<T>())),
          class = enable_if_t<!is_same<T, string>::value>>
ostream &operator<<(ostream &os, const T &c) {
    os << '[';
    for (auto it = begin(c); it != end(c); ++it)
        os << (it == begin(c) ? "" : ", ") << *it;
    return os << ']';
}
template <class T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
    os << "\n[\n";
    for (int i = 0; i < v.size(); i++) {
        os << v[i];
        os << '\n';
    }
    return os << ']';
}

/**TEMPLATE END: DEBUG PRINT -----------------------------------------------*/

/**TEMPLATE START: SHORT HAND -----------------------------------------------*/
#define pb                push_back
#define ppb               pop_back
#define all(x)            (x).begin(),(x).end()
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define FOR(i, a, b)      for(int i = (a); i < (b); i++)
#define FORE(i, a, b)     for(int i = (a); i <= (b); i++)
#define FORD(i, a, b)     for(int i = (a); i >= (b); i--)
#define FASTIO            ios_base::sync_with_stdio(false); cin.tie(NULL)
#define EPS               (double)(0.000000001)
#define INF               (long long)(1e18)
#define MOD               1000000007
#define MOD2              998244353
#define decimal(v, d)     fixed << setprecision(d) << v

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; 
/**TEMPLATE END: SHORT HAND -----------------------------------------------*/

/**TEMPLATE START: MISC -----------------------------------------------*/
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
 
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/**TEMPLATE END: MISC -----------------------------------------------*/

void solve();

int32_t main() {
    FASTIO;
#ifndef ONLINE_JUDGE
    (void)!freopen("input.txt", "r", stdin);
    (void)!freopen("output.txt", "w", stdout);
#endif

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        cout << "\n";
    }
    return 0;
}

// clang-format on

#define int long long

void solve()
{
    int n;
    cin >> n;
    vector<vector<int>> a(2, vector<int>(n));
    for (int i = 0; i < n; i++) {
        cin >> a[0][i];
    }
    for (int i = 0; i < n; i++) {
        cin >> a[1][i];
    }

    vector<vector<int>> presum(2, vector<int>(n));
    presum[0][0] = a[0][0];
    presum[1][0] = a[1][0];
    for (int i = 1; i < n; i++) {
        presum[0][i] = presum[0][i - 1] + a[0][i];
        presum[1][i] = presum[1][i - 1] + a[1][i];
    }

    vector<int> du(n);

    auto range_sum = [&](int i) {
        return (presum[1][n - 1] - presum[1][i] + a[1][i]) + (presum[0][n - 1] - presum[0][i] + a[0][i]);
    };

    int sum = 0;
    int ctr = 1;
    for (int i = 0; i < n; i++) {
        sum += (ctr * a[1][i]);
        ctr++;
    }
    for (int i = n - 1; i >= 0; i--) {
        sum += (ctr * a[0][i]);
        ctr++;
    }

    du[0] = sum;

    for (int i = 1; i < n; i++) {
        int curr = du[i - 1] - (a[1][i - 1]) - ((n - (i - 1)) * 2 * a[0][i - 1]);
        du[i] = curr - range_sum(i);
    }

    vector<int> ud(n);

    sum = 0;
    ctr = 1;
    for (int i = 0; i < n; i++) {
        sum += (ctr * a[0][i]);
        ctr++;
    }
    for (int i = n - 1; i >= 0; i--) {
        sum += (ctr * a[1][i]);
        ctr++;
    }

    ud[0] = sum;

    for (int i = 1; i < n; i++) {
        int curr = ud[i - 1] - (a[0][i - 1]) - ((n - (i - 1)) * 2 * a[1][i - 1]);
        ud[i] = curr - range_sum(i);
    }

    debug(a);
    debug(presum);
    debug(du);
    debug(ud);

    int best = ud[0] - range_sum(0);

    ctr = 0;
    int base = 0;
    int pos = 0;
    for (int i = 0; i < n;) {
        debug(i, ctr, pos);
        base += (ctr * a[pos][i]);
        best = max(best, base);
        if (i < n - 1) {
            if (pos != 0) {
                best = max(best, base + (du[i + 1] + ((ctr - 1) * range_sum(i))));
            } else {
                best = max(best, base + (ud[i + 1] + ((ctr - 1) * range_sum(i))));
            }
        }
        if (ctr % 2 != 0) {
            i++;
        } else {
            pos = 1 - pos;
        }
        ctr++;
    }

    cout << best;
}
