CF1630C.Paint the Middle

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given nn elements numbered from 11 to nn , the element ii has value aia_i and color cic_i , initially, ci=0c_i = 0 for all ii .

The following operation can be applied:

  • Select three elements ii , jj and kk ( 1i<j<kn1 \leq i < j < k \leq n ), such that cic_i , cjc_j and ckc_k are all equal to 00 and ai=aka_i = a_k , then set cj=1c_j = 1 .

Find the maximum value of i=1nci\sum\limits_{i=1}^n{c_i} that can be obtained after applying the given operation any number of times.

输入格式

The first line contains an integer nn ( 3n21053 \leq n \leq 2 \cdot 10^5 ) — the number of elements.

The second line consists of nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 1ain1 \leq a_i \leq n ), where aia_i is the value of the ii -th element.

输出格式

Print a single integer in a line — the maximum value of i=1nci\sum\limits_{i=1}^n{c_i} 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:

首页