program atcoder
    implicit none
    integer(8) :: i,j,n
    integer(8),allocatable,dimension(:,:) :: dpf,dps
    integer(8),allocatable,dimension(:) :: a
    read*,n
    allocate(dpf(0:n,0:n))
    allocate(dps(0:n,0:n))
    allocate(a(n))
    read(*,*)(a(i),i=1,n)

    ! dpf(i,j) := [i,j]の区間でゲームを行った際の先攻の人の得点
    ! dps(i,j) := [i,j]の区間でゲームを行った際の後攻の人の得点

    do i = 1,n
        dpf(i,i) = a(i)
        dps(i,i) = 0
        !区間が[i,i]の時、先攻はa[i]点、後攻の人は0点
    enddo
    

    do i = 1,n
        do j = 1,n-i
            
            ! 区間[j,i+j]で先攻の人の得点は 
            ! ( a(j)+区間[j+1,i+j]で後攻の人の得点 )　と　( a(j+i)+区間[j,i+j-1]で後攻の人の得点 ) の大きい方
            dpf(j,i+j) = max( dps(j+1,j+i)+a(j) , dps(j,j+i-1)+a(j+i) )

            ! 区間[j,i+j]で後攻の人の得点は 
            ! 先攻の人がa(j)を取った場合 -> 区間(j+1,i+j)の先攻の人の得点
            ! 先攻の人がa(i+j)を取った場合 -> 区間(j,i+j-1)の先攻の人の得点
            if( dps(j+1,j+i)+a(j) > dps(j,j+i-1)+a(j+i) )then
                dps(j,j+i) = dpf(j+1,j+i)
            else
                dps(j,j+i) = dpf(j,j+i-1)
            endif

        enddo
    enddo

    write(*,'(I0)')dpf(1,n)-dps(1,n)


    stop 
contains
end program atcoder

; ModuleID = 'FIRModule'
source_filename = "FIRModule"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@_QFEa.0 = internal unnamed_addr global ptr null
@_QFEdpf.0 = internal unnamed_addr global ptr null
@_QFEdpf.7 = internal unnamed_addr global i64 1
@_QFEdpf.8 = internal unnamed_addr global i64 0
@_QFEdpf.10 = internal unnamed_addr global i64 1
@_QFEdps.0 = internal unnamed_addr global ptr null
@_QFEdps.7 = internal unnamed_addr global i64 1
@_QFEdps.8 = internal unnamed_addr global i64 0
@_QFEdps.10 = internal unnamed_addr global i64 1
@_QQcl.c7fc116d452e5b63ffa17e79462fb7ca = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_5204/source.f\00"
@_QQcl.28493029 = linkonce constant [4 x i8] c"(I0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #1 {
  %1 = alloca i64, align 8
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.c7fc116d452e5b63ffa17e79462fb7ca, i32 6)
  %3 = call i1 @_FortranAioInputInteger(ptr %2, ptr nonnull %1, i32 8)
  %4 = call i32 @_FortranAioEndIoStatement(ptr %2)
  %5 = load i64, ptr %1, align 8, !tbaa !3
  %6 = add i64 %5, 1
  %7 = call i64 @llvm.smax.i64(i64 %6, i64 0)
  %8 = shl i64 %7, 3
  %9 = mul i64 %8, %7
  %10 = call ptr @malloc(i64 %9)
  %11 = icmp ugt i64 %5, 9223372036854775806
  %12 = zext i1 %11 to i64
  store ptr %10, ptr @_QFEdpf.0, align 8, !tbaa !7
  store i64 %12, ptr @_QFEdpf.7, align 8, !tbaa !7
  store i64 %7, ptr @_QFEdpf.8, align 8, !tbaa !7
  store i64 %12, ptr @_QFEdpf.10, align 8, !tbaa !7
  %13 = call ptr @malloc(i64 %9)
  store ptr %13, ptr @_QFEdps.0, align 8, !tbaa !7
  store i64 %12, ptr @_QFEdps.7, align 8, !tbaa !7
  store i64 %7, ptr @_QFEdps.8, align 8, !tbaa !7
  store i64 %12, ptr @_QFEdps.10, align 8, !tbaa !7
  %14 = call i64 @llvm.smax.i64(i64 %5, i64 0)
  %15 = shl i64 %14, 3
  %16 = call ptr @malloc(i64 %15)
  store ptr %16, ptr @_QFEa.0, align 8, !tbaa !7
  %17 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.c7fc116d452e5b63ffa17e79462fb7ca, i32 10)
  %18 = load i64, ptr %1, align 8, !tbaa !3
  %19 = icmp sgt i64 %18, 0
  br i1 %19, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %20 = phi i64 [ %24, %.lr.ph ], [ 1, %0 ]
  %.unpack699 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %21 = add i64 %20, -1
  %22 = getelementptr i64, ptr %.unpack699, i64 %21
  %23 = call i1 @_FortranAioInputInteger(ptr %17, ptr %22, i32 8)
  %24 = add nuw i64 %20, 1
  %exitcond.not = icmp eq i64 %20, %18
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  %25 = call i32 @_FortranAioEndIoStatement(ptr %17)
  %26 = load i64, ptr %1, align 8, !tbaa !3
  %27 = icmp sgt i64 %26, 0
  br i1 %27, label %.lr.ph712, label %._crit_edge719

