N = int(input()) A = sorted([int(a) for a in input().split()]) def calc(A): n = len(A) A = A[::-1] M = max(a - b for a, b in zip(A, A[1:])) ans = 0 prev = 0 for k in range(M, A[0] - A[-1] + 1): X = [0] S = [0] j = 0 for i, a in enumerate(A): if i == 0: continue if i == 1: X.append(1) S.append(1) continue while A[j] > a + k: j += 1 X.append((S[-1] - S[j]) % P) S.append((S[-1] + X[-1]) % P) ans = (ans + (S[-1] - prev) * k) % P prev = S[-1] return ans * 2 % P P = 998244353 print(calc(A))