CF1195D2.Submarine in the Rybinsk Sea (hard edition)
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This problem differs from the previous one only in the absence of the constraint on the equal length of all numbers a1,a2,…,an .
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(a1a2…ap−1ap,b1b2…bq−1bq) , where a1…ap and b1…bq 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 pgeq then f(a_1dotsa_p,b_1dotsb_q)=a_1a_2dotsa_p−q+1b_1a_p−q+2b_2dotsa_p−1b_q−1a_pb_q ;
- if p<q then f(a_1dotsa_p,b_1dotsb_q)=b_1b_2dotsb_q−pa_1b_q−p+1a_2dotsa_p−1b_q−1a_pb_q .
Mishanya gives you an array consisting of n integers a_i , your task is to help students to calculate sum_i=1nsum_j=1nf(a_i,a_j) modulo 998,244,353$$.
输入格式
The first line of the input contains a single integer n ( 1≤n≤100000 ) — the number of elements in the array. The second line of the input contains n integers a1,a2,…,an ( 1≤ai≤109 ) — the elements of the array.
输出格式
Print the answer modulo 998244353 .
输入输出样例
输入#1
3 12 3 45
输出#1
12330
输入#2
2 123 456
输出#2
1115598
输入#3
1 1
输出#3
11
输入#4
5 1000000000 1000000000 1000000000 1000000000 1000000000
输出#4
265359409