#include <bits/stdc++.h>
template <int Mod>
struct ModuloArithmetic {
  static int add(int x, int y) {
    long long const tmp = static_cast<long long>(x) + y;
    return (tmp > Mod) ? (tmp - Mod) : tmp;
  }
  static int mul(int x, int y) {
    long long const tmp = static_cast<long long>(x) * y;
    return tmp % Mod;
  }
};
using Modulo = ModuloArithmetic<1000000000 + 7>;
struct Column {
  int h;
  int h_partial;
  int partial;
  static Column Next(int h, Column const &prev) {
    int const h_partial = std::min(prev.h, h);
    int const h_partial_from_prev = std::min(prev.h_partial, h_partial);
    int const ones = h_partial - h_partial_from_prev + 1;
    int const fat = Modulo::mul(prev.partial, h_partial_from_prev);
    int const partial = Modulo::add(ones, fat);
    return {h, h_partial, partial};
  }
  int Total() const {
    return Modulo::add(Modulo::mul(h_partial, partial), (h - h_partial));
  }
};
int main() {
  std::cin.sync_with_stdio(false);
  int n;
  std::cin >> n;
  int possibilities = 0;
  Column prev{0, 0, 0};
  for (int i = 0; i < n; ++i) {
    int h;
    std::cin >> h;
    Column const next = Column::Next(h - 1, prev);
    possibilities = Modulo::add(possibilities, next.Total());
    prev = next;
  }
  std::cout << possibilities;
  return 0;
}
