Problem: The manager of the Japanese sweets shop Tomogurido in Aizuwakamatsu City is a very skillful craftsman, but he feels a little mood. The buns made by the manager are very delicious, but the size varies depending on the mood at that time.

The store manager's wife, who couldn't see it, came up with the idea of ​​packing buns of different sizes and weights in a bag for sale. If you pack the buns in a bag so that they have a certain weight, you can sell them at a fixed price even if they are different in size, and there is also a surprise that you do not know what kind of buns are in until you open it. It may be for sale. When it was put on the market under the name of "Dismembered Manju", a new idea became a hot topic and Tomokuri-do quickly became popular. However, there was a problem, and the number of "separate buns" that could be made changed depending on how the buns were put in the bag, which sometimes caused waste. When you came to Tomokuri-do as a part-time job, you decided to create a program to pack it in a bag without waste.

There are 9 types of buns weighing 1 to 9. When packing in a bag, pack so that the total weight of the buns is exactly 10. The combination of buns is 1 + 1 + 2 + 4 + 2 = 10 or 1 + 1 + 1 + 1 + 1 + 5 = 10, and you can use any number of buns of the same weight.

Enter the information on the number of buns to be made and the weight of the buns, and create a program that outputs the maximum number of "separate buns" that can be made.



input

Given multiple datasets. The end of the input is indicated by a single zero. Each dataset is given in the following format:


n
m1 m2 ... mn


The number of buns n (2 ≤ n ≤ 100) is given on the first line. The second line gives the weight mi (1 ≤ mi ≤ 9) for each bun.

The number of datasets does not exceed 100.

output

For each dataset, the maximum number of "disjoint buns" that could be packed is output on one line.

Example

Input

5
4 9 1 3 8
10
8 5 3 6 2 1 4 5 4 5
9
5 7 3 8 2 9 6 4 1
0


Output

1
4
4

Solution (in CPP):

Solution:
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<queue>

using namespace std;

void part(int x, vector<int> &d, vector<vector<int> > &a, int pre)
{
	if ( x == 0 ) {
		a.push_back(d);
	}
	
	for (int i = pre; i >= 1; --i) {
		if (x - i >= 0) {
			d.push_back(i);
			part(x - i, d, a, i);
			d.pop_back();
		}
	}
}

const int NPAT = 41;
int res;
int parts[NPAT][9];

inline int ideal(const vector<int> &m)
{
	return (m[0] + 2*m[1] + 3*m[2] + 4*m[3] + 5*m[4] + 6*m[5] + 7*m[6] + 8*m[7] + 9*m[8]) / 10;
}

bool solve(vector<int> &m, int pre, int step)
{
	if ( res < step ) {
		res = step;
	}
	
	if ( step + ideal(m) <= res ) {
		return false;
	}

	for (int i = pre; i < NPAT; ++i) {
		bool packable = true;

		for (int j = 0; j < 9; ++j) {
			if (m[j] < parts[ i ][ j ]) {
				packable = false;
			}
		}

		if ( packable ) {
			// Translate
			for (int j = 0; j < 9; ++j) {
				m[j] -= parts[ i ][ j ];
			}

			solve(m, i, step + 1);
			
			// Rollback
			for ( int j = 0; j < 9; ++j ) {
				m[j] += parts[ i ][ j ];
			}

		}
	}
	return false;
}


int main(void)
{
	vector<int> d;
	vector< vector<int> > s;
	part(10, d, s, 9);

	for (int sz = 2; sz < 22; ++sz){
		for (int i = 0; i < (int)s.size(); ++i){
			if ( s[i].size() == sz ){
				for (int j = 0; j < (int)s[i].size(); ++j){
					parts[i][s[i][j] - 1]++;
				}
			}
		}
	}

	while (true) {
		int n;
		vector<int> m(9,0);
		cin >> n;

		if (n == 0) {
			break;
		}

		for (int i = 0; i < n; ++i) {
			int tmp;
			cin >> tmp;
			m[tmp - 1]++;
		}

		res = 0;

		for (int i = 0; i < 4; ++i){
			int t = min(m[8 - i], m[i]);
			m[8 - i] -= t;
			m[i] -= t;
			res += t;
		}
		if (m[4] >= 2){
			res += m[4] / 2;
			m[4] %= 2;
		}

		solve(m, 0, res);
		cout << res << endl;
	}
	return 0;
}