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

public class history_md implements Runnable {
	final int[] we = {0, 1, 3};
	final int[] they = {3, 1, 0};
	
	class State implements Comparable<State> {
		int points;
		int[] played;
		int[] toplay;
		
		public State(int pts, int playedN, int toPlayN) {
			points = pts;
			played = new int[playedN];
			toplay = new int[toPlayN];
		}

		public int compareTo(State o) {
			int n = played.length + toplay.length;
			int on = o.played.length + o.toplay.length;
			if (n == on) {
				if (toplay.length == o.toplay.length) {
					if (points == o.points) {
						for (int i = 0; i < played.length; i++) {
							if (played[i] != o.played[i])
								return played[i] - o.played[i];
						}
						for (int i = 0; i < toplay.length; i++) {
							if (toplay[i] != o.toplay[i])
								return toplay[i] - o.toplay[i];
						}
						return 0;
					}
					return points - o.points;
				}
				return o.toplay.length - toplay.length;
			}
			return on - n;
		}

		public void process(long v) {
			if (toplay.length == 0) {
				if (points != 0)
					throw new Error();
				if (played.length == 0) {
					answer += v;
					return;
				}
				State s = new State(played[0], 0, played.length - 1);
				for (int i = 1; i < played.length; i++)
					s.toplay[i - 1] = played[i];
				if (s.points < 0 || s.points > they[0] * s.toplay.length)
					return;
				add(s, v);
				return;
			}
			for (int g = 0; g < 3; g++) {
				State s = new State(points - we[g], played.length + 1, toplay.length - 1);
				if (s.points < 0 || s.points > they[0] * s.toplay.length)
					continue;
				for (int i = 0; i < played.length; i++) {
					s.played[i] = played[i];
				}
				s.played[played.length] = toplay[0] - they[g];
				Arrays.sort(s.played);
				for (int i = 1; i < toplay.length; i++) {
					s.toplay[i - 1] = toplay[i];
				}
				add(s, v);
			}
		}
		
		@Override
		public String toString() {
			return points + "\n" + Arrays.toString(played) + "\n" + Arrays.toString(toplay);
		}
	}
	
	private Scanner in;
	private PrintWriter out;

	public void run() {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
	
	TreeMap<State, Long> tm = new TreeMap<State, Long>();
	long answer = 0;
	
	private void add(State s, long v) {
		if (tm.containsKey(s))
			tm.put(s, tm.get(s) + v);
		else
			tm.put(s, v);
	}

	private void solve() throws IOException {
		Locale.setDefault(Locale.US);
		in = new Scanner(new FileReader("history.in"));
		out = new PrintWriter("history.out");
		int n = in.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = in.nextInt();
		Arrays.sort(a);
		State init = new State(0, n, 0);
		init.played = a;
		add(init, 1);
		while (!tm.isEmpty()) {
			State s = tm.firstKey();
			long v = tm.get(s);
			tm.remove(s);
			s.process(v);
		}
		out.println(answer);
		in.close();
		out.close();
	}

	public static void main(String[] args) {
		new Thread(new history_md()).start();
	}
}
