#include using namespace std; #define all(v) v.begin(),v.end() const int inf=2e9; const int MD=1e9+7; int main(){cin.tie(0);ios::sync_with_stdio(false); int N;cin>>N; vectordp1={-inf}; vector>dp2={{inf,-inf}}; vector>dp4={{0,1}}; for(int _=0;_>A; int x=lower_bound(all(dp1),A)-dp1.begin(); if(x==dp1.size()){ dp1.push_back(A); dp2.push_back({inf}); dp4.push_back({0}); }else{ dp1[x]=A; } dp2[x].push_back(A); int y=upper_bound(all(dp2[x-1]),A,greater())-dp2[x-1].begin()-1; dp4[x].push_back((dp4[x].back()+dp4[x-1].back()-dp4[x-1][y]+MD)%MD); } cout<