Under construction

Still being built. Things may change

Hosting Contests

Interview

Time limit2sMemory limit512 MB

Summary
Given counts of five problem groups, each usable at one of its allowed difficulty slots, find the maximum number of easy-medium-hard contests.
Level

Medium5 of 10

Topics
Greedy, Binary search
Solved
No attempts yet

Problem

Hyeonjong likes holding programming contests. He has written a great many problems, and now he wants to know how many contests he can hold with them.

One contest consists of three problems: one easy problem, one medium problem, and one hard problem. All three must be on hand before a contest can be held.

Hyeonjong sorted the problems he has written into the following five difficulty groups.

  • EE problems can be used only as an easy problem.
  • EMEM problems can be used as an easy problem or as a medium problem.
  • MM problems can be used only as a medium problem.
  • MHMH problems can be used as a medium problem or as a hard problem.
  • HH problems can be used only as a hard problem.

Each problem can be used in one contest only, and at one difficulty only.

Write a program that finds the maximum number of contests Hyeonjong can hold.

Input

The first line contains EE, EMEM, MM, MHMH, HH, separated by spaces. (0≤E,EM,M,MH,H≤100,0000 \le E, EM, M, MH, H \le 100{,}000)

Output

Print on the first line the maximum number of contests Hyeonjong can hold.

Examples3

  1. Example 1

    Input
    2 2 1 2 2
    
    Expected output
    3
    
  2. Example 2

    Input
    100 100 100 0 0
    
    Expected output
    0
    
  3. Example 3

    Input
    1 2 3 4 5
    
    Expected output
    3