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
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cstring>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define VI vector<int>
#define PII pair<int,int>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define lint long long int
#define max_n 1000005

using namespace std;


int n;
int c[max_n];
int d[max_n];
int dist[max_n];
int sposoby[max_n];
int mod = 1e9+7;

void uzupelnij(){
	FOR(i,0,n) dist[i] = -1;
	FOR(i,0,n) sposoby[i] =0 ;
	dist[n] = 0;
	sposoby[n] = 1;
	for(int i=n-1;i>=0;i--){
		int maxc = c[i];
		int mind = d[i];
		FOR(j,i,n){
			maxc = max(c[j],maxc);
			mind = min(d[j],mind);
			if((j-i+1)>=maxc && (j-i+1)<=mind){
				if(dist[i] == dist[j+1]+1){
					sposoby[i] +=sposoby[j+1];
					sposoby[i]%=mod;
				}
				if(dist[i] < dist[j+1]+1){
					sposoby[i] = sposoby[j+1];
					dist[i] = dist[j+1]+1;
				}
			}
			if(j>mind+i-1) break;
		}
	}
}



int main(){
	scanf("%d",&n);
	FOR(i,0,n) scanf("%d%d",&c[i],&d[i]);
	uzupelnij();
	if(sposoby[0]==0) printf("NIE\n");
	else printf("%d %d\n",dist[0],sposoby[0]);
}