#include <bits/stdc++.h>
using namespace std;
double PI = 3.1415926536;
int dX[] = {1, -1, 0, 0};
int dY[] = {0, 0, 1, -1};
int idx;
string res;
vector<string> s;
int rec() {
  if (idx == (int)s.size()) return -1;
  if (s[idx] == "int") {
    res += "int";
    return 1;
  } else {
    res += "pair";
    idx++;
    res += "<";
    if (rec() == -1) return -1;
    res += ",";
    idx++;
    if (rec() == -1) return -1;
    res += ">";
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  string tmp;
  cin.ignore();
  getline(cin, tmp);
  for (int i = (0); i < ((int)tmp.size()); i++) {
    if (tmp.substr(i, 4) == "pair")
      s.push_back("pair");
    else if (tmp.substr(i, 3) == "int")
      s.push_back("int");
  }
  if (rec() == -1 || idx != (int)s.size() - 1)
    puts("Error occurred");
  else
    cout << res;
}
