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
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>

using namespace std;
const int M = 1000000007;
const int N = 1048576;

class MaxValue {
  public:
  MaxValue() {
    clean();
  }

  void clean() {
    fill_n(t_, N + N, 0);
  }

  void insert(int pos, int v) {
    pos += N;
    t_[pos] = v;
    while (pos) {
      pos /= 2;
      t_[pos] = max(t_[pos * 2], t_[pos * 2 + 1]);
    }
  }

  int get(int a, int b) {
    int ret = 0;
    a += N;
    b += N;
    while (a < b) {
      ret = max(ret, t_[a]);
      if (a + 1 < b) {
        ret = max(ret, t_[a + 1]);
      }
      a = a / 2 + 1;
      ret = max(ret, t_[b - 1]);
      b /= 2;
    }
    return ret;
  }

  private:
  int t_[N + N];
};

int r1[N];
int r2[N];
int n;
MaxValue mvc, mvd;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int c, d;
    scanf("%d%d", &c, &d);
    mvc.insert(i, c);
    mvd.insert(i, N - d);
  }
  fill_n(r1, n + 1, 0);
  fill_n(r2, n + 1, 0);
  r2[0] = 1;
  for (int i = 0; i < n; ++i) {
    if (!r2[i]) continue;
    int c = mvc.get(i, i + 1);
    int d = N - mvd.get(i, i + 1);
    for (int j = i + c; j <= n; ++j) {
      c = mvc.get(i, j);
      d = N - mvd.get(i, j);
      if (j > i + d) break;
      if (j < i + c) {
        j = i + c - 1;
        continue;
      }
      if (r1[j] == r1[i] + 1) {
        r2[j] += r2[i];
        r2[j] %= M;
      } else if (r1[j] < r1[i] + 1) {
        r1[j] = r1[i] + 1;
        r2[j] = r2[i];
      }
    }
  }
  if (r2[n]) {
    printf("%d %d\n", r1[n], r2[n]);
  } else {
    printf("NIE\n");
  }
  return 0;
}