#K74912. Detecting a 132 Pattern in a Sequence
Detecting a 132 Pattern in a Sequence
Detecting a 132 Pattern in a Sequence
You are given a sequence of distinct integers. Your task is to determine whether a 132 pattern exists in the sequence.
A 132 pattern is defined as a subsequence of three integers \(a_1, a_2, a_3\) such that:
\(a_1 < a_3 < a_2\)
You should read the input from stdin
and output the result to stdout
. If the pattern exists, print True
; otherwise, print False
.
inputFormat
The input consists of two parts:
- The first line contains an integer \(n\), which represents the number of elements in the sequence.
- The second line contains \(n\) space-separated integers that make up the sequence.
outputFormat
Output a single line with either True
if there exists a 132 pattern in the sequence or False
otherwise.
4
1 2 3 4
False