jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
N = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))

ans = 0
for i in range(1, N):
    a1[i] = a1[i-1] + a1[i]
    a2[N-i-1] = a2[N-i] + a2[N-i-1]

for i in range(N):
    ans = max(ans, a1[i] + a2[i])

print(ans)
//  [python]
f = lambda :list(map(int,input().split()))
N = int(input())
A1 = f()
A2 = f()

dp = [[0 for i in range(N)] for j in range(2)]

dp[0][0] = A1[0]
dp[1][0] = dp[0][0] + A2[0]

for i in range(1,N):
    dp[0][i] = dp[0][i-1] + A1[i]
for j in range(1,N):
    dp[1][j] = max((dp[0][j], dp[1][j-1])) + A2[j]

print(dp[1][N-1])
//  [python]
N = int(input())
P = [list(map(int,input().split())) for _ in range(2)]
ans = sum(P[0]) + P[1][N-1]
p = ans

for i in range(N-1, 0, -1):
    p = p - P[0][i] + P[1][i-1]
    ans = max(p, ans)

print(ans)
//  [python]
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
res = 0
for i in range(n):
  c = 0
  for j in range(n):
    if j <= i:
      c += a[j]
    else:
      c += b[j]
  res = max(res,c)
print(res)
//  [python]
N = int(input())
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
C = []

S = sum(A2) + A1[0]

for i in range(1,N):
  C.append(S)
  S += A1[i]-A2[i-1]
  
print(max(C))
//  [python]
n=int(input())
a=list(map(int,input().split()))
b=list(map(int, input().split()))
ans = 0
        for i in range(n):
                        ans = max(ans,sum(a[:i+1])+sum(b[i:n]))
//  [java]
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[][] A = new int[3][N + 1];
		for (int i = 1; i <= N; i++)
			A[1][i] = sc.nextInt();
		for (int i = 1; i <= N; i++)
			A[2][i] = sc.nextInt();

		int max = 0;
		for (int i = 1; i <= N; i++) {
			int s = 0;
			for (int j = 1; j <= i; j++)
				s += A[1][j];
			for (int k = i; k <= N; k++)
				s += A[2][k];
			max = Math.max(max, s);
		}

		System.out.println(max);
	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}
//  [java]
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a1 = new int[n+1];
        int[] a2 = new int[n];

        for(int i=0; i<n; i++) {
            a1[i] = sc.nextInt();
        }
        for(int i=0; i<n; i++) {
            a2[i] = sc.nextInt();
        }

        int a1Sum = 0;
        for(int i=1; i<n; i++) {
            a1Sum += a1[i];
        }

        int a2Sum = 0;
        for(int i=0; i<n-1; i++) {
            a2Sum += a2[i];
        }

        int cnt = 0;
        for(int i=0; i<n; i++) {
            if(a1Sum >= a2Sum) {
                cnt += a1[i];
                a1Sum -= a1[i+1];
                a2Sum -= a2[i];
            } else {
                cnt = a1[i] + a2Sum;
                break;
            }
        }
        System.out.println(cnt+a2[n-1]);
    }
}
//  [java]
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a1 = new int[n+1];
        int[] a2 = new int[n];

        for(int i=0; i<n; i++) {
            a1[i] = sc.nextInt();
        }
        for(int i=0; i<n; i++) {
            a2[i] = sc.nextInt();
        }

        int a1Sum = 0;
        for(int i=1; i<n; i++) {
            a1Sum += a1[i];
        }

        int a2Sum = 0;
        for(int i=0; i<n-1; i++) {
            a2Sum += a2[i];
        }

        int cnt = 0;
        for(int i=0; i<n; i++) {
            if(a1Sum >= a2Sum) {
                cnt += a1[i];
                a1Sum -= a1[i+1];
                a2Sum -= a2[i];
            } else {
                cnt += a1[i] + a2Sum;
                break;
            }
        }
        System.out.println(cnt+a2[n-1]);
    }
}
//  [java]
import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {

  static int x,y,n;
  static int sum,ans;
  static int[][] a;

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    a = new int[2][n];

    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < n; j++) {
        a[i][j] = sc.nextInt();
      }
    }

    x = 0; y = 0;
    sum = 0;
    ans = Integer.MIN_VALUE;

    dfs(x,y);

    System.out.println(ans);

  }

  public static boolean dfs (int i, int j) {

    if (i < 0 || i >=n || j < 0 || j >= 2) {
      return false;
    }

    sum += a[j][i];

    if (i == n-1 && j == 1) {
      ans = Math.max(sum,ans);
      sum = 0;
    }

    if (dfs(i+1,j)) return true;

    if (dfs(i,j+1)) return true;

    return false;

  }

}
//  [cpp]
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  int N;
  cin >> N;

  int A[2][110];
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < N; ++j) {
      cin >> A[i][j];
    }
  }

  int total = A[0][0] + A[1][N-1];
  for (int i = 0; i < N-1; ++i) {
    total += A[1][i];
  }

  int ans = total;
  for (int i = 1; i < N; ++i) {
    total += -A[1][i-1] + A[0][i];
    ans = max(ans, total);
  }

  cout << ans << endl;

  return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<vector<int>> a(2, vector<int>(n));

  for(int i=0; i<n; i++){
    cin >> a.at(0).at(i);
  }
  for(int i=0; i<n; i++){
    cin >> a.at(1).at(i);
  }

  vector<int> candy(n, 0);
  for(int i=0; i<n; i++){
    for(int j=0; j<=i; j++) candy.at(i)+=a.at(0).at(j);
    for(int j=i; j<n; j++) candy.at(i)+=a.at(1).at(j);
  }

  sort(candy.begin(), candy.end());
  cout << candy.at(n-1) << endl;
}
//  [cpp]
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, A[2][100];
    cin >> N;
    REP(i, 2) {
        REP(j, N) {
            cin >> A[i][j];
        }
    }
    int res = 0;
    REP(i, N) {
        int sum = 0;
        REP(j, N) {
            if (j < i) {
                sum += A[0][j];
            } else if (j > i) {
                sum += A[1][j];
            } else {
                sum += A[0][j] + A[1][j];
            }
        }
        amax(res, sum);
    }
    cout << res << endl;
    return 0;
}
//  [cpp]
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define Fast ios_base :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define rep(i, n) for(i=0; i<n; i++)
#define fort(i, n) for(i=1; i<=n; i++)
const int inf=1e9,mod=1e9+7,N=2e5+5;

