from heapq import * from collections import * import sys input = sys.stdin.readline class QuasiBinaryTree: def __init__(self, rule="min"): if rule == "max": self.pm = -1 else: self.pm = 1 self.inf = 10**18 self.P = [self.inf] self.Q = [] def insert(self, x): heappush(self.P, x * self.pm) def erase(self, x): heappush(self.Q, x * self.pm) def top(self): while self.Q and (self.P[0] == self.Q[0]): heappop(self.P) heappop(self.Q) return self.P[0] * self.pm N = int(input()) A = list(map(int, input().split())) T1, T2 = QuasiBinaryTree("min"), QuasiBinaryTree("max") Q = deque() ans = 0 for i in range(N): T1.insert(A[i]) T2.insert(A[i]) Q.append(A[i]) while len(Q) >= 2: ma = T2.top() mi = T1.top() T1.erase(mi) mi2 = T1.top() T1.insert(mi) if mi + mi2 >= ma: break else: q = Q.popleft() T1.erase(q) T2.erase(q) ans += len(Q) - 1 print(ans)