#K81057. Arithmetic Sequence Combination Check

    ID: 35668 Type: Default 1000ms 256MiB

Arithmetic Sequence Combination Check

Arithmetic Sequence Combination Check

Given an array of integers, determine if there exists any non-trivial subset (with at least three elements) such that when the subset is sorted in increasing order, it forms an arithmetic sequence. An arithmetic sequence is one in which the difference between consecutive elements is constant.

For example, if the input array is [3, 1, 4, 5], one valid subset is [1, 3, 5] (after sorting) which is arithmetic with a common difference of 2. Your program should read input from stdin and output the result to stdout.

inputFormat

The first line contains a single integer n, representing the number of elements in the array. The second line contains n space-separated integers.

outputFormat

Output a single line containing Yes if there exists any subset of at least three numbers that forms an arithmetic sequence after sorting; otherwise, output No.## sample

4
3 1 4 5
Yes