using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var a = NList; var count = new long[4]; var ans = 0L; foreach (var ai in a) { if (ai == 1) ans += count[1] * 2 + count[2] * 3 + count[3] * 2; else if (ai == 2) ans += count[1] * 3 + count[2] + count[3]; else ans += count[1] * 2 + count[2] + count[3]; if (ai < 3) ++count[ai]; else ++count[3]; } WriteLine(ans); } }