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 MAXN = 3e5 + 10;
vector<vector<int>> now(3, vector<int>(10));
int dp[2 * MAXN];
int N;
int Up(vector<vector<int>> now, int n) {
  int maxn = 0;
  int q = n / 2;
  for (int i = 0; i <= q; i++) {
    vector<vector<int>> fnow(now);
    int count = 0;
    int num = 0;
    int k = 1, v = 1;
    int fi = i;
    while (fi--) {
      num += fnow[k][v] * (count++);
      fnow[k++][v] = 0;
      num += fnow[k][v] * (count++);
      fnow[k][v++] = 0;
      num += fnow[k][v] * (count++);
      fnow[k--][v] = 0;
      num += fnow[k][v] * (count++);
      fnow[k][v] = 0;
      if (fnow[k][v + 1] == 0) break;
      v++;
    }
    while (fnow[k][v] != 0) {
      num += fnow[k][v] * (count++);
      fnow[k][v] = 0;
      if (fnow[k][v + 1] == 0) break;
      ++v;
    }
    ++k;
    while (fnow[k][v] != 0) {
      num += fnow[k][v] * (count++);
      fnow[k][v] = 0;
      if (fnow[k][v - 1] == 0) break;
      --v;
    }
    if (num < maxn) break;
    maxn = max(maxn, num);
  }
  return maxn;
}
int Down(vector<vector<int>> now, int n) {
  int maxn = 0;
  int q = (n - 1) / 2;
  for (int i = 0; i <= q; i++) {
    vector<vector<int>> fnow(now);
    int count = 2;
    int num = fnow[2][1];
    fnow[2][1] = 0;
    fnow[1][1] = 0;
    int k = 2, v = 2;
    int fi = i;
    while (fi--) {
      num += now[k][v] * (count++);
      fnow[k--][v] = 0;
      num += now[k][v] * (count++);
      fnow[k][v++] = 0;
      num += now[k][v] * (count++);
      fnow[k++][v] = 0;
      num += now[k][v] * (count++);
      fnow[k][v] = 0;
      if (fnow[k][v + 1] == 0) break;
      v++;
    }
    while (fnow[k][v] != 0) {
      num += fnow[k][v] * (count++);
      fnow[k][v] = 0;
      if (fnow[k][v + 1] == 0) break;
      ++v;
    }
    --k;
    while (fnow[k][v] != 0) {
      num += fnow[k][v] * (count++);
      fnow[k][v] = 0;
      if (fnow[k][v - 1] == 0) break;
      --v;
    }
    if (num < maxn) break;
    maxn = max(maxn, num);
  }
  return maxn;
}
int main() {
  int biggest;
  scanf("%d", &N);
  now[0].resize(N + 2);
  int one = 0;
  int two = 0;
  for (int i = 1; i < 3; i++) {
    now[i].resize(N + 2);
    for (int j = 1; j <= N; j++) {
      scanf("%d", &now[i][j]);
      if (i == 1 && j != 1)
        one += now[i][j];
      else if (i == 2)
        two += now[i][j];
    }
  }
  if (one > two) {
    biggest = Down(now, N);
  } else if (one < two) {
    biggest = Up(now, N);
  } else {
    biggest = max(Up(now, N), Down(now, N));
  }
  printf("%d\n", biggest);
}
