There are famous Russian nesting dolls named matryoshkas sold in one of the souvenir stores nearby, and you'd like to buy several of them. The store has n different matryoshkas. Any matryoshka is a figure of volume out_i with an empty space inside of volume in_i (of course, out_i > in_i).

You don't have much free space inside your bag, but, fortunately, you know that matryoshkas can be nested one inside another. Formally, let's call a set of matryoshkas nested if we can rearrange dolls in such a way, that the first doll can be nested inside the second one, the second doll — inside the third one and so on. Matryoshka i can be nested inside matryoshka j if out_i ≤ in_j. So only the last doll will take space inside your bag.

Let's call extra space of a nested set of dolls as a total volume of empty space inside this structure. Obviously, it's equal to in_{i_1} + (in_{i_2} - out_{i_1}) + (in_{i_3} - out_{i_2}) + ... + (in_{i_k} - out_{i_{k-1}}), where i_1, i_2, ..., i_k are the indices of the chosen dolls in the order they are nested in each other.

Finally, let's call a nested subset of the given sequence as big enough if there isn't any doll from the sequence that can be added to the nested subset without breaking its nested property.

You want to buy many matryoshkas, so you should choose a big enough nested subset to buy it. But you will be disappointed if too much space in your bag will be wasted, so you want to choose a big enough subset so that its extra space is minimum possible among all big enough subsets. Now you wonder, how many different nested subsets meet these conditions (they are big enough, and there is no big enough subset such that its extra space is less than the extra space of the chosen subset). Two subsets are considered different if there exists at least one index i such that one of the subsets contains the i-th doll, and another subset doesn't.

Since the answer can be large, print it modulo 10^9 + 7.

Input

The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of matryoshkas.

The next n lines contain a description of each doll: two integers out_i and in_i (1 ≤ in_i < out_i ≤ 10^9) — the outer and inners volumes of the i-th matryoshka.

Output

Print one integer — the number of big enough nested subsets such that extra space of each of these subsets is minimum possible. Since the answer can be large, print it modulo 10^9 + 7.

Example

Input


7
4 1
4 2
4 2
2 1
5 4
6 4
3 2


Output


6

Note

There are 6 big enough nested subsets with minimum possible extra space in the example: 

  * \{1, 5\}: we can't add any other matryoshka and keep it nested; it's extra space is 1; 
  * \{1, 6\}; 
  * \{2, 4, 5\}; 
  * \{2, 4, 6\}; 
  * \{3, 4, 5\}; 
  * \{3, 4, 6\}. 



There are no more "good" subsets because, for example, subset \{6, 7\} is not big enough (we can add the 4-th matryoshka to it) or subset \{4, 6, 7\} has extra space equal to 2.
/**
 * Created by Aminul on 7/23/2019.
 */

import org.omg.CORBA.INTERNAL;
import sun.reflect.generics.tree.Tree;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

import static java.lang.Math.*;

public class E_3 {
    static final long mod = (long) 1e9 + 7, inf = (long)2e9;
    public static void main(String[] args) throws Exception {
        FastReader in = new FastReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = in.nextInt();
        Pair[] pairs = new Pair[n];
        long minOut = Long.MAX_VALUE, maxIn = 0;
        TreeSet<Integer> set = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            int out = in.nextInt(), inn = in.nextInt();
            set.add(inn);
            set.add(out);
            pairs[i] = new Pair(inn, out);
            minOut = min(minOut, out);
            maxIn = max(maxIn, inn);
        }
        int N = set.size(), idx = 1;
        HashMap<Integer, Integer> map = new HashMap<>();
        for(int i : set) {
            map.put(i, idx++);
        }
        SegTree segTree = new SegTree(N);
        Arrays.sort(pairs);
        for (int i = n - 1; i >= 0; i--) {
            int x = pairs[i].in, out = pairs[i].out;
            int Xorg = map.get(x), Yorg = map.get(out);
            if (out > maxIn) {
                Node tmp = segTree.query(Xorg, Xorg);
                if(tmp.cost == inf)  {
                    tmp.cost = x;
                    tmp.count = 0;
                }
                tmp.count++;
                segTree.update(Xorg, tmp);
               // debug(i, pairs[i], Xorg, tmp);
            } else {
                Node ceilVal = segTree.query(Yorg, N);
                ceilVal.cost += (x - out);
                Node tmp = segTree.query(Xorg, Xorg);
                //if(tmp.cost == inf) tmp.count = 0;
                if (tmp == null || tmp.cost == inf || tmp.cost > ceilVal.cost) tmp = ceilVal;
                else if (tmp.cost == ceilVal.cost) {
                    tmp.count += ceilVal.count;
                    if (tmp.count >= mod) tmp.count -= mod;
                }
               // debug(i, pairs[i], Xorg, tmp, ceilVal);
                segTree.update(Xorg, tmp);
            }
            //debug(pairs[i],  " ", map);
        }