using namespace std;
template<class T> void umax(T &a,T b){a=max(a,b);}
int pref[2][N];
int main()
{
	Fast;
	int n;
	cin >> n;
	int arr[2][n+1], i, j;
	rep(i, n){
		fort(j, n){
			cin >> arr[i][j];
			if(j==1) pref[i][j] = arr[i][j];
			else pref[i][j] = pref[i][j-1] + arr[i][j];
		}
	}
	int ans = 0;
	fort(i, n){
		umax(ans,pref[0][i]+pref[1][n-1]-pref[1][i-1]+arr[1][n]);
	}
	cout << ans << endl;
	return 0;
}
//  [cpp]
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#define ll long long
#define pb push_back
#define Fast ios_base :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define rep(i, n) for(i=0; i<n; i++)
#define fort(i, n) for(i=1; i<=n; i++)
const int inf=1e9,mod=1e9+7,N=2e5+5;
template<class T> void umax(T &a,T b){a=max(a,b);}
using namespace std;
int pref[2][N];
int main()
{
	Fast;
	int n;
	cin >> n;
	int arr[2][n+1], i, j;
	rep(i, n){
		fort(j, n){
			cin >> arr[i][j];
			if(j==1) pref[i][j] = arr[i][j];
			else pref[i][j] = pref[i][j-1] + arr[i][j];
		}
	}
	int ans = 0;
	fort(i, n){
		umax(ans,pref[0][i]+pref[1][n-1]-pref[1][i-1]+arr[1][n]);
	}
	cout << ans << endl;
	return 0;
}
//  [cpp]
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#define ll long long
#define pb push_back
#define Fast ios_base :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define rep(i, n) for(i=0; i<n; i++)
#define fort(i, n) for(i=1; i<=n; i++)
const int inf=1e9,mod=1e9+7,N=2e5+5;
template<class T> void umax(T &a,T b){a=max(a,b);}
using namespace std;
int pref[2][N];
int main()
{
	Fast;
	int n;
	cin >> n;
	int arr[2][n+1], i, j;
	rep(i, n){
		fort(j, n){
			cin >> arr[i][j];
			if(j==1) pref[i][j] = arr[i][j];
			else pref[i][j] = pref[i][j-1] + arr[i][j];
		}
	}
	int ans = 0;
	fort(i, n){
		umax(ans,pref[0][i]+pref[1][n-1]-pref[1][i-1]+a[1][n]);
	}
	cout << ans << endl;
	return 0;
}
//  [c]
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

#define mod 1000000007
#define limit 200001
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i = 0; i < n; i++)
#define max(a,b) {if(a>b){return a;}return b;}
#define min(a,b) {if(a<b){return a;}return b;}

