Periodic AP

5

1 votes
Easy
Problem

Nissy likes Arithmetic Progression. He sees an array of integers a1,a2,...,an of length n. He wants to find all values of x satisfying these conditions:

  • x occurs in the array

  • Consider the positions/indices of occurrence of number x in the array and on sorting these positions/indices in the ascending order, they must form an arithmetic progression.

But Nissy can’t find them all on his own. He needs your help in finding them.

Input Format:

First Line: An integer n

The next line contains integers a1,a2,...,an  separated by spaces.

Output Format:

In the first line print an integer t = the total number of valid x.

On each of the next t lines print two space-separated integers x  and dx, where x is the value and dx is the common difference between the positions/indices of occurrences in the progression(if x occurs exactly once in the sequence, dx must equal 0). Print the pairs in the order of increasing x.

Constraints:

1n105

1ai105

Sample Input
8
1 2 1 3 1 3 1 5
Sample Output
4
1 2
2 0
3 2
5 0
Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?