Microwavable Subsequence
시간 제한1초메모리 제한2048 MB
x < y인 모든 값 쌍에 대해 x와 y만 쓰고 인접한 원소가 서로 다른 가장 긴 부분수열의 길이를 구해 모두 더한다.
문제
You are given an array of integers: .
A subsequence can be derived from an array by removing zero or more elements without changing the order of the remaining elements. For example, , , , and are subsequences of array , while is not a subsequence of array .
A subsequence is microwavable if the subsequence consists of at most two distinct values and each element differs from its adjacent elements. For example, , , and are microwavable, while and are not microwavable.
Denote a function as the length of the longest microwavable subsequence of array such that each element within the subsequence is either or . Find the sum of for all .
입력
The first line consists of two integers ().
The second line consists of integers ().
출력
Output a single integer representing the sum of for all .