package ru.redguy.tasks;

import javafx.util.Pair;
import ru.redguy.ATask;
import ru.redguy.Task;

import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

@ATask("26")
public class Task26 extends Task {
    @Override
    public void run() throws IOException {
        String data = getFile("26.txt");
        data = data.substring(data.indexOf("\n")+1);
        List<Long> numbers = data.lines().map(Long::valueOf).collect(Collectors.toList());

        List<Long> normal = numbers.stream().filter(number -> number%2==0).collect(Collectors.toList());

        List<Pair> pairs = normal.stream()
                .flatMap(a -> normal.stream().map(b -> new Pair(a,b)))
                .distinct()
                .filter(p -> !Objects.equals(p.a, p.b))
                .collect(Collectors.toList());

        Long max = pairs.stream().map(p -> (p.a+p.b)/2).filter(numbers::contains).max(Comparator.comparingLong(a->a)).get();
        System.out.println(pairs.size()+" "+max);
    }

    static class Pair {
        Long a;
        Long b;

        public Pair(Long a, Long b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public boolean equals(Object o) {
            if(o instanceof Pair) {
                Pair p = (Pair) o;
                return (Objects.equals(a, p.a) && Objects.equals(b, p.b))||(Objects.equals(a, p.b) && Objects.equals(b, p.a));
            }
            return false;
        }
    }
}
