Good deal!
I guessed correctly.
In the attached find (now un hidden) a helper column A. This formula repeats the merged row headers.
I figured out the M F headers and their role in the output columns. In D37:H41
With that range selected copy and paste into cells D43, D49, D55, J37, J43, J49 and J55.
For the subtotals by M and F in I37:I41
Then copy that range and paste into the remaining relative cells columns I and O. The formula subtotals for each A, B, C ... E
and gender subtotals are self explanatory. Again copy the first range and paste into relevant cells.
I assume you know how to hide column A if desired.
Bookmarks