import java.util.*;

class Calories {
    int food(int q, int c) {
        return q * c;
    }
}

class Fruit extends Calories {
    int food(int q, int c) {
        return q * c;
    }
}

class Vegetable extends Calories {
    int food(int q, int c) {
        return q * c;
    }
}

class Dairy extends Calories {
    int food(int q, int c) {
        return q * c;
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        // Constraint check for n
        if (n < -20 || n > 20) {
            System.out.println("Invalid input");
            return;
        }

        int total = 0;

        for (int i = 0; i < n; i++) {
            String type = sc.next();
            int q = sc.nextInt();
            int c = sc.nextInt();

            // Constraint check for q and c
            if (q < 0 || c < 0) {
                System.out.println(-1);
                return;
            }

            Calories obj;  // parent reference

            // 👇 Object Creation using switch
            switch (type) {
                case "Fruit":
                    obj = new Fruit();      // create Fruit object
                    break;
                case "Vegetable":
                    obj = new Vegetable();  // create Vegetable object
                    break;
                case "Dairy":
                    obj = new Dairy();      // create Dairy object
                    break;
                default:
                    System.out.println("Invalid input");
                    return;
            }

            // Call method using created object
            total += obj.food(q, c);
        }

        System.out.println(total);
    }
}