Vasya used to be an accountant before the war began and he is one of the few who knows how to operate a computer, so he was assigned as the programmer.

We all know that programs often store sets of integers. For example, if we have a problem about a weighted directed graph, its edge can be represented by three integers: the number of the starting vertex, the number of the final vertex and the edge's weight. So, as Vasya was trying to represent characteristics of a recently invented robot in his program, he faced the following problem.

Vasya is not a programmer, so he asked his friend Gena, what the convenient way to store n integers is. Gena used to code in language X-- and so he can use only the types that occur in this language. Let's define, what a "type" is in language X--:

  * First, a type is a string "int". 
  * Second, a type is a string that starts with "pair", then followed by angle brackets listing exactly two comma-separated other types of language X--. This record contains no spaces. 
  * No other strings can be regarded as types. 



More formally: type := int | pair<type,type>. For example, Gena uses the following type for graph edges: pair<int,pair<int,int>>.

Gena was pleased to help Vasya, he dictated to Vasya a type of language X--, that stores n integers. Unfortunately, Gena was in a hurry, so he omitted the punctuation. Now Gena has already left and Vasya can't find the correct punctuation, resulting in a type of language X--, however hard he tries.

Help Vasya and add the punctuation marks so as to receive the valid type of language X--. Otherwise say that the task is impossible to perform.

Input

The first line contains a single integer n (1 ≤ n ≤ 105), showing how many numbers the type dictated by Gena contains.

The second line contains space-separated words, said by Gena. Each of them is either "pair" or "int" (without the quotes).

It is guaranteed that the total number of words does not exceed 105 and that among all the words that Gena said, there are exactly n words "int".

Output

If it is possible to add the punctuation marks so as to get a correct type of language X-- as a result, print a single line that represents the resulting type. Otherwise, print "Error occurred" (without the quotes). Inside the record of a type should not be any extra spaces and other characters. 

It is guaranteed that if such type exists, then it is unique.

Note that you should print the type dictated by Gena (if such type exists) and not any type that can contain n values.

Examples

Input

3
pair pair int int int


Output

pair&lt;pair&lt;int,int&gt;,int&gt;

Input

1
pair int


Output

Error occurred
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.Vector;

/**
 * @author Ivanov A.K.
 */
public class A {
    private BufferedReader reader;
    private StringTokenizer tokenizer;
    private PrintWriter pw;

    public static final int pairEmpty = 0;
    public static final int integer = 1;
    public static final int pairWithFirst = 2;
    public static final int parenth = 3;

    void solve() throws IOException {
        int n = nextInt();
        Stack<Integer> stack = new Stack<Integer>();
        StringBuilder stringBuilder = new StringBuilder();

        for (int i = 0 ; i < n; ) {
            String s = nextToken();
            if (s.equals("pair"))
                stack.push(pairEmpty);
            else {
                stack.push(integer);
                ++i;
            }

            if (stack.size() >= 2) {
                int a = stack.pop();
                int b = stack.pop();

                if (b == pairEmpty) {
                    if (a == integer) {
                        stringBuilder.append("pair<int,");
                        stack.push(pairWithFirst);
                    } else if (a == pairEmpty) {
                        stringBuilder.append("pair<");
                        stack.push(pairWithFirst);
                        stack.push(pairEmpty);
                    }
                } else if (b == pairWithFirst) {
                    if (a == integer) {
                        stringBuilder.append("int>");
                        while(stack.size() > 0 && stack.peek() == parenth) {
                            stack.pop();
                            stringBuilder.append(">");
                        }
                        if (i != n)
                            stringBuilder.append(",");
                    } else if (a == pairEmpty) {
                        stack.push(parenth);
                        stack.push(pairEmpty);
                    }
                } else {
                    stack.push(b);
                    stack.push(a);
                    break;
                }

            }
        }

        if (tokenizer.hasMoreTokens()) {
            System.out.println("Error occurred");
            return;
        }

        if (stack.size() == 0)
            System.out.println(stringBuilder);
        else if (stack.size() == 1 && stack.peek() == integer && n == 1)
            System.out.println("int");
        else
            System.out.println("Error occurred");

    }


    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            pw = new PrintWriter(System.out);
            solve();
            pw.close();
            reader.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new A().run();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
//
//    long nextLong() throws IOException {
//        return Long.parseLong(nextToken());
//    }
//
    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}