#include<iostream>
#define N 100
using namespace std;
struct ListNode{
ListNode * link;
bool tag;
union {
char data;
ListNode * dlink;
} ;
} ;
struct Stack{
ListNode * stackarray[ N] ;
int sp;
} ;
Stack s;
int push( Stack * ,ListNode * ) ;
ListNode* pop( Stack * ) ;
int isempty( Stack * ) ;
int isfull( Stack * ) ;
ListNode* create( char [ ] ) ;
int main( void ) {
s.sp = - 1 ;
ListNode* h= NULL ;
char input[ 50 ] ;
cin >> input;
h= create( input) ;
cout << h- > data<< endl;
system ( "pause" ) ;
return 0 ;
}
ListNode* create( char string[ ] ) {
ListNode * p= new ListNode;
ListNode * q;
int i= 0 ;
char x;
x= string[ i++ ] ;
do {
switch ( x) {
case '(' :
x= string[ i++ ] ;
p- > tag= true ;
if ( x== ')' ) {
p- > dlink= NULL ;
if ( ! isempty( & s) )
x= string[ i++ ] ;
}
else {
p- > dlink= new ListNode;
push( & s,p) ;
}
break ;
case ')' :
p- > link= NULL ;
p= pop( & s) ;
if ( ! isempty( & s) )
x= string[ i++ ] ;
break ;
case ',' :
p- > link= new ListNode;
p= p- > link;
x= string[ i++ ] ;
break ;
default :
p- > tag= false ;
p- > data= x- 48 ;
x= string[ i++ ] ;
}
} while ( ! isempty( & s) ) ;
q= p- > dlink;
free ( p) ;
return q;
}
int push( Stack * p,ListNode * x) {
if ( isfull( p) )
return 1 ;
p- > sp++ ;
p- > stackarray[ p- > sp] = x;
}
ListNode* pop( Stack * p) {
if ( isempty( p) )
return NULL ;
else
return p- > stackarray[ p- > sp-- ] ;
}
int isempty( Stack * p) {
if ( p- > sp== - 1 )
return 1 ;
else
return 0 ;
}
int isfull( Stack * p) {
if ( p- > sp== N- 1 )
return 1 ;
else
return 0 ;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNkZWZpbmUgTiAxMDAKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgoKCnN0cnVjdCBMaXN0Tm9kZXsKICAgICAgICAgICAKICAgICBMaXN0Tm9kZSAqbGluazsKICAgICBib29sIHRhZzsKICAgICB1bmlvbnsKICAgICAgIGNoYXIgZGF0YTsgICAgCiAgICAgICBMaXN0Tm9kZSAqZGxpbms7ICAgIAogICAgICAgICAgIH07CiAgICAgICAgCiAgICAgICAgfTsgCiAgICAgICAgCiBzdHJ1Y3QgU3RhY2t7CiAgICAgICBMaXN0Tm9kZSAqc3RhY2thcnJheVtOXTsKICAgICAgIGludCBzcDsKICAgICAgIAogICAgICAgCiAgICAgICB9OyAgICAgICAKU3RhY2sgczsKICAgICAKaW50IHB1c2goU3RhY2sgKixMaXN0Tm9kZSAqKTsKTGlzdE5vZGUqIHBvcChTdGFjayAqKTsKaW50IGlzZW1wdHkoU3RhY2sgKik7IAppbnQgaXNmdWxsKFN0YWNrICopOyAgCkxpc3ROb2RlKiBjcmVhdGUoY2hhciBbXSk7CiAgICAgICAgCmludCBtYWluKHZvaWQpewogICAgcy5zcD0tMTsgIAogICAgCiAgICAKICAgIExpc3ROb2RlKiBoPU5VTEw7CiAgICAKICAgIGNoYXIgaW5wdXRbNTBdOwogICAgY2luPj5pbnB1dDsKICAgIGg9Y3JlYXRlKGlucHV0KTsKICAgCiAgICBjb3V0PDxoLT5kYXRhPDxlbmRsOwogICAgCiAgICAKICAgICBzeXN0ZW0oInBhdXNlIik7CiAgICAgcmV0dXJuIDA7CiAgICAKICAgIAp9CgoKTGlzdE5vZGUqIGNyZWF0ZShjaGFyIHN0cmluZ1tdICl7CiAgICAgICAgICBMaXN0Tm9kZSAqcD1uZXcgTGlzdE5vZGU7CiAgICAgICAgICBMaXN0Tm9kZSAqcTsKICAgICAgICAgIGludCBpPTA7CiAgICAgICAgICBjaGFyIHg7CiAgICAgICAgICB4PXN0cmluZ1tpKytdOwogICAgICAgICAKICAgICAgICAgIGRvewogICAgICAgICAgICAgIHN3aXRjaCh4KXsKICAgICAgICAgICAgICAgICAgY2FzZSAnKCc6ICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgIHg9c3RyaW5nW2krK107CiAgICAgICAgICAgICAgICAgICAgICAgIHAtPnRhZz10cnVlOwogICAgICAgICAgICAgICAgICAgICAgICBpZih4PT0nKScpewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwLT5kbGluaz1OVUxMOyAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYoIWlzZW1wdHkoJnMpKSAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHg9c3RyaW5nW2krK107ICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgZWxzZXsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHAtPmRsaW5rPW5ldyBMaXN0Tm9kZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHB1c2goJnMscCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gCiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgY2FzZSAnKSc6CiAgICAgICAgICAgICAgICAgICAgICAgIHAtPmxpbms9TlVMTDsKICAgICAgICAgICAgICAgICAgICAgICAgcD1wb3AoJnMpOwogICAgICAgICAgICAgICAgICAgICAgICAgICBpZighaXNlbXB0eSgmcykpICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgeD1zdHJpbmdbaSsrXTsgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgY2FzZSAnLCc6CiAgICAgICAgICAgICAgICAgICAgICAgIHAtPmxpbms9bmV3IExpc3ROb2RlOwogICAgICAgICAgICAgICAgICAgICAgICBwPXAtPmxpbms7CiAgICAgICAgICAgICAgICAgICAgICAgIHg9c3RyaW5nW2krK107CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgICAgICAgICAgICAgcC0+dGFnPWZhbHNlOwogICAgICAgICAgICAgICAgICAgICAgICAgICBwLT5kYXRhPXgtNDg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgIHg9c3RyaW5nW2krK107ICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICB9ICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICB9d2hpbGUoIWlzZW1wdHkoJnMpKTsKICAgICAgICAgIAogICAgICAgICAgcT1wLT5kbGluazsKICAgICAgICAgIAogICAgICAgICAgZnJlZShwKTsKICAgICAgICAgIHJldHVybiBxOwogICAgICAgICAgCiAgICAgICAgICAKICAgICAgICAgIH0KICAgICAgICAgIAogICAgICAgICAgCmludCBwdXNoKFN0YWNrICpwLExpc3ROb2RlICp4KXsKICAgICBpZihpc2Z1bGwocCkpCiAgICAgcmV0dXJuIDE7CiAgICAgcC0+c3ArKzsKICAgICBwLT5zdGFja2FycmF5W3AtPnNwXT14OwogICAgIAogICAgIH0KICAgICAKTGlzdE5vZGUqIHBvcChTdGFjayAqcCl7CiAgICAgaWYoaXNlbXB0eShwKSkKICAgICByZXR1cm4gTlVMTDsKICAgICBlbHNlCiAgICAgcmV0dXJuIHAtPnN0YWNrYXJyYXlbcC0+c3AtLV07ICAgICAKICAgICAKICAgICAgCiAgICAgfSAKICAgICAKaW50IGlzZW1wdHkoU3RhY2sgKnApewogICAgIGlmKHAtPnNwPT0tMSkKICAgICByZXR1cm4gMTsKICAgICBlbHNlCiAgICAgcmV0dXJuIDA7ICAgICAgCiAgICAgfQogICAgICAgICAgCmludCBpc2Z1bGwoU3RhY2sgKnApewogICAgaWYocC0+c3A9PU4tMSkgICAKICAgIHJldHVybiAxOwogICAgZWxzZQogICAgcmV0dXJuIDA7ICAgCn0=