Codeforces Round 245 (Div. 1)
C
Guess the Tree
Codeforces
2300
原题
← BD →
翻译中…

Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food.

翻译中…

Iahub asks Iahubina: can you build a rooted tree, such that

翻译中…
  • each internal node (a node with at least one son) has at least two sons;
  • node $*i*$ has $*c*_{*i*}$ nodes in its subtree?
翻译中…

Iahubina has to guess the tree. Being a smart girl, she realized that it's possible no tree can follow Iahub's restrictions. In this way, Iahub will eat all the food. You need to help Iahubina: determine if there's at least one tree following Iahub's restrictions. The required tree must contain $*n*$ nodes.

翻译中…

Input

翻译中…

The first line of the input contains integer $*n*$ ($1 ≤ *n* ≤ 24$). Next line contains $*n*$ positive integers: the $*i*$-th number represents $*c*_{*i*}$ $(1 ≤ *c*_{*i*} ≤ *n*)$.

翻译中…

Output

翻译中…

Output on the first line "YES" (without quotes) if there exist at least one tree following Iahub's restrictions, otherwise output "NO" (without quotes).

翻译中…

样例

Input #1
4
1 1 1 4
Output #1
YES
InputCopy OutputCopy
Input #2
5
1 1 5 2 1
Output #2
NO
InputCopy OutputCopy
题目信息
题号
429C
时间限制
1 s
内存限制
256 MB
标签
位运算
构造
动态规划
贪心
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。