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: Wrong Answer)

#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
// #include <unordered_map>
// #include <unordered_set>
#include <utility>
#include <vector>

#define pb push_back
#define mp make_pair

#ifdef ONLINE_JUDGE
#define link renamelink
#define next renamenext
#define prev renameprev
#endif

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef long double ld;

inline void EnableFileIO(const string &fileName, bool local = 0) {
  if (fileName.empty()) return;
  if (local) {
    freopen((fileName + ".in").c_str(), "r", stdin);
    freopen((fileName + ".out").c_str(), "w", stdout);
    return;
  }
#ifdef ONLINE_JUDGE
  freopen((fileName + ".in").c_str(), "r", stdin);
  freopen((fileName + ".out").c_str(), "w", stdout);
#endif
}

const int INF = (1 << 30) - 1;
const LL LINF = (1LL << 61) - 1;
const double EPS = 1e-10, PI = acos(-1);
const int N = 2e5 + 100, P = 1e9 + 7;

LL qpow(LL b, LL k) {
  LL r = 1;
  while (k) {
    if (k & 1) r = r * b % P;
    b = b * b % P, k >>= 1;
  }
  return r;
}

int n;
int id[N], x[N], v[N];

inline bool compv(const int &i, const int &j) { return v[i] < v[j]; }
pii a[N], tim[N];
LL f[N], sum[N];

inline bool meet(int i, int j) {
  return (x[id[j]] - x[id[i]]) * 1LL * (v[id[i]] - v[id[j]]) >= 0;
}

int main() {
  // srand((int)time(0));
  // printf("Hello, world!\n");
  // EnableFileIO("");

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", x + i, v + i);
    id[i] = i;
  }
  sort(id, id + n, compv);

  for (int i = 0; i < n; i++) {
    int l = -1, r = i;
    while (r - l > 1) {
      int mid = (l + r) >> 1;
      if (meet(mid, i)) {
        r = mid;
      } else {
        l = mid;
      }
    }
    tim[i + 1].first = r;

    l = i, r = n;
    while (r - l > 1) {
      int mid = (l + r) >> 1;
      if (meet(mid, i)) {
        l = mid;
      } else {
        r = mid;
      }
    }
    tim[i + 1].second = l;
  }
  sort(tim + 1, tim + n + 1);

  int head = 0, pos = 0;
  f[0] = 1, sum[0] = 1;
  tim[0] = mp(-1, -1);
  for (int i = 1; i <= n; i++) {
    while (tim[head].second < tim[i].first - 1) ++head;
    f[i] = sum[i - 1] - (head ? sum[head - 1] : 0);
    sum[i] = (sum[i - 1] + f[i]) % P;
    if (tim[i].second != n - 1) pos = i;
  }
  printf("%lld\n", ((sum[n] - sum[pos]) % P + P) % P);
  return 0;
}