✅ Java
\nclass Pair{\n    int arrive;\n    int depart;\n    Pair(int arrive,int depart){\n        this.arrive=arrive;\n        this.depart=depart;\n    }\n}\nclass Sol
```\nclass Pair{\n    int arrive;\n    int depart;\n    Pair(int arrive,int depart){\n        this.arrive=arrive;\n        this.depart=depart;\n    }\n}\nclass Solution {\n    public int pow(int a, int b, int m){\n        if(b==0)\n            return 1;\n        if(b==1)\n            return a;\n        Long res=new Long(pow(a,b/2,m));\n        res=(res*res)%m;\n        if(b%2==1){\n            res=(res*a)%m;\n        }\n        return res.intValue();\n    }\n    public int countWays(int[][] ranges) {\n        List<Pair> store=new ArrayList<>();\n        for(int i=0;i<ranges.length;i++){\n            store.add(new Pair(ranges[i][0],ranges[i][1]));\n        }\n        Collections.sort(store,(a,b)->a.arrive-b.arrive);\n        List<Pair> ans=new ArrayList<>();\n        int arrived=store.get(0).arrive;\n        int departed=store.get(0).depart;\n        for(Pair p:store){\n            if(departed>=p.arrive){\n                arrived=Math.min(arrived,p.arrive);\n                departed=Math.max(departed,p.depart);\n            }\n            else{\n                ans.add(new Pair(arrived,departed));\n                arrived=p.arrive;\n                departed=p.depart;\n            }\n        }\n        ans.add(new Pair(arrived,departed));\n        int arr[][]=new int[ans.size()][2];\n        int k=0;\n        for(Pair x: ans){\n            arr[k][0]=x.arrive;\n            arr[k][1]=x.depart;\n            k++;\n        }\n        return pow(2,arr.length,(int)(1e9+7));\n    }\n}\n```\n![image](https://assets.leetcode.com/users/images/62416d0f-a315-4371-ae96-0cee5c2d3812_1677945830.9658315.jpeg)\n
['Java']