C. Three Parts of the Array

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an array d1,d2,…,dnd1,d2,…,dn consisting of nn integer numbers.

Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possibly, empty) of the original array.

Let the sum of elements of the first part be sum1sum1, the sum of elements of the second part be sum2sum2 and the sum of elements of the third part be sum3sum3. Among all possible ways to split the array you have to choose a way such that sum1=sum3sum1=sum3 and sum1sum1 is maximum possible.

More formally, if the first part of the array contains aa elements, the second part of the array contains bb elements and the third part contains ccelements, then:

sum1=∑1≤i≤adi,sum1=∑1≤i≤adi,sum2=∑a+1≤i≤a+bdi,sum2=∑a+1≤i≤a+bdi,sum3=∑a+b+1≤i≤a+b+cdi.sum3=∑a+b+1≤i≤a+b+cdi.

The sum of an empty array is 00.

Your task is to find a way to split the array such that sum1=sum3sum1=sum3 and sum1sum1 is maximum possible.

Input

The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of elements in the array dd.

The second line of the input contains nn integers d1,d2,…,dnd1,d2,…,dn (1≤di≤1091≤di≤109) — the elements of the array dd.

Output

Print a single integer — the maximum possible value of sum1sum1, considering that the condition sum1=sum3sum1=sum3 must be met.

Obviously, at least one valid way to split the array exists (use a=c=0a=c=0 and b=nb=n).

Examples

input

5
1 3 1 1 4

output

5

input

Copy

5
1 3 2 1 4

output

Copy

4

input

Copy

3
4 1 2

output

Copy

0

Note

In the first example there is only one possible splitting which maximizes sum1sum1: [1,3,1],[ ],[1,4][1,3,1],[ ],[1,4].

In the second example the only way to have sum1=4sum1=4 is: [1,3],[2,1],[4][1,3],[2,1],[4].

In the third example there is only one way to split the array: [ ],[4,1,2],[ ][ ],[4,1,2],[ ].

题解:将给的一组数分成3组(每一组都可以为0个数的和),是的sum1==sum3;  我们可以双向遍历数组,记录和,然后二分查找最大的即可;

AC代码为:

最新文章

  1. 2013年度IT博客大赛跻身10强
  2. UITextFieldDelegate协议
  3. 更新日志 - fir.im Jenkins & Gradle 插件上线
  4. RobotFrameWork webservice soap接口测试 (二)
  5. 如何查看tensorflow版本与存储位置
  6. JS中的call、apply、bind方法
  7. Enable Access Logs in JBoss 7 and tomcat--转
  8. hdu3308LCIS(线段树,点更新,段查寻,查寻时一定要注意跨越时如何计算)
  9. oracle Recyclebin
  10. sc delete 服务名
  11. Python中三种基本结构的语句
  12. ES6简介
  13. 从spring框架中的事件驱动模型出发,优化实际应用开发代码
  14. iOS 钥匙串存储用户数据
  15. Supercomputer 解题报告
  16. 【Windows】字符串处理
  17. asp.net web 服务器端全局定时执行任务
  18. MySql详解(七)
  19. python3转变exe的方法
  20. (原创)使用mceusb设备,将lirc移植到android笔记

热门文章

  1. Java自学基础、进阶、项目实战网站推荐
  2. Redis持久化的几种方式——深入解析RDB
  3. Vue项目性能优化整理
  4. tornado的使用-上传图片
  5. [LC]111题 二叉树的最小深度 (递归)
  6. [LC]141题 Intersection of Two Linked Lists (相交链表)(链表)
  7. SpringBoot基本配置详解
  8. Python字符串类型判断错误
  9. 【Vue | ElementUI】Vue离开当前页面时弹出确认框实现
  10. C++程序的耦合性设计