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, ..., 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 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... 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 ≥ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q; 
  * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... 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 ∑_{i = 1}^{n}∑_{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 ≤ n ≤ 100 000) — the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 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
#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long int n, i, j, k;
  cin >> n;
  unsigned long long int ans = 0;
  unsigned long long int digits[12] = {0};
  unsigned long long int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    unsigned long long int x = a[i];
    unsigned long long int ct = 0;
    while (x > 0) {
      ct++;
      x /= 10;
    }
    digits[ct]++;
  }
  unsigned long long int backward[n][12];
  unsigned long long int forwardd[n][12];
  for (i = 0; i < n; i++) {
    unsigned long long int no_of_dig = 0;
    unsigned long long int y = a[i];
    while (y > 0) {
      no_of_dig++;
      y /= 10;
    }
    for (j = 0; j < no_of_dig; j++) {
      unsigned long long int temp = no_of_dig - 1 - j;
      unsigned long long int x = a[i];
      vector<unsigned long long int> v;
      while (x > 0) {
        v.push_back(x % 10);
        x /= 10;
      }
      reverse(v.begin(), v.end());
      unsigned long long int xx = 0;
      for (k = 0; k < no_of_dig; k++) {
        xx = (xx * 10) + v[k];
        xx = xx % 998244353;
        if (k != no_of_dig - 1 && k >= temp) {
          xx = (xx * 10);
        }
        xx = xx % 998244353;
      }
      backward[i][j] = xx;
      forwardd[i][j + 1] = (xx * 10) % 998244353;
    }
    for (j = no_of_dig; j < 12; j++) {
      backward[i][j] = backward[i][j - 1];
      if (j + 1 < 12) forwardd[i][j + 1] = forwardd[i][j];
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < 12; j++) {
      ans = ((ans % 998244353) + ((backward[i][j] * digits[j]) % 998244353)) %
            998244353;
    }
    for (j = 1; j < 12; j++) {
      ans = ((ans % 998244353) + ((forwardd[i][j] * digits[j]) % 998244353)) %
            998244353;
    }
  }
  cout << ans % 998244353;
}
