data Score = Score Int Int Int deriving (Show,Read,Eq)
data Grade = A|B|C|D|E|F deriving (Show)

total :: Score->Int
total (Score m f _) = m+f

isAbscent :: Score -> Bool
isAbscent (Score m f _)
	|m == -1 || f == -1 = True
	|otherwise = False
	
kyusai ::Score->Bool
kyusai (Score _ _ r)
	|r>=50 = True
	|otherwise = False
	
readScore :: String->Score
readScore = (\[a,b,c]->Score a b c).map (read :: String->Int).words

grading :: Score->Grade
grading x
	|isAbscent x || total x < 30 = F
	|total x < 50 && not (kyusai x) = D
	|total x < 50 && kyusai x = C
	|total x < 65 = C
	|total x < 80 = B
	|otherwise = A
	
haltSignal :: Score
haltSignal = Score (-1) (-1) (-1)

main = getContents >>= mapM_ print.map grading.takeWhile (/=haltSignal).map readScore.lines