module Memoizable
	def memoize(name)
		original = "__original_#{name}__"
		([Class, Module].include?(self.class) ? self : self.class).class_eval {
			alias_method(original, name)
			private(original)
			cache = {}
			define_method(name){|*args|
				cache[args] ||= send(original, *args)
			}
		}
	end 
end
include Memoizable

MOD = 1_000_000_007

def fact(n)
	return 1 if n == 0
	n * fact(n-1)
end

def all_perm(n)
	return 1 if n == 0
	1 + (0..n-1).map {|k| fact(n) / fact(k)}.inject(:+)
end

def f(sizes)
	h = { [0, 0] => 1 }
	sizes.reverse.each do |s|
		new_h = Hash.new(0)
		h.each do |(k, l), c|
			new_h[[k, l]] += c
			new_h[[k+1, l+s]] += c
		end
		h = new_h
	end

	s = 0
	h.each do |(k, l), c|
		s += (10 ** l) * c * fact(k) * all_perm(sizes.size - k)
	end
	s
end

memoize :fact
memoize :all_perm
memoize :f

n = gets.to_i
cards = (1..n).map { gets.to_i }.sort
sum = 0

size_count = Hash.new(0)
sum_per_size = Hash.new(0)
cards.each do |x|
	k = x.to_s.size
	size_count[k] += 1
	sum_per_size[k] += x
end

(1..4).each do |i|
	sizes = (1..4).map {|j| [j] * (size_count[j] - (j == i ? 1 : 0))}.flatten
	sum += sum_per_size[i] * f(sizes)
end

if cards[0] > 0 || n == 1
	puts sum % MOD
	exit
end

size_count[1] -= 1
(1..4).each do |i|
	sizes = (1..4).map {|j| [j] * (size_count[j] - (j == i ? 1 : 0))}.flatten
	sum -= sum_per_size[i] * f(sizes)
end

puts sum % MOD