fun main(args:Array<String>?): Unit {
    val n = readLine()!!.trim().toInt()
    val states = readLine()!!.trim().split(' ').map(String::toInt)
    val ranges = states.indices.mapNotNull { i ->
        when {
            i == 0 ->
                i until ((i + 1 until n).find { j -> states[j] != states[i] } ?: n)
            states[i] != states[i - 1] ->
                i until ((i + 1 until n).find { j -> states[i] != states[j] } ?: n)
            else ->
                null
        }
    }
    val memo = Array(ranges.size){Array(ranges.size){null as Boolean?}}
    fun sub(from: Int, to: Int): Boolean {
        return when{
            to < from -> true
            memo[from][to] != null -> memo[from][to]!!
            else -> {
                memo[from][to] = (ranges[from].count() > 1 && sub(from + 1, to)) ||
                        (from + 1 until to).any{mid -> sub(from, mid) && sub(mid + 1, to)} ||
                        (states[ranges[from].first] == states[ranges[to].first] && ((from until to).filter{mid -> states[ranges[mid].first] == states[ranges[from].first]}.any{mid -> sub(from + 1, mid - 1) && sub(mid + 1, to - 1)}))
                memo[from][to]!!
            }
        }
    }
    println(
            if (sub(0, ranges.lastIndex)) "yes" else "no"
    )
}
