import java.util.InputMismatchException;
import java.util.Scanner;


public class FoodInventory {

    
    public static void main(String[] args) {
        
        Scanner scanner = new Scanner(System.in);
        long totalCalories = 0;

        try {
            
            int n = scanner.nextInt();
            scanner.nextLine(); 

            
            for (int i = 0; i < n; i++) {
                
                String line = scanner.nextLine();
                
                String[] parts = line.split(" ");
                
                
                if (parts.length != 3) {
                    System.out.println("Invalid input");
                    return; 
                }

                String type = parts[0];
                int quantity;
                int caloriesPerUnit;

                try {
                    s.
                    quantity = Integer.parseInt(parts[1]);
                    caloriesPerUnit = Integer.parseInt(parts[2]);
                } catch (NumberFormatException e) {
                   
                    System.out.println("Invalid input");
                    return; 
                }

                
                if (quantity < 0 || caloriesPerUnit < 0) {
                    System.out.println(-1);
                    return; 
                }

                
                if (!type.equals("Fruit") && !type.equals("Vegetable") && !type.equals("Dairy")) {
                    System.out.println("Invalid input");
                    return; 
                }

                
                totalCalories += (long) quantity * caloriesPerUnit;
            }

            
            System.out.println(totalCalories);

        } catch (InputMismatchException e) {
            
            System.out.println("Invalid input");
        } finally {
            
            scanner.close();
        }
    }
}
