#include <bits/stdc++.h>
using namespace std;
int n = 0;
vector<string> v, s;
stack<int> stk;
bool f(int i) {
  if (i == n) return stk.empty() ? true : false;
  if (v[i] == "pair") {
    s.push_back("<");
    if (i > 0) {
      if (s[i - 1] == "<")
        stk.push(1);
      else {
        if (stk.empty()) return false;
        if (stk.top() != 1) return false;
        stk.pop();
        stk.push(2);
      }
    }
  } else {
    if (s[i - 1] == "<") {
      s.push_back(",");
      stk.push(1);
    } else {
      if (stk.empty()) return false;
      if (stk.top() != 1) return false;
      string st = ">";
      stk.pop();
      while (!stk.empty()) {
        int m = stk.top();
        if (m == 1) break;
        stk.pop();
        st += ">";
      }
      if (i < n - 1) st += ",";
      s.push_back(st);
    }
  }
  return f(i + 1);
}
int main() {
  int m;
  cin >> m;
  string str;
  while (cin >> str) {
    v.push_back(str);
    n++;
  }
  if (n == 1) {
    if (v[0] == "int")
      cout << v[0] << endl;
    else
      cout << "Error occurred" << endl;
  } else if (n == 2)
    cout << "Error occurred" << endl;
  else {
    if (v[0] == "int")
      cout << "Error occurred" << endl;
    else {
      if (f(0)) {
        for (int a = 0; a < n; a++) cout << v[a] << s[a];
        cout << endl;
      } else
        cout << "Error occurred" << endl;
    }
  }
  return 0;
}
