#include <bits/stdc++.h>
using namespace std;
queue<string> stk;
stack<int> pro;
int needtype = 1;
string s;
int main() {
  getline(cin, s);
  while (cin >> s) {
    stk.push(s);
    needtype--;
    if (needtype == -1) return puts("Error occurred"), 0;
    if (s == "pair") needtype += 2;
  }
  if (needtype) return puts("Error occurred"), 0;
  if (((int)(stk).size()) == 1 && stk.front() == "int") return puts("int"), 0;
  while (stk.size()) {
    cout << stk.front();
    if (stk.front() == "pair") {
      pro.push(2);
    }
    stk.pop();
    while (pro.size()) {
      if (pro.top() == 2) {
        cout << "<";
        break;
      } else if (pro.top() == 1) {
        cout << ",";
        break;
      } else {
        cout << ">", pro.pop();
      }
    }
    if (pro.size()) {
      int to = pro.top();
      pro.pop();
      pro.push(to - 1);
    }
  }
  return 0;
}
