import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] sa = br.readLine().split(" "); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); } br.close(); long[] c = new long[3]; for (int i = 0; i < n; i++) { if (a[i] <= 2) { c[a[i]]++; } } c[0] = n - c[1] - c[2]; long ans = 0; ans += c[0] * (c[0] - 1) / 2; ans += c[0] * c[1] * 2; ans += c[0] * c[2]; ans += c[1] * (c[1] - 1) / 2 * 2; ans += c[1] * c[2] * 3; ans += c[2] * (c[2] - 1) / 2; System.out.println(ans); } }