#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned char uchar;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

vector<ull> data;

void make(ull mask, int rem, int p)
{
    if(rem == 0){
        data.push_back(mask);
        return;
    }
    
    if(p >= 2){
        make(mask, rem, p-1);
    }
    if(p <= rem){
        reinterpret_cast<uchar*>(&mask)[p-1]++;
        make(mask, rem-p, p);
    }
}

bool ok(ull a, ull b)
{
    uchar* p = reinterpret_cast<uchar*>(&a);
    uchar* q = reinterpret_cast<uchar*>(&b);
    
    rep(i, 8){
        if(p[i] < q[i]) return false;
    }
    
    return true;
}

unordered_map<ull, int> memo;
int func(ull mask)
{
    if(memo.count(mask)) return memo[mask];
    
    int ans = 0;
    for(ull d : data){
        if(ok(mask, d)){
            ans = max(ans, func(mask - d) + 1);
        }
    }
    
    return memo[mask] = ans;
}

void func(int n)
{
    int hist[10] = {};
    rep(i, n){
        int a;
        cin >> a;
        hist[a]++;
    }
    
    int ans = hist[5] / 2;
    hist[5] %= 2;
    reps(i, 1, 5){
        int v = min(hist[i], hist[10-i]);
        ans += v;
        hist[i] -= v;
        hist[10-i] -= v;
    }
    
    ull mask = 0;
    rep(i, 8){
        reinterpret_cast<uchar*>(&mask)[i] = hist[i+1];
    }
    ans += func(mask);
    
    cout << ans << endl;
}


int main()
{
    make(0, 10, 8);
    
    int n;
    while(cin >> n, n){
        func(n);
    }
}