let count_overlaps intervals =
  let arr = Array.of_list intervals in
  let n = Array.length arr in
  let count = ref 0 in
  for i = 0 to n - 1 do
    let (s1, e1) = arr.(i) in
    for j = i + 1 to n - 1 do
      let (s2, e2) = arr.(j) in
      if s1 <= e2 && s2 <= e1 then count := !count + 1
    done
  done;
  !count

;;

count_overlaps [(1, 4); (2, 5); (7, 9); (3, 6); (8, 10); (11, 12); (0, 2)]
