import heapq import sys from sortedcontainers import SortedList class DualHeap: def __init__(self): self.min_heap = [] # 最小ヒープ self.max_heap = [] # 最大ヒープ self.data = SortedList() # データ全体の管理に利用 def add(self, value): heapq.heappush(self.min_heap, value) heapq.heappush(self.max_heap, -value) self.data.add(value) def remove(self, value): if value in self.data: self.min_heap.remove(value) heapq.heapify(self.min_heap) self.max_heap.remove(-value) heapq.heapify(self.max_heap) self.data.remove(value) else: print("Value not found in the heap.") sys.exit() def get_min(self): if self.min_heap: return self.min_heap[0] print('No') sys.exit() def get_max(self): if self.max_heap: return -self.max_heap[0] print('No') sys.exit() def __len__(self): return len(self.data) # 使用例 dual_heap = DualHeap() # 値の追加 dual_heap.add(10) dual_heap.add(1) dual_heap.add(5) dual_heap.add(20) dual_heap.add(7) # 最小値の取得 print("Min value:", dual_heap.get_min()) # 最大値の取得 print("Max value:", dual_heap.get_max()) # 値の削除 dual_heap.remove(10) n=int(input()) a=list(map(int,input().split())) b=DualHeap() c=DualHeap() for i in a: if i>0: b.add(i) else: c.add(i) B=len(b) C=len(c) x=sum(a) if x==0: print('Yes') exit() while B+C>1: if x>0: y=b.get_min() z=c.get_min() b.remove(y) c.remove(z) B-=1 C-=1 if y+z>0: b.add(y+z) B+=1 elif y+z<0: c.add(y+z);C+=1 else: y=b.get_max() z=c.get_max() b.remove(y) c.remove(z) B-=1 C-=1 if y+z>0: b.add(y+z) B+=1 elif y+z<0: c.add(y+z);C+=1 print('Yes')