#!/usr/local/bin/perl -w

my %count;
while (<>) {
  my $correct = $_;
  my $output = (substr($correct, 0, 1) eq '-')? <>: $_;
  $correct  =~  /\(\w+-?((?:[-\w]+)?)/ or warn "Confused by $correct";
  my $ctag = $1;
  $output  =~  /\(\w+-?((?:[-\w]+)?)/ or warn "Confused by $correct";
  my $otag = $1;
  ++$count{$ctag}{$otag};
}

foreach my $ctag (sort keys %count) {
  foreach my $otag (sort keys %{$count{$ctag}}) {
    printf "%7s %7s %d\n", $ctag, $otag, $count{$ctag}{$otag};
  }
}
