unittest
{
	assert( [ "5", "3 2 2 4 1", "1 2 2 2 1" ].parse.expand.solve == 14 );
	assert( [ "4", "1 1 1 1", "1 1 1 1" ].parse.expand.solve == 5 );
	assert( [ "7", "3 3 4 5 4 5 3", "5 3 4 4 2 3 2" ].parse.expand.solve == 29 );
	assert( [ "1", "2", "3" ].parse.expand.solve == 5 );
}



import std.algorithm;
import std.conv;
import std.functional;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	long[][ 2 ] ass;
	foreach( ref as; ass )
	{
		input.popFront;
		as = input.front.split.to!( long[] );
	}
	return tuple( ass );
}

long solve( long[][ 2 ] ass, long x = 0L, long y = 0L )
{
	auto l = ( ass.length      <= x + 1 ) ? 0L : memoize!solve( ass, x + 1, y );
	auto d = ( ass[ x ].length <= y + 1 ) ? 0L : memoize!solve( ass, x, y + 1 );
	
	return ass[ x ][ y ] + max( l, d );
}
