CodeEff/ECCO huggingface dataset:
# Original solution
a,b = (int(i) for i in input().split())
ct= 0
for i in range(a,b+1):
 judge = str(i)
 if judge == judge[4]+judge[3]+judge[2]+judge[1]+judge[0]:
     ct  += 1
print(ct)

# Optimized solution
def solve():
  a,b = (int(i) for i in input().split())
  ct = 0
  for judge in range(a,b+1):
    j = str(judge)
    if j[0] == j[4] and j[1] == j[3]:
      ct += 1
  print(ct)
solve()
# Original solution
A,B=list(map(int,input().split()))
count=0
for i in range(A,B+1):
  #print(i)
  str_i=str(i)
  for j in range(len(str_i)):
    #print(str_i[j],str_i[-j-1])
    if(str_i[j]!=str_i[-j-1]):
      break
    if(j>(len(str_i)//2+1)):
      #print(i)
      count+=1
print(count)

# Optimized solution
A,B=list(map(int,input().split()))
S=0
for I in range(A,B+1):
	Q=str(I)
	R=Q[::-1]
	if R==Q:
		S+=1
print(S)
# Original solution
A,B=list(map(int,input().split()))
S=0
for I in range(A,B+1):
	Q=str(I)
	R=Q[::-1]
	if R==Q:
		S+=1
print(S)

# Optimized solution
a,b=list(map(int,input().split()))
print((len([i for i in map(str,list(range(a,b+1))) if i==i[::-1]])))#条件を満たすとき、リストの長さを１増やす。リストの長さが回文数の数。
# Original solution
# ABC090 B - Palindromic Numbers
a,b = list(map(int,input().split()))

ans = 0
for i in range(a,b+1):
    s = ''
    s = str(i)
    if s[0:1]==s[4:5] and s[1:2]==s[3:4]:
        ans += 1
print(ans)

# Optimized solution
a,b=list(map(int,input().split()))
ans=0
for i in range(a,b+1):
  t=str(i)
  if t==t[::-1]:
    ans+=1
print(ans)
# Original solution
a, b = list(map(int, input().split()))
x = 0

for i in range(a, b+1):
    if str(i)==str(i)[::-1]:
        x+=1

print(x)

# Optimized solution
a,b=list(map(int,input().split()))
print((len([i for i in map(str, list(range(a, b+1))) if i==i[::-1]])))
# Original solution
a,b = list(map(int,input().split()))
ans = 0
for i in range(a,b+1):
  if str(i) == str(i)[::-1]:
    ans += 1
print(ans)

# Optimized solution
a,b = list(map(int,input().split()))
ans = 0
for i in range(a,b+1):
  s = str(i)
  if s == s[::-1]:
    ans += 1
print(ans)
# Original solution
a, b = list(map(int, input().split()))
count = 0
for i in range(a, b+1):
  i = str(i)
  if i[0] == i[-1] and i[1] == i[-2]:
    count +=1
print(count)

# Optimized solution
A, B = list(map(int, input().split()))

count = 0
for i in range(A, B+1):
	s = str(i)
	if s[0] == s[4] and s[1] == s[3]:
		count += 1
print(count)
# Original solution
a, b = list(map(int, input().split()))
count = 0
for i in range(a, b + 1):
    if str(i)[0] == str(i)[4] and str(i)[1] == str(i)[3]:
        count += 1
print(count)

# Optimized solution
a, b = list(map(int, input().split()))
cnt = 0
for i in range(a, b + 1):
    if str(i) == str(i)[::-1]:
        cnt += 1
print(cnt)
# Original solution
A,B = list(map(int,input().split()))
j = 0
for i in range(A,B+1):
  l = list(str(i))
  l_reverse = list(reversed(l))
  if l == l_reverse:
    j += 1
print(j)

# Optimized solution
A, B = list(map(int,input().split()))

ans = 0
for n in range(A, B+1):
    n = str(n)
    if n == n[::-1]:
        ans += 1
print(ans)
# Original solution
import math

A, B = list(map(int, input().split()))
flag = True
count = 0
for i in range(A, B+1):
    for j in range(int(math.ceil(len(str(A)))/2)):
        if str(i)[j] != str(i)[-1-j]:
            count -= 1
            break
    count += 1
print(count)

# Optimized solution
import math

A, B = list(map(int, input().split()))
flag = True
count = B-A+1
for i in range(A, B+1):
    for j in range(int(math.ceil(len(str(A)))/2)):
        if str(i)[j] != str(i)[-1-j]:
            count -= 1
            break
print(count)
# Original solution
a,b=list(map(int,input().split()))

ans=0

for i in range(a,b+1):
    buf=str(i)
    #print(buf[0:int(len(buf)/2)],buf[int(len(buf)/2+1):])
    str1=buf[0:int(len(buf)/2)]
    str2=buf[int(len(buf)/2+1):]
    if str1[0]==str2[1] and str1[1]==str2[0]:
        ans+=1

print(ans)


# Optimized solution
a,b=list(map(int,input().split()))

ans=0

for i in range(a,b+1):
    buf=str(i)
    str1=buf[::-1]
    if buf==str1:
        ans+=1

print(ans)
# Original solution
In = input().split(" ")
T = int(In[0])
A = int(In[1])
K = int(In[2])
 
if K>=T+A:
  print("0 0")
else:
  if (K > T):
    print(("0 {0}".format(A-(K-T))))
  elif (T > K):
    print(("{0} {1}".format(T-K, A)))
  else:
    for i in range(K):
      if T >= 1:
        T -= 1
      else:
        if A >= 1:
          A -= 1
        else:
          break
    print(("{0} {1}".format(T, A)))

# Optimized solution
In = input().split(" ")
T = int(In[0])
A = int(In[1])
K = int(In[2])
 
if K <= T:
  print(("{0} {1}".format(T-K,A)))
elif K <= T+A:
  print(("0 {0}".format(A-(K-T))))
else:
  print("0 0")
# Original solution
a,b,k = list(map(int,input().split()))
if (a + b) <= k:
  print("0 0")
else:
  for i in range (k):
    if a > 0:
      a -= 1
    elif b > 0:
      b -= 1
    else:
      break
  print((str(a) + " " + str(b)))

# Optimized solution
a,b,k = list(map(int,input().split()))
if (a + b) <= k:
  a = 0
  b = 0
elif a >= k:
  a = a - k
else:
  b = b - (k - a)
  a = 0 
print((str(a) + " " + str(b)))
# Original solution
A,B,K = list(map(int,input().split()))

if K >= A+B:
    print((str(0)+' '+str(0)))

else:
    for i in range(K):
        if A > 0:
            A -= 1
        elif B > 0:
            B -= 1
    print((str(A)+' '+str(B)))

# Optimized solution
A,B,K = list(map(int,input().split()))

if K >= A+B:
    print((str(0)+' '+str(0)))

elif K < A:
    print((str(A-K)+' '+str(B)))

elif K >= A:
    print((str(0)+' '+str(B-(K-A))))
# Original solution
a = list(map(int, input().split()))

if((a[0]+a[1]) == a[2]):
    print("0 0")

if((a[0]+a[1]) != a[2]):
    for i in range(0, a[2]):
        if(a[0] >= 1):
            a[0] -= 1
        elif(a[1] >= 1):
            a[1] -= 1
    print(("%d %d"%(a[0],a[1])))    

# Optimized solution
a = list(map(int, input().split()))

t = a[0]-a[2]

if t<0:

    a[1] = a[1] +t
    if(a[1] < 0):
        a[1] = 0
    t = 0

print(("%d %d"%(t,a[1])))
# Original solution
import random
N = int(eval(input()))
a = [int(ai) for ai in input().split()]

random.seed(42)
count = 0
for i in range(0, N-1):
    if a[i] == a[i+1]:
        count += 1
    while a[i] == a[i+1]:
        a[i+1] = random.randint(1, N)
        if i < N - 2:
            while a[i+1] == a[i+2]:
                a[i+1] = random.randint(1, N)

print(count)

# Optimized solution
N = int(eval(input()))
a = [int(ai) for ai in input().split()]

count = 0
for i in range(0, N-1):
    if a[i] == a[i+1]:
        count += 1
        a[i+1] = float('inf')
print(count)
# Original solution
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N = int(eval(input()))
a = [int(t) for t in input().split()]
assert len(a) == N

# 同じ値が何個並んでいるか
sslen = [1]  # a[0]
for i in range(1, len(a)):
    if a[i] == a[i-1]:
        sslen[-1] += 1
    else:
        sslen.append(1)

print((sum(l//2 for l in sslen)))

# Optimized solution
from itertools import groupby

N = int(eval(input()))
a = list(map(int, input().split()))

n = sum(len(list(s))//2 for _,s in groupby(a))
print(n)
# Original solution
from itertools import*
print((sum(len(list(j))//2 for _, j in groupby(open(0).read().split()[1:]))))

# Optimized solution
from itertools import*
eval(input())
print((sum(len(list(j))//2for _,j in groupby(input().split()))))
# Original solution
eval(input())
cnt=0
now=0
res=0
for a in map(int,input().split()):
    if a==now:
        cnt+=1
    else:
        res+=cnt//2
        cnt=1
    now=a
print((res+cnt//2))

# Optimized solution
eval(input())
ans=x=0
for a in input().split():
    ans+=a==x
    x=a*(a!=x)
print(ans)
# Original solution
import random

n = int(eval(input()))
A = list(map(int, input().split()))

ans = 0
for i in range(1, n-1):
    if A[i] == A[i-1]:
        ans += 1
        while(1):
            A[i] = random.randrange(10000)+1
            if A[i] != A[i-1] and A[i] != A[i+1]: break

if A[-1] == A[-2]: ans += 1
print(ans)

# Optimized solution
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())


def main():
    n = II()
    A = LI()

    res = 0
    for i in range(1, n):
        if A[i] == A[i - 1]:
            A[i] = 0
            res += 1

    return res


print((main()))
# Original solution
N = int(eval(input()))
src = list(map(int,input().split()))

prev = -1
seq = 1
ans = 0
for a in src:
    if prev == a:
        seq += 1
    else:
        ans += seq//2
        seq = 1
    prev = a

if seq > 1:
    ans += seq//2
print(ans)

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))

ans = 0
changed = False
for a,b in zip(A,A[1:]):
    if changed:
        changed = False
        continue
    if a == b:
        ans += 1
        changed = True
print(ans)
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
neighbor = 1
nei = []
for i in range(1,n):
    if a[i] == a[i-1]:
        neighbor+=1
    else:
        if neighbor >1:
            nei.append(neighbor)
            neighbor = 1
if neighbor >1:
    nei.append(neighbor)
ans = 0
for x in nei:
    ans += x//2 
    
print(ans)

# Optimized solution
n = int(eval(input()))
ans = 0
a = list(map(int,input().split()))
now = a[0]
cnt = 1
p = []
for i in range(n-1):
    if now == a[i+1]:cnt+=1
    else:
        p.append(cnt)
        now = a[i+1]
        cnt = 1
p.append(cnt)
for x in p:
    ans+=x//2
print(ans)
# Original solution
import itertools

n = int(eval(input()))
a = list(map(int,input().split()))

res = 0
g = itertools.groupby(a)
for k,v in g:
    vv = len(list(v))
    res += vv//2
print(res)


# Optimized solution
from itertools import groupby as gb

N = int(eval(input()))
a = list(map(int,input().split()))
g = gb(a)
res = 0
for k,v in g:
    res += len(list(v)) // 2
print(res)
# Original solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
#from operator import itemgetter
from copy import deepcopy
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def LI2(): return [int(eval(input())) for i in range(n)]
def MXI(): return [LI()for i in range(n)]
inf = 10**17
mod = 10**9 + 7

s=input().rstrip()
u=list(s)
if (u[0]==u[1] and u[0]==u[2]) or (u[3]==u[1] and u[3]==u[2]):
    print("Yes")
else:
    print("No")

# Optimized solution
# coding: utf-8
# hello worldと表示する
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def LI2(): return [int(eval(input())) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print(('\n'.join(x)))
def printni(x): print(('\n'.join(list(map(str,x)))))
inf = 10**17
mod = 10**9 + 7

s=SI()
if (s[0]==s[1] and s[1]==s[2]) or (s[1]==s[2] and s[2]==s[3]):
    print("Yes")
else:
    print("No")
# Original solution
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics

def main():
    n = sys.stdin.readline().rstrip()

    if n[0] * 3 in n: ans = 'Yes'
    elif n [3] * 3 in n: ans = 'Yes'
    else: ans = 'No'
    print(ans)

if __name__ == "__main__":
    # execute only if run as a script
    main()


# Optimized solution
import sys

def main():
    n = sys.stdin.readline().rstrip()

    cnt = 1
    for i in range(3):
        if n[i] == n[i+1]:
            cnt += 1
            if cnt == 3:
                ans = 'Yes'
                break
        else:
            cnt = 1
    else:
        ans = 'No'
    
    print(ans)
    
if __name__ == "__main__":
    main()
# Original solution
import sys 
sys.setrecursionlimit(100000) 

N = int(eval(input()))
*a, = list(map(int, input().split()))

dp = [[-1] *  N for _ in range(N)]
for i in range(N): dp[i][i] = a[i]

def rec(i, j):
    if dp[i][j] != -1:
        return dp[i][j]
    ans = max(a[i] - rec(i+1, j), a[j] - rec(i, j-1))
    dp[i][j] = ans
    return ans

print((rec(0, N-1)))

# Optimized solution
N = int(eval(input()))
*a, = list(map(int, input().split()))

dp = [[None] *  N for _ in range(N)]
for i in range(N): dp[i][i] = a[i]

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

print((dp[0][N-1]))
# Original solution
N = int(eval(input()))
*a, = list(map(int, input().split()))

dp = [[None] *  N for _ in range(N)]
for i in range(N): dp[i][i] = a[i]

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

print((dp[0][N-1]))

# Optimized solution
N = int(eval(input()))
*a, = list(map(int, input().split()))

dp = [[0] *  N for _ in range(N)]
for i in range(N): dp[i][i] = a[i]

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

print((dp[0][N-1]))
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
n = N % 2

DP = [[0] * (N+1) for _ in range(N+1)]

for w in range(1, N+1):
    for i in range(N):
        j = i + w
        if j > N:
            continue
        if (w+n) % 2 == 1:
            DP[i][j] = min(DP[i+1][j] - A[i], DP[i][j-1] - A[j-1])
        else:
            DP[i][j] = max(DP[i+1][j] + A[i], DP[i][j-1] + A[j-1])

print((DP[0][N]))


# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
DP = [[0] * (N+1) for _ in range(N+1)]

for num in range(1, N + 1):
    for start in range(N):
        end = start + num
        if end > N:
            break
        if num == 1:
            DP[start][end] = A[start]
        else:
            DP[start][end] = max(A[start] - DP[start+1][end], A[end - 1] - DP[start][end - 1])
print((DP[0][N]))
# Original solution
import sys
sys.setrecursionlimit(10**6)
n=int(sys.stdin.readline())
a=list(map(int,sys.stdin.readline().split()))
d=dict()
def help(a,i,j):
    if d.get(str(i)+" "+str(j),None)!=None:
        return d[str(i)+" "+str(j)]
    if j<i:
        return 0
    if i==j:
        return a[i]
    t1=a[i]-help(a,i+1,j)
    t2=a[j]-help(a,i,j-1)
    # print(i,j)
    # print(t1,t2)
    if t1>t2:
        d[str(i)+" "+str(j)]=t1 
    else:
        d[str(i)+" "+str(j)]=t2 
    return d[str(i)+" "+str(j)]
print((help(a,0,len(a)-1)))

# Optimized solution
import sys
n=int(sys.stdin.readline())
a=list(map(int,sys.stdin.readline().split()))
dp=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
    dp[i][i]=a[i]
for i in range(2,n+1):
    for j in range(n-i+1):
        k=j+i-1 
        dp[j][k]=max(a[k]-dp[j][k-1],a[j]-dp[j+1][k])
print((dp[0][len(a)-1]))
# Original solution
def f(a,p1,p2):
    if p1>p2:
        return 0
   
    return max(a[p1]+min(f(a,p1+2,p2),f(a,p1+1,p2-1))
                      ,a[p2]+min(f(a,p1+1,p2-1),f(a,p1,p2-2)))
n=int(eval(input()))
a=list(map(int,input().split()))
s=sum(a)
first=f(a,0,n-1)
print((first-(s-first)))
                             


# Optimized solution
def f(a,i,j,dp):
    if dp[i][j]==-1:
        if i>j:
            return 0

        dp[i][j]=max(a[i]+min(f(a,i+2,j,dp),f(a,i+1,j-1,dp)),
                                a[j]+min(f(a,i+1,j-1,dp),f(a,i,j-2,dp)))
    return dp[i][j]
        
n=int(eval(input()))
dp=[[-1 for i in range(n)] for j in range(n)]
a=list(map(int,input().split()))
for i in range(n):
    dp[i][i]=a[i]

for i in range(n-1):
    dp[i][i+1]=max(a[i],a[i+1])

s1=f(a,0,n-1,dp)

print((s1-sum(a)+s1))
# Original solution
import sys
input = sys.stdin.readline
N = int(eval(input()))
a = list(map(int, input().split()))

dp = [[0] * (N + 1) for _ in range(N)]
for l in range(N):
  for r in range(l, N + 1):
    if l == r: continue
    if (N - (r - l)) % 2: dp[l][r] = float("inf")
    else: dp[l][r] = -float("inf") 
for c in range(N + 1):
  for l in range(N - c + 1):
    if l == N: continue
    r = l + c
    t = (N - (r - l)) % 2
    if l - 1 >= 0:
      if t == 0:
        dp[l - 1][r] = min(dp[l - 1][r], dp[l][r] - a[l - 1])
      else:
        dp[l - 1][r] = max(dp[l - 1][r], dp[l][r] + a[l - 1])
    if r + 1 <= N:
      if t == 0:
        dp[l][r + 1] = min(dp[l][r + 1], dp[l][r] - a[r])
      else:
        dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + a[r])
print((dp[0][N]))

# Optimized solution
import sys
input = sys.stdin.readline
N = int(eval(input()))
a = list(map(int, input().split()))
inf = 10 ** 14
dp = [[0] * (N + 1) for _ in range(N)]
for l in range(N):
  for r in range(l, N + 1):
    if l == r: continue
    if (N - (r - l)) % 2: dp[l][r] = inf
    else: dp[l][r] = -inf
for c in range(N + 1):
  for l in range(N - c + 1):
    if l == N: continue
    r = l + c
    t = (N - (r - l)) % 2
    if l - 1 >= 0:
      if t == 0:
        dp[l - 1][r] = min(dp[l - 1][r], dp[l][r] - a[l - 1])
      else:
        dp[l - 1][r] = max(dp[l - 1][r], dp[l][r] + a[l - 1])
    if r + 1 <= N:
      if t == 0:
        dp[l][r + 1] = min(dp[l][r + 1], dp[l][r] - a[r])
      else:
        dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + a[r])
print((dp[0][N]))
# Original solution
import sys
# input処理を高速化する
input = sys.stdin.readline

def chmax(a, b):
    if a >= b:
        return a
    return b

def chmin(a, b):
    if a <= b:
        return a
    return b

def main():
    N = int(eval(input()))
    a = list(map(int, input().split()))

    # aiからajのX−Yの最大値
    # [左端,右端)=[l,r)からの遷移    
    # 左をとる[l+1,r)、右をとる[l,r−1)の2通り
    dp = [[0] * (N+2)  for _ in range(N+2)]
    dp[N+1][N+1] = 4999999995

    for len in range(1, N + 1):
        for i in range(N + 1 - len):
            j = i + len

            if (N - len) % 2 == 0:
                dp[i][j] = chmax(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1])
            else:
                dp[i][j] = chmin(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1])

    print((dp[0][N]))
 


main()

# Optimized solution
import sys
# input処理を高速化する
input = sys.stdin.readline

def chmax(a, b):
    if a >= b:
        return a
    return b

def chmin(a, b):
    if a <= b:
        return a
    return b

def main():
    N = int(eval(input()))
    a = list(map(int, input().split()))

    # aiからajのX−Yの最大値
    # [左端,右端)=[l,r)からの遷移    
    # 左をとる[l+1,r)、右をとる[l,r−1)の2通り
    dp = [[0] * (N+2)  for _ in range(N+2)]

    for len in range(1, N + 1):
        for i in range(N + 1 - len):
            j = i + len

            if (N - len) % 2 == 0:
                dp[i][j] = chmax(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1])
            else:
                dp[i][j] = chmin(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1])

    print((dp[0][N]))

main()
# Original solution
N = int(eval(input()))
a = [int(x) for x in input().split()]
dp = [0 for i in range(N)]
for i in range(N-1, -1, -1):
    dp[i] = a[i]
    prev = dp[i]
    for j in range(i+1, N):
        right = a[i] - dp[j]
        left = a[j] - prev
        if right > left:
            dp[j] = right
            prev = right
        else:
            dp[j] = left
            prev = left
print((dp[-1]))

# Optimized solution
def main():
    N = int(eval(input()))
    a = list(map(int, input().split()))
 
    dp = [0 for i in range(N)]
 
    for i in range(N-1, -1, -1):
        dp[i] = a[i]
        prev = dp[i]
        for j in range(i+1, N):
            right = a[i] - dp[j]
            left = a[j] - prev
            if right > left:
                dp[j] = right
                prev = right
            else:
                dp[j] = left
                prev = left
    print((dp[-1]))
 
 
main()
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))
dp = [0 for i in range(N)]
for i in range(N-1, -1, -1):
    dp[i] = a[i]
    prev = dp[i]
    for j in range(i+1, N):
        right = a[i] - dp[j]
        left = a[j] - prev
        if right > left:
            dp[j] = right
            prev = right
        else:
            dp[j] = left
            prev = left
print((dp[-1]))

# Optimized solution
def main():
	N = int(eval(input()))
	a = list(map(int, input().split()))
	dp = [0 for i in range(N)]
	for i in range(N-1, -1, -1):
		dp[i] = a[i]
		prev = dp[i]
		for j in range(i+1, N):
			right = a[i] - dp[j]
			left = a[j] - prev
			if right > left:
				dp[j] = right
				prev = right
			else:
				dp[j] = left
				prev = left
	print((dp[-1]))

main()
# Original solution
import sys
sys.setrecursionlimit(10**9)
N = int(eval(input()))
a = list(map(int,input().split()))

cum = [0]*(N+1)
for i in range(N):
    cum[i] = cum[i-1]+a[i]

dp = [[-1]*N for _ in range(N)]
for i in range(N):
    dp[i][i] = a[i]

def cal(i,j):
    if dp[i][j] == -1:
        dp[i][j] = cum[j]-cum[i-1]-min(cal(i+1,j),cal(i,j-1))
    return dp[i][j]

print((2*cal(0,N-1)-cum[N-1]))

# Optimized solution
N = int(eval(input()))
a = list(map(int,input().split()))

dp = [[0]*(N+1) for _ in range(N+1)]

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

print((dp[0][N-1]))
# Original solution

def main():
    n = int(eval(input()))
    a = list(map(int, input().split()))

    dp = [[[0 for i in range(2)]for i in range(n+2)] for i in range(n+2)]
    # dp [start][end][chance] is the diffence between X and Y 
    # such for range start to end with the current chance of player
    for start in range(n, 0, -1):
        for end in range(start, n+1):
            for chance in range(2):
                temp = -1 if chance else 1
                val1 = a[start-1]*temp + dp[start+1][end][chance ^ 1]
                val2 = a[end-1]*temp + dp[start][end-1][chance ^ 1]
                dp[start][end][chance] = min(
                    val1, val2) if chance else max(val1, val2)
    print((dp[1][n][0]))


if __name__ == "__main__":
    main()


# Optimized solution

def main():
    n = int(eval(input()))
    a = list(map(int, input().split()))

    dp = [[0 for i in range(n+2)]for i in range(n+2)]
    # dp [start][end] is the diffence between X and Y
    # such for range start to end
    for start in range(n, 0, -1):
        for end in range(start, n+1):
            if start == end:
                dp[start][end] = a[start-1]
            else:
                dp[start][end] = max(a[start-1]-dp[start+1]
                                     [end], a[end-1]-dp[start][end-1])
    print((dp[1][n]))


if __name__ == "__main__":
    main()
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

dp = [[0] * (n+1) for _ in range(n+1)]

for i in range(n)[::-1]:
    for j in range(n + 1):
        if i >= j:
            continue
        minus = (n - i + j) % 2 * (-2) + 1
        dp[i][j] = max(a[j - 1]-dp[i][j - 1], a[i]-dp[i + 1][j])

print((dp[0][n]))


# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

dp = [[0] * (n+1) for _ in range(n+1)]

for i in range(n)[::-1]:
    for j in range(n + 1):
        if i >= j:
            continue
        dp[i][j] = max(a[j - 1] - dp[i][j - 1], a[i] - dp[i + 1][j])

print((dp[0][n]))