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

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Number theory

Combinatorics

Mathematics


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)


n = int(input())
a = input().split()
b = [[] for i in range(10)]
c = [[] for i in range(10)]
d = [0 for i in range(11)]
ans = 0
for i in a:
	b[len(i) - 1].append(i)
for i in range(9, -1, -1):
	d[i] = d[i + 1] + len(b[i])
for i in range(10):
	for j in b[i]:
		k = ''.join(map(''.join, zip(j, j)))
		c[i].append(k)
for i in range(10):
	for j in range(i, 10):
		for k in b[j]:
			idx = -i - 1
			l = int(''.join(map(''.join, zip(k[idx:], k[idx:]))))
			if i == j:
				ans = ans + d[i] * l
			else:
				ans = ans + len(b[i]) * l
				ans = ans + 2 * len(b[i]) * int(k[:idx]) * 10 ** (-idx * 2)
print(ans % 998244353)


import sys
from math import sqrt
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 998244353
n = int(input())
a = input().split()
ans = 0
d = dict()
for i in a:
	d[len(i)] = d.get(len(i), 0) + 1
for i in a:
	j = 1
	tot = 0
	while j < len(i):
		if j in d:
			b = str()
			b += i[:len(i) - j] + '00' * j
			ans += int(b) * d[j] * 2
			b = str()
			for k in i[len(i) - j:]:
				b += k * 2
			ans += int(b) * d[j]
			tot += d[j]
		j += 1
	b = str()
	for j in i:
		b += j * 2
	ans += int(b) * (n - tot)
	ans = ans % mod
print(ans % mod)


def ch(a):
	cnt = 0
	while a > 0:
		a //= 10
		cnt += 1
	return cnt
a = int(input())
b = list(map(int, input().split()))
k = [0] * 20
for i in range(a):
	k[ch(b[i])] += 1
summ = 0
summ1 = 0
st = [1]
for i in range(25):
	st.append(st[-1] * 10)
