logo AlgoBeat OnlineJudge
登录 注册

#216103. [ICPC 2021 NAC] Mountainous Palindromic Subarray

内存限制:2048 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

An array is Mountainous if it is strictly increasing, then strictly decreasing. Note that Mountainous arrays must therefore be of length three or greater.

A Subarray is defined as an array that can be attained by deleting some prefix and suffix (possibly empty) from the original array.

An array or subarray is a Palindrome if it is the same sequence forwards and backwards.

Given an array of integers, compute the length of the longest Subarray that is both Mountainous and a Palindrome.

输入格式

The first line of input contains an integer (), which is the number of integers in the array.

Each of the next lines contains a single integer (). These values form the array. They are given in order.

输出格式

Output a single integer, which is the length of the longest Mountainous Palindromic Subarray, or if no such array exists.

样例

样例输入 1

8
2
1
2
3
2
1
7
8

样例输出 1

5

样例输入 2

5
2
5
8
7
2

样例输出 2

-1