Problem:
Score : 1200 points

Problem Statement

Takahashi is an expert of Clone Jutsu, a secret art that creates copies of his body.

On a number line, there are N copies of Takahashi, numbered 1 through N.
The i-th copy is located at position X_i and starts walking with velocity V_i in the positive direction at time 0.

Kenus is a master of Transformation Jutsu, and not only can he change into a person other than himself, but he can also transform another person into someone else.

Kenus can select some of the copies of Takahashi at time 0, and transform them into copies of Aoki, another Ninja.
The walking velocity of a copy does not change when it transforms.
From then on, whenever a copy of Takahashi and a copy of Aoki are at the same coordinate, that copy of Takahashi transforms into a copy of Aoki.

Among the 2^N ways to transform some copies of Takahashi into copies of Aoki at time 0, in how many ways will all the copies of Takahashi become copies of Aoki after a sufficiently long time?
Find the count modulo 10^9+7.

Constraints

1 ≤ N ≤ 200000

1 ≤ X_i,V_i ≤ 10^9(1 ≤ i ≤ N)

X_i and V_i are integers.

All X_i are distinct.

All V_i are distinct.

Input

The input is given from Standard Input in the following format:

N
X_1 V_1
:
X_N V_N

Output

Print the number of the ways that cause all the copies of Takahashi to turn into copies of Aoki after a sufficiently long time, modulo 10^9+7.

Sample Input 1

3
2 5
6 1
3 7

Sample Output 1

6

All copies of Takahashi will turn into copies of Aoki after a sufficiently long time if Kenus transforms one of the following sets of copies of Takahashi into copies of Aoki: (2), (3), (1,2), (1,3), (2,3) and (1,2,3).

Sample Input 2

4
3 7
2 9
8 16
10 8

Sample Output 2

9

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
struct TTL{
	int x,v;
}p[200010];
const int mod=1000000007;
int L[200010],R[200010];
int f[200010],q[200010];
int lsh[600010],cnt;
int read()
{
	int ans=0;char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	while (ch>='0'&&ch<='9') ans=ans*10+ch-'0',ch=getchar();
	return ans;
}
bool cmp(TTL a,TTL b)
{
	return a.x<b.x;
}
int ycl()//左边最大 右边最小 
{
	int maxn=0,minn=2e9;
	for (int i=1;i<=n;i++)
	{
		maxn=(maxn>p[i].v)?maxn:p[i].v;
		R[i]=maxn;
		lsh[++cnt]=maxn;
	}
	for (int i=n;i>=1;i--)
	{
		minn=(minn<p[i].v)?minn:p[i].v;
		L[i]=minn;
		lsh[++cnt]=minn;
	}
///	for (int i=1;i<=n;i++)
//		printf("%d %d\n",L[i],R[i]);
}
void plu(int &a,int b)
{
	a+=b;
	if (a>=mod) a-=mod;
}
void jian(int &a,int b)
{
	a-=b;
	if (a<0) a+=mod;
}
int main()
{
	n=read();
	for (int i=1;i<=n;i++)
		p[i].x=read(),p[i].v=read(),lsh[++cnt]=p[i].v;
	sort(p+1,p+1+n,cmp);
	ycl();
	sort(lsh+1,lsh+1+cnt);
	cnt=unique(lsh+1,lsh+1+cnt)-1-lsh;
	for (int i=1;i<=n;i++)
	{
		L[i]=lower_bound(lsh+1,lsh+1+cnt,L[i])-lsh;
		R[i]=lower_bound(lsh+1,lsh+1+cnt,R[i])-lsh;
	//	printf("%d %d\n",L[i],R[i]);
	}
	int head=0,tail=1;
	int sum=1;
	L[0]=0;R[0]=0;f[0]=1;
	n++;
	L[n]=n;R[n]=n;
	for (int i=1;i<=n;i++)
	{
		while (head<tail&&L[i]>R[q[head+1]]+1)
			jian(sum,f[q[head+1]]),head++;
		f[i]=sum;
		plu(sum,f[i]);
		q[++tail]=i;
	//	cout<<sum<<endl;
	}
	printf("%d",f[n]);
}