190_C. STL
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
```python

###pyrival template for fast IO
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
class pair:
    def __init__(self):
        self.parent=None
        self.left=None
        self.right=None
        self.visited=False
        self.isleft=True
    def type(self):
        return 0

class integer:
    def __init__(self):
        self.parent=None
        self.visited=False
        self.isleft=True

    def type(self):
        return 1

num=int(input())
arr=[pair() if x=="pair" else integer() for x in input().split()]
n=len(arr)
def build_tree(arr):###dfs approach
    if arr[0].type()==0:
        currnode=arr[0]
    else:
        if n==1:return True
        return False
    i=1
    while i in range(1,n):
        if currnode==None:######tree ends but input not ends
            return False
        if currnode.left!=None and currnode.right!=None:
            currnode=currnode.parent
        elif currnode.left==None:
            currnode.left=arr[i]
            arr[i].parent=currnode
            if arr[i].type()==0:
                currnode=arr[i]
            i+=1
        elif currnode.right==None:
            currnode.right=arr[i]
            arr[i].parent=currnode
            if arr[i].type()==0:
                currnode=arr[i]
            i+=1
    ###we back track to check for invalid nodes(input ends but tree incomplete)
    while True:
        if currnode.left==None or currnode.right==None:
            return False
        if currnode.parent==None:
            return True
        else:currnode=currnode.parent


def dfs(arr):
    currnode=arr[0]
    ans=[]
    while currnode!=None:
        if currnode.type()==0:
            if currnode.visited==False:
                ans.append("pair")
                ans.append("<")
                currnode.visited=True

            if currnode.left.visited==True and currnode.right.visited==True:
                if currnode.isleft==True:ans.append(",")
                else :ans.append(">")
                currnode=currnode.parent
            elif currnode.left.visited==False:
                currnode=currnode.left
            else:
                currnode=currnode.right
                currnode.isleft=False
        else:
            if currnode.visited==False:
                currnode.visited=True
            ans.append("int")
            if currnode.isleft==True:ans.append(",")
            else:ans.append(">")
            currnode=currnode.parent
    ans[-1]="\n"
    return ans

if build_tree(arr)==True:
    for i in dfs(arr):
        sys.stdout.write(i)
else:
    print("Error occurred")
```