#include <bits/stdc++.h>
using namespace std;
long long x, xxxxx = 0;
string s, word;
long long indx = 0, lmt;
string v[100009], out = "";
bool f_int = false;
bool ok() {
  if (indx > lmt) return xxxxx = 1, false;
  bool o1, o2;
  o1 = o2 = false;
  if (v[indx] == "int" and indx != 1) {
    out += "int";
    f_int = true;
    return true;
  }
  ++indx;
  out += "pair<";
  o1 = ok();
  ++indx;
  out += ",";
  o2 = ok();
  if (!o2) xxxxx = 1, out += "XXX";
  out += ">";
  return true;
}
int main() {
  cin >> x;
  getchar();
  getline(cin, s);
  stringstream ss(s);
  while (ss >> word) {
    v[++indx] = word;
  }
  if (indx == 1) {
    if (v[1] == "int")
      cout << "int";
    else
      cout << "Error occurred";
    return 0;
  }
  lmt = indx;
  indx = 1;
  ok();
  if (xxxxx || !f_int || indx != lmt)
    cout << "Error occurred";
  else
    cout << out;
}