        long minCost = Long.MAX_VALUE, cnt = 0, last = 0;
        for (int i = 0; i < n; i++) {
            int x = pairs[i].in, out = pairs[i].out;
            if(x <= last) continue;
            last = x;
            int Xorg = map.get(x), Yorg = map.get(out);
            if (x >= minOut) {
                break;
            }
            Node tmp = segTree.query(Xorg, Xorg);
            if (tmp.cost == minCost) {
                cnt += tmp.count;
                if (cnt >= mod) cnt -= mod;
                //debug(tmp, cnt);
            } else if (tmp.cost < minCost) {
                minCost = tmp.cost;
                cnt = tmp.count;
            }
        }

        pw.println(cnt);
        pw.close();
    }


    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class Node {
        long cost, count;

        Node() {

        }

        Node(long Cost, long Count) {
            cost = Cost;
            count = Count;
        }

        void setValues(long Cost, long Count) {
            cost = Cost;
            count = Count;
        }

        @Override
        public String toString() {
            return cost + " " + count;
        }

        Node copy() {
            return new Node(cost, count);
        }
    }

    static class Pair implements Comparable<Pair> {
        int in, out;

        Pair(int IN, int OUT) {
            in = IN;
            out = OUT;
        }

        public int compareTo(Pair p) {
            if (in == p.in) return out - p.out;
            return in - p.in;
        }

        public String toString() {
            return in + " " + out;
        }
    }

    static int arr[];
    static class SegTree{
        int n ;
        Node seg[];
        int DEFAULT_VALUE = 0; // change here
        SegTree(int N){
            n = N;
            seg = new Node[4*n];
            for (int i = 0; i < seg.length; i++) {
                seg[i] = new Node((int)2e9, 0);
            }
        }

        void update(int pos, Node val){
            update(1, 1, n, pos, val);
        }
        void update(int p, int s, int e, int pos, Node val){
            if(s == pos && e == pos){
                seg[p] = val;
                return;
            }
            if(s > pos || s > e || e < pos) return;
            int m = (s+e)/2, l = 2*p, r = 2*p+1;
            update(l, s, m, pos, val);
            update(r, m+1, e, pos, val);
            if(seg[p] == null) seg[p] = new Node();
            if(seg[l].cost == seg[r].cost) {
                seg[p].cost = seg[l].cost;
                seg[p].count = seg[l].count + seg[r].count;
                if(seg[p].count >= mod) {
                    seg[p].count -= mod;
                }
            } else if(seg[l].cost < seg[r].cost) seg[p].setValues(seg[l].cost, seg[l].count);
            else seg[p].setValues(seg[r].cost, seg[r].count);
        }

        Node query(int l, int r){
            return query(1, 1, n, l, r);
        }

        Node query(int p, int s, int e, int a, int b){
            if(s >= a && e <= b){
                if(seg[p] == null) return null;
                return seg[p].copy();
            }
            if(s > e || s > b || e < a) return null;
            int m = (s+e)/2, l = 2*p, r = 2*p+1;
            Node x = query(l, s, m, a, b), y = query(r, m+1,e , a, b);
            if(x == null) return y;
            if(y == null) return x;
            if(x.cost < y.cost) return x;
            if(y.cost < x.cost) return y;
            x.count += y.count;
            if(x.count >= mod) x.count -= mod;
            return x;

        }
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            this.is = is;
        }

        public int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }

        public String next() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while (!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }


        public String nextLine() {
            int c = skip();
            StringBuilder sb = new StringBuilder();
            while (!isEndOfLine(c)) {
                sb.appendCodePoint(c);
                c = readByte();
            }
            return sb.toString();
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public char[] next(int n) {
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }

        public char readChar() {
            return (char) skip();
        }
    }
}