#include using namespace std; #define ll long long #define pb push_back ll mod=1000000007; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,ao; cin>>n; vector a; ll s=0; for(int i=0;i>ao;a.pb(ao);} vector b,v; for(int k=0;k bo; bo.assign(a.begin()+i,a.begin()+j+1); sort(bo.begin(),bo.end(),greater() ); b.pb(*bo.begin()); } } } mapm; map::iterator f; int l=b.size(); for(int k=0;k() ); m[*v.begin()]++; } } } for(f=m.begin();f!=m.end();f++){ s=((s%mod)+(f->first*f->second)%mod)%mod; } cout<