#include <bits/stdc++.h>
using namespace std;
vector<string> type;
int x = 0;
string g;
void makep() {
  g += "pair<";
  ++x;
  if (x >= (long long)type.size()) {
    cout << "Error occurred";
    exit(0);
  }
  if (type[x] == "int")
    g += "int,";
  else if (type[x] == "pair") {
    makep();
    g.push_back(',');
  }
  ++x;
  if (x >= (long long)type.size()) {
    cout << "Error occurred";
    exit(0);
  }
  if (type[x] == "int")
    g += "int>";
  else if (type[x] == "pair") {
    makep();
    g.push_back('>');
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  string s;
  while (cin >> s) {
    type.push_back(s);
  }
  if (n == 1) {
    if ((long long)type.size() == 1)
      cout << "int"
           << "\n";
    else
      cout << ("Error occurred") << " ";
  } else {
    if (type[0] == "int")
      cout << ("Error occurred") << " ";
    else {
      makep();
      if (x < (long long)type.size() - 1)
        cout << ("Error occurred") << " ";
      else
        cout << g << "\n";
    }
  }
}
