#include using namespace std; //*/ #include using namespace atcoder; //*/ #define rep(i,n) for(int i=0;i; using ll = long long; using ull = unsigned long long; //*/ template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } typedef pair pii; typedef pair pll; typedef vector vll; typedef vector vint; random_device rnd; mt19937 rng(rnd()); using mint = modint998244353; void solve(){ int n; cin >> n; mint ans = 0,ten = 10; vll a(n); rep(i,n) cin >> a[i]; vector s(n),t(n); rep(i,n){ ll x = a[i]; string now = ""; while(x){ char tar = '0'+ x%10; x /= 10; now = tar + now; } s[i] = now; for(char &c : now) if(c=='0') c -= 1; while(now.size() <= 18) now += '0'; t[i] = now; } vint id(n); rep(i,n) id[i] = i; sort(ALL(id),[&](int i,int j){ int zeroi = 20,zeroj = 20; rep(x,s[i].size()){ if(s[i][x] == '0'){ zeroi = x; break; } } rep(x,s[j].size()){ if(s[j][x] == '0'){ zeroj = x; break; } } rep(x,min(s.size(),t.size())){ if(x < zeroi && x < zeroj && s[i][x] != s[j][x]) return s[i] < s[j]; } if(zeroi != 20 && zeroj == 20) return true; if(zeroi == 20 && zeroj != 20) return false; if(zeroi < zeroj) return false; else if(zeroi > zeroj) return true; return t[i] < t[j]; }); rep(i,n){ ans = ans*ten.pow(s[id[i]].size())+a[id[i]]; } cout << ans.val() << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; //cin >> t; rep(dirc,t) solve(); }