
Image by Joost J. Bakker, from commons.wikimedia.org
You have just started at the Nordic Cargo Permuting Company, whose business is moving cargo between its $$$k$$$ cargo bays.
Your boss has handed you today's work order: a list of $$$n$$$ cargo swaps. Each swap names two bays, and carrying it out means exchanging the cargo in those two bays. The swaps are to be carried out in the order listed. Your boss is adamant that every swap is carried out as written, for various paperwork reasons.
You wonder whether the work order could be shortened. A section of the list consists of the swaps at list positions $$$\ell$$$ through $$$r$$$, for some $$$1 \leq \ell \leq r \leq n$$$.
A section is redundant if skipping it makes no difference: carrying out only the swaps outside the section, in the order listed, leaves every piece of cargo in the same bay as carrying out the entire list does.
You are sure your cutting and gluing skills are up to the task of removing a redundant section from the work order. But how many sections are redundant?
The input consists of:
Output the number of redundant sections.
6 31 22 31 22 31 22 3
1
4 21 21 21 21 2
4
3 41 23 41 3
0
| Name |
|---|


