Positioning Peter’s Paintings

시간 제한2초메모리 제한2048 MB

요약
직립한 두 직사각형 그림의 밑변과 높이가 주어질 때, 두 그림을 겹치지 않게 담는 직사각형 벽의 최소 둘레를 구한다.
난이도

보통10점 중 6점

유형
기하, 수학, 구현
정답자
아직 제출이 없습니다

문제

Peter the painter just finished painting two rectangular paintings and would like to display both on a rectangular wall which has the smallest perimeter possible. The first painting has a base of length AA units and a height of length BB units. The second painting has a base of length XX units and a height of length YY units.

Peter has a few conditions on how to arrange his paintings on the rectangular wall. The first condition is that the paintings must be upright, meaning that the bases of the paintings are parallel to the floor. The second condition is that he would like to display both paintings in full, meaning that they cannot overlap each other. Please help determine the rectangular wall of minimum perimeter such that the paintings can be displayed without violating his conditions.

입력

The one line of input will consist of four space-separated positive integers, AA, BB, XX, YY (1≤A,B,X,Y≤1081 ≤ A, B, X, Y ≤ 10^8).

출력

Output a single integer representing the minimum perimeter of a rectangular wall without violating Peter’s conditions.

예제3

  1. 예제 1

    입력
    3 3 3 3
    
    예상 출력
    18
    
  2. 예제 2

    입력
    2 2 4 4
    
    예상 출력
    20
    
  3. 예제 3

    입력
    1 2 3 1
    
    예상 출력
    12