// Arup Guha
// 10/2/2017
// Solution to 2017 NAQ Problem: Company Picnic

import java.util.*;

public class companypicnic_arup {

	public static int n;
	public static employee[] tree;
	public static int ceo;
	public static HashMap<String,Integer> nameMap;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		nameMap = new HashMap<String,Integer>();
		tree = new employee[n];

		// Read in input.
		for (int i=0; i<n; i++) {
			String name = stdin.next();
			double vel = stdin.nextDouble();
			String boss = stdin.next();
			tree[i] = new employee(name, vel, boss);
			nameMap.put(name, i);
			if (boss.equals("CEO")) ceo = i;
		}

		// Add kids.
		for (int i=0; i<n; i++) {
			if (i == ceo) continue;
			tree[nameMap.get(tree[i].boss)].kids.add(tree[i]);
		}

		// Solve it!
		average res = tree[ceo].solve();
		System.out.printf("%d %.8f\n",res.n, res.avg);
	}
}

class employee {

	public String name;
	public String boss;
	public double speed;
	public ArrayList<employee> kids;
	public average bestWithout;

	public employee(String n, double s, String b) {
		name = n;
		speed = s;
		boss = b;
		kids = new ArrayList<employee>();
		bestWithout = new average(0, 0);
	}

	public average solve() {

		// Can't form a team with one person.
		if (kids == null) return new average(0, 0);

		// Store answers for each kid.
		ArrayList<average> res = new ArrayList<average>();
		for (int i=0; i<kids.size(); i++)
			res.add(kids.get(i).solve());

		// This is our initial best - not involving the root.
		for (int i=0; i<res.size(); i++)
			bestWithout = bestWithout.add(res.get(i));

		// Set our result to this temporarily.
		average ans = bestWithout;

		// Now, see if we can do better by combining the root with one of its kids.
		for (int i=0; i<kids.size(); i++) {

			// This is our team with root and kid i.
			average tmp = new average(1, Math.min(speed, kids.get(i).speed));

			// Add all other subtrees except i.
			for (int j=0; j<kids.size(); j++) {
				if (j == i) continue;
				tmp = tmp.add(res.get(j));
			}

			// Add in i's subtree, without i.
			tmp = tmp.add(kids.get(i).bestWithout);

			// Reassign our best result, if necessary.
			if (tmp.beat(ans)) ans = tmp;
		}

		// Ta da!
		return ans;
	}
}

class average {

	public int n;
	public double avg;

	public average(int myn, double vel) {
		n = myn;
		avg = vel;
	}

	// Here is how you take a weighted average...define 0 to avoid checking for empty items.
	public average add(average other) {
		if (n+other.n == 0) return new average(0, 0);
		return new average(n+other.n, (n*avg + other.n*other.avg)/(n+other.n));
	}

	// According to the problem spec.
	public boolean beat(average other) {
		if (this.n > other.n) return true;
		if (this.n < other.n) return false;
		return this.avg > other.avg;
	}
}