#C5855. Increasing Subsequence of Length 3

    ID: 49550 Type: Default 1000ms 256MiB

Increasing Subsequence of Length 3

Increasing Subsequence of Length 3

Given an integer N and a sequence of N distinct integers, determine whether there exists a subsequence of length 3 that is strictly increasing.

The problem is to check if there are three indices i, j, k (with i < j < k) such that sequence[i] < sequence[j] < sequence[k]. In mathematical terms, we need to decide if there exists a triplet of indices where:

[ sequence[i] < sequence[j] < sequence[k] ]

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

It is guaranteed that all elements in the sequence are distinct.

inputFormat

The first line of input contains an integer N representing the number of elements in the sequence. The second line contains N space-separated integers which form the sequence.

Note: Input is provided via stdin.

outputFormat

Output a single line with either YES or NO depending on whether there exists a strictly increasing subsequence of length 3.

Note: Output should be written to stdout.

## sample
5
1 2 3 4 5
YES

</p>