Arithmetic Progression Subsequences (1) X57357


Statement
 

pdf   zip

Write a program that reads two integers nn and rr, both strictly greater than 11, followed by a sequence of integers, and finds out whether the sequence contains a consecutive subsequence of length at least nn that forms an arithmetic progression with step rr.

A consecutive subsequence of integers forms an arithmetic progression with step rr if the difference between two consecutive numbers equals rr. For instance, 45674 5 6 7 is an arithmetic progression with r=1r = 1, and 223344556622 33 44 55 66 is an arithmetic progression with r=11r = 11.

If the input sequence contains such a progression, the program must print a line with the first nn elements in the progression. Otherwise, the program must indicate "No arithmetic progression found with step r and length at least n".

Input

The input consists of two integers n>1n>1 and r>1r>1, followed by a sequence of integers containing at least 2 elements.

Output

If a progression subsequence with reason rr and length at least nn exists, the output are the first nn elements of the progression. Otherwise, the output is "No arithmetic progression found with step r and length at least n".

Public test cases
  • Input

    4 1
    7 1 -2 6 9 10 11 12 15
    
    

    Output

    9 10 11 12
    
  • Input

    4 1
    7 1 -2 5 6 7 8 9 12 15
    
    

    Output

    5 6 7 8
    
  • Input

    5 11
    7 1 -2 
    10 21
    32
    43 54 
    88 3 -5 -6
    
    

    Output

    10 21 32 43 54
    
  • Input

    5 3
    2 4 6 8 10 12 14 21
    
    

    Output

    No arithmetic progression found with step 3 and length at least 5
    
  • Input

    5 3
    7 1  2 5 8 11
    32 43 54 
    88 3 -5 -6
    
    

    Output

    No arithmetic progression found with step 3 and length at least 5
    
  • Information
    Author
    ProAl
    Language
    English
    Official solutions
    Python
    User solutions
    Python