#DSU0000034. Biến dãy thành đối xứng (KAIBUNsyo)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Biến dãy thành đối xứng (KAIBUNsyo)
KAIBUNsyo
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of positive integers. The array is palindromic if reading it from left to right gives the same sequence as reading it from right to left. Equivalently, must hold for every index .
In one operation, choose two distinct positive integers and , then replace every current occurrence of in the array with . All other values remain unchanged. This operation affects an entire value class, not a single chosen position. You may perform operations repeatedly on the resulting array.
Find the minimum number of operations required to make the array palindromic.
Input
The first line contains . The next line contains integers .
Output
Print the minimum number of operations.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
8
1 5 3 2 5 2 3 1
Output
2
Explanation
Mirrored pairs are (1,1), (5,3), (3,2), (2,5). Values 2, 3, and 5 must become equal. Merging three distinct values requires two operations.