int main(){
    int n,i,j;
    int tmp = 0;
    int under_point = 0;
    int max_value = 0;
    int a[2][100];
    
    scanf("%d",&n);
    rep(i,n) scanf("%d",&a[0][i]);
    rep(j,n) scanf("%d",&a[1][j]);
    
    for(i = 0; i < n; i++){
        for(j = 0; j < under_point; j++) tmp += a[0][j];
        tmp += a[0][under_point];
        tmp += a[1][under_point];
        for(j = under_point+1; j < n; j++) tmp += a[1][j];
        if(tmp > max_value){
            max_value = tmp;
//            printf("max = %d\n",max_value);
        }
        tmp = 0;
        under_point++;
    }
    
    printf("%d\n",max_value);
}
//  [c]
#include <stdio.h>
#define max(x, y)  ((x)<(y) ? (y) : (x))

int main(){
  int n;  scanf("%d", &n);
  int field[2][102];
  field[0][0] = field[1][0] = 0;
  for(int i=0; i<2; i++)
    for(int j=1; j<=n; j++){
      int cand;  scanf("%d", &cand);
      field[i][j] = field[i][j-1] + cand;
    }
  int ans = 0;
  for(int i=1; i<=n; i++){
    int score = field[0][i] + (field[1][n] - field[1][i-1]);
    ans = max(ans, score);
  }
  printf("%d\n", ans);
  return 0;
}
//  [c]
#include <stdio.h>

