#P5679. Existence of Arithmetic Progression Subsequence
Existence of Arithmetic Progression Subsequence
Existence of Arithmetic Progression Subsequence
Given a sequence of positive integers of length \(N\), determine whether there exists an arithmetic subsequence of length at least three. An arithmetic progression is a sequence in which the difference between consecutive elements is constant. Formally, a subsequence \(a_{i_1}, a_{i_2}, \ldots, a_{i_k}\) (with \(1 \le i_1 < i_2 < \cdots < i_k \le N\) and \(k \ge 3\)) is an arithmetic progression if\( a_{i_2} - a_{i_1} = a_{i_3} - a_{i_2} = \cdots = a_{i_k} - a_{i_{k-1}} \).
inputFormat
The input consists of two lines. The first line contains a single integer \(N\) (the length of the sequence). The second line contains \(N\) positive integers separated by spaces representing the sequence.
outputFormat
Output a single line containing YES if there is an arithmetic subsequence of length at least three, and NO otherwise.
sample
5
1 3 5 7 9
YES