#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<int, int> pi;

int n;
const int maxn = 2e5 + 5;
pi a[maxn];
int pre[maxn], suf[maxn];
int id[maxn], tot;

int dp[maxn];
int sum[maxn];
const int mod = 1e9 + 7;

void add(int &a, int b){
    a += b;
    if(a >= mod)
        a -= mod;
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> a[i].fi >> a[i].se;
        id[++tot] = a[i].se;
    }
    sort(a + 1, a + 1 + n);
    sort(id + 1, id + 1 + n);
    for(int i = 1;i <= n;i++){
        a[i].se = lower_bound(id + 1, id + 1 + n, a[i].se) - id;
    }
    pre[0] = 0;
    for(int i = 1;i <= n;i++){
        pre[i] = max(pre[i - 1], a[i].se);
    }
    suf[n + 1] = n + 1;
    for(int i = n;i >= 1;i--){
        suf[i] = min(suf[i + 1], a[i].se);
    }
    dp[n + 1] = 1;
    sum[n + 1] = 1;
    int j = n + 1;
    for(int i = n;i >= 1;i--){
        while(j > i and suf[j] > pre[i] + 1){
            j--;
        }
        int delta = (sum[i + 1] - sum[j + 1] + mod) % mod;
        dp[i] = delta;
        sum[i] = sum[i + 1];
        add(sum[i], dp[i]);
    }
    int ans = 0;
    for(int i = 1;i <= n;i++){
        if(suf[i] == suf[1]){
            add(ans, dp[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

### Prompt

Your task is to create a cpp solution to the following problem:

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.

Examples

Input

3
2 5
6 1
3 7


Output

6


Input

4
3 7
2 9
8 16
10 8


Output

9

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<int, int> pi;

int n;
const int maxn = 2e5 + 5;
pi a[maxn];
int pre[maxn], suf[maxn];
int id[maxn], tot;

int dp[maxn];
int sum[maxn];
const int mod = 1e9 + 7;

void add(int &a, int b){
    a += b;
    if(a >= mod)
        a -= mod;
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> a[i].fi >> a[i].se;
        id[++tot] = a[i].se;
    }
    sort(a + 1, a + 1 + n);
    sort(id + 1, id + 1 + n);
    for(int i = 1;i <= n;i++){
        a[i].se = lower_bound(id + 1, id + 1 + n, a[i].se) - id;
    }
    pre[0] = 0;
    for(int i = 1;i <= n;i++){
        pre[i] = max(pre[i - 1], a[i].se);
    }
    suf[n + 1] = n + 1;
    for(int i = n;i >= 1;i--){
        suf[i] = min(suf[i + 1], a[i].se);
    }
    dp[n + 1] = 1;
    sum[n + 1] = 1;
    int j = n + 1;
    for(int i = n;i >= 1;i--){
        while(j > i and suf[j] > pre[i] + 1){
            j--;
        }
        int delta = (sum[i + 1] - sum[j + 1] + mod) % mod;
        dp[i] = delta;
        sum[i] = sum[i + 1];
        add(sum[i], dp[i]);
    }
    int ans = 0;
    for(int i = 1;i <= n;i++){
        if(suf[i] == suf[1]){
            add(ans, dp[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

```