#include using namespace std; #define mod 1000000007 int a[200000],b[524300],x,y; void constr(int l,int h,int p) { if(l==h) { b[p]=a[l]; return; } int m=(l+h)/2; constr(l,m,2*p+1); constr(m+1,h,2*p+2); b[p]=max(b[2*p+1],b[2*p+2]); } int call(int l,int h,int p) { if(hy) return 0; if(x<=l && y>=h) return b[p]; int m=(l+h)/2,p1,p2; p1=call(l,m,2*p+1); p2=call(m+1,h,2*p+2); return(max(p1,p2)); } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ long int n,s; int i,j,k; cin>>n; double c=(n*(n+1))/2; c=(c*(c+1))/2; for(i=0;i>a[i]; s+=(a[i]%mod); c--; } constr(0,n-1,0); for(i=2;i2) { c--; s+=(call(0,n-1,0)%mod); y++; } else break; } } } x=0; y=n-1; while(c>=mod) c-=mod; i=c; s+=((i*(call(0,n-1,0)%mod))%mod); cout<