The distance from the end of any car (boxcar or engine car) to the end of the next car is the sum of the 2 m distance between the cars and the 15 m length of a boxcar, or 17 m.
Thus the distance from the end of the engine car to the end of the 10th boxcar (the end of the train) is 10×17=170 m.
Since the engine car has a length of 26 m, then the total length of a train with 10 boxcars is 26+170=196 m.
The total length of a train with n boxcars is (26+15n+2n) m (one 26 m engine car, n 15 m boxcars, and a 2 m distance in front of each of the n boxcars).
That is, the total length of a train with n boxcars is (26+17n) m.
If a train has a length of 2015 m, then 26+17n=2015 or 17n=1989 and so n=117.
A train with a total length of 2015 m has 117 boxcars.
A train with 14 boxcars has length 26+17(14)=264 m.
The length of time during which a portion of the train is in Canada and a portion of the train is in the United States at the same time is equal to the total length of time it takes the train to cross the border. (When the train is crossing the border, portions of the train are in both countries at the same time.)
The train begins to cross the border when the front of the engine car reaches the border. The train finishes crossing the border when the end of the last boxcar reaches the border and so the front is 264 m farther.
That is, the length of time required for the train to cross the border is equal to the length of time it takes the train to travel a distance equal to the length of the train, or 264 m.
Since the train is travelling at a speed of 1.6 m/s, then the time required to travel 264 m is 1.6264=165 s.
Therefore, the length of time during which a portion of the train is in Canada and a portion of the train is in the United States at the same time is 165 s.