local mod = 998244353 local function badd(x, y) return (x + y) % mod end local n = io.read("*n") local t = {} for i = 1, n do local a = io.read("*n") if t[a - 1] then v = badd(t[a - 1], 1) else v = 1 end if not t[a] then t[a] = v else t[a] = badd(t[a], v) end end local ret = mod - n for key, val in pairs(t) do ret = badd(ret, val) end print(ret)