#include #include #include #include using namespace std; struct rec{ int x,y,nxt; bool operator < (const rec another) const{ return y>another.y; } }b[200009],a[200009]; #define mod 1000000007 priority_queue q; int readint(){ int ch=getchar(),ret=0; while(ch<'0' || ch>'9') ch=getchar(); while(ch>='0' && ch<='9') ret=ret*10+ch-'0',ch=getchar(); return ret; } int n,m,k,ans[100009],cnt,cur,fir[100009],now[100009]; int d[100009],T; bool vis[100009]; bool cmp(rec x,rec y){ return x.y=d[i] && !vis[i]){ k-=d[i]; d[i]=0; ans[++cnt]=i; vis[i]=1; for (int j=fir[i];j;j=a[j].nxt){ q.push(a[j]); } } while(!q.empty()){ rec x=q.top(); q.pop(); while(!q.empty() && q.top().y==x.y){ if (!vis[x.y]){ d[x.y]--; } x=q.top(); q.pop(); } if (d[x.y]) d[x.y]--; if (vis[x.y] || x.y>i) continue; if (k>=d[x.y]){ k-=d[x.y]; d[x.y]=0; ans[++cnt]=x.y; vis[x.y]=true; for (int j=fir[x.y];j;j=a[j].nxt){ q.push(a[j]); } } } } long long ANS=0; for (int i=1;i<=n;i++){ ANS=(ANS+(long long)i*ans[i]) % mod; } printf("%I64d\n",ANS); } }