#include <bits/stdc++.h>
using namespace std;
char str[100000 + 5];
vector<string> E;
int idx = 0;
string ans;
bool go() {
  if (idx == E.size()) return false;
  if (E[idx] == "pair") {
    ans += "pair<";
    idx++;
    if (idx == E.size()) return false;
    if (go() == false) return false;
    ans += ",";
    if (go() == false) return false;
    ans += ">";
  } else {
    ans += "int";
    idx++;
    return true;
  }
  return true;
}
int main() {
  int n;
  scanf("%d", &n);
  string str;
  ans = "";
  while (cin >> str) {
    E.push_back(str);
  }
  int f = go();
  if (f == 0 || idx != E.size())
    cout << "Error occurred" << endl;
  else
    cout << ans << endl;
}
