# LeetCode 3623. Count Number of Trapezoids in F#

## URL

[Count Number of Trapezoids I - LeetCode](https://leetcode.com/problems/count-number-of-trapezoids-i/description/?envType=daily-question&envId=2025-12-02)

## Code

[dotnet-study/fsharp/leetcode/challenge/202512/count\_number\_of\_trapezoids1/main.fsx at master · syohex/dotnet-study](https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/challenge/202512/count_number_of_trapezoids1/main.fsx)

```fsharp
let countTrapezoids (points: (int * int) list) : int =
    let modulo = 1_000_000_007L

    let rec countTrapezoids' ys totalEdges acc =
        match ys with
        | [] -> acc % modulo |> int
        | h :: t ->
            let edges = (h * (h - 1)) / 2
            let acc = acc + int64 edges * totalEdges
            let totalEdges = totalEdges + int64 edges
            countTrapezoids' t totalEdges acc

    let ys =
        points
        |> List.fold
            (fun acc (_, y) ->
                match Map.tryFind y acc with
                | Some v -> Map.add y (v + 1) acc
                | None -> Map.add y 1 acc)
            Map.empty
        |> Map.values
        |> Seq.toList

    countTrapezoids' ys 0L 0L
```
