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 "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld =long double;
const ld eps = 1e-9;

bool check(const vector<vector<pair<int, int>>>&humans, int x, int y) {
	for (int i = 0; i < 4; ++i) {
		auto it=find(humans[i].begin(),humans[i].end(),make_pair(x,y));
		if(it!=humans[i].end())return false;
	}
	return true;
}
int dx[] = { -1,0,1,0,0 };
int dy[] = { 0,1,0,-1,0 };

template<typename T> struct Compress {
	map<T, int>mp;
	map<int, T>revmp;

	Compress(vector<T>vs) {
		setmp(vs);
	}

	Compress() :mp(), revmp() {

	}
	void setmp(vector<T>vs) {
		sort(vs.begin(), vs.end());
		vs.erase(unique(vs.begin(), vs.end()), vs.end());
		for (int i = 0; i < static_cast<int>(vs.size()); ++i) {
			mp[vs[i]] = i;
			revmp[i] = vs[i];
		}
	}

};
struct sale {
	int id;
	int d;
	int s;
	int e;
};

struct aa {
	int flag;
	int x;
	int y;
	int cost;
};

bool operator <(const vector<int>&l, const vector<int>&r) {
	for (int i = 0; i < l.size(); ++i) {
		if(l[i]<r[i])return true;
		else if(l[i]>r[i])return false;
	}
	return false;
}
int solve(vector<int>haves, vector<int>nums) {
	map<pair<vector<int>,int>,int>mp;
	mp[make_pair(nums,0)]=1;

	int ans=1;
	queue<pair<vector<int>,int>>que;
	que.push(make_pair(nums,0));
	while (!que.empty()) {
		auto atop(que.front());
		que.pop();

		int x=atop.second;
		vector<int>v(atop.first);

		int cost=mp[make_pair(atop.first,atop.second)];
		ans=max(ans,cost);
		for (int i = 0; i < haves.size(); ++i) {
			if (v[i]){
				if (x+haves[i] >= 11) {

				}
				else if (x + haves[i] == 10) {
					v[i]--;
					auto np=make_pair(v,0);
					if (mp[np] < cost + 1) {
						mp[np]=cost+1;
						que.push(np);
					}
					v[i]++;
				}
				else {
					v[i]--;
					auto np=make_pair(v,x+haves[i]);
					if (mp[np] < cost) {
						mp[np]=cost;
						que.push(np);
					}
					v[i]++;
				}
			}
		}
	}
	return ans-1;
}

int main()
{
	while (true) {
		int N;cin>>N;
		if(N==0)break;
		vector<int>vs(10);
		for (int i = 0; i < N; ++i) {
			int a;cin>>a;
			vs[a]++;

		}
		int ans=0;
		for (int i = 6; i <= 9; ++i) {
			int x=min(vs[i],vs[10-i]);
			vs[i]-=x;
			vs[10-i]-=x;
			ans+=x;
		}
		{
			int x=vs[5]/2;
			vs[5]-=2*x;
			ans+=x;
		}
		vector<int>haves;
		vector<int>nums;
		for (int i = 1; i <= 9; ++i) {
			if (vs[i]) {
				haves.push_back(i);
				nums.push_back(vs[i]);
			}
		}
		ans+=solve(haves,nums);
		cout<<ans<<endl;
	}
	return 0;
}