#include <bits/stdc++.h>
using namespace std;
vector<string> s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  string cur;
  string ans;
  while (cin >> cur) s.push_back(cur);
  if (s.size() == 1) {
    if (s[0] == "int") {
      cout << "int\n";
      return 0;
    } else {
      cout << "Error occurred\n";
      return 0;
    };
  }
  stack<int> st;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == "pair") {
      ans += s[i];
      ans += "<";
      st.push(0);
    } else {
      ans += s[i];
      if (st.empty()) {
        cout << "Error occurred\n";
        return 0;
      };
      while (st.size()) {
        int top = st.top();
        top++;
        st.pop();
        if (top == 1) {
          st.push(top);
          ans += ",";
          break;
        } else {
          ans += ">";
        }
      }
    }
  }
  if (st.size()) {
    cout << "Error occurred\n";
    return 0;
  };
  cout << ans << "\n";
  return 0;
}
