In this situation, car A should let car B go first.
That way, the car behind them can get out of the level crossing.