#include <bits/stdc++.h>
using namespace std;
vector<string> V;
int main() {
  int n;
  cin >> n;
  string aux;
  while (cin >> aux) {
    V.push_back(aux);
  }
  n = V.size();
  int c = 0;
  int ele = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (V[i] == "int")
      ele++;
    else {
      ele--;
      c++;
    }
    if (ele == 0) break;
  }
  if (ele == 1) {
    stack<int> S;
    for (int i = 0; i < n; i++) {
      cout << V[i];
      if (V[i] == "pair") {
        cout << "<";
        S.push(0);
      } else {
        int aux = 2;
        while (aux == 2) {
          if (S.empty()) break;
          aux = S.top();
          S.pop();
          if (aux == 0) {
            cout << ",";
          } else {
            cout << ">";
          }
          aux++;
          if (aux == 1) S.push(aux);
        }
      }
    }
    cout << "\n";
  } else {
    cout << "Error occurred\n";
  }
  return 0;
}
