#include <bits/stdc++.h>
using namespace std;
int main( )
{
int c = 0 , d = 0 , n;
cin >> n;
while ( n-- ) {
string s;
cin >> s;
if ( s == "for" ) {
++ d;
c = max( c, d) ;
} else if ( s == "end" ) {
-- d;
}
}
if ( c == 0 ) {
cout << "O(1)" << endl;
} else if ( c == 1 ) {
cout << "O(n)" << endl;
} else {
cout << "O(n^" << c << ")" << endl;
}
return 0 ;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpCnsKICAgIGludCBjID0gMCwgZCA9IDAsIG47CiAgICBjaW4gPj4gbjsKICAgIHdoaWxlIChuLS0pIHsKICAgICAgICBzdHJpbmcgczsKICAgICAgICBjaW4gPj4gczsKICAgICAgICBpZiAocyA9PSAiZm9yIikgewogICAgICAgICAgICArK2Q7CiAgICAgICAgICAgIGMgPSBtYXgoYywgZCk7CiAgICAgICAgfSBlbHNlIGlmIChzID09ICJlbmQiKSB7CiAgICAgICAgICAgIC0tZDsKICAgICAgICB9CiAgICB9CiAgICBpZiAoYyA9PSAwKSB7CiAgICAgICAgY291dCA8PCAiTygxKSIgPDwgZW5kbDsKICAgIH0gZWxzZSBpZiAoYyA9PSAxKSB7CiAgICAgICAgY291dCA8PCAiTyhuKSIgPDwgZW5kbDsKICAgIH0gZWxzZSB7CiAgICAgICAgY291dCA8PCAiTyhuXiIgPDwgYyA8PCAiKSIgPDwgZW5kbDsKICAgIH0KICAgIHJldHVybiAwOwp9
stdin
MTgKaW5zdHJ1Y3Rpb24KZm9yCmZvcgppbnN0cnVjdGlvbgplbmQKZm9yCmluc3RydWN0aW9uCmluc3RydWN0aW9uCmluc3RydWN0aW9uCmZvcgppbnN0cnVjdGlvbgppbnN0cnVjdGlvbgplbmQKaW5zdHJ1Y3Rpb24KZW5kCmVuZAppbnN0cnVjdGlvbgppbnN0cnVjdGlvbg==
18
instruction
for
for
instruction
end
for
instruction
instruction
instruction
for
instruction
instruction
end
instruction
end
end
instruction
instruction