| 2026-2027 ICPC NERC (NEERC), North-Western Russia Regional Contest (Northern Subregionals) |
|---|
| Закончено |
Nora wants to join two wooden planks with a bolt. The first plank is $$$a$$$ centimeters long and has a hole $$$x$$$ centimeters from its left end. The second plank is $$$b$$$ centimeters long and has a hole $$$y$$$ centimeters from its left end. Each hole lies strictly between the two ends of its plank.
Nora places the planks horizontally, one on top of the other, and slides them until the holes line up. She does not rotate or flip either plank. She then passes a bolt through both holes to join the planks together.
Help Nora determine the width of the resulting construction, that is, the horizontal distance from its leftmost end to its rightmost end.
The only line contains four integers $$$a$$$, $$$b$$$, $$$x$$$, and $$$y$$$, denoting the lengths of the first and second planks and the distances from their left ends to their respective holes ($$$2 \le a, b \le 1000$$$; $$$0 \lt x \lt a$$$; $$$0 \lt y \lt b$$$).
Print an integer denoting the width of the construction in centimeters.
8 6 3 4
9
6 8 4 3
9
17 17 6 6
17
The figure shows the arrangement of the planks in the first example. The planks are shown separately for clarity, and the dashed line passes through both holes. The width of the construction is $$$9$$$ centimeters.
In the second example, the same two planks are swapped, so the width is again $$$9$$$ centimeters.
In the third example, the planks have equal lengths and their holes are equally far from the left ends, so the planks line up exactly and the width is $$$17$$$ centimeters.
| Название |
|---|


