#K74257. Count Distinct Elements in a Matrix
Count Distinct Elements in a Matrix
Count Distinct Elements in a Matrix
You are given a matrix of integers. Your task is to count the number of distinct elements present in the matrix.
The input consists of an integer \( n \) on the first line, representing the number of rows. Each of the next \( n \) lines contains the elements of the corresponding row, separated by spaces. If \( n \) is 0, the matrix is empty.
Example:
For the matrix:
3 1 2 3 4 5 6 7 8 9
The output should be 9
because there are 9 distinct integers in the matrix.
inputFormat
The first line of input contains a single integer \( n \) (\( 0 \leq n \leq 10^5 \)), representing the number of rows in the matrix. If \( n > 0 \), then each of the following \( n \) lines contains a sequence of space-separated integers representing one row of the matrix. Each row can have a variable number of integers.
outputFormat
Output a single integer, the number of distinct elements in the matrix.
## sample3
1 2 3
4 5 6
7 8 9
9
</p>