#C8087. Increasing Subsequence

    ID: 52030 Type: Default 1000ms 256MiB

Increasing Subsequence

Increasing Subsequence

Given a sequence of n integers, determine whether there exists a strictly increasing subsequence of length at least 3.

A strictly increasing subsequence is a sequence of indices i, j, k such that i < j < k and a[i] < a[j] < a[k]. In mathematical notation, we require that there exist indices \( 1 \leq i < j < k \leq n \) satisfying: \[ a[i] < a[j] < a[k] \]

If such a subsequence exists, output YES; otherwise, output NO.

inputFormat

The input is given from standard input and consists of two lines:

  1. The first line contains a single integer n (\(1 \le n \le 10^5\)), representing the number of elements in the sequence.
  2. The second line contains n space-separated integers \(a_1, a_2, \ldots, a_n\) where \(-10^9 \le a_i \le 10^9\).

outputFormat

Output a single line to standard output containing either YES if there exists a strictly increasing subsequence of length at least 3, or NO otherwise.

## sample
5
5 1 2 4 3
YES

</p>