This problem differs from the previous one only in the absence of the constraint on the equal length of all numbers $a_1, a_2, \dots, a_n$.

A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem.

Let's denote a function that alternates digits of two numbers $f(a_1 a_2 \dots a_{p - 1} a_p, b_1 b_2 \dots b_{q - 1} b_q)$, where $a_1 \dots a_p$ and $b_1 \dots b_q$ are digits of two integers written in the decimal notation without leading zeros.

In other words, the function $f(x, y)$ alternately shuffles the digits of the numbers $x$ and $y$ by writing them from the lowest digits to the older ones, starting with the number $y$. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below.

For example: $$f(1111, 2222) = 12121212$$ $$f(7777, 888) = 7787878$$ $$f(33, 44444) = 4443434$$ $$f(555, 6) = 5556$$ $$f(111, 2222) = 2121212$$

Formally,  if $p \ge q$ then $f(a_1 \dots a_p, b_1 \dots b_q) = a_1 a_2 \dots a_{p - q + 1} b_1 a_{p - q + 2} b_2 \dots a_{p - 1} b_{q - 1} a_p b_q$;  if $p < q$ then $f(a_1 \dots a_p, b_1 \dots b_q) = b_1 b_2 \dots b_{q - p} a_1 b_{q - p + 1} a_2 \dots a_{p - 1} b_{q - 1} a_p b_q$. 

Mishanya gives you an array consisting of $n$ integers $a_i$, your task is to help students to calculate $\sum_{i = 1}^{n}\sum_{j = 1}^{n} f(a_i, a_j)$ modulo $998\,244\,353$.


-----Input-----

The first line of the input contains a single integer $n$ ($1 \le n \le 100\,000$) — the number of elements in the array. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the elements of the array.


-----Output-----

Print the answer modulo $998\,244\,353$.


-----Examples-----
Input
3
12 3 45

Output
12330
Input
2
123 456

Output
1115598

Difficulty: MEDIUM_HARD

Solutions:
from sys import stdin, stdout, exit
mod = 998244353
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
ans = 0

