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:
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
 
static const int tx[] = {+0,+1,+0,-1};
static const int ty[] = {-1,+0,+1,+0};
 
static const double EPS = 1e-8;


map<vector<int>,int> dp;

int dfs(vector<int>& buns,int sum,int comb_i,vector<vector<int> >& all_combinations){
  if(comb_i >= all_combinations.size()) return sum;
  if(dp.find(buns) != dp.end()) return dp[buns];

  vector<int> prev = buns;
  bool isok = true;
  for(int weight = 1; weight <= 9; weight++){
    int use_count = all_combinations[comb_i][weight];
    buns[weight] -= use_count;
    if(buns[weight] < 0){
      isok = false;
      break;
    }
  }

  int res = 0;
  if(isok){
    res = max(sum + 1,dfs(buns,sum + 1,comb_i,all_combinations));
  }
  buns = prev;
  res = max(res,dfs(buns,sum,comb_i + 1,all_combinations));

  return (dp[buns] = max(res,dp[buns]));
}

void make_combinations(int weight,int sum,vector<int>& current,vector<vector<int> >& all_combinations){
  if(sum >= 10){
    if(sum == 10) all_combinations.push_back(current);
    return;
  }
  if(weight >= 10) return;

  for(int use_count = 0; use_count <= 10; use_count++){
    current[weight] = use_count;
    make_combinations(weight + 1,sum + weight * use_count,current,all_combinations);
    current[weight] = 0;
  }
}

int main(){
  int total_buns;
  
  vector<vector<int> > all_combinations;
  vector<int> current(11);
  make_combinations(1,0,current,all_combinations);
  sort(all_combinations.begin(),all_combinations.end());

  while(~scanf("%d",&total_buns)){
    if(total_buns == 0) break;
    vector<int> buns(11);
    dp.clear();

    for(int i = 0; i < total_buns; i++){
      int weight;
      scanf("%d",&weight);
      buns[weight]++;
    }

    int greedy_sum = 0;
    for(int weight = 1; weight <= 5; weight++){
      if(weight == 5){
        int use_count = (buns[weight] / 2) * 2;
        greedy_sum += use_count / 2;
        buns[weight] -= use_count;
      }
      else{
        int use_count = min(buns[weight],buns[10 - weight]);
        greedy_sum += use_count;
        buns[weight] -= use_count;
        buns[10 - weight] -= use_count;
      }
    }

    printf("%d\n",greedy_sum + dfs(buns,0,0,all_combinations));
  }
}