import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] sa = br.readLine().split(" "); List> list = new ArrayList<>(20); for (int i = 0; i < 20; i++) { list.add(new ArrayList<>()); } for (int i = 0; i < n; i++) { list.get(sa[i].length()).add(sa[i]); } br.close(); int[] size = new int[20]; for (int i = 0; i < 20; i++) { size[i] = list.get(i).size(); Collections.sort(list.get(i)); } int mod = 998244353; StringBuilder sb = new StringBuilder(); int[] idx = new int[20]; for (int i = 0; i < n - 1; i++) { String min = "999999999999999999999"; int minj = 0; for (int j = 1; j < 20; j++) { for (int j2 = 1; j2 < 20; j2++) { if (idx[j] >= size[j]) { continue; } if (j == j2) { if (idx[j] + 1 < size[j]) { String s = list.get(j).get(idx[j]) + list.get(j).get(idx[j] + 1); if (s.compareTo(min) < 0) { min = s; minj = j; } } } else { if (idx[j2] < size[j2]) { String s = list.get(j).get(idx[j]) + list.get(j2).get(idx[j2]); if (s.compareTo(min) < 0) { min = s; minj = j; } } } } } sb.append(list.get(minj).get(idx[minj])); idx[minj]++; } for (int j = 1; j < 20; j++) { if (idx[j] < size[j]) { sb.append(list.get(j).get(idx[j])); break; } } long ans = 0; for (int i = 0; i < sb.length(); i++) { int d = sb.charAt(i) - '0'; ans *= 10; ans += d; ans %= mod; } System.out.println(ans); } }