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 <algorithm>
#include <map>
using namespace std;
typedef pair<int,int> pr;
typedef pair<pr , pr > ppr;
typedef pair<int,vector<int> > pv;
int num[5]={},numTimes[5]={},numbers,alls;
vector<pv > p; 
void search(int times,int gets[5]){
	if(times==numbers){
	
		int sum=0;
		for(int i=0;i<numbers;i++)
			sum+=num[i]*gets[i];
		if(sum==10){
			pv a;
			a.first=-1;
			for(int i=0;i<numbers;i++){
				a.second.push_back(gets[i]);
				if(a.first==-1 && gets[i]!=0)
				a.first=100-num[i];
			}
				
		p.push_back(a);
		}
	}
	else{
		for(int i=0;i<=numTimes[times] && i<=10 ;i++){
		gets[times]=i;
		search(times+1,gets);
		}
	}
}
int findAns(int x,int times[]){
	if (x==p.size())
		return 0;
	int maxim=0,ans=1;
	int ar[5];
	for(int i=0;i<5;i++)
	ar[i]=p[x].second[i];
	for(int i=0;i<numbers;i++){
		if(ar[i]>times[i])
			ans=0;
		times[i]-=ar[i];
	}
	if(ans)
	maxim=max(maxim,1+findAns(x,times));
	for(int i=0;i<numbers;i++)
		times[i]+=ar[i];
	maxim=max(maxim,findAns(x+1,times));
	return maxim;
}
int solved(vector<pr> v){
		int ans=0;
		for(int i=0;i<v.size();i++){
			num[i]=v[i].first;
			numTimes[i]=v[i].second;
		}
		sort(v.begin(),v.end());
		numbers=v.size();
		int gets[5]={};
		alls=0;
		for(int i=0;i<numbers;i++)
		alls+=num[i]*numTimes[i];
		sort(p.begin(),p.end());
		search(0,gets);
		return findAns(0,numTimes);
}
int main() {
	// your code goes here
	int n,tmp;
	while(cin >> n && n!=0){
		p.clear();
		for(int i=0;i<5;i++){
			num[i]=0;
			numTimes[i]=0;
		}
		
		numbers=0;
		vector<pr > v;
		int nums[10]={},sum=0;
		for(int i=0;i<n;i++){
			cin >> tmp;
			nums[tmp]++;
		}
		for(int i=1;i<=4;i++)
			if(nums[i] && nums[10-i]){
				int manju=min(nums[i],nums[10-i]);
				sum+=manju;
				nums[i]-=manju;
				nums[10-i]-=manju;
			}
		sum+=nums[5]/2;
		nums[5]%=2;
		while(nums[3]>=2 && nums[4] >= 1){
			nums[3]-=2;
			nums[4]-=1;
			sum++;
		}
		for(int i=1;i<=8;i++)
			if(nums[i])
				v.push_back(pr(i,nums[i]));
		cout << sum+solved(v) << endl;
	}
	return 0;
}