#include <bits/stdc++.h>
using namespace std;
string res, s;
int flag = 0;
void getType() {
  if (cin >> s) {
    res += s;
    if (s == "pair") {
      res += "<";
      getType();
      res += ",";
      getType();
      res += ">";
    }
  } else
    flag = 1;
}
int main() {
  int n;
  cin >> n;
  getType();
  if (flag == 1 || cin >> s) {
    cout << "Error occurred";
    return 0;
  }
  cout << res;
  return 0;
}
