跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F0933. Maximum path

    ID: 939 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划贪心模拟算法思想编程与模拟挑战难度共享题库Codeforces英文题面题目来源题面语言

Maximum path

题目描述

D. Maximum path
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a rectangular table n. Each cell contains an integer. You can move from one cell to another if they share a side.

Find such path from the upper left cell to the bottom right cell of the table that doesn't visit any of the cells twice, and the sum of numbers written in the cells of this path is maximum possible.

Input

The first line contains an integer n (1≤n≤105) − the number of columns in the table.

Next three lines contain n integers each − the description of the table. The j-th number in the i-th line corresponds to the cell aij (-109aij≤109) of the table.

Output

Output the maximum sum of numbers on a path from the upper left cell to the bottom right cell of the table, that doesn't visit any of the cells twice.

Examples
Input
3
1 1 1
1 -1 1
1 1 1
Output
7
Input
5
10 10 10 -1 -1
-1 10 10 10 10
-1 10 10 10 10
Output
110
Note

The path for the first example:

The path for the second example:


题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 369 题。保留原作者与原赛事署名。