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: interview

Starter code:

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):
#        print(cur, cur_head)
        if l > 0:
            ans += lens[l]*(cur+10*prev)#space_out(x,l)
            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")


#!/usr/bin/env python3
import math
import sys
from collections import Counter

MOD = 1000000007  # Facebook Hacker Cup mod

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):
  # requires a >= 1
  ret = 0
  while a:
    ret += 1
    a //= 10
  return ret


def contrib_for_digs(x, part_digs, x_is_a):
  # x: the number
  # part_digs: digits of partner
  # x_is_a: true if x is a, false if x is b
  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

  # totally heinous
  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()


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
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)


from collections import Counter

_MODER = 998244353


# split s
# def split_str(s):
#     return '0'.join(list(s)) + '0'

def solve(n, a):
    r = 0
    c = Counter()  # c[k]; number of elements whose length is k
    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()):
            # s is a
            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

            # s is b
            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)


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)

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:
    #LEN_a=len(a)

    for k in range(1,11):
        x=C[k]
        #if k==LEN_a:
        #    x-=1

        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]

#second
			
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)])#>something
			else:
				#print (i[j],k,cur,howmanyhavelengthgreater[cur]+CT[cur])
				P[k]+=int(i[j])*(howmanyhavelengthgreater[cur]+CT[cur])#>something
		cur+=1
	
		

#first
			
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])#>something
			else: P[k]+=int(i[j])*(CT[cur+1-(2*cur+1-k)])#>something
		cur+=1
	#print(P)
		


for i in range(30):
	ans = (ans+P[i]*pow(10,i,M))%M;
print (ans)

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)

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(list(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 = 998_244_353
    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)

def __starting_point():
    if len(sys.argv) > 1 and sys.argv[1] == 'True':
        IS_LOCAL = True
    main()

__starting_point()

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()

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)

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 list(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)


# s = list(map(int,input().split(" ")))

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)	





# alpha = "abcdefghijklmnopqrstuvwxyz"
prime = 998244353 
# INF = 1000_000_000

# from heapq import heappush, heappop
# from collections import defaultdict
# from math import sqrt
# from collections import deque      
# from math import gcd

n = int(input())
# arr = (map(int, input().split()))
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):
        # tmp = ans
        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
        # print("check", int(i[j]), ans, ans-tmp)
        k+=1
print(ans)

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 = "",""
		zeroth = [str(0) for _ in range(i)]
		p = 0
		while p<i:
			num1 += list_dig[p]
			num1 += zeroth[p]
			p += 1
		while p < digs:
			num1 += list_dig[p]
			p += 1
		p = 0
		while p<i:
			num2 += zeroth[p]
			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]

	for i in range(digs+1,11):
		if dig_count[i] == 0:
			continue
		num1,num2 = "",""
		zeroth = [str(0) for _ in range(i)]
		p = 0
		while p<digs:
			num1 += list_dig[p]
			num1 += zeroth[p]
			p += 1
		num1 += "0"
		p = 0
		while p<digs:
			num2 += zeroth[p]
			num2 += list_dig[p]
			p += 1
		num2 += "0"
		num1 = num1[::-1]
		num2 = num2[::-1]
		ans += (int(num1)+int(num2))*dig_count[i]

print(ans%mod)

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)

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)

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]

	for i in range(digs+1,11):
		if dig_count[i] == 0:
			continue
		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))*dig_count[i]

print(ans%mod)

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
        # print(num)
        # print("l = ", l)
        # print(r)
        le = extra + l
        re = extra + r
        # print("length = ", j)    
        # print(num)
        # print("extra l = ", l)
        # print(r)
        if j in length:
            ans += int(le)*length[j]
            ans += int(re)*length[j]
# print(ans)       
print(ans%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 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()

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])

    #less
    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]))

    #equal
    cursuml1 = 0

    for enum in d[i]:
        res = le2(enum)
        ans = (ans + curlen * 11  * res) % mod
        cursuml1 = (cursuml1+10*res)%mod

    #more
    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)