import java.util.*;
import java.util.stream.Collectors;

/**
 * Created by jpoial on 28.05.2015.
 */
public class Homework {

    public static void main (String[] args) {
        List<Integer> myList = Arrays.asList (1, -1, 0, 2, -4, 2, 4, 5, 7, -3, -5);
        List<Integer> res;
        int sum = myList.stream().mapToInt(Integer::intValue).sum();
        int count = (int)(myList.stream().count());
        double avg = (double)sum / count;
        System.out.println ("avg=" + avg);
        res = myList.stream()
                //.peek (i -> System.out.println("peek1 " + i))
                .filter (i -> i < avg)
                //.peek (i -> System.out.println("peek2 " + i))
                //.count();
                //.mapToInt (Integer::intValue)
                //.sum();
                .collect (Collectors.toList());
                //.stream()
                //.count();
        System.out.println ("res=" + res);
        //myList = new ArrayList<Integer>();
        int max = myList.stream().max (Integer::compareTo).orElseThrow (RuntimeException::new);
        int min = myList.stream().min (Integer::compareTo).orElseThrow (RuntimeException::new);
        sum = myList.stream().mapToInt (Integer::intValue).sum();
        count = (int)(myList.stream().count());
        double mark = (double)(sum-max-min)/(count -2.);
        System.out.println ("mark=" + mark);
    }
}
