P3970
#include<bits/stdc++.h>
#define lowbit(i) i&(-i)
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;
int n, a[N], b[N], c[N], tr[N], p[N] = {1}, ans, las[N];
int query(int x) {
int sum = 0;
for(int i = x; i; i -= lowbit(i)) sum += tr[i];
return sum;
}
void update(int x) {
for(int i = x;i <= n;i += lowbit(i)) ++tr[i];
}
int main () {
for(int i = 1;i <= 1e5;++i) p[i] = p[i-1]*2%mod;
scanf("%d", &n);
for(int i = 1;i <= n;++i) scanf("%d", a+i), b[i] = a[i];
sort(b+1, b+n+1);
for(int i = 1;i <= n;++i) c[i] = lower_bound(b+1, b+n+1, a[i])-b;
for(int i = 1;i <= n;++i) {
int x = query(c[i]-1);
ans = (ans + p[max(0, x-las[c[i]])] - 1) % mod;
las[c[i]] = max(las[c[i]], x);
if(!(query(c[i])-query(c[i]-1))) update(c[i]);
}
printf("%d", ans);
return 0;
}