class Bit: #0-indexed def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): i += 1 s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): i += 1 while i <= self.size: self.tree[i] += x i += i & -i MOD = 10 ** 9 + 7 compress = lambda arr: {e: i for i, e in enumerate(sorted(set(arr)))} n = int(input()) a = list(map(int, input().split())) c = compress(a) b = [0] * n for i in range(n): b[i] = c[a[i]] fw = Bit(n) x1 = [0] * n x2 = [0] * n for i in range(n): fw.add(b[i], pow(2, i, MOD)) x1[i] = fw.sum(b[i] - 1) x2[i] = fw.sum(n - 1) - fw.sum(b[i]) fw = Bit(n) y1 = [0] * n y2 = [0] * n for i in range(n - 1, -1, -1): fw.add(b[i], pow(2, n - i - 1, MOD)) y1[i] = fw.sum(b[i] - 1) y2[i] = fw.sum(n - 1) - fw.sum(b[i]) ans = 0 for i in range(n): ans += x1[i] * y1[i] + x2[i] * y2[i] print(ans % MOD)