n = gets.to_i
a = gets.split.map(&:to_i)
erasable = {}
(0..n-1).each do |d|
    (0..n-1-d).each do |i|
        if d == 0
            erasable[[i, i]] = false
        elsif d <= 2
            erasable[[i, i+d]] = (a[i..i+d].uniq.size == 1)
        elsif (i..i+d-1).any? {|j| erasable[[i, j]] && erasable[[j+1, i+d]]}
            erasable[[i, i+d]] = true
        elsif a[i] == a[i+d]
            j = i
            j += 1 until a[j+1] != a[i]
            k = i + d
            k -= 1 until a[k-1] != a[i+d]
            erasable[[i, i+d]] = erasable[[j+1, k-1]]
        else
            erasable[[i, i+d]] = false
        end
    end
end
puts erasable[[0, n-1]] ? 'yes' : 'no'

