P7935 [COCI 2007/2008 #5] AVOGADRO
Description
Luka drew a table with $3$ rows and $N$ columns, and then wrote the integers from $1$ to $N$ into the table. In the first row, each integer appears exactly once. In the other two rows, each number may appear any number of times, or not appear at all.
Luka may now delete any number of columns. After that, he sorts each row of the table in increasing order.
He wants to obtain a table such that, after sorting in increasing order, the three rows are exactly the same. Please find the minimum number of columns he needs to delete.
Input Format
The first line contains an integer $N$, which is the number of columns in the table.
The next three lines each contain $N$ integers. These integers are all between $1$ and $N$. In the first row, each number appears once and only once.
Output Format
One line containing an integer, the minimum number of columns Luka needs to delete.
Explanation/Hint
For $40\%$ of the testdata, $N \le 100$.
For $70\%$ of the testdata, $N \le 10000$.
For $100\%$ of the testdata, $1 \le N \le 10^5$.
### Sample 1 Explanation:
For Sample 1, Luka needs to delete the 2nd, 4th, 6th, and 7th columns. After deleting and sorting, all three rows contain only the three integers $1, 3, 5$.
The score for this problem follows the original contest settings, with a full score of $60$ points.
Translated by ChatGPT 5