Scanf.scanf "%s" (fun s ->
    let n = String.length s in
    let arr = Array.make 2019 0 in
    arr.(0) <- 1;
    let rec loop i cur ten =
        if i >= 0 then (
            let cur = (cur + ten * ( int_of_char s.[i] - 48)) mod 2019 in
            arr.(cur) <- arr.(cur) + 1;
            loop (i - 1) cur ((ten * 10) mod 2019)
        )
    in
    loop (n - 1) 0 1;
    Array.fold_left (fun acc v -> acc + v * (v - 1) / 2) 0 arr |> Printf.printf "%d\n"
)