Statement
There is an array of length . Initially, for every .
You are also given a permutation of and queries. Query is described by three integers . When it is executed, is replaced by for every .
You must execute every one of the queries exactly once. You may choose their execution order arbitrarily.
Maximize the number of positions satisfying after all queries have been executed.
Input
The input is given from Standard Input in the following format:
Each case is given in the following format:
Output
For each test case, print one integer: the maximum possible number of positions satisfying after all queries have been executed.
Constraints
- .
- .
- .
- is a permutation of .
- ().
- ().
- The sum of over all test cases does not exceed .
- The sum of over all test cases does not exceed .
Subtasks
Samples
In the first test case, whichever of the two queries is executed later overwrites the whole array, so at most one position can match the target permutation.
In the second test case, all three positions can be made correct by choosing a suitable order.