Under construction

Still being built. Things may change

Special Chicken Distribution

Interview

Time limit1sMemory limit1024 MB

Summary
Given N pieces of each of three chicken kinds and soldier preference counts A, B, C, find the maximum number of soldiers who get their preferred chicken.
Level

Easy2 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

For the Seollal holiday, the unit ordered chicken as a special meal for its soldiers. Fried chicken, soy sauce chicken, and seasoned chicken were each ordered in NN pieces, and the plan is to give one piece to each soldier.

To give as many soldiers as possible the kind of chicken they prefer, the soldier Eunu surveyed the soldiers' preferences. Among the three kinds, AA soldiers prefer fried chicken most, BB prefer soy sauce chicken most, and CC prefer seasoned chicken most. Every soldier chose only one kind when answering.

Find the maximum number of soldiers who can receive the kind of chicken they prefer most.

Input

The first line contains the number of pieces NN of each kind of chicken ordered. (1≤N≤1 000)(1\leq N\leq 1\,000)

The second line contains AA, the number of soldiers who prefer fried chicken most, BB, the number who prefer soy sauce chicken most, and CC, the number who prefer seasoned chicken most, separated by spaces. (1≤A,B,C≤3 000)(1\leq A,B,C\leq 3\,000)

Output

Print the maximum number of soldiers who can receive the kind of chicken they prefer most.

Examples4

  1. Example 1

    Input
    5
    1 7 6
    
    Expected output
    11
    
  2. Example 2

    Input
    10
    9 8 7
    
    Expected output
    24
    
  3. Example 3

    Input
    5
    5 5 5
    
    Expected output
    15
    
  4. Example 4

    Input
    10
    100 200 300
    
    Expected output
    30