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, 1] S = [0, 1] j = 0 for i, a in enumerate(A): if i < 2: continue while A[j] > a + k: j += 1 X.append(S[-1] - S[j]) if X[-1] < 0: X[-1] += P S.append(S[-1] + X[-1]) if S[-1] >= P: S[-1] -= P ans = (ans + (S[-1] - prev) * k) % P prev = S[-1] return ans * 2 % P P = 998244353 print(calc(A))