import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; 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(" "); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); } br.close(); int mod = 998244353; Map dp = new HashMap<>(); Map val = new HashMap<>(); for (int i = 0; i < n; i++) { long d1 = dp.getOrDefault(a[i], 0L); long d2 = dp.getOrDefault(a[i] - 1, 0L); long v1 = val.getOrDefault(a[i], 0L); long v2 = val.getOrDefault(a[i] - 1, 0L); dp.put(a[i], (d1 + d2 + v2) % mod); val.put(a[i], v1 + 1); } long ans = 0; for (long v : dp.values()) { ans += v; } ans %= mod; System.out.println(ans); } }