The formula on the right line is a+1-b.
So your topic is A = 7 and B = 4.
So the 7th+1-4 = 4 from the right, you use the letter abcdefg to represent these 7 cars, the 4th car from left to right is D, and then from right to left, D is also ranked 4th.
Fourth from the left, there are 7-4=3 cars on your right. From the right: 3+ 1=4 cars.
So the fourth one from the right.