program histogram_coloring
  implicit none
  type pair
    integer(8) :: x, y
  end type
  integer(8), parameter :: md = 1000000007_8
  integer :: n, h(100) = 0
  type(pair) :: p
  read(*,*) n
  read(*,*) h(1:n)
  p = solve(h(1:n))
  write(*,'(i0)') p%y
contains
  recursive function solve(h) result(ret)
    integer, intent(in) :: h(:)
    integer :: m, x(size(h)+1)
    integer :: n, i, j, w
    integer(8) :: dp1, dp2
    type(pair) :: ret, tmp
    n = size(h)
    m = minval(h)
    x(1:n) = h-m
    x(n+1) = 0
    w = n
    dp1 = 1_8
    dp2 = 1_8
    i = 0
    do while (i <= n)
      j = i+1
      do while (x(j) /= 0)
        j = j+1
      end do
      if (i+1 <= j-1) then
        tmp = solve(x(i+1:j-1))
        dp1 = mod(dp1*tmp%x,md)
        dp2 = mod(dp2*(tmp%x+tmp%y),md)
        w = w-(j-i-1)
      end if
      i = j
    end do
    ret%x = mod(dp1*pow(2_8,m),md)
    ret%y = modulo(mod(dp2*pow(2_8,w),md)+mod(dp1*(pow(2_8,m)-2_8),md),md)
  end
  function pow(a,b) result(r)
    integer(8), intent(in) :: a
    integer, intent(in) :: b
    integer(8) :: r, p
    integer :: k
    r = 1_8
    p = a
    k = b
    do while (k > 0)
      if (btest(k,0)) r = mod(r*p,md)
      p = mod(p*p,md)
      k = rshift(k,1)
    end do
  end
end program histogram_coloring