CF1630C.Paint the Middle
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given n elements numbered from 1 to n , the element i has value ai and color ci , initially, ci=0 for all i .
The following operation can be applied:
- Select three elements i , j and k ( 1≤i<j<k≤n ), such that ci , cj and ck are all equal to 0 and ai=ak , then set cj=1 .
Find the maximum value of i=1∑nci that can be obtained after applying the given operation any number of times.
输入格式
The first line contains an integer n ( 3≤n≤2⋅105 ) — the number of elements.
The second line consists of n integers a1,a2,…,an ( 1≤ai≤n ), where ai is the value of the i -th element.
输出格式
Print a single integer in a line — the maximum value of i=1∑nci that can be obtained after applying the given operation any number of times.
输入输出样例
输入#1
7 1 2 1 2 7 4 7
输出#1
2
输入#2
13 1 2 3 2 1 3 3 4 5 5 5 4 7
输出#2
7
说明/提示
In the first test, it is possible to apply the following operations in order: