#include <bits/stdc++.h>
using namespace std;
long long BIT[1000005];
long long prevy[1000005];
long long N;
void add(long long val, long long x) {
  while (x <= N) {
    BIT[x] += val;
    BIT[x] %= 1000000007;
    x += (x & (-x));
  }
}
long long q(long long b) {
  long long ret = 0;
  while (b) {
    ret += BIT[b];
    ret %= 1000000007;
    b -= (b & (-b));
  }
  return ret;
}
long long n;
int main() {
  cin >> n;
  N = 1000000;
  long long x;
  for (int i = 0; i <= 1000000; ++i) {
    prevy[i] = -1;
  }
  long long temp = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> x;
    long long anse = 0;
    if (prevy[x] == -1) {
      prevy[x] = 0;
      anse += ((x * (q(x))) % 1000000007);
      anse += x;
      anse += 1000000007;
      anse %= 1000000007;
      add(1000000007 - prevy[x], x);
      prevy[x] = anse;
      add((anse + 1000000007) % 1000000007, x);
    } else {
      anse += ((x * (q(x))) % 1000000007);
      anse += x;
      anse += 1000000007;
      anse %= 1000000007;
      add(1000000007 - prevy[x], x);
      prevy[x] = anse;
      add(anse, x);
    }
    temp += anse;
    temp %= 1000000007;
  }
  cout << q(1000000);
  return 0;
}