for i in range(a):
	ot = [b[i] * 10, b[i] // 10 * 100 + b[i] % 10]
	for j in range(2, 25):
		if j % 2 == 0:
			ot.append(ot[-1] * 10)
			continue
		n = ot[j - 2]
		ot.append(n // st[j] * st[j + 1] + n % st[j])
	l = ch(b[i])
	for j in range(0, 12):
		if l == j:
			summ1 += k[j] * (ot[j * 2 - 2] + ot[j * 2 - 1])
		else:
			summ += k[j] * (ot[j * 2 - 2] + ot[j * 2 - 1])
print((summ + summ1) % 998244353)


n = int(input())
num = input().rstrip().split(' ')
ans = 0
length = [0 for _ in range(11)]
for k in num:
	length[len(k)] += 1
for i in num:
	check = len(i)
	for j in range(11):
		if check <= j:
			for l in range(check):
				ans += 11 * length[j] * int(i[check - l - 1]) * pow(10, 2 * l, 998244353)
				ans %= 998244353
		else:
			count = 0
			for u in range(check - (check - j)):
				ans += 11 * length[j] * int(i[check - u - 1]) * pow(10, count, 998244353)
				count += 2
				ans %= 998244353
			for v in range(check - (check - j), check):
				ans += 2 * length[j] * int(i[check - v - 1]) * pow(10, count, 998244353)
				count += 1
				ans %= 998244353
print(ans)


import sys
from collections import deque
IS_LOCAL = False

def read_one(dtype=int):
	return dtype(input())

def read_multiple(f, dtype=int):
	return f(map(dtype, input().split()))

def swap(x, y):
	return (y, x)

def main():
	n = 3
	a = [12, 3, 45]
	if not IS_LOCAL:
		n = read_one()
		a = read_multiple(list)
	d = 998244353
	(s, k) = (0, 1)
	tot = n
	z = 0
	while tot > 0:
		zeroed = 0
		for i in range(n):
			if a[i] == 0:
				continue
			t = a[i] % 10
			a[i] //= 10
			if a[i] == 0:
				zeroed += 1
			s = (s + t * z * k * 2) % d
			s = (s + t * tot * k * k * 11) % d
		k *= 10
		z += k * zeroed
		tot -= zeroed
	print(s)
if len(sys.argv) > 1 and sys.argv[1] == 'True':
	IS_LOCAL = True
main()


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

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

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

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest

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
f = []
u = 1
for i in range(23):
	f.append(u % 998244353)
	u *= 10

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

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		n = ri()
		a = ria()
		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
		wi(ans % 998244353)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


from sys import stdin
n = int(stdin.readline())
a = list(stdin.readline().split())
d = dict()
for x in range(13):
	d[x] = 0
for x in a:
	d[len(x)] += 1
ans = 0
MOD = 998244353
for x in a:
	for y in d:
		if d[y]:
			str1 = ''
			str2 = ''
			temp = x[::-1]
			z = 0
			while z < min(len(x), y):
				str1 += temp[z]
				str1 += '0'
				str2 += '0'
				str2 += temp[z]
				z += 1
			while z < len(x):
				str1 += temp[z]
				str2 += temp[z]
				z += 1
			ans += (int(str1[::-1]) + int(str2[::-1])) * d[y] % MOD
print(ans % MOD)


def F(sai, saj):
	p = len(sai)
	q = len(saj)
	if p >= q:
		z = ''
		for t in range(p - q):
			z += sai[t]
		for t in range(q):
			z += sai[t + p - q]
			z += saj[t]
	else:
		z = ''
		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 = 0
	for i in range(len(z) - 1, -1, -1):
		if z[i] != 'a':
			r += c * int(z[i])
		c *= 10
	return r
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 = []
for i in range(11):
	k.append('a' * i)
ans = 0
for i in a:
	for j in d:
		ans += cnt[j] * (F(k[j], str(i)) + F(str(i), k[j])) % 998244353
print(ans % 998244353)


n = int(input())
arr = list(map(str, input().split()))
cnt = [0] * 12
for val in arr:
	cnt[len(val)] += 1
acumcnt = [0] * 12
acumcnt[10] = cnt[10]
for i in range(9, -1, -1):
	acumcnt[i] = acumcnt[i + 1] + cnt[i]
mod = 998244353
ans = 0
modarr = [0] * 20
for i in range(20):
	modarr[i] = 10 ** i % mod % mod
for s in arr:
	for i in range(1, len(s) + 1):
		tmp = int(s[-i])
		if i == 1:
			ans += (acumcnt[2] + cnt[1]) * tmp * modarr[1] % mod
			ans += (acumcnt[2] + cnt[1]) * tmp * modarr[0] % mod
		elif i == 2:
			ans += (acumcnt[3] + cnt[2]) * tmp * modarr[3] % mod
			ans += (acumcnt[3] + cnt[2] + 2 * cnt[1]) * tmp * modarr[2] % mod
		else:
			for j in range(i, i * 2):
				if j == i * 2 - 1:
					ans += (acumcnt[i + 1] + cnt[i]) * tmp * modarr[j] % mod
				elif j == i * 2 - 2:
					ans += (acumcnt[i + 1] + cnt[i] + 2 * cnt[i - 1]) * tmp * modarr[j] % mod
				else:
					ans += 2 * cnt[j - i + 1] * tmp * modarr[j] % mod
print(ans % mod)


n = int(input())
arr = list(map(int, input().split()))
lengths = [0 for i in range(11)]
for i in arr:
	lengths[len(str(i)) - 1] += 1
ans = 0
for i in arr:
	for j in range(len(lengths)):
		ans += i * 10 * lengths[j]
		d = 10 * 100 ** j
		i = i % d + (i - i % d) * 10
		ans += i * lengths[j]
print(ans % 998244353)


n = int(input())
a = input().split()
b = {}
c = {}
for x in a:
	y = len(x)
	z = int(x)
	b[y] = b.get(y, 0) + 1
	c[z] = c.get(z, 0) + 1
M = 998244353
p = [1] * 30
for i in range(1, len(p)):
	p[i] = p[i - 1] * 10 % M
ans = 0
for (key, val) in c.items():
	w = 0
	while key > 0:
		d = key % 10
		key //= 10
		z = 0
		for (x, y) in b.items():
			z += y * (p[min(w, x)] + p[min(w + 1, x)])
		ans += val * d * p[w] * z % M
		w += 1
print(ans % M)


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 math
import sys
from collections import Counter
MOD = 1000000007

def f(a, b):
	ret = 0
	pow10 = 1
	while a and b:
		ret += b % 10 * pow10
		pow10 *= 10
		b //= 10
		ret += a % 10 * pow10
		pow10 *= 10
		a //= 10
	ret += a * pow10
	ret += b * pow10
	return ret

def ndigits(a):
	ret = 0
	while a:
		ret += 1
		a //= 10
	return ret

def contrib_for_digs(x, part_digs, x_is_a):
	partner = 10 ** (part_digs - 1)
	(a1, b1) = (partner, x)
	(a2, b2) = (2 * partner, x)
	if x_is_a:
		(a1, b1) = (b1, a1)
		(a2, b2) = (b2, a2)
	return 2 * f(a1, b1) - f(a2, b2)

def contrib(a, cnt):
	ret = 0
	for (part_digs, part_cnt) in list(cnt.items()):
		ret += part_cnt * contrib_for_digs(a, part_digs, True)
		ret += part_cnt * contrib_for_digs(a, part_digs, False)
	return ret

def solve_case():
	n = int(input())
	a = [int(p) for p in input().split()]
	a.sort()
	digs = [ndigits(ai) for ai in a]
	cnt = Counter(digs)
	ret = 0
	for ai in a:
		ret += contrib(ai, cnt)
	print(ret % 998244353)
if __name__ == '__main__' and (not hasattr(sys, 'ps1')):
	solve_case()


input()
a = list(map(int, input().split()))
cl = [0] * 10
for i in a:
	cl[len(str(i)) - 1] += 1
(ans, M) = (0, 998244353)
pad = lambda a, d: a % d + (a - a % d) * 10
for i in a:
	for (p, le) in enumerate(cl):
		ans = ans + i * 10 * le
		i = pad(i, 10 * 100 ** p)
		ans = ans + i * le
print(ans % M)


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 os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	a = list(map(int, input().split()))
	tmp = [[0 for _ in range(20)] for _ in range(10)]
	for i in range(n):
		s = [0 for j in range(10)]
		ss = str(a[i])
		for j in range(10):
			if j < len(ss):
				s[9 - j] = ord(ss[len(ss) - j - 1])
			else:
				s[9 - j] = 58 + j - len(ss)
		for j in range(10):
			tmp[j][s[9 - j] - 48] += 1
	asd = 0
	asd2 = 0
	for i in range(10):
		tp = 0
		for j in range(10):
			for k in range(10, 20):
				if tmp[i][k] != 0 and tmp[i][j] != 0:
					asd2 = (asd2 + j * tmp[i][j] * 2 * tmp[i][k] * pow(10, i * 2 - (k - 10))) % 998244353
			for k in range(10):
				tp += (10 * j + k) * tmp[i][k] * tmp[i][j]
		asd = (asd + tp * pow(100, i)) % 998244353
	print((asd + asd2) % 998244353)
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')
main()


n = int(input())
array = list(map(int, input().split(' ')))
count = [0 for i in range(10)]
for i in array:
	count[len(str(i)) - 1] += 1
result = 0
for i in array:
	for (l, c) in enumerate(count):
		result += i * 10 * c
		d = 10 * 100 ** l
		i = i % d + (i - i % d) * 10
		result += i * c
print(result % 998244353)


def dig_cnt(n):
	ans = 0
	while n >= 1:
		ans += 1
		n /= 10
	return ans
n = int(input())
arr = [int(x) for x in input().split()]
dig_count = [0 for _ in range(11)]
for i in arr:
	dig_count[dig_cnt(i)] += 1
ans = 0
mod = 998244353
for x in range(n):
	gv = str(arr[x])
	list_dig = []
	for i in gv:
		list_dig.append(i)
	list_dig = list_dig[::-1]
	digs = dig_cnt(arr[x])
	num = 0
	for i in gv:
		num = num * 10 + int(i)
		num = num * 10 + int(i)
	ans += num * dig_count[digs]
	for i in range(digs):
		if dig_count[i] == 0:
			continue
		(num1, num2) = ('', '')
		p = 0
		while p < i:
			num1 += list_dig[p]
			num1 += '0'
			p += 1
		while p < digs:
			num1 += list_dig[p]
			p += 1
		p = 0
		while p < i:
			num2 += '0'
			num2 += list_dig[p]
			p += 1
		while p < digs:
			num2 += list_dig[p]
			p += 1
		num1 = num1[::-1]
		num2 = num2[::-1]
		ans += (int(num1) + int(num2)) * dig_count[i]
	fact = 0
	for i in range(digs + 1, 11):
		fact += dig_count[i]
	(num1, num2) = ('', '')
	p = 0
	while p < digs:
		num1 += list_dig[p]
		num1 += '0'
		p += 1
	num1 += '0'
	p = 0
	while p < digs:
		num2 += '0'
		num2 += list_dig[p]
		p += 1
	num2 += '0'
	num1 = num1[::-1]
	num2 = num2[::-1]
	ans += (int(num1) + int(num2)) * fact
print(ans % mod)


from collections import defaultdict as dd, deque as dq
import math, string
import sys

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 998244353
tens = [1]
curr = 1
for i in range(1, 10 ** 5 + 5):
	curr *= 10
	curr %= MOD
	tens.append(curr)

def solve():
	N = getInt()
	A = getInts()
	lens = [0] * 11
	for a in A:
		lens[len(str(a))] += 1
	ans = 0
	for a in A:
		X = [int(s) for s in str(a)]
		for (i, x) in enumerate(X):
			for k in range(1, 11):
				if not lens[k]:
					continue
				L = lens[k]
				if len(X) - i > k:
					ans += int(x) * tens[k + len(X) - i - 1] * L * 2
					ans %= MOD
				else:
					ans += int(x) * tens[2 * (len(X) - i - 1)] * L * 11
					ans %= MOD
	return ans
print(solve())


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
l = [len(str(i)) for i in a]
c = Counter(l)
cl = [c[i] for i in range(1, 11)]
M = 998244353
pad = lambda a, d: a % d + (a - a % d) * 10
ans = 0
for i in a:
	il = len(str(i))
	t = i
	for p in range(10):
		i = pad(i, 100 ** p)
		ans = (ans + i * cl[p]) % M
	i = t
	for p in range(10):
		i = pad(i, 10 * 100 ** p)
		ans = (ans + i * cl[p]) % M
print(ans)


n = int(input())
mod = 998244353
ans = 0
ai = input().split()
lengths = [0] * 11
for i in range(n):
	temp = len(ai[i])
	lengths[temp] += 1
tens = [0] * 25
for i in range(25):
	tens[i] = 10 ** i
for i in range(n):
	temp = len(ai[i])
	num = 0
	for j in range(temp, 11):
		num += lengths[j]
	for z in range(temp):
		ans += num * tens[z * 2] * int(ai[i][-z - 1])
		ans += num * tens[z * 2 + 1] * int(ai[i][-z - 1])
	for j in range(1, temp):
		if lengths[j] != 0:
			for z in range(j):
				ans += lengths[j] * tens[z * 2] * int(ai[i][-z - 1])
				ans += lengths[j] * tens[z * 2 + 1] * int(ai[i][-z - 1])
			for z in range(temp - j):
				ans += 2 * lengths[j] * tens[j * 2 + z] * int(ai[i][-(z + j) - 1])
	ans %= mod
print(ans)


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, math, queue, bisect
MOD = 998244353
sys.setrecursionlimit(1000000)

def first(n, d):
	p = 0
	a = 0
	while n > 0:
		a += n % 10 * pow(10, p, MOD)
		if d > 0:
			p += 2
			d -= 1
		else:
			p += 1
		n = n // 10
		a = a % MOD
	return a

def second(n, d):
	p = 1
	a = 0
	d -= 1
	while n > 0:
		a += n % 10 * pow(10, p, MOD)
		if d > 0:
			p += 2
			d -= 1
		else:
			p += 1
		n = n // 10
		a = a % MOD
	return a
n = int(input())
a = list(map(int, input().split()))
d = {i: 0 for i in range(1, 11)}
for ai in a:
	d[len(str(ai))] += 1
ans = 0
for ai in a:
	for di in d:
		ans += d[di] * first(ai, di) % MOD
		ans += d[di] * second(ai, di) % MOD
		ans = ans % MOD
print(ans)


modulo = 998244353
from collections import Counter

def conv(x):
	res = 0
	for v in x:
		res = (res * 100 + int(v)) % modulo
	return res
n = int(input())
x = list(input().split())
c = Counter((len(v) for v in x))
res = 0
for v in x:
	u = len(v)
	for (w, k) in c.items():
		if w >= u:
			res += k * 11 * conv(v)
		else:
			d = u - w
			res += k * 11 * conv(v[d:])
			res += k * 2 * int(v[:d]) * 10 ** (2 * w)
	res %= modulo
print(res)


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)


from sys import stdin
n = int(stdin.readline())
a = list((list((j for j in i)) for i in stdin.readline().split()))
b = list((0 for i in range(0, 10)))
for i in a:
	b[len(i) - 1] += 1
Ans = 0

def left(x, b):
	Sum = 0
	y = len(x)
	for i in range(0, 10):
		if b[i] == 0:
			continue
		X = x.copy()
		for j in range(0, i + 1):
			if y - j >= 0:
				X.insert(y - j, '0')
			else:
				break
		Sum += int(''.join(X)) * b[i]
	return Sum

def right(x, b):
	Sum = 0
	y = len(x)
	for i in range(0, 10):
		if b[i] == 0:
			continue
		X = x.copy()
		for j in range(0, i + 1):
			if y - j - 1 >= 0:
				X.insert(y - j - 1, '0')
			else:
				break
		Sum += int(''.join(X)) * b[i]
	return Sum
for x in a:
	Ans += left(x, b)
	Ans += right(x, b)
print(Ans % 998244353)


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 collections import Counter
_MODER = 998244353

def solve(n, a):
	r = 0
	c = Counter()
	for e in a:
		c[len(str(e))] += 1
	for e in a:
		s = str(e)
		current_len = len(s)
		for (k, v) in list(c.items()):
			if k >= current_len:
				ns = '0'.join(list(s)) + '0'
			else:
				ns = s[:current_len - k] + '0'.join(list(s[current_len - k:])) + '0'
			r = (r + int(ns) * v % _MODER) % _MODER
			if k >= current_len - 1:
				ns = '0'.join(list(s))
			else:
				ns = s[:current_len - k - 1] + '0'.join(list(s[current_len - k - 1:]))
			r = (r + int(ns) * v % _MODER) % _MODER
	return r
n = int(input())
a = list(map(int, input().split()))
r = solve(n, a)
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)


