class SegTree MIN = [-100_000_000, 0] def initialize(data) @offset = 1 << data.size.bit_length @data = Array.new(@offset * 2, MIN) @cmd = Array.new(@offset * 2, 0) data.each_with_index do |a,i| @data[@offset + i] = [a - i, i] end k = @offset - 1 while k > 0 if @data[2 * k][0] >= @data[2 * k + 1][0] @data[k] = @data[2 * k].dup else @data[k] = @data[2 * k + 1].dup end k -= 1 end end def apply_cmd(k) x = @cmd[k] @cmd[k] = 0 @data[k][0] += x if 2 * k + 1 < @data.size @cmd[2 * k] += x @cmd[2 * k + 1] += x end end def range_add(a, b, x, k = 1, l = 0, r = @offset) apply_cmd(k) return @data[k].dup if b <= l || r <= a if a <= l && r <= b @cmd[k] += x return [@data[k][0] + @cmd[k], @data[k][1]] end mid = (l + r) / 2 lv = range_add(a, b, x, 2 * k, l, mid) rv = range_add(a, b, x, 2 * k + 1, mid, r) if lv[0] >= rv[0] @data[k] = lv.dup else @data[k] = rv.dup end end def range_max(a, b, k = 1, l = 0, r = @offset) apply_cmd(k) return MIN if b <= l || r <= a return @data[k] if a <= l && r <= b mid = (l + r) / 2 return [range_max(a, b, 2 * k, l, mid), range_max(a, b, 2 * k + 1, mid, r)].max end def inspect @data[@offset, @offset].inspect + ", @cmd=#{@cmd}" end end N = gets.to_i A = gets.split.map(&:to_i) a0 = A.sum A.unshift(-a0) st = SegTree.new(A) loop do v, i = st.range_max(0, N + 1) if v.zero? && i.zero? puts "Yes" break elsif v.zero? st.range_add(i, i + 1, -i) st.range_add(0, i, 1) else puts "No" break end end