// Arup Guha
// 5/2/2012
// Solution to 2011 South East Regional Problem B: Hexagram

import java.util.*;

public class hexagram {

	// Stores who is on a line.
	final static int[][] lines = {{0,2,5,7}, {1,2,3,4}, {0,3,6,10}, {1,5,8,11}, {4,6,9,11}, {7,8,9,10}};

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);

		int[] values = new int[12];
		read(stdin, values);

		// Go through all the cases.
		while (!zero(values)) {

			// Set up backtracking.
			boolean[] used = new boolean[12];
			for (int i=0; i<12; i++)
				used[i] = false;

			int[] soln = new int[12];
			for (int i=0; i<12; i++)
				soln[i] = -1;

			// Solve and move to next case.
			System.out.println(numSols(soln, 0, used, values, getTarget(values))/12);
			read(stdin, values);
		}

	}

	public static int numSols(int[] soln, int nextVal, boolean[] used, int[] values, int target) {

		// Here is where I backtrack...skip if the current board is impossible,
		if (!hasPotential(soln, target))
			return 0;

		// Check if this one's complete.
		if (nextVal == 12)
			return 1;

		// Loop through all potential values.
		int ans = 0;
		for (int i=0; i<12; i++) {

			// Regular permuation code, the way I used to write it 10 years ago!
			if (!used[i]) {
				soln[nextVal] = values[i];
				used[i] = true;
				ans += numSols(soln, nextVal+1,used,values,target);
				used[i] = false;
				soln[nextVal] = -1;
			}
		}

		// Ta da!
		return ans;
	}

	public static boolean hasPotential(int[] soln, int target) {

		// test line i.
		for (int i=0; i<lines.length; i++) {
			boolean flag = true;
			int sum = 0;
			
			// Add up this line.
			for (int j=0; j<lines[i].length; j++) {
				int term = soln[lines[i][j]];
				if (term < 0)
					flag = false;
				sum += term;
			}

			// This can't work.
			if (flag && sum != target)
				return false;
		}
		
		// If we make it here, we didn't find proof the board is impossible.
		return true;
	}

	// Reads input case.
	public static void read(Scanner stdin, int[] values) {
		for (int i=0; i<values.length; i++)
			values[i] = stdin.nextInt();
	}

	// Returns true iff everything is 0 in the array.
	public static boolean zero(int[] array) {

		for (int i=0; i<array.length; i++)
			if (array[i] != 0)
				return false;
		return true;
	}

	// Determine target for a line from the original board.
	public static int getTarget(int[] values) {
		int sum = 0;
		for (int i=0; i<12; i++)
			sum += values[i];
		return sum/3;
	}
}