#C3554. Longest Bitonic Subarray

    ID: 46994 Type: Default 1000ms 256MiB

Longest Bitonic Subarray

Longest Bitonic Subarray

Given an array of daily temperatures, your task is to determine the length of the longest contiguous subarray that first strictly increases and then strictly decreases. A valid bitonic subarray must have a strictly increasing sequence of days followed by a strictly decreasing sequence of days (both parts must be non-empty).

In mathematical terms, if the increasing part has length i (i ≥ 1) and the decreasing part has length j (j ≥ 1), then the bitonic subarray has a total length of i + j + 1. If no such subarray exists, output 0.

You are required to read input from standard input (stdin) and write the output to standard output (stdout).

inputFormat

The input consists of two lines. The first line contains a single integer n, representing the number of days. The second line contains n space-separated integers, each denoting the temperature for a day.

outputFormat

Output a single integer denoting the length of the longest bitonic subarray. If there is no valid bitonic subarray, print 0.## sample

7
2 1 4 7 3 2 5
5

</p>