.lr.ph712:                                        ; preds = %._crit_edge
  %.unpack655 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack667 = load ptr, ptr @_QFEdpf.0, align 8, !tbaa !7
  %.unpack674.unpack.unpack = load i64, ptr @_QFEdpf.7, align 8, !tbaa !7
  %.unpack674.unpack.unpack677 = load i64, ptr @_QFEdpf.8, align 8, !tbaa !7
  %.unpack674.unpack675.unpack = load i64, ptr @_QFEdpf.10, align 8, !tbaa !7
  %.unpack683 = load ptr, ptr @_QFEdps.0, align 8, !tbaa !7
  %.unpack690.unpack.unpack = load i64, ptr @_QFEdps.7, align 8, !tbaa !7
  %.unpack690.unpack.unpack693 = load i64, ptr @_QFEdps.8, align 8, !tbaa !7
  %.unpack690.unpack691.unpack = load i64, ptr @_QFEdps.10, align 8, !tbaa !7
  br label %28

28:                                               ; preds = %.lr.ph712, %28
  %29 = phi i64 [ 1, %.lr.ph712 ], [ %43, %28 ]
  %30 = add i64 %29, -1
  %31 = getelementptr i64, ptr %.unpack655, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !3
  %33 = sub i64 %29, %.unpack674.unpack.unpack
  %34 = sub i64 %29, %.unpack674.unpack675.unpack
  %35 = mul i64 %34, %.unpack674.unpack.unpack677
  %36 = add i64 %33, %35
  %37 = getelementptr i64, ptr %.unpack667, i64 %36
  store i64 %32, ptr %37, align 8, !tbaa !3
  %38 = sub i64 %29, %.unpack690.unpack.unpack
  %39 = sub i64 %29, %.unpack690.unpack691.unpack
  %40 = mul i64 %39, %.unpack690.unpack.unpack693
  %41 = add i64 %38, %40
  %42 = getelementptr i64, ptr %.unpack683, i64 %41
  store i64 0, ptr %42, align 8, !tbaa !3
  %43 = add nuw i64 %29, 1
  %exitcond720.not = icmp eq i64 %29, %26
  br i1 %exitcond720.not, label %._crit_edge713, label %28

._crit_edge713:                                   ; preds = %28
  %.pre = load i64, ptr %1, align 8, !tbaa !3
  %44 = icmp sgt i64 %.pre, 0
  br i1 %44, label %.lr.ph718, label %._crit_edge719

.lr.ph718:                                        ; preds = %._crit_edge713
  %.unpack551 = load ptr, ptr @_QFEdps.0, align 8
  %.unpack558.unpack.unpack = load i64, ptr @_QFEdps.7, align 8
  %.unpack558.unpack.unpack561 = load i64, ptr @_QFEdps.8, align 8
  %.unpack558.unpack559.unpack = load i64, ptr @_QFEdps.10, align 8
  %.unpack567 = load ptr, ptr @_QFEa.0, align 8
  %.unpack579 = load ptr, ptr @_QFEdpf.0, align 8
  %.unpack586.unpack.unpack = load i64, ptr @_QFEdpf.7, align 8
  %.unpack586.unpack.unpack589 = load i64, ptr @_QFEdpf.8, align 8
  %.unpack586.unpack587.unpack = load i64, ptr @_QFEdpf.10, align 8
  br label %45

45:                                               ; preds = %.lr.ph718, %._crit_edge716
  %46 = phi i64 [ 1, %.lr.ph718 ], [ %102, %._crit_edge716 ]
  %47 = load i64, ptr %1, align 8, !tbaa !3
  %48 = sub i64 %47, %46
  %49 = icmp sgt i64 %48, 0
  br i1 %49, label %.lr.ph715, label %._crit_edge716

