#!/usr/local/bin/perl

$students = 0;
@subjects = ("English", "history", "mathematics",
             "science", "geography");
while ($line = <STDIN>) {
        $line =~ s/^\s+|\s+$//g;
        @words = split (/\s+/, $line);
        @students[$students++] = $words[0];
        for ($count = 1; $count <= 5; $count++) {
                $marks{$words[0].$subjects[$count-1]} =
                     $words[$count];
        }
}

# now print the failing grades, one student per line
foreach $student (sort (@students)) {
       $has_failed = 0;
        foreach $subject (sort (@subjects)) {
                if ($marks{$student.$subject} < 50) {
                        if ($has_failed == 0) {
                                $has_failed = 1;
                                print ("$student failed:");
                        }
                        print (" $subject");
                }
        }
        if ($has_failed == 1) {
                print ("\n");
        }
}
