Problem:
Grading

Write a program which reads a list of student test scores and evaluates the performance for each student.

The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1.

The final performance of a student is evaluated by the following procedure:

If the student does not take the midterm or final examination, the student's grade shall be F.

If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A.

If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B.

If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C.

If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C.

If the total score of the midterm and final examination is less than 30, the student's grade shall be F.

Input

The input consists of multiple datasets. For each dataset, three integers m, f and r are given in a line.

The input ends with three -1 for m, f and r respectively. Your program should not process for the terminal symbols.

The number of datasets (the number of students) does not exceed 50.

Output

For each dataset, print the grade (A, B, C, D or F) in a line.

Sample Input

40 42 -1
20 30 -1
0 2 -1
-1 -1 -1

Sample Output

A
C
F

Solution in JAVA (judge verdict: Wrong Answer)

import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		LinkedList<Integer> pit = new LinkedList<>();
		LinkedList<String> pfm = new LinkedList<>();

		int m = 0;
		int f = 0;
		int r = 0;
		
		//???????????\???
		int cnt = 0;
		while(m != -1 || f != -1 || r != -1) {
			m = sc.nextInt();
			f = sc.nextInt();
			r = sc.nextInt();
			if(m == -1 && f == -1 && r == -1) {
				break;
			} else {
				pit.add(m);
				pit.add(f);
				pit.add(r);
				cnt+=3;
			}
		}
		
		int k = 0;
		for(int i = 2; i < cnt; i+=3) {
			if(pit.get(i-2) == -1 && pit.get(i-1) == -1) {
				pfm.add("F");
				k++;
			} else if(pit.get(i-2) + pit.get(i-1) >= 80) {
				pfm.add("A");
				k++;
			} else if(pit.get(i-2) + pit.get(i-1) >= 65) {
				pfm.add("B");
				k++;
			} else if(pit.get(i-2) + pit.get(i-1) >= 50) {
				pfm.add("C");
				k++;
			} else if(pit.get(i-2) + pit.get(i-1) >= 30) {
				if(pit.get(i) >= 50) {
					pfm.add("C");
					k++;
				} else {
					pfm.add("D");
					k++;
				}
			} else if(pit.get(i-2) + pit.get(i-1) < 30) {
				pfm.add("F");
				k++;
			}
		}
		
		for(int i = 0; i < k; i++) {
			System.out.println(pfm.get(i));
		}
	}
}