#include <bits/stdc++.h>
using namespace std;
int pos = -1;
void Go(vector<string> &t) {
  if (t[++pos] == "int") {
    cout << "int";
  } else {
    cout << "pair<";
    Go(t);
    cout << ",";
    Go(t);
    cout << ">";
  }
}
int main() {
  int n, i = 0;
  bool check = true;
  cin >> n;
  string t, t1 = "";
  int bal = 0;
  int k = 0;
  std::vector<std::string> s;
  char c;
  std::getline(std::cin, t);
  std::getline(std::cin, t);
  for (int j = 0; j < t.length(); j++) {
    if (t[j] != ' ') {
      t1 += t[j];
    } else {
      s.push_back(t1);
      t1 = "";
    }
  }
  s.push_back(t1);
  k = s.size();
  {
    for (int i = 0; i < k - 1; i++) {
      if (s[i] == "pair")
        bal++;
      else {
        bal--;
      }
      if (bal < 0) {
        check = false;
      }
    }
    if (s[k - 1] == "pair")
      bal++;
    else {
      bal--;
    }
    if (bal != -1) {
      check = false;
    }
    if (!check) {
      cout << "Error occurred";
      return 0;
    }
  }
  Go(s);
}
