Pearls in a Row

There are n pearls in a row. Let’s enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type a i.

Let’s call a sequence of consecutive pearls a segment. Let’s call a segment good if it contains two pearls of the same type.

Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.

As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.

Input

The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row.

The second line contains n integers a i (1 ≤ a i ≤ 109) – the type of the i-th pearl.

Output

On the first line print integer k — the maximal number of segments in a partition of the row.

Each of the next k lines should contain two integers l j, r j (1 ≤ l j ≤ r j ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment.

Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type.

If there are several optimal solutions print any of them. You can print the segments in any order.

If there are no correct partitions of the row print the number “-1”.

Examples

input

5
1 2 3 4 1

output

1
1 5

input

5
1 2 3 4 5

output

-1

input

7
1 2 1 3 1 2 1

output

2
1 3
4 7

Solution:

#include <bits/stdc++.h>

using namespace std;

const int N = 1234567;

int a[N], x[N], y[N];

int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  set <int> used;
int cnt = 0;
int from = 0;
for (int i = 0; i < n; i++) {
    if (used.find(a[i]) != used.end()) {
      x[cnt] = from;
      y[cnt] = i;
      cnt++;
      used.clear();
      from = i + 1;
    } else {
      used.insert(a[i]);
    }
  }
  if (cnt == 0) {
    printf("%d\n", -1);
    return 0;
  }
  y[cnt - 1] = n - 1;
  printf("%d\n", cnt);
  for (int i = 0; i < cnt; i++) {
    printf("%d %d\n", 1 + x[i], 1 + y[i]);
  }
  return 0;
}