#!/afs/athena/contrib/perl/perl

$| = 1;
$p = 'Hello';
while (<>){
    
    next if (/^Time:/);
    next if (/^$/);
    ($newz=1) if (/^From:/);
    next if (/^From:/);
    
    if($newz){
	$tot++;
	print("$tot, ");
	$newz = 0;
    }

    push(@zephyr, split(' '));
    for $w (@zephyr){
	$next{$p} .= "$w\n";
#	$next{$pp.' '.$p} .="$w\n";
	$p = $w;
    }
}


while(1){
    if($next{$l}){
	$choices = $next{$l};
	@chs = split(/\n/, $choices);
	$c = rand($#chs);
	$word = $chs[$c];
    }
    else{
	($l, $garbage) = each(%next);
	($ll, $garbage) = each(%next);
	($word, $garbage)= each(%next);
    }
    $llen += length($word.' ');
    if($llen <40){
	print("$word ");
    }
    else{
	print("\n$word ");
	$llen = length($word.' ');
    }

    $l = $word;
}
