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 <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

vector<vector<int> > sum10;
vector<int> as;

void dfs(vector<int> v, int now, int sum) {
  if (sum == 10) {
    sum10.push_back(v);
    return;
  }
  if (now == as.size()) return;
  dfs(v,now+1,sum);
  if (sum + as[now] <= 10) {
    v.push_back(now);
    dfs(v,now,sum+as[now]);
  }
}

map<vector<int> , int> mp[50];

int solve(int now, vector<int> v) {
  if (now == sum10.size()) return 0;
  if (mp[now].count(v)) return mp[now][v];

  int a;
  int &r = a;
  if (now<sum10.size()-5) r = mp[now][v];
  int res = 0;
  REP(i,100) {
    bool dame = 0;
    res = max(res, solve(now+1, v) + i);
    FOR(it, sum10[now]) {
      if (v[*it]-- == 0) dame = 1;
    }
    if(dame) break;
  }
  if (now<sum10.size()-5) return r = res;
  return res;
}

int a[10];

int main() {
  // REP(i,9) as.push_back(i+1);
  // vector<int> t;
  // dfs(t,0,0);
  // FOR(it, sum10) {
  //   FOR(jt, *it) cout << *jt << " ";
  //   cout << endl;
  // }
  int n;
  while(cin>>n,n) {
    int ans = 0;
    memset(a,0,sizeof(a));
    REP(i,n) {
      int b;cin >> b;
      if (b >= 10) {
        if (b == 10) ans++;
      } else {
        a[b]++;
      }
    }
    for (int i=1; i<=4; ++i) {
      int j = 10-i;
      int m = min(a[i], a[j]);
      a[i] -= m;
      a[j] -= m;
      ans += m;
    }
    ans += a[5] / 2;
    a[5] -= a[5]/2*2;
    vector<int> v;
    as.clear();
    REP(i,10) if (a[i]) {
      as.push_back(i);
      v.push_back(a[i]);
    }
    sum10.clear();
    vector<int> t;
    dfs(t,0,0);
    REP(i,sum10.size()) mp[i].clear();
    ans += solve(0,v);
    cout << ans << endl;
  }
}