n = int(input())
mod = 998244353
ans = 0
arr = list(map(int, input().split(' ')))
counti = [0] * 11
maxi = -1
for i in range(n):
	val = len(str(arr[i]))
	counti[val] += 1
	maxi = max(maxi, val)
for i in range(n):
	x = arr[i]
	curr = str(x)
	currl = len(curr)
	for f in range(1, maxi + 1):
		currc = counti[f]
		req1 = curr[0]
		if currc == 0:
			continue
		if f >= currl:
			tmp = 0
			for j in range(1, len(curr)):
				req1 += '0'
				req1 += curr[j]
			req2 = req1 + '0'
		else:
			posl = currl - f
			req1 = ''
			for j in range(0, posl):
				req1 += curr[j]
			req2 = req1
			req1 += curr[posl]
			for j in range(posl + 1, len(curr)):
				req1 += '0'
				req1 += curr[j]
			req1 += '0'
			for j in range(posl, len(curr)):
				req2 += '0'
				req2 += curr[j]
		v1 = int(req2)
		v2 = int(req1)
		v1 = v1 % mod * (currc % mod) % mod
		v2 = v2 % mod * (currc % mod) % mod
		ans = (ans % mod + v1 % mod) % mod
		ans = (ans % mod + v2 % mod) % mod
