#include <bits/stdc++.h>
template <class t>
inline void read(t &s) {
  s = 0;
  register long long f = 1;
  register char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  s *= f;
  return;
}
template <class t, class... A>
inline void read(t &x, A &...a) {
  read(x);
  read(a...);
}
template <class t>
inline void write(t x) {
  if (x < 0) putchar('-'), x = -x;
  long long buf[21], top = 0;
  while (x) buf[++top] = x % 10, x /= 10;
  if (!top) buf[++top] = 0;
  while (top) putchar(buf[top--] ^ '0');
  return;
}
inline void setIn(std::string s) {
  freopen(s.c_str(), "r", stdin);
  return;
}
inline void setOut(std::string s) {
  freopen(s.c_str(), "w", stdout);
  return;
}
inline void setIO(std::string s = "") {
  setIn(s + ".in");
  setOut(s + ".out");
  return;
}
template <class t>
inline bool ckmin(t &x, t y) {
  if (x > y) {
    x = y;
    return 1;
  }
  return 0;
}
template <class t>
inline bool ckmax(t &x, t y) {
  if (x < y) {
    x = y;
    return 1;
  }
  return 0;
}
inline long long lowbit(long long x) { return x & (-x); }
const long long MaxN = 1e6 + 50;
const long long p = 1e9 + 7;
long long g[MaxN], a[MaxN];
signed main(void) {
  long long n;
  read(n);
  for (long long i = 1; i <= n; ++i) read(a[i]), --a[i];
  for (long long i = 2; i <= n; ++i)
    g[i] = (g[i - 1] * std::min(std::min(a[i], a[i - 1]), a[i - 2]) % p +
            std::min(a[i], a[i - 1])) %
           p;
  register long long ans = 0;
  for (long long i = 1; i <= n; ++i)
    (ans += a[i] + std::min(a[i], a[i - 1]) * (g[i]) % p) %= p;
  write(ans), std::puts("");
  return 0;
}
