#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
struct P {
	int pos, v;
}p[maxn];
bool cmp(P a, P b) {
	return a.v > b.v;
}
vector<int> pos;
ll qpow(ll a, ll b) {
	ll fac = a;
	ll ans = 1;
	while (b) {
		if (b & 1) ans = ans * fac%mod;
		fac = fac * fac%mod;
		b /= 2;
	}
	return ans;
}
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &p[i].pos, &p[i].v);
		pos.push_back(p[i].pos);
	}
	sort(p, p + n, cmp);
	sort(pos.begin(), pos.end());
	int rec = 0;
	while (pos.size()&&pos.back() == p[rec].pos) {
		rec++;
		pos.pop_back();
	}
	//cout << rec << endl;
	if (rec == n) cout << 1 << endl;
	else cout << 3 * qpow(2, n - rec - 2) % mod << endl;
	
}