struct monkey
{
int div, t, f, ins = 0;
string op;
};
ll update(string s, ll val)
{
stringstream ss(s);
string x;
ll val0 = val;
bool add, mul;
add = mul = 0;
while (ss >> x)
{
if (x == "==" || x == "new")
continue;
add |= (x == "+");
mul |= (x == "*");
if (x[0] >= '0' && x[0] <= '9')
val0 = stoi(x);
}
if (add)
val += val0;
if (mul)
val *= val0;
return val;
}
int to_int(string x)
{
int val = 0;
for (int i = 0; i < sz(x); i++)
if (x[i] >= '0' && x[i] <= '9')
val *= 10, val += (x[i] - '0');
return val;
}
void Solve()
{
priority_queue<ll> pq; // max_inspections
map<int, queue<ll>> mp; // values;
map<int, monkey> mp1; // divide,conditions,inspections
int id = 0, r = 10000;
ll ans;
bool fst, snd;
fst = snd = 0;
string s;
// Processing Input
while (getline(cin, s))
{
if (s[0] == 'M')
continue;
stringstream ss(s);
string x;
bool st, op, ts;
st = op = ts = 0;
while (ss >> x)
{
st |= (x == "Starting");
op |= (x == "Operation:");
ts |= (x == "Test:");
fst |= (x == "true:");
snd |= (x == "false:");
if (st && x[0] >= '0' && x[0] <= '9')
mp[id].push(to_int(x));
else if (op)
mp1[id].op += " " + x;
else if (ts && x[0] >= '0' && x[0] <= '9')
mp1[id].div = stoi(x);
else if (!snd && fst && x[0] >= '0' && x[0] <= '9')
mp1[id].t = stoi(x);
else if (snd && x[0] >= '0' && x[0] <= '9')
mp1[id].f = stoi(x);
}
if (fst && snd)
id++, fst = snd = 0;
}
// Actual rounds
while (r--)
for (int i = 0; i < id; i++)
while (sz(mp[i]))
{
ll val = mp[i].front();
mp[i].pop();
val = update(mp1[i].op, val);
if (!(val % mp1[i].div))
mp[mp1[i].t].push(val);
else
mp[mp1[i].f].push(val);
mp1[i].ins++;
}
for (auto it : mp1)
pq.push(it.second.ins);
ans = pq.top();
pq.pop();
ans *= pq.top();
cout << ans;
}