#!/usr/bin/env perl
#
# how long are consecutive runs of values?
#
#   ./trial | ./runstats
#   perl -E 'say rand > 0.5 ? 1 : 0 for 1..1e5' | ./runstats

use 5.10.0;
use warnings;

my %table;

my $prev = readline;
chomp $prev;
my $run = 1;
while ( my $value = readline ) {
    chomp $value;
    if ( $value != $prev ) {
        $table{$run}++;
        $run  = 1;
        $prev = $value;
        next;
    }
    $run++;
}

for my $k ( sort { $a <=> $b } keys %table ) {
    printf "%-2d %d\n", $k, $table{$k};
}
