#pragma GCC optimize "O3" #pragma GCC target "avx" #include #include #include #include #include #include #include #include #include #include #include #include #include #define repeat(i,n) for (int i = 0; (i) < int(n); ++(i)) #define repeat_from(i,m,n) for (int i = (m); (i) < int(n); ++(i)) #define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i)) #define repeat_from_reverse(i,m,n) for (int i = (n)-1; (i) >= int(m); --(i)) #define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) #define debug(x) #x << " = " << (x) << " " using ll = long long; using namespace std; template inline void setmax(T & a, T const & b) { a = max(a, b); } template inline void setmin(T & a, T const & b) { a = min(a, b); } template auto vectors(X x, T a) { return vector(x, a); } template auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector(x, cont); } ll gcd(ll a, ll b) { while (a) { b %= a; swap(a, b); } return b; } pair make_rational(ll num, ll den) { ll d = gcd(num, den); return make_pair(num / d, den / d); } pair operator + (pair x, pair y) { return make_rational(x.first * y.second + y.first * x.second, x.second * y.second); } pair operator - (pair x, pair y) { return make_rational(x.first * y.second - y.first * x.second, x.second * y.second); } pair operator * (pair x, pair y) { return make_rational(x.first * y.first, x.second * y.second); } pair operator / (pair x, pair y) { return make_rational(x.first * y.second, x.second * y.first); } constexpr int max_n = 7; int main() { int n; scanf("%d", &n); vector a(n); repeat (i,n) scanf("%d", &a[i]); bool found = false; array, 2*max_n-1> s; repeat (i,n) s[i] = { ll(a[i]), 1 }; repeat_from (i,n,max_n) s[i] = { -1, 0 }; repeat(i,max_n-1) s[max_n+i] = { -2, 0 }; whole(sort, s); do { stack > stk; int i = 0; function go = [&]() { if (found) return; if (s[i] == make_pair(-1, 0)) { // invalid } else if (s[i] == make_pair(-2, 0)) { // op if (stk.size() >= 2) { pair y = stk.top(); stk.pop(); pair x = stk.top(); stk.pop(); if (x == y) { found = true; } ++ i; stk.push(x + y); go(); stk.pop(); stk.push(x - y); go(); stk.pop(); stk.push(x * y); go(); stk.pop(); stk.push(x / y); go(); stk.pop(); -- i; stk.push(x); stk.push(y); } } else { stk.push(s[i]); ++ i; go(); -- i; stk.pop(); } }; go(); } while(whole(next_permutation, s)); printf("%s\n", found ? "YES" : "NO"); return 0; }