sclass RunLengthCounter<A> {
  gettable A value;
  gettable long runLength;
  
  long add(A value) {
    if (eq(this.value, value))
      ++runLength;
    else
      runLength = 1;
    this.value = value;
    ret runLength;
  }
}