There is a shop selling cookies in baskets. The shop has N numbered baskets numbered from 1 to N in order.

Dave is trying to buy some cookies for his two sons. He is going to purchase cookies so that the baskets' for the first son is 1 to m, for the second the number should be m+1 to r.(1 <= l <= m, m+1 <= r <= N) However, the number of cookies which the two sons will receive must be the same. That is, if A[i] is the number of cookies contained in the basket i,A[l]+..+A[m] = A[m+1]+..+A[r] should be satisfied.

Given an array cookie that contains the number of cookies in order, complete the solution function that returns the maximum number of cookies that can be given to a son if he buys cookies that meet the conditions. However, if cookies cannot be purchased according to the conditions, return 0.

  • The length of the cookie between 1 and 2000, inclusive.
  • Each element of the cookie is a natural number between 1 and 500 inclusive.

cookie result
[1,1,2,3] 3
[1,2,4,5] 0

Example #1
If he buys basket number 2 and 3 for the first son and number 4 for the second son, they will receive 3 cookies each. It is the maximum number of cookies which can be given to each son.

Example #2
There is no way to buy cookies to meet the given condition.

Result Stop
Result of [Run Test] or [Submit] will be displayed here
내가 제출한 코드가 왜 틀렸는지 프로그래머스 AI에게 물어보세요.
제출 후 채점하기를 눌러 30점 이상인 경우 물어볼 수 있어요.
베타 기간 동안에는 한 문제당 1번만 물어볼 수 있어요.