using System; using System.Collections.Generic; namespace test { static class Program { static void Main() { long n = long.Parse(Console.ReadLine()); string[] astr = Console.ReadLine().Split(' '); long[] a = new long[n]; for(int i = 0; i < n; i++) { a[i] = long.Parse(astr[i]); } Dictionary dict = new Dictionary(); for (int i = 0; i < n; i++) { if (dict.ContainsKey(a[i] - 1)) { if (dict.ContainsKey(a[i])) { dict[a[i]] = (dict[a[i]] +dict[a[i] - 1] + 1)%998244353; } else { dict.Add(a[i], (dict[a[i] - 1] + 1)%998244353); } } else { if (dict.ContainsKey(a[i])) { dict[a[i]] = (dict[a[i]]+1)%998244353; } else { dict.Add(a[i], 1); } } } long count = 0; foreach (var item in dict) { count += item.Value; } Console.WriteLine((count - n+998244353)%998244353); } } }