Formula for splitting profit and loss for every person
Either I totally misunderstand the question, or this is just adding up numbers, there are no economic or mathematical principles involved. (In which case this is not the right SE for it.)

Denoting the "balances" by $b_1,b_2,...$ and the "supplies" by $s_1,s_2,...$ total profits are
$$
\Pi_{total} = \sum_i (b_i-s_i)
$$
You want everyone to end up with a proportional share of this, so that in the end they have
$$
\frac{s_i}{\sum_i s_i} \Pi_{total}.
$$
To compensate for their investment, each person should get
$$
x_i = s_i + \frac{s_i}{\sum_i s_i} \Pi_{total}.
$$
One can verify that
$$
\begin{align*}
\sum_i x_i &amp; = \sum_i s_i + \sum_i\frac{s_i}{\sum_i s_i} \Pi_{total} \\
&amp; = \sum_i s_i + \Pi_{total} = \sum_i b_i
\end{align*}
$$
so we made no mistakes, you can indeed give people their values $x_i$.