// you should not overflow in the sum... static long longAverage(long... a) { long sum = 0; for i over a: sum += a[i]; ret ldiv_round(sum, l(a)); } static long longAverage(Iterable l) { long sum = 0; long n = 0; fOr (Long i : l) if (i != null) { sum += i; ++n; } ret ldiv_round(sum, n); }