.lr.ph715:                                        ; preds = %45, %95
  %50 = phi i64 [ %100, %95 ], [ %48, %45 ]
  %51 = phi i64 [ %52, %95 ], [ 1, %45 ]
  %52 = add nuw i64 %51, 1
  %53 = sub i64 %52, %.unpack558.unpack.unpack
  %54 = add nuw i64 %51, %46
  %55 = sub i64 %54, %.unpack558.unpack559.unpack
  %56 = mul i64 %55, %.unpack558.unpack.unpack561
  %57 = add i64 %53, %56
  %58 = getelementptr i64, ptr %.unpack551, i64 %57
  %59 = load i64, ptr %58, align 8, !tbaa !3
  %60 = add i64 %51, -1
  %61 = getelementptr i64, ptr %.unpack567, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !3
  %63 = add i64 %62, %59
  %64 = sub i64 %51, %.unpack558.unpack.unpack
  %65 = add i64 %54, -1
  %66 = sub i64 %65, %.unpack558.unpack559.unpack
  %67 = mul i64 %66, %.unpack558.unpack.unpack561
  %68 = add i64 %67, %64
  %69 = getelementptr i64, ptr %.unpack551, i64 %68
  %70 = load i64, ptr %69, align 8, !tbaa !3
  %71 = add i64 %54, -1
  %72 = getelementptr i64, ptr %.unpack567, i64 %71
  %73 = load i64, ptr %72, align 8, !tbaa !3
  %74 = add i64 %73, %70
  %75 = call i64 @llvm.smax.i64(i64 %63, i64 %74)
  %76 = sub i64 %51, %.unpack586.unpack.unpack
  %77 = sub i64 %54, %.unpack586.unpack587.unpack
  %78 = mul i64 %77, %.unpack586.unpack.unpack589
  %79 = add i64 %78, %76
  %80 = getelementptr i64, ptr %.unpack579, i64 %79
  store i64 %75, ptr %80, align 8, !tbaa !3
  %81 = load i64, ptr %58, align 8, !tbaa !3
  %82 = load i64, ptr %61, align 8, !tbaa !3
  %83 = add i64 %82, %81
  %84 = load i64, ptr %69, align 8, !tbaa !3
  %85 = load i64, ptr %72, align 8, !tbaa !3
  %86 = add i64 %85, %84
  %87 = icmp sgt i64 %83, %86
  br i1 %87, label %88, label %91

88:                                               ; preds = %.lr.ph715
  %89 = sub i64 %52, %.unpack586.unpack.unpack
  %90 = add i64 %89, %78
  br label %95

91:                                               ; preds = %.lr.ph715
  %92 = sub i64 %65, %.unpack586.unpack587.unpack
  %93 = mul i64 %92, %.unpack586.unpack.unpack589
  %94 = add i64 %93, %76
  br label %95

95:                                               ; preds = %88, %91
  %.sink = phi i64 [ %90, %88 ], [ %94, %91 ]
  %96 = getelementptr i64, ptr %.unpack579, i64 %.sink
  %97 = load i64, ptr %96, align 8, !tbaa !3
  %98 = add i64 %56, %64
  %99 = getelementptr i64, ptr %.unpack551, i64 %98
  store i64 %97, ptr %99, align 8, !tbaa !3
  %100 = add nsw i64 %50, -1
  %101 = icmp sgt i64 %50, 1
  br i1 %101, label %.lr.ph715, label %._crit_edge716

._crit_edge716:                                   ; preds = %95, %45
  %102 = add nuw i64 %46, 1
  %exitcond721.not = icmp eq i64 %46, %.pre
  br i1 %exitcond721.not, label %._crit_edge719, label %45

._crit_edge719:                                   ; preds = %._crit_edge716, %._crit_edge, %._crit_edge713
  %103 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28493029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.c7fc116d452e5b63ffa17e79462fb7ca, i32 41)
  %.unpack = load ptr, ptr @_QFEdpf.0, align 8, !tbaa !7
  %.unpack526.unpack.unpack = load i64, ptr @_QFEdpf.7, align 8, !tbaa !7
  %.unpack526.unpack.unpack529 = load i64, ptr @_QFEdpf.8, align 8, !tbaa !7
  %.unpack526.unpack527.unpack = load i64, ptr @_QFEdpf.10, align 8, !tbaa !7
  %104 = sub i64 1, %.unpack526.unpack.unpack
  %105 = load i64, ptr %1, align 8, !tbaa !3
  %106 = sub i64 %105, %.unpack526.unpack527.unpack
  %107 = mul i64 %106, %.unpack526.unpack.unpack529
  %108 = add i64 %104, %107
  %109 = getelementptr i64, ptr %.unpack, i64 %108
  %110 = load i64, ptr %109, align 8, !tbaa !3
  %.unpack535 = load ptr, ptr @_QFEdps.0, align 8, !tbaa !7
  %.unpack542.unpack.unpack = load i64, ptr @_QFEdps.7, align 8, !tbaa !7
  %.unpack542.unpack.unpack545 = load i64, ptr @_QFEdps.8, align 8, !tbaa !7
  %.unpack542.unpack543.unpack = load i64, ptr @_QFEdps.10, align 8, !tbaa !7
  %111 = sub i64 1, %.unpack542.unpack.unpack
  %112 = sub i64 %105, %.unpack542.unpack543.unpack
  %113 = mul i64 %112, %.unpack542.unpack.unpack545
  %114 = add i64 %111, %113
  %115 = getelementptr i64, ptr %.unpack535, i64 %114
  %116 = load i64, ptr %115, align 8, !tbaa !3
  %117 = sub i64 %110, %116
  %118 = call i1 @_FortranAioOutputInteger64(ptr %103, i64 %117)
  %119 = call i32 @_FortranAioEndIoStatement(ptr %103)
  %120 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

declare {} @_FortranAStopStatement(i32, i1, i1) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #2

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { noreturn }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!4, !4, i64 0}
!4 = !{!"any data access", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
!7 = !{!8, !8, i64 0}
!8 = !{!"descriptor member", !5, i64 0}
