#include <bits/stdc++.h>
using namespace std;
void func(void) {
  freopen("input.c", "r", stdin);
  freopen("output.c", "w", stdout);
}
void print(vector<long long> &v) {
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) {
    printf("%lld ", v[i]);
  }
  printf("\n");
}
void print(vector<pair<long long, long long> > &v) {
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) {
    printf("%lld %lld\n", v[i].first, v[i].second);
  }
}
void print(double d) { cout << fixed << setprecision(10) << d << endl; }
void print(string s, double d) {
  cout << s << " ";
  cout << fixed << setprecision(10) << d << endl;
}
const int N = 1e5 + 100;
const int N1 = 1e6 + 100;
long long a[N1];
long long v[N];
long long cpy[N];
long long tree[N];
long long query(int idx) {
  long long sum = 0;
  while (idx > 0) {
    sum += tree[idx];
    sum %= 1000000007;
    idx -= idx & (-idx);
  }
  return sum;
}
void update(int idx, int x, int n) {
  while (idx <= n) {
    tree[idx] += x;
    tree[idx] %= 1000000007;
    idx += idx & (-idx);
  }
}
long long getAns(long long x, long long y) {
  long long up = query(y);
  long long down = query(x - 1);
  return (up - down + 1000000007) % 1000000007;
}
map<long long, long long> m;
int main() {
  long long n, q, i, j = 0, temp, t, k, ans = 0, sum = 0, x, y, z, cnt = 0,
                     fg = 0, mx = 0, mx1 = 0, mn = 8000000000000000000,
                     mn1 = 8000000000000000000;
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &v[i]);
    cpy[i] = v[i];
  }
  sort(cpy + 1, cpy + 1 + n);
  for (int i = 1; i <= n; i++) {
    m[cpy[i]] = i;
  }
  for (int i = n; i > 0; i--) {
    temp = getAns(m[v[i]], n);
    temp *= v[i];
    temp %= 1000000007;
    temp += v[i];
    temp %= 1000000007;
    temp -= a[v[i]];
    temp += 1000000007;
    temp %= 1000000007;
    a[v[i]] += temp;
    a[v[i]] %= 1000000007;
    update(m[v[i]], temp, n);
    m[v[i]]--;
    ans += temp;
    ans %= 1000000007;
  }
  cout << ans << endl;
}
