One distance decides the answer: you may not park within 50 m of a railroad crossing. Parking is when a vehicle stays stopped for more than 5 minutes, and not to let people get in or out or to load. The rule does not split the crossing into “before” and “after”: the 50 m count in both directions. Car A is parked 40 m before the gate, less than 50 m. Car B is on the shoulder right after the rails, also much closer than 50 m. Both are on the right shoulder, but that does not help: parking within 50 m of a crossing is prohibited. So both drivers broke the rule