Generalized statistics collector with a functional interface

Java Hard generics

Task «Generalized statistics collector with a functional interface»

Implement a parameterized class `StatisticsCollector<T>` that accepts arbitrary objects and computes statistics: count, sum (if T extends Number, otherwise null), min and max (if T extends Comparable). Additionally, implement a method `filter(Predicate<T>)` that returns a new StatisticsCollector with objects that passed the filter. Input data: a number n, then n lines, each line contains either an integer or a string (without spaces). After collecting all elements, output the statistics: count, sum (for numbers), min, max (if Comparable). If the type does not support the operation, output "N/A". Use generics and wildcards.

Input Format

In the first line, an integer n (1 ≤ n ≤ 1000). Then n lines, each containing one value (an integer or a string).

Output Format

For the collected objects, output 4 lines: count, sum ("N/A" if not numbers), min ("N/A" if not Comparable), max ("N/A" if not Comparable).

Examples

Example 1

INPUT
3 100 hello 200
OUTPUT
3 300 100 200
main.java