print(ans)


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)


n = int(input())
a = list(map(str, input().split()))
sizes = [0] * 10
MOD = 998244353
for i in range(n):
	sizes[len(a[i]) - 1] += 1
dp = [0] * 10
for i in range(10):
	for j in range(10):
		if i <= j:
			dp[i] = (dp[i] + 11 * sizes[j] * 10 ** i % MOD * 10 ** i) % MOD
		else:
			dp[i] = (dp[i] + 20 * sizes[j] * 10 ** i % MOD * 10 ** j) % MOD
ans = 0
for i in range(n):
	for j in range(len(a[i])):
		l = len(a[i]) - j - 1
		ans = (ans + dp[l] * int(a[i][j])) % MOD
print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
threading.stack_size(10 ** 8)
sys.setrecursionlimit(300000)
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 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
modulo = 998244353
from collections import Counter

def conv(x):
	res = 0
	for v in x:
		res = (res * 100 + int(v)) % modulo
	return res
n = int(input())
x = list(input().split())
c = Counter((len(v) for v in x))
res = 0
for v in x:
	u = len(v)
	for (w, k) in c.items():
		if w >= u:
			res += k * 11 * conv(v)
		else:
			d = u - w
			res += k * 11 * conv(v[d:])
			res += k * 2 * int(v[:d]) * 10 ** (2 * w)
	res %= modulo
