아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Mountainous Palindromic Subarray

시간 제한2초메모리 제한2048 MB

요약
앞부분은 순증가, 뒷부분은 순감소하면서 앞뒤로 읽어도 같은 가장 긴 부분 배열의 길이를 구한다.
난이도

보통10점 중 4점

유형
투 포인터, 구현
정답자
아직 제출이 없습니다

문제

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 nn (1≤n≤1061 \le n \le 10^6), which is the number of integers in the array.

Each of the next nn lines contains a single integer xx (1≤x≤1091 \le x \le 10^9). 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 −1-1 of no such array exists.

예제2

  1. 예제 1

    입력
    8
    2
    1
    2
    3
    2
    1
    7
    8
    
    예상 출력
    5
    
  2. 예제 2

    입력
    5
    2
    5
    8
    7
    2
    
    예상 출력
    -1