#include <bits/stdc++.h>
const int modul = 1e9 + 7;
int n;
int64_t result, calc;
int64_t height[1000005];
int add(int64_t a, int64_t b) {
  a = int64_t(a + b) % modul;
  if (a < 0) {
    a += modul;
  }
  return a;
}
int mul(int64_t a, int64_t b) { return int64_t(a * b) % modul; }
int main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  std::cin >> n;
  result = 0;
  for (int i = 1; i <= n; ++i) {
    std::cin >> height[i];
    result = add(result, height[i] - 1);
  }
  calc = 0;
  for (int i = 2; i <= n; ++i) {
    if (i > 2) {
      calc =
          mul(calc,
              std::min(std::min(height[i - 1], height[i - 2]), height[i]) - 1);
    }
    calc = add(calc, std::min(height[i], height[i - 1]) - 1);
    result = add(result, mul(calc, std::min(height[i], height[i - 1]) - 1));
  }
  std::cout << result;
  return 0;
}
