#include <bits/stdc++.h>
namespace XX {
template <int MOD>
long long int powmod(long long int a, long long int b) {
  long long int ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return ret;
}
}  // namespace XX
namespace XX {
template <template <typename> class Compare, typename T>
inline T& UP(T& x, const T& y) {
  Compare<T>()(y, x) && (x = y);
  return x;
}
template <typename Compare, typename T>
inline T& UP(T& x, const T& y, Compare comp) {
  comp(y, x) && (x = y);
  return x;
}
template <typename T>
inline T& GT(T& x, const T& y) {
  return UP<std::greater>(x, y);
}
template <typename T>
inline T& LS(T& x, const T& y) {
  return UP<std::less>(x, y);
}
template <typename T, typename... Args>
std::array<std::reference_wrapper<T>, sizeof...(Args) + 1> MAKEV(
    T& arg1, Args&... args) {
  return {arg1, args...};
}
struct Range {
  struct It {
    int num, step;
    int operator*() { return num; }
    void operator++() { num += step; }
    bool operator!=(const It& other) { return num != other.num; }
  };
  Range(int ee) : b(0), e(ee) {}
  Range(int bb, int ee) : b(bb), e(ee) {}
  It begin() { return {b, (b < e ? 1 : -1)}; }
  It end() { return {e}; }
  int b, e;
};
}  // namespace XX
template <typename T>
struct ScanfSpecifier {};
template <>
struct ScanfSpecifier<int> {
  static constexpr const char* value = "%d";
};
template <>
struct ScanfSpecifier<double> {
  static constexpr const char* value = "%lf";
};
template <>
struct ScanfSpecifier<float> {
  static constexpr const char* value = "%f";
};
template <>
struct ScanfSpecifier<char> {
  static constexpr const char* value = " %c";
};
template <>
struct ScanfSpecifier<const char*> {
  static constexpr const char* value = "%s";
};
template <>
struct ScanfSpecifier<unsigned long> {
  static constexpr const char* value = "%lu";
};
template <>
struct ScanfSpecifier<long long int> {
  static constexpr const char* value = "%lld";
};
template <typename T>
int RD(T& arg) {
  return std::scanf(ScanfSpecifier<T>::value, &arg);
}
template <int S>
int RD(char (&arg)[S]) {
  return std::scanf("%s", arg);
}
template <>
int RD<char*>(char*& arg) {
  return std::scanf("%s", arg);
}
template <typename T, typename... Args>
int RD(T& arg1, Args&... args) {
  return RD(arg1) + RD(args...);
}
template <typename It>
void RDV(It begin, It end) {
  while (begin != end) RD(*begin++);
}
template <typename C>
void RDV(C& c) {
  RDV(std::begin(c), std::end(c));
}
template <typename... Args>
void WT(Args... args) {
  int alc = 0;
  int dummy[] = {((alc++ ? std::printf(" ") : 0),
                  std::printf(ScanfSpecifier<Args>::value, args), 0)...};
}
template <typename... Args>
void WTL(Args... args) {
  WT(args...);
  std::printf("\n");
}
template <typename It>
void WTV(It begin, It end) {
  int alc = 0;
  while (begin != end) (alc++ ? std::printf(" ") : 0), WT(*begin++);
}
template <typename C>
void WTV(const C& c) {
  WTV(std::begin(c), std::end(c));
}
template <typename It>
void WTVL(It begin, It end) {
  WTV(begin, end);
  std::printf("\n");
}
template <typename C>
void WTVL(const C& c) {
  WTVL(std::begin(c), std::end(c));
}
const int MOD = 1e9 + 7;
auto POW = XX::powmod<MOD>;
using XX::GT;
using XX::LS;
using XX::UP;
using RG = XX::Range;
using XX::MAKEV;
using namespace std;
int h[1000009];
int n;
int main() {
  RD(n);
  RDV(h, h + n);
  int ans = 0;
  ans = h[0] - 1;
  int last = h[0] - 1;
  int m = 0;
  for (int i : RG(1, n)) {
    (ans += h[i] - 1) %= MOD;
    int now = min(h[i], h[i - 1]) - 1;
    (ans += now * 1ll * now % MOD) %= MOD;
    m = m * 1ll * POW(last, MOD - 2) % MOD * (min(h[i] - 1, last)) % MOD * now %
        MOD;
    (ans += m) %= MOD;
    (m += now * 1ll * now % MOD) %= MOD;
    last = now;
  }
  WTL(ans);
}
