#K58937. Counting Unique and Non-Unique Elements
Counting Unique and Non-Unique Elements
Counting Unique and Non-Unique Elements
You are given a sequence of integers which terminates with a -1. Your task is to analyze the sequence (excluding the -1) and determine:
- The number of unique elements, i.e., elements that appear exactly once.
- The number of non-unique elements, i.e., distinct elements that appear more than once.
Formally, let \( A = [a_1, a_2, \dots, a_n] \) be the list of integers before the sentinel value \(-1\). Define:
[ unique = #{ x \in A : \text{frequency}(x)=1}\qquad\text{and}\qquad non_unique = #{ x \in A : \text{frequency}(x)>1} ]
Print the two numbers separated by a space. The input will be given via standard input (stdin) and output should be printed to standard output (stdout).
inputFormat
The input is given as a single line containing space-separated integers. The sequence is terminated by the integer -1
, which should not be considered as part of the sequence.
For example:
1 2 3 -1
outputFormat
Output two integers separated by a single space. The first integer is the count of unique elements and the second integer is the count of non-unique elements.
For example, for the input 1 2 3 -1
the output should be:
3 0## sample
1 2 3 -1
3 0