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
#include <cstdio>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <set>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

const int INF = 1 << 30;
const double EPS = 1e-12;

int main()
{
    int n;
    scanf("%d", &n);
    vi c(n+1,0), d(n+1,-1), ans(n+1,0);
    vector<ll> ile(n+1,0);
    ans[0]=0;
    ile[0]=1;
    ll mod=1000000007;
    for(int i=1; i<=n; i++)
    {
        scanf("%d %d", &c[i], &d[i]);
        int mini=c[i], maksi=d[i];
        for(int j=1; j<=min(i,maksi); j++)
        {
            int pocz=i-j;
            if(j>=mini)
            {
                if(ans[pocz]>=ans[i])
                {
                    ans[i]=ans[pocz]+1;
                    ile[i]=ile[pocz];
                }
                else if(ans[pocz]+1==ans[i])
                {
                    ile[i]=(ile[i]+ile[pocz])%mod;
                }
            }
            mini=max(mini, c[pocz]);
            maksi=min(maksi,d[pocz]);
            //printf("%d: ans=%d ile=%lld\n",i,ans[i],ile[i]);
        }
    }
    if(ans[n]>0) printf("%d %lld\n", ans[n], ile[n]);
    else printf("NIE\n");
}