#include <bits/stdc++.h>
using namespace std;
vector<string> arr;
int m[100005];
bool calc(int s, int &n) {
  int i;
  string str = "";
  if (s == arr.size()) {
    n = s;
    m[s] = n;
    return false;
  }
  if (arr[s] == "int") {
    n = s;
    m[s] = n;
    return true;
  } else if (arr[s] == "pair") {
    bool b = calc(s + 1, i);
    if (!b) return b;
    b = calc(i + 1, i);
    if (!b) return b;
    n = i;
    m[s] = n;
    return true;
  }
}
void print(int s) {
  if (s == arr.size()) return;
  if (arr[s] == "int")
    cout << arr[s];
  else if (arr[s] == "pair") {
    cout << "pair<";
    print(s + 1);
    cout << ",";
    print(m[s + 1] + 1);
    cout << ">";
  }
}
int main() {
  int i, j, k, n;
  bool b;
  cin >> n;
  getchar();
  string str, st;
  getline(cin, st);
  stringstream ss(st);
  while (ss >> str) arr.push_back(str);
  b = calc(0, i);
  if (i < arr.size() - 1 || !b)
    cout << "Error occurred\n";
  else
    print(0);
  return 0;
}
