from collections import defaultdict

while True:
    try:
        n = int(input())
        num = list(map(int, input().split()))
        d = defaultdict(int)
        for i in num:
            d[i] += 1
        q, r = divmod(n, 9)
        lst = list(d.values())
        if len(d) == 9 and lst.count(q+1) == r and lst.count(q) == 9-r:     # 排序后每9个数一组,最后可能多出几个数
            print('YES')
        else:
            print('NO')
    except:
        break