#!/usr/bin/perl

sub printit
{
  my $tape=$_[0];
  if($blocks[$tape]>0)
  {
    print $lastwrite[$tape]?"Write":"Read";
    print " ".$blocks[$tape]." records unit $tape\n";
    $blocks[$tape] = 0;
  }
  $lastwrite[$tape] = -1;
}

for($tape=1; $tape<=6; $tape++)
{
  $lastwrite[$tape] = -1;
  $blocks[$tape] = 0;
}

while($l = <>)
{
  chomp($l);
# print "\t$l\n";
  if($l =~ /^(Read|Write) (\d+) word.* unit (\d):/)
  {
#   print "$1 $2 $3\n";
    $write = $1 eq "Write";
    $len = ($2-2)/2;
    $tape = $3;
    next if($len==4);
    if($lastwrite[$tape] == $write)
    {
      $blocks[$tape] += $len;
#     print "blocks: $blocks\n";
    }
    else
    {
      printit($tape);
      $lastwrite[$tape] = $write;
      $blocks[$tape]= $len;
    }
  }
  elsif($l =~ /^Rewind tape unit (\d).$/)
  {
    $tape = $1;
    printit($tape);
  }
  elsif($l =~ /^to filemark on tape unit (\d).$/)
  {
    $tape = $1;
    printit($tape);
  }
}

for($tape=1; $tape<=6; $tape++)
{
  printit($tape);
}



