import java.util.*;

public class FoodInventorySystem {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine().trim());
        int totalCalories = 0;
        Set<String> validTypes = new HashSet<>(
            Arrays.asList("Fruit", "Vegetable", "Dairy")
        );

        for (int i = 0; i < n; i++) {
            String line = sc.nextLine().trim();
            String[] parts = line.split("\\s+");
            if (parts.length != 3) {
                System.out.println("Invalid input");
                System.exit(0);
            }
            String type = parts[0];
            int quantity, caloriesPerUnit;
            try {
                quantity = Integer.parseInt(parts[1]);
                caloriesPerUnit = Integer.parseInt(parts[2]);
            } catch (NumberFormatException e) {
                System.out.println("Invalid input");
                System.exit(0);
            }
            if (!validTypes.contains(type)) {
                System.out.println("Invalid input");
                System.exit(0);
            }
            if (quantity < 0 || caloriesPerUnit < 0) {
                System.out.println(-1);
                System.exit(0);
            }
            totalCalories += quantity * caloriesPerUnit;
        }
        System.out.println(totalCalories);
    }
}
