#abc381f. F - 1122 Subsequence
F - 1122 Subsequence
当前没有测试数据。
Score : points
问题陈述
一个正整数序列 (可能为空)被称为1122序列,当且仅当它满足以下三个条件:(1122序列的定义与问题D中相同。)
- 是偶数。这里, 表示 的长度。
- 对于每个满足 的整数 , 和 相等。
- 每个正整数在 中要么不出现,要么恰好出现两次。也就是说, 中包含的每个正整数在 中恰好出现两次。
给定一个由正整数组成的长度为 的序列 ,请打印出 的一个**子序列(不一定是连续的)**的最大长度,该子序列是一个1122序列。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
A sequence of positive integers (possibly empty) is called a 1122 sequence if and only if it satisfies all of the following three conditions: (The definition of a 1122 sequence is the same as in Problem D.)
- is even. Here, denotes the length of .
- For each integer satisfying , and are equal.
- Each positive integer appears in either not at all or exactly twice. That is, every positive integer contained in appears exactly twice in .
Given a sequence of length consisting of positive integers, print the maximum length of a subsequence (not necessarily contiguous) of that is a 1122 sequence.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the maximum length of a (not necessarily contiguous) subsequence of that is a 1122 sequence.
Sample Input 1
7
1 3 3 1 2 2 1
Sample Output 1
4
For example, choosing the -st, -th, -th, and -th elements of , we get , which is a 1122 sequence of length .
There is no longer subsequence that satisfies the conditions for a 1122 sequence, so the answer is .
Sample Input 2
1
20
Sample Output 2
0