print(res)


mod = 998244353
s = 0
input()
d = [0] * 11

def get(n, l, i):
	if l < i:
		return (n, d[i] * 11 * (int(n) % mod) % mod)
	t = int(n) % mod * 10 % mod
	n = n[:-(2 * i - 1)] + '0' + n[-(2 * i - 1):]
	return (n, d[i] * (t + int(n) % mod) % mod % mod)
l = input().split()
for i in l:
	d[len(i)] += 1
for i in l:
	n = i
	x = len(n)
	for j in range(1, 11):
		(n, tmp) = get(n, x, j)
		s = (s + tmp) % mod
print(s)


n = int(input())
x = input()
x = [i for i in x.split()]
length = {}
for i in x:
	if len(i) not in length:
		length[len(i)] = 1
	else:
		length[len(i)] = length[len(i)] + 1
dict = {}
ans = 0
for i in range(n):
	l = ''
	r = ''
	for j in range(1, 11):
		num = x[i]
		extra = ''
		if len(num) > j:
			extra = num[0:len(num) - j]
		if len(num) - j >= 0:
			l = '0' + num[len(num) - j] + l
			r = num[len(num) - j] + '0' + r
		le = extra + l
		re = extra + r
		if j in length:
			ans += int(le) * length[j]
			ans += int(re) * length[j]
print(ans % 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()