1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <iostream>
#include <vector>

typedef long long int ll;

struct mine
{
	int from;
	int to;
	std::vector<int> pos;
	bool vis=false;
	std::vector<int> links;

	bool should_link_to(const mine& other) const
	{
		for(int other_pos:other.pos)
			if(from<=other_pos&&other_pos<=to)
				return true;
		return false;
	}

	void merge_with(const mine& other)
	{
		for(int other_pos:other.pos)
			pos.push_back(other_pos);
		if(from>other.from)
			from=other.from;
		if(to<other.to)
			to=other.to;
	}
};

int cnt;
std::vector<mine> mines;

void merge()
{
	for(int i=0;i<(int)mines.size();++i)
		for(int j=0;j<(int)mines.size();)
		{
			if(i!=j)
			{
				if(mines[i].should_link_to(mines[j])&&mines[j].should_link_to(mines[i]))
				{
					mines[i].merge_with(mines[j]);
					mines[j]=mines.back();
					mines.pop_back();
					continue;
				}
			}
			++j;
		}
}

void link()
{
	for(int i=0;i<cnt;++i)
		for(int j=0;j<cnt;++j)
			if(i!=j)
				if(mines[i].should_link_to(mines[j]))
					mines[i].links.push_back(j);
}

int marked;

void mark_rec(int i)
{
	mine& m = mines[i];
	m.vis=true;
	marked|=1<<i;
	for(int link:m.links)
		if(!mines[link].vis)
			mark_rec(link);
}

void mark(int mask)
{
	marked=0;
	for(int i=0;i<cnt;++i)
		if((mask&(1<<i))&&!mines[i].vis)
			mark_rec(i);
}

void clear()
{
	for(mine& m:mines)
		m.vis=false;
}

int main()
{
	int n;
	std::cin>>n;
	for(int i=0;i<n;++i)
	{
		int p,r;
		std::cin>>p>>r;

		mine m;
		m.from=p-r;
		m.to=p+r;
		m.pos.push_back(p);

		mines.push_back(m);
	}
	merge();
	cnt=mines.size();
	link();
	ll res=1;
	int range=1<<cnt;
	std::vector<bool> res_record(range+1,false);
	for(int i=1;i<range;++i)
	{
		mark(i);
		if(!res_record[marked])
		{
			res_record[marked]=true;
			constexpr int c_limit=1000 * 1000 * 1000 + 7;
			if(++res==c_limit)
				res=0;
		}
		clear();
	}
    std::cout<<res;
	return 0;
}