#include <bits/stdc++.h>
using namespace std;
string s, t;
int ok = 1, n;
void f() {
  if (cin >> s) {
    t += s;
    if (s == "pair") t += '<', f(), t += ',', f(), t += '>';
  } else
    ok = 0;
}
int main() {
  cin >> n;
  f();
  if (!ok || cin >> s) {
    cout << "Error occurred";
    return 0;
  }
  cout << t;
  return 0;
}
