#include <bits/stdc++.h>
using namespace std;
vector<string> a;
string an;
long long p;
long long n, c;
bool valid = 1;
int f() {
  while (1) {
    if (p >= a.size()) {
      valid = 0;
      return 1;
    }
    if (a[p] == "int") {
      p++;
      c--;
      an += "int";
      return 1;
    }
    p++;
    an += "pair<";
    string s = "";
    f();
    an += ",";
    string ss = "";
    f();
    an += ">";
    return 1;
  }
}
int main() {
  string l, s;
  cin >> n;
  c = n;
  while (cin >> s) a.push_back(s);
  s = f();
  if (valid && !c && p >= a.size())
    cout << an << endl;
  else
    cout << "Error occurred" << endl;
}
