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[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray(); static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var a = NList; var set = new HashSet(); var list = new List(); for (var i = 0; i < 9; ++i) { for (var j = 0; j < a[i]; ++j) list.Add((char)(i + '1')); } var ans = 0L; Permutate(list.ToArray(), arr => { var s = string.Concat(arr); if (set.Add(s)) ans += int.Parse(s); }); WriteLine(ans % 1_000_000_007); } static void Permutate(T[] array, Action action) { Permutate(array, 0, array.Length, action); } static void Permutate(T[] array, int pos, int count, Action action) { if (count == 0) { action(array); return; } for (var i = 0; i < count; i++) { Swap(array, pos, pos + i); Permutate(array, pos + 1, count - 1, action); Swap(array, pos, pos + i); } } static void Swap(T[] array, int x, int y) { var temp = array[x]; array[x] = array[y]; array[y] = temp; } }