#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
using namespace std;
typedef long long BigInt;
typedef long long ll;
struct Node{
pair<BigInt, BigInt> plus_num, mult_num, active_num;
bool log_node = false;
Node(bool log_node = false){
plus_num = mult_num = active_num = {0, 0};
this->log_node = log_node;
}
};
string s;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> s;
s += ")";
stack<Node> st;
st.push(Node());
st.push(Node());
BigInt curr_num = 0;
bool exists_curr_num = false;
bool is_n = false, is_log = false;
for(int i = 0; i < s.size(); ++i){
if(isdigit(s[i])){
curr_num *= 10;
curr_num += s[i] - '0';
exists_curr_num = true;
continue;
}
if(exists_curr_num){
if(st.top().active_num == pair<BigInt, BigInt>{1, 0}){
st.top().active_num = {curr_num, 0};
}
else if(st.top().active_num == pair<BigInt, BigInt>{0, 1}){
st.top().active_num = {0, curr_num};
}
exists_curr_num = false;
curr_num = 0;
}
if(s[i] == 'N'){
st.top().active_num = {1, 0};
continue;
}
if(s[i] == 'l'){
st.push(Node(true));
i += 3;
continue;
}
if(s[i] == '('){
st.push(Node());
continue;
}
if(s[i] == '^'){
continue;
}
if(s[i] == ')'){
auto &t = st.top();
t.mult_num.first += t.active_num.first;
t.mult_num.second += t.active_num.second;
t.plus_num = max(t.plus_num, t.mult_num);
auto p_num = t.plus_num;
if(t.log_node){
if(p_num.first || p_num.second){
p_num = pair<BigInt, BigInt>{0, 1};
}
else{
p_num = pair<BigInt, BigInt>{0, 0};
}
}
st.pop();
st.top().active_num = p_num;
continue;
}
if(s[i] == '+'){
auto &t = st.top();
t.mult_num.first += t.active_num.first;
t.mult_num.second += t.active_num.second;
t.active_num = pair<BigInt, BigInt>{0, 0};
t.plus_num = max(t.plus_num, t.mult_num);
t.mult_num = pair<BigInt, BigInt>{0, 0};
continue;
}
if(s[i] == '*'){
auto &t = st.top();
t.mult_num.first += t.active_num.first;
t.mult_num.second += t.active_num.second;
t.active_num = pair<BigInt, BigInt>{0, 0};
continue;
}
}
assert(st.size() == 1);
auto ans = st.top().active_num;
cout << ans.first << " " << ans.second << "\n";
}