Given n integer registers r1, r2, ..., rn we define a Compare-Exchange Instruction CE(a, b), where a, b are register indices (1 <= a < b <= n):
CE(a, b)::
if content(ra) > content(rb) then
exchange the contents of registers ra and rb;
A Compare-Exchange program (shortly CE-program) is any nite sequence of Compare-Exchange instructions. A CE-program is called a Minimum-Finding program if after its execution the register r1 always contains the smallest value among all values in the registers. Such program is called reliable if it remains a Minimum-Finding program after removing any single Compare-Exchange instruction.
Given a CE-program P , what is the smallest number of instructions that should be added at the end of program P in order to get a reliable Minimum-Finding program?
Example
Consider the following CE-program for 3 registers:
CE(1, 2); CE(2, 3); CE(1, 2).
In order to make this program a reliable Minimum-Finding program it is sufficient to add only two instructions, CE(1, 3) and CE(1, 2).
Task
Write a program which for each data set:
reads the description of a CE-program,
computes the smallest number of CE-instructions that should be added to make this program a reliable Minimum-Finding program,
writes the result.