#K34242. Minimum Number of Swaps to Arrange Pairs
Minimum Number of Swaps to Arrange Pairs
Minimum Number of Swaps to Arrange Pairs
You are given an array of even length consisting of (n) integers, where each integer appears exactly twice. The task is to compute the minimum number of swaps required to rearrange the array so that each pair of identical elements becomes adjacent. In one swap, you can exchange any two elements in the array.
Formally, if the array is defined as (a_1, a_2, \dots, a_n), where (n) is even, find the minimum number of swaps required such that for every odd index (i), (a_i = a_{i+1}). All formulas are written in (\LaTeX) format.
inputFormat
The input is taken from standard input and consists of two lines:
1. The first line contains a single integer (n) (an even number), representing the length of the array.
2. The second line contains (n) space-separated integers. It is guaranteed that each integer appears exactly twice.
outputFormat
Output a single integer to standard output representing the minimum number of swaps required to arrange the pairs adjacently.## sample
6
1 3 2 1 2 3
2