#include <bits/stdc++.h>
using namespace std;
long long gettype(long long x, vector<string>& vs) {
  if (x >= vs.size()) return -1;
  if (vs[x] == "int") {
    cout << "int";
    return x;
  } else {
    cout << "pair<";
    long long y = gettype(x + 1, vs);
    cout << ",";
    y = gettype(y + 1, vs);
    cout << ">";
    return y;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m = 0;
  cin >> n;
  string s;
  vector<string> vs;
  while (cin >> s) {
    vs.push_back(s);
    m++;
  }
  long long bal = 0;
  bool pos = 1;
  for (long long int i = 0; i < m; i++) {
    if (vs[i] == "pair")
      bal++;
    else
      bal--;
    if (i == m - 1) {
      if (bal != -1) pos = 0;
    } else if (bal < 0) {
      pos = 0;
      break;
    }
  }
  if (!pos) {
    cout << "Error occurred";
  } else {
    gettype(0, vs);
  }
}
