import java.util.*;
class ComponentConverter {
static class ComponentRatio {
double ratio;
ComponentRatio
(String name,
double ratio
) { this.name = name;
this.ratio = ratio;
}
}
public static void main
(String[] args
) { Scanner sc
= new Scanner
(System.
in);
String[] comps
= sc.
nextLine().
split(","); int n = comps.length;
List<String> components = new ArrayList<>();
components.add(comp.trim());
for (int i = 0; i < n; i++) matrix[i][i] = 1.0;
while (sc.hasNextLine()) {
String line
= sc.
nextLine().
trim(); if (line.isEmpty()) break;
String[] parts
= line.
split(" is "); String from
= parts
[0].
trim(); String toPart
= parts
[1].
trim();
int qty
= Integer.
parseInt(toPart.
replaceAll("[^0-9]",
"")); String to
= toPart.
replaceAll("[0-9]",
"").
trim();
int i = components.indexOf(from);
int j = components.indexOf(to);
matrix[i][j] = (double) qty;
matrix[j][i] = 1.0 / qty;
}
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (matrix[i][k] != null && matrix[k][j] != null && matrix[i][j] == null) {
matrix[i][j] = matrix[i][k] * matrix[k][j];
}
}
}
}
int rootIndex = -1;
for (int i = 0; i < n; i++) {
boolean isRoot = true;
for (int j = 0; j < n; j++) {
if (matrix[i][j] == null || matrix[i][j] < 1.0) {
isRoot = false;
break;
}
}
if (isRoot) {
rootIndex = i;
break;
}
}
if (rootIndex == -1) {
System.
out.
println("No root component found."); return;
}
List<ComponentRatio> ratios = new ArrayList<>();
for (int i = 0; i < n; i++) {
ratios.add(new ComponentRatio(components.get(i), matrix[rootIndex][i]));
}
ratios.
sort(Comparator.
comparingDouble(r
-> r.
ratio));
StringBuilder sb = new StringBuilder();
for (ComponentRatio r : ratios) {
if (sb.length() > 0) sb.append(" equals ");
sb.
append((int)Math.
round(r.
ratio)).
append(r.
name); }
System.
out.
println(sb.
toString()); }
}