long (int @NotNull [] time, int part) { assert part >= 1; int n = time.length; Arrays.sort(time); long total = 0; int start = n / 2 - n / part / 2; int end = n / 2 + n / part / 2; for (int i = start; i < end; i++) { total += time[i]; } int middlePartLength = end - start; return middlePartLength == 0 ? 0 : total / middlePartLength; }