Scanf.scanf "%d %d" (fun n aa ->
    let x = Array.init n (fun _ -> Scanf.scanf " %d" (fun x -> x - aa)) in
    let rec loop i a b c =
        if i = n then a, b, c else
        if x.(i) < 0 then loop (i + 1) (-x.(i) :: a) b c else
        if x.(i) > 0 then loop (i + 1) a b (x.(i) :: c) else
                          loop (i + 1) a (b * 2) c
    in
    let a, b, c = loop 0 [] 1 [] in
    let build l =
        let arr = Array.make 2501 0 in
        arr.(0) <- 1;
        let rec loop = function
            | [] -> arr
            | hd :: tl ->
                for j = 2500 - hd downto 0 do
                    arr.(hd + j) <- arr.(hd + j) + arr.(j)
                done;
                loop tl
        in
        loop l
    in
    let mi = build a in
    let pl = build c in
    let rec loop i acc =
        if i = 2501 then acc else
            loop (i + 1) (acc + mi.(i) * pl.(i) * b)
    in
    loop 0 (-1) |> Printf.printf "%d\n"
)