#include <bits/stdc++.h>
using namespace std;
int t[1020304];
int n;
void ins(int x, int val) {
  for (int z = x; z <= 1000000; z += (z & -z)) t[z] = (t[z] + val) % 1000000007;
}
int Ask(int x) {
  int ret = 0;
  for (int z = x; z; z -= (z & -z)) ret = (ret + t[z]) % 1000000007;
  return ret;
}
int a[1020304], f[1020304];
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    int t = Ask(a[i]), t0 = Ask(a[i] - 1);
    int pre = (t + 1000000007 - t0) % 1000000007;
    int tA = ((long long)t0 * a[i] % 1000000007 + a[i] + 1000000007 - pre) %
             1000000007;
    int tB = (long long)pre * a[i] % 1000000007;
    f[i] = (tA + tB) % 1000000007;
    ans = (ans + f[i]) % 1000000007;
    ins(a[i], f[i]);
  }
  cout << ans << endl;
  return 0;
}
