Under construction

Still being built. Things may change

Colored Paper

Time limit1sMemory limit128 MB

Summary
Given counts of six square sizes (1-6 cm), determine the minimum number of 6x6 boards needed to place all squares without overlap or crossing edges.
Level

Medium6 of 10

Topics
Greedy, Math, Simulation
Solved
No attempts yet

Problem

There are six kinds of square colored paper whose side lengths are 1cm, 2cm, 3cm, 4cm, 5cm, and 6cm. A sheet of type k has side length kcm.

Figure 1

All sheets must be attached to boards that are 6cm wide and 6cm tall. A sheet must not cross the boundary of a board, and two sheets must not overlap. Each sheet must fit completely inside a single board.

Figure 2

Given the number of sheets of each size, find the minimum number of 6cm × 6cm boards needed to attach all of them.

Input

Six lines are given. From the first line to the sixth line, they contain the numbers of type 1 through type 6 colored papers in order. Each count is at most 100.

Output

Print the minimum number of boards needed to attach all the colored papers.

Examples1

  1. Example 1

    Input
    5
    3
    0
    1
    1
    0
    
    Expected output
    2