int main(void) {

  int n;
  scanf("%d", &n);
  int a[2][n];
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  int sum[2][n];
  sum[0][0] = a[0][0];
  for (int i = 1; i < n; i++) {
    sum[0][i] = sum[0][i-1]+a[0][i];
  }
  int max;
  sum[1][0] = sum[0][0]+a[1][0];
  for (int i = 1; i < n; i++) {
    max = sum[0][i];
    if (sum[1][i-1] > max) {
      max = sum[1][i-1];
    }
    sum[1][i] = max+a[1][i];
  }
  printf("%d\n", sum[1][n-1]);

  return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>

int compare_int_reverse(const void *a, const void *b);
	
int main(void)
{
	int i;
	int n;
	char *p;
	int alice, bob;
	int a[128];
	char buffer[4096];

	// read input
	scanf("%d\n",&n);
	fgets(buffer, sizeof buffer-1, stdin);
	//printf("%d %s",n,buffer);

	p=buffer;
	for (i=0;i<n;++i)
	{
		a[i]=strtol(p,&p,10);
		//printf("\ta[%d]=%d\n",i,a[i]);
	}

	// sort
	qsort(a,n,sizeof (int), compare_int_reverse);

	// sum for Alice and Bob
	alice=0;
	bob=0;
	for (i=0;i<n;++i)
	{
		if ((i&1)==0)
		{
			alice+=a[i];
		}
		else
		{
			bob+=a[i];
		}
	}

	//printf("\tAlice: %d\n",alice);
	//printf("\tBob: %d\n",bob);
	printf("%d\n",alice-bob);

	return 0;
}


int compare_int_reverse(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}
//  [c]
#include<stdio.h>

int main()
{
  int n;
  
  scanf("%d",&n);
  
  int a[2][n];
  int i,j;
  
  for(i=0;i<2;i++)
  {
    for(j=0;j<n;j++)
    {
      scanf("%d",&a[i][j]);
    }
  }
  
  int sum_1=0,sum_2=0,ans;
  
  ans=a[0][0]+a[1][n-1];
  j=0;
  
  while(j<n-1)
  {
    for(i=j;i<n-1;i++)
    {
      sum_1+=a[0][i+1];
    }
    
    for(i=j;i<n;i++)
    {
      sum_2+=a[1][i];
    }
    
    if(sum_1>=sum_2)
    {
      ans+=a[0][j+1];
    }
    else
    {
      ans+=a[1][j];
    }
    j++;
  }
   
 printf("%d\n",ans);
  return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

int Max(int a, int b) {
	return a < b ? b : a;
}

int main(void) {
	int n, c,grid[2][51] = {0};
	scanf("%d", &n);

	for (int i = 0; i < 2; i++) {
		for (int j = 1; j <= n; j++) {
			scanf("%d", &c);
			if (i == 0) {
				grid[i][j] = grid[i][j - 1] + c;
			}
			else {
				grid[i][j] = Max(grid[i][j - 1], grid[i - 1][j]) + c;
			}
		}
	}
	printf("%d\n", grid[1][n]);
}
//  [javascript]
function main(input) {
  const lines = input.split("\n");
  const N = parseInt(lines.shift());

  const upper = lines.shift().split(' ').map(x => parseInt(x));
  const downer = lines.shift().split(' ').map(x => parseInt(x));

  const cum_up = [upper[0]];
  const cum_down = [downer[0]];

  if (N==1){
    console.log(upper[0] + downer[0]);
    return
  }
  for(var i=1;i<N;i++){
    cum_up.push(cum_up[i-1]+upper[i])
    cum_down.push(cum_down[i-1]+downer[i])
  }

  var result = cum_up[0]+cum_down[N-1];
  for(var i=1;i<N;i++){
    var current = cum_up[i]+cum_down[N-1]-cum_down[i-1]
    if (current > result){result = current;}
  }

  console.log(result);

//  console.log(upper);
//  console.log(cum_up);

//  console.log(downer);
//  console.log(cum_down);

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
// inputに入力データ全体が入る
function Main(input) {

  var inp = input.split('\n');
  var N = inp[0];
  var tmp = inp[1].split(' ');
  var tmp2 = inp[2].split(' ');
  var A = new Array;
  A[0] = new Array;
  A[1] = new Array;

  for (var j = 0; j < N; j++) {
    A[0][j] = parseInt(tmp[j]);
    A[1][j] = parseInt(tmp2[j]);
  }


  var maxVal = 0;
  for (var tmp = 0; tmp <= N - 1; tmp++) {
    var sum = 0;
    for (var l = 0; l <= N - 1 - tmp; l++) {
      sum += A[0][l];
    }
    for (var m = N - 1 - tmp; m <= N - 1; m++) {
      sum += A[1][m];
    }
    if (sum > maxVal) maxVal = sum;
  }
  console.log('%d', maxVal);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
"use strict";
function Main(input) {
    let cin = new Inputer(input);
    let N = cin.getInt();
    let A0 = new Array(N);
    let A1 = new Array(N);
    for (let n = 0; n < N; n++) A0[n] = cin.getInt();
    for (let n = 0; n < N; n++) A1[n] = cin.getInt();
    for (let n = 1; n < N; n++) {
        A0[n] += A0[n - 1];
        A1[N - n - 1] += A1[N - n];
    }
    let ans = 0;
    for (let n = 0; n < N; n++) {
        let s = A0[n] + A1[n];
        if (ans < s) ans = s;
    }
    console.log(ans);
}
class Inputer{constructor(t){if(typeof t=='undefined')throw new Error('引数（stdin）を省略できません！');this.cnt=0;this.items=t.split(/\n|\s/)}getInt(){return this.items[this.cnt++]-0}getIntArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');if(t<1)throw new Error('引数は1以上であること！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getInt();return r}getStr(){return this.items[this.cnt++]}getStrArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');if(t<1)throw new Error('引数は1以上であること！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getStr();return r}}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
"use strict";
    
const main = arg => {
    arg = arg.split("\n");
    const N     = ~~arg[0];
    const table = arg.slice(1, 3).map(n=>n.split(" ").map(l=>~~l));
    
    const topLowSum    = table[0].reduce((m,n)=>m+n);
    const bottomLowSum = table[1].reduce((m,n)=>m+n);
    
    let answer = 0;
    let pivot;

    for(let i=0; i<N; i++) {
        let top  = topLowSum - table[0].slice(0, i + ~~1).reduce((m,n)=>m+n) + table[1][N-1];
        let down = i === 0 ? bottomLowSum : bottomLowSum - table[1].slice(0, i).reduce((m,n)=>m+n);
    
        if(down > top) {
            pivot = i;
            break;
        }
    }
    
    if(pivot !== undefined) {
        const beforePivot = table[0].slice(0, pivot + 1).reduce((m,n)=>m+n);
        const afterPivot  = table[1].slice(pivot, N).reduce((m,n)=>m+n);

        console.log(beforePivot + afterPivot);
    } else {
        console.log(topLowSum + table[1][N-1]);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N     = ~~arg[0];
    const table = arg.slice(1, 3).map(n=>n.split(" ").map(l=>~~l));
    
    const topLowSum    = table[0].reduce((m,n)=>m+n);
    const bottomLowSum = table[1].reduce((m,n)=>m+n);
    
    let answer = 0;
    let pivot;

    for(let i=0; i<N; i++) {
        let top  = topLowSum - table[0].slice(0, i + ~~1).reduce((m,n)=>m+n) + table[1][N-1];
        let down = i === 0 ? bottomLowSum : bottomLowSum - table[1].slice(0, i).reduce((m,n)=>m+n);
    
        if(down > top) {
            pivot = i;
            break;
        }
    }
    
    if(pivot !== undefined) {
        const beforePivot = table[0].slice(0, pivot + 1).reduce((m,n)=>m+n);
        const afterPivot  = table[1].slice(pivot, N).reduce((m,n)=>m+n);

        console.log(beforePivot + afterPivot);
    } else {
        console.log(topLowSum + table[1][N-1]);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N     = ~~arg[0];
    const table = arg.slice(1, 3).map(n=>n.split(" ").map(l=>~~l));
    
    const topLowSum    = table[0].reduce((m,n)=>m+n);
    const bottomLowSum = table[1].reduce((m,n)=>m+n);
    
    let answer = 0;
    let pivot;
    
    console.log(bottomLowSum)
    
    for(let i=0; i<N; i++) {
        let top  = topLowSum - table[0].slice(0, i + ~~1).reduce((m,n)=>m+n) + table[1][N-1];
        let down = i === 0 ? bottomLowSum : bottomLowSum - table[1].slice(0, i).reduce((m,n)=>m+n);
    
        if(down > top) {
            pivot = i;
            break;
        }
    }
    
    if(pivot !== undefined) {
        const beforePivot = table[0].slice(0, pivot + 1).reduce((m,n)=>m+n);
        const afterPivot  = table[1].slice(pivot, N).reduce((m,n)=>m+n);

        console.log(beforePivot + afterPivot);
    } else {
        console.log(topLowSum + table[1][N-1]);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var n int
var A [][]int

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	A = make([][]int, 2)
	for i := 0; i < n; i++ {
		tmp := nextInt()
		A[0] = append(A[0], tmp)
	}
	sum := 0
	for i := 0; i < n; i++ {
		tmp := nextInt()
		sum += tmp
		A[1] = append(A[1], tmp)
	}

	upsum := make([]int, n)
	downsum := make([]int, n)
	upsum[0] = A[0][0]
	downsum[0] = sum

	ans := -1
	for i := 0; i < n; i++ {
		if upsum[i]+downsum[i] > ans {

			ans = upsum[i] + downsum[i]
		}
		if i < n-1 {
			upsum[i+1] = upsum[i] + A[0][i+1]
			downsum[i+1] = downsum[i] - A[1][i]
		}
	}

	fmt.Println(ans)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

// const (
// 	initialBufSize = bufio.MaxScanTokenSize //65536
// 	maxBufSize     = 100000
// )
func main() {
	scanner.Split(bufio.ScanWords)
	// buf := make([]byte, initialBufSize)
	// scanner.Buffer(buf, maxBufSize)

	n := nextInt()
	a1 := make([]int, n)
	a2 := make([]int, n)
	for i := range a1 {
		a1[i] = nextInt()
	}
	for i := range a2 {
		a2[i] = nextInt()
	}

	max := 0
	for i := 0; i < n; i++ {
		sum := 0
		for j := 0; j <= i; j++ {
			sum += a1[j]
		}
		for k := i; k < n; k++ {
			sum += a2[k]
		}
		if sum > max {
			max = sum
		}
	}
	fmt.Println(max)
}

func next() string {
	scanner.Scan()
	return scanner.Text()
}
func nextInt() int {
	i, err := strconv.Atoi(next())
	if err != nil {
		fmt.Println(err)
	}
	return i
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func solve() {
	n := getInt()
	a1 := getIntSlice(n)
	a2 := getIntSlice(n)

	ans := -1
	for i := 0; i < n; i++ {
		s := sum(a1[0:i+1]...) + sum(a2[i:n]...)
		ans = max(ans, s)
	}

	fmt.Fprintln(wr, ans)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

// -----------------------------------------

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func intMax(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

func main() {
	sc.Split(bufio.ScanWords)

	N := scanInt()
	A := [2][]int{}
	A[0], A[1] = make([]int, N), make([]int, N)
	for i := 1; i < N; i++ {
		A[0][i] += A[0][i-1]
	}
	for i := N - 2; i >= 0; i-- {
		A[1][i] += A[1][i+1]
	}

	ans := 0
	for i := 0; i < N; i++ {
		ans = intMax(ans, A[0][i]+A[1][i])
	}

	fmt.Println(ans)
}
//  [go]
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([][]int, 2)
	t := [2]int{0, 0}
	for i := 0; i < 2; i++ {
		a[i] = make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Scan(&a[i][j])
			t[i] += a[i][j]
		}
	}

	ans := 0
	for i := 0; i < n; i++ {
		sum := 0
		for j := 0; j <= i; j++ {
			sum += a[0][j]
		}
		for j := i + 1; j < n; j++ {
			sum += a[1][j]
		}

		if ans < sum {
			ans = sum
		}
	}

	fmt.Println(ans)
}
//  [go]
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	m := make([][]int, 2)
	for i := 0; i < 2; i++ {
		n := make([]int, N)
		for j := 0; j < N; j++ {
			fmt.Scan(&n[j])
		}
		m[i] = n
	}
	wa := make([][]int, 2)
	a := make([]int, N)
	a[N-1] = m[1][N-1]
	for j := N - 1; j > 0; j-- {
		a[j-1] = m[1][j-1] + a[j]
	}
	wa[1] = a

	a = make([]int, N)
	for i := 1; i < N; i++ {
		a[i] = m[0][i] + wa[1][i]
	}
	wa[0] = a

	r := m[0][0]
	for i := 0; i < N; i++ {
		if i+1 == N {
			r += wa[1][N-1]
			break
		}
		if wa[0][i+1] > wa[1][i+1] {
			r += m[0][i+1]
		} else {
			fmt.Println("した")
			r += wa[1][i]
			break
		}
	}
	fmt.Println(r)

}
//  [ruby]
n = gets.to_i
as = 2.times.map{gets.chomp.split.map(&:to_i)}

dp = Array.new(2){Array.new(n,0)}
dp[0][0] = as[0][0]
dp[1][0] = dp[0][0] + as[1][0]
(0..n-2).each do |i|
	dp[0][i+1] = dp[0][i] + as[0][i+1]
	dp[1][i+1] = [dp[1][i] + as[1][i+1], dp[0][i+1] + as[1][i+1]].max
end

puts dp[1][n-1]
//  [ruby]
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end


def max(a,b)
    return a>b ? a : b
end
N=gets.to_i
a=array(2)
2.times do|i|
    a[i]=get_i
end
dp=array(N,0,2)
dp[0][0]=a[0][0]
2.times do|i|
    N.times do|j|
        next if i.zero? and j.zero?
        if i-1>=0
            dp[i][j]=max(dp[i][j],dp[i-1][j]+a[i][j])
        end
        if j-1>=0
            dp[i][j]=max(dp[i][j],dp[i][j-1]+a[i][j])
        end
    end
end
puts dp[1][N-1]
//  [ruby]
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)

suma=0
sumb=0
n.times do |i|
  suma += a[i]
  sumb += b[i]
end

suma += b[n-1]
sumb += a[0]

if suma > sumb then
  ans=suma
else
  ans=sumb
end

tmpsuma=a[0]
tmpsumb=sumb-a[0]
for i in 1..n-1 do
  if i==0 then
    i = 1
  end
  tmpsuma += a[i]
  tmpsumb -= b[i-1]
  if tmpsuma+tmpsumb > ans then
    ans = tmpsuma+tmpsumb
  end
end

puts ans
//  [ruby]
n=gets.to_i
up,under=2.times.map{gets.split.map(&:to_i)}
a=0

for i in 1...n-1
    v1=up[0..i].inject(&:+)
    v2=under[i..-1].inject(&:+)
    if v1+v2>a
        a=v1+v2
    end
    
end
puts a
//  [ruby]
lines = readlines.join.split.map(&:to_i)
range = lines.shift
ary = []
2.times do 
    ary << lines.slice!(0..range-1)
end
ans = []
for i in 0..range do
    ans << (ary[0].slice(0..i)).push(ary[1].slice(i..range-1))
end
ans.map!{|t| t.flatten}
ans.map!{|f| f.sum }
p ans.max
//  [ruby]
lines = readlines.join.split.map(&:to_i)
range = lines.shift
ary = []
2.times do 
    ary << lines.slice!(0..range-1)
end
ans = []
for i in 0..range do
    ans << (ary[0].slice(0..i)).append(ary[1].slice(i..range-1))
end
ans.map!{|t| t.flatten}
ans.map!{|f| f.sum }
p ans.max
//  [rust]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        n: usize,
        a1: [i64; n],
        a2: [i64; n],
    };
    println!(
        "{}",
        (0..n)
        .map(|i|{
            (0..i+1).map(|i| a1[i]).sum::<i64>() +
            (i..n).map(|i| a2[i]).sum::<i64>()
        })
        .max().unwrap()
    );
}
//  [rust]
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<Vec<usize>> = (0..2)
        .map(|_| {
            (0..n)
                .map(|_| itr.next().unwrap().parse().unwrap())
                .collect()
        })
        .collect();

    let mut ans = 0;
    for i in 0..n {
        let mut tmp = 0;
        let mut k = 0;
        for j in 0..n {
            tmp += a[k][j];
            if i == j {
                tmp += a[k + 1][j];
                k += 1;
            }
        }
        ans = std::cmp::max(ans, tmp);
    }
    println!("{}", ans);
}
//  [rust]
use std::io;

fn read_grid() -> Vec<Vec<i32>> {
    //! load stdio input like below.
    //! ```
    //! 2
    //! 2 3
    //! 4 5
    //! ```
    let mut line = String::new();
    let mut inputs = Vec::<Vec<char>>::new();
    io::stdin().read_line(&mut line).unwrap();
    let n = line.trim().parse::<i32>();
    line.clear();
    io::stdin().read_line(&mut line).unwrap();
    let first_line: Vec<i32> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    line.clear();
    io::stdin().read_line(&mut line).unwrap();
    let second_line: Vec<i32> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    vec![first_line, second_line]
}

fn solve(grid: Vec<Vec<i32>>) -> i32 {
    let mut max_all = 0;
    for k in 1..(grid[0].len() + 1) {
        let start = grid[0][0];
        let first_sum: i32 = grid[0][..k].iter().sum();
        let second_sum: i32 = grid[1][(k - 1)..].iter().sum();
        let sum = first_sum + second_sum;

        if sum > max_all {
            max_all = sum;
        }
    }
    let first_sum: i32 = grid[0].iter().sum();
    let second_sum: i32 = grid[1][grid[0].len() - 1];
    let sum = first_sum + second_sum;
    if sum > max_all {
        max_all = sum;
    }
    return max_all;
}

fn main() {
    let inputs = read_grid();
    let res = solve(inputs);
    println!("{}", res);
}
//  [rust]
use std::io;

fn read_grid() -> Vec<Vec<i32>> {
    //! load stdio input like below.
    //! ```
    //! 2
    //! 2 3
    //! 4 5
    //! ```
    let mut line = String::new();
    let mut inputs = Vec::<Vec<char>>::new();
    io::stdin().read_line(&mut line).unwrap();
    let n = line.trim().parse::<i32>();
    line.clear();
    io::stdin().read_line(&mut line).unwrap();
    let first_line: Vec<i32> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    line.clear();
    io::stdin().read_line(&mut line).unwrap();
    let second_line: Vec<i32> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    vec![first_line, second_line]
}

fn solve(grid: Vec<Vec<i32>>) -> i32 {
    let mut max_all = 0;
    for k in 0..grid[0].len() {
        let start = grid[0][0];
        let first_sum: i32 = grid[0][..k].iter().sum();
        let second_sum: i32 = grid[1][k..].iter().sum();
        let sum = first_sum + second_sum + start;

        if sum > max_all {
            max_all = sum;
        }
    }
    let first_sum: i32 = grid[0].iter().sum();
    let second_sum: i32 = grid[1][grid[0].len() - 1];
    let sum = first_sum + second_sum;
    if sum > max_all {
        max_all = sum;
    }
    return max_all;
}

fn main() {
    let inputs = read_grid();
    let res = solve(inputs);
    println!("{}", res);
}
//  [rust]
use std::io;

fn read_grid() -> Vec<Vec<i32>> {
    //! load stdio input like below.
    //! ```
    //! 2
    //! 2 3
    //! 4 5
    //! ```
    let mut line = String::new();
    let mut inputs = Vec::<Vec<char>>::new();
    io::stdin().read_line(&mut line).unwrap();
    let n = line.trim().parse::<i32>();
    line.clear();
    io::stdin().read_line(&mut line).unwrap();
    let first_line: Vec<i32> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    line.clear();
    io::stdin().read_line(&mut line).unwrap();
    let second_line: Vec<i32> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    vec![first_line, second_line]
}

fn solve(grid: Vec<Vec<i32>>) -> i32 {
    let mut max_all = 0;
    for k in 0..grid[0].len() {
        let start = grid[0][0];
        let first_sum: i32 = grid[0][..k].iter().sum();
        let second_sum: i32 = grid[1][k..].iter().sum();
        let sum = first_sum + second_sum + start;

        if sum > max_all {
            max_all = sum
        }
    }
    let first_sum: i32 = grid[0].iter().sum();
    let second_sum: i32 = grid[1][grid[0].len() - 1];
    let sum = first_sum + second_sum;
    if sum > max_all {
        max_all = sum
    }
    return max_all;
}

fn main() {
    let inputs = read_grid();
    let res = solve(inputs);
    println!("{}", res);
}
//  [rust]
use std::io;

fn read_grid() -> Vec<Vec<i32>> {
    //! load stdio input like below.
    //! ```
    //! 2
    //! 2 3
    //! 4 5
    //! ```
    let mut line = String::new();
    let mut inputs = Vec::<Vec<char>>::new();
    io::stdin().read_line(&mut line).unwrap();
    let n = line.trim().parse::<i32>();
    line.clear();
    io::stdin().read_line(&mut line).unwrap();
    let first_line: Vec<i32> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    line.clear();
    io::stdin().read_line(&mut line).unwrap();
    let second_line: Vec<i32> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    vec![first_line, second_line]
}

fn solve(grid: Vec<Vec<i32>>) -> i32 {
    let mut max_all = 0;
    for k in 0..grid[0].len() {
        let start = grid[0][0];
        let first_sum: i32 = grid[0][..k].iter().sum();
        let second_sum: i32 = grid[1][k..].iter().sum();
        let sum = first_sum + second_sum + start;

        if sum > max_all {
            max_all = sum
        }
    }
    return max_all;
}

fn main() {
    let inputs = read_grid();
    let res = solve(inputs);
    println!("{}", res);
}
//  [swift]
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}

func readLines() -> [String] {
    return readLine()!.map { String($0) }
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}
// https://algo-logic.info/divisor/
/// 約数の配列を返す
func divisor(_ n:Int) -> [Int] {
    var ret = [Int]()
    var i = 1
    while i * i <= n {
        if n % i == 0 {
            ret.append(i)
            if i * i != n {
                ret.append(n / i)
            }
        }
        i += 1
    }
    return ret
}

func main() {
    let n = readInt()
    let table = [readInts(),readInts()]
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    var remUnder = table[1].reduce(0) { $0 + $1 }
    
    var ans = 0
    var left = 0
    for i in 0..<n {
        left += table[0][i]
        ans = max(ans, remUnder + left)
        remUnder -= table[1][i]
    }
    print(ans)
}
main()
//  [swift]
let N = Int(readLine()!)!
let A1 = readLine()!.characters.split(" ").map{Int(String($0))!}
let A2 = readLine()!.characters.split(" ").map{Int(String($0))!}
var sumA1 = A1[0]
var sumA2 = A2.reduce(0){$0+$1}
var ans = sumA1 + sumA2
for i in 1..<N {
    sumA1 += A1[i]
    sumA2 -= A2[i-1]
    ans = max(sumA1 + sumA2, ans)
}
print(ans)
//  [swift]
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}

