Class Packing

No attempts yetTime limit1sMemory limit128 MB

Problem

On the first day of every school year, the principal of a primary school must sort the newly enrolled pupils into classes and assign one teacher to each class. She wants to use as few teachers as possible.

She knows how many pupils are enrolled in each of the seven grades, from Kindergarten up to year 6. Pupils must be placed into classes according to the following rules:

  • A class containing pupils from Kindergarten, year 1, or year 2 may hold at most 20 pupils.
  • A class containing pupils from year 3 or year 4 may hold at most 25 pupils.
  • A class containing pupils from year 5 or year 6 may hold at most 30 pupils.
  • A class may only contain pupils from a single grade, or from two consecutive grades. For example, a class with Kindergarten and year 1 pupils may hold at most 20 pupils, while a class with year 4 and year 5 pupils may hold at most 25 pupils. In other words, when a class mixes two consecutive grades, it must respect the smallest size limit that applies to any grade in it.
  • Exactly one teacher is assigned to each class, and every class has a teacher.

Given the enrolment numbers, compute the minimum number of teachers required.

Input

The input contains several test cases. Each test case is a single line of seven non-negative integers: the number of pupils enrolled in Kindergarten, year 1, year 2, year 3, year 4, year 5, and year 6, in that order. Every integer is less than 200, and consecutive integers are separated by a single space.

A line containing seven zeros marks the end of the input and must not be processed.

Output

For each test case, print a single line containing one integer: the minimum number of teachers required.