#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
const int N = 1e6 + 10, mod = 1e7 + 7;
int a[N], n;
int count(int l, int r)
{
if (l == r) return 0;
int s = 0;
int num = r - l + 1;
for (int i = 1; i <= r - l + 1; i ++ )
{
int cnt = (LL)(num + num - i + 1) * i / 2 % mod;
cnt = cnt - (0 + i - 1) * i / 2 % mod;
s = (s + (LL) cnt * a[l + i - 1] % mod) % mod;
}
return s;
}
int main()
{
cin >> n;
for (int i = 0; i < n; i ++ ) cin >> a[i];
int ans = 0;
int i = 0, j = 0;
while (i < n)
{
while (i + 1 < n && a[i] == a[i + 1]) i ++;
j = i;
while (j + 1 < n && a[j] != a[j + 1]) j ++;
// cout << i << ' ' << j << endl;
ans = (ans + count(i, j)) % mod;
i = j + 1;
}
cout << ans;
return 0;
}