/**
 *  created: 18/04/2021, 15:08:05
**/

#include <bits/stdc++.h>

using namespace std;

const int max_n = 100111, mod = 1000000007;

int n, a[max_n], ans = 1;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    ++n;
    sort(a, a + n);
    for (int i = 1; i < n; ++i) {
        ans = 1LL * ans * (a[i] - a[i - 1] + 1) % mod;
    }
    printf("%d\n", ans);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define pa pair<long long, int>

const int mod = 998244353, i2 = mod + 1 >> 1;
int n, a[200010];
long long pow2[200010], inv2[200010], ans = 0;
vector<pa> s;

int main()
{
    scanf("%d", &n);
    pow2[0] =inv2[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        pow2[i] = (pow2[i - 1] << 1) % mod;
        inv2[i] = inv2[i - 1] * i2 % mod;
    }
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    sort(a + 1, a + 1 + n);
    s.push_back({a[1], 1});
    for (int i = 2; i <= n; i++)
        if (a[i] == a[i - 1])
            s.back().second++;
        else
            s.push_back({a[i], 1});
    long long now = 0;
    int num = 0;
    for (int i = 0; i < s.size(); i++)
    {
        (ans += s[i].first * s[i].first % mod * (pow2[s[i].second] - 1) % mod) %= mod;
        (ans += s[i].first * (pow2[s[i].second] - 1) % mod * pow2[num] % mod * now % mod) %= mod;
        num += s[i].second;
        (now += s[i].first * (pow2[s[i].second] - 1) % mod * inv2[num] % mod) %= mod;
    }
    printf("%lld\n", ans);
}