#include <bits/stdc++.h>
using namespace std;
int a[1000005];
map<int, vector<int> > adj;
vector<string> v, res;
void dfs(int u) {
  printf("%s", v[u].c_str());
  if (adj[u].size() == 0) return;
  if (v[u].size() >= 1) {
    printf("<");
    dfs(adj[u][0]);
    printf(",");
  }
  if (v[u].size() >= 2) {
    dfs(adj[u][1]);
    printf(">");
  }
}
int main() {
  int n;
  cin >> n;
  getchar();
  string s;
  getline(cin, s);
  string temp;
  stack<int> st;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == ' ') {
      v.push_back(temp);
      temp.clear();
    } else
      temp += s[i];
  }
  v.push_back(temp);
  st.push(0);
  for (int i = 1; i < v.size(); i++) {
    int temp;
    if (st.size())
      temp = st.top();
    else {
      cout << "Error occurred" << endl;
      return 0;
    }
    while (st.size() && adj[temp].size() == 2) {
      st.pop();
      if (st.size())
        temp = st.top();
      else {
        cout << "Error occurred" << endl;
        return 0;
      }
    }
    if (st.size())
      adj[st.top()].push_back(i);
    else {
      cout << "Error occurred" << endl;
      return 0;
    }
    if (v[i] == "pair") {
      st.push(i);
    }
  }
  for (int i = 0; i < v.size(); i++) {
    if (v[i] == "pair" && adj[i].size() != 2) {
      cout << "Error occurred" << endl;
      return 0;
    }
    if (v[i] == "int" && adj[i].size() != 0) {
      cout << "Error occurred" << endl;
      return 0;
    }
  }
  dfs(0);
  cout << endl;
}
