import java.io.*;
import java.util.*;

public class history_gk {
    static Scanner in;
    static PrintWriter out;

    static int[] points = new int[]{0, 1, 3};
    static int[] conj = new int[]{3, 1, 100, 0};

    static Map<W, Long> cache = new HashMap<W, Long>();

    static List<int[]>[][] variants;

    static class W {
        public int[] a;

        public W(int[] a) {
            this.a = a;
        }
        
        @Override
        public int hashCode() {
            return Arrays.hashCode(a);
        }

        @Override
        public boolean equals(Object o) {
            return Arrays.equals(a, ((W) o).a);
        }
    }

    List<int[]> getVariants(int i, int j) {
        if (variants[i][j] == null) {
            if (j > 3 * i) {
                variants[i][j] = Collections.emptyList();
            } else {
                variants[i][j] = new ArrayList<int[]>();
                for (int p : points) {
                    if (0 <= j - p) {
                        for (int[] l : getVariants(i - 1, j - p)) {
                            int[] nl = new int[l.length + 1];
                            for (int x = 0; x < i - 1; x++) {
                                nl[x] = l[x];
                            }
                            nl[i - 1] = p;
                            variants[i][j].add(nl);
                        }
                    }
                }
            }
        }
        return variants[i][j];
    }

    int solveHits = 0;
    int solveGets = 0;
    int solveCalc = 0;
    int solveZero = 0;

    long solve(int[] t) {
        solveGets++;
        W w = new W(t);
        Arrays.sort(t);

        Long ans = cache.get(w);
        if (ans != null) {
            solveHits++;
            return ans;
        }

        int n = t.length;
        int s = 0;
        for (int i : t) {
            s += i;
        }
        int plays = n * (n - 1) / 2;
        long result = 0;
        if (s < 2 * plays || 3 * plays < s) {
            cache.put(w, 0L);
            return 0;
        }
        for (int[] v : getVariants(n - 1, t[n - 1])) {
            int[] l = new int[n - 1];
            int i = 0;
            for (i = 0; i < n - 1; i++) {
                int z = t[i] - conj[v[i]];
                if (z < 0) break;
                l[i] = z;
            }
            if (i == n - 1) {
                result += solve(l);
            }
        }
        if (result == 0) {
            solveZero++;
        }
        solveCalc++;
        cache.put(w, result);
        return result;
    }

    public void run() {
        int n = in.nextInt();

        int[] t = new int[n];
        for (int i = 0; i < n; i++) {
            t[i] = in.nextInt();
        }

        variants = new List[n + 1][3 * n + 1];
        variants[0][0] = Collections.singletonList(new int[0]);

        cache.put(new W(new int[0]), 1L);

        out.println(solve(t));
        //System.out.format("total=%d hits=%d miss=%d zero=%d\n", solveGets, solveHits, solveCalc, solveZero);
    }

    public static void main(String[] args) throws IOException {
        in = new Scanner(System.in);
        out = new PrintWriter(System.out);

        new history_gk().run();


        in.close();
        out.close();
    }
}
