This is an integer linear programming question.
Let $L$, $T$, and $R$ be positive integer values and define the sets $\mathscr{L} = \{1,2,\ldots,L\}$, $\mathscr{T} = \{1,2,\ldots,T\}$ and $\mathscr{R} = \{1,2,\ldots,R\}$. Additionaly, consider the functions $\mathcal{L}(r) , r \in \mathscr{R}$ and $\mathcal{T}(r) , r \in \mathscr{R}$ such that $\mathcal{L}(r) \in \mathscr{L}$ and $\mathcal{T}(r) \in \mathscr{T}$ for any $r \in \mathscr{R}$.
An output of the problem (actually, it will be used to write other constraints) is the decision variable $o_{lt}, l \in \mathscr{L}, t \in \mathscr{T}$ which counts all occurrences of values $l$ and $t$ as result of functions $\mathcal{L}$ and $\mathcal{T}$. In other words, let $\mathscr{U}_{lt} = \{ r \in \mathscr{R} | \mathcal{L}(r) = l \land \mathcal{T}(r) = t \} $, then $o_{lt} = |\mathscr{U}_{lt}|$.
How can I write constraints using integer linear programming to define $o_{lt}$ as described above?
If the functions $\mathcal{L}$ and $\mathcal{T}$ and the sets $\mathscr{L}$, $\mathscr{R}$ and $\mathscr{T}$ are known (parameters), then $\mathscr{U}_{\ell t}$ and $o_{\ell t}$ are also known (parameters), and there are no constraints needed. So I'm going to assume that the domain sets are known but the functions are somehow being solved for in the model.
The only way I can see to compute $o_{.}$ requires new binary variables $x_{.}$ and $y_{.}$, and new continuous variables $z_{.}$ with domains $[0,1]$. The following constraints should do the job:
$$\begin{align*} \mathcal{L}(r) & =\sum_{\ell\in\mathscr{L}}\ell\cdot x_{r\ell}\ \forall r\in\mathscr{R}\\ \mathcal{T}(r) & =\sum_{t\in\mathscr{T}}t\cdot y_{rt}\ \forall r\in\mathscr{R}\\ \sum_{\ell\in\mathscr{L}}x_{r\ell} & =1\ \forall r\in\mathscr{R}\\ \sum_{t\in\mathscr{T}}y_{rt} & =1\ \forall r\in\mathscr{R}\\ z_{r\ell t} & \le x_{r\ell}\ \forall r\in\mathscr{R},\ell\in\mathscr{L},t\in\mathscr{T}\\ z_{r\ell t} & \le y_{rt}\ \forall r\in\mathscr{R},\ell\in\mathscr{L},t\in\mathscr{T}\\ z_{r\ell t} & \ge x_{r\ell}+y_{rt}-1\ \forall r\in\mathscr{R},\ell\in\mathscr{L},t\in\mathscr{T}\\ o_{\ell t} & =\sum_{r\in\mathscr{R}}z_{r\ell t} \end{align*}$$ For each value of $r$, $x_{r.}$ and $y_{r.}$ each form type 1 specially ordered sets (SOS1), which may or may not be leveraged by the solver you employ.