Unfortunately we were unable to fully decode your file, as it is not encoded in UTF-8. You can try to decode it yourself by downloading it here.
  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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <map> 
#include <string>
#include <vector>  
#include <iostream> 
#include <sstream> 
#include <queue>
#include <algorithm>

using namespace std;
 
#define ll long long
#define PB 		push_back
#define FOR(a,start,end) 	for(int a=int(start); a<int(end); a++)
#define INF 		INT_MAX
#define SORT(a) 	sort(a.begin(),a.end()) 
#define CL(a,x) 		memset(a,x,sizeof(a))
#define REP(a,x)	for(int a=0;a<x;a++)
#define REP1(a,x)	for(int a=1;a<=x;a++)
#define MP 		make_pair

 
 
typedef vector<int>     vi;
typedef pair<int,int>     pii; 
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vector<int> > vvi;
typedef vector<vector<string> > vvs;
typedef vector<pair<string,string> > vss;
typedef pair<string,string> pss; 
typedef pair<int,pii> ppii;
typedef vector<ppii> vppii;
typedef vector<vector<pii> > vvii;
typedef vector<vvi> vvvi;


ll k1,k2;
int w,i0,i,j,k,n,a,i2;
int z,c,d,t,z1,n0;
int m,b; 
int cas,g,ng,p,np;
int a1,a2,b1,b2;

vi vn,vk,va,vc,vb; 
vii vx;
vppii vp,vd;
vvi vvk,vvp;	
pii p1,p2,p0; 
int ta[100],tk[100];

pii dru(int i0, int i2){
	int kmin,i,j,i1,i3;
	ll z1max,z2max;
	pii p2,p3;

	if(i0>i2)
		return MP(0,1);
	else if(i0==i2){
		if(vx[i0].first==1)
			return MP(1,1);
		else
			return MP(0,0);
	}
	kmin=0;
	
	j=i0;
	for(i=i0;i<=i2;i++){
		if(vx[i].first>kmin){
			kmin=vx[i].first;
			j=i;
		}
	}
	i1=max(i0,j-kmin+1);
	i3=min(i2,j+kmin-1);
	for(i=j-1;i>=max(i0,j-kmin+1);i--){
		if(vx[i].first>kmin||vx[i].second<kmin){
			i1=i+1;
			break;
		}
	}
	for(i=j+1;i<=min(i2,j+kmin-1);i++){
		if(vx[i].first>kmin||vx[i].second<kmin){
			i3=i-1;
			break;
		}
	}
	if(i3-i1+1<kmin)
		return MP(0,0);
	
	z1max=0;
	z2max=1;
	for(i=i1;i<=i3-kmin+1;i++){
		p2=dru(i0,i-1);
		p3=dru(i+kmin,i3);
		if((ll)(p2.first+p3.first)>z1max){
			z1max=(ll)(p2.first+p3.first);
			z2max=((ll)p2.second*(ll)p3.second)%d;
		}
		else if((z1max!=0)&&((ll)(p2.first+p3.first)==z1max)){
			//z1max=(ll)(p2.first+p3.first);
			z2max+=((ll)p2.second*(ll)p3.second)%d;
			z2max%=d;
		}
	}
	z1max++;
	return MP((int)z1max,(int)z2max);
	 
}


int main() {  
//	freopen( "c:\\wojtek\\uva\\pa\\debug\\t2.in", "rt", stdin);  
	//	int czas=clock();
	//pi=2*acos(0.0);
	  
	//scanf("%ld",&t);
	//cin>>t;
	//for(cas=0;cas<t;cas++){
	cin>>n;
	d=1000000007;
	vx.clear();
	
	for(i=0;i<n;i++){
		cin>>a1>>b1;
		vx.push_back(MP(a1,b1));
			
	}
		//dzielimy na przedzia�y 1/1
	vk.clear();
	for(i=0;i<n;i++){
		if(vx[i].first==1&&vx[i].second==1)
			vk.push_back(i);
	}
	i0=0;
	k1=vk.size();
	k2=1;
	if(k1>0){
		for(i=0;i<vk.size();i++){
			p1=dru(i0,vk[i]-1);
			k1+=p1.first;
			k2*=(ll)p1.second;
			k2%=d;
			i0=vk[i]+1;
		}
		p1=dru(i0,n-1);
		k1+=p1.first;
		k2*=(ll)p1.second;
		k2%=d;
		

	}
	else {
		p1=dru(0,n-1);
		k1+=p1.first;
		k2*=(ll)p1.second;
		k2%=d;
	}


	if(k2<=0)
		cout<<"NIE"<<endl;
	else {
		
		cout<<k1<<" "<<k2<<endl;
	}

	
	

	

	//czas = clock() - czas;
	//printf("%lf\n",double(czas)/CLOCKS_PER_SEC);					

			
	return 0;
	 
}