#P11857. Minimum Frame Perimeter

    ID: 13957 Type: Default 1000ms 256MiB

Minimum Frame Perimeter

Minimum Frame Perimeter

Given two rectangular paintings, where the first painting has dimensions $A\times B$ and the second has dimensions $X\times Y$, your task is to determine the minimum possible perimeter of a rectangular frame that can contain both paintings under the following constraints:

  • Both paintings must be completely inside the frame.
  • The paintings must not overlap (touching at the edges is allowed).
  • The paintings cannot be rotated.
  • The edges of the paintings must be either parallel or perpendicular to the ground.

You can arrange the paintings either side by side (horizontally) or one above the other (vertically). For the horizontal arrangement, the frame's width is $A+X$ and height is $\max(B,Y)$, giving a perimeter of $2\times (A+X+\max(B,Y))$. For the vertical arrangement, the frame's width is $\max(A,X)$ and its height is $B+Y$, with a perimeter of $2\times (\max(A,X)+B+Y)$. Output the minimum perimeter obtained from these two arrangements.

inputFormat

The input consists of a single line containing four positive integers: A B X Y, where:

  • $A$ and $B$ are the length and width of the first painting, respectively.
  • $X$ and $Y$ are the length and width of the second painting, respectively.

outputFormat

Output a single integer, the minimum possible perimeter of the frame that can enclose both paintings under the given constraints.

sample

1 2 3 4
16