static Map> runLengthStats(L list) {
Map> map = new Map;
int n = l(list), i = 0;
while (i < n) {
A a = list.get(i);
int j = i+1;
while (j < n && eq(a, list.get(j))) ++j;
MultiSet ms = getOrCreate(map, a, -> new MultiSet);
ms.add(j-i);
i = j;
}
ret map;
}