#include <bits/stdc++.h>
using namespace std;
int n, i, a[300000], ans[300000], daan, tree[3000000];
vector<int> v[1200000];
long long MOD = 1000000000 + 7;
void insert(int i, int j) {
  while (i > 0) {
    tree[i] += j;
    tree[i] %= MOD;
    i -= i & (-i);
  }
}
int find(int i) {
  int tmp = 0;
  while (i <= n) {
    tmp = tmp + tree[i];
    tmp %= MOD;
    i += i & (-i);
  }
  return tmp;
}
int main() {
  int i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) v[a[i]].push_back(i);
  for (i = 1000000; i >= 1; i--) {
    int m = v[i].size();
    if (m == 0) continue;
    ans[m + 1] = 0;
    for (j = m; j >= 1; j--) {
      ans[j] = i + ((long long)find(v[i][j - 1] + 1) * (long long)i) % MOD;
      ans[j] %= MOD;
      ans[j] = ans[j] + ((long long)i * (long long)ans[j + 1]) % (MOD);
      ans[j] %= MOD;
    }
    if (m >= 1) daan = (daan + ans[1]) % MOD;
    for (j = 1; j <= m; j++) insert(v[i][j - 1], (ans[j] - ans[j + 1]) % MOD);
  }
  daan = (daan + MOD) % MOD;
  printf("%d", daan);
  return 0;
}
