#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  vector<string> w;
  while (cin >> s) {
    w.push_back(s);
  }
  string ans;
  vector<int> stack;
  bool error = false;
  int index = 0;
  for (int i = 0; i < w.size(); i++) {
    index = i + 1;
    ans += w[i];
    if (w[i] == "pair") {
      stack.push_back(2);
      ans += "<";
    } else if (w[i] == "int") {
      int size = stack.size();
      if (!size) {
        break;
      }
      if (stack[size - 1] == 2) {
        ans += ",";
        stack[size - 1] = 1;
      } else {
        ans += ">";
        stack.pop_back();
        while (stack.size() and stack[stack.size() - 1] == 1) {
          ans += ">";
          stack.pop_back();
        }
        if (stack.size()) {
          ans += ",";
          stack[stack.size() - 1] = 1;
        }
      }
    } else
      error = true;
    if (!stack.size()) break;
  }
  if (stack.size() or index < w.size()) error = true;
  if (error)
    cout << "Error occurred" << endl;
  else
    cout << ans << endl;
  return 0;
}
