program main
  implicit none
  integer :: i, n, k, m, total
  integer, allocatable :: a(:), dp(:,:,:)
  integer, parameter :: pmod = 998244353

  read *, n
  allocate (a(0:n-1))
  do i = 1, n
    read *, a(i)
  end do
  total = 3 ** n - (2**n - 2) * 3 - 3
  m = int((sum(a)+1)/2)
  allocate (dp(0:n, 0:2, 0:m))
  dp = 0
  dp(0, 2, 0) = 1

  do i = 1, n
    k = a(i-1)
    dp(i, :, k:) = dp(i, :, k:) + dp(i-1, :, :m-k-1)
    dp(i, :,m-1) = dp(i, :,m-1) + sum(dp(i-1, :, m-k:), dim=2)

    dp(i, 0, :) = dp(i, 0, :) + (dp(i-1, 0, :) + dp(i-1, 1, :)) * 2
    dp(i, 1, :) = dp(i, 1, :) + dp(i-1, 1, :)
    dp(i, 1, :) = dp(i, 1, :) + dp(i-1, 2, :)

    if (mod(i, 10) == 0) dp(i, :, :) = mod(dp(i, :, :), pmod)
  end do

  print '(i0)', mod((total - dp(-1, 0, -1) * 3), pmod)

end program
