#include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector a(n+1); for (int i = 0; i <= n; i++) cin >> a[i]; // Total vertices V and sum of degrees sumD ll V = 0, sumD = 0; for (int i = 0; i <= n; i++) { V += a[i]; // include isolated vertices (degree 0) sumD += a[i] * i; } // Basic necessary conditions if ((sumD & 1) || sumD > 2*(V - 1)) { cout << "No\n"; return 0; } // Max degree constraint: no degree >= V for (int d = V; d <= n; d++) { if (a[d] > 0) { cout << "No\n"; return 0; } } // Build degree groups in descending order vector degs; vector cnt; for (int d = n; d >= 0; d--) { if (a[d] > 0) { degs.push_back(d); cnt.push_back(a[d]); } } int m = degs.size(); // Prefix counts and prefix sum of degrees vector pc(m), ps(m); for (int i = 0; i < m; i++) { pc[i] = cnt[i] + (i > 0 ? pc[i-1] : 0); ps[i] = cnt[i]*degs[i] + (i > 0 ? ps[i-1] : 0); } // Check Erdos-Gallai for forest for (int i = 0; i < m; i++) { ll k = pc[i]; // number of largest-degree vertices ll lhs = ps[i]; // sum of their degrees // compute rhs = k*(k-1) + sum_{j>i} min(degs[j], k) ll rhs = k*(k-1); if (i < m-1) { // find first index j>i where degs[j] <= k int l = i+1, r = m; while (l < r) { int mid = (l+r)/2; if (degs[mid] > k) l = mid+1; else r = mid; } int p = l; // those with deg > k contribute k each ll cntBig = (p-1 >= i+1 ? pc[p-1] - pc[i] : 0); // those with deg <= k contribute deg ll sumSmall = ps[m-1] - (p-1 >= 0 ? ps[p-1] : 0); rhs += cntBig * k + sumSmall; } if (lhs > rhs) { cout << "No\n"; return 0; } } cout << "Yes\n"; return 0; }