// Path: aula23-reduction/src/main/java/util/StreamUtils.java
// public static <T> Stream<T> filterEvenLine(Stream<T> src) {
//     Spliterator<T> iter = src.spliterator();
//     Spliterator<T> res = new AbstractSpliterator<T>(Long.MAX_VALUE, Spliterator.ORDERED ) {
//         @Override
//         public boolean tryAdvance(Consumer<? super T> action) {
//             return iter.tryAdvance(item -> {})
//                     ? iter.tryAdvance(action)
//                     : false;
//         }
//     };
//     return StreamSupport.stream(res, false);
// }


import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import static java.lang.System.out;
import static java.util.Arrays.stream;
import static util.StreamUtils.filterEvenLine;
    }

    static double streamAverage3(IntStream temperatures) {
        Averager avg = temperatures
                .mapToObj(nr -> new Averager(nr))
                .parallel()
                .reduce((prev, curr) -> prev.add(curr))
                .get();
        return ((double)avg.sum)/avg.count;
    }

    static class Averager{
        final int sum;
        final int count;

        public Averager(int sum, int count) {
            this.sum = sum;
            this.count = count;
        }

        public Averager(int nr) {
            sum = nr; count = 1;
        }

        public Averager add(Averager other) {
            return new Averager(this.sum + other.sum, this.count + other.count);
        }
    }

    static int streamMax(Stream<String> lines) {
// Path: aula23-reduction/src/main/java/util/StreamUtils.java
// public static <T> Stream<T> filterEvenLine(Stream<T> src) {
//     Spliterator<T> iter = src.spliterator();
//     Spliterator<T> res = new AbstractSpliterator<T>(Long.MAX_VALUE, Spliterator.ORDERED ) {
//         @Override
//         public boolean tryAdvance(Consumer<? super T> action) {
//             return iter.tryAdvance(item -> {})
//                     ? iter.tryAdvance(action)
//                     : false;
//         }
//     };
//     return StreamSupport.stream(res, false);
// }


// Path: aula23-reduction/src/main/java/App.java
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import static java.lang.System.out;
import static java.util.Arrays.stream;
import static util.StreamUtils.filterEvenLine;

    }

    static double streamAverage3(IntStream temperatures) {
        Averager avg = temperatures
                .mapToObj(nr -> new Averager(nr))
                .parallel()
                .reduce((prev, curr) -> prev.add(curr))
                .get();
        return ((double)avg.sum)/avg.count;
    }

    static class Averager{
        final int sum;
        final int count;

        public Averager(int sum, int count) {
            this.sum = sum;
            this.count = count;
        }

        public Averager(int nr) {
            sum = nr; count = 1;
        }

        public Averager add(Averager other) {
            return new Averager(this.sum + other.sum, this.count + other.count);
        }
    }

    static int streamMax(Stream<String> lines) {
        return filterEvenLine(lines