let rec rle_decode pairs =
  match pairs with
  | [] -> []
  | (x, n) :: rest ->
    let rec rep k = if k = 0 then [] else x :: rep (k - 1) in
    rep n @ rle_decode rest

;;

List.fold_left (+) 0 (rle_decode [(1, 3); (2, 2); (3, 4); (1, 2)])
