CF352B.Jeff and Periods

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

One day Jeff got hold of an integer sequence a1a_{1} , a2a_{2} , ...... , ana_{n} of length nn . The boy immediately decided to analyze the sequence. For that, he needs to find all values of xx , for which these conditions hold:

  • xx occurs in sequence aa .
  • Consider all positions of numbers xx in the sequence aa (such ii , that ai=xa_{i}=x ). These numbers, sorted in the increasing order, must form an arithmetic progression.

Help Jeff, find all xx that meet the problem conditions.

输入格式

The first line contains integer nn (1<=n<=105)(1<=n<=10^{5}) . The next line contains integers a1a_{1} , a2a_{2} , ...... , ana_{n} (1<=ai<=105)(1<=a_{i}<=10^{5}) . The numbers are separated by spaces.

输出格式

In the first line print integer tt — the number of valid xx . On each of the next tt lines print two integers xx and pxp_{x} , where xx is current suitable value, pxp_{x} is the common difference between numbers in the progression (if xx occurs exactly once in the sequence, pxp_{x} must equal 0). Print the pairs in the order of increasing xx .

输入输出样例

  • 输入#1

    1
    2
    

    输出#1

    1
    2 0
    
  • 输入#2

    8
    1 2 1 3 1 2 1 5
    

    输出#2

    4
    1 2
    2 4
    3 0
    5 0
    

说明/提示

In the first test 22 occurs exactly once in the sequence, ergo p2=0p_{2}=0 .

首页