/*3102*/
import java.util.*;
class stack {
int data[];
int top;
stack(int k) {
data = new int[k];
top = -1;
}
void push(int k) {
top++;
data[top] = k;
}
void pop() {
if(top!=-1) {
data[top]=0;
top--;
}
}
void top() {
if (top==-1) {
System.out.println(-1);
}
else {
System.out.println(data[top]);
}
}
void empty(){
if(top==-1) System.out.println("true");
else System.out.println("false");
}
void size() {
System.out.println(top+1);
}
}
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n;
n = s.nextInt();// 몇개 명령어?
stack stack = new stack(n);
String str;
s.nextLine();
for (int i = 0; i < n; i++) {
str = s.nextLine();
String[] data = str.split(" ");
if (str.equals("top()")) {
stack.top();
}
else if(str.equals("pop()")) {
stack.pop();
}
else if(str.equals("size()")) {
stack.size();
}
else if(str.equals("empty()")) {
stack.empty();
}
else {
stack.push(Integer.parseInt(data[1]));
}
}
}
}
/////////////////
/*3102*/
import java.net.StandardSocketOptions;
import java.util.*;
class stack {
String data[];
int top;
stack(int k) {
data = new String[k];
top = -1;
}
void push(String k) {
top++;
data[top] = k;
}
void pop() {
if(top!=-1) {
data[top]=null;
top--;
}
}
}
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String str;
str = s.next();
String galho []= new String[str.length()];
stack stack = new stack(str.length());
int sum=0;
int num;
for(int i=0; i<str.length();i++) {
galho[i] = str.substring(i, i+1);
if (galho[i].equals("(") || galho[i].equals("[")) {
stack.push(galho[i]);
}
else if(galho[i].equals(")")) {
if(galho[i-1].equals("(")){
sum=sum+2;
stack.pop();
stack.push("2");
}
else if(!galho[i-1].equals("(")||!galho[i-1].equals(")")||!galho[i-1].equals("[")||!galho[i-1].equals("]")) {
sum=Integer.parseInt(galho[i-1])*2;
}
}
else if(galho[i].equals("]")) {
if(galho[i-1].equals("[")){
sum=sum+3;
stack.pop();
stack.push("3");
}
else if(!galho[i-1].equals("(")||!galho[i-1].equals(")")||!galho[i-1].equals("[")||!galho[i-1].equals("]")) {
sum=Integer.parseInt(galho[i-1])*3;
}
}
else {
sum=sum+Integer.parseInt(galho[i]);
}
}
}
}