let ans, k, n = ref 0, ref 0, Scanf.scanf " %d" (+) 0
let ss, ls = Array.(make (n * (n - 1) / 2) 0, init n @@ fun _ -> Scanf.scanf " %d" (+) 0)
let g i k a = a.(i) > k
let f k a = let l, r = ref @@ -1, ref @@ Array.length a in while !r - !l > 1 do let m = !l + (!r - !l) / 2 in if g m k a then r := m else l := m done; !r
let _ = for i = 0 to n - 1 do for j = i + 1 to n - 1 do ss.(!k) <- ls.(i) + ls.(j); incr k done done;
  Array.(sort (-) ss; sort (fun x y -> y - x) ls; iteri (fun i l -> ans := !ans + (n - i - 1) * (n - i - 2) / 2 - f l ss) ls); Printf.printf "%d\n" !ans