#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const long long mod = 1e9 + 7;
const long long INF = 1e18;
const int MAX = 1e5 + 10, N = 1e6 + 10;
const int lim = 1 << 18;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  cin.ignore();
  string s;
  getline(cin, s);
  deque<string> lft;
  string tmp;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] != ' ')
      tmp += s[i];
    else
      lft.push_back(tmp), tmp = "";
  }
  lft.push_back(tmp);
  deque<string> st;
  vector<string> ans;
  for (int i = 0; i < lft.size(); i++) {
    if (st.size()) {
      if (st.back() == "int")
        ans.push_back(",");
      else
        ans.push_back("<");
    }
    ans.push_back(lft[i]);
    st.push_back(lft[i]);
    while (st.size() > 2) {
      int n = st.size();
      if (st[n - 1] == "int" && st[n - 2] == "int" && st[n - 3] == "pair")
        st.pop_back(), st.pop_back(), st.pop_back(), st.push_back("int"),
            ans.push_back(">");
      else
        break;
    }
  }
  if (st.size() > 1)
    cout << "Error occurred";
  else
    for (int i = 0; i < ans.size(); i++) cout << ans[i];
  cout << "\n";
  return 0;
}
