Under construction

Still being built. Things may change

Moving Company

Interview

Time limit2sMemory limit512 MB

Summary
Given counts of items weighing 1 to 5 kg, find the minimum number of 5 kg baskets needed to pack them all.
Level

Medium6 of 10

Topics
Greedy, Math, Implementation, Brute force
Solved
No attempts yet

Problem

Alex runs a moving company. In the house he must move today there are AA items weighing 1kg, BB items weighing 2kg, CC items weighing 3kg, DD items weighing 4kg, and EE items weighing 5kg.

To carry the items he must put them into baskets, and a basket can hold at most 5kg. Alex wants to minimize the number of baskets needed to hold all the items.

The total weight of the items in one basket cannot exceed 5kg.

Given the weights of the items, write a program that finds the minimum number of baskets needed to hold all the items.

Input

The first line gives A,B,C,D,EA, B, C, D, E. (0≤A,B,C,D,E≤1,000)(0 \le A, B, C, D, E \le 1{,}000)

Output

Print the minimum number of baskets needed to hold all the items on the first line.

Examples5

  1. Example 1

    Input
    5 0 0 0 0
    
    Expected output
    1
    
  2. Example 2

    Input
    0 0 0 0 5
    
    Expected output
    5
    
  3. Example 3

    Input
    1 1 1 1 1
    
    Expected output
    3
    
  4. Example 4

    Input
    10 8 2 7 3
    
    Expected output
    15
    
  5. Example 5

    Input
    8 2 7 3 0
    
    Expected output
    10