#include <bits/stdc++.h>
using namespace std;
string a[200001];
int consType(int i) {
  if (a[i] == "int") {
    cout << "int";
    return i + 1;
  } else {
    cout << "pair<";
    int ret = consType(i + 1);
    cout << ",";
    ret = consType(ret);
    cout << ">";
    return ret;
  }
}
int main(int argc, char *argv[]) {
  int p = 0, i = 0, n;
  int idx = 0;
  string s;
  cin >> n;
  while (cin >> s) {
    a[++idx] = s;
  }
  for (int j = 1; j <= idx; j++) {
    if (a[j] == "pair")
      p++;
    else
      i++;
    if ((j != idx && (p - i < 0 || p - i > n)) || (j == idx && p - i != -1)) {
      cout << "Error occurred" << endl;
      return 0;
    }
  }
  consType(1);
  cout << endl;
  return 0;
}