func readLines() -> [String] {
    return readLine()!.map { String($0) }
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}
// https://algo-logic.info/divisor/
/// 約数の配列を返す
func divisor(_ n:Int) -> [Int] {
    var ret = [Int]()
    var i = 1
    while i * i <= n {
        if n % i == 0 {
            ret.append(i)
            if i * i != n {
                ret.append(n / i)
            }
        }
        i += 1
    }
    return ret
}
 
func main() {
    let n = readInt()
    let table = [readInts(),readInts()]
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    var remOver = table[0].reduce(0) { $0 + $1 }
    var remUnder = table[1].reduce(0) { $0 + $1 }
    var ans = 0
    
    var isOver = true
    
    for i in 0..<n {
        ans += table[0][i]
        remOver -= table[0][i]
        if remOver + table[1][n - 1] < remUnder {
            ans += remUnder
            isOver = false
            break
        }
        remUnder -= table[1][i]
    }
    
    print(isOver ? ans + table[1][n - 1]: ans)
}
main()
//  [swift]
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}

func readLines() -> [String] {
    return readLine()!.map { String($0) }
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}
// https://algo-logic.info/divisor/
/// 約数の配列を返す
func divisor(_ n:Int) -> [Int] {
    var ret = [Int]()
    var i = 1
    while i * i <= n {
        if n % i == 0 {
            ret.append(i)
            if i * i != n {
                ret.append(n / i)
            }
        }
        i += 1
    }
    return ret
}
 
func main() {
    let n = readInt()
    var table = [readInts(),readInts()]
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    var remOver = table[0].reduce(0) { $0 + $1 }
    var remUnder = table[1].reduce(0) { $0 + $1 }
    
    var ans = 0
    
    for i in 0..<n {
        ans += table[0][i]
        if remOver - table[0][i] < remUnder {
            ans += remUnder
            break
        }
        remOver -= table[0][i]
        remUnder -= table[1][i]
    }
    
    print(ans)
}
main()