MOD = 998244353 def main(): import sys N, *rest = list(map(int, sys.stdin.read().split())) A = rest[:N] A.sort() max_val = A[-1] others = A[:-1] total = 0 from itertools import combinations # Generate all subsets of others that can be part of S (including none) # S must include max_val (which is handled by the structure) # Iterate over all possible subsets of others to include in S (max_val is always included) for k in range(0, len(others)+1): for subset in combinations(others, k): S = list(subset) + [max_val] S_sorted = sorted(S) T = [] for x in others: if x not in subset: T.append(x) T_sorted = sorted(T, reverse=True) if not T_sorted: seq = S_sorted else: seq = S_sorted + T_sorted danger = 0 for i in range(len(seq)-1): diff = abs(seq[i] - seq[i+1]) if diff > danger: danger = diff total += danger print(total % MOD) if __name__ == "__main__": main()