#/usr/bin/perl

use strict;
my $f = '\S+\s+';
my %engines;

my @enames = ( 'Ask Jeeves', 'Google', 'Google Images', 'MSN', 'Yahoo' );

my $e;
foreach $e (@enames) { $engines{$e} = 0; };

my $lastGImage;
while (<STDIN>)
{
  my $who;
  my $agent;
  if (/^(\S+)\s+$f$f$f$f$f$f$f$f$f\"(\S+)\"/)
  {
      $who = $1;
      $agent = $2;
  }
  
  s/\" .*$//;
  my $e = '';
  next if ($agent =~ /^-?$/);
  if    ($agent =~ /search\.yahoo/)               { $e = 'Yahoo'; }
  elsif ($agent =~ m@^http://images.google@)
  {
      if ($who ne $lastGImage) { $e = 'Google Images'; }
      $lastGImage = $who;
  }
  elsif ($agent =~ m@^http://www.google.*search@) { $e = 'Google'; }
  elsif ($agent =~ m@^http://search.msn.com@)     { $e = 'MSN'; }
  elsif ($agent =~ m@^http://web.ask.com@)        { $e = 'Ask Jeeves'; }
  if ($e) { $engines{$e}++; }
}

$ARGV[0] =~ s/.log.*$//;
print "$ARGV[0]\t";
foreach $e (@enames)
{
  print "$engines{$e}\t";
}
print "\n";


