#include <bits/stdc++.h>

typedef long long LL;
typedef __int128 LLL;

const int N = 10;
const int MOD = 998244353;

int n;

int main() {

  scanf("%d", &n);
  std::vector<std::pair<LL, LLL>> a(n);
  for(auto &[x, y]: a) {
    scanf("%lld", &x);
    LL t = x;
    y = 1;
    while(t) {
      t /= 10;
      y *= 10;
    }
  }

  std::sort(a.begin(), a.end(), [] (const auto &s, const auto &t) {
				  auto &&[x, y] = s;
				  auto &&[p, q] = t;
				  return x * q + p < y * p + x;});

  int ans = 0;
  for(auto &&[x, y]: a)
    ans = (ans * y + x) % MOD;  
  
  printf("%d\n", ans);
  
  return 0;

}