def l(x):
	if x == 0:
		return 0
	return 1 + l(x // 10)
lens = [0] * 15
for x in a:
	lens[l(x)] += 1

def space_out(x, l):
	ans = []
	for (i, c) in enumerate(reversed(str(x))):
		ans.append(c)
		if i < l:
			ans.append('0')
	return int(''.join(reversed(ans)))
for i in range(n):
	x = a[i]
	cur_head = x // 10
	cur = x
	prev = x
	for l in range(11):
		if l > 0:
			ans += lens[l] * (cur + 10 * prev)
			ans %= mod
		prev = cur
		cur -= cur_head * 10 ** (2 * l + 1)
		cur += cur_head * 10 ** (2 * l + 2)
		cur_head //= 10
stdout.write(str(ans) + '\n')


n = int(input())
l = list(input().strip().split())
sum = 0
dic = {}
for i in range(n):
	if len(l[i]) in dic:
		dic[len(l[i])] += 1
	else:
		dic[len(l[i])] = 1

def calc(a, k):
	a0 = a[-k:]
	a1 = a[:-k]
	A1 = 0
	if a1 != '':
		A1 = int(a1) * 10 ** (k * 2) * 2
	ans = ''
	for k in a0:
		ans += k * 2
	return A1 + int(ans)
for i in range(n):
	for k in dic:
		sum += calc(l[i], k) * dic[k] % 998244353
		sum = sum % 998244353
print(sum)


from collections import Counter
b = 998244353

def __starting_point():
	n = int(input())
	arr = input().split()
	mp = list(map(lambda x: len(x), arr))
	cnt = Counter(mp)
	s = 0
	for a in arr:
		l = list(reversed(a))
		for (num, ln) in cnt.items():
			l1 = int(''.join(list(reversed(['%s0' % x if i < num else x for (i, x) in enumerate(l)]))))
			l2 = int(''.join(list(reversed(['0%s' % x if j < num else x for (j, x) in enumerate(l)]))))
			s = (s + l1 * ln) % b
			s = (s + l2 * ln) % b
	print(s)
__starting_point()


INF = 10 ** 10
MOD = 998244353

def mod_mul(x, y, z=0):
	result = 0
	if y == 0:
		return result
	while y > 1:
		if y & 1 == 1:
			result += x
			if result >= MOD:
				result -= MOD
		x += x
		if x >= MOD:
			x -= MOD
		y >>= 1
	result += x
	if result >= MOD:
		result -= MOD
	result += z
	if result >= MOD:
		result -= MOD
	return result

def main():
	n = int(input())
	str_a = input().split()
	counter = [0] * 11
	for ai in str_a:
		counter[len(ai)] += 1
	pow10 = [0] * 19
	pow10[0] = 1
	for i in range(18):
		pow10[i + 1] = mod_mul(pow10[i], 10)
	ans = 0
	for i in range(n):
		for (j, digit) in enumerate(reversed(str_a[i])):
			digit = ord(digit) - 48
			for k in range(1, 11):
				ans = mod_mul(mod_mul(counter[k] * digit, pow10[min(2 * j, j + k)]), 11 if j < k else 2, ans)
	print(ans % MOD)
import sys
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
main()
print(*out, sep='\n')


mod = 998244353

def main():
	n = int(input())
	A = list(map(int, input().split()))
	N = 10 ** 6
	table = [0] * (N + 1)
	table[0] = 1
	for i in range(1, N + 1):
		table[i] = table[i - 1] * 10
		table[i] %= mod
	C = [0] * 11
	for a in A:
		C[len(str(a))] += 1
	ans = 0
	for (i, a) in enumerate(A):
		a = str(a)
		a = list(a)
		a.reverse()
		for (j, c) in enumerate(a):
			c = int(c)
			for k in range(11):
				if k <= j:
					ans += c * table[2 * j + 1 - (j - k + 1)] * C[k]
				else:
					ans += c * table[2 * j + 1] * C[k]
			for k in range(11):
				if k <= j - 1:
					ans += c * table[2 * j - (j - k)] * C[k]
				else:
					ans += c * table[2 * j] * C[k]
			ans %= mod
	print(ans)
main()


n = int(input())
a = input()
b = a.split(' ')
l = len(b[0])
z = ''
times = []
pre = []
for i in range(12):
	times.append(0)
	pre.append(0)
for i in range(n):
	times[len(b[i])] = times[len(b[i])] + 1
p = 998244353
pre[1] = times[1]
for i in range(2, 12):
	pre[i] = pre[i - 1] + times[i]
su = 0
for i in range(n):
	cur = b[i]
	siz = len(b[i])
	num = ''
	for j in range(siz):
		num = num + b[i][j]
		num = num + '0'
	num = int(num)
	su = (su % p + num % p * (pre[10] - pre[siz - 1]) % p % p) % p
	num = num // 10
	su = (su % p + num % p * (pre[10] - pre[siz - 1]) % p % p) % p
	for j in range(1, siz):
		if times[j] == 0:
			continue
		dif = siz - j
		cur_num1 = cur[0:dif]
		cur_num2 = cur[0:dif]
		for k in range(dif, siz):
			cur_num1 = cur_num1 + cur[k]
			cur_num1 = cur_num1 + '0'
			cur_num2 = cur_num2 + '0'
			cur_num2 = cur_num2 + cur[k]
		cur_num1 = int(cur_num1)
		cur_num2 = int(cur_num2)
		su = (su % p + cur_num1 % p * times[j] % p % p) % p
		su = (su % p + cur_num2 % p * times[j] % p % p) % p
print(su)


n = int(input())
sum = 0
line = input().split()
freq = []
for i in range(0, 11):
	freq.append(0)
for item in line:
	freq[len(item)] += 1

def solve1(str, l):
	n = len(str)
	i = 0
	s = ''
	if n >= l:
		s = str[0:n - l]
		i = n - l
	for k in range(i, n):
		s = s + str[k] + '0'
	return s

def solve2(str, l):
	n = len(str)
	i = 0
	s = ''
	if n >= l:
		s = str[0:n - l]
		i = n - l
	for k in range(i, n):
		s = s + '0' + str[k]
	return s
for i in range(0, n):
	for l in range(1, 11):
		if freq[l] != 0:
			temp1 = solve1(line[i], l)
			temp2 = solve2(line[i], l)
			sum = sum + (int(temp1) + int(temp2)) * freq[l]
			sum %= 998244353
print(sum)


from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
inf = float('inf')
from functools import cmp_to_key
from collections import defaultdict as dd
from collections import Counter, deque
from heapq import *
import math
from math import floor, ceil, sqrt

def geti():
	return map(int, input().strip().split())

def getl():
	return list(map(int, input().strip().split()))

def getis():
	return map(str, input().strip().split())

def getls():
	return list(map(str, input().strip().split()))

def gets():
	return input().strip()

def geta():
	return int(input())

def print_s(s):
	stdout.write(s + '\n')

def solve():
	n = geta()
	a = getl()
	ans = 0
	mod = 998244353
	count = dd(int)
	for i in a:
		count[len(str(i))] += 1
	for i in a:
		for j in count:
			new = ''
			now = str(i)
			index = len(now) - 1
			other = ''
			for zero in range(j):
				if index == -1:
					break
				other = now[index] + other
				other = '0' + other
				new = '0' + new
				new = now[index] + new
				index -= 1
			while index != -1:
				new = now[index] + new
				other = now[index] + other
				index -= 1
			ans += int(new) * count[j]
			ans %= mod
			ans += int(other) * count[j]
			ans %= mod
	print(ans)
solve()


prime = 998244353
n = int(input())
arr = list(input().split())
count = [0 for i in range(11)]
count2 = [0 for i in range(11)]
for i in arr:
	count[len(i)] += 1
for i in range(1, 11):
	count2[i] = count2[i - 1] + count[i]
ans = 0
for i in arr:
	place = 1
	k = 1
	for j in range(len(i) - 1, -1, -1):
		ans = (ans + (count2[10] - count2[k - 1]) * place * int(i[j])) % prime
		ans = (ans + (count2[10] - count2[k - 1]) * place * int(i[j]) * 10) % prime
		for l in range(1, k):
			ans = (ans + 2 * count[l] * pow(10, l + k - 1) * int(i[j])) % prime
		place = place * 100
		k += 1
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
A = list(input().split())
mod = 998244353

def calc(a, k):
	a0 = a[-k:]
	a1 = a[:-k]
	A1 = 0
	if a1 != '':
		A1 = int(a1) * 10 ** (k * 2) * 2
	ANS = ''
	for k in a0:
		ANS += k * 2
	return A1 + int(ANS)
L = [len(a) for a in A]
from collections import Counter
C = Counter(L)
ANS = 0
for a in A:
	for k in range(1, 11):
		x = C[k]
		ANS = (ANS + calc(a, k) * x) % mod
print(ANS)


import math
n = int(input())
arr = [i for i in input().split()]
CT = [0 for i in range(40)]
for i in arr:
	CT[len(i)] += 1
P = [0 for i in range(40)]
M = 998244353
ans = 0
howmanyhavelengthlesser = [0 for i in range(40)]
howmanyhavelengthgreater = [0 for i in range(40)]
for i in range(40):
	for j in range(i):
		howmanyhavelengthlesser[i] += CT[j]
	for j in range(i + 1, 40):
		howmanyhavelengthgreater[i] += CT[j]
for i in arr:
	cur = 0
	for j in range(len(i) - 1, -1, -1):
		for k in range(cur, 2 * cur + 1):
			if k != 2 * cur:
				P[k] += int(i[j]) * CT[cur - (2 * cur - k)]
			else:
				P[k] += int(i[j]) * (howmanyhavelengthgreater[cur] + CT[cur])
		cur += 1
for i in arr:
	cur = 0
	for j in range(len(i) - 1, -1, -1):
		for k in range(cur + 1, 2 * cur + 2):
			if k == 2 * cur + 1:
				P[k] += int(i[j]) * (howmanyhavelengthgreater[cur + 1] + CT[cur + 1])
			else:
				P[k] += int(i[j]) * CT[cur + 1 - (2 * cur + 1 - k)]
		cur += 1
for i in range(30):
	ans = (ans + P[i] * pow(10, i, M)) % M
print(ans)


from sys import stdin

def main():
	n = int(input())
	aa = input().split()
	aad = [[int(ad) for ad in a] for a in aa]
	sums = []
	dcount = []
	for a in aad:
		l = len(a)
		for i in range(l):
			if i >= len(sums):
				sums.append(a[-i - 1])
				dcount.append(1)
			else:
				sums[i] += a[-i - 1]
				dcount[i] += 1
	digits = len(sums)
	sums += [0] * digits
	lencount = [dcount[n] - dcount[n + 1] for n in range(digits - 1)] + [dcount[-1]]
	sums2 = [0] * (digits * 2)
	for i in range(digits):
		sums2[i * 2] = sums[i] * dcount[i]
		sums2[i * 2 + 1] = sums[i] * dcount[i]
		for j in range(i):
			sums2[i * 2] += sums[i * 2 - j - 1] * lencount[j] * 2
			sums2[i * 2 + 1] += sums[i * 2 - j] * lencount[j] * 2
	res = 0
	for i in range(len(sums2) - 1, -1, -1):
		res = (sums2[i] + res * 10) % 998244353
	print(res)

def __starting_point():
	main()
__starting_point()


mod = 998244353

def count_digits(x):
	return len(str(x))
n = int(input())
a = [int(x) for x in input().split(' ')]
digs = [0] * 11
ans = 0
for ai in a:
	digs[count_digits(ai)] += 1
for ai in a:
	x = ai
	g = 1
	for d in range(1, 11):
		x = x % g + x // g * 10 * g
		g *= 100
		ans = (ans + digs[d] * x % mod) % mod
	x = ai
	g = 10
	for d in range(1, 11):
		x = x % g + x // g * 10 * g
		g *= 100
		ans = (ans + digs[d] * x % mod) % mod
print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
n = int(input())
mod = 998244353
vals = [[int(i) for i in k] for k in input().split()]
length = [0 for s in range(10)]
for i in range(n):
	digits = len(vals[i])
	length[digits - 1] += 1
ans = 0
for i in range(n):
	digits = len(vals[i])
	for s in range(10):
		cv = 0
		count = 0
		if digits - 2 <= s:
			for b in range(digits - 1, -1, -1):
				count += vals[i][b] * pow(10, cv, mod)
				count = count % mod
				cv += 2
		else:
			count += vals[i][-1]
			cv += 2
			for b in range(digits - 2, digits - 3 - s, -1):
				count += vals[i][b] * pow(10, cv, mod)
				count = count % mod
				cv += 2
			cv -= 1
			for b in range(digits - 3 - s, -1, -1):
				count += vals[i][b] * pow(10, cv, mod)
				count = count % mod
				cv += 1
		ans += count * length[s] % mod
		ans = ans % mod
for i in range(n):
	digits = len(vals[i])
	for s in range(10):
		cv = 1
		count = 0
		if digits - 1 <= s:
			for b in range(digits - 1, -1, -1):
				count += vals[i][b] * pow(10, cv, mod)
				count = count % mod
				cv += 2
		else:
			for b in range(digits - 1, digits - 2 - s, -1):
				count += vals[i][b] * pow(10, cv, mod)
				count = count % mod
				cv += 2
			cv -= 1
			for b in range(digits - 2 - s, -1, -1):
				count += vals[i][b] * pow(10, cv, mod)
				count = count % mod
				cv += 1
		ans += count * length[s] % mod
		ans = ans % mod
print(ans)


import sys
input = sys.stdin.readline

def main():
	N = int(input())
	A = list(map(int, input().split()))
	mod = 998244353
	max_l = 0
	Dig = [0] * 11
	for a in A:
		l = len(str(a))
		Dig[l - 1] += 1
		max_l = max(max_l, l)
	D = [0] * 21
	for a in A:
		l = len(str(a))
		for j in range(max_l):
			for k in range(l):
				n = int(str(a)[l - 1 - k])
				ck = Dig[j]
				if j >= k:
					D[k * 2] += ck * n % mod
					D[k * 2 + 1] += ck * n % mod
				else:
					D[j + k + 1] += 2 * ck * n % mod
	ans = 0
	for i in range(21):
		ans = (ans + D[i] % mod * (10 ** i % mod)) % mod
	print(ans)
main()


import io, sys
input = lambda f=io.StringIO(sys.stdin.buffer.read().decode()).readline: f().rstrip()
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
MOD = 998244353
pow10 = [10 ** i % MOD for i in range(21)]
n = ii()
a = li()
rec = [0] * 11
cnt = [0] * 11
for x in a:
	i = -1
	while x:
		i += 1
		rec[i] += pow10[2 * i + 1]
		x //= 10
	cnt[i] += 1
	j = 2 * i + 1
	while i < 10:
		i += 1
		j += 1
		rec[i] += pow10[j]
suf = [0] * 12
for i in range(10, -1, -1):
	suf[i] = suf[i + 1] + cnt[i]
ans = 0
for x in a:
	i = -1
	while x:
		i += 1
		d = x % 10
		ans += rec[i] * d
		ans += d * pow10[2 * i] * suf[i] % MOD
		x //= 10
		ans += x * pow10[2 * i + 2] * cnt[i] % MOD
	ans %= MOD
print(ans)


import sys

def input():
	return sys.stdin.readline().strip()

def dinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(str, tinput())

def rt(a, s):
	t = ''
	z = 0
	x = len(a)
	y = len(s)
	while z < x and z < y:
		t = t + a[z] + s[z]
		z += 1
	print(y, x, t)
	if y > x:
		t = t + s[z:]
	else:
		t = t + a[z:]
	return int(t)

def main():
	n = dinput()
	q = list(rinput())
	w = {}
	ans = 0
	for i in q:
		if len(i) not in w:
			w[len(i)] = 1
		else:
			w[len(i)] = w[len(i)] + 1
	for i in range(n):
		y = ''
		x = ''
		for j in range(1, 11):
			c = q[i]
			if len(c) > j:
				a = c[0:len(c) - j]
			else:
				a = ''
			if len(c) - j >= 0:
				y = '0' + c[len(c) - j] + y
				x = c[len(c) - j] + '0' + x
			l = a + y
			r = a + x
			if j in w:
				ans += int(l) * w[j]
				ans += int(r) * w[j]
	print(ans % 998244353)
main()


f = []
u = 1
for i in range(23):
	f.append(u % 998244353)
	u *= 10

def F(sai, saj):
	p = len(sai)
	q = len(saj)
	z = ''
	if p >= q:
		for t in range(p - q):
			z += sai[t]
		for t in range(q):
			z += sai[t + p - q]
			z += saj[t]
	else:
		for t in range(q - p):
			z += saj[t]
		for t in range(p):
			z += sai[t]
			z += saj[t + q - p]
	c = 1
	r = []
	for i in range(len(z)):
		if z[i] != 'a':
			r.append(len(z) - 1 - i)
	return r

def cont(r, k):
	c = 0
	for i in range(len(k) - 1, -1, -1):
		c += f[r[i]] * int(k[i])
		c %= 998244353
	return c
n = int(input())
a = [int(x) for x in input().split()]
cnt = [0] * 11
for i in a:
	cnt[len(str(i))] += 1
d = {}
for i in range(11):
	if cnt[i]:
		d[i] = 1
k = []
g = []
memo = {}
for i in range(11):
	k.append('a' * i)
	g.append('b' * i)
for i in k:
	for j in g:
		memo[len(i), len(j), 0] = F(i, j)
		memo[len(j), len(i), 1] = F(j, i)
ans = 0
for i in a:
	e = str(i)
	for j in d:
		ans += cnt[j] * (cont(memo[len(k[j]), len(e), 0], e) + cont(memo[len(e), len(k[j]), 1], e)) % 998244353
print(ans % 998244353)


def le2(num):
	s = str(num)
	ans = ''
	for i in s:
		ans += i + '0'
	ans = ans[:-1]
	return int(ans)

def m1(num, less):
	sn = str(num)
	sr = ''
	for i in range(less):
		sr += '0' + sn[-1]
		sn = sn[:-1]
	sr = sn + sr[::-1]
	return int(sr)

def m2(num, less):
	sn = str(num)
	sr = ''
	for i in range(less):
		sr += sn[-1] + '0'
		sn = sn[:-1]
	sr = sn + sr[::-1]
	return int(sr)
mod = 998244353
ans = 0
n = int(input())
d = [[] for i in range(11)]
a = list(map(int, input().split()))
for i in a:
	d[len(str(i))].append(i)
prev = 0
for i in range(1, 11):
	curlen = len(d[i])
	for lessnum in d[i - 1]:
		prev = (prev + le2(lessnum)) % mod
	ans = (ans + prev * curlen) % mod
	for lessdigits in range(1, i):
		downsum = 0
		for curnum in d[i]:
			downsum = (downsum + m1(curnum, lessdigits)) % mod
		ans = ans + downsum * len(d[lessdigits])
	cursuml1 = 0
	for enum in d[i]:
		res = le2(enum)
		ans = (ans + curlen * 11 * res) % mod
		cursuml1 = (cursuml1 + 10 * res) % mod
	for moredigits in range(i + 1, 11):
		ans = (ans + cursuml1 * len(d[moredigits])) % mod
		moresum = 0
		for morenum in d[moredigits]:
			moresum = (moresum + m2(morenum, i)) % mod
		ans = (ans + moresum * curlen) % mod
print(ans)


mod = 998244353
ten = [1]
for i in range(1, 30):
	ten.append(ten[i - 1] * 10 % mod)

def funcxy(bit, x_l, y_l):
	if x_l >= y_l:
		if y_l > bit:
			return ten[2 * bit + 1]
		else:
			return ten[bit + y_l]
	else:
		return ten[2 * bit + 1]

def funcyx(bit, x_l, y_l):
	if x_l > y_l:
		if y_l > bit:
			return ten[2 * bit]
		else:
			return ten[bit + y_l]
	else:
		return ten[2 * bit]
n = int(input())
a = [x for x in input().split()]
length = [len(x) for x in a]
d = {}
for x in length:
	if x in d:
		d[x] += 1
	else:
		d[x] = 1
len_set = set(length)
res = 0
for x in a:
	x_l = len(x)
	x = [int(x_) for x_ in x[::-1]]
	for (i, xi) in enumerate(x):
		for y_l in len_set:
			res += xi * funcxy(i, x_l, y_l) * d[y_l]
			res += xi * funcyx(i, x_l, y_l) * d[y_l]
print(res % mod)


import math
import heapq, bisect
import sys
from collections import deque
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree1:

	def __init__(self, data, default=9999999, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
n = int(input())
l = list(map(int, input().split()))
d = dict()
cd = dict()
for i in range(n):
	c = countdig(l[i])
	if l[i] not in cd:
		cd.update({l[i]: c})
	if c in d:
		d[c] += 1
	else:
		d.update({c: 1})
tot = 0
for i in range(n):
	r = cd[l[i]]
	cop = l[i]
	for j in d:
		ans = 0
		if d[j] == 0:
			continue
		else:
			re = 10
			c = 1
			w = j - 1
			t = 1
			w1 = j
			t1 = 0
			for k in range(r):
				ans = (ans + l[i] % re * pow(10, c - 1 + t, mod1) % mod1) % mod1
				ans = (ans + l[i] % re * pow(10, c - 1 + t1, mod1) % mod1) % mod1
				if w > 0:
					w -= 1
					t += 1
				if w1 > 0:
					w1 -= 1
					t1 += 1
				c += 1
				l[i] //= 10
			tot += ans % mod1 * (d[j] % mod1)
			tot %= mod1
			l[i] = cop
print(tot % mod1)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter()
for ai in a:
	l = len(str(ai))
	c[l] += 1
res = 0
mod = 998244353
for ai in a:
	s = str(ai)
	l = len(s)
	for (key, value) in c.items():
		if key >= l:
			eq = '0'.join(s)
			res = (res + int(eq) * value) % mod
			eq = '0'.join(s) + '0'
			res = (res + int(eq) * value) % mod
		else:
			eq = []
			for i in range(l - key, l):
				eq.append(s[i] * 2)
			eq = [s[:-key]] + eq
			eq = ''.join(eq)
			res = (res + (int(eq) + int(s[:-key] + '0' * 2 * key)) * value) % mod
print(res)


n = int(input())
ans = [0] * 30
length = [0] * 11
lol = [o for o in input().split()]
count = [0] * 30
for i in range(n):
	length[len(lol[i]) - 1] += 1
for i in range(n):
	lol[i] = lol[i][::-1]
	for j in range(len(lol[i])):
		for k in range(j):
			ans[2 * k + (j - k) + 1] += 2 * (int(lol[i][j]) * length[k])
		for k in range(j, 10):
			ans[2 * j] += int(lol[i][j]) * length[k]
			ans[2 * j + 1] += int(lol[i][j]) * length[k]
realans = ['0'] * 30
c = 0
for i in range(30):
	realans[i] = str(int(ans[i] + c) % 10)
	c = (ans[i] + c) // 10
print(int(''.join(realans[::-1])) % 998244353)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
mod = 998244353
cnt = [0] * 20
for i in range(n):
	cnt[len(str(a[i])) - 1] += 1
ans = 0
for x in a:
	for (n, k) in enumerate(cnt):
		ans += x * 10 * k
		d = 10 * 100 ** n
		x = x % d + (x - x % d) * 10
		ans += x * k
print(ans % mod)


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
MOD = 998244353

def pads(x, k):
	(e, r) = (1, 0)
	while x > 0:
		(x, m) = divmod(x, 10)
		r += e * m
		e *= [10, 100][k > 0]
		k -= 1
	return r % MOD
nb = RI()
arr = RMI()
lcnt = [0] * 11
for i in arr:
	lcnt[len(str(i))] += 1
r = 0
for j in range(1, 11):
	for i in range(nb):
		r = (r + lcnt[j] * (pads(arr[i], j) + 10 * pads(arr[i], j - 1))) % MOD
print(r)


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 998244353
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	N = 10001
	invfact = [0] * N
	fact = [1] * N
	for i in range(1, N):
		fact[i] = fact[i - 1] * i % mod
	invfact[-1] = pow(fact[-1], mod - 2, mod)
	for i in range(N - 2, -1, -1):
		invfact[i] = (i + 1) * invfact[i + 1] % mod

	def nCr(x, y):
		if y > x:
			return 0
		ans = invfact[x - y] * invfact[y] % mod
		ans *= fact[x]
		ans %= mod
		return ans
	n = ii()
	a = list(map(str, input().split()))
	count = [0] * 21
	elem_size = [0] * 11
	for i in a:
		elem_size[len(i)] += 1
	for i in range(n):
		n1 = len(a[i])
		cur = list(a[i])
		for j in range(1, n1):
			idx = 0
			x = n1 - j
			k = 2 * j + x - 1
			while x:
				count[k] += 2 * elem_size[j] * int(cur[idx]) % mod
				count[k] %= mod
				x -= 1
				k -= 1
				idx += 1
			f = 0
			for k1 in range(k, -1, -1):
				count[k1] += elem_size[j] * int(cur[idx]) % mod
				count[k1] %= mod
				if f:
					idx += 1
				f ^= 1
		for j in range(n1, 11):
			idx = 0
			f = 0
			for k in range(2 * n1 - 1, -1, -1):
				count[k] += elem_size[j] * int(cur[idx]) % mod
				count[k] %= mod
				if f:
					idx += 1
				f ^= 1
	ans = 0
	pw = 1
	for i in range(21):
		ans += count[i] * pw % mod
		ans %= mod
		pw *= 10
		pw %= mod
	print(ans)
if file:
	if path.exists('tmp/input.txt'):
		sys.stdin = open('tmp/input.txt', 'r')
		sys.stdout = open('tmp/output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


n = int(input())

def cal(X):
	ans = 0
	_len = len(X)
	for i in range(_len):
		ans += int(X[i]) * 100 ** (_len - 1 - i)
	return ans * 11
A = input().split()

def LOL(n):
	if n == '':
		return 0
	else:
		return int(n)
cnt = [0 for i in range(11)]
for i in A:
	cnt[len(i)] += 1
ans = 0
for i in A:
	_len = len(i)
	for j in range(1, 1 + _len):
		ans += cnt[j] * (2 * LOL(i[:_len - j]) * 100 ** j + cal(i[_len - j:]))
	for j in range(_len + 1, 11):
		ans += cal(i) * cnt[j]
print(ans % 998244353)


from sys import stdin, stdout
N = int(input())
arr1 = [int(x) for x in stdin.readline().split()]
arr2 = list(arr1)
L = 0
for i in range(N):
	L = max(L, len(str(arr1[i])))
res = 0
for i in range(1, L + 1):
	s = 0
	valid = 0
	remove = 0
	for j in range(N):
		num = arr1[j]
		if len(str(num)) >= i:
			valid += 1
		if len(str(num)) == i - 1:
			remove += 1
	for j in range(N):
		num = arr1[j]
		if len(str(num)) >= i:
			digit = int(str(num)[-i])
			A = 10
			B = 1
			s += valid * digit * 11
	for j in range(N):
		num = arr2[j]
		res += 10 ** (2 * i - 2) * 2 * num * remove
		arr2[j] = arr2[j] // 10
	res += 10 ** (2 * i - 2) * s
print(res % 998244353)


mod = 998244353
pws = [1]
for i in range(1, 22):
	pws.append(pws[i - 1] * 10)
n = int(input())
h = list(map(int, input().split()))
a = [[] for i in range(n)]
for i in range(n):
	x = h[i]
	while x:
		a[i].append(x % 10)
		x = x // 10
cnt = [0] * 11
for i in range(n):
	cnt[len(a[i])] += 1
s = 0
for i in range(n):
	for j in range(len(a[i])):
		cur = 0
		for k in range(1, j):
			s = (s + a[i][j] * pws[j + k] * cnt[k]) % mod
			cur += cnt[k]
		s = (s + a[i][j] * pws[2 * j] * (n - cur)) % mod
		cur = 0
		for k in range(1, j + 1):
			s = (s + a[i][j] * pws[j + k] * cnt[k]) % mod
			cur += cnt[k]
		s = (s + a[i][j] * pws[2 * j + 1] * (n - cur)) % mod
print(s)


def f(ch):
	return ord(ch) - ord('0')
n = int(input())
v = list(map(int, input().split()))
fr = [0] * 20
for x in v:
	fr[len(str(x))] += 1
for i in range(1, 20):
	fr[i] += fr[i - 1]
ans = 0
pre = [[-1] * 20 for _ in range(20)]
for x in v:
	strx = str(x)[::-1]
	for i in range(len(strx)):
		ans += 10 ** (2 * i + 1) * (n - fr[i]) * f(strx[i])
		dig = f(strx[i])
		if pre[i][dig] == -1:
			pre[i][dig] = 0
			for j in range(1, i + 1):
				pre[i][dig] += 10 ** (i + j) * (fr[j] - fr[j - 1]) * f(strx[i])
		ans += pre[i][dig]
pre = [[-1] * 20 for _ in range(20)]
for y in v:
	stry = str(y)[::-1]
	for i in range(len(stry)):
		ans += 10 ** (2 * i) * (n - (fr[i - 1] if i > 0 else 0)) * f(stry[i])
		dig = f(stry[i])
		if pre[i][dig] == -1:
			pre[i][dig] = 0
			for j in range(1, i):
				pre[i][dig] += 10 ** (i + j) * (fr[j] - fr[j - 1]) * f(stry[i])
		ans += pre[i][dig]
print(ans % 998244353)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	n = N()
	arr = RLL()
	res = 0
	ldic = defaultdict(int)
	for i in arr:
		ldic[len(str(i))] += 1
	for i in arr:
		p = res
		pre = suf = 0
		tag = 1
		ole = len(str(i))
		nle = 0
		while i > 0:
			lst = i % 10
			pre += lst * tag
			suf += lst * (tag * 10)
			tag *= 100
			i //= 10
			nle += 1
			le = ldic[nle]
			if le != 0:
				res = (res + pre * le % mod + suf * le % mod + 2 * i * tag * le) % mod
		grt = 0
		for j in ldic:
			if j > ole:
				grt += ldic[j]
		res = (res + pre * grt % mod + suf * grt % mod) % mod
	print(res % mod)
main()