local mfl = math.floor local n = io.read("*n") local t = {0, 0, 0} for i = 1, n do a = math.min(3, io.read("*n")) t[a] = t[a] + 1 end local ret = 0 ret = ret + t[1] * (t[1] - 1) ret = ret + mfl(t[2] * (t[2] - 1) / 2) ret = ret + mfl(t[3] * (t[3] - 1) / 2) ret = ret + t[1] * t[3] * 2 ret = ret + t[2] * t[3] ret = ret + t[1] * t[2] * 3 print(ret)