Here's a way to solve this:
If A is the home team, wave off the facemask flag and make everybody happy, except B
If B is the home team, pretend that since there are more fouls on A than there were on B, you subtract the total yards penalized on A from the total yards penalized on B, (5 or 15 depending on the degree of the facemask) then you start at the 20 and go backwards.
If we can figure this out, then